Skip to content

Commit 5829046

Browse files
mwilczyrafaeljw
authored andcommitted
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 <[email protected]> Signed-off-by: Michal Wilczynski <[email protected]> [ rjw: Changelog edits, acpi_ac_notify() modifications fixup ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 616990c commit 5829046

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

drivers/acpi/ac.c

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ MODULE_AUTHOR("Paul Diefenbaugh");
3333
MODULE_DESCRIPTION("ACPI AC Adapter Driver");
3434
MODULE_LICENSE("GPL");
3535

36-
static int acpi_ac_add(struct acpi_device *device);
37-
static void acpi_ac_remove(struct acpi_device *device);
36+
static int acpi_ac_probe(struct platform_device *pdev);
37+
static void acpi_ac_remove(struct platform_device *pdev);
38+
3839
static void acpi_ac_notify(acpi_handle handle, u32 event, void *data);
3940

4041
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);
5152
static int ac_sleep_before_get_state_ms;
5253
static int ac_only;
5354

54-
static struct acpi_driver acpi_ac_driver = {
55-
.name = "ac",
56-
.class = ACPI_AC_CLASS,
57-
.ids = ac_device_ids,
58-
.ops = {
59-
.add = acpi_ac_add,
60-
.remove = acpi_ac_remove,
61-
},
62-
.drv.pm = &acpi_ac_pm,
63-
};
64-
6555
struct acpi_ac {
6656
struct power_supply *charger;
6757
struct power_supply_desc charger_desc;
@@ -129,8 +119,8 @@ static enum power_supply_property ac_props[] = {
129119
/* Driver Model */
130120
static void acpi_ac_notify(acpi_handle handle, u32 event, void *data)
131121
{
132-
struct acpi_device *device = data;
133-
struct acpi_ac *ac = acpi_driver_data(device);
122+
struct acpi_ac *ac = data;
123+
struct acpi_device *device = ac->device;
134124

135125
switch (event) {
136126
default:
@@ -211,8 +201,9 @@ static const struct dmi_system_id ac_dmi_table[] __initconst = {
211201
{},
212202
};
213203

214-
static int acpi_ac_add(struct acpi_device *device)
204+
static int acpi_ac_probe(struct platform_device *pdev)
215205
{
206+
struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
216207
struct power_supply_config psy_cfg = {};
217208
struct acpi_ac *ac;
218209
int result;
@@ -224,7 +215,8 @@ static int acpi_ac_add(struct acpi_device *device)
224215
ac->device = device;
225216
strcpy(acpi_device_name(device), ACPI_AC_DEVICE_NAME);
226217
strcpy(acpi_device_class(device), ACPI_AC_CLASS);
227-
device->driver_data = ac;
218+
219+
platform_set_drvdata(pdev, ac);
228220

229221
result = acpi_ac_get_state(ac);
230222
if (result)
@@ -237,7 +229,7 @@ static int acpi_ac_add(struct acpi_device *device)
237229
ac->charger_desc.properties = ac_props;
238230
ac->charger_desc.num_properties = ARRAY_SIZE(ac_props);
239231
ac->charger_desc.get_property = get_ac_property;
240-
ac->charger = power_supply_register(&ac->device->dev,
232+
ac->charger = power_supply_register(&pdev->dev,
241233
&ac->charger_desc, &psy_cfg);
242234
if (IS_ERR(ac->charger)) {
243235
result = PTR_ERR(ac->charger);
@@ -251,7 +243,7 @@ static int acpi_ac_add(struct acpi_device *device)
251243
register_acpi_notifier(&ac->battery_nb);
252244

253245
result = acpi_dev_install_notify_handler(device, ACPI_ALL_NOTIFY,
254-
acpi_ac_notify, device);
246+
acpi_ac_notify, ac);
255247
if (result)
256248
goto err_unregister;
257249

@@ -269,7 +261,7 @@ static int acpi_ac_add(struct acpi_device *device)
269261
#ifdef CONFIG_PM_SLEEP
270262
static int acpi_ac_resume(struct device *dev)
271263
{
272-
struct acpi_ac *ac = acpi_driver_data(to_acpi_device(dev));
264+
struct acpi_ac *ac = dev_get_drvdata(dev);
273265
unsigned int old_state;
274266

275267
old_state = ac->state;
@@ -284,18 +276,28 @@ static int acpi_ac_resume(struct device *dev)
284276
#define acpi_ac_resume NULL
285277
#endif
286278

287-
static void acpi_ac_remove(struct acpi_device *device)
279+
static void acpi_ac_remove(struct platform_device *pdev)
288280
{
289-
struct acpi_ac *ac = acpi_driver_data(device);
281+
struct acpi_ac *ac = platform_get_drvdata(pdev);
290282

291-
acpi_dev_remove_notify_handler(device, ACPI_ALL_NOTIFY,
283+
acpi_dev_remove_notify_handler(ac->device, ACPI_ALL_NOTIFY,
292284
acpi_ac_notify);
293285
power_supply_unregister(ac->charger);
294286
unregister_acpi_notifier(&ac->battery_nb);
295287

296288
kfree(ac);
297289
}
298290

291+
static struct platform_driver acpi_ac_driver = {
292+
.probe = acpi_ac_probe,
293+
.remove_new = acpi_ac_remove,
294+
.driver = {
295+
.name = "ac",
296+
.acpi_match_table = ac_device_ids,
297+
.pm = &acpi_ac_pm,
298+
},
299+
};
300+
299301
static int __init acpi_ac_init(void)
300302
{
301303
int result;
@@ -308,7 +310,7 @@ static int __init acpi_ac_init(void)
308310

309311
dmi_check_system(ac_dmi_table);
310312

311-
result = acpi_bus_register_driver(&acpi_ac_driver);
313+
result = platform_driver_register(&acpi_ac_driver);
312314
if (result < 0)
313315
return -ENODEV;
314316

@@ -317,7 +319,7 @@ static int __init acpi_ac_init(void)
317319

318320
static void __exit acpi_ac_exit(void)
319321
{
320-
acpi_bus_unregister_driver(&acpi_ac_driver);
322+
platform_driver_unregister(&acpi_ac_driver);
321323
}
322324
module_init(acpi_ac_init);
323325
module_exit(acpi_ac_exit);

0 commit comments

Comments
 (0)