Commit 5f5aa6f1 authored by Guenter Roeck's avatar Guenter Roeck

watchdog: bcm2835_wdt: Convert to use device managed functions and other improvements

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.
Other improvements as listed below.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Drop assignments to otherwise unused variables
- Replace of_iomap() with platform_get_resource() followed by
  devm_ioremap_resource()
- Replace &pdev->dev with dev if 'struct device *dev' is a declared
  variable
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()

Cc: Stephen Warren <swarren@wwwdotorg.org>
Cc: Lee Jones <lee@kernel.org>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Ray Jui <rjui@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Acked-by: default avatarEric Anholt <eric@anholt.net>
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent cb5c14ea
...@@ -172,8 +172,8 @@ static void bcm2835_power_off(void) ...@@ -172,8 +172,8 @@ static void bcm2835_power_off(void)
static int bcm2835_wdt_probe(struct platform_device *pdev) static int bcm2835_wdt_probe(struct platform_device *pdev)
{ {
struct resource *res;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node;
struct bcm2835_wdt *wdt; struct bcm2835_wdt *wdt;
int err; int err;
...@@ -184,16 +184,15 @@ static int bcm2835_wdt_probe(struct platform_device *pdev) ...@@ -184,16 +184,15 @@ static int bcm2835_wdt_probe(struct platform_device *pdev)
spin_lock_init(&wdt->lock); spin_lock_init(&wdt->lock);
wdt->base = of_iomap(np, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!wdt->base) { wdt->base = devm_ioremap_resource(dev, res);
dev_err(dev, "Failed to remap watchdog regs"); if (IS_ERR(wdt->base))
return -ENODEV; return PTR_ERR(wdt->base);
}
watchdog_set_drvdata(&bcm2835_wdt_wdd, wdt); watchdog_set_drvdata(&bcm2835_wdt_wdd, wdt);
watchdog_init_timeout(&bcm2835_wdt_wdd, heartbeat, dev); watchdog_init_timeout(&bcm2835_wdt_wdd, heartbeat, dev);
watchdog_set_nowayout(&bcm2835_wdt_wdd, nowayout); watchdog_set_nowayout(&bcm2835_wdt_wdd, nowayout);
bcm2835_wdt_wdd.parent = &pdev->dev; bcm2835_wdt_wdd.parent = dev;
if (bcm2835_wdt_is_running(wdt)) { if (bcm2835_wdt_is_running(wdt)) {
/* /*
* The currently active timeout value (set by the * The currently active timeout value (set by the
...@@ -208,10 +207,10 @@ static int bcm2835_wdt_probe(struct platform_device *pdev) ...@@ -208,10 +207,10 @@ static int bcm2835_wdt_probe(struct platform_device *pdev)
watchdog_set_restart_priority(&bcm2835_wdt_wdd, 128); watchdog_set_restart_priority(&bcm2835_wdt_wdd, 128);
err = watchdog_register_device(&bcm2835_wdt_wdd); watchdog_stop_on_reboot(&bcm2835_wdt_wdd);
err = devm_watchdog_register_device(dev, &bcm2835_wdt_wdd);
if (err) { if (err) {
dev_err(dev, "Failed to register watchdog device"); dev_err(dev, "Failed to register watchdog device");
iounmap(wdt->base);
return err; return err;
} }
...@@ -224,21 +223,12 @@ static int bcm2835_wdt_probe(struct platform_device *pdev) ...@@ -224,21 +223,12 @@ static int bcm2835_wdt_probe(struct platform_device *pdev)
static int bcm2835_wdt_remove(struct platform_device *pdev) static int bcm2835_wdt_remove(struct platform_device *pdev)
{ {
struct bcm2835_wdt *wdt = platform_get_drvdata(pdev);
if (pm_power_off == bcm2835_power_off) if (pm_power_off == bcm2835_power_off)
pm_power_off = NULL; pm_power_off = NULL;
watchdog_unregister_device(&bcm2835_wdt_wdd);
iounmap(wdt->base);
return 0; return 0;
} }
static void bcm2835_wdt_shutdown(struct platform_device *pdev)
{
bcm2835_wdt_stop(&bcm2835_wdt_wdd);
}
static const struct of_device_id bcm2835_wdt_of_match[] = { static const struct of_device_id bcm2835_wdt_of_match[] = {
{ .compatible = "brcm,bcm2835-pm-wdt", }, { .compatible = "brcm,bcm2835-pm-wdt", },
{}, {},
...@@ -248,7 +238,6 @@ MODULE_DEVICE_TABLE(of, bcm2835_wdt_of_match); ...@@ -248,7 +238,6 @@ MODULE_DEVICE_TABLE(of, bcm2835_wdt_of_match);
static struct platform_driver bcm2835_wdt_driver = { static struct platform_driver bcm2835_wdt_driver = {
.probe = bcm2835_wdt_probe, .probe = bcm2835_wdt_probe,
.remove = bcm2835_wdt_remove, .remove = bcm2835_wdt_remove,
.shutdown = bcm2835_wdt_shutdown,
.driver = { .driver = {
.name = "bcm2835-wdt", .name = "bcm2835-wdt",
.of_match_table = bcm2835_wdt_of_match, .of_match_table = bcm2835_wdt_of_match,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment