|
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) |
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) |
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); |
0 commit comments