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 39FB6C77B73 for ; Thu, 20 Apr 2023 10:01:21 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 25532862F6; Thu, 20 Apr 2023 12:01:12 +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=1681984872; bh=5fIcII9MytwHbISDthkS/JB8FrK5NFEf8zViezVqEUQ=; h=Date:Subject:To:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=m8wrANaghvg0Zyp79dJ1VqpCWQeMqUKoMbbm0eTCcAdlvtBMHBWpz5SMeQ5GpKmiS TFlCNSbJnJLsnCq3YfcXEWPKCl7zwWkmhaNBbvKY/JW4rxkrKMLtCNz1WjxAI8qSWL A3DeJJCOjVDlq8MAu50twZWQSuuJuaiF7vPQdqW6x5WveL0btFcEbAK+5a664vsouC MFGfEk67+J/JMKs9EXr+n3huQ10y+irCsxoqbzmiBvpJntfVZXTDlufHwP+m6VkU4F BF23iQVwk3rYBjvADgcNh2yuu+txy/JX+C+tajl66LPmSCFnJhyotoZ5yxfVCMq4r7 FVYN2QoJPFbdQ== Received: by phobos.denx.de (Postfix, from userid 109) id 3229C81298; Thu, 20 Apr 2023 12:01:08 +0200 (CEST) Received: from mout-u-204.mailbox.org (mout-u-204.mailbox.org [IPv6:2001:67c:2050:101:465::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 BA924862E9 for ; Thu, 20 Apr 2023 12:01:05 +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 4Q2Cpl5xT4z9sZM; Thu, 20 Apr 2023 12:01:03 +0200 (CEST) Message-ID: Date: Thu, 20 Apr 2023 12:01:03 +0200 MIME-Version: 1.0 Subject: Re: [PATCH v2] watchdog: ftwdt010: return a previously deleted driver now ported to DM Content-Language: en-US To: Sergei Antonov , u-boot@lists.denx.de, trini@konsulko.com References: <20230412110158.33164-1-saproj@gmail.com> From: Stefan Roese In-Reply-To: <20230412110158.33164-1-saproj@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4Q2Cpl5xT4z9sZM 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.8 at phobos.denx.de X-Virus-Status: Clean On 4/12/23 13:01, Sergei Antonov wrote: > The ftwdt010 watchdog driver was deleted by > commit 11232139e399 ("nds32: Remove the architecture") > > Return it to the codebase in a DM compatible form. Enable it in > sandbox_defconfig to test compilability. > Another platform using ftwdt010 will be submitted later. > > Signed-off-by: Sergei Antonov > Reviewed-by: Stefan Roese Applied to u-boot-watchdog/master Thanks, Stefan > --- > > v2: > * "imply WATCHDOG" in Kconfig like other watchdog drivers do > * (by Stefan Roese) make .compatible string the same as in Linux driver > > configs/sandbox_defconfig | 1 + > drivers/watchdog/Kconfig | 7 ++ > drivers/watchdog/Makefile | 1 + > drivers/watchdog/ftwdt010_wdt.c | 132 ++++++++++++++++++++++++++++++++ > include/faraday/ftwdt010_wdt.h | 3 - > 5 files changed, 141 insertions(+), 3 deletions(-) > create mode 100644 drivers/watchdog/ftwdt010_wdt.c > > diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig > index cbace259f8..1025aa9fe9 100644 > --- a/configs/sandbox_defconfig > +++ b/configs/sandbox_defconfig > @@ -322,6 +322,7 @@ CONFIG_WDT=y > CONFIG_WDT_GPIO=y > CONFIG_WDT_SANDBOX=y > CONFIG_WDT_ALARM_SANDBOX=y > +CONFIG_WDT_FTWDT010=y > CONFIG_FS_CBFS=y > CONFIG_FS_CRAMFS=y > CONFIG_ADDR_MAP=y > diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig > index b5ac8f7f50..8f78df509a 100644 > --- a/drivers/watchdog/Kconfig > +++ b/drivers/watchdog/Kconfig > @@ -359,4 +359,11 @@ config SPL_WDT > Enable driver model for watchdog timer in SPL. > This is similar to CONFIG_WDT in U-Boot. > > +config WDT_FTWDT010 > + bool "Faraday Technology ftwdt010 watchdog timer support" > + depends on WDT > + imply WATCHDOG > + help > + Faraday Technology ftwdt010 watchdog is an architecture independent > + watchdog. It is usually used in SoC chip design. > endmenu > diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile > index 446d961d7d..fffa338bef 100644 > --- a/drivers/watchdog/Makefile > +++ b/drivers/watchdog/Makefile > @@ -26,6 +26,7 @@ obj-$(CONFIG_WDT_BOOKE) += booke_wdt.o > obj-$(CONFIG_WDT_CORTINA) += cortina_wdt.o > obj-$(CONFIG_WDT_ORION) += orion_wdt.o > obj-$(CONFIG_WDT_CDNS) += cdns_wdt.o > +obj-$(CONFIG_WDT_FTWDT010) += ftwdt010_wdt.o > obj-$(CONFIG_WDT_GPIO) += gpio_wdt.o > obj-$(CONFIG_WDT_MAX6370) += max6370_wdt.o > obj-$(CONFIG_WDT_MESON_GXBB) += meson_gxbb_wdt.o > diff --git a/drivers/watchdog/ftwdt010_wdt.c b/drivers/watchdog/ftwdt010_wdt.c > new file mode 100644 > index 0000000000..a6b33b1720 > --- /dev/null > +++ b/drivers/watchdog/ftwdt010_wdt.c > @@ -0,0 +1,132 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * Watchdog driver for the FTWDT010 Watch Dog Driver > + * > + * (c) Copyright 2004 Faraday Technology Corp. (www.faraday-tech.com) > + * Based on sa1100_wdt.c by Oleg Drokin > + * Based on SoftDog driver by Alan Cox > + * > + * Copyright (C) 2011 Andes Technology Corporation > + * Macpaul Lin, Andes Technology Corporation > + * > + * 27/11/2004 Initial release, Faraday. > + * 12/01/2011 Port to u-boot, Macpaul Lin. > + * 22/08/2022 Port to DM > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +struct ftwdt010_wdt_priv { > + struct ftwdt010_wdt __iomem *regs; > +}; > + > +/* > + * Set the watchdog time interval. > + * Counter is 32 bit. > + */ > +static int ftwdt010_wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags) > +{ > + struct ftwdt010_wdt_priv *priv = dev_get_priv(dev); > + struct ftwdt010_wdt *wd = priv->regs; > + unsigned int reg; > + > + debug("Activating WDT %llu ms\n", timeout_ms); > + > + /* Check if disabled */ > + if (readl(&wd->wdcr) & ~FTWDT010_WDCR_ENABLE) { > + printf("sorry, watchdog is disabled\n"); > + return -1; > + } > + > + /* > + * In a 66MHz system, > + * if you set WDLOAD as 0x03EF1480 (66000000) > + * the reset timer is 1 second. > + */ > + reg = FTWDT010_WDLOAD(timeout_ms * FTWDT010_TIMEOUT_FACTOR); > + > + writel(reg, &wd->wdload); > + > + return 0; > +} > + > +static int ftwdt010_wdt_reset(struct udevice *dev) > +{ > + struct ftwdt010_wdt_priv *priv = dev_get_priv(dev); > + struct ftwdt010_wdt *wd = priv->regs; > + > + /* clear control register */ > + writel(0, &wd->wdcr); > + > + /* Write Magic number */ > + writel(FTWDT010_WDRESTART_MAGIC, &wd->wdrestart); > + > + /* Enable WDT */ > + writel((FTWDT010_WDCR_RST | FTWDT010_WDCR_ENABLE), &wd->wdcr); > + > + return 0; > +} > + > +static int ftwdt010_wdt_stop(struct udevice *dev) > +{ > + struct ftwdt010_wdt_priv *priv = dev_get_priv(dev); > + struct ftwdt010_wdt *wd = priv->regs; > + > + debug("Deactivating WDT..\n"); > + > + /* > + * It was defined with CONFIG_WATCHDOG_NOWAYOUT in Linux > + * > + * Shut off the timer. > + * Lock it in if it's a module and we defined ...NOWAYOUT > + */ > + writel(0, &wd->wdcr); > + return 0; > +} > + > +static int ftwdt010_wdt_expire_now(struct udevice *dev, ulong flags) > +{ > + struct ftwdt010_wdt_priv *priv = dev_get_priv(dev); > + struct ftwdt010_wdt *wd = priv->regs; > + > + debug("Expiring WDT..\n"); > + writel(FTWDT010_WDLOAD(0), &wd->wdload); > + return ftwdt010_wdt_reset(dev); > +} > + > +static int ftwdt010_wdt_probe(struct udevice *dev) > +{ > + struct ftwdt010_wdt_priv *priv = dev_get_priv(dev); > + > + priv->regs = dev_read_addr_ptr(dev); > + if (!priv->regs) > + return -EINVAL; > + > + return 0; > +} > + > +static const struct wdt_ops ftwdt010_wdt_ops = { > + .start = ftwdt010_wdt_start, > + .reset = ftwdt010_wdt_reset, > + .stop = ftwdt010_wdt_stop, > + .expire_now = ftwdt010_wdt_expire_now, > +}; > + > +static const struct udevice_id ftwdt010_wdt_ids[] = { > + { .compatible = "faraday,ftwdt010" }, > + {} > +}; > + > +U_BOOT_DRIVER(ftwdt010_wdt) = { > + .name = "ftwdt010_wdt", > + .id = UCLASS_WDT, > + .of_match = ftwdt010_wdt_ids, > + .ops = &ftwdt010_wdt_ops, > + .probe = ftwdt010_wdt_probe, > + .priv_auto = sizeof(struct ftwdt010_wdt_priv), > +}; > diff --git a/include/faraday/ftwdt010_wdt.h b/include/faraday/ftwdt010_wdt.h > index 804907d645..d4c11e39a0 100644 > --- a/include/faraday/ftwdt010_wdt.h > +++ b/include/faraday/ftwdt010_wdt.h > @@ -89,7 +89,4 @@ struct ftwdt010_wdt { > */ > #define FTWDT010_TIMEOUT_FACTOR (get_board_sys_clk() / 1000) /* 1 ms */ > > -void ftwdt010_wdt_reset(void); > -void ftwdt010_wdt_disable(void); > - > #endif /* __FTWDT010_H */ 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