diff options
Diffstat (limited to 'drivers/watchdog/wdt-uclass.c')
-rw-r--r-- | drivers/watchdog/wdt-uclass.c | 58 |
1 files changed, 22 insertions, 36 deletions
diff --git a/drivers/watchdog/wdt-uclass.c b/drivers/watchdog/wdt-uclass.c index 417e8d7eef9..10be334e9ed 100644 --- a/drivers/watchdog/wdt-uclass.c +++ b/drivers/watchdog/wdt-uclass.c @@ -5,7 +5,6 @@ #define LOG_CATEGORY UCLASS_WDT -#include <common.h> #include <cyclic.h> #include <div64.h> #include <dm.h> @@ -18,17 +17,20 @@ #include <asm/global_data.h> #include <dm/device-internal.h> #include <dm/lists.h> +#include <linux/kernel.h> DECLARE_GLOBAL_DATA_PTR; #define WATCHDOG_TIMEOUT_SECS (CONFIG_WATCHDOG_TIMEOUT_MSECS / 1000) struct wdt_priv { + /* The udevice owning this wdt_priv. */ + struct udevice *dev; /* Timeout, in seconds, to configure this device to. */ u32 timeout; /* * Time, in milliseconds, between calling the device's ->reset() - * method from watchdog_reset(). + * method from schedule(). */ ulong reset_period; /* @@ -41,18 +43,17 @@ struct wdt_priv { /* autostart */ bool autostart; - struct cyclic_info *cyclic; + struct cyclic_info cyclic; }; -static void wdt_cyclic(void *ctx) +static void wdt_cyclic(struct cyclic_info *c) { - struct udevice *dev = ctx; - struct wdt_priv *priv; + struct wdt_priv *priv = container_of(c, struct wdt_priv, cyclic); + struct udevice *dev = priv->dev; if (!device_active(dev)) return; - priv = dev_get_uclass_priv(dev); if (!priv->running) return; @@ -122,24 +123,20 @@ int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags) struct wdt_priv *priv = dev_get_uclass_priv(dev); char str[16]; - priv->running = true; - memset(str, 0, 16); if (IS_ENABLED(CONFIG_WATCHDOG)) { + if (priv->running) + cyclic_unregister(&priv->cyclic); + /* Register the watchdog driver as a cyclic function */ - priv->cyclic = cyclic_register(wdt_cyclic, - priv->reset_period * 1000, - dev->name, dev); - if (!priv->cyclic) { - printf("cyclic_register for %s failed\n", - dev->name); - return -ENODEV; - } else { - snprintf(str, 16, "every %ldms", - priv->reset_period); - } + cyclic_register(&priv->cyclic, wdt_cyclic, + priv->reset_period * 1000, + dev->name); + + snprintf(str, 16, "every %ldms", priv->reset_period); } + priv->running = true; printf("WDT: Started %s with%s servicing %s (%ds timeout)\n", dev->name, IS_ENABLED(CONFIG_WATCHDOG) ? "" : "out", str, (u32)lldiv(timeout_ms, 1000)); @@ -160,6 +157,9 @@ int wdt_stop(struct udevice *dev) if (ret == 0) { struct wdt_priv *priv = dev_get_uclass_priv(dev); + if (IS_ENABLED(CONFIG_WATCHDOG) && priv->running) + cyclic_unregister(&priv->cyclic); + priv->running = false; } @@ -222,21 +222,6 @@ int wdt_expire_now(struct udevice *dev, ulong flags) return ret; } -#if defined(CONFIG_WATCHDOG) -/* - * Called by macro WATCHDOG_RESET. This function be called *very* early, - * so we need to make sure, that the watchdog driver is ready before using - * it in this function. - */ -void watchdog_reset(void) -{ - /* - * Empty function for now. The actual WDT handling is now done in - * the cyclic function instead. - */ -} -#endif - static int wdt_pre_probe(struct udevice *dev) { u32 timeout = WATCHDOG_TIMEOUT_SECS; @@ -258,12 +243,13 @@ static int wdt_pre_probe(struct udevice *dev) autostart = true; } priv = dev_get_uclass_priv(dev); + priv->dev = dev; priv->timeout = timeout; priv->reset_period = reset_period; priv->autostart = autostart; /* * Pretend this device was last reset "long" ago so the first - * watchdog_reset will actually call its ->reset method. + * schedule() will actually call its ->reset method. */ priv->next_reset = get_timer(0); |