History

mfd / platform: cros_ec: Move debugfs attributes to its own driver

The entire way how cros debugfs attibutes are created is broken. cros_ec_debugfs should be its own driver and its attributes should be associated with a debugfs driver not the mfd driver.

Enric Balletbo i Serra committed 7 years ago

Commit 6fce0a21 parent acb99005 files · +56 −68Browse files

Unified · Split

5 files
  1. drivers/mfd/cros_ec_dev.c +1 −40
  2. drivers/platform/chrome/Kconfig +11 −0
  3. drivers/platform/chrome/Makefile +2 −2
  4. drivers/platform/chrome/cros_ec_debugfs.c +42 −20
  5. include/linux/mfd/cros_ec.h +0 −6
drivers/mfd/cros_ec_dev.c+1−40
@@ -394,6 +394,7 @@ static const struct mfd_cell cros_usbpd_charger_cells[] = { · 393 unmodified lines
394};394};
395 395
396static const struct mfd_cell cros_ec_platform_cells[] = {396static const struct mfd_cell cros_ec_platform_cells[] = {
397 { .name = "cros-ec-debugfs" },
397 { .name = "cros-ec-lightbar" },398 { .name = "cros-ec-lightbar" },
398 { .name = "cros-ec-vbc" },399 { .name = "cros-ec-vbc" },
399};400};
@@ -489,9 +490,6 @@ static int ec_device_probe(struct platform_device *pdev) · 89 unmodified lines
489 "failed to add cros-ec platform devices: %d\n",490 "failed to add cros-ec platform devices: %d\n",
490 retval);491 retval);
491 492
492 if (cros_ec_debugfs_init(ec))
493 dev_warn(dev, "failed to create debugfs directory\n");
494
495 return 0;493 return 0;
496 494
497failed:495failed:
@@ -503,62 +501,25 @@ static int ec_device_remove(struct platform_device *pdev) · 5 unmodified lines
503{501{
504 struct cros_ec_dev *ec = dev_get_drvdata(&pdev->dev);502 struct cros_ec_dev *ec = dev_get_drvdata(&pdev->dev);
505 503
506 cros_ec_debugfs_remove(ec);
507
508 mfd_remove_devices(ec->dev);504 mfd_remove_devices(ec->dev);
509 cdev_del(&ec->cdev);505 cdev_del(&ec->cdev);
510 device_unregister(&ec->class_dev);506 device_unregister(&ec->class_dev);
511 return 0;507 return 0;
512}508}
513 509
514static void ec_device_shutdown(struct platform_device *pdev)
515{
516 struct cros_ec_dev *ec = dev_get_drvdata(&pdev->dev);
517
518 /* Be sure to clear up debugfs delayed works */
519 cros_ec_debugfs_remove(ec);
520}
521
522static const struct platform_device_id cros_ec_id[] = {510static const struct platform_device_id cros_ec_id[] = {
523 { DRV_NAME, 0 },511 { DRV_NAME, 0 },
524 { /* sentinel */ }512 { /* sentinel */ }
525};513};
526MODULE_DEVICE_TABLE(platform, cros_ec_id);514MODULE_DEVICE_TABLE(platform, cros_ec_id);
527 515
528static __maybe_unused int ec_device_suspend(struct device *dev)
529{
530 struct cros_ec_dev *ec = dev_get_drvdata(dev);
531
532 cros_ec_debugfs_suspend(ec);
533
534 return 0;
535}
536
537static __maybe_unused int ec_device_resume(struct device *dev)
538{
539 struct cros_ec_dev *ec = dev_get_drvdata(dev);
540
541 cros_ec_debugfs_resume(ec);
542
543 return 0;
544}
545
546static const struct dev_pm_ops cros_ec_dev_pm_ops = {
547#ifdef CONFIG_PM_SLEEP
548 .suspend = ec_device_suspend,
549 .resume = ec_device_resume,
550#endif
551};
552
553static struct platform_driver cros_ec_dev_driver = {516static struct platform_driver cros_ec_dev_driver = {
554 .driver = {517 .driver = {
555 .name = DRV_NAME,518 .name = DRV_NAME,
556 .pm = &cros_ec_dev_pm_ops,
557 },519 },
558 .id_table = cros_ec_id,520 .id_table = cros_ec_id,
559 .probe = ec_device_probe,521 .probe = ec_device_probe,
560 .remove = ec_device_remove,522 .remove = ec_device_remove,
561 .shutdown = ec_device_shutdown,
562};523};
563 524
564static int __init cros_ec_dev_init(void)525static int __init cros_ec_dev_init(void)
drivers/platform/chrome/Kconfig+11−0
@@ -133,4 +133,15 @@ config CROS_EC_VBC · 132 unmodified lines
133 To compile this driver as a module, choose M here: the133 To compile this driver as a module, choose M here: the
134 module will be called cros_ec_vbc.134 module will be called cros_ec_vbc.
135 135
136config CROS_EC_DEBUGFS
137 tristate "Export ChromeOS EC internals in DebugFS"
138 depends on MFD_CROS_EC_CHARDEV && DEBUG_FS
139 default MFD_CROS_EC_CHARDEV
140 help
141 This option exposes the ChromeOS EC device internals to
142 userspace.
143
144 To compile this driver as a module, choose M here: the
145 module will be called cros_ec_debugfs.
146
136endif # CHROMEOS_PLATFORMS147endif # CHROMEOS_PLATFORMS
drivers/platform/chrome/Makefile+2−2
@@ -3,8 +3,7 @@ · 2 unmodified lines
3obj-$(CONFIG_CHROMEOS_LAPTOP) += chromeos_laptop.o3obj-$(CONFIG_CHROMEOS_LAPTOP) += chromeos_laptop.o
4obj-$(CONFIG_CHROMEOS_PSTORE) += chromeos_pstore.o4obj-$(CONFIG_CHROMEOS_PSTORE) += chromeos_pstore.o
5obj-$(CONFIG_CHROMEOS_TBMC) += chromeos_tbmc.o5obj-$(CONFIG_CHROMEOS_TBMC) += chromeos_tbmc.o
6cros_ec_ctl-objs := cros_ec_sysfs.o \6cros_ec_ctl-objs := cros_ec_sysfs.o
7 cros_ec_debugfs.o
8obj-$(CONFIG_CROS_EC_CTL) += cros_ec_ctl.o7obj-$(CONFIG_CROS_EC_CTL) += cros_ec_ctl.o
9obj-$(CONFIG_CROS_EC_I2C) += cros_ec_i2c.o8obj-$(CONFIG_CROS_EC_I2C) += cros_ec_i2c.o
10obj-$(CONFIG_CROS_EC_SPI) += cros_ec_spi.o9obj-$(CONFIG_CROS_EC_SPI) += cros_ec_spi.o
@@ -15,3 +14,4 @@ obj-$(CONFIG_CROS_EC_PROTO) += cros_ec_proto.o · 4 unmodified lines
15obj-$(CONFIG_CROS_KBD_LED_BACKLIGHT) += cros_kbd_led_backlight.o14obj-$(CONFIG_CROS_KBD_LED_BACKLIGHT) += cros_kbd_led_backlight.o
16obj-$(CONFIG_CROS_EC_LIGHTBAR) += cros_ec_lightbar.o15obj-$(CONFIG_CROS_EC_LIGHTBAR) += cros_ec_lightbar.o
17obj-$(CONFIG_CROS_EC_VBC) += cros_ec_vbc.o16obj-$(CONFIG_CROS_EC_VBC) += cros_ec_vbc.o
17obj-$(CONFIG_CROS_EC_DEBUGFS) += cros_ec_debugfs.o
drivers/platform/chrome/cros_ec_debugfs.c+42−20
@@ -23,12 +23,16 @@ · 22 unmodified lines
23#include <linux/fs.h>23#include <linux/fs.h>
24#include <linux/mfd/cros_ec.h>24#include <linux/mfd/cros_ec.h>
25#include <linux/mfd/cros_ec_commands.h>25#include <linux/mfd/cros_ec_commands.h>
26#include <linux/module.h>
26#include <linux/mutex.h>27#include <linux/mutex.h>
28#include <linux/platform_device.h>
27#include <linux/poll.h>29#include <linux/poll.h>
28#include <linux/sched.h>30#include <linux/sched.h>
29#include <linux/slab.h>31#include <linux/slab.h>
30#include <linux/wait.h>32#include <linux/wait.h>
31 33
34#define DRV_NAME "cros-ec-debugfs"
35
32#define LOG_SHIFT 1436#define LOG_SHIFT 14
33#define LOG_SIZE (1 << LOG_SHIFT)37#define LOG_SIZE (1 << LOG_SHIFT)
34#define LOG_POLL_SEC 1038#define LOG_POLL_SEC 10
@@ -423,8 +427,9 @@ static int cros_ec_create_pdinfo(struct cros_ec_debugfs *debug_info) · 388 unmodified lines
423 return 0;427 return 0;
424}428}
425 429
426int cros_ec_debugfs_init(struct cros_ec_dev *ec)430static int cros_ec_debugfs_probe(struct platform_device *pd)
427{431{
432 struct cros_ec_dev *ec = dev_get_drvdata(pd->dev.parent);
428 struct cros_ec_platform *ec_platform = dev_get_platdata(ec->dev);433 struct cros_ec_platform *ec_platform = dev_get_platdata(ec->dev);
429 const char *name = ec_platform->ec_name;434 const char *name = ec_platform->ec_name;
430 struct cros_ec_debugfs *debug_info;435 struct cros_ec_debugfs *debug_info;
@@ -453,40 +458,57 @@ int cros_ec_debugfs_init(struct cros_ec_dev *ec) · 22 unmodified lines
453 458
454 ec->debug_info = debug_info;459 ec->debug_info = debug_info;
455 460
461 dev_set_drvdata(&pd->dev, ec);
462
456 return 0;463 return 0;
457 464
458remove_debugfs:465remove_debugfs:
459 debugfs_remove_recursive(debug_info->dir);466 debugfs_remove_recursive(debug_info->dir);
460 return ret;467 return ret;
461}468}
462EXPORT_SYMBOL(cros_ec_debugfs_init);
463 469
464void cros_ec_debugfs_remove(struct cros_ec_dev *ec)470static int cros_ec_debugfs_remove(struct platform_device *pd)
465{471{
466 if (!ec->debug_info)472 struct cros_ec_dev *ec = dev_get_drvdata(pd->dev.parent);
467 return;
468 473
469 debugfs_remove_recursive(ec->debug_info->dir);474 debugfs_remove_recursive(ec->debug_info->dir);
470 cros_ec_cleanup_console_log(ec->debug_info);475 cros_ec_cleanup_console_log(ec->debug_info);
476
477 return 0;
471}478}
472EXPORT_SYMBOL(cros_ec_debugfs_remove);
473 479
474void cros_ec_debugfs_suspend(struct cros_ec_dev *ec)480static int __maybe_unused cros_ec_debugfs_suspend(struct device *dev)
475{481{
476 /*482 struct cros_ec_dev *ec = dev_get_drvdata(dev);
477 * cros_ec_debugfs_init() failures are non-fatal; it's also possible483
478 * that we initted things but decided that console log wasn't supported.484 cancel_delayed_work_sync(&ec->debug_info->log_poll_work);
479 * We'll use the same set of checks that cros_ec_debugfs_remove() +485
480 * cros_ec_cleanup_console_log() end up using to handle those cases.486 return 0;
481 */
482 if (ec->debug_info && ec->debug_info->log_buffer.buf)
483 cancel_delayed_work_sync(&ec->debug_info->log_poll_work);
484}487}
485EXPORT_SYMBOL(cros_ec_debugfs_suspend);
486 488
487void cros_ec_debugfs_resume(struct cros_ec_dev *ec)489static int __maybe_unused cros_ec_debugfs_resume(struct device *dev)
488{490{
489 if (ec->debug_info && ec->debug_info->log_buffer.buf)491 struct cros_ec_dev *ec = dev_get_drvdata(dev);
490 schedule_delayed_work(&ec->debug_info->log_poll_work, 0);492
493 schedule_delayed_work(&ec->debug_info->log_poll_work, 0);
494
495 return 0;
491}496}
492EXPORT_SYMBOL(cros_ec_debugfs_resume);497
498static SIMPLE_DEV_PM_OPS(cros_ec_debugfs_pm_ops,
499 cros_ec_debugfs_suspend, cros_ec_debugfs_resume);
500
501static struct platform_driver cros_ec_debugfs_driver = {
502 .driver = {
503 .name = DRV_NAME,
504 .pm = &cros_ec_debugfs_pm_ops,
505 },
506 .probe = cros_ec_debugfs_probe,
507 .remove = cros_ec_debugfs_remove,
508};
509
510module_platform_driver(cros_ec_debugfs_driver);
511
512MODULE_LICENSE("GPL");
513MODULE_DESCRIPTION("Debug logs for ChromeOS EC");
514MODULE_ALIAS("platform:" DRV_NAME);
include/linux/mfd/cros_ec.h+0−6
@@ -328,10 +328,4 @@ u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev); · 327 unmodified lines
328/* sysfs stuff */328/* sysfs stuff */
329extern struct attribute_group cros_ec_attr_group;329extern struct attribute_group cros_ec_attr_group;
330 330
331/* debugfs stuff */
332int cros_ec_debugfs_init(struct cros_ec_dev *ec);
333void cros_ec_debugfs_remove(struct cros_ec_dev *ec);
334void cros_ec_debugfs_suspend(struct cros_ec_dev *ec);
335void cros_ec_debugfs_resume(struct cros_ec_dev *ec);
336
337#endif /* __LINUX_MFD_CROS_EC_H */331#endif /* __LINUX_MFD_CROS_EC_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t