Skip to content

Commit 03667e1

Browse files
committed
ACPI: NFIT: core: 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 NFIT core 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. This change was mostly developed by Michal Wilczynski [1]. Linu: https://lore.kernel.org/linux-acpi/20231011083334.3987477-6-michal.wilczynski@intel.com/ [1] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Link: https://patch.msgid.link/6221453.lOV4Wx5bFT@rafael.j.wysocki Acked-by: Ira Weiny <ira.weiny@intel.com> Tested-by: Ira Weiny <ira.weiny@intel.com>
1 parent 3ad5df2 commit 03667e1

1 file changed

Lines changed: 28 additions & 19 deletions

File tree

drivers/acpi/nfit/core.c

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/*
33
* Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
44
*/
5+
#include <linux/platform_device.h>
56
#include <linux/list_sort.h>
67
#include <linux/libnvdimm.h>
78
#include <linux/module.h>
@@ -89,15 +90,22 @@ static const guid_t *to_nfit_bus_uuid(int family)
8990
static struct acpi_device *to_acpi_dev(struct acpi_nfit_desc *acpi_desc)
9091
{
9192
struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc;
93+
struct acpi_device *adev;
9294

93-
/*
94-
* If provider == 'ACPI.NFIT' we can assume 'dev' is a struct
95-
* acpi_device.
96-
*/
95+
/* If provider == 'ACPI.NFIT', a struct acpi_device is there. */
9796
if (!nd_desc->provider_name
9897
|| strcmp(nd_desc->provider_name, "ACPI.NFIT") != 0)
9998
return NULL;
10099

100+
/*
101+
* But it can be the ACPI companion of acpi_desc->dev when it cones from
102+
* acpi_nfit_probe().
103+
*/
104+
adev = ACPI_COMPANION(acpi_desc->dev);
105+
if (adev)
106+
return adev;
107+
108+
/* Or it is acpi_desc->dev itself when it comes from nfit_ctl_test(). */
101109
return to_acpi_device(acpi_desc->dev);
102110
}
103111

@@ -3283,11 +3291,11 @@ static void acpi_nfit_put_table(void *table)
32833291

32843292
static void acpi_nfit_notify(acpi_handle handle, u32 event, void *data)
32853293
{
3286-
struct acpi_device *adev = data;
3294+
struct device *dev = data;
32873295

3288-
device_lock(&adev->dev);
3289-
__acpi_nfit_notify(&adev->dev, handle, event);
3290-
device_unlock(&adev->dev);
3296+
device_lock(dev);
3297+
__acpi_nfit_notify(dev, handle, event);
3298+
device_unlock(dev);
32913299
}
32923300

32933301
static void acpi_nfit_remove_notify_handler(void *data)
@@ -3328,18 +3336,19 @@ void acpi_nfit_shutdown(void *data)
33283336
}
33293337
EXPORT_SYMBOL_GPL(acpi_nfit_shutdown);
33303338

3331-
static int acpi_nfit_add(struct acpi_device *adev)
3339+
static int acpi_nfit_probe(struct platform_device *pdev)
33323340
{
33333341
struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL };
33343342
struct acpi_nfit_desc *acpi_desc;
3335-
struct device *dev = &adev->dev;
3343+
struct device *dev = &pdev->dev;
3344+
struct acpi_device *adev = ACPI_COMPANION(dev);
33363345
struct acpi_table_header *tbl;
33373346
acpi_status status = AE_OK;
33383347
acpi_size sz;
33393348
int rc = 0;
33403349

33413350
rc = acpi_dev_install_notify_handler(adev, ACPI_DEVICE_NOTIFY,
3342-
acpi_nfit_notify, adev);
3351+
acpi_nfit_notify, dev);
33433352
if (rc)
33443353
return rc;
33453354

@@ -3369,7 +3378,7 @@ static int acpi_nfit_add(struct acpi_device *adev)
33693378
acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL);
33703379
if (!acpi_desc)
33713380
return -ENOMEM;
3372-
acpi_nfit_desc_init(acpi_desc, &adev->dev);
3381+
acpi_nfit_desc_init(acpi_desc, dev);
33733382

33743383
/* Save the acpi header for exporting the revision via sysfs */
33753384
acpi_desc->acpi_header = *tbl;
@@ -3474,11 +3483,11 @@ static const struct acpi_device_id acpi_nfit_ids[] = {
34743483
};
34753484
MODULE_DEVICE_TABLE(acpi, acpi_nfit_ids);
34763485

3477-
static struct acpi_driver acpi_nfit_driver = {
3478-
.name = KBUILD_MODNAME,
3479-
.ids = acpi_nfit_ids,
3480-
.ops = {
3481-
.add = acpi_nfit_add,
3486+
static struct platform_driver acpi_nfit_driver = {
3487+
.probe = acpi_nfit_probe,
3488+
.driver = {
3489+
.name = "acpi-nfit",
3490+
.acpi_match_table = acpi_nfit_ids,
34823491
},
34833492
};
34843493

@@ -3516,7 +3525,7 @@ static __init int nfit_init(void)
35163525
return -ENOMEM;
35173526

35183527
nfit_mce_register();
3519-
ret = acpi_bus_register_driver(&acpi_nfit_driver);
3528+
ret = platform_driver_register(&acpi_nfit_driver);
35203529
if (ret) {
35213530
nfit_mce_unregister();
35223531
destroy_workqueue(nfit_wq);
@@ -3529,7 +3538,7 @@ static __init int nfit_init(void)
35293538
static __exit void nfit_exit(void)
35303539
{
35313540
nfit_mce_unregister();
3532-
acpi_bus_unregister_driver(&acpi_nfit_driver);
3541+
platform_driver_unregister(&acpi_nfit_driver);
35333542
destroy_workqueue(nfit_wq);
35343543
WARN_ON(!list_empty(&acpi_descs));
35353544
}

0 commit comments

Comments
 (0)