hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/drivers/watchdog/da9063_wdt.c
....@@ -46,15 +46,16 @@
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)
....@@ -188,17 +189,19 @@
188189
189190 static int da9063_wdt_probe(struct platform_device *pdev)
190191 {
192
+ struct device *dev = &pdev->dev;
191193 struct da9063 *da9063;
192194 struct watchdog_device *wdd;
195
+ unsigned int timeout;
193196
194
- if (!pdev->dev.parent)
197
+ if (!dev->parent)
195198 return -EINVAL;
196199
197
- da9063 = dev_get_drvdata(pdev->dev.parent);
200
+ da9063 = dev_get_drvdata(dev->parent);
198201 if (!da9063)
199202 return -EINVAL;
200203
201
- wdd = devm_kzalloc(&pdev->dev, sizeof(*wdd), GFP_KERNEL);
204
+ wdd = devm_kzalloc(dev, sizeof(*wdd), GFP_KERNEL);
202205 if (!wdd)
203206 return -ENOMEM;
204207
....@@ -207,22 +210,30 @@
207210 wdd->min_timeout = DA9063_WDT_MIN_TIMEOUT;
208211 wdd->max_timeout = DA9063_WDT_MAX_TIMEOUT;
209212 wdd->min_hw_heartbeat_ms = DA9063_RESET_PROTECTION_MS;
210
- wdd->timeout = DA9063_WDG_TIMEOUT;
211
- wdd->parent = &pdev->dev;
212
-
213
+ wdd->parent = dev;
213214 wdd->status = WATCHDOG_NOWAYOUT_INIT_STATUS;
214215
215216 watchdog_set_restart_priority(wdd, 128);
216
-
217217 watchdog_set_drvdata(wdd, da9063);
218218
219
- /* Change the timeout to the default value if the watchdog is running */
220
- if (da9063_wdt_is_running(da9063)) {
221
- da9063_wdt_update_timeout(da9063, DA9063_WDG_TIMEOUT);
219
+ 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 */
227
+ watchdog_init_timeout(wdd, 0, dev);
228
+ da9063_wdt_set_timeout(wdd, wdd->timeout);
229
+
230
+ /* Update timeout if the watchdog is already running. */
231
+ if (timeout) {
232
+ da9063_wdt_update_timeout(da9063, wdd->timeout);
222233 set_bit(WDOG_HW_RUNNING, &wdd->status);
223234 }
224235
225
- return devm_watchdog_register_device(&pdev->dev, wdd);
236
+ return devm_watchdog_register_device(dev, wdd);
226237 }
227238
228239 static struct platform_driver da9063_wdt_driver = {