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: asus-laptop: 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 Asus laptop ACPI 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.

Link: https://lore.kernel.org/all/2396510.ElGaqSPkdT@rafael.j.wysocki/ [1]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Denis Benato <denis.benato@linux.dev>
Link: https://patch.msgid.link/2402539.ElGaqSPkdT@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
ba19eb10 378500dc

+18 -17
+18 -17
drivers/platform/x86/asus-laptop.c
··· 1824 1824 1825 1825 static bool asus_device_present; 1826 1826 1827 - static int asus_acpi_add(struct acpi_device *device) 1827 + static int asus_acpi_probe(struct platform_device *pdev) 1828 1828 { 1829 + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 1829 1830 struct asus_laptop *asus; 1830 1831 int result; 1831 1832 ··· 1838 1837 asus->handle = device->handle; 1839 1838 strscpy(acpi_device_name(device), ASUS_LAPTOP_DEVICE_NAME); 1840 1839 strscpy(acpi_device_class(device), ASUS_LAPTOP_CLASS); 1841 - device->driver_data = asus; 1842 1840 asus->device = device; 1843 1841 1844 1842 asus_dmi_check(); ··· 1845 1845 result = asus_acpi_init(asus); 1846 1846 if (result) 1847 1847 goto fail_platform; 1848 + 1849 + platform_set_drvdata(pdev, asus); 1848 1850 1849 1851 /* 1850 1852 * Need platform type detection first, then the platform ··· 1909 1907 return result; 1910 1908 } 1911 1909 1912 - static void asus_acpi_remove(struct acpi_device *device) 1910 + static void asus_acpi_remove(struct platform_device *pdev) 1913 1911 { 1914 - struct asus_laptop *asus = acpi_driver_data(device); 1912 + struct asus_laptop *asus = platform_get_drvdata(pdev); 1915 1913 1916 - acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY, asus_acpi_notify); 1914 + acpi_dev_remove_notify_handler(asus->device, ACPI_DEVICE_NOTIFY, 1915 + asus_acpi_notify); 1917 1916 asus_backlight_exit(asus); 1918 1917 asus_rfkill_exit(asus); 1919 1918 asus_led_exit(asus); ··· 1933 1930 }; 1934 1931 MODULE_DEVICE_TABLE(acpi, asus_device_ids); 1935 1932 1936 - static struct acpi_driver asus_acpi_driver = { 1937 - .name = ASUS_LAPTOP_NAME, 1938 - .class = ASUS_LAPTOP_CLASS, 1939 - .ids = asus_device_ids, 1940 - .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS, 1941 - .ops = { 1942 - .add = asus_acpi_add, 1943 - .remove = asus_acpi_remove, 1944 - }, 1933 + static struct platform_driver asus_acpi_driver = { 1934 + .probe = asus_acpi_probe, 1935 + .remove = asus_acpi_remove, 1936 + .driver = { 1937 + .name = ASUS_LAPTOP_NAME, 1938 + .acpi_match_table = asus_device_ids, 1939 + }, 1945 1940 }; 1946 1941 1947 1942 static int __init asus_laptop_init(void) ··· 1950 1949 if (result < 0) 1951 1950 return result; 1952 1951 1953 - result = acpi_bus_register_driver(&asus_acpi_driver); 1952 + result = platform_driver_register(&asus_acpi_driver); 1954 1953 if (result < 0) 1955 1954 goto fail_acpi_driver; 1956 1955 if (!asus_device_present) { ··· 1960 1959 return 0; 1961 1960 1962 1961 fail_no_device: 1963 - acpi_bus_unregister_driver(&asus_acpi_driver); 1962 + platform_driver_unregister(&asus_acpi_driver); 1964 1963 fail_acpi_driver: 1965 1964 platform_driver_unregister(&platform_driver); 1966 1965 return result; ··· 1968 1967 1969 1968 static void __exit asus_laptop_exit(void) 1970 1969 { 1971 - acpi_bus_unregister_driver(&asus_acpi_driver); 1970 + platform_driver_unregister(&asus_acpi_driver); 1972 1971 platform_driver_unregister(&platform_driver); 1973 1972 } 1974 1973