hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/drivers/watchdog/of_xilinx_wdt.c
....@@ -151,43 +151,46 @@
151151 return XWT_TIMER_FAILED;
152152 }
153153
154
+static void xwdt_clk_disable_unprepare(void *data)
155
+{
156
+ clk_disable_unprepare(data);
157
+}
158
+
154159 static int xwdt_probe(struct platform_device *pdev)
155160 {
161
+ struct device *dev = &pdev->dev;
156162 int rc;
157163 u32 pfreq = 0, enable_once = 0;
158
- struct resource *res;
159164 struct xwdt_device *xdev;
160165 struct watchdog_device *xilinx_wdt_wdd;
161166
162
- xdev = devm_kzalloc(&pdev->dev, sizeof(*xdev), GFP_KERNEL);
167
+ xdev = devm_kzalloc(dev, sizeof(*xdev), GFP_KERNEL);
163168 if (!xdev)
164169 return -ENOMEM;
165170
166171 xilinx_wdt_wdd = &xdev->xilinx_wdt_wdd;
167172 xilinx_wdt_wdd->info = &xilinx_wdt_ident;
168173 xilinx_wdt_wdd->ops = &xilinx_wdt_ops;
169
- xilinx_wdt_wdd->parent = &pdev->dev;
174
+ xilinx_wdt_wdd->parent = dev;
170175
171
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
172
- xdev->base = devm_ioremap_resource(&pdev->dev, res);
176
+ xdev->base = devm_platform_ioremap_resource(pdev, 0);
173177 if (IS_ERR(xdev->base))
174178 return PTR_ERR(xdev->base);
175179
176
- rc = of_property_read_u32(pdev->dev.of_node, "xlnx,wdt-interval",
180
+ rc = of_property_read_u32(dev->of_node, "xlnx,wdt-interval",
177181 &xdev->wdt_interval);
178182 if (rc)
179
- dev_warn(&pdev->dev,
180
- "Parameter \"xlnx,wdt-interval\" not found\n");
183
+ dev_warn(dev, "Parameter \"xlnx,wdt-interval\" not found\n");
181184
182
- rc = of_property_read_u32(pdev->dev.of_node, "xlnx,wdt-enable-once",
185
+ rc = of_property_read_u32(dev->of_node, "xlnx,wdt-enable-once",
183186 &enable_once);
184187 if (rc)
185
- dev_warn(&pdev->dev,
188
+ dev_warn(dev,
186189 "Parameter \"xlnx,wdt-enable-once\" not found\n");
187190
188191 watchdog_set_nowayout(xilinx_wdt_wdd, enable_once);
189192
190
- xdev->clk = devm_clk_get(&pdev->dev, NULL);
193
+ xdev->clk = devm_clk_get(dev, NULL);
191194 if (IS_ERR(xdev->clk)) {
192195 if (PTR_ERR(xdev->clk) != -ENOENT)
193196 return PTR_ERR(xdev->clk);
....@@ -198,10 +201,10 @@
198201 */
199202 xdev->clk = NULL;
200203
201
- rc = of_property_read_u32(pdev->dev.of_node, "clock-frequency",
204
+ rc = of_property_read_u32(dev->of_node, "clock-frequency",
202205 &pfreq);
203206 if (rc)
204
- dev_warn(&pdev->dev,
207
+ dev_warn(dev,
205208 "The watchdog clock freq cannot be obtained\n");
206209 } else {
207210 pfreq = clk_get_rate(xdev->clk);
....@@ -220,42 +223,30 @@
220223
221224 rc = clk_prepare_enable(xdev->clk);
222225 if (rc) {
223
- dev_err(&pdev->dev, "unable to enable clock\n");
226
+ dev_err(dev, "unable to enable clock\n");
224227 return rc;
225228 }
229
+ rc = devm_add_action_or_reset(dev, xwdt_clk_disable_unprepare,
230
+ xdev->clk);
231
+ if (rc)
232
+ return rc;
226233
227234 rc = xwdt_selftest(xdev);
228235 if (rc == XWT_TIMER_FAILED) {
229
- dev_err(&pdev->dev, "SelfTest routine error\n");
230
- goto err_clk_disable;
236
+ dev_err(dev, "SelfTest routine error\n");
237
+ return rc;
231238 }
232239
233
- rc = watchdog_register_device(xilinx_wdt_wdd);
234
- if (rc) {
235
- dev_err(&pdev->dev, "Cannot register watchdog (err=%d)\n", rc);
236
- goto err_clk_disable;
237
- }
240
+ rc = devm_watchdog_register_device(dev, xilinx_wdt_wdd);
241
+ if (rc)
242
+ return rc;
238243
239244 clk_disable(xdev->clk);
240245
241
- dev_info(&pdev->dev, "Xilinx Watchdog Timer at %p with timeout %ds\n",
246
+ dev_info(dev, "Xilinx Watchdog Timer at %p with timeout %ds\n",
242247 xdev->base, xilinx_wdt_wdd->timeout);
243248
244249 platform_set_drvdata(pdev, xdev);
245
-
246
- return 0;
247
-err_clk_disable:
248
- clk_disable_unprepare(xdev->clk);
249
-
250
- return rc;
251
-}
252
-
253
-static int xwdt_remove(struct platform_device *pdev)
254
-{
255
- struct xwdt_device *xdev = platform_get_drvdata(pdev);
256
-
257
- watchdog_unregister_device(&xdev->xilinx_wdt_wdd);
258
- clk_disable_unprepare(xdev->clk);
259250
260251 return 0;
261252 }
....@@ -305,7 +296,6 @@
305296
306297 static struct platform_driver xwdt_driver = {
307298 .probe = xwdt_probe,
308
- .remove = xwdt_remove,
309299 .driver = {
310300 .name = WATCHDOG_NAME,
311301 .of_match_table = xwdt_of_match,