Linux-Watchdog Archive on lore.kernel.org
 help / color / Atom feed
From: Anson Huang <anson.huang@nxp.com>
To: Guenter Roeck <linux@roeck-us.net>
Cc: "wim@linux-watchdog.org" <wim@linux-watchdog.org>,
	"shawnguo@kernel.org" <shawnguo@kernel.org>,
	"s.hauer@pengutronix.de" <s.hauer@pengutronix.de>,
	"kernel@pengutronix.de" <kernel@pengutronix.de>,
	"festevam@gmail.com" <festevam@gmail.com>,
	"linux-watchdog@vger.kernel.org" <linux-watchdog@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	dl-linux-imx <linux-imx@nxp.com>
Subject: RE: [PATCH V3 1/2] watchdog: imx7ulp: Strictly follow the sequence for wdog operations
Date: Thu, 30 Jul 2020 22:48:42 +0000
Message-ID: <DB3PR0402MB391669AC8C63D32F5AC65136F5710@DB3PR0402MB3916.eurprd04.prod.outlook.com> (raw)
In-Reply-To: <20200730165240.GA178323@roeck-us.net>

Hi, Guenter


> Subject: Re: [PATCH V3 1/2] watchdog: imx7ulp: Strictly follow the sequence
> for wdog operations
> 
> On Thu, Jul 30, 2020 at 10:03:10AM +0800, Anson Huang wrote:
> > According to reference manual, the i.MX7ULP WDOG's operations except
> > refresh should follow below sequence:
> >
> > 1. disable global interrupts;
> > 2. unlock the wdog and wait unlock bit set; 3. reconfigure the wdog
> > and wait for reconfiguration bit set; 4. enabel global interrupts.
> >
> > Strictly follow the recommended sequence can make it more robust.
> >
> > Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
> > ---
> > changes since V2:
> > 	- change the wait timeout to 20us according to experiment;
> > 	- drop WARN_ON when timeout, and check its return value in each caller
> for
> > 	  unlock wait, no need to handle the return value for reconfiguration.
> > ---
> >  drivers/watchdog/imx7ulp_wdt.c | 74
> > ++++++++++++++++++++++++++++++++++--------
> >  1 file changed, 61 insertions(+), 13 deletions(-)
> >
> > diff --git a/drivers/watchdog/imx7ulp_wdt.c
> > b/drivers/watchdog/imx7ulp_wdt.c index 7993c8c..010ddd1 100644
> > --- a/drivers/watchdog/imx7ulp_wdt.c
> > +++ b/drivers/watchdog/imx7ulp_wdt.c
> > @@ -5,6 +5,7 @@
> >
> >  #include <linux/clk.h>
> >  #include <linux/io.h>
> > +#include <linux/iopoll.h>
> >  #include <linux/kernel.h>
> >  #include <linux/module.h>
> >  #include <linux/of.h>
> > @@ -36,6 +37,7 @@
> >  #define DEFAULT_TIMEOUT	60
> >  #define MAX_TIMEOUT	128
> >  #define WDOG_CLOCK_RATE	1000
> > +#define WDOG_WAIT_TIMEOUT	20
> >
> >  static bool nowayout = WATCHDOG_NOWAYOUT;
> module_param(nowayout,
> > bool, 0000); @@ -48,17 +50,40 @@ struct imx7ulp_wdt_device {
> >  	struct clk *clk;
> >  };
> >
> > -static void imx7ulp_wdt_enable(struct watchdog_device *wdog, bool
> > enable)
> > +static int imx7ulp_wdt_wait(void __iomem *base, u32 mask) {
> > +	u32 val = readl(base + WDOG_CS);
> > +
> > +	if (!(val & mask) && readl_poll_timeout_atomic(base + WDOG_CS, val,
> > +						       val & mask, 0,
> > +						       WDOG_WAIT_TIMEOUT))
> > +		return -ETIMEDOUT;
> > +
> > +	return 0;
> > +}
> > +
> > +static int imx7ulp_wdt_enable(struct watchdog_device *wdog, bool
> > +enable)
> >  {
> >  	struct imx7ulp_wdt_device *wdt = watchdog_get_drvdata(wdog);
> >
> >  	u32 val = readl(wdt->base + WDOG_CS);
> > +	int ret;
> >
> > +	local_irq_disable();
> >  	writel(UNLOCK, wdt->base + WDOG_CNT);
> > +	ret = imx7ulp_wdt_wait(wdt->base, WDOG_CS_ULK);
> > +	if (ret)
> > +		goto enable_out;
> >  	if (enable)
> >  		writel(val | WDOG_CS_EN, wdt->base + WDOG_CS);
> >  	else
> >  		writel(val & ~WDOG_CS_EN, wdt->base + WDOG_CS);
> > +	imx7ulp_wdt_wait(wdt->base, WDOG_CS_RCS);
> > +
> > +enable_out:
> > +	local_irq_enable();
> > +
> > +	return ret;
> >  }
> >
> >  static bool imx7ulp_wdt_is_enabled(void __iomem *base) @@ -79,17
> > +104,12 @@ static int imx7ulp_wdt_ping(struct watchdog_device *wdog)
> >
> >  static int imx7ulp_wdt_start(struct watchdog_device *wdog)  {
> > -
> > -	imx7ulp_wdt_enable(wdog, true);
> > -
> > -	return 0;
> > +	return imx7ulp_wdt_enable(wdog, true);
> >  }
> >
> >  static int imx7ulp_wdt_stop(struct watchdog_device *wdog)  {
> > -	imx7ulp_wdt_enable(wdog, false);
> > -
> > -	return 0;
> > +	return imx7ulp_wdt_enable(wdog, false);
> >  }
> >
> >  static int imx7ulp_wdt_set_timeout(struct watchdog_device *wdog, @@
> > -97,22 +117,37 @@ static int imx7ulp_wdt_set_timeout(struct
> > watchdog_device *wdog,  {
> >  	struct imx7ulp_wdt_device *wdt = watchdog_get_drvdata(wdog);
> >  	u32 val = WDOG_CLOCK_RATE * timeout;
> > +	int ret;
> >
> > +	local_irq_disable();
> >  	writel(UNLOCK, wdt->base + WDOG_CNT);
> > +	ret = imx7ulp_wdt_wait(wdt->base, WDOG_CS_ULK);
> > +	if (ret)
> > +		goto timeout_out;
> >  	writel(val, wdt->base + WDOG_TOVAL);
> > +	imx7ulp_wdt_wait(wdt->base, WDOG_CS_RCS);
> > +
> > +timeout_out:
> > +	local_irq_enable();
> >
> >  	wdog->timeout = timeout;
> 
> This needs to be moved up - the timeout did not get changed on error.

Ah, yes, will fix it in V4.

Thanks,
Anson



      reply index

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-30  2:03 Anson Huang
2020-07-30  2:03 ` [PATCH V3 2/2] watchdog: imx7ulp: Watchdog should continue running for wait/stop mode Anson Huang
2020-07-30 16:53   ` Guenter Roeck
2020-07-30 16:52 ` [PATCH V3 1/2] watchdog: imx7ulp: Strictly follow the sequence for wdog operations Guenter Roeck
2020-07-30 22:48   ` Anson Huang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DB3PR0402MB391669AC8C63D32F5AC65136F5710@DB3PR0402MB3916.eurprd04.prod.outlook.com \
    --to=anson.huang@nxp.com \
    --cc=festevam@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    --cc=wim@linux-watchdog.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-Watchdog Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-watchdog/0 linux-watchdog/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-watchdog linux-watchdog/ https://lore.kernel.org/linux-watchdog \
		linux-watchdog@vger.kernel.org
	public-inbox-index linux-watchdog

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-watchdog


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git