Skip to content

Commit 6d25905

Browse files
committed
ACPI: SMBUS HC: Convert the driver to a platform one
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
1 parent db65a06 commit 6d25905

2 files changed

Lines changed: 21 additions & 24 deletions

File tree

drivers/acpi/ec.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,8 +1733,6 @@ static int acpi_ec_probe(struct platform_device *pdev)
17331733
"EC: Used to handle transactions and events\n");
17341734

17351735
platform_set_drvdata(pdev, ec);
1736-
/* This is needed for the SMBUS HC driver to work. */
1737-
device->driver_data = ec;
17381736

17391737
ret = !!request_region(ec->data_addr, 1, "EC data");
17401738
WARN(!ret, "Could not request EC data io port 0x%lx", ec->data_addr);

drivers/acpi/sbshc.c

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <linux/delay.h>
1414
#include <linux/module.h>
1515
#include <linux/interrupt.h>
16+
#include <linux/platform_device.h>
17+
1618
#include "sbshc.h"
1719
#include "internal.h"
1820

@@ -30,8 +32,8 @@ struct acpi_smb_hc {
3032
bool done;
3133
};
3234

33-
static int acpi_smbus_hc_add(struct acpi_device *device);
34-
static void acpi_smbus_hc_remove(struct acpi_device *device);
35+
static int acpi_smbus_hc_probe(struct platform_device *pdev);
36+
static void acpi_smbus_hc_remove(struct platform_device *pdev);
3537

3638
static const struct acpi_device_id sbs_device_ids[] = {
3739
{"ACPI0001", 0},
@@ -41,14 +43,13 @@ static const struct acpi_device_id sbs_device_ids[] = {
4143

4244
MODULE_DEVICE_TABLE(acpi, sbs_device_ids);
4345

44-
static struct acpi_driver acpi_smb_hc_driver = {
45-
.name = "smbus_hc",
46-
.class = ACPI_SMB_HC_CLASS,
47-
.ids = sbs_device_ids,
48-
.ops = {
49-
.add = acpi_smbus_hc_add,
50-
.remove = acpi_smbus_hc_remove,
51-
},
46+
static struct platform_driver acpi_smb_hc_driver = {
47+
.probe = acpi_smbus_hc_probe,
48+
.remove = acpi_smbus_hc_remove,
49+
.driver = {
50+
.name = "acpi-smbus-hc",
51+
.acpi_match_table = sbs_device_ids,
52+
},
5253
};
5354

5455
union acpi_smb_status {
@@ -237,15 +238,13 @@ static int smbus_alarm(void *context)
237238
return 0;
238239
}
239240

240-
static int acpi_smbus_hc_add(struct acpi_device *device)
241+
static int acpi_smbus_hc_probe(struct platform_device *pdev)
241242
{
243+
struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
242244
int status;
243245
unsigned long long val;
244246
struct acpi_smb_hc *hc;
245247

246-
if (!device)
247-
return -EINVAL;
248-
249248
status = acpi_evaluate_integer(device->handle, "_EC", NULL, &val);
250249
if (ACPI_FAILURE(status)) {
251250
pr_err("error obtaining _EC.\n");
@@ -261,9 +260,12 @@ static int acpi_smbus_hc_add(struct acpi_device *device)
261260
mutex_init(&hc->lock);
262261
init_waitqueue_head(&hc->wait);
263262

264-
hc->ec = acpi_driver_data(acpi_dev_parent(device));
263+
platform_set_drvdata(pdev, hc);
264+
265+
hc->ec = dev_get_drvdata(pdev->dev.parent);
265266
hc->offset = (val >> 8) & 0xff;
266267
hc->query_bit = val & 0xff;
268+
/* This is needed for the SBS driver to work. */
267269
device->driver_data = hc;
268270

269271
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)
273275
return 0;
274276
}
275277

276-
static void acpi_smbus_hc_remove(struct acpi_device *device)
278+
static void acpi_smbus_hc_remove(struct platform_device *pdev)
277279
{
278-
struct acpi_smb_hc *hc;
279-
280-
if (!device)
281-
return;
280+
struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
281+
struct acpi_smb_hc *hc = platform_get_drvdata(pdev);
282282

283-
hc = acpi_driver_data(device);
284283
acpi_ec_remove_query_handler(hc->ec, hc->query_bit);
285284
acpi_os_wait_events_complete();
286285
kfree(hc);
287286
device->driver_data = NULL;
288287
}
289288

290-
module_acpi_driver(acpi_smb_hc_driver);
289+
module_platform_driver(acpi_smb_hc_driver);
291290

292291
MODULE_LICENSE("GPL");
293292
MODULE_AUTHOR("Alexey Starikovskiy");

0 commit comments

Comments
 (0)