[PATCH v2 2/8] watchdog: w83627hf_wdt: Convert to platform driver model
Paul Louvel <[email protected]> Sun, 26 Jul 2026 20:44:29 +0200
| Newsgroups | org.kernel.vger.linux-watchdog,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
Convert the driver to the Linux driver model with a platform driver / device. Signed-off-by: Paul Louvel <[email protected]> --- drivers/watchdog/w83627hf_wdt.c | 126 +++++++++++++++++++++++++--------------- 1 file changed, 79 insertions(+), 47 deletions(-) diff --git a/drivers/watchdog/w83627hf_wdt.c b/drivers/watchdog/w83627hf_wdt.c index 1529a4e16820..206ab91fdb2a 100644 --- a/drivers/watchdog/w83627hf_wdt.c +++ b/drivers/watchdog/w83627hf_wdt.c @@ -29,6 +29,7 @@ #include <linux/bits.h> #include <linux/module.h> +#include <linux/platform_device.h> #include <linux/moduleparam.h> #include <linux/types.h> #include <linux/watchdog.h> @@ -464,6 +465,36 @@ static int wdt_find(int addr) return ret; } +static int wdt_probe(struct platform_device *pdev) +{ + const struct platform_device_id *id = platform_get_device_id(pdev); + enum chips chip = id->driver_data; + struct device *dev = &pdev->dev; + int ret; + + dev_info(dev, "WDT driver initialising\n"); + + snprintf(wdt_info.identity, sizeof(wdt_info.identity), "%s Watchdog", + id->name); + + watchdog_init_timeout(&wdt_dev, timeout, NULL); + watchdog_set_nowayout(&wdt_dev, nowayout); + watchdog_stop_on_reboot(&wdt_dev); + + ret = w83627hf_init(&wdt_dev, chip); + if (ret) + return dev_err_probe(dev, ret, "failed to initialize watchdog\n"); + + ret = devm_watchdog_register_device(&pdev->dev, &wdt_dev); + if (ret) + return ret; + + dev_info(dev, "initialized. timeout=%d sec (nowayout=%d)\n", + wdt_dev.timeout, nowayout); + + return ret; +} + /* * On some systems, the NCT6791D comes with a companion chip and the * watchdog function is in this companion chip. We must use a different @@ -490,36 +521,48 @@ static const struct dmi_system_id wdt_dmi_table[] __initconst = { {} }; +static const struct platform_device_id wdt_ids[] = { + { .name = "W83627HF", .driver_data = w83627hf }, + { .name = "W83627S", .driver_data = w83627s }, + { .name = "W83697HF", .driver_data = w83697hf }, + { .name = "W83697UG", .driver_data = w83697ug }, + { .name = "W83637HF", .driver_data = w83637hf }, + { .name = "W83627THF", .driver_data = w83627thf }, + { .name = "W83687THF", .driver_data = w83687thf }, + { .name = "W83627EHF", .driver_data = w83627ehf }, + { .name = "W83627DHG", .driver_data = w83627dhg }, + { .name = "W83627UHG", .driver_data = w83627uhg }, + { .name = "W83667HG", .driver_data = w83667hg }, + { .name = "W83667DHG-P", .driver_data = w83627dhg_p }, + { .name = "W83667HG-B", .driver_data = w83667hg_b }, + { .name = "NCT6775", .driver_data = nct6775 }, + { .name = "NCT6776", .driver_data = nct6776 }, + { .name = "NCT6779", .driver_data = nct6779 }, + { .name = "NCT6791", .driver_data = nct6791 }, + { .name = "NCT6792", .driver_data = nct6792 }, + { .name = "NCT6793", .driver_data = nct6793 }, + { .name = "NCT6795", .driver_data = nct6795 }, + { .name = "NCT6796", .driver_data = nct6796 }, + { .name = "NCT6102", .driver_data = nct6102 }, + { .name = "NCT6116", .driver_data = nct6116 }, + { .name = "NCT6126", .driver_data = nct6126 }, + {}, +}; + +static struct platform_driver wdt_driver = { + .probe = wdt_probe, + .id_table = wdt_ids, + .driver = { + .name = KBUILD_MODNAME, + }, +}; + +static struct platform_device *wdt_pdev; + static int __init wdt_init(void) { int ret; int chip; - static const char * const chip_name[] = { - "W83627HF", - "W83627S", - "W83697HF", - "W83697UG", - "W83637HF", - "W83627THF", - "W83687THF", - "W83627EHF", - "W83627DHG", - "W83627UHG", - "W83667HG", - "W83667DHG-P", - "W83667HG-B", - "NCT6775", - "NCT6776", - "NCT6779", - "NCT6791", - "NCT6792", - "NCT6793", - "NCT6795", - "NCT6796", - "NCT6102", - "NCT6116", - "NCT6126" - }; /* Apply system-specific quirks */ dmi_check_system(wdt_dmi_table); @@ -533,35 +576,24 @@ static int __init wdt_init(void) return chip; } - pr_info("WDT driver for %s Super I/O chip initialising\n", - chip_name[chip]); - - snprintf(wdt_info.identity, sizeof(wdt_info.identity), "%s Watchdog", - chip_name[chip]); - - watchdog_init_timeout(&wdt_dev, timeout, NULL); - watchdog_set_nowayout(&wdt_dev, nowayout); - watchdog_stop_on_reboot(&wdt_dev); - - ret = w83627hf_init(&wdt_dev, chip); - if (ret) { - pr_err("failed to initialize watchdog (err=%d)\n", ret); - return ret; - } - - ret = watchdog_register_device(&wdt_dev); + ret = platform_driver_register(&wdt_driver); if (ret) return ret; - pr_info("initialized. timeout=%d sec (nowayout=%d)\n", - wdt_dev.timeout, nowayout); + wdt_pdev = platform_device_register_data(NULL, wdt_ids[chip].name, + PLATFORM_DEVID_NONE, NULL, 0); + if (IS_ERR(wdt_pdev)) { + platform_driver_unregister(&wdt_driver); + return PTR_ERR(wdt_pdev); + } - return ret; + return 0; } static void __exit wdt_exit(void) { - watchdog_unregister_device(&wdt_dev); + platform_device_unregister(wdt_pdev); + platform_driver_unregister(&wdt_driver); } module_init(wdt_init); -- 2.55.0