diff options
author | Marco Felsch <m.felsch@pengutronix.de> | 2018-06-04 11:00:59 -0400 |
---|---|---|
committer | Wim Van Sebroeck <wim@linux-watchdog.org> | 2018-06-07 06:41:43 -0400 |
commit | 16a7eec2fcd020c73cf0ca38bf774775167d22eb (patch) | |
tree | f56c361e1a111e51aff2d10f2a9be4cc60f86be4 | |
parent | 6f4cedb7b4c35473f8f600cc09fa084185803265 (diff) |
watchdog: da9063: remove duplicated timeout_to_sel calls
Every time da9063_wdt_update_timeout() gets called a timeout_to_sel() is
made because the timeout argument of update_timeout() is the raw
register value. Moving the second<->raw-value translation into
da9063_wdt_update_timeout() removes duplicated code.
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
Acked-by: Steve Twiss <stwiss.opensource@diasemi.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
-rw-r--r-- | drivers/watchdog/da9063_wdt.c | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/drivers/watchdog/da9063_wdt.c b/drivers/watchdog/da9063_wdt.c index 760aa9bca81b..384dca16af8b 100644 --- a/drivers/watchdog/da9063_wdt.c +++ b/drivers/watchdog/da9063_wdt.c | |||
@@ -64,8 +64,10 @@ static int da9063_wdt_disable_timer(struct da9063 *da9063) | |||
64 | DA9063_TWDSCALE_DISABLE); | 64 | DA9063_TWDSCALE_DISABLE); |
65 | } | 65 | } |
66 | 66 | ||
67 | static int da9063_wdt_update_timeout(struct da9063 *da9063, unsigned int regval) | 67 | static int |
68 | da9063_wdt_update_timeout(struct da9063 *da9063, unsigned int timeout) | ||
68 | { | 69 | { |
70 | unsigned int regval; | ||
69 | int ret; | 71 | int ret; |
70 | 72 | ||
71 | /* | 73 | /* |
@@ -81,6 +83,7 @@ static int da9063_wdt_update_timeout(struct da9063 *da9063, unsigned int regval) | |||
81 | return ret; | 83 | return ret; |
82 | 84 | ||
83 | usleep_range(150, 300); | 85 | usleep_range(150, 300); |
86 | regval = da9063_wdt_timeout_to_sel(timeout); | ||
84 | 87 | ||
85 | return regmap_update_bits(da9063->regmap, DA9063_REG_CONTROL_D, | 88 | return regmap_update_bits(da9063->regmap, DA9063_REG_CONTROL_D, |
86 | DA9063_TWDSCALE_MASK, regval); | 89 | DA9063_TWDSCALE_MASK, regval); |
@@ -89,11 +92,9 @@ static int da9063_wdt_update_timeout(struct da9063 *da9063, unsigned int regval) | |||
89 | static int da9063_wdt_start(struct watchdog_device *wdd) | 92 | static int da9063_wdt_start(struct watchdog_device *wdd) |
90 | { | 93 | { |
91 | struct da9063 *da9063 = watchdog_get_drvdata(wdd); | 94 | struct da9063 *da9063 = watchdog_get_drvdata(wdd); |
92 | unsigned int selector; | ||
93 | int ret; | 95 | int ret; |
94 | 96 | ||
95 | selector = da9063_wdt_timeout_to_sel(wdd->timeout); | 97 | ret = da9063_wdt_update_timeout(da9063, wdd->timeout); |
96 | ret = da9063_wdt_update_timeout(da9063, selector); | ||
97 | if (ret) | 98 | if (ret) |
98 | dev_err(da9063->dev, "Watchdog failed to start (err = %d)\n", | 99 | dev_err(da9063->dev, "Watchdog failed to start (err = %d)\n", |
99 | ret); | 100 | ret); |
@@ -132,11 +133,8 @@ static int da9063_wdt_set_timeout(struct watchdog_device *wdd, | |||
132 | unsigned int timeout) | 133 | unsigned int timeout) |
133 | { | 134 | { |
134 | struct da9063 *da9063 = watchdog_get_drvdata(wdd); | 135 | struct da9063 *da9063 = watchdog_get_drvdata(wdd); |
135 | unsigned int selector; | ||
136 | int ret = 0; | 136 | int ret = 0; |
137 | 137 | ||
138 | selector = da9063_wdt_timeout_to_sel(timeout); | ||
139 | |||
140 | /* | 138 | /* |
141 | * There are two cases when a set_timeout() will be called: | 139 | * There are two cases when a set_timeout() will be called: |
142 | * 1. The watchdog is off and someone wants to set the timeout for the | 140 | * 1. The watchdog is off and someone wants to set the timeout for the |
@@ -148,13 +146,13 @@ static int da9063_wdt_set_timeout(struct watchdog_device *wdd, | |||
148 | * enabling the watchdog, so the timeout must be buffered by the driver. | 146 | * enabling the watchdog, so the timeout must be buffered by the driver. |
149 | */ | 147 | */ |
150 | if (watchdog_active(wdd)) | 148 | if (watchdog_active(wdd)) |
151 | ret = da9063_wdt_update_timeout(da9063, selector); | 149 | ret = da9063_wdt_update_timeout(da9063, timeout); |
152 | 150 | ||
153 | if (ret) | 151 | if (ret) |
154 | dev_err(da9063->dev, "Failed to set watchdog timeout (err = %d)\n", | 152 | dev_err(da9063->dev, "Failed to set watchdog timeout (err = %d)\n", |
155 | ret); | 153 | ret); |
156 | else | 154 | else |
157 | wdd->timeout = wdt_timeout[selector]; | 155 | wdd->timeout = wdt_timeout[da9063_wdt_timeout_to_sel(timeout)]; |
158 | 156 | ||
159 | return ret; | 157 | return ret; |
160 | } | 158 | } |
@@ -220,10 +218,7 @@ static int da9063_wdt_probe(struct platform_device *pdev) | |||
220 | 218 | ||
221 | /* Change the timeout to the default value if the watchdog is running */ | 219 | /* Change the timeout to the default value if the watchdog is running */ |
222 | if (da9063_wdt_is_running(da9063)) { | 220 | if (da9063_wdt_is_running(da9063)) { |
223 | unsigned int timeout; | 221 | da9063_wdt_update_timeout(da9063, DA9063_WDG_TIMEOUT); |
224 | |||
225 | timeout = da9063_wdt_timeout_to_sel(DA9063_WDG_TIMEOUT); | ||
226 | da9063_wdt_update_timeout(da9063, timeout); | ||
227 | set_bit(WDOG_HW_RUNNING, &wdd->status); | 222 | set_bit(WDOG_HW_RUNNING, &wdd->status); |
228 | } | 223 | } |
229 | 224 | ||