Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

watchdog: gpio: Convert to use infrastructure triggered keepalives

The watchdog infrastructure now supports handling watchdog keepalive
if the watchdog is running while the watchdog device is closed.
The infrastructure now also supports generating additional heartbeats
if the maximum hardware timeout is smaller than or close to the
configured timeout. Convert the driver to use this infrastructure.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>

authored by

Guenter Roeck and committed by
Wim Van Sebroeck
03bca158 ecd94a41

+13 -60
+13 -60
drivers/watchdog/gpio_wdt.c
··· 18 18 19 19 #define SOFT_TIMEOUT_MIN 1 20 20 #define SOFT_TIMEOUT_DEF 60 21 - #define SOFT_TIMEOUT_MAX 0xffff 22 21 23 22 enum { 24 23 HW_ALGO_TOGGLE, ··· 29 30 bool active_low; 30 31 bool state; 31 32 bool always_running; 32 - bool armed; 33 33 unsigned int hw_algo; 34 - unsigned int hw_margin; 35 - unsigned long last_jiffies; 36 - struct timer_list timer; 37 34 struct watchdog_device wdd; 38 35 }; 39 36 ··· 42 47 gpio_direction_input(priv->gpio); 43 48 } 44 49 45 - static void gpio_wdt_hwping(unsigned long data) 50 + static int gpio_wdt_ping(struct watchdog_device *wdd) 46 51 { 47 - struct watchdog_device *wdd = (struct watchdog_device *)data; 48 52 struct gpio_wdt_priv *priv = watchdog_get_drvdata(wdd); 49 - 50 - if (priv->armed && time_after(jiffies, priv->last_jiffies + 51 - msecs_to_jiffies(wdd->timeout * 1000))) { 52 - dev_crit(wdd->parent, 53 - "Timer expired. System will reboot soon!\n"); 54 - return; 55 - } 56 - 57 - /* Restart timer */ 58 - mod_timer(&priv->timer, jiffies + priv->hw_margin); 59 53 60 54 switch (priv->hw_algo) { 61 55 case HW_ALGO_TOGGLE: ··· 59 75 gpio_set_value_cansleep(priv->gpio, priv->active_low); 60 76 break; 61 77 } 62 - } 63 - 64 - static void gpio_wdt_start_impl(struct gpio_wdt_priv *priv) 65 - { 66 - priv->state = priv->active_low; 67 - gpio_direction_output(priv->gpio, priv->state); 68 - priv->last_jiffies = jiffies; 69 - gpio_wdt_hwping((unsigned long)&priv->wdd); 78 + return 0; 70 79 } 71 80 72 81 static int gpio_wdt_start(struct watchdog_device *wdd) 73 82 { 74 83 struct gpio_wdt_priv *priv = watchdog_get_drvdata(wdd); 75 84 76 - gpio_wdt_start_impl(priv); 77 - priv->armed = true; 85 + priv->state = priv->active_low; 86 + gpio_direction_output(priv->gpio, priv->state); 78 87 79 - return 0; 88 + set_bit(WDOG_HW_RUNNING, &wdd->status); 89 + 90 + return gpio_wdt_ping(wdd); 80 91 } 81 92 82 93 static int gpio_wdt_stop(struct watchdog_device *wdd) 83 94 { 84 95 struct gpio_wdt_priv *priv = watchdog_get_drvdata(wdd); 85 96 86 - priv->armed = false; 87 97 if (!priv->always_running) { 88 - mod_timer(&priv->timer, 0); 89 98 gpio_wdt_disable(priv); 99 + clear_bit(WDOG_HW_RUNNING, &wdd->status); 90 100 } 91 101 92 102 return 0; 93 - } 94 - 95 - static int gpio_wdt_ping(struct watchdog_device *wdd) 96 - { 97 - struct gpio_wdt_priv *priv = watchdog_get_drvdata(wdd); 98 - 99 - priv->last_jiffies = jiffies; 100 - 101 - return 0; 102 - } 103 - 104 - static int gpio_wdt_set_timeout(struct watchdog_device *wdd, unsigned int t) 105 - { 106 - wdd->timeout = t; 107 - 108 - return gpio_wdt_ping(wdd); 109 103 } 110 104 111 105 static const struct watchdog_info gpio_wdt_ident = { ··· 97 135 .start = gpio_wdt_start, 98 136 .stop = gpio_wdt_stop, 99 137 .ping = gpio_wdt_ping, 100 - .set_timeout = gpio_wdt_set_timeout, 101 138 }; 102 139 103 140 static int gpio_wdt_probe(struct platform_device *pdev) ··· 146 185 if (hw_margin < 2 || hw_margin > 65535) 147 186 return -EINVAL; 148 187 149 - /* Use safe value (1/2 of real timeout) */ 150 - priv->hw_margin = msecs_to_jiffies(hw_margin / 2); 151 - 152 188 priv->always_running = of_property_read_bool(pdev->dev.of_node, 153 189 "always-running"); 154 190 ··· 154 196 priv->wdd.info = &gpio_wdt_ident; 155 197 priv->wdd.ops = &gpio_wdt_ops; 156 198 priv->wdd.min_timeout = SOFT_TIMEOUT_MIN; 157 - priv->wdd.max_timeout = SOFT_TIMEOUT_MAX; 199 + priv->wdd.max_hw_heartbeat_ms = hw_margin; 158 200 priv->wdd.parent = &pdev->dev; 159 201 160 202 if (watchdog_init_timeout(&priv->wdd, 0, &pdev->dev) < 0) 161 203 priv->wdd.timeout = SOFT_TIMEOUT_DEF; 162 204 163 - setup_timer(&priv->timer, gpio_wdt_hwping, (unsigned long)&priv->wdd); 164 - 165 205 watchdog_stop_on_reboot(&priv->wdd); 166 206 167 - ret = watchdog_register_device(&priv->wdd); 168 - if (ret) 169 - return ret; 170 - 171 207 if (priv->always_running) 172 - gpio_wdt_start_impl(priv); 208 + gpio_wdt_start(&priv->wdd); 173 209 174 - return 0; 210 + ret = watchdog_register_device(&priv->wdd); 211 + 212 + return ret; 175 213 } 176 214 177 215 static int gpio_wdt_remove(struct platform_device *pdev) 178 216 { 179 217 struct gpio_wdt_priv *priv = platform_get_drvdata(pdev); 180 218 181 - del_timer_sync(&priv->timer); 182 219 watchdog_unregister_device(&priv->wdd); 183 220 184 221 return 0;