]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ACPI: SMBUS HC: Convert the driver to a platform one
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 11 Dec 2025 14:17:58 +0000 (15:17 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 29 Dec 2025 20:04:23 +0000 (21:04 +0100)
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 SMBUS HC driver to a platform one.

After this conversion, acpi_ec_probe() does not need to populate the
driver_data pointer of the EC platform device's ACPI companion any
more, so update it accordingly.

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>
Link: https://patch.msgid.link/13909645.uLZWGnKmhe@rafael.j.wysocki
drivers/acpi/ec.c
drivers/acpi/sbshc.c

index bf4d86571b0d45b9a3c51d8a9bf562429e6ec177..197970339edc93b13a9a9fb838c59119d4db50a5 100644 (file)
@@ -1733,8 +1733,6 @@ static int acpi_ec_probe(struct platform_device *pdev)
                         "EC: Used to handle transactions and events\n");
 
        platform_set_drvdata(pdev, ec);
-       /* This is needed for the SMBUS HC driver to work. */
-       device->driver_data = ec;
 
        ret = !!request_region(ec->data_addr, 1, "EC data");
        WARN(!ret, "Could not request EC data io port 0x%lx", ec->data_addr);
index 1a2bf520be2306c36a8ad26e75442d347372edb9..b2892037e5d28854c72d9d3fa78e31ec52e4e023 100644 (file)
@@ -13,6 +13,8 @@
 #include <linux/delay.h>
 #include <linux/module.h>
 #include <linux/interrupt.h>
+#include <linux/platform_device.h>
+
 #include "sbshc.h"
 #include "internal.h"
 
@@ -30,8 +32,8 @@ struct acpi_smb_hc {
        bool done;
 };
 
-static int acpi_smbus_hc_add(struct acpi_device *device);
-static void acpi_smbus_hc_remove(struct acpi_device *device);
+static int acpi_smbus_hc_probe(struct platform_device *pdev);
+static void acpi_smbus_hc_remove(struct platform_device *pdev);
 
 static const struct acpi_device_id sbs_device_ids[] = {
        {"ACPI0001", 0},
@@ -41,14 +43,13 @@ static const struct acpi_device_id sbs_device_ids[] = {
 
 MODULE_DEVICE_TABLE(acpi, sbs_device_ids);
 
-static struct acpi_driver acpi_smb_hc_driver = {
-       .name = "smbus_hc",
-       .class = ACPI_SMB_HC_CLASS,
-       .ids = sbs_device_ids,
-       .ops = {
-               .add = acpi_smbus_hc_add,
-               .remove = acpi_smbus_hc_remove,
-               },
+static struct platform_driver acpi_smb_hc_driver = {
+       .probe = acpi_smbus_hc_probe,
+       .remove = acpi_smbus_hc_remove,
+       .driver = {
+               .name = "acpi-smbus-hc",
+               .acpi_match_table = sbs_device_ids,
+       },
 };
 
 union acpi_smb_status {
@@ -237,15 +238,13 @@ static int smbus_alarm(void *context)
        return 0;
 }
 
-static int acpi_smbus_hc_add(struct acpi_device *device)
+static int acpi_smbus_hc_probe(struct platform_device *pdev)
 {
+       struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
        int status;
        unsigned long long val;
        struct acpi_smb_hc *hc;
 
-       if (!device)
-               return -EINVAL;
-
        status = acpi_evaluate_integer(device->handle, "_EC", NULL, &val);
        if (ACPI_FAILURE(status)) {
                pr_err("error obtaining _EC.\n");
@@ -261,9 +260,12 @@ static int acpi_smbus_hc_add(struct acpi_device *device)
        mutex_init(&hc->lock);
        init_waitqueue_head(&hc->wait);
 
-       hc->ec = acpi_driver_data(acpi_dev_parent(device));
+       platform_set_drvdata(pdev, hc);
+
+       hc->ec = dev_get_drvdata(pdev->dev.parent);
        hc->offset = (val >> 8) & 0xff;
        hc->query_bit = val & 0xff;
+       /* This is needed for the SBS driver to work. */
        device->driver_data = hc;
 
        acpi_ec_add_query_handler(hc->ec, hc->query_bit, NULL, smbus_alarm, hc);
@@ -273,21 +275,18 @@ static int acpi_smbus_hc_add(struct acpi_device *device)
        return 0;
 }
 
-static void acpi_smbus_hc_remove(struct acpi_device *device)
+static void acpi_smbus_hc_remove(struct platform_device *pdev)
 {
-       struct acpi_smb_hc *hc;
-
-       if (!device)
-               return;
+       struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
+       struct acpi_smb_hc *hc = platform_get_drvdata(pdev);
 
-       hc = acpi_driver_data(device);
        acpi_ec_remove_query_handler(hc->ec, hc->query_bit);
        acpi_os_wait_events_complete();
        kfree(hc);
        device->driver_data = NULL;
 }
 
-module_acpi_driver(acpi_smb_hc_driver);
+module_platform_driver(acpi_smb_hc_driver);
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Alexey Starikovskiy");