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 A348FC38A2D for ; Mon, 24 Oct 2022 06:02:22 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6298984F1B; Mon, 24 Oct 2022 08:02:20 +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=1666591340; bh=edMyCTEz3yvUGEOPMRL3T88j7Pr7Yfl9ZxSZoPSfJQM=; h=Date:Subject:To:Cc:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=EVwlIrK+TvkVvDfJSoVNqgnVO/BI0oIsNTGx3SXR2/t/zM8h6jYxsaebKftsQ/rre rRbOijm5Q+N0rCnCkm8EFPjnz2t1TDEtnshmDKDrcLm00vg69MS+1uaxwC9OGzvWIX skwsKo0tfyIFuUw36anDZxQPpCMgIFhyET0OSx3RSavvnlIosS5Sa4RT4maEHEiDn9 zX29JgeZaJkwyPT2+skkz2fbF1udtHOhSaqp3XTZEtbq3bP0lCFrFP3L+j60ABjTe7 TX35erEmy7r/byTIw5wrmaad7h+2oYiTqFzXn08zaHx6tk0pyCG0i8xMVUyVoN/1s0 hiWdbf7yVbN2g== Received: by phobos.denx.de (Postfix, from userid 109) id 01E0284F1B; Mon, 24 Oct 2022 08:02:19 +0200 (CEST) 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 C4B1D84F50 for ; Mon, 24 Oct 2022 08:02:08 +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 smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (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 4Mwkx916PVz9sTg; Mon, 24 Oct 2022 08:02:05 +0200 (CEST) Message-ID: <4b85cbcd-7a78-e846-8cde-573a394f1993@denx.de> Date: Mon, 24 Oct 2022 08:02:03 +0200 MIME-Version: 1.0 Subject: Re: [PATCH v2 4/4] watchdog: ulp_wdog: add driver model for ulp watchdog driver Content-Language: en-US To: "Alice Guo (OSS)" , sbabic@denx.de, festevam@gmail.com, sjg@chromium.org Cc: uboot-imx@nxp.com, u-boot@lists.denx.de References: <20221021084118.2367-1-alice.guo@oss.nxp.com> <20221021084118.2367-5-alice.guo@oss.nxp.com> From: Stefan Roese In-Reply-To: <20221021084118.2367-5-alice.guo@oss.nxp.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.6 at phobos.denx.de X-Virus-Status: Clean On 21.10.22 10:41, Alice Guo (OSS) wrote: > From: Alice Guo > > Enable driver model for ulp watchdog timer. When CONFIG_WDT=y and the > status of device node is "okay", initr_watchdog will be called and > finally calls ulp_wdt_probe() and ulp_wdt_start(). > > Signed-off-by: Alice Guo > Reviewed-by: Ye Li Reviewed-by: Stefan Roese Thanks, Stefan > --- > > Changes for v2: > none > > drivers/watchdog/ulp_wdog.c | 94 ++++++++++++++++++++++++++++++++++--- > 1 file changed, 87 insertions(+), 7 deletions(-) > > diff --git a/drivers/watchdog/ulp_wdog.c b/drivers/watchdog/ulp_wdog.c > index 1b286816b5..e081054304 100644 > --- a/drivers/watchdog/ulp_wdog.c > +++ b/drivers/watchdog/ulp_wdog.c > @@ -7,6 +7,8 @@ > #include > #include > #include > +#include > +#include > > /* > * MX7ULP WDOG Register Map > @@ -18,6 +20,11 @@ struct wdog_regs { > u32 win; > }; > > +struct ulp_wdt_priv { > + struct wdog_regs *wdog; > + u32 clk_rate; > +}; > + > #ifndef CONFIG_WATCHDOG_TIMEOUT_MSECS > #define CONFIG_WATCHDOG_TIMEOUT_MSECS 0x1500 > #endif > @@ -46,6 +53,9 @@ struct wdog_regs { > #define WDG_32KHZ_CLK (0x2) > #define WDG_EXT_CLK (0x3) > > +#define CLK_RATE_1KHZ 1000 > +#define CLK_RATE_32KHZ 125 > + > void hw_watchdog_set_timeout(u16 val) > { > /* setting timeout value */ > @@ -54,10 +64,8 @@ void hw_watchdog_set_timeout(u16 val) > writel(val, &wdog->toval); > } > > -void hw_watchdog_reset(void) > +void ulp_watchdog_reset(struct wdog_regs *wdog) > { > - struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR; > - > if (readl(&wdog->cs) & WDGCS_CMD32EN) { > writel(REFRESH_WORD, &wdog->cnt); > } else { > @@ -68,9 +76,8 @@ void hw_watchdog_reset(void) > } > } > > -void hw_watchdog_init(void) > +void ulp_watchdog_init(struct wdog_regs *wdog, u16 timeout) > { > - struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR; > u32 cmd32 = 0; > > if (readl(&wdog->cs) & WDGCS_CMD32EN) { > @@ -87,7 +94,7 @@ void hw_watchdog_init(void) > while (!(readl(&wdog->cs) & WDGCS_ULK)) > ; > > - hw_watchdog_set_timeout(CONFIG_WATCHDOG_TIMEOUT_MSECS); > + hw_watchdog_set_timeout(timeout); > writel(0, &wdog->win); > > /* setting 1-kHz clock source, enable counter running, and clear interrupt */ > @@ -102,7 +109,21 @@ void hw_watchdog_init(void) > while (!(readl(&wdog->cs) & WDGCS_RCS)) > ; > > - hw_watchdog_reset(); > + ulp_watchdog_reset(wdog); > +} > + > +void hw_watchdog_reset(void) > +{ > + struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR; > + > + ulp_watchdog_reset(wdog); > +} > + > +void hw_watchdog_init(void) > +{ > + struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR; > + > + ulp_watchdog_init(wdog, CONFIG_WATCHDOG_TIMEOUT_MSECS); > } > > void reset_cpu(void) > @@ -142,3 +163,62 @@ void reset_cpu(void) > > while (1); > } > + > +static int ulp_wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags) > +{ > + struct ulp_wdt_priv *priv = dev_get_priv(dev); > + u64 timeout = 0; > + > + timeout = (timeout_ms * priv->clk_rate) / 1000; > + if (timeout > U16_MAX) > + return -EINVAL; > + > + ulp_watchdog_init(priv->wdog, (u16)timeout); > + > + return 0; > +} > + > +static int ulp_wdt_reset(struct udevice *dev) > +{ > + struct ulp_wdt_priv *priv = dev_get_priv(dev); > + > + ulp_watchdog_reset(priv->wdog); > + > + return 0; > +} > + > +static int ulp_wdt_probe(struct udevice *dev) > +{ > + struct ulp_wdt_priv *priv = dev_get_priv(dev); > + > + priv->wdog = dev_read_addr_ptr(dev); > + if (!priv->wdog) > + return -EINVAL; > + > + priv->clk_rate = (u32)dev_get_driver_data(dev); > + if (!priv->clk_rate) > + return -EINVAL; > + > + return 0; > +} > + > +static const struct wdt_ops ulp_wdt_ops = { > + .start = ulp_wdt_start, > + .reset = ulp_wdt_reset, > +}; > + > +static const struct udevice_id ulp_wdt_ids[] = { > + { .compatible = "fsl,imx7ulp-wdt", .data = CLK_RATE_1KHZ }, > + { .compatible = "fsl,imx8ulp-wdt", .data = CLK_RATE_1KHZ }, > + { .compatible = "fsl,imx93-wdt", .data = CLK_RATE_32KHZ }, > + {} > +}; > + > +U_BOOT_DRIVER(ulp_wdt) = { > + .name = "ulp_wdt", > + .id = UCLASS_WDT, > + .of_match = ulp_wdt_ids, > + .priv_auto = sizeof(struct ulp_wdt_priv), > + .probe = ulp_wdt_probe, > + .ops = &ulp_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