Skip to content

Commit 02c057d

Browse files
committed
ACPI: video: 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 video 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> Reviewed-by: Armin Wolf <W_Armin@gmx.de> Link: https://patch.msgid.link/1957556.tdWV9SEqCh@rafael.j.wysocki
1 parent d91a624 commit 02c057d

1 file changed

Lines changed: 23 additions & 24 deletions

File tree

drivers/acpi/acpi_video.c

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/sort.h>
2222
#include <linux/pci.h>
2323
#include <linux/pci_ids.h>
24+
#include <linux/platform_device.h>
2425
#include <linux/slab.h>
2526
#include <linux/dmi.h>
2627
#include <linux/suspend.h>
@@ -76,8 +77,8 @@ static int register_count;
7677
static DEFINE_MUTEX(register_count_mutex);
7778
static DEFINE_MUTEX(video_list_lock);
7879
static LIST_HEAD(video_bus_head);
79-
static int acpi_video_bus_add(struct acpi_device *device);
80-
static void acpi_video_bus_remove(struct acpi_device *device);
80+
static int acpi_video_bus_probe(struct platform_device *pdev);
81+
static void acpi_video_bus_remove(struct platform_device *pdev);
8182
static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data);
8283

8384
/*
@@ -98,14 +99,13 @@ static const struct acpi_device_id video_device_ids[] = {
9899
};
99100
MODULE_DEVICE_TABLE(acpi, video_device_ids);
100101

101-
static struct acpi_driver acpi_video_bus = {
102-
.name = "video",
103-
.class = ACPI_VIDEO_CLASS,
104-
.ids = video_device_ids,
105-
.ops = {
106-
.add = acpi_video_bus_add,
107-
.remove = acpi_video_bus_remove,
108-
},
102+
static struct platform_driver acpi_video_bus = {
103+
.probe = acpi_video_bus_probe,
104+
.remove = acpi_video_bus_remove,
105+
.driver = {
106+
.name = "acpi-video",
107+
.acpi_match_table = video_device_ids,
108+
},
109109
};
110110

111111
struct acpi_video_bus_flags {
@@ -1888,7 +1888,8 @@ static void acpi_video_dev_add_notify_handler(struct acpi_video_device *device)
18881888
device->flags.notify = 1;
18891889
}
18901890

1891-
static int acpi_video_bus_add_notify_handler(struct acpi_video_bus *video)
1891+
static int acpi_video_bus_add_notify_handler(struct acpi_video_bus *video,
1892+
struct platform_device *pdev)
18921893
{
18931894
struct input_dev *input;
18941895
struct acpi_video_device *dev;
@@ -1911,7 +1912,7 @@ static int acpi_video_bus_add_notify_handler(struct acpi_video_bus *video)
19111912
input->phys = video->phys;
19121913
input->id.bustype = BUS_HOST;
19131914
input->id.product = 0x06;
1914-
input->dev.parent = &video->device->dev;
1915+
input->dev.parent = &pdev->dev;
19151916
input->evbit[0] = BIT(EV_KEY);
19161917
set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
19171918
set_bit(KEY_VIDEO_NEXT, input->keybit);
@@ -1983,8 +1984,9 @@ static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
19831984

19841985
static int instance;
19851986

1986-
static int acpi_video_bus_add(struct acpi_device *device)
1987+
static int acpi_video_bus_probe(struct platform_device *pdev)
19871988
{
1989+
struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
19881990
struct acpi_video_bus *video;
19891991
bool auto_detect;
19901992
int error;
@@ -2021,6 +2023,8 @@ static int acpi_video_bus_add(struct acpi_device *device)
20212023
instance++;
20222024
}
20232025

2026+
platform_set_drvdata(pdev, video);
2027+
20242028
video->device = device;
20252029
strscpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
20262030
strscpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
@@ -2068,7 +2072,7 @@ static int acpi_video_bus_add(struct acpi_device *device)
20682072
!auto_detect)
20692073
acpi_video_bus_register_backlight(video);
20702074

2071-
error = acpi_video_bus_add_notify_handler(video);
2075+
error = acpi_video_bus_add_notify_handler(video, pdev);
20722076
if (error)
20732077
goto err_del;
20742078

@@ -2096,15 +2100,10 @@ static int acpi_video_bus_add(struct acpi_device *device)
20962100
return error;
20972101
}
20982102

2099-
static void acpi_video_bus_remove(struct acpi_device *device)
2103+
static void acpi_video_bus_remove(struct platform_device *pdev)
21002104
{
2101-
struct acpi_video_bus *video = NULL;
2102-
2103-
2104-
if (!device || !acpi_driver_data(device))
2105-
return;
2106-
2107-
video = acpi_driver_data(device);
2105+
struct acpi_video_bus *video = platform_get_drvdata(pdev);
2106+
struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
21082107

21092108
acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY,
21102109
acpi_video_bus_notify);
@@ -2167,7 +2166,7 @@ int acpi_video_register(void)
21672166

21682167
dmi_check_system(video_dmi_table);
21692168

2170-
ret = acpi_bus_register_driver(&acpi_video_bus);
2169+
ret = platform_driver_register(&acpi_video_bus);
21712170
if (ret)
21722171
goto leave;
21732172

@@ -2187,7 +2186,7 @@ void acpi_video_unregister(void)
21872186
{
21882187
mutex_lock(&register_count_mutex);
21892188
if (register_count) {
2190-
acpi_bus_unregister_driver(&acpi_video_bus);
2189+
platform_driver_unregister(&acpi_video_bus);
21912190
register_count = 0;
21922191
may_report_brightness_keys = false;
21932192
}

0 commit comments

Comments
 (0)