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.
Unified · Split
| @@ -394,6 +394,7 @@ static const struct mfd_cell cros_usbpd_charger_cells[] = { · 393 unmodified lines | ||
| 394 | 394 | }; |
| 395 | 395 | |
| 396 | 396 | static const struct mfd_cell cros_ec_platform_cells[] = { |
| 397 | + { .name = "cros-ec-debugfs" }, | |
| 397 | 398 | { .name = "cros-ec-lightbar" }, |
| 398 | 399 | { .name = "cros-ec-vbc" }, |
| 399 | 400 | }; |
| @@ -489,9 +490,6 @@ static int ec_device_probe(struct platform_device *pdev) · 89 unmodified lines | ||
| 489 | 490 | "failed to add cros-ec platform devices: %d\n", |
| 490 | 491 | retval); |
| 491 | 492 | |
| 492 | − if (cros_ec_debugfs_init(ec)) | |
| 493 | − dev_warn(dev, "failed to create debugfs directory\n"); | |
| 494 | − | |
| 495 | 493 | return 0; |
| 496 | 494 | |
| 497 | 495 | failed: |
| @@ -503,62 +501,25 @@ static int ec_device_remove(struct platform_device *pdev) · 5 unmodified lines | ||
| 503 | 501 | { |
| 504 | 502 | struct cros_ec_dev *ec = dev_get_drvdata(&pdev->dev); |
| 505 | 503 | |
| 506 | − cros_ec_debugfs_remove(ec); | |
| 507 | − | |
| 508 | 504 | mfd_remove_devices(ec->dev); |
| 509 | 505 | cdev_del(&ec->cdev); |
| 510 | 506 | device_unregister(&ec->class_dev); |
| 511 | 507 | return 0; |
| 512 | 508 | } |
| 513 | 509 | |
| 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 | − | |
| 522 | 510 | static const struct platform_device_id cros_ec_id[] = { |
| 523 | 511 | { DRV_NAME, 0 }, |
| 524 | 512 | { /* sentinel */ } |
| 525 | 513 | }; |
| 526 | 514 | MODULE_DEVICE_TABLE(platform, cros_ec_id); |
| 527 | 515 | |
| 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 | − | |
| 553 | 516 | static struct platform_driver cros_ec_dev_driver = { |
| 554 | 517 | .driver = { |
| 555 | 518 | .name = DRV_NAME, |
| 556 | − .pm = &cros_ec_dev_pm_ops, | |
| 557 | 519 | }, |
| 558 | 520 | .id_table = cros_ec_id, |
| 559 | 521 | .probe = ec_device_probe, |
| 560 | 522 | .remove = ec_device_remove, |
| 561 | − .shutdown = ec_device_shutdown, | |
| 562 | 523 | }; |
| 563 | 524 | |
| 564 | 525 | static int __init cros_ec_dev_init(void) |
| @@ -133,4 +133,15 @@ config CROS_EC_VBC · 132 unmodified lines | ||
| 133 | 133 | To compile this driver as a module, choose M here: the |
| 134 | 134 | module will be called cros_ec_vbc. |
| 135 | 135 | |
| 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 | + | |
| 136 | 147 | endif # CHROMEOS_PLATFORMS |
| @@ -3,8 +3,7 @@ · 2 unmodified lines | ||
| 3 | 3 | obj-$(CONFIG_CHROMEOS_LAPTOP) += chromeos_laptop.o |
| 4 | 4 | obj-$(CONFIG_CHROMEOS_PSTORE) += chromeos_pstore.o |
| 5 | 5 | 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 | |
| 8 | 7 | obj-$(CONFIG_CROS_EC_CTL) += cros_ec_ctl.o |
| 9 | 8 | obj-$(CONFIG_CROS_EC_I2C) += cros_ec_i2c.o |
| 10 | 9 | 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 | ||
| 15 | 14 | obj-$(CONFIG_CROS_KBD_LED_BACKLIGHT) += cros_kbd_led_backlight.o |
| 16 | 15 | obj-$(CONFIG_CROS_EC_LIGHTBAR) += cros_ec_lightbar.o |
| 17 | 16 | obj-$(CONFIG_CROS_EC_VBC) += cros_ec_vbc.o |
| 17 | +obj-$(CONFIG_CROS_EC_DEBUGFS) += cros_ec_debugfs.o | |
| @@ -23,12 +23,16 @@ · 22 unmodified lines | ||
| 23 | 23 | #include <linux/fs.h> |
| 24 | 24 | #include <linux/mfd/cros_ec.h> |
| 25 | 25 | #include <linux/mfd/cros_ec_commands.h> |
| 26 | +#include <linux/module.h> | |
| 26 | 27 | #include <linux/mutex.h> |
| 28 | +#include <linux/platform_device.h> | |
| 27 | 29 | #include <linux/poll.h> |
| 28 | 30 | #include <linux/sched.h> |
| 29 | 31 | #include <linux/slab.h> |
| 30 | 32 | #include <linux/wait.h> |
| 31 | 33 | |
| 34 | +#define DRV_NAME "cros-ec-debugfs" | |
| 35 | + | |
| 32 | 36 | #define LOG_SHIFT 14 |
| 33 | 37 | #define LOG_SIZE (1 << LOG_SHIFT) |
| 34 | 38 | #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 | 427 | return 0; |
| 424 | 428 | } |
| 425 | 429 | |
| 426 | −int cros_ec_debugfs_init(struct cros_ec_dev *ec) | |
| 430 | +static int cros_ec_debugfs_probe(struct platform_device *pd) | |
| 427 | 431 | { |
| 432 | + struct cros_ec_dev *ec = dev_get_drvdata(pd->dev.parent); | |
| 428 | 433 | struct cros_ec_platform *ec_platform = dev_get_platdata(ec->dev); |
| 429 | 434 | const char *name = ec_platform->ec_name; |
| 430 | 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 | 459 | ec->debug_info = debug_info; |
| 455 | 460 | |
| 461 | + dev_set_drvdata(&pd->dev, ec); | |
| 462 | + | |
| 456 | 463 | return 0; |
| 457 | 464 | |
| 458 | 465 | remove_debugfs: |
| 459 | 466 | debugfs_remove_recursive(debug_info->dir); |
| 460 | 467 | return ret; |
| 461 | 468 | } |
| 462 | −EXPORT_SYMBOL(cros_ec_debugfs_init); | |
| 463 | 469 | |
| 464 | −void cros_ec_debugfs_remove(struct cros_ec_dev *ec) | |
| 470 | +static int cros_ec_debugfs_remove(struct platform_device *pd) | |
| 465 | 471 | { |
| 466 | − if (!ec->debug_info) | |
| 467 | − return; | |
| 472 | + struct cros_ec_dev *ec = dev_get_drvdata(pd->dev.parent); | |
| 468 | 473 | |
| 469 | 474 | debugfs_remove_recursive(ec->debug_info->dir); |
| 470 | 475 | cros_ec_cleanup_console_log(ec->debug_info); |
| 476 | + | |
| 477 | + return 0; | |
| 471 | 478 | } |
| 472 | −EXPORT_SYMBOL(cros_ec_debugfs_remove); | |
| 473 | 479 | |
| 474 | −void cros_ec_debugfs_suspend(struct cros_ec_dev *ec) | |
| 480 | +static int __maybe_unused cros_ec_debugfs_suspend(struct device *dev) | |
| 475 | 481 | { |
| 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; | |
| 484 | 487 | } |
| 485 | −EXPORT_SYMBOL(cros_ec_debugfs_suspend); | |
| 486 | 488 | |
| 487 | −void cros_ec_debugfs_resume(struct cros_ec_dev *ec) | |
| 489 | +static int __maybe_unused cros_ec_debugfs_resume(struct device *dev) | |
| 488 | 490 | { |
| 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; | |
| 491 | 496 | } |
| 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); | |
| @@ -328,10 +328,4 @@ u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev); · 327 unmodified lines | ||
| 328 | 328 | /* sysfs stuff */ |
| 329 | 329 | extern struct attribute_group cros_ec_attr_group; |
| 330 | 330 | |
| 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 | − | |
| 337 | 331 | #endif /* __LINUX_MFD_CROS_EC_H */ |