summaryrefslogtreecommitdiffstats
path: root/drivers/acpi/ac.c
diff options
context:
space:
mode:
authorMichal Wilczynski <michal.wilczynski@intel.com>2023-10-11 11:33:31 +0300
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2023-10-13 20:11:29 +0200
commit5829046825ac89fffc60f2670bc564fda2c0155a (patch)
tree43e44778e420e0c1f99167e67052bd4a46cefd9d /drivers/acpi/ac.c
parent616990c92e40e4721beb66c2f855915fc1f32aba (diff)
downloadlinux-stable-5829046825ac89fffc60f2670bc564fda2c0155a.tar.gz
linux-stable-5829046825ac89fffc60f2670bc564fda2c0155a.tar.bz2
linux-stable-5829046825ac89fffc60f2670bc564fda2c0155a.zip
ACPI: AC: Replace acpi_driver with platform_driver
The AC driver uses struct acpi_driver to register itself while it would be more logically consistent to use struct platform_driver for this purpose, because the corresponding platform device is present and the role of struct acpi_device is to amend the other bus types. ACPI devices are not meant to be used as proper representation of hardware entities, but to collect information on those hardware entities provided by the platform firmware. Use struct platform_driver for registering the AC driver. Suggested-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: Michal Wilczynski <michal.wilczynski@intel.com> [ rjw: Changelog edits, acpi_ac_notify() modifications fixup ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/acpi/ac.c')
-rw-r--r--drivers/acpi/ac.c52
1 files changed, 27 insertions, 25 deletions
diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index f809f6889b4a..1e592d48881b 100644
--- a/drivers/acpi/ac.c
+++ b/drivers/acpi/ac.c
@@ -33,8 +33,9 @@ MODULE_AUTHOR("Paul Diefenbaugh");
MODULE_DESCRIPTION("ACPI AC Adapter Driver");
MODULE_LICENSE("GPL");
-static int acpi_ac_add(struct acpi_device *device);
-static void acpi_ac_remove(struct acpi_device *device);
+static int acpi_ac_probe(struct platform_device *pdev);
+static void acpi_ac_remove(struct platform_device *pdev);
+
static void acpi_ac_notify(acpi_handle handle, u32 event, void *data);
static const struct acpi_device_id ac_device_ids[] = {
@@ -51,17 +52,6 @@ static SIMPLE_DEV_PM_OPS(acpi_ac_pm, NULL, acpi_ac_resume);
static int ac_sleep_before_get_state_ms;
static int ac_only;
-static struct acpi_driver acpi_ac_driver = {
- .name = "ac",
- .class = ACPI_AC_CLASS,
- .ids = ac_device_ids,
- .ops = {
- .add = acpi_ac_add,
- .remove = acpi_ac_remove,
- },
- .drv.pm = &acpi_ac_pm,
-};
-
struct acpi_ac {
struct power_supply *charger;
struct power_supply_desc charger_desc;
@@ -129,8 +119,8 @@ static enum power_supply_property ac_props[] = {
/* Driver Model */
static void acpi_ac_notify(acpi_handle handle, u32 event, void *data)
{
- struct acpi_device *device = data;
- struct acpi_ac *ac = acpi_driver_data(device);
+ struct acpi_ac *ac = data;
+ struct acpi_device *device = ac->device;
switch (event) {
default:
@@ -211,8 +201,9 @@ static const struct dmi_system_id ac_dmi_table[] __initconst = {
{},
};
-static int acpi_ac_add(struct acpi_device *device)
+static int acpi_ac_probe(struct platform_device *pdev)
{
+ struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
struct power_supply_config psy_cfg = {};
struct acpi_ac *ac;
int result;
@@ -224,7 +215,8 @@ static int acpi_ac_add(struct acpi_device *device)
ac->device = device;
strcpy(acpi_device_name(device), ACPI_AC_DEVICE_NAME);
strcpy(acpi_device_class(device), ACPI_AC_CLASS);
- device->driver_data = ac;
+
+ platform_set_drvdata(pdev, ac);
result = acpi_ac_get_state(ac);
if (result)
@@ -237,7 +229,7 @@ static int acpi_ac_add(struct acpi_device *device)
ac->charger_desc.properties = ac_props;
ac->charger_desc.num_properties = ARRAY_SIZE(ac_props);
ac->charger_desc.get_property = get_ac_property;
- ac->charger = power_supply_register(&ac->device->dev,
+ ac->charger = power_supply_register(&pdev->dev,
&ac->charger_desc, &psy_cfg);
if (IS_ERR(ac->charger)) {
result = PTR_ERR(ac->charger);
@@ -251,7 +243,7 @@ static int acpi_ac_add(struct acpi_device *device)
register_acpi_notifier(&ac->battery_nb);
result = acpi_dev_install_notify_handler(device, ACPI_ALL_NOTIFY,
- acpi_ac_notify, device);
+ acpi_ac_notify, ac);
if (result)
goto err_unregister;
@@ -269,7 +261,7 @@ err_release_ac:
#ifdef CONFIG_PM_SLEEP
static int acpi_ac_resume(struct device *dev)
{
- struct acpi_ac *ac = acpi_driver_data(to_acpi_device(dev));
+ struct acpi_ac *ac = dev_get_drvdata(dev);
unsigned int old_state;
old_state = ac->state;
@@ -284,11 +276,11 @@ static int acpi_ac_resume(struct device *dev)
#define acpi_ac_resume NULL
#endif
-static void acpi_ac_remove(struct acpi_device *device)
+static void acpi_ac_remove(struct platform_device *pdev)
{
- struct acpi_ac *ac = acpi_driver_data(device);
+ struct acpi_ac *ac = platform_get_drvdata(pdev);
- acpi_dev_remove_notify_handler(device, ACPI_ALL_NOTIFY,
+ acpi_dev_remove_notify_handler(ac->device, ACPI_ALL_NOTIFY,
acpi_ac_notify);
power_supply_unregister(ac->charger);
unregister_acpi_notifier(&ac->battery_nb);
@@ -296,6 +288,16 @@ static void acpi_ac_remove(struct acpi_device *device)
kfree(ac);
}
+static struct platform_driver acpi_ac_driver = {
+ .probe = acpi_ac_probe,
+ .remove_new = acpi_ac_remove,
+ .driver = {
+ .name = "ac",
+ .acpi_match_table = ac_device_ids,
+ .pm = &acpi_ac_pm,
+ },
+};
+
static int __init acpi_ac_init(void)
{
int result;
@@ -308,7 +310,7 @@ static int __init acpi_ac_init(void)
dmi_check_system(ac_dmi_table);
- result = acpi_bus_register_driver(&acpi_ac_driver);
+ result = platform_driver_register(&acpi_ac_driver);
if (result < 0)
return -ENODEV;
@@ -317,7 +319,7 @@ static int __init acpi_ac_init(void)
static void __exit acpi_ac_exit(void)
{
- acpi_bus_unregister_driver(&acpi_ac_driver);
+ platform_driver_unregister(&acpi_ac_driver);
}
module_init(acpi_ac_init);
module_exit(acpi_ac_exit);