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.

Merge branch 'acpi-driver'

Merge updates of drivers handling devices defined in the ACPI
specification and other generic devices with ACPI interfaces for
6.20-rc1/7.0-rc1:

- Add a piece of documentation explaining why binding drivers directly
to ACPI device objects is not a good idea in general and why it is
desirable to convert drivers doing so into proper platform drivers
that use struct platform_driver for device binding (Rafael Wysocki)

- Convert multiple "core ACPI" drivers, including the NFIT ACPI device
driver, the generic ACPI button drivers, the generic ACPI thermal
zone driver, the ACPI hardware event device (HED) driver, the ACPI EC
driver, the ACPI SMBUS HC driver, the ACPI Smart Battery Subsystem
(SBS) driver, and the ACPI backlight (video) driver to proper platform
drivers that use struct platform_driver for device binding (Rafael
Wysocki)

- Use acpi_get_local_u64_address() in the ACPI backlight (video) driver
to evaluate _ADR instead of evaluating that object directly (Andy
Shevchenko)

* acpi-driver: (25 commits)
ACPI: video: simplify code with acpi_get_local_u64_address()
ACPI: scan: Clean up after recent changes
ACPI: scan: Use acpi_setup_gpe_for_wake() for buttons
ACPI: PM: Let acpi_dev_pm_attach() skip devices without ACPI PM
ACPI: Documentation: driver-api: Disapprove of using ACPI drivers
ACPI: video: Convert the driver to a platform one
ACPI: video: Adjust event notification routine
ACPI: scan: Register platform devices for backlight device objects
ACPI: SBS: Convert the driver to a platform one
ACPI: SMBUS HC: Convert the driver to a platform one
ACPI: EC: Convert the driver to a platform one
ACPI: EC: Register a platform device for ECDT EC
ACPI: HED: Convert the driver to a platform one
ACPI: thermal: Rework system suspend and resume handling
ACPI: thermal: Convert the driver to a platform one
ACPI: thermal: Adjust event notification routine
ACPI: scan: Register platform devices for thermal zones
ACPI: scan: Do not mark button ACPI devices as wakeup-capable
ACPI: scan: Do not bind ACPI drivers to fixed event buttons
ACPI: tiny-power-button: Convert the driver to a platform one
...

+383 -341
+80
Documentation/driver-api/acpi/acpi-drivers.rst
··· 1 + .. SPDX-License-Identifier: GPL-2.0 2 + .. include:: <isonum.txt> 3 + 4 + ========================================= 5 + Why using ACPI drivers is not a good idea 6 + ========================================= 7 + 8 + :Copyright: |copy| 2026, Intel Corporation 9 + 10 + :Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com> 11 + 12 + Even though binding drivers directly to struct acpi_device objects, also 13 + referred to as "ACPI device nodes", allows basic functionality to be provided 14 + at least in some cases, there are problems with it, related to general 15 + consistency, sysfs layout, power management operation ordering, and code 16 + cleanliness. 17 + 18 + First of all, ACPI device nodes represent firmware entities rather than 19 + hardware and in many cases they provide auxiliary information on devices 20 + enumerated independently (like PCI devices or CPUs). It is therefore generally 21 + questionable to assign resources to them because the entities represented by 22 + them do not decode addresses in the memory or I/O address spaces and do not 23 + generate interrupts or similar (all of that is done by hardware). 24 + 25 + Second, as a general rule, a struct acpi_device can only be a parent of another 26 + struct acpi_device. If that is not the case, the location of the child device 27 + in the device hierarchy is at least confusing and it may not be straightforward 28 + to identify the piece of hardware providing functionality represented by it. 29 + However, binding a driver directly to an ACPI device node may cause that to 30 + happen if the given driver registers input devices or wakeup sources under it, 31 + for example. 32 + 33 + Next, using system suspend and resume callbacks directly on ACPI device nodes 34 + is also questionable because it may cause ordering problems to appear. Namely, 35 + ACPI device nodes are registered before enumerating hardware corresponding to 36 + them and they land on the PM list in front of the majority of other device 37 + objects. Consequently, the execution ordering of their PM callbacks may be 38 + different from what is generally expected. Also, in general, dependencies 39 + returned by _DEP objects do not affect ACPI device nodes themselves, but the 40 + "physical" devices associated with them, which potentially is one more source 41 + of inconsistency related to treating ACPI device nodes as "real" device 42 + representation. 43 + 44 + All of the above means that binding drivers to ACPI device nodes should 45 + generally be avoided and so struct acpi_driver objects should not be used. 46 + 47 + Moreover, a device ID is necessary to bind a driver directly to an ACPI device 48 + node, but device IDs are not generally associated with all of them. Some of 49 + them contain alternative information allowing the corresponding pieces of 50 + hardware to be identified, for example represeted by an _ADR object return 51 + value, and device IDs are not used in those cases. In consequence, confusingly 52 + enough, binding an ACPI driver to an ACPI device node may even be impossible. 53 + 54 + When that happens, the piece of hardware corresponding to the given ACPI device 55 + node is represented by another device object, like a struct pci_dev, and the 56 + ACPI device node is the "ACPI companion" of that device, accessible through its 57 + fwnode pointer used by the ACPI_COMPANION() macro. The ACPI companion holds 58 + additional information on the device configuration and possibly some "recipes" 59 + on device manipulation in the form of AML (ACPI Machine Language) bytecode 60 + provided by the platform firmware. Thus the role of the ACPI device node is 61 + similar to the role of a struct device_node on a system where Device Tree is 62 + used for platform description. 63 + 64 + For consistency, this approach has been extended to the cases in which ACPI 65 + device IDs are used. Namely, in those cases, an additional device object is 66 + created to represent the piece of hardware corresponding to a given ACPI device 67 + node. By default, it is a platform device, but it may also be a PNP device, a 68 + CPU device, or another type of device, depending on what the given piece of 69 + hardware actually is. There are even cases in which multiple devices are 70 + "backed" or "accompanied" by one ACPI device node (e.g. ACPI device nodes 71 + corresponding to GPUs that may provide firmware interfaces for backlight 72 + brightness control in addition to GPU configuration information). 73 + 74 + This means that it really should never be necessary to bind a driver directly to 75 + an ACPI device node because there is a "proper" device object representing the 76 + corresponding piece of hardware that can be bound to by a "proper" driver using 77 + the given ACPI device node as the device's ACPI companion. Thus, in principle, 78 + there is no reason to use ACPI drivers and if they all were replaced with other 79 + driver types (for example, platform drivers), some code could be dropped and 80 + some complexity would go away.
+1
Documentation/driver-api/acpi/index.rst
··· 7 7 8 8 linuxized-acpica 9 9 scan_handlers 10 + acpi-drivers
+23 -19
drivers/acpi/acpi_platform.c
··· 114 114 struct platform_device *pdev = NULL; 115 115 struct platform_device_info pdevinfo; 116 116 const struct acpi_device_id *match; 117 - struct resource_entry *rentry; 118 - struct list_head resource_list; 119 117 struct resource *resources = NULL; 120 - int count; 118 + int count = 0; 121 119 122 120 /* If the ACPI node already has a physical device attached, skip it. */ 123 - if (adev->physical_node_count) 121 + if (adev->physical_node_count && !adev->pnp.type.backlight) 124 122 return NULL; 125 123 126 124 match = acpi_match_acpi_device(forbidden_id_list, adev); ··· 135 137 } 136 138 } 137 139 138 - INIT_LIST_HEAD(&resource_list); 139 - count = acpi_dev_get_resources(adev, &resource_list, NULL, NULL); 140 - if (count < 0) 141 - return NULL; 142 - if (count > 0) { 143 - resources = kcalloc(count, sizeof(*resources), GFP_KERNEL); 144 - if (!resources) { 145 - acpi_dev_free_resource_list(&resource_list); 146 - return ERR_PTR(-ENOMEM); 147 - } 148 - count = 0; 149 - list_for_each_entry(rentry, &resource_list, node) 150 - acpi_platform_fill_resource(adev, rentry->res, 151 - &resources[count++]); 140 + if (adev->device_type == ACPI_BUS_TYPE_DEVICE && !adev->pnp.type.backlight) { 141 + LIST_HEAD(resource_list); 152 142 153 - acpi_dev_free_resource_list(&resource_list); 143 + count = acpi_dev_get_resources(adev, &resource_list, NULL, NULL); 144 + if (count < 0) 145 + return ERR_PTR(-ENODATA); 146 + 147 + if (count > 0) { 148 + struct resource_entry *rentry; 149 + 150 + resources = kcalloc(count, sizeof(*resources), GFP_KERNEL); 151 + if (!resources) { 152 + acpi_dev_free_resource_list(&resource_list); 153 + return ERR_PTR(-ENOMEM); 154 + } 155 + count = 0; 156 + list_for_each_entry(rentry, &resource_list, node) 157 + acpi_platform_fill_resource(adev, rentry->res, 158 + &resources[count++]); 159 + 160 + acpi_dev_free_resource_list(&resource_list); 161 + } 154 162 } 155 163 156 164 memset(&pdevinfo, 0, sizeof(pdevinfo));
+28 -34
drivers/acpi/acpi_video.c
··· 21 21 #include <linux/sort.h> 22 22 #include <linux/pci.h> 23 23 #include <linux/pci_ids.h> 24 + #include <linux/platform_device.h> 24 25 #include <linux/slab.h> 25 26 #include <linux/dmi.h> 26 27 #include <linux/suspend.h> ··· 77 76 static DEFINE_MUTEX(register_count_mutex); 78 77 static DEFINE_MUTEX(video_list_lock); 79 78 static LIST_HEAD(video_bus_head); 80 - static int acpi_video_bus_add(struct acpi_device *device); 81 - static void acpi_video_bus_remove(struct acpi_device *device); 79 + static int acpi_video_bus_probe(struct platform_device *pdev); 80 + static void acpi_video_bus_remove(struct platform_device *pdev); 82 81 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data); 83 82 84 83 /* ··· 99 98 }; 100 99 MODULE_DEVICE_TABLE(acpi, video_device_ids); 101 100 102 - static struct acpi_driver acpi_video_bus = { 103 - .name = "video", 104 - .class = ACPI_VIDEO_CLASS, 105 - .ids = video_device_ids, 106 - .ops = { 107 - .add = acpi_video_bus_add, 108 - .remove = acpi_video_bus_remove, 109 - }, 101 + static struct platform_driver acpi_video_bus = { 102 + .probe = acpi_video_bus_probe, 103 + .remove = acpi_video_bus_remove, 104 + .driver = { 105 + .name = "acpi-video", 106 + .acpi_match_table = video_device_ids, 107 + }, 110 108 }; 111 109 112 110 struct acpi_video_bus_flags { ··· 1134 1134 struct acpi_video_bus *video = arg; 1135 1135 struct acpi_video_device_attrib *attribute; 1136 1136 struct acpi_video_device *data; 1137 - unsigned long long device_id; 1138 - acpi_status status; 1139 1137 int device_type; 1138 + u64 device_id; 1140 1139 1141 - status = acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id); 1142 1140 /* Skip devices without _ADR instead of failing. */ 1143 - if (ACPI_FAILURE(status)) 1141 + if (acpi_get_local_u64_address(device->handle, &device_id)) 1144 1142 goto exit; 1145 1143 1146 1144 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL); ··· 1538 1540 1539 1541 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data) 1540 1542 { 1541 - struct acpi_device *device = data; 1542 - struct acpi_video_bus *video = acpi_driver_data(device); 1543 + struct acpi_video_bus *video = data; 1544 + struct acpi_device *device = video->device; 1543 1545 struct input_dev *input; 1544 1546 int keycode = 0; 1545 - 1546 - if (!video || !video->input) 1547 - return; 1548 1547 1549 1548 input = video->input; 1550 1549 ··· 1886 1891 device->flags.notify = 1; 1887 1892 } 1888 1893 1889 - static int acpi_video_bus_add_notify_handler(struct acpi_video_bus *video) 1894 + static int acpi_video_bus_add_notify_handler(struct acpi_video_bus *video, 1895 + struct platform_device *pdev) 1890 1896 { 1891 1897 struct input_dev *input; 1892 1898 struct acpi_video_device *dev; ··· 1910 1914 input->phys = video->phys; 1911 1915 input->id.bustype = BUS_HOST; 1912 1916 input->id.product = 0x06; 1913 - input->dev.parent = &video->device->dev; 1917 + input->dev.parent = &pdev->dev; 1914 1918 input->evbit[0] = BIT(EV_KEY); 1915 1919 set_bit(KEY_SWITCHVIDEOMODE, input->keybit); 1916 1920 set_bit(KEY_VIDEO_NEXT, input->keybit); ··· 1982 1986 1983 1987 static int instance; 1984 1988 1985 - static int acpi_video_bus_add(struct acpi_device *device) 1989 + static int acpi_video_bus_probe(struct platform_device *pdev) 1986 1990 { 1991 + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 1987 1992 struct acpi_video_bus *video; 1988 1993 bool auto_detect; 1989 1994 int error; ··· 2020 2023 device->pnp.bus_id[3] = '0' + instance; 2021 2024 instance++; 2022 2025 } 2026 + 2027 + platform_set_drvdata(pdev, video); 2023 2028 2024 2029 video->device = device; 2025 2030 strscpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME); ··· 2070 2071 !auto_detect) 2071 2072 acpi_video_bus_register_backlight(video); 2072 2073 2073 - error = acpi_video_bus_add_notify_handler(video); 2074 + error = acpi_video_bus_add_notify_handler(video, pdev); 2074 2075 if (error) 2075 2076 goto err_del; 2076 2077 2077 2078 error = acpi_dev_install_notify_handler(device, ACPI_DEVICE_NOTIFY, 2078 - acpi_video_bus_notify, device); 2079 + acpi_video_bus_notify, video); 2079 2080 if (error) 2080 2081 goto err_remove; 2081 2082 ··· 2098 2099 return error; 2099 2100 } 2100 2101 2101 - static void acpi_video_bus_remove(struct acpi_device *device) 2102 + static void acpi_video_bus_remove(struct platform_device *pdev) 2102 2103 { 2103 - struct acpi_video_bus *video = NULL; 2104 - 2105 - 2106 - if (!device || !acpi_driver_data(device)) 2107 - return; 2108 - 2109 - video = acpi_driver_data(device); 2104 + struct acpi_video_bus *video = platform_get_drvdata(pdev); 2105 + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 2110 2106 2111 2107 acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY, 2112 2108 acpi_video_bus_notify); ··· 2164 2170 2165 2171 dmi_check_system(video_dmi_table); 2166 2172 2167 - ret = acpi_bus_register_driver(&acpi_video_bus); 2173 + ret = platform_driver_register(&acpi_video_bus); 2168 2174 if (ret) 2169 2175 goto leave; 2170 2176 ··· 2184 2190 { 2185 2191 mutex_lock(&register_count_mutex); 2186 2192 if (register_count) { 2187 - acpi_bus_unregister_driver(&acpi_video_bus); 2193 + platform_driver_unregister(&acpi_video_bus); 2188 2194 register_count = 0; 2189 2195 may_report_brightness_keys = false; 2190 2196 }
+3
drivers/acpi/bus.c
··· 818 818 if (list_empty(&adev->pnp.ids)) 819 819 return NULL; 820 820 821 + if (adev->pnp.type.backlight) 822 + return adev; 823 + 821 824 return acpi_primary_dev_companion(adev, dev); 822 825 } 823 826
+65 -63
drivers/acpi/button.c
··· 19 19 #include <linux/slab.h> 20 20 #include <linux/acpi.h> 21 21 #include <linux/dmi.h> 22 + #include <linux/platform_device.h> 22 23 #include <acpi/button.h> 23 24 24 25 #define ACPI_BUTTON_CLASS "button" ··· 146 145 {} 147 146 }; 148 147 149 - static int acpi_button_add(struct acpi_device *device); 150 - static void acpi_button_remove(struct acpi_device *device); 148 + static int acpi_button_probe(struct platform_device *pdev); 149 + static void acpi_button_remove(struct platform_device *pdev); 151 150 152 151 #ifdef CONFIG_PM_SLEEP 153 152 static int acpi_button_suspend(struct device *dev); ··· 158 157 #endif 159 158 static SIMPLE_DEV_PM_OPS(acpi_button_pm, acpi_button_suspend, acpi_button_resume); 160 159 161 - static struct acpi_driver acpi_button_driver = { 162 - .name = "button", 163 - .class = ACPI_BUTTON_CLASS, 164 - .ids = button_device_ids, 165 - .ops = { 166 - .add = acpi_button_add, 167 - .remove = acpi_button_remove, 160 + static struct platform_driver acpi_button_driver = { 161 + .probe = acpi_button_probe, 162 + .remove = acpi_button_remove, 163 + .driver = { 164 + .name = "acpi-button", 165 + .acpi_match_table = button_device_ids, 166 + .pm = &acpi_button_pm, 168 167 }, 169 - .drv.pm = &acpi_button_pm, 170 168 }; 171 169 172 170 struct acpi_button { 171 + struct acpi_device *adev; 172 + struct platform_device *pdev; 173 173 unsigned int type; 174 174 struct input_dev *input; 175 175 char phys[32]; /* for input device */ ··· 204 202 return lid_state ? 1 : 0; 205 203 } 206 204 207 - static int acpi_lid_notify_state(struct acpi_device *device, int state) 205 + static int acpi_lid_notify_state(struct acpi_button *button, int state) 208 206 { 209 - struct acpi_button *button = acpi_driver_data(device); 207 + struct acpi_device *device = button->adev; 210 208 ktime_t next_report; 211 209 bool do_update; 212 210 ··· 289 287 static int __maybe_unused acpi_button_state_seq_show(struct seq_file *seq, 290 288 void *offset) 291 289 { 292 - struct acpi_device *device = seq->private; 290 + struct acpi_button *button = seq->private; 293 291 int state; 294 292 295 - state = acpi_lid_evaluate_state(device); 293 + state = acpi_lid_evaluate_state(button->adev); 296 294 seq_printf(seq, "state: %s\n", 297 295 state < 0 ? "unsupported" : (state ? "open" : "closed")); 298 296 return 0; 299 297 } 300 298 301 - static int acpi_button_add_fs(struct acpi_device *device) 299 + static int acpi_button_add_fs(struct acpi_button *button) 302 300 { 303 - struct acpi_button *button = acpi_driver_data(device); 301 + struct acpi_device *device = button->adev; 304 302 struct proc_dir_entry *entry = NULL; 305 303 int ret = 0; 306 304 ··· 335 333 /* create /proc/acpi/button/lid/LID/state */ 336 334 entry = proc_create_single_data(ACPI_BUTTON_FILE_STATE, S_IRUGO, 337 335 acpi_device_dir(device), acpi_button_state_seq_show, 338 - device); 336 + button); 339 337 if (!entry) { 340 338 ret = -ENODEV; 341 339 goto remove_dev_dir; ··· 357 355 goto done; 358 356 } 359 357 360 - static int acpi_button_remove_fs(struct acpi_device *device) 358 + static int acpi_button_remove_fs(struct acpi_button *button) 361 359 { 362 - struct acpi_button *button = acpi_driver_data(device); 360 + struct acpi_device *device = button->adev; 363 361 364 362 if (button->type != ACPI_BUTTON_TYPE_LID) 365 363 return 0; ··· 387 385 } 388 386 EXPORT_SYMBOL(acpi_lid_open); 389 387 390 - static int acpi_lid_update_state(struct acpi_device *device, 388 + static int acpi_lid_update_state(struct acpi_button *button, 391 389 bool signal_wakeup) 392 390 { 391 + struct acpi_device *device = button->adev; 393 392 int state; 394 393 395 394 state = acpi_lid_evaluate_state(device); ··· 398 395 return state; 399 396 400 397 if (state && signal_wakeup) 401 - acpi_pm_wakeup_event(&device->dev); 398 + acpi_pm_wakeup_event(&button->pdev->dev); 402 399 403 - return acpi_lid_notify_state(device, state); 400 + return acpi_lid_notify_state(button, state); 404 401 } 405 402 406 - static void acpi_lid_initialize_state(struct acpi_device *device) 403 + static void acpi_lid_initialize_state(struct acpi_button *button) 407 404 { 408 - struct acpi_button *button = acpi_driver_data(device); 409 - 410 405 switch (lid_init_state) { 411 406 case ACPI_BUTTON_LID_INIT_OPEN: 412 - (void)acpi_lid_notify_state(device, 1); 407 + (void)acpi_lid_notify_state(button, 1); 413 408 break; 414 409 case ACPI_BUTTON_LID_INIT_METHOD: 415 - (void)acpi_lid_update_state(device, false); 410 + (void)acpi_lid_update_state(button, false); 416 411 break; 417 412 case ACPI_BUTTON_LID_INIT_IGNORE: 418 413 default: ··· 422 421 423 422 static void acpi_lid_notify(acpi_handle handle, u32 event, void *data) 424 423 { 425 - struct acpi_device *device = data; 426 - struct acpi_button *button; 424 + struct acpi_button *button = data; 425 + struct acpi_device *device = button->adev; 427 426 428 427 if (event != ACPI_BUTTON_NOTIFY_STATUS) { 429 428 acpi_handle_debug(device->handle, "Unsupported event [0x%x]\n", ··· 431 430 return; 432 431 } 433 432 434 - button = acpi_driver_data(device); 435 433 if (!button->lid_state_initialized) 436 434 return; 437 435 438 - acpi_lid_update_state(device, true); 436 + acpi_lid_update_state(button, true); 439 437 } 440 438 441 439 static void acpi_button_notify(acpi_handle handle, u32 event, void *data) 442 440 { 443 - struct acpi_device *device = data; 444 - struct acpi_button *button; 441 + struct acpi_button *button = data; 442 + struct acpi_device *device = button->adev; 445 443 struct input_dev *input; 446 444 int keycode; 447 445 ··· 455 455 return; 456 456 } 457 457 458 - acpi_pm_wakeup_event(&device->dev); 458 + acpi_pm_wakeup_event(&button->pdev->dev); 459 459 460 - button = acpi_driver_data(device); 461 460 if (button->suspended || event == ACPI_BUTTON_NOTIFY_WAKE) 462 461 return; 463 462 ··· 487 488 #ifdef CONFIG_PM_SLEEP 488 489 static int acpi_button_suspend(struct device *dev) 489 490 { 490 - struct acpi_device *device = to_acpi_device(dev); 491 - struct acpi_button *button = acpi_driver_data(device); 491 + struct acpi_button *button = dev_get_drvdata(dev); 492 492 493 493 button->suspended = true; 494 494 return 0; ··· 495 497 496 498 static int acpi_button_resume(struct device *dev) 497 499 { 500 + struct acpi_button *button = dev_get_drvdata(dev); 501 + struct acpi_device *device = ACPI_COMPANION(dev); 498 502 struct input_dev *input; 499 - struct acpi_device *device = to_acpi_device(dev); 500 - struct acpi_button *button = acpi_driver_data(device); 501 503 502 504 button->suspended = false; 503 505 if (button->type == ACPI_BUTTON_TYPE_LID) { 504 506 button->last_state = !!acpi_lid_evaluate_state(device); 505 507 button->last_time = ktime_get(); 506 - acpi_lid_initialize_state(device); 508 + acpi_lid_initialize_state(button); 507 509 } 508 510 509 511 if (button->type == ACPI_BUTTON_TYPE_POWER) { ··· 519 521 520 522 static int acpi_lid_input_open(struct input_dev *input) 521 523 { 522 - struct acpi_device *device = input_get_drvdata(input); 523 - struct acpi_button *button = acpi_driver_data(device); 524 + struct acpi_button *button = input_get_drvdata(input); 525 + struct acpi_device *device = button->adev; 524 526 525 527 button->last_state = !!acpi_lid_evaluate_state(device); 526 528 button->last_time = ktime_get(); 527 - acpi_lid_initialize_state(device); 529 + acpi_lid_initialize_state(button); 528 530 529 531 return 0; 530 532 } 531 533 532 - static int acpi_button_add(struct acpi_device *device) 534 + static int acpi_button_probe(struct platform_device *pdev) 533 535 { 536 + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 534 537 acpi_notify_handler handler; 535 538 struct acpi_button *button; 536 539 struct input_dev *input; ··· 548 549 if (!button) 549 550 return -ENOMEM; 550 551 551 - device->driver_data = button; 552 + platform_set_drvdata(pdev, button); 552 553 554 + button->pdev = pdev; 555 + button->adev = device; 553 556 button->input = input = input_allocate_device(); 554 557 if (!input) { 555 558 error = -ENOMEM; ··· 588 587 } 589 588 590 589 if (!error) 591 - error = acpi_button_add_fs(device); 590 + error = acpi_button_add_fs(button); 592 591 593 592 if (error) { 594 593 input_free_device(input); ··· 601 600 input->phys = button->phys; 602 601 input->id.bustype = BUS_HOST; 603 602 input->id.product = button->type; 604 - input->dev.parent = &device->dev; 603 + input->dev.parent = &pdev->dev; 605 604 606 605 switch (button->type) { 607 606 case ACPI_BUTTON_TYPE_POWER: ··· 618 617 break; 619 618 } 620 619 621 - input_set_drvdata(input, device); 620 + input_set_drvdata(input, button); 622 621 error = input_register_device(input); 623 622 if (error) { 624 623 input_free_device(input); ··· 629 628 case ACPI_BUS_TYPE_POWER_BUTTON: 630 629 status = acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, 631 630 acpi_button_event, 632 - device); 631 + button); 633 632 break; 634 633 case ACPI_BUS_TYPE_SLEEP_BUTTON: 635 634 status = acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON, 636 635 acpi_button_event, 637 - device); 636 + button); 638 637 break; 639 638 default: 640 639 status = acpi_install_notify_handler(device->handle, 641 640 ACPI_ALL_NOTIFY, handler, 642 - device); 641 + button); 643 642 break; 644 643 } 645 644 if (ACPI_FAILURE(status)) { ··· 655 654 lid_device = device; 656 655 } 657 656 658 - device_init_wakeup(&device->dev, true); 657 + device_init_wakeup(&pdev->dev, true); 659 658 pr_info("%s [%s]\n", name, acpi_device_bid(device)); 660 659 return 0; 661 660 662 661 err_input_unregister: 663 662 input_unregister_device(input); 664 663 err_remove_fs: 665 - acpi_button_remove_fs(device); 664 + acpi_button_remove_fs(button); 666 665 err_free_button: 667 666 kfree(button); 668 667 return error; 669 668 } 670 669 671 - static void acpi_button_remove(struct acpi_device *device) 670 + static void acpi_button_remove(struct platform_device *pdev) 672 671 { 673 - struct acpi_button *button = acpi_driver_data(device); 672 + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 673 + struct acpi_button *button = platform_get_drvdata(pdev); 674 674 675 675 switch (device->device_type) { 676 676 case ACPI_BUS_TYPE_POWER_BUTTON: ··· 691 689 } 692 690 acpi_os_wait_events_complete(); 693 691 694 - acpi_button_remove_fs(device); 692 + acpi_button_remove_fs(button); 695 693 input_unregister_device(button->input); 696 694 kfree(button); 697 695 } ··· 730 728 NULL, 0644); 731 729 MODULE_PARM_DESC(lid_init_state, "Behavior for reporting LID initial state"); 732 730 733 - static int acpi_button_register_driver(struct acpi_driver *driver) 731 + static int __init acpi_button_init(void) 734 732 { 735 733 const struct dmi_system_id *dmi_id; 736 734 ··· 746 744 * Modules such as nouveau.ko and i915.ko have a link time dependency 747 745 * on acpi_lid_open(), and would therefore not be loadable on ACPI 748 746 * capable kernels booted in non-ACPI mode if the return value of 749 - * acpi_bus_register_driver() is returned from here with ACPI disabled 747 + * platform_driver_register() is returned from here with ACPI disabled 750 748 * when this driver is built as a module. 751 749 */ 752 750 if (acpi_disabled) 753 751 return 0; 754 752 755 - return acpi_bus_register_driver(driver); 753 + return platform_driver_register(&acpi_button_driver); 756 754 } 757 755 758 - static void acpi_button_unregister_driver(struct acpi_driver *driver) 756 + static void __exit acpi_button_exit(void) 759 757 { 760 758 if (!acpi_disabled) 761 - acpi_bus_unregister_driver(driver); 759 + platform_driver_unregister(&acpi_button_driver); 762 760 } 763 761 764 - module_driver(acpi_button_driver, acpi_button_register_driver, 765 - acpi_button_unregister_driver); 762 + module_init(acpi_button_init); 763 + module_exit(acpi_button_exit);
+9
drivers/acpi/device_pm.c
··· 1457 1457 return 0; 1458 1458 1459 1459 /* 1460 + * Skip devices whose ACPI companions don't support power management and 1461 + * don't have a wakeup GPE. 1462 + */ 1463 + if (!acpi_device_power_manageable(adev) && !acpi_device_can_wakeup(adev)) { 1464 + dev_dbg(dev, "No ACPI power management or wakeup GPE\n"); 1465 + return 0; 1466 + } 1467 + 1468 + /* 1460 1469 * Only attach the power domain to the first device if the 1461 1470 * companion is shared by multiple. This is to prevent doing power 1462 1471 * management twice.
+20 -34
drivers/acpi/ec.c
··· 23 23 #include <linux/delay.h> 24 24 #include <linux/interrupt.h> 25 25 #include <linux/list.h> 26 + #include <linux/platform_device.h> 26 27 #include <linux/printk.h> 27 28 #include <linux/spinlock.h> 28 29 #include <linux/slab.h> ··· 1675 1674 return ret; 1676 1675 } 1677 1676 1678 - static int acpi_ec_add(struct acpi_device *device) 1677 + static int acpi_ec_probe(struct platform_device *pdev) 1679 1678 { 1679 + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 1680 1680 struct acpi_ec *ec; 1681 1681 int ret; 1682 1682 ··· 1732 1730 acpi_handle_info(ec->handle, 1733 1731 "EC: Used to handle transactions and events\n"); 1734 1732 1735 - device->driver_data = ec; 1733 + platform_set_drvdata(pdev, ec); 1736 1734 1737 1735 ret = !!request_region(ec->data_addr, 1, "EC data"); 1738 1736 WARN(!ret, "Could not request EC data io port 0x%lx", ec->data_addr); ··· 1752 1750 return ret; 1753 1751 } 1754 1752 1755 - static void acpi_ec_remove(struct acpi_device *device) 1753 + static void acpi_ec_remove(struct platform_device *pdev) 1756 1754 { 1757 - struct acpi_ec *ec; 1755 + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 1756 + struct acpi_ec *ec = platform_get_drvdata(pdev); 1758 1757 1759 - if (!device) 1760 - return; 1761 - 1762 - ec = acpi_driver_data(device); 1763 1758 release_region(ec->data_addr, 1); 1764 1759 release_region(ec->command_addr, 1); 1765 1760 device->driver_data = NULL; ··· 2094 2095 #ifdef CONFIG_PM_SLEEP 2095 2096 static int acpi_ec_suspend(struct device *dev) 2096 2097 { 2097 - struct acpi_ec *ec = 2098 - acpi_driver_data(to_acpi_device(dev)); 2098 + struct acpi_ec *ec = dev_get_drvdata(dev); 2099 2099 2100 2100 if (!pm_suspend_no_platform() && ec_freeze_events) 2101 2101 acpi_ec_disable_event(ec); ··· 2103 2105 2104 2106 static int acpi_ec_suspend_noirq(struct device *dev) 2105 2107 { 2106 - struct acpi_ec *ec = acpi_driver_data(to_acpi_device(dev)); 2108 + struct acpi_ec *ec = dev_get_drvdata(dev); 2107 2109 2108 2110 /* 2109 2111 * The SCI handler doesn't run at this point, so the GPE can be ··· 2120 2122 2121 2123 static int acpi_ec_resume_noirq(struct device *dev) 2122 2124 { 2123 - struct acpi_ec *ec = acpi_driver_data(to_acpi_device(dev)); 2125 + struct acpi_ec *ec = dev_get_drvdata(dev); 2124 2126 2125 2127 acpi_ec_leave_noirq(ec); 2126 2128 ··· 2133 2135 2134 2136 static int acpi_ec_resume(struct device *dev) 2135 2137 { 2136 - struct acpi_ec *ec = 2137 - acpi_driver_data(to_acpi_device(dev)); 2138 + struct acpi_ec *ec = dev_get_drvdata(dev); 2138 2139 2139 2140 acpi_ec_enable_event(ec); 2140 2141 return 0; ··· 2262 2265 NULL, 0644); 2263 2266 MODULE_PARM_DESC(ec_event_clearing, "Assumed SCI_EVT clearing timing"); 2264 2267 2265 - static struct acpi_driver acpi_ec_driver = { 2266 - .name = "ec", 2267 - .class = ACPI_EC_CLASS, 2268 - .ids = ec_device_ids, 2269 - .ops = { 2270 - .add = acpi_ec_add, 2271 - .remove = acpi_ec_remove, 2272 - }, 2273 - .drv.pm = &acpi_ec_pm, 2268 + static struct platform_driver acpi_ec_driver = { 2269 + .probe = acpi_ec_probe, 2270 + .remove = acpi_ec_remove, 2271 + .driver = { 2272 + .name = "acpi-ec", 2273 + .acpi_match_table = ec_device_ids, 2274 + .pm = &acpi_ec_pm, 2275 + }, 2274 2276 }; 2275 2277 2276 2278 static void acpi_ec_destroy_workqueues(void) ··· 2374 2378 } 2375 2379 2376 2380 /* Driver must be registered after acpi_ec_init_workqueues(). */ 2377 - acpi_bus_register_driver(&acpi_ec_driver); 2381 + platform_driver_register(&acpi_ec_driver); 2378 2382 2379 2383 acpi_ec_ecdt_start(); 2380 2384 } 2381 - 2382 - /* EC driver currently not unloadable */ 2383 - #if 0 2384 - static void __exit acpi_ec_exit(void) 2385 - { 2386 - 2387 - acpi_bus_unregister_driver(&acpi_ec_driver); 2388 - acpi_ec_destroy_workqueues(); 2389 - } 2390 - #endif /* 0 */
+13 -10
drivers/acpi/hed.c
··· 13 13 #include <linux/module.h> 14 14 #include <linux/init.h> 15 15 #include <linux/acpi.h> 16 + #include <linux/platform_device.h> 16 17 #include <acpi/hed.h> 17 18 18 19 static const struct acpi_device_id acpi_hed_ids[] = { ··· 48 47 blocking_notifier_call_chain(&acpi_hed_notify_list, 0, NULL); 49 48 } 50 49 51 - static int acpi_hed_add(struct acpi_device *device) 50 + static int acpi_hed_probe(struct platform_device *pdev) 52 51 { 52 + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 53 53 int err; 54 54 55 55 /* Only one hardware error device */ ··· 66 64 return err; 67 65 } 68 66 69 - static void acpi_hed_remove(struct acpi_device *device) 67 + static void acpi_hed_remove(struct platform_device *pdev) 70 68 { 69 + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 70 + 71 71 acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY, 72 72 acpi_hed_notify); 73 73 hed_handle = NULL; 74 74 } 75 75 76 - static struct acpi_driver acpi_hed_driver = { 77 - .name = "hardware_error_device", 78 - .class = "hardware_error", 79 - .ids = acpi_hed_ids, 80 - .ops = { 81 - .add = acpi_hed_add, 82 - .remove = acpi_hed_remove, 76 + static struct platform_driver acpi_hed_driver = { 77 + .probe = acpi_hed_probe, 78 + .remove = acpi_hed_remove, 79 + .driver = { 80 + .name = "acpi-hardware-error-device", 81 + .acpi_match_table = acpi_hed_ids, 83 82 }, 84 83 }; 85 84 86 85 static int __init acpi_hed_driver_init(void) 87 86 { 88 - return acpi_bus_register_driver(&acpi_hed_driver); 87 + return platform_driver_register(&acpi_hed_driver); 89 88 } 90 89 subsys_initcall(acpi_hed_driver_init); 91 90
+28 -19
drivers/acpi/nfit/core.c
··· 2 2 /* 3 3 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved. 4 4 */ 5 + #include <linux/platform_device.h> 5 6 #include <linux/list_sort.h> 6 7 #include <linux/libnvdimm.h> 7 8 #include <linux/module.h> ··· 90 89 static struct acpi_device *to_acpi_dev(struct acpi_nfit_desc *acpi_desc) 91 90 { 92 91 struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc; 92 + struct acpi_device *adev; 93 93 94 - /* 95 - * If provider == 'ACPI.NFIT' we can assume 'dev' is a struct 96 - * acpi_device. 97 - */ 94 + /* If provider == 'ACPI.NFIT', a struct acpi_device is there. */ 98 95 if (!nd_desc->provider_name 99 96 || strcmp(nd_desc->provider_name, "ACPI.NFIT") != 0) 100 97 return NULL; 101 98 99 + /* 100 + * But it can be the ACPI companion of acpi_desc->dev when it cones from 101 + * acpi_nfit_probe(). 102 + */ 103 + adev = ACPI_COMPANION(acpi_desc->dev); 104 + if (adev) 105 + return adev; 106 + 107 + /* Or it is acpi_desc->dev itself when it comes from nfit_ctl_test(). */ 102 108 return to_acpi_device(acpi_desc->dev); 103 109 } 104 110 ··· 3291 3283 3292 3284 static void acpi_nfit_notify(acpi_handle handle, u32 event, void *data) 3293 3285 { 3294 - struct acpi_device *adev = data; 3286 + struct device *dev = data; 3295 3287 3296 - device_lock(&adev->dev); 3297 - __acpi_nfit_notify(&adev->dev, handle, event); 3298 - device_unlock(&adev->dev); 3288 + device_lock(dev); 3289 + __acpi_nfit_notify(dev, handle, event); 3290 + device_unlock(dev); 3299 3291 } 3300 3292 3301 3293 static void acpi_nfit_remove_notify_handler(void *data) ··· 3336 3328 } 3337 3329 EXPORT_SYMBOL_GPL(acpi_nfit_shutdown); 3338 3330 3339 - static int acpi_nfit_add(struct acpi_device *adev) 3331 + static int acpi_nfit_probe(struct platform_device *pdev) 3340 3332 { 3341 3333 struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL }; 3342 3334 struct acpi_nfit_desc *acpi_desc; 3343 - struct device *dev = &adev->dev; 3335 + struct device *dev = &pdev->dev; 3336 + struct acpi_device *adev = ACPI_COMPANION(dev); 3344 3337 struct acpi_table_header *tbl; 3345 3338 acpi_status status = AE_OK; 3346 3339 acpi_size sz; 3347 3340 int rc = 0; 3348 3341 3349 3342 rc = acpi_dev_install_notify_handler(adev, ACPI_DEVICE_NOTIFY, 3350 - acpi_nfit_notify, adev); 3343 + acpi_nfit_notify, dev); 3351 3344 if (rc) 3352 3345 return rc; 3353 3346 ··· 3378 3369 acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); 3379 3370 if (!acpi_desc) 3380 3371 return -ENOMEM; 3381 - acpi_nfit_desc_init(acpi_desc, &adev->dev); 3372 + acpi_nfit_desc_init(acpi_desc, dev); 3382 3373 3383 3374 /* Save the acpi header for exporting the revision via sysfs */ 3384 3375 acpi_desc->acpi_header = *tbl; ··· 3483 3474 }; 3484 3475 MODULE_DEVICE_TABLE(acpi, acpi_nfit_ids); 3485 3476 3486 - static struct acpi_driver acpi_nfit_driver = { 3487 - .name = KBUILD_MODNAME, 3488 - .ids = acpi_nfit_ids, 3489 - .ops = { 3490 - .add = acpi_nfit_add, 3477 + static struct platform_driver acpi_nfit_driver = { 3478 + .probe = acpi_nfit_probe, 3479 + .driver = { 3480 + .name = "acpi-nfit", 3481 + .acpi_match_table = acpi_nfit_ids, 3491 3482 }, 3492 3483 }; 3493 3484 ··· 3525 3516 return -ENOMEM; 3526 3517 3527 3518 nfit_mce_register(); 3528 - ret = acpi_bus_register_driver(&acpi_nfit_driver); 3519 + ret = platform_driver_register(&acpi_nfit_driver); 3529 3520 if (ret) { 3530 3521 nfit_mce_unregister(); 3531 3522 destroy_workqueue(nfit_wq); ··· 3538 3529 static __exit void nfit_exit(void) 3539 3530 { 3540 3531 nfit_mce_unregister(); 3541 - acpi_bus_unregister_driver(&acpi_nfit_driver); 3532 + platform_driver_unregister(&acpi_nfit_driver); 3542 3533 destroy_workqueue(nfit_wq); 3543 3534 WARN_ON(!list_empty(&acpi_descs)); 3544 3535 }
+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);
+20 -23
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; 266 - device->driver_data = hc; 267 269 268 270 acpi_ec_add_query_handler(hc->ec, hc->query_bit, NULL, smbus_alarm, hc); 269 271 dev_info(&device->dev, "SBS HC: offset = 0x%0x, query_bit = 0x%0x\n", ··· 273 273 return 0; 274 274 } 275 275 276 - static void acpi_smbus_hc_remove(struct acpi_device *device) 276 + static void acpi_smbus_hc_remove(struct platform_device *pdev) 277 277 { 278 - struct acpi_smb_hc *hc; 278 + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 279 + struct acpi_smb_hc *hc = platform_get_drvdata(pdev); 279 280 280 - if (!device) 281 - return; 282 - 283 - hc = acpi_driver_data(device); 284 281 acpi_ec_remove_query_handler(hc->ec, hc->query_bit); 285 282 acpi_os_wait_events_complete(); 286 283 kfree(hc); 287 284 device->driver_data = NULL; 288 285 } 289 286 290 - module_acpi_driver(acpi_smb_hc_driver); 287 + module_platform_driver(acpi_smb_hc_driver); 291 288 292 289 MODULE_LICENSE("GPL"); 293 290 MODULE_AUTHOR("Alexey Starikovskiy");
+23 -44
drivers/acpi/scan.c
··· 1000 1000 return err; 1001 1001 } 1002 1002 1003 - /* Do not use a button for S5 wakeup */ 1004 - #define ACPI_AVOID_WAKE_FROM_S5 BIT(0) 1005 - 1006 1003 static bool acpi_wakeup_gpe_init(struct acpi_device *device) 1007 1004 { 1008 1005 static const struct acpi_device_id button_device_ids[] = { 1009 - {"PNP0C0C", 0}, /* Power button */ 1010 - {"PNP0C0D", ACPI_AVOID_WAKE_FROM_S5}, /* Lid */ 1011 - {"PNP0C0E", ACPI_AVOID_WAKE_FROM_S5}, /* Sleep button */ 1006 + {"PNP0C0D", 0}, /* Lid */ 1007 + {"PNP0C0E", 0}, /* Sleep button */ 1012 1008 {"", 0}, 1013 1009 }; 1014 1010 struct acpi_device_wakeup *wakeup = &device->wakeup; ··· 1013 1017 1014 1018 wakeup->flags.notifier_present = 0; 1015 1019 1016 - /* Power button, Lid switch always enable wakeup */ 1017 1020 match = acpi_match_acpi_device(button_device_ids, device); 1018 - if (match) { 1019 - if ((match->driver_data & ACPI_AVOID_WAKE_FROM_S5) && 1020 - wakeup->sleep_state == ACPI_STATE_S5) 1021 - wakeup->sleep_state = ACPI_STATE_S4; 1022 - acpi_mark_gpe_for_wake(wakeup->gpe_device, wakeup->gpe_number); 1023 - device_set_wakeup_capable(&device->dev, true); 1024 - return true; 1025 - } 1021 + if (match && wakeup->sleep_state == ACPI_STATE_S5) 1022 + wakeup->sleep_state = ACPI_STATE_S4; 1026 1023 1027 1024 status = acpi_setup_gpe_for_wake(device->handle, wakeup->gpe_device, 1028 1025 wakeup->gpe_number); ··· 1458 1469 break; 1459 1470 case ACPI_BUS_TYPE_THERMAL: 1460 1471 acpi_add_id(pnp, ACPI_THERMAL_HID); 1472 + pnp->type.platform_id = 1; 1461 1473 break; 1462 1474 case ACPI_BUS_TYPE_POWER_BUTTON: 1463 1475 acpi_add_id(pnp, ACPI_BUTTON_HID_POWERF); ··· 2339 2349 if (ret < 0) 2340 2350 return 0; 2341 2351 2342 - if (device->pnp.type.platform_id || device->flags.enumeration_by_parent) 2352 + if (device->pnp.type.platform_id || device->pnp.type.backlight || 2353 + device->flags.enumeration_by_parent) 2343 2354 acpi_default_enumeration(device); 2344 2355 else 2345 2356 acpi_device_set_enumerated(device); ··· 2581 2590 2582 2591 static void acpi_scan_claim_resources(struct acpi_device *adev) 2583 2592 { 2584 - struct list_head resource_list = LIST_HEAD_INIT(resource_list); 2585 2593 struct resource_entry *rentry; 2594 + LIST_HEAD(resource_list); 2586 2595 unsigned int count = 0; 2587 2596 const char *regionid; 2588 2597 ··· 2638 2647 exit: 2639 2648 acpi_dev_free_resource_list(&resource_list); 2640 2649 } 2641 - 2642 2650 2643 2651 static int __init acpi_reserve_motherboard_resources(void) 2644 2652 { ··· 2731 2741 if (result) 2732 2742 return result; 2733 2743 2734 - device->flags.match_driver = true; 2735 - return device_attach(&device->dev); 2744 + acpi_default_enumeration(device); 2745 + return 0; 2736 2746 } 2737 2747 EXPORT_SYMBOL_GPL(acpi_bus_register_early_device); 2738 2748 2749 + static void acpi_bus_add_fixed_device_object(enum acpi_bus_device_type type) 2750 + { 2751 + struct acpi_device *adev = NULL; 2752 + 2753 + acpi_add_single_object(&adev, NULL, type, false); 2754 + if (adev) 2755 + acpi_default_enumeration(adev); 2756 + } 2757 + 2739 2758 static void acpi_bus_scan_fixed(void) 2740 2759 { 2741 - if (!(acpi_gbl_FADT.flags & ACPI_FADT_POWER_BUTTON)) { 2742 - struct acpi_device *adev = NULL; 2760 + if (!(acpi_gbl_FADT.flags & ACPI_FADT_POWER_BUTTON)) 2761 + acpi_bus_add_fixed_device_object(ACPI_BUS_TYPE_POWER_BUTTON); 2743 2762 2744 - acpi_add_single_object(&adev, NULL, ACPI_BUS_TYPE_POWER_BUTTON, 2745 - false); 2746 - if (adev) { 2747 - adev->flags.match_driver = true; 2748 - if (device_attach(&adev->dev) >= 0) 2749 - device_init_wakeup(&adev->dev, true); 2750 - else 2751 - dev_dbg(&adev->dev, "No driver\n"); 2752 - } 2753 - } 2754 - 2755 - if (!(acpi_gbl_FADT.flags & ACPI_FADT_SLEEP_BUTTON)) { 2756 - struct acpi_device *adev = NULL; 2757 - 2758 - acpi_add_single_object(&adev, NULL, ACPI_BUS_TYPE_SLEEP_BUTTON, 2759 - false); 2760 - if (adev) { 2761 - adev->flags.match_driver = true; 2762 - if (device_attach(&adev->dev) < 0) 2763 - dev_dbg(&adev->dev, "No driver\n"); 2764 - } 2765 - } 2763 + if (!(acpi_gbl_FADT.flags & ACPI_FADT_SLEEP_BUTTON)) 2764 + acpi_bus_add_fixed_device_object(ACPI_BUS_TYPE_SLEEP_BUTTON); 2766 2765 } 2767 2766 2768 2767 static void __init acpi_get_spcr_uart_addr(void)
+34 -56
drivers/acpi/thermal.c
··· 25 25 #include <linux/kmod.h> 26 26 #include <linux/reboot.h> 27 27 #include <linux/device.h> 28 + #include <linux/platform_device.h> 28 29 #include <linux/thermal.h> 29 30 #include <linux/acpi.h> 30 31 #include <linux/workqueue.h> ··· 671 670 672 671 static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data) 673 672 { 674 - struct acpi_device *device = data; 675 - struct acpi_thermal *tz = acpi_driver_data(device); 673 + struct acpi_thermal *tz = data; 676 674 677 675 if (!tz) 678 676 return; ··· 685 685 acpi_thermal_trips_update(tz, event); 686 686 break; 687 687 default: 688 - acpi_handle_debug(device->handle, "Unsupported event [0x%x]\n", 689 - event); 688 + acpi_handle_debug(tz->device->handle, 689 + "Unsupported event [0x%x]\n", event); 690 690 break; 691 691 } 692 692 } ··· 777 777 kfree(tz); 778 778 } 779 779 780 - static int acpi_thermal_add(struct acpi_device *device) 780 + static int acpi_thermal_probe(struct platform_device *pdev) 781 781 { 782 782 struct thermal_trip trip_table[ACPI_THERMAL_MAX_NR_TRIPS] = { 0 }; 783 + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 783 784 struct acpi_thermal_trip *acpi_trip; 784 785 struct thermal_trip *trip; 785 786 struct acpi_thermal *tz; ··· 796 795 if (!tz) 797 796 return -ENOMEM; 798 797 798 + platform_set_drvdata(pdev, tz); 799 + 799 800 tz->device = device; 800 801 strscpy(tz->name, device->pnp.bus_id); 801 802 strscpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME); 802 803 strscpy(acpi_device_class(device), ACPI_THERMAL_CLASS); 803 - device->driver_data = tz; 804 804 805 805 acpi_thermal_aml_dependency_fix(tz); 806 806 ··· 883 881 acpi_device_bid(device), deci_kelvin_to_celsius(tz->temp_dk)); 884 882 885 883 result = acpi_dev_install_notify_handler(device, ACPI_DEVICE_NOTIFY, 886 - acpi_thermal_notify, device); 884 + acpi_thermal_notify, tz); 887 885 if (result) 888 886 goto flush_wq; 889 887 ··· 898 896 return result; 899 897 } 900 898 901 - static void acpi_thermal_remove(struct acpi_device *device) 899 + static void acpi_thermal_remove(struct platform_device *pdev) 902 900 { 903 - struct acpi_thermal *tz; 901 + struct acpi_thermal *tz = platform_get_drvdata(pdev); 904 902 905 - if (!device || !acpi_driver_data(device)) 906 - return; 907 - 908 - tz = acpi_driver_data(device); 909 - 910 - acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY, 903 + acpi_dev_remove_notify_handler(tz->device, ACPI_DEVICE_NOTIFY, 911 904 acpi_thermal_notify); 912 905 913 906 flush_workqueue(acpi_thermal_pm_queue); ··· 911 914 } 912 915 913 916 #ifdef CONFIG_PM_SLEEP 914 - static int acpi_thermal_suspend(struct device *dev) 917 + static int acpi_thermal_prepare(struct device *dev) 915 918 { 916 919 /* Make sure the previously queued thermal check work has been done */ 917 920 flush_workqueue(acpi_thermal_pm_queue); 918 921 return 0; 919 922 } 920 923 921 - static int acpi_thermal_resume(struct device *dev) 924 + static void acpi_thermal_complete(struct device *dev) 922 925 { 923 - struct acpi_thermal *tz; 924 - int i, j; 925 - 926 - if (!dev) 927 - return -EINVAL; 928 - 929 - tz = acpi_driver_data(to_acpi_device(dev)); 930 - if (!tz) 931 - return -EINVAL; 932 - 933 - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { 934 - struct acpi_thermal_trip *acpi_trip = &tz->trips.active[i].trip; 935 - 936 - if (!acpi_thermal_trip_valid(acpi_trip)) 937 - break; 938 - 939 - for (j = 0; j < acpi_trip->devices.count; j++) 940 - acpi_bus_update_power(acpi_trip->devices.handles[j], NULL); 941 - } 942 - 943 - acpi_queue_thermal_check(tz); 944 - 945 - return AE_OK; 926 + acpi_queue_thermal_check(dev_get_drvdata(dev)); 946 927 } 947 - #else 948 - #define acpi_thermal_suspend NULL 949 - #define acpi_thermal_resume NULL 950 - #endif 951 - static SIMPLE_DEV_PM_OPS(acpi_thermal_pm, acpi_thermal_suspend, acpi_thermal_resume); 928 + 929 + static const struct dev_pm_ops acpi_thermal_pm_ops = { 930 + .prepare = acpi_thermal_prepare, 931 + .complete = acpi_thermal_complete, 932 + }; 933 + #define ACPI_THERMAL_PM &acpi_thermal_pm_ops 934 + #else /* !CONFIG_PM_SLEEP */ 935 + #define ACPI_THERMAL_PM NULL 936 + #endif /* CONFIG_PM_SLEEP */ 952 937 953 938 static const struct acpi_device_id thermal_device_ids[] = { 954 939 {ACPI_THERMAL_HID, 0}, ··· 938 959 }; 939 960 MODULE_DEVICE_TABLE(acpi, thermal_device_ids); 940 961 941 - static struct acpi_driver acpi_thermal_driver = { 942 - .name = "thermal", 943 - .class = ACPI_THERMAL_CLASS, 944 - .ids = thermal_device_ids, 945 - .ops = { 946 - .add = acpi_thermal_add, 947 - .remove = acpi_thermal_remove, 948 - }, 949 - .drv.pm = &acpi_thermal_pm, 962 + static struct platform_driver acpi_thermal_driver = { 963 + .probe = acpi_thermal_probe, 964 + .remove = acpi_thermal_remove, 965 + .driver = { 966 + .name = "acpi-thermal", 967 + .acpi_match_table = thermal_device_ids, 968 + .pm = ACPI_THERMAL_PM, 969 + }, 950 970 }; 951 971 952 972 static int thermal_act(const struct dmi_system_id *d) ··· 1043 1065 if (!acpi_thermal_pm_queue) 1044 1066 return -ENODEV; 1045 1067 1046 - result = acpi_bus_register_driver(&acpi_thermal_driver); 1068 + result = platform_driver_register(&acpi_thermal_driver); 1047 1069 if (result < 0) { 1048 1070 destroy_workqueue(acpi_thermal_pm_queue); 1049 1071 return -ENODEV; ··· 1054 1076 1055 1077 static void __exit acpi_thermal_exit(void) 1056 1078 { 1057 - acpi_bus_unregister_driver(&acpi_thermal_driver); 1079 + platform_driver_unregister(&acpi_thermal_driver); 1058 1080 destroy_workqueue(acpi_thermal_pm_queue); 1059 1081 } 1060 1082
+15 -12
drivers/acpi/tiny-power-button.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-or-later 2 - #include <linux/module.h> 3 - #include <linux/sched/signal.h> 4 2 #include <linux/acpi.h> 3 + #include <linux/module.h> 4 + #include <linux/platform_device.h> 5 + #include <linux/sched/signal.h> 5 6 #include <acpi/button.h> 6 7 7 8 MODULE_AUTHOR("Josh Triplett"); ··· 36 35 return ACPI_INTERRUPT_HANDLED; 37 36 } 38 37 39 - static int acpi_tiny_power_button_add(struct acpi_device *device) 38 + static int acpi_tiny_power_button_probe(struct platform_device *pdev) 40 39 { 40 + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 41 41 acpi_status status; 42 42 43 43 if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON) { ··· 57 55 return 0; 58 56 } 59 57 60 - static void acpi_tiny_power_button_remove(struct acpi_device *device) 58 + static void acpi_tiny_power_button_remove(struct platform_device *pdev) 61 59 { 60 + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 61 + 62 62 if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON) { 63 63 acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, 64 64 acpi_tiny_power_button_event); ··· 71 67 acpi_os_wait_events_complete(); 72 68 } 73 69 74 - static struct acpi_driver acpi_tiny_power_button_driver = { 75 - .name = "tiny-power-button", 76 - .class = "tiny-power-button", 77 - .ids = tiny_power_button_device_ids, 78 - .ops = { 79 - .add = acpi_tiny_power_button_add, 80 - .remove = acpi_tiny_power_button_remove, 70 + static struct platform_driver acpi_tiny_power_button_driver = { 71 + .probe = acpi_tiny_power_button_probe, 72 + .remove = acpi_tiny_power_button_remove, 73 + .driver = { 74 + .name = "acpi-tiny-power-button", 75 + .acpi_match_table = tiny_power_button_device_ids, 81 76 }, 82 77 }; 83 78 84 - module_acpi_driver(acpi_tiny_power_button_driver); 79 + module_platform_driver(acpi_tiny_power_button_driver);