From mboxrd@z Thu Jan 1 00:00:00 1970 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 8772EC6FA86 for ; Sat, 17 Sep 2022 08:15:15 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B53D584B5A; Sat, 17 Sep 2022 10:15:00 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1663402501; bh=N3RRqsF/zXEx+YNJwVyeb+3l+WM5dvHzzeX6yIU/H88=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=fq/1ptZsbpGf6SjyoT20gz7XWre2T7VcwgJxEnlciNu5m5RWxR3lgY7j19QVZHvo+ YNlIf7VhQFvjI7OPTLa1lHDf9Gf2kKK/Mb+dUbqt/VnOugBBO1m5FNg0UEyyh7c6wN 4Oa5UpOWIylSO5wpM1n471gYiqmCnLnqqW1JEKM/gn5enHSgqrETzGXGiLTYiW0OHD YsjmXiUSimrAszi/oeIOqIgBi7HUUSx+MqnB7qDnZvM2G746wzT5PqPsS0CUU8oKbb /qXpHEiXyJwpNescufC1CBZl1aFkKrgJGibAet855CgM1Q+Nb6DcbUEcTZ8lEH+BZ8 IINVEhTJWhHQg== Received: by phobos.denx.de (Postfix, from userid 109) id 5E9F384BDE; Sat, 17 Sep 2022 10:14:56 +0200 (CEST) Received: from mout-u-204.mailbox.org (mout-u-204.mailbox.org [80.241.59.204]) (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 284A98495B for ; Sat, 17 Sep 2022 10:14:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sr@denx.de Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-204.mailbox.org (Postfix) with ESMTPS id 4MV3dS1y3Rz9sSS; Sat, 17 Sep 2022 10:14:52 +0200 (CEST) From: Stefan Roese To: u-boot@lists.denx.de Cc: trini@konsulko.com, sjg@chromium.org, rasmus.villemoes@prevas.dk Subject: [PATCH v2 1/6] watchdog: Integrate watchdog triggering into the cyclic framework Date: Sat, 17 Sep 2022 10:14:45 +0200 Message-Id: <20220917081450.21549-2-sr@denx.de> In-Reply-To: <20220917081450.21549-1-sr@denx.de> References: <20220917081450.21549-1-sr@denx.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4MV3dS1y3Rz9sSS X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.6 at phobos.denx.de X-Virus-Status: Clean This patch integrates the watchdog triggering into the recently added cyclic infrastructure. Each watchdog device that shall be triggered registers it's own cyclic function. This way, multiple watchdog devices are still supported, each via a cyclic function with separate trigger intervals. Signed-off-by: Stefan Roese Reviewed-by: Simon Glass --- v2: - Added Simon's RB tag v1: - Reword WDT logging at startup as suggested by Rasmus - Fail upon !priv->cyclic initr_watchdog() - Remove some superflous checks in wdt_cyclic() drivers/watchdog/Kconfig | 2 + drivers/watchdog/wdt-uclass.c | 73 ++++++++++++++++++++--------------- 2 files changed, 43 insertions(+), 32 deletions(-) diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 50e6a1efba51..e55deaf906b5 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -3,6 +3,7 @@ menu "Watchdog Timer Support" config WATCHDOG bool "Enable U-Boot watchdog reset" depends on !HW_WATCHDOG + select CYCLIC help This option enables U-Boot watchdog support where U-Boot is using watchdog_reset function to service watchdog device in U-Boot. Enable @@ -74,6 +75,7 @@ config WDT bool "Enable driver model for watchdog timer drivers" depends on DM imply WATCHDOG + select CYCLIC help Enable driver model for watchdog timer. At the moment the API is very simple and only supports four operations: diff --git a/drivers/watchdog/wdt-uclass.c b/drivers/watchdog/wdt-uclass.c index dbf556467d3c..3f342cd99fdd 100644 --- a/drivers/watchdog/wdt-uclass.c +++ b/drivers/watchdog/wdt-uclass.c @@ -6,6 +6,7 @@ #define LOG_CATEGORY UCLASS_WDT #include +#include #include #include #include @@ -38,8 +39,25 @@ struct wdt_priv { bool running; /* No autostart */ bool noautostart; + + struct cyclic_info *cyclic; }; +static void wdt_cyclic(void *ctx) +{ + struct udevice *dev = ctx; + struct wdt_priv *priv; + + if (!device_active(dev)) + return; + + priv = dev_get_uclass_priv(dev); + if (!priv->running) + return; + + wdt_reset(dev); +} + static void init_watchdog_dev(struct udevice *dev) { struct wdt_priv *priv; @@ -64,9 +82,6 @@ static void init_watchdog_dev(struct udevice *dev) printf("WDT: Failed to start %s\n", dev->name); return; } - - printf("WDT: Started %s with%s servicing (%ds timeout)\n", dev->name, - IS_ENABLED(CONFIG_WATCHDOG) ? "" : "out", priv->timeout); } int initr_watchdog(void) @@ -105,8 +120,29 @@ int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags) ret = ops->start(dev, timeout_ms, flags); if (ret == 0) { struct wdt_priv *priv = dev_get_uclass_priv(dev); + char str[16]; priv->running = true; + + memset(str, 0, 16); + if (IS_ENABLED(CONFIG_WATCHDOG)) { + /* Register the watchdog driver as a cyclic function */ + priv->cyclic = cyclic_register(wdt_cyclic, + priv->reset_period * 1000, + dev->name, dev); + if (!priv->cyclic) { + printf("cyclic_register for %s failed\n", + dev->name); + return -ENODEV; + } else { + snprintf(str, 16, "every %ldms", + priv->reset_period); + } + } + + printf("WDT: Started %s with%s servicing %s (%ds timeout)\n", + dev->name, IS_ENABLED(CONFIG_WATCHDOG) ? "" : "out", + str, priv->timeout); } return ret; @@ -194,37 +230,10 @@ int wdt_expire_now(struct udevice *dev, ulong flags) */ void watchdog_reset(void) { - struct wdt_priv *priv; - struct udevice *dev; - struct uclass *uc; - ulong now; - - /* Exit if GD is not ready or watchdog is not initialized yet */ - if (!gd || !(gd->flags & GD_FLG_WDT_READY)) - return; - - if (uclass_get(UCLASS_WDT, &uc)) - return; - /* - * All devices bound to the wdt uclass should have been probed - * in initr_watchdog(). But just in case something went wrong, - * check device_active() before accessing the uclass private - * data. + * Empty function for now. The actual WDT handling is now done in + * the cyclic function instead. */ - uclass_foreach_dev(dev, uc) { - if (!device_active(dev)) - continue; - priv = dev_get_uclass_priv(dev); - if (!priv->running) - continue; - /* Do not reset the watchdog too often */ - now = get_timer(0); - if (time_after_eq(now, priv->next_reset)) { - priv->next_reset = now + priv->reset_period; - wdt_reset(dev); - } - } } #endif -- 2.37.3