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 13AE5C05027 for ; Thu, 26 Jan 2023 06:28:51 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BE3E0854DF; Thu, 26 Jan 2023 07:28:48 +0100 (CET) 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=1674714529; bh=HMhVZldgUzEGLzLmXfNhqGRdMNokBpZVVpyKB18OFes=; h=Date:Subject:To:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=jATJh6gYVK67GOukBaEFN6hS0B/AoDTXF7ANAh4GiqREKxqquwczl+2oosJ5xRUti j1ALW9maWczMk0d7k1kHJ08KRaU2cgfZggyhIJYrm2Z4o0pfQ5xy4fPacAqQi+M65W nCIZ8W1PVaCGdy+sO+FtpxHqWQhOa5bj4CPb6v3hdBBqHH8MlbPIEaANF8TADgneRl kEGLT5Z21kUuEWJc01Ia2heqeVOQ8AvPOhuAW5QRFr4jR6IjG+dbgh04goMSDplXy2 GHWOQXjPtplrJbBBbug3ujqfrryluB6iWKi5A80DWIT/TDAoSg2K/mMuYDccU5PFpY OQApqNzomD4hg== Received: by phobos.denx.de (Postfix, from userid 109) id E039D854F1; Thu, 26 Jan 2023 07:28:46 +0100 (CET) Received: from mout-u-107.mailbox.org (mout-u-107.mailbox.org [IPv6:2001:67c:2050:101:465::107]) (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 55614854C5 for ; Thu, 26 Jan 2023 07:28:44 +0100 (CET) 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 smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (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-107.mailbox.org (Postfix) with ESMTPS id 4P2W4V13W4z9sT2; Thu, 26 Jan 2023 07:28:42 +0100 (CET) Message-ID: Date: Thu, 26 Jan 2023 07:28:40 +0100 MIME-Version: 1.0 Subject: Re: [PATCH v3] watchdog: Add a watchdog driver for Raspberry Pi boards To: ETIENNE DUBLE , u-boot References: <567596241.308425.1674640648249.JavaMail.zimbra@univ-grenoble-alpes.fr> Content-Language: en-US From: Stefan Roese In-Reply-To: <567596241.308425.1674640648249.JavaMail.zimbra@univ-grenoble-alpes.fr> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 On 1/25/23 10:57, ETIENNE DUBLE wrote: > This driver supports the bcm2835 watchdog found on > Raspberry Pi boards. > It is derived from the Linux driver and was tested > on two Raspberry Pi board versions (B+ and 3B+). > > Signed-off-by: Etienne Dublé Reviewed-by: Stefan Roese Thanks, Stefan > --- > Changes for v2: > - fixed whitespaces in email > - moved a static variable to the priv struct > Changes for v3: > - used the max timeout value the hardware supports > - turned the warning to a one-line message > > drivers/watchdog/Kconfig | 9 +++ > drivers/watchdog/Makefile | 1 + > drivers/watchdog/bcm2835_wdt.c | 132 +++++++++++++++++++++++++++++++++ > 3 files changed, 142 insertions(+) > create mode 100644 drivers/watchdog/bcm2835_wdt.c > > diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig > index f1b1cf63ca..06c0d630c8 100644 > --- a/drivers/watchdog/Kconfig > +++ b/drivers/watchdog/Kconfig > @@ -30,6 +30,7 @@ config WATCHDOG_TIMEOUT_MSECS > default 128000 if ARCH_MX7 || ARCH_VF610 > default 30000 if ARCH_SOCFPGA > default 16000 if ARCH_SUNXI > + default 15000 if ARCH_BCM283X > default 60000 > help > Watchdog timeout in msec > @@ -326,6 +327,14 @@ config WDT_SUNXI > help > Enable support for the watchdog timer in Allwinner sunxi SoCs. > > +config WDT_BCM2835 > + bool "Broadcom 2835 watchdog timer support" > + depends on WDT && ARCH_BCM283X > + default y > + help > + Enable support for the watchdog timer in Broadcom 283X SoCs such > + as Raspberry Pi boards. > + > config XILINX_TB_WATCHDOG > bool "Xilinx Axi watchdog timer support" > depends on WDT > diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile > index 446d961d7d..f99915960c 100644 > --- a/drivers/watchdog/Makefile > +++ b/drivers/watchdog/Makefile > @@ -21,6 +21,7 @@ obj-$(CONFIG_WDT_APPLE) += apple_wdt.o > obj-$(CONFIG_WDT_ARMADA_37XX) += armada-37xx-wdt.o > obj-$(CONFIG_WDT_ASPEED) += ast_wdt.o > obj-$(CONFIG_WDT_AST2600) += ast2600_wdt.o > +obj-$(CONFIG_WDT_BCM2835) += bcm2835_wdt.o > obj-$(CONFIG_WDT_BCM6345) += bcm6345_wdt.o > obj-$(CONFIG_WDT_BOOKE) += booke_wdt.o > obj-$(CONFIG_WDT_CORTINA) += cortina_wdt.o > diff --git a/drivers/watchdog/bcm2835_wdt.c b/drivers/watchdog/bcm2835_wdt.c > new file mode 100644 > index 0000000000..3c1ead3dda > --- /dev/null > +++ b/drivers/watchdog/bcm2835_wdt.c > @@ -0,0 +1,132 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * Copyright (C) 2013 Lubomir Rintel > + * Copyright (C) 2023 Etienne Dublé (CNRS) > + * > + * This code is mostly derived from the linux driver. > + */ > + > +#include > +#include > +#include > +#include > + > +#define PM_RSTC 0x1c > +#define PM_WDOG 0x24 > + > +#define PM_PASSWORD 0x5a000000 > + > +/* The hardware supports a maximum timeout value of 0xfffff ticks > + * (just below 16 seconds). > + */ > +#define PM_WDOG_MAX_TICKS 0x000fffff > +#define PM_RSTC_WRCFG_CLR 0xffffffcf > +#define PM_RSTC_WRCFG_FULL_RESET 0x00000020 > +#define PM_RSTC_RESET 0x00000102 > + > +#define MS_TO_WDOG_TICKS(x) (((x) << 16) / 1000) > + > +struct bcm2835_wdt_priv { > + void __iomem *base; > + u64 timeout_ticks; > +}; > + > +static int bcm2835_wdt_start_ticks(struct udevice *dev, > + u64 timeout_ticks, ulong flags) > +{ > + struct bcm2835_wdt_priv *priv = dev_get_priv(dev); > + void __iomem *base = priv->base; > + u32 cur; > + > + writel(PM_PASSWORD | timeout_ticks, base + PM_WDOG); > + cur = readl(base + PM_RSTC); > + writel(PM_PASSWORD | (cur & PM_RSTC_WRCFG_CLR) | PM_RSTC_WRCFG_FULL_RESET, > + base + PM_RSTC); > + > + return 0; > +} > + > +static int bcm2835_wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags) > +{ > + struct bcm2835_wdt_priv *priv = dev_get_priv(dev); > + > + priv->timeout_ticks = MS_TO_WDOG_TICKS(timeout_ms); > + > + if (priv->timeout_ticks > PM_WDOG_MAX_TICKS) { > + printf("bcm2835_wdt: the timeout value is too high, using ~16s instead.\n"); > + priv->timeout_ticks = PM_WDOG_MAX_TICKS; > + } > + > + return bcm2835_wdt_start_ticks(dev, priv->timeout_ticks, flags); > +} > + > +static int bcm2835_wdt_reset(struct udevice *dev) > +{ > + struct bcm2835_wdt_priv *priv = dev_get_priv(dev); > + > + /* restart the timer with the value of priv->timeout_ticks > + * saved from the last bcm2835_wdt_start() call. > + */ > + return bcm2835_wdt_start_ticks(dev, priv->timeout_ticks, 0); > +} > + > +static int bcm2835_wdt_stop(struct udevice *dev) > +{ > + struct bcm2835_wdt_priv *priv = dev_get_priv(dev); > + void __iomem *base = priv->base; > + > + writel(PM_PASSWORD | PM_RSTC_RESET, base + PM_RSTC); > + > + return 0; > +} > + > +static int bcm2835_wdt_expire_now(struct udevice *dev, ulong flags) > +{ > + int ret; > + > + /* use a timeout of 10 ticks (~150us) */ > + ret = bcm2835_wdt_start_ticks(dev, 10, flags); > + if (ret) > + return ret; > + > + mdelay(500); > + > + return 0; > +} > + > +static const struct wdt_ops bcm2835_wdt_ops = { > + .reset = bcm2835_wdt_reset, > + .start = bcm2835_wdt_start, > + .stop = bcm2835_wdt_stop, > + .expire_now = bcm2835_wdt_expire_now, > +}; > + > +static const struct udevice_id bcm2835_wdt_ids[] = { > + { .compatible = "brcm,bcm2835-pm" }, > + { .compatible = "brcm,bcm2835-pm-wdt" }, > + { /* sentinel */ } > +}; > + > +static int bcm2835_wdt_probe(struct udevice *dev) > +{ > + struct bcm2835_wdt_priv *priv = dev_get_priv(dev); > + > + priv->base = dev_remap_addr(dev); > + if (!priv->base) > + return -EINVAL; > + > + priv->timeout_ticks = PM_WDOG_MAX_TICKS; > + > + bcm2835_wdt_stop(dev); > + > + return 0; > +} > + > +U_BOOT_DRIVER(bcm2835_wdt) = { > + .name = "bcm2835_wdt", > + .id = UCLASS_WDT, > + .of_match = bcm2835_wdt_ids, > + .probe = bcm2835_wdt_probe, > + .priv_auto = sizeof(struct bcm2835_wdt_priv), > + .ops = &bcm2835_wdt_ops, > +}; Viele Grüße, Stefan Roese -- DENX Software Engineering GmbH, Managing Director: Erika Unter HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr@denx.de