Linux Watchdog driver development
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Marco Felsch <m.felsch@pengutronix.de>
Cc: wim@linux-watchdog.org, support.opensource@diasemi.com,
	linux-watchdog@vger.kernel.org, kernel@pengutronix.de
Subject: Re: [PATCH v2 2/2] watchdog: da9063: remove duplicated timeout_to_sel calls
Date: Mon, 4 Jun 2018 12:25:28 -0700	[thread overview]
Message-ID: <20180604192528.GB19408@roeck-us.net> (raw)
In-Reply-To: <20180604150059.8602-3-m.felsch@pengutronix.de>

On Mon, Jun 04, 2018 at 05:00:59PM +0200, Marco Felsch wrote:
> Every time da9063_wdt_update_timeout() gets called a timeout_to_sel() is
> made because the timeout argument of update_timeout() is the raw
> register value. Moving the second<->raw-value translation into
> da9063_wdt_update_timeout() removes duplicated code.
> 
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  drivers/watchdog/da9063_wdt.c | 21 ++++++++-------------
>  1 file changed, 8 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/watchdog/da9063_wdt.c b/drivers/watchdog/da9063_wdt.c
> index 760aa9bca81b..384dca16af8b 100644
> --- a/drivers/watchdog/da9063_wdt.c
> +++ b/drivers/watchdog/da9063_wdt.c
> @@ -64,8 +64,10 @@ static int da9063_wdt_disable_timer(struct da9063 *da9063)
>  				  DA9063_TWDSCALE_DISABLE);
>  }
>  
> -static int da9063_wdt_update_timeout(struct da9063 *da9063, unsigned int regval)
> +static int
> +da9063_wdt_update_timeout(struct da9063 *da9063, unsigned int timeout)
>  {
> +	unsigned int regval;
>  	int ret;
>  
>  	/*
> @@ -81,6 +83,7 @@ static int da9063_wdt_update_timeout(struct da9063 *da9063, unsigned int regval)
>  		return ret;
>  
>  	usleep_range(150, 300);
> +	regval = da9063_wdt_timeout_to_sel(timeout);
>  
>  	return regmap_update_bits(da9063->regmap, DA9063_REG_CONTROL_D,
>  				  DA9063_TWDSCALE_MASK, regval);
> @@ -89,11 +92,9 @@ static int da9063_wdt_update_timeout(struct da9063 *da9063, unsigned int regval)
>  static int da9063_wdt_start(struct watchdog_device *wdd)
>  {
>  	struct da9063 *da9063 = watchdog_get_drvdata(wdd);
> -	unsigned int selector;
>  	int ret;
>  
> -	selector = da9063_wdt_timeout_to_sel(wdd->timeout);
> -	ret = da9063_wdt_update_timeout(da9063, selector);
> +	ret = da9063_wdt_update_timeout(da9063, wdd->timeout);
>  	if (ret)
>  		dev_err(da9063->dev, "Watchdog failed to start (err = %d)\n",
>  			ret);
> @@ -132,11 +133,8 @@ static int da9063_wdt_set_timeout(struct watchdog_device *wdd,
>  				  unsigned int timeout)
>  {
>  	struct da9063 *da9063 = watchdog_get_drvdata(wdd);
> -	unsigned int selector;
>  	int ret = 0;
>  
> -	selector = da9063_wdt_timeout_to_sel(timeout);
> -
>  	/*
>  	 * There are two cases when a set_timeout() will be called:
>  	 * 1. The watchdog is off and someone wants to set the timeout for the
> @@ -148,13 +146,13 @@ static int da9063_wdt_set_timeout(struct watchdog_device *wdd,
>  	 * enabling the watchdog, so the timeout must be buffered by the driver.
>  	 */
>  	if (watchdog_active(wdd))
> -		ret = da9063_wdt_update_timeout(da9063, selector);
> +		ret = da9063_wdt_update_timeout(da9063, timeout);
>  
>  	if (ret)
>  		dev_err(da9063->dev, "Failed to set watchdog timeout (err = %d)\n",
>  			ret);
>  	else
> -		wdd->timeout = wdt_timeout[selector];
> +		wdd->timeout = wdt_timeout[da9063_wdt_timeout_to_sel(timeout)];
>  
>  	return ret;
>  }
> @@ -220,10 +218,7 @@ static int da9063_wdt_probe(struct platform_device *pdev)
>  
>  	/* Change the timeout to the default value if the watchdog is running */
>  	if (da9063_wdt_is_running(da9063)) {
> -		unsigned int timeout;
> -
> -		timeout = da9063_wdt_timeout_to_sel(DA9063_WDG_TIMEOUT);
> -		da9063_wdt_update_timeout(da9063, timeout);
> +		da9063_wdt_update_timeout(da9063, DA9063_WDG_TIMEOUT);
>  		set_bit(WDOG_HW_RUNNING, &wdd->status);
>  	}
>  
> -- 
> 2.17.1
> 

  reply	other threads:[~2018-06-04 19:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-04 15:00 [PATCH v2 0/2] watchdog: da9063: small improvements Marco Felsch
2018-06-04 15:00 ` [PATCH v2 1/2] watchdog: da9063: rename helper function to avoid misunderstandings Marco Felsch
2018-06-04 19:24   ` Guenter Roeck
2018-06-05 12:38   ` Steve Twiss
2018-06-04 15:00 ` [PATCH v2 2/2] watchdog: da9063: remove duplicated timeout_to_sel calls Marco Felsch
2018-06-04 19:25   ` Guenter Roeck [this message]
2018-06-05 12:38   ` Steve Twiss

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=20180604192528.GB19408@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=kernel@pengutronix.de \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=m.felsch@pengutronix.de \
    --cc=support.opensource@diasemi.com \
    --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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox