asus-laptop.c revision 17e78f6260fbc8f55c279cca081c26c88d96ec00
1/* 2 * asus-laptop.c - Asus Laptop Support 3 * 4 * 5 * Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor 6 * Copyright (C) 2006-2007 Corentin Chary 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 * 22 * 23 * The development page for this driver is located at 24 * http://sourceforge.net/projects/acpi4asus/ 25 * 26 * Credits: 27 * Pontus Fuchs - Helper functions, cleanup 28 * Johann Wiesner - Small compile fixes 29 * John Belmonte - ACPI code for Toshiba laptop was a good starting point. 30 * Eric Burghard - LED display support for W1N 31 * Josh Green - Light Sens support 32 * Thomas Tuttle - His first patch for led support was very helpfull 33 * Sam Lin - GPS support 34 */ 35 36#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 37 38#include <linux/kernel.h> 39#include <linux/module.h> 40#include <linux/init.h> 41#include <linux/types.h> 42#include <linux/err.h> 43#include <linux/proc_fs.h> 44#include <linux/backlight.h> 45#include <linux/fb.h> 46#include <linux/leds.h> 47#include <linux/platform_device.h> 48#include <acpi/acpi_drivers.h> 49#include <acpi/acpi_bus.h> 50#include <asm/uaccess.h> 51#include <linux/input.h> 52 53#define ASUS_LAPTOP_VERSION "0.42" 54 55#define ASUS_LAPTOP_NAME "Asus Laptop Support" 56#define ASUS_LAPTOP_CLASS "hotkey" 57#define ASUS_LAPTOP_DEVICE_NAME "Hotkey" 58#define ASUS_LAPTOP_FILE KBUILD_MODNAME 59#define ASUS_LAPTOP_PREFIX "\\_SB.ATKD." 60 61MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary"); 62MODULE_DESCRIPTION(ASUS_LAPTOP_NAME); 63MODULE_LICENSE("GPL"); 64 65/* 66 * WAPF defines the behavior of the Fn+Fx wlan key 67 * The significance of values is yet to be found, but 68 * most of the time: 69 * 0x0 will do nothing 70 * 0x1 will allow to control the device with Fn+Fx key. 71 * 0x4 will send an ACPI event (0x88) while pressing the Fn+Fx key 72 * 0x5 like 0x1 or 0x4 73 * So, if something doesn't work as you want, just try other values =) 74 */ 75static uint wapf = 1; 76module_param(wapf, uint, 0644); 77MODULE_PARM_DESC(wapf, "WAPF value"); 78 79static uint wireless_status = 1; 80static uint bluetooth_status = 1; 81 82module_param(wireless_status, uint, 0644); 83MODULE_PARM_DESC(wireless_status, "Set the wireless status on boot " 84 "(0 = disabled, 1 = enabled, -1 = don't do anything). " 85 "default is 1"); 86 87module_param(bluetooth_status, uint, 0644); 88MODULE_PARM_DESC(bluetooth_status, "Set the wireless status on boot " 89 "(0 = disabled, 1 = enabled, -1 = don't do anything). " 90 "default is 1"); 91 92/* 93 * Some events we use, same for all Asus 94 */ 95#define ATKD_BR_UP 0x10 96#define ATKD_BR_DOWN 0x20 97#define ATKD_LCD_ON 0x33 98#define ATKD_LCD_OFF 0x34 99 100/* 101 * Known bits returned by \_SB.ATKD.HWRS 102 */ 103#define WL_HWRS 0x80 104#define BT_HWRS 0x100 105 106/* 107 * Flags for hotk status 108 * WL_ON and BT_ON are also used for wireless_status() 109 */ 110#define WL_RSTS 0x01 /* internal Wifi */ 111#define BT_RSTS 0x02 /* internal Bluetooth */ 112 113#define ASUS_HANDLE(object, paths...) \ 114 static acpi_handle object##_handle = NULL; \ 115 static char *object##_paths[] = { paths } 116 117/* LED */ 118ASUS_HANDLE(mled_set, ASUS_LAPTOP_PREFIX "MLED"); 119ASUS_HANDLE(tled_set, ASUS_LAPTOP_PREFIX "TLED"); 120ASUS_HANDLE(rled_set, ASUS_LAPTOP_PREFIX "RLED"); /* W1JC */ 121ASUS_HANDLE(pled_set, ASUS_LAPTOP_PREFIX "PLED"); /* A7J */ 122ASUS_HANDLE(gled_set, ASUS_LAPTOP_PREFIX "GLED"); /* G1, G2 (probably) */ 123 124/* LEDD */ 125ASUS_HANDLE(ledd_set, ASUS_LAPTOP_PREFIX "SLCM"); 126 127/* 128 * Bluetooth and WLAN 129 * WLED and BLED are not handled like other XLED, because in some dsdt 130 * they also control the WLAN/Bluetooth device. 131 */ 132ASUS_HANDLE(wl_switch, ASUS_LAPTOP_PREFIX "WLED"); 133ASUS_HANDLE(bt_switch, ASUS_LAPTOP_PREFIX "BLED"); 134ASUS_HANDLE(wireless_status, ASUS_LAPTOP_PREFIX "RSTS"); /* All new models */ 135 136/* Brightness */ 137ASUS_HANDLE(brightness_set, ASUS_LAPTOP_PREFIX "SPLV"); 138ASUS_HANDLE(brightness_get, ASUS_LAPTOP_PREFIX "GPLV"); 139 140/* Backlight */ 141ASUS_HANDLE(lcd_switch, "\\_SB.PCI0.SBRG.EC0._Q10", /* All new models */ 142 "\\_SB.PCI0.ISA.EC0._Q10", /* A1x */ 143 "\\_SB.PCI0.PX40.ECD0._Q10", /* L3C */ 144 "\\_SB.PCI0.PX40.EC0.Q10", /* M1A */ 145 "\\_SB.PCI0.LPCB.EC0._Q10", /* P30 */ 146 "\\_SB.PCI0.LPCB.EC0._Q0E", /* P30/P35 */ 147 "\\_SB.PCI0.PX40.Q10", /* S1x */ 148 "\\Q10"); /* A2x, L2D, L3D, M2E */ 149 150/* Display */ 151ASUS_HANDLE(display_set, ASUS_LAPTOP_PREFIX "SDSP"); 152ASUS_HANDLE(display_get, 153 /* A6B, A6K A6R A7D F3JM L4R M6R A3G M6A M6V VX-1 V6J V6V W3Z */ 154 "\\_SB.PCI0.P0P1.VGA.GETD", 155 /* A3E A4K, A4D A4L A6J A7J A8J Z71V M9V S5A M5A z33A W1Jc W2V G1 */ 156 "\\_SB.PCI0.P0P2.VGA.GETD", 157 /* A6V A6Q */ 158 "\\_SB.PCI0.P0P3.VGA.GETD", 159 /* A6T, A6M */ 160 "\\_SB.PCI0.P0PA.VGA.GETD", 161 /* L3C */ 162 "\\_SB.PCI0.PCI1.VGAC.NMAP", 163 /* Z96F */ 164 "\\_SB.PCI0.VGA.GETD", 165 /* A2D */ 166 "\\ACTD", 167 /* A4G Z71A W1N W5A W5F M2N M3N M5N M6N S1N S5N */ 168 "\\ADVG", 169 /* P30 */ 170 "\\DNXT", 171 /* A2H D1 L2D L3D L3H L2E L5D L5C M1A M2E L4L W3V */ 172 "\\INFB", 173 /* A3F A6F A3N A3L M6N W3N W6A */ 174 "\\SSTE"); 175 176ASUS_HANDLE(ls_switch, ASUS_LAPTOP_PREFIX "ALSC"); /* Z71A Z71V */ 177ASUS_HANDLE(ls_level, ASUS_LAPTOP_PREFIX "ALSL"); /* Z71A Z71V */ 178 179/* GPS */ 180/* R2H use different handle for GPS on/off */ 181ASUS_HANDLE(gps_on, ASUS_LAPTOP_PREFIX "SDON"); /* R2H */ 182ASUS_HANDLE(gps_off, ASUS_LAPTOP_PREFIX "SDOF"); /* R2H */ 183ASUS_HANDLE(gps_status, ASUS_LAPTOP_PREFIX "GPST"); 184 185/* Keyboard light */ 186ASUS_HANDLE(kled_set, ASUS_LAPTOP_PREFIX "SLKB"); 187ASUS_HANDLE(kled_get, ASUS_LAPTOP_PREFIX "GLKB"); 188 189/* 190 * Define a specific led structure to keep the main structure clean 191 */ 192#define ASUS_DEFINE_LED(object) \ 193 int object##_wk; \ 194 struct work_struct object##_work; \ 195 struct led_classdev object; 196 197 198#define led_to_asus(led_cdev, led) \ 199 container_of(container_of(led_cdev, struct asus_laptop_leds, \ 200 led), \ 201 struct asus_laptop, leds) 202#define work_to_asus(work, led) \ 203 container_of(container_of(work, struct asus_laptop_leds, \ 204 led##_work), \ 205 struct asus_laptop, leds) 206 207struct asus_laptop_leds { 208 ASUS_DEFINE_LED(mled) 209 ASUS_DEFINE_LED(tled) 210 ASUS_DEFINE_LED(rled) 211 ASUS_DEFINE_LED(pled) 212 ASUS_DEFINE_LED(gled) 213 ASUS_DEFINE_LED(kled) 214 struct workqueue_struct *workqueue; 215}; 216 217/* 218 * This is the main structure, we can use it to store anything interesting 219 * about the hotk device 220 */ 221struct asus_laptop { 222 char *name; /* laptop name */ 223 224 struct acpi_table_header *dsdt_info; 225 struct platform_device *platform_device; 226 struct acpi_device *device; /* the device we are in */ 227 struct backlight_device *backlight_device; 228 229 struct input_dev *inputdev; 230 struct key_entry *keymap; 231 232 struct asus_laptop_leds leds; 233 234 int wireless_status; 235 bool have_rsts; 236 int lcd_state; 237 238 acpi_handle handle; /* the handle of the hotk device */ 239 u32 ledd_status; /* status of the LED display */ 240 u8 light_level; /* light sensor level */ 241 u8 light_switch; /* light sensor switch value */ 242 u16 event_count[128]; /* count for each event TODO make this better */ 243 u16 *keycode_map; 244}; 245 246struct key_entry { 247 char type; 248 u8 code; 249 u16 keycode; 250}; 251 252enum { KE_KEY, KE_END }; 253 254static const struct key_entry asus_keymap[] = { 255 {KE_KEY, 0x02, KEY_SCREENLOCK}, 256 {KE_KEY, 0x05, KEY_WLAN}, 257 {KE_KEY, 0x08, KEY_F13}, 258 {KE_KEY, 0x17, KEY_ZOOM}, 259 {KE_KEY, 0x1f, KEY_BATTERY}, 260 {KE_KEY, 0x30, KEY_VOLUMEUP}, 261 {KE_KEY, 0x31, KEY_VOLUMEDOWN}, 262 {KE_KEY, 0x32, KEY_MUTE}, 263 {KE_KEY, 0x33, KEY_SWITCHVIDEOMODE}, 264 {KE_KEY, 0x34, KEY_SWITCHVIDEOMODE}, 265 {KE_KEY, 0x40, KEY_PREVIOUSSONG}, 266 {KE_KEY, 0x41, KEY_NEXTSONG}, 267 {KE_KEY, 0x43, KEY_STOPCD}, 268 {KE_KEY, 0x45, KEY_PLAYPAUSE}, 269 {KE_KEY, 0x4c, KEY_MEDIA}, 270 {KE_KEY, 0x50, KEY_EMAIL}, 271 {KE_KEY, 0x51, KEY_WWW}, 272 {KE_KEY, 0x55, KEY_CALC}, 273 {KE_KEY, 0x5C, KEY_SCREENLOCK}, /* Screenlock */ 274 {KE_KEY, 0x5D, KEY_WLAN}, 275 {KE_KEY, 0x5E, KEY_WLAN}, 276 {KE_KEY, 0x5F, KEY_WLAN}, 277 {KE_KEY, 0x60, KEY_SWITCHVIDEOMODE}, 278 {KE_KEY, 0x61, KEY_SWITCHVIDEOMODE}, 279 {KE_KEY, 0x62, KEY_SWITCHVIDEOMODE}, 280 {KE_KEY, 0x63, KEY_SWITCHVIDEOMODE}, 281 {KE_KEY, 0x6B, KEY_F13}, /* Lock Touchpad */ 282 {KE_KEY, 0x82, KEY_CAMERA}, 283 {KE_KEY, 0x88, KEY_WLAN }, 284 {KE_KEY, 0x8A, KEY_PROG1}, 285 {KE_KEY, 0x95, KEY_MEDIA}, 286 {KE_KEY, 0x99, KEY_PHONE}, 287 {KE_KEY, 0xc4, KEY_KBDILLUMUP}, 288 {KE_KEY, 0xc5, KEY_KBDILLUMDOWN}, 289 {KE_END, 0}, 290}; 291 292/* 293 * This function evaluates an ACPI method, given an int as parameter, the 294 * method is searched within the scope of the handle, can be NULL. The output 295 * of the method is written is output, which can also be NULL 296 * 297 * returns 0 if write is successful, -1 else. 298 */ 299static int write_acpi_int_ret(acpi_handle handle, const char *method, int val, 300 struct acpi_buffer *output) 301{ 302 struct acpi_object_list params; /* list of input parameters (an int) */ 303 union acpi_object in_obj; /* the only param we use */ 304 acpi_status status; 305 306 if (!handle) 307 return 0; 308 309 params.count = 1; 310 params.pointer = &in_obj; 311 in_obj.type = ACPI_TYPE_INTEGER; 312 in_obj.integer.value = val; 313 314 status = acpi_evaluate_object(handle, (char *)method, ¶ms, output); 315 if (status == AE_OK) 316 return 0; 317 else 318 return -1; 319} 320 321static int write_acpi_int(acpi_handle handle, const char *method, int val) 322{ 323 return write_acpi_int_ret(handle, method, val, NULL); 324} 325 326/* Generic LED function */ 327static void asus_led_set(struct asus_laptop *asus, acpi_handle handle, 328 int value) 329{ 330 if (handle == mled_set_handle) 331 value = !value; 332 else if (handle == gled_set_handle) 333 value = !value + 1; 334 else 335 value = !!value; 336 337 write_acpi_int(handle, NULL, value); 338} 339 340/* 341 * LEDs 342 */ 343#define ASUS_LED(object, ledname, max) \ 344 static void object##_led_set(struct led_classdev *led_cdev, \ 345 enum led_brightness value); \ 346 static enum led_brightness object##_led_get( \ 347 struct led_classdev *led_cdev); \ 348 static void object##_led_update(struct work_struct *ignored); \ 349 static struct led_classdev object##_led = { \ 350 .name = "asus::" ledname, \ 351 .brightness_set = object##_led_set, \ 352 .brightness_get = object##_led_get, \ 353 .max_brightness = max \ 354 } 355 356ASUS_LED(mled, "mail", 1); 357ASUS_LED(tled, "touchpad", 1); 358ASUS_LED(rled, "record", 1); 359ASUS_LED(pled, "phone", 1); 360ASUS_LED(gled, "gaming", 1); 361ASUS_LED(kled, "kbd_backlight", 3); 362 363/* /sys/class/led handlers */ 364#define ASUS_LED_HANDLER(object, mask) \ 365 static void object##_led_set(struct led_classdev *led_cdev, \ 366 enum led_brightness value) \ 367 { \ 368 struct asus_laptop *asus = \ 369 led_to_asus(led_cdev, object); \ 370 \ 371 asus->leds.object##_wk = (value > 0) ? 1 : 0; \ 372 queue_work(asus->leds.workqueue, \ 373 &asus->leds.object##_work); \ 374 } \ 375 static void object##_led_update(struct work_struct *work) \ 376 { \ 377 struct asus_laptop *asus = work_to_asus(work, object); \ 378 \ 379 int value = asus->leds.object##_wk; \ 380 asus_led_set(asus, object##_set_handle, value); \ 381 } \ 382 static enum led_brightness object##_led_get( \ 383 struct led_classdev *led_cdev) \ 384 { \ 385 return led_cdev->brightness; \ 386 } 387 388ASUS_LED_HANDLER(mled, MLED_ON); 389ASUS_LED_HANDLER(pled, PLED_ON); 390ASUS_LED_HANDLER(rled, RLED_ON); 391ASUS_LED_HANDLER(tled, TLED_ON); 392ASUS_LED_HANDLER(gled, GLED_ON); 393 394/* 395 * Keyboard backlight (also a LED) 396 */ 397static int get_kled_lvl(void) 398{ 399 unsigned long long kblv; 400 struct acpi_object_list params; 401 union acpi_object in_obj; 402 acpi_status rv; 403 404 params.count = 1; 405 params.pointer = &in_obj; 406 in_obj.type = ACPI_TYPE_INTEGER; 407 in_obj.integer.value = 2; 408 409 rv = acpi_evaluate_integer(kled_get_handle, NULL, ¶ms, &kblv); 410 if (ACPI_FAILURE(rv)) { 411 pr_warning("Error reading kled level\n"); 412 return 0; 413 } 414 return kblv; 415} 416 417static int set_kled_lvl(struct asus_laptop *asus, int kblv) 418{ 419 if (kblv > 0) 420 kblv = (1 << 7) | (kblv & 0x7F); 421 else 422 kblv = 0; 423 424 if (write_acpi_int(kled_set_handle, NULL, kblv)) { 425 pr_warning("Keyboard LED display write failed\n"); 426 return -EINVAL; 427 } 428 return 0; 429} 430 431static void kled_led_set(struct led_classdev *led_cdev, 432 enum led_brightness value) 433{ 434 struct asus_laptop *asus = led_to_asus(led_cdev, kled); 435 436 asus->leds.kled_wk = value; 437 queue_work(asus->leds.workqueue, &asus->leds.kled_work); 438} 439 440static void kled_led_update(struct work_struct *work) 441{ 442 struct asus_laptop *asus = work_to_asus(work, kled); 443 444 set_kled_lvl(asus, asus->leds.kled_wk); 445} 446 447static enum led_brightness kled_led_get(struct led_classdev *led_cdev) 448{ 449 return get_kled_lvl(); 450} 451 452#define ASUS_LED_UNREGISTER(object) \ 453 if (object##_led.dev) \ 454 led_classdev_unregister(&object##_led) 455 456static void asus_led_exit(struct asus_laptop *asus) 457{ 458 ASUS_LED_UNREGISTER(mled); 459 ASUS_LED_UNREGISTER(tled); 460 ASUS_LED_UNREGISTER(pled); 461 ASUS_LED_UNREGISTER(rled); 462 ASUS_LED_UNREGISTER(gled); 463 ASUS_LED_UNREGISTER(kled); 464 if (asus->leds.workqueue) { 465 destroy_workqueue(asus->leds.workqueue); 466 asus->leds.workqueue = NULL; 467 } 468} 469 470/* Ugly macro, need to fix that later */ 471#define ASUS_LED_REGISTER(asus, object, _name, max) \ 472 do { \ 473 struct led_classdev *ldev = &asus->leds.object; \ 474 if (!object##_set_handle) \ 475 break ; \ 476 \ 477 INIT_WORK(&asus->leds.object##_work, object##_led_update); \ 478 ldev->name = "asus::" _name; \ 479 ldev->brightness_set = object##_led_set; \ 480 ldev->max_brightness = max; \ 481 rv = led_classdev_register(&asus->platform_device->dev, ldev); \ 482 if (rv) \ 483 goto error; \ 484 } while (0) 485 486static int asus_led_init(struct asus_laptop *asus) 487{ 488 int rv; 489 490 /* 491 * Functions that actually update the LED's are called from a 492 * workqueue. By doing this as separate work rather than when the LED 493 * subsystem asks, we avoid messing with the Asus ACPI stuff during a 494 * potentially bad time, such as a timer interrupt. 495 */ 496 asus->leds.workqueue = create_singlethread_workqueue("led_workqueue"); 497 if (!asus->leds.workqueue) 498 return -ENOMEM; 499 500 ASUS_LED_REGISTER(asus, mled, "mail", 1); 501 ASUS_LED_REGISTER(asus, tled, "touchpad", 1); 502 ASUS_LED_REGISTER(asus, rled, "record", 1); 503 ASUS_LED_REGISTER(asus, pled, "phone", 1); 504 ASUS_LED_REGISTER(asus, gled, "gaming", 1); 505 if (kled_set_handle && kled_get_handle) 506 ASUS_LED_REGISTER(asus, kled, "kbd_backlight", 3); 507error: 508 if (rv) 509 asus_led_exit(asus); 510 return rv; 511} 512 513/* 514 * Backlight device 515 */ 516static int asus_lcd_status(struct asus_laptop *asus) 517{ 518 return asus->lcd_state; 519} 520 521static int asus_lcd_set(struct asus_laptop *asus, int value) 522{ 523 int lcd = 0; 524 acpi_status status = 0; 525 526 lcd = !!value; 527 528 if (lcd == asus_lcd_status(asus)) 529 return 0; 530 531 if (!lcd_switch_handle) 532 return -ENODEV; 533 534 status = acpi_evaluate_object(lcd_switch_handle, 535 NULL, NULL, NULL); 536 537 if (ACPI_FAILURE(status)) { 538 pr_warning("Error switching LCD\n"); 539 return -ENODEV; 540 } 541 542 asus->lcd_state = lcd; 543 return 0; 544} 545 546static void lcd_blank(struct asus_laptop *asus, int blank) 547{ 548 struct backlight_device *bd = asus->backlight_device; 549 550 asus->lcd_state = (blank == FB_BLANK_UNBLANK); 551 552 if (bd) { 553 bd->props.power = blank; 554 backlight_update_status(bd); 555 } 556} 557 558static int read_brightness(struct backlight_device *bd) 559{ 560 unsigned long long value; 561 acpi_status rv = AE_OK; 562 563 rv = acpi_evaluate_integer(brightness_get_handle, NULL, NULL, &value); 564 if (ACPI_FAILURE(rv)) 565 pr_warning("Error reading brightness\n"); 566 567 return value; 568} 569 570static int set_brightness(struct backlight_device *bd, int value) 571{ 572 if (write_acpi_int(brightness_set_handle, NULL, value)) { 573 pr_warning("Error changing brightness\n"); 574 return -EIO; 575 } 576 return 0; 577} 578 579static int update_bl_status(struct backlight_device *bd) 580{ 581 struct asus_laptop *asus = bl_get_data(bd); 582 int rv; 583 int value = bd->props.brightness; 584 585 rv = set_brightness(bd, value); 586 if (rv) 587 return rv; 588 589 value = (bd->props.power == FB_BLANK_UNBLANK) ? 1 : 0; 590 return asus_lcd_set(asus, value); 591} 592 593static struct backlight_ops asusbl_ops = { 594 .get_brightness = read_brightness, 595 .update_status = update_bl_status, 596}; 597 598static int asus_backlight_init(struct asus_laptop *asus) 599{ 600 struct backlight_device *bd; 601 struct device *dev = &asus->platform_device->dev; 602 603 if (brightness_set_handle && lcd_switch_handle) { 604 bd = backlight_device_register(ASUS_LAPTOP_FILE, dev, 605 asus, &asusbl_ops); 606 if (IS_ERR(bd)) { 607 pr_err("Could not register asus backlight device\n"); 608 asus->backlight_device = NULL; 609 return PTR_ERR(bd); 610 } 611 612 asus->backlight_device = bd; 613 614 bd->props.max_brightness = 15; 615 bd->props.brightness = read_brightness(NULL); 616 bd->props.power = FB_BLANK_UNBLANK; 617 backlight_update_status(bd); 618 } 619 return 0; 620} 621 622static void asus_backlight_exit(struct asus_laptop *asus) 623{ 624 if (asus->backlight_device) 625 backlight_device_unregister(asus->backlight_device); 626} 627 628/* 629 * Platform device handlers 630 */ 631 632/* 633 * We write our info in page, we begin at offset off and cannot write more 634 * than count bytes. We set eof to 1 if we handle those 2 values. We return the 635 * number of bytes written in page 636 */ 637static ssize_t show_infos(struct device *dev, 638 struct device_attribute *attr, char *page) 639{ 640 struct asus_laptop *asus = dev_get_drvdata(dev); 641 int len = 0; 642 unsigned long long temp; 643 char buf[16]; /* enough for all info */ 644 acpi_status rv = AE_OK; 645 646 /* 647 * We use the easy way, we don't care of off and count, so we don't set eof 648 * to 1 649 */ 650 651 len += sprintf(page, ASUS_LAPTOP_NAME " " ASUS_LAPTOP_VERSION "\n"); 652 len += sprintf(page + len, "Model reference : %s\n", asus->name); 653 /* 654 * The SFUN method probably allows the original driver to get the list 655 * of features supported by a given model. For now, 0x0100 or 0x0800 656 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card. 657 * The significance of others is yet to be found. 658 */ 659 rv = acpi_evaluate_integer(asus->handle, "SFUN", NULL, &temp); 660 if (!ACPI_FAILURE(rv)) 661 len += sprintf(page + len, "SFUN value : %#x\n", 662 (uint) temp); 663 /* 664 * The HWRS method return informations about the hardware. 665 * 0x80 bit is for WLAN, 0x100 for Bluetooth. 666 * The significance of others is yet to be found. 667 * If we don't find the method, we assume the device are present. 668 */ 669 rv = acpi_evaluate_integer(asus->handle, "HRWS", NULL, &temp); 670 if (!ACPI_FAILURE(rv)) 671 len += sprintf(page + len, "HRWS value : %#x\n", 672 (uint) temp); 673 /* 674 * Another value for userspace: the ASYM method returns 0x02 for 675 * battery low and 0x04 for battery critical, its readings tend to be 676 * more accurate than those provided by _BST. 677 * Note: since not all the laptops provide this method, errors are 678 * silently ignored. 679 */ 680 rv = acpi_evaluate_integer(asus->handle, "ASYM", NULL, &temp); 681 if (!ACPI_FAILURE(rv)) 682 len += sprintf(page + len, "ASYM value : %#x\n", 683 (uint) temp); 684 if (asus->dsdt_info) { 685 snprintf(buf, 16, "%d", asus->dsdt_info->length); 686 len += sprintf(page + len, "DSDT length : %s\n", buf); 687 snprintf(buf, 16, "%d", asus->dsdt_info->checksum); 688 len += sprintf(page + len, "DSDT checksum : %s\n", buf); 689 snprintf(buf, 16, "%d", asus->dsdt_info->revision); 690 len += sprintf(page + len, "DSDT revision : %s\n", buf); 691 snprintf(buf, 7, "%s", asus->dsdt_info->oem_id); 692 len += sprintf(page + len, "OEM id : %s\n", buf); 693 snprintf(buf, 9, "%s", asus->dsdt_info->oem_table_id); 694 len += sprintf(page + len, "OEM table id : %s\n", buf); 695 snprintf(buf, 16, "%x", asus->dsdt_info->oem_revision); 696 len += sprintf(page + len, "OEM revision : 0x%s\n", buf); 697 snprintf(buf, 5, "%s", asus->dsdt_info->asl_compiler_id); 698 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf); 699 snprintf(buf, 16, "%x", asus->dsdt_info->asl_compiler_revision); 700 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf); 701 } 702 703 return len; 704} 705 706static int parse_arg(const char *buf, unsigned long count, int *val) 707{ 708 if (!count) 709 return 0; 710 if (count > 31) 711 return -EINVAL; 712 if (sscanf(buf, "%i", val) != 1) 713 return -EINVAL; 714 return count; 715} 716 717static ssize_t sysfs_acpi_set(struct asus_laptop *asus, 718 const char *buf, size_t count, 719 acpi_handle handle) 720{ 721 int rv, value; 722 int out = 0; 723 724 rv = parse_arg(buf, count, &value); 725 if (rv > 0) 726 out = value ? 1 : 0; 727 728 if (write_acpi_int(handle, NULL, value)) 729 return -ENODEV; 730 return rv; 731} 732 733/* 734 * LEDD display 735 */ 736static ssize_t show_ledd(struct device *dev, 737 struct device_attribute *attr, char *buf) 738{ 739 struct asus_laptop *asus = dev_get_drvdata(dev); 740 741 return sprintf(buf, "0x%08x\n", asus->ledd_status); 742} 743 744static ssize_t store_ledd(struct device *dev, struct device_attribute *attr, 745 const char *buf, size_t count) 746{ 747 struct asus_laptop *asus = dev_get_drvdata(dev); 748 int rv, value; 749 750 rv = parse_arg(buf, count, &value); 751 if (rv > 0) { 752 if (write_acpi_int(ledd_set_handle, NULL, value)) 753 pr_warning("LED display write failed\n"); 754 else 755 asus->ledd_status = (u32) value; 756 } 757 return rv; 758} 759 760/* 761 * Wireless 762 */ 763static int asus_wireless_status(struct asus_laptop *asus, int mask) 764{ 765 unsigned long long status; 766 acpi_status rv = AE_OK; 767 768 if (!asus->have_rsts) 769 return (asus->wireless_status & mask) ? 1 : 0; 770 771 rv = acpi_evaluate_integer(wireless_status_handle, NULL, NULL, &status); 772 if (ACPI_FAILURE(rv)) { 773 pr_warning("Error reading Wireless status\n"); 774 return -EINVAL; 775 } 776 return !!(status & mask); 777} 778 779/* 780 * WLAN 781 */ 782static ssize_t show_wlan(struct device *dev, 783 struct device_attribute *attr, char *buf) 784{ 785 struct asus_laptop *asus = dev_get_drvdata(dev); 786 787 return sprintf(buf, "%d\n", asus_wireless_status(asus, WL_RSTS)); 788} 789 790static ssize_t store_wlan(struct device *dev, struct device_attribute *attr, 791 const char *buf, size_t count) 792{ 793 struct asus_laptop *asus = dev_get_drvdata(dev); 794 795 return sysfs_acpi_set(asus, buf, count, wl_switch_handle); 796} 797 798/* 799 * Bluetooth 800 */ 801static ssize_t show_bluetooth(struct device *dev, 802 struct device_attribute *attr, char *buf) 803{ 804 struct asus_laptop *asus = dev_get_drvdata(dev); 805 806 return sprintf(buf, "%d\n", asus_wireless_status(asus, BT_RSTS)); 807} 808 809static ssize_t store_bluetooth(struct device *dev, 810 struct device_attribute *attr, const char *buf, 811 size_t count) 812{ 813 struct asus_laptop *asus = dev_get_drvdata(dev); 814 815 return sysfs_acpi_set(asus, buf, count, bt_switch_handle); 816} 817 818/* 819 * Display 820 */ 821static void set_display(struct asus_laptop *asus, int value) 822{ 823 /* no sanity check needed for now */ 824 if (write_acpi_int(display_set_handle, NULL, value)) 825 pr_warning("Error setting display\n"); 826 return; 827} 828 829static int read_display(struct asus_laptop *asus) 830{ 831 unsigned long long value = 0; 832 acpi_status rv = AE_OK; 833 834 /* 835 * In most of the case, we know how to set the display, but sometime 836 * we can't read it 837 */ 838 if (display_get_handle) { 839 rv = acpi_evaluate_integer(display_get_handle, NULL, 840 NULL, &value); 841 if (ACPI_FAILURE(rv)) 842 pr_warning("Error reading display status\n"); 843 } 844 845 value &= 0x0F; /* needed for some models, shouldn't hurt others */ 846 847 return value; 848} 849 850/* 851 * Now, *this* one could be more user-friendly, but so far, no-one has 852 * complained. The significance of bits is the same as in store_disp() 853 */ 854static ssize_t show_disp(struct device *dev, 855 struct device_attribute *attr, char *buf) 856{ 857 struct asus_laptop *asus = dev_get_drvdata(dev); 858 859 return sprintf(buf, "%d\n", read_display(asus)); 860} 861 862/* 863 * Experimental support for display switching. As of now: 1 should activate 864 * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI. 865 * Any combination (bitwise) of these will suffice. I never actually tested 4 866 * displays hooked up simultaneously, so be warned. See the acpi4asus README 867 * for more info. 868 */ 869static ssize_t store_disp(struct device *dev, struct device_attribute *attr, 870 const char *buf, size_t count) 871{ 872 struct asus_laptop *asus = dev_get_drvdata(dev); 873 int rv, value; 874 875 rv = parse_arg(buf, count, &value); 876 if (rv > 0) 877 set_display(asus, value); 878 return rv; 879} 880 881/* 882 * Light Sens 883 */ 884static void set_light_sens_switch(struct asus_laptop *asus, int value) 885{ 886 if (write_acpi_int(ls_switch_handle, NULL, value)) 887 pr_warning("Error setting light sensor switch\n"); 888 asus->light_switch = value; 889} 890 891static ssize_t show_lssw(struct device *dev, 892 struct device_attribute *attr, char *buf) 893{ 894 struct asus_laptop *asus = dev_get_drvdata(dev); 895 896 return sprintf(buf, "%d\n", asus->light_switch); 897} 898 899static ssize_t store_lssw(struct device *dev, struct device_attribute *attr, 900 const char *buf, size_t count) 901{ 902 struct asus_laptop *asus = dev_get_drvdata(dev); 903 int rv, value; 904 905 rv = parse_arg(buf, count, &value); 906 if (rv > 0) 907 set_light_sens_switch(asus, value ? 1 : 0); 908 909 return rv; 910} 911 912static void set_light_sens_level(struct asus_laptop *asus, int value) 913{ 914 if (write_acpi_int(ls_level_handle, NULL, value)) 915 pr_warning("Error setting light sensor level\n"); 916 asus->light_level = value; 917} 918 919static ssize_t show_lslvl(struct device *dev, 920 struct device_attribute *attr, char *buf) 921{ 922 struct asus_laptop *asus = dev_get_drvdata(dev); 923 924 return sprintf(buf, "%d\n", asus->light_level); 925} 926 927static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr, 928 const char *buf, size_t count) 929{ 930 struct asus_laptop *asus = dev_get_drvdata(dev); 931 int rv, value; 932 933 rv = parse_arg(buf, count, &value); 934 if (rv > 0) { 935 value = (0 < value) ? ((15 < value) ? 15 : value) : 0; 936 /* 0 <= value <= 15 */ 937 set_light_sens_level(asus, value); 938 } 939 940 return rv; 941} 942 943/* 944 * GPS 945 * TODO: use rfkill 946 */ 947static int asus_gps_status(struct asus_laptop *asus) 948{ 949 unsigned long long status; 950 acpi_status rv = AE_OK; 951 952 rv = acpi_evaluate_integer(gps_status_handle, NULL, NULL, &status); 953 if (ACPI_FAILURE(rv)) { 954 pr_warning("Error reading GPS status\n"); 955 return -ENODEV; 956 } 957 return !!status; 958} 959 960static int asus_gps_switch(struct asus_laptop *asus, int status) 961{ 962 acpi_handle handle = status ? gps_on_handle : gps_off_handle; 963 964 if (write_acpi_int(handle, NULL, 0x02)) 965 return -ENODEV; 966 return 0; 967} 968 969static ssize_t show_gps(struct device *dev, 970 struct device_attribute *attr, char *buf) 971{ 972 struct asus_laptop *asus = dev_get_drvdata(dev); 973 974 return sprintf(buf, "%d\n", asus_gps_status(asus)); 975} 976 977static ssize_t store_gps(struct device *dev, struct device_attribute *attr, 978 const char *buf, size_t count) 979{ 980 struct asus_laptop *asus = dev_get_drvdata(dev); 981 int rv, value; 982 int ret; 983 984 rv = parse_arg(buf, count, &value); 985 if (rv <= 0) 986 return -EINVAL; 987 ret = asus_gps_switch(asus, !!value); 988 if (ret) 989 return ret; 990 return rv; 991} 992 993/* 994 * Input device (i.e. hotkeys) 995 */ 996static struct key_entry *asus_get_entry_by_scancode(struct asus_laptop *asus, 997 int code) 998{ 999 struct key_entry *key; 1000 1001 for (key = asus->keymap; key->type != KE_END; key++) 1002 if (code == key->code) 1003 return key; 1004 1005 return NULL; 1006} 1007 1008static struct key_entry *asus_get_entry_by_keycode(struct asus_laptop *asus, 1009 int code) 1010{ 1011 struct key_entry *key; 1012 1013 for (key = asus->keymap; key->type != KE_END; key++) 1014 if (code == key->keycode && key->type == KE_KEY) 1015 return key; 1016 1017 return NULL; 1018} 1019 1020static int asus_getkeycode(struct input_dev *dev, int scancode, int *keycode) 1021{ 1022 struct asus_laptop *asus = input_get_drvdata(dev); 1023 struct key_entry *key = asus_get_entry_by_scancode(asus, scancode); 1024 1025 if (key && key->type == KE_KEY) { 1026 *keycode = key->keycode; 1027 return 0; 1028 } 1029 1030 return -EINVAL; 1031} 1032 1033static int asus_setkeycode(struct input_dev *dev, int scancode, int keycode) 1034{ 1035 struct asus_laptop *asus = input_get_drvdata(dev); 1036 struct key_entry *key; 1037 int old_keycode; 1038 1039 if (keycode < 0 || keycode > KEY_MAX) 1040 return -EINVAL; 1041 1042 key = asus_get_entry_by_scancode(asus, scancode); 1043 if (key && key->type == KE_KEY) { 1044 old_keycode = key->keycode; 1045 key->keycode = keycode; 1046 set_bit(keycode, dev->keybit); 1047 if (!asus_get_entry_by_keycode(asus, old_keycode)) 1048 clear_bit(old_keycode, dev->keybit); 1049 return 0; 1050 } 1051 1052 return -EINVAL; 1053} 1054 1055static void asus_input_notify(struct asus_laptop *asus, int event) 1056{ 1057 struct key_entry *key; 1058 1059 key = asus_get_entry_by_scancode(asus, event); 1060 if (!key) 1061 return ; 1062 1063 switch (key->type) { 1064 case KE_KEY: 1065 input_report_key(asus->inputdev, key->keycode, 1); 1066 input_sync(asus->inputdev); 1067 input_report_key(asus->inputdev, key->keycode, 0); 1068 input_sync(asus->inputdev); 1069 break; 1070 } 1071} 1072 1073static int asus_input_init(struct asus_laptop *asus) 1074{ 1075 const struct key_entry *key; 1076 int result; 1077 1078 asus->inputdev = input_allocate_device(); 1079 if (!asus->inputdev) { 1080 pr_info("Unable to allocate input device\n"); 1081 return 0; 1082 } 1083 asus->inputdev->name = "Asus Laptop extra buttons"; 1084 asus->inputdev->dev.parent = &asus->platform_device->dev; 1085 asus->inputdev->phys = ASUS_LAPTOP_FILE "/input0"; 1086 asus->inputdev->id.bustype = BUS_HOST; 1087 asus->inputdev->getkeycode = asus_getkeycode; 1088 asus->inputdev->setkeycode = asus_setkeycode; 1089 input_set_drvdata(asus->inputdev, asus); 1090 1091 asus->keymap = kmemdup(asus_keymap, sizeof(asus_keymap), 1092 GFP_KERNEL); 1093 for (key = asus->keymap; key->type != KE_END; key++) { 1094 switch (key->type) { 1095 case KE_KEY: 1096 set_bit(EV_KEY, asus->inputdev->evbit); 1097 set_bit(key->keycode, asus->inputdev->keybit); 1098 break; 1099 } 1100 } 1101 result = input_register_device(asus->inputdev); 1102 if (result) { 1103 pr_info("Unable to register input device\n"); 1104 input_free_device(asus->inputdev); 1105 } 1106 return result; 1107} 1108 1109static void asus_input_exit(struct asus_laptop *asus) 1110{ 1111 if (asus->inputdev) 1112 input_unregister_device(asus->inputdev); 1113} 1114 1115/* 1116 * ACPI driver 1117 */ 1118static void asus_acpi_notify(struct acpi_device *device, u32 event) 1119{ 1120 struct asus_laptop *asus = acpi_driver_data(device); 1121 u16 count; 1122 1123 /* 1124 * We need to tell the backlight device when the backlight power is 1125 * switched 1126 */ 1127 if (event == ATKD_LCD_ON) 1128 lcd_blank(asus, FB_BLANK_UNBLANK); 1129 else if (event == ATKD_LCD_OFF) 1130 lcd_blank(asus, FB_BLANK_POWERDOWN); 1131 1132 /* TODO Find a better way to handle events count. */ 1133 count = asus->event_count[event % 128]++; 1134 acpi_bus_generate_proc_event(asus->device, event, count); 1135 acpi_bus_generate_netlink_event(asus->device->pnp.device_class, 1136 dev_name(&asus->device->dev), event, 1137 count); 1138 1139 asus_input_notify(asus, event); 1140} 1141 1142#define ASUS_CREATE_DEVICE_ATTR(_name) \ 1143 struct device_attribute dev_attr_##_name = { \ 1144 .attr = { \ 1145 .name = __stringify(_name), \ 1146 .mode = 0 }, \ 1147 .show = NULL, \ 1148 .store = NULL, \ 1149 } 1150 1151#define ASUS_SET_DEVICE_ATTR(_name, _mode, _show, _store) \ 1152 do { \ 1153 dev_attr_##_name.attr.mode = _mode; \ 1154 dev_attr_##_name.show = _show; \ 1155 dev_attr_##_name.store = _store; \ 1156 } while(0) 1157 1158static ASUS_CREATE_DEVICE_ATTR(infos); 1159static ASUS_CREATE_DEVICE_ATTR(wlan); 1160static ASUS_CREATE_DEVICE_ATTR(bluetooth); 1161static ASUS_CREATE_DEVICE_ATTR(display); 1162static ASUS_CREATE_DEVICE_ATTR(ledd); 1163static ASUS_CREATE_DEVICE_ATTR(ls_switch); 1164static ASUS_CREATE_DEVICE_ATTR(ls_level); 1165static ASUS_CREATE_DEVICE_ATTR(gps); 1166 1167static struct attribute *asuspf_attributes[] = { 1168 &dev_attr_infos.attr, 1169 &dev_attr_wlan.attr, 1170 &dev_attr_bluetooth.attr, 1171 &dev_attr_display.attr, 1172 &dev_attr_ledd.attr, 1173 &dev_attr_ls_switch.attr, 1174 &dev_attr_ls_level.attr, 1175 &dev_attr_gps.attr, 1176 NULL 1177}; 1178 1179static struct attribute_group platform_attribute_group = { 1180 .attrs = asuspf_attributes 1181}; 1182 1183static int asus_platform_init(struct asus_laptop *asus) 1184{ 1185 int result; 1186 1187 asus->platform_device = platform_device_alloc(ASUS_LAPTOP_FILE, -1); 1188 if (!asus->platform_device) 1189 return -ENOMEM; 1190 platform_set_drvdata(asus->platform_device, asus); 1191 1192 result = platform_device_add(asus->platform_device); 1193 if (result) 1194 goto fail_platform_device; 1195 1196 result = sysfs_create_group(&asus->platform_device->dev.kobj, 1197 &platform_attribute_group); 1198 if (result) 1199 goto fail_sysfs; 1200 return 0; 1201 1202fail_sysfs: 1203 platform_device_del(asus->platform_device); 1204fail_platform_device: 1205 platform_device_put(asus->platform_device); 1206 return result; 1207} 1208 1209static void asus_platform_exit(struct asus_laptop *asus) 1210{ 1211 sysfs_remove_group(&asus->platform_device->dev.kobj, 1212 &platform_attribute_group); 1213 platform_device_unregister(asus->platform_device); 1214} 1215 1216static struct platform_driver platform_driver = { 1217 .driver = { 1218 .name = ASUS_LAPTOP_FILE, 1219 .owner = THIS_MODULE, 1220 } 1221}; 1222 1223static void asus_laptop_add_fs(struct asus_laptop *asus) 1224{ 1225 ASUS_SET_DEVICE_ATTR(infos, 0444, show_infos, NULL); 1226 1227 if (wl_switch_handle) 1228 ASUS_SET_DEVICE_ATTR(wlan, 0644, show_wlan, store_wlan); 1229 1230 if (bt_switch_handle) 1231 ASUS_SET_DEVICE_ATTR(bluetooth, 0644, 1232 show_bluetooth, store_bluetooth); 1233 1234 if (display_set_handle && display_get_handle) 1235 ASUS_SET_DEVICE_ATTR(display, 0644, show_disp, store_disp); 1236 else if (display_set_handle) 1237 ASUS_SET_DEVICE_ATTR(display, 0200, NULL, store_disp); 1238 1239 if (ledd_set_handle) 1240 ASUS_SET_DEVICE_ATTR(ledd, 0644, show_ledd, store_ledd); 1241 1242 if (ls_switch_handle && ls_level_handle) { 1243 ASUS_SET_DEVICE_ATTR(ls_level, 0644, show_lslvl, store_lslvl); 1244 ASUS_SET_DEVICE_ATTR(ls_switch, 0644, show_lssw, store_lssw); 1245 } 1246 1247 if (gps_status_handle && gps_on_handle && gps_off_handle) 1248 ASUS_SET_DEVICE_ATTR(gps, 0644, show_gps, store_gps); 1249} 1250 1251static int asus_handle_init(char *name, acpi_handle * handle, 1252 char **paths, int num_paths) 1253{ 1254 int i; 1255 acpi_status status; 1256 1257 for (i = 0; i < num_paths; i++) { 1258 status = acpi_get_handle(NULL, paths[i], handle); 1259 if (ACPI_SUCCESS(status)) 1260 return 0; 1261 } 1262 1263 *handle = NULL; 1264 return -ENODEV; 1265} 1266 1267#define ASUS_HANDLE_INIT(object) \ 1268 asus_handle_init(#object, &object##_handle, object##_paths, \ 1269 ARRAY_SIZE(object##_paths)) 1270 1271/* 1272 * This function is used to initialize the context with right values. In this 1273 * method, we can make all the detection we want, and modify the asus_laptop 1274 * struct 1275 */ 1276static int asus_laptop_get_info(struct asus_laptop *asus) 1277{ 1278 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 1279 union acpi_object *model = NULL; 1280 unsigned long long bsts_result, hwrs_result; 1281 char *string = NULL; 1282 acpi_status status; 1283 1284 /* 1285 * Get DSDT headers early enough to allow for differentiating between 1286 * models, but late enough to allow acpi_bus_register_driver() to fail 1287 * before doing anything ACPI-specific. Should we encounter a machine, 1288 * which needs special handling (i.e. its hotkey device has a different 1289 * HID), this bit will be moved. 1290 */ 1291 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus->dsdt_info); 1292 if (ACPI_FAILURE(status)) 1293 pr_warning("Couldn't get the DSDT table header\n"); 1294 1295 /* We have to write 0 on init this far for all ASUS models */ 1296 if (write_acpi_int_ret(asus->handle, "INIT", 0, &buffer)) { 1297 pr_err("Hotkey initialization failed\n"); 1298 return -ENODEV; 1299 } 1300 1301 /* This needs to be called for some laptops to init properly */ 1302 status = 1303 acpi_evaluate_integer(asus->handle, "BSTS", NULL, &bsts_result); 1304 if (ACPI_FAILURE(status)) 1305 pr_warning("Error calling BSTS\n"); 1306 else if (bsts_result) 1307 pr_notice("BSTS called, 0x%02x returned\n", 1308 (uint) bsts_result); 1309 1310 /* This too ... */ 1311 write_acpi_int(asus->handle, "CWAP", wapf); 1312 1313 /* 1314 * Try to match the object returned by INIT to the specific model. 1315 * Handle every possible object (or the lack of thereof) the DSDT 1316 * writers might throw at us. When in trouble, we pass NULL to 1317 * asus_model_match() and try something completely different. 1318 */ 1319 if (buffer.pointer) { 1320 model = buffer.pointer; 1321 switch (model->type) { 1322 case ACPI_TYPE_STRING: 1323 string = model->string.pointer; 1324 break; 1325 case ACPI_TYPE_BUFFER: 1326 string = model->buffer.pointer; 1327 break; 1328 default: 1329 string = ""; 1330 break; 1331 } 1332 } 1333 asus->name = kstrdup(string, GFP_KERNEL); 1334 if (!asus->name) 1335 return -ENOMEM; 1336 1337 if (*string) 1338 pr_notice(" %s model detected\n", string); 1339 1340 ASUS_HANDLE_INIT(mled_set); 1341 ASUS_HANDLE_INIT(tled_set); 1342 ASUS_HANDLE_INIT(rled_set); 1343 ASUS_HANDLE_INIT(pled_set); 1344 ASUS_HANDLE_INIT(gled_set); 1345 1346 ASUS_HANDLE_INIT(ledd_set); 1347 1348 ASUS_HANDLE_INIT(kled_set); 1349 ASUS_HANDLE_INIT(kled_get); 1350 1351 /* 1352 * The HWRS method return informations about the hardware. 1353 * 0x80 bit is for WLAN, 0x100 for Bluetooth. 1354 * The significance of others is yet to be found. 1355 * If we don't find the method, we assume the device are present. 1356 */ 1357 status = 1358 acpi_evaluate_integer(asus->handle, "HRWS", NULL, &hwrs_result); 1359 if (ACPI_FAILURE(status)) 1360 hwrs_result = WL_HWRS | BT_HWRS; 1361 1362 if (hwrs_result & WL_HWRS) 1363 ASUS_HANDLE_INIT(wl_switch); 1364 if (hwrs_result & BT_HWRS) 1365 ASUS_HANDLE_INIT(bt_switch); 1366 1367 if (!ASUS_HANDLE_INIT(wireless_status)) 1368 asus->have_rsts = true; 1369 1370 ASUS_HANDLE_INIT(brightness_set); 1371 ASUS_HANDLE_INIT(brightness_get); 1372 1373 ASUS_HANDLE_INIT(lcd_switch); 1374 1375 ASUS_HANDLE_INIT(display_set); 1376 ASUS_HANDLE_INIT(display_get); 1377 1378 /* 1379 * There is a lot of models with "ALSL", but a few get 1380 * a real light sens, so we need to check it. 1381 */ 1382 if (!ASUS_HANDLE_INIT(ls_switch)) 1383 ASUS_HANDLE_INIT(ls_level); 1384 1385 ASUS_HANDLE_INIT(gps_on); 1386 ASUS_HANDLE_INIT(gps_off); 1387 ASUS_HANDLE_INIT(gps_status); 1388 1389 kfree(model); 1390 1391 return AE_OK; 1392} 1393 1394static bool asus_device_present; 1395 1396static int __devinit asus_acpi_init(struct asus_laptop *asus) 1397{ 1398 int result = 0; 1399 1400 result = acpi_bus_get_status(asus->device); 1401 if (result) 1402 return result; 1403 if (!asus->device->status.present) { 1404 pr_err("Hotkey device not present, aborting\n"); 1405 return -ENODEV; 1406 } 1407 1408 result = asus_laptop_get_info(asus); 1409 if (result) 1410 return result; 1411 1412 asus_laptop_add_fs(asus); 1413 1414 /* WLED and BLED are on by default */ 1415 if (bluetooth_status >= 0) 1416 write_acpi_int(bt_switch_handle, NULL, !!bluetooth_status); 1417 if (wireless_status >= 0) 1418 write_acpi_int(wl_switch_handle, NULL, !!wireless_status); 1419 1420 /* Keyboard Backlight is on by default */ 1421 if (kled_set_handle) 1422 set_kled_lvl(asus, 1); 1423 1424 /* LED display is off by default */ 1425 asus->ledd_status = 0xFFF; 1426 1427 /* Set initial values of light sensor and level */ 1428 asus->light_switch = 0; /* Default to light sensor disabled */ 1429 asus->light_level = 5; /* level 5 for sensor sensitivity */ 1430 1431 if (ls_switch_handle) 1432 set_light_sens_switch(asus, asus->light_switch); 1433 1434 if (ls_level_handle) 1435 set_light_sens_level(asus, asus->light_level); 1436 1437 /* GPS is on by default */ 1438 asus_gps_switch(asus, 1); 1439 return result; 1440} 1441 1442static int __devinit asus_acpi_add(struct acpi_device *device) 1443{ 1444 struct asus_laptop *asus; 1445 int result; 1446 1447 pr_notice("Asus Laptop Support version %s\n", 1448 ASUS_LAPTOP_VERSION); 1449 asus = kzalloc(sizeof(struct asus_laptop), GFP_KERNEL); 1450 if (!asus) 1451 return -ENOMEM; 1452 asus->handle = device->handle; 1453 strcpy(acpi_device_name(device), ASUS_LAPTOP_DEVICE_NAME); 1454 strcpy(acpi_device_class(device), ASUS_LAPTOP_CLASS); 1455 device->driver_data = asus; 1456 asus->device = device; 1457 1458 result = asus_acpi_init(asus); 1459 if (result) 1460 goto fail_platform; 1461 1462 /* 1463 * Register the platform device first. It is used as a parent for the 1464 * sub-devices below. 1465 */ 1466 result = asus_platform_init(asus); 1467 if (result) 1468 goto fail_platform; 1469 1470 if (!acpi_video_backlight_support()) { 1471 result = asus_backlight_init(asus); 1472 if (result) 1473 goto fail_backlight; 1474 } else 1475 pr_info("Backlight controlled by ACPI video driver\n"); 1476 1477 result = asus_input_init(asus); 1478 if (result) 1479 goto fail_input; 1480 1481 result = asus_led_init(asus); 1482 if (result) 1483 goto fail_led; 1484 1485 asus_device_present = true; 1486 return 0; 1487 1488fail_led: 1489 asus_input_exit(asus); 1490fail_input: 1491 asus_backlight_exit(asus); 1492fail_backlight: 1493 asus_platform_exit(asus); 1494fail_platform: 1495 kfree(asus->name); 1496 kfree(asus); 1497 1498 return result; 1499} 1500 1501static int asus_acpi_remove(struct acpi_device *device, int type) 1502{ 1503 struct asus_laptop *asus = acpi_driver_data(device); 1504 1505 asus_backlight_exit(asus); 1506 asus_led_exit(asus); 1507 asus_input_exit(asus); 1508 asus_platform_exit(asus); 1509 1510 kfree(asus->name); 1511 kfree(asus); 1512 return 0; 1513} 1514 1515static const struct acpi_device_id asus_device_ids[] = { 1516 {"ATK0100", 0}, 1517 {"ATK0101", 0}, 1518 {"", 0}, 1519}; 1520MODULE_DEVICE_TABLE(acpi, asus_device_ids); 1521 1522static struct acpi_driver asus_acpi_driver = { 1523 .name = ASUS_LAPTOP_NAME, 1524 .class = ASUS_LAPTOP_CLASS, 1525 .owner = THIS_MODULE, 1526 .ids = asus_device_ids, 1527 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS, 1528 .ops = { 1529 .add = asus_acpi_add, 1530 .remove = asus_acpi_remove, 1531 .notify = asus_acpi_notify, 1532 }, 1533}; 1534 1535static int __init asus_laptop_init(void) 1536{ 1537 int result; 1538 1539 result = platform_driver_register(&platform_driver); 1540 if (result < 0) 1541 return result; 1542 1543 result = acpi_bus_register_driver(&asus_acpi_driver); 1544 if (result < 0) 1545 goto fail_acpi_driver; 1546 if (!asus_device_present) { 1547 result = -ENODEV; 1548 goto fail_no_device; 1549 } 1550 return 0; 1551 1552fail_no_device: 1553 acpi_bus_unregister_driver(&asus_acpi_driver); 1554fail_acpi_driver: 1555 platform_driver_unregister(&platform_driver); 1556 return result; 1557} 1558 1559static void __exit asus_laptop_exit(void) 1560{ 1561 acpi_bus_unregister_driver(&asus_acpi_driver); 1562 platform_driver_unregister(&platform_driver); 1563} 1564 1565module_init(asus_laptop_init); 1566module_exit(asus_laptop_exit); 1567