1/* 2 * asus_acpi.c - Asus Laptop ACPI Extras 3 * 4 * 5 * Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 2 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * 21 * 22 * The development page for this driver is located at 23 * http://sourceforge.net/projects/acpi4asus/ 24 * 25 * Credits: 26 * Pontus Fuchs - Helper functions, cleanup 27 * Johann Wiesner - Small compile fixes 28 * John Belmonte - ACPI code for Toshiba laptop was a good starting point. 29 * ���ic Burghard - LED display support for W1N 30 * 31 */ 32 33#include <linux/kernel.h> 34#include <linux/module.h> 35#include <linux/slab.h> 36#include <linux/init.h> 37#include <linux/types.h> 38#include <linux/proc_fs.h> 39#include <linux/seq_file.h> 40#include <linux/backlight.h> 41#include <acpi/acpi_drivers.h> 42#include <acpi/acpi_bus.h> 43#include <asm/uaccess.h> 44 45#define ASUS_ACPI_VERSION "0.30" 46 47#define PROC_ASUS "asus" /* The directory */ 48#define PROC_MLED "mled" 49#define PROC_WLED "wled" 50#define PROC_TLED "tled" 51#define PROC_BT "bluetooth" 52#define PROC_LEDD "ledd" 53#define PROC_INFO "info" 54#define PROC_LCD "lcd" 55#define PROC_BRN "brn" 56#define PROC_DISP "disp" 57 58#define ACPI_HOTK_NAME "Asus Laptop ACPI Extras Driver" 59#define ACPI_HOTK_CLASS "hotkey" 60#define ACPI_HOTK_DEVICE_NAME "Hotkey" 61 62/* 63 * Some events we use, same for all Asus 64 */ 65#define BR_UP 0x10 66#define BR_DOWN 0x20 67 68/* 69 * Flags for hotk status 70 */ 71#define MLED_ON 0x01 /* Mail LED */ 72#define WLED_ON 0x02 /* Wireless LED */ 73#define TLED_ON 0x04 /* Touchpad LED */ 74#define BT_ON 0x08 /* Internal Bluetooth */ 75 76MODULE_AUTHOR("Julien Lerouge, Karol Kozimor"); 77MODULE_DESCRIPTION(ACPI_HOTK_NAME); 78MODULE_LICENSE("GPL"); 79 80static uid_t asus_uid; 81static gid_t asus_gid; 82module_param(asus_uid, uint, 0); 83MODULE_PARM_DESC(asus_uid, "UID for entries in /proc/acpi/asus"); 84module_param(asus_gid, uint, 0); 85MODULE_PARM_DESC(asus_gid, "GID for entries in /proc/acpi/asus"); 86 87/* For each model, all features implemented, 88 * those marked with R are relative to HOTK, A for absolute */ 89struct model_data { 90 char *name; /* name of the laptop________________A */ 91 char *mt_mled; /* method to handle mled_____________R */ 92 char *mled_status; /* node to handle mled reading_______A */ 93 char *mt_wled; /* method to handle wled_____________R */ 94 char *wled_status; /* node to handle wled reading_______A */ 95 char *mt_tled; /* method to handle tled_____________R */ 96 char *tled_status; /* node to handle tled reading_______A */ 97 char *mt_ledd; /* method to handle LED display______R */ 98 char *mt_bt_switch; /* method to switch Bluetooth on/off_R */ 99 char *bt_status; /* no model currently supports this__? */ 100 char *mt_lcd_switch; /* method to turn LCD on/off_________A */ 101 char *lcd_status; /* node to read LCD panel state______A */ 102 char *brightness_up; /* method to set brightness up_______A */ 103 char *brightness_down; /* method to set brightness down ____A */ 104 char *brightness_set; /* method to set absolute brightness_R */ 105 char *brightness_get; /* method to get absolute brightness_R */ 106 char *brightness_status;/* node to get brightness____________A */ 107 char *display_set; /* method to set video output________R */ 108 char *display_get; /* method to get video output________R */ 109}; 110 111/* 112 * This is the main structure, we can use it to store anything interesting 113 * about the hotk device 114 */ 115struct asus_hotk { 116 struct acpi_device *device; /* the device we are in */ 117 acpi_handle handle; /* the handle of the hotk device */ 118 char status; /* status of the hotk, for LEDs */ 119 u32 ledd_status; /* status of the LED display */ 120 struct model_data *methods; /* methods available on the laptop */ 121 u8 brightness; /* brightness level */ 122 enum { 123 A1x = 0, /* A1340D, A1300F */ 124 A2x, /* A2500H */ 125 A4G, /* A4700G */ 126 D1x, /* D1 */ 127 L2D, /* L2000D */ 128 L3C, /* L3800C */ 129 L3D, /* L3400D */ 130 L3H, /* L3H, L2000E, L5D */ 131 L4R, /* L4500R */ 132 L5x, /* L5800C */ 133 L8L, /* L8400L */ 134 M1A, /* M1300A */ 135 M2E, /* M2400E, L4400L */ 136 M6N, /* M6800N, W3400N */ 137 M6R, /* M6700R, A3000G */ 138 P30, /* Samsung P30 */ 139 S1x, /* S1300A, but also L1400B and M2400A (L84F) */ 140 S2x, /* S200 (J1 reported), Victor MP-XP7210 */ 141 W1N, /* W1000N */ 142 W5A, /* W5A */ 143 W3V, /* W3030V */ 144 xxN, /* M2400N, M3700N, M5200N, M6800N, 145 S1300N, S5200N*/ 146 A4S, /* Z81sp */ 147 F3Sa, /* (Centrino) */ 148 R1F, 149 END_MODEL 150 } model; /* Models currently supported */ 151 u16 event_count[128]; /* Count for each event TODO make this better */ 152}; 153 154/* Here we go */ 155#define A1x_PREFIX "\\_SB.PCI0.ISA.EC0." 156#define L3C_PREFIX "\\_SB.PCI0.PX40.ECD0." 157#define M1A_PREFIX "\\_SB.PCI0.PX40.EC0." 158#define P30_PREFIX "\\_SB.PCI0.LPCB.EC0." 159#define S1x_PREFIX "\\_SB.PCI0.PX40." 160#define S2x_PREFIX A1x_PREFIX 161#define xxN_PREFIX "\\_SB.PCI0.SBRG.EC0." 162 163static struct model_data model_conf[END_MODEL] = { 164 /* 165 * TODO I have seen a SWBX and AIBX method on some models, like L1400B, 166 * it seems to be a kind of switch, but what for ? 167 */ 168 169 { 170 .name = "A1x", 171 .mt_mled = "MLED", 172 .mled_status = "\\MAIL", 173 .mt_lcd_switch = A1x_PREFIX "_Q10", 174 .lcd_status = "\\BKLI", 175 .brightness_up = A1x_PREFIX "_Q0E", 176 .brightness_down = A1x_PREFIX "_Q0F"}, 177 178 { 179 .name = "A2x", 180 .mt_mled = "MLED", 181 .mt_wled = "WLED", 182 .wled_status = "\\SG66", 183 .mt_lcd_switch = "\\Q10", 184 .lcd_status = "\\BAOF", 185 .brightness_set = "SPLV", 186 .brightness_get = "GPLV", 187 .display_set = "SDSP", 188 .display_get = "\\INFB"}, 189 190 { 191 .name = "A4G", 192 .mt_mled = "MLED", 193/* WLED present, but not controlled by ACPI */ 194 .mt_lcd_switch = xxN_PREFIX "_Q10", 195 .brightness_set = "SPLV", 196 .brightness_get = "GPLV", 197 .display_set = "SDSP", 198 .display_get = "\\ADVG"}, 199 200 { 201 .name = "D1x", 202 .mt_mled = "MLED", 203 .mt_lcd_switch = "\\Q0D", 204 .lcd_status = "\\GP11", 205 .brightness_up = "\\Q0C", 206 .brightness_down = "\\Q0B", 207 .brightness_status = "\\BLVL", 208 .display_set = "SDSP", 209 .display_get = "\\INFB"}, 210 211 { 212 .name = "L2D", 213 .mt_mled = "MLED", 214 .mled_status = "\\SGP6", 215 .mt_wled = "WLED", 216 .wled_status = "\\RCP3", 217 .mt_lcd_switch = "\\Q10", 218 .lcd_status = "\\SGP0", 219 .brightness_up = "\\Q0E", 220 .brightness_down = "\\Q0F", 221 .display_set = "SDSP", 222 .display_get = "\\INFB"}, 223 224 { 225 .name = "L3C", 226 .mt_mled = "MLED", 227 .mt_wled = "WLED", 228 .mt_lcd_switch = L3C_PREFIX "_Q10", 229 .lcd_status = "\\GL32", 230 .brightness_set = "SPLV", 231 .brightness_get = "GPLV", 232 .display_set = "SDSP", 233 .display_get = "\\_SB.PCI0.PCI1.VGAC.NMAP"}, 234 235 { 236 .name = "L3D", 237 .mt_mled = "MLED", 238 .mled_status = "\\MALD", 239 .mt_wled = "WLED", 240 .mt_lcd_switch = "\\Q10", 241 .lcd_status = "\\BKLG", 242 .brightness_set = "SPLV", 243 .brightness_get = "GPLV", 244 .display_set = "SDSP", 245 .display_get = "\\INFB"}, 246 247 { 248 .name = "L3H", 249 .mt_mled = "MLED", 250 .mt_wled = "WLED", 251 .mt_lcd_switch = "EHK", 252 .lcd_status = "\\_SB.PCI0.PM.PBC", 253 .brightness_set = "SPLV", 254 .brightness_get = "GPLV", 255 .display_set = "SDSP", 256 .display_get = "\\INFB"}, 257 258 { 259 .name = "L4R", 260 .mt_mled = "MLED", 261 .mt_wled = "WLED", 262 .wled_status = "\\_SB.PCI0.SBRG.SG13", 263 .mt_lcd_switch = xxN_PREFIX "_Q10", 264 .lcd_status = "\\_SB.PCI0.SBSM.SEO4", 265 .brightness_set = "SPLV", 266 .brightness_get = "GPLV", 267 .display_set = "SDSP", 268 .display_get = "\\_SB.PCI0.P0P1.VGA.GETD"}, 269 270 { 271 .name = "L5x", 272 .mt_mled = "MLED", 273/* WLED present, but not controlled by ACPI */ 274 .mt_tled = "TLED", 275 .mt_lcd_switch = "\\Q0D", 276 .lcd_status = "\\BAOF", 277 .brightness_set = "SPLV", 278 .brightness_get = "GPLV", 279 .display_set = "SDSP", 280 .display_get = "\\INFB"}, 281 282 { 283 .name = "L8L" 284/* No features, but at least support the hotkeys */ 285 }, 286 287 { 288 .name = "M1A", 289 .mt_mled = "MLED", 290 .mt_lcd_switch = M1A_PREFIX "Q10", 291 .lcd_status = "\\PNOF", 292 .brightness_up = M1A_PREFIX "Q0E", 293 .brightness_down = M1A_PREFIX "Q0F", 294 .brightness_status = "\\BRIT", 295 .display_set = "SDSP", 296 .display_get = "\\INFB"}, 297 298 { 299 .name = "M2E", 300 .mt_mled = "MLED", 301 .mt_wled = "WLED", 302 .mt_lcd_switch = "\\Q10", 303 .lcd_status = "\\GP06", 304 .brightness_set = "SPLV", 305 .brightness_get = "GPLV", 306 .display_set = "SDSP", 307 .display_get = "\\INFB"}, 308 309 { 310 .name = "M6N", 311 .mt_mled = "MLED", 312 .mt_wled = "WLED", 313 .wled_status = "\\_SB.PCI0.SBRG.SG13", 314 .mt_lcd_switch = xxN_PREFIX "_Q10", 315 .lcd_status = "\\_SB.BKLT", 316 .brightness_set = "SPLV", 317 .brightness_get = "GPLV", 318 .display_set = "SDSP", 319 .display_get = "\\SSTE"}, 320 321 { 322 .name = "M6R", 323 .mt_mled = "MLED", 324 .mt_wled = "WLED", 325 .mt_lcd_switch = xxN_PREFIX "_Q10", 326 .lcd_status = "\\_SB.PCI0.SBSM.SEO4", 327 .brightness_set = "SPLV", 328 .brightness_get = "GPLV", 329 .display_set = "SDSP", 330 .display_get = "\\_SB.PCI0.P0P1.VGA.GETD"}, 331 332 { 333 .name = "P30", 334 .mt_wled = "WLED", 335 .mt_lcd_switch = P30_PREFIX "_Q0E", 336 .lcd_status = "\\BKLT", 337 .brightness_up = P30_PREFIX "_Q68", 338 .brightness_down = P30_PREFIX "_Q69", 339 .brightness_get = "GPLV", 340 .display_set = "SDSP", 341 .display_get = "\\DNXT"}, 342 343 { 344 .name = "S1x", 345 .mt_mled = "MLED", 346 .mled_status = "\\EMLE", 347 .mt_wled = "WLED", 348 .mt_lcd_switch = S1x_PREFIX "Q10", 349 .lcd_status = "\\PNOF", 350 .brightness_set = "SPLV", 351 .brightness_get = "GPLV"}, 352 353 { 354 .name = "S2x", 355 .mt_mled = "MLED", 356 .mled_status = "\\MAIL", 357 .mt_lcd_switch = S2x_PREFIX "_Q10", 358 .lcd_status = "\\BKLI", 359 .brightness_up = S2x_PREFIX "_Q0B", 360 .brightness_down = S2x_PREFIX "_Q0A"}, 361 362 { 363 .name = "W1N", 364 .mt_mled = "MLED", 365 .mt_wled = "WLED", 366 .mt_ledd = "SLCM", 367 .mt_lcd_switch = xxN_PREFIX "_Q10", 368 .lcd_status = "\\BKLT", 369 .brightness_set = "SPLV", 370 .brightness_get = "GPLV", 371 .display_set = "SDSP", 372 .display_get = "\\ADVG"}, 373 374 { 375 .name = "W5A", 376 .mt_bt_switch = "BLED", 377 .mt_wled = "WLED", 378 .mt_lcd_switch = xxN_PREFIX "_Q10", 379 .brightness_set = "SPLV", 380 .brightness_get = "GPLV", 381 .display_set = "SDSP", 382 .display_get = "\\ADVG"}, 383 384 { 385 .name = "W3V", 386 .mt_mled = "MLED", 387 .mt_wled = "WLED", 388 .mt_lcd_switch = xxN_PREFIX "_Q10", 389 .lcd_status = "\\BKLT", 390 .brightness_set = "SPLV", 391 .brightness_get = "GPLV", 392 .display_set = "SDSP", 393 .display_get = "\\INFB"}, 394 395 { 396 .name = "xxN", 397 .mt_mled = "MLED", 398/* WLED present, but not controlled by ACPI */ 399 .mt_lcd_switch = xxN_PREFIX "_Q10", 400 .lcd_status = "\\BKLT", 401 .brightness_set = "SPLV", 402 .brightness_get = "GPLV", 403 .display_set = "SDSP", 404 .display_get = "\\ADVG"}, 405 406 { 407 .name = "A4S", 408 .brightness_set = "SPLV", 409 .brightness_get = "GPLV", 410 .mt_bt_switch = "BLED", 411 .mt_wled = "WLED" 412 }, 413 414 { 415 .name = "F3Sa", 416 .mt_bt_switch = "BLED", 417 .mt_wled = "WLED", 418 .mt_mled = "MLED", 419 .brightness_get = "GPLV", 420 .brightness_set = "SPLV", 421 .mt_lcd_switch = "\\_SB.PCI0.SBRG.EC0._Q10", 422 .lcd_status = "\\_SB.PCI0.SBRG.EC0.RPIN", 423 .display_get = "\\ADVG", 424 .display_set = "SDSP", 425 }, 426 { 427 .name = "R1F", 428 .mt_bt_switch = "BLED", 429 .mt_mled = "MLED", 430 .mt_wled = "WLED", 431 .mt_lcd_switch = "\\Q10", 432 .lcd_status = "\\GP06", 433 .brightness_set = "SPLV", 434 .brightness_get = "GPLV", 435 .display_set = "SDSP", 436 .display_get = "\\INFB" 437 } 438}; 439 440/* procdir we use */ 441static struct proc_dir_entry *asus_proc_dir; 442 443static struct backlight_device *asus_backlight_device; 444 445/* 446 * This header is made available to allow proper configuration given model, 447 * revision number , ... this info cannot go in struct asus_hotk because it is 448 * available before the hotk 449 */ 450static struct acpi_table_header *asus_info; 451 452/* The actual device the driver binds to */ 453static struct asus_hotk *hotk; 454 455/* 456 * The hotkey driver and autoloading declaration 457 */ 458static int asus_hotk_add(struct acpi_device *device); 459static int asus_hotk_remove(struct acpi_device *device, int type); 460static void asus_hotk_notify(struct acpi_device *device, u32 event); 461 462static const struct acpi_device_id asus_device_ids[] = { 463 {"ATK0100", 0}, 464 {"", 0}, 465}; 466MODULE_DEVICE_TABLE(acpi, asus_device_ids); 467 468static struct acpi_driver asus_hotk_driver = { 469 .name = "asus_acpi", 470 .class = ACPI_HOTK_CLASS, 471 .owner = THIS_MODULE, 472 .ids = asus_device_ids, 473 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS, 474 .ops = { 475 .add = asus_hotk_add, 476 .remove = asus_hotk_remove, 477 .notify = asus_hotk_notify, 478 }, 479}; 480 481/* 482 * This function evaluates an ACPI method, given an int as parameter, the 483 * method is searched within the scope of the handle, can be NULL. The output 484 * of the method is written is output, which can also be NULL 485 * 486 * returns 1 if write is successful, 0 else. 487 */ 488static int write_acpi_int(acpi_handle handle, const char *method, int val, 489 struct acpi_buffer *output) 490{ 491 struct acpi_object_list params; /* list of input parameters (int) */ 492 union acpi_object in_obj; /* the only param we use */ 493 acpi_status status; 494 495 params.count = 1; 496 params.pointer = &in_obj; 497 in_obj.type = ACPI_TYPE_INTEGER; 498 in_obj.integer.value = val; 499 500 status = acpi_evaluate_object(handle, (char *)method, ¶ms, output); 501 return (status == AE_OK); 502} 503 504static int read_acpi_int(acpi_handle handle, const char *method, int *val) 505{ 506 struct acpi_buffer output; 507 union acpi_object out_obj; 508 acpi_status status; 509 510 output.length = sizeof(out_obj); 511 output.pointer = &out_obj; 512 513 status = acpi_evaluate_object(handle, (char *)method, NULL, &output); 514 *val = out_obj.integer.value; 515 return (status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER); 516} 517 518static int asus_info_proc_show(struct seq_file *m, void *v) 519{ 520 int temp; 521 522 seq_printf(m, ACPI_HOTK_NAME " " ASUS_ACPI_VERSION "\n"); 523 seq_printf(m, "Model reference : %s\n", hotk->methods->name); 524 /* 525 * The SFUN method probably allows the original driver to get the list 526 * of features supported by a given model. For now, 0x0100 or 0x0800 527 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card. 528 * The significance of others is yet to be found. 529 */ 530 if (read_acpi_int(hotk->handle, "SFUN", &temp)) 531 seq_printf(m, "SFUN value : 0x%04x\n", temp); 532 /* 533 * Another value for userspace: the ASYM method returns 0x02 for 534 * battery low and 0x04 for battery critical, its readings tend to be 535 * more accurate than those provided by _BST. 536 * Note: since not all the laptops provide this method, errors are 537 * silently ignored. 538 */ 539 if (read_acpi_int(hotk->handle, "ASYM", &temp)) 540 seq_printf(m, "ASYM value : 0x%04x\n", temp); 541 if (asus_info) { 542 seq_printf(m, "DSDT length : %d\n", asus_info->length); 543 seq_printf(m, "DSDT checksum : %d\n", asus_info->checksum); 544 seq_printf(m, "DSDT revision : %d\n", asus_info->revision); 545 seq_printf(m, "OEM id : %.*s\n", ACPI_OEM_ID_SIZE, asus_info->oem_id); 546 seq_printf(m, "OEM table id : %.*s\n", ACPI_OEM_TABLE_ID_SIZE, asus_info->oem_table_id); 547 seq_printf(m, "OEM revision : 0x%x\n", asus_info->oem_revision); 548 seq_printf(m, "ASL comp vendor id : %.*s\n", ACPI_NAME_SIZE, asus_info->asl_compiler_id); 549 seq_printf(m, "ASL comp revision : 0x%x\n", asus_info->asl_compiler_revision); 550 } 551 552 return 0; 553} 554 555static int asus_info_proc_open(struct inode *inode, struct file *file) 556{ 557 return single_open(file, asus_info_proc_show, NULL); 558} 559 560static const struct file_operations asus_info_proc_fops = { 561 .owner = THIS_MODULE, 562 .open = asus_info_proc_open, 563 .read = seq_read, 564 .llseek = seq_lseek, 565 .release = single_release, 566}; 567 568/* 569 * /proc handlers 570 * We write our info in page, we begin at offset off and cannot write more 571 * than count bytes. We set eof to 1 if we handle those 2 values. We return the 572 * number of bytes written in page 573 */ 574 575/* Generic LED functions */ 576static int read_led(const char *ledname, int ledmask) 577{ 578 if (ledname) { 579 int led_status; 580 581 if (read_acpi_int(NULL, ledname, &led_status)) 582 return led_status; 583 else 584 printk(KERN_WARNING "Asus ACPI: Error reading LED " 585 "status\n"); 586 } 587 return (hotk->status & ledmask) ? 1 : 0; 588} 589 590static int parse_arg(const char __user *buf, unsigned long count, int *val) 591{ 592 char s[32]; 593 if (!count) 594 return 0; 595 if (count > 31) 596 return -EINVAL; 597 if (copy_from_user(s, buf, count)) 598 return -EFAULT; 599 s[count] = 0; 600 if (sscanf(s, "%i", val) != 1) 601 return -EINVAL; 602 return count; 603} 604 605static int 606write_led(const char __user *buffer, unsigned long count, 607 char *ledname, int ledmask, int invert) 608{ 609 int rv, value; 610 int led_out = 0; 611 612 rv = parse_arg(buffer, count, &value); 613 if (rv > 0) 614 led_out = value ? 1 : 0; 615 616 hotk->status = 617 (led_out) ? (hotk->status | ledmask) : (hotk->status & ~ledmask); 618 619 if (invert) /* invert target value */ 620 led_out = !led_out; 621 622 if (!write_acpi_int(hotk->handle, ledname, led_out, NULL)) 623 printk(KERN_WARNING "Asus ACPI: LED (%s) write failed\n", 624 ledname); 625 626 return rv; 627} 628 629/* 630 * Proc handlers for MLED 631 */ 632static int mled_proc_show(struct seq_file *m, void *v) 633{ 634 seq_printf(m, "%d\n", read_led(hotk->methods->mled_status, MLED_ON)); 635 return 0; 636} 637 638static int mled_proc_open(struct inode *inode, struct file *file) 639{ 640 return single_open(file, mled_proc_show, NULL); 641} 642 643static ssize_t mled_proc_write(struct file *file, const char __user *buffer, 644 size_t count, loff_t *pos) 645{ 646 return write_led(buffer, count, hotk->methods->mt_mled, MLED_ON, 1); 647} 648 649static const struct file_operations mled_proc_fops = { 650 .owner = THIS_MODULE, 651 .open = mled_proc_open, 652 .read = seq_read, 653 .llseek = seq_lseek, 654 .release = single_release, 655 .write = mled_proc_write, 656}; 657 658/* 659 * Proc handlers for LED display 660 */ 661static int ledd_proc_show(struct seq_file *m, void *v) 662{ 663 seq_printf(m, "0x%08x\n", hotk->ledd_status); 664 return 0; 665} 666 667static int ledd_proc_open(struct inode *inode, struct file *file) 668{ 669 return single_open(file, ledd_proc_show, NULL); 670} 671 672static ssize_t ledd_proc_write(struct file *file, const char __user *buffer, 673 size_t count, loff_t *pos) 674{ 675 int rv, value; 676 677 rv = parse_arg(buffer, count, &value); 678 if (rv > 0) { 679 if (!write_acpi_int 680 (hotk->handle, hotk->methods->mt_ledd, value, NULL)) 681 printk(KERN_WARNING 682 "Asus ACPI: LED display write failed\n"); 683 else 684 hotk->ledd_status = (u32) value; 685 } 686 return rv; 687} 688 689static const struct file_operations ledd_proc_fops = { 690 .owner = THIS_MODULE, 691 .open = ledd_proc_open, 692 .read = seq_read, 693 .llseek = seq_lseek, 694 .release = single_release, 695 .write = ledd_proc_write, 696}; 697 698/* 699 * Proc handlers for WLED 700 */ 701static int wled_proc_show(struct seq_file *m, void *v) 702{ 703 seq_printf(m, "%d\n", read_led(hotk->methods->wled_status, WLED_ON)); 704 return 0; 705} 706 707static int wled_proc_open(struct inode *inode, struct file *file) 708{ 709 return single_open(file, wled_proc_show, NULL); 710} 711 712static ssize_t wled_proc_write(struct file *file, const char __user *buffer, 713 size_t count, loff_t *pos) 714{ 715 return write_led(buffer, count, hotk->methods->mt_wled, WLED_ON, 0); 716} 717 718static const struct file_operations wled_proc_fops = { 719 .owner = THIS_MODULE, 720 .open = wled_proc_open, 721 .read = seq_read, 722 .llseek = seq_lseek, 723 .release = single_release, 724 .write = wled_proc_write, 725}; 726 727/* 728 * Proc handlers for Bluetooth 729 */ 730static int bluetooth_proc_show(struct seq_file *m, void *v) 731{ 732 seq_printf(m, "%d\n", read_led(hotk->methods->bt_status, BT_ON)); 733 return 0; 734} 735 736static int bluetooth_proc_open(struct inode *inode, struct file *file) 737{ 738 return single_open(file, bluetooth_proc_show, NULL); 739} 740 741static ssize_t bluetooth_proc_write(struct file *file, 742 const char __user *buffer, size_t count, loff_t *pos) 743{ 744 /* Note: mt_bt_switch controls both internal Bluetooth adapter's 745 presence and its LED */ 746 return write_led(buffer, count, hotk->methods->mt_bt_switch, BT_ON, 0); 747} 748 749static const struct file_operations bluetooth_proc_fops = { 750 .owner = THIS_MODULE, 751 .open = bluetooth_proc_open, 752 .read = seq_read, 753 .llseek = seq_lseek, 754 .release = single_release, 755 .write = bluetooth_proc_write, 756}; 757 758/* 759 * Proc handlers for TLED 760 */ 761static int tled_proc_show(struct seq_file *m, void *v) 762{ 763 seq_printf(m, "%d\n", read_led(hotk->methods->tled_status, TLED_ON)); 764 return 0; 765} 766 767static int tled_proc_open(struct inode *inode, struct file *file) 768{ 769 return single_open(file, tled_proc_show, NULL); 770} 771 772static ssize_t tled_proc_write(struct file *file, const char __user *buffer, 773 size_t count, loff_t *pos) 774{ 775 return write_led(buffer, count, hotk->methods->mt_tled, TLED_ON, 0); 776} 777 778static const struct file_operations tled_proc_fops = { 779 .owner = THIS_MODULE, 780 .open = tled_proc_open, 781 .read = seq_read, 782 .llseek = seq_lseek, 783 .release = single_release, 784 .write = tled_proc_write, 785}; 786 787static int get_lcd_state(void) 788{ 789 int lcd = 0; 790 791 if (hotk->model == L3H) { 792 /* L3H and the like have to be handled differently */ 793 acpi_status status = 0; 794 struct acpi_object_list input; 795 union acpi_object mt_params[2]; 796 struct acpi_buffer output; 797 union acpi_object out_obj; 798 799 input.count = 2; 800 input.pointer = mt_params; 801 /* Note: the following values are partly guessed up, but 802 otherwise they seem to work */ 803 mt_params[0].type = ACPI_TYPE_INTEGER; 804 mt_params[0].integer.value = 0x02; 805 mt_params[1].type = ACPI_TYPE_INTEGER; 806 mt_params[1].integer.value = 0x02; 807 808 output.length = sizeof(out_obj); 809 output.pointer = &out_obj; 810 811 status = 812 acpi_evaluate_object(NULL, hotk->methods->lcd_status, 813 &input, &output); 814 if (status != AE_OK) 815 return -1; 816 if (out_obj.type == ACPI_TYPE_INTEGER) 817 /* That's what the AML code does */ 818 lcd = out_obj.integer.value >> 8; 819 } else if (hotk->model == F3Sa) { 820 unsigned long long tmp; 821 union acpi_object param; 822 struct acpi_object_list input; 823 acpi_status status; 824 825 /* Read pin 11 */ 826 param.type = ACPI_TYPE_INTEGER; 827 param.integer.value = 0x11; 828 input.count = 1; 829 input.pointer = ¶m; 830 831 status = acpi_evaluate_integer(NULL, hotk->methods->lcd_status, 832 &input, &tmp); 833 if (status != AE_OK) 834 return -1; 835 836 lcd = tmp; 837 } else { 838 /* We don't have to check anything if we are here */ 839 if (!read_acpi_int(NULL, hotk->methods->lcd_status, &lcd)) 840 printk(KERN_WARNING 841 "Asus ACPI: Error reading LCD status\n"); 842 843 if (hotk->model == L2D) 844 lcd = ~lcd; 845 } 846 847 return (lcd & 1); 848} 849 850static int set_lcd_state(int value) 851{ 852 int lcd = 0; 853 acpi_status status = 0; 854 855 lcd = value ? 1 : 0; 856 if (lcd != get_lcd_state()) { 857 /* switch */ 858 if (hotk->model != L3H) { 859 status = 860 acpi_evaluate_object(NULL, 861 hotk->methods->mt_lcd_switch, 862 NULL, NULL); 863 } else { 864 /* L3H and the like must be handled differently */ 865 if (!write_acpi_int 866 (hotk->handle, hotk->methods->mt_lcd_switch, 0x07, 867 NULL)) 868 status = AE_ERROR; 869 /* L3H's AML executes EHK (0x07) upon Fn+F7 keypress, 870 the exact behaviour is simulated here */ 871 } 872 if (ACPI_FAILURE(status)) 873 printk(KERN_WARNING "Asus ACPI: Error switching LCD\n"); 874 } 875 return 0; 876 877} 878 879static int lcd_proc_show(struct seq_file *m, void *v) 880{ 881 seq_printf(m, "%d\n", get_lcd_state()); 882 return 0; 883} 884 885static int lcd_proc_open(struct inode *inode, struct file *file) 886{ 887 return single_open(file, lcd_proc_show, NULL); 888} 889 890static ssize_t lcd_proc_write(struct file *file, const char __user *buffer, 891 size_t count, loff_t *pos) 892{ 893 int rv, value; 894 895 rv = parse_arg(buffer, count, &value); 896 if (rv > 0) 897 set_lcd_state(value); 898 return rv; 899} 900 901static const struct file_operations lcd_proc_fops = { 902 .owner = THIS_MODULE, 903 .open = lcd_proc_open, 904 .read = seq_read, 905 .llseek = seq_lseek, 906 .release = single_release, 907 .write = lcd_proc_write, 908}; 909 910static int read_brightness(struct backlight_device *bd) 911{ 912 int value; 913 914 if (hotk->methods->brightness_get) { /* SPLV/GPLV laptop */ 915 if (!read_acpi_int(hotk->handle, hotk->methods->brightness_get, 916 &value)) 917 printk(KERN_WARNING 918 "Asus ACPI: Error reading brightness\n"); 919 } else if (hotk->methods->brightness_status) { /* For D1 for example */ 920 if (!read_acpi_int(NULL, hotk->methods->brightness_status, 921 &value)) 922 printk(KERN_WARNING 923 "Asus ACPI: Error reading brightness\n"); 924 } else /* No GPLV method */ 925 value = hotk->brightness; 926 return value; 927} 928 929/* 930 * Change the brightness level 931 */ 932static int set_brightness(int value) 933{ 934 acpi_status status = 0; 935 int ret = 0; 936 937 /* SPLV laptop */ 938 if (hotk->methods->brightness_set) { 939 if (!write_acpi_int(hotk->handle, hotk->methods->brightness_set, 940 value, NULL)) { 941 printk(KERN_WARNING 942 "Asus ACPI: Error changing brightness\n"); 943 ret = -EIO; 944 } 945 goto out; 946 } 947 948 /* No SPLV method if we are here, act as appropriate */ 949 value -= read_brightness(NULL); 950 while (value != 0) { 951 status = acpi_evaluate_object(NULL, (value > 0) ? 952 hotk->methods->brightness_up : 953 hotk->methods->brightness_down, 954 NULL, NULL); 955 (value > 0) ? value-- : value++; 956 if (ACPI_FAILURE(status)) { 957 printk(KERN_WARNING 958 "Asus ACPI: Error changing brightness\n"); 959 ret = -EIO; 960 } 961 } 962out: 963 return ret; 964} 965 966static int set_brightness_status(struct backlight_device *bd) 967{ 968 return set_brightness(bd->props.brightness); 969} 970 971static int brn_proc_show(struct seq_file *m, void *v) 972{ 973 seq_printf(m, "%d\n", read_brightness(NULL)); 974 return 0; 975} 976 977static int brn_proc_open(struct inode *inode, struct file *file) 978{ 979 return single_open(file, brn_proc_show, NULL); 980} 981 982static ssize_t brn_proc_write(struct file *file, const char __user *buffer, 983 size_t count, loff_t *pos) 984{ 985 int rv, value; 986 987 rv = parse_arg(buffer, count, &value); 988 if (rv > 0) { 989 value = (0 < value) ? ((15 < value) ? 15 : value) : 0; 990 /* 0 <= value <= 15 */ 991 set_brightness(value); 992 } 993 return rv; 994} 995 996static const struct file_operations brn_proc_fops = { 997 .owner = THIS_MODULE, 998 .open = brn_proc_open, 999 .read = seq_read, 1000 .llseek = seq_lseek, 1001 .release = single_release, 1002 .write = brn_proc_write, 1003}; 1004 1005static void set_display(int value) 1006{ 1007 /* no sanity check needed for now */ 1008 if (!write_acpi_int(hotk->handle, hotk->methods->display_set, 1009 value, NULL)) 1010 printk(KERN_WARNING "Asus ACPI: Error setting display\n"); 1011 return; 1012} 1013 1014/* 1015 * Now, *this* one could be more user-friendly, but so far, no-one has 1016 * complained. The significance of bits is the same as in proc_write_disp() 1017 */ 1018static int disp_proc_show(struct seq_file *m, void *v) 1019{ 1020 int value = 0; 1021 1022 if (!read_acpi_int(hotk->handle, hotk->methods->display_get, &value)) 1023 printk(KERN_WARNING 1024 "Asus ACPI: Error reading display status\n"); 1025 value &= 0x07; /* needed for some models, shouldn't hurt others */ 1026 seq_printf(m, "%d\n", value); 1027 return 0; 1028} 1029 1030static int disp_proc_open(struct inode *inode, struct file *file) 1031{ 1032 return single_open(file, disp_proc_show, NULL); 1033} 1034 1035/* 1036 * Experimental support for display switching. As of now: 1 should activate 1037 * the LCD output, 2 should do for CRT, and 4 for TV-Out. Any combination 1038 * (bitwise) of these will suffice. I never actually tested 3 displays hooked 1039 * up simultaneously, so be warned. See the acpi4asus README for more info. 1040 */ 1041static ssize_t disp_proc_write(struct file *file, const char __user *buffer, 1042 size_t count, loff_t *pos) 1043{ 1044 int rv, value; 1045 1046 rv = parse_arg(buffer, count, &value); 1047 if (rv > 0) 1048 set_display(value); 1049 return rv; 1050} 1051 1052static const struct file_operations disp_proc_fops = { 1053 .owner = THIS_MODULE, 1054 .open = disp_proc_open, 1055 .read = seq_read, 1056 .llseek = seq_lseek, 1057 .release = single_release, 1058 .write = disp_proc_write, 1059}; 1060 1061static int 1062asus_proc_add(char *name, const struct file_operations *proc_fops, mode_t mode, 1063 struct acpi_device *device) 1064{ 1065 struct proc_dir_entry *proc; 1066 1067 proc = proc_create_data(name, mode, acpi_device_dir(device), 1068 proc_fops, acpi_driver_data(device)); 1069 if (!proc) { 1070 printk(KERN_WARNING " Unable to create %s fs entry\n", name); 1071 return -1; 1072 } 1073 proc->uid = asus_uid; 1074 proc->gid = asus_gid; 1075 return 0; 1076} 1077 1078static int asus_hotk_add_fs(struct acpi_device *device) 1079{ 1080 struct proc_dir_entry *proc; 1081 mode_t mode; 1082 1083 /* 1084 * If parameter uid or gid is not changed, keep the default setting for 1085 * our proc entries (-rw-rw-rw-) else, it means we care about security, 1086 * and then set to -rw-rw---- 1087 */ 1088 1089 if ((asus_uid == 0) && (asus_gid == 0)) { 1090 mode = S_IFREG | S_IRUGO | S_IWUGO; 1091 } else { 1092 mode = S_IFREG | S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP; 1093 printk(KERN_WARNING " asus_uid and asus_gid parameters are " 1094 "deprecated, use chown and chmod instead!\n"); 1095 } 1096 1097 acpi_device_dir(device) = asus_proc_dir; 1098 if (!acpi_device_dir(device)) 1099 return -ENODEV; 1100 1101 proc = proc_create(PROC_INFO, mode, acpi_device_dir(device), 1102 &asus_info_proc_fops); 1103 if (proc) { 1104 proc->uid = asus_uid; 1105 proc->gid = asus_gid; 1106 } else { 1107 printk(KERN_WARNING " Unable to create " PROC_INFO 1108 " fs entry\n"); 1109 } 1110 1111 if (hotk->methods->mt_wled) { 1112 asus_proc_add(PROC_WLED, &wled_proc_fops, mode, device); 1113 } 1114 1115 if (hotk->methods->mt_ledd) { 1116 asus_proc_add(PROC_LEDD, &ledd_proc_fops, mode, device); 1117 } 1118 1119 if (hotk->methods->mt_mled) { 1120 asus_proc_add(PROC_MLED, &mled_proc_fops, mode, device); 1121 } 1122 1123 if (hotk->methods->mt_tled) { 1124 asus_proc_add(PROC_TLED, &tled_proc_fops, mode, device); 1125 } 1126 1127 if (hotk->methods->mt_bt_switch) { 1128 asus_proc_add(PROC_BT, &bluetooth_proc_fops, mode, device); 1129 } 1130 1131 /* 1132 * We need both read node and write method as LCD switch is also 1133 * accessible from the keyboard 1134 */ 1135 if (hotk->methods->mt_lcd_switch && hotk->methods->lcd_status) { 1136 asus_proc_add(PROC_LCD, &lcd_proc_fops, mode, device); 1137 } 1138 1139 if ((hotk->methods->brightness_up && hotk->methods->brightness_down) || 1140 (hotk->methods->brightness_get && hotk->methods->brightness_set)) { 1141 asus_proc_add(PROC_BRN, &brn_proc_fops, mode, device); 1142 } 1143 1144 if (hotk->methods->display_set) { 1145 asus_proc_add(PROC_DISP, &disp_proc_fops, mode, device); 1146 } 1147 1148 return 0; 1149} 1150 1151static int asus_hotk_remove_fs(struct acpi_device *device) 1152{ 1153 if (acpi_device_dir(device)) { 1154 remove_proc_entry(PROC_INFO, acpi_device_dir(device)); 1155 if (hotk->methods->mt_wled) 1156 remove_proc_entry(PROC_WLED, acpi_device_dir(device)); 1157 if (hotk->methods->mt_mled) 1158 remove_proc_entry(PROC_MLED, acpi_device_dir(device)); 1159 if (hotk->methods->mt_tled) 1160 remove_proc_entry(PROC_TLED, acpi_device_dir(device)); 1161 if (hotk->methods->mt_ledd) 1162 remove_proc_entry(PROC_LEDD, acpi_device_dir(device)); 1163 if (hotk->methods->mt_bt_switch) 1164 remove_proc_entry(PROC_BT, acpi_device_dir(device)); 1165 if (hotk->methods->mt_lcd_switch && hotk->methods->lcd_status) 1166 remove_proc_entry(PROC_LCD, acpi_device_dir(device)); 1167 if ((hotk->methods->brightness_up 1168 && hotk->methods->brightness_down) 1169 || (hotk->methods->brightness_get 1170 && hotk->methods->brightness_set)) 1171 remove_proc_entry(PROC_BRN, acpi_device_dir(device)); 1172 if (hotk->methods->display_set) 1173 remove_proc_entry(PROC_DISP, acpi_device_dir(device)); 1174 } 1175 return 0; 1176} 1177 1178static void asus_hotk_notify(struct acpi_device *device, u32 event) 1179{ 1180 /* TODO Find a better way to handle events count. */ 1181 if (!hotk) 1182 return; 1183 1184 /* 1185 * The BIOS *should* be sending us device events, but apparently 1186 * Asus uses system events instead, so just ignore any device 1187 * events we get. 1188 */ 1189 if (event > ACPI_MAX_SYS_NOTIFY) 1190 return; 1191 1192 if ((event & ~((u32) BR_UP)) < 16) 1193 hotk->brightness = (event & ~((u32) BR_UP)); 1194 else if ((event & ~((u32) BR_DOWN)) < 16) 1195 hotk->brightness = (event & ~((u32) BR_DOWN)); 1196 1197 acpi_bus_generate_proc_event(hotk->device, event, 1198 hotk->event_count[event % 128]++); 1199 1200 return; 1201} 1202 1203/* 1204 * Match the model string to the list of supported models. Return END_MODEL if 1205 * no match or model is NULL. 1206 */ 1207static int asus_model_match(char *model) 1208{ 1209 if (model == NULL) 1210 return END_MODEL; 1211 1212 if (strncmp(model, "L3D", 3) == 0) 1213 return L3D; 1214 else if (strncmp(model, "L2E", 3) == 0 || 1215 strncmp(model, "L3H", 3) == 0 || strncmp(model, "L5D", 3) == 0) 1216 return L3H; 1217 else if (strncmp(model, "L3", 2) == 0 || strncmp(model, "L2B", 3) == 0) 1218 return L3C; 1219 else if (strncmp(model, "L8L", 3) == 0) 1220 return L8L; 1221 else if (strncmp(model, "L4R", 3) == 0) 1222 return L4R; 1223 else if (strncmp(model, "M6N", 3) == 0 || strncmp(model, "W3N", 3) == 0) 1224 return M6N; 1225 else if (strncmp(model, "M6R", 3) == 0 || strncmp(model, "A3G", 3) == 0) 1226 return M6R; 1227 else if (strncmp(model, "M2N", 3) == 0 || 1228 strncmp(model, "M3N", 3) == 0 || 1229 strncmp(model, "M5N", 3) == 0 || 1230 strncmp(model, "S1N", 3) == 0 || 1231 strncmp(model, "S5N", 3) == 0) 1232 return xxN; 1233 else if (strncmp(model, "M1", 2) == 0) 1234 return M1A; 1235 else if (strncmp(model, "M2", 2) == 0 || strncmp(model, "L4E", 3) == 0) 1236 return M2E; 1237 else if (strncmp(model, "L2", 2) == 0) 1238 return L2D; 1239 else if (strncmp(model, "L8", 2) == 0) 1240 return S1x; 1241 else if (strncmp(model, "D1", 2) == 0) 1242 return D1x; 1243 else if (strncmp(model, "A1", 2) == 0) 1244 return A1x; 1245 else if (strncmp(model, "A2", 2) == 0) 1246 return A2x; 1247 else if (strncmp(model, "J1", 2) == 0) 1248 return S2x; 1249 else if (strncmp(model, "L5", 2) == 0) 1250 return L5x; 1251 else if (strncmp(model, "A4G", 3) == 0) 1252 return A4G; 1253 else if (strncmp(model, "W1N", 3) == 0) 1254 return W1N; 1255 else if (strncmp(model, "W3V", 3) == 0) 1256 return W3V; 1257 else if (strncmp(model, "W5A", 3) == 0) 1258 return W5A; 1259 else if (strncmp(model, "R1F", 3) == 0) 1260 return R1F; 1261 else if (strncmp(model, "A4S", 3) == 0) 1262 return A4S; 1263 else if (strncmp(model, "F3Sa", 4) == 0) 1264 return F3Sa; 1265 else 1266 return END_MODEL; 1267} 1268 1269/* 1270 * This function is used to initialize the hotk with right values. In this 1271 * method, we can make all the detection we want, and modify the hotk struct 1272 */ 1273static int asus_hotk_get_info(void) 1274{ 1275 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 1276 union acpi_object *model = NULL; 1277 int bsts_result; 1278 char *string = NULL; 1279 acpi_status status; 1280 1281 /* 1282 * Get DSDT headers early enough to allow for differentiating between 1283 * models, but late enough to allow acpi_bus_register_driver() to fail 1284 * before doing anything ACPI-specific. Should we encounter a machine, 1285 * which needs special handling (i.e. its hotkey device has a different 1286 * HID), this bit will be moved. A global variable asus_info contains 1287 * the DSDT header. 1288 */ 1289 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus_info); 1290 if (ACPI_FAILURE(status)) 1291 printk(KERN_WARNING " Couldn't get the DSDT table header\n"); 1292 1293 /* We have to write 0 on init this far for all ASUS models */ 1294 if (!write_acpi_int(hotk->handle, "INIT", 0, &buffer)) { 1295 printk(KERN_ERR " Hotkey initialization failed\n"); 1296 return -ENODEV; 1297 } 1298 1299 /* This needs to be called for some laptops to init properly */ 1300 if (!read_acpi_int(hotk->handle, "BSTS", &bsts_result)) 1301 printk(KERN_WARNING " Error calling BSTS\n"); 1302 else if (bsts_result) 1303 printk(KERN_NOTICE " BSTS called, 0x%02x returned\n", 1304 bsts_result); 1305 1306 /* 1307 * Try to match the object returned by INIT to the specific model. 1308 * Handle every possible object (or the lack of thereof) the DSDT 1309 * writers might throw at us. When in trouble, we pass NULL to 1310 * asus_model_match() and try something completely different. 1311 */ 1312 if (buffer.pointer) { 1313 model = buffer.pointer; 1314 switch (model->type) { 1315 case ACPI_TYPE_STRING: 1316 string = model->string.pointer; 1317 break; 1318 case ACPI_TYPE_BUFFER: 1319 string = model->buffer.pointer; 1320 break; 1321 default: 1322 kfree(model); 1323 model = NULL; 1324 break; 1325 } 1326 } 1327 hotk->model = asus_model_match(string); 1328 if (hotk->model == END_MODEL) { /* match failed */ 1329 if (asus_info && 1330 strncmp(asus_info->oem_table_id, "ODEM", 4) == 0) { 1331 hotk->model = P30; 1332 printk(KERN_NOTICE 1333 " Samsung P30 detected, supported\n"); 1334 hotk->methods = &model_conf[hotk->model]; 1335 kfree(model); 1336 return 0; 1337 } else { 1338 hotk->model = M2E; 1339 printk(KERN_NOTICE " unsupported model %s, trying " 1340 "default values\n", string); 1341 printk(KERN_NOTICE 1342 " send /proc/acpi/dsdt to the developers\n"); 1343 kfree(model); 1344 return -ENODEV; 1345 } 1346 } 1347 hotk->methods = &model_conf[hotk->model]; 1348 printk(KERN_NOTICE " %s model detected, supported\n", string); 1349 1350 /* Sort of per-model blacklist */ 1351 if (strncmp(string, "L2B", 3) == 0) 1352 hotk->methods->lcd_status = NULL; 1353 /* L2B is similar enough to L3C to use its settings, with this only 1354 exception */ 1355 else if (strncmp(string, "A3G", 3) == 0) 1356 hotk->methods->lcd_status = "\\BLFG"; 1357 /* A3G is like M6R */ 1358 else if (strncmp(string, "S5N", 3) == 0 || 1359 strncmp(string, "M5N", 3) == 0 || 1360 strncmp(string, "W3N", 3) == 0) 1361 hotk->methods->mt_mled = NULL; 1362 /* S5N, M5N and W3N have no MLED */ 1363 else if (strncmp(string, "L5D", 3) == 0) 1364 hotk->methods->mt_wled = NULL; 1365 /* L5D's WLED is not controlled by ACPI */ 1366 else if (strncmp(string, "M2N", 3) == 0 || 1367 strncmp(string, "W3V", 3) == 0 || 1368 strncmp(string, "S1N", 3) == 0) 1369 hotk->methods->mt_wled = "WLED"; 1370 /* M2N, S1N and W3V have a usable WLED */ 1371 else if (asus_info) { 1372 if (strncmp(asus_info->oem_table_id, "L1", 2) == 0) 1373 hotk->methods->mled_status = NULL; 1374 /* S1300A reports L84F, but L1400B too, account for that */ 1375 } 1376 1377 kfree(model); 1378 1379 return 0; 1380} 1381 1382static int asus_hotk_check(void) 1383{ 1384 int result = 0; 1385 1386 result = acpi_bus_get_status(hotk->device); 1387 if (result) 1388 return result; 1389 1390 if (hotk->device->status.present) { 1391 result = asus_hotk_get_info(); 1392 } else { 1393 printk(KERN_ERR " Hotkey device not present, aborting\n"); 1394 return -EINVAL; 1395 } 1396 1397 return result; 1398} 1399 1400static int asus_hotk_found; 1401 1402static int asus_hotk_add(struct acpi_device *device) 1403{ 1404 acpi_status status = AE_OK; 1405 int result; 1406 1407 printk(KERN_NOTICE "Asus Laptop ACPI Extras version %s\n", 1408 ASUS_ACPI_VERSION); 1409 1410 hotk = kzalloc(sizeof(struct asus_hotk), GFP_KERNEL); 1411 if (!hotk) 1412 return -ENOMEM; 1413 1414 hotk->handle = device->handle; 1415 strcpy(acpi_device_name(device), ACPI_HOTK_DEVICE_NAME); 1416 strcpy(acpi_device_class(device), ACPI_HOTK_CLASS); 1417 device->driver_data = hotk; 1418 hotk->device = device; 1419 1420 result = asus_hotk_check(); 1421 if (result) 1422 goto end; 1423 1424 result = asus_hotk_add_fs(device); 1425 if (result) 1426 goto end; 1427 1428 /* For laptops without GPLV: init the hotk->brightness value */ 1429 if ((!hotk->methods->brightness_get) 1430 && (!hotk->methods->brightness_status) 1431 && (hotk->methods->brightness_up && hotk->methods->brightness_down)) { 1432 status = 1433 acpi_evaluate_object(NULL, hotk->methods->brightness_down, 1434 NULL, NULL); 1435 if (ACPI_FAILURE(status)) 1436 printk(KERN_WARNING " Error changing brightness\n"); 1437 else { 1438 status = 1439 acpi_evaluate_object(NULL, 1440 hotk->methods->brightness_up, 1441 NULL, NULL); 1442 if (ACPI_FAILURE(status)) 1443 printk(KERN_WARNING " Strange, error changing" 1444 " brightness\n"); 1445 } 1446 } 1447 1448 asus_hotk_found = 1; 1449 1450 /* LED display is off by default */ 1451 hotk->ledd_status = 0xFFF; 1452 1453end: 1454 if (result) 1455 kfree(hotk); 1456 1457 return result; 1458} 1459 1460static int asus_hotk_remove(struct acpi_device *device, int type) 1461{ 1462 asus_hotk_remove_fs(device); 1463 1464 kfree(hotk); 1465 1466 return 0; 1467} 1468 1469static struct backlight_ops asus_backlight_data = { 1470 .get_brightness = read_brightness, 1471 .update_status = set_brightness_status, 1472}; 1473 1474static void asus_acpi_exit(void) 1475{ 1476 if (asus_backlight_device) 1477 backlight_device_unregister(asus_backlight_device); 1478 1479 acpi_bus_unregister_driver(&asus_hotk_driver); 1480 remove_proc_entry(PROC_ASUS, acpi_root_dir); 1481 1482 return; 1483} 1484 1485static int __init asus_acpi_init(void) 1486{ 1487 struct backlight_properties props; 1488 int result; 1489 1490 result = acpi_bus_register_driver(&asus_hotk_driver); 1491 if (result < 0) 1492 return result; 1493 1494 asus_proc_dir = proc_mkdir(PROC_ASUS, acpi_root_dir); 1495 if (!asus_proc_dir) { 1496 printk(KERN_ERR "Asus ACPI: Unable to create /proc entry\n"); 1497 acpi_bus_unregister_driver(&asus_hotk_driver); 1498 return -ENODEV; 1499 } 1500 1501 /* 1502 * This is a bit of a kludge. We only want this module loaded 1503 * for ASUS systems, but there's currently no way to probe the 1504 * ACPI namespace for ASUS HIDs. So we just return failure if 1505 * we didn't find one, which will cause the module to be 1506 * unloaded. 1507 */ 1508 if (!asus_hotk_found) { 1509 acpi_bus_unregister_driver(&asus_hotk_driver); 1510 remove_proc_entry(PROC_ASUS, acpi_root_dir); 1511 return -ENODEV; 1512 } 1513 1514 memset(&props, 0, sizeof(struct backlight_properties)); 1515 props.max_brightness = 15; 1516 asus_backlight_device = backlight_device_register("asus", NULL, NULL, 1517 &asus_backlight_data, 1518 &props); 1519 if (IS_ERR(asus_backlight_device)) { 1520 printk(KERN_ERR "Could not register asus backlight device\n"); 1521 asus_backlight_device = NULL; 1522 asus_acpi_exit(); 1523 return -ENODEV; 1524 } 1525 1526 return 0; 1527} 1528 1529module_init(asus_acpi_init); 1530module_exit(asus_acpi_exit); 1531