Skip to content

Commit db65a06

Browse files
committed
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>
1 parent fe9542b commit db65a06

2 files changed

Lines changed: 22 additions & 36 deletions

File tree

drivers/acpi/ec.c

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/delay.h>
2424
#include <linux/interrupt.h>
2525
#include <linux/list.h>
26+
#include <linux/platform_device.h>
2627
#include <linux/printk.h>
2728
#include <linux/spinlock.h>
2829
#include <linux/slab.h>
@@ -1674,8 +1675,9 @@ static int acpi_ec_setup(struct acpi_ec *ec, struct acpi_device *device, bool ca
16741675
return ret;
16751676
}
16761677

1677-
static int acpi_ec_add(struct acpi_device *device)
1678+
static int acpi_ec_probe(struct platform_device *pdev)
16781679
{
1680+
struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
16791681
struct acpi_ec *ec;
16801682
int ret;
16811683

@@ -1730,6 +1732,8 @@ static int acpi_ec_add(struct acpi_device *device)
17301732
acpi_handle_info(ec->handle,
17311733
"EC: Used to handle transactions and events\n");
17321734

1735+
platform_set_drvdata(pdev, ec);
1736+
/* This is needed for the SMBUS HC driver to work. */
17331737
device->driver_data = ec;
17341738

17351739
ret = !!request_region(ec->data_addr, 1, "EC data");
@@ -1750,14 +1754,11 @@ static int acpi_ec_add(struct acpi_device *device)
17501754
return ret;
17511755
}
17521756

1753-
static void acpi_ec_remove(struct acpi_device *device)
1757+
static void acpi_ec_remove(struct platform_device *pdev)
17541758
{
1755-
struct acpi_ec *ec;
1759+
struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
1760+
struct acpi_ec *ec = platform_get_drvdata(pdev);
17561761

1757-
if (!device)
1758-
return;
1759-
1760-
ec = acpi_driver_data(device);
17611762
release_region(ec->data_addr, 1);
17621763
release_region(ec->command_addr, 1);
17631764
device->driver_data = NULL;
@@ -2095,8 +2096,7 @@ void __init acpi_ec_ecdt_probe(void)
20952096
#ifdef CONFIG_PM_SLEEP
20962097
static int acpi_ec_suspend(struct device *dev)
20972098
{
2098-
struct acpi_ec *ec =
2099-
acpi_driver_data(to_acpi_device(dev));
2099+
struct acpi_ec *ec = dev_get_drvdata(dev);
21002100

21012101
if (!pm_suspend_no_platform() && ec_freeze_events)
21022102
acpi_ec_disable_event(ec);
@@ -2105,7 +2105,7 @@ static int acpi_ec_suspend(struct device *dev)
21052105

21062106
static int acpi_ec_suspend_noirq(struct device *dev)
21072107
{
2108-
struct acpi_ec *ec = acpi_driver_data(to_acpi_device(dev));
2108+
struct acpi_ec *ec = dev_get_drvdata(dev);
21092109

21102110
/*
21112111
* 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)
21222122

21232123
static int acpi_ec_resume_noirq(struct device *dev)
21242124
{
2125-
struct acpi_ec *ec = acpi_driver_data(to_acpi_device(dev));
2125+
struct acpi_ec *ec = dev_get_drvdata(dev);
21262126

21272127
acpi_ec_leave_noirq(ec);
21282128

@@ -2135,8 +2135,7 @@ static int acpi_ec_resume_noirq(struct device *dev)
21352135

21362136
static int acpi_ec_resume(struct device *dev)
21372137
{
2138-
struct acpi_ec *ec =
2139-
acpi_driver_data(to_acpi_device(dev));
2138+
struct acpi_ec *ec = dev_get_drvdata(dev);
21402139

21412140
acpi_ec_enable_event(ec);
21422141
return 0;
@@ -2265,15 +2264,14 @@ module_param_call(ec_event_clearing, param_set_event_clearing, param_get_event_c
22652264
NULL, 0644);
22662265
MODULE_PARM_DESC(ec_event_clearing, "Assumed SCI_EVT clearing timing");
22672266

2268-
static struct acpi_driver acpi_ec_driver = {
2269-
.name = "ec",
2270-
.class = ACPI_EC_CLASS,
2271-
.ids = ec_device_ids,
2272-
.ops = {
2273-
.add = acpi_ec_add,
2274-
.remove = acpi_ec_remove,
2275-
},
2276-
.drv.pm = &acpi_ec_pm,
2267+
static struct platform_driver acpi_ec_driver = {
2268+
.probe = acpi_ec_probe,
2269+
.remove = acpi_ec_remove,
2270+
.driver = {
2271+
.name = "acpi-ec",
2272+
.acpi_match_table = ec_device_ids,
2273+
.pm = &acpi_ec_pm,
2274+
},
22772275
};
22782276

22792277
static void acpi_ec_destroy_workqueues(void)
@@ -2378,17 +2376,7 @@ void __init acpi_ec_init(void)
23782376
}
23792377

23802378
/* Driver must be registered after acpi_ec_init_workqueues(). */
2381-
acpi_bus_register_driver(&acpi_ec_driver);
2379+
platform_driver_register(&acpi_ec_driver);
23822380

23832381
acpi_ec_ecdt_start();
23842382
}
2385-
2386-
/* EC driver currently not unloadable */
2387-
#if 0
2388-
static void __exit acpi_ec_exit(void)
2389-
{
2390-
2391-
acpi_bus_unregister_driver(&acpi_ec_driver);
2392-
acpi_ec_destroy_workqueues();
2393-
}
2394-
#endif /* 0 */

drivers/acpi/scan.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,9 +2755,7 @@ int acpi_bus_register_early_device(int type)
27552755
return result;
27562756

27572757
acpi_default_enumeration(device);
2758-
2759-
device->flags.match_driver = true;
2760-
return device_attach(&device->dev);
2758+
return 0;
27612759
}
27622760
EXPORT_SYMBOL_GPL(acpi_bus_register_early_device);
27632761

0 commit comments

Comments
 (0)