summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2021-08-09 18:20:36 +0200
committerWim Van Sebroeck <wim@linux-watchdog.org>2021-10-26 21:31:05 +0200
commit27e0fe00a5c618571ab1533aec5c48b7200efb09 (patch)
tree45797baa4910413aa608eef67d837e501ce512eb
parent8bea27edc393bdb66b1b586447e97146dce37fbc (diff)
watchdog: f71808e_wdt: refactor to platform device/driver pair
Driver so far wasn't ported to the driver model and registered the watchdog device out of the init after probing the I/O ports for a watchdog with correct vendor and device revision. Keep the device detection part at init time, but move watchdog registration to a platform driver probe function. Suggested-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Link: https://lore.kernel.org/r/9e1088839662e5c357286cab0b9de0bb0602e4fd.1628525954.git-series.a.fatoum@pengutronix.de Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
-rw-r--r--drivers/watchdog/f71808e_wdt.c49
1 files changed, 42 insertions, 7 deletions
diff --git a/drivers/watchdog/f71808e_wdt.c b/drivers/watchdog/f71808e_wdt.c
index 67e344627586..a23f68be137f 100644
--- a/drivers/watchdog/f71808e_wdt.c
+++ b/drivers/watchdog/f71808e_wdt.c
@@ -13,6 +13,7 @@
#include <linux/io.h>
#include <linux/ioport.h>
#include <linux/module.h>
+#include <linux/platform_device.h>
#include <linux/watchdog.h>
#define DRVNAME "f71808e_wdt"
@@ -431,10 +432,19 @@ static const struct watchdog_ops fintek_wdt_ops = {
.set_timeout = fintek_wdt_set_timeout,
};
-static int __init watchdog_init(int sioaddr)
+static int fintek_wdt_probe(struct platform_device *pdev)
{
+ struct device *dev = &pdev->dev;
struct watchdog_device *wdd;
int wdt_conf, err = 0;
+ struct resource *res;
+ int sioaddr;
+
+ res = platform_get_resource(pdev, IORESOURCE_IO, 0);
+ if (!res)
+ return -ENXIO;
+
+ sioaddr = res->start;
watchdog.sioaddr = sioaddr;
watchdog.ident.options = WDIOF_SETTIMEOUT
@@ -467,6 +477,7 @@ static int __init watchdog_init(int sioaddr)
superio_exit(sioaddr);
+ wdd->parent = dev;
wdd->info = &watchdog.ident;
wdd->ops = &fintek_wdt_ops;
wdd->min_timeout = 1;
@@ -491,16 +502,16 @@ static int __init watchdog_init(int sioaddr)
if (start_withtimeout) {
err = fintek_wdt_start(wdd);
if (err) {
- pr_err("cannot start watchdog timer\n");
+ dev_err(dev, "cannot start watchdog timer\n");
return err;
}
set_bit(WDOG_HW_RUNNING, &wdd->status);
- pr_info("watchdog started with initial timeout of %u sec\n",
- start_withtimeout);
+ dev_info(dev, "watchdog started with initial timeout of %u sec\n",
+ start_withtimeout);
}
- return watchdog_register_device(wdd);
+ return devm_watchdog_register_device(dev, wdd);
}
static int __init fintek_wdt_find(int sioaddr)
@@ -566,9 +577,19 @@ exit:
return err;
}
+static struct platform_driver fintek_wdt_driver = {
+ .probe = fintek_wdt_probe,
+ .driver = {
+ .name = DRVNAME,
+ },
+};
+
+static struct platform_device *fintek_wdt_pdev;
+
static int __init fintek_wdt_init(void)
{
static const unsigned short addrs[] = { 0x2e, 0x4e };
+ struct resource wdt_res = {};
int err = -ENODEV;
int i;
@@ -585,12 +606,26 @@ static int __init fintek_wdt_init(void)
if (i == ARRAY_SIZE(addrs))
return err;
- return watchdog_init(addrs[i]);
+ platform_driver_register(&fintek_wdt_driver);
+
+ wdt_res.name = "superio port";
+ wdt_res.flags = IORESOURCE_IO;
+ wdt_res.start = addrs[i];
+ wdt_res.end = addrs[i] + 1;
+
+ fintek_wdt_pdev = platform_device_register_simple(DRVNAME, -1, &wdt_res, 1);
+ if (IS_ERR(fintek_wdt_pdev)) {
+ platform_driver_unregister(&fintek_wdt_driver);
+ return PTR_ERR(fintek_wdt_pdev);
+ }
+
+ return 0;
}
static void __exit fintek_wdt_exit(void)
{
- watchdog_unregister_device(&watchdog.wdd);
+ platform_device_unregister(fintek_wdt_pdev);
+ platform_driver_unregister(&fintek_wdt_driver);
}
MODULE_DESCRIPTION("F71808E Watchdog Driver");