[PATCH linux 2/3] watchdog/aspeed_wdt: Move watchdog reset to a separate function
OpenBMC Patches
patches at stwcx.xyz
Fri Oct 23 04:59:38 AEDT 2015
From: Jeremy Kerr <jk at ozlabs.org>
We do the same reset procedure in apeed_wdt_enable and our reboot
notifier, so move these to a separate function.
Also, use a couple of definitions for the watchdog control value
rather than a hardcoded '3'.
Signed-off-by: Jeremy Kerr <jk at ozlabs.org>
---
drivers/watchdog/aspeed_wdt.c | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/drivers/watchdog/aspeed_wdt.c b/drivers/watchdog/aspeed_wdt.c
index c4f6795..57503be 100644
--- a/drivers/watchdog/aspeed_wdt.c
+++ b/drivers/watchdog/aspeed_wdt.c
@@ -37,21 +37,27 @@ MODULE_DEVICE_TABLE(of, aspeed_wdt_of_table);
#define WDT_RELOAD_VALUE 0x04
#define WDT_RESTART 0x08
#define WDT_CTRL 0x0C
+#define WDT_CTRL_RESET_SYSTEM (0x1 << 1)
+#define WDT_CTRL_ENABLE (0x1 << 0)
#define WDT_RESTART_MAGIC 0x4755
-static int aspeed_wdt_start(struct watchdog_device *wdd)
+static void aspeed_wdt_enable(struct aspeed_wdt *wdt, int count)
{
- struct aspeed_wdt *wdt = container_of(wdd, struct aspeed_wdt, wdd);
+ u32 ctrl = WDT_CTRL_RESET_SYSTEM | WDT_CTRL_ENABLE;
writel(0, wdt->base + WDT_CTRL);
- writel(wdd->timeout * wdt->rate, wdt->base + WDT_RELOAD_VALUE);
+ writel(count, wdt->base + WDT_RELOAD_VALUE);
writel(WDT_RESTART_MAGIC, wdt->base + WDT_RESTART);
- writel(3, wdt->base + WDT_CTRL);
+ writel(ctrl, wdt->base + WDT_CTRL);
+}
+static int aspeed_wdt_start(struct watchdog_device *wdd)
+{
+ struct aspeed_wdt *wdt = container_of(wdd, struct aspeed_wdt, wdd);
dev_dbg(wdd->dev, "starting with timeout of %d (rate %lu)\n",
wdd->timeout, wdt->rate);
-
+ aspeed_wdt_enable(wdt, wdd->timeout * wdt->rate);
return 0;
}
@@ -83,19 +89,15 @@ static int aspeed_wdt_set_timeout(struct watchdog_device *wdd,
static int aspeed_wdt_restart(struct notifier_block *nb, unsigned long action,
void *data)
{
- struct aspeed_wdt *wdt = container_of(nb, struct aspeed_wdt, restart_nb);
- u32 timeout;
+ struct aspeed_wdt *wdt = container_of(nb,
+ struct aspeed_wdt, restart_nb);
/*
* Trigger watchdog bite:
* Setup reload count to be 128ms, and enable WDT.
*/
- timeout = 128 * wdt->rate / 1000;
+ aspeed_wdt_enable(wdt, 128 * wdt->rate / 1000);
- writel(0, wdt->base + WDT_CTRL);
- writel(timeout, wdt->base + WDT_RELOAD_VALUE);
- writel(WDT_RESTART_MAGIC, wdt->base + WDT_RESTART);
- writel(3, wdt->base + WDT_CTRL);
return NOTIFY_DONE;
}
--
2.6.0
More information about the openbmc
mailing list