.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Watchdog driver for Alphascale ASM9260. |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (c) 2014 Oleksij Rempel <linux@rempel-privat.de> |
---|
5 | | - * |
---|
6 | | - * Licensed under GPLv2 or later. |
---|
7 | 6 | */ |
---|
8 | 7 | |
---|
9 | 8 | #include <linux/bitops.h> |
---|
.. | .. |
---|
196 | 195 | .restart = asm9260_restart, |
---|
197 | 196 | }; |
---|
198 | 197 | |
---|
| 198 | +static void asm9260_clk_disable_unprepare(void *data) |
---|
| 199 | +{ |
---|
| 200 | + clk_disable_unprepare(data); |
---|
| 201 | +} |
---|
| 202 | + |
---|
199 | 203 | static int asm9260_wdt_get_dt_clks(struct asm9260_wdt_priv *priv) |
---|
200 | 204 | { |
---|
201 | 205 | int err; |
---|
.. | .. |
---|
219 | 223 | dev_err(priv->dev, "Failed to enable ahb_clk!\n"); |
---|
220 | 224 | return err; |
---|
221 | 225 | } |
---|
| 226 | + err = devm_add_action_or_reset(priv->dev, |
---|
| 227 | + asm9260_clk_disable_unprepare, |
---|
| 228 | + priv->clk_ahb); |
---|
| 229 | + if (err) |
---|
| 230 | + return err; |
---|
222 | 231 | |
---|
223 | 232 | err = clk_set_rate(priv->clk, CLOCK_FREQ); |
---|
224 | 233 | if (err) { |
---|
225 | | - clk_disable_unprepare(priv->clk_ahb); |
---|
226 | 234 | dev_err(priv->dev, "Failed to set rate!\n"); |
---|
227 | 235 | return err; |
---|
228 | 236 | } |
---|
229 | 237 | |
---|
230 | 238 | err = clk_prepare_enable(priv->clk); |
---|
231 | 239 | if (err) { |
---|
232 | | - clk_disable_unprepare(priv->clk_ahb); |
---|
233 | 240 | dev_err(priv->dev, "Failed to enable clk!\n"); |
---|
234 | 241 | return err; |
---|
235 | 242 | } |
---|
| 243 | + err = devm_add_action_or_reset(priv->dev, |
---|
| 244 | + asm9260_clk_disable_unprepare, |
---|
| 245 | + priv->clk); |
---|
| 246 | + if (err) |
---|
| 247 | + return err; |
---|
236 | 248 | |
---|
237 | 249 | /* wdt has internal divider */ |
---|
238 | 250 | clk = clk_get_rate(priv->clk); |
---|
239 | 251 | if (!clk) { |
---|
240 | | - clk_disable_unprepare(priv->clk); |
---|
241 | | - clk_disable_unprepare(priv->clk_ahb); |
---|
242 | 252 | dev_err(priv->dev, "Failed, clk is 0!\n"); |
---|
243 | 253 | return -EINVAL; |
---|
244 | 254 | } |
---|
.. | .. |
---|
274 | 284 | |
---|
275 | 285 | static int asm9260_wdt_probe(struct platform_device *pdev) |
---|
276 | 286 | { |
---|
| 287 | + struct device *dev = &pdev->dev; |
---|
277 | 288 | struct asm9260_wdt_priv *priv; |
---|
278 | 289 | struct watchdog_device *wdd; |
---|
279 | | - struct resource *res; |
---|
280 | 290 | int ret; |
---|
281 | | - const char * const mode_name[] = { "hw", "sw", "debug", }; |
---|
| 291 | + static const char * const mode_name[] = { "hw", "sw", "debug", }; |
---|
282 | 292 | |
---|
283 | | - priv = devm_kzalloc(&pdev->dev, sizeof(struct asm9260_wdt_priv), |
---|
284 | | - GFP_KERNEL); |
---|
| 293 | + priv = devm_kzalloc(dev, sizeof(struct asm9260_wdt_priv), GFP_KERNEL); |
---|
285 | 294 | if (!priv) |
---|
286 | 295 | return -ENOMEM; |
---|
287 | 296 | |
---|
288 | | - priv->dev = &pdev->dev; |
---|
| 297 | + priv->dev = dev; |
---|
289 | 298 | |
---|
290 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
291 | | - priv->iobase = devm_ioremap_resource(&pdev->dev, res); |
---|
| 299 | + priv->iobase = devm_platform_ioremap_resource(pdev, 0); |
---|
292 | 300 | if (IS_ERR(priv->iobase)) |
---|
293 | 301 | return PTR_ERR(priv->iobase); |
---|
294 | 302 | |
---|
295 | | - priv->rst = devm_reset_control_get_exclusive(&pdev->dev, "wdt_rst"); |
---|
| 303 | + priv->rst = devm_reset_control_get_exclusive(dev, "wdt_rst"); |
---|
296 | 304 | if (IS_ERR(priv->rst)) |
---|
297 | 305 | return PTR_ERR(priv->rst); |
---|
298 | 306 | |
---|
.. | .. |
---|
305 | 313 | wdd->ops = &asm9260_wdt_ops; |
---|
306 | 314 | wdd->min_timeout = 1; |
---|
307 | 315 | wdd->max_timeout = BM_WDTC_MAX(priv->wdt_freq); |
---|
308 | | - wdd->parent = &pdev->dev; |
---|
| 316 | + wdd->parent = dev; |
---|
309 | 317 | |
---|
310 | 318 | watchdog_set_drvdata(wdd, priv); |
---|
311 | 319 | |
---|
.. | .. |
---|
315 | 323 | * the max instead. |
---|
316 | 324 | */ |
---|
317 | 325 | wdd->timeout = ASM9260_WDT_DEFAULT_TIMEOUT; |
---|
318 | | - watchdog_init_timeout(wdd, 0, &pdev->dev); |
---|
| 326 | + watchdog_init_timeout(wdd, 0, dev); |
---|
319 | 327 | |
---|
320 | 328 | asm9260_wdt_get_dt_mode(priv); |
---|
321 | 329 | |
---|
.. | .. |
---|
327 | 335 | * Not all supported platforms specify an interrupt for the |
---|
328 | 336 | * watchdog, so let's make it optional. |
---|
329 | 337 | */ |
---|
330 | | - ret = devm_request_irq(&pdev->dev, priv->irq, |
---|
331 | | - asm9260_wdt_irq, 0, pdev->name, priv); |
---|
| 338 | + ret = devm_request_irq(dev, priv->irq, asm9260_wdt_irq, 0, |
---|
| 339 | + pdev->name, priv); |
---|
332 | 340 | if (ret < 0) |
---|
333 | | - dev_warn(&pdev->dev, "failed to request IRQ\n"); |
---|
| 341 | + dev_warn(dev, "failed to request IRQ\n"); |
---|
334 | 342 | } |
---|
335 | 343 | |
---|
336 | 344 | watchdog_set_restart_priority(wdd, 128); |
---|
337 | 345 | |
---|
338 | | - ret = watchdog_register_device(wdd); |
---|
| 346 | + watchdog_stop_on_reboot(wdd); |
---|
| 347 | + watchdog_stop_on_unregister(wdd); |
---|
| 348 | + ret = devm_watchdog_register_device(dev, wdd); |
---|
339 | 349 | if (ret) |
---|
340 | | - goto clk_off; |
---|
| 350 | + return ret; |
---|
341 | 351 | |
---|
342 | 352 | platform_set_drvdata(pdev, priv); |
---|
343 | 353 | |
---|
344 | | - dev_info(&pdev->dev, "Watchdog enabled (timeout: %d sec, mode: %s)\n", |
---|
| 354 | + dev_info(dev, "Watchdog enabled (timeout: %d sec, mode: %s)\n", |
---|
345 | 355 | wdd->timeout, mode_name[priv->mode]); |
---|
346 | | - return 0; |
---|
347 | | - |
---|
348 | | -clk_off: |
---|
349 | | - clk_disable_unprepare(priv->clk); |
---|
350 | | - clk_disable_unprepare(priv->clk_ahb); |
---|
351 | | - return ret; |
---|
352 | | -} |
---|
353 | | - |
---|
354 | | -static void asm9260_wdt_shutdown(struct platform_device *pdev) |
---|
355 | | -{ |
---|
356 | | - struct asm9260_wdt_priv *priv = platform_get_drvdata(pdev); |
---|
357 | | - |
---|
358 | | - asm9260_wdt_disable(&priv->wdd); |
---|
359 | | -} |
---|
360 | | - |
---|
361 | | -static int asm9260_wdt_remove(struct platform_device *pdev) |
---|
362 | | -{ |
---|
363 | | - struct asm9260_wdt_priv *priv = platform_get_drvdata(pdev); |
---|
364 | | - |
---|
365 | | - asm9260_wdt_disable(&priv->wdd); |
---|
366 | | - |
---|
367 | | - watchdog_unregister_device(&priv->wdd); |
---|
368 | | - |
---|
369 | | - clk_disable_unprepare(priv->clk); |
---|
370 | | - clk_disable_unprepare(priv->clk_ahb); |
---|
371 | | - |
---|
372 | 356 | return 0; |
---|
373 | 357 | } |
---|
374 | 358 | |
---|
.. | .. |
---|
384 | 368 | .of_match_table = asm9260_wdt_of_match, |
---|
385 | 369 | }, |
---|
386 | 370 | .probe = asm9260_wdt_probe, |
---|
387 | | - .remove = asm9260_wdt_remove, |
---|
388 | | - .shutdown = asm9260_wdt_shutdown, |
---|
389 | 371 | }; |
---|
390 | 372 | module_platform_driver(asm9260_wdt_driver); |
---|
391 | 373 | |
---|