.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * PIC32 watchdog driver |
---|
3 | 4 | * |
---|
4 | 5 | * Joshua Henderson <joshua.henderson@microchip.com> |
---|
5 | 6 | * Copyright (c) 2016, Microchip Technology Inc. |
---|
6 | | - * |
---|
7 | | - * This program is free software; you can redistribute it and/or |
---|
8 | | - * modify it under the terms of the GNU General Public License |
---|
9 | | - * as published by the Free Software Foundation; either version |
---|
10 | | - * 2 of the License, or (at your option) any later version. |
---|
11 | 7 | */ |
---|
12 | 8 | #include <linux/clk.h> |
---|
13 | 9 | #include <linux/device.h> |
---|
.. | .. |
---|
166 | 162 | }; |
---|
167 | 163 | MODULE_DEVICE_TABLE(of, pic32_wdt_dt_ids); |
---|
168 | 164 | |
---|
| 165 | +static void pic32_clk_disable_unprepare(void *data) |
---|
| 166 | +{ |
---|
| 167 | + clk_disable_unprepare(data); |
---|
| 168 | +} |
---|
| 169 | + |
---|
169 | 170 | static int pic32_wdt_drv_probe(struct platform_device *pdev) |
---|
170 | 171 | { |
---|
| 172 | + struct device *dev = &pdev->dev; |
---|
171 | 173 | int ret; |
---|
172 | 174 | struct watchdog_device *wdd = &pic32_wdd; |
---|
173 | 175 | struct pic32_wdt *wdt; |
---|
174 | | - struct resource *mem; |
---|
175 | 176 | |
---|
176 | | - wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL); |
---|
| 177 | + wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); |
---|
177 | 178 | if (!wdt) |
---|
178 | 179 | return -ENOMEM; |
---|
179 | 180 | |
---|
180 | | - mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
181 | | - wdt->regs = devm_ioremap_resource(&pdev->dev, mem); |
---|
| 181 | + wdt->regs = devm_platform_ioremap_resource(pdev, 0); |
---|
182 | 182 | if (IS_ERR(wdt->regs)) |
---|
183 | 183 | return PTR_ERR(wdt->regs); |
---|
184 | 184 | |
---|
185 | | - wdt->rst_base = devm_ioremap(&pdev->dev, PIC32_BASE_RESET, 0x10); |
---|
| 185 | + wdt->rst_base = devm_ioremap(dev, PIC32_BASE_RESET, 0x10); |
---|
186 | 186 | if (!wdt->rst_base) |
---|
187 | 187 | return -ENOMEM; |
---|
188 | 188 | |
---|
189 | | - wdt->clk = devm_clk_get(&pdev->dev, NULL); |
---|
| 189 | + wdt->clk = devm_clk_get(dev, NULL); |
---|
190 | 190 | if (IS_ERR(wdt->clk)) { |
---|
191 | | - dev_err(&pdev->dev, "clk not found\n"); |
---|
| 191 | + dev_err(dev, "clk not found\n"); |
---|
192 | 192 | return PTR_ERR(wdt->clk); |
---|
193 | 193 | } |
---|
194 | 194 | |
---|
195 | 195 | ret = clk_prepare_enable(wdt->clk); |
---|
196 | 196 | if (ret) { |
---|
197 | | - dev_err(&pdev->dev, "clk enable failed\n"); |
---|
| 197 | + dev_err(dev, "clk enable failed\n"); |
---|
198 | 198 | return ret; |
---|
199 | 199 | } |
---|
| 200 | + ret = devm_add_action_or_reset(dev, pic32_clk_disable_unprepare, |
---|
| 201 | + wdt->clk); |
---|
| 202 | + if (ret) |
---|
| 203 | + return ret; |
---|
200 | 204 | |
---|
201 | 205 | if (pic32_wdt_is_win_enabled(wdt)) { |
---|
202 | | - dev_err(&pdev->dev, "windowed-clear mode is not supported.\n"); |
---|
203 | | - ret = -ENODEV; |
---|
204 | | - goto out_disable_clk; |
---|
| 206 | + dev_err(dev, "windowed-clear mode is not supported.\n"); |
---|
| 207 | + return -ENODEV; |
---|
205 | 208 | } |
---|
206 | 209 | |
---|
207 | | - wdd->timeout = pic32_wdt_get_timeout_secs(wdt, &pdev->dev); |
---|
| 210 | + wdd->timeout = pic32_wdt_get_timeout_secs(wdt, dev); |
---|
208 | 211 | if (!wdd->timeout) { |
---|
209 | | - dev_err(&pdev->dev, |
---|
210 | | - "failed to read watchdog register timeout\n"); |
---|
211 | | - ret = -EINVAL; |
---|
212 | | - goto out_disable_clk; |
---|
| 212 | + dev_err(dev, "failed to read watchdog register timeout\n"); |
---|
| 213 | + return -EINVAL; |
---|
213 | 214 | } |
---|
214 | 215 | |
---|
215 | | - dev_info(&pdev->dev, "timeout %d\n", wdd->timeout); |
---|
| 216 | + dev_info(dev, "timeout %d\n", wdd->timeout); |
---|
216 | 217 | |
---|
217 | 218 | wdd->bootstatus = pic32_wdt_bootstatus(wdt) ? WDIOF_CARDRESET : 0; |
---|
218 | 219 | |
---|
219 | 220 | watchdog_set_nowayout(wdd, WATCHDOG_NOWAYOUT); |
---|
220 | 221 | watchdog_set_drvdata(wdd, wdt); |
---|
221 | 222 | |
---|
222 | | - ret = watchdog_register_device(wdd); |
---|
223 | | - if (ret) { |
---|
224 | | - dev_err(&pdev->dev, "watchdog register failed, err %d\n", ret); |
---|
225 | | - goto out_disable_clk; |
---|
226 | | - } |
---|
| 223 | + ret = devm_watchdog_register_device(dev, wdd); |
---|
| 224 | + if (ret) |
---|
| 225 | + return ret; |
---|
227 | 226 | |
---|
228 | 227 | platform_set_drvdata(pdev, wdd); |
---|
229 | | - |
---|
230 | | - return 0; |
---|
231 | | - |
---|
232 | | -out_disable_clk: |
---|
233 | | - clk_disable_unprepare(wdt->clk); |
---|
234 | | - |
---|
235 | | - return ret; |
---|
236 | | -} |
---|
237 | | - |
---|
238 | | -static int pic32_wdt_drv_remove(struct platform_device *pdev) |
---|
239 | | -{ |
---|
240 | | - struct watchdog_device *wdd = platform_get_drvdata(pdev); |
---|
241 | | - struct pic32_wdt *wdt = watchdog_get_drvdata(wdd); |
---|
242 | | - |
---|
243 | | - watchdog_unregister_device(wdd); |
---|
244 | | - clk_disable_unprepare(wdt->clk); |
---|
245 | 228 | |
---|
246 | 229 | return 0; |
---|
247 | 230 | } |
---|
248 | 231 | |
---|
249 | 232 | static struct platform_driver pic32_wdt_driver = { |
---|
250 | 233 | .probe = pic32_wdt_drv_probe, |
---|
251 | | - .remove = pic32_wdt_drv_remove, |
---|
252 | 234 | .driver = { |
---|
253 | 235 | .name = "pic32-wdt", |
---|
254 | 236 | .of_match_table = of_match_ptr(pic32_wdt_dt_ids), |
---|