1 /* 2 * Eee PC WMI hotkey driver 3 * 4 * Copyright(C) 2010 Intel Corporation. 5 * Copyright(C) 2010 Corentin Chary <corentin.chary@gmail.com> 6 * 7 * Portions based on wistron_btns.c: 8 * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz> 9 * Copyright (C) 2005 Bernhard Rosenkraenzer <bero@arklinux.org> 10 * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru> 11 * 12 * This program is free software; you can redistribute it and/or modify 13 * it under the terms of the GNU General Public License as published by 14 * the Free Software Foundation; either version 2 of the License, or 15 * (at your option) any later version. 16 * 17 * This program is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * GNU General Public License for more details. 21 * 22 * You should have received a copy of the GNU General Public License 23 * along with this program; if not, write to the Free Software 24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 */ 26 27 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 28 29 #include <linux/kernel.h> 30 #include <linux/module.h> 31 #include <linux/init.h> 32 #include <linux/types.h> 33 #include <linux/slab.h> 34 #include <linux/input.h> 35 #include <linux/input/sparse-keymap.h> 36 #include <linux/fb.h> 37 #include <linux/backlight.h> 38 #include <linux/leds.h> 39 #include <linux/rfkill.h> 40 #include <linux/pci.h> 41 #include <linux/pci_hotplug.h> 42 #include <linux/debugfs.h> 43 #include <linux/seq_file.h> 44 #include <linux/platform_device.h> 45 #include <linux/dmi.h> 46 #include <acpi/acpi_bus.h> 47 #include <acpi/acpi_drivers.h> 48 49 #define EEEPC_WMI_FILE "eeepc-wmi" 50 51 MODULE_AUTHOR("Yong Wang <yong.y.wang@intel.com>"); 52 MODULE_DESCRIPTION("Eee PC WMI Hotkey Driver"); 53 MODULE_LICENSE("GPL"); 54 55 #define EEEPC_ACPI_HID "ASUS010" /* old _HID used in eeepc-laptop */ 56 57 #define EEEPC_WMI_EVENT_GUID "ABBC0F72-8EA1-11D1-00A0-C90629100000" 58 #define EEEPC_WMI_MGMT_GUID "97845ED0-4E6D-11DE-8A39-0800200C9A66" 59 60 MODULE_ALIAS("wmi:"EEEPC_WMI_EVENT_GUID); 61 MODULE_ALIAS("wmi:"EEEPC_WMI_MGMT_GUID); 62 63 #define NOTIFY_BRNUP_MIN 0x11 64 #define NOTIFY_BRNUP_MAX 0x1f 65 #define NOTIFY_BRNDOWN_MIN 0x20 66 #define NOTIFY_BRNDOWN_MAX 0x2e 67 68 /* WMI Methods */ 69 #define EEEPC_WMI_METHODID_DSTS 0x53544344 70 #define EEEPC_WMI_METHODID_DEVS 0x53564544 71 #define EEEPC_WMI_METHODID_CFVS 0x53564643 72 73 /* Wireless */ 74 #define EEEPC_WMI_DEVID_WLAN 0x00010011 75 #define EEEPC_WMI_DEVID_BLUETOOTH 0x00010013 76 #define EEEPC_WMI_DEVID_WIMAX 0x00010017 77 #define EEEPC_WMI_DEVID_WWAN3G 0x00010019 78 79 /* Backlight and Brightness */ 80 #define EEEPC_WMI_DEVID_BACKLIGHT 0x00050011 81 #define EEEPC_WMI_DEVID_BRIGHTNESS 0x00050012 82 83 /* Misc */ 84 #define EEEPC_WMI_DEVID_CAMERA 0x00060013 85 86 /* Storage */ 87 #define EEEPC_WMI_DEVID_CARDREADER 0x00080013 88 89 /* Input */ 90 #define EEEPC_WMI_DEVID_TOUCHPAD 0x00100011 91 #define EEEPC_WMI_DEVID_TOUCHPAD_LED 0x00100012 92 93 /* DSTS masks */ 94 #define EEEPC_WMI_DSTS_STATUS_BIT 0x00000001 95 #define EEEPC_WMI_DSTS_PRESENCE_BIT 0x00010000 96 #define EEEPC_WMI_DSTS_BRIGHTNESS_MASK 0x000000FF 97 #define EEEPC_WMI_DSTS_MAX_BRIGTH_MASK 0x0000FF00 98 99 static bool hotplug_wireless; 100 101 module_param(hotplug_wireless, bool, 0444); 102 MODULE_PARM_DESC(hotplug_wireless, 103 "Enable hotplug for wireless device. " 104 "If your laptop needs that, please report to " 105 "acpi4asus-user@lists.sourceforge.net."); 106 107 static const struct key_entry eeepc_wmi_keymap[] = { 108 /* Sleep already handled via generic ACPI code */ 109 { KE_IGNORE, NOTIFY_BRNDOWN_MIN, { KEY_BRIGHTNESSDOWN } }, 110 { KE_IGNORE, NOTIFY_BRNUP_MIN, { KEY_BRIGHTNESSUP } }, 111 { KE_KEY, 0x30, { KEY_VOLUMEUP } }, 112 { KE_KEY, 0x31, { KEY_VOLUMEDOWN } }, 113 { KE_KEY, 0x32, { KEY_MUTE } }, 114 { KE_KEY, 0x5c, { KEY_F15 } }, /* Power Gear key */ 115 { KE_KEY, 0x5d, { KEY_WLAN } }, 116 { KE_KEY, 0x6b, { KEY_F13 } }, /* Disable Touchpad */ 117 { KE_KEY, 0x88, { KEY_WLAN } }, 118 { KE_KEY, 0xcc, { KEY_SWITCHVIDEOMODE } }, 119 { KE_KEY, 0xe0, { KEY_PROG1 } }, /* Task Manager */ 120 { KE_KEY, 0xe1, { KEY_F14 } }, /* Change Resolution */ 121 { KE_KEY, 0xe9, { KEY_BRIGHTNESS_ZERO } }, 122 { KE_END, 0}, 123 }; 124 125 struct bios_args { 126 u32 dev_id; 127 u32 ctrl_param; 128 }; 129 130 /* 131 * eeepc-wmi/ - debugfs root directory 132 * dev_id - current dev_id 133 * ctrl_param - current ctrl_param 134 * devs - call DEVS(dev_id, ctrl_param) and print result 135 * dsts - call DSTS(dev_id) and print result 136 */ 137 struct eeepc_wmi_debug { 138 struct dentry *root; 139 u32 dev_id; 140 u32 ctrl_param; 141 }; 142 143 struct eeepc_wmi { 144 bool hotplug_wireless; 145 146 struct input_dev *inputdev; 147 struct backlight_device *backlight_device; 148 struct platform_device *platform_device; 149 150 struct led_classdev tpd_led; 151 int tpd_led_wk; 152 struct workqueue_struct *led_workqueue; 153 struct work_struct tpd_led_work; 154 155 struct rfkill *wlan_rfkill; 156 struct rfkill *bluetooth_rfkill; 157 struct rfkill *wimax_rfkill; 158 struct rfkill *wwan3g_rfkill; 159 160 struct hotplug_slot *hotplug_slot; 161 struct mutex hotplug_lock; 162 struct mutex wmi_lock; 163 struct workqueue_struct *hotplug_workqueue; 164 struct work_struct hotplug_work; 165 166 struct eeepc_wmi_debug debug; 167 }; 168 169 static int eeepc_wmi_input_init(struct eeepc_wmi *eeepc) 170 { 171 int err; 172 173 eeepc->inputdev = input_allocate_device(); 174 if (!eeepc->inputdev) 175 return -ENOMEM; 176 177 eeepc->inputdev->name = "Eee PC WMI hotkeys"; 178 eeepc->inputdev->phys = EEEPC_WMI_FILE "/input0"; 179 eeepc->inputdev->id.bustype = BUS_HOST; 180 eeepc->inputdev->dev.parent = &eeepc->platform_device->dev; 181 182 err = sparse_keymap_setup(eeepc->inputdev, eeepc_wmi_keymap, NULL); 183 if (err) 184 goto err_free_dev; 185 186 err = input_register_device(eeepc->inputdev); 187 if (err) 188 goto err_free_keymap; 189 190 return 0; 191 192 err_free_keymap: 193 sparse_keymap_free(eeepc->inputdev); 194 err_free_dev: 195 input_free_device(eeepc->inputdev); 196 return err; 197 } 198 199 static void eeepc_wmi_input_exit(struct eeepc_wmi *eeepc) 200 { 201 if (eeepc->inputdev) { 202 sparse_keymap_free(eeepc->inputdev); 203 input_unregister_device(eeepc->inputdev); 204 } 205 206 eeepc->inputdev = NULL; 207 } 208 209 static acpi_status eeepc_wmi_get_devstate(u32 dev_id, u32 *retval) 210 { 211 struct acpi_buffer input = { (acpi_size)sizeof(u32), &dev_id }; 212 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; 213 union acpi_object *obj; 214 acpi_status status; 215 u32 tmp; 216 217 status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID, 218 1, EEEPC_WMI_METHODID_DSTS, 219 &input, &output); 220 221 if (ACPI_FAILURE(status)) 222 return status; 223 224 obj = (union acpi_object *)output.pointer; 225 if (obj && obj->type == ACPI_TYPE_INTEGER) 226 tmp = (u32)obj->integer.value; 227 else 228 tmp = 0; 229 230 if (retval) 231 *retval = tmp; 232 233 kfree(obj); 234 235 return status; 236 237 } 238 239 static acpi_status eeepc_wmi_set_devstate(u32 dev_id, u32 ctrl_param, 240 u32 *retval) 241 { 242 struct bios_args args = { 243 .dev_id = dev_id, 244 .ctrl_param = ctrl_param, 245 }; 246 struct acpi_buffer input = { (acpi_size)sizeof(args), &args }; 247 acpi_status status; 248 249 if (!retval) { 250 status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID, 1, 251 EEEPC_WMI_METHODID_DEVS, 252 &input, NULL); 253 } else { 254 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; 255 union acpi_object *obj; 256 u32 tmp; 257 258 status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID, 1, 259 EEEPC_WMI_METHODID_DEVS, 260 &input, &output); 261 262 if (ACPI_FAILURE(status)) 263 return status; 264 265 obj = (union acpi_object *)output.pointer; 266 if (obj && obj->type == ACPI_TYPE_INTEGER) 267 tmp = (u32)obj->integer.value; 268 else 269 tmp = 0; 270 271 *retval = tmp; 272 273 kfree(obj); 274 } 275 276 return status; 277 } 278 279 /* Helper for special devices with magic return codes */ 280 static int eeepc_wmi_get_devstate_bits(u32 dev_id, u32 mask) 281 { 282 u32 retval = 0; 283 acpi_status status; 284 285 status = eeepc_wmi_get_devstate(dev_id, &retval); 286 287 if (ACPI_FAILURE(status)) 288 return -EINVAL; 289 290 if (!(retval & EEEPC_WMI_DSTS_PRESENCE_BIT)) 291 return -ENODEV; 292 293 return retval & mask; 294 } 295 296 static int eeepc_wmi_get_devstate_simple(u32 dev_id) 297 { 298 return eeepc_wmi_get_devstate_bits(dev_id, EEEPC_WMI_DSTS_STATUS_BIT); 299 } 300 301 /* 302 * LEDs 303 */ 304 /* 305 * These functions actually update the LED's, and are called from a 306 * workqueue. By doing this as separate work rather than when the LED 307 * subsystem asks, we avoid messing with the Eeepc ACPI stuff during a 308 * potentially bad time, such as a timer interrupt. 309 */ 310 static void tpd_led_update(struct work_struct *work) 311 { 312 int ctrl_param; 313 struct eeepc_wmi *eeepc; 314 315 eeepc = container_of(work, struct eeepc_wmi, tpd_led_work); 316 317 ctrl_param = eeepc->tpd_led_wk; 318 eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_TOUCHPAD_LED, ctrl_param, NULL); 319 } 320 321 static void tpd_led_set(struct led_classdev *led_cdev, 322 enum led_brightness value) 323 { 324 struct eeepc_wmi *eeepc; 325 326 eeepc = container_of(led_cdev, struct eeepc_wmi, tpd_led); 327 328 eeepc->tpd_led_wk = !!value; 329 queue_work(eeepc->led_workqueue, &eeepc->tpd_led_work); 330 } 331 332 static int read_tpd_led_state(struct eeepc_wmi *eeepc) 333 { 334 return eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_TOUCHPAD_LED); 335 } 336 337 static enum led_brightness tpd_led_get(struct led_classdev *led_cdev) 338 { 339 struct eeepc_wmi *eeepc; 340 341 eeepc = container_of(led_cdev, struct eeepc_wmi, tpd_led); 342 343 return read_tpd_led_state(eeepc); 344 } 345 346 static int eeepc_wmi_led_init(struct eeepc_wmi *eeepc) 347 { 348 int rv; 349 350 if (read_tpd_led_state(eeepc) < 0) 351 return 0; 352 353 eeepc->led_workqueue = create_singlethread_workqueue("led_workqueue"); 354 if (!eeepc->led_workqueue) 355 return -ENOMEM; 356 INIT_WORK(&eeepc->tpd_led_work, tpd_led_update); 357 358 eeepc->tpd_led.name = "eeepc::touchpad"; 359 eeepc->tpd_led.brightness_set = tpd_led_set; 360 eeepc->tpd_led.brightness_get = tpd_led_get; 361 eeepc->tpd_led.max_brightness = 1; 362 363 rv = led_classdev_register(&eeepc->platform_device->dev, 364 &eeepc->tpd_led); 365 if (rv) { 366 destroy_workqueue(eeepc->led_workqueue); 367 return rv; 368 } 369 370 return 0; 371 } 372 373 static void eeepc_wmi_led_exit(struct eeepc_wmi *eeepc) 374 { 375 if (eeepc->tpd_led.dev) 376 led_classdev_unregister(&eeepc->tpd_led); 377 if (eeepc->led_workqueue) 378 destroy_workqueue(eeepc->led_workqueue); 379 } 380 381 /* 382 * PCI hotplug (for wlan rfkill) 383 */ 384 static bool eeepc_wlan_rfkill_blocked(struct eeepc_wmi *eeepc) 385 { 386 int result = eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_WLAN); 387 388 if (result < 0) 389 return false; 390 return !result; 391 } 392 393 static void eeepc_rfkill_hotplug(struct eeepc_wmi *eeepc) 394 { 395 struct pci_dev *dev; 396 struct pci_bus *bus; 397 bool blocked; 398 bool absent; 399 u32 l; 400 401 mutex_lock(&eeepc->wmi_lock); 402 blocked = eeepc_wlan_rfkill_blocked(eeepc); 403 mutex_unlock(&eeepc->wmi_lock); 404 405 mutex_lock(&eeepc->hotplug_lock); 406 407 if (eeepc->wlan_rfkill) 408 rfkill_set_sw_state(eeepc->wlan_rfkill, blocked); 409 410 if (eeepc->hotplug_slot) { 411 bus = pci_find_bus(0, 1); 412 if (!bus) { 413 pr_warning("Unable to find PCI bus 1?\n"); 414 goto out_unlock; 415 } 416 417 if (pci_bus_read_config_dword(bus, 0, PCI_VENDOR_ID, &l)) { 418 pr_err("Unable to read PCI config space?\n"); 419 goto out_unlock; 420 } 421 absent = (l == 0xffffffff); 422 423 if (blocked != absent) { 424 pr_warning("BIOS says wireless lan is %s, " 425 "but the pci device is %s\n", 426 blocked ? "blocked" : "unblocked", 427 absent ? "absent" : "present"); 428 pr_warning("skipped wireless hotplug as probably " 429 "inappropriate for this model\n"); 430 goto out_unlock; 431 } 432 433 if (!blocked) { 434 dev = pci_get_slot(bus, 0); 435 if (dev) { 436 /* Device already present */ 437 pci_dev_put(dev); 438 goto out_unlock; 439 } 440 dev = pci_scan_single_device(bus, 0); 441 if (dev) { 442 pci_bus_assign_resources(bus); 443 if (pci_bus_add_device(dev)) 444 pr_err("Unable to hotplug wifi\n"); 445 } 446 } else { 447 dev = pci_get_slot(bus, 0); 448 if (dev) { 449 pci_remove_bus_device(dev); 450 pci_dev_put(dev); 451 } 452 } 453 } 454 455 out_unlock: 456 mutex_unlock(&eeepc->hotplug_lock); 457 } 458 459 static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data) 460 { 461 struct eeepc_wmi *eeepc = data; 462 463 if (event != ACPI_NOTIFY_BUS_CHECK) 464 return; 465 466 /* 467 * We can't call directly eeepc_rfkill_hotplug because most 468 * of the time WMBC is still being executed and not reetrant. 469 * There is currently no way to tell ACPICA that we want this 470 * method to be serialized, we schedule a eeepc_rfkill_hotplug 471 * call later, in a safer context. 472 */ 473 queue_work(eeepc->hotplug_workqueue, &eeepc->hotplug_work); 474 } 475 476 static int eeepc_register_rfkill_notifier(struct eeepc_wmi *eeepc, 477 char *node) 478 { 479 acpi_status status; 480 acpi_handle handle; 481 482 status = acpi_get_handle(NULL, node, &handle); 483 484 if (ACPI_SUCCESS(status)) { 485 status = acpi_install_notify_handler(handle, 486 ACPI_SYSTEM_NOTIFY, 487 eeepc_rfkill_notify, 488 eeepc); 489 if (ACPI_FAILURE(status)) 490 pr_warning("Failed to register notify on %s\n", node); 491 } else 492 return -ENODEV; 493 494 return 0; 495 } 496 497 static void eeepc_unregister_rfkill_notifier(struct eeepc_wmi *eeepc, 498 char *node) 499 { 500 acpi_status status = AE_OK; 501 acpi_handle handle; 502 503 status = acpi_get_handle(NULL, node, &handle); 504 505 if (ACPI_SUCCESS(status)) { 506 status = acpi_remove_notify_handler(handle, 507 ACPI_SYSTEM_NOTIFY, 508 eeepc_rfkill_notify); 509 if (ACPI_FAILURE(status)) 510 pr_err("Error removing rfkill notify handler %s\n", 511 node); 512 } 513 } 514 515 static int eeepc_get_adapter_status(struct hotplug_slot *hotplug_slot, 516 u8 *value) 517 { 518 int result = eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_WLAN); 519 520 if (result < 0) 521 return result; 522 523 *value = !!result; 524 return 0; 525 } 526 527 static void eeepc_cleanup_pci_hotplug(struct hotplug_slot *hotplug_slot) 528 { 529 kfree(hotplug_slot->info); 530 kfree(hotplug_slot); 531 } 532 533 static struct hotplug_slot_ops eeepc_hotplug_slot_ops = { 534 .owner = THIS_MODULE, 535 .get_adapter_status = eeepc_get_adapter_status, 536 .get_power_status = eeepc_get_adapter_status, 537 }; 538 539 static void eeepc_hotplug_work(struct work_struct *work) 540 { 541 struct eeepc_wmi *eeepc; 542 543 eeepc = container_of(work, struct eeepc_wmi, hotplug_work); 544 eeepc_rfkill_hotplug(eeepc); 545 } 546 547 static int eeepc_setup_pci_hotplug(struct eeepc_wmi *eeepc) 548 { 549 int ret = -ENOMEM; 550 struct pci_bus *bus = pci_find_bus(0, 1); 551 552 if (!bus) { 553 pr_err("Unable to find wifi PCI bus\n"); 554 return -ENODEV; 555 } 556 557 eeepc->hotplug_workqueue = 558 create_singlethread_workqueue("hotplug_workqueue"); 559 if (!eeepc->hotplug_workqueue) 560 goto error_workqueue; 561 562 INIT_WORK(&eeepc->hotplug_work, eeepc_hotplug_work); 563 564 eeepc->hotplug_slot = kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL); 565 if (!eeepc->hotplug_slot) 566 goto error_slot; 567 568 eeepc->hotplug_slot->info = kzalloc(sizeof(struct hotplug_slot_info), 569 GFP_KERNEL); 570 if (!eeepc->hotplug_slot->info) 571 goto error_info; 572 573 eeepc->hotplug_slot->private = eeepc; 574 eeepc->hotplug_slot->release = &eeepc_cleanup_pci_hotplug; 575 eeepc->hotplug_slot->ops = &eeepc_hotplug_slot_ops; 576 eeepc_get_adapter_status(eeepc->hotplug_slot, 577 &eeepc->hotplug_slot->info->adapter_status); 578 579 ret = pci_hp_register(eeepc->hotplug_slot, bus, 0, "eeepc-wifi"); 580 if (ret) { 581 pr_err("Unable to register hotplug slot - %d\n", ret); 582 goto error_register; 583 } 584 585 return 0; 586 587 error_register: 588 kfree(eeepc->hotplug_slot->info); 589 error_info: 590 kfree(eeepc->hotplug_slot); 591 eeepc->hotplug_slot = NULL; 592 error_slot: 593 destroy_workqueue(eeepc->hotplug_workqueue); 594 error_workqueue: 595 return ret; 596 } 597 598 /* 599 * Rfkill devices 600 */ 601 static int eeepc_rfkill_set(void *data, bool blocked) 602 { 603 int dev_id = (unsigned long)data; 604 u32 ctrl_param = !blocked; 605 acpi_status status; 606 607 status = eeepc_wmi_set_devstate(dev_id, ctrl_param, NULL); 608 609 if (ACPI_FAILURE(status)) 610 return -EIO; 611 612 return 0; 613 } 614 615 static void eeepc_rfkill_query(struct rfkill *rfkill, void *data) 616 { 617 int dev_id = (unsigned long)data; 618 int result; 619 620 result = eeepc_wmi_get_devstate_simple(dev_id); 621 622 if (result < 0) 623 return ; 624 625 rfkill_set_sw_state(rfkill, !result); 626 } 627 628 static int eeepc_rfkill_wlan_set(void *data, bool blocked) 629 { 630 struct eeepc_wmi *eeepc = data; 631 int ret; 632 633 /* 634 * This handler is enabled only if hotplug is enabled. 635 * In this case, the eeepc_wmi_set_devstate() will 636 * trigger a wmi notification and we need to wait 637 * this call to finish before being able to call 638 * any wmi method 639 */ 640 mutex_lock(&eeepc->wmi_lock); 641 ret = eeepc_rfkill_set((void *)(long)EEEPC_WMI_DEVID_WLAN, blocked); 642 mutex_unlock(&eeepc->wmi_lock); 643 return ret; 644 } 645 646 static void eeepc_rfkill_wlan_query(struct rfkill *rfkill, void *data) 647 { 648 eeepc_rfkill_query(rfkill, (void *)(long)EEEPC_WMI_DEVID_WLAN); 649 } 650 651 static const struct rfkill_ops eeepc_rfkill_wlan_ops = { 652 .set_block = eeepc_rfkill_wlan_set, 653 .query = eeepc_rfkill_wlan_query, 654 }; 655 656 static const struct rfkill_ops eeepc_rfkill_ops = { 657 .set_block = eeepc_rfkill_set, 658 .query = eeepc_rfkill_query, 659 }; 660 661 static int eeepc_new_rfkill(struct eeepc_wmi *eeepc, 662 struct rfkill **rfkill, 663 const char *name, 664 enum rfkill_type type, int dev_id) 665 { 666 int result = eeepc_wmi_get_devstate_simple(dev_id); 667 668 if (result < 0) 669 return result; 670 671 if (dev_id == EEEPC_WMI_DEVID_WLAN && eeepc->hotplug_wireless) 672 *rfkill = rfkill_alloc(name, &eeepc->platform_device->dev, type, 673 &eeepc_rfkill_wlan_ops, eeepc); 674 else 675 *rfkill = rfkill_alloc(name, &eeepc->platform_device->dev, type, 676 &eeepc_rfkill_ops, (void *)(long)dev_id); 677 678 if (!*rfkill) 679 return -EINVAL; 680 681 rfkill_init_sw_state(*rfkill, !result); 682 result = rfkill_register(*rfkill); 683 if (result) { 684 rfkill_destroy(*rfkill); 685 *rfkill = NULL; 686 return result; 687 } 688 return 0; 689 } 690 691 static void eeepc_wmi_rfkill_exit(struct eeepc_wmi *eeepc) 692 { 693 eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P5"); 694 eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P6"); 695 eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P7"); 696 if (eeepc->wlan_rfkill) { 697 rfkill_unregister(eeepc->wlan_rfkill); 698 rfkill_destroy(eeepc->wlan_rfkill); 699 eeepc->wlan_rfkill = NULL; 700 } 701 /* 702 * Refresh pci hotplug in case the rfkill state was changed after 703 * eeepc_unregister_rfkill_notifier() 704 */ 705 eeepc_rfkill_hotplug(eeepc); 706 if (eeepc->hotplug_slot) 707 pci_hp_deregister(eeepc->hotplug_slot); 708 if (eeepc->hotplug_workqueue) 709 destroy_workqueue(eeepc->hotplug_workqueue); 710 711 if (eeepc->bluetooth_rfkill) { 712 rfkill_unregister(eeepc->bluetooth_rfkill); 713 rfkill_destroy(eeepc->bluetooth_rfkill); 714 eeepc->bluetooth_rfkill = NULL; 715 } 716 if (eeepc->wimax_rfkill) { 717 rfkill_unregister(eeepc->wimax_rfkill); 718 rfkill_destroy(eeepc->wimax_rfkill); 719 eeepc->wimax_rfkill = NULL; 720 } 721 if (eeepc->wwan3g_rfkill) { 722 rfkill_unregister(eeepc->wwan3g_rfkill); 723 rfkill_destroy(eeepc->wwan3g_rfkill); 724 eeepc->wwan3g_rfkill = NULL; 725 } 726 } 727 728 static int eeepc_wmi_rfkill_init(struct eeepc_wmi *eeepc) 729 { 730 int result = 0; 731 732 mutex_init(&eeepc->hotplug_lock); 733 mutex_init(&eeepc->wmi_lock); 734 735 result = eeepc_new_rfkill(eeepc, &eeepc->wlan_rfkill, 736 "eeepc-wlan", RFKILL_TYPE_WLAN, 737 EEEPC_WMI_DEVID_WLAN); 738 739 if (result && result != -ENODEV) 740 goto exit; 741 742 result = eeepc_new_rfkill(eeepc, &eeepc->bluetooth_rfkill, 743 "eeepc-bluetooth", RFKILL_TYPE_BLUETOOTH, 744 EEEPC_WMI_DEVID_BLUETOOTH); 745 746 if (result && result != -ENODEV) 747 goto exit; 748 749 result = eeepc_new_rfkill(eeepc, &eeepc->wimax_rfkill, 750 "eeepc-wimax", RFKILL_TYPE_WIMAX, 751 EEEPC_WMI_DEVID_WIMAX); 752 753 if (result && result != -ENODEV) 754 goto exit; 755 756 result = eeepc_new_rfkill(eeepc, &eeepc->wwan3g_rfkill, 757 "eeepc-wwan3g", RFKILL_TYPE_WWAN, 758 EEEPC_WMI_DEVID_WWAN3G); 759 760 if (result && result != -ENODEV) 761 goto exit; 762 763 if (!eeepc->hotplug_wireless) 764 goto exit; 765 766 result = eeepc_setup_pci_hotplug(eeepc); 767 /* 768 * If we get -EBUSY then something else is handling the PCI hotplug - 769 * don't fail in this case 770 */ 771 if (result == -EBUSY) 772 result = 0; 773 774 eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P5"); 775 eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P6"); 776 eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P7"); 777 /* 778 * Refresh pci hotplug in case the rfkill state was changed during 779 * setup. 780 */ 781 eeepc_rfkill_hotplug(eeepc); 782 783 exit: 784 if (result && result != -ENODEV) 785 eeepc_wmi_rfkill_exit(eeepc); 786 787 if (result == -ENODEV) 788 result = 0; 789 790 return result; 791 } 792 793 /* 794 * Backlight 795 */ 796 static int read_backlight_power(void) 797 { 798 int ret = eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_BACKLIGHT); 799 800 if (ret < 0) 801 return ret; 802 803 return ret ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN; 804 } 805 806 static int read_brightness(struct backlight_device *bd) 807 { 808 u32 retval; 809 acpi_status status; 810 811 status = eeepc_wmi_get_devstate(EEEPC_WMI_DEVID_BRIGHTNESS, &retval); 812 813 if (ACPI_FAILURE(status)) 814 return -EIO; 815 else 816 return retval & EEEPC_WMI_DSTS_BRIGHTNESS_MASK; 817 } 818 819 static int update_bl_status(struct backlight_device *bd) 820 { 821 u32 ctrl_param; 822 acpi_status status; 823 int power; 824 825 ctrl_param = bd->props.brightness; 826 827 status = eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_BRIGHTNESS, 828 ctrl_param, NULL); 829 830 if (ACPI_FAILURE(status)) 831 return -EIO; 832 833 power = read_backlight_power(); 834 if (power != -ENODEV && bd->props.power != power) { 835 ctrl_param = !!(bd->props.power == FB_BLANK_UNBLANK); 836 status = eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_BACKLIGHT, 837 ctrl_param, NULL); 838 839 if (ACPI_FAILURE(status)) 840 return -EIO; 841 } 842 return 0; 843 } 844 845 static const struct backlight_ops eeepc_wmi_bl_ops = { 846 .get_brightness = read_brightness, 847 .update_status = update_bl_status, 848 }; 849 850 static int eeepc_wmi_backlight_notify(struct eeepc_wmi *eeepc, int code) 851 { 852 struct backlight_device *bd = eeepc->backlight_device; 853 int old = bd->props.brightness; 854 int new = old; 855 856 if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX) 857 new = code - NOTIFY_BRNUP_MIN + 1; 858 else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX) 859 new = code - NOTIFY_BRNDOWN_MIN; 860 861 bd->props.brightness = new; 862 backlight_update_status(bd); 863 backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY); 864 865 return old; 866 } 867 868 static int eeepc_wmi_backlight_init(struct eeepc_wmi *eeepc) 869 { 870 struct backlight_device *bd; 871 struct backlight_properties props; 872 int max; 873 int power; 874 875 max = eeepc_wmi_get_devstate_bits(EEEPC_WMI_DEVID_BRIGHTNESS, 876 EEEPC_WMI_DSTS_MAX_BRIGTH_MASK); 877 power = read_backlight_power(); 878 879 if (max < 0 && power < 0) { 880 /* Try to keep the original error */ 881 if (max == -ENODEV && power == -ENODEV) 882 return -ENODEV; 883 if (max != -ENODEV) 884 return max; 885 else 886 return power; 887 } 888 if (max == -ENODEV) 889 max = 0; 890 if (power == -ENODEV) 891 power = FB_BLANK_UNBLANK; 892 893 memset(&props, 0, sizeof(struct backlight_properties)); 894 props.max_brightness = max; 895 bd = backlight_device_register(EEEPC_WMI_FILE, 896 &eeepc->platform_device->dev, eeepc, 897 &eeepc_wmi_bl_ops, &props); 898 if (IS_ERR(bd)) { 899 pr_err("Could not register backlight device\n"); 900 return PTR_ERR(bd); 901 } 902 903 eeepc->backlight_device = bd; 904 905 bd->props.brightness = read_brightness(bd); 906 bd->props.power = power; 907 backlight_update_status(bd); 908 909 return 0; 910 } 911 912 static void eeepc_wmi_backlight_exit(struct eeepc_wmi *eeepc) 913 { 914 if (eeepc->backlight_device) 915 backlight_device_unregister(eeepc->backlight_device); 916 917 eeepc->backlight_device = NULL; 918 } 919 920 static void eeepc_wmi_notify(u32 value, void *context) 921 { 922 struct eeepc_wmi *eeepc = context; 923 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; 924 union acpi_object *obj; 925 acpi_status status; 926 int code; 927 int orig_code; 928 929 status = wmi_get_event_data(value, &response); 930 if (status != AE_OK) { 931 pr_err("bad event status 0x%x\n", status); 932 return; 933 } 934 935 obj = (union acpi_object *)response.pointer; 936 937 if (obj && obj->type == ACPI_TYPE_INTEGER) { 938 code = obj->integer.value; 939 orig_code = code; 940 941 if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX) 942 code = NOTIFY_BRNUP_MIN; 943 else if (code >= NOTIFY_BRNDOWN_MIN && 944 code <= NOTIFY_BRNDOWN_MAX) 945 code = NOTIFY_BRNDOWN_MIN; 946 947 if (code == NOTIFY_BRNUP_MIN || code == NOTIFY_BRNDOWN_MIN) { 948 if (!acpi_video_backlight_support()) 949 eeepc_wmi_backlight_notify(eeepc, orig_code); 950 } 951 952 if (!sparse_keymap_report_event(eeepc->inputdev, 953 code, 1, true)) 954 pr_info("Unknown key %x pressed\n", code); 955 } 956 957 kfree(obj); 958 } 959 960 /* 961 * Sys helpers 962 */ 963 static int parse_arg(const char *buf, unsigned long count, int *val) 964 { 965 if (!count) 966 return 0; 967 if (sscanf(buf, "%i", val) != 1) 968 return -EINVAL; 969 return count; 970 } 971 972 static ssize_t store_sys_wmi(int devid, const char *buf, size_t count) 973 { 974 acpi_status status; 975 u32 retval; 976 int rv, value; 977 978 value = eeepc_wmi_get_devstate_simple(devid); 979 if (value == -ENODEV) /* Check device presence */ 980 return value; 981 982 rv = parse_arg(buf, count, &value); 983 status = eeepc_wmi_set_devstate(devid, value, &retval); 984 985 if (ACPI_FAILURE(status)) 986 return -EIO; 987 return rv; 988 } 989 990 static ssize_t show_sys_wmi(int devid, char *buf) 991 { 992 int value = eeepc_wmi_get_devstate_simple(devid); 993 994 if (value < 0) 995 return value; 996 997 return sprintf(buf, "%d\n", value); 998 } 999 1000 #define EEEPC_WMI_CREATE_DEVICE_ATTR(_name, _mode, _cm) \ 1001 static ssize_t show_##_name(struct device *dev, \ 1002 struct device_attribute *attr, \ 1003 char *buf) \ 1004 { \ 1005 return show_sys_wmi(_cm, buf); \ 1006 } \ 1007 static ssize_t store_##_name(struct device *dev, \ 1008 struct device_attribute *attr, \ 1009 const char *buf, size_t count) \ 1010 { \ 1011 return store_sys_wmi(_cm, buf, count); \ 1012 } \ 1013 static struct device_attribute dev_attr_##_name = { \ 1014 .attr = { \ 1015 .name = __stringify(_name), \ 1016 .mode = _mode }, \ 1017 .show = show_##_name, \ 1018 .store = store_##_name, \ 1019 } 1020 1021 EEEPC_WMI_CREATE_DEVICE_ATTR(touchpad, 0644, EEEPC_WMI_DEVID_TOUCHPAD); 1022 EEEPC_WMI_CREATE_DEVICE_ATTR(camera, 0644, EEEPC_WMI_DEVID_CAMERA); 1023 EEEPC_WMI_CREATE_DEVICE_ATTR(cardr, 0644, EEEPC_WMI_DEVID_CARDREADER); 1024 1025 static ssize_t store_cpufv(struct device *dev, struct device_attribute *attr, 1026 const char *buf, size_t count) 1027 { 1028 int value; 1029 struct acpi_buffer input = { (acpi_size)sizeof(value), &value }; 1030 acpi_status status; 1031 1032 if (!count || sscanf(buf, "%i", &value) != 1) 1033 return -EINVAL; 1034 if (value < 0 || value > 2) 1035 return -EINVAL; 1036 1037 status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID, 1038 1, EEEPC_WMI_METHODID_CFVS, &input, NULL); 1039 1040 if (ACPI_FAILURE(status)) 1041 return -EIO; 1042 else 1043 return count; 1044 } 1045 1046 static DEVICE_ATTR(cpufv, S_IRUGO | S_IWUSR, NULL, store_cpufv); 1047 1048 static struct attribute *platform_attributes[] = { 1049 &dev_attr_cpufv.attr, 1050 &dev_attr_camera.attr, 1051 &dev_attr_cardr.attr, 1052 &dev_attr_touchpad.attr, 1053 NULL 1054 }; 1055 1056 static mode_t eeepc_sysfs_is_visible(struct kobject *kobj, 1057 struct attribute *attr, 1058 int idx) 1059 { 1060 bool supported = true; 1061 int devid = -1; 1062 1063 if (attr == &dev_attr_camera.attr) 1064 devid = EEEPC_WMI_DEVID_CAMERA; 1065 else if (attr == &dev_attr_cardr.attr) 1066 devid = EEEPC_WMI_DEVID_CARDREADER; 1067 else if (attr == &dev_attr_touchpad.attr) 1068 devid = EEEPC_WMI_DEVID_TOUCHPAD; 1069 1070 if (devid != -1) 1071 supported = eeepc_wmi_get_devstate_simple(devid) != -ENODEV; 1072 1073 return supported ? attr->mode : 0; 1074 } 1075 1076 static struct attribute_group platform_attribute_group = { 1077 .is_visible = eeepc_sysfs_is_visible, 1078 .attrs = platform_attributes 1079 }; 1080 1081 static void eeepc_wmi_sysfs_exit(struct platform_device *device) 1082 { 1083 sysfs_remove_group(&device->dev.kobj, &platform_attribute_group); 1084 } 1085 1086 static int eeepc_wmi_sysfs_init(struct platform_device *device) 1087 { 1088 return sysfs_create_group(&device->dev.kobj, &platform_attribute_group); 1089 } 1090 1091 /* 1092 * Platform device 1093 */ 1094 static int __init eeepc_wmi_platform_init(struct eeepc_wmi *eeepc) 1095 { 1096 return eeepc_wmi_sysfs_init(eeepc->platform_device); 1097 } 1098 1099 static void eeepc_wmi_platform_exit(struct eeepc_wmi *eeepc) 1100 { 1101 eeepc_wmi_sysfs_exit(eeepc->platform_device); 1102 } 1103 1104 /* 1105 * debugfs 1106 */ 1107 struct eeepc_wmi_debugfs_node { 1108 struct eeepc_wmi *eeepc; 1109 char *name; 1110 int (*show)(struct seq_file *m, void *data); 1111 }; 1112 1113 static int show_dsts(struct seq_file *m, void *data) 1114 { 1115 struct eeepc_wmi *eeepc = m->private; 1116 acpi_status status; 1117 u32 retval = -1; 1118 1119 status = eeepc_wmi_get_devstate(eeepc->debug.dev_id, &retval); 1120 1121 if (ACPI_FAILURE(status)) 1122 return -EIO; 1123 1124 seq_printf(m, "DSTS(%x) = %x\n", eeepc->debug.dev_id, retval); 1125 1126 return 0; 1127 } 1128 1129 static int show_devs(struct seq_file *m, void *data) 1130 { 1131 struct eeepc_wmi *eeepc = m->private; 1132 acpi_status status; 1133 u32 retval = -1; 1134 1135 status = eeepc_wmi_set_devstate(eeepc->debug.dev_id, 1136 eeepc->debug.ctrl_param, &retval); 1137 if (ACPI_FAILURE(status)) 1138 return -EIO; 1139 1140 seq_printf(m, "DEVS(%x, %x) = %x\n", eeepc->debug.dev_id, 1141 eeepc->debug.ctrl_param, retval); 1142 1143 return 0; 1144 } 1145 1146 static struct eeepc_wmi_debugfs_node eeepc_wmi_debug_files[] = { 1147 { NULL, "devs", show_devs }, 1148 { NULL, "dsts", show_dsts }, 1149 }; 1150 1151 static int eeepc_wmi_debugfs_open(struct inode *inode, struct file *file) 1152 { 1153 struct eeepc_wmi_debugfs_node *node = inode->i_private; 1154 1155 return single_open(file, node->show, node->eeepc); 1156 } 1157 1158 static const struct file_operations eeepc_wmi_debugfs_io_ops = { 1159 .owner = THIS_MODULE, 1160 .open = eeepc_wmi_debugfs_open, 1161 .read = seq_read, 1162 .llseek = seq_lseek, 1163 .release = single_release, 1164 }; 1165 1166 static void eeepc_wmi_debugfs_exit(struct eeepc_wmi *eeepc) 1167 { 1168 debugfs_remove_recursive(eeepc->debug.root); 1169 } 1170 1171 static int eeepc_wmi_debugfs_init(struct eeepc_wmi *eeepc) 1172 { 1173 struct dentry *dent; 1174 int i; 1175 1176 eeepc->debug.root = debugfs_create_dir(EEEPC_WMI_FILE, NULL); 1177 if (!eeepc->debug.root) { 1178 pr_err("failed to create debugfs directory"); 1179 goto error_debugfs; 1180 } 1181 1182 dent = debugfs_create_x32("dev_id", S_IRUGO|S_IWUSR, 1183 eeepc->debug.root, &eeepc->debug.dev_id); 1184 if (!dent) 1185 goto error_debugfs; 1186 1187 dent = debugfs_create_x32("ctrl_param", S_IRUGO|S_IWUSR, 1188 eeepc->debug.root, &eeepc->debug.ctrl_param); 1189 if (!dent) 1190 goto error_debugfs; 1191 1192 for (i = 0; i < ARRAY_SIZE(eeepc_wmi_debug_files); i++) { 1193 struct eeepc_wmi_debugfs_node *node = &eeepc_wmi_debug_files[i]; 1194 1195 node->eeepc = eeepc; 1196 dent = debugfs_create_file(node->name, S_IFREG | S_IRUGO, 1197 eeepc->debug.root, node, 1198 &eeepc_wmi_debugfs_io_ops); 1199 if (!dent) { 1200 pr_err("failed to create debug file: %s\n", node->name); 1201 goto error_debugfs; 1202 } 1203 } 1204 1205 return 0; 1206 1207 error_debugfs: 1208 eeepc_wmi_debugfs_exit(eeepc); 1209 return -ENOMEM; 1210 } 1211 1212 /* 1213 * WMI Driver 1214 */ 1215 static void eeepc_dmi_check(struct eeepc_wmi *eeepc) 1216 { 1217 const char *model; 1218 1219 model = dmi_get_system_info(DMI_PRODUCT_NAME); 1220 if (!model) 1221 return; 1222 1223 /* 1224 * Whitelist for wlan hotplug 1225 * 1226 * Eeepc 1000H needs the current hotplug code to handle 1227 * Fn+F2 correctly. We may add other Eeepc here later, but 1228 * it seems that most of the laptops supported by eeepc-wmi 1229 * don't need to be on this list 1230 */ 1231 if (strcmp(model, "1000H") == 0) { 1232 eeepc->hotplug_wireless = true; 1233 pr_info("wlan hotplug enabled\n"); 1234 } 1235 } 1236 1237 static int __init eeepc_wmi_add(struct platform_device *pdev) 1238 { 1239 struct eeepc_wmi *eeepc; 1240 acpi_status status; 1241 int err; 1242 1243 eeepc = kzalloc(sizeof(struct eeepc_wmi), GFP_KERNEL); 1244 if (!eeepc) 1245 return -ENOMEM; 1246 1247 eeepc->platform_device = pdev; 1248 platform_set_drvdata(eeepc->platform_device, eeepc); 1249 1250 eeepc->hotplug_wireless = hotplug_wireless; 1251 eeepc_dmi_check(eeepc); 1252 1253 err = eeepc_wmi_platform_init(eeepc); 1254 if (err) 1255 goto fail_platform; 1256 1257 err = eeepc_wmi_input_init(eeepc); 1258 if (err) 1259 goto fail_input; 1260 1261 err = eeepc_wmi_led_init(eeepc); 1262 if (err) 1263 goto fail_leds; 1264 1265 err = eeepc_wmi_rfkill_init(eeepc); 1266 if (err) 1267 goto fail_rfkill; 1268 1269 if (!acpi_video_backlight_support()) { 1270 err = eeepc_wmi_backlight_init(eeepc); 1271 if (err && err != -ENODEV) 1272 goto fail_backlight; 1273 } else 1274 pr_info("Backlight controlled by ACPI video driver\n"); 1275 1276 status = wmi_install_notify_handler(EEEPC_WMI_EVENT_GUID, 1277 eeepc_wmi_notify, eeepc); 1278 if (ACPI_FAILURE(status)) { 1279 pr_err("Unable to register notify handler - %d\n", 1280 status); 1281 err = -ENODEV; 1282 goto fail_wmi_handler; 1283 } 1284 1285 err = eeepc_wmi_debugfs_init(eeepc); 1286 if (err) 1287 goto fail_debugfs; 1288 1289 return 0; 1290 1291 fail_debugfs: 1292 wmi_remove_notify_handler(EEEPC_WMI_EVENT_GUID); 1293 fail_wmi_handler: 1294 eeepc_wmi_backlight_exit(eeepc); 1295 fail_backlight: 1296 eeepc_wmi_rfkill_exit(eeepc); 1297 fail_rfkill: 1298 eeepc_wmi_led_exit(eeepc); 1299 fail_leds: 1300 eeepc_wmi_input_exit(eeepc); 1301 fail_input: 1302 eeepc_wmi_platform_exit(eeepc); 1303 fail_platform: 1304 kfree(eeepc); 1305 return err; 1306 } 1307 1308 static int __exit eeepc_wmi_remove(struct platform_device *device) 1309 { 1310 struct eeepc_wmi *eeepc; 1311 1312 eeepc = platform_get_drvdata(device); 1313 wmi_remove_notify_handler(EEEPC_WMI_EVENT_GUID); 1314 eeepc_wmi_backlight_exit(eeepc); 1315 eeepc_wmi_input_exit(eeepc); 1316 eeepc_wmi_led_exit(eeepc); 1317 eeepc_wmi_rfkill_exit(eeepc); 1318 eeepc_wmi_debugfs_exit(eeepc); 1319 eeepc_wmi_platform_exit(eeepc); 1320 1321 kfree(eeepc); 1322 return 0; 1323 } 1324 1325 /* 1326 * Platform driver - hibernate/resume callbacks 1327 */ 1328 static int eeepc_hotk_thaw(struct device *device) 1329 { 1330 struct eeepc_wmi *eeepc = dev_get_drvdata(device); 1331 1332 if (eeepc->wlan_rfkill) { 1333 bool wlan; 1334 1335 /* 1336 * Work around bios bug - acpi _PTS turns off the wireless led 1337 * during suspend. Normally it restores it on resume, but 1338 * we should kick it ourselves in case hibernation is aborted. 1339 */ 1340 wlan = eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_WLAN); 1341 eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_WLAN, wlan, NULL); 1342 } 1343 1344 return 0; 1345 } 1346 1347 static int eeepc_hotk_restore(struct device *device) 1348 { 1349 struct eeepc_wmi *eeepc = dev_get_drvdata(device); 1350 int bl; 1351 1352 /* Refresh both wlan rfkill state and pci hotplug */ 1353 if (eeepc->wlan_rfkill) 1354 eeepc_rfkill_hotplug(eeepc); 1355 1356 if (eeepc->bluetooth_rfkill) { 1357 bl = !eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_BLUETOOTH); 1358 rfkill_set_sw_state(eeepc->bluetooth_rfkill, bl); 1359 } 1360 if (eeepc->wimax_rfkill) { 1361 bl = !eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_WIMAX); 1362 rfkill_set_sw_state(eeepc->wimax_rfkill, bl); 1363 } 1364 if (eeepc->wwan3g_rfkill) { 1365 bl = !eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_WWAN3G); 1366 rfkill_set_sw_state(eeepc->wwan3g_rfkill, bl); 1367 } 1368 1369 return 0; 1370 } 1371 1372 static const struct dev_pm_ops eeepc_pm_ops = { 1373 .thaw = eeepc_hotk_thaw, 1374 .restore = eeepc_hotk_restore, 1375 }; 1376 1377 static struct platform_driver platform_driver = { 1378 .remove = __exit_p(eeepc_wmi_remove), 1379 .driver = { 1380 .name = EEEPC_WMI_FILE, 1381 .owner = THIS_MODULE, 1382 .pm = &eeepc_pm_ops, 1383 }, 1384 }; 1385 1386 static acpi_status __init eeepc_wmi_parse_device(acpi_handle handle, u32 level, 1387 void *context, void **retval) 1388 { 1389 pr_warning("Found legacy ATKD device (%s)", EEEPC_ACPI_HID); 1390 *(bool *)context = true; 1391 return AE_CTRL_TERMINATE; 1392 } 1393 1394 static int __init eeepc_wmi_check_atkd(void) 1395 { 1396 acpi_status status; 1397 bool found = false; 1398 1399 status = acpi_get_devices(EEEPC_ACPI_HID, eeepc_wmi_parse_device, 1400 &found, NULL); 1401 1402 if (ACPI_FAILURE(status) || !found) 1403 return 0; 1404 return -1; 1405 } 1406 1407 static int __init eeepc_wmi_probe(struct platform_device *pdev) 1408 { 1409 if (!wmi_has_guid(EEEPC_WMI_EVENT_GUID) || 1410 !wmi_has_guid(EEEPC_WMI_MGMT_GUID)) { 1411 pr_warning("No known WMI GUID found\n"); 1412 return -ENODEV; 1413 } 1414 1415 if (eeepc_wmi_check_atkd()) { 1416 pr_warning("WMI device present, but legacy ATKD device is also " 1417 "present and enabled."); 1418 pr_warning("You probably booted with acpi_osi=\"Linux\" or " 1419 "acpi_osi=\"!Windows 2009\""); 1420 pr_warning("Can't load eeepc-wmi, use default acpi_osi " 1421 "(preferred) or eeepc-laptop"); 1422 return -ENODEV; 1423 } 1424 1425 return eeepc_wmi_add(pdev); 1426 } 1427 1428 static struct platform_device *platform_device; 1429 1430 static int __init eeepc_wmi_init(void) 1431 { 1432 platform_device = platform_create_bundle(&platform_driver, 1433 eeepc_wmi_probe, 1434 NULL, 0, NULL, 0); 1435 if (IS_ERR(platform_device)) 1436 return PTR_ERR(platform_device); 1437 return 0; 1438 } 1439 1440 static void __exit eeepc_wmi_exit(void) 1441 { 1442 platform_device_unregister(platform_device); 1443 platform_driver_unregister(&platform_driver); 1444 } 1445 1446 module_init(eeepc_wmi_init); 1447 module_exit(eeepc_wmi_exit); 1448