[PATCH v1 2/2] platform/x86: eeepc-laptop: Convert ACPI driver to a platform one

Rafael J. Wysocki posted 1 patch 1 month, 2 weeks ago
drivers/platform/x86/eeepc-laptop.c | 32 +++++++++++++++--------------
1 file changed, 17 insertions(+), 15 deletions(-)
[PATCH v1 2/2] platform/x86: eeepc-laptop: Convert ACPI driver to a platform one
Posted by Rafael J. Wysocki 1 month, 2 weeks ago
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>

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 EEEPC laptop 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.

Link: https://lore.kernel.org/all/2396510.ElGaqSPkdT@rafael.j.wysocki/ [1]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/platform/x86/eeepc-laptop.c | 32 +++++++++++++++--------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c
index 626a99a71fce..02a71095920e 100644
--- a/drivers/platform/x86/eeepc-laptop.c
+++ b/drivers/platform/x86/eeepc-laptop.c
@@ -1361,8 +1361,9 @@ static void eeepc_enable_camera(struct eeepc_laptop *eeepc)
 
 static bool eeepc_device_present;
 
-static int eeepc_acpi_add(struct acpi_device *device)
+static int eeepc_acpi_probe(struct platform_device *pdev)
 {
+	struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
 	struct eeepc_laptop *eeepc;
 	int result;
 
@@ -1373,9 +1374,10 @@ static int eeepc_acpi_add(struct acpi_device *device)
 	eeepc->handle = device->handle;
 	strscpy(acpi_device_name(device), EEEPC_ACPI_DEVICE_NAME);
 	strscpy(acpi_device_class(device), EEEPC_ACPI_CLASS);
-	device->driver_data = eeepc;
 	eeepc->device = device;
 
+	platform_set_drvdata(pdev, eeepc);
+
 	eeepc->hotplug_disabled = hotplug_disabled;
 
 	eeepc_dmi_check(eeepc);
@@ -1448,11 +1450,12 @@ static int eeepc_acpi_add(struct acpi_device *device)
 	return result;
 }
 
-static void eeepc_acpi_remove(struct acpi_device *device)
+static void eeepc_acpi_remove(struct platform_device *pdev)
 {
-	struct eeepc_laptop *eeepc = acpi_driver_data(device);
+	struct eeepc_laptop *eeepc = platform_get_drvdata(pdev);
 
-	acpi_dev_remove_notify_handler(device, ACPI_ALL_NOTIFY, eeepc_acpi_notify);
+	acpi_dev_remove_notify_handler(ACPI_COMPANION(&pdev->dev),
+				       ACPI_ALL_NOTIFY, eeepc_acpi_notify);
 	eeepc_backlight_exit(eeepc);
 	eeepc_rfkill_exit(eeepc);
 	eeepc_input_exit(eeepc);
@@ -1469,13 +1472,12 @@ static const struct acpi_device_id eeepc_device_ids[] = {
 };
 MODULE_DEVICE_TABLE(acpi, eeepc_device_ids);
 
-static struct acpi_driver eeepc_acpi_driver = {
-	.name = EEEPC_LAPTOP_NAME,
-	.class = EEEPC_ACPI_CLASS,
-	.ids = eeepc_device_ids,
-	.ops = {
-		.add = eeepc_acpi_add,
-		.remove = eeepc_acpi_remove,
+static struct platform_driver eeepc_acpi_driver = {
+	.probe = eeepc_acpi_probe,
+	.remove = eeepc_acpi_remove,
+	.driver = {
+		.name = EEEPC_LAPTOP_NAME,
+		.acpi_match_table = eeepc_device_ids,
 	},
 };
 
@@ -1488,7 +1490,7 @@ static int __init eeepc_laptop_init(void)
 	if (result < 0)
 		return result;
 
-	result = acpi_bus_register_driver(&eeepc_acpi_driver);
+	result = platform_driver_register(&eeepc_acpi_driver);
 	if (result < 0)
 		goto fail_acpi_driver;
 
@@ -1500,7 +1502,7 @@ static int __init eeepc_laptop_init(void)
 	return 0;
 
 fail_no_device:
-	acpi_bus_unregister_driver(&eeepc_acpi_driver);
+	platform_driver_unregister(&eeepc_acpi_driver);
 fail_acpi_driver:
 	platform_driver_unregister(&platform_driver);
 	return result;
@@ -1508,7 +1510,7 @@ static int __init eeepc_laptop_init(void)
 
 static void __exit eeepc_laptop_exit(void)
 {
-	acpi_bus_unregister_driver(&eeepc_acpi_driver);
+	platform_driver_unregister(&eeepc_acpi_driver);
 	platform_driver_unregister(&platform_driver);
 }
 
-- 
2.51.0
Re: [PATCH v1 2/2] platform/x86: eeepc-laptop: Convert ACPI driver to a platform one
Posted by Denis Benato 1 month, 2 weeks ago
On 2/28/26 16:22, Rafael J. Wysocki wrote:
> From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
>
> 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 EEEPC laptop 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.
>
> Link: https://lore.kernel.org/all/2396510.ElGaqSPkdT@rafael.j.wysocki/ [1]
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Denis Benato <denis.benato@linux.dev>
> ---
>  drivers/platform/x86/eeepc-laptop.c | 32 +++++++++++++++--------------
>  1 file changed, 17 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c
> index 626a99a71fce..02a71095920e 100644
> --- a/drivers/platform/x86/eeepc-laptop.c
> +++ b/drivers/platform/x86/eeepc-laptop.c
> @@ -1361,8 +1361,9 @@ static void eeepc_enable_camera(struct eeepc_laptop *eeepc)
>  
>  static bool eeepc_device_present;
>  
> -static int eeepc_acpi_add(struct acpi_device *device)
> +static int eeepc_acpi_probe(struct platform_device *pdev)
>  {
> +	struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
>  	struct eeepc_laptop *eeepc;
>  	int result;
>  
> @@ -1373,9 +1374,10 @@ static int eeepc_acpi_add(struct acpi_device *device)
>  	eeepc->handle = device->handle;
>  	strscpy(acpi_device_name(device), EEEPC_ACPI_DEVICE_NAME);
>  	strscpy(acpi_device_class(device), EEEPC_ACPI_CLASS);
> -	device->driver_data = eeepc;
>  	eeepc->device = device;
>  
> +	platform_set_drvdata(pdev, eeepc);
> +
>  	eeepc->hotplug_disabled = hotplug_disabled;
>  
>  	eeepc_dmi_check(eeepc);
> @@ -1448,11 +1450,12 @@ static int eeepc_acpi_add(struct acpi_device *device)
>  	return result;
>  }
>  
> -static void eeepc_acpi_remove(struct acpi_device *device)
> +static void eeepc_acpi_remove(struct platform_device *pdev)
>  {
> -	struct eeepc_laptop *eeepc = acpi_driver_data(device);
> +	struct eeepc_laptop *eeepc = platform_get_drvdata(pdev);
>  
> -	acpi_dev_remove_notify_handler(device, ACPI_ALL_NOTIFY, eeepc_acpi_notify);
> +	acpi_dev_remove_notify_handler(ACPI_COMPANION(&pdev->dev),
> +				       ACPI_ALL_NOTIFY, eeepc_acpi_notify);
>  	eeepc_backlight_exit(eeepc);
>  	eeepc_rfkill_exit(eeepc);
>  	eeepc_input_exit(eeepc);
> @@ -1469,13 +1472,12 @@ static const struct acpi_device_id eeepc_device_ids[] = {
>  };
>  MODULE_DEVICE_TABLE(acpi, eeepc_device_ids);
>  
> -static struct acpi_driver eeepc_acpi_driver = {
> -	.name = EEEPC_LAPTOP_NAME,
> -	.class = EEEPC_ACPI_CLASS,
> -	.ids = eeepc_device_ids,
> -	.ops = {
> -		.add = eeepc_acpi_add,
> -		.remove = eeepc_acpi_remove,
> +static struct platform_driver eeepc_acpi_driver = {
> +	.probe = eeepc_acpi_probe,
> +	.remove = eeepc_acpi_remove,
> +	.driver = {
> +		.name = EEEPC_LAPTOP_NAME,
> +		.acpi_match_table = eeepc_device_ids,
>  	},
>  };
>  
> @@ -1488,7 +1490,7 @@ static int __init eeepc_laptop_init(void)
>  	if (result < 0)
>  		return result;
>  
> -	result = acpi_bus_register_driver(&eeepc_acpi_driver);
> +	result = platform_driver_register(&eeepc_acpi_driver);
>  	if (result < 0)
>  		goto fail_acpi_driver;
>  
> @@ -1500,7 +1502,7 @@ static int __init eeepc_laptop_init(void)
>  	return 0;
>  
>  fail_no_device:
> -	acpi_bus_unregister_driver(&eeepc_acpi_driver);
> +	platform_driver_unregister(&eeepc_acpi_driver);
>  fail_acpi_driver:
>  	platform_driver_unregister(&platform_driver);
>  	return result;
> @@ -1508,7 +1510,7 @@ static int __init eeepc_laptop_init(void)
>  
>  static void __exit eeepc_laptop_exit(void)
>  {
> -	acpi_bus_unregister_driver(&eeepc_acpi_driver);
> +	platform_driver_unregister(&eeepc_acpi_driver);
>  	platform_driver_unregister(&platform_driver);
>  }
>