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
394394 };
395395
396396 static const struct mfd_cell cros_ec_platform_cells[] = {
397+ { .name = "cros-ec-debugfs" },
397398 { .name = "cros-ec-lightbar" },
398399 { .name = "cros-ec-vbc" },
399400 };
@@ -489,9 +490,6 @@ static int ec_device_probe(struct platform_device *pdev) · 89 unmodified lines
489490 "failed to add cros-ec platform devices: %d\n",
490491 retval);
491492
492− if (cros_ec_debugfs_init(ec))
493− dev_warn(dev, "failed to create debugfs directory\n");
494−
495493 return 0;
496494
497495 failed:
@@ -503,62 +501,25 @@ static int ec_device_remove(struct platform_device *pdev) · 5 unmodified lines
503501 {
504502 struct cros_ec_dev *ec = dev_get_drvdata(&pdev->dev);
505503
506− cros_ec_debugfs_remove(ec);
507−
508504 mfd_remove_devices(ec->dev);
509505 cdev_del(&ec->cdev);
510506 device_unregister(&ec->class_dev);
511507 return 0;
512508 }
513509
514−static 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−
522510 static const struct platform_device_id cros_ec_id[] = {
523511 { DRV_NAME, 0 },
524512 { /* sentinel */ }
525513 };
526514 MODULE_DEVICE_TABLE(platform, cros_ec_id);
527515
528−static __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−
537−static __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−
546−static 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−
553516 static struct platform_driver cros_ec_dev_driver = {
554517 .driver = {
555518 .name = DRV_NAME,
556− .pm = &cros_ec_dev_pm_ops,
557519 },
558520 .id_table = cros_ec_id,
559521 .probe = ec_device_probe,
560522 .remove = ec_device_remove,
561− .shutdown = ec_device_shutdown,
562523 };
563524
564525 static int __init cros_ec_dev_init(void)
drivers/platform/chrome/Kconfig+11−0
@@ -133,4 +133,15 @@ config CROS_EC_VBC · 132 unmodified lines
133133 To compile this driver as a module, choose M here: the
134134 module will be called cros_ec_vbc.
135135
136+config 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+
136147 endif # CHROMEOS_PLATFORMS
drivers/platform/chrome/Makefile+2−2
@@ -3,8 +3,7 @@ · 2 unmodified lines
33 obj-$(CONFIG_CHROMEOS_LAPTOP) += chromeos_laptop.o
44 obj-$(CONFIG_CHROMEOS_PSTORE) += chromeos_pstore.o
55 obj-$(CONFIG_CHROMEOS_TBMC) += chromeos_tbmc.o
6−cros_ec_ctl-objs := cros_ec_sysfs.o \
7− cros_ec_debugfs.o
6+cros_ec_ctl-objs := cros_ec_sysfs.o
87 obj-$(CONFIG_CROS_EC_CTL) += cros_ec_ctl.o
98 obj-$(CONFIG_CROS_EC_I2C) += cros_ec_i2c.o
109 obj-$(CONFIG_CROS_EC_SPI) += cros_ec_spi.o
@@ -15,3 +14,4 @@ obj-$(CONFIG_CROS_EC_PROTO) += cros_ec_proto.o · 4 unmodified lines
1514 obj-$(CONFIG_CROS_KBD_LED_BACKLIGHT) += cros_kbd_led_backlight.o
1615 obj-$(CONFIG_CROS_EC_LIGHTBAR) += cros_ec_lightbar.o
1716 obj-$(CONFIG_CROS_EC_VBC) += cros_ec_vbc.o
17+obj-$(CONFIG_CROS_EC_DEBUGFS) += cros_ec_debugfs.o
drivers/platform/chrome/cros_ec_debugfs.c+42−20
@@ -23,12 +23,16 @@ · 22 unmodified lines
2323 #include <linux/fs.h>
2424 #include <linux/mfd/cros_ec.h>
2525 #include <linux/mfd/cros_ec_commands.h>
26+#include <linux/module.h>
2627 #include <linux/mutex.h>
28+#include <linux/platform_device.h>
2729 #include <linux/poll.h>
2830 #include <linux/sched.h>
2931 #include <linux/slab.h>
3032 #include <linux/wait.h>
3133
34+#define DRV_NAME "cros-ec-debugfs"
35+
3236 #define LOG_SHIFT 14
3337 #define LOG_SIZE (1 << LOG_SHIFT)
3438 #define LOG_POLL_SEC 10
@@ -423,8 +427,9 @@ static int cros_ec_create_pdinfo(struct cros_ec_debugfs *debug_info) · 388 unmodified lines
423427 return 0;
424428 }
425429
426−int cros_ec_debugfs_init(struct cros_ec_dev *ec)
430+static int cros_ec_debugfs_probe(struct platform_device *pd)
427431 {
432+ struct cros_ec_dev *ec = dev_get_drvdata(pd->dev.parent);
428433 struct cros_ec_platform *ec_platform = dev_get_platdata(ec->dev);
429434 const char *name = ec_platform->ec_name;
430435 struct cros_ec_debugfs *debug_info;
@@ -453,40 +458,57 @@ int cros_ec_debugfs_init(struct cros_ec_dev *ec) · 22 unmodified lines
453458
454459 ec->debug_info = debug_info;
455460
461+ dev_set_drvdata(&pd->dev, ec);
462+
456463 return 0;
457464
458465 remove_debugfs:
459466 debugfs_remove_recursive(debug_info->dir);
460467 return ret;
461468 }
462−EXPORT_SYMBOL(cros_ec_debugfs_init);
463469
464−void cros_ec_debugfs_remove(struct cros_ec_dev *ec)
470+static int cros_ec_debugfs_remove(struct platform_device *pd)
465471 {
466− if (!ec->debug_info)
467− return;
472+ struct cros_ec_dev *ec = dev_get_drvdata(pd->dev.parent);
468473
469474 debugfs_remove_recursive(ec->debug_info->dir);
470475 cros_ec_cleanup_console_log(ec->debug_info);
476+
477+ return 0;
471478 }
472−EXPORT_SYMBOL(cros_ec_debugfs_remove);
473479
474−void cros_ec_debugfs_suspend(struct cros_ec_dev *ec)
480+static int __maybe_unused cros_ec_debugfs_suspend(struct device *dev)
475481 {
476− /*
477− * cros_ec_debugfs_init() failures are non-fatal; it's also possible
478− * that we initted things but decided that console log wasn't supported.
479− * We'll use the same set of checks that cros_ec_debugfs_remove() +
480− * cros_ec_cleanup_console_log() end up using to handle those cases.
481− */
482− if (ec->debug_info && ec->debug_info->log_buffer.buf)
483− cancel_delayed_work_sync(&ec->debug_info->log_poll_work);
482+ struct cros_ec_dev *ec = dev_get_drvdata(dev);
483+
484+ cancel_delayed_work_sync(&ec->debug_info->log_poll_work);
485+
486+ return 0;
484487 }
485−EXPORT_SYMBOL(cros_ec_debugfs_suspend);
486488
487−void cros_ec_debugfs_resume(struct cros_ec_dev *ec)
489+static int __maybe_unused cros_ec_debugfs_resume(struct device *dev)
488490 {
489− if (ec->debug_info && ec->debug_info->log_buffer.buf)
490− schedule_delayed_work(&ec->debug_info->log_poll_work, 0);
491+ struct cros_ec_dev *ec = dev_get_drvdata(dev);
492+
493+ schedule_delayed_work(&ec->debug_info->log_poll_work, 0);
494+
495+ return 0;
491496 }
492−EXPORT_SYMBOL(cros_ec_debugfs_resume);
497+
498+static SIMPLE_DEV_PM_OPS(cros_ec_debugfs_pm_ops,
499+ cros_ec_debugfs_suspend, cros_ec_debugfs_resume);
500+
501+static 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+
510+module_platform_driver(cros_ec_debugfs_driver);
511+
512+MODULE_LICENSE("GPL");
513+MODULE_DESCRIPTION("Debug logs for ChromeOS EC");
514+MODULE_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
328328 /* sysfs stuff */
329329 extern struct attribute_group cros_ec_attr_group;
330330
331−/* debugfs stuff */
332−int cros_ec_debugfs_init(struct cros_ec_dev *ec);
333−void cros_ec_debugfs_remove(struct cros_ec_dev *ec);
334−void cros_ec_debugfs_suspend(struct cros_ec_dev *ec);
335−void cros_ec_debugfs_resume(struct cros_ec_dev *ec);
336−
337331 #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