Skip to content

Commit abd71a9

Browse files
ktbowmanWim Van Sebroeck
authored andcommitted
Watchdog: sp5100_tco: Move timer initialization into function
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> Link: https://lore.kernel.org/r/20220202153525.1693378-2-terry.bowman@amd.com Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
1 parent 1aea522 commit abd71a9

1 file changed

Lines changed: 36 additions & 29 deletions

File tree

drivers/watchdog/sp5100_tco.c

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,41 @@ static u32 sp5100_tco_read_pm_reg32(u8 index)
223223
return val;
224224
}
225225

226+
static int sp5100_tco_timer_init(struct sp5100_tco *tco)
227+
{
228+
struct watchdog_device *wdd = &tco->wdd;
229+
struct device *dev = wdd->parent;
230+
u32 val;
231+
232+
val = readl(SP5100_WDT_CONTROL(tco->tcobase));
233+
if (val & SP5100_WDT_DISABLED) {
234+
dev_err(dev, "Watchdog hardware is disabled\n");
235+
return -ENODEV;
236+
}
237+
238+
/*
239+
* Save WatchDogFired status, because WatchDogFired flag is
240+
* cleared here.
241+
*/
242+
if (val & SP5100_WDT_FIRED)
243+
wdd->bootstatus = WDIOF_CARDRESET;
244+
245+
/* Set watchdog action to reset the system */
246+
val &= ~SP5100_WDT_ACTION_RESET;
247+
writel(val, SP5100_WDT_CONTROL(tco->tcobase));
248+
249+
/* Set a reasonable heartbeat before we stop the timer */
250+
tco_timer_set_timeout(wdd, wdd->timeout);
251+
252+
/*
253+
* Stop the TCO before we change anything so we don't race with
254+
* a zeroed timer.
255+
*/
256+
tco_timer_stop(wdd);
257+
258+
return 0;
259+
}
260+
226261
static int sp5100_tco_setupdevice(struct device *dev,
227262
struct watchdog_device *wdd)
228263
{
@@ -348,35 +383,7 @@ static int sp5100_tco_setupdevice(struct device *dev,
348383
/* Setup the watchdog timer */
349384
tco_timer_enable(tco);
350385

351-
val = readl(SP5100_WDT_CONTROL(tco->tcobase));
352-
if (val & SP5100_WDT_DISABLED) {
353-
dev_err(dev, "Watchdog hardware is disabled\n");
354-
ret = -ENODEV;
355-
goto unreg_region;
356-
}
357-
358-
/*
359-
* Save WatchDogFired status, because WatchDogFired flag is
360-
* cleared here.
361-
*/
362-
if (val & SP5100_WDT_FIRED)
363-
wdd->bootstatus = WDIOF_CARDRESET;
364-
/* Set watchdog action to reset the system */
365-
val &= ~SP5100_WDT_ACTION_RESET;
366-
writel(val, SP5100_WDT_CONTROL(tco->tcobase));
367-
368-
/* Set a reasonable heartbeat before we stop the timer */
369-
tco_timer_set_timeout(wdd, wdd->timeout);
370-
371-
/*
372-
* Stop the TCO before we change anything so we don't race with
373-
* a zeroed timer.
374-
*/
375-
tco_timer_stop(wdd);
376-
377-
release_region(SP5100_IO_PM_INDEX_REG, SP5100_PM_IOPORTS_SIZE);
378-
379-
return 0;
386+
ret = sp5100_tco_timer_init(tco);
380387

381388
unreg_region:
382389
release_region(SP5100_IO_PM_INDEX_REG, SP5100_PM_IOPORTS_SIZE);

0 commit comments

Comments
 (0)