[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <13909645.uLZWGnKmhe@rafael.j.wysocki>
Date: Thu, 11 Dec 2025 15:17:58 +0100
From: "Rafael J. Wysocki" <rafael@...nel.org>
To: Linux ACPI <linux-acpi@...r.kernel.org>
Cc: LKML <linux-kernel@...r.kernel.org>, Linux PM <linux-pm@...r.kernel.org>,
Armin Wolf <w_armin@....de>, Hans de Goede <hansg@...nel.org>
Subject:
[RFT][PATCH v1 3/6] ACPI: SMBUS HC: Convert the driver to a platform one
From: Rafael J. Wysocki <rafael.j.wysocki@...el.com>
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@...el.com>
---
drivers/acpi/ec.c | 2 --
drivers/acpi/sbshc.c | 43 +++++++++++++++++++++----------------------
2 files changed, 21 insertions(+), 24 deletions(-)
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -1733,8 +1733,6 @@ static int acpi_ec_probe(struct platform
"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);
--- a/drivers/acpi/sbshc.c
+++ b/drivers/acpi/sbshc.c
@@ -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_d
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
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
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");
Powered by blists - more mailing lists