diff mbox series

[v5,1/4] Watchdog: sp5100_tco: Move timer initialization into function

Message ID 20220202153525.1693378-2-terry.bowman@amd.com
State New
Headers show
Series Watchdog: sp5100_tco: Replace cd6h/cd7h port I/O accesses with MMIO accesses | expand

Commit Message

Terry Bowman Feb. 2, 2022, 3:35 p.m. UTC
Refactor driver's timer initialization into new function. This is needed
inorder to support adding new device layouts while using common timer
initialization.

Co-developed-by: Robert Richter <rrichter@amd.com>
Signed-off-by: Robert Richter <rrichter@amd.com>
Signed-off-by: Terry Bowman <terry.bowman@amd.com>
Tested-by: Jean Delvare <jdelvare@suse.de>
Reviewed-by: Jean Delvare <jdelvare@suse.de>
---
 drivers/watchdog/sp5100_tco.c | 65 +++++++++++++++++++----------------
 1 file changed, 36 insertions(+), 29 deletions(-)

Comments

Guenter Roeck Feb. 2, 2022, 7:51 p.m. UTC | #1
On Wed, Feb 02, 2022 at 09:35:22AM -0600, Terry Bowman wrote:
> Refactor driver's timer initialization into new function. This is needed
> inorder to support adding new device layouts while using common timer
> initialization.
> 
> Co-developed-by: Robert Richter <rrichter@amd.com>
> Signed-off-by: Robert Richter <rrichter@amd.com>
> Signed-off-by: Terry Bowman <terry.bowman@amd.com>
> Tested-by: Jean Delvare <jdelvare@suse.de>
> Reviewed-by: Jean Delvare <jdelvare@suse.de>

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

> ---
>  drivers/watchdog/sp5100_tco.c | 65 +++++++++++++++++++----------------
>  1 file changed, 36 insertions(+), 29 deletions(-)
> 
> diff --git a/drivers/watchdog/sp5100_tco.c b/drivers/watchdog/sp5100_tco.c
> index dd9a744f82f8..b365bbc9ac36 100644
> --- a/drivers/watchdog/sp5100_tco.c
> +++ b/drivers/watchdog/sp5100_tco.c
> @@ -223,6 +223,41 @@ static u32 sp5100_tco_read_pm_reg32(u8 index)
>  	return val;
>  }
>  
> +static int sp5100_tco_timer_init(struct sp5100_tco *tco)
> +{
> +	struct watchdog_device *wdd = &tco->wdd;
> +	struct device *dev = wdd->parent;
> +	u32 val;
> +
> +	val = readl(SP5100_WDT_CONTROL(tco->tcobase));
> +	if (val & SP5100_WDT_DISABLED) {
> +		dev_err(dev, "Watchdog hardware is disabled\n");
> +		return -ENODEV;
> +	}
> +
> +	/*
> +	 * Save WatchDogFired status, because WatchDogFired flag is
> +	 * cleared here.
> +	 */
> +	if (val & SP5100_WDT_FIRED)
> +		wdd->bootstatus = WDIOF_CARDRESET;
> +
> +	/* Set watchdog action to reset the system */
> +	val &= ~SP5100_WDT_ACTION_RESET;
> +	writel(val, SP5100_WDT_CONTROL(tco->tcobase));
> +
> +	/* Set a reasonable heartbeat before we stop the timer */
> +	tco_timer_set_timeout(wdd, wdd->timeout);
> +
> +	/*
> +	 * Stop the TCO before we change anything so we don't race with
> +	 * a zeroed timer.
> +	 */
> +	tco_timer_stop(wdd);
> +
> +	return 0;
> +}
> +
>  static int sp5100_tco_setupdevice(struct device *dev,
>  				  struct watchdog_device *wdd)
>  {
> @@ -348,35 +383,7 @@ static int sp5100_tco_setupdevice(struct device *dev,
>  	/* Setup the watchdog timer */
>  	tco_timer_enable(tco);
>  
> -	val = readl(SP5100_WDT_CONTROL(tco->tcobase));
> -	if (val & SP5100_WDT_DISABLED) {
> -		dev_err(dev, "Watchdog hardware is disabled\n");
> -		ret = -ENODEV;
> -		goto unreg_region;
> -	}
> -
> -	/*
> -	 * Save WatchDogFired status, because WatchDogFired flag is
> -	 * cleared here.
> -	 */
> -	if (val & SP5100_WDT_FIRED)
> -		wdd->bootstatus = WDIOF_CARDRESET;
> -	/* Set watchdog action to reset the system */
> -	val &= ~SP5100_WDT_ACTION_RESET;
> -	writel(val, SP5100_WDT_CONTROL(tco->tcobase));
> -
> -	/* Set a reasonable heartbeat before we stop the timer */
> -	tco_timer_set_timeout(wdd, wdd->timeout);
> -
> -	/*
> -	 * Stop the TCO before we change anything so we don't race with
> -	 * a zeroed timer.
> -	 */
> -	tco_timer_stop(wdd);
> -
> -	release_region(SP5100_IO_PM_INDEX_REG, SP5100_PM_IOPORTS_SIZE);
> -
> -	return 0;
> +	ret = sp5100_tco_timer_init(tco);
>  
>  unreg_region:
>  	release_region(SP5100_IO_PM_INDEX_REG, SP5100_PM_IOPORTS_SIZE);
> -- 
> 2.30.2
>
diff mbox series

Patch

diff --git a/drivers/watchdog/sp5100_tco.c b/drivers/watchdog/sp5100_tco.c
index dd9a744f82f8..b365bbc9ac36 100644
--- a/drivers/watchdog/sp5100_tco.c
+++ b/drivers/watchdog/sp5100_tco.c
@@ -223,6 +223,41 @@  static u32 sp5100_tco_read_pm_reg32(u8 index)
 	return val;
 }
 
+static int sp5100_tco_timer_init(struct sp5100_tco *tco)
+{
+	struct watchdog_device *wdd = &tco->wdd;
+	struct device *dev = wdd->parent;
+	u32 val;
+
+	val = readl(SP5100_WDT_CONTROL(tco->tcobase));
+	if (val & SP5100_WDT_DISABLED) {
+		dev_err(dev, "Watchdog hardware is disabled\n");
+		return -ENODEV;
+	}
+
+	/*
+	 * Save WatchDogFired status, because WatchDogFired flag is
+	 * cleared here.
+	 */
+	if (val & SP5100_WDT_FIRED)
+		wdd->bootstatus = WDIOF_CARDRESET;
+
+	/* Set watchdog action to reset the system */
+	val &= ~SP5100_WDT_ACTION_RESET;
+	writel(val, SP5100_WDT_CONTROL(tco->tcobase));
+
+	/* Set a reasonable heartbeat before we stop the timer */
+	tco_timer_set_timeout(wdd, wdd->timeout);
+
+	/*
+	 * Stop the TCO before we change anything so we don't race with
+	 * a zeroed timer.
+	 */
+	tco_timer_stop(wdd);
+
+	return 0;
+}
+
 static int sp5100_tco_setupdevice(struct device *dev,
 				  struct watchdog_device *wdd)
 {
@@ -348,35 +383,7 @@  static int sp5100_tco_setupdevice(struct device *dev,
 	/* Setup the watchdog timer */
 	tco_timer_enable(tco);
 
-	val = readl(SP5100_WDT_CONTROL(tco->tcobase));
-	if (val & SP5100_WDT_DISABLED) {
-		dev_err(dev, "Watchdog hardware is disabled\n");
-		ret = -ENODEV;
-		goto unreg_region;
-	}
-
-	/*
-	 * Save WatchDogFired status, because WatchDogFired flag is
-	 * cleared here.
-	 */
-	if (val & SP5100_WDT_FIRED)
-		wdd->bootstatus = WDIOF_CARDRESET;
-	/* Set watchdog action to reset the system */
-	val &= ~SP5100_WDT_ACTION_RESET;
-	writel(val, SP5100_WDT_CONTROL(tco->tcobase));
-
-	/* Set a reasonable heartbeat before we stop the timer */
-	tco_timer_set_timeout(wdd, wdd->timeout);
-
-	/*
-	 * Stop the TCO before we change anything so we don't race with
-	 * a zeroed timer.
-	 */
-	tco_timer_stop(wdd);
-
-	release_region(SP5100_IO_PM_INDEX_REG, SP5100_PM_IOPORTS_SIZE);
-
-	return 0;
+	ret = sp5100_tco_timer_init(tco);
 
 unreg_region:
 	release_region(SP5100_IO_PM_INDEX_REG, SP5100_PM_IOPORTS_SIZE);