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.

platform/x86: system76: Convert ACPI driver to a platform one

In all cases in which a struct acpi_driver is used for binding a driver
to an ACPI device object, a corresponding platform device is created by
the ACPI core and that device is regarded as a proper representation of
underlying hardware. Accordingly, a struct platform_driver should be
used by driver code to bind to that device. There are multiple reasons
why drivers should not bind directly to ACPI device objects [1].

Overall, it is better to bind drivers to platform devices than to their
ACPI companions, so convert the System76 ACPI driver to a platform one.

After this change, the subordinate hwmon, input and LED class devices
will be registered under the platform device used for driver binding
instead of its ACPI companion.

While this is not expected to alter functionality, it changes sysfs
layout and so it will be visible to user space.

Link: https://lore.kernel.org/all/2396510.ElGaqSPkdT@rafael.j.wysocki/ [1]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://patch.msgid.link/3401648.aeNJFYEL58@rafael.j.wysocki
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

authored by

Rafael J. Wysocki and committed by
Ilpo Järvinen
80b8f68b 89729c9c

+25 -23
+25 -23
drivers/platform/x86/system76_acpi.c
··· 18 18 #include <linux/leds.h> 19 19 #include <linux/module.h> 20 20 #include <linux/pci_ids.h> 21 + #include <linux/platform_device.h> 21 22 #include <linux/power_supply.h> 22 23 #include <linux/sysfs.h> 23 24 #include <linux/types.h> ··· 671 670 } 672 671 } 673 672 674 - // Add a System76 ACPI device 675 - static int system76_add(struct acpi_device *acpi_dev) 673 + // Probe a System76 platform device 674 + static int system76_probe(struct platform_device *pdev) 676 675 { 676 + struct acpi_device *acpi_dev = ACPI_COMPANION(&pdev->dev); 677 677 struct system76_data *data; 678 678 int err; 679 679 680 - data = devm_kzalloc(&acpi_dev->dev, sizeof(*data), GFP_KERNEL); 680 + data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); 681 681 if (!data) 682 682 return -ENOMEM; 683 - acpi_dev->driver_data = data; 683 + 684 + platform_set_drvdata(pdev, data); 685 + 684 686 data->acpi_dev = acpi_dev; 685 687 686 688 // Some models do not run open EC firmware. Check for an ACPI method ··· 699 695 data->ap_led.brightness_set_blocking = ap_led_set; 700 696 data->ap_led.max_brightness = 1; 701 697 data->ap_led.default_trigger = "rfkill-none"; 702 - err = devm_led_classdev_register(&acpi_dev->dev, &data->ap_led); 698 + err = devm_led_classdev_register(&pdev->dev, &data->ap_led); 703 699 if (err) 704 700 return err; 705 701 ··· 743 739 } 744 740 745 741 if (data->kbled_type != KBLED_NONE) { 746 - err = devm_led_classdev_register(&acpi_dev->dev, &data->kb_led); 742 + err = devm_led_classdev_register(&pdev->dev, &data->kb_led); 747 743 if (err) 748 744 return err; 749 745 } 750 746 751 - data->input = devm_input_allocate_device(&acpi_dev->dev); 747 + data->input = devm_input_allocate_device(&pdev->dev); 752 748 if (!data->input) 753 749 return -ENOMEM; 754 750 755 751 data->input->name = "System76 ACPI Hotkeys"; 756 752 data->input->phys = "system76_acpi/input0"; 757 753 data->input->id.bustype = BUS_HOST; 758 - data->input->dev.parent = &acpi_dev->dev; 754 + data->input->dev.parent = &pdev->dev; 759 755 input_set_capability(data->input, EV_KEY, KEY_SCREENLOCK); 760 756 761 757 err = input_register_device(data->input); ··· 776 772 if (err) 777 773 goto error; 778 774 779 - data->therm = devm_hwmon_device_register_with_info(&acpi_dev->dev, 775 + data->therm = devm_hwmon_device_register_with_info(&pdev->dev, 780 776 "system76_acpi", data, &thermal_chip_info, NULL); 781 777 err = PTR_ERR_OR_ZERO(data->therm); 782 778 if (err) ··· 796 792 return err; 797 793 } 798 794 799 - // Remove a System76 ACPI device 800 - static void system76_remove(struct acpi_device *acpi_dev) 795 + // Remove a System76 platform device 796 + static void system76_remove(struct platform_device *pdev) 801 797 { 802 - struct system76_data *data; 803 - 804 - data = acpi_driver_data(acpi_dev); 798 + struct system76_data *data = platform_get_drvdata(pdev); 805 799 806 800 if (data->has_open_ec) { 807 801 system76_battery_exit(); ··· 807 805 kfree(data->ntmp); 808 806 } 809 807 810 - acpi_dev_remove_notify_handler(acpi_dev, ACPI_DEVICE_NOTIFY, system76_notify); 808 + acpi_dev_remove_notify_handler(ACPI_COMPANION(&pdev->dev), 809 + ACPI_DEVICE_NOTIFY, system76_notify); 811 810 812 811 system76_get(data, "FINI"); 813 812 } 814 813 815 - static struct acpi_driver system76_driver = { 816 - .name = "System76 ACPI Driver", 817 - .class = "hotkey", 818 - .ids = device_ids, 819 - .ops = { 820 - .add = system76_add, 821 - .remove = system76_remove, 814 + static struct platform_driver system76_driver = { 815 + .probe = system76_probe, 816 + .remove = system76_remove, 817 + .driver = { 818 + .name = "System76 ACPI Driver", 819 + .acpi_match_table = device_ids, 822 820 }, 823 821 }; 824 - module_acpi_driver(system76_driver); 822 + module_platform_driver(system76_driver); 825 823 826 824 MODULE_DESCRIPTION("System76 ACPI Driver"); 827 825 MODULE_AUTHOR("Jeremy Soller <jeremy@system76.com>");