2024-01-26 10:44:56

by Łukasz Majczak

[permalink] [raw]
Subject: [PATCH v4 0/3] Introduce EC-based watchdog

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.

V1:https://patchwork.kernel.org/project/linux-watchdog/patch/[email protected]/
V2:https://patchwork.kernel.org/project/linux-watchdog/list/?series=817925
V3:https://patchwork.kernel.org/project/linux-watchdog/list/?series=818036

Changelog
V3->V4:
* updated sizeof() argument with pointer dereference
* added cros_ec_wdt_id to the driver structure
* "mfd: cros_ec: Register EC-based watchdog subdevice"
has been already applied to the for-mfd-next
V2->V3:
* drop "-drv" from driver name
* use format #define<space>NAME<tab>value
V1->V2:
* Split 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 | 204 ++++++++++++++++++
.../linux/platform_data/cros_ec_commands.h | 78 +++----
6 files changed, 266 insertions(+), 43 deletions(-)
create mode 100644 drivers/watchdog/cros_ec_wdt.c

--
2.43.0.429.g432eaa2c6b-goog



2024-01-26 10:45:26

by Łukasz Majczak

[permalink] [raw]
Subject: [PATCH v4 2/3] watchdog: Add ChromeOS EC-based watchdog driver

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

Signed-off-by: Lukasz Majczak <[email protected]>
---
MAINTAINERS | 6 +
drivers/watchdog/Kconfig | 11 ++
drivers/watchdog/Makefile | 1 +
drivers/watchdog/cros_ec_wdt.c | 204 +++++++++++++++++++++++++++++++++
4 files changed, 222 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ä <[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]
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..ba045e29f9a5
--- /dev/null
+++ b/drivers/watchdog/cros_ec_wdt.c
@@ -0,0 +1,204 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2024 Google LLC.
+ * Author: Lukasz Majczak <[email protected]>
+ */
+
+#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"
+
+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(*wdd), 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 const struct platform_device_id cros_ec_wdt_id[] = {
+ { DRV_NAME, 0 },
+ {}
+};
+
+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,
+ },
+ .id_table = cros_ec_wdt_id,
+};
+
+module_platform_driver(cros_ec_wdt_driver);
+
+MODULE_DEVICE_TABLE(platform, cros_ec_wdt_id);
+MODULE_DESCRIPTION("Cros EC Watchdog Device Driver");
+MODULE_LICENSE("GPL");
--
2.43.0.429.g432eaa2c6b-goog


2024-01-27 16:26:51

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v4 2/3] watchdog: Add ChromeOS EC-based watchdog driver

On Fri, Jan 26, 2024 at 09:57:20AM +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 <[email protected]>

Reviewed-by: Guenter Roeck <[email protected]>

Note that this should have been patch 2/2 (since the last patch
of the series has beel applied and is no longer part of the series).

Thanks,
Guenter

2024-02-01 13:07:28

by Lee Jones

[permalink] [raw]
Subject: [GIT PULL] Immutable branch between MFD, CROS and Watchdog due for the v6.9 merge window

Good afternoon,

The following changes since commit 6613476e225e090cc9aad49be7fa504e290dd33d:

Linux 6.8-rc1 (2024-01-21 14:11:32 -0800)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git ib-mfd-cros-watchdog-v6.9

for you to fetch changes up to 843dac4d3687f7628ba4f76e1481ee3838b27a35:

watchdog: Add ChromeOS EC-based watchdog driver (2024-02-01 11:49:30 +0000)

----------------------------------------------------------------
Immutable branch between MFD, CROS and Watchdog due for the v6.9 merge window

----------------------------------------------------------------
Lukasz Majczak (2):
platform/chrome: Update binary interface for EC-based watchdog
watchdog: Add ChromeOS EC-based watchdog driver

MAINTAINERS | 6 +
drivers/watchdog/Kconfig | 11 ++
drivers/watchdog/Makefile | 1 +
drivers/watchdog/cros_ec_wdt.c | 204 +++++++++++++++++++++++++
include/linux/platform_data/cros_ec_commands.h | 78 +++++-----
5 files changed, 257 insertions(+), 43 deletions(-)
create mode 100644 drivers/watchdog/cros_ec_wdt.c

--
Lee Jones [李琼斯]

2024-02-02 12:47:49

by Łukasz Majczak

[permalink] [raw]
Subject: Re: [GIT PULL] Immutable branch between MFD, CROS and Watchdog due for the v6.9 merge window

On Thu, Feb 1, 2024 at 2:06 PM Lee Jones <[email protected]> wrote:
>
> Good afternoon,
>
> The following changes since commit 6613476e225e090cc9aad49be7fa504e290dd33d:
>
> Linux 6.8-rc1 (2024-01-21 14:11:32 -0800)
>
> are available in the Git repository at:
>
> git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git ib-mfd-cros-watchdog-v6.9
>
> for you to fetch changes up to 843dac4d3687f7628ba4f76e1481ee3838b27a35:
>
> watchdog: Add ChromeOS EC-based watchdog driver (2024-02-01 11:49:30 +0000)
>
> ----------------------------------------------------------------
> Immutable branch between MFD, CROS and Watchdog due for the v6.9 merge window
>
> ----------------------------------------------------------------
> Lukasz Majczak (2):
> platform/chrome: Update binary interface for EC-based watchdog
> watchdog: Add ChromeOS EC-based watchdog driver
>
> MAINTAINERS | 6 +
> drivers/watchdog/Kconfig | 11 ++
> drivers/watchdog/Makefile | 1 +
> drivers/watchdog/cros_ec_wdt.c | 204 +++++++++++++++++++++++++
> include/linux/platform_data/cros_ec_commands.h | 78 +++++-----
> 5 files changed, 257 insertions(+), 43 deletions(-)
> create mode 100644 drivers/watchdog/cros_ec_wdt.c
>
> --
> Lee Jones [李琼斯]

Hi Lee,

I'm about to sent V5 of patches:
* watchdog: Add ChromeOS EC-based watchdog driver
* platform/chrome: Update binary interface for EC-based watchdog
but I'm not sure how I should proceed - can I base those on the master
branch or shall I rebase on top of ib-mfd-cros-watchdog-v6.9?

Best regards,
Lukasz

2024-02-02 12:51:01

by Lee Jones

[permalink] [raw]
Subject: Re: [GIT PULL] Immutable branch between MFD, CROS and Watchdog due for the v6.9 merge window

On Fri, 02 Feb 2024, Łukasz Majczak wrote:

> On Thu, Feb 1, 2024 at 2:06 PM Lee Jones <[email protected]> wrote:
> >
> > Good afternoon,
> >
> > The following changes since commit 6613476e225e090cc9aad49be7fa504e290dd33d:
> >
> > Linux 6.8-rc1 (2024-01-21 14:11:32 -0800)
> >
> > are available in the Git repository at:
> >
> > git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git ib-mfd-cros-watchdog-v6.9
> >
> > for you to fetch changes up to 843dac4d3687f7628ba4f76e1481ee3838b27a35:
> >
> > watchdog: Add ChromeOS EC-based watchdog driver (2024-02-01 11:49:30 +0000)
> >
> > ----------------------------------------------------------------
> > Immutable branch between MFD, CROS and Watchdog due for the v6.9 merge window
> >
> > ----------------------------------------------------------------
> > Lukasz Majczak (2):
> > platform/chrome: Update binary interface for EC-based watchdog
> > watchdog: Add ChromeOS EC-based watchdog driver
> >
> > MAINTAINERS | 6 +
> > drivers/watchdog/Kconfig | 11 ++
> > drivers/watchdog/Makefile | 1 +
> > drivers/watchdog/cros_ec_wdt.c | 204 +++++++++++++++++++++++++
> > include/linux/platform_data/cros_ec_commands.h | 78 +++++-----
> > 5 files changed, 257 insertions(+), 43 deletions(-)
> > create mode 100644 drivers/watchdog/cros_ec_wdt.c
> >
> > --
> > Lee Jones [李琼斯]
>
> Hi Lee,
>
> I'm about to sent V5 of patches:
> * watchdog: Add ChromeOS EC-based watchdog driver
> * platform/chrome: Update binary interface for EC-based watchdog

These patches are applied, you cannot resend them.

If you need to make adjustments, please submit incremental changes.

> but I'm not sure how I should proceed - can I base those on the master
> branch or shall I rebase on top of ib-mfd-cros-watchdog-v6.9?

Unless it causes issues, I tend to work on Linux next.

--
Lee Jones [李琼斯]

Subject: Re: [PATCH v4 0/3] Introduce EC-based watchdog

Hello:

This series was applied to chrome-platform/linux.git (for-kernelci)
by Lee Jones <[email protected]>:

On Fri, 26 Jan 2024 09:57:18 +0000 you wrote:
> 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.
>
> V1:https://patchwork.kernel.org/project/linux-watchdog/patch/[email protected]/
> V2:https://patchwork.kernel.org/project/linux-watchdog/list/?series=817925
> V3:https://patchwork.kernel.org/project/linux-watchdog/list/?series=818036
>
> [...]

Here is the summary with links:
- [v4,1/3] platform/chrome: Update binary interface for EC-based watchdog
https://git.kernel.org/chrome-platform/c/4d2ff655fb85
- [v4,2/3] watchdog: Add ChromeOS EC-based watchdog driver
https://git.kernel.org/chrome-platform/c/843dac4d3687

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



Subject: Re: [PATCH v4 0/3] Introduce EC-based watchdog

Hello:

This series was applied to chrome-platform/linux.git (for-next)
by Lee Jones <[email protected]>:

On Fri, 26 Jan 2024 09:57:18 +0000 you wrote:
> 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.
>
> V1:https://patchwork.kernel.org/project/linux-watchdog/patch/[email protected]/
> V2:https://patchwork.kernel.org/project/linux-watchdog/list/?series=817925
> V3:https://patchwork.kernel.org/project/linux-watchdog/list/?series=818036
>
> [...]

Here is the summary with links:
- [v4,1/3] platform/chrome: Update binary interface for EC-based watchdog
https://git.kernel.org/chrome-platform/c/4d2ff655fb85
- [v4,2/3] watchdog: Add ChromeOS EC-based watchdog driver
https://git.kernel.org/chrome-platform/c/843dac4d3687

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html