2 * asus_acpi.c - Asus Laptop ACPI Extras
5 * Copyright (C) 2002, 2003, 2004 Julien Lerouge, Karol Kozimor
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.
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.
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
22 * The development page for this driver is located at
23 * http://sourceforge.net/projects/acpi4asus/
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.
32 * Add mode selection on module loading (parameter) -> still necessary?
33 * Complete display switching -- may require dirty hacks or calling _DOS?
36 #include <linux/kernel.h>
37 #include <linux/module.h>
38 #include <linux/init.h>
39 #include <linux/types.h>
40 #include <linux/proc_fs.h>
41 #include <acpi/acpi_drivers.h>
42 #include <acpi/acpi_bus.h>
44 #define ASUS_ACPI_VERSION "0.28"
46 #define PROC_ASUS "asus" //the directory
47 #define PROC_MLED "mled"
48 #define PROC_WLED "wled"
49 #define PROC_TLED "tled"
50 #define PROC_INFO "info"
51 #define PROC_LCD "lcd"
52 #define PROC_BRN "brn"
53 #define PROC_DISP "disp"
55 #define ACPI_HOTK_NAME "Asus Laptop ACPI Extras Driver"
56 #define ACPI_HOTK_CLASS "hotkey"
57 #define ACPI_HOTK_DEVICE_NAME "Hotkey"
58 #define ACPI_HOTK_HID "ATK0100"
61 * Some events we use, same for all Asus
67 * Flags for hotk status
69 #define MLED_ON 0x01 //is MLED ON ?
73 MODULE_AUTHOR("Julien Lerouge, Karol Kozimor");
74 MODULE_DESCRIPTION(ACPI_HOTK_NAME);
75 MODULE_LICENSE("GPL");
78 static uid_t asus_uid;
79 static gid_t asus_gid;
80 MODULE_PARM(asus_uid, "i");
81 MODULE_PARM_DESC(uid, "UID for entries in /proc/acpi/asus.\n");
82 MODULE_PARM(asus_gid, "i");
83 MODULE_PARM_DESC(gid, "GID for entries in /proc/acpi/asus.\n");
86 /* For each model, all features implemented,
87 * those marked with R are relative to HOTK, A for absolute */
89 char *name; //name of the laptop________________A
90 char *mt_mled; //method to handle mled_____________R
91 char *mled_status; //node to handle mled reading_______A
92 char *mt_wled; //method to handle wled_____________R
93 char *wled_status; //node to handle wled reading_______A
94 char *mt_tled; //method to handle tled_____________R
95 char *tled_status; //node to handle tled reading_______A
96 char *mt_lcd_switch; //method to turn LCD ON/OFF_________A
97 char *lcd_status; //node to read LCD panel state______A
98 char *brightness_up; //method to set brightness up_______A
99 char *brightness_down; //guess what ?______________________A
100 char *brightness_set; //method to set absolute brightness_R
101 char *brightness_get; //method to get absolute brightness_R
102 char *brightness_status; //node to get brightness____________A
103 char *display_set; //method to set video output________R
104 char *display_get; //method to get video output________R
108 * This is the main structure, we can use it to store anything interesting
109 * about the hotk device
112 struct acpi_device *device; //the device we are in
113 acpi_handle handle; //the handle of the hotk device
114 char status; //status of the hotk, for LEDs, ...
115 struct model_data *methods; //methods available on the laptop
116 u8 brightness; //brightness level
118 A1x = 0, //A1340D, A1300F
124 L3H, //L3H, but also L2000E
128 M2E, //M2400E, L4400L
130 S1x, //S1300A, but also L1400B and M2400A (L84F)
131 S2x, //S200 (J1 reported), Victor MP-XP7210
132 xxN, //M2400N, M3700N, M6800N, S1300N, S5200N (Centrino)
134 } model; //Models currently supported
135 u16 event_count[128]; //count for each event TODO make this better
139 #define A1x_PREFIX "\\_SB.PCI0.ISA.EC0."
140 #define L3C_PREFIX "\\_SB.PCI0.PX40.ECD0."
141 #define M1A_PREFIX "\\_SB.PCI0.PX40.EC0."
142 #define P30_PREFIX "\\_SB.PCI0.LPCB.EC0."
143 #define S1x_PREFIX "\\_SB.PCI0.PX40."
144 #define S2x_PREFIX A1x_PREFIX
145 #define xxN_PREFIX "\\_SB.PCI0.SBRG.EC0."
147 static struct model_data model_conf[END_MODEL] = {
149 * Those pathnames are relative to the HOTK / ATKD device :
157 * TODO I have seen a SWBX and AIBX method on some models, like L1400B,
158 * it seems to be a kind of switch, but what for ?
165 .mled_status = "\\MAIL",
166 .mt_lcd_switch = A1x_PREFIX "_Q10",
167 .lcd_status = "\\BKLI",
168 .brightness_up = A1x_PREFIX "_Q0E",
169 .brightness_down = A1x_PREFIX "_Q0F"
176 .wled_status = "\\SG66",
177 .mt_lcd_switch = "\\Q10",
178 .lcd_status = "\\BAOF",
179 .brightness_set = "SPLV",
180 .brightness_get = "GPLV",
181 .display_set = "SDSP",
182 .display_get = "\\INFB"
188 .mt_lcd_switch = "\\Q0D",
189 .lcd_status = "\\GP11",
190 .brightness_up = "\\Q0C",
191 .brightness_down = "\\Q0B",
192 .brightness_status = "\\BLVL",
193 .display_set = "SDSP",
194 .display_get = "\\INFB"
200 .mled_status = "\\SGP6",
202 .wled_status = "\\RCP3",
203 .mt_lcd_switch = "\\Q10",
204 .lcd_status = "\\SGP0",
205 .brightness_up = "\\Q0E",
206 .brightness_down = "\\Q0F",
207 .display_set = "SDSP",
208 .display_get = "\\INFB"
215 .mt_lcd_switch = L3C_PREFIX "_Q10",
216 .lcd_status = "\\GL32",
217 .brightness_set = "SPLV",
218 .brightness_get = "GPLV",
219 .display_set = "SDSP",
220 .display_get = "\\_SB.PCI0.PCI1.VGAC.NMAP"
226 .mled_status = "\\MALD",
228 .mt_lcd_switch = "\\Q10",
229 .lcd_status = "\\BKLG",
230 .brightness_set = "SPLV",
231 .brightness_get = "GPLV",
232 .display_set = "SDSP",
233 .display_get = "\\INFB"
240 .mt_lcd_switch = "EHK",
241 .lcd_status = "\\_SB.PCI0.PM.PBC",
242 .brightness_set = "SPLV",
243 .brightness_get = "GPLV",
244 .display_set = "SDSP",
245 .display_get = "\\INFB"
251 /* WLED present, but not controlled by ACPI */
253 .mt_lcd_switch = "\\Q0D",
254 .lcd_status = "\\BAOF",
255 .brightness_set = "SPLV",
256 .brightness_get = "GPLV",
257 .display_set = "SDSP",
258 .display_get = "\\INFB"
263 /* No features, but at least support the hotkeys */
269 .mt_lcd_switch = M1A_PREFIX "Q10",
270 .lcd_status = "\\PNOF",
271 .brightness_up = M1A_PREFIX "Q0E",
272 .brightness_down = M1A_PREFIX "Q0F",
273 .brightness_status = "\\BRIT",
274 .display_set = "SDSP",
275 .display_get = "\\INFB"
282 .mt_lcd_switch = "\\Q10",
283 .lcd_status = "\\GP06",
284 .brightness_set = "SPLV",
285 .brightness_get = "GPLV",
286 .display_set = "SDSP",
287 .display_get = "\\INFB"
293 .mt_lcd_switch = P30_PREFIX "_Q0E",
294 .lcd_status = "\\BKLT",
295 .brightness_up = P30_PREFIX "_Q68",
296 .brightness_down = P30_PREFIX "_Q69",
297 .brightness_get = "GPLV",
298 .display_set = "SDSP",
299 .display_get = "\\DNXT"
305 .mled_status = "\\EMLE",
307 .mt_lcd_switch = S1x_PREFIX "Q10" ,
308 .lcd_status = "\\PNOF",
309 .brightness_set = "SPLV",
310 .brightness_get = "GPLV"
316 .mled_status = "\\MAIL",
317 .mt_lcd_switch = S2x_PREFIX "_Q10",
318 .lcd_status = "\\BKLI",
319 .brightness_up = S2x_PREFIX "_Q0B",
320 .brightness_down = S2x_PREFIX "_Q0A"
326 /* WLED present, but not controlled by ACPI */
327 .mt_lcd_switch = xxN_PREFIX "_Q10",
328 .lcd_status = "\\BKLT",
329 .brightness_set = "SPLV",
330 .brightness_get = "GPLV",
331 .display_set = "SDSP",
332 .display_get = "\\ADVG"
337 static struct proc_dir_entry *asus_proc_dir;
340 * This header is made available to allow proper configuration given model,
341 * revision number , ... this info cannot go in struct asus_hotk because it is
342 * available before the hotk
344 static struct acpi_table_header *asus_info;
347 * The hotkey driver declaration
349 static int asus_hotk_add(struct acpi_device *device);
350 static int asus_hotk_remove(struct acpi_device *device, int type);
351 static struct acpi_driver asus_hotk_driver = {
352 .name = ACPI_HOTK_NAME,
353 .class = ACPI_HOTK_CLASS,
354 .ids = ACPI_HOTK_HID,
356 .add = asus_hotk_add,
357 .remove = asus_hotk_remove,
362 * This function evaluates an ACPI method, given an int as parameter, the
363 * method is searched within the scope of the handle, can be NULL. The output
364 * of the method is written is output, which can also be NULL
366 * returns 1 if write is successful, 0 else.
368 static int write_acpi_int(acpi_handle handle, const char *method, int val,
369 struct acpi_buffer *output)
371 struct acpi_object_list params; //list of input parameters (an int here)
372 union acpi_object in_obj; //the only param we use
376 params.pointer = &in_obj;
377 in_obj.type = ACPI_TYPE_INTEGER;
378 in_obj.integer.value = val;
380 status = acpi_evaluate_object(handle, (char *) method, ¶ms, output);
381 return (status == AE_OK);
385 static int read_acpi_int(acpi_handle handle, const char *method, int *val)
387 struct acpi_buffer output;
388 union acpi_object out_obj;
391 output.length = sizeof(out_obj);
392 output.pointer = &out_obj;
394 status = acpi_evaluate_object(handle, (char *) method, NULL, &output);
395 *val = out_obj.integer.value;
396 return (status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER);
400 * We write our info in page, we begin at offset off and cannot write more
401 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
402 * number of bytes written in page
405 proc_read_info(char *page, char **start, off_t off, int count, int *eof,
410 struct asus_hotk *hotk = (struct asus_hotk *) data;
411 char buf[16]; //enough for all info
413 * We use the easy way, we don't care of off and count, so we don't set eof
417 len += sprintf(page, ACPI_HOTK_NAME " " ASUS_ACPI_VERSION "\n");
418 len += sprintf(page + len, "Model reference : %s\n",
419 hotk->methods->name);
421 * The SFUN method probably allows the original driver to get the list
422 * of features supported by a given model. For now, 0x0100 or 0x0800
423 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
424 * The significance of others is yet to be found.
426 if (read_acpi_int(hotk->handle, "SFUN", &temp))
427 len += sprintf(page + len, "SFUN value : 0x%04x\n", temp);
429 * Another value for userspace: the ASYM method returns 0x02 for
430 * battery low and 0x04 for battery critical, it's readings tend to be
431 * more accurate than those provided by _BST.
432 * Note: since not all the laptops provide this method, errors are
435 if (read_acpi_int(hotk->handle, "ASYM", &temp))
436 len += sprintf(page + len, "ASYM value : 0x%04x\n", temp);
438 snprintf(buf, 16, "%d", asus_info->length);
439 len += sprintf(page + len, "DSDT length : %s\n", buf);
440 snprintf(buf, 16, "%d", asus_info->checksum);
441 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
442 snprintf(buf, 16, "%d", asus_info->revision);
443 len += sprintf(page + len, "DSDT revision : %s\n", buf);
444 snprintf(buf, 7, "%s", asus_info->oem_id);
445 len += sprintf(page + len, "OEM id : %s\n", buf);
446 snprintf(buf, 9, "%s", asus_info->oem_table_id);
447 len += sprintf(page + len, "OEM table id : %s\n", buf);
448 snprintf(buf, 16, "%x", asus_info->oem_revision);
449 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
450 snprintf(buf, 5, "%s", asus_info->asl_compiler_id);
451 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
452 snprintf(buf, 16, "%x", asus_info->asl_compiler_revision);
453 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
462 * We write our info in page, we begin at offset off and cannot write more
463 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
464 * number of bytes written in page
467 /* Generic LED functions */
469 read_led(struct asus_hotk *hotk, const char *ledname, int ledmask)
474 if (read_acpi_int(NULL, ledname, &led_status))
477 printk(KERN_WARNING "Asus ACPI: Error reading LED "
480 return (hotk->status & ledmask) ? 1 : 0;
484 /* FIXME: kill extraneous args so it can be called independently */
486 write_led(const char *buffer, unsigned long count, struct asus_hotk *hotk,
487 char *ledname, int ledmask, int invert)
492 if (sscanf(buffer, "%i", &value) == 1)
493 led_out = value ? 1 : 0;
496 (led_out) ? (hotk->status | ledmask) : (hotk->status & ~ledmask);
498 if (invert) /* invert target value */
499 led_out = !led_out & 0x1;
501 if (!write_acpi_int(hotk->handle, ledname, led_out, NULL))
502 printk(KERN_WARNING "Asus ACPI: LED (%s) write failed\n", ledname);
509 * Proc handlers for MLED
512 proc_read_mled(char *page, char **start, off_t off, int count, int *eof,
515 struct asus_hotk *hotk = (struct asus_hotk *) data;
516 return sprintf(page, "%d\n", read_led(hotk, hotk->methods->mled_status, MLED_ON));
521 proc_write_mled(struct file *file, const char *buffer,
522 unsigned long count, void *data)
524 struct asus_hotk *hotk = (struct asus_hotk *) data;
525 return write_led(buffer, count, hotk, hotk->methods->mt_mled, MLED_ON, 1);
529 * Proc handlers for WLED
532 proc_read_wled(char *page, char **start, off_t off, int count, int *eof,
535 struct asus_hotk *hotk = (struct asus_hotk *) data;
536 return sprintf(page, "%d\n", read_led(hotk, hotk->methods->wled_status, WLED_ON));
540 proc_write_wled(struct file *file, const char *buffer,
541 unsigned long count, void *data)
543 struct asus_hotk *hotk = (struct asus_hotk *) data;
544 return write_led(buffer, count, hotk, hotk->methods->mt_wled, WLED_ON, 0);
548 * Proc handlers for TLED
551 proc_read_tled(char *page, char **start, off_t off, int count, int *eof,
554 struct asus_hotk *hotk = (struct asus_hotk *) data;
555 return sprintf(page, "%d\n", read_led(hotk, hotk->methods->tled_status, TLED_ON));
559 proc_write_tled(struct file *file, const char *buffer,
560 unsigned long count, void *data)
562 struct asus_hotk *hotk = (struct asus_hotk *) data;
563 return write_led(buffer, count, hotk, hotk->methods->mt_tled, TLED_ON, 0);
568 static int get_lcd_state(struct asus_hotk *hotk)
572 if (hotk->model != L3H) {
573 /* We don't have to check anything if we are here */
574 if (!read_acpi_int(NULL, hotk->methods->lcd_status, &lcd))
575 printk(KERN_WARNING "Asus ACPI: Error reading LCD status\n");
577 if (hotk->model == L2D)
579 } else { /* L3H and the like have to be handled differently */
580 acpi_status status = 0;
581 struct acpi_object_list input;
582 union acpi_object mt_params[2];
583 struct acpi_buffer output;
584 union acpi_object out_obj;
587 input.pointer = mt_params;
588 /* Note: the following values are partly guessed up, but
589 otherwise they seem to work */
590 mt_params[0].type = ACPI_TYPE_INTEGER;
591 mt_params[0].integer.value = 0x02;
592 mt_params[1].type = ACPI_TYPE_INTEGER;
593 mt_params[1].integer.value = 0x02;
595 output.length = sizeof(out_obj);
596 output.pointer = &out_obj;
598 status = acpi_evaluate_object(NULL, hotk->methods->lcd_status, &input, &output);
601 if (out_obj.type == ACPI_TYPE_INTEGER)
602 /* That's what the AML code does */
603 lcd = out_obj.integer.value >> 8;
609 static int set_lcd_state(struct asus_hotk *hotk, int value)
612 acpi_status status = 0;
615 if (lcd != get_lcd_state(hotk)) {
617 if (hotk->model != L3H) {
619 acpi_evaluate_object(NULL, hotk->methods->mt_lcd_switch,
621 } else { /* L3H and the like have to be handled differently */
622 if (!write_acpi_int(hotk->handle, hotk->methods->mt_lcd_switch, 0x07, NULL))
624 /* L3H's AML executes EHK (0x07) upon Fn+F7 keypress,
625 the exact behaviour is simulated here */
627 if (ACPI_FAILURE(status))
628 printk(KERN_WARNING "Asus ACPI: Error switching LCD\n");
635 proc_read_lcd(char *page, char **start, off_t off, int count, int *eof,
638 return sprintf(page, "%d\n", get_lcd_state((struct asus_hotk *) data));
643 proc_write_lcd(struct file *file, const char *buffer,
644 unsigned long count, void *data)
647 struct asus_hotk *hotk = (struct asus_hotk *) data;
649 if (sscanf(buffer, "%i", &value) == 1)
650 set_lcd_state(hotk, value);
655 static int read_brightness(struct asus_hotk *hotk)
659 if(hotk->methods->brightness_get) { /* SPLV/GPLV laptop */
660 if (!read_acpi_int(hotk->handle, hotk->methods->brightness_get,
662 printk(KERN_WARNING "Asus ACPI: Error reading brightness\n");
663 } else if (hotk->methods->brightness_status) { /* For D1 for example */
664 if (!read_acpi_int(NULL, hotk->methods->brightness_status,
666 printk(KERN_WARNING "Asus ACPI: Error reading brightness\n");
667 } else /* No GPLV method */
668 value = hotk->brightness;
673 * Change the brightness level
675 static void set_brightness(int value, struct asus_hotk *hotk)
677 acpi_status status = 0;
680 if(hotk->methods->brightness_set) {
681 if (!write_acpi_int(hotk->handle, hotk->methods->brightness_set,
683 printk(KERN_WARNING "Asus ACPI: Error changing brightness\n");
687 /* No SPLV method if we are here, act as appropriate */
688 value -= read_brightness(hotk);
690 status = acpi_evaluate_object(NULL, (value > 0) ?
691 hotk->methods->brightness_up :
692 hotk->methods->brightness_down,
694 (value > 0) ? value-- : value++;
695 if (ACPI_FAILURE(status))
696 printk(KERN_WARNING "Asus ACPI: Error changing brightness\n");
702 proc_read_brn(char *page, char **start, off_t off, int count, int *eof,
705 struct asus_hotk *hotk = (struct asus_hotk *) data;
706 return sprintf(page, "%d\n", read_brightness(hotk));
710 proc_write_brn(struct file *file, const char *buffer,
711 unsigned long count, void *data)
714 struct asus_hotk *hotk = (struct asus_hotk *) data;
716 if (sscanf(buffer, "%d", &value) == 1) {
717 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
718 /* 0 <= value <= 15 */
719 set_brightness(value, hotk);
721 printk(KERN_WARNING "Asus ACPI: Error reading user input\n");
727 static void set_display(int value, struct asus_hotk *hotk)
729 /* no sanity check needed for now */
730 if (!write_acpi_int(hotk->handle, hotk->methods->display_set,
732 printk(KERN_WARNING "Asus ACPI: Error setting display\n");
737 * Now, *this* one could be more user-friendly, but so far, no-one has
738 * complained. The significance of bits is the same as in proc_write_disp()
741 proc_read_disp(char *page, char **start, off_t off, int count, int *eof,
745 struct asus_hotk *hotk = (struct asus_hotk *) data;
747 if (!read_acpi_int(hotk->handle, hotk->methods->display_get, &value))
748 printk(KERN_WARNING "Asus ACPI: Error reading display status\n");
749 return sprintf(page, "%d\n", value);
753 * Experimental support for display switching. As of now: 1 should activate
754 * the LCD output, 2 should do for CRT, and 4 for TV-Out. Any combination
755 * (bitwise) of these will suffice. I never actually tested 3 displays hooked up
756 * simultaneously, so be warned. See the acpi4asus README for more info.
759 proc_write_disp(struct file *file, const char *buffer,
760 unsigned long count, void *data)
763 struct asus_hotk *hotk = (struct asus_hotk *) data;
765 if (sscanf(buffer, "%d", &value) == 1)
766 set_display(value, hotk);
768 printk(KERN_WARNING "Asus ACPI: Error reading user input\n");
775 typedef int (proc_readfunc)(char *page, char **start, off_t off, int count,
776 int *eof, void *data);
777 typedef int (proc_writefunc)(struct file *file, const char *buffer,
778 unsigned long count, void *data);
781 __init asus_proc_add(char *name, proc_writefunc *writefunc,
782 proc_readfunc *readfunc, mode_t mode,
783 struct acpi_device *device)
785 struct proc_dir_entry *proc = create_proc_entry(name, mode, acpi_device_dir(device));
787 printk(KERN_WARNING " Unable to create %s fs entry\n", name);
790 proc->write_proc = writefunc;
791 proc->read_proc = readfunc;
792 proc->data = acpi_driver_data(device);
793 proc->owner = THIS_MODULE;
794 proc->uid = asus_uid;
795 proc->gid = asus_gid;
799 static int __init asus_hotk_add_fs(struct acpi_device *device)
801 struct proc_dir_entry *proc;
802 struct asus_hotk *hotk = acpi_driver_data(device);
806 * If parameter uid or gid is not changed, keep the default setting for
807 * our proc entries (-rw-rw-rw-) else, it means we care about security,
808 * and then set to -rw-rw----
811 if ((asus_uid == 0) && (asus_gid == 0)){
812 mode = S_IFREG | S_IRUGO | S_IWUGO;
814 mode = S_IFREG | S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP;
817 acpi_device_dir(device) = asus_proc_dir;
818 if (!acpi_device_dir(device))
821 proc = create_proc_entry(PROC_INFO, mode, acpi_device_dir(device));
823 proc->read_proc = proc_read_info;
824 proc->data = acpi_driver_data(device);
825 proc->owner = THIS_MODULE;
826 proc->uid = asus_uid;
827 proc->gid = asus_gid;
829 printk(KERN_WARNING " Unable to create " PROC_INFO
833 if (hotk->methods->mt_wled) {
834 asus_proc_add(PROC_WLED, &proc_write_wled, &proc_read_wled, mode, device);
837 if (hotk->methods->mt_mled) {
838 asus_proc_add(PROC_MLED, &proc_write_mled, &proc_read_mled, mode, device);
841 if (hotk->methods->mt_tled) {
842 asus_proc_add(PROC_TLED, &proc_write_tled, &proc_read_tled, mode, device);
846 * We need both read node and write method as LCD switch is also accessible
849 if (hotk->methods->mt_lcd_switch && hotk->methods->lcd_status) {
850 asus_proc_add(PROC_LCD, &proc_write_lcd, &proc_read_lcd, mode, device);
853 if ((hotk->methods->brightness_up && hotk->methods->brightness_down) ||
854 (hotk->methods->brightness_get && hotk->methods->brightness_get)) {
855 asus_proc_add(PROC_BRN, &proc_write_brn, &proc_read_brn, mode, device);
858 if (hotk->methods->display_set) {
859 asus_proc_add(PROC_DISP, &proc_write_disp, &proc_read_disp, mode, device);
867 static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
869 /* TODO Find a better way to handle events count. Here, in data, we receive
870 * the hotk, so we can do anything!
872 struct asus_hotk *hotk = (struct asus_hotk *) data;
877 if ((event & ~((u32) BR_UP)) < 16) {
878 hotk->brightness = (event & ~((u32) BR_UP));
879 } else if ((event & ~((u32) BR_DOWN)) < 16 ) {
880 hotk->brightness = (event & ~((u32) BR_DOWN));
883 acpi_bus_generate_event(hotk->device, event,
884 hotk->event_count[event % 128]++);
890 * This function is used to initialize the hotk with right values. In this
891 * method, we can make all the detection we want, and modify the hotk struct
893 static int __init asus_hotk_get_info(struct asus_hotk *hotk)
895 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
896 struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL };
897 union acpi_object *model = NULL;
902 * Get DSDT headers early enough to allow for differentiating between
903 * models, but late enough to allow acpi_bus_register_driver() to fail
904 * before doing anything ACPI-specific. Should we encounter a machine,
905 * which needs special handling (i.e. its hotkey device has a different
906 * HID), this bit will be moved. A global variable asus_info contains
909 status = acpi_get_table(ACPI_TABLE_DSDT, 1, &dsdt);
910 if (ACPI_FAILURE(status))
911 printk(KERN_WARNING " Couldn't get the DSDT table header\n");
913 asus_info = (struct acpi_table_header *) dsdt.pointer;
915 /* We have to write 0 on init this far for all ASUS models */
916 if (!write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
917 printk(KERN_ERR " Hotkey initialization failed\n");
921 /* This needs to be called for some laptops to init properly */
922 if (!read_acpi_int(hotk->handle, "BSTS", &bsts_result))
923 printk(KERN_WARNING " Error calling BSTS\n");
924 else if (bsts_result)
925 printk(KERN_NOTICE " BSTS called, 0x%02x returned\n", bsts_result);
927 /* Samsung P30 has a device with a valid _HID whose INIT does not
928 * return anything. Catch this one and any similar here */
929 if (buffer.pointer == NULL) {
930 if (asus_info && /* Samsung P30 */
931 strncmp(asus_info->oem_table_id, "ODEM", 4) == 0) {
933 printk(KERN_NOTICE " Samsung P30 detected, supported\n");
936 printk(KERN_WARNING " no string returned by INIT\n");
937 printk(KERN_WARNING " trying default values, supply "
938 "the developers with your DSDT\n");
940 hotk->methods = &model_conf[hotk->model];
944 model = (union acpi_object *) buffer.pointer;
945 if (model->type == ACPI_TYPE_STRING) {
946 printk(KERN_NOTICE " %s model detected, ", model->string.pointer);
949 hotk->model = END_MODEL;
950 if (strncmp(model->string.pointer, "L3D", 3) == 0)
952 else if (strncmp(model->string.pointer, "L3H", 3) == 0 ||
953 strncmp(model->string.pointer, "L2E", 3) == 0)
955 else if (strncmp(model->string.pointer, "L3", 2) == 0 ||
956 strncmp(model->string.pointer, "L2B", 3) == 0)
958 else if (strncmp(model->string.pointer, "L8L", 3) == 0)
960 else if (strncmp(model->string.pointer, "M2N", 3) == 0 ||
961 strncmp(model->string.pointer, "M3N", 3) == 0 ||
962 strncmp(model->string.pointer, "M6N", 3) == 0 ||
963 strncmp(model->string.pointer, "S1N", 3) == 0 ||
964 strncmp(model->string.pointer, "S5N", 3) == 0)
966 else if (strncmp(model->string.pointer, "M1", 2) == 0)
968 else if (strncmp(model->string.pointer, "M2", 2) == 0 ||
969 strncmp(model->string.pointer, "L4E", 3) == 0)
971 else if (strncmp(model->string.pointer, "L2", 2) == 0)
973 else if (strncmp(model->string.pointer, "L8", 2) == 0)
975 else if (strncmp(model->string.pointer, "D1", 2) == 0)
977 else if (strncmp(model->string.pointer, "A1", 2) == 0)
979 else if (strncmp(model->string.pointer, "A2", 2) == 0)
981 else if (strncmp(model->string.pointer, "J1", 2) == 0)
983 else if (strncmp(model->string.pointer, "L5", 2) == 0)
986 if (hotk->model == END_MODEL) {
987 /* By default use the same values, as I don't know others */
988 printk("unsupported, trying default values, supply the "
989 "developers with your DSDT\n");
992 printk("supported\n");
995 hotk->methods = &model_conf[hotk->model];
997 /* Sort of per-model blacklist */
998 if (strncmp(model->string.pointer, "L2B", 3) == 0)
999 hotk->methods->lcd_status = NULL;
1000 /* L2B is similar enough to L3C to use its settings, with this only
1002 else if (strncmp(model->string.pointer, "S5N", 3) == 0)
1003 hotk->methods->mt_mled = NULL;
1004 /* S5N has no MLED */
1005 else if (strncmp(model->string.pointer, "M6N", 3) == 0) {
1006 hotk->methods->display_get = NULL; //TODO
1007 hotk->methods->lcd_status = "\\_SB.BKLT";
1008 hotk->methods->mt_wled = "WLED";
1009 hotk->methods->wled_status = "\\_SB.PCI0.SBRG.SG13";
1010 /* M6N differs slightly and has a usable WLED */
1012 else if (asus_info) {
1013 if (strncmp(asus_info->oem_table_id, "L1", 2) == 0)
1014 hotk->methods->mled_status = NULL;
1015 /* S1300A reports L84F, but L1400B too, account for that */
1018 acpi_os_free(model);
1025 static int __init asus_hotk_check(struct asus_hotk *hotk)
1032 result = acpi_bus_get_status(hotk->device);
1036 if (hotk->device->status.present) {
1037 result = asus_hotk_get_info(hotk);
1039 printk(KERN_ERR " Hotkey device not present, aborting\n");
1048 static int __init asus_hotk_add(struct acpi_device *device)
1050 struct asus_hotk *hotk = NULL;
1051 acpi_status status = AE_OK;
1057 printk(KERN_NOTICE "Asus Laptop ACPI Extras version %s\n",
1061 (struct asus_hotk *) kmalloc(sizeof(struct asus_hotk), GFP_KERNEL);
1064 memset(hotk, 0, sizeof(struct asus_hotk));
1066 hotk->handle = device->handle;
1067 strcpy(acpi_device_name(device), ACPI_HOTK_DEVICE_NAME);
1068 strcpy(acpi_device_class(device), ACPI_HOTK_CLASS);
1069 acpi_driver_data(device) = hotk;
1070 hotk->device = device;
1073 result = asus_hotk_check(hotk);
1077 result = asus_hotk_add_fs(device);
1082 * We install the handler, it will receive the hotk in parameter, so, we
1083 * could add other data to the hotk struct
1085 status = acpi_install_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
1086 asus_hotk_notify, hotk);
1087 if (ACPI_FAILURE(status))
1088 printk(KERN_ERR " Error installing notify handler\n");
1090 /* For laptops without GPLV: init the hotk->brightness value */
1091 if ((!hotk->methods->brightness_get) && (!hotk->methods->brightness_status) &&
1092 (hotk->methods->brightness_up && hotk->methods->brightness_down)) {
1093 status = acpi_evaluate_object(NULL, hotk->methods->brightness_down,
1095 if (ACPI_FAILURE(status))
1096 printk(KERN_WARNING " Error changing brightness\n");
1098 status = acpi_evaluate_object(NULL, hotk->methods->brightness_up,
1100 if (ACPI_FAILURE(status))
1101 printk(KERN_WARNING " Strange, error changing"
1115 static int asus_hotk_remove(struct acpi_device *device, int type)
1117 acpi_status status = 0;
1118 struct asus_hotk *hotk = NULL;
1120 if (!device || !acpi_driver_data(device))
1123 hotk = (struct asus_hotk *) acpi_driver_data(device);
1125 status = acpi_remove_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
1127 if (ACPI_FAILURE(status))
1128 printk(KERN_ERR "Asus ACPI: Error removing notify handler\n");
1136 static int __init asus_acpi_init(void)
1140 asus_proc_dir = proc_mkdir(PROC_ASUS, acpi_root_dir);
1141 if (!asus_proc_dir) {
1142 printk(KERN_ERR "Asus ACPI: Unable to create /proc entry\n");
1145 asus_proc_dir->owner = THIS_MODULE;
1147 result = acpi_bus_register_driver(&asus_hotk_driver);
1149 remove_proc_entry(PROC_ASUS, acpi_root_dir);
1157 static void __exit asus_acpi_exit(void)
1159 acpi_bus_unregister_driver(&asus_hotk_driver);
1160 remove_proc_entry(PROC_ASUS, acpi_root_dir);
1162 acpi_os_free(asus_info);
1167 module_init(asus_acpi_init);
1168 module_exit(asus_acpi_exit);