From patchwork Fri Jan 19 08:43:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?=C5=81ukasz_Majczak?= X-Patchwork-Id: 13523415 Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C2981E535 for ; Fri, 19 Jan 2024 08:43:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705653817; cv=none; b=NipjfN07KIDmBfJwOPSdZ07aPynnnog9wkIKOvMMZ9XaOyrMMznLU5nOVU+GqJ2HE69EF14yJua8dF8zUjifk4kdij+wsZwZeG2XA7LiN49XjNiAeyn9MKeAYHDOiqsDI1oRYw1pYe6AYbnkZFZi/RNWS0QXQALi63mkUb540CU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705653817; c=relaxed/simple; bh=PFKESGwT+52VOtSt0GyKDZV9D4/icQHM8Qc6/fiJ5to=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GRvl/7cLXRvgaThQ1YZeqUGsyRNBI7y0oxI3OvEv/SFe91YtWnc1+x/hDE0JmWxuUNCsvl5yglHqpUHKGZIIL3RaPoNuZRjtbcqKPMFmDEG2P4PD1/EekvyjVOldm1hdeol+3BDrYZaWAc6X2+vnU23Ug/ZmSd+fQXFzKsGHgp4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=JcgJmH/Z; arc=none smtp.client-ip=209.85.208.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="JcgJmH/Z" Received: by mail-lj1-f170.google.com with SMTP id 38308e7fff4ca-2cd33336b32so7252841fa.0 for ; Fri, 19 Jan 2024 00:43:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1705653813; x=1706258613; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=V8Jw334gbtlpfyMf//A4Kl+X5QTyArqRPZ+OYE2aYXw=; b=JcgJmH/ZUamO5lf2vlfraUpon6jWYMC+N1GW7Wqev9THV1ATPjfMX+0FNsuvQLUcXs O0zJ3Rz/ZTh/2zY5iWTFq6dPCwRxhtXNnKIHy8bEvvz0u8WteetOcH1R41DcgxQq3OWX x0dYoetdVdBTg6sPDNdNv/r2x3jk6Ann70RZo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705653813; x=1706258613; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V8Jw334gbtlpfyMf//A4Kl+X5QTyArqRPZ+OYE2aYXw=; b=EAG+Gqero6HpbFCY1JrTiFmMs8IUjRGp+D0aJsMW0/F15Msmjlukd1smC4lpt955nY 6aE9hBekIUekfWDPfLE8djNL+r/7S8IeVHgg74IG/UuoUOTv3KzPiwEKOWpEkr+H3xeu +YkCl1oxbVcnOuqBv/t2ICuNQdlZRyIUOdiMAUb+bGUOjhzVl07r/6LveBU2W0w37wUb IItRjO0W2t21nKKtgyw8rFNV6FqfaEwaBwgAucoaHl/Z19lGMJWeRjxrj1rg+/aYpKz9 qn4dVFNya1hDf2ig1ii0EmYoOTFdjGb5xP/KpkUd9Z4Uj7yxn328x0I9cCbDPsWOY3rr A0Og== X-Gm-Message-State: AOJu0Yyq58Zx3zBw1XiKm5FW8avbbcg0IswqBIF/JIFZ3rt2hn1Zmm8T KytoVzNl9DAeQq/SAGjKgPYqQ6xYMcLWbmTgzC0pZ2mUi3Yez1Xl2se2nKMOsA== X-Google-Smtp-Source: AGHT+IGIBDb//4zZKW1szACYww6QbXCrisECs5lZ66+O573YHzIQR1uK1qMig1Xr2ISC4DBr1N9I/w== X-Received: by 2002:ac2:464c:0:b0:50e:3479:3846 with SMTP id s12-20020ac2464c000000b0050e34793846mr474705lfo.68.1705653813409; Fri, 19 Jan 2024 00:43:33 -0800 (PST) Received: from cracow.c.googlers.com.com (138.58.228.35.bc.googleusercontent.com. [35.228.58.138]) by smtp.gmail.com with ESMTPSA id q23-20020ac246f7000000b0050e6aff6630sm905591lfo.152.2024.01.19.00.43.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 00:43:33 -0800 (PST) From: Lukasz Majczak To: Gwendal Grignou , Tzung-Bi Shih , Radoslaw Biernacki , Wim Van Sebroeck , Lee Jones , Benson Leung , Guenter Roeck , Krzysztof Kozlowski , linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev Cc: Lukasz Majczak Subject: [PATCH v3 1/3] platform/chrome: Update binary interface for EC-based watchdog Date: Fri, 19 Jan 2024 08:43:25 +0000 Message-ID: <20240119084328.3135503-2-lma@chromium.org> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog In-Reply-To: <20240119084328.3135503-1-lma@chromium.org> References: <20240119084328.3135503-1-lma@chromium.org> Precedence: bulk X-Mailing-List: linux-watchdog@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Update structures and defines related to EC_CMD_HANG_DETECT to allow usage of new EC-based watchdog. Signed-off-by: Lukasz Majczak --- .../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 */ From patchwork Fri Jan 19 08:43:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?=C5=81ukasz_Majczak?= X-Patchwork-Id: 13523416 Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 81BF21E534 for ; Fri, 19 Jan 2024 08:43:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705653818; cv=none; b=R+wlmNUyIJxYBvZ3qxgZkb0xZvG/7nztoQf+koxmPB9PJ9tz2aQKwp8ARAxpUVt5M6VeoAA3EBLcbZy3LBMJnu6N+tH3aFWIIgmiwiHjXPIC7uRT4R4zu3dgGOExH7h4R8L2STuGYs7yiOAYYYMzmJQsV7OiyKXbU1jsbcIFW7k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705653818; c=relaxed/simple; bh=ptf1HR9yRb1jC/RRprHqgf//qYN+lezB2C1lPxTDC1E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=p1Dzy5+TnGP8O6/w/+TdfuDUTVHlSErhTnR399aBJWybRiWTi+PzSPpGZhYX5ol/uwqx2gA6GKWEifCKE7lsoREM+/DVcF17DjTTQuyQbhHiszLLf4VVH7qM5dQo40kO+AurOfyyWhBlp2dgQ9bxTirs2h25hXJAFqDRPAFxU0Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=oNwvnVCj; arc=none smtp.client-ip=209.85.167.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="oNwvnVCj" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-50eab4bf47aso486341e87.0 for ; Fri, 19 Jan 2024 00:43:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1705653814; x=1706258614; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Et4CtZLo0Zs8wJbeGnnolJcmqvepEHLWSur8uVrZQBk=; b=oNwvnVCj56jxK6kvGa5xI70IyOWt6thG6VUd2/RbNE2bK1neztEaeJkMJGLToyNigP 7JeNv6lYdnC4cwyYCM3B4KHtXJtIkivfPbtD3zLdXqunjQNK7AXX44oOAN5BPjHrLa3Z lXvTjvUPXQgaBw+/V7VLec4VN2yZqaZDixBuw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705653814; x=1706258614; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Et4CtZLo0Zs8wJbeGnnolJcmqvepEHLWSur8uVrZQBk=; b=eH28RGI5KyOZ3xfGogccPY/nf5s9rLcDp+Mr6PgK8WiZDpDw8i0MUXAiVrqW1ujgcz jIT3PA7y6HOz9DtIHzQzK+o/yRLycMefXZCJbkUEuNRBH84GEscA5gAM4ElXfmwgzbiE 0jfzo8K3tnFkykDequa3v+g1AeQJ16M9Q5y8OAxYYbO5lK4+PJDvWEUL9YWdNaodQjRv mJagdBwb1ht/C84D7i5wpfa7HqVUNJTLDi47yatAa4HdqM3h6Yd6BH+xq3gVuSiZmRZV Bj9CA8SjqYCLH0CoDgXWUikHUdFO4/qivikqE4P0cOQtKDpYwCefi946vLXtGEoKK6S9 M6pA== X-Gm-Message-State: AOJu0YxTxcokBlmQUauz+XR97PA54ARBTcoDdEC/7nnKYYnpJX6Hpo8+ 6nQTCMWN0PesmCdUfP8KCGKNEm1b31X4ueMiALWiHfc1GoOIJQvNemFK6zUGZQ== X-Google-Smtp-Source: AGHT+IFYJwW224ISBqEbH1mxAWe2JvYdmTswXUM+MtTz4PbFSklOcWlQMDyWS5CnDgt7/6kndQxAJA== X-Received: by 2002:a05:6512:32a1:b0:50f:de3:b0a5 with SMTP id q1-20020a05651232a100b0050f0de3b0a5mr414682lfe.1.1705653814683; Fri, 19 Jan 2024 00:43:34 -0800 (PST) Received: from cracow.c.googlers.com.com (138.58.228.35.bc.googleusercontent.com. [35.228.58.138]) by smtp.gmail.com with ESMTPSA id q23-20020ac246f7000000b0050e6aff6630sm905591lfo.152.2024.01.19.00.43.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 00:43:34 -0800 (PST) From: Lukasz Majczak To: Gwendal Grignou , Tzung-Bi Shih , Radoslaw Biernacki , Wim Van Sebroeck , Lee Jones , Benson Leung , Guenter Roeck , Krzysztof Kozlowski , linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev Cc: Lukasz Majczak Subject: [PATCH v3 2/3] watchdog: Add ChromeOS EC-based watchdog driver Date: Fri, 19 Jan 2024 08:43:26 +0000 Message-ID: <20240119084328.3135503-3-lma@chromium.org> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog In-Reply-To: <20240119084328.3135503-1-lma@chromium.org> References: <20240119084328.3135503-1-lma@chromium.org> Precedence: bulk X-Mailing-List: linux-watchdog@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Embedded Controller (EC) present on Chromebook devices can be used as a watchdog. Implement a driver to support it. Signed-off-by: Lukasz Majczak --- 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ä S: Maintained F: drivers/platform/chrome/cros_hps_i2c.c +CHROMEOS EC WATCHDOG +M: Lukasz Majczak +L: chrome-platform@lists.linux.dev +S: Maintained +F: drivers/watchdog/cros_ec_wdt.c + CHRONTEL CH7322 CEC DRIVER M: Joe Tessler 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..d03eb0562e08 --- /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 + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#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(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"); From patchwork Fri Jan 19 08:43:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?=C5=81ukasz_Majczak?= X-Patchwork-Id: 13523417 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F398241EC for ; Fri, 19 Jan 2024 08:43:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705653819; cv=none; b=bW+0o4gIbKKaiYWIDaDokhNqX4T2t2JnitPeZhe7oAn8aDHXHjvDZoeGL7w1lhadqnH5f5dvRo/+0KLpoZDMZ6J4kjTRYT0SGq8jpgNHP6MdD1dpmMqszZuObmKWvuurKmdo3fU23nF5gUaNhBNJJB7vqc0IS9lkyiCRmktMo8U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705653819; c=relaxed/simple; bh=osSLkFHxCEi9lg/snRlEZT8CPmmDwFp84neEb75c09c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eLfzWtQ/tsCgzFLPyiYijLIlGwMGdulctNy59fherJ1J3Cp0j66agizbOnK+krXCH0bAsRJZGmJeGcMaMoA/tTOd3vMyiaB/nptM6gIRnOfX2o9hLN5K+bFkemvQ7xVZjkU77Lcoq5y+xUEs7owDiZvF/VGTwKREhu/2ulz/zyQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=liU1URIE; arc=none smtp.client-ip=209.85.167.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="liU1URIE" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-50e5a9bcec9so571837e87.3 for ; Fri, 19 Jan 2024 00:43:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1705653816; x=1706258616; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LriL7tXJHljhDBH+IF5gAskdccX7dSP4qzgOWwB59VY=; b=liU1URIEnmIUaeQuwkkVRL7XCuG6KJdqt2XTiv8U90rzJcwqn/TbJpETHliTG/FX+4 BTpSrXr9/suHqw+dEcPqOmatS3aMaQtHGkYa7iuTr72EqeiviZ2cSLf8SpikDQ8TPSuX mFcSza51J5ASTDsnJKK2/QIVmdOcMhx2odcpY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705653816; x=1706258616; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LriL7tXJHljhDBH+IF5gAskdccX7dSP4qzgOWwB59VY=; b=lh8ogKZgbvmPs62r8XzndT26rZBN+ZCdKIzqEuxX2kdePhe1eolcheVhelxG6vYh6d X+jVP4xmzl9afUXCIkDjmY8U4EmLay+Lne+NqYLl3kmjuM8QuOapQd9bzQOjzvytNM5p tAJS+RHkvFw2T1BZXwYLzPpVKL2Kom3ENuACwlyxldWVxH3Q5CYEjzWjWQ1ugTH5eznf SdxAJ/NkpXse59RwWxFdPBgZz61THl/1J53z7MLEs70oMvXWpalagz8bsgTgUKuDfGgS NbmRiAznSIKrKPxZjC6nwdD6GyycDDVzyDMx7CJCInsjuQxCE+Onlf04F/ipN51PTnJh D9Zg== X-Gm-Message-State: AOJu0YwZcjTIh3bKqYvM3VcNmBlYCPbBV/W0l81r/7Rq9WY+5dwkzZId nN2eUt82vhjJ+hcJIH7JvwzQ2gOiqYAJxDGjAxcoR8G1aWvxRxvgGri2tC+GnQ== X-Google-Smtp-Source: AGHT+IFTIsShTsLVt2WoGAE/70+F7JfM4Qy0jMxOp/f9e/N031wHAWuBBM0NHSRyhAcB1H6QiaSrng== X-Received: by 2002:ac2:5627:0:b0:50e:7410:d293 with SMTP id b7-20020ac25627000000b0050e7410d293mr464015lff.135.1705653816543; Fri, 19 Jan 2024 00:43:36 -0800 (PST) Received: from cracow.c.googlers.com.com (138.58.228.35.bc.googleusercontent.com. [35.228.58.138]) by smtp.gmail.com with ESMTPSA id q23-20020ac246f7000000b0050e6aff6630sm905591lfo.152.2024.01.19.00.43.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 00:43:36 -0800 (PST) From: Lukasz Majczak To: Gwendal Grignou , Tzung-Bi Shih , Radoslaw Biernacki , Wim Van Sebroeck , Lee Jones , Benson Leung , Guenter Roeck , Krzysztof Kozlowski , linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev Cc: Lukasz Majczak Subject: [PATCH v3 3/3] mfd: cros_ec: Register EC-based watchdog subdevice Date: Fri, 19 Jan 2024 08:43:27 +0000 Message-ID: <20240119084328.3135503-4-lma@chromium.org> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog In-Reply-To: <20240119084328.3135503-1-lma@chromium.org> References: <20240119084328.3135503-1-lma@chromium.org> Precedence: bulk X-Mailing-List: linux-watchdog@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add ChromeOS EC-based watchdog as EC subdevice. Signed-off-by: Lukasz Majczak --- 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..4996220ce64b 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", } +}; + 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[] = {