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: 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

+21 -29
+21 -27
drivers/acpi/sbs.c
··· 19 19 #include <linux/timer.h> 20 20 #include <linux/jiffies.h> 21 21 #include <linux/delay.h> 22 + #include <linux/platform_device.h> 22 23 #include <linux/power_supply.h> 23 24 #include <linux/platform_data/x86/apple.h> 24 25 #include <acpi/battery.h> ··· 96 95 97 96 #define to_acpi_sbs(x) power_supply_get_drvdata(x) 98 97 99 - static void acpi_sbs_remove(struct acpi_device *device); 98 + static void acpi_sbs_remove(struct platform_device *pdev); 100 99 static int acpi_battery_get_state(struct acpi_battery *battery); 101 100 102 101 static inline int battery_scale(int log) ··· 629 628 } 630 629 } 631 630 632 - static int acpi_sbs_add(struct acpi_device *device) 631 + static int acpi_sbs_probe(struct platform_device *pdev) 633 632 { 633 + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 634 634 struct acpi_sbs *sbs; 635 635 int result = 0; 636 636 int id; ··· 644 642 645 643 mutex_init(&sbs->lock); 646 644 647 - sbs->hc = acpi_driver_data(acpi_dev_parent(device)); 645 + platform_set_drvdata(pdev, sbs); 646 + 647 + sbs->hc = dev_get_drvdata(pdev->dev.parent); 648 648 sbs->device = device; 649 649 strscpy(acpi_device_name(device), ACPI_SBS_DEVICE_NAME); 650 650 strscpy(acpi_device_class(device), ACPI_SBS_CLASS); 651 - device->driver_data = sbs; 652 651 653 652 result = acpi_charger_add(sbs); 654 653 if (result && result != -ENODEV) ··· 673 670 acpi_smbus_register_callback(sbs->hc, acpi_sbs_callback, sbs); 674 671 end: 675 672 if (result) 676 - acpi_sbs_remove(device); 673 + acpi_sbs_remove(pdev); 677 674 return result; 678 675 } 679 676 680 - static void acpi_sbs_remove(struct acpi_device *device) 677 + static void acpi_sbs_remove(struct platform_device *pdev) 681 678 { 682 - struct acpi_sbs *sbs; 679 + struct acpi_sbs *sbs = platform_get_drvdata(pdev); 683 680 int id; 684 681 685 - if (!device) 686 - return; 687 - sbs = acpi_driver_data(device); 688 - if (!sbs) 689 - return; 690 682 mutex_lock(&sbs->lock); 691 683 acpi_smbus_unregister_callback(sbs->hc); 692 684 for (id = 0; id < MAX_SBS_BAT; ++id) ··· 695 697 #ifdef CONFIG_PM_SLEEP 696 698 static int acpi_sbs_resume(struct device *dev) 697 699 { 698 - struct acpi_sbs *sbs; 699 - if (!dev) 700 - return -EINVAL; 701 - sbs = to_acpi_device(dev)->driver_data; 702 - acpi_sbs_callback(sbs); 700 + acpi_sbs_callback(dev_get_drvdata(dev)); 703 701 return 0; 704 702 } 705 703 #else ··· 704 710 705 711 static SIMPLE_DEV_PM_OPS(acpi_sbs_pm, NULL, acpi_sbs_resume); 706 712 707 - static struct acpi_driver acpi_sbs_driver = { 708 - .name = "sbs", 709 - .class = ACPI_SBS_CLASS, 710 - .ids = sbs_device_ids, 711 - .ops = { 712 - .add = acpi_sbs_add, 713 - .remove = acpi_sbs_remove, 714 - }, 715 - .drv.pm = &acpi_sbs_pm, 713 + static struct platform_driver acpi_sbs_driver = { 714 + .probe = acpi_sbs_probe, 715 + .remove = acpi_sbs_remove, 716 + .driver = { 717 + .name = "acpi-sbs", 718 + .acpi_match_table = sbs_device_ids, 719 + .pm = &acpi_sbs_pm, 720 + }, 716 721 }; 717 - module_acpi_driver(acpi_sbs_driver); 722 + 723 + module_platform_driver(acpi_sbs_driver);
-2
drivers/acpi/sbshc.c
··· 265 265 hc->ec = dev_get_drvdata(pdev->dev.parent); 266 266 hc->offset = (val >> 8) & 0xff; 267 267 hc->query_bit = val & 0xff; 268 - /* This is needed for the SBS driver to work. */ 269 - device->driver_data = hc; 270 268 271 269 acpi_ec_add_query_handler(hc->ec, hc->query_bit, NULL, smbus_alarm, hc); 272 270 dev_info(&device->dev, "SBS HC: offset = 0x%0x, query_bit = 0x%0x\n",