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 8211BC433EF for ; Wed, 9 Mar 2022 06:13:54 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 46738839B1; Wed, 9 Mar 2022 07:13:51 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com 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=gmail.com header.i=@gmail.com header.b="Bi9YoCNR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DB7E983990; Wed, 9 Mar 2022 07:13:45 +0100 (CET) Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 077CA83990 for ; Wed, 9 Mar 2022 07:13:38 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jim.t90615@gmail.com Received: by mail-pf1-x42a.google.com with SMTP id s8so1337076pfk.12 for ; Tue, 08 Mar 2022 22:13:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GXLZIkvRydmCOIpViJHE4qSJwBcHzTT5Q28q01x5xxU=; b=Bi9YoCNRSIAEPYFgJiS18w4ydyPYpIWE2JbtSmwNH0tx/x//xqTJt8HXvAnJF8VJ9A iliL2CpHl4BsyN6xAld4pfnb4/8QY7wD4pNgo8xMi32+QdncwxZm5nBR6V9dubVaGNjn RB6hkkO0ywmXXehCu5TSd/KpoQP3/TenXebAQnGpyeHyWN9BYP+eeG1CpdNg3Bjl1PSy qAIyirqPYDI9hg8OnC97ZS5HBMry4F2dczge3/POcIGpqiCGIwwAt2Qdbq+O7vtGjKPh 4Pdenw6BIyFRrhPQ0mocmBxwq9q1UeAB8oLBnCqq/LbY5/8hj46tYWeDKDcGkLHUu03q 8U4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GXLZIkvRydmCOIpViJHE4qSJwBcHzTT5Q28q01x5xxU=; b=Os0W3JwM6omYl01szw8nD3nNXx19cx7GhsUVlE3EEB2sh1g3krAs0S5BfqNkPBp1bJ Gt9LZOZIQv6Cl6x9VuIA76T0/kBA+MnFUH6SlQIOBmW5JOCkxlEHzdqd4XcGAg9TqwtX JXfuz7dJYeVfpQx+PbqriG/38S4reluAZ4fyEoGxDubifPUatYrziQUxSAicPyCS367H 0d6kSuNIlNZu1SLyF6ipWaancwJz2TkYZPO8iKAuZfwZ7QDzZ/0sV498NHwgJ5X08z/J q6G2eL9byUuuvDmOHnoMHeDTpZH49S4QJkFY+rGcCCTvKDhCUBBbHiz4JnjQEWu5NQGH jkLA== X-Gm-Message-State: AOAM530ZsJBK6+q+XTtqx+/KhaBKtS1qu4t58w30v/yoXmOUxzgmAy08 BXh3UpKG7ORO+ZPZ7fsRxqg= X-Google-Smtp-Source: ABdhPJz1J1kV2eIpKJgvndNzJq1Qta4J8DcL1mfaET0qt4wbFMvfNNGpw1WQa2ZebYRlCRDdZKaORQ== X-Received: by 2002:a05:6a00:301c:b0:4f6:f04e:ca34 with SMTP id ay28-20020a056a00301c00b004f6f04eca34mr16836813pfb.19.1646806416443; Tue, 08 Mar 2022 22:13:36 -0800 (PST) Received: from localhost.localdomain ([112.78.86.21]) by smtp.gmail.com with ESMTPSA id gb5-20020a17090b060500b001bd312f7396sm1087389pjb.45.2022.03.08.22.13.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 22:13:36 -0800 (PST) From: jimliu2 X-Google-Original-From: jimliu2 To: sr@denx.de, 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 Subject: [PATCH v2 1/1] wdt: nuvoton: Add support for Nuvoton Date: Wed, 9 Mar 2022 14:13:18 +0800 Message-Id: <20220309061318.475-2-JJLIU0@nuvoton.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220309061318.475-1-JJLIU0@nuvoton.com> References: <20220309061318.475-1-JJLIU0@nuvoton.com> 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 Add watchdog controller driver for NPCM7xx/npcm8xx Signed-off-by: jimliu2 --- drivers/watchdog/Kconfig | 6 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/npcm_wdt.c | 119 ++++++++++++++++++++++++++++++++++++ 3 files changed, 126 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..6abc146d99 --- /dev/null +++ b/drivers/watchdog/npcm_wdt.c @@ -0,0 +1,119 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2022 Nuvoton Technology, Inc + */ + +#include +#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, +}; -- 2.17.1