diff --git a/drivers/watchdog/aspeed_wdt.c b/drivers/watchdog/aspeed_wdt.c index e863424210d960..9b82420f902542 100644 --- a/drivers/watchdog/aspeed_wdt.c +++ b/drivers/watchdog/aspeed_wdt.c @@ -33,25 +33,33 @@ static const struct of_device_id aspeed_wdt_of_table[] = { }; MODULE_DEVICE_TABLE(of, aspeed_wdt_of_table); -#define WDT_STATUS 0x00 -#define WDT_BITE_COUNT 0x04 -#define WDT_RELOAD 0x08 -#define WDT_CTRL 0x0C +#define WDT_STATUS 0x00 +#define WDT_RELOAD_VALUE 0x04 +#define WDT_RESTART 0x08 +#define WDT_CTRL 0x0C +#define WDT_CTRL_RESET_MODE_FULL_CHIP (0x01 << 5) +#define WDT_CTRL_RESET_SYSTEM (0x1 << 1) +#define WDT_CTRL_ENABLE (0x1 << 0) -#define WDT_RELOAD_MAGIC 0x4755 +#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_MODE_FULL_CHIP | WDT_CTRL_RESET_SYSTEM | + WDT_CTRL_ENABLE; writel(0, wdt->base + WDT_CTRL); - writel(wdd->timeout * wdt->rate, wdt->base + WDT_BITE_COUNT); - writel(WDT_RELOAD_MAGIC, wdt->base + WDT_RELOAD); - writel(3, wdt->base + WDT_CTRL); + writel(count, wdt->base + WDT_RELOAD_VALUE); + writel(WDT_RESTART_MAGIC, wdt->base + WDT_RESTART); + 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; } @@ -68,7 +76,7 @@ static int aspeed_wdt_ping(struct watchdog_device *wdd) struct aspeed_wdt *wdt = container_of(wdd, struct aspeed_wdt, wdd); dev_dbg(wdd->dev, "ping\n"); - writel(WDT_RELOAD_MAGIC, wdt->base + WDT_RELOAD); + writel(WDT_RESTART_MAGIC, wdt->base + WDT_RESTART); return 0; } @@ -83,19 +91,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 BITE_TIME to be 128ms, and enable WDT. + * 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_BITE_COUNT); - writel(WDT_RELOAD_MAGIC, wdt->base + WDT_RELOAD); - writel(3, wdt->base + WDT_CTRL); return NOTIFY_DONE; }