Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

+22 -36
+21 -33
drivers/acpi/ec.c
··· 23 23 #include <linux/delay.h> 24 24 #include <linux/interrupt.h> 25 25 #include <linux/list.h> 26 + #include <linux/platform_device.h> 26 27 #include <linux/printk.h> 27 28 #include <linux/spinlock.h> 28 29 #include <linux/slab.h> ··· 1675 1674 return ret; 1676 1675 } 1677 1676 1678 - static int acpi_ec_add(struct acpi_device *device) 1677 + static int acpi_ec_probe(struct platform_device *pdev) 1679 1678 { 1679 + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 1680 1680 struct acpi_ec *ec; 1681 1681 int ret; 1682 1682 ··· 1732 1730 acpi_handle_info(ec->handle, 1733 1731 "EC: Used to handle transactions and events\n"); 1734 1732 1733 + platform_set_drvdata(pdev, ec); 1734 + /* This is needed for the SMBUS HC driver to work. */ 1735 1735 device->driver_data = ec; 1736 1736 1737 1737 ret = !!request_region(ec->data_addr, 1, "EC data"); ··· 1754 1750 return ret; 1755 1751 } 1756 1752 1757 - static void acpi_ec_remove(struct acpi_device *device) 1753 + static void acpi_ec_remove(struct platform_device *pdev) 1758 1754 { 1759 - struct acpi_ec *ec; 1755 + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 1756 + struct acpi_ec *ec = platform_get_drvdata(pdev); 1760 1757 1761 - if (!device) 1762 - return; 1763 - 1764 - ec = acpi_driver_data(device); 1765 1758 release_region(ec->data_addr, 1); 1766 1759 release_region(ec->command_addr, 1); 1767 1760 device->driver_data = NULL; ··· 2096 2095 #ifdef CONFIG_PM_SLEEP 2097 2096 static int acpi_ec_suspend(struct device *dev) 2098 2097 { 2099 - struct acpi_ec *ec = 2100 - acpi_driver_data(to_acpi_device(dev)); 2098 + struct acpi_ec *ec = dev_get_drvdata(dev); 2101 2099 2102 2100 if (!pm_suspend_no_platform() && ec_freeze_events) 2103 2101 acpi_ec_disable_event(ec); ··· 2105 2105 2106 2106 static int acpi_ec_suspend_noirq(struct device *dev) 2107 2107 { 2108 - struct acpi_ec *ec = acpi_driver_data(to_acpi_device(dev)); 2108 + struct acpi_ec *ec = dev_get_drvdata(dev); 2109 2109 2110 2110 /* 2111 2111 * The SCI handler doesn't run at this point, so the GPE can be ··· 2122 2122 2123 2123 static int acpi_ec_resume_noirq(struct device *dev) 2124 2124 { 2125 - struct acpi_ec *ec = acpi_driver_data(to_acpi_device(dev)); 2125 + struct acpi_ec *ec = dev_get_drvdata(dev); 2126 2126 2127 2127 acpi_ec_leave_noirq(ec); 2128 2128 ··· 2135 2135 2136 2136 static int acpi_ec_resume(struct device *dev) 2137 2137 { 2138 - struct acpi_ec *ec = 2139 - acpi_driver_data(to_acpi_device(dev)); 2138 + struct acpi_ec *ec = dev_get_drvdata(dev); 2140 2139 2141 2140 acpi_ec_enable_event(ec); 2142 2141 return 0; ··· 2264 2265 NULL, 0644); 2265 2266 MODULE_PARM_DESC(ec_event_clearing, "Assumed SCI_EVT clearing timing"); 2266 2267 2267 - static struct acpi_driver acpi_ec_driver = { 2268 - .name = "ec", 2269 - .class = ACPI_EC_CLASS, 2270 - .ids = ec_device_ids, 2271 - .ops = { 2272 - .add = acpi_ec_add, 2273 - .remove = acpi_ec_remove, 2274 - }, 2275 - .drv.pm = &acpi_ec_pm, 2268 + static struct platform_driver acpi_ec_driver = { 2269 + .probe = acpi_ec_probe, 2270 + .remove = acpi_ec_remove, 2271 + .driver = { 2272 + .name = "acpi-ec", 2273 + .acpi_match_table = ec_device_ids, 2274 + .pm = &acpi_ec_pm, 2275 + }, 2276 2276 }; 2277 2277 2278 2278 static void acpi_ec_destroy_workqueues(void) ··· 2376 2378 } 2377 2379 2378 2380 /* Driver must be registered after acpi_ec_init_workqueues(). */ 2379 - acpi_bus_register_driver(&acpi_ec_driver); 2381 + platform_driver_register(&acpi_ec_driver); 2380 2382 2381 2383 acpi_ec_ecdt_start(); 2382 2384 } 2383 - 2384 - /* EC driver currently not unloadable */ 2385 - #if 0 2386 - static void __exit acpi_ec_exit(void) 2387 - { 2388 - 2389 - acpi_bus_unregister_driver(&acpi_ec_driver); 2390 - acpi_ec_destroy_workqueues(); 2391 - } 2392 - #endif /* 0 */
+1 -3
drivers/acpi/scan.c
··· 2755 2755 return result; 2756 2756 2757 2757 acpi_default_enumeration(device); 2758 - 2759 - device->flags.match_driver = true; 2760 - return device_attach(&device->dev); 2758 + return 0; 2761 2759 } 2762 2760 EXPORT_SYMBOL_GPL(acpi_bus_register_early_device); 2763 2761