Skip to content

Commit 52d8640

Browse files
committed
ACPI: button: 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 button driver to a platform one. 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> Link: https://patch.msgid.link/2461734.NG923GbCHz@rafael.j.wysocki
1 parent 93dc5db commit 52d8640

1 file changed

Lines changed: 32 additions & 29 deletions

File tree

drivers/acpi/button.c

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/slab.h>
2020
#include <linux/acpi.h>
2121
#include <linux/dmi.h>
22+
#include <linux/platform_device.h>
2223
#include <acpi/button.h>
2324

2425
#define ACPI_BUTTON_CLASS "button"
@@ -145,8 +146,8 @@ static const struct dmi_system_id dmi_lid_quirks[] = {
145146
{}
146147
};
147148

148-
static int acpi_button_add(struct acpi_device *device);
149-
static void acpi_button_remove(struct acpi_device *device);
149+
static int acpi_button_probe(struct platform_device *pdev);
150+
static void acpi_button_remove(struct platform_device *pdev);
150151

151152
#ifdef CONFIG_PM_SLEEP
152153
static int acpi_button_suspend(struct device *dev);
@@ -157,19 +158,19 @@ static int acpi_button_resume(struct device *dev);
157158
#endif
158159
static SIMPLE_DEV_PM_OPS(acpi_button_pm, acpi_button_suspend, acpi_button_resume);
159160

160-
static struct acpi_driver acpi_button_driver = {
161-
.name = "button",
162-
.class = ACPI_BUTTON_CLASS,
163-
.ids = button_device_ids,
164-
.ops = {
165-
.add = acpi_button_add,
166-
.remove = acpi_button_remove,
161+
static struct platform_driver acpi_button_driver = {
162+
.probe = acpi_button_probe,
163+
.remove = acpi_button_remove,
164+
.driver = {
165+
.name = "acpi-button",
166+
.acpi_match_table = button_device_ids,
167+
.pm = &acpi_button_pm,
167168
},
168-
.drv.pm = &acpi_button_pm,
169169
};
170170

171171
struct acpi_button {
172172
struct acpi_device *adev;
173+
struct platform_device *pdev;
173174
unsigned int type;
174175
struct input_dev *input;
175176
char phys[32]; /* for input device */
@@ -397,7 +398,7 @@ static int acpi_lid_update_state(struct acpi_button *button,
397398
return state;
398399

399400
if (state && signal_wakeup)
400-
acpi_pm_wakeup_event(&device->dev);
401+
acpi_pm_wakeup_event(&button->pdev->dev);
401402

402403
return acpi_lid_notify_state(button, state);
403404
}
@@ -454,7 +455,7 @@ static void acpi_button_notify(acpi_handle handle, u32 event, void *data)
454455
return;
455456
}
456457

457-
acpi_pm_wakeup_event(&device->dev);
458+
acpi_pm_wakeup_event(&button->pdev->dev);
458459

459460
if (button->suspended || event == ACPI_BUTTON_NOTIFY_WAKE)
460461
return;
@@ -486,18 +487,17 @@ static u32 acpi_button_event(void *data)
486487
#ifdef CONFIG_PM_SLEEP
487488
static int acpi_button_suspend(struct device *dev)
488489
{
489-
struct acpi_device *device = to_acpi_device(dev);
490-
struct acpi_button *button = acpi_driver_data(device);
490+
struct acpi_button *button = dev_get_drvdata(dev);
491491

492492
button->suspended = true;
493493
return 0;
494494
}
495495

496496
static int acpi_button_resume(struct device *dev)
497497
{
498+
struct acpi_button *button = dev_get_drvdata(dev);
499+
struct acpi_device *device = ACPI_COMPANION(dev);
498500
struct input_dev *input;
499-
struct acpi_device *device = to_acpi_device(dev);
500-
struct acpi_button *button = acpi_driver_data(device);
501501

502502
button->suspended = false;
503503
if (button->type == ACPI_BUTTON_TYPE_LID) {
@@ -529,8 +529,9 @@ static int acpi_lid_input_open(struct input_dev *input)
529529
return 0;
530530
}
531531

532-
static int acpi_button_add(struct acpi_device *device)
532+
static int acpi_button_probe(struct platform_device *pdev)
533533
{
534+
struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
534535
acpi_notify_handler handler;
535536
struct acpi_button *button;
536537
struct input_dev *input;
@@ -547,8 +548,9 @@ static int acpi_button_add(struct acpi_device *device)
547548
if (!button)
548549
return -ENOMEM;
549550

550-
device->driver_data = button;
551+
platform_set_drvdata(pdev, button);
551552

553+
button->pdev = pdev;
552554
button->adev = device;
553555
button->input = input = input_allocate_device();
554556
if (!input) {
@@ -599,7 +601,7 @@ static int acpi_button_add(struct acpi_device *device)
599601
input->phys = button->phys;
600602
input->id.bustype = BUS_HOST;
601603
input->id.product = button->type;
602-
input->dev.parent = &device->dev;
604+
input->dev.parent = &pdev->dev;
603605

604606
switch (button->type) {
605607
case ACPI_BUTTON_TYPE_POWER:
@@ -653,7 +655,7 @@ static int acpi_button_add(struct acpi_device *device)
653655
lid_device = device;
654656
}
655657

656-
device_init_wakeup(&device->dev, true);
658+
device_init_wakeup(&pdev->dev, true);
657659
pr_info("%s [%s]\n", name, acpi_device_bid(device));
658660
return 0;
659661

@@ -666,9 +668,10 @@ static int acpi_button_add(struct acpi_device *device)
666668
return error;
667669
}
668670

669-
static void acpi_button_remove(struct acpi_device *device)
671+
static void acpi_button_remove(struct platform_device *pdev)
670672
{
671-
struct acpi_button *button = acpi_driver_data(device);
673+
struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
674+
struct acpi_button *button = platform_get_drvdata(pdev);
672675

673676
switch (device->device_type) {
674677
case ACPI_BUS_TYPE_POWER_BUTTON:
@@ -727,7 +730,7 @@ module_param_call(lid_init_state,
727730
NULL, 0644);
728731
MODULE_PARM_DESC(lid_init_state, "Behavior for reporting LID initial state");
729732

730-
static int acpi_button_register_driver(struct acpi_driver *driver)
733+
static int __init acpi_button_init(void)
731734
{
732735
const struct dmi_system_id *dmi_id;
733736

@@ -743,20 +746,20 @@ static int acpi_button_register_driver(struct acpi_driver *driver)
743746
* Modules such as nouveau.ko and i915.ko have a link time dependency
744747
* on acpi_lid_open(), and would therefore not be loadable on ACPI
745748
* capable kernels booted in non-ACPI mode if the return value of
746-
* acpi_bus_register_driver() is returned from here with ACPI disabled
749+
* platform_driver_register() is returned from here with ACPI disabled
747750
* when this driver is built as a module.
748751
*/
749752
if (acpi_disabled)
750753
return 0;
751754

752-
return acpi_bus_register_driver(driver);
755+
return platform_driver_register(&acpi_button_driver);
753756
}
754757

755-
static void acpi_button_unregister_driver(struct acpi_driver *driver)
758+
static void __exit acpi_button_exit(void)
756759
{
757760
if (!acpi_disabled)
758-
acpi_bus_unregister_driver(driver);
761+
platform_driver_unregister(&acpi_button_driver);
759762
}
760763

761-
module_driver(acpi_button_driver, acpi_button_register_driver,
762-
acpi_button_unregister_driver);
764+
module_init(acpi_button_init);
765+
module_exit(acpi_button_exit);

0 commit comments

Comments
 (0)