diff options
| author | Boris BREZILLON <b.brezillon@overkiz.com> | 2013-11-03 12:52:44 -0500 |
|---|---|---|
| committer | Wim Van Sebroeck <wim@iguana.be> | 2014-01-28 15:34:55 -0500 |
| commit | f72fa00f8ab216ee484d61de17ddc84712456c3a (patch) | |
| tree | ca9aff9149e04e11f9669c8e3af8c7516e39fc7d | |
| parent | a04c3f01d33f4661424deeff67913699a0910c53 (diff) | |
watchdog: at91sam9_wdt: increase security margin on watchdog counter reset
Try to reset the watchdog counter 4 or 2 times more often than actually
requested, to avoid spurious watchdog reset.
If this is not possible because of the min_heartbeat value, reset it at
the min_heartbeat period.
Signed-off-by: Boris BREZILLON <b.brezillon@overkiz.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
| -rw-r--r-- | drivers/watchdog/at91sam9_wdt.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/drivers/watchdog/at91sam9_wdt.c b/drivers/watchdog/at91sam9_wdt.c index ab0c4e0165d1..489729b26298 100644 --- a/drivers/watchdog/at91sam9_wdt.c +++ b/drivers/watchdog/at91sam9_wdt.c | |||
| @@ -158,6 +158,7 @@ static int at91_wdt_init(struct platform_device *pdev, struct at91wdt *wdt) | |||
| 158 | int err; | 158 | int err; |
| 159 | u32 mask = wdt->mr_mask; | 159 | u32 mask = wdt->mr_mask; |
| 160 | unsigned long min_heartbeat = 1; | 160 | unsigned long min_heartbeat = 1; |
| 161 | unsigned long max_heartbeat; | ||
| 161 | struct device *dev = &pdev->dev; | 162 | struct device *dev = &pdev->dev; |
| 162 | 163 | ||
| 163 | tmp = wdt_read(wdt, AT91_WDT_MR); | 164 | tmp = wdt_read(wdt, AT91_WDT_MR); |
| @@ -181,23 +182,29 @@ static int at91_wdt_init(struct platform_device *pdev, struct at91wdt *wdt) | |||
| 181 | if (delta < value) | 182 | if (delta < value) |
| 182 | min_heartbeat = ticks_to_hz_roundup(value - delta); | 183 | min_heartbeat = ticks_to_hz_roundup(value - delta); |
| 183 | 184 | ||
| 184 | wdt->heartbeat = ticks_to_hz_rounddown(value); | 185 | max_heartbeat = ticks_to_hz_rounddown(value); |
| 185 | if (!wdt->heartbeat) { | 186 | if (!max_heartbeat) { |
| 186 | dev_err(dev, | 187 | dev_err(dev, |
| 187 | "heartbeat is too small for the system to handle it correctly\n"); | 188 | "heartbeat is too small for the system to handle it correctly\n"); |
| 188 | return -EINVAL; | 189 | return -EINVAL; |
| 189 | } | 190 | } |
| 190 | 191 | ||
| 191 | if (wdt->heartbeat < min_heartbeat + 4) { | 192 | /* |
| 193 | * Try to reset the watchdog counter 4 or 2 times more often than | ||
| 194 | * actually requested, to avoid spurious watchdog reset. | ||
| 195 | * If this is not possible because of the min_heartbeat value, reset | ||
| 196 | * it at the min_heartbeat period. | ||
| 197 | */ | ||
| 198 | if ((max_heartbeat / 4) >= min_heartbeat) | ||
| 199 | wdt->heartbeat = max_heartbeat / 4; | ||
| 200 | else if ((max_heartbeat / 2) >= min_heartbeat) | ||
| 201 | wdt->heartbeat = max_heartbeat / 2; | ||
| 202 | else | ||
| 192 | wdt->heartbeat = min_heartbeat; | 203 | wdt->heartbeat = min_heartbeat; |
| 204 | |||
| 205 | if (max_heartbeat < min_heartbeat + 4) | ||
| 193 | dev_warn(dev, | 206 | dev_warn(dev, |
| 194 | "min heartbeat and max heartbeat might be too close for the system to handle it correctly\n"); | 207 | "min heartbeat and max heartbeat might be too close for the system to handle it correctly\n"); |
| 195 | if (wdt->heartbeat < 4) | ||
| 196 | dev_warn(dev, | ||
| 197 | "heartbeat might be too small for the system to handle it correctly\n"); | ||
| 198 | } else { | ||
| 199 | wdt->heartbeat -= 4; | ||
| 200 | } | ||
| 201 | 208 | ||
| 202 | if ((tmp & AT91_WDT_WDFIEN) && wdt->irq) { | 209 | if ((tmp & AT91_WDT_WDFIEN) && wdt->irq) { |
| 203 | err = request_irq(wdt->irq, wdt_interrupt, | 210 | err = request_irq(wdt->irq, wdt_interrupt, |
