Skip to contentSkip to conversation

platform/x86: lg-laptop: Bind to a platform device instead of an ACPI one

PATCH In review Rafael J. Wysocki 2 participants 4 messages Mar 12 – Mar 17

Subsystems (3)
lore
Share & tools
lore

Rafael J. Wysocki

author maintainer
#0 lore raw

cover platform/x86: lg-laptop: Bind to a platform device instead of an ACPI one

Hi All,

This series is part of a larger effort to switch over all drivers using the struct acpi_driver interface to the more common struct platform_driver interface and eliminate the former. The background is explained in Documentation/driver-api/acpi/acpi-drivers.rst and in the changelog of the patch that introduced the above document:

https://lore.kernel.org/all/[email protected]/

The bottom line is that the kernel would be better off without struct acpi_driver and so it is better to get rid of it.

This series carries out driver conversion of the platform x86 LG Gram ACPI features and hotkeys driver.

Patch [1/2] drops a debug-only .notify() callback from the driver, which is requisite for the driver conversion.

Patch [2/2] converts the driver to using struct platform_driver for device binding.

Thanks!

author maintainer
#1 lore raw

PATCH 1/2 platform/x86: lg-laptop: Drop debug-only ACPI notify handler

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

To facilitate subsequent conversion of the driver to using struct platform_driver instead of struct acpi_driver, drop the debug-only notify handler method from the driver.

No intentional functional impact beyond debug.

---
 drivers/platform/x86/lg-laptop.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/platform/x86/lg-laptop.c +0 -6
index 61ef7a218a80..7122d96abf86 100644
@@ -271,11 +271,6 @@ static void wmi_input_setup(void)
 	}
 }
 
-static void acpi_notify(struct acpi_device *device, u32 event)
-{
-	acpi_handle_debug(device->handle, "notify: %d\n", event);
-}
-
 static ssize_t fan_mode_store(struct device *dev,
 			      struct device_attribute *attr,
 			      const char *buffer, size_t count)
@@ -906,7 +901,6 @@ static struct acpi_driver acpi_driver = {
 	.ops = {
 		.add = acpi_add,
 		.remove = acpi_remove,
-		.notify = acpi_notify,
 		},
 };
 
Signature · 1 line
2.51.0
author maintainer
#2 lore raw

PATCH 2/2 platform/x86: lg-laptop: Convert ACPI driver to a platform one

In reply to Rafael J. Wysocki

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

In all cases in which a struct acpi_driver is used for binding a driver to an ACPI device object, a corresponding platform device is created by the ACPI core and that device is regarded as a proper representation of underlying hardware. Accordingly, a struct platform_driver should be used by driver code to bind to that device. There are multiple reasons why drivers should not bind directly to ACPI device objects [1].

Overall, it is better to bind drivers to platform devices than to their ACPI companions, so convert the LG Gram ACPI features and hotkeys driver from an ACPI 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/platform/x86/lg-laptop.c | 45 +++++++++-----------------------
 1 file changed, 13 insertions(+), 32 deletions(-)
drivers/platform/x86/lg-laptop.c +13 -32
index 7122d96abf86..9681412d694b 100644
@@ -759,8 +759,9 @@ static void lg_laptop_remove_address_space_handler(void *data)
 					  &lg_laptop_address_space_handler);
 }
 
-static int acpi_add(struct acpi_device *device)
+static int acpi_probe(struct platform_device *pdev)
 {
+	struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
 	struct platform_device_info pdev_info = {
 		.fwnode = acpi_fwnode_handle(device),
 		.name = PLATFORM_NAME,
@@ -776,11 +777,11 @@ static int acpi_add(struct acpi_device *device)
 
 	status = acpi_install_address_space_handler(device->handle, LG_ADDRESS_SPACE_ID,
 						    &lg_laptop_address_space_handler,
-						    NULL, &device->dev);
+						    NULL, &pdev->dev);
 	if (ACPI_FAILURE(status))
 		return -ENODEV;
 
-	ret = devm_add_action_or_reset(&device->dev, lg_laptop_remove_address_space_handler,
+	ret = devm_add_action_or_reset(&pdev->dev, lg_laptop_remove_address_space_handler,
 				       device);
 	if (ret < 0)
 		return ret;
@@ -874,7 +875,7 @@ static int acpi_add(struct acpi_device *device)
 	return ret;
 }
 
-static void acpi_remove(struct acpi_device *device)
+static void acpi_remove(struct platform_device *pdev)
 {
 	sysfs_remove_group(&pf_device->dev.kobj, &dev_attribute_group);
 
@@ -894,33 +895,13 @@ static const struct acpi_device_id device_ids[] = {
 };
 MODULE_DEVICE_TABLE(acpi, device_ids);
 
-static struct acpi_driver acpi_driver = {
-	.name = "LG Gram Laptop Support",
-	.class = "lg-laptop",
-	.ids = device_ids,
-	.ops = {
-		.add = acpi_add,
-		.remove = acpi_remove,
-		},
+static struct platform_driver acpi_driver = {
+	.probe = acpi_probe,
+	.remove = acpi_remove,
+	.driver = {
+		.name = "LG Gram Laptop Support",
+		.acpi_match_table = device_ids,
+	},
 };
 
-static int __init acpi_init(void)
-{
-	int result;
-
-	result = acpi_bus_register_driver(&acpi_driver);
-	if (result < 0) {
-		pr_debug("Error registering driver\n");
-		return -ENODEV;
-	}
-
-	return 0;
-}
-
-static void __exit acpi_exit(void)
-{
-	acpi_bus_unregister_driver(&acpi_driver);
-}
-
-module_init(acpi_init);
-module_exit(acpi_exit);
+module_platform_driver(acpi_driver);
Signature · 1 line
2.51.0
maintainer
#3 lore raw
In reply to Rafael J. Wysocki
Quoted 9 lines · Rafael J. Wysocki

This series is part of a larger effort to switch over all drivers using the struct acpi_driver interface to the more common struct platform_driver interface and eliminate the former. The background is explained in Documentation/driver-api/acpi/acpi-drivers.rst and in the changelog of the patch that introduced the above document:

https://lore.kernel.org/all/[email protected]/

[...]

Thank you for your contribution, it has been applied to my local review-ilpo-next branch. Note it will show up in the public platform-drivers-x86/review-ilpo-next branch only once I've pushed my local branch there, which might take a while.

The list of commits applied:
[1/2] platform/x86: lg-laptop: Drop debug-only ACPI notify handler

      commit: c12fe0b2c12195e0d1c56e0f670a6bd792b0567e
[2/2] platform/x86: lg-laptop: Convert ACPI driver to a platform one
      commit: 2d9cb20610f75ca48c1cac064aede90196787507

--
i.