Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DDE2C433F5 for ; Fri, 29 Oct 2021 03:18:29 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8472E60ED5 for ; Fri, 29 Oct 2021 03:18:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8472E60ED5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sholland.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 054CC8358A; Fri, 29 Oct 2021 05:18:24 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sholland.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=sholland.org header.i=@sholland.org header.b="EwfMAhvr"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="EYfCwBgP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 566628357F; Fri, 29 Oct 2021 05:17:24 +0200 (CEST) Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D7358835A3 for ; Fri, 29 Oct 2021 05:17:10 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sholland.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=samuel@sholland.org Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 196585C0190; Thu, 28 Oct 2021 23:17:10 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 28 Oct 2021 23:17:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=ItmYWHa6/lFk5 Eov0TcTj9sOdHxOHGlBrYcS+1aN29c=; b=EwfMAhvrK9uNwOxhqKPKR8GTb/jZq oY13CnSiIi4rtXl3rpOfb4E1Nq5RSo/gUxZIemEKNZBnVff0ACP/DR4mSA9kWQT9 rqQOxIIvlz8drGdYJgllcA/fzDknkpW4fZJZa7fYfPzmRAeZKjb1PW3jUQTy8lka UB5XbX7xGapg7FyYuy0tiytIFFywUJjjn7K441Q72zoeECl97tBHnmSnOmqvaT6F AZYCl9As14ke2tw9DnnH5qkJ1NDV7OQNkQQ0c8MSrtUxymO4AgAF5uZs7x+lljNK FzNUIkHNjxfnNDnrDkferxtte9X38hRNxp1QnFR4do6WhlSQOtOwRwg0A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=ItmYWHa6/lFk5Eov0TcTj9sOdHxOHGlBrYcS+1aN29c=; b=EYfCwBgP evT1FnE5ThvSQoSvt6bGb7yunn8NVeHxuZ69z9gqsm+k+1VXzMdYGs5N9XphOqPf WBLXNBqx7Bl6S3fIbnsDJ7846EFgRJvQYAjbodxB92xTe3GdTvqYAEE9P62ghQyh ledikBH/kVKL7lnNnYMnT67HSPu6Og5NgoL5PF9BW4JY/t1M/uvtD9zhLl+43ho3 j33EoJONh0XBhX90lpbzYk1sxpHcbrD4M9wpxEoooYDu1CC0O50Fy69kv+pQEJyB wRj/yPsG+jy9yEL1A8bRXX9OBADs1C+qCrt3Lo+L1yH9oSzDQBuwANxt0eHFGwHd xMGlfWLL2EV1vg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrvdeggedgieehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucggtf frrghtthgvrhhnpeduhfejfedvhffgfeehtefghfeiiefgfeehgfdvvdevfeegjeehjedv gfejheeuieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 28 Oct 2021 23:17:08 -0400 (EDT) From: Samuel Holland To: Stefan Roese , u-boot@lists.denx.de, Jagan Teki , Andre Przywara Cc: Bin Meng , Sean Anderson , Heinrich Schuchardt , Simon Glass , Samuel Holland Subject: [PATCH v2 4/6] watchdog: Automatically register device with sysreset Date: Thu, 28 Oct 2021 22:16:54 -0500 Message-Id: <20211029031656.24167-5-samuel@sholland.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211029031656.24167-1-samuel@sholland.org> References: <20211029031656.24167-1-samuel@sholland.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Add an option to automatically register watchdog devices with the wdt_reboot driver for use with sysreset. This allows sysreset to be a drop-in replacement for platform-specific watchdog reset code, without needing any device tree changes. Signed-off-by: Samuel Holland --- Changes in v2: - Rebase on top of 492ee6b8d0e7 (now handle all watchdogs). drivers/sysreset/Kconfig | 7 +++++++ drivers/sysreset/sysreset_watchdog.c | 24 ++++++++++++++++++++++++ drivers/watchdog/wdt-uclass.c | 5 +++++ include/sysreset.h | 14 ++++++++++++++ 4 files changed, 50 insertions(+) diff --git a/drivers/sysreset/Kconfig b/drivers/sysreset/Kconfig index de75c9cccc..f6d60038b8 100644 --- a/drivers/sysreset/Kconfig +++ b/drivers/sysreset/Kconfig @@ -131,6 +131,13 @@ config SYSRESET_WATCHDOG help Reboot support for generic watchdog reset. +config SYSRESET_WATCHDOG_AUTO + bool "Automatically register first watchdog with sysreset" + depends on SYSRESET_WATCHDOG + help + If enabled, the first watchdog (as selected by the watchdog uclass) + will automatically be registered with the watchdog reboot driver. + config SYSRESET_RESETCTL bool "Enable support for reset controller reboot driver" select DM_RESET diff --git a/drivers/sysreset/sysreset_watchdog.c b/drivers/sysreset/sysreset_watchdog.c index b723f5647c..35efcac59d 100644 --- a/drivers/sysreset/sysreset_watchdog.c +++ b/drivers/sysreset/sysreset_watchdog.c @@ -5,7 +5,9 @@ #include #include +#include #include +#include #include #include @@ -57,3 +59,25 @@ U_BOOT_DRIVER(wdt_reboot) = { .plat_auto = sizeof(struct wdt_reboot_plat), .ops = &wdt_reboot_ops, }; + +#if IS_ENABLED(CONFIG_SYSRESET_WATCHDOG_AUTO) +int sysreset_register_wdt(struct udevice *dev) +{ + struct wdt_reboot_plat *plat = malloc(sizeof(*plat)); + int ret; + + if (!plat) + return -ENOMEM; + + plat->wdt = dev; + + ret = device_bind(dev, DM_DRIVER_GET(wdt_reboot), + dev->name, plat, ofnode_null(), NULL); + if (ret) { + free(plat); + return ret; + } + + return 0; +} +#endif diff --git a/drivers/watchdog/wdt-uclass.c b/drivers/watchdog/wdt-uclass.c index 7570710c4d..985f114084 100644 --- a/drivers/watchdog/wdt-uclass.c +++ b/drivers/watchdog/wdt-uclass.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -44,6 +45,10 @@ static void init_watchdog_dev(struct udevice *dev) priv = dev_get_uclass_priv(dev); + ret = sysreset_register_wdt(dev); + if (ret) + printf("WDT: Failed to register sysreset\n"); + if (!IS_ENABLED(CONFIG_WATCHDOG_AUTOSTART)) { printf("WDT: Not starting %s\n", dev->name); return; diff --git a/include/sysreset.h b/include/sysreset.h index 9d4ed87cea..d0e63e6d2b 100644 --- a/include/sysreset.h +++ b/include/sysreset.h @@ -133,4 +133,18 @@ void sysreset_walk_halt(enum sysreset_t type); */ void reset_cpu(void); +/** + * sysreset_register_wdt() - register a watchdog for use with sysreset + * + * This registers the given watchdog timer to be used to reset the system. + * + * @dev: WDT device + * @return: 0 if OK, -errno if error + */ +#if IS_ENABLED(CONFIG_SYSRESET_WATCHDOG_AUTO) +int sysreset_register_wdt(struct udevice *dev); +#else +static inline int sysreset_register_wdt(struct udevice *dev) { return 0; } +#endif + #endif -- 2.32.0