drivers: watchdog: Add ChromeOS EC watchdog
Subsystems (4)
Lukasz Majczak
maintainerPATCH 1/1 drivers: watchdog: Add ChromeOS EC watchdog
This adds EC-based watchdog support for ChromeOS based devices equipped with embedded controller (EC).
--- MAINTAINERS | 6 + drivers/mfd/cros_ec_dev.c | 9 + drivers/watchdog/Kconfig | 15 + drivers/watchdog/Makefile | 3 + drivers/watchdog/cros_ec_wdt.c | 303 ++++++++++++++++++ .../linux/platform_data/cros_ec_commands.h | 78 ++--- 6 files changed, 370 insertions(+), 44 deletions(-) create mode 100644 drivers/watchdog/cros_ec_wdt.c
MAINTAINERS +6 -0
@@ -4952,6 +4952,12 @@ R: Sami Kyöstilä <[email protected]> S: Maintained F: drivers/platform/chrome/cros_hps_i2c.c +CHROMEOS EC WATCHDOG +M: Lukasz Majczak <[email protected]> +L: [email protected] +S: Maintained +F: drivers/watchdog/cros_ec_wdt.c + CHRONTEL CH7322 CEC DRIVER M: Joe Tessler <[email protected]> L: [email protected]
drivers/mfd/cros_ec_dev.c +9 -0
@@ -91,6 +91,10 @@ static const struct mfd_cell cros_usbpd_notify_cells[] = { { .name = "cros-usbpd-notify", }, }; +static const struct mfd_cell cros_ec_wdt_cells[] = { + { .name ="cros-ec-wdt-drv" , } +}; +static const struct cros_feature_to_cells cros_subdevices[] = { { .id =EC_FEATURE_CEC ,
@@ -107,6 +111,11 @@ static const struct cros_feature_to_cells cros_subdevices[] = { .mfd_cells = cros_usbpd_charger_cells, .num_cells = ARRAY_SIZE(cros_usbpd_charger_cells), }, + { + .id = EC_FEATURE_HANG_DETECT, + .mfd_cells = cros_ec_wdt_cells, + .num_cells = ARRAY_SIZE(cros_ec_wdt_cells), + }, };static const struct mfd_cell cros_ec_platform_cells[] = {
drivers/watchdog/Kconfig +15 -0
@@ -2251,4 +2251,19 @@ config KEEMBAY_WATCHDOG To compile this driver as a module, choose M here: the module will be called keembay_wdt. +# +# ChromeOS EC-based Watchdog +# + +config CROS_EC_WATCHDOG + tristate "ChromeOS EC-based watchdog driver" + select WATCHDOG_CORE + depends on CROS_EC + help + This is the watchdog driver for ChromeOS devices equipped with EC. + The EC watchdog - when enabled - expects to be kicked within a given + time (default set to 30 seconds) otherwise it will simple reboot + the AP. Priori to that it can also send an event (configurable timeout) + about upcoming reboot. + endif # WATCHDOG
drivers/watchdog/Makefile +3 -0
@@ -234,3 +234,6 @@ obj-$(CONFIG_MENZ069_WATCHDOG) += menz69_wdt.o obj-$(CONFIG_RAVE_SP_WATCHDOG) += rave-sp-wdt.o obj-$(CONFIG_STPMIC1_WATCHDOG) += stpmic1_wdt.o obj-$(CONFIG_SL28CPLD_WATCHDOG) += sl28cpld_wdt.o + +# Cros EC watchdog +obj-$(CONFIG_CROS_EC_WATCHDOG) += cros_ec_wdt.o
drivers/watchdog/cros_ec_wdt.c new file +303 -0
303 lines not on this page · raw message
include/linux/platform_data/cros_ec_commands.h +34 -44
94 lines not on this page · raw message
Signature · 1 line
2.43.0.381.gb435a96ce8-goog
Quoted 63 lines · Lukasz Majczak
This adds EC-based watchdog support for ChromeOS based devices equipped with embedded controller (EC).
Signed-off-by Lukasz Majczak <[email protected]>--- MAINTAINERS | 6 + drivers/mfd/cros_ec_dev.c | 9 + drivers/watchdog/Kconfig | 15 + drivers/watchdog/Makefile | 3 + drivers/watchdog/cros_ec_wdt.c | 303 ++++++++++++++++++ .../linux/platform_data/cros_ec_commands.h | 78 ++--- 6 files changed, 370 insertions(+), 44 deletions(-) create mode 100644 drivers/watchdog/cros_ec_wdt.cMAINTAINERS +6
-0@@ -4952,6 +4952,12 @@ R: Sami Kyöstilä <[email protected]> S: Maintained F: drivers/platform/chrome/cros_hps_i2c.c +CHROMEOS EC WATCHDOG +M: Lukasz Majczak <[email protected]> +L: [email protected] +S: Maintained +F: drivers/watchdog/cros_ec_wdt.c + CHRONTEL CH7322 CEC DRIVER M: Joe Tessler <[email protected]> L: [email protected]drivers/mfd/cros_ec_dev.c +9
-0@@ -91,6 +91,10 @@ static const struct mfd_cell cros_usbpd_notify_cells[] = { { .name = "cros-usbpd-notify", }, }; +static const struct mfd_cell cros_ec_wdt_cells[] = { + { .name ="cros-ec-wdt-drv" , } +}; +static const struct cros_feature_to_cells cros_subdevices[] = { { .id =EC_FEATURE_CEC ,@@ -107,6 +111,11 @@ static const struct cros_feature_to_cells cros_subdevices[] = { .mfd_cells = cros_usbpd_charger_cells, .num_cells = ARRAY_SIZE(cros_usbpd_charger_cells), }, + { + .id = EC_FEATURE_HANG_DETECT, + .mfd_cells = cros_ec_wdt_cells, + .num_cells = ARRAY_SIZE(cros_ec_wdt_cells), + }, };static const struct mfd_cell cros_ec_platform_cells[] = {drivers/watchdog/Kconfig +0
-0
drivers/watchdog/Kconfig config KEEMBAY_WATCHDOG · line 2256
Quoted 6 lines
drivers/watchdog/Kconfig +3
-0@@ -2251,4 +2251,19 @@ config KEEMBAY_WATCHDOG To compile this driver as a module, choose M here: the module will be called keembay_wdt. +# +# ChromeOS EC-based Watchdog +#
Drop comment, useless, copies what's below.
drivers/watchdog/Kconfig config KEEMBAY_WATCHDOG · line 2267
Quoted 11 lines
drivers/watchdog/Kconfig +11
-0+ +config CROS_EC_WATCHDOG + tristate "ChromeOS EC-based watchdog driver" + select WATCHDOG_CORE + depends on CROS_EC + help + This is the watchdog driver for ChromeOS devices equipped with EC. + The EC watchdog - when enabled - expects to be kicked within a given + time (default set to 30 seconds) otherwise it will simple reboot + the AP. Priori to that it can also send an event (configurable timeout) + about upcoming reboot.
Instead you could say what will be the name of the module.
drivers/watchdog/Makefile obj-$(CONFIG_MENZ069_WATCHDOG) += menz69_wdt.o · line 238
Quoted 12 lines
drivers/watchdog/Kconfig +1
-0+ endif # WATCHDOGdrivers/watchdog/Makefile +2
-0@@ -234,3 +234,6 @@ obj-$(CONFIG_MENZ069_WATCHDOG) += menz69_wdt.o obj-$(CONFIG_RAVE_SP_WATCHDOG) += rave-sp-wdt.o obj-$(CONFIG_STPMIC1_WATCHDOG) += stpmic1_wdt.o obj-$(CONFIG_SL28CPLD_WATCHDOG) += sl28cpld_wdt.o + +# Cros EC watchdog
Drop comment.
Also, are you sure you placed it in appropriate place, not just at the end of both files?
Quoted 13 lines
drivers/watchdog/Makefile +1
-0+obj-$(CONFIG_CROS_EC_WATCHDOG) += cros_ec_wdt.odrivers/watchdog/cros_ec_wdt.c new file +6
-0@@ -0,0 +1,303 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <linux/slab.h> +#include <linux/err.h> +#include <linux/of_device.h> +#include <linux/kernel.h>
drivers/watchdog/cros_ec_wdt.c line 16
Quoted 10 lines
drivers/watchdog/cros_ec_wdt.c new file +10
-0+#include <linux/module.h> +#include <linux/platform_data/cros_ec_commands.h> +#include <linux/platform_data/cros_ec_proto.h> +#include <linux/platform_device.h> +#include <linux/watchdog.h> +#include <linux/uaccess.h> + +#define CROS_EC_WATCHDOG_DEFAULT_TIME 30/* seconds */ + +#define DEV_NAME "cros-ec-wdt-dev"
Drop unused defines.
Quoted 7 lines
drivers/watchdog/cros_ec_wdt.c new file +7
-0+#define DRV_NAME "cros-ec-wdt-drv" + +static int cros_ec_wdt_ping (struct watchdog_device *wdd); +static int cros_ec_wdt_start (struct watchdog_device *wdd); +static int cros_ec_wdt_stop (struct watchdog_device *wdd); +static int cros_ec_wdt_set_timeout (struct watchdog_device *wdd,unsigned int t); +
...
Quoted 5 lines
drivers/watchdog/cros_ec_wdt.c new file +5
-0+ +static int cros_ec_wdt_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +/* We need to get a reference to cros_ec_devices
drivers/watchdog/cros_ec_wdt.c line 181
Quoted 10 lines
drivers/watchdog/cros_ec_wdt.c new file +10
-0+* (provides communication layer) which is a parent of +* the cros-ec-dev (our parent) +*/ +struct cros_ec_device *cros_ec =dev_get_drvdata (dev->parent->parent); +int ret =0 ; +uint32_t bootstatus; + +if (!cros_ec) { + ret = -ENODEV ; +dev_err_probe (dev, ret,"There is no coresponding EC device!" );
Syntax is return dev_err_probe
Quoted 10 lines
drivers/watchdog/cros_ec_wdt.c new file +10
-0+return ret; + } + + cros_ec_wdd.parent = &pdev->dev; + wd_data.cros_ec = cros_ec; + wd_data.wdd = &cros_ec_wdd; + wd_data.start_on_resume = false; + wd_data.keepalive_on = false; + wd_data.wdd->timeout =CROS_EC_WATCHDOG_DEFAULT_TIME ; +
drivers/watchdog/cros_ec_wdt.c line 201
Quoted 10 lines
drivers/watchdog/cros_ec_wdt.c new file +10
-0+watchdog_stop_on_reboot (&cros_ec_wdd); +watchdog_stop_on_unregister (&cros_ec_wdd); +watchdog_set_drvdata (&cros_ec_wdd, &wd_data); +platform_set_drvdata (pdev, &wd_data); + +/* Get current AP boot status */ + ret =cros_ec_wdt_send_hang_detect (&wd_data,EC_HANG_DETECT_CMD_GET_STATUS ,0 , + &bootstatus); +if (ret <0 ) { +dev_err_probe (dev, ret,"Couldn't get AP boot status from EC" );
Syntax is return dev_err_probe
Quoted 4 lines
drivers/watchdog/cros_ec_wdt.c new file +4
-0+return ret; + } + +/*
drivers/watchdog/cros_ec_wdt.c line 215
Quoted 10 lines
drivers/watchdog/cros_ec_wdt.c new file +10
-0+* If bootstatus is not EC_HANG_DETECT_AP_BOOT_NORMAL +* it mens EC has rebooted the AP due to watchdog timeout. +* Lets translate it to watchdog core status code. +*/ +if (bootstatus !=EC_HANG_DETECT_AP_BOOT_NORMAL ) + wd_data.wdd->bootstatus =WDIOF_CARDRESET ; + + ret =watchdog_register_device (&cros_ec_wdd); +if (ret <0 ) +dev_err_probe (dev, ret,"Couldn't get AP boot status from EC" );
Syntax is return dev_err_probe
drivers/watchdog/cros_ec_wdt.c
Quoted 2 lines
drivers/watchdog/cros_ec_wdt.c new file +2
-0+ +return ret;
return 0
Quoted 47 lines
drivers/watchdog/cros_ec_wdt.c new file +47
-0+} + +static int cros_ec_wdt_remove (struct platform_device *pdev) +{ +struct cros_ec_wdt_data *wd_data =platform_get_drvdata (pdev); + +watchdog_unregister_device (wd_data->wdd); + +return 0 ; +} + +static void cros_ec_wdt_shutdown (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct cros_ec_wdt_data *wd_data =platform_get_drvdata (pdev); +int ret; + +/* +* Clean only bootstatus flag. +* EC wdt is are already stopped by watchdog framework. +*/ + ret =cros_ec_wdt_send_hang_detect (wd_data, +EC_HANG_DETECT_CMD_CLEAR_STATUS ,0 ,NULL ); +if (ret <0 ) +dev_err (dev,"%s failed (%d)" , __func__, ret); + +watchdog_unregister_device (wd_data->wdd); +} + +static int __maybe_unused cros_ec_wdt_suspend (struct platform_device *pdev,pm_message_t state) +{ +struct device *dev = &pdev->dev; +struct cros_ec_wdt_data *wd_data =platform_get_drvdata (pdev); +int ret; + +if (watchdog_active (wd_data->wdd)) { + ret =cros_ec_wdt_send_hang_detect (wd_data, +EC_HANG_DETECT_CMD_CANCEL ,0 ,NULL ); +if (ret <0 ) +dev_err (dev,"%s failed (%d)" , __func__, ret); + wd_data->start_on_resume = true; + } + +return 0 ; +} + +static int __maybe_unused cros_ec_wdt_resume (struct platform_device *pdev)
drivers/watchdog/cros_ec_wdt.c line 274
Quoted 10 lines
drivers/watchdog/cros_ec_wdt.c new file +10
-0+{ +struct device *dev = &pdev->dev; +struct cros_ec_wdt_data *wd_data =platform_get_drvdata (pdev); +int ret; + +/* start_on_resume is only set if watchdog was active +* when device was going to sleep +*/ +if (wd_data->start_on_resume) { +/* On resume we just need to setup a EC watchdog the same way as
Use comment style from Linux coding style.
drivers/watchdog/cros_ec_wdt.c line 280
Quoted 6 lines
drivers/watchdog/cros_ec_wdt.c new file +6
-0+* in cros_ec_wdt_start(). When userspace resumes from suspend +* the watchdog app should just start petting the watchdog again. +*/ + ret =cros_ec_wdt_start (wd_data->wdd); +if (ret <0 ) +dev_err (dev,"%s failed (%d)" , __func__, ret);
That's not really helpful. This applies everywhere. You have all over the place debugging prints with __func__. This is not useful pattern. Print something useful, not function name.
Quoted 11 lines
drivers/watchdog/cros_ec_wdt.c new file +11
-0+ + wd_data->start_on_resume = false; + } + +return 0 ; +} + +static struct platform_driver cros_ec_wdt_driver = { + .probe = cros_ec_wdt_probe, + .remove = cros_ec_wdt_remove, + .shutdown = cros_ec_wdt_shutdown,
drivers/watchdog/cros_ec_wdt.c line 301
Quoted 10 lines
drivers/watchdog/cros_ec_wdt.c new file +10
-0+ .suspend = pm_ptr(cros_ec_wdt_suspend), + .resume = pm_ptr(cros_ec_wdt_resume), + .driver = { + .name = DRV_NAME, + }, +}; + +module_platform_driver (cros_ec_wdt_driver); + +MODULE_ALIAS ("platform:" DRV_NAME );
You should not need MODULE_ALIAS() in normal cases. If you need it, usually it means your device ID table is wrong (e.g. misses either entries or MODULE_DEVICE_TABLE()). MODULE_ALIAS() is not a substitute for incomplete ID table.
include/linux/platform_data/cros_ec_commands.h struct ec_response_i2c_passthru { · line 3964
Quoted 13 lines
drivers/watchdog/cros_ec_wdt.c new file +2
-0+MODULE_DESCRIPTION ("Cros EC Watchdog Device Driver" ); +MODULE_LICENSE ("GPL" );include/linux/platform_data/cros_ec_commands.h +1
-2@@ -3961,60 +3961,50 @@ struct ec_response_i2c_passthru { } __ec_align1;/*****************************************************************************/ -/* Power button hang detect */ - +/* AP hang detect */
I don't understand how this change is related to the new driver. This entire hunk is confusing.
Best regards,
Krzysztof
Łukasz Majczak
maintainerHi Krzysztof,
Please find the answers below.
Quoted 68 lines · Krzysztof Kozlowski
Quoted 66 lines · Lukasz Majczak
This adds EC-based watchdog support for ChromeOS based devices equipped with embedded controller (EC).
Signed-off-by Lukasz Majczak <[email protected]>--- MAINTAINERS | 6 + drivers/mfd/cros_ec_dev.c | 9 + drivers/watchdog/Kconfig | 15 + drivers/watchdog/Makefile | 3 + drivers/watchdog/cros_ec_wdt.c | 303 ++++++++++++++++++ .../linux/platform_data/cros_ec_commands.h | 78 ++--- 6 files changed, 370 insertions(+), 44 deletions(-) create mode 100644 drivers/watchdog/cros_ec_wdt.cMAINTAINERS +6
-0@@ -4952,6 +4952,12 @@ R: Sami Kyöstilä <[email protected]> S: Maintained F: drivers/platform/chrome/cros_hps_i2c.c +CHROMEOS EC WATCHDOG +M: Lukasz Majczak <[email protected]> +L: [email protected] +S: Maintained +F: drivers/watchdog/cros_ec_wdt.c + CHRONTEL CH7322 CEC DRIVER M: Joe Tessler <[email protected]> L: [email protected]drivers/mfd/cros_ec_dev.c +9
-0@@ -91,6 +91,10 @@ static const struct mfd_cell cros_usbpd_notify_cells[] = { { .name = "cros-usbpd-notify", }, }; +static const struct mfd_cell cros_ec_wdt_cells[] = { + { .name ="cros-ec-wdt-drv" , } +}; +static const struct cros_feature_to_cells cros_subdevices[] = { { .id =EC_FEATURE_CEC ,@@ -107,6 +111,11 @@ static const struct cros_feature_to_cells cros_subdevices[] = { .mfd_cells = cros_usbpd_charger_cells, .num_cells = ARRAY_SIZE(cros_usbpd_charger_cells), }, + { + .id = EC_FEATURE_HANG_DETECT, + .mfd_cells = cros_ec_wdt_cells, + .num_cells = ARRAY_SIZE(cros_ec_wdt_cells), + }, };static const struct mfd_cell cros_ec_platform_cells[] = {drivers/watchdog/Kconfig +0
-0@@ -2251,4 +2251,19 @@ config KEEMBAY_WATCHDOG To compile this driver as a module, choose M here: the module will be called keembay_wdt.
Quoted 5 lines
drivers/watchdog/Kconfig config KEEMBAY_WATCHDOG · line 2256
Quoted 3 lines
drivers/watchdog/Kconfig +3
-0+# +# ChromeOS EC-based Watchdog +#Drop comment, useless, copies what's below.
ACK
Quoted 15 lines
drivers/watchdog/Kconfig config KEEMBAY_WATCHDOG · line 2267
Quoted 12 lines
drivers/watchdog/Kconfig +11
-0+ +config CROS_EC_WATCHDOG + tristate "ChromeOS EC-based watchdog driver" + select WATCHDOG_CORE + depends on CROS_EC + help + This is the watchdog driver for ChromeOS devices equipped with EC. + The EC watchdog - when enabled - expects to be kicked within a given + time (default set to 30 seconds) otherwise it will simple reboot + the AP. Priori to that it can also send an event (configurable timeout) + about upcoming reboot.Instead you could say what will be the name of the module.
ACK
Quoted 15 lines
drivers/watchdog/Makefile obj-$(CONFIG_MENZ069_WATCHDOG) += menz69_wdt.o · line 238
Quoted 12 lines
drivers/watchdog/Kconfig +1
-0+ endif # WATCHDOGdrivers/watchdog/Makefile +2
-0@@ -234,3 +234,6 @@ obj-$(CONFIG_MENZ069_WATCHDOG) += menz69_wdt.o obj-$(CONFIG_RAVE_SP_WATCHDOG) += rave-sp-wdt.o obj-$(CONFIG_STPMIC1_WATCHDOG) += stpmic1_wdt.o obj-$(CONFIG_SL28CPLD_WATCHDOG) += sl28cpld_wdt.o + +# Cros EC watchdogDrop comment.
Quoted 3 lines
Also, are you sure you placed it in appropriate place, not just at the end of both files?
ACK, I will find a better place for above (both in Makefile and Kconfig) and will try to keep alphabetic order.
Quoted 17 lines
Quoted 17 lines
drivers/watchdog/Makefile +1
-0+obj-$(CONFIG_CROS_EC_WATCHDOG) += cros_ec_wdt.odrivers/watchdog/cros_ec_wdt.c new file +10
-0@@ -0,0 +1,303 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <linux/slab.h> +#include <linux/err.h> +#include <linux/of_device.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/platform_data/cros_ec_commands.h> +#include <linux/platform_data/cros_ec_proto.h> +#include <linux/platform_device.h>
Quoted 8 lines
drivers/watchdog/cros_ec_wdt.c line 16
Quoted 6 lines
drivers/watchdog/cros_ec_wdt.c new file +6
-0+#include <linux/watchdog.h> +#include <linux/uaccess.h> + +#define CROS_EC_WATCHDOG_DEFAULT_TIME 30/* seconds */ + +#define DEV_NAME "cros-ec-wdt-dev"Drop unused defines.
ACK
Quoted 20 lines
Quoted 8 lines
drivers/watchdog/cros_ec_wdt.c new file +7
-0+#define DRV_NAME "cros-ec-wdt-drv" + +static int cros_ec_wdt_ping (struct watchdog_device *wdd); +static int cros_ec_wdt_start (struct watchdog_device *wdd); +static int cros_ec_wdt_stop (struct watchdog_device *wdd); +static int cros_ec_wdt_set_timeout (struct watchdog_device *wdd,unsigned int t); +...
Quoted 9 lines
drivers/watchdog/cros_ec_wdt.c new file +9
-0+ +static int cros_ec_wdt_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +/* We need to get a reference to cros_ec_devices +* (provides communication layer) which is a parent of +* the cros-ec-dev (our parent) +*/ +struct cros_ec_device *cros_ec =dev_get_drvdata (dev->parent->parent);
Quoted 9 lines
drivers/watchdog/cros_ec_wdt.c line 181
Quoted 6 lines
drivers/watchdog/cros_ec_wdt.c new file +6
-0+int ret =0 ; +uint32_t bootstatus; + +if (!cros_ec) { + ret = -ENODEV ; +dev_err_probe (dev, ret,"There is no coresponding EC device!" );Syntax is return
dev_err_probe
ACK
Quoted 14 lines
Quoted 14 lines
drivers/watchdog/cros_ec_wdt.c new file +14
-0+return ret; + } + + cros_ec_wdd.parent = &pdev->dev; + wd_data.cros_ec = cros_ec; + wd_data.wdd = &cros_ec_wdd; + wd_data.start_on_resume = false; + wd_data.keepalive_on = false; + wd_data.wdd->timeout =CROS_EC_WATCHDOG_DEFAULT_TIME ; + +watchdog_stop_on_reboot (&cros_ec_wdd); +watchdog_stop_on_unregister (&cros_ec_wdd); +watchdog_set_drvdata (&cros_ec_wdd, &wd_data); +platform_set_drvdata (pdev, &wd_data);
Quoted 8 lines
drivers/watchdog/cros_ec_wdt.c line 201
Quoted 6 lines
drivers/watchdog/cros_ec_wdt.c new file +6
-0+ +/* Get current AP boot status */ + ret =cros_ec_wdt_send_hang_detect (&wd_data,EC_HANG_DETECT_CMD_GET_STATUS ,0 , + &bootstatus); +if (ret <0 ) { +dev_err_probe (dev, ret,"Couldn't get AP boot status from EC" );Syntax is return
dev_err_probe
ACK
Quoted 18 lines
Quoted 5 lines
drivers/watchdog/cros_ec_wdt.c new file +4
-0+return ret; + } + +/* drivers/watchdog/cros_ec_wdt.c line 215
Quoted 10 lines
drivers/watchdog/cros_ec_wdt.c new file +10
-0+* If bootstatus is not EC_HANG_DETECT_AP_BOOT_NORMAL +* it mens EC has rebooted the AP due to watchdog timeout. +* Lets translate it to watchdog core status code. +*/ +if (bootstatus !=EC_HANG_DETECT_AP_BOOT_NORMAL ) + wd_data.wdd->bootstatus =WDIOF_CARDRESET ; + + ret =watchdog_register_device (&cros_ec_wdd); +if (ret <0 ) +dev_err_probe (dev, ret,"Couldn't get AP boot status from EC" );Syntax is return
dev_err_probe
ACK
Quoted 5 lines
drivers/watchdog/cros_ec_wdt.c
Quoted 2 lines
drivers/watchdog/cros_ec_wdt.c new file +2
-0+ +return ret;return 0
ACK
Quoted 51 lines
Quoted 51 lines
drivers/watchdog/cros_ec_wdt.c new file +51
-0+} + +static int cros_ec_wdt_remove (struct platform_device *pdev) +{ +struct cros_ec_wdt_data *wd_data =platform_get_drvdata (pdev); + +watchdog_unregister_device (wd_data->wdd); + +return 0 ; +} + +static void cros_ec_wdt_shutdown (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct cros_ec_wdt_data *wd_data =platform_get_drvdata (pdev); +int ret; + +/* +* Clean only bootstatus flag. +* EC wdt is are already stopped by watchdog framework. +*/ + ret =cros_ec_wdt_send_hang_detect (wd_data, +EC_HANG_DETECT_CMD_CLEAR_STATUS ,0 ,NULL ); +if (ret <0 ) +dev_err (dev,"%s failed (%d)" , __func__, ret); + +watchdog_unregister_device (wd_data->wdd); +} + +static int __maybe_unused cros_ec_wdt_suspend (struct platform_device *pdev,pm_message_t state) +{ +struct device *dev = &pdev->dev; +struct cros_ec_wdt_data *wd_data =platform_get_drvdata (pdev); +int ret; + +if (watchdog_active (wd_data->wdd)) { + ret =cros_ec_wdt_send_hang_detect (wd_data, +EC_HANG_DETECT_CMD_CANCEL ,0 ,NULL ); +if (ret <0 ) +dev_err (dev,"%s failed (%d)" , __func__, ret); + wd_data->start_on_resume = true; + } + +return 0 ; +} + +static int __maybe_unused cros_ec_wdt_resume (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct cros_ec_wdt_data *wd_data =platform_get_drvdata (pdev); +int ret;
Quoted 9 lines
drivers/watchdog/cros_ec_wdt.c line 274
Quoted 6 lines
drivers/watchdog/cros_ec_wdt.c new file +6
-0+ +/* start_on_resume is only set if watchdog was active +* when device was going to sleep +*/ +if (wd_data->start_on_resume) { +/* On resume we just need to setup a EC watchdog the same way as Use comment style from Linux coding style.
ACK
Quoted 11 lines
drivers/watchdog/cros_ec_wdt.c line 280
Quoted 6 lines
drivers/watchdog/cros_ec_wdt.c new file +6
-0+* in cros_ec_wdt_start(). When userspace resumes from suspend +* the watchdog app should just start petting the watchdog again. +*/ + ret =cros_ec_wdt_start (wd_data->wdd); +if (ret <0 ) +dev_err (dev,"%s failed (%d)" , __func__, ret);That's not really helpful. This applies everywhere. You have all over the place debugging prints with
__func__. This is not useful pattern. Print something useful, not function name.
ACK, I will revisit the logs messages (both the meanings and log levels)
Quoted 18 lines
Quoted 18 lines
drivers/watchdog/cros_ec_wdt.c new file +18
-0+ + wd_data->start_on_resume = false; + } + +return 0 ; +} + +static struct platform_driver cros_ec_wdt_driver = { + .probe = cros_ec_wdt_probe, + .remove = cros_ec_wdt_remove, + .shutdown = cros_ec_wdt_shutdown, + .suspend =pm_ptr (cros_ec_wdt_suspend), + .resume =pm_ptr (cros_ec_wdt_resume), + .driver = { + .name =DRV_NAME , + }, +}; +
Quoted 10 lines
drivers/watchdog/cros_ec_wdt.c line 301
Quoted 3 lines
drivers/watchdog/cros_ec_wdt.c new file +3
-0+module_platform_driver (cros_ec_wdt_driver); + +MODULE_ALIAS ("platform:" DRV_NAME );You should not need
MODULE_ALIAS()in normal cases. If you need it, usually it means your device ID table is wrong (e.g. misses either entries orMODULE_DEVICE_TABLE()).MODULE_ALIAS()is not a substitute for incomplete ID table.
ACK, I will use MODULE_DEVICE_TABLE().
Quoted 9 lines
Quoted 9 lines
drivers/watchdog/cros_ec_wdt.c new file +2
-0+MODULE_DESCRIPTION ("Cros EC Watchdog Device Driver" ); +MODULE_LICENSE ("GPL" );include/linux/platform_data/cros_ec_commands.h +0
-0@@ -3961,60 +3961,50 @@ struct ec_response_i2c_passthru { } __ec_align1;
Quoted 8 lines
include/linux/platform_data/cros_ec_commands.h struct ec_response_i2c_passthru { · line 3964
Quoted 4 lines
include/linux/platform_data/cros_ec_commands.h +1
-2/*****************************************************************************/ -/* Power button hang detect */ - +/* AP hang detect */ I don't understand how this change is related to the new driver. This entire hunk is confusing.
Yes, that updates the API and definition for embedded controller (EC). It should go in the separate patch.
Quoted 4 lines
Best regards,
Krzysztof
Best regards,
Lukasz
On 17/01/2024 11:24, Lukasz Majczak wrote:
Few more nits:
Quoted 1 line
This adds EC-based watchdog support for ChromeOS
Please do not use "This commit/patch/change", but imperative mood. See longer explanation here:
https://elixir.bootlin.com/linux/v5.17.1/source/Documentation/process/submitting-patches.rst#L95
Quoted 2 lines
based devices equipped with embedded controller (EC).
Please use subject prefixes matching the subsystem. You can get them for example with git log --oneline -- DIRECTORY_OR_FILE on the directory your patch is touching.
And not a nit - important:
Please use scripts/get_maintainers.pl to get a list of necessary people and lists to CC (and consider --no-git-fallback argument). It might happen, that command when run on an older kernel, gives you outdated entries. Therefore please be sure you base your patches on recent Linux kernel.
Tools are doing it automatically, so either you work on some ancient tree (don't), on fork of kernel (don't) or ignore some maintainers (really don't).
Best regards,
Krzysztof
Guenter Roeck
maintainerQuoted 4 lines · Lukasz Majczak
This adds EC-based watchdog support for ChromeOS based devices equipped with embedded controller (EC).
Signed-off-by Lukasz Majczak <[email protected]>
checkpatch --strict says:
total: 0 errors, 0 warnings, 14 checks, 455 lines checked
Please fix.
Quoted 44 lines
--- MAINTAINERS | 6 + drivers/mfd/cros_ec_dev.c | 9 + drivers/watchdog/Kconfig | 15 + drivers/watchdog/Makefile | 3 + drivers/watchdog/cros_ec_wdt.c | 303 ++++++++++++++++++ .../linux/platform_data/cros_ec_commands.h | 78 ++--- 6 files changed, 370 insertions(+), 44 deletions(-)create mode 100644
drivers/watchdog/cros_ec_wdt.cMAINTAINERS +6
-0@@ -4952,6 +4952,12 @@ R: Sami Kyöstilä <[email protected]> S: Maintained F: drivers/platform/chrome/cros_hps_i2c.c +CHROMEOS EC WATCHDOG +M: Lukasz Majczak <[email protected]> +L: [email protected] +S: Maintained +F: drivers/watchdog/cros_ec_wdt.c + CHRONTEL CH7322 CEC DRIVER M: Joe Tessler <[email protected]> L: [email protected]drivers/mfd/cros_ec_dev.c +4
-0@@ -91,6 +91,10 @@ static const struct mfd_cell cros_usbpd_notify_cells[] = { { .name = "cros-usbpd-notify", }, }; +static const struct mfd_cell cros_ec_wdt_cells[] = { + { .name ="cros-ec-wdt-drv" , } +}; +static const struct cros_feature_to_cells cros_subdevices[] = { { .id =EC_FEATURE_CEC ,@@ -107,6 +111,11 @@ static const struct cros_feature_to_cells cros_subdevices[] = { .mfd_cells = cros_usbpd_charger_cells,
drivers/mfd/cros_ec_dev.c static const struct cros_feature_to_cells cros_subdevices[] = { · line 121
Quoted 10 lines
drivers/mfd/cros_ec_dev.c +5
-0.num_cells = ARRAY_SIZE(cros_usbpd_charger_cells), }, + { + .id = EC_FEATURE_HANG_DETECT, + .mfd_cells = cros_ec_wdt_cells, + .num_cells = ARRAY_SIZE(cros_ec_wdt_cells), + }, };static const struct mfd_cell cros_ec_platform_cells[] = {
The above should be a separate patch.
drivers/watchdog/Kconfig config KEEMBAY_WATCHDOG · line 2256
Quoted 11 lines
drivers/watchdog/Kconfig +3
-0@@ -2251,4 +2251,19 @@ config KEEMBAY_WATCHDOG To compile this driver as a module, choose M here: the module will be called keembay_wdt. +# +# ChromeOS EC-based Watchdog +#
Pointless comment.
drivers/watchdog/Kconfig config KEEMBAY_WATCHDOG · line 2268
Quoted 12 lines
drivers/watchdog/Kconfig +12
-0+ +config CROS_EC_WATCHDOG + tristate "ChromeOS EC-based watchdog driver" + select WATCHDOG_CORE + depends on CROS_EC + help + This is the watchdog driver for ChromeOS devices equipped with EC. + The EC watchdog - when enabled - expects to be kicked within a given + time (default set to 30 seconds) otherwise it will simple reboot + the AP. Priori to that it can also send an event (configurable timeout) + about upcoming reboot. +
In other words, it is a watchdog driver. I don't think it adds value to describe how a watchdog works here, nor to describe what other (unused) functionality the hardware may have.
Also, please try to insert in alphabetic order.
drivers/watchdog/Makefile obj-$(CONFIG_MENZ069_WATCHDOG) += menz69_wdt.o · line 238
Quoted 11 lines
drivers/watchdog/Kconfig +0
-0endif # WATCHDOGdrivers/watchdog/Makefile +2
-0@@ -234,3 +234,6 @@ obj-$(CONFIG_MENZ069_WATCHDOG) += menz69_wdt.o obj-$(CONFIG_RAVE_SP_WATCHDOG) += rave-sp-wdt.o obj-$(CONFIG_STPMIC1_WATCHDOG) += stpmic1_wdt.o obj-$(CONFIG_SL28CPLD_WATCHDOG) += sl28cpld_wdt.o + +# Cros EC watchdog
We don't add individual comments for each watchdog, and we should not start doing so. Also, please try to insert in alphabetic order.
Quoted 9 lines
drivers/watchdog/Makefile +1
-0+obj-$(CONFIG_CROS_EC_WATCHDOG) += cros_ec_wdt.odrivers/watchdog/cros_ec_wdt.c new file +2
-0@@ -0,0 +1,303 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +
drivers/watchdog/cros_ec_wdt.c line 12
Quoted 10 lines
drivers/watchdog/cros_ec_wdt.c new file +10
-0+#include <linux/slab.h> +#include <linux/err.h> +#include <linux/of_device.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/platform_data/cros_ec_commands.h> +#include <linux/platform_data/cros_ec_proto.h> +#include <linux/platform_device.h> +#include <linux/watchdog.h> +#include <linux/uaccess.h>
Alphabetic include file order, please. Also, I don't immediately see where uaccess.h or of_device.h are used. Please drop unused includes.
drivers/watchdog/cros_ec_wdt.c line 17
Quoted 5 lines
drivers/watchdog/cros_ec_wdt.c new file +5
-0+ +#define CROS_EC_WATCHDOG_DEFAULT_TIME 30/* seconds */ + +#define DEV_NAME "cros-ec-wdt-dev" +#define DRV_NAME "cros-ec-wdt-drv"
One of those is unused.
drivers/watchdog/cros_ec_wdt.c line 23
Quoted 6 lines
drivers/watchdog/cros_ec_wdt.c new file +6
-0+ +static int cros_ec_wdt_ping (struct watchdog_device *wdd); +static int cros_ec_wdt_start (struct watchdog_device *wdd); +static int cros_ec_wdt_stop (struct watchdog_device *wdd); +static int cros_ec_wdt_set_timeout (struct watchdog_device *wdd,unsigned int t); +
Please rearrange to avoid forward declarations.
drivers/watchdog/cros_ec_wdt.c line 30
Quoted 7 lines
drivers/watchdog/cros_ec_wdt.c new file +7
-0+struct cros_ec_wdt_data { +bool start_on_resume; +bool keepalive_on; +struct cros_ec_device *cros_ec; +struct watchdog_device *wdd; +}; +static struct cros_ec_wdt_data wd_data;
Please allocate and avoid static variables.
Quoted 10 lines
drivers/watchdog/cros_ec_wdt.c new file +10
-0+ +static const struct watchdog_info cros_ec_wdt_ident = { + .options =WDIOF_SETTIMEOUT |WDIOF_KEEPALIVEPING |WDIOF_MAGICCLOSE , + .firmware_version =0 , + .identity =DRV_NAME , +}; + +static const struct watchdog_ops cros_ec_wdt_ops = { + .owner =THIS_MODULE , + .ping = cros_ec_wdt_ping,
drivers/watchdog/cros_ec_wdt.c line 50
Quoted 10 lines
drivers/watchdog/cros_ec_wdt.c new file +10
-0+ .start = cros_ec_wdt_start, + .stop = cros_ec_wdt_stop, + .set_timeout = cros_ec_wdt_set_timeout, +}; + +static struct watchdog_device cros_ec_wdd = { + .info = &cros_ec_wdt_ident, + .ops = &cros_ec_wdt_ops, + .timeout =CROS_EC_WATCHDOG_DEFAULT_TIME , + .bootstatus =EC_HANG_DETECT_AP_BOOT_NORMAL
Consider allocating and embedding in struct cros_ec_wdt_data. .timeout and .bootstatus are overwritten anyway, and it does not make sense to initialize those elements here.
drivers/watchdog/cros_ec_wdt.c line 53
Quoted 3 lines
drivers/watchdog/cros_ec_wdt.c new file +3
-0+}; + +static int cros_ec_wdt_send_hang_detect(struct cros_ec_wdt_data *wd_data,
Seems to me that cros_ec_wdt_send_cmd or similar would be a better function name, but your call.
Quoted 20 lines
drivers/watchdog/cros_ec_wdt.c new file +20
-0+uint16_t command, + uint16_t reboot_timeout_sec, + uint32_t *status) +{ + int ret; + + struct { + struct cros_ec_command msg; + union { + struct ec_params_hang_detect req; + struct ec_response_hang_detect resp; + }; + } __packed buf = { + .msg = { + .version = 0, + .command = EC_CMD_HANG_DETECT, + .insize = (command == EC_HANG_DETECT_CMD_GET_STATUS) ? + sizeof(struct ec_response_hang_detect) : + 0, + .outsize = sizeof(struct ec_params_hang_detect),
drivers/watchdog/cros_ec_wdt.c line 83
Quoted 10 lines
drivers/watchdog/cros_ec_wdt.c new file +10
-0+ }, + .req = { + .command = command, + .reboot_timeout_sec = reboot_timeout_sec, + } + }; + + ret =cros_ec_cmd_xfer_status (wd_data->cros_ec, &buf.msg); +if (ret <0 ) { + dev_warn(wd_data->wdd->parent,
Given that wdd is needed anyway,
drivers/watchdog/cros_ec_wdt.c line 85
Quoted 2 lines
drivers/watchdog/cros_ec_wdt.c new file +2
-0+"cros_ec_cmd_xfer_status failed(%d) command (%04x) reboot_timeout_sec(%ds)" , + ret, command, reboot_timeout_sec);
That message, if ever seen, does not make much sense if the command was one that does not set the timeout. On top of that, this code dumps a warning, and the calling code dumps an error message. Is the EC really that fragile that it is necessary to dump all those error messages ?
If not, please consider replacing most if not all of those log messages with dev_dbg().
drivers/watchdog/cros_ec_wdt.c line 89
Quoted 4 lines
drivers/watchdog/cros_ec_wdt.c new file +4
-0+return ret; + } + +if (status && (command ==EC_HANG_DETECT_CMD_GET_STATUS )) {
Unnecessary (). Besides, it doesn't make much sense. Why provide a status pointer but only use it if the command is a specific one ?
drivers/watchdog/cros_ec_wdt.c line 92
Quoted 3 lines
drivers/watchdog/cros_ec_wdt.c new file +3
-0+ *status = buf.resp.status; +dev_info (wd_data->wdd->parent,"EC Watchdog boot status (%d)" , + buf.resp.status);
That message does not belong here.
Quoted 4 lines
drivers/watchdog/cros_ec_wdt.c new file +4
-0+ } + +return 0 ; +}
drivers/watchdog/cros_ec_wdt.c line 106
Quoted 10 lines
drivers/watchdog/cros_ec_wdt.c new file +10
-0+ +static int cros_ec_wdt_ping (struct watchdog_device *wdd) +{ +struct cros_ec_wdt_data *wd_data =watchdog_get_drvdata (wdd); +int ret; + + ret =cros_ec_wdt_send_hang_detect (wd_data,EC_HANG_DETECT_CMD_RELOAD , +0 ,NULL ); +if (ret <0 ) +dev_err (wdd->parent,"%s failed (%d)" , __func__, ret);
return here and drop the else.
Nore that this driver is extremely noisy. If the EC for some reason doesn't respond as expected the error messages will drown all other kernel messages. I really do not see the point of this.
drivers/watchdog/cros_ec_wdt.c line 108
Quoted 2 lines
drivers/watchdog/cros_ec_wdt.c new file +2
-0+else + wd_data->keepalive_on = true;
This is odd and needs a detailed explanation. More on that see below.
Quoted 19 lines
drivers/watchdog/cros_ec_wdt.c new file +19
-0+ +return ret; +} + +static int cros_ec_wdt_start (struct watchdog_device *wdd) +{ +struct cros_ec_wdt_data *wd_data =watchdog_get_drvdata (wdd); +int ret =0 ; + +/* Prepare watchdog on EC side */ + ret =cros_ec_wdt_send_hang_detect (wd_data, +EC_HANG_DETECT_CMD_SET_TIMEOUT , + wdd->timeout, +NULL ); +if (ret <0 ) +dev_err (wdd->parent,"%s failed (%d)" , __func__, ret); + +return ret; +}
drivers/watchdog/cros_ec_wdt.c line 137
Quoted 10 lines
drivers/watchdog/cros_ec_wdt.c new file +10
-0+ +static int cros_ec_wdt_stop (struct watchdog_device *wdd) +{ +struct cros_ec_wdt_data *wd_data =watchdog_get_drvdata (wdd); +int ret =0 ; + +if (wd_data->keepalive_on) { + wd_data->keepalive_on = false; + ret =cros_ec_wdt_send_hang_detect (wd_data,EC_HANG_DETECT_CMD_CANCEL , +0 ,NULL );
This needs explanation. Why is it only needed here after the first ping is sent, but on suspend it is unconditional ? In other words, why does the watchdog behave differently after the first ping ? Why does the watchdog not have to be stopped if it never received a ping ? Logically that seems odd, if not plain wrong. The watchdog should behave exactly the same after it was started, no matter if it ever received a ping or not.
Quoted 7 lines
drivers/watchdog/cros_ec_wdt.c new file +7
-0+if (ret <0 ) +dev_err (wdd->parent,"%s failed (%d)" , __func__, ret); + } + +return ret; +} +
drivers/watchdog/cros_ec_wdt.c line 154
Quoted 10 lines
drivers/watchdog/cros_ec_wdt.c new file +10
-0+static int cros_ec_wdt_set_timeout (struct watchdog_device *wdd,unsigned int t) +{ +struct cros_ec_wdt_data *wd_data =watchdog_get_drvdata (wdd); +int ret; + +if (t <EC_HANG_DETECT_MIN_TIMEOUT ) { +dev_err (wdd->parent, +"%s failed, requested timeout is lower than min(%d < %d)" , + __func__, t,EC_HANG_DETECT_MIN_TIMEOUT ); +return -EINVAL ;
This should be handled in the watchdog core. If it isn't the driver is misconfigured.
drivers/watchdog/cros_ec_wdt.c line 161
Quoted 7 lines
drivers/watchdog/cros_ec_wdt.c new file +7
-0+ } + + ret =cros_ec_wdt_send_hang_detect (wd_data, +EC_HANG_DETECT_CMD_SET_TIMEOUT , + t,NULL ); +if (ret <0 ) +dev_err (wdd->parent,"%s failed (%d)" , __func__, ret);
return here.
Quoted 4 lines
drivers/watchdog/cros_ec_wdt.c new file +4
-0+else + wdd->timeout = t; + +return ret;
drivers/watchdog/cros_ec_wdt.c line 175
Quoted 10 lines
drivers/watchdog/cros_ec_wdt.c new file +10
-0+} + +static int cros_ec_wdt_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +/* We need to get a reference to cros_ec_devices +* (provides communication layer) which is a parent of +* the cros-ec-dev (our parent) +*/ +struct cros_ec_device *cros_ec =dev_get_drvdata (dev->parent->parent);
Other cros drivers get struct cros_ec_dev from dev->parent and then use ec->ec_dev. Please explain why you don't use the same pattern; dereferencing parent->parent and assuming to know its driver data seems to be (much) more risky than the existing pattern.
Also, the comment seems obvious. None of the other cros_ec drivers needed it, and I don't see why it would add value here.
drivers/watchdog/cros_ec_wdt.c line 182
Quoted 7 lines
drivers/watchdog/cros_ec_wdt.c new file +7
-0+int ret =0 ; +uint32_t bootstatus; + +if (!cros_ec) { + ret = -ENODEV ; +dev_err_probe (dev, ret,"There is no coresponding EC device!" ); +return ret;
return dev_err_probe(). Same elsewhere.
drivers/watchdog/cros_ec_wdt.c line 190
Quoted 8 lines
drivers/watchdog/cros_ec_wdt.c new file +8
-0+ } + + cros_ec_wdd.parent = &pdev->dev; + wd_data.cros_ec = cros_ec; + wd_data.wdd = &cros_ec_wdd; + wd_data.start_on_resume = false; + wd_data.keepalive_on = false; + wd_data.wdd->timeout =CROS_EC_WATCHDOG_DEFAULT_TIME ;
Ah, I guess the reason for the error handling when setting the timeout is the lack of setting boundaries here. That is wrong. min_timeout and max_timeout need to be set.
Quoted 7 lines
drivers/watchdog/cros_ec_wdt.c new file +7
-0+ +watchdog_stop_on_reboot (&cros_ec_wdd); +watchdog_stop_on_unregister (&cros_ec_wdd); +watchdog_set_drvdata (&cros_ec_wdd, &wd_data); +platform_set_drvdata (pdev, &wd_data); + +/* Get current AP boot status */
drivers/watchdog/cros_ec_wdt.c line 207
Quoted 10 lines
drivers/watchdog/cros_ec_wdt.c new file +10
-0+ ret =cros_ec_wdt_send_hang_detect (&wd_data,EC_HANG_DETECT_CMD_GET_STATUS ,0 , + &bootstatus); +if (ret <0 ) { +dev_err_probe (dev, ret,"Couldn't get AP boot status from EC" ); +return ret; + } + +/* +* If bootstatus is not EC_HANG_DETECT_AP_BOOT_NORMAL +* it mens EC has rebooted the AP due to watchdog timeout.
means
drivers/watchdog/cros_ec_wdt.c line 215
Quoted 8 lines
drivers/watchdog/cros_ec_wdt.c new file +8
-0+* Lets translate it to watchdog core status code. +*/ +if (bootstatus !=EC_HANG_DETECT_AP_BOOT_NORMAL ) + wd_data.wdd->bootstatus =WDIOF_CARDRESET ; + + ret =watchdog_register_device (&cros_ec_wdd); +if (ret <0 ) +dev_err_probe (dev, ret,"Couldn't get AP boot status from EC" );
Wrong error message.
drivers/watchdog/cros_ec_wdt.c line 224
Quoted 9 lines
drivers/watchdog/cros_ec_wdt.c new file +9
-0+ +return ret; +} + +static int cros_ec_wdt_remove (struct platform_device *pdev) +{ +struct cros_ec_wdt_data *wd_data =platform_get_drvdata (pdev); + +watchdog_unregister_device (wd_data->wdd);
Why not use devm_watchdog_register_device() ? Please explain.
Quoted 4 lines
drivers/watchdog/cros_ec_wdt.c new file +4
-0+ +return 0 ; +} +
drivers/watchdog/cros_ec_wdt.c line 238
Quoted 10 lines
drivers/watchdog/cros_ec_wdt.c new file +10
-0+static void cros_ec_wdt_shutdown (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct cros_ec_wdt_data *wd_data =platform_get_drvdata (pdev); +int ret; + +/* +* Clean only bootstatus flag. +* EC wdt is are already stopped by watchdog framework. +*/
Why is this necessary if the watchdog is stopped ?
drivers/watchdog/cros_ec_wdt.c line 244
Quoted 6 lines
drivers/watchdog/cros_ec_wdt.c new file +6
-0+ ret =cros_ec_wdt_send_hang_detect (wd_data, +EC_HANG_DETECT_CMD_CLEAR_STATUS ,0 ,NULL ); +if (ret <0 ) +dev_err (dev,"%s failed (%d)" , __func__, ret); + +watchdog_unregister_device (wd_data->wdd);
This doesn't make sense to me. Explain why it is necessary.
Quoted 4 lines
drivers/watchdog/cros_ec_wdt.c new file +4
-0+} + +static int __maybe_unused cros_ec_wdt_suspend (struct platform_device *pdev,pm_message_t state) +{
drivers/watchdog/cros_ec_wdt.c line 258
Quoted 10 lines
drivers/watchdog/cros_ec_wdt.c new file +10
-0+struct device *dev = &pdev->dev; +struct cros_ec_wdt_data *wd_data =platform_get_drvdata (pdev); +int ret; + +if (watchdog_active (wd_data->wdd)) { + ret =cros_ec_wdt_send_hang_detect (wd_data, +EC_HANG_DETECT_CMD_CANCEL ,0 ,NULL ); +if (ret <0 ) +dev_err (dev,"%s failed (%d)" , __func__, ret); + wd_data->start_on_resume = true;
Needs explanation. See below.
Quoted 4 lines
drivers/watchdog/cros_ec_wdt.c new file +4
-0+ } + +return 0 ; +}
drivers/watchdog/cros_ec_wdt.c line 272
Quoted 10 lines
drivers/watchdog/cros_ec_wdt.c new file +10
-0+ +static int __maybe_unused cros_ec_wdt_resume (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct cros_ec_wdt_data *wd_data =platform_get_drvdata (pdev); +int ret; + +/* start_on_resume is only set if watchdog was active +* when device was going to sleep +*/
Please use standard multi-line comments. This is not the networking subsystem. Even more important, use _consistent_ multi-line comments.
drivers/watchdog/cros_ec_wdt.c line 273
Quoted 1 line
drivers/watchdog/cros_ec_wdt.c new file +1
-0+if (wd_data->start_on_resume) {
Please explain why watchdog_active() does not work here.
drivers/watchdog/cros_ec_wdt.c line 277
Quoted 4 lines
drivers/watchdog/cros_ec_wdt.c new file +4
-0+/* On resume we just need to setup a EC watchdog the same way as +* in cros_ec_wdt_start(). When userspace resumes from suspend +* the watchdog app should just start petting the watchdog again. +*/
Isn't that obvious ?
Quoted 57 lines
drivers/watchdog/cros_ec_wdt.c new file +26
-0+ ret =cros_ec_wdt_start (wd_data->wdd); +if (ret <0 ) +dev_err (dev,"%s failed (%d)" , __func__, ret); + + wd_data->start_on_resume = false; + } + +return 0 ; +} + +static struct platform_driver cros_ec_wdt_driver = { + .probe = cros_ec_wdt_probe, + .remove = cros_ec_wdt_remove, + .shutdown = cros_ec_wdt_shutdown, + .suspend =pm_ptr (cros_ec_wdt_suspend), + .resume =pm_ptr (cros_ec_wdt_resume), + .driver = { + .name =DRV_NAME , + }, +}; + +module_platform_driver (cros_ec_wdt_driver); + +MODULE_ALIAS ("platform:" DRV_NAME ); +MODULE_DESCRIPTION ("Cros EC Watchdog Device Driver" ); +MODULE_LICENSE ("GPL" );include/linux/platform_data/cros_ec_commands.h +2
-18@@ -3961,60 +3961,50 @@ struct ec_response_i2c_passthru { } __ec_align1;/*****************************************************************************/ -/* Power button hang detect */ - +/* AP hang detect */ #define EC_CMD_HANG_DETECT 0x009F -/* Reasons to start hang detection timer */ -/* Power button pressed */ -#define EC_HANG_START_ON_POWER_PRESS BIT(0) - -/* Lid closed */ -#define EC_HANG_START_ON_LID_CLOSE BIT(1) - -/* Lid opened */ -#define EC_HANG_START_ON_LID_OPEN BIT(2) - -/* Start of AP S3->S0 transition (booting or resuming from suspend) */ -#define EC_HANG_START_ON_RESUME BIT(3) - -/* Reasons to cancel hang detection */ +#define EC_HANG_DETECT_MIN_TIMEOUT 5 -/* Power button released */ -#define EC_HANG_STOP_ON_POWER_RELEASE BIT(8)
include/linux/platform_data/cros_ec_commands.h struct ec_response_i2c_passthru { · line 3976
Quoted 10 lines
include/linux/platform_data/cros_ec_commands.h +6
-2+/* EC hang detect commands */ +enum ec_hang_detect_cmds { +/* Reload AP hang detect timer. */ +EC_HANG_DETECT_CMD_RELOAD =0x0 , -/* Any host command from AP received */ -#define EC_HANG_STOP_ON_HOST_COMMAND BIT(9) +/* Stop AP hang detect timer. */ +EC_HANG_DETECT_CMD_CANCEL =0x1 ,
This is making unrelated changes. Please make those in a separate patch. It might be best to update this file in a separate patch to start with.
Quoted 58 lines
include/linux/platform_data/cros_ec_commands.h +26
-24-/* Stop on end of AP S0->S3 transition (suspending or shutting down) */ -#define EC_HANG_STOP_ON_SUSPEND BIT(10) +/* Configure watchdog with given reboot timeout and +* cancel currently running AP hand detect timer. +*/ +EC_HANG_DETECT_CMD_SET_TIMEOUT =0x2 , -/* -* If this flag is set, all the other fields are ignored, and the hang detect -* timer is started. This provides the AP a way to start the hang timer -* without reconfiguring any of the other hang detect settings. Note that -* you must previously have configured the timeouts. -*/ -#define EC_HANG_START_NOW BIT(30) +/* Get last hang status - whether the AP boot was clear or not */ +EC_HANG_DETECT_CMD_GET_STATUS =0x3 , -/* -* If this flag is set, all the other fields are ignored (including -* EC_HANG_START_NOW). This provides the AP a way to stop the hang timer -* without reconfiguring any of the other hang detect settings. -*/ -#define EC_HANG_STOP_NOW BIT(31) +/* Clear last hang status. Called when AP is rebooting/shutting down +* gracefully. +*/ + EC_HANG_DETECT_CMD_CLEAR_STATUS = 0x4 +};struct ec_params_hang_detect { -/* Flags; see EC_HANG_* */ -uint32_t flags; - -/* Timeout in msec before generating host event, if enabled */ -uint16_t host_event_timeout_msec; - -/* Timeout in msec before generating warm reboot, if enabled */ -uint16_t warm_reboot_timeout_msec; -} __ec_align4; +uint16_t command;/* enum ec_hang_detect_cmds */ +/* Timeout in seconds before generating reboot */ +uint16_t reboot_timeout_sec; +} __ec_align2; +/* Status codes that describe whether AP has boot normally or the hang has been +* detected and EC has reset AP +*/ +enum ec_hang_detect_status { +EC_HANG_DETECT_AP_BOOT_NORMAL =0x0 , +EC_HANG_DETECT_AP_BOOT_EC_WDT =0x1 , +EC_HANG_DETECT_AP_BOOT_COUNT , +}; +struct ec_response_hang_detect { +uint8_t status;/* enum ec_hang_detect_status */ +} __ec_align1;/*****************************************************************************/ /* Commands for battery charging */
Łukasz Majczak
maintainerHi Guenter
Please see my comments below
Quoted 5 lines · Guenter Roeck
Quoted 3 lines · Lukasz Majczak
This adds EC-based watchdog support for ChromeOS based devices equipped with embedded controller (EC).
Quoted 7 lines
Quoted 1 line
Signed-off-by Lukasz Majczak <[email protected]>checkpatch --strict says:
total: 0 errors, 0 warnings, 14 checks, 455 lines checked
Please fix.
ACK, Although I would keep uint16_t/uint32_t types in cros_ec_commands.h as those are shared with EC firmware.
Quoted 53 lines
Quoted 53 lines
--- MAINTAINERS | 6 + drivers/mfd/cros_ec_dev.c | 9 + drivers/watchdog/Kconfig | 15 + drivers/watchdog/Makefile | 3 + drivers/watchdog/cros_ec_wdt.c | 303 ++++++++++++++++++ .../linux/platform_data/cros_ec_commands.h | 78 ++--- 6 files changed, 370 insertions(+), 44 deletions(-)create mode 100644
drivers/watchdog/cros_ec_wdt.cMAINTAINERS +6
-0@@ -4952,6 +4952,12 @@ R: Sami Kyöstilä <[email protected]> S: Maintained F: drivers/platform/chrome/cros_hps_i2c.c +CHROMEOS EC WATCHDOG +M: Lukasz Majczak <[email protected]> +L: [email protected] +S: Maintained +F: drivers/watchdog/cros_ec_wdt.c + CHRONTEL CH7322 CEC DRIVER M: Joe Tessler <[email protected]> L: [email protected]drivers/mfd/cros_ec_dev.c +9
-0@@ -91,6 +91,10 @@ static const struct mfd_cell cros_usbpd_notify_cells[] = { { .name = "cros-usbpd-notify", }, }; +static const struct mfd_cell cros_ec_wdt_cells[] = { + { .name ="cros-ec-wdt-drv" , } +}; +static const struct cros_feature_to_cells cros_subdevices[] = { { .id =EC_FEATURE_CEC ,@@ -107,6 +111,11 @@ static const struct cros_feature_to_cells cros_subdevices[] = { .mfd_cells = cros_usbpd_charger_cells, .num_cells = ARRAY_SIZE(cros_usbpd_charger_cells), }, + { + .id = EC_FEATURE_HANG_DETECT, + .mfd_cells = cros_ec_wdt_cells, + .num_cells = ARRAY_SIZE(cros_ec_wdt_cells), + }, };
Quoted 4 lines
drivers/mfd/cros_ec_dev.c static const struct cros_feature_to_cells cros_subdevices[] = { · line 121
Quoted 1 line
drivers/mfd/cros_ec_dev.c +0
-0static const struct mfd_cell cros_ec_platform_cells[] = {The above should be a separate patch.
ACK, I will create a separate one for this.
Quoted 8 lines
Quoted 8 lines
drivers/watchdog/Kconfig +0
-0@@ -2251,4 +2251,19 @@ config KEEMBAY_WATCHDOG To compile this driver as a module, choose M here: the module will be called keembay_wdt.
Quoted 6 lines
drivers/watchdog/Kconfig config KEEMBAY_WATCHDOG · line 2256
Quoted 3 lines
drivers/watchdog/Kconfig +3
-0+# +# ChromeOS EC-based Watchdog +#Pointless comment.
ACK
Quoted 17 lines
drivers/watchdog/Kconfig config KEEMBAY_WATCHDOG · line 2268
Quoted 12 lines
drivers/watchdog/Kconfig +12
-0+ +config CROS_EC_WATCHDOG + tristate "ChromeOS EC-based watchdog driver" + select WATCHDOG_CORE + depends on CROS_EC + help + This is the watchdog driver for ChromeOS devices equipped with EC. + The EC watchdog - when enabled - expects to be kicked within a given + time (default set to 30 seconds) otherwise it will simple reboot + the AP. Priori to that it can also send an event (configurable timeout) + about upcoming reboot. +In other words, it is a watchdog driver. I don't think it adds value to describe how a watchdog works here, nor to describe what other (unused) functionality the hardware may have.
Quoted 1 line
Also, please try to insert in alphabetic order.
ACK
Quoted 16 lines
drivers/watchdog/Makefile obj-$(CONFIG_MENZ069_WATCHDOG) += menz69_wdt.o · line 238
Quoted 12 lines
drivers/watchdog/Kconfig +0
-0endif # WATCHDOGdrivers/watchdog/Makefile +2
-0@@ -234,3 +234,6 @@ obj-$(CONFIG_MENZ069_WATCHDOG) += menz69_wdt.o obj-$(CONFIG_RAVE_SP_WATCHDOG) += rave-sp-wdt.o obj-$(CONFIG_STPMIC1_WATCHDOG) += stpmic1_wdt.o obj-$(CONFIG_SL28CPLD_WATCHDOG) += sl28cpld_wdt.o + +# Cros EC watchdogWe don't add individual comments for each watchdog, and we should not start doing so. Also, please try to insert in alphabetic order.
ACK
Quoted 14 lines
Quoted 14 lines
drivers/watchdog/Makefile +1
-0+obj-$(CONFIG_CROS_EC_WATCHDOG) += cros_ec_wdt.odrivers/watchdog/cros_ec_wdt.c new file +7
-0@@ -0,0 +1,303 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <linux/slab.h> +#include <linux/err.h> +#include <linux/of_device.h> +#include <linux/kernel.h> +#include <linux/module.h>
Quoted 9 lines
drivers/watchdog/cros_ec_wdt.c line 12
Quoted 5 lines
drivers/watchdog/cros_ec_wdt.c new file +5
-0+#include <linux/platform_data/cros_ec_commands.h> +#include <linux/platform_data/cros_ec_proto.h> +#include <linux/platform_device.h> +#include <linux/watchdog.h> +#include <linux/uaccess.h> Alphabetic include file order, please. Also, I don't immediately see where
uaccess.horof_device.hare used. Please drop unused includes.
ACK, in fact uaccess.h or of_device.h are unnecessary
Quoted 8 lines
drivers/watchdog/cros_ec_wdt.c line 17
Quoted 5 lines
drivers/watchdog/cros_ec_wdt.c new file +5
-0+ +#define CROS_EC_WATCHDOG_DEFAULT_TIME 30/* seconds */ + +#define DEV_NAME "cros-ec-wdt-dev" +#define DRV_NAME "cros-ec-wdt-drv"One of those is unused.
ACK
Quoted 9 lines
drivers/watchdog/cros_ec_wdt.c line 23
Quoted 6 lines
drivers/watchdog/cros_ec_wdt.c new file +6
-0+ +static int cros_ec_wdt_ping (struct watchdog_device *wdd); +static int cros_ec_wdt_start (struct watchdog_device *wdd); +static int cros_ec_wdt_stop (struct watchdog_device *wdd); +static int cros_ec_wdt_set_timeout (struct watchdog_device *wdd,unsigned int t); +Please rearrange to avoid forward declarations.
ACK
Quoted 10 lines
drivers/watchdog/cros_ec_wdt.c line 30
Quoted 7 lines
drivers/watchdog/cros_ec_wdt.c new file +7
-0+struct cros_ec_wdt_data { +bool start_on_resume; +bool keepalive_on; +struct cros_ec_device *cros_ec; +struct watchdog_device *wdd; +}; +static struct cros_ec_wdt_data wd_data;Please allocate and avoid static variables.
ACK
Quoted 16 lines
Quoted 16 lines
drivers/watchdog/cros_ec_wdt.c new file +16
-0+ +static const struct watchdog_info cros_ec_wdt_ident = { + .options =WDIOF_SETTIMEOUT |WDIOF_KEEPALIVEPING |WDIOF_MAGICCLOSE , + .firmware_version =0 , + .identity =DRV_NAME , +}; + +static const struct watchdog_ops cros_ec_wdt_ops = { + .owner =THIS_MODULE , + .ping = cros_ec_wdt_ping, + .start = cros_ec_wdt_start, + .stop = cros_ec_wdt_stop, + .set_timeout = cros_ec_wdt_set_timeout, +}; + +static struct watchdog_device cros_ec_wdd = {
Quoted 9 lines
drivers/watchdog/cros_ec_wdt.c line 50
Quoted 4 lines
drivers/watchdog/cros_ec_wdt.c new file +4
-0+ .info = &cros_ec_wdt_ident, + .ops = &cros_ec_wdt_ops, + .timeout =CROS_EC_WATCHDOG_DEFAULT_TIME , + .bootstatus = EC_HANG_DETECT_AP_BOOT_NORMALConsider allocating and embedding in struct
cros_ec_wdt_data. .timeout and .bootstatus are overwritten anyway, and it does not make sense to initialize those elements here.
ACK, Agree, in fact cros_ec_wdt_data might be not necessary at all and I might be able to drop it.
Quoted 6 lines
drivers/watchdog/cros_ec_wdt.c line 53
Quoted 3 lines
drivers/watchdog/cros_ec_wdt.c new file +3
-0+}; + +static int cros_ec_wdt_send_hang_detect(struct cros_ec_wdt_data *wd_data,Seems to me that
cros_ec_wdt_send_cmdor similar would be a better function name, but your call.
ACK, cros_ec_wdt_send_cmd looks better - thank you,
Quoted 37 lines
Quoted 21 lines
drivers/watchdog/cros_ec_wdt.c new file +20
-0+uint16_t command, + uint16_t reboot_timeout_sec, + uint32_t *status) +{ + int ret; + + struct { + struct cros_ec_command msg; + union { + struct ec_params_hang_detect req; + struct ec_response_hang_detect resp; + }; + } __packed buf = { + .msg = { + .version = 0, + .command = EC_CMD_HANG_DETECT, + .insize = (command == EC_HANG_DETECT_CMD_GET_STATUS) ? + sizeof(struct ec_response_hang_detect) : + 0, + .outsize = sizeof(struct ec_params_hang_detect),drivers/watchdog/cros_ec_wdt.c line 83
Quoted 10 lines
drivers/watchdog/cros_ec_wdt.c new file +10
-0+ }, + .req = { + .command = command, + .reboot_timeout_sec = reboot_timeout_sec, + } + }; + + ret =cros_ec_cmd_xfer_status (wd_data->cros_ec, &buf.msg); +if (ret <0 ) { + dev_warn(wd_data->wdd->parent,Given that wdd is needed anyway,
drivers/watchdog/cros_ec_wdt.c line 85
Quoted 2 lines
drivers/watchdog/cros_ec_wdt.c new file +2
-0+"cros_ec_cmd_xfer_status failed(%d) command (%04x) reboot_timeout_sec(%ds)" , + ret, command, reboot_timeout_sec);
Quoted 7 lines
That message, if ever seen, does not make much sense if the command was one that does not set the timeout. On top of that, this code dumps a warning, and the calling code dumps an error message. Is the EC really that fragile that it is necessary to dump all those error messages ?
If not, please consider replacing most if not all of those log messages with
dev_dbg().
ACK, I will revisit log messages (and levels)
Quoted 9 lines
drivers/watchdog/cros_ec_wdt.c line 89
Quoted 5 lines
drivers/watchdog/cros_ec_wdt.c new file +4
-0+return ret; + } + +if (status && (command ==EC_HANG_DETECT_CMD_GET_STATUS )) {Unnecessary (). Besides, it doesn't make much sense. Why provide a status pointer but only use it if the command is a specific one ?
ACK, I will rework the whole function to be more generic.
Quoted 6 lines
drivers/watchdog/cros_ec_wdt.c line 92
Quoted 3 lines
drivers/watchdog/cros_ec_wdt.c new file +3
-0+ *status = buf.resp.status; +dev_info (wd_data->wdd->parent,"EC Watchdog boot status (%d)" , + buf.resp.status);That message does not belong here.
ACK
Quoted 8 lines
Quoted 8 lines
drivers/watchdog/cros_ec_wdt.c new file +8
-0+ } + +return 0 ; +} + +static int cros_ec_wdt_ping (struct watchdog_device *wdd) +{ +struct cros_ec_wdt_data *wd_data =watchdog_get_drvdata (wdd);
Quoted 9 lines
drivers/watchdog/cros_ec_wdt.c line 106
Quoted 6 lines
drivers/watchdog/cros_ec_wdt.c new file +6
-0+int ret; + + ret =cros_ec_wdt_send_hang_detect (wd_data,EC_HANG_DETECT_CMD_RELOAD , +0 ,NULL ); +if (ret <0 ) +dev_err (wdd->parent,"%s failed (%d)" , __func__, ret);return here and drop the else.
ACK
Quoted 4 lines
Nore that this driver is extremely noisy. If the EC for some reason doesn't respond as expected the error messages will drown all other kernel messages. I really do not see the point of this.
ACK, I will try to clean it up.
Quoted 5 lines
drivers/watchdog/cros_ec_wdt.c line 108
Quoted 2 lines
drivers/watchdog/cros_ec_wdt.c new file +2
-0+else + wd_data->keepalive_on = true;This is odd and needs a detailed explanation. More on that see below.
I have revisited the code again and I think I can drop struc cros_ec_wdt_data and rely purely on structures provided by framework.
Quoted 28 lines
Quoted 28 lines
drivers/watchdog/cros_ec_wdt.c new file +28
-0+ +return ret; +} + +static int cros_ec_wdt_start (struct watchdog_device *wdd) +{ +struct cros_ec_wdt_data *wd_data =watchdog_get_drvdata (wdd); +int ret =0 ; + +/* Prepare watchdog on EC side */ + ret =cros_ec_wdt_send_hang_detect (wd_data, +EC_HANG_DETECT_CMD_SET_TIMEOUT , + wdd->timeout, +NULL ); +if (ret <0 ) +dev_err (wdd->parent,"%s failed (%d)" , __func__, ret); + +return ret; +} + +static int cros_ec_wdt_stop (struct watchdog_device *wdd) +{ +struct cros_ec_wdt_data *wd_data =watchdog_get_drvdata (wdd); +int ret =0 ; + +if (wd_data->keepalive_on) { + wd_data->keepalive_on = false; + ret = cros_ec_wdt_send_hang_detect(wd_data, EC_HANG_DETECT_CMD_CANCEL,
Quoted 9 lines
drivers/watchdog/cros_ec_wdt.c line 137
Quoted 1 line
drivers/watchdog/cros_ec_wdt.c new file +1
-0+ 0, NULL);This needs explanation. Why is it only needed here after the first ping is sent, but on suspend it is unconditional ? In other words, why does the watchdog behave differently after the first ping ? Why does the watchdog not have to be stopped if it never received a ping ? Logically that seems odd, if not plain wrong. The watchdog should behave exactly the same after it was started, no matter if it ever received a ping or not.
ACK, Same as with "keepalive_on" I will drop the struct cros_ec_wdt_data. Agree with the confusion here, sorry for that, I will simplify it.
Quoted 11 lines
Quoted 11 lines
drivers/watchdog/cros_ec_wdt.c new file +11
-0+if (ret <0 ) +dev_err (wdd->parent,"%s failed (%d)" , __func__, ret); + } + +return ret; +} + +static int cros_ec_wdt_set_timeout (struct watchdog_device *wdd,unsigned int t) +{ +struct cros_ec_wdt_data *wd_data =watchdog_get_drvdata (wdd); +int ret;
Quoted 9 lines
drivers/watchdog/cros_ec_wdt.c line 154
Quoted 6 lines
drivers/watchdog/cros_ec_wdt.c new file +6
-0+ +if (t <EC_HANG_DETECT_MIN_TIMEOUT ) { +dev_err (wdd->parent, +"%s failed, requested timeout is lower than min(%d < %d)" , + __func__, t,EC_HANG_DETECT_MIN_TIMEOUT ); +return -EINVAL ;This should be handled in the watchdog core. If it isn't the driver is misconfigured.
ACK, yes, both min and max values should be set.
Quoted 10 lines
drivers/watchdog/cros_ec_wdt.c line 161
Quoted 7 lines
drivers/watchdog/cros_ec_wdt.c new file +7
-0+ } + + ret =cros_ec_wdt_send_hang_detect (wd_data, +EC_HANG_DETECT_CMD_SET_TIMEOUT , + t,NULL ); +if (ret <0 ) +dev_err (wdd->parent,"%s failed (%d)" , __func__, ret);return here.
ACK
Quoted 12 lines
Quoted 12 lines
drivers/watchdog/cros_ec_wdt.c new file +12
-0+else + wdd->timeout = t; + +return ret; +} + +static int cros_ec_wdt_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +/* We need to get a reference to cros_ec_devices +* (provides communication layer) which is a parent of +* the cros-ec-dev (our parent)
Quoted 9 lines
drivers/watchdog/cros_ec_wdt.c line 175
Quoted 2 lines
drivers/watchdog/cros_ec_wdt.c new file +2
-0+*/ +struct cros_ec_device *cros_ec =dev_get_drvdata (dev->parent->parent);Other cros drivers get struct
cros_ec_devfromdev->parentand then useec->ec_dev. Please explain why you don't use the same pattern; dereferencingparent->parentand assuming to know its driver data seems to be (much) more risky than the existing pattern.
ACK, I will look at other cros_ec driver as an example.
Quoted 3 lines
Also, the comment seems obvious. None of the other
cros_ecdrivers needed it, and I don't see why it would add value here.
ACK
Quoted 10 lines
drivers/watchdog/cros_ec_wdt.c line 182
Quoted 7 lines
drivers/watchdog/cros_ec_wdt.c new file +7
-0+int ret =0 ; +uint32_t bootstatus; + +if (!cros_ec) { + ret = -ENODEV ; +dev_err_probe (dev, ret,"There is no coresponding EC device!" ); +return ret;return
dev_err_probe(). Same elsewhere.
ACK
Quoted 9 lines
drivers/watchdog/cros_ec_wdt.c line 190
Quoted 8 lines
drivers/watchdog/cros_ec_wdt.c new file +8
-0+ } + + cros_ec_wdd.parent = &pdev->dev; + wd_data.cros_ec = cros_ec; + wd_data.wdd = &cros_ec_wdd; + wd_data.start_on_resume = false; + wd_data.keepalive_on = false; + wd_data.wdd->timeout =CROS_EC_WATCHDOG_DEFAULT_TIME ;
Quoted 4 lines
Ah, I guess the reason for the error handling when setting the timeout is the lack of setting boundaries here. That is wrong.
min_timeoutandmax_timeoutneed to be set.
ACK
Quoted 11 lines
Quoted 11 lines
drivers/watchdog/cros_ec_wdt.c new file +11
-0+ +watchdog_stop_on_reboot (&cros_ec_wdd); +watchdog_stop_on_unregister (&cros_ec_wdd); +watchdog_set_drvdata (&cros_ec_wdd, &wd_data); +platform_set_drvdata (pdev, &wd_data); + +/* Get current AP boot status */ + ret =cros_ec_wdt_send_hang_detect (&wd_data,EC_HANG_DETECT_CMD_GET_STATUS ,0 , + &bootstatus); +if (ret <0 ) { +dev_err_probe (dev, ret,"Couldn't get AP boot status from EC" );
Quoted 9 lines
drivers/watchdog/cros_ec_wdt.c line 207
Quoted 6 lines
drivers/watchdog/cros_ec_wdt.c new file +6
-0+return ret; + } + +/* +* If bootstatus is not EC_HANG_DETECT_AP_BOOT_NORMAL +* it mens EC has rebooted the AP due to watchdog timeout. means
ACK
Quoted 11 lines
drivers/watchdog/cros_ec_wdt.c line 215
Quoted 8 lines
drivers/watchdog/cros_ec_wdt.c new file +8
-0+* Lets translate it to watchdog core status code. +*/ +if (bootstatus !=EC_HANG_DETECT_AP_BOOT_NORMAL ) + wd_data.wdd->bootstatus =WDIOF_CARDRESET ; + + ret =watchdog_register_device (&cros_ec_wdd); +if (ret <0 ) +dev_err_probe (dev, ret,"Couldn't get AP boot status from EC" );Wrong error message.
ACK
Quoted 11 lines
drivers/watchdog/cros_ec_wdt.c line 224
Quoted 9 lines
drivers/watchdog/cros_ec_wdt.c new file +9
-0+ +return ret; +} + +static int cros_ec_wdt_remove (struct platform_device *pdev) +{ +struct cros_ec_wdt_data *wd_data =platform_get_drvdata (pdev); + +watchdog_unregister_device (wd_data->wdd);Why not use
devm_watchdog_register_device()? Please explain.
ACK, good point, thank you.
Quoted 8 lines
Quoted 8 lines
drivers/watchdog/cros_ec_wdt.c new file +8
-0+ +return 0 ; +} + +static void cros_ec_wdt_shutdown (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct cros_ec_wdt_data *wd_data =platform_get_drvdata (pdev);
Quoted 9 lines
drivers/watchdog/cros_ec_wdt.c line 238
Quoted 6 lines
drivers/watchdog/cros_ec_wdt.c new file +6
-0+int ret; + +/* +* Clean only bootstatus flag. +* EC wdt is are already stopped by watchdog framework. +*/ Why is this necessary if the watchdog is stopped ?
ACK, The idea was to clear the bootstatus (on EC side) when AP was shutting down gracefully, to address the scenario:
1. EC kicks AP and sets bootstatus for doing so
2. AP boots and in sometime gracefully shutdown/reboot (EC still keeps bootstatus that it's kicked AP)
3. AP boots again and read the bootstatus from EC and thinks it was kicked by EC ...but yeah much easier is to read-and-clear the boot status during probe and keep it in the "bootstatus" field of thestruct watchdog_device (where it was meant to be ) that will simplify the code.
Quoted 9 lines
drivers/watchdog/cros_ec_wdt.c line 244
Quoted 6 lines
drivers/watchdog/cros_ec_wdt.c new file +6
-0+ ret =cros_ec_wdt_send_hang_detect (wd_data, +EC_HANG_DETECT_CMD_CLEAR_STATUS ,0 ,NULL ); +if (ret <0 ) +dev_err (dev,"%s failed (%d)" , __func__, ret); + +watchdog_unregister_device (wd_data->wdd);This doesn't make sense to me. Explain why it is necessary.
ACK, this will be removed.
Quoted 8 lines
Quoted 8 lines
drivers/watchdog/cros_ec_wdt.c new file +8
-0+} + +static int __maybe_unused cros_ec_wdt_suspend (struct platform_device *pdev,pm_message_t state) +{ +struct device *dev = &pdev->dev; +struct cros_ec_wdt_data *wd_data =platform_get_drvdata (pdev); +int ret; +
Quoted 9 lines
drivers/watchdog/cros_ec_wdt.c line 258
Quoted 6 lines
drivers/watchdog/cros_ec_wdt.c new file +6
-0+if (watchdog_active (wd_data->wdd)) { + ret =cros_ec_wdt_send_hang_detect (wd_data, +EC_HANG_DETECT_CMD_CANCEL ,0 ,NULL ); +if (ret <0 ) +dev_err (dev,"%s failed (%d)" , __func__, ret); + wd_data->start_on_resume = true;Needs explanation. See below.
ACK, same as with "keepalive_on" - will drop the struct cros_ec_wdt_data and rely on watchdog_active().
Quoted 9 lines
Quoted 9 lines
drivers/watchdog/cros_ec_wdt.c new file +9
-0+ } + +return 0 ; +} + +static int __maybe_unused cros_ec_wdt_resume (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct cros_ec_wdt_data *wd_data =platform_get_drvdata (pdev);
Quoted 9 lines
drivers/watchdog/cros_ec_wdt.c line 272
Quoted 5 lines
drivers/watchdog/cros_ec_wdt.c new file +5
-0+int ret; + +/* start_on_resume is only set if watchdog was active +* when device was going to sleep +*/ Please use standard multi-line comments. This is not the networking subsystem. Even more important, use _consistent_ multi-line comments.
ACK
Quoted 10 lines
drivers/watchdog/cros_ec_wdt.c line 273
Quoted 1 line
drivers/watchdog/cros_ec_wdt.c new file +1
-0+if (wd_data->start_on_resume) {Please explain why
watchdog_active()does not work here.drivers/watchdog/cros_ec_wdt.c line 277
Quoted 4 lines
drivers/watchdog/cros_ec_wdt.c new file +4
-0+/* On resume we just need to setup a EC watchdog the same way as +* in cros_ec_wdt_start(). When userspace resumes from suspend +* the watchdog app should just start petting the watchdog again. +*/ Isn't that obvious ?
ACK, Right
Quoted 63 lines
Quoted 63 lines
drivers/watchdog/cros_ec_wdt.c new file +26
-0+ ret =cros_ec_wdt_start (wd_data->wdd); +if (ret <0 ) +dev_err (dev,"%s failed (%d)" , __func__, ret); + + wd_data->start_on_resume = false; + } + +return 0 ; +} + +static struct platform_driver cros_ec_wdt_driver = { + .probe = cros_ec_wdt_probe, + .remove = cros_ec_wdt_remove, + .shutdown = cros_ec_wdt_shutdown, + .suspend =pm_ptr (cros_ec_wdt_suspend), + .resume =pm_ptr (cros_ec_wdt_resume), + .driver = { + .name =DRV_NAME , + }, +}; + +module_platform_driver (cros_ec_wdt_driver); + +MODULE_ALIAS ("platform:" DRV_NAME ); +MODULE_DESCRIPTION ("Cros EC Watchdog Device Driver" ); +MODULE_LICENSE ("GPL" );include/linux/platform_data/cros_ec_commands.h +6
-18@@ -3961,60 +3961,50 @@ struct ec_response_i2c_passthru { } __ec_align1;/*****************************************************************************/ -/* Power button hang detect */ - +/* AP hang detect */ #define EC_CMD_HANG_DETECT 0x009F -/* Reasons to start hang detection timer */ -/* Power button pressed */ -#define EC_HANG_START_ON_POWER_PRESS BIT(0) - -/* Lid closed */ -#define EC_HANG_START_ON_LID_CLOSE BIT(1) - -/* Lid opened */ -#define EC_HANG_START_ON_LID_OPEN BIT(2) - -/* Start of AP S3->S0 transition (booting or resuming from suspend) */ -#define EC_HANG_START_ON_RESUME BIT(3) - -/* Reasons to cancel hang detection */ +#define EC_HANG_DETECT_MIN_TIMEOUT 5 -/* Power button released */ -#define EC_HANG_STOP_ON_POWER_RELEASE BIT(8) +/* EC hang detect commands */ +enum ec_hang_detect_cmds { +/* Reload AP hang detect timer. */ +EC_HANG_DETECT_CMD_RELOAD =0x0 ,
Quoted 9 lines
include/linux/platform_data/cros_ec_commands.h struct ec_response_i2c_passthru { · line 3976
Quoted 5 lines
include/linux/platform_data/cros_ec_commands.h +2
-2-/* Any host command from AP received */ -#define EC_HANG_STOP_ON_HOST_COMMAND BIT(9) +/* Stop AP hang detect timer. */ + EC_HANG_DETECT_CMD_CANCEL = 0x1,This is making unrelated changes. Please make those in a separate patch. It might be best to update this file in a separate patch to start with.
ACK, I will create a separate one for this.
Quoted 44 lines
Quoted 44 lines
include/linux/platform_data/cros_ec_commands.h +15
-24-/* Stop on end of AP S0->S3 transition (suspending or shutting down) */ -#define EC_HANG_STOP_ON_SUSPEND BIT(10) +/* Configure watchdog with given reboot timeout and +* cancel currently running AP hand detect timer. +*/ +EC_HANG_DETECT_CMD_SET_TIMEOUT =0x2 , -/* -* If this flag is set, all the other fields are ignored, and the hang detect -* timer is started. This provides the AP a way to start the hang timer -* without reconfiguring any of the other hang detect settings. Note that -* you must previously have configured the timeouts. -*/ -#define EC_HANG_START_NOW BIT(30) +/* Get last hang status - whether the AP boot was clear or not */ +EC_HANG_DETECT_CMD_GET_STATUS =0x3 , -/* -* If this flag is set, all the other fields are ignored (including -* EC_HANG_START_NOW). This provides the AP a way to stop the hang timer -* without reconfiguring any of the other hang detect settings. -*/ -#define EC_HANG_STOP_NOW BIT(31) +/* Clear last hang status. Called when AP is rebooting/shutting down +* gracefully. +*/ + EC_HANG_DETECT_CMD_CLEAR_STATUS = 0x4 +};struct ec_params_hang_detect { -/* Flags; see EC_HANG_* */ -uint32_t flags; - -/* Timeout in msec before generating host event, if enabled */ -uint16_t host_event_timeout_msec; - -/* Timeout in msec before generating warm reboot, if enabled */ -uint16_t warm_reboot_timeout_msec; -} __ec_align4; +uint16_t command;/* enum ec_hang_detect_cmds */ +/* Timeout in seconds before generating reboot */ +uint16_t reboot_timeout_sec; +} __ec_align2;
Quoted 15 lines
Quoted 4 lines
include/linux/platform_data/cros_ec_commands.h +4
-0+/* Status codes that describe whether AP has boot normally or the hang has been +* detected and EC has reset AP +*/ +enum ec_hang_detect_status {include/linux/platform_data/cros_ec_commands.h struct ec_response_i2c_passthru { · line 4010
Quoted 10 lines
include/linux/platform_data/cros_ec_commands.h +7
-0+EC_HANG_DETECT_AP_BOOT_NORMAL =0x0 , +EC_HANG_DETECT_AP_BOOT_EC_WDT =0x1 , + EC_HANG_DETECT_AP_BOOT_COUNT, +}; +struct ec_response_hang_detect { +uint8_t status;/* enum ec_hang_detect_status */ +} __ec_align1;/*****************************************************************************/ /* Commands for battery charging */
Thank you Guenter for all the comments, I will try to address them best I can sith V2 and thank you for your time reading all of this and answering.
Best regards,
Lukasz
Guenter Roeck
maintainerQuoted 12 lines · Łukasz Majczak
Hi Guenter
Please see my comments below
Quoted 7 lines · Guenter Roeck
Quoted 4 lines · Lukasz Majczak
This adds EC-based watchdog support for ChromeOS based devices equipped with embedded controller (EC).
Signed-off-by Lukasz Majczak <[email protected]>
Quoted 9 lines
Quoted 5 lines
checkpatch --strict says:
total: 0 errors, 0 warnings, 14 checks, 455 lines checked
Please fix.
ACK, Although I would keep uint16_t/uint32_t types in
cros_ec_commands.has those are shared with EC firmware.
Makes sense. Thanks!
Guenter