mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-21 16:29:59 +00:00
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>
This commit is contained in:
parent
8bea27edc3
commit
27e0fe00a5
1 changed files with 42 additions and 7 deletions
|
@ -13,6 +13,7 @@
|
||||||
#include <linux/io.h>
|
#include <linux/io.h>
|
||||||
#include <linux/ioport.h>
|
#include <linux/ioport.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
|
#include <linux/platform_device.h>
|
||||||
#include <linux/watchdog.h>
|
#include <linux/watchdog.h>
|
||||||
|
|
||||||
#define DRVNAME "f71808e_wdt"
|
#define DRVNAME "f71808e_wdt"
|
||||||
|
@ -431,10 +432,19 @@ static const struct watchdog_ops fintek_wdt_ops = {
|
||||||
.set_timeout = fintek_wdt_set_timeout,
|
.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;
|
struct watchdog_device *wdd;
|
||||||
int wdt_conf, err = 0;
|
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.sioaddr = sioaddr;
|
||||||
watchdog.ident.options = WDIOF_SETTIMEOUT
|
watchdog.ident.options = WDIOF_SETTIMEOUT
|
||||||
|
@ -467,6 +477,7 @@ static int __init watchdog_init(int sioaddr)
|
||||||
|
|
||||||
superio_exit(sioaddr);
|
superio_exit(sioaddr);
|
||||||
|
|
||||||
|
wdd->parent = dev;
|
||||||
wdd->info = &watchdog.ident;
|
wdd->info = &watchdog.ident;
|
||||||
wdd->ops = &fintek_wdt_ops;
|
wdd->ops = &fintek_wdt_ops;
|
||||||
wdd->min_timeout = 1;
|
wdd->min_timeout = 1;
|
||||||
|
@ -491,16 +502,16 @@ static int __init watchdog_init(int sioaddr)
|
||||||
if (start_withtimeout) {
|
if (start_withtimeout) {
|
||||||
err = fintek_wdt_start(wdd);
|
err = fintek_wdt_start(wdd);
|
||||||
if (err) {
|
if (err) {
|
||||||
pr_err("cannot start watchdog timer\n");
|
dev_err(dev, "cannot start watchdog timer\n");
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
set_bit(WDOG_HW_RUNNING, &wdd->status);
|
set_bit(WDOG_HW_RUNNING, &wdd->status);
|
||||||
pr_info("watchdog started with initial timeout of %u sec\n",
|
dev_info(dev, "watchdog started with initial timeout of %u sec\n",
|
||||||
start_withtimeout);
|
start_withtimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
return watchdog_register_device(wdd);
|
return devm_watchdog_register_device(dev, wdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __init fintek_wdt_find(int sioaddr)
|
static int __init fintek_wdt_find(int sioaddr)
|
||||||
|
@ -566,9 +577,19 @@ static int __init fintek_wdt_find(int sioaddr)
|
||||||
return err;
|
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 int __init fintek_wdt_init(void)
|
||||||
{
|
{
|
||||||
static const unsigned short addrs[] = { 0x2e, 0x4e };
|
static const unsigned short addrs[] = { 0x2e, 0x4e };
|
||||||
|
struct resource wdt_res = {};
|
||||||
int err = -ENODEV;
|
int err = -ENODEV;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -585,12 +606,26 @@ static int __init fintek_wdt_init(void)
|
||||||
if (i == ARRAY_SIZE(addrs))
|
if (i == ARRAY_SIZE(addrs))
|
||||||
return err;
|
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)
|
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");
|
MODULE_DESCRIPTION("F71808E Watchdog Driver");
|
||||||
|
|
Loading…
Reference in a new issue