.. | .. |
---|
46 | 46 | } |
---|
47 | 47 | |
---|
48 | 48 | /* |
---|
49 | | - * Return 0 if watchdog is disabled, else non zero. |
---|
| 49 | + * Read the currently active timeout. |
---|
| 50 | + * Zero means the watchdog is disabled. |
---|
50 | 51 | */ |
---|
51 | | -static unsigned int da9063_wdt_is_running(struct da9063 *da9063) |
---|
| 52 | +static unsigned int da9063_wdt_read_timeout(struct da9063 *da9063) |
---|
52 | 53 | { |
---|
53 | 54 | unsigned int val; |
---|
54 | 55 | |
---|
55 | 56 | regmap_read(da9063->regmap, DA9063_REG_CONTROL_D, &val); |
---|
56 | 57 | |
---|
57 | | - return val & DA9063_TWDSCALE_MASK; |
---|
| 58 | + return wdt_timeout[val & DA9063_TWDSCALE_MASK]; |
---|
58 | 59 | } |
---|
59 | 60 | |
---|
60 | 61 | static int da9063_wdt_disable_timer(struct da9063 *da9063) |
---|
.. | .. |
---|
188 | 189 | |
---|
189 | 190 | static int da9063_wdt_probe(struct platform_device *pdev) |
---|
190 | 191 | { |
---|
| 192 | + struct device *dev = &pdev->dev; |
---|
191 | 193 | struct da9063 *da9063; |
---|
192 | 194 | struct watchdog_device *wdd; |
---|
| 195 | + unsigned int timeout; |
---|
193 | 196 | |
---|
194 | | - if (!pdev->dev.parent) |
---|
| 197 | + if (!dev->parent) |
---|
195 | 198 | return -EINVAL; |
---|
196 | 199 | |
---|
197 | | - da9063 = dev_get_drvdata(pdev->dev.parent); |
---|
| 200 | + da9063 = dev_get_drvdata(dev->parent); |
---|
198 | 201 | if (!da9063) |
---|
199 | 202 | return -EINVAL; |
---|
200 | 203 | |
---|
201 | | - wdd = devm_kzalloc(&pdev->dev, sizeof(*wdd), GFP_KERNEL); |
---|
| 204 | + wdd = devm_kzalloc(dev, sizeof(*wdd), GFP_KERNEL); |
---|
202 | 205 | if (!wdd) |
---|
203 | 206 | return -ENOMEM; |
---|
204 | 207 | |
---|
.. | .. |
---|
207 | 210 | wdd->min_timeout = DA9063_WDT_MIN_TIMEOUT; |
---|
208 | 211 | wdd->max_timeout = DA9063_WDT_MAX_TIMEOUT; |
---|
209 | 212 | 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; |
---|
213 | 214 | wdd->status = WATCHDOG_NOWAYOUT_INIT_STATUS; |
---|
214 | 215 | |
---|
215 | 216 | watchdog_set_restart_priority(wdd, 128); |
---|
216 | | - |
---|
217 | 217 | watchdog_set_drvdata(wdd, da9063); |
---|
218 | 218 | |
---|
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); |
---|
222 | 233 | set_bit(WDOG_HW_RUNNING, &wdd->status); |
---|
223 | 234 | } |
---|
224 | 235 | |
---|
225 | | - return devm_watchdog_register_device(&pdev->dev, wdd); |
---|
| 236 | + return devm_watchdog_register_device(dev, wdd); |
---|
226 | 237 | } |
---|
227 | 238 | |
---|
228 | 239 | static struct platform_driver da9063_wdt_driver = { |
---|