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: dell/dell-rbtn: 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 Dell Airplane Mode Switch (rbtn) ACPI
driver to a platform one.

After this change, the subordinate rfkill device 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/6141354.MhkbZ0Pkbq@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
19ebacfb da71de1b

+52 -56
+52 -56
drivers/platform/x86/dell/dell-rbtn.c
··· 9 9 #include <linux/acpi.h> 10 10 #include <linux/rfkill.h> 11 11 #include <linux/input.h> 12 + #include <linux/platform_device.h> 12 13 13 14 #include "dell-rbtn.h" 14 15 ··· 110 109 .set_block = rbtn_rfkill_set_block, 111 110 }; 112 111 113 - static int rbtn_rfkill_init(struct acpi_device *device) 112 + static int rbtn_rfkill_init(struct device *dev) 114 113 { 115 - struct rbtn_data *rbtn_data = device->driver_data; 114 + struct rbtn_data *rbtn_data = dev_get_drvdata(dev); 116 115 int ret; 117 116 118 117 if (rbtn_data->rfkill) ··· 123 122 * but rfkill interface does not support "ANY" type 124 123 * so "WLAN" type is used 125 124 */ 126 - rbtn_data->rfkill = rfkill_alloc("dell-rbtn", &device->dev, 127 - RFKILL_TYPE_WLAN, &rbtn_ops, device); 125 + rbtn_data->rfkill = rfkill_alloc("dell-rbtn", dev, RFKILL_TYPE_WLAN, 126 + &rbtn_ops, ACPI_COMPANION(dev)); 128 127 if (!rbtn_data->rfkill) 129 128 return -ENOMEM; 130 129 ··· 138 137 return 0; 139 138 } 140 139 141 - static void rbtn_rfkill_exit(struct acpi_device *device) 140 + static void rbtn_rfkill_exit(struct device *dev) 142 141 { 143 - struct rbtn_data *rbtn_data = device->driver_data; 142 + struct rbtn_data *rbtn_data = dev_get_drvdata(dev); 144 143 145 144 if (!rbtn_data->rfkill) 146 145 return; ··· 150 149 rbtn_data->rfkill = NULL; 151 150 } 152 151 153 - static void rbtn_rfkill_event(struct acpi_device *device) 152 + static void rbtn_rfkill_event(struct device *dev) 154 153 { 155 - struct rbtn_data *rbtn_data = device->driver_data; 154 + struct rbtn_data *rbtn_data = dev_get_drvdata(dev); 156 155 157 156 if (rbtn_data->rfkill) 158 - rbtn_rfkill_query(rbtn_data->rfkill, device); 157 + rbtn_rfkill_query(rbtn_data->rfkill, ACPI_COMPANION(dev)); 159 158 } 160 159 161 160 ··· 206 205 * acpi driver 207 206 */ 208 207 209 - static int rbtn_add(struct acpi_device *device); 210 - static void rbtn_remove(struct acpi_device *device); 208 + static int rbtn_probe(struct platform_device *pdev); 209 + static void rbtn_remove(struct platform_device *pdev); 211 210 static void rbtn_notify(acpi_handle handle, u32 event, void *data); 212 211 213 212 static const struct acpi_device_id rbtn_ids[] = { ··· 252 251 253 252 static int rbtn_suspend(struct device *dev) 254 253 { 255 - struct acpi_device *device = to_acpi_device(dev); 256 - struct rbtn_data *rbtn_data = acpi_driver_data(device); 254 + struct rbtn_data *rbtn_data = dev_get_drvdata(dev); 257 255 258 256 rbtn_data->suspended = true; 259 257 ··· 261 261 262 262 static int rbtn_resume(struct device *dev) 263 263 { 264 - struct acpi_device *device = to_acpi_device(dev); 265 - struct rbtn_data *rbtn_data = acpi_driver_data(device); 264 + struct rbtn_data *rbtn_data = dev_get_drvdata(dev); 266 265 acpi_status status; 267 266 268 267 /* ··· 285 286 286 287 static SIMPLE_DEV_PM_OPS(rbtn_pm_ops, rbtn_suspend, rbtn_resume); 287 288 288 - static struct acpi_driver rbtn_driver = { 289 - .name = "dell-rbtn", 290 - .ids = rbtn_ids, 291 - .drv.pm = &rbtn_pm_ops, 292 - .ops = { 293 - .add = rbtn_add, 294 - .remove = rbtn_remove, 289 + static struct platform_driver rbtn_driver = { 290 + .probe = rbtn_probe, 291 + .remove = rbtn_remove, 292 + .driver = { 293 + .name = "dell-rbtn", 294 + .acpi_match_table = rbtn_ids, 295 + .pm = &rbtn_pm_ops, 295 296 }, 296 297 }; 297 298 ··· 306 307 307 308 static int rbtn_inc_count(struct device *dev, void *data) 308 309 { 309 - struct acpi_device *device = to_acpi_device(dev); 310 - struct rbtn_data *rbtn_data = device->driver_data; 310 + struct rbtn_data *rbtn_data = dev_get_drvdata(dev); 311 311 int *count = data; 312 312 313 313 if (rbtn_data->type == RBTN_SLIDER) ··· 317 319 318 320 static int rbtn_switch_dev(struct device *dev, void *data) 319 321 { 320 - struct acpi_device *device = to_acpi_device(dev); 321 - struct rbtn_data *rbtn_data = device->driver_data; 322 + struct rbtn_data *rbtn_data = dev_get_drvdata(dev); 322 323 bool enable = data; 323 324 324 325 if (rbtn_data->type != RBTN_SLIDER) 325 326 return 0; 326 327 327 328 if (enable) 328 - rbtn_rfkill_init(device); 329 + rbtn_rfkill_init(dev); 329 330 else 330 - rbtn_rfkill_exit(device); 331 + rbtn_rfkill_exit(dev); 331 332 332 333 return 0; 333 334 } ··· 338 341 int ret; 339 342 340 343 count = 0; 341 - ret = driver_for_each_device(&rbtn_driver.drv, NULL, &count, 344 + ret = driver_for_each_device(&rbtn_driver.driver, NULL, &count, 342 345 rbtn_inc_count); 343 346 if (ret || count == 0) 344 347 return -ENODEV; ··· 350 353 return ret; 351 354 352 355 if (auto_remove_rfkill && first) 353 - ret = driver_for_each_device(&rbtn_driver.drv, NULL, 356 + ret = driver_for_each_device(&rbtn_driver.driver, NULL, 354 357 (void *)false, rbtn_switch_dev); 355 358 356 359 return ret; ··· 366 369 return ret; 367 370 368 371 if (auto_remove_rfkill && !rbtn_chain_head.head) 369 - ret = driver_for_each_device(&rbtn_driver.drv, NULL, 372 + ret = driver_for_each_device(&rbtn_driver.driver, NULL, 370 373 (void *)true, rbtn_switch_dev); 371 374 372 375 return ret; ··· 378 381 * acpi driver functions 379 382 */ 380 383 381 - static void rbtn_cleanup(struct acpi_device *device) 384 + static void rbtn_cleanup(struct device *dev) 382 385 { 383 - struct rbtn_data *rbtn_data = device->driver_data; 386 + struct rbtn_data *rbtn_data = dev_get_drvdata(dev); 384 387 385 388 switch (rbtn_data->type) { 386 389 case RBTN_TOGGLE: 387 390 rbtn_input_exit(rbtn_data); 388 391 break; 389 392 case RBTN_SLIDER: 390 - rbtn_rfkill_exit(device); 393 + rbtn_rfkill_exit(dev); 391 394 break; 392 395 default: 393 396 break; 394 397 } 395 398 } 396 399 397 - static int rbtn_add(struct acpi_device *device) 400 + static int rbtn_probe(struct platform_device *pdev) 398 401 { 402 + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 399 403 struct rbtn_data *rbtn_data; 400 404 enum rbtn_type type; 401 405 int ret = 0; 402 406 403 407 type = rbtn_check(device); 404 408 if (type == RBTN_UNKNOWN) { 405 - dev_info(&device->dev, "Unknown device type\n"); 409 + dev_info(&pdev->dev, "Unknown device type\n"); 406 410 return -EINVAL; 407 411 } 408 412 409 - rbtn_data = devm_kzalloc(&device->dev, sizeof(*rbtn_data), GFP_KERNEL); 413 + rbtn_data = devm_kzalloc(&pdev->dev, sizeof(*rbtn_data), GFP_KERNEL); 410 414 if (!rbtn_data) 411 415 return -ENOMEM; 412 416 413 417 ret = rbtn_acquire(device, true); 414 418 if (ret < 0) { 415 - dev_err(&device->dev, "Cannot enable device\n"); 419 + dev_err(&pdev->dev, "Cannot enable device\n"); 416 420 return ret; 417 421 } 418 422 423 + platform_set_drvdata(pdev, rbtn_data); 424 + 419 425 rbtn_data->type = type; 420 - device->driver_data = rbtn_data; 421 426 422 427 switch (rbtn_data->type) { 423 428 case RBTN_TOGGLE: ··· 429 430 if (auto_remove_rfkill && rbtn_chain_head.head) 430 431 ret = 0; 431 432 else 432 - ret = rbtn_rfkill_init(device); 433 + ret = rbtn_rfkill_init(&pdev->dev); 433 434 break; 434 435 default: 435 436 ret = -EINVAL; ··· 439 440 goto err; 440 441 441 442 ret = acpi_dev_install_notify_handler(device, ACPI_DEVICE_NOTIFY, 442 - rbtn_notify, device); 443 + rbtn_notify, &pdev->dev); 443 444 if (ret) 444 445 goto err_cleanup; 445 446 446 447 return 0; 447 448 448 449 err_cleanup: 449 - rbtn_cleanup(device); 450 + rbtn_cleanup(&pdev->dev); 450 451 err: 451 452 rbtn_acquire(device, false); 452 453 return ret; 453 454 } 454 455 455 - static void rbtn_remove(struct acpi_device *device) 456 + static void rbtn_remove(struct platform_device *pdev) 456 457 { 458 + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 459 + 457 460 acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY, rbtn_notify); 458 - rbtn_cleanup(device); 461 + rbtn_cleanup(&pdev->dev); 459 462 rbtn_acquire(device, false); 460 463 } 461 464 462 465 static void rbtn_notify(acpi_handle handle, u32 event, void *data) 463 466 { 464 - struct acpi_device *device = data; 465 - struct rbtn_data *rbtn_data = device->driver_data; 467 + struct device *dev = data; 468 + struct rbtn_data *rbtn_data = dev_get_drvdata(dev); 466 469 467 470 /* 468 471 * Some BIOSes send a notification at resume. 469 472 * Ignore it to prevent unwanted input events. 470 473 */ 471 474 if (rbtn_data->suspended) { 472 - dev_dbg(&device->dev, "ACPI notification ignored\n"); 475 + dev_dbg(dev, "ACPI notification ignored\n"); 473 476 return; 474 477 } 475 478 476 479 if (event != 0x80) { 477 - dev_info(&device->dev, "Received unknown event (0x%x)\n", 480 + dev_info(dev, "Received unknown event (0x%x)\n", 478 481 event); 479 482 return; 480 483 } ··· 486 485 rbtn_input_event(rbtn_data); 487 486 break; 488 487 case RBTN_SLIDER: 489 - rbtn_rfkill_event(device); 490 - atomic_notifier_call_chain(&rbtn_chain_head, event, device); 488 + rbtn_rfkill_event(dev); 489 + atomic_notifier_call_chain(&rbtn_chain_head, event, NULL); 491 490 break; 492 491 default: 493 492 break; 494 493 } 495 494 } 496 495 497 - 498 - /* 499 - * module functions 500 - */ 501 - 502 - module_acpi_driver(rbtn_driver); 496 + module_platform_driver(rbtn_driver); 503 497 504 498 module_param(auto_remove_rfkill, bool, 0444); 505 499