2 * asus_acpi.c - Asus Laptop ACPI Extras
5 * Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 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.
29 * Éric Burghard - LED display support for W1N
33 #include <linux/kernel.h>
34 #include <linux/module.h>
35 #include <linux/init.h>
36 #include <linux/types.h>
37 #include <linux/proc_fs.h>
38 #include <acpi/acpi_drivers.h>
39 #include <acpi/acpi_bus.h>
40 #include <asm/uaccess.h>
42 #define ASUS_ACPI_VERSION "0.30"
44 #define PROC_ASUS "asus" //the directory
45 #define PROC_MLED "mled"
46 #define PROC_WLED "wled"
47 #define PROC_TLED "tled"
48 #define PROC_BT "bluetooth"
49 #define PROC_LEDD "ledd"
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 //mail LED
70 #define WLED_ON 0x02 //wireless LED
71 #define TLED_ON 0x04 //touchpad LED
72 #define BT_ON 0x08 //internal Bluetooth
74 MODULE_AUTHOR("Julien Lerouge, Karol Kozimor");
75 MODULE_DESCRIPTION(ACPI_HOTK_NAME
);
76 MODULE_LICENSE("GPL");
78 static uid_t asus_uid
;
79 static gid_t asus_gid
;
80 module_param(asus_uid
, uint
, 0);
81 MODULE_PARM_DESC(asus_uid
, "UID for entries in /proc/acpi/asus.\n");
82 module_param(asus_gid
, uint
, 0);
83 MODULE_PARM_DESC(asus_gid
, "GID for entries in /proc/acpi/asus.\n");
85 /* For each model, all features implemented,
86 * those marked with R are relative to HOTK, A for absolute */
88 char *name
; //name of the laptop________________A
89 char *mt_mled
; //method to handle mled_____________R
90 char *mled_status
; //node to handle mled reading_______A
91 char *mt_wled
; //method to handle wled_____________R
92 char *wled_status
; //node to handle wled reading_______A
93 char *mt_tled
; //method to handle tled_____________R
94 char *tled_status
; //node to handle tled reading_______A
95 char *mt_ledd
; //method to handle LED display______R
96 char *mt_bt_switch
; //method to switch Bluetooth on/off_R
97 char *bt_status
; //no model currently supports this__?
98 char *mt_lcd_switch
; //method to turn LCD on/off_________A
99 char *lcd_status
; //node to read LCD panel state______A
100 char *brightness_up
; //method to set brightness up_______A
101 char *brightness_down
; //guess what ?______________________A
102 char *brightness_set
; //method to set absolute brightness_R
103 char *brightness_get
; //method to get absolute brightness_R
104 char *brightness_status
; //node to get brightness____________A
105 char *display_set
; //method to set video output________R
106 char *display_get
; //method to get video output________R
110 * This is the main structure, we can use it to store anything interesting
111 * about the hotk device
114 struct acpi_device
*device
; //the device we are in
115 acpi_handle handle
; //the handle of the hotk device
116 char status
; //status of the hotk, for LEDs, ...
117 u32 ledd_status
; //status of the LED display
118 struct model_data
*methods
; //methods available on the laptop
119 u8 brightness
; //brightness level
121 A1x
= 0, //A1340D, A1300F
128 L3H
, //L3H, but also L2000E
133 M2E
, //M2400E, L4400L
134 M6N
, //M6800N, W3400N
135 M6R
, //M6700R, A3000G
137 S1x
, //S1300A, but also L1400B and M2400A (L84F)
138 S2x
, //S200 (J1 reported), Victor MP-XP7210
141 xxN
, //M2400N, M3700N, M5200N, M6800N, S1300N, S5200N
144 } model
; //Models currently supported
145 u16 event_count
[128]; //count for each event TODO make this better
149 #define A1x_PREFIX "\\_SB.PCI0.ISA.EC0."
150 #define L3C_PREFIX "\\_SB.PCI0.PX40.ECD0."
151 #define M1A_PREFIX "\\_SB.PCI0.PX40.EC0."
152 #define P30_PREFIX "\\_SB.PCI0.LPCB.EC0."
153 #define S1x_PREFIX "\\_SB.PCI0.PX40."
154 #define S2x_PREFIX A1x_PREFIX
155 #define xxN_PREFIX "\\_SB.PCI0.SBRG.EC0."
157 static struct model_data model_conf
[END_MODEL
] = {
159 * TODO I have seen a SWBX and AIBX method on some models, like L1400B,
160 * 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"},
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"},
187 /* WLED present, but not controlled by ACPI */
188 .mt_lcd_switch
= xxN_PREFIX
"_Q10",
189 .brightness_set
= "SPLV",
190 .brightness_get
= "GPLV",
191 .display_set
= "SDSP",
192 .display_get
= "\\ADVG"},
197 .mt_lcd_switch
= "\\Q0D",
198 .lcd_status
= "\\GP11",
199 .brightness_up
= "\\Q0C",
200 .brightness_down
= "\\Q0B",
201 .brightness_status
= "\\BLVL",
202 .display_set
= "SDSP",
203 .display_get
= "\\INFB"},
208 .mled_status
= "\\SGP6",
210 .wled_status
= "\\RCP3",
211 .mt_lcd_switch
= "\\Q10",
212 .lcd_status
= "\\SGP0",
213 .brightness_up
= "\\Q0E",
214 .brightness_down
= "\\Q0F",
215 .display_set
= "SDSP",
216 .display_get
= "\\INFB"},
222 .mt_lcd_switch
= L3C_PREFIX
"_Q10",
223 .lcd_status
= "\\GL32",
224 .brightness_set
= "SPLV",
225 .brightness_get
= "GPLV",
226 .display_set
= "SDSP",
227 .display_get
= "\\_SB.PCI0.PCI1.VGAC.NMAP"},
232 .mled_status
= "\\MALD",
234 .mt_lcd_switch
= "\\Q10",
235 .lcd_status
= "\\BKLG",
236 .brightness_set
= "SPLV",
237 .brightness_get
= "GPLV",
238 .display_set
= "SDSP",
239 .display_get
= "\\INFB"},
245 .mt_lcd_switch
= "EHK",
246 .lcd_status
= "\\_SB.PCI0.PM.PBC",
247 .brightness_set
= "SPLV",
248 .brightness_get
= "GPLV",
249 .display_set
= "SDSP",
250 .display_get
= "\\INFB"},
256 .wled_status
= "\\_SB.PCI0.SBRG.SG13",
257 .mt_lcd_switch
= xxN_PREFIX
"_Q10",
258 .lcd_status
= "\\_SB.PCI0.SBSM.SEO4",
259 .brightness_set
= "SPLV",
260 .brightness_get
= "GPLV",
261 .display_set
= "SDSP",
262 .display_get
= "\\_SB.PCI0.P0P1.VGA.GETD"},
267 /* WLED present, but not controlled by ACPI */
269 .mt_lcd_switch
= "\\Q0D",
270 .lcd_status
= "\\BAOF",
271 .brightness_set
= "SPLV",
272 .brightness_get
= "GPLV",
273 .display_set
= "SDSP",
274 .display_get
= "\\INFB"},
278 /* No features, but at least support the hotkeys */
284 .mt_lcd_switch
= M1A_PREFIX
"Q10",
285 .lcd_status
= "\\PNOF",
286 .brightness_up
= M1A_PREFIX
"Q0E",
287 .brightness_down
= M1A_PREFIX
"Q0F",
288 .brightness_status
= "\\BRIT",
289 .display_set
= "SDSP",
290 .display_get
= "\\INFB"},
296 .mt_lcd_switch
= "\\Q10",
297 .lcd_status
= "\\GP06",
298 .brightness_set
= "SPLV",
299 .brightness_get
= "GPLV",
300 .display_set
= "SDSP",
301 .display_get
= "\\INFB"},
307 .wled_status
= "\\_SB.PCI0.SBRG.SG13",
308 .mt_lcd_switch
= xxN_PREFIX
"_Q10",
309 .lcd_status
= "\\_SB.BKLT",
310 .brightness_set
= "SPLV",
311 .brightness_get
= "GPLV",
312 .display_set
= "SDSP",
313 .display_get
= "\\_SB.PCI0.P0P1.VGA.GETD"},
318 .mt_lcd_switch
= xxN_PREFIX
"_Q10",
319 .lcd_status
= "\\_SB.PCI0.SBSM.SEO4",
320 .brightness_set
= "SPLV",
321 .brightness_get
= "GPLV",
322 .display_set
= "SDSP",
323 .display_get
= "\\SSTE"},
328 .mt_lcd_switch
= P30_PREFIX
"_Q0E",
329 .lcd_status
= "\\BKLT",
330 .brightness_up
= P30_PREFIX
"_Q68",
331 .brightness_down
= P30_PREFIX
"_Q69",
332 .brightness_get
= "GPLV",
333 .display_set
= "SDSP",
334 .display_get
= "\\DNXT"},
339 .mled_status
= "\\EMLE",
341 .mt_lcd_switch
= S1x_PREFIX
"Q10",
342 .lcd_status
= "\\PNOF",
343 .brightness_set
= "SPLV",
344 .brightness_get
= "GPLV"},
349 .mled_status
= "\\MAIL",
350 .mt_lcd_switch
= S2x_PREFIX
"_Q10",
351 .lcd_status
= "\\BKLI",
352 .brightness_up
= S2x_PREFIX
"_Q0B",
353 .brightness_down
= S2x_PREFIX
"_Q0A"},
360 .mt_lcd_switch
= xxN_PREFIX
"_Q10",
361 .lcd_status
= "\\BKLT",
362 .brightness_set
= "SPLV",
363 .brightness_get
= "GPLV",
364 .display_set
= "SDSP",
365 .display_get
= "\\ADVG"},
369 .mt_bt_switch
= "BLED",
371 .mt_lcd_switch
= xxN_PREFIX
"_Q10",
372 .brightness_set
= "SPLV",
373 .brightness_get
= "GPLV",
374 .display_set
= "SDSP",
375 .display_get
= "\\ADVG"},
380 /* WLED present, but not controlled by ACPI */
381 .mt_lcd_switch
= xxN_PREFIX
"_Q10",
382 .lcd_status
= "\\BKLT",
383 .brightness_set
= "SPLV",
384 .brightness_get
= "GPLV",
385 .display_set
= "SDSP",
386 .display_get
= "\\ADVG"}
390 static struct proc_dir_entry
*asus_proc_dir
;
393 * This header is made available to allow proper configuration given model,
394 * revision number , ... this info cannot go in struct asus_hotk because it is
395 * available before the hotk
397 static struct acpi_table_header
*asus_info
;
399 /* The actual device the driver binds to */
400 static struct asus_hotk
*hotk
;
403 * The hotkey driver declaration
405 static int asus_hotk_add(struct acpi_device
*device
);
406 static int asus_hotk_remove(struct acpi_device
*device
, int type
);
407 static struct acpi_driver asus_hotk_driver
= {
408 .name
= ACPI_HOTK_NAME
,
409 .class = ACPI_HOTK_CLASS
,
410 .ids
= ACPI_HOTK_HID
,
412 .add
= asus_hotk_add
,
413 .remove
= asus_hotk_remove
,
418 * This function evaluates an ACPI method, given an int as parameter, the
419 * method is searched within the scope of the handle, can be NULL. The output
420 * of the method is written is output, which can also be NULL
422 * returns 1 if write is successful, 0 else.
424 static int write_acpi_int(acpi_handle handle
, const char *method
, int val
,
425 struct acpi_buffer
*output
)
427 struct acpi_object_list params
; //list of input parameters (an int here)
428 union acpi_object in_obj
; //the only param we use
432 params
.pointer
= &in_obj
;
433 in_obj
.type
= ACPI_TYPE_INTEGER
;
434 in_obj
.integer
.value
= val
;
436 status
= acpi_evaluate_object(handle
, (char *)method
, ¶ms
, output
);
437 return (status
== AE_OK
);
440 static int read_acpi_int(acpi_handle handle
, const char *method
, int *val
)
442 struct acpi_buffer output
;
443 union acpi_object out_obj
;
446 output
.length
= sizeof(out_obj
);
447 output
.pointer
= &out_obj
;
449 status
= acpi_evaluate_object(handle
, (char *)method
, NULL
, &output
);
450 *val
= out_obj
.integer
.value
;
451 return (status
== AE_OK
) && (out_obj
.type
== ACPI_TYPE_INTEGER
);
455 * We write our info in page, we begin at offset off and cannot write more
456 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
457 * number of bytes written in page
460 proc_read_info(char *page
, char **start
, off_t off
, int count
, int *eof
,
465 char buf
[16]; //enough for all info
467 * We use the easy way, we don't care of off and count, so we don't set eof
471 len
+= sprintf(page
, ACPI_HOTK_NAME
" " ASUS_ACPI_VERSION
"\n");
472 len
+= sprintf(page
+ len
, "Model reference : %s\n",
473 hotk
->methods
->name
);
475 * The SFUN method probably allows the original driver to get the list
476 * of features supported by a given model. For now, 0x0100 or 0x0800
477 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
478 * The significance of others is yet to be found.
480 if (read_acpi_int(hotk
->handle
, "SFUN", &temp
))
482 sprintf(page
+ len
, "SFUN value : 0x%04x\n", temp
);
484 * Another value for userspace: the ASYM method returns 0x02 for
485 * battery low and 0x04 for battery critical, its readings tend to be
486 * more accurate than those provided by _BST.
487 * Note: since not all the laptops provide this method, errors are
490 if (read_acpi_int(hotk
->handle
, "ASYM", &temp
))
492 sprintf(page
+ len
, "ASYM value : 0x%04x\n", temp
);
494 snprintf(buf
, 16, "%d", asus_info
->length
);
495 len
+= sprintf(page
+ len
, "DSDT length : %s\n", buf
);
496 snprintf(buf
, 16, "%d", asus_info
->checksum
);
497 len
+= sprintf(page
+ len
, "DSDT checksum : %s\n", buf
);
498 snprintf(buf
, 16, "%d", asus_info
->revision
);
499 len
+= sprintf(page
+ len
, "DSDT revision : %s\n", buf
);
500 snprintf(buf
, 7, "%s", asus_info
->oem_id
);
501 len
+= sprintf(page
+ len
, "OEM id : %s\n", buf
);
502 snprintf(buf
, 9, "%s", asus_info
->oem_table_id
);
503 len
+= sprintf(page
+ len
, "OEM table id : %s\n", buf
);
504 snprintf(buf
, 16, "%x", asus_info
->oem_revision
);
505 len
+= sprintf(page
+ len
, "OEM revision : 0x%s\n", buf
);
506 snprintf(buf
, 5, "%s", asus_info
->asl_compiler_id
);
507 len
+= sprintf(page
+ len
, "ASL comp vendor id : %s\n", buf
);
508 snprintf(buf
, 16, "%x", asus_info
->asl_compiler_revision
);
509 len
+= sprintf(page
+ len
, "ASL comp revision : 0x%s\n", buf
);
517 * We write our info in page, we begin at offset off and cannot write more
518 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
519 * number of bytes written in page
522 /* Generic LED functions */
523 static int read_led(const char *ledname
, int ledmask
)
528 if (read_acpi_int(NULL
, ledname
, &led_status
))
531 printk(KERN_WARNING
"Asus ACPI: Error reading LED "
534 return (hotk
->status
& ledmask
) ? 1 : 0;
537 static int parse_arg(const char __user
* buf
, unsigned long count
, int *val
)
544 if (copy_from_user(s
, buf
, count
))
547 if (sscanf(s
, "%i", val
) != 1)
552 /* FIXME: kill extraneous args so it can be called independently */
554 write_led(const char __user
* buffer
, unsigned long count
,
555 char *ledname
, int ledmask
, int invert
)
560 count
= parse_arg(buffer
, count
, &value
);
562 led_out
= value
? 1 : 0;
565 (led_out
) ? (hotk
->status
| ledmask
) : (hotk
->status
& ~ledmask
);
567 if (invert
) /* invert target value */
568 led_out
= !led_out
& 0x1;
570 if (!write_acpi_int(hotk
->handle
, ledname
, led_out
, NULL
))
571 printk(KERN_WARNING
"Asus ACPI: LED (%s) write failed\n",
578 * Proc handlers for MLED
581 proc_read_mled(char *page
, char **start
, off_t off
, int count
, int *eof
,
584 return sprintf(page
, "%d\n",
585 read_led(hotk
->methods
->mled_status
, MLED_ON
));
589 proc_write_mled(struct file
*file
, const char __user
* buffer
,
590 unsigned long count
, void *data
)
592 return write_led(buffer
, count
, hotk
->methods
->mt_mled
, MLED_ON
, 1);
596 * Proc handlers for LED display
599 proc_read_ledd(char *page
, char **start
, off_t off
, int count
, int *eof
,
602 return sprintf(page
, "0x%08x\n", hotk
->ledd_status
);
606 proc_write_ledd(struct file
*file
, const char __user
* buffer
,
607 unsigned long count
, void *data
)
611 count
= parse_arg(buffer
, count
, &value
);
614 (hotk
->handle
, hotk
->methods
->mt_ledd
, value
, NULL
))
616 "Asus ACPI: LED display write failed\n");
618 hotk
->ledd_status
= (u32
) value
;
619 } else if (count
< 0)
620 printk(KERN_WARNING
"Asus ACPI: Error reading user input\n");
626 * Proc handlers for WLED
629 proc_read_wled(char *page
, char **start
, off_t off
, int count
, int *eof
,
632 return sprintf(page
, "%d\n",
633 read_led(hotk
->methods
->wled_status
, WLED_ON
));
637 proc_write_wled(struct file
*file
, const char __user
* buffer
,
638 unsigned long count
, void *data
)
640 return write_led(buffer
, count
, hotk
->methods
->mt_wled
, WLED_ON
, 0);
644 * Proc handlers for Bluetooth
647 proc_read_bluetooth(char *page
, char **start
, off_t off
, int count
, int *eof
,
650 return sprintf(page
, "%d\n", read_led(hotk
->methods
->bt_status
, BT_ON
));
654 proc_write_bluetooth(struct file
*file
, const char __user
* buffer
,
655 unsigned long count
, void *data
)
657 /* Note: mt_bt_switch controls both internal Bluetooth adapter's
658 presence and its LED */
659 return write_led(buffer
, count
, hotk
->methods
->mt_bt_switch
, BT_ON
, 0);
663 * Proc handlers for TLED
666 proc_read_tled(char *page
, char **start
, off_t off
, int count
, int *eof
,
669 return sprintf(page
, "%d\n",
670 read_led(hotk
->methods
->tled_status
, TLED_ON
));
674 proc_write_tled(struct file
*file
, const char __user
* buffer
,
675 unsigned long count
, void *data
)
677 return write_led(buffer
, count
, hotk
->methods
->mt_tled
, TLED_ON
, 0);
680 static int get_lcd_state(void)
684 if (hotk
->model
!= L3H
) {
685 /* We don't have to check anything if we are here */
686 if (!read_acpi_int(NULL
, hotk
->methods
->lcd_status
, &lcd
))
688 "Asus ACPI: Error reading LCD status\n");
690 if (hotk
->model
== L2D
)
692 } else { /* L3H and the like have to be handled differently */
693 acpi_status status
= 0;
694 struct acpi_object_list input
;
695 union acpi_object mt_params
[2];
696 struct acpi_buffer output
;
697 union acpi_object out_obj
;
700 input
.pointer
= mt_params
;
701 /* Note: the following values are partly guessed up, but
702 otherwise they seem to work */
703 mt_params
[0].type
= ACPI_TYPE_INTEGER
;
704 mt_params
[0].integer
.value
= 0x02;
705 mt_params
[1].type
= ACPI_TYPE_INTEGER
;
706 mt_params
[1].integer
.value
= 0x02;
708 output
.length
= sizeof(out_obj
);
709 output
.pointer
= &out_obj
;
712 acpi_evaluate_object(NULL
, hotk
->methods
->lcd_status
,
716 if (out_obj
.type
== ACPI_TYPE_INTEGER
)
717 /* That's what the AML code does */
718 lcd
= out_obj
.integer
.value
>> 8;
724 static int set_lcd_state(int value
)
727 acpi_status status
= 0;
730 if (lcd
!= get_lcd_state()) {
732 if (hotk
->model
!= L3H
) {
734 acpi_evaluate_object(NULL
,
735 hotk
->methods
->mt_lcd_switch
,
737 } else { /* L3H and the like have to be handled differently */
739 (hotk
->handle
, hotk
->methods
->mt_lcd_switch
, 0x07,
742 /* L3H's AML executes EHK (0x07) upon Fn+F7 keypress,
743 the exact behaviour is simulated here */
745 if (ACPI_FAILURE(status
))
746 printk(KERN_WARNING
"Asus ACPI: Error switching LCD\n");
753 proc_read_lcd(char *page
, char **start
, off_t off
, int count
, int *eof
,
756 return sprintf(page
, "%d\n", get_lcd_state());
760 proc_write_lcd(struct file
*file
, const char __user
* buffer
,
761 unsigned long count
, void *data
)
765 count
= parse_arg(buffer
, count
, &value
);
767 set_lcd_state(value
);
771 static int read_brightness(void)
775 if (hotk
->methods
->brightness_get
) { /* SPLV/GPLV laptop */
776 if (!read_acpi_int(hotk
->handle
, hotk
->methods
->brightness_get
,
779 "Asus ACPI: Error reading brightness\n");
780 } else if (hotk
->methods
->brightness_status
) { /* For D1 for example */
781 if (!read_acpi_int(NULL
, hotk
->methods
->brightness_status
,
784 "Asus ACPI: Error reading brightness\n");
785 } else /* No GPLV method */
786 value
= hotk
->brightness
;
791 * Change the brightness level
793 static void set_brightness(int value
)
795 acpi_status status
= 0;
798 if (hotk
->methods
->brightness_set
) {
799 if (!write_acpi_int(hotk
->handle
, hotk
->methods
->brightness_set
,
802 "Asus ACPI: Error changing brightness\n");
806 /* No SPLV method if we are here, act as appropriate */
807 value
-= read_brightness();
809 status
= acpi_evaluate_object(NULL
, (value
> 0) ?
810 hotk
->methods
->brightness_up
:
811 hotk
->methods
->brightness_down
,
813 (value
> 0) ? value
-- : value
++;
814 if (ACPI_FAILURE(status
))
816 "Asus ACPI: Error changing brightness\n");
822 proc_read_brn(char *page
, char **start
, off_t off
, int count
, int *eof
,
825 return sprintf(page
, "%d\n", read_brightness());
829 proc_write_brn(struct file
*file
, const char __user
* buffer
,
830 unsigned long count
, void *data
)
834 count
= parse_arg(buffer
, count
, &value
);
836 value
= (0 < value
) ? ((15 < value
) ? 15 : value
) : 0;
837 /* 0 <= value <= 15 */
838 set_brightness(value
);
839 } else if (count
< 0) {
840 printk(KERN_WARNING
"Asus ACPI: Error reading user input\n");
846 static void set_display(int value
)
848 /* no sanity check needed for now */
849 if (!write_acpi_int(hotk
->handle
, hotk
->methods
->display_set
,
851 printk(KERN_WARNING
"Asus ACPI: Error setting display\n");
856 * Now, *this* one could be more user-friendly, but so far, no-one has
857 * complained. The significance of bits is the same as in proc_write_disp()
860 proc_read_disp(char *page
, char **start
, off_t off
, int count
, int *eof
,
865 if (!read_acpi_int(hotk
->handle
, hotk
->methods
->display_get
, &value
))
867 "Asus ACPI: Error reading display status\n");
868 value
&= 0x07; /* needed for some models, shouldn't hurt others */
869 return sprintf(page
, "%d\n", value
);
873 * Experimental support for display switching. As of now: 1 should activate
874 * the LCD output, 2 should do for CRT, and 4 for TV-Out. Any combination
875 * (bitwise) of these will suffice. I never actually tested 3 displays hooked up
876 * simultaneously, so be warned. See the acpi4asus README for more info.
879 proc_write_disp(struct file
*file
, const char __user
* buffer
,
880 unsigned long count
, void *data
)
884 count
= parse_arg(buffer
, count
, &value
);
888 printk(KERN_WARNING
"Asus ACPI: Error reading user input\n");
893 typedef int (proc_readfunc
) (char *page
, char **start
, off_t off
, int count
,
894 int *eof
, void *data
);
895 typedef int (proc_writefunc
) (struct file
* file
, const char __user
* buffer
,
896 unsigned long count
, void *data
);
899 asus_proc_add(char *name
, proc_writefunc
* writefunc
,
900 proc_readfunc
* readfunc
, mode_t mode
,
901 struct acpi_device
*device
)
903 struct proc_dir_entry
*proc
=
904 create_proc_entry(name
, mode
, acpi_device_dir(device
));
906 printk(KERN_WARNING
" Unable to create %s fs entry\n", name
);
909 proc
->write_proc
= writefunc
;
910 proc
->read_proc
= readfunc
;
911 proc
->data
= acpi_driver_data(device
);
912 proc
->owner
= THIS_MODULE
;
913 proc
->uid
= asus_uid
;
914 proc
->gid
= asus_gid
;
918 static int asus_hotk_add_fs(struct acpi_device
*device
)
920 struct proc_dir_entry
*proc
;
924 * If parameter uid or gid is not changed, keep the default setting for
925 * our proc entries (-rw-rw-rw-) else, it means we care about security,
926 * and then set to -rw-rw----
929 if ((asus_uid
== 0) && (asus_gid
== 0)) {
930 mode
= S_IFREG
| S_IRUGO
| S_IWUGO
;
932 mode
= S_IFREG
| S_IRUSR
| S_IRGRP
| S_IWUSR
| S_IWGRP
;
933 printk(KERN_WARNING
" asus_uid and asus_gid parameters are "
934 "deprecated, use chown and chmod instead!\n");
937 acpi_device_dir(device
) = asus_proc_dir
;
938 if (!acpi_device_dir(device
))
941 proc
= create_proc_entry(PROC_INFO
, mode
, acpi_device_dir(device
));
943 proc
->read_proc
= proc_read_info
;
944 proc
->data
= acpi_driver_data(device
);
945 proc
->owner
= THIS_MODULE
;
946 proc
->uid
= asus_uid
;
947 proc
->gid
= asus_gid
;
949 printk(KERN_WARNING
" Unable to create " PROC_INFO
953 if (hotk
->methods
->mt_wled
) {
954 asus_proc_add(PROC_WLED
, &proc_write_wled
, &proc_read_wled
,
958 if (hotk
->methods
->mt_ledd
) {
959 asus_proc_add(PROC_LEDD
, &proc_write_ledd
, &proc_read_ledd
,
963 if (hotk
->methods
->mt_mled
) {
964 asus_proc_add(PROC_MLED
, &proc_write_mled
, &proc_read_mled
,
968 if (hotk
->methods
->mt_tled
) {
969 asus_proc_add(PROC_TLED
, &proc_write_tled
, &proc_read_tled
,
973 if (hotk
->methods
->mt_bt_switch
) {
974 asus_proc_add(PROC_BT
, &proc_write_bluetooth
,
975 &proc_read_bluetooth
, mode
, device
);
979 * We need both read node and write method as LCD switch is also accessible
982 if (hotk
->methods
->mt_lcd_switch
&& hotk
->methods
->lcd_status
) {
983 asus_proc_add(PROC_LCD
, &proc_write_lcd
, &proc_read_lcd
, mode
,
987 if ((hotk
->methods
->brightness_up
&& hotk
->methods
->brightness_down
) ||
988 (hotk
->methods
->brightness_get
&& hotk
->methods
->brightness_set
)) {
989 asus_proc_add(PROC_BRN
, &proc_write_brn
, &proc_read_brn
, mode
,
993 if (hotk
->methods
->display_set
) {
994 asus_proc_add(PROC_DISP
, &proc_write_disp
, &proc_read_disp
,
1001 static int asus_hotk_remove_fs(struct acpi_device
*device
)
1003 if (acpi_device_dir(device
)) {
1004 remove_proc_entry(PROC_INFO
, acpi_device_dir(device
));
1005 if (hotk
->methods
->mt_wled
)
1006 remove_proc_entry(PROC_WLED
, acpi_device_dir(device
));
1007 if (hotk
->methods
->mt_mled
)
1008 remove_proc_entry(PROC_MLED
, acpi_device_dir(device
));
1009 if (hotk
->methods
->mt_tled
)
1010 remove_proc_entry(PROC_TLED
, acpi_device_dir(device
));
1011 if (hotk
->methods
->mt_ledd
)
1012 remove_proc_entry(PROC_LEDD
, acpi_device_dir(device
));
1013 if (hotk
->methods
->mt_bt_switch
)
1014 remove_proc_entry(PROC_BT
, acpi_device_dir(device
));
1015 if (hotk
->methods
->mt_lcd_switch
&& hotk
->methods
->lcd_status
)
1016 remove_proc_entry(PROC_LCD
, acpi_device_dir(device
));
1017 if ((hotk
->methods
->brightness_up
1018 && hotk
->methods
->brightness_down
)
1019 || (hotk
->methods
->brightness_get
1020 && hotk
->methods
->brightness_set
))
1021 remove_proc_entry(PROC_BRN
, acpi_device_dir(device
));
1022 if (hotk
->methods
->display_set
)
1023 remove_proc_entry(PROC_DISP
, acpi_device_dir(device
));
1028 static void asus_hotk_notify(acpi_handle handle
, u32 event
, void *data
)
1030 /* TODO Find a better way to handle events count. */
1034 if ((event
& ~((u32
) BR_UP
)) < 16) {
1035 hotk
->brightness
= (event
& ~((u32
) BR_UP
));
1036 } else if ((event
& ~((u32
) BR_DOWN
)) < 16) {
1037 hotk
->brightness
= (event
& ~((u32
) BR_DOWN
));
1040 acpi_bus_generate_event(hotk
->device
, event
,
1041 hotk
->event_count
[event
% 128]++);
1047 * This function is used to initialize the hotk with right values. In this
1048 * method, we can make all the detection we want, and modify the hotk struct
1050 static int asus_hotk_get_info(void)
1052 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1053 struct acpi_buffer dsdt
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1054 union acpi_object
*model
= NULL
;
1059 * Get DSDT headers early enough to allow for differentiating between
1060 * models, but late enough to allow acpi_bus_register_driver() to fail
1061 * before doing anything ACPI-specific. Should we encounter a machine,
1062 * which needs special handling (i.e. its hotkey device has a different
1063 * HID), this bit will be moved. A global variable asus_info contains
1066 status
= acpi_get_table(ACPI_TABLE_ID_DSDT
, 1, &dsdt
);
1067 if (ACPI_FAILURE(status
))
1068 printk(KERN_WARNING
" Couldn't get the DSDT table header\n");
1070 asus_info
= (struct acpi_table_header
*)dsdt
.pointer
;
1072 /* We have to write 0 on init this far for all ASUS models */
1073 if (!write_acpi_int(hotk
->handle
, "INIT", 0, &buffer
)) {
1074 printk(KERN_ERR
" Hotkey initialization failed\n");
1078 /* This needs to be called for some laptops to init properly */
1079 if (!read_acpi_int(hotk
->handle
, "BSTS", &bsts_result
))
1080 printk(KERN_WARNING
" Error calling BSTS\n");
1081 else if (bsts_result
)
1082 printk(KERN_NOTICE
" BSTS called, 0x%02x returned\n",
1085 /* This is unlikely with implicit return */
1086 if (buffer
.pointer
== NULL
)
1089 model
= (union acpi_object
*)buffer
.pointer
;
1091 * Samsung P30 has a device with a valid _HID whose INIT does not
1092 * return anything. It used to be possible to catch this exception,
1093 * but the implicit return code will now happily confuse the
1094 * driver. We assume that every ACPI_TYPE_STRING is a valid model
1095 * identifier but it's still possible to get completely bogus data.
1097 if (model
->type
== ACPI_TYPE_STRING
) {
1098 printk(KERN_NOTICE
" %s model detected, ",
1099 model
->string
.pointer
);
1101 if (asus_info
&& /* Samsung P30 */
1102 strncmp(asus_info
->oem_table_id
, "ODEM", 4) == 0) {
1105 " Samsung P30 detected, supported\n");
1108 printk(KERN_WARNING
" no string returned by INIT\n");
1109 printk(KERN_WARNING
" trying default values, supply "
1110 "the developers with your DSDT\n");
1112 hotk
->methods
= &model_conf
[hotk
->model
];
1119 hotk
->model
= END_MODEL
;
1120 if (strncmp(model
->string
.pointer
, "L3D", 3) == 0)
1122 else if (strncmp(model
->string
.pointer
, "L3H", 3) == 0 ||
1123 strncmp(model
->string
.pointer
, "L2E", 3) == 0)
1125 else if (strncmp(model
->string
.pointer
, "L3", 2) == 0 ||
1126 strncmp(model
->string
.pointer
, "L2B", 3) == 0)
1128 else if (strncmp(model
->string
.pointer
, "L8L", 3) == 0)
1130 else if (strncmp(model
->string
.pointer
, "L4R", 3) == 0)
1132 else if (strncmp(model
->string
.pointer
, "M6N", 3) == 0 ||
1133 strncmp(model
->string
.pointer
, "W3N", 3) == 0)
1135 else if (strncmp(model
->string
.pointer
, "M6R", 3) == 0 ||
1136 strncmp(model
->string
.pointer
, "A3G", 3) == 0)
1138 else if (strncmp(model
->string
.pointer
, "M2N", 3) == 0 ||
1139 strncmp(model
->string
.pointer
, "M3N", 3) == 0 ||
1140 strncmp(model
->string
.pointer
, "M5N", 3) == 0 ||
1141 strncmp(model
->string
.pointer
, "M6N", 3) == 0 ||
1142 strncmp(model
->string
.pointer
, "S1N", 3) == 0 ||
1143 strncmp(model
->string
.pointer
, "S5N", 3) == 0)
1145 else if (strncmp(model
->string
.pointer
, "M1", 2) == 0)
1147 else if (strncmp(model
->string
.pointer
, "M2", 2) == 0 ||
1148 strncmp(model
->string
.pointer
, "L4E", 3) == 0)
1150 else if (strncmp(model
->string
.pointer
, "L2", 2) == 0)
1152 else if (strncmp(model
->string
.pointer
, "L8", 2) == 0)
1154 else if (strncmp(model
->string
.pointer
, "D1", 2) == 0)
1156 else if (strncmp(model
->string
.pointer
, "A1", 2) == 0)
1158 else if (strncmp(model
->string
.pointer
, "A2", 2) == 0)
1160 else if (strncmp(model
->string
.pointer
, "J1", 2) == 0)
1162 else if (strncmp(model
->string
.pointer
, "L5", 2) == 0)
1164 else if (strncmp(model
->string
.pointer
, "A4G", 3) == 0)
1166 else if (strncmp(model
->string
.pointer
, "W1N", 3) == 0)
1168 else if (strncmp(model
->string
.pointer
, "W5A", 3) == 0)
1171 if (hotk
->model
== END_MODEL
) {
1172 printk("unsupported, trying default values, supply the "
1173 "developers with your DSDT\n");
1176 printk("supported\n");
1179 hotk
->methods
= &model_conf
[hotk
->model
];
1181 /* Sort of per-model blacklist */
1182 if (strncmp(model
->string
.pointer
, "L2B", 3) == 0)
1183 hotk
->methods
->lcd_status
= NULL
;
1184 /* L2B is similar enough to L3C to use its settings, with this only
1186 else if (strncmp(model
->string
.pointer
, "A3G", 3) == 0)
1187 hotk
->methods
->lcd_status
= "\\BLFG";
1188 /* A3G is like M6R */
1189 else if (strncmp(model
->string
.pointer
, "S5N", 3) == 0 ||
1190 strncmp(model
->string
.pointer
, "M5N", 3) == 0 ||
1191 strncmp(model
->string
.pointer
, "W3N", 3) == 0)
1192 hotk
->methods
->mt_mled
= NULL
;
1193 /* S5N, M5N and W3N have no MLED */
1194 else if (strncmp(model
->string
.pointer
, "M2N", 3) == 0)
1195 hotk
->methods
->mt_wled
= "WLED";
1196 /* M2N has a usable WLED */
1197 else if (asus_info
) {
1198 if (strncmp(asus_info
->oem_table_id
, "L1", 2) == 0)
1199 hotk
->methods
->mled_status
= NULL
;
1200 /* S1300A reports L84F, but L1400B too, account for that */
1208 static int asus_hotk_check(void)
1212 result
= acpi_bus_get_status(hotk
->device
);
1216 if (hotk
->device
->status
.present
) {
1217 result
= asus_hotk_get_info();
1219 printk(KERN_ERR
" Hotkey device not present, aborting\n");
1226 static int asus_hotk_found
;
1228 static int asus_hotk_add(struct acpi_device
*device
)
1230 acpi_status status
= AE_OK
;
1236 printk(KERN_NOTICE
"Asus Laptop ACPI Extras version %s\n",
1240 (struct asus_hotk
*)kmalloc(sizeof(struct asus_hotk
), GFP_KERNEL
);
1243 memset(hotk
, 0, sizeof(struct asus_hotk
));
1245 hotk
->handle
= device
->handle
;
1246 strcpy(acpi_device_name(device
), ACPI_HOTK_DEVICE_NAME
);
1247 strcpy(acpi_device_class(device
), ACPI_HOTK_CLASS
);
1248 acpi_driver_data(device
) = hotk
;
1249 hotk
->device
= device
;
1251 result
= asus_hotk_check();
1255 result
= asus_hotk_add_fs(device
);
1260 * We install the handler, it will receive the hotk in parameter, so, we
1261 * could add other data to the hotk struct
1263 status
= acpi_install_notify_handler(hotk
->handle
, ACPI_SYSTEM_NOTIFY
,
1264 asus_hotk_notify
, hotk
);
1265 if (ACPI_FAILURE(status
))
1266 printk(KERN_ERR
" Error installing notify handler\n");
1268 /* For laptops without GPLV: init the hotk->brightness value */
1269 if ((!hotk
->methods
->brightness_get
)
1270 && (!hotk
->methods
->brightness_status
)
1271 && (hotk
->methods
->brightness_up
&& hotk
->methods
->brightness_down
)) {
1273 acpi_evaluate_object(NULL
, hotk
->methods
->brightness_down
,
1275 if (ACPI_FAILURE(status
))
1276 printk(KERN_WARNING
" Error changing brightness\n");
1279 acpi_evaluate_object(NULL
,
1280 hotk
->methods
->brightness_up
,
1282 if (ACPI_FAILURE(status
))
1283 printk(KERN_WARNING
" Strange, error changing"
1288 asus_hotk_found
= 1;
1290 /* LED display is off by default */
1291 hotk
->ledd_status
= 0xFFF;
1301 static int asus_hotk_remove(struct acpi_device
*device
, int type
)
1303 acpi_status status
= 0;
1305 if (!device
|| !acpi_driver_data(device
))
1308 status
= acpi_remove_notify_handler(hotk
->handle
, ACPI_SYSTEM_NOTIFY
,
1310 if (ACPI_FAILURE(status
))
1311 printk(KERN_ERR
"Asus ACPI: Error removing notify handler\n");
1313 asus_hotk_remove_fs(device
);
1320 static int __init
asus_acpi_init(void)
1327 if (!acpi_specific_hotkey_enabled
) {
1328 printk(KERN_ERR
"Using generic hotkey driver\n");
1331 asus_proc_dir
= proc_mkdir(PROC_ASUS
, acpi_root_dir
);
1332 if (!asus_proc_dir
) {
1333 printk(KERN_ERR
"Asus ACPI: Unable to create /proc entry\n");
1336 asus_proc_dir
->owner
= THIS_MODULE
;
1338 result
= acpi_bus_register_driver(&asus_hotk_driver
);
1340 remove_proc_entry(PROC_ASUS
, acpi_root_dir
);
1345 * This is a bit of a kludge. We only want this module loaded
1346 * for ASUS systems, but there's currently no way to probe the
1347 * ACPI namespace for ASUS HIDs. So we just return failure if
1348 * we didn't find one, which will cause the module to be
1351 if (!asus_hotk_found
) {
1352 acpi_bus_unregister_driver(&asus_hotk_driver
);
1353 remove_proc_entry(PROC_ASUS
, acpi_root_dir
);
1360 static void __exit
asus_acpi_exit(void)
1362 acpi_bus_unregister_driver(&asus_hotk_driver
);
1363 remove_proc_entry(PROC_ASUS
, acpi_root_dir
);
1370 module_init(asus_acpi_init
);
1371 module_exit(asus_acpi_exit
);