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 482D6C433F5 for ; Thu, 10 Mar 2022 07:46:05 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 908DA839D9; Thu, 10 Mar 2022 08:46:02 +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=1646898363; bh=D5bqSA+xu3Jgj4EfLL+j/RirI3mXujwBHVka2+3U4oA=; h=Date:Subject:To:Cc:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ui31gFTGnwW53TtKvc3N2rBHU1q9m4edjwQeo4iVASMp0YFLCiwIIfq/4y2EbwnBe 5/i3zRiZs/i2v4Rsqr4WcR9EQQ/M5nMQyyTy3KcYZAPanCYPjBsqlrtmf3v4aU5P6G F3d2B5Y77I2LSayAmGu/6qgUOMyTK5QmjMbgIqTyLwgjeI7DpkysazvwCLTb/LMQFZ ahBuwaFFUICKdJu0QR1MGUnaB13ulbtfeinduj6WY1C5Mim1CHoZUKsf5q6Pxbo2L8 6zXm34c0wLQZuthDajAOUzElkEEd3cuWMJtubw6GcjHx97d0+uOwSGikkgUNAryDNI TQrhZhbng4YYA== Received: by phobos.denx.de (Postfix, from userid 109) id 6DD16839D4; Thu, 10 Mar 2022 08:45:59 +0100 (CET) Received: from mout-u-204.mailbox.org (mout-u-204.mailbox.org [91.198.250.253]) (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 38FF883A5C for ; Thu, 10 Mar 2022 08:45:53 +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 smtp1.mailbox.org (unknown [91.198.250.123]) (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 4KDh284jG3z9sQt; Thu, 10 Mar 2022 08:45:52 +0100 (CET) Message-ID: <01bc2efa-fe4a-b941-57ec-511ec93cd33a@denx.de> Date: Thu, 10 Mar 2022 08:45:45 +0100 MIME-Version: 1.0 Subject: Re: [PATCH v3] wdt: nuvoton: Add support for Nuvoton Content-Language: en-US To: jimliu2 , priyanka.jain@nxp.com, andre.przywara@arm.com, sjg@chromium.org, samuel@sholland.org, xypron.glpk@gmx.de, JJLIU0@nuvoton.com, michael@walle.cc, rasmus.villemoes@prevas.dk, judge.packham@gmail.com, pali@kernel.org, kettenis@openbsd.org, KWLIU@nuvoton.com, YSCHU@nuvoton.com, sven@svenpeter.dev Cc: u-boot@lists.denx.de References: <20220310035002.6209-1-JJLIU0@nuvoton.com> From: Stefan Roese In-Reply-To: <20220310035002.6209-1-JJLIU0@nuvoton.com> 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.5 at phobos.denx.de X-Virus-Status: Clean On 3/10/22 04:50, jimliu2 wrote: > Add watchdog controller driver for NPCM7xx/npcm8xx > > Signed-off-by: jimliu2 Reviewed-by: Stefan Roese Thanks, Stefan > --- > Changes for v2: > - coding Style cleanup > - change register type from struct npcm_wdt to iomem > > Changes for v3: > - remove common.h > > drivers/watchdog/Kconfig | 6 ++ > drivers/watchdog/Makefile | 1 + > drivers/watchdog/npcm_wdt.c | 118 ++++++++++++++++++++++++++++++++++++ > 3 files changed, 125 insertions(+) > create mode 100644 drivers/watchdog/npcm_wdt.c > > diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig > index f90f0ca02b..15edcf570f 100644 > --- a/drivers/watchdog/Kconfig > +++ b/drivers/watchdog/Kconfig > @@ -196,6 +196,12 @@ config WDT_MTK > The watchdog timer is stopped when initialized. > It performs full SoC reset. > > +config WDT_NPCM > + bool "Nuvoton watchdog timer support" > + depends on WDT && ARCH_NPCM > + help > + Nuvoton npcm7xx/npcm8xx watchdog. > + > config WDT_OCTEONTX > bool "OcteonTX core watchdog support" > depends on WDT && (ARCH_OCTEONTX || ARCH_OCTEONTX2) > diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile > index a35bd559f5..1089cd21f5 100644 > --- a/drivers/watchdog/Makefile > +++ b/drivers/watchdog/Makefile > @@ -31,6 +31,7 @@ obj-$(CONFIG_WDT_MPC8xx) += mpc8xx_wdt.o > obj-$(CONFIG_WDT_MT7620) += mt7620_wdt.o > obj-$(CONFIG_WDT_MT7621) += mt7621_wdt.o > obj-$(CONFIG_WDT_MTK) += mtk_wdt.o > +obj-$(CONFIG_WDT_NPCM) += npcm_wdt.o > obj-$(CONFIG_WDT_OCTEONTX) += octeontx_wdt.o > obj-$(CONFIG_WDT_OMAP3) += omap_wdt.o > obj-$(CONFIG_WDT_SBSA) += sbsa_gwdt.o > diff --git a/drivers/watchdog/npcm_wdt.c b/drivers/watchdog/npcm_wdt.c > new file mode 100644 > index 0000000000..333c06a4e7 > --- /dev/null > +++ b/drivers/watchdog/npcm_wdt.c > @@ -0,0 +1,118 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * Copyright (c) 2022 Nuvoton Technology, Inc > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define NPCM_WTCLK (BIT(10) | BIT(11)) /* Clock divider */ > +#define NPCM_WTE BIT(7) /* Enable */ > +#define NPCM_WTIE BIT(6) /* Enable irq */ > +#define NPCM_WTIS (BIT(4) | BIT(5)) /* Interval selection */ > +#define NPCM_WTIF BIT(3) /* Interrupt flag*/ > +#define NPCM_WTRF BIT(2) /* Reset flag */ > +#define NPCM_WTRE BIT(1) /* Reset enable */ > +#define NPCM_WTR BIT(0) /* Reset counter */ > + > +struct npcm_wdt_priv { > + void __iomem *regs; > +}; > + > +static int npcm_wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags) > +{ > + struct npcm_wdt_priv *priv = dev_get_priv(dev); > + u32 time_out, val; > + > + time_out = (u32)(timeout_ms) / 1000; > + if (time_out < 2) > + val = 0x800; > + else if (time_out < 3) > + val = 0x420; > + else if (time_out < 6) > + val = 0x810; > + else if (time_out < 11) > + val = 0x430; > + else if (time_out < 22) > + val = 0x820; > + else if (time_out < 44) > + val = 0xC00; > + else if (time_out < 87) > + val = 0x830; > + else if (time_out < 173) > + val = 0xC10; > + else if (time_out < 688) > + val = 0xC20; > + else > + val = 0xC30; > + > + val |= NPCM_WTRE | NPCM_WTE | NPCM_WTR | NPCM_WTIE; > + writel(val, priv->regs); > + > + return 0; > +} > + > +static int npcm_wdt_stop(struct udevice *dev) > +{ > + struct npcm_wdt_priv *priv = dev_get_priv(dev); > + > + writel(0, priv->regs); > + > + return 0; > +} > + > +static int npcm_wdt_reset(struct udevice *dev) > +{ > + struct npcm_wdt_priv *priv = dev_get_priv(dev); > + > + writel(NPCM_WTR | NPCM_WTRE | NPCM_WTE, priv->regs); > + udelay(1000); > + > + return 0; > +} > + > +static int npcm_wdt_of_to_plat(struct udevice *dev) > +{ > + struct npcm_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 npcm_wdt_ops = { > + .start = npcm_wdt_start, > + .reset = npcm_wdt_reset, > + .stop = npcm_wdt_stop, > +}; > + > +static const struct udevice_id npcm_wdt_ids[] = { > + { .compatible = "nuvoton,npcm750-wdt" }, > + { .compatible = "nuvoton,npcm845-wdt" }, > + { } > +}; > + > +static int npcm_wdt_probe(struct udevice *dev) > +{ > + debug("%s() wdt%u\n", __func__, dev_seq(dev)); > + npcm_wdt_stop(dev); > + > + return 0; > +} > + > +U_BOOT_DRIVER(npcm_wdt) = { > + .name = "npcm_wdt", > + .id = UCLASS_WDT, > + .of_match = npcm_wdt_ids, > + .probe = npcm_wdt_probe, > + .priv_auto = sizeof(struct npcm_wdt_priv), > + .of_to_plat = npcm_wdt_of_to_plat, > + .ops = &npcm_wdt_ops, > +}; Viele Grüße, Stefan Roese -- DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr@denx.de