Skip to content

Commit d1db160

Browse files
committed
ACPI: thermal: 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 thermal zone 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. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Tested-by: lihuisong@huawei.com Link: https://patch.msgid.link/2249483.irdbgypaU6@rafael.j.wysocki
1 parent a497538 commit d1db160

1 file changed

Lines changed: 19 additions & 29 deletions

File tree

drivers/acpi/thermal.c

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <linux/kmod.h>
2626
#include <linux/reboot.h>
2727
#include <linux/device.h>
28+
#include <linux/platform_device.h>
2829
#include <linux/thermal.h>
2930
#include <linux/acpi.h>
3031
#include <linux/workqueue.h>
@@ -776,9 +777,10 @@ static void acpi_thermal_free_thermal_zone(struct acpi_thermal *tz)
776777
kfree(tz);
777778
}
778779

779-
static int acpi_thermal_add(struct acpi_device *device)
780+
static int acpi_thermal_probe(struct platform_device *pdev)
780781
{
781782
struct thermal_trip trip_table[ACPI_THERMAL_MAX_NR_TRIPS] = { 0 };
783+
struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
782784
struct acpi_thermal_trip *acpi_trip;
783785
struct thermal_trip *trip;
784786
struct acpi_thermal *tz;
@@ -794,11 +796,12 @@ static int acpi_thermal_add(struct acpi_device *device)
794796
if (!tz)
795797
return -ENOMEM;
796798

799+
platform_set_drvdata(pdev, tz);
800+
797801
tz->device = device;
798802
strscpy(tz->name, device->pnp.bus_id);
799803
strscpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
800804
strscpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
801-
device->driver_data = tz;
802805

803806
acpi_thermal_aml_dependency_fix(tz);
804807

@@ -895,16 +898,11 @@ static int acpi_thermal_add(struct acpi_device *device)
895898
return result;
896899
}
897900

898-
static void acpi_thermal_remove(struct acpi_device *device)
901+
static void acpi_thermal_remove(struct platform_device *pdev)
899902
{
900-
struct acpi_thermal *tz;
901-
902-
if (!device || !acpi_driver_data(device))
903-
return;
903+
struct acpi_thermal *tz = platform_get_drvdata(pdev);
904904

905-
tz = acpi_driver_data(device);
906-
907-
acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY,
905+
acpi_dev_remove_notify_handler(tz->device, ACPI_DEVICE_NOTIFY,
908906
acpi_thermal_notify);
909907

910908
flush_workqueue(acpi_thermal_pm_queue);
@@ -922,16 +920,9 @@ static int acpi_thermal_suspend(struct device *dev)
922920

923921
static int acpi_thermal_resume(struct device *dev)
924922
{
925-
struct acpi_thermal *tz;
923+
struct acpi_thermal *tz = dev_get_drvdata(dev);
926924
int i, j;
927925

928-
if (!dev)
929-
return -EINVAL;
930-
931-
tz = acpi_driver_data(to_acpi_device(dev));
932-
if (!tz)
933-
return -EINVAL;
934-
935926
for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
936927
struct acpi_thermal_trip *acpi_trip = &tz->trips.active[i].trip;
937928

@@ -958,15 +949,14 @@ static const struct acpi_device_id thermal_device_ids[] = {
958949
};
959950
MODULE_DEVICE_TABLE(acpi, thermal_device_ids);
960951

961-
static struct acpi_driver acpi_thermal_driver = {
962-
.name = "thermal",
963-
.class = ACPI_THERMAL_CLASS,
964-
.ids = thermal_device_ids,
965-
.ops = {
966-
.add = acpi_thermal_add,
967-
.remove = acpi_thermal_remove,
968-
},
969-
.drv.pm = &acpi_thermal_pm,
952+
static struct platform_driver acpi_thermal_driver = {
953+
.probe = acpi_thermal_probe,
954+
.remove = acpi_thermal_remove,
955+
.driver = {
956+
.name = "acpi-thermal",
957+
.acpi_match_table = thermal_device_ids,
958+
.pm = &acpi_thermal_pm,
959+
},
970960
};
971961

972962
static int thermal_act(const struct dmi_system_id *d)
@@ -1064,7 +1054,7 @@ static int __init acpi_thermal_init(void)
10641054
if (!acpi_thermal_pm_queue)
10651055
return -ENODEV;
10661056

1067-
result = acpi_bus_register_driver(&acpi_thermal_driver);
1057+
result = platform_driver_register(&acpi_thermal_driver);
10681058
if (result < 0) {
10691059
destroy_workqueue(acpi_thermal_pm_queue);
10701060
return -ENODEV;
@@ -1075,7 +1065,7 @@ static int __init acpi_thermal_init(void)
10751065

10761066
static void __exit acpi_thermal_exit(void)
10771067
{
1078-
acpi_bus_unregister_driver(&acpi_thermal_driver);
1068+
platform_driver_unregister(&acpi_thermal_driver);
10791069
destroy_workqueue(acpi_thermal_pm_queue);
10801070
}
10811071

0 commit comments

Comments
 (0)