Skip to content

Commit d37ec2f

Browse files
committed
watchdog: ni903x_wdt: Convert to a platform driver
In all cases in which a struct acpi_driver is used for binding a driver to an ACPI device object, a corresponding platform device is created by the ACPI core and that device is regarded as a proper representation of underlying hardware. Accordingly, a struct platform_driver should be used by driver code to bind to that device. There are multiple reasons why drivers should not bind directly to ACPI device objects [1]. In particular, registering a watchdog device under a struct acpi_device is questionable because it causes the watchdog to be hidden in the ACPI bus sysfs hierarchy and it goes against the general rule that a struct acpi_device can only be a parent of another struct acpi_device. Overall, it is better to bind drivers to platform devices than to their ACPI companions, so convert the ni903x_wdt watchdog ACPI driver to a platform one. While this is not expected to alter functionality, it changes sysfs layout and so it will be visible to user space. Note that after this change it actually makes sense to look for the "timeout-sec" property via device_property_read_u32() under the device passed to watchdog_init_timeout() because it has an fwnode handle (unlike a struct acpi_device which is an fwnode itself). Link: https://lore.kernel.org/all/2396510.ElGaqSPkdT@rafael.j.wysocki/ [1] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Link: https://patch.msgid.link/13996583.uLZWGnKmhe@rafael.j.wysocki
1 parent 112b2f9 commit d37ec2f

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

drivers/watchdog/ni903x_wdt.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/interrupt.h>
99
#include <linux/io.h>
1010
#include <linux/module.h>
11+
#include <linux/platform_device.h>
1112
#include <linux/watchdog.h>
1213

1314
#define NIWD_CONTROL 0x01
@@ -177,9 +178,9 @@ static const struct watchdog_ops ni903x_wdd_ops = {
177178
.get_timeleft = ni903x_wdd_get_timeleft,
178179
};
179180

180-
static int ni903x_acpi_add(struct acpi_device *device)
181+
static int ni903x_acpi_probe(struct platform_device *pdev)
181182
{
182-
struct device *dev = &device->dev;
183+
struct device *dev = &pdev->dev;
183184
struct watchdog_device *wdd;
184185
struct ni903x_wdt *wdt;
185186
acpi_status status;
@@ -189,10 +190,10 @@ static int ni903x_acpi_add(struct acpi_device *device)
189190
if (!wdt)
190191
return -ENOMEM;
191192

192-
device->driver_data = wdt;
193+
platform_set_drvdata(pdev, wdt);
193194
wdt->dev = dev;
194195

195-
status = acpi_walk_resources(device->handle, METHOD_NAME__CRS,
196+
status = acpi_walk_resources(ACPI_HANDLE(dev), METHOD_NAME__CRS,
196197
ni903x_resources, wdt);
197198
if (ACPI_FAILURE(status) || wdt->io_base == 0) {
198199
dev_err(dev, "failed to get resources\n");
@@ -224,9 +225,9 @@ static int ni903x_acpi_add(struct acpi_device *device)
224225
return 0;
225226
}
226227

227-
static void ni903x_acpi_remove(struct acpi_device *device)
228+
static void ni903x_acpi_remove(struct platform_device *pdev)
228229
{
229-
struct ni903x_wdt *wdt = acpi_driver_data(device);
230+
struct ni903x_wdt *wdt = platform_get_drvdata(pdev);
230231

231232
ni903x_wdd_stop(&wdt->wdd);
232233
watchdog_unregister_device(&wdt->wdd);
@@ -238,16 +239,16 @@ static const struct acpi_device_id ni903x_device_ids[] = {
238239
};
239240
MODULE_DEVICE_TABLE(acpi, ni903x_device_ids);
240241

241-
static struct acpi_driver ni903x_acpi_driver = {
242-
.name = NIWD_NAME,
243-
.ids = ni903x_device_ids,
244-
.ops = {
245-
.add = ni903x_acpi_add,
246-
.remove = ni903x_acpi_remove,
242+
static struct platform_driver ni903x_acpi_driver = {
243+
.probe = ni903x_acpi_probe,
244+
.remove = ni903x_acpi_remove,
245+
.driver = {
246+
.name = NIWD_NAME,
247+
.acpi_match_table = ni903x_device_ids,
247248
},
248249
};
249250

250-
module_acpi_driver(ni903x_acpi_driver);
251+
module_platform_driver(ni903x_acpi_driver);
251252

252253
MODULE_DESCRIPTION("NI 903x Watchdog");
253254
MODULE_AUTHOR("Jeff Westfahl <jeff.westfahl@ni.com>");

0 commit comments

Comments
 (0)