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 4EDC1C001B0 for ; Mon, 24 Jul 2023 06:37:10 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D68C386828; Mon, 24 Jul 2023 08:37:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (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=1690180623; bh=hshC1Tv6JoEMs8BK28573Qi9kevUHznSzt2+QpVsiCA=; h=Date:Subject:To:Cc:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=O/5dUBJfkhq1Z2T5EnzzO7YwvFsA9o2vWuXVijf2MxvvxJkJRhGP4aE+QGOI87Eq7 Vl5kytUgo1iXY1sQmZoDJaTt9WCQqRl7PFihG84Xr7A7q5koaNAa54ms17gWvAJFvm At8DdbqhzVPyDKM6mLEcS5Pg1n0bVcm4Jsq8z4Hz2MElzqmZXKbd1BV1uJisuMJb0b p4G/oE4Sl0eiFZWQZcIQ0GXKPZKv9PZ29xuFYzBKHks6RlsfkkFjifT8kIdrKwo2iY dyH66fT9rF83JKelz/jr5b189a2BRYWW+L89T7kmurjpBfde4gb3U4MmLEqoY7Jyoo vcA2MnR5mOUoA== Received: by phobos.denx.de (Postfix, from userid 109) id EB0948681A; Mon, 24 Jul 2023 08:36: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 6368B86810 for ; Mon, 24 Jul 2023 08:36:34 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (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 [10.196.197.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 4R8Vmj4T7Gz9sR0; Mon, 24 Jul 2023 08:36:21 +0200 (CEST) Message-ID: <59111941-80b7-58cc-af5b-c0eb14805087@denx.de> Date: Mon, 24 Jul 2023 08:36:19 +0200 MIME-Version: 1.0 Subject: Re: [PATCH v4 5/6] mips: ls1c300: add watchdog support Content-Language: en-US To: Du Huanpeng , u74147@gmail.com, u-boot@lists.denx.de Cc: jiaxun.yang@flygoat.com, chenhuacai@loongson.cn, daniel.schwierzeck@gmail.com, lukma@denx.de, seanga2@gmail.com, sjg@chromium.org, pali@kernel.org, quentin.schulz@theobroma-systems.com, kever.yang@rock-chips.com, kabel@kernel.org, sergiu.moga@microchip.com, claudiu.beznea@microchip.com, michal.simek@amd.com, ashok.reddy.soma@amd.com, yanhong.wang@starfivetech.com, t.karthik.reddy@amd.com, sumit.garg@linaro.org, eugen.hristev@collabora.com References: <20230723043912.221-1-dhu@hodcarrier.org> <20230723043912.221-6-dhu@hodcarrier.org> From: Stefan Roese In-Reply-To: <20230723043912.221-6-dhu@hodcarrier.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 7/23/23 06:39, Du Huanpeng wrote: > Signed-off-by: Du Huanpeng A small description is always helpful (mandatory) in the commit text. Please add at least one or two sentences here. > --- > drivers/watchdog/Kconfig | 8 +++ > drivers/watchdog/Makefile | 1 + > drivers/watchdog/lsmips_wdt.c | 128 ++++++++++++++++++++++++++++++++++ > 3 files changed, 137 insertions(+) > create mode 100644 drivers/watchdog/lsmips_wdt.c > > diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig > index 646663528a..f60011e5b3 100644 > --- a/drivers/watchdog/Kconfig > +++ b/drivers/watchdog/Kconfig > @@ -171,6 +171,14 @@ config WDT_GPIO > doc/device-tree-bindings/watchdog/gpio-wdt.txt for > information on how to describe the watchdog in device tree. > > +config WDT_LSMIPS > + bool "Loongson MIPS watchdog timer support" > + depends on WDT > + help > + Select this to enable watchdog timer for Loongson SoCs. > + The watchdog timer is stopped when initialized. > + It performs full SoC reset. > + > config WDT_MAX6370 > bool "MAX6370 watchdog timer support" > depends on WDT > diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile > index fd5d9c7376..8afd61a4fc 100644 > --- a/drivers/watchdog/Makefile > +++ b/drivers/watchdog/Makefile > @@ -30,6 +30,7 @@ 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_LSMIPS) += lsmips_wdt.o > obj-$(CONFIG_WDT_MAX6370) += max6370_wdt.o > obj-$(CONFIG_WDT_MESON_GXBB) += meson_gxbb_wdt.o > obj-$(CONFIG_WDT_MPC8xxx) += mpc8xxx_wdt.o > diff --git a/drivers/watchdog/lsmips_wdt.c b/drivers/watchdog/lsmips_wdt.c > new file mode 100644 > index 0000000000..69006d332d > --- /dev/null > +++ b/drivers/watchdog/lsmips_wdt.c > @@ -0,0 +1,128 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Watchdog driver for MediaTek SoCs > + * > + * Copyright (C) 2018 MediaTek Inc. > + * Author: Ryder Lee > + * > + * based on: drivers/watchdog/mtk_wdt.c > + * Copyright (C) 2020-2023 Du Huanpeng > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > + > +struct lsmips_wdt_priv { > + void __iomem *base; > +#define WDT_EN 0 > +#define WDT_TIMER 4 > +#define WDT_SET 8 > + ulong clock; > + unsigned long timeout; > +}; > + > +static int lsmips_wdt_reset(struct udevice *dev) > +{ > + struct lsmips_wdt_priv *priv = dev_get_priv(dev); > + > + writel(priv->timeout, priv->base + WDT_TIMER); > + writel(1, priv->base + WDT_SET); > + > + return 0; > +} > + > +static int lsmips_wdt_stop(struct udevice *dev) > +{ > + struct lsmips_wdt_priv *priv = dev_get_priv(dev); > + > + writel(0, priv->base + WDT_EN); > + return 0; > +} > + > +static int lsmips_wdt_expire_now(struct udevice *dev, ulong flags) > +{ > + struct lsmips_wdt_priv *priv = dev_get_priv(dev); > + > + writel(1, priv->base + WDT_EN); > + writel(1, priv->base + WDT_TIMER); > + writel(1, priv->base + WDT_SET); > + > + hang(); > + return 0; > +} > + > +static int lsmips_wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags) > +{ > + struct lsmips_wdt_priv *priv = dev_get_priv(dev); > + unsigned int timeout; > + const unsigned int MSEC_PER_SEC = 1000; Upper case variable names are very unusual. Why not use a macro / define instead? Nitpicking: Reverse X-mas tree ordering of the variable declarations is preferred. > + > + timeout = U32_MAX / (priv->clock / MSEC_PER_SEC); > + > + if (timeout < timeout_ms) > + timeout = U32_MAX; > + else > + timeout = timeout_ms * (priv->clock / MSEC_PER_SEC); > + > + debug("WDT: reload = %08x\n", timeout); > + > + writel(1, priv->base + WDT_EN); > + writel(timeout, priv->base + WDT_TIMER); > + writel(1, priv->base + WDT_SET); > + > + priv->timeout = timeout; > + > + return 0; > +} > + > +static int lsmips_wdt_probe(struct udevice *dev) > +{ > + struct lsmips_wdt_priv *priv = dev_get_priv(dev); > + struct clk cl; > + ulong clock; > + > + priv->base = dev_remap_addr(dev); > + if (!priv->base) > + return -ENOENT; > + > + if (clk_get_by_index(dev, 0, &cl) == 0) > + clock = clk_get_rate(&cl); > + > + debug("WDT: clock = %ld\n", clock); > + > + if (IS_ERR_VALUE(clock)) { > + dev_err(dev, "failed to get rate\n"); > + return clock; > + } > + > + priv->clock = clock; > + writel(0, priv->base + WDT_EN); > + return 0; > +} > + > +static const struct wdt_ops lsmips_wdt_ops = { > + .start = lsmips_wdt_start, > + .reset = lsmips_wdt_reset, > + .stop = lsmips_wdt_stop, > + .expire_now = lsmips_wdt_expire_now, > +}; > + > +static const struct udevice_id lsmips_wdt_ids[] = { > + { .compatible = "loongson,ls1c300-wdt"}, I was not able to find this compatible property in the Linux source tree. Is this WDT not supported there? Thanks, Stefan