Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Watchdog driver for DA9063 PMICs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright(c) 2012 Dialog Semiconductor Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Author: Mariusz Wojtasik <mariusz.wojtasik@diasemi.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/watchdog.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/mfd/da9063/registers.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/mfd/da9063/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * Watchdog selector to timeout in seconds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *   0: WDT disabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  *   others: timeout = 2048 ms * 2^(TWDSCALE-1).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static const unsigned int wdt_timeout[] = { 0, 2, 4, 8, 16, 32, 65, 131 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define DA9063_TWDSCALE_DISABLE		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define DA9063_TWDSCALE_MIN		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define DA9063_TWDSCALE_MAX		(ARRAY_SIZE(wdt_timeout) - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define DA9063_WDT_MIN_TIMEOUT		wdt_timeout[DA9063_TWDSCALE_MIN]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define DA9063_WDT_MAX_TIMEOUT		wdt_timeout[DA9063_TWDSCALE_MAX]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define DA9063_WDG_TIMEOUT		wdt_timeout[3]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define DA9063_RESET_PROTECTION_MS	256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static unsigned int da9063_wdt_timeout_to_sel(unsigned int secs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	for (i = DA9063_TWDSCALE_MIN; i <= DA9063_TWDSCALE_MAX; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		if (wdt_timeout[i] >= secs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 			return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	return DA9063_TWDSCALE_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * Read the currently active timeout.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * Zero means the watchdog is disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static unsigned int da9063_wdt_read_timeout(struct da9063 *da9063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	regmap_read(da9063->regmap, DA9063_REG_CONTROL_D, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	return wdt_timeout[val & DA9063_TWDSCALE_MASK];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) static int da9063_wdt_disable_timer(struct da9063 *da9063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	return regmap_update_bits(da9063->regmap, DA9063_REG_CONTROL_D,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 				  DA9063_TWDSCALE_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 				  DA9063_TWDSCALE_DISABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) da9063_wdt_update_timeout(struct da9063 *da9063, unsigned int timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	unsigned int regval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	 * The watchdog triggers a reboot if a timeout value is already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	 * programmed because the timeout value combines two functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	 * in one: indicating the counter limit and starting the watchdog.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	 * The watchdog must be disabled to be able to change the timeout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	 * value if the watchdog is already running. Then we can set the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	 * new timeout value which enables the watchdog again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	ret = da9063_wdt_disable_timer(da9063);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	usleep_range(150, 300);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	regval = da9063_wdt_timeout_to_sel(timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	return regmap_update_bits(da9063->regmap, DA9063_REG_CONTROL_D,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 				  DA9063_TWDSCALE_MASK, regval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) static int da9063_wdt_start(struct watchdog_device *wdd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	struct da9063 *da9063 = watchdog_get_drvdata(wdd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	ret = da9063_wdt_update_timeout(da9063, wdd->timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		dev_err(da9063->dev, "Watchdog failed to start (err = %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static int da9063_wdt_stop(struct watchdog_device *wdd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	struct da9063 *da9063 = watchdog_get_drvdata(wdd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	ret = da9063_wdt_disable_timer(da9063);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		dev_alert(da9063->dev, "Watchdog failed to stop (err = %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			  ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static int da9063_wdt_ping(struct watchdog_device *wdd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	struct da9063 *da9063 = watchdog_get_drvdata(wdd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	ret = regmap_write(da9063->regmap, DA9063_REG_CONTROL_F,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			   DA9063_WATCHDOG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		dev_alert(da9063->dev, "Failed to ping the watchdog (err = %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			  ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static int da9063_wdt_set_timeout(struct watchdog_device *wdd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 				  unsigned int timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	struct da9063 *da9063 = watchdog_get_drvdata(wdd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	 * There are two cases when a set_timeout() will be called:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	 * 1. The watchdog is off and someone wants to set the timeout for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	 *    further use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	 * 2. The watchdog is already running and a new timeout value should be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	 *    set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	 * The watchdog can't store a timeout value not equal zero without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	 * enabling the watchdog, so the timeout must be buffered by the driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if (watchdog_active(wdd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		ret = da9063_wdt_update_timeout(da9063, timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		dev_err(da9063->dev, "Failed to set watchdog timeout (err = %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		wdd->timeout = wdt_timeout[da9063_wdt_timeout_to_sel(timeout)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static int da9063_wdt_restart(struct watchdog_device *wdd, unsigned long action,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			      void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	struct da9063 *da9063 = watchdog_get_drvdata(wdd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	ret = regmap_write(da9063->regmap, DA9063_REG_CONTROL_F,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			   DA9063_SHUTDOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		dev_alert(da9063->dev, "Failed to shutdown (err = %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			  ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static const struct watchdog_info da9063_watchdog_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	.identity = "DA9063 Watchdog",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static const struct watchdog_ops da9063_watchdog_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	.start = da9063_wdt_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	.stop = da9063_wdt_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	.ping = da9063_wdt_ping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	.set_timeout = da9063_wdt_set_timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	.restart = da9063_wdt_restart,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static int da9063_wdt_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	struct da9063 *da9063;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	struct watchdog_device *wdd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	unsigned int timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	if (!dev->parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	da9063 = dev_get_drvdata(dev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	if (!da9063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	wdd = devm_kzalloc(dev, sizeof(*wdd), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	if (!wdd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	wdd->info = &da9063_watchdog_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	wdd->ops = &da9063_watchdog_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	wdd->min_timeout = DA9063_WDT_MIN_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	wdd->max_timeout = DA9063_WDT_MAX_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	wdd->min_hw_heartbeat_ms = DA9063_RESET_PROTECTION_MS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	wdd->parent = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	wdd->status = WATCHDOG_NOWAYOUT_INIT_STATUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	watchdog_set_restart_priority(wdd, 128);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	watchdog_set_drvdata(wdd, da9063);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	wdd->timeout = DA9063_WDG_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	/* Use pre-configured timeout if watchdog is already running. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	timeout = da9063_wdt_read_timeout(da9063);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	if (timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		wdd->timeout = timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	/* Set timeout, maybe override it with DT value, scale it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	watchdog_init_timeout(wdd, 0, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	da9063_wdt_set_timeout(wdd, wdd->timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	/* Update timeout if the watchdog is already running. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if (timeout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		da9063_wdt_update_timeout(da9063, wdd->timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		set_bit(WDOG_HW_RUNNING, &wdd->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	return devm_watchdog_register_device(dev, wdd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static struct platform_driver da9063_wdt_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	.probe = da9063_wdt_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		.name = DA9063_DRVNAME_WATCHDOG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) module_platform_driver(da9063_wdt_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) MODULE_AUTHOR("Mariusz Wojtasik <mariusz.wojtasik@diasemi.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) MODULE_DESCRIPTION("Watchdog driver for Dialog DA9063");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) MODULE_ALIAS("platform:" DA9063_DRVNAME_WATCHDOG);