chrome-platform.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] Introduce EC-based watchdog
@ 2024-01-18 19:53 Lukasz Majczak
  2024-01-18 19:53 ` [PATCH v2 1/3] platform/chrome: Update binary interface for " Lukasz Majczak
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Lukasz Majczak @ 2024-01-18 19:53 UTC (permalink / raw)
  To: Gwendal Grignou, Tzung-Bi Shih, Radoslaw Biernacki,
	Wim Van Sebroeck, Lee Jones, Benson Leung, Guenter Roeck,
	Krzysztof Kozlowski, linux-watchdog, linux-kernel,
	chrome-platform
  Cc: Lukasz Majczak

Chromeos devices are equipped with the embedded controller (EC)
that can be used as a watchdog. The following patches
updates the structures and definitions required to
communicate with EC-based watchdog and implements the
driver itself.

The first version of this patch was sent here:
https://patchwork.kernel.org/project/linux-watchdog/patch/20240117102450.4080839-1-lma@chromium.org/

Changelog
V1->V2:
* Splitted into three patches
* Supplement the watchdog configuration with min/max timeouts
* Removed struct cros_ec_wdt_data  and get aligned to watchdog framework
* Simplified suspend/resume callbacks
* Removed excessive log messages
* Reworked cros_ec_wdt_send_hang_detect() function to be more generic
* Usage of devm_* allowed to delete .remove module callback
* Changed MODULE_ALIAS to MODULE_DEVICE_TABLE
* Moved clearing bootstatus (on EC) to probe() and thanks to that
  got rid of .shutdown() module callback
* Fixed/removed comments, removed unused includes and general cleanup

Best regards,
Lukasz

Lukasz Majczak (3):
  platform/chrome: Update binary interface for EC-based watchdog
  watchdog: Add ChromeOS EC-based watchdog driver
  mfd: cros_ec: Register EC-based watchdog subdevice

 MAINTAINERS                                   |   6 +
 drivers/mfd/cros_ec_dev.c                     |   9 +
 drivers/watchdog/Kconfig                      |  11 +
 drivers/watchdog/Makefile                     |   1 +
 drivers/watchdog/cros_ec_wdt.c                | 202 ++++++++++++++++++
 .../linux/platform_data/cros_ec_commands.h    |  78 +++----
 6 files changed, 264 insertions(+), 43 deletions(-)
 create mode 100644 drivers/watchdog/cros_ec_wdt.c

-- 
2.43.0.429.g432eaa2c6b-goog


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v2 1/3] platform/chrome: Update binary interface for EC-based watchdog
  2024-01-18 19:53 [PATCH v2 0/3] Introduce EC-based watchdog Lukasz Majczak
@ 2024-01-18 19:53 ` Lukasz Majczak
  2024-01-18 23:42   ` Guenter Roeck
  2024-01-19  3:41   ` Tzung-Bi Shih
  2024-01-18 19:53 ` [PATCH v2 2/3] watchdog: Add ChromeOS EC-based watchdog driver Lukasz Majczak
  2024-01-18 19:53 ` [PATCH v2 3/3] mfd: cros_ec: Register EC-based watchdog subdevice Lukasz Majczak
  2 siblings, 2 replies; 13+ messages in thread
From: Lukasz Majczak @ 2024-01-18 19:53 UTC (permalink / raw)
  To: Gwendal Grignou, Tzung-Bi Shih, Radoslaw Biernacki,
	Wim Van Sebroeck, Lee Jones, Benson Leung, Guenter Roeck,
	Krzysztof Kozlowski, linux-watchdog, linux-kernel,
	chrome-platform
  Cc: Lukasz Majczak

Update structures and defines related to EC_CMD_HANG_DETECT
to allow usage of new EC-based watchdog.

Signed-off-by: Lukasz Majczak <lma@chromium.org>
---
 .../linux/platform_data/cros_ec_commands.h    | 78 +++++++++----------
 1 file changed, 35 insertions(+), 43 deletions(-)

diff --git a/include/linux/platform_data/cros_ec_commands.h b/include/linux/platform_data/cros_ec_commands.h
index 7dae17b62a4d..ecc47d5fe239 100644
--- a/include/linux/platform_data/cros_ec_commands.h
+++ b/include/linux/platform_data/cros_ec_commands.h
@@ -3961,60 +3961,52 @@ 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
+#define EC_HANG_DETECT_MAX_TIMEOUT 65535
 
-/* 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,
 
-/* 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,
 
-/* 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 hang 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;
+	uint16_t command; /* enum ec_hang_detect_cmds */
+	/* Timeout in seconds before generating reboot */
+	uint16_t reboot_timeout_sec;
+} __ec_align2;
 
-	/* Timeout in msec before generating warm reboot, if enabled */
-	uint16_t warm_reboot_timeout_msec;
-} __ec_align4;
+/* 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 */
 
-- 
2.43.0.429.g432eaa2c6b-goog


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 2/3] watchdog: Add ChromeOS EC-based watchdog driver
  2024-01-18 19:53 [PATCH v2 0/3] Introduce EC-based watchdog Lukasz Majczak
  2024-01-18 19:53 ` [PATCH v2 1/3] platform/chrome: Update binary interface for " Lukasz Majczak
@ 2024-01-18 19:53 ` Lukasz Majczak
  2024-01-18 23:44   ` Guenter Roeck
  2024-01-19  3:42   ` Tzung-Bi Shih
  2024-01-18 19:53 ` [PATCH v2 3/3] mfd: cros_ec: Register EC-based watchdog subdevice Lukasz Majczak
  2 siblings, 2 replies; 13+ messages in thread
From: Lukasz Majczak @ 2024-01-18 19:53 UTC (permalink / raw)
  To: Gwendal Grignou, Tzung-Bi Shih, Radoslaw Biernacki,
	Wim Van Sebroeck, Lee Jones, Benson Leung, Guenter Roeck,
	Krzysztof Kozlowski, linux-watchdog, linux-kernel,
	chrome-platform
  Cc: Lukasz Majczak

Embedded Controller (EC) present on Chromebook devices
can be used as a watchdog.
Implement a driver to support it.

Signed-off-by: Lukasz Majczak <lma@chromium.org>
---
 MAINTAINERS                    |   6 +
 drivers/watchdog/Kconfig       |  11 ++
 drivers/watchdog/Makefile      |   1 +
 drivers/watchdog/cros_ec_wdt.c | 202 +++++++++++++++++++++++++++++++++
 4 files changed, 220 insertions(+)
 create mode 100644 drivers/watchdog/cros_ec_wdt.c

diff --git a/MAINTAINERS b/MAINTAINERS
index ef90ddc0fda6..aaae581aae70 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4981,6 +4981,12 @@ R:	Sami Kyöstilä <skyostil@chromium.org>
 S:	Maintained
 F:	drivers/platform/chrome/cros_hps_i2c.c
 
+CHROMEOS EC WATCHDOG
+M:	Lukasz Majczak <lma@chromium.org>
+L:	chrome-platform@lists.linux.dev
+S:	Maintained
+F:	drivers/watchdog/cros_ec_wdt.c
+
 CHRONTEL CH7322 CEC DRIVER
 M:	Joe Tessler <jrt@google.com>
 L:	linux-media@vger.kernel.org
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 7d22051b15a2..4700b218340f 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -181,6 +181,17 @@ config BD957XMUF_WATCHDOG
 	  watchdog. Alternatively say M to compile the driver as a module,
 	  which will be called bd9576_wdt.
 
+config CROS_EC_WATCHDOG
+	tristate "ChromeOS EC-based watchdog"
+	select WATCHDOG_CORE
+	depends on CROS_EC
+	help
+	  Watchdog driver for Chromebook devices equipped with embedded controller.
+	  Trigger event is recorded in EC and checked on the subsequent boot.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called cros_ec_wdt.
+
 config DA9052_WATCHDOG
 	tristate "Dialog DA9052 Watchdog"
 	depends on PMIC_DA9052 || COMPILE_TEST
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 7cbc34514ec1..3710c218f05e 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -217,6 +217,7 @@ obj-$(CONFIG_XEN_WDT) += xen_wdt.o
 
 # Architecture Independent
 obj-$(CONFIG_BD957XMUF_WATCHDOG) += bd9576_wdt.o
+obj-$(CONFIG_CROS_EC_WATCHDOG) += cros_ec_wdt.o
 obj-$(CONFIG_DA9052_WATCHDOG) += da9052_wdt.o
 obj-$(CONFIG_DA9055_WATCHDOG) += da9055_wdt.o
 obj-$(CONFIG_DA9062_WATCHDOG) += da9062_wdt.o
diff --git a/drivers/watchdog/cros_ec_wdt.c b/drivers/watchdog/cros_ec_wdt.c
new file mode 100644
index 000000000000..1915b8d55e45
--- /dev/null
+++ b/drivers/watchdog/cros_ec_wdt.c
@@ -0,0 +1,202 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2024 Google LLC.
+ * Author: Lukasz Majczak <lma@chromium.com>
+ */
+
+#include <linux/err.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/mod_devicetable.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>
+
+#define CROS_EC_WATCHDOG_DEFAULT_TIME 30 /* seconds */
+#define DRV_NAME "cros-ec-wdt-drv"
+
+union cros_ec_wdt_data {
+	struct ec_params_hang_detect req;
+	struct ec_response_hang_detect resp;
+} __packed;
+
+static int cros_ec_wdt_send_cmd(struct cros_ec_device *cros_ec,
+				union cros_ec_wdt_data *arg)
+{
+	int ret;
+	struct {
+		struct cros_ec_command msg;
+		union cros_ec_wdt_data data;
+	} __packed buf = {
+		.msg = {
+			.version = 0,
+			.command = EC_CMD_HANG_DETECT,
+			.insize  = (arg->req.command == EC_HANG_DETECT_CMD_GET_STATUS) ?
+				   sizeof(struct ec_response_hang_detect) :
+				   0,
+			.outsize = sizeof(struct ec_params_hang_detect),
+		},
+		.data.req = arg->req
+	};
+
+	ret = cros_ec_cmd_xfer_status(cros_ec, &buf.msg);
+	if (ret < 0)
+		return ret;
+
+	arg->resp = buf.data.resp;
+
+	return 0;
+}
+
+static int cros_ec_wdt_ping(struct watchdog_device *wdd)
+{
+	struct cros_ec_device *cros_ec = watchdog_get_drvdata(wdd);
+	union cros_ec_wdt_data arg;
+	int ret;
+
+	arg.req.command = EC_HANG_DETECT_CMD_RELOAD;
+	ret = cros_ec_wdt_send_cmd(cros_ec, &arg);
+	if (ret < 0)
+		dev_dbg(wdd->parent, "Failed to ping watchdog (%d)", ret);
+
+	return ret;
+}
+
+static int cros_ec_wdt_start(struct watchdog_device *wdd)
+{
+	struct cros_ec_device *cros_ec = watchdog_get_drvdata(wdd);
+	union cros_ec_wdt_data arg;
+	int ret;
+
+	/* Prepare watchdog on EC side */
+	arg.req.command = EC_HANG_DETECT_CMD_SET_TIMEOUT;
+	arg.req.reboot_timeout_sec = wdd->timeout;
+	ret = cros_ec_wdt_send_cmd(cros_ec, &arg);
+	if (ret < 0)
+		dev_dbg(wdd->parent, "Failed to start watchdog (%d)", ret);
+
+	return ret;
+}
+
+static int cros_ec_wdt_stop(struct watchdog_device *wdd)
+{
+	struct cros_ec_device *cros_ec = watchdog_get_drvdata(wdd);
+	union cros_ec_wdt_data arg;
+	int ret;
+
+	arg.req.command = EC_HANG_DETECT_CMD_CANCEL;
+	ret = cros_ec_wdt_send_cmd(cros_ec, &arg);
+	if (ret < 0)
+		dev_dbg(wdd->parent, "Failed to stop watchdog (%d)", ret);
+
+	return ret;
+}
+
+static int cros_ec_wdt_set_timeout(struct watchdog_device *wdd, unsigned int t)
+{
+	unsigned int old_timeout = wdd->timeout;
+	int ret;
+
+	wdd->timeout = t;
+	ret = cros_ec_wdt_start(wdd);
+	if (ret < 0)
+		wdd->timeout = old_timeout;
+
+	return ret;
+}
+
+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 int cros_ec_wdt_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct cros_ec_dev *ec_dev = dev_get_drvdata(dev->parent);
+	struct cros_ec_device *cros_ec = ec_dev->ec_dev;
+	struct watchdog_device *wdd;
+	union cros_ec_wdt_data arg;
+	int ret = 0;
+
+	wdd = devm_kzalloc(&pdev->dev, sizeof(struct watchdog_device), GFP_KERNEL);
+	if (!wdd)
+		return -ENOMEM;
+
+	arg.req.command = EC_HANG_DETECT_CMD_GET_STATUS;
+	ret = cros_ec_wdt_send_cmd(cros_ec, &arg);
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "Failed to get watchdog bootstatus");
+
+	wdd->parent = &pdev->dev;
+	wdd->info = &cros_ec_wdt_ident;
+	wdd->ops = &cros_ec_wdt_ops;
+	wdd->timeout = CROS_EC_WATCHDOG_DEFAULT_TIME;
+	wdd->min_timeout = EC_HANG_DETECT_MIN_TIMEOUT;
+	wdd->max_timeout = EC_HANG_DETECT_MAX_TIMEOUT;
+	if (arg.resp.status == EC_HANG_DETECT_AP_BOOT_EC_WDT)
+		wdd->bootstatus = WDIOF_CARDRESET;
+
+	arg.req.command = EC_HANG_DETECT_CMD_CLEAR_STATUS;
+	ret = cros_ec_wdt_send_cmd(cros_ec, &arg);
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "Failed to clear watchdog bootstatus");
+
+	watchdog_stop_on_reboot(wdd);
+	watchdog_stop_on_unregister(wdd);
+	watchdog_set_drvdata(wdd, cros_ec);
+	platform_set_drvdata(pdev, wdd);
+
+	return devm_watchdog_register_device(dev, wdd);
+}
+
+static int __maybe_unused cros_ec_wdt_suspend(struct platform_device *pdev, pm_message_t state)
+{
+	struct watchdog_device *wdd = platform_get_drvdata(pdev);
+	int ret = 0;
+
+	if (watchdog_active(wdd))
+		ret = cros_ec_wdt_stop(wdd);
+
+	return ret;
+}
+
+static int __maybe_unused cros_ec_wdt_resume(struct platform_device *pdev)
+{
+	struct watchdog_device *wdd = platform_get_drvdata(pdev);
+	int ret = 0;
+
+	if (watchdog_active(wdd))
+		ret = cros_ec_wdt_start(wdd);
+
+	return ret;
+}
+
+static struct platform_driver cros_ec_wdt_driver = {
+	.probe		= cros_ec_wdt_probe,
+	.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);
+
+static const struct platform_device_id cros_ec_wdt_id[] = {
+	{ DRV_NAME, 0 },
+	{}
+};
+MODULE_DEVICE_TABLE(platform, cros_ec_wdt_id);
+MODULE_DESCRIPTION("Cros EC Watchdog Device Driver");
+MODULE_LICENSE("GPL");
-- 
2.43.0.429.g432eaa2c6b-goog


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 3/3] mfd: cros_ec: Register EC-based watchdog subdevice
  2024-01-18 19:53 [PATCH v2 0/3] Introduce EC-based watchdog Lukasz Majczak
  2024-01-18 19:53 ` [PATCH v2 1/3] platform/chrome: Update binary interface for " Lukasz Majczak
  2024-01-18 19:53 ` [PATCH v2 2/3] watchdog: Add ChromeOS EC-based watchdog driver Lukasz Majczak
@ 2024-01-18 19:53 ` Lukasz Majczak
  2024-01-18 23:44   ` Guenter Roeck
  2 siblings, 1 reply; 13+ messages in thread
From: Lukasz Majczak @ 2024-01-18 19:53 UTC (permalink / raw)
  To: Gwendal Grignou, Tzung-Bi Shih, Radoslaw Biernacki,
	Wim Van Sebroeck, Lee Jones, Benson Leung, Guenter Roeck,
	Krzysztof Kozlowski, linux-watchdog, linux-kernel,
	chrome-platform
  Cc: Lukasz Majczak

Add ChromeOS EC-based watchdog as EC subdevice.

Signed-off-by: Lukasz Majczak <lma@chromium.org>
---
 drivers/mfd/cros_ec_dev.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/mfd/cros_ec_dev.c b/drivers/mfd/cros_ec_dev.c
index 603b1cd52785..d0140a285f69 100644
--- a/drivers/mfd/cros_ec_dev.c
+++ b/drivers/mfd/cros_ec_dev.c
@@ -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[] = {
-- 
2.43.0.429.g432eaa2c6b-goog


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 1/3] platform/chrome: Update binary interface for EC-based watchdog
  2024-01-18 19:53 ` [PATCH v2 1/3] platform/chrome: Update binary interface for " Lukasz Majczak
@ 2024-01-18 23:42   ` Guenter Roeck
  2024-01-19  3:41   ` Tzung-Bi Shih
  1 sibling, 0 replies; 13+ messages in thread
From: Guenter Roeck @ 2024-01-18 23:42 UTC (permalink / raw)
  To: Lukasz Majczak
  Cc: Gwendal Grignou, Tzung-Bi Shih, Radoslaw Biernacki,
	Wim Van Sebroeck, Lee Jones, Benson Leung, Guenter Roeck,
	Krzysztof Kozlowski, linux-watchdog, linux-kernel,
	chrome-platform

On Thu, Jan 18, 2024 at 07:53:22PM +0000, Lukasz Majczak wrote:
> Update structures and defines related to EC_CMD_HANG_DETECT
> to allow usage of new EC-based watchdog.
> 
> Signed-off-by: Lukasz Majczak <lma@chromium.org>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  .../linux/platform_data/cros_ec_commands.h    | 78 +++++++++----------
>  1 file changed, 35 insertions(+), 43 deletions(-)
> 
> diff --git a/include/linux/platform_data/cros_ec_commands.h b/include/linux/platform_data/cros_ec_commands.h
> index 7dae17b62a4d..ecc47d5fe239 100644
> --- a/include/linux/platform_data/cros_ec_commands.h
> +++ b/include/linux/platform_data/cros_ec_commands.h
> @@ -3961,60 +3961,52 @@ 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
> +#define EC_HANG_DETECT_MAX_TIMEOUT 65535
>  
> -/* 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,
>  
> -/* 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,
>  
> -/* 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 hang 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;
> +	uint16_t command; /* enum ec_hang_detect_cmds */
> +	/* Timeout in seconds before generating reboot */
> +	uint16_t reboot_timeout_sec;
> +} __ec_align2;
>  
> -	/* Timeout in msec before generating warm reboot, if enabled */
> -	uint16_t warm_reboot_timeout_msec;
> -} __ec_align4;
> +/* 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 */
>  
> -- 
> 2.43.0.429.g432eaa2c6b-goog
> 
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 2/3] watchdog: Add ChromeOS EC-based watchdog driver
  2024-01-18 19:53 ` [PATCH v2 2/3] watchdog: Add ChromeOS EC-based watchdog driver Lukasz Majczak
@ 2024-01-18 23:44   ` Guenter Roeck
  2024-01-19  3:42   ` Tzung-Bi Shih
  1 sibling, 0 replies; 13+ messages in thread
From: Guenter Roeck @ 2024-01-18 23:44 UTC (permalink / raw)
  To: Lukasz Majczak
  Cc: Gwendal Grignou, Tzung-Bi Shih, Radoslaw Biernacki,
	Wim Van Sebroeck, Lee Jones, Benson Leung, Guenter Roeck,
	Krzysztof Kozlowski, linux-watchdog, linux-kernel,
	chrome-platform

On Thu, Jan 18, 2024 at 07:53:23PM +0000, Lukasz Majczak wrote:
> Embedded Controller (EC) present on Chromebook devices
> can be used as a watchdog.
> Implement a driver to support it.
> 
> Signed-off-by: Lukasz Majczak <lma@chromium.org>

Nits:

> +#define CROS_EC_WATCHDOG_DEFAULT_TIME 30 /* seconds */
> +#define DRV_NAME "cros-ec-wdt-drv"

#define<space>NAME<tab>value

please, and "-drv" in the driver name is really unnecessary.

With that changed,

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

Thanks,
Guenter

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 3/3] mfd: cros_ec: Register EC-based watchdog subdevice
  2024-01-18 19:53 ` [PATCH v2 3/3] mfd: cros_ec: Register EC-based watchdog subdevice Lukasz Majczak
@ 2024-01-18 23:44   ` Guenter Roeck
  2024-01-19  8:36     ` Łukasz Majczak
  0 siblings, 1 reply; 13+ messages in thread
From: Guenter Roeck @ 2024-01-18 23:44 UTC (permalink / raw)
  To: Lukasz Majczak
  Cc: Gwendal Grignou, Tzung-Bi Shih, Radoslaw Biernacki,
	Wim Van Sebroeck, Lee Jones, Benson Leung, Guenter Roeck,
	Krzysztof Kozlowski, linux-watchdog, linux-kernel,
	chrome-platform

On Thu, Jan 18, 2024 at 07:53:24PM +0000, Lukasz Majczak wrote:
> Add ChromeOS EC-based watchdog as EC subdevice.
> 
> Signed-off-by: Lukasz Majczak <lma@chromium.org>
> ---
>  drivers/mfd/cros_ec_dev.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/mfd/cros_ec_dev.c b/drivers/mfd/cros_ec_dev.c
> index 603b1cd52785..d0140a285f69 100644
> --- a/drivers/mfd/cros_ec_dev.c
> +++ b/drivers/mfd/cros_ec_dev.c
> @@ -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", }

Assuming you drop "-drv",

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

Thanks,
Guenter

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 1/3] platform/chrome: Update binary interface for EC-based watchdog
  2024-01-18 19:53 ` [PATCH v2 1/3] platform/chrome: Update binary interface for " Lukasz Majczak
  2024-01-18 23:42   ` Guenter Roeck
@ 2024-01-19  3:41   ` Tzung-Bi Shih
  2024-01-19  8:34     ` Łukasz Majczak
  1 sibling, 1 reply; 13+ messages in thread
From: Tzung-Bi Shih @ 2024-01-19  3:41 UTC (permalink / raw)
  To: Lukasz Majczak
  Cc: Gwendal Grignou, Radoslaw Biernacki, Wim Van Sebroeck, Lee Jones,
	Benson Leung, Guenter Roeck, Krzysztof Kozlowski, linux-watchdog,
	linux-kernel, chrome-platform

On Thu, Jan 18, 2024 at 07:53:22PM +0000, Lukasz Majczak wrote:
> +#define EC_HANG_DETECT_MIN_TIMEOUT 5
> +#define EC_HANG_DETECT_MAX_TIMEOUT 65535

EC_HANG_DETECT_MAX_TIMEOUT isn't in the latest ec_commands.h [1].  Could you
either add EC_HANG_DETECT_MAX_TIMEOUT to ec_commands.h or drop the macro here?

[1] https://crrev.com/5a76e67210b15fcf67d8a6f90439993598949ae4/include/ec_commands.h#4749

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 2/3] watchdog: Add ChromeOS EC-based watchdog driver
  2024-01-18 19:53 ` [PATCH v2 2/3] watchdog: Add ChromeOS EC-based watchdog driver Lukasz Majczak
  2024-01-18 23:44   ` Guenter Roeck
@ 2024-01-19  3:42   ` Tzung-Bi Shih
  2024-01-19  3:55     ` Guenter Roeck
  1 sibling, 1 reply; 13+ messages in thread
From: Tzung-Bi Shih @ 2024-01-19  3:42 UTC (permalink / raw)
  To: Lukasz Majczak
  Cc: Gwendal Grignou, Radoslaw Biernacki, Wim Van Sebroeck, Lee Jones,
	Benson Leung, Guenter Roeck, Krzysztof Kozlowski, linux-watchdog,
	linux-kernel, chrome-platform

On Thu, Jan 18, 2024 at 07:53:23PM +0000, Lukasz Majczak wrote:
> diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
> index 7d22051b15a2..4700b218340f 100644
> --- a/drivers/watchdog/Kconfig
> +++ b/drivers/watchdog/Kconfig
> @@ -181,6 +181,17 @@ config BD957XMUF_WATCHDOG
>  	  watchdog. Alternatively say M to compile the driver as a module,
>  	  which will be called bd9576_wdt.
>  
> +config CROS_EC_WATCHDOG
> +	tristate "ChromeOS EC-based watchdog"
> +	select WATCHDOG_CORE
> +	depends on CROS_EC
> +	help
> +	  Watchdog driver for Chromebook devices equipped with embedded controller.
> +	  Trigger event is recorded in EC and checked on the subsequent boot.

Perhaps unrelated to the patch, but I'm curious what the mechanism is.  Does
it use any existing paths for checking the saved events in EC?  What it does
if there is a saved WDT reset event?

> diff --git a/drivers/watchdog/cros_ec_wdt.c b/drivers/watchdog/cros_ec_wdt.c
[...]
> +static int cros_ec_wdt_ping(struct watchdog_device *wdd)
> +{
[...]
> +	arg.req.command = EC_HANG_DETECT_CMD_RELOAD;
> +	ret = cros_ec_wdt_send_cmd(cros_ec, &arg);
> +	if (ret < 0)
> +		dev_dbg(wdd->parent, "Failed to ping watchdog (%d)", ret);

I think this would be worth dev_info() or dev_warn()?

> +static int cros_ec_wdt_start(struct watchdog_device *wdd)
> +{
[...]
> +	/* Prepare watchdog on EC side */
> +	arg.req.command = EC_HANG_DETECT_CMD_SET_TIMEOUT;
> +	arg.req.reboot_timeout_sec = wdd->timeout;
> +	ret = cros_ec_wdt_send_cmd(cros_ec, &arg);
> +	if (ret < 0)
> +		dev_dbg(wdd->parent, "Failed to start watchdog (%d)", ret);

Same here: dev_info() or dev_warn()?

> +static int cros_ec_wdt_stop(struct watchdog_device *wdd)
> +{
[...]
> +	arg.req.command = EC_HANG_DETECT_CMD_CANCEL;
> +	ret = cros_ec_wdt_send_cmd(cros_ec, &arg);
> +	if (ret < 0)
> +		dev_dbg(wdd->parent, "Failed to stop watchdog (%d)", ret);

Same here: dev_info() or dev_warn()?

> +static int cros_ec_wdt_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct cros_ec_dev *ec_dev = dev_get_drvdata(dev->parent);
> +	struct cros_ec_device *cros_ec = ec_dev->ec_dev;
> +	struct watchdog_device *wdd;
> +	union cros_ec_wdt_data arg;
> +	int ret = 0;

nit: `ret` doesn't need to be initialized.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 2/3] watchdog: Add ChromeOS EC-based watchdog driver
  2024-01-19  3:42   ` Tzung-Bi Shih
@ 2024-01-19  3:55     ` Guenter Roeck
  2024-01-19  5:28       ` Tzung-Bi Shih
  0 siblings, 1 reply; 13+ messages in thread
From: Guenter Roeck @ 2024-01-19  3:55 UTC (permalink / raw)
  To: Tzung-Bi Shih, Lukasz Majczak
  Cc: Gwendal Grignou, Radoslaw Biernacki, Wim Van Sebroeck, Lee Jones,
	Benson Leung, Guenter Roeck, Krzysztof Kozlowski, linux-watchdog,
	linux-kernel, chrome-platform

On 1/18/24 19:42, Tzung-Bi Shih wrote:
> On Thu, Jan 18, 2024 at 07:53:23PM +0000, Lukasz Majczak wrote:
>> diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
>> index 7d22051b15a2..4700b218340f 100644
>> --- a/drivers/watchdog/Kconfig
>> +++ b/drivers/watchdog/Kconfig
>> @@ -181,6 +181,17 @@ config BD957XMUF_WATCHDOG
>>   	  watchdog. Alternatively say M to compile the driver as a module,
>>   	  which will be called bd9576_wdt.
>>   
>> +config CROS_EC_WATCHDOG
>> +	tristate "ChromeOS EC-based watchdog"
>> +	select WATCHDOG_CORE
>> +	depends on CROS_EC
>> +	help
>> +	  Watchdog driver for Chromebook devices equipped with embedded controller.
>> +	  Trigger event is recorded in EC and checked on the subsequent boot.
> 
> Perhaps unrelated to the patch, but I'm curious what the mechanism is.  Does
> it use any existing paths for checking the saved events in EC?  What it does
> if there is a saved WDT reset event?
> 

Reporting the reason of the previous reset/restart is part of the watchdog API.

>> diff --git a/drivers/watchdog/cros_ec_wdt.c b/drivers/watchdog/cros_ec_wdt.c
> [...]
>> +static int cros_ec_wdt_ping(struct watchdog_device *wdd)
>> +{
> [...]
>> +	arg.req.command = EC_HANG_DETECT_CMD_RELOAD;
>> +	ret = cros_ec_wdt_send_cmd(cros_ec, &arg);
>> +	if (ret < 0)
>> +		dev_dbg(wdd->parent, "Failed to ping watchdog (%d)", ret);
> 
> I think this would be worth dev_info() or dev_warn()?
> 
>> +static int cros_ec_wdt_start(struct watchdog_device *wdd)
>> +{
> [...]
>> +	/* Prepare watchdog on EC side */
>> +	arg.req.command = EC_HANG_DETECT_CMD_SET_TIMEOUT;
>> +	arg.req.reboot_timeout_sec = wdd->timeout;
>> +	ret = cros_ec_wdt_send_cmd(cros_ec, &arg);
>> +	if (ret < 0)
>> +		dev_dbg(wdd->parent, "Failed to start watchdog (%d)", ret);
> 
> Same here: dev_info() or dev_warn()?
> 

We had that before. It is just noise. If it fails, it will likely
fail continuously, causing log spam. We don't do that kind of
continuous error messages for other watchdog drivers and should not
start doing it here.

Thanks,
Guenter


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 2/3] watchdog: Add ChromeOS EC-based watchdog driver
  2024-01-19  3:55     ` Guenter Roeck
@ 2024-01-19  5:28       ` Tzung-Bi Shih
  0 siblings, 0 replies; 13+ messages in thread
From: Tzung-Bi Shih @ 2024-01-19  5:28 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Lukasz Majczak, Gwendal Grignou, Radoslaw Biernacki,
	Wim Van Sebroeck, Lee Jones, Benson Leung, Guenter Roeck,
	Krzysztof Kozlowski, linux-watchdog, linux-kernel,
	chrome-platform

On Thu, Jan 18, 2024 at 07:55:39PM -0800, Guenter Roeck wrote:
> On 1/18/24 19:42, Tzung-Bi Shih wrote:
> > On Thu, Jan 18, 2024 at 07:53:23PM +0000, Lukasz Majczak wrote:
> > > diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
> > > index 7d22051b15a2..4700b218340f 100644
> > > --- a/drivers/watchdog/Kconfig
> > > +++ b/drivers/watchdog/Kconfig
> > > @@ -181,6 +181,17 @@ config BD957XMUF_WATCHDOG
> > >   	  watchdog. Alternatively say M to compile the driver as a module,
> > >   	  which will be called bd9576_wdt.
> > > +config CROS_EC_WATCHDOG
> > > +	tristate "ChromeOS EC-based watchdog"
> > > +	select WATCHDOG_CORE
> > > +	depends on CROS_EC
> > > +	help
> > > +	  Watchdog driver for Chromebook devices equipped with embedded controller.
> > > +	  Trigger event is recorded in EC and checked on the subsequent boot.
> > 
> > Perhaps unrelated to the patch, but I'm curious what the mechanism is.  Does
> > it use any existing paths for checking the saved events in EC?  What it does
> > if there is a saved WDT reset event?
> > 
> 
> Reporting the reason of the previous reset/restart is part of the watchdog API.

Oh, I see.  It is in cros_ec_wdt_probe(): `wdd->bootstatus`.

+static int cros_ec_wdt_probe(struct platform_device *pdev)
+{
[...]
+	arg.req.command = EC_HANG_DETECT_CMD_GET_STATUS;
+	ret = cros_ec_wdt_send_cmd(cros_ec, &arg);
[...]
+	if (arg.resp.status == EC_HANG_DETECT_AP_BOOT_EC_WDT)
+		wdd->bootstatus = WDIOF_CARDRESET;

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 1/3] platform/chrome: Update binary interface for EC-based watchdog
  2024-01-19  3:41   ` Tzung-Bi Shih
@ 2024-01-19  8:34     ` Łukasz Majczak
  0 siblings, 0 replies; 13+ messages in thread
From: Łukasz Majczak @ 2024-01-19  8:34 UTC (permalink / raw)
  To: Tzung-Bi Shih
  Cc: Gwendal Grignou, Radoslaw Biernacki, Wim Van Sebroeck, Lee Jones,
	Benson Leung, Guenter Roeck, Krzysztof Kozlowski, linux-watchdog,
	linux-kernel, chrome-platform

On Fri, Jan 19, 2024 at 4:41 AM Tzung-Bi Shih <tzungbi@kernel.org> wrote:
>
> On Thu, Jan 18, 2024 at 07:53:22PM +0000, Lukasz Majczak wrote:
> > +#define EC_HANG_DETECT_MIN_TIMEOUT 5
> > +#define EC_HANG_DETECT_MAX_TIMEOUT 65535
>
> EC_HANG_DETECT_MAX_TIMEOUT isn't in the latest ec_commands.h [1].  Could you
> either add EC_HANG_DETECT_MAX_TIMEOUT to ec_commands.h or drop the macro here?
>
> [1] https://crrev.com/5a76e67210b15fcf67d8a6f90439993598949ae4/include/ec_commands.h#4749

Yes, I will update ec_commands.h on the EC-side to match above
definitions although it doesn't influence any logic on the EC side.

Best regards
Lukasz

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 3/3] mfd: cros_ec: Register EC-based watchdog subdevice
  2024-01-18 23:44   ` Guenter Roeck
@ 2024-01-19  8:36     ` Łukasz Majczak
  0 siblings, 0 replies; 13+ messages in thread
From: Łukasz Majczak @ 2024-01-19  8:36 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Gwendal Grignou, Tzung-Bi Shih, Radoslaw Biernacki,
	Wim Van Sebroeck, Lee Jones, Benson Leung, Guenter Roeck,
	Krzysztof Kozlowski, linux-watchdog, linux-kernel,
	chrome-platform

> Assuming you drop "-drv",
>
> Reviewed-by: Guenter Roeck <linux@roeck-us.net>
>
> Thanks,
> Guenter

I will do so, thank you.

Best regards,
Lukasz

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-01-19  8:36 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-18 19:53 [PATCH v2 0/3] Introduce EC-based watchdog Lukasz Majczak
2024-01-18 19:53 ` [PATCH v2 1/3] platform/chrome: Update binary interface for " Lukasz Majczak
2024-01-18 23:42   ` Guenter Roeck
2024-01-19  3:41   ` Tzung-Bi Shih
2024-01-19  8:34     ` Łukasz Majczak
2024-01-18 19:53 ` [PATCH v2 2/3] watchdog: Add ChromeOS EC-based watchdog driver Lukasz Majczak
2024-01-18 23:44   ` Guenter Roeck
2024-01-19  3:42   ` Tzung-Bi Shih
2024-01-19  3:55     ` Guenter Roeck
2024-01-19  5:28       ` Tzung-Bi Shih
2024-01-18 19:53 ` [PATCH v2 3/3] mfd: cros_ec: Register EC-based watchdog subdevice Lukasz Majczak
2024-01-18 23:44   ` Guenter Roeck
2024-01-19  8:36     ` Łukasz Majczak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).