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>
43 #include <asm/uaccess.h>
45 #define ASUS_ACPI_VERSION "0.28"
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_INFO "info"
52 #define PROC_LCD "lcd"
53 #define PROC_BRN "brn"
54 #define PROC_DISP "disp"
56 #define ACPI_HOTK_NAME "Asus Laptop ACPI Extras Driver"
57 #define ACPI_HOTK_CLASS "hotkey"
58 #define ACPI_HOTK_DEVICE_NAME "Hotkey"
59 #define ACPI_HOTK_HID "ATK0100"
62 * Some events we use, same for all Asus
68 * Flags for hotk status
70 #define MLED_ON 0x01 //is MLED ON ?
74 MODULE_AUTHOR("Julien Lerouge, Karol Kozimor");
75 MODULE_DESCRIPTION(ACPI_HOTK_NAME);
76 MODULE_LICENSE("GPL");
79 static uid_t asus_uid;
80 static gid_t asus_gid;
81 MODULE_PARM(asus_uid, "i");
82 MODULE_PARM_DESC(uid, "UID for entries in /proc/acpi/asus.\n");
83 MODULE_PARM(asus_gid, "i");
84 MODULE_PARM_DESC(gid, "GID for entries in /proc/acpi/asus.\n");
87 /* For each model, all features implemented,
88 * those marked with R are relative to HOTK, A for absolute */
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_lcd_switch; //method to turn LCD ON/OFF_________A
98 char *lcd_status; //node to read LCD panel state______A
99 char *brightness_up; //method to set brightness up_______A
100 char *brightness_down; //guess what ?______________________A
101 char *brightness_set; //method to set absolute brightness_R
102 char *brightness_get; //method to get absolute brightness_R
103 char *brightness_status; //node to get brightness____________A
104 char *display_set; //method to set video output________R
105 char *display_get; //method to get video output________R
109 * This is the main structure, we can use it to store anything interesting
110 * about the hotk device
113 struct acpi_device *device; //the device we are in
114 acpi_handle handle; //the handle of the hotk device
115 char status; //status of the hotk, for LEDs, ...
116 struct model_data *methods; //methods available on the laptop
117 u8 brightness; //brightness level
119 A1x = 0, //A1340D, A1300F
125 L3H, //L3H, but also L2000E
129 M2E, //M2400E, L4400L
131 S1x, //S1300A, but also L1400B and M2400A (L84F)
132 S2x, //S200 (J1 reported), Victor MP-XP7210
133 xxN, //M2400N, M3700N, M6800N, S1300N, S5200N (Centrino)
135 } model; //Models currently supported
136 u16 event_count[128]; //count for each event TODO make this better
140 #define A1x_PREFIX "\\_SB.PCI0.ISA.EC0."
141 #define L3C_PREFIX "\\_SB.PCI0.PX40.ECD0."
142 #define M1A_PREFIX "\\_SB.PCI0.PX40.EC0."
143 #define P30_PREFIX "\\_SB.PCI0.LPCB.EC0."
144 #define S1x_PREFIX "\\_SB.PCI0.PX40."
145 #define S2x_PREFIX A1x_PREFIX
146 #define xxN_PREFIX "\\_SB.PCI0.SBRG.EC0."
148 static struct model_data model_conf[END_MODEL] = {
150 * Those pathnames are relative to the HOTK / ATKD device :
158 * TODO I have seen a SWBX and AIBX method on some models, like L1400B,
159 * it seems to be a kind of switch, but what for ?
166 .mled_status = "\\MAIL",
167 .mt_lcd_switch = A1x_PREFIX "_Q10",
168 .lcd_status = "\\BKLI",
169 .brightness_up = A1x_PREFIX "_Q0E",
170 .brightness_down = A1x_PREFIX "_Q0F"
177 .wled_status = "\\SG66",
178 .mt_lcd_switch = "\\Q10",
179 .lcd_status = "\\BAOF",
180 .brightness_set = "SPLV",
181 .brightness_get = "GPLV",
182 .display_set = "SDSP",
183 .display_get = "\\INFB"
189 .mt_lcd_switch = "\\Q0D",
190 .lcd_status = "\\GP11",
191 .brightness_up = "\\Q0C",
192 .brightness_down = "\\Q0B",
193 .brightness_status = "\\BLVL",
194 .display_set = "SDSP",
195 .display_get = "\\INFB"
201 .mled_status = "\\SGP6",
203 .wled_status = "\\RCP3",
204 .mt_lcd_switch = "\\Q10",
205 .lcd_status = "\\SGP0",
206 .brightness_up = "\\Q0E",
207 .brightness_down = "\\Q0F",
208 .display_set = "SDSP",
209 .display_get = "\\INFB"
216 .mt_lcd_switch = L3C_PREFIX "_Q10",
217 .lcd_status = "\\GL32",
218 .brightness_set = "SPLV",
219 .brightness_get = "GPLV",
220 .display_set = "SDSP",
221 .display_get = "\\_SB.PCI0.PCI1.VGAC.NMAP"
227 .mled_status = "\\MALD",
229 .mt_lcd_switch = "\\Q10",
230 .lcd_status = "\\BKLG",
231 .brightness_set = "SPLV",
232 .brightness_get = "GPLV",
233 .display_set = "SDSP",
234 .display_get = "\\INFB"
241 .mt_lcd_switch = "EHK",
242 .lcd_status = "\\_SB.PCI0.PM.PBC",
243 .brightness_set = "SPLV",
244 .brightness_get = "GPLV",
245 .display_set = "SDSP",
246 .display_get = "\\INFB"
252 /* WLED present, but not controlled by ACPI */
254 .mt_lcd_switch = "\\Q0D",
255 .lcd_status = "\\BAOF",
256 .brightness_set = "SPLV",
257 .brightness_get = "GPLV",
258 .display_set = "SDSP",
259 .display_get = "\\INFB"
264 /* No features, but at least support the hotkeys */
270 .mt_lcd_switch = M1A_PREFIX "Q10",
271 .lcd_status = "\\PNOF",
272 .brightness_up = M1A_PREFIX "Q0E",
273 .brightness_down = M1A_PREFIX "Q0F",
274 .brightness_status = "\\BRIT",
275 .display_set = "SDSP",
276 .display_get = "\\INFB"
283 .mt_lcd_switch = "\\Q10",
284 .lcd_status = "\\GP06",
285 .brightness_set = "SPLV",
286 .brightness_get = "GPLV",
287 .display_set = "SDSP",
288 .display_get = "\\INFB"
294 .mt_lcd_switch = P30_PREFIX "_Q0E",
295 .lcd_status = "\\BKLT",
296 .brightness_up = P30_PREFIX "_Q68",
297 .brightness_down = P30_PREFIX "_Q69",
298 .brightness_get = "GPLV",
299 .display_set = "SDSP",
300 .display_get = "\\DNXT"
306 .mled_status = "\\EMLE",
308 .mt_lcd_switch = S1x_PREFIX "Q10" ,
309 .lcd_status = "\\PNOF",
310 .brightness_set = "SPLV",
311 .brightness_get = "GPLV"
317 .mled_status = "\\MAIL",
318 .mt_lcd_switch = S2x_PREFIX "_Q10",
319 .lcd_status = "\\BKLI",
320 .brightness_up = S2x_PREFIX "_Q0B",
321 .brightness_down = S2x_PREFIX "_Q0A"
327 /* WLED present, but not controlled by ACPI */
328 .mt_lcd_switch = xxN_PREFIX "_Q10",
329 .lcd_status = "\\BKLT",
330 .brightness_set = "SPLV",
331 .brightness_get = "GPLV",
332 .display_set = "SDSP",
333 .display_get = "\\ADVG"
338 static struct proc_dir_entry *asus_proc_dir;
341 * This header is made available to allow proper configuration given model,
342 * revision number , ... this info cannot go in struct asus_hotk because it is
343 * available before the hotk
345 static struct acpi_table_header *asus_info;
348 * The hotkey driver declaration
350 static int asus_hotk_add(struct acpi_device *device);
351 static int asus_hotk_remove(struct acpi_device *device, int type);
352 static struct acpi_driver asus_hotk_driver = {
353 .name = ACPI_HOTK_NAME,
354 .class = ACPI_HOTK_CLASS,
355 .ids = ACPI_HOTK_HID,
357 .add = asus_hotk_add,
358 .remove = asus_hotk_remove,
363 * This function evaluates an ACPI method, given an int as parameter, the
364 * method is searched within the scope of the handle, can be NULL. The output
365 * of the method is written is output, which can also be NULL
367 * returns 1 if write is successful, 0 else.
369 static int write_acpi_int(acpi_handle handle, const char *method, int val,
370 struct acpi_buffer *output)
372 struct acpi_object_list params; //list of input parameters (an int here)
373 union acpi_object in_obj; //the only param we use
377 params.pointer = &in_obj;
378 in_obj.type = ACPI_TYPE_INTEGER;
379 in_obj.integer.value = val;
381 status = acpi_evaluate_object(handle, (char *) method, ¶ms, output);
382 return (status == AE_OK);
386 static int read_acpi_int(acpi_handle handle, const char *method, int *val)
388 struct acpi_buffer output;
389 union acpi_object out_obj;
392 output.length = sizeof(out_obj);
393 output.pointer = &out_obj;
395 status = acpi_evaluate_object(handle, (char *) method, NULL, &output);
396 *val = out_obj.integer.value;
397 return (status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER);
401 * We write our info in page, we begin at offset off and cannot write more
402 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
403 * number of bytes written in page
406 proc_read_info(char *page, char **start, off_t off, int count, int *eof,
411 struct asus_hotk *hotk = (struct asus_hotk *) data;
412 char buf[16]; //enough for all info
414 * We use the easy way, we don't care of off and count, so we don't set eof
418 len += sprintf(page, ACPI_HOTK_NAME " " ASUS_ACPI_VERSION "\n");
419 len += sprintf(page + len, "Model reference : %s\n",
420 hotk->methods->name);
422 * The SFUN method probably allows the original driver to get the list
423 * of features supported by a given model. For now, 0x0100 or 0x0800
424 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
425 * The significance of others is yet to be found.
427 if (read_acpi_int(hotk->handle, "SFUN", &temp))
428 len += sprintf(page + len, "SFUN value : 0x%04x\n", temp);
430 * Another value for userspace: the ASYM method returns 0x02 for
431 * battery low and 0x04 for battery critical, it's readings tend to be
432 * more accurate than those provided by _BST.
433 * Note: since not all the laptops provide this method, errors are
436 if (read_acpi_int(hotk->handle, "ASYM", &temp))
437 len += sprintf(page + len, "ASYM value : 0x%04x\n", temp);
439 snprintf(buf, 16, "%d", asus_info->length);
440 len += sprintf(page + len, "DSDT length : %s\n", buf);
441 snprintf(buf, 16, "%d", asus_info->checksum);
442 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
443 snprintf(buf, 16, "%d", asus_info->revision);
444 len += sprintf(page + len, "DSDT revision : %s\n", buf);
445 snprintf(buf, 7, "%s", asus_info->oem_id);
446 len += sprintf(page + len, "OEM id : %s\n", buf);
447 snprintf(buf, 9, "%s", asus_info->oem_table_id);
448 len += sprintf(page + len, "OEM table id : %s\n", buf);
449 snprintf(buf, 16, "%x", asus_info->oem_revision);
450 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
451 snprintf(buf, 5, "%s", asus_info->asl_compiler_id);
452 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
453 snprintf(buf, 16, "%x", asus_info->asl_compiler_revision);
454 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
463 * We write our info in page, we begin at offset off and cannot write more
464 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
465 * number of bytes written in page
468 /* Generic LED functions */
470 read_led(struct asus_hotk *hotk, const char *ledname, int ledmask)
475 if (read_acpi_int(NULL, ledname, &led_status))
478 printk(KERN_WARNING "Asus ACPI: Error reading LED "
481 return (hotk->status & ledmask) ? 1 : 0;
484 static int parse_arg(const char __user *buf, unsigned long count, int *val)
491 if (copy_from_user(s, buf, count))
494 if (sscanf(s, "%i", val) != 1)
499 /* FIXME: kill extraneous args so it can be called independently */
501 write_led(const char __user *buffer, unsigned long count, struct asus_hotk *hotk,
502 char *ledname, int ledmask, int invert)
507 count = parse_arg(buffer, count, &value);
509 led_out = value ? 1 : 0;
512 (led_out) ? (hotk->status | ledmask) : (hotk->status & ~ledmask);
514 if (invert) /* invert target value */
515 led_out = !led_out & 0x1;
517 if (!write_acpi_int(hotk->handle, ledname, led_out, NULL))
518 printk(KERN_WARNING "Asus ACPI: LED (%s) write failed\n", ledname);
525 * Proc handlers for MLED
528 proc_read_mled(char *page, char **start, off_t off, int count, int *eof,
531 struct asus_hotk *hotk = (struct asus_hotk *) data;
532 return sprintf(page, "%d\n", read_led(hotk, hotk->methods->mled_status, MLED_ON));
537 proc_write_mled(struct file *file, const char __user *buffer,
538 unsigned long count, void *data)
540 struct asus_hotk *hotk = (struct asus_hotk *) data;
541 return write_led(buffer, count, hotk, hotk->methods->mt_mled, MLED_ON, 1);
545 * Proc handlers for WLED
548 proc_read_wled(char *page, char **start, off_t off, int count, int *eof,
551 struct asus_hotk *hotk = (struct asus_hotk *) data;
552 return sprintf(page, "%d\n", read_led(hotk, hotk->methods->wled_status, WLED_ON));
556 proc_write_wled(struct file *file, const char __user *buffer,
557 unsigned long count, void *data)
559 struct asus_hotk *hotk = (struct asus_hotk *) data;
560 return write_led(buffer, count, hotk, hotk->methods->mt_wled, WLED_ON, 0);
564 * Proc handlers for TLED
567 proc_read_tled(char *page, char **start, off_t off, int count, int *eof,
570 struct asus_hotk *hotk = (struct asus_hotk *) data;
571 return sprintf(page, "%d\n", read_led(hotk, hotk->methods->tled_status, TLED_ON));
575 proc_write_tled(struct file *file, const char __user *buffer,
576 unsigned long count, void *data)
578 struct asus_hotk *hotk = (struct asus_hotk *) data;
579 return write_led(buffer, count, hotk, hotk->methods->mt_tled, TLED_ON, 0);
584 static int get_lcd_state(struct asus_hotk *hotk)
588 if (hotk->model != L3H) {
589 /* We don't have to check anything if we are here */
590 if (!read_acpi_int(NULL, hotk->methods->lcd_status, &lcd))
591 printk(KERN_WARNING "Asus ACPI: Error reading LCD status\n");
593 if (hotk->model == L2D)
595 } else { /* L3H and the like have to be handled differently */
596 acpi_status status = 0;
597 struct acpi_object_list input;
598 union acpi_object mt_params[2];
599 struct acpi_buffer output;
600 union acpi_object out_obj;
603 input.pointer = mt_params;
604 /* Note: the following values are partly guessed up, but
605 otherwise they seem to work */
606 mt_params[0].type = ACPI_TYPE_INTEGER;
607 mt_params[0].integer.value = 0x02;
608 mt_params[1].type = ACPI_TYPE_INTEGER;
609 mt_params[1].integer.value = 0x02;
611 output.length = sizeof(out_obj);
612 output.pointer = &out_obj;
614 status = acpi_evaluate_object(NULL, hotk->methods->lcd_status, &input, &output);
617 if (out_obj.type == ACPI_TYPE_INTEGER)
618 /* That's what the AML code does */
619 lcd = out_obj.integer.value >> 8;
625 static int set_lcd_state(struct asus_hotk *hotk, int value)
628 acpi_status status = 0;
631 if (lcd != get_lcd_state(hotk)) {
633 if (hotk->model != L3H) {
635 acpi_evaluate_object(NULL, hotk->methods->mt_lcd_switch,
637 } else { /* L3H and the like have to be handled differently */
638 if (!write_acpi_int(hotk->handle, hotk->methods->mt_lcd_switch, 0x07, NULL))
640 /* L3H's AML executes EHK (0x07) upon Fn+F7 keypress,
641 the exact behaviour is simulated here */
643 if (ACPI_FAILURE(status))
644 printk(KERN_WARNING "Asus ACPI: Error switching LCD\n");
651 proc_read_lcd(char *page, char **start, off_t off, int count, int *eof,
654 return sprintf(page, "%d\n", get_lcd_state((struct asus_hotk *) data));
659 proc_write_lcd(struct file *file, const char __user *buffer,
660 unsigned long count, void *data)
663 struct asus_hotk *hotk = (struct asus_hotk *) data;
665 count = parse_arg(buffer, count, &value);
667 set_lcd_state(hotk, value);
672 static int read_brightness(struct asus_hotk *hotk)
676 if(hotk->methods->brightness_get) { /* SPLV/GPLV laptop */
677 if (!read_acpi_int(hotk->handle, hotk->methods->brightness_get,
679 printk(KERN_WARNING "Asus ACPI: Error reading brightness\n");
680 } else if (hotk->methods->brightness_status) { /* For D1 for example */
681 if (!read_acpi_int(NULL, hotk->methods->brightness_status,
683 printk(KERN_WARNING "Asus ACPI: Error reading brightness\n");
684 } else /* No GPLV method */
685 value = hotk->brightness;
690 * Change the brightness level
692 static void set_brightness(int value, struct asus_hotk *hotk)
694 acpi_status status = 0;
697 if(hotk->methods->brightness_set) {
698 if (!write_acpi_int(hotk->handle, hotk->methods->brightness_set,
700 printk(KERN_WARNING "Asus ACPI: Error changing brightness\n");
704 /* No SPLV method if we are here, act as appropriate */
705 value -= read_brightness(hotk);
707 status = acpi_evaluate_object(NULL, (value > 0) ?
708 hotk->methods->brightness_up :
709 hotk->methods->brightness_down,
711 (value > 0) ? value-- : value++;
712 if (ACPI_FAILURE(status))
713 printk(KERN_WARNING "Asus ACPI: Error changing brightness\n");
719 proc_read_brn(char *page, char **start, off_t off, int count, int *eof,
722 struct asus_hotk *hotk = (struct asus_hotk *) data;
723 return sprintf(page, "%d\n", read_brightness(hotk));
727 proc_write_brn(struct file *file, const char __user *buffer,
728 unsigned long count, void *data)
731 struct asus_hotk *hotk = (struct asus_hotk *) data;
733 count = parse_arg(buffer, count, &value);
735 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
736 /* 0 <= value <= 15 */
737 set_brightness(value, hotk);
738 } else if (count < 0) {
739 printk(KERN_WARNING "Asus ACPI: Error reading user input\n");
745 static void set_display(int value, struct asus_hotk *hotk)
747 /* no sanity check needed for now */
748 if (!write_acpi_int(hotk->handle, hotk->methods->display_set,
750 printk(KERN_WARNING "Asus ACPI: Error setting display\n");
755 * Now, *this* one could be more user-friendly, but so far, no-one has
756 * complained. The significance of bits is the same as in proc_write_disp()
759 proc_read_disp(char *page, char **start, off_t off, int count, int *eof,
763 struct asus_hotk *hotk = (struct asus_hotk *) data;
765 if (!read_acpi_int(hotk->handle, hotk->methods->display_get, &value))
766 printk(KERN_WARNING "Asus ACPI: Error reading display status\n");
767 return sprintf(page, "%d\n", value);
771 * Experimental support for display switching. As of now: 1 should activate
772 * the LCD output, 2 should do for CRT, and 4 for TV-Out. Any combination
773 * (bitwise) of these will suffice. I never actually tested 3 displays hooked up
774 * simultaneously, so be warned. See the acpi4asus README for more info.
777 proc_write_disp(struct file *file, const char __user *buffer,
778 unsigned long count, void *data)
781 struct asus_hotk *hotk = (struct asus_hotk *) data;
783 count = parse_arg(buffer, count, &value);
785 set_display(value, hotk);
787 printk(KERN_WARNING "Asus ACPI: Error reading user input\n");
793 typedef int (proc_readfunc)(char *page, char **start, off_t off, int count,
794 int *eof, void *data);
795 typedef int (proc_writefunc)(struct file *file, const char __user *buffer,
796 unsigned long count, void *data);
799 __init asus_proc_add(char *name, proc_writefunc *writefunc,
800 proc_readfunc *readfunc, mode_t mode,
801 struct acpi_device *device)
803 struct proc_dir_entry *proc = create_proc_entry(name, mode, acpi_device_dir(device));
805 printk(KERN_WARNING " Unable to create %s fs entry\n", name);
808 proc->write_proc = writefunc;
809 proc->read_proc = readfunc;
810 proc->data = acpi_driver_data(device);
811 proc->owner = THIS_MODULE;
812 proc->uid = asus_uid;
813 proc->gid = asus_gid;
817 static int __init asus_hotk_add_fs(struct acpi_device *device)
819 struct proc_dir_entry *proc;
820 struct asus_hotk *hotk = acpi_driver_data(device);
824 * If parameter uid or gid is not changed, keep the default setting for
825 * our proc entries (-rw-rw-rw-) else, it means we care about security,
826 * and then set to -rw-rw----
829 if ((asus_uid == 0) && (asus_gid == 0)){
830 mode = S_IFREG | S_IRUGO | S_IWUGO;
832 mode = S_IFREG | S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP;
835 acpi_device_dir(device) = asus_proc_dir;
836 if (!acpi_device_dir(device))
839 proc = create_proc_entry(PROC_INFO, mode, acpi_device_dir(device));
841 proc->read_proc = proc_read_info;
842 proc->data = acpi_driver_data(device);
843 proc->owner = THIS_MODULE;
844 proc->uid = asus_uid;
845 proc->gid = asus_gid;
847 printk(KERN_WARNING " Unable to create " PROC_INFO
851 if (hotk->methods->mt_wled) {
852 asus_proc_add(PROC_WLED, &proc_write_wled, &proc_read_wled, mode, device);
855 if (hotk->methods->mt_mled) {
856 asus_proc_add(PROC_MLED, &proc_write_mled, &proc_read_mled, mode, device);
859 if (hotk->methods->mt_tled) {
860 asus_proc_add(PROC_TLED, &proc_write_tled, &proc_read_tled, mode, device);
864 * We need both read node and write method as LCD switch is also accessible
867 if (hotk->methods->mt_lcd_switch && hotk->methods->lcd_status) {
868 asus_proc_add(PROC_LCD, &proc_write_lcd, &proc_read_lcd, mode, device);
871 if ((hotk->methods->brightness_up && hotk->methods->brightness_down) ||
872 (hotk->methods->brightness_get && hotk->methods->brightness_get)) {
873 asus_proc_add(PROC_BRN, &proc_write_brn, &proc_read_brn, mode, device);
876 if (hotk->methods->display_set) {
877 asus_proc_add(PROC_DISP, &proc_write_disp, &proc_read_disp, mode, device);
884 static int asus_hotk_remove_fs(struct acpi_device* device)
886 struct asus_hotk* hotk = acpi_driver_data(device);
889 if(acpi_device_dir(device)){
890 remove_proc_entry(PROC_INFO,acpi_device_dir(device));
891 if (hotk->methods->mt_wled)
892 remove_proc_entry(PROC_WLED,acpi_device_dir(device));
893 if (hotk->methods->mt_mled)
894 remove_proc_entry(PROC_MLED,acpi_device_dir(device));
895 if (hotk->methods->mt_tled)
896 remove_proc_entry(PROC_TLED,acpi_device_dir(device));
897 if (hotk->methods->mt_lcd_switch && hotk->methods->lcd_status)
898 remove_proc_entry(PROC_LCD, acpi_device_dir(device));
899 if ((hotk->methods->brightness_up && hotk->methods->brightness_down) || (hotk->methods->brightness_get && hotk->methods->brightness_get))
900 remove_proc_entry(PROC_BRN, acpi_device_dir(device));
901 if (hotk->methods->display_set)
902 remove_proc_entry(PROC_DISP, acpi_device_dir(device));
908 static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
910 /* TODO Find a better way to handle events count. Here, in data, we receive
911 * the hotk, so we can do anything!
913 struct asus_hotk *hotk = (struct asus_hotk *) data;
918 if ((event & ~((u32) BR_UP)) < 16) {
919 hotk->brightness = (event & ~((u32) BR_UP));
920 } else if ((event & ~((u32) BR_DOWN)) < 16 ) {
921 hotk->brightness = (event & ~((u32) BR_DOWN));
924 acpi_bus_generate_event(hotk->device, event,
925 hotk->event_count[event % 128]++);
931 * This function is used to initialize the hotk with right values. In this
932 * method, we can make all the detection we want, and modify the hotk struct
934 static int __init asus_hotk_get_info(struct asus_hotk *hotk)
936 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
937 struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL };
938 union acpi_object *model = NULL;
943 * Get DSDT headers early enough to allow for differentiating between
944 * models, but late enough to allow acpi_bus_register_driver() to fail
945 * before doing anything ACPI-specific. Should we encounter a machine,
946 * which needs special handling (i.e. its hotkey device has a different
947 * HID), this bit will be moved. A global variable asus_info contains
950 status = acpi_get_table(ACPI_TABLE_DSDT, 1, &dsdt);
951 if (ACPI_FAILURE(status))
952 printk(KERN_WARNING " Couldn't get the DSDT table header\n");
954 asus_info = (struct acpi_table_header *) dsdt.pointer;
956 /* We have to write 0 on init this far for all ASUS models */
957 if (!write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
958 printk(KERN_ERR " Hotkey initialization failed\n");
962 /* This needs to be called for some laptops to init properly */
963 if (!read_acpi_int(hotk->handle, "BSTS", &bsts_result))
964 printk(KERN_WARNING " Error calling BSTS\n");
965 else if (bsts_result)
966 printk(KERN_NOTICE " BSTS called, 0x%02x returned\n", bsts_result);
968 /* Samsung P30 has a device with a valid _HID whose INIT does not
969 * return anything. Catch this one and any similar here */
970 if (buffer.pointer == NULL) {
971 if (asus_info && /* Samsung P30 */
972 strncmp(asus_info->oem_table_id, "ODEM", 4) == 0) {
974 printk(KERN_NOTICE " Samsung P30 detected, supported\n");
977 printk(KERN_WARNING " no string returned by INIT\n");
978 printk(KERN_WARNING " trying default values, supply "
979 "the developers with your DSDT\n");
981 hotk->methods = &model_conf[hotk->model];
985 model = (union acpi_object *) buffer.pointer;
986 if (model->type == ACPI_TYPE_STRING) {
987 printk(KERN_NOTICE " %s model detected, ", model->string.pointer);
990 hotk->model = END_MODEL;
991 if (strncmp(model->string.pointer, "L3D", 3) == 0)
993 else if (strncmp(model->string.pointer, "L3H", 3) == 0 ||
994 strncmp(model->string.pointer, "L2E", 3) == 0)
996 else if (strncmp(model->string.pointer, "L3", 2) == 0 ||
997 strncmp(model->string.pointer, "L2B", 3) == 0)
999 else if (strncmp(model->string.pointer, "L8L", 3) == 0)
1001 else if (strncmp(model->string.pointer, "M2N", 3) == 0 ||
1002 strncmp(model->string.pointer, "M3N", 3) == 0 ||
1003 strncmp(model->string.pointer, "M6N", 3) == 0 ||
1004 strncmp(model->string.pointer, "S1N", 3) == 0 ||
1005 strncmp(model->string.pointer, "S5N", 3) == 0)
1007 else if (strncmp(model->string.pointer, "M1", 2) == 0)
1009 else if (strncmp(model->string.pointer, "M2", 2) == 0 ||
1010 strncmp(model->string.pointer, "L4E", 3) == 0)
1012 else if (strncmp(model->string.pointer, "L2", 2) == 0)
1014 else if (strncmp(model->string.pointer, "L8", 2) == 0)
1016 else if (strncmp(model->string.pointer, "D1", 2) == 0)
1018 else if (strncmp(model->string.pointer, "A1", 2) == 0)
1020 else if (strncmp(model->string.pointer, "A2", 2) == 0)
1022 else if (strncmp(model->string.pointer, "J1", 2) == 0)
1024 else if (strncmp(model->string.pointer, "L5", 2) == 0)
1027 if (hotk->model == END_MODEL) {
1028 /* By default use the same values, as I don't know others */
1029 printk("unsupported, trying default values, supply the "
1030 "developers with your DSDT\n");
1033 printk("supported\n");
1036 hotk->methods = &model_conf[hotk->model];
1038 /* Sort of per-model blacklist */
1039 if (strncmp(model->string.pointer, "L2B", 3) == 0)
1040 hotk->methods->lcd_status = NULL;
1041 /* L2B is similar enough to L3C to use its settings, with this only
1043 else if (strncmp(model->string.pointer, "S5N", 3) == 0)
1044 hotk->methods->mt_mled = NULL;
1045 /* S5N has no MLED */
1046 else if (strncmp(model->string.pointer, "M6N", 3) == 0) {
1047 hotk->methods->display_get = NULL; //TODO
1048 hotk->methods->lcd_status = "\\_SB.BKLT";
1049 hotk->methods->mt_wled = "WLED";
1050 hotk->methods->wled_status = "\\_SB.PCI0.SBRG.SG13";
1051 /* M6N differs slightly and has a usable WLED */
1053 else if (asus_info) {
1054 if (strncmp(asus_info->oem_table_id, "L1", 2) == 0)
1055 hotk->methods->mled_status = NULL;
1056 /* S1300A reports L84F, but L1400B too, account for that */
1059 acpi_os_free(model);
1066 static int __init asus_hotk_check(struct asus_hotk *hotk)
1073 result = acpi_bus_get_status(hotk->device);
1077 if (hotk->device->status.present) {
1078 result = asus_hotk_get_info(hotk);
1080 printk(KERN_ERR " Hotkey device not present, aborting\n");
1089 static int __init asus_hotk_add(struct acpi_device *device)
1091 struct asus_hotk *hotk = NULL;
1092 acpi_status status = AE_OK;
1098 printk(KERN_NOTICE "Asus Laptop ACPI Extras version %s\n",
1102 (struct asus_hotk *) kmalloc(sizeof(struct asus_hotk), GFP_KERNEL);
1105 memset(hotk, 0, sizeof(struct asus_hotk));
1107 hotk->handle = device->handle;
1108 strcpy(acpi_device_name(device), ACPI_HOTK_DEVICE_NAME);
1109 strcpy(acpi_device_class(device), ACPI_HOTK_CLASS);
1110 acpi_driver_data(device) = hotk;
1111 hotk->device = device;
1114 result = asus_hotk_check(hotk);
1118 result = asus_hotk_add_fs(device);
1123 * We install the handler, it will receive the hotk in parameter, so, we
1124 * could add other data to the hotk struct
1126 status = acpi_install_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
1127 asus_hotk_notify, hotk);
1128 if (ACPI_FAILURE(status))
1129 printk(KERN_ERR " Error installing notify handler\n");
1131 /* For laptops without GPLV: init the hotk->brightness value */
1132 if ((!hotk->methods->brightness_get) && (!hotk->methods->brightness_status) &&
1133 (hotk->methods->brightness_up && hotk->methods->brightness_down)) {
1134 status = acpi_evaluate_object(NULL, hotk->methods->brightness_down,
1136 if (ACPI_FAILURE(status))
1137 printk(KERN_WARNING " Error changing brightness\n");
1139 status = acpi_evaluate_object(NULL, hotk->methods->brightness_up,
1141 if (ACPI_FAILURE(status))
1142 printk(KERN_WARNING " Strange, error changing"
1155 static int asus_hotk_remove(struct acpi_device *device, int type)
1157 acpi_status status = 0;
1158 struct asus_hotk *hotk = NULL;
1160 if (!device || !acpi_driver_data(device))
1163 hotk = (struct asus_hotk *) acpi_driver_data(device);
1165 status = acpi_remove_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
1167 if (ACPI_FAILURE(status))
1168 printk(KERN_ERR "Asus ACPI: Error removing notify handler\n");
1170 asus_hotk_remove_fs(device);
1178 static int __init asus_acpi_init(void)
1182 asus_proc_dir = proc_mkdir(PROC_ASUS, acpi_root_dir);
1183 if (!asus_proc_dir) {
1184 printk(KERN_ERR "Asus ACPI: Unable to create /proc entry\n");
1187 asus_proc_dir->owner = THIS_MODULE;
1189 result = acpi_bus_register_driver(&asus_hotk_driver);
1191 remove_proc_entry(PROC_ASUS, acpi_root_dir);
1199 static void __exit asus_acpi_exit(void)
1201 acpi_bus_unregister_driver(&asus_hotk_driver);
1202 remove_proc_entry(PROC_ASUS, acpi_root_dir);
1204 acpi_os_free(asus_info);
1209 module_init(asus_acpi_init);
1210 module_exit(asus_acpi_exit);