Skip to contentSkip to conversation

sonypi: Convert ACPI driver to a platform one

PATCH In review Rafael J. Wysocki 2 participants 3 messages Feb 23 – Mar 17

Subsystems (4)
lore
Share & tools
lore

Rafael J. Wysocki

author maintainer
#0 lore raw

PATCH 1/1 sonypi: Convert ACPI driver to a platform one

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 sonypi 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/char/sonypi.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)
drivers/char/sonypi.c +13 -12
index 677bb5ac950a..ccda997a9098 100644
@@ -1115,15 +1115,17 @@ static int sonypi_disable(void)
 }
 
 #ifdef CONFIG_ACPI
-static int sonypi_acpi_add(struct acpi_device *device)
+static int sonypi_acpi_probe(struct platform_device *pdev)
 {
+	struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
+
 	sonypi_acpi_device = device;
 	strcpy(acpi_device_name(device), "Sony laptop hotkeys");
 	strcpy(acpi_device_class(device), "sony/hotkey");
 	return 0;
 }
 
-static void sonypi_acpi_remove(struct acpi_device *device)
+static void sonypi_acpi_remove(struct platform_device *pdev)
 {
 	sonypi_acpi_device = NULL;
 }
@@ -1133,13 +1135,12 @@ static const struct acpi_device_id sonypi_device_ids[] = {
 	{"", 0},
 };
 
-static struct acpi_driver sonypi_acpi_driver = {
-	.name           = "sonypi",
-	.class          = "hkey",
-	.ids            = sonypi_device_ids,
-	.ops            = {
-		           .add = sonypi_acpi_add,
-			   .remove = sonypi_acpi_remove,
+static struct platform_driver sonypi_acpi_driver = {
+	.probe = sonypi_acpi_probe,
+	.remove = sonypi_acpi_remove,
+	.driver = {
+		.name = "sonypi_acpi",
+		.acpi_match_table = sonypi_device_ids,
 	},
 };
 #endif
@@ -1518,8 +1519,8 @@ static int __init sonypi_init(void)
 		goto err_free_device;
 
 #ifdef CONFIG_ACPI
-	if (acpi_bus_register_driver(&sonypi_acpi_driver) >= 0)
-		acpi_driver_registered = 1;
+	error = platform_driver_register(&sonypi_acpi_driver);
+	acpi_driver_registered = !error;
 #endif
 
 	return 0;
@@ -1535,7 +1536,7 @@ static void __exit sonypi_exit(void)
 {
 #ifdef CONFIG_ACPI
 	if (acpi_driver_registered)
-		acpi_bus_unregister_driver(&sonypi_acpi_driver);
+		platform_driver_unregister(&sonypi_acpi_driver);
 #endif
 	platform_device_unregister(sonypi_platform_device);
 	platform_driver_unregister(&sonypi_driver);
Signature · 1 line
2.51.0
author maintainer
#1 lore raw
Quoted 78 lines · 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 sonypi 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/char/sonypi.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)
drivers/char/sonypi.c +12 -11
index 677bb5ac950a..ccda997a9098 100644
@@ -1115,15 +1115,17 @@ static int sonypi_disable(void)
 }
 
 #ifdef CONFIG_ACPI
-static int sonypi_acpi_add(struct acpi_device *device)
+static int sonypi_acpi_probe(struct platform_device *pdev)
 {
+       struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
+
        sonypi_acpi_device = device;
        strcpy(acpi_device_name(device), "Sony laptop hotkeys");
        strcpy(acpi_device_class(device), "sony/hotkey");
        return 0;
 }
 
-static void sonypi_acpi_remove(struct acpi_device *device)
+static void sonypi_acpi_remove(struct platform_device *pdev)
 {
        sonypi_acpi_device = NULL;
 }
@@ -1133,13 +1135,12 @@ static const struct acpi_device_id sonypi_device_ids[] = {
        {"", 0},
 };
 
-static struct acpi_driver sonypi_acpi_driver = {
-       .name           = "sonypi",
-       .class          = "hkey",
-       .ids            = sonypi_device_ids,
-       .ops            = {
-                          .add = sonypi_acpi_add,
-                          .remove = sonypi_acpi_remove,
+static struct platform_driver sonypi_acpi_driver = {
+       .probe = sonypi_acpi_probe,
+       .remove = sonypi_acpi_remove,
+       .driver = {
+               .name = "sonypi_acpi",
+               .acpi_match_table = sonypi_device_ids,
        },
 };
 #endif
@@ -1518,8 +1519,8 @@ static int __init sonypi_init(void)
                goto err_free_device;
 
 #ifdef CONFIG_ACPI
-       if (acpi_bus_register_driver(&sonypi_acpi_driver) >= 0)
-               acpi_driver_registered = 1;
+       error = platform_driver_register(&sonypi_acpi_driver);
+       acpi_driver_registered = !error;
 #endif
 
        return 0;

drivers/char/sonypi.c static void __exit sonypi_exit(void)

Quoted 9 lines
drivers/char/sonypi.c +1 -2
@@ -1535,7 +1536,7 @@ static void __exit sonypi_exit(void)
 {
 #ifdef CONFIG_ACPI
        if (acpi_driver_registered)
-               acpi_bus_unregister_driver(&sonypi_acpi_driver);
+               platform_driver_unregister(&sonypi_acpi_driver);
 #endif
        platform_device_unregister(sonypi_platform_device);
        platform_driver_unregister(&sonypi_driver);
--

If anyone has any objections or concerns regarding this change, please let me know.

In the absence of any, I'll queue it up for 7.1.

Thanks!

maintainer Reviewed-by
#2 lore raw
Quoted 93 lines · Rafael J. Wysocki
Quoted 78 lines · 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 sonypi 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/char/sonypi.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)
drivers/char/sonypi.c +12 -11
index 677bb5ac950a..ccda997a9098 100644
@@ -1115,15 +1115,17 @@ static int sonypi_disable(void)
 }
 
 #ifdef CONFIG_ACPI
-static int sonypi_acpi_add(struct acpi_device *device)
+static int sonypi_acpi_probe(struct platform_device *pdev)
 {
+       struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
+
        sonypi_acpi_device = device;
        strcpy(acpi_device_name(device), "Sony laptop hotkeys");
        strcpy(acpi_device_class(device), "sony/hotkey");
        return 0;
 }
 
-static void sonypi_acpi_remove(struct acpi_device *device)
+static void sonypi_acpi_remove(struct platform_device *pdev)
 {
        sonypi_acpi_device = NULL;
 }
@@ -1133,13 +1135,12 @@ static const struct acpi_device_id sonypi_device_ids[] = {
        {"", 0},
 };
 
-static struct acpi_driver sonypi_acpi_driver = {
-       .name           = "sonypi",
-       .class          = "hkey",
-       .ids            = sonypi_device_ids,
-       .ops            = {
-                          .add = sonypi_acpi_add,
-                          .remove = sonypi_acpi_remove,
+static struct platform_driver sonypi_acpi_driver = {
+       .probe = sonypi_acpi_probe,
+       .remove = sonypi_acpi_remove,
+       .driver = {
+               .name = "sonypi_acpi",
+               .acpi_match_table = sonypi_device_ids,
        },
 };
 #endif
@@ -1518,8 +1519,8 @@ static int __init sonypi_init(void)
                goto err_free_device;
 
 #ifdef CONFIG_ACPI
-       if (acpi_bus_register_driver(&sonypi_acpi_driver) >= 0)
-               acpi_driver_registered = 1;
+       error = platform_driver_register(&sonypi_acpi_driver);
+       acpi_driver_registered = !error;
 #endif
 
        return 0;

drivers/char/sonypi.c static void __exit sonypi_exit(void)

Quoted 9 lines
drivers/char/sonypi.c +1 -2
@@ -1535,7 +1536,7 @@ static void __exit sonypi_exit(void)
 {
 #ifdef CONFIG_ACPI
        if (acpi_driver_registered)
-               acpi_bus_unregister_driver(&sonypi_acpi_driver);
+               platform_driver_unregister(&sonypi_acpi_driver);
 #endif
        platform_device_unregister(sonypi_platform_device);
        platform_driver_unregister(&sonypi_driver);
--

If anyone has any objections or concerns regarding this change, please let me know.

Quoted 1 line

In the absence of any, I'll queue it up for 7.1.

I did check it earlier, it seemed fine to me.

Signature · 1 line
 i.