From e86264595225d2764a903965356ef59aeb7d1c47 Mon Sep 17 00:00:00 2001 From: Eric Caruso Date: Tue, 16 May 2017 17:46:48 +0200 Subject: mfd: cros_ec: add debugfs, console log file If the EC supports the new CONSOLE_READ command type, then we place a console_log file in debugfs for that EC device which allows us to grab EC logs. The kernel will poll every 10 seconds for the log and keep its own buffer, but userspace should grab this and write it out to some logs which actually get rotated. Signed-off-by: Eric Caruso Signed-off-by: Nicolas Boichat Acked-by: Lee Jones Tested-by: Enric Balletbo i Serra [bleung: restored original version of this commit, with pointer size issue to be fixed in next commit] Signed-off-by: Benson Leung --- drivers/platform/chrome/cros_ec_dev.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'drivers/platform/chrome/cros_ec_dev.c') diff --git a/drivers/platform/chrome/cros_ec_dev.c b/drivers/platform/chrome/cros_ec_dev.c index 6aa120cd0574..20ce1c23fb5c 100644 --- a/drivers/platform/chrome/cros_ec_dev.c +++ b/drivers/platform/chrome/cros_ec_dev.c @@ -24,6 +24,7 @@ #include #include +#include "cros_ec_debugfs.h" #include "cros_ec_dev.h" /* Device variables */ @@ -427,6 +428,9 @@ static int ec_device_probe(struct platform_device *pdev) goto failed; } + if (cros_ec_debugfs_init(ec)) + dev_warn(dev, "failed to create debugfs directory\n"); + /* check whether this EC is a sensor hub. */ if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE)) cros_ec_sensors_register(ec); @@ -441,6 +445,9 @@ failed: static int ec_device_remove(struct platform_device *pdev) { struct cros_ec_dev *ec = dev_get_drvdata(&pdev->dev); + + cros_ec_debugfs_remove(ec); + cdev_del(&ec->cdev); device_unregister(&ec->class_dev); return 0; -- cgit v1.2.3 From 405c84308c4335ee7cb58b9304b77b85e61f7129 Mon Sep 17 00:00:00 2001 From: Eric Caruso Date: Tue, 16 May 2017 17:46:48 +0200 Subject: platform/chrome: cros_ec_lightbar - Control of suspend/resume lightbar sequence Don't let EC control suspend/resume sequence. If the EC controls the lightbar and sets the sequence when it notices the chipset transitioning between states, we can't make exceptions for cases where we don't want to activate the lightbar. Instead, let's move the suspend/resume notifications into the kernel so we can selectively play the sequences. Signed-off-by: Eric Caruso Signed-off-by: Guenter Roeck Signed-off-by: Enric Balletbo i Serra Acked-by: Lee Jones Signed-off-by: Benson Leung --- drivers/platform/chrome/cros_ec_dev.c | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'drivers/platform/chrome/cros_ec_dev.c') diff --git a/drivers/platform/chrome/cros_ec_dev.c b/drivers/platform/chrome/cros_ec_dev.c index 20ce1c23fb5c..7c2622319211 100644 --- a/drivers/platform/chrome/cros_ec_dev.c +++ b/drivers/platform/chrome/cros_ec_dev.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -435,6 +436,10 @@ static int ec_device_probe(struct platform_device *pdev) if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE)) cros_ec_sensors_register(ec); + /* Take control of the lightbar from the EC. */ + if (ec_has_lightbar(ec)) + lb_manual_suspend_ctrl(ec, 1); + return 0; failed: @@ -446,6 +451,10 @@ static int ec_device_remove(struct platform_device *pdev) { struct cros_ec_dev *ec = dev_get_drvdata(&pdev->dev); + /* Let the EC take over the lightbar again. */ + if (ec_has_lightbar(ec)) + lb_manual_suspend_ctrl(ec, 0); + cros_ec_debugfs_remove(ec); cdev_del(&ec->cdev); @@ -459,9 +468,37 @@ static const struct platform_device_id cros_ec_id[] = { }; MODULE_DEVICE_TABLE(platform, cros_ec_id); +static int ec_device_suspend(struct device *dev) +{ + struct cros_ec_dev *ec = dev_get_drvdata(dev); + + if (ec_has_lightbar(ec)) + lb_suspend(ec); + + return 0; +} + +static int ec_device_resume(struct device *dev) +{ + struct cros_ec_dev *ec = dev_get_drvdata(dev); + + if (ec_has_lightbar(ec)) + lb_resume(ec); + + return 0; +} + +static const struct dev_pm_ops cros_ec_dev_pm_ops = { +#ifdef CONFIG_PM_SLEEP + .suspend = ec_device_suspend, + .resume = ec_device_resume, +#endif +}; + static struct platform_driver cros_ec_dev_driver = { .driver = { .name = "cros-ec-ctl", + .pm = &cros_ec_dev_pm_ops, }, .probe = ec_device_probe, .remove = ec_device_remove, -- cgit v1.2.3 From 995c0ec9a81f9e4e75f280f095534f4ed1a9ea9d Mon Sep 17 00:00:00 2001 From: Jeffery Yu Date: Tue, 16 May 2017 17:46:48 +0200 Subject: platform/chrome: cros_ec_lightbar - Avoid I2C xfer to EC during suspend A Mutex lock in cros_ec_cmd_xfer which may be held by frozen Userspace thread during system suspending. So should not call this routine in suspend thread. Signed-off-by: Jeffery Yu Signed-off-by: Guenter Roeck Signed-off-by: Enric Balletbo i Serra Signed-off-by: Benson Leung --- drivers/platform/chrome/cros_ec_dev.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'drivers/platform/chrome/cros_ec_dev.c') diff --git a/drivers/platform/chrome/cros_ec_dev.c b/drivers/platform/chrome/cros_ec_dev.c index 7c2622319211..b9bf086f7569 100644 --- a/drivers/platform/chrome/cros_ec_dev.c +++ b/drivers/platform/chrome/cros_ec_dev.c @@ -437,8 +437,7 @@ static int ec_device_probe(struct platform_device *pdev) cros_ec_sensors_register(ec); /* Take control of the lightbar from the EC. */ - if (ec_has_lightbar(ec)) - lb_manual_suspend_ctrl(ec, 1); + lb_manual_suspend_ctrl(ec, 1); return 0; @@ -452,8 +451,7 @@ static int ec_device_remove(struct platform_device *pdev) struct cros_ec_dev *ec = dev_get_drvdata(&pdev->dev); /* Let the EC take over the lightbar again. */ - if (ec_has_lightbar(ec)) - lb_manual_suspend_ctrl(ec, 0); + lb_manual_suspend_ctrl(ec, 0); cros_ec_debugfs_remove(ec); @@ -472,8 +470,7 @@ static int ec_device_suspend(struct device *dev) { struct cros_ec_dev *ec = dev_get_drvdata(dev); - if (ec_has_lightbar(ec)) - lb_suspend(ec); + lb_suspend(ec); return 0; } @@ -482,8 +479,7 @@ static int ec_device_resume(struct device *dev) { struct cros_ec_dev *ec = dev_get_drvdata(dev); - if (ec_has_lightbar(ec)) - lb_resume(ec); + lb_resume(ec); return 0; } -- cgit v1.2.3 From 5d6a312e8f99f0a0bf793256c203fa17c97a15e1 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Tue, 27 Jun 2017 17:36:36 +0200 Subject: platform/chrome: cros_ec_lightbar - hide unused PM functions The only reference to the new functions is inside of an #ifdef, which now causes a harmless warning when CONFIG_PM_SLEEP is not set: chrome/cros_ec_dev.c:478:12: error: 'ec_device_resume' defined but not used [-Werror=unused-function] chrome/cros_ec_dev.c:469:12: error: 'ec_device_suspend' defined but not used [-Werror=unused-function] This marks the two functions as __maybe_unused so they can get silently dropped by the compiler. Fixes: 405c84308c43 ("platform/chrome: cros_ec_lightbar - Control of suspend/resume lightbar sequence") Signed-off-by: Arnd Bergmann Reviewed-by: Guenter Roeck Signed-off-by: Benson Leung --- drivers/platform/chrome/cros_ec_dev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/platform/chrome/cros_ec_dev.c') diff --git a/drivers/platform/chrome/cros_ec_dev.c b/drivers/platform/chrome/cros_ec_dev.c index b9bf086f7569..cf6c4f0846b8 100644 --- a/drivers/platform/chrome/cros_ec_dev.c +++ b/drivers/platform/chrome/cros_ec_dev.c @@ -466,7 +466,7 @@ static const struct platform_device_id cros_ec_id[] = { }; MODULE_DEVICE_TABLE(platform, cros_ec_id); -static int ec_device_suspend(struct device *dev) +static __maybe_unused int ec_device_suspend(struct device *dev) { struct cros_ec_dev *ec = dev_get_drvdata(dev); @@ -475,7 +475,7 @@ static int ec_device_suspend(struct device *dev) return 0; } -static int ec_device_resume(struct device *dev) +static __maybe_unused int ec_device_resume(struct device *dev) { struct cros_ec_dev *ec = dev_get_drvdata(dev); -- cgit v1.2.3