hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/watchdog/davinci_wdt.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * drivers/char/watchdog/davinci_wdt.c
34 *
....@@ -5,10 +6,7 @@
56 *
67 * Copyright (C) 2006-2013 Texas Instruments.
78 *
8
- * 2007 (c) MontaVista Software, Inc. This file is licensed under
9
- * the terms of the GNU General Public License version 2. This program
10
- * is licensed "as is" without any warranty of any kind, whether express
11
- * or implied.
9
+ * 2007 (c) MontaVista Software, Inc.
1210 */
1311
1412 #include <linux/module.h>
....@@ -191,11 +189,15 @@
191189 .restart = davinci_wdt_restart,
192190 };
193191
192
+static void davinci_clk_disable_unprepare(void *data)
193
+{
194
+ clk_disable_unprepare(data);
195
+}
196
+
194197 static int davinci_wdt_probe(struct platform_device *pdev)
195198 {
196199 int ret = 0;
197200 struct device *dev = &pdev->dev;
198
- struct resource *wdt_mem;
199201 struct watchdog_device *wdd;
200202 struct davinci_wdt_device *davinci_wdt;
201203
....@@ -204,18 +206,19 @@
204206 return -ENOMEM;
205207
206208 davinci_wdt->clk = devm_clk_get(dev, NULL);
207
-
208
- if (IS_ERR(davinci_wdt->clk)) {
209
- if (PTR_ERR(davinci_wdt->clk) != -EPROBE_DEFER)
210
- dev_err(&pdev->dev, "failed to get clock node\n");
211
- return PTR_ERR(davinci_wdt->clk);
212
- }
209
+ if (IS_ERR(davinci_wdt->clk))
210
+ return dev_err_probe(dev, PTR_ERR(davinci_wdt->clk),
211
+ "failed to get clock node\n");
213212
214213 ret = clk_prepare_enable(davinci_wdt->clk);
215214 if (ret) {
216
- dev_err(&pdev->dev, "failed to prepare clock\n");
215
+ dev_err(dev, "failed to prepare clock\n");
217216 return ret;
218217 }
218
+ ret = devm_add_action_or_reset(dev, davinci_clk_disable_unprepare,
219
+ davinci_wdt->clk);
220
+ if (ret)
221
+ return ret;
219222
220223 platform_set_drvdata(pdev, davinci_wdt);
221224
....@@ -225,7 +228,7 @@
225228 wdd->min_timeout = 1;
226229 wdd->max_timeout = MAX_HEARTBEAT;
227230 wdd->timeout = DEFAULT_HEARTBEAT;
228
- wdd->parent = &pdev->dev;
231
+ wdd->parent = dev;
229232
230233 watchdog_init_timeout(wdd, heartbeat, dev);
231234
....@@ -235,35 +238,11 @@
235238 watchdog_set_nowayout(wdd, 1);
236239 watchdog_set_restart_priority(wdd, 128);
237240
238
- wdt_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
239
- davinci_wdt->base = devm_ioremap_resource(dev, wdt_mem);
240
- if (IS_ERR(davinci_wdt->base)) {
241
- ret = PTR_ERR(davinci_wdt->base);
242
- goto err_clk_disable;
243
- }
241
+ davinci_wdt->base = devm_platform_ioremap_resource(pdev, 0);
242
+ if (IS_ERR(davinci_wdt->base))
243
+ return PTR_ERR(davinci_wdt->base);
244244
245
- ret = watchdog_register_device(wdd);
246
- if (ret) {
247
- dev_err(dev, "cannot register watchdog device\n");
248
- goto err_clk_disable;
249
- }
250
-
251
- return 0;
252
-
253
-err_clk_disable:
254
- clk_disable_unprepare(davinci_wdt->clk);
255
-
256
- return ret;
257
-}
258
-
259
-static int davinci_wdt_remove(struct platform_device *pdev)
260
-{
261
- struct davinci_wdt_device *davinci_wdt = platform_get_drvdata(pdev);
262
-
263
- watchdog_unregister_device(&davinci_wdt->wdd);
264
- clk_disable_unprepare(davinci_wdt->clk);
265
-
266
- return 0;
245
+ return devm_watchdog_register_device(dev, wdd);
267246 }
268247
269248 static const struct of_device_id davinci_wdt_of_match[] = {
....@@ -278,7 +257,6 @@
278257 .of_match_table = davinci_wdt_of_match,
279258 },
280259 .probe = davinci_wdt_probe,
281
- .remove = davinci_wdt_remove,
282260 };
283261
284262 module_platform_driver(platform_wdt_driver);