Skip to content

Commit 9460eaa

Browse files
committed
ACPI: SBS: 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 smart battery subsystem (SBS) driver to a platform one. After this conversion, acpi_smbus_hc_probe() does not need to populate the driver_data pointer of the SMBUS HC 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/3390477.aeNJFYEL58@rafael.j.wysocki
1 parent 6d25905 commit 9460eaa

2 files changed

Lines changed: 21 additions & 29 deletions

File tree

drivers/acpi/sbs.c

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/timer.h>
2020
#include <linux/jiffies.h>
2121
#include <linux/delay.h>
22+
#include <linux/platform_device.h>
2223
#include <linux/power_supply.h>
2324
#include <linux/platform_data/x86/apple.h>
2425
#include <acpi/battery.h>
@@ -95,7 +96,7 @@ struct acpi_sbs {
9596

9697
#define to_acpi_sbs(x) power_supply_get_drvdata(x)
9798

98-
static void acpi_sbs_remove(struct acpi_device *device);
99+
static void acpi_sbs_remove(struct platform_device *pdev);
99100
static int acpi_battery_get_state(struct acpi_battery *battery);
100101

101102
static inline int battery_scale(int log)
@@ -628,8 +629,9 @@ static void acpi_sbs_callback(void *context)
628629
}
629630
}
630631

631-
static int acpi_sbs_add(struct acpi_device *device)
632+
static int acpi_sbs_probe(struct platform_device *pdev)
632633
{
634+
struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
633635
struct acpi_sbs *sbs;
634636
int result = 0;
635637
int id;
@@ -642,11 +644,12 @@ static int acpi_sbs_add(struct acpi_device *device)
642644

643645
mutex_init(&sbs->lock);
644646

645-
sbs->hc = acpi_driver_data(acpi_dev_parent(device));
647+
platform_set_drvdata(pdev, sbs);
648+
649+
sbs->hc = dev_get_drvdata(pdev->dev.parent);
646650
sbs->device = device;
647651
strscpy(acpi_device_name(device), ACPI_SBS_DEVICE_NAME);
648652
strscpy(acpi_device_class(device), ACPI_SBS_CLASS);
649-
device->driver_data = sbs;
650653

651654
result = acpi_charger_add(sbs);
652655
if (result && result != -ENODEV)
@@ -670,20 +673,15 @@ static int acpi_sbs_add(struct acpi_device *device)
670673
acpi_smbus_register_callback(sbs->hc, acpi_sbs_callback, sbs);
671674
end:
672675
if (result)
673-
acpi_sbs_remove(device);
676+
acpi_sbs_remove(pdev);
674677
return result;
675678
}
676679

677-
static void acpi_sbs_remove(struct acpi_device *device)
680+
static void acpi_sbs_remove(struct platform_device *pdev)
678681
{
679-
struct acpi_sbs *sbs;
682+
struct acpi_sbs *sbs = platform_get_drvdata(pdev);
680683
int id;
681684

682-
if (!device)
683-
return;
684-
sbs = acpi_driver_data(device);
685-
if (!sbs)
686-
return;
687685
mutex_lock(&sbs->lock);
688686
acpi_smbus_unregister_callback(sbs->hc);
689687
for (id = 0; id < MAX_SBS_BAT; ++id)
@@ -697,11 +695,7 @@ static void acpi_sbs_remove(struct acpi_device *device)
697695
#ifdef CONFIG_PM_SLEEP
698696
static int acpi_sbs_resume(struct device *dev)
699697
{
700-
struct acpi_sbs *sbs;
701-
if (!dev)
702-
return -EINVAL;
703-
sbs = to_acpi_device(dev)->driver_data;
704-
acpi_sbs_callback(sbs);
698+
acpi_sbs_callback(dev_get_drvdata(dev));
705699
return 0;
706700
}
707701
#else
@@ -710,14 +704,14 @@ static int acpi_sbs_resume(struct device *dev)
710704

711705
static SIMPLE_DEV_PM_OPS(acpi_sbs_pm, NULL, acpi_sbs_resume);
712706

713-
static struct acpi_driver acpi_sbs_driver = {
714-
.name = "sbs",
715-
.class = ACPI_SBS_CLASS,
716-
.ids = sbs_device_ids,
717-
.ops = {
718-
.add = acpi_sbs_add,
719-
.remove = acpi_sbs_remove,
720-
},
721-
.drv.pm = &acpi_sbs_pm,
707+
static struct platform_driver acpi_sbs_driver = {
708+
.probe = acpi_sbs_probe,
709+
.remove = acpi_sbs_remove,
710+
.driver = {
711+
.name = "acpi-sbs",
712+
.acpi_match_table = sbs_device_ids,
713+
.pm = &acpi_sbs_pm,
714+
},
722715
};
723-
module_acpi_driver(acpi_sbs_driver);
716+
717+
module_platform_driver(acpi_sbs_driver);

drivers/acpi/sbshc.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,6 @@ static int acpi_smbus_hc_probe(struct platform_device *pdev)
265265
hc->ec = dev_get_drvdata(pdev->dev.parent);
266266
hc->offset = (val >> 8) & 0xff;
267267
hc->query_bit = val & 0xff;
268-
/* This is needed for the SBS driver to work. */
269-
device->driver_data = hc;
270268

271269
acpi_ec_add_query_handler(hc->ec, hc->query_bit, NULL, smbus_alarm, hc);
272270
dev_info(&device->dev, "SBS HC: offset = 0x%0x, query_bit = 0x%0x\n",

0 commit comments

Comments
 (0)