Skip to content

Commit c471830

Browse files
sriedmuellerWim Van Sebroeck
authored andcommitted
watchdog: da9063: Make use of pre-configured timeout during probe
The watchdog might already be running during boot with a timeout set by e.g. the bootloader. Make use of this pre-configured timeout instead of falling back to the default timeout if no device tree value is given. Signed-off-by: Stefan Riedmueller <[email protected]> Reviewed-by: Adam Thomson <[email protected]> Reviewed-by: Guenter Roeck <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Guenter Roeck <[email protected]> Signed-off-by: Wim Van Sebroeck <[email protected]>
1 parent e8799ce commit c471830

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

drivers/watchdog/da9063_wdt.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,16 @@ static unsigned int da9063_wdt_timeout_to_sel(unsigned int secs)
4646
}
4747

4848
/*
49-
* Return 0 if watchdog is disabled, else non zero.
49+
* Read the currently active timeout.
50+
* Zero means the watchdog is disabled.
5051
*/
51-
static unsigned int da9063_wdt_is_running(struct da9063 *da9063)
52+
static unsigned int da9063_wdt_read_timeout(struct da9063 *da9063)
5253
{
5354
unsigned int val;
5455

5556
regmap_read(da9063->regmap, DA9063_REG_CONTROL_D, &val);
5657

57-
return val & DA9063_TWDSCALE_MASK;
58+
return wdt_timeout[val & DA9063_TWDSCALE_MASK];
5859
}
5960

6061
static int da9063_wdt_disable_timer(struct da9063 *da9063)
@@ -191,6 +192,7 @@ static int da9063_wdt_probe(struct platform_device *pdev)
191192
struct device *dev = &pdev->dev;
192193
struct da9063 *da9063;
193194
struct watchdog_device *wdd;
195+
unsigned int timeout;
194196

195197
if (!dev->parent)
196198
return -EINVAL;
@@ -214,13 +216,19 @@ static int da9063_wdt_probe(struct platform_device *pdev)
214216
watchdog_set_restart_priority(wdd, 128);
215217
watchdog_set_drvdata(wdd, da9063);
216218

217-
/* Set default timeout, maybe override it with DT value, scale it */
218219
wdd->timeout = DA9063_WDG_TIMEOUT;
220+
221+
/* Use pre-configured timeout if watchdog is already running. */
222+
timeout = da9063_wdt_read_timeout(da9063);
223+
if (timeout)
224+
wdd->timeout = timeout;
225+
226+
/* Set timeout, maybe override it with DT value, scale it */
219227
watchdog_init_timeout(wdd, 0, dev);
220228
da9063_wdt_set_timeout(wdd, wdd->timeout);
221229

222-
/* Change the timeout to the default value if the watchdog is running */
223-
if (da9063_wdt_is_running(da9063)) {
230+
/* Update timeout if the watchdog is already running. */
231+
if (timeout) {
224232
da9063_wdt_update_timeout(da9063, wdd->timeout);
225233
set_bit(WDOG_HW_RUNNING, &wdd->status);
226234
}

0 commit comments

Comments
 (0)