hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/drivers/watchdog/loongson1_wdt.c
....@@ -1,10 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (c) 2016 Yang Ling <gnaygnil@gmail.com>
3
- *
4
- * This program is free software; you can redistribute it and/or modify it
5
- * under the terms of the GNU General Public License as published by the
6
- * Free Software Foundation; either version 2 of the License, or (at your
7
- * option) any later version.
84 */
95
106 #include <linux/clk.h>
....@@ -83,38 +79,44 @@
8379 .set_timeout = ls1x_wdt_set_timeout,
8480 };
8581
82
+static void ls1x_clk_disable_unprepare(void *data)
83
+{
84
+ clk_disable_unprepare(data);
85
+}
86
+
8687 static int ls1x_wdt_probe(struct platform_device *pdev)
8788 {
89
+ struct device *dev = &pdev->dev;
8890 struct ls1x_wdt_drvdata *drvdata;
8991 struct watchdog_device *ls1x_wdt;
9092 unsigned long clk_rate;
91
- struct resource *res;
9293 int err;
9394
94
- drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL);
95
+ drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
9596 if (!drvdata)
9697 return -ENOMEM;
9798
98
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
99
- drvdata->base = devm_ioremap_resource(&pdev->dev, res);
99
+ drvdata->base = devm_platform_ioremap_resource(pdev, 0);
100100 if (IS_ERR(drvdata->base))
101101 return PTR_ERR(drvdata->base);
102102
103
- drvdata->clk = devm_clk_get(&pdev->dev, pdev->name);
103
+ drvdata->clk = devm_clk_get(dev, pdev->name);
104104 if (IS_ERR(drvdata->clk))
105105 return PTR_ERR(drvdata->clk);
106106
107107 err = clk_prepare_enable(drvdata->clk);
108108 if (err) {
109
- dev_err(&pdev->dev, "clk enable failed\n");
109
+ dev_err(dev, "clk enable failed\n");
110110 return err;
111111 }
112
+ err = devm_add_action_or_reset(dev, ls1x_clk_disable_unprepare,
113
+ drvdata->clk);
114
+ if (err)
115
+ return err;
112116
113117 clk_rate = clk_get_rate(drvdata->clk);
114
- if (!clk_rate) {
115
- err = -EINVAL;
116
- goto err0;
117
- }
118
+ if (!clk_rate)
119
+ return -EINVAL;
118120 drvdata->clk_rate = clk_rate;
119121
120122 ls1x_wdt = &drvdata->wdt;
....@@ -123,41 +125,25 @@
123125 ls1x_wdt->timeout = DEFAULT_HEARTBEAT;
124126 ls1x_wdt->min_timeout = 1;
125127 ls1x_wdt->max_hw_heartbeat_ms = U32_MAX / clk_rate * 1000;
126
- ls1x_wdt->parent = &pdev->dev;
128
+ ls1x_wdt->parent = dev;
127129
128
- watchdog_init_timeout(ls1x_wdt, heartbeat, &pdev->dev);
130
+ watchdog_init_timeout(ls1x_wdt, heartbeat, dev);
129131 watchdog_set_nowayout(ls1x_wdt, nowayout);
130132 watchdog_set_drvdata(ls1x_wdt, drvdata);
131133
132
- err = watchdog_register_device(&drvdata->wdt);
133
- if (err) {
134
- dev_err(&pdev->dev, "failed to register watchdog device\n");
135
- goto err0;
136
- }
134
+ err = devm_watchdog_register_device(dev, &drvdata->wdt);
135
+ if (err)
136
+ return err;
137137
138138 platform_set_drvdata(pdev, drvdata);
139139
140
- dev_info(&pdev->dev, "Loongson1 Watchdog driver registered\n");
141
-
142
- return 0;
143
-err0:
144
- clk_disable_unprepare(drvdata->clk);
145
- return err;
146
-}
147
-
148
-static int ls1x_wdt_remove(struct platform_device *pdev)
149
-{
150
- struct ls1x_wdt_drvdata *drvdata = platform_get_drvdata(pdev);
151
-
152
- watchdog_unregister_device(&drvdata->wdt);
153
- clk_disable_unprepare(drvdata->clk);
140
+ dev_info(dev, "Loongson1 Watchdog driver registered\n");
154141
155142 return 0;
156143 }
157144
158145 static struct platform_driver ls1x_wdt_driver = {
159146 .probe = ls1x_wdt_probe,
160
- .remove = ls1x_wdt_remove,
161147 .driver = {
162148 .name = "ls1x-wdt",
163149 },