diff options
| author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2025-12-11 17:17:23 +0300 |
|---|---|---|
| committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2025-12-29 23:04:23 +0300 |
| commit | db65a06d10b3bf7153ba80cde6e447d440412b9f (patch) | |
| tree | edb5b846cffc5758b5afcdf1750d36cc4a98510c | |
| parent | fe9542b8b53cd72cd6304278052a3d7db3f6c824 (diff) | |
| download | linux-db65a06d10b3bf7153ba80cde6e447d440412b9f.tar.xz | |
ACPI: EC: Convert the driver to a platform one
While binding drivers directly to struct acpi_device objects allows
basic functionality to be provided, at least in the majority of cases,
there are some problems with it, related to general consistency, sysfs
layout, power management operation ordering, and code cleanliness.
Overall, it is better to bind drivers to platform devices than to their
ACPI companions, so convert the ACPI embedded controller (EC) driver
to a platform one.
After this conversion, acpi_bus_register_early_device() does not need
to attempt to bind an ACPI driver to the struct acpi_device created by
it, so update it accordingly.
While this is not expected to alter functionality, it changes sysfs
layout and so it will be visible to user space.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
[ rjw: Removed excess semicolon ]
Link: https://patch.msgid.link/1946304.tdWV9SEqCh@rafael.j.wysocki
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
| -rw-r--r-- | drivers/acpi/ec.c | 54 | ||||
| -rw-r--r-- | drivers/acpi/scan.c | 4 |
2 files changed, 22 insertions, 36 deletions
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index 59b3d50ff01e..bf4d86571b0d 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -23,6 +23,7 @@ #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/list.h> +#include <linux/platform_device.h> #include <linux/printk.h> #include <linux/spinlock.h> #include <linux/slab.h> @@ -1674,8 +1675,9 @@ static int acpi_ec_setup(struct acpi_ec *ec, struct acpi_device *device, bool ca return ret; } -static int acpi_ec_add(struct acpi_device *device) +static int acpi_ec_probe(struct platform_device *pdev) { + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); struct acpi_ec *ec; int ret; @@ -1730,6 +1732,8 @@ static int acpi_ec_add(struct acpi_device *device) acpi_handle_info(ec->handle, "EC: Used to handle transactions and events\n"); + platform_set_drvdata(pdev, ec); + /* This is needed for the SMBUS HC driver to work. */ device->driver_data = ec; ret = !!request_region(ec->data_addr, 1, "EC data"); @@ -1750,14 +1754,11 @@ err: return ret; } -static void acpi_ec_remove(struct acpi_device *device) +static void acpi_ec_remove(struct platform_device *pdev) { - struct acpi_ec *ec; + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); + struct acpi_ec *ec = platform_get_drvdata(pdev); - if (!device) - return; - - ec = acpi_driver_data(device); release_region(ec->data_addr, 1); release_region(ec->command_addr, 1); device->driver_data = NULL; @@ -2095,8 +2096,7 @@ out: #ifdef CONFIG_PM_SLEEP static int acpi_ec_suspend(struct device *dev) { - struct acpi_ec *ec = - acpi_driver_data(to_acpi_device(dev)); + struct acpi_ec *ec = dev_get_drvdata(dev); if (!pm_suspend_no_platform() && ec_freeze_events) acpi_ec_disable_event(ec); @@ -2105,7 +2105,7 @@ static int acpi_ec_suspend(struct device *dev) static int acpi_ec_suspend_noirq(struct device *dev) { - struct acpi_ec *ec = acpi_driver_data(to_acpi_device(dev)); + struct acpi_ec *ec = dev_get_drvdata(dev); /* * The SCI handler doesn't run at this point, so the GPE can be @@ -2122,7 +2122,7 @@ static int acpi_ec_suspend_noirq(struct device *dev) static int acpi_ec_resume_noirq(struct device *dev) { - struct acpi_ec *ec = acpi_driver_data(to_acpi_device(dev)); + struct acpi_ec *ec = dev_get_drvdata(dev); acpi_ec_leave_noirq(ec); @@ -2135,8 +2135,7 @@ static int acpi_ec_resume_noirq(struct device *dev) static int acpi_ec_resume(struct device *dev) { - struct acpi_ec *ec = - acpi_driver_data(to_acpi_device(dev)); + struct acpi_ec *ec = dev_get_drvdata(dev); acpi_ec_enable_event(ec); return 0; @@ -2265,15 +2264,14 @@ module_param_call(ec_event_clearing, param_set_event_clearing, param_get_event_c NULL, 0644); MODULE_PARM_DESC(ec_event_clearing, "Assumed SCI_EVT clearing timing"); -static struct acpi_driver acpi_ec_driver = { - .name = "ec", - .class = ACPI_EC_CLASS, - .ids = ec_device_ids, - .ops = { - .add = acpi_ec_add, - .remove = acpi_ec_remove, - }, - .drv.pm = &acpi_ec_pm, +static struct platform_driver acpi_ec_driver = { + .probe = acpi_ec_probe, + .remove = acpi_ec_remove, + .driver = { + .name = "acpi-ec", + .acpi_match_table = ec_device_ids, + .pm = &acpi_ec_pm, + }, }; static void acpi_ec_destroy_workqueues(void) @@ -2378,17 +2376,7 @@ void __init acpi_ec_init(void) } /* Driver must be registered after acpi_ec_init_workqueues(). */ - acpi_bus_register_driver(&acpi_ec_driver); + platform_driver_register(&acpi_ec_driver); acpi_ec_ecdt_start(); } - -/* EC driver currently not unloadable */ -#if 0 -static void __exit acpi_ec_exit(void) -{ - - acpi_bus_unregister_driver(&acpi_ec_driver); - acpi_ec_destroy_workqueues(); -} -#endif /* 0 */ diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index a67d1a2d0a2a..d0479ac40856 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -2755,9 +2755,7 @@ int acpi_bus_register_early_device(int type) return result; acpi_default_enumeration(device); - - device->flags.match_driver = true; - return device_attach(&device->dev); + return 0; } EXPORT_SYMBOL_GPL(acpi_bus_register_early_device); |
