Takashi Iwai 231478
From abd71a948f7aab47ca49d3e7fe6afa6c48c8aae0 Mon Sep 17 00:00:00 2001
Takashi Iwai 231478
From: Terry Bowman <terry.bowman@amd.com>
Takashi Iwai 231478
Date: Wed, 2 Feb 2022 09:35:22 -0600
Takashi Iwai 231478
Subject: [PATCH] Watchdog: sp5100_tco: Move timer initialization into function
Takashi Iwai 231478
Git-commit: abd71a948f7aab47ca49d3e7fe6afa6c48c8aae0
Takashi Iwai 231478
Patch-mainline: v5.18-rc1
Takashi Iwai 231478
References: bsc#1199260
Takashi Iwai 231478
Takashi Iwai 231478
Refactor driver's timer initialization into new function. This is needed
Takashi Iwai 231478
inorder to support adding new device layouts while using common timer
Takashi Iwai 231478
initialization.
Takashi Iwai 231478
Takashi Iwai 231478
Co-developed-by: Robert Richter <rrichter@amd.com>
Takashi Iwai 231478
Signed-off-by: Robert Richter <rrichter@amd.com>
Takashi Iwai 231478
Signed-off-by: Terry Bowman <terry.bowman@amd.com>
Takashi Iwai 231478
Tested-by: Jean Delvare <jdelvare@suse.de>
Takashi Iwai 231478
Reviewed-by: Jean Delvare <jdelvare@suse.de>
Takashi Iwai 231478
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Takashi Iwai 231478
Link: https://lore.kernel.org/r/20220202153525.1693378-2-terry.bowman@amd.com
Takashi Iwai 231478
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Takashi Iwai 231478
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
Takashi Iwai 231478
Acked-by: Takashi Iwai <tiwai@suse.de>
Takashi Iwai 231478
Takashi Iwai 231478
---
Takashi Iwai 231478
 drivers/watchdog/sp5100_tco.c | 65 +++++++++++++++++++----------------
Takashi Iwai 231478
 1 file changed, 36 insertions(+), 29 deletions(-)
Takashi Iwai 231478
Takashi Iwai 231478
diff --git a/drivers/watchdog/sp5100_tco.c b/drivers/watchdog/sp5100_tco.c
Takashi Iwai 231478
index dd9a744f82f8..b365bbc9ac36 100644
Takashi Iwai 231478
--- a/drivers/watchdog/sp5100_tco.c
Takashi Iwai 231478
+++ b/drivers/watchdog/sp5100_tco.c
Takashi Iwai 231478
@@ -223,6 +223,41 @@ static u32 sp5100_tco_read_pm_reg32(u8 index)
Takashi Iwai 231478
 	return val;
Takashi Iwai 231478
 }
Takashi Iwai 231478
 
Takashi Iwai 231478
+static int sp5100_tco_timer_init(struct sp5100_tco *tco)
Takashi Iwai 231478
+{
Takashi Iwai 231478
+	struct watchdog_device *wdd = &tco->wdd;
Takashi Iwai 231478
+	struct device *dev = wdd->parent;
Takashi Iwai 231478
+	u32 val;
Takashi Iwai 231478
+
Takashi Iwai 231478
+	val = readl(SP5100_WDT_CONTROL(tco->tcobase));
Takashi Iwai 231478
+	if (val & SP5100_WDT_DISABLED) {
Takashi Iwai 231478
+		dev_err(dev, "Watchdog hardware is disabled\n");
Takashi Iwai 231478
+		return -ENODEV;
Takashi Iwai 231478
+	}
Takashi Iwai 231478
+
Takashi Iwai 231478
+	/*
Takashi Iwai 231478
+	 * Save WatchDogFired status, because WatchDogFired flag is
Takashi Iwai 231478
+	 * cleared here.
Takashi Iwai 231478
+	 */
Takashi Iwai 231478
+	if (val & SP5100_WDT_FIRED)
Takashi Iwai 231478
+		wdd->bootstatus = WDIOF_CARDRESET;
Takashi Iwai 231478
+
Takashi Iwai 231478
+	/* Set watchdog action to reset the system */
Takashi Iwai 231478
+	val &= ~SP5100_WDT_ACTION_RESET;
Takashi Iwai 231478
+	writel(val, SP5100_WDT_CONTROL(tco->tcobase));
Takashi Iwai 231478
+
Takashi Iwai 231478
+	/* Set a reasonable heartbeat before we stop the timer */
Takashi Iwai 231478
+	tco_timer_set_timeout(wdd, wdd->timeout);
Takashi Iwai 231478
+
Takashi Iwai 231478
+	/*
Takashi Iwai 231478
+	 * Stop the TCO before we change anything so we don't race with
Takashi Iwai 231478
+	 * a zeroed timer.
Takashi Iwai 231478
+	 */
Takashi Iwai 231478
+	tco_timer_stop(wdd);
Takashi Iwai 231478
+
Takashi Iwai 231478
+	return 0;
Takashi Iwai 231478
+}
Takashi Iwai 231478
+
Takashi Iwai 231478
 static int sp5100_tco_setupdevice(struct device *dev,
Takashi Iwai 231478
 				  struct watchdog_device *wdd)
Takashi Iwai 231478
 {
Takashi Iwai 231478
@@ -348,35 +383,7 @@ static int sp5100_tco_setupdevice(struct device *dev,
Takashi Iwai 231478
 	/* Setup the watchdog timer */
Takashi Iwai 231478
 	tco_timer_enable(tco);
Takashi Iwai 231478
 
Takashi Iwai 231478
-	val = readl(SP5100_WDT_CONTROL(tco->tcobase));
Takashi Iwai 231478
-	if (val & SP5100_WDT_DISABLED) {
Takashi Iwai 231478
-		dev_err(dev, "Watchdog hardware is disabled\n");
Takashi Iwai 231478
-		ret = -ENODEV;
Takashi Iwai 231478
-		goto unreg_region;
Takashi Iwai 231478
-	}
Takashi Iwai 231478
-
Takashi Iwai 231478
-	/*
Takashi Iwai 231478
-	 * Save WatchDogFired status, because WatchDogFired flag is
Takashi Iwai 231478
-	 * cleared here.
Takashi Iwai 231478
-	 */
Takashi Iwai 231478
-	if (val & SP5100_WDT_FIRED)
Takashi Iwai 231478
-		wdd->bootstatus = WDIOF_CARDRESET;
Takashi Iwai 231478
-	/* Set watchdog action to reset the system */
Takashi Iwai 231478
-	val &= ~SP5100_WDT_ACTION_RESET;
Takashi Iwai 231478
-	writel(val, SP5100_WDT_CONTROL(tco->tcobase));
Takashi Iwai 231478
-
Takashi Iwai 231478
-	/* Set a reasonable heartbeat before we stop the timer */
Takashi Iwai 231478
-	tco_timer_set_timeout(wdd, wdd->timeout);
Takashi Iwai 231478
-
Takashi Iwai 231478
-	/*
Takashi Iwai 231478
-	 * Stop the TCO before we change anything so we don't race with
Takashi Iwai 231478
-	 * a zeroed timer.
Takashi Iwai 231478
-	 */
Takashi Iwai 231478
-	tco_timer_stop(wdd);
Takashi Iwai 231478
-
Takashi Iwai 231478
-	release_region(SP5100_IO_PM_INDEX_REG, SP5100_PM_IOPORTS_SIZE);
Takashi Iwai 231478
-
Takashi Iwai 231478
-	return 0;
Takashi Iwai 231478
+	ret = sp5100_tco_timer_init(tco);
Takashi Iwai 231478
 
Takashi Iwai 231478
 unreg_region:
Takashi Iwai 231478
 	release_region(SP5100_IO_PM_INDEX_REG, SP5100_PM_IOPORTS_SIZE);
Takashi Iwai 231478
-- 
Takashi Iwai 231478
2.35.3
Takashi Iwai 231478