Lines Matching +full:da9063 +full:- +full:watchdog
1 // SPDX-License-Identifier: GPL-2.0+
3 * Watchdog driver for DA9063 PMICs.
13 #include <linux/watchdog.h>
19 #include <linux/mfd/da9063/registers.h>
20 #include <linux/mfd/da9063/core.h>
25 * Watchdog selector to timeout in seconds.
27 * others: timeout = 2048 ms * 2^(TWDSCALE-1).
34 #define DA9063_TWDSCALE_MAX (ARRAY_SIZE(wdt_timeout) - 1)
54 * Zero means the watchdog is disabled.
56 static unsigned int da9063_wdt_read_timeout(struct da9063 *da9063) in da9063_wdt_read_timeout() argument
60 regmap_read(da9063->regmap, DA9063_REG_CONTROL_D, &val); in da9063_wdt_read_timeout()
65 static int da9063_wdt_disable_timer(struct da9063 *da9063) in da9063_wdt_disable_timer() argument
67 return regmap_update_bits(da9063->regmap, DA9063_REG_CONTROL_D, in da9063_wdt_disable_timer()
73 da9063_wdt_update_timeout(struct da9063 *da9063, unsigned int timeout) in da9063_wdt_update_timeout() argument
79 * The watchdog triggers a reboot if a timeout value is already in da9063_wdt_update_timeout()
81 * in one: indicating the counter limit and starting the watchdog. in da9063_wdt_update_timeout()
82 * The watchdog must be disabled to be able to change the timeout in da9063_wdt_update_timeout()
83 * value if the watchdog is already running. Then we can set the in da9063_wdt_update_timeout()
84 * new timeout value which enables the watchdog again. in da9063_wdt_update_timeout()
86 ret = da9063_wdt_disable_timer(da9063); in da9063_wdt_update_timeout()
93 return regmap_update_bits(da9063->regmap, DA9063_REG_CONTROL_D, in da9063_wdt_update_timeout()
99 struct da9063 *da9063 = watchdog_get_drvdata(wdd); in da9063_wdt_start() local
102 ret = da9063_wdt_update_timeout(da9063, wdd->timeout); in da9063_wdt_start()
104 dev_err(da9063->dev, "Watchdog failed to start (err = %d)\n", in da9063_wdt_start()
112 struct da9063 *da9063 = watchdog_get_drvdata(wdd); in da9063_wdt_stop() local
115 ret = da9063_wdt_disable_timer(da9063); in da9063_wdt_stop()
117 dev_alert(da9063->dev, "Watchdog failed to stop (err = %d)\n", in da9063_wdt_stop()
125 struct da9063 *da9063 = watchdog_get_drvdata(wdd); in da9063_wdt_ping() local
135 ret = regmap_write(da9063->regmap, DA9063_REG_CONTROL_F, in da9063_wdt_ping()
138 dev_alert(da9063->dev, "Failed to ping the watchdog (err = %d)\n", in da9063_wdt_ping()
147 struct da9063 *da9063 = watchdog_get_drvdata(wdd); in da9063_wdt_set_timeout() local
152 * 1. The watchdog is off and someone wants to set the timeout for the in da9063_wdt_set_timeout()
154 * 2. The watchdog is already running and a new timeout value should be in da9063_wdt_set_timeout()
157 * The watchdog can't store a timeout value not equal zero without in da9063_wdt_set_timeout()
158 * enabling the watchdog, so the timeout must be buffered by the driver. in da9063_wdt_set_timeout()
161 ret = da9063_wdt_update_timeout(da9063, timeout); in da9063_wdt_set_timeout()
164 dev_err(da9063->dev, "Failed to set watchdog timeout (err = %d)\n", in da9063_wdt_set_timeout()
167 wdd->timeout = wdt_timeout[da9063_wdt_timeout_to_sel(timeout)]; in da9063_wdt_set_timeout()
175 struct da9063 *da9063 = watchdog_get_drvdata(wdd); in da9063_wdt_restart() local
176 struct i2c_client *client = to_i2c_client(da9063->dev); in da9063_wdt_restart()
187 ret = __i2c_smbus_xfer(client->adapter, client->addr, client->flags, in da9063_wdt_restart()
192 dev_alert(da9063->dev, "Failed to shutdown (err = %d)\n", in da9063_wdt_restart()
203 .identity = "DA9063 Watchdog",
217 struct device *dev = &pdev->dev; in da9063_wdt_probe()
218 struct da9063 *da9063; in da9063_wdt_probe() local
222 if (!dev->parent) in da9063_wdt_probe()
223 return -EINVAL; in da9063_wdt_probe()
225 da9063 = dev_get_drvdata(dev->parent); in da9063_wdt_probe()
226 if (!da9063) in da9063_wdt_probe()
227 return -EINVAL; in da9063_wdt_probe()
231 return -ENOMEM; in da9063_wdt_probe()
233 use_sw_pm = device_property_present(dev, "dlg,use-sw-pm"); in da9063_wdt_probe()
235 wdd->info = &da9063_watchdog_info; in da9063_wdt_probe()
236 wdd->ops = &da9063_watchdog_ops; in da9063_wdt_probe()
237 wdd->min_timeout = DA9063_WDT_MIN_TIMEOUT; in da9063_wdt_probe()
238 wdd->max_timeout = DA9063_WDT_MAX_TIMEOUT; in da9063_wdt_probe()
239 wdd->min_hw_heartbeat_ms = DA9063_RESET_PROTECTION_MS; in da9063_wdt_probe()
240 wdd->parent = dev; in da9063_wdt_probe()
241 wdd->status = WATCHDOG_NOWAYOUT_INIT_STATUS; in da9063_wdt_probe()
244 watchdog_set_drvdata(wdd, da9063); in da9063_wdt_probe()
247 wdd->timeout = DA9063_WDG_TIMEOUT; in da9063_wdt_probe()
249 /* Use pre-configured timeout if watchdog is already running. */ in da9063_wdt_probe()
250 timeout = da9063_wdt_read_timeout(da9063); in da9063_wdt_probe()
252 wdd->timeout = timeout; in da9063_wdt_probe()
256 da9063_wdt_set_timeout(wdd, wdd->timeout); in da9063_wdt_probe()
258 /* Update timeout if the watchdog is already running. */ in da9063_wdt_probe()
260 da9063_wdt_update_timeout(da9063, wdd->timeout); in da9063_wdt_probe()
261 set_bit(WDOG_HW_RUNNING, &wdd->status); in da9063_wdt_probe()
306 MODULE_DESCRIPTION("Watchdog driver for Dialog DA9063");