Skip to contentSkip to conversation

ACPI: video: Convert ACPI video driver to a platform one

PATCH RESEND In review Rafael J. Wysocki 3 participants 10 messages Jan 2 – Jan 15 ACPI

v1 of 3 In review Latest is v3 →

lore
Share & tools
lore
author maintainer
#1 lore raw

PATCH RESEND 1/3 ACPI: scan: Register platform devices for backlight device objects

From: "Rafael J. Wysocki" <[email protected]>

ACPI device objects associated with backlight interfaces are special because they are ACPI companions of PCI devices (GPUs), but the interfaces exposed by them resemble platform device one.

Currently, the ACPI video driver binds to them with the help of a special "synthetic" device ID regardless of the pairing with the PCI devices, but since it is generally better to use platform drivers for handling such interfaces, the plan is to convert that drviver into a platform one.

However, for this purpose, platform devices corresponding to the ACPI backlight device objects need to be registered, so update acpi_bus_attach() to apply the default ACPI enumeration to them and modify acpi_create_platform_device() to avoid bailing out early if a "physical" device is already attached to a backlight ACPI device object.

In addition, update acpi_companion_match() to return a valid struct acpi_device pointer if the ACPI companion of the given device is a backlight ACPI device object, which will facilitate driver matching for platform devices corresponding to those objects.

No intentional functional impact.

---
 drivers/acpi/acpi_platform.c | 4 ++--
 drivers/acpi/bus.c           | 3 +++
 drivers/acpi/scan.c          | 3 ++-
 3 files changed, 7 insertions(+), 3 deletions(-)
drivers/acpi/acpi_platform.c +2 -2
index 52c8d602f3a5..377ca8324121 100644
@@ -118,7 +118,7 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev,
 	int count = 0;
 
 	/* If the ACPI node already has a physical device attached, skip it. */
-	if (adev->physical_node_count)
+	if (adev->physical_node_count && !adev->pnp.type.backlight)
 		return NULL;
 
 	match = acpi_match_acpi_device(forbidden_id_list, adev);
@@ -135,7 +135,7 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev,
 		}
 	}
 
-	if (adev->device_type == ACPI_BUS_TYPE_DEVICE) {
+	if (adev->device_type == ACPI_BUS_TYPE_DEVICE && !adev->pnp.type.backlight) {
 		struct list_head resource_list = LIST_HEAD_INIT(resource_list);
 
 		count = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
drivers/acpi/bus.c +3 -0
index a984ccd4a2a0..574e190f6bf9 100644
@@ -761,6 +761,9 @@ const struct acpi_device *acpi_companion_match(const struct device *dev)
 	if (list_empty(&adev->pnp.ids))
 		return NULL;
 
+	if (adev->pnp.type.backlight)
+		return adev;
+
 	return acpi_primary_dev_companion(adev, dev);
 }
 
drivers/acpi/scan.c +2 -1
index d0479ac40856..360d82378e56 100644
@@ -2350,7 +2350,8 @@ static int acpi_bus_attach(struct acpi_device *device, void *first_pass)
 	if (ret < 0)
 		return 0;
 
-	if (device->pnp.type.platform_id || device->flags.enumeration_by_parent)
+	if (device->pnp.type.platform_id || device->pnp.type.backlight ||
+	    device->flags.enumeration_by_parent)
 		acpi_default_enumeration(device);
 	else
 		acpi_device_set_enumerated(device);
Signature · 1 line
2.51.0
author maintainer
#2 lore raw

PATCH RESEND 2/3 ACPI: video: Adjust event notification routine

In reply to Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Adjust acpi_video_bus_notify() to cast its "data" argument to a struct acpi_video_bus pointer instead of a struct acpi_device one, which allows the use of acpi_driver_data() to be limited and will facilitate subsequent changes.

No intentional functional impact.

---
 drivers/acpi/acpi_video.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/acpi/acpi_video.c +3 -6
index be8e7e18abca..54e09e7f8e77 100644
@@ -1540,14 +1540,11 @@ static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
 
 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
 {
-	struct acpi_device *device = data;
-	struct acpi_video_bus *video = acpi_driver_data(device);
+	struct acpi_video_bus *video = data;
+	struct acpi_device *device = video->device;
 	struct input_dev *input;
 	int keycode = 0;
 
-	if (!video || !video->input)
-		return;
-
 	input = video->input;
 
 	switch (event) {
@@ -2076,7 +2073,7 @@ static int acpi_video_bus_add(struct acpi_device *device)
 		goto err_del;
 
 	error = acpi_dev_install_notify_handler(device, ACPI_DEVICE_NOTIFY,
-						acpi_video_bus_notify, device);
+						acpi_video_bus_notify, video);
 	if (error)
 		goto err_remove;
 
Signature · 1 line
2.51.0
author maintainer
#3 lore raw

PATCH RESEND 3/3 ACPI: video: Convert the driver to a platform one

In reply to Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

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.

---
 drivers/acpi/acpi_video.c | 47 +++++++++++++++++++--------------------
 1 file changed, 23 insertions(+), 24 deletions(-)
drivers/acpi/acpi_video.c +23 -24
index 54e09e7f8e77..944aba605c1a 100644
@@ -21,6 +21,7 @@
 #include <linux/sort.h>
 #include <linux/pci.h>
 #include <linux/pci_ids.h>
+#include <linux/platform_device.h>
 #include <linux/slab.h>
 #include <linux/dmi.h>
 #include <linux/suspend.h>
@@ -76,8 +77,8 @@ static int register_count;
 static DEFINE_MUTEX(register_count_mutex);
 static DEFINE_MUTEX(video_list_lock);
 static LIST_HEAD(video_bus_head);
-static int acpi_video_bus_add(struct acpi_device *device);
-static void acpi_video_bus_remove(struct acpi_device *device);
+static int acpi_video_bus_probe(struct platform_device *pdev);
+static void acpi_video_bus_remove(struct platform_device *pdev);
 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data);
 
 /*
@@ -98,14 +99,13 @@ static const struct acpi_device_id video_device_ids[] = {
 };
 MODULE_DEVICE_TABLE(acpi, video_device_ids);
 
-static struct acpi_driver acpi_video_bus = {
-	.name = "video",
-	.class = ACPI_VIDEO_CLASS,
-	.ids = video_device_ids,
-	.ops = {
-		.add = acpi_video_bus_add,
-		.remove = acpi_video_bus_remove,
-		},
+static struct platform_driver acpi_video_bus = {
+	.probe = acpi_video_bus_probe,
+	.remove = acpi_video_bus_remove,
+	.driver = {
+		.name = "acpi-video",
+		.acpi_match_table = video_device_ids,
+	},
 };
 
 struct acpi_video_bus_flags {
@@ -1888,7 +1888,8 @@ static void acpi_video_dev_add_notify_handler(struct acpi_video_device *device)
 		device->flags.notify = 1;
 }
 
-static int acpi_video_bus_add_notify_handler(struct acpi_video_bus *video)
+static int acpi_video_bus_add_notify_handler(struct acpi_video_bus *video,
+					     struct platform_device *pdev)
 {
 	struct input_dev *input;
 	struct acpi_video_device *dev;
@@ -1911,7 +1912,7 @@ static int acpi_video_bus_add_notify_handler(struct acpi_video_bus *video)
 	input->phys = video->phys;
 	input->id.bustype = BUS_HOST;
 	input->id.product = 0x06;
-	input->dev.parent = &video->device->dev;
+	input->dev.parent = &pdev->dev;
 	input->evbit[0] = BIT(EV_KEY);
 	set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
 	set_bit(KEY_VIDEO_NEXT, input->keybit);
@@ -1983,8 +1984,9 @@ static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
 
 static int instance;
 
-static int acpi_video_bus_add(struct acpi_device *device)
+static int acpi_video_bus_probe(struct platform_device *pdev)
 {
+	struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
 	struct acpi_video_bus *video;
 	bool auto_detect;
 	int error;
@@ -2021,6 +2023,8 @@ static int acpi_video_bus_add(struct acpi_device *device)
 		instance++;
 	}
 
+	platform_set_drvdata(pdev, video);
+
 	video->device = device;
 	strscpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
 	strscpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
@@ -2068,7 +2072,7 @@ static int acpi_video_bus_add(struct acpi_device *device)
 	    !auto_detect)
 		acpi_video_bus_register_backlight(video);
 
-	error = acpi_video_bus_add_notify_handler(video);
+	error = acpi_video_bus_add_notify_handler(video, pdev);
 	if (error)
 		goto err_del;
 
@@ -2096,15 +2100,10 @@ static int acpi_video_bus_add(struct acpi_device *device)
 	return error;
 }
 
-static void acpi_video_bus_remove(struct acpi_device *device)
+static void acpi_video_bus_remove(struct platform_device *pdev)
 {
-	struct acpi_video_bus *video = NULL;
-
-
-	if (!device || !acpi_driver_data(device))
-		return;
-
-	video = acpi_driver_data(device);
+	struct acpi_video_bus *video = platform_get_drvdata(pdev);
+	struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
 
 	acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY,
 				       acpi_video_bus_notify);
@@ -2167,7 +2166,7 @@ int acpi_video_register(void)
 
 	dmi_check_system(video_dmi_table);
 
-	ret = acpi_bus_register_driver(&acpi_video_bus);
+	ret = platform_driver_register(&acpi_video_bus);
 	if (ret)
 		goto leave;
 
@@ -2187,7 +2186,7 @@ void acpi_video_unregister(void)
 {
 	mutex_lock(&register_count_mutex);
 	if (register_count) {
-		acpi_bus_unregister_driver(&acpi_video_bus);
+		platform_driver_unregister(&acpi_video_bus);
 		register_count = 0;
 		may_report_brightness_keys = false;
 	}
Signature · 1 line
2.51.0
#4 lore raw
In reply to Rafael J. Wysocki

Hi Rafael,

Quoted 7 lines · Rafael J. Wysocki

Hi All,

This is a resend of

https://lore.kernel.org/linux-acpi/[email protected]/

due to the lack of feedback.

Sorry for not being able to provide feedback. I'm still getting up 2 speed wrt my new position at Qualcomm so atm I don't really have time to look into this.

I do plan to add linux-pm/linux-next + these patches to my local kernel so that they get some testing that way. If I hit any issues I'll let you know.

Regards,

Hans

author maintainer
#5 lore raw

Hi Hans,

Quoted 8 lines · Hans de Goede

Hi Rafael,

Quoted 4 lines · Rafael J. Wysocki

Hi All,

This is a resend of

Quoted 7 lines
Quoted 3 lines

https://lore.kernel.org/linux-acpi/[email protected]/

due to the lack of feedback.

Sorry for not being able to provide feedback. I'm still getting up 2 speed wrt my new position at Qualcomm so atm I don't really have time to look into this.

No worries.

Quoted 3 lines

I do plan to add linux-pm/linux-next + these patches to my local kernel so that they get some testing that way. If I hit any issues I'll let you know.

Thank you!

#6 lore raw
In reply to Rafael J. Wysocki

Am 02.01.26 um 12:48 schrieb Rafael J. Wysocki:

Quoted 9 lines

Hi All,

This is a resend of

https://lore.kernel.org/linux-acpi/[email protected]/

due to the lack of feedback.

It applies on top of the ACPI patches in linux-next.

I am somehow unable to apply this series onto linux-next. Can you send a new series that can be applied on the current linux-next?

Thanks,
Armin Wolf

Quoted 9 lines

The original cover letter still applies.

Thanks!

author maintainer
#7 lore raw
Quoted 7 lines · Armin Wolf

Am 02.01.26 um 12:48 schrieb Rafael J. Wysocki:

Quoted 4 lines

Hi All,

This is a resend of

Quoted 8 lines
Quoted 5 lines

https://lore.kernel.org/linux-acpi/[email protected]/

due to the lack of feedback.

It applies on top of the ACPI patches in linux-next.

I am somehow unable to apply this series onto linux-next. Can you send a new series that can be applied on the current linux-next?

It should be there in linux-next already, sorry for forgetting to mention that.

Reviewed-by on the v1 series
#8 lore raw
In reply to Rafael J. Wysocki

Am 02.01.26 um 12:48 schrieb Rafael J. Wysocki:

Quoted 6 lines

Hi All,

This is a resend of

https://lore.kernel.org/linux-acpi/[email protected]/

Quoted 7 lines

due to the lack of feedback.

It applies on top of the ACPI patches in linux-next.

The original cover letter still applies.

Thanks!

I finally found some time to test this series on a machine that has a working ACPI backlight implementation. I only booted inside a minimal console environment, but i was able to still control the backlight using the acpi-video driver.

I also verified that acpi-video was bound to the correct platform device, and that the backlight device was still associated with the correct PCI device belonging to the integrated GPU.

So for the whole series:

Thanks,
Armin Wolf

author maintainer
#9 lore raw
Quoted 21 lines · Armin Wolf

Am 02.01.26 um 12:48 schrieb Rafael J. Wysocki:

Quoted 6 lines

Hi All,

This is a resend of

https://lore.kernel.org/linux-acpi/[email protected]/

Quoted 7 lines

due to the lack of feedback.

It applies on top of the ACPI patches in linux-next.

The original cover letter still applies.

Thanks!

I finally found some time to test this series on a machine that has a working ACPI backlight implementation. I only booted inside a minimal console environment, but i was able to still control the backlight using the acpi-video driver.

Quoted 6 lines

I also verified that acpi-video was bound to the correct platform device, and that the backlight device was still associated with the correct PCI device belonging to the integrated GPU.

So for the whole series:

Thank you!