hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/watchdog/atlas7_wdt.c
....@@ -1,9 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Watchdog driver for CSR Atlas7
34 *
45 * Copyright (c) 2015 Cambridge Silicon Radio Limited, a CSR plc group company.
5
- *
6
- * Licensed under GPLv2.
76 */
87
98 #include <linux/clk.h>
....@@ -125,80 +124,57 @@
125124 {}
126125 };
127126
127
+static void atlas7_clk_disable_unprepare(void *data)
128
+{
129
+ clk_disable_unprepare(data);
130
+}
131
+
128132 static int atlas7_wdt_probe(struct platform_device *pdev)
129133 {
130
- struct device_node *np = pdev->dev.of_node;
134
+ struct device *dev = &pdev->dev;
131135 struct atlas7_wdog *wdt;
132
- struct resource *res;
133136 struct clk *clk;
134137 int ret;
135138
136
- wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL);
139
+ wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
137140 if (!wdt)
138141 return -ENOMEM;
139
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
140
- wdt->base = devm_ioremap_resource(&pdev->dev, res);
142
+ wdt->base = devm_platform_ioremap_resource(pdev, 0);
141143 if (IS_ERR(wdt->base))
142144 return PTR_ERR(wdt->base);
143145
144
- clk = of_clk_get(np, 0);
146
+ clk = devm_clk_get(dev, NULL);
145147 if (IS_ERR(clk))
146148 return PTR_ERR(clk);
147149 ret = clk_prepare_enable(clk);
148150 if (ret) {
149
- dev_err(&pdev->dev, "clk enable failed\n");
150
- goto err;
151
+ dev_err(dev, "clk enable failed\n");
152
+ return ret;
151153 }
154
+ ret = devm_add_action_or_reset(dev, atlas7_clk_disable_unprepare, clk);
155
+ if (ret)
156
+ return ret;
152157
153158 /* disable watchdog hardware */
154159 writel(0, wdt->base + ATLAS7_WDT_CNT_CTRL);
155160
156161 wdt->tick_rate = clk_get_rate(clk);
157
- if (!wdt->tick_rate) {
158
- ret = -EINVAL;
159
- goto err1;
160
- }
162
+ if (!wdt->tick_rate)
163
+ return -EINVAL;
161164
162165 wdt->clk = clk;
163166 atlas7_wdd.min_timeout = 1;
164167 atlas7_wdd.max_timeout = UINT_MAX / wdt->tick_rate;
165168
166
- watchdog_init_timeout(&atlas7_wdd, 0, &pdev->dev);
169
+ watchdog_init_timeout(&atlas7_wdd, 0, dev);
167170 watchdog_set_nowayout(&atlas7_wdd, nowayout);
168171
169172 watchdog_set_drvdata(&atlas7_wdd, wdt);
170173 platform_set_drvdata(pdev, &atlas7_wdd);
171174
172
- ret = watchdog_register_device(&atlas7_wdd);
173
- if (ret)
174
- goto err1;
175
-
176
- return 0;
177
-
178
-err1:
179
- clk_disable_unprepare(clk);
180
-err:
181
- clk_put(clk);
182
- return ret;
183
-}
184
-
185
-static void atlas7_wdt_shutdown(struct platform_device *pdev)
186
-{
187
- struct watchdog_device *wdd = platform_get_drvdata(pdev);
188
- struct atlas7_wdog *wdt = watchdog_get_drvdata(wdd);
189
-
190
- atlas7_wdt_disable(wdd);
191
- clk_disable_unprepare(wdt->clk);
192
-}
193
-
194
-static int atlas7_wdt_remove(struct platform_device *pdev)
195
-{
196
- struct watchdog_device *wdd = platform_get_drvdata(pdev);
197
- struct atlas7_wdog *wdt = watchdog_get_drvdata(wdd);
198
-
199
- atlas7_wdt_shutdown(pdev);
200
- clk_put(wdt->clk);
201
- return 0;
175
+ watchdog_stop_on_reboot(&atlas7_wdd);
176
+ watchdog_stop_on_unregister(&atlas7_wdd);
177
+ return devm_watchdog_register_device(dev, &atlas7_wdd);
202178 }
203179
204180 static int __maybe_unused atlas7_wdt_suspend(struct device *dev)
....@@ -236,8 +212,6 @@
236212 .of_match_table = atlas7_wdt_ids,
237213 },
238214 .probe = atlas7_wdt_probe,
239
- .remove = atlas7_wdt_remove,
240
- .shutdown = atlas7_wdt_shutdown,
241215 };
242216 module_platform_driver(atlas7_wdt_driver);
243217