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.29"
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_param(asus_uid
, uint
, 0);
82 MODULE_PARM_DESC(uid
, "UID for entries in /proc/acpi/asus.\n");
83 module_param(asus_gid
, uint
, 0);
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
130 M2E
, //M2400E, L4400L
134 S1x
, //S1300A, but also L1400B and M2400A (L84F)
135 S2x
, //S200 (J1 reported), Victor MP-XP7210
136 xxN
, //M2400N, M3700N, M5200N, S1300N, S5200N, W1OOON
139 } model
; //Models currently supported
140 u16 event_count
[128]; //count for each event TODO make this better
144 #define A1x_PREFIX "\\_SB.PCI0.ISA.EC0."
145 #define L3C_PREFIX "\\_SB.PCI0.PX40.ECD0."
146 #define M1A_PREFIX "\\_SB.PCI0.PX40.EC0."
147 #define P30_PREFIX "\\_SB.PCI0.LPCB.EC0."
148 #define S1x_PREFIX "\\_SB.PCI0.PX40."
149 #define S2x_PREFIX A1x_PREFIX
150 #define xxN_PREFIX "\\_SB.PCI0.SBRG.EC0."
152 static struct model_data model_conf
[END_MODEL
] = {
154 * Those pathnames are relative to the HOTK / ATKD device :
162 * TODO I have seen a SWBX and AIBX method on some models, like L1400B,
163 * it seems to be a kind of switch, but what for ?
170 .mled_status
= "\\MAIL",
171 .mt_lcd_switch
= A1x_PREFIX
"_Q10",
172 .lcd_status
= "\\BKLI",
173 .brightness_up
= A1x_PREFIX
"_Q0E",
174 .brightness_down
= A1x_PREFIX
"_Q0F"
181 .wled_status
= "\\SG66",
182 .mt_lcd_switch
= "\\Q10",
183 .lcd_status
= "\\BAOF",
184 .brightness_set
= "SPLV",
185 .brightness_get
= "GPLV",
186 .display_set
= "SDSP",
187 .display_get
= "\\INFB"
193 .mt_lcd_switch
= "\\Q0D",
194 .lcd_status
= "\\GP11",
195 .brightness_up
= "\\Q0C",
196 .brightness_down
= "\\Q0B",
197 .brightness_status
= "\\BLVL",
198 .display_set
= "SDSP",
199 .display_get
= "\\INFB"
205 .mled_status
= "\\SGP6",
207 .wled_status
= "\\RCP3",
208 .mt_lcd_switch
= "\\Q10",
209 .lcd_status
= "\\SGP0",
210 .brightness_up
= "\\Q0E",
211 .brightness_down
= "\\Q0F",
212 .display_set
= "SDSP",
213 .display_get
= "\\INFB"
220 .mt_lcd_switch
= L3C_PREFIX
"_Q10",
221 .lcd_status
= "\\GL32",
222 .brightness_set
= "SPLV",
223 .brightness_get
= "GPLV",
224 .display_set
= "SDSP",
225 .display_get
= "\\_SB.PCI0.PCI1.VGAC.NMAP"
231 .mled_status
= "\\MALD",
233 .mt_lcd_switch
= "\\Q10",
234 .lcd_status
= "\\BKLG",
235 .brightness_set
= "SPLV",
236 .brightness_get
= "GPLV",
237 .display_set
= "SDSP",
238 .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"
257 .wled_status
= "\\_SB.PCI0.SBRG.SG13",
258 .mt_lcd_switch
= xxN_PREFIX
"_Q10",
259 .lcd_status
= "\\_SB.PCI0.SBSM.SEO4",
260 .brightness_set
= "SPLV",
261 .brightness_get
= "GPLV",
262 .display_set
= "SDSP",
263 .display_get
= "\\_SB.PCI0.P0P1.VGA.GETD"
269 /* WLED present, but not controlled by ACPI */
271 .mt_lcd_switch
= "\\Q0D",
272 .lcd_status
= "\\BAOF",
273 .brightness_set
= "SPLV",
274 .brightness_get
= "GPLV",
275 .display_set
= "SDSP",
276 .display_get
= "\\INFB"
281 /* No features, but at least support the hotkeys */
287 .mt_lcd_switch
= M1A_PREFIX
"Q10",
288 .lcd_status
= "\\PNOF",
289 .brightness_up
= M1A_PREFIX
"Q0E",
290 .brightness_down
= M1A_PREFIX
"Q0F",
291 .brightness_status
= "\\BRIT",
292 .display_set
= "SDSP",
293 .display_get
= "\\INFB"
300 .mt_lcd_switch
= "\\Q10",
301 .lcd_status
= "\\GP06",
302 .brightness_set
= "SPLV",
303 .brightness_get
= "GPLV",
304 .display_set
= "SDSP",
305 .display_get
= "\\INFB"
312 .wled_status
= "\\_SB.PCI0.SBRG.SG13",
313 .mt_lcd_switch
= xxN_PREFIX
"_Q10",
314 .lcd_status
= "\\_SB.BKLT",
315 .brightness_set
= "SPLV",
316 .brightness_get
= "GPLV",
317 .display_set
= "SDSP",
318 .display_get
= "\\SSTE"
324 .mt_lcd_switch
= xxN_PREFIX
"_Q10",
325 .lcd_status
= "\\_SB.PCI0.SBSM.SEO4",
326 .brightness_set
= "SPLV",
327 .brightness_get
= "GPLV",
328 .display_set
= "SDSP",
329 .display_get
= "\\SSTE"
336 .mt_lcd_switch
= P30_PREFIX
"_Q0E",
337 .lcd_status
= "\\BKLT",
338 .brightness_up
= P30_PREFIX
"_Q68",
339 .brightness_down
= P30_PREFIX
"_Q69",
340 .brightness_get
= "GPLV",
341 .display_set
= "SDSP",
342 .display_get
= "\\DNXT"
348 .mled_status
= "\\EMLE",
350 .mt_lcd_switch
= S1x_PREFIX
"Q10" ,
351 .lcd_status
= "\\PNOF",
352 .brightness_set
= "SPLV",
353 .brightness_get
= "GPLV"
359 .mled_status
= "\\MAIL",
360 .mt_lcd_switch
= S2x_PREFIX
"_Q10",
361 .lcd_status
= "\\BKLI",
362 .brightness_up
= S2x_PREFIX
"_Q0B",
363 .brightness_down
= S2x_PREFIX
"_Q0A"
369 /* WLED present, but not controlled by ACPI */
370 .mt_lcd_switch
= xxN_PREFIX
"_Q10",
371 .lcd_status
= "\\BKLT",
372 .brightness_set
= "SPLV",
373 .brightness_get
= "GPLV",
374 .display_set
= "SDSP",
375 .display_get
= "\\ADVG"
380 static struct proc_dir_entry
*asus_proc_dir
;
383 * This header is made available to allow proper configuration given model,
384 * revision number , ... this info cannot go in struct asus_hotk because it is
385 * available before the hotk
387 static struct acpi_table_header
*asus_info
;
389 /* The actual device the driver binds to */
390 static struct asus_hotk
*hotk
;
393 * The hotkey driver declaration
395 static int asus_hotk_add(struct acpi_device
*device
);
396 static int asus_hotk_remove(struct acpi_device
*device
, int type
);
397 static struct acpi_driver asus_hotk_driver
= {
398 .name
= ACPI_HOTK_NAME
,
399 .class = ACPI_HOTK_CLASS
,
400 .ids
= ACPI_HOTK_HID
,
402 .add
= asus_hotk_add
,
403 .remove
= asus_hotk_remove
,
408 * This function evaluates an ACPI method, given an int as parameter, the
409 * method is searched within the scope of the handle, can be NULL. The output
410 * of the method is written is output, which can also be NULL
412 * returns 1 if write is successful, 0 else.
414 static int write_acpi_int(acpi_handle handle
, const char *method
, int val
,
415 struct acpi_buffer
*output
)
417 struct acpi_object_list params
; //list of input parameters (an int here)
418 union acpi_object in_obj
; //the only param we use
422 params
.pointer
= &in_obj
;
423 in_obj
.type
= ACPI_TYPE_INTEGER
;
424 in_obj
.integer
.value
= val
;
426 status
= acpi_evaluate_object(handle
, (char *) method
, ¶ms
, output
);
427 return (status
== AE_OK
);
431 static int read_acpi_int(acpi_handle handle
, const char *method
, int *val
)
433 struct acpi_buffer output
;
434 union acpi_object out_obj
;
437 output
.length
= sizeof(out_obj
);
438 output
.pointer
= &out_obj
;
440 status
= acpi_evaluate_object(handle
, (char *) method
, NULL
, &output
);
441 *val
= out_obj
.integer
.value
;
442 return (status
== AE_OK
) && (out_obj
.type
== ACPI_TYPE_INTEGER
);
446 * We write our info in page, we begin at offset off and cannot write more
447 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
448 * number of bytes written in page
451 proc_read_info(char *page
, char **start
, off_t off
, int count
, int *eof
,
456 char buf
[16]; //enough for all info
458 * We use the easy way, we don't care of off and count, so we don't set eof
462 len
+= sprintf(page
, ACPI_HOTK_NAME
" " ASUS_ACPI_VERSION
"\n");
463 len
+= sprintf(page
+ len
, "Model reference : %s\n",
464 hotk
->methods
->name
);
466 * The SFUN method probably allows the original driver to get the list
467 * of features supported by a given model. For now, 0x0100 or 0x0800
468 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
469 * The significance of others is yet to be found.
471 if (read_acpi_int(hotk
->handle
, "SFUN", &temp
))
472 len
+= sprintf(page
+ len
, "SFUN value : 0x%04x\n", temp
);
474 * Another value for userspace: the ASYM method returns 0x02 for
475 * battery low and 0x04 for battery critical, its readings tend to be
476 * more accurate than those provided by _BST.
477 * Note: since not all the laptops provide this method, errors are
480 if (read_acpi_int(hotk
->handle
, "ASYM", &temp
))
481 len
+= sprintf(page
+ len
, "ASYM value : 0x%04x\n", temp
);
483 snprintf(buf
, 16, "%d", asus_info
->length
);
484 len
+= sprintf(page
+ len
, "DSDT length : %s\n", buf
);
485 snprintf(buf
, 16, "%d", asus_info
->checksum
);
486 len
+= sprintf(page
+ len
, "DSDT checksum : %s\n", buf
);
487 snprintf(buf
, 16, "%d", asus_info
->revision
);
488 len
+= sprintf(page
+ len
, "DSDT revision : %s\n", buf
);
489 snprintf(buf
, 7, "%s", asus_info
->oem_id
);
490 len
+= sprintf(page
+ len
, "OEM id : %s\n", buf
);
491 snprintf(buf
, 9, "%s", asus_info
->oem_table_id
);
492 len
+= sprintf(page
+ len
, "OEM table id : %s\n", buf
);
493 snprintf(buf
, 16, "%x", asus_info
->oem_revision
);
494 len
+= sprintf(page
+ len
, "OEM revision : 0x%s\n", buf
);
495 snprintf(buf
, 5, "%s", asus_info
->asl_compiler_id
);
496 len
+= sprintf(page
+ len
, "ASL comp vendor id : %s\n", buf
);
497 snprintf(buf
, 16, "%x", asus_info
->asl_compiler_revision
);
498 len
+= sprintf(page
+ len
, "ASL comp revision : 0x%s\n", buf
);
507 * We write our info in page, we begin at offset off and cannot write more
508 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
509 * number of bytes written in page
512 /* Generic LED functions */
514 read_led(const char *ledname
, int ledmask
)
519 if (read_acpi_int(NULL
, ledname
, &led_status
))
522 printk(KERN_WARNING
"Asus ACPI: Error reading LED "
525 return (hotk
->status
& ledmask
) ? 1 : 0;
528 static int parse_arg(const char __user
*buf
, unsigned long count
, int *val
)
535 if (copy_from_user(s
, buf
, count
))
538 if (sscanf(s
, "%i", val
) != 1)
543 /* FIXME: kill extraneous args so it can be called independently */
545 write_led(const char __user
*buffer
, unsigned long count
,
546 char *ledname
, int ledmask
, int invert
)
551 count
= parse_arg(buffer
, count
, &value
);
553 led_out
= value
? 1 : 0;
556 (led_out
) ? (hotk
->status
| ledmask
) : (hotk
->status
& ~ledmask
);
558 if (invert
) /* invert target value */
559 led_out
= !led_out
& 0x1;
561 if (!write_acpi_int(hotk
->handle
, ledname
, led_out
, NULL
))
562 printk(KERN_WARNING
"Asus ACPI: LED (%s) write failed\n", ledname
);
569 * Proc handlers for MLED
572 proc_read_mled(char *page
, char **start
, off_t off
, int count
, int *eof
,
575 return sprintf(page
, "%d\n", read_led(hotk
->methods
->mled_status
, MLED_ON
));
580 proc_write_mled(struct file
*file
, const char __user
*buffer
,
581 unsigned long count
, void *data
)
583 return write_led(buffer
, count
, hotk
->methods
->mt_mled
, MLED_ON
, 1);
587 * Proc handlers for WLED
590 proc_read_wled(char *page
, char **start
, off_t off
, int count
, int *eof
,
593 return sprintf(page
, "%d\n", read_led(hotk
->methods
->wled_status
, WLED_ON
));
597 proc_write_wled(struct file
*file
, const char __user
*buffer
,
598 unsigned long count
, void *data
)
600 return write_led(buffer
, count
, hotk
->methods
->mt_wled
, WLED_ON
, 0);
604 * Proc handlers for TLED
607 proc_read_tled(char *page
, char **start
, off_t off
, int count
, int *eof
,
610 return sprintf(page
, "%d\n", read_led(hotk
->methods
->tled_status
, TLED_ON
));
614 proc_write_tled(struct file
*file
, const char __user
*buffer
,
615 unsigned long count
, void *data
)
617 return write_led(buffer
, count
, hotk
->methods
->mt_tled
, TLED_ON
, 0);
621 static int get_lcd_state(void)
625 if (hotk
->model
!= L3H
) {
626 /* We don't have to check anything if we are here */
627 if (!read_acpi_int(NULL
, hotk
->methods
->lcd_status
, &lcd
))
628 printk(KERN_WARNING
"Asus ACPI: Error reading LCD status\n");
630 if (hotk
->model
== L2D
)
632 } else { /* L3H and the like have to be handled differently */
633 acpi_status status
= 0;
634 struct acpi_object_list input
;
635 union acpi_object mt_params
[2];
636 struct acpi_buffer output
;
637 union acpi_object out_obj
;
640 input
.pointer
= mt_params
;
641 /* Note: the following values are partly guessed up, but
642 otherwise they seem to work */
643 mt_params
[0].type
= ACPI_TYPE_INTEGER
;
644 mt_params
[0].integer
.value
= 0x02;
645 mt_params
[1].type
= ACPI_TYPE_INTEGER
;
646 mt_params
[1].integer
.value
= 0x02;
648 output
.length
= sizeof(out_obj
);
649 output
.pointer
= &out_obj
;
651 status
= acpi_evaluate_object(NULL
, hotk
->methods
->lcd_status
, &input
, &output
);
654 if (out_obj
.type
== ACPI_TYPE_INTEGER
)
655 /* That's what the AML code does */
656 lcd
= out_obj
.integer
.value
>> 8;
662 static int set_lcd_state(int value
)
665 acpi_status status
= 0;
668 if (lcd
!= get_lcd_state()) {
670 if (hotk
->model
!= L3H
) {
672 acpi_evaluate_object(NULL
, hotk
->methods
->mt_lcd_switch
,
674 } else { /* L3H and the like have to be handled differently */
675 if (!write_acpi_int(hotk
->handle
, hotk
->methods
->mt_lcd_switch
, 0x07, NULL
))
677 /* L3H's AML executes EHK (0x07) upon Fn+F7 keypress,
678 the exact behaviour is simulated here */
680 if (ACPI_FAILURE(status
))
681 printk(KERN_WARNING
"Asus ACPI: Error switching LCD\n");
688 proc_read_lcd(char *page
, char **start
, off_t off
, int count
, int *eof
,
691 return sprintf(page
, "%d\n", get_lcd_state());
696 proc_write_lcd(struct file
*file
, const char __user
*buffer
,
697 unsigned long count
, void *data
)
701 count
= parse_arg(buffer
, count
, &value
);
703 set_lcd_state(value
);
708 static int read_brightness(void)
712 if(hotk
->methods
->brightness_get
) { /* SPLV/GPLV laptop */
713 if (!read_acpi_int(hotk
->handle
, hotk
->methods
->brightness_get
,
715 printk(KERN_WARNING
"Asus ACPI: Error reading brightness\n");
716 } else if (hotk
->methods
->brightness_status
) { /* For D1 for example */
717 if (!read_acpi_int(NULL
, hotk
->methods
->brightness_status
,
719 printk(KERN_WARNING
"Asus ACPI: Error reading brightness\n");
720 } else /* No GPLV method */
721 value
= hotk
->brightness
;
726 * Change the brightness level
728 static void set_brightness(int value
)
730 acpi_status status
= 0;
733 if(hotk
->methods
->brightness_set
) {
734 if (!write_acpi_int(hotk
->handle
, hotk
->methods
->brightness_set
,
736 printk(KERN_WARNING
"Asus ACPI: Error changing brightness\n");
740 /* No SPLV method if we are here, act as appropriate */
741 value
-= read_brightness();
743 status
= acpi_evaluate_object(NULL
, (value
> 0) ?
744 hotk
->methods
->brightness_up
:
745 hotk
->methods
->brightness_down
,
747 (value
> 0) ? value
-- : value
++;
748 if (ACPI_FAILURE(status
))
749 printk(KERN_WARNING
"Asus ACPI: Error changing brightness\n");
755 proc_read_brn(char *page
, char **start
, off_t off
, int count
, int *eof
,
758 return sprintf(page
, "%d\n", read_brightness());
762 proc_write_brn(struct file
*file
, const char __user
*buffer
,
763 unsigned long count
, void *data
)
767 count
= parse_arg(buffer
, count
, &value
);
769 value
= (0 < value
) ? ((15 < value
) ? 15 : value
) : 0;
770 /* 0 <= value <= 15 */
771 set_brightness(value
);
772 } else if (count
< 0) {
773 printk(KERN_WARNING
"Asus ACPI: Error reading user input\n");
779 static void set_display(int value
)
781 /* no sanity check needed for now */
782 if (!write_acpi_int(hotk
->handle
, hotk
->methods
->display_set
,
784 printk(KERN_WARNING
"Asus ACPI: Error setting display\n");
789 * Now, *this* one could be more user-friendly, but so far, no-one has
790 * complained. The significance of bits is the same as in proc_write_disp()
793 proc_read_disp(char *page
, char **start
, off_t off
, int count
, int *eof
,
798 if (!read_acpi_int(hotk
->handle
, hotk
->methods
->display_get
, &value
))
799 printk(KERN_WARNING
"Asus ACPI: Error reading display status\n");
800 value
&= 0x07; /* needed for some models, shouldn't hurt others */
801 return sprintf(page
, "%d\n", value
);
805 * Experimental support for display switching. As of now: 1 should activate
806 * the LCD output, 2 should do for CRT, and 4 for TV-Out. Any combination
807 * (bitwise) of these will suffice. I never actually tested 3 displays hooked up
808 * simultaneously, so be warned. See the acpi4asus README for more info.
811 proc_write_disp(struct file
*file
, const char __user
*buffer
,
812 unsigned long count
, void *data
)
816 count
= parse_arg(buffer
, count
, &value
);
820 printk(KERN_WARNING
"Asus ACPI: Error reading user input\n");
826 typedef int (proc_readfunc
)(char *page
, char **start
, off_t off
, int count
,
827 int *eof
, void *data
);
828 typedef int (proc_writefunc
)(struct file
*file
, const char __user
*buffer
,
829 unsigned long count
, void *data
);
832 __init
asus_proc_add(char *name
, proc_writefunc
*writefunc
,
833 proc_readfunc
*readfunc
, mode_t mode
,
834 struct acpi_device
*device
)
836 struct proc_dir_entry
*proc
= create_proc_entry(name
, mode
, acpi_device_dir(device
));
838 printk(KERN_WARNING
" Unable to create %s fs entry\n", name
);
841 proc
->write_proc
= writefunc
;
842 proc
->read_proc
= readfunc
;
843 proc
->data
= acpi_driver_data(device
);
844 proc
->owner
= THIS_MODULE
;
845 proc
->uid
= asus_uid
;
846 proc
->gid
= asus_gid
;
850 static int __init
asus_hotk_add_fs(struct acpi_device
*device
)
852 struct proc_dir_entry
*proc
;
856 * If parameter uid or gid is not changed, keep the default setting for
857 * our proc entries (-rw-rw-rw-) else, it means we care about security,
858 * and then set to -rw-rw----
861 if ((asus_uid
== 0) && (asus_gid
== 0)){
862 mode
= S_IFREG
| S_IRUGO
| S_IWUGO
;
864 mode
= S_IFREG
| S_IRUSR
| S_IRGRP
| S_IWUSR
| S_IWGRP
;
867 acpi_device_dir(device
) = asus_proc_dir
;
868 if (!acpi_device_dir(device
))
871 proc
= create_proc_entry(PROC_INFO
, mode
, acpi_device_dir(device
));
873 proc
->read_proc
= proc_read_info
;
874 proc
->data
= acpi_driver_data(device
);
875 proc
->owner
= THIS_MODULE
;
876 proc
->uid
= asus_uid
;
877 proc
->gid
= asus_gid
;
879 printk(KERN_WARNING
" Unable to create " PROC_INFO
883 if (hotk
->methods
->mt_wled
) {
884 asus_proc_add(PROC_WLED
, &proc_write_wled
, &proc_read_wled
, mode
, device
);
887 if (hotk
->methods
->mt_mled
) {
888 asus_proc_add(PROC_MLED
, &proc_write_mled
, &proc_read_mled
, mode
, device
);
891 if (hotk
->methods
->mt_tled
) {
892 asus_proc_add(PROC_TLED
, &proc_write_tled
, &proc_read_tled
, mode
, device
);
896 * We need both read node and write method as LCD switch is also accessible
899 if (hotk
->methods
->mt_lcd_switch
&& hotk
->methods
->lcd_status
) {
900 asus_proc_add(PROC_LCD
, &proc_write_lcd
, &proc_read_lcd
, mode
, device
);
903 if ((hotk
->methods
->brightness_up
&& hotk
->methods
->brightness_down
) ||
904 (hotk
->methods
->brightness_get
&& hotk
->methods
->brightness_set
)) {
905 asus_proc_add(PROC_BRN
, &proc_write_brn
, &proc_read_brn
, mode
, device
);
908 if (hotk
->methods
->display_set
) {
909 asus_proc_add(PROC_DISP
, &proc_write_disp
, &proc_read_disp
, mode
, device
);
915 static int asus_hotk_remove_fs(struct acpi_device
* device
)
917 if(acpi_device_dir(device
)) {
918 remove_proc_entry(PROC_INFO
,acpi_device_dir(device
));
919 if (hotk
->methods
->mt_wled
)
920 remove_proc_entry(PROC_WLED
,acpi_device_dir(device
));
921 if (hotk
->methods
->mt_mled
)
922 remove_proc_entry(PROC_MLED
,acpi_device_dir(device
));
923 if (hotk
->methods
->mt_tled
)
924 remove_proc_entry(PROC_TLED
,acpi_device_dir(device
));
925 if (hotk
->methods
->mt_lcd_switch
&& hotk
->methods
->lcd_status
)
926 remove_proc_entry(PROC_LCD
, acpi_device_dir(device
));
927 if ((hotk
->methods
->brightness_up
&& hotk
->methods
->brightness_down
) ||
928 (hotk
->methods
->brightness_get
&& hotk
->methods
->brightness_set
))
929 remove_proc_entry(PROC_BRN
, acpi_device_dir(device
));
930 if (hotk
->methods
->display_set
)
931 remove_proc_entry(PROC_DISP
, acpi_device_dir(device
));
937 static void asus_hotk_notify(acpi_handle handle
, u32 event
, void *data
)
939 /* TODO Find a better way to handle events count.*/
943 if ((event
& ~((u32
) BR_UP
)) < 16) {
944 hotk
->brightness
= (event
& ~((u32
) BR_UP
));
945 } else if ((event
& ~((u32
) BR_DOWN
)) < 16 ) {
946 hotk
->brightness
= (event
& ~((u32
) BR_DOWN
));
949 acpi_bus_generate_event(hotk
->device
, event
,
950 hotk
->event_count
[event
% 128]++);
956 * This function is used to initialize the hotk with right values. In this
957 * method, we can make all the detection we want, and modify the hotk struct
959 static int __init
asus_hotk_get_info(void)
961 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
962 struct acpi_buffer dsdt
= { ACPI_ALLOCATE_BUFFER
, NULL
};
963 union acpi_object
*model
= NULL
;
968 * Get DSDT headers early enough to allow for differentiating between
969 * models, but late enough to allow acpi_bus_register_driver() to fail
970 * before doing anything ACPI-specific. Should we encounter a machine,
971 * which needs special handling (i.e. its hotkey device has a different
972 * HID), this bit will be moved. A global variable asus_info contains
975 status
= acpi_get_table(ACPI_TABLE_DSDT
, 1, &dsdt
);
976 if (ACPI_FAILURE(status
))
977 printk(KERN_WARNING
" Couldn't get the DSDT table header\n");
979 asus_info
= (struct acpi_table_header
*) dsdt
.pointer
;
981 /* We have to write 0 on init this far for all ASUS models */
982 if (!write_acpi_int(hotk
->handle
, "INIT", 0, &buffer
)) {
983 printk(KERN_ERR
" Hotkey initialization failed\n");
987 /* This needs to be called for some laptops to init properly */
988 if (!read_acpi_int(hotk
->handle
, "BSTS", &bsts_result
))
989 printk(KERN_WARNING
" Error calling BSTS\n");
990 else if (bsts_result
)
991 printk(KERN_NOTICE
" BSTS called, 0x%02x returned\n", bsts_result
);
993 /* Samsung P30 has a device with a valid _HID whose INIT does not
994 * return anything. Catch this one and any similar here */
995 if (buffer
.pointer
== NULL
) {
996 if (asus_info
&& /* Samsung P30 */
997 strncmp(asus_info
->oem_table_id
, "ODEM", 4) == 0) {
999 printk(KERN_NOTICE
" Samsung P30 detected, supported\n");
1002 printk(KERN_WARNING
" no string returned by INIT\n");
1003 printk(KERN_WARNING
" trying default values, supply "
1004 "the developers with your DSDT\n");
1006 hotk
->methods
= &model_conf
[hotk
->model
];
1010 model
= (union acpi_object
*) buffer
.pointer
;
1011 if (model
->type
== ACPI_TYPE_STRING
) {
1012 printk(KERN_NOTICE
" %s model detected, ", model
->string
.pointer
);
1015 hotk
->model
= END_MODEL
;
1016 if (strncmp(model
->string
.pointer
, "L3D", 3) == 0)
1018 else if (strncmp(model
->string
.pointer
, "L3H", 3) == 0 ||
1019 strncmp(model
->string
.pointer
, "L2E", 3) == 0)
1021 else if (strncmp(model
->string
.pointer
, "L3", 2) == 0 ||
1022 strncmp(model
->string
.pointer
, "L2B", 3) == 0)
1024 else if (strncmp(model
->string
.pointer
, "L8L", 3) == 0)
1026 else if (strncmp(model
->string
.pointer
, "L4R", 3) == 0)
1028 else if (strncmp(model
->string
.pointer
, "M6N", 3) == 0)
1030 else if (strncmp(model
->string
.pointer
, "M6R", 3) == 0)
1032 else if (strncmp(model
->string
.pointer
, "M2N", 3) == 0 ||
1033 strncmp(model
->string
.pointer
, "M3N", 3) == 0 ||
1034 strncmp(model
->string
.pointer
, "M5N", 3) == 0 ||
1035 strncmp(model
->string
.pointer
, "M6N", 3) == 0 ||
1036 strncmp(model
->string
.pointer
, "S1N", 3) == 0 ||
1037 strncmp(model
->string
.pointer
, "S5N", 3) == 0 ||
1038 strncmp(model
->string
.pointer
, "W1N", 3) == 0)
1040 else if (strncmp(model
->string
.pointer
, "M1", 2) == 0)
1042 else if (strncmp(model
->string
.pointer
, "M2", 2) == 0 ||
1043 strncmp(model
->string
.pointer
, "L4E", 3) == 0)
1045 else if (strncmp(model
->string
.pointer
, "L2", 2) == 0)
1047 else if (strncmp(model
->string
.pointer
, "L8", 2) == 0)
1049 else if (strncmp(model
->string
.pointer
, "D1", 2) == 0)
1051 else if (strncmp(model
->string
.pointer
, "A1", 2) == 0)
1053 else if (strncmp(model
->string
.pointer
, "A2", 2) == 0)
1055 else if (strncmp(model
->string
.pointer
, "J1", 2) == 0)
1057 else if (strncmp(model
->string
.pointer
, "L5", 2) == 0)
1060 if (hotk
->model
== END_MODEL
) {
1061 printk("unsupported, trying default values, supply the "
1062 "developers with your DSDT\n");
1065 printk("supported\n");
1068 hotk
->methods
= &model_conf
[hotk
->model
];
1070 /* Sort of per-model blacklist */
1071 if (strncmp(model
->string
.pointer
, "L2B", 3) == 0)
1072 hotk
->methods
->lcd_status
= NULL
;
1073 /* L2B is similar enough to L3C to use its settings, with this only
1075 else if (strncmp(model
->string
.pointer
, "S5N", 3) == 0 ||
1076 strncmp(model
->string
.pointer
, "M5N", 3) == 0)
1077 hotk
->methods
->mt_mled
= NULL
;
1078 /* S5N and M5N have no MLED */
1079 else if (strncmp(model
->string
.pointer
, "M2N", 3) == 0 ||
1080 strncmp(model
->string
.pointer
, "W1N", 3) == 0)
1081 hotk
->methods
->mt_wled
= "WLED";
1082 /* M2N and W1N have a usable WLED */
1083 else if (asus_info
) {
1084 if (strncmp(asus_info
->oem_table_id
, "L1", 2) == 0)
1085 hotk
->methods
->mled_status
= NULL
;
1086 /* S1300A reports L84F, but L1400B too, account for that */
1089 acpi_os_free(model
);
1095 static int __init
asus_hotk_check(void)
1099 result
= acpi_bus_get_status(hotk
->device
);
1103 if (hotk
->device
->status
.present
) {
1104 result
= asus_hotk_get_info();
1106 printk(KERN_ERR
" Hotkey device not present, aborting\n");
1114 static int __init
asus_hotk_add(struct acpi_device
*device
)
1116 acpi_status status
= AE_OK
;
1122 printk(KERN_NOTICE
"Asus Laptop ACPI Extras version %s\n",
1126 (struct asus_hotk
*) kmalloc(sizeof(struct asus_hotk
), GFP_KERNEL
);
1129 memset(hotk
, 0, sizeof(struct asus_hotk
));
1131 hotk
->handle
= device
->handle
;
1132 strcpy(acpi_device_name(device
), ACPI_HOTK_DEVICE_NAME
);
1133 strcpy(acpi_device_class(device
), ACPI_HOTK_CLASS
);
1134 acpi_driver_data(device
) = hotk
;
1135 hotk
->device
= device
;
1138 result
= asus_hotk_check();
1142 result
= asus_hotk_add_fs(device
);
1147 * We install the handler, it will receive the hotk in parameter, so, we
1148 * could add other data to the hotk struct
1150 status
= acpi_install_notify_handler(hotk
->handle
, ACPI_SYSTEM_NOTIFY
,
1151 asus_hotk_notify
, hotk
);
1152 if (ACPI_FAILURE(status
))
1153 printk(KERN_ERR
" Error installing notify handler\n");
1155 /* For laptops without GPLV: init the hotk->brightness value */
1156 if ((!hotk
->methods
->brightness_get
) && (!hotk
->methods
->brightness_status
) &&
1157 (hotk
->methods
->brightness_up
&& hotk
->methods
->brightness_down
)) {
1158 status
= acpi_evaluate_object(NULL
, hotk
->methods
->brightness_down
,
1160 if (ACPI_FAILURE(status
))
1161 printk(KERN_WARNING
" Error changing brightness\n");
1163 status
= acpi_evaluate_object(NULL
, hotk
->methods
->brightness_up
,
1165 if (ACPI_FAILURE(status
))
1166 printk(KERN_WARNING
" Strange, error changing"
1180 static int asus_hotk_remove(struct acpi_device
*device
, int type
)
1182 acpi_status status
= 0;
1184 if (!device
|| !acpi_driver_data(device
))
1187 status
= acpi_remove_notify_handler(hotk
->handle
, ACPI_SYSTEM_NOTIFY
,
1189 if (ACPI_FAILURE(status
))
1190 printk(KERN_ERR
"Asus ACPI: Error removing notify handler\n");
1192 asus_hotk_remove_fs(device
);
1200 static int __init
asus_acpi_init(void)
1207 asus_proc_dir
= proc_mkdir(PROC_ASUS
, acpi_root_dir
);
1208 if (!asus_proc_dir
) {
1209 printk(KERN_ERR
"Asus ACPI: Unable to create /proc entry\n");
1212 asus_proc_dir
->owner
= THIS_MODULE
;
1214 result
= acpi_bus_register_driver(&asus_hotk_driver
);
1216 acpi_bus_unregister_driver(&asus_hotk_driver
);
1217 remove_proc_entry(PROC_ASUS
, acpi_root_dir
);
1225 static void __exit
asus_acpi_exit(void)
1227 acpi_bus_unregister_driver(&asus_hotk_driver
);
1228 remove_proc_entry(PROC_ASUS
, acpi_root_dir
);
1230 acpi_os_free(asus_info
);
1235 module_init(asus_acpi_init
);
1236 module_exit(asus_acpi_exit
);