Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+21 -24
-2
drivers/acpi/ec.c
··· 1733 1733 "EC: Used to handle transactions and events\n"); 1734 1734 1735 1735 platform_set_drvdata(pdev, ec); 1736 - /* This is needed for the SMBUS HC driver to work. */ 1737 - device->driver_data = ec; 1738 1736 1739 1737 ret = !!request_region(ec->data_addr, 1, "EC data"); 1740 1738 WARN(!ret, "Could not request EC data io port 0x%lx", ec->data_addr);
+21 -22
drivers/acpi/sbshc.c
··· 13 13 #include <linux/delay.h> 14 14 #include <linux/module.h> 15 15 #include <linux/interrupt.h> 16 + #include <linux/platform_device.h> 17 + 16 18 #include "sbshc.h" 17 19 #include "internal.h" 18 20 ··· 32 30 bool done; 33 31 }; 34 32 35 - static int acpi_smbus_hc_add(struct acpi_device *device); 36 - static void acpi_smbus_hc_remove(struct acpi_device *device); 33 + static int acpi_smbus_hc_probe(struct platform_device *pdev); 34 + static void acpi_smbus_hc_remove(struct platform_device *pdev); 37 35 38 36 static const struct acpi_device_id sbs_device_ids[] = { 39 37 {"ACPI0001", 0}, ··· 43 41 44 42 MODULE_DEVICE_TABLE(acpi, sbs_device_ids); 45 43 46 - static struct acpi_driver acpi_smb_hc_driver = { 47 - .name = "smbus_hc", 48 - .class = ACPI_SMB_HC_CLASS, 49 - .ids = sbs_device_ids, 50 - .ops = { 51 - .add = acpi_smbus_hc_add, 52 - .remove = acpi_smbus_hc_remove, 53 - }, 44 + static struct platform_driver acpi_smb_hc_driver = { 45 + .probe = acpi_smbus_hc_probe, 46 + .remove = acpi_smbus_hc_remove, 47 + .driver = { 48 + .name = "acpi-smbus-hc", 49 + .acpi_match_table = sbs_device_ids, 50 + }, 54 51 }; 55 52 56 53 union acpi_smb_status { ··· 238 237 return 0; 239 238 } 240 239 241 - static int acpi_smbus_hc_add(struct acpi_device *device) 240 + static int acpi_smbus_hc_probe(struct platform_device *pdev) 242 241 { 242 + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 243 243 int status; 244 244 unsigned long long val; 245 245 struct acpi_smb_hc *hc; 246 - 247 - if (!device) 248 - return -EINVAL; 249 246 250 247 status = acpi_evaluate_integer(device->handle, "_EC", NULL, &val); 251 248 if (ACPI_FAILURE(status)) { ··· 260 261 mutex_init(&hc->lock); 261 262 init_waitqueue_head(&hc->wait); 262 263 263 - hc->ec = acpi_driver_data(acpi_dev_parent(device)); 264 + platform_set_drvdata(pdev, hc); 265 + 266 + hc->ec = dev_get_drvdata(pdev->dev.parent); 264 267 hc->offset = (val >> 8) & 0xff; 265 268 hc->query_bit = val & 0xff; 269 + /* This is needed for the SBS driver to work. */ 266 270 device->driver_data = hc; 267 271 268 272 acpi_ec_add_query_handler(hc->ec, hc->query_bit, NULL, smbus_alarm, hc); ··· 275 273 return 0; 276 274 } 277 275 278 - static void acpi_smbus_hc_remove(struct acpi_device *device) 276 + static void acpi_smbus_hc_remove(struct platform_device *pdev) 279 277 { 280 - struct acpi_smb_hc *hc; 278 + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 279 + struct acpi_smb_hc *hc = platform_get_drvdata(pdev); 281 280 282 - if (!device) 283 - return; 284 - 285 - hc = acpi_driver_data(device); 286 281 acpi_ec_remove_query_handler(hc->ec, hc->query_bit); 287 282 acpi_os_wait_events_complete(); 288 283 kfree(hc); 289 284 device->driver_data = NULL; 290 285 } 291 286 292 - module_acpi_driver(acpi_smb_hc_driver); 287 + module_platform_driver(acpi_smb_hc_driver); 293 288 294 289 MODULE_LICENSE("GPL"); 295 290 MODULE_AUTHOR("Alexey Starikovskiy");