Skip to content

Commit e8799ce

Browse files
sriedmuellerWim Van Sebroeck
authored andcommitted
watchdog: da9062: Initialize timeout during probe
During probe try to set the timeout from device tree and fall back to either the pre-configured timeout set by e.g. the bootloader in case the watchdog is already running or the default value. If the watchdog is already running make sure to update the timeout and tell the framework about the running state to make sure the watchdog is handled correctly until user space takes over. Updating the timeout also removes the need for an additional manual ping so we can remove that as well. 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 f249eef commit e8799ce

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

drivers/watchdog/da9062_wdt.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ struct da9062_watchdog {
3535
bool use_sw_pm;
3636
};
3737

38+
static unsigned int da9062_wdt_read_timeout(struct da9062_watchdog *wdt)
39+
{
40+
unsigned int val;
41+
42+
regmap_read(wdt->hw->regmap, DA9062AA_CONTROL_D, &val);
43+
44+
return wdt_timeout[val & DA9062AA_TWDSCALE_MASK];
45+
}
46+
3847
static unsigned int da9062_wdt_timeout_to_sel(unsigned int secs)
3948
{
4049
unsigned int i;
@@ -183,7 +192,7 @@ MODULE_DEVICE_TABLE(of, da9062_compatible_id_table);
183192
static int da9062_wdt_probe(struct platform_device *pdev)
184193
{
185194
struct device *dev = &pdev->dev;
186-
int ret;
195+
unsigned int timeout;
187196
struct da9062 *chip;
188197
struct da9062_watchdog *wdt;
189198

@@ -213,11 +222,19 @@ static int da9062_wdt_probe(struct platform_device *pdev)
213222
watchdog_set_drvdata(&wdt->wdtdev, wdt);
214223
dev_set_drvdata(dev, &wdt->wdtdev);
215224

216-
ret = devm_watchdog_register_device(dev, &wdt->wdtdev);
217-
if (ret < 0)
218-
return ret;
225+
timeout = da9062_wdt_read_timeout(wdt);
226+
if (timeout)
227+
wdt->wdtdev.timeout = timeout;
228+
229+
/* Set timeout from DT value if available */
230+
watchdog_init_timeout(&wdt->wdtdev, 0, dev);
231+
232+
if (timeout) {
233+
da9062_wdt_set_timeout(&wdt->wdtdev, wdt->wdtdev.timeout);
234+
set_bit(WDOG_HW_RUNNING, &wdt->wdtdev.status);
235+
}
219236

220-
return da9062_wdt_ping(&wdt->wdtdev);
237+
return devm_watchdog_register_device(dev, &wdt->wdtdev);
221238
}
222239

223240
static int __maybe_unused da9062_wdt_suspend(struct device *dev)

0 commit comments

Comments
 (0)