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.
32 #include <linux/kernel.h>
33 #include <linux/module.h>
34 #include <linux/init.h>
35 #include <linux/types.h>
36 #include <linux/proc_fs.h>
37 #include <acpi/acpi_drivers.h>
38 #include <acpi/acpi_bus.h>
39 #include <asm/uaccess.h>
41 #define ASUS_ACPI_VERSION "0.30"
43 #define PROC_ASUS "asus" //the directory
44 #define PROC_MLED "mled"
45 #define PROC_WLED "wled"
46 #define PROC_TLED "tled"
47 #define PROC_INFO "info"
48 #define PROC_LCD "lcd"
49 #define PROC_BRN "brn"
50 #define PROC_DISP "disp"
52 #define ACPI_HOTK_NAME "Asus Laptop ACPI Extras Driver"
53 #define ACPI_HOTK_CLASS "hotkey"
54 #define ACPI_HOTK_DEVICE_NAME "Hotkey"
55 #define ACPI_HOTK_HID "ATK0100"
58 * Some events we use, same for all Asus
64 * Flags for hotk status
66 #define MLED_ON 0x01 //is MLED ON ?
70 MODULE_AUTHOR("Julien Lerouge, Karol Kozimor");
71 MODULE_DESCRIPTION(ACPI_HOTK_NAME
);
72 MODULE_LICENSE("GPL");
74 static uid_t asus_uid
;
75 static gid_t asus_gid
;
76 module_param(asus_uid
, uint
, 0);
77 MODULE_PARM_DESC(asus_uid
, "UID for entries in /proc/acpi/asus.\n");
78 module_param(asus_gid
, uint
, 0);
79 MODULE_PARM_DESC(asus_gid
, "GID for entries in /proc/acpi/asus.\n");
81 /* For each model, all features implemented,
82 * those marked with R are relative to HOTK, A for absolute */
84 char *name
; //name of the laptop________________A
85 char *mt_mled
; //method to handle mled_____________R
86 char *mled_status
; //node to handle mled reading_______A
87 char *mt_wled
; //method to handle wled_____________R
88 char *wled_status
; //node to handle wled reading_______A
89 char *mt_tled
; //method to handle tled_____________R
90 char *tled_status
; //node to handle tled reading_______A
91 char *mt_lcd_switch
; //method to turn LCD ON/OFF_________A
92 char *lcd_status
; //node to read LCD panel state______A
93 char *brightness_up
; //method to set brightness up_______A
94 char *brightness_down
; //guess what ?______________________A
95 char *brightness_set
; //method to set absolute brightness_R
96 char *brightness_get
; //method to get absolute brightness_R
97 char *brightness_status
; //node to get brightness____________A
98 char *display_set
; //method to set video output________R
99 char *display_get
; //method to get video output________R
103 * This is the main structure, we can use it to store anything interesting
104 * about the hotk device
107 struct acpi_device
*device
; //the device we are in
108 acpi_handle handle
; //the handle of the hotk device
109 char status
; //status of the hotk, for LEDs, ...
110 struct model_data
*methods
; //methods available on the laptop
111 u8 brightness
; //brightness level
113 A1x
= 0, //A1340D, A1300F
119 L3H
, //L3H, but also L2000E
124 M2E
, //M2400E, L4400L
126 M6R
, //M6700R, A3000G
128 S1x
, //S1300A, but also L1400B and M2400A (L84F)
129 S2x
, //S200 (J1 reported), Victor MP-XP7210
130 xxN
, //M2400N, M3700N, M5200N, S1300N, S5200N, W1OOON
133 } model
; //Models currently supported
134 u16 event_count
[128]; //count for each event TODO make this better
138 #define A1x_PREFIX "\\_SB.PCI0.ISA.EC0."
139 #define L3C_PREFIX "\\_SB.PCI0.PX40.ECD0."
140 #define M1A_PREFIX "\\_SB.PCI0.PX40.EC0."
141 #define P30_PREFIX "\\_SB.PCI0.LPCB.EC0."
142 #define S1x_PREFIX "\\_SB.PCI0.PX40."
143 #define S2x_PREFIX A1x_PREFIX
144 #define xxN_PREFIX "\\_SB.PCI0.SBRG.EC0."
146 static struct model_data model_conf
[END_MODEL
] = {
148 * TODO I have seen a SWBX and AIBX method on some models, like L1400B,
149 * it seems to be a kind of switch, but what for ?
155 .mled_status
= "\\MAIL",
156 .mt_lcd_switch
= A1x_PREFIX
"_Q10",
157 .lcd_status
= "\\BKLI",
158 .brightness_up
= A1x_PREFIX
"_Q0E",
159 .brightness_down
= A1x_PREFIX
"_Q0F"},
165 .wled_status
= "\\SG66",
166 .mt_lcd_switch
= "\\Q10",
167 .lcd_status
= "\\BAOF",
168 .brightness_set
= "SPLV",
169 .brightness_get
= "GPLV",
170 .display_set
= "SDSP",
171 .display_get
= "\\INFB"},
176 .mt_lcd_switch
= "\\Q0D",
177 .lcd_status
= "\\GP11",
178 .brightness_up
= "\\Q0C",
179 .brightness_down
= "\\Q0B",
180 .brightness_status
= "\\BLVL",
181 .display_set
= "SDSP",
182 .display_get
= "\\INFB"},
187 .mled_status
= "\\SGP6",
189 .wled_status
= "\\RCP3",
190 .mt_lcd_switch
= "\\Q10",
191 .lcd_status
= "\\SGP0",
192 .brightness_up
= "\\Q0E",
193 .brightness_down
= "\\Q0F",
194 .display_set
= "SDSP",
195 .display_get
= "\\INFB"},
201 .mt_lcd_switch
= L3C_PREFIX
"_Q10",
202 .lcd_status
= "\\GL32",
203 .brightness_set
= "SPLV",
204 .brightness_get
= "GPLV",
205 .display_set
= "SDSP",
206 .display_get
= "\\_SB.PCI0.PCI1.VGAC.NMAP"},
211 .mled_status
= "\\MALD",
213 .mt_lcd_switch
= "\\Q10",
214 .lcd_status
= "\\BKLG",
215 .brightness_set
= "SPLV",
216 .brightness_get
= "GPLV",
217 .display_set
= "SDSP",
218 .display_get
= "\\INFB"},
224 .mt_lcd_switch
= "EHK",
225 .lcd_status
= "\\_SB.PCI0.PM.PBC",
226 .brightness_set
= "SPLV",
227 .brightness_get
= "GPLV",
228 .display_set
= "SDSP",
229 .display_get
= "\\INFB"},
235 .wled_status
= "\\_SB.PCI0.SBRG.SG13",
236 .mt_lcd_switch
= xxN_PREFIX
"_Q10",
237 .lcd_status
= "\\_SB.PCI0.SBSM.SEO4",
238 .brightness_set
= "SPLV",
239 .brightness_get
= "GPLV",
240 .display_set
= "SDSP",
241 .display_get
= "\\_SB.PCI0.P0P1.VGA.GETD"},
246 /* WLED present, but not controlled by ACPI */
248 .mt_lcd_switch
= "\\Q0D",
249 .lcd_status
= "\\BAOF",
250 .brightness_set
= "SPLV",
251 .brightness_get
= "GPLV",
252 .display_set
= "SDSP",
253 .display_get
= "\\INFB"},
257 /* No features, but at least support the hotkeys */
263 .mt_lcd_switch
= M1A_PREFIX
"Q10",
264 .lcd_status
= "\\PNOF",
265 .brightness_up
= M1A_PREFIX
"Q0E",
266 .brightness_down
= M1A_PREFIX
"Q0F",
267 .brightness_status
= "\\BRIT",
268 .display_set
= "SDSP",
269 .display_get
= "\\INFB"},
275 .mt_lcd_switch
= "\\Q10",
276 .lcd_status
= "\\GP06",
277 .brightness_set
= "SPLV",
278 .brightness_get
= "GPLV",
279 .display_set
= "SDSP",
280 .display_get
= "\\INFB"},
286 .wled_status
= "\\_SB.PCI0.SBRG.SG13",
287 .mt_lcd_switch
= xxN_PREFIX
"_Q10",
288 .lcd_status
= "\\_SB.BKLT",
289 .brightness_set
= "SPLV",
290 .brightness_get
= "GPLV",
291 .display_set
= "SDSP",
292 .display_get
= "\\_SB.PCI0.P0P1.VGA.GETD"},
297 .mt_lcd_switch
= xxN_PREFIX
"_Q10",
298 .lcd_status
= "\\_SB.PCI0.SBSM.SEO4",
299 .brightness_set
= "SPLV",
300 .brightness_get
= "GPLV",
301 .display_set
= "SDSP",
302 .display_get
= "\\SSTE"},
307 .mt_lcd_switch
= P30_PREFIX
"_Q0E",
308 .lcd_status
= "\\BKLT",
309 .brightness_up
= P30_PREFIX
"_Q68",
310 .brightness_down
= P30_PREFIX
"_Q69",
311 .brightness_get
= "GPLV",
312 .display_set
= "SDSP",
313 .display_get
= "\\DNXT"},
318 .mled_status
= "\\EMLE",
320 .mt_lcd_switch
= S1x_PREFIX
"Q10",
321 .lcd_status
= "\\PNOF",
322 .brightness_set
= "SPLV",
323 .brightness_get
= "GPLV"},
328 .mled_status
= "\\MAIL",
329 .mt_lcd_switch
= S2x_PREFIX
"_Q10",
330 .lcd_status
= "\\BKLI",
331 .brightness_up
= S2x_PREFIX
"_Q0B",
332 .brightness_down
= S2x_PREFIX
"_Q0A"},
337 /* WLED present, but not controlled by ACPI */
338 .mt_lcd_switch
= xxN_PREFIX
"_Q10",
339 .lcd_status
= "\\BKLT",
340 .brightness_set
= "SPLV",
341 .brightness_get
= "GPLV",
342 .display_set
= "SDSP",
343 .display_get
= "\\ADVG"}
347 static struct proc_dir_entry
*asus_proc_dir
;
350 * This header is made available to allow proper configuration given model,
351 * revision number , ... this info cannot go in struct asus_hotk because it is
352 * available before the hotk
354 static struct acpi_table_header
*asus_info
;
356 /* The actual device the driver binds to */
357 static struct asus_hotk
*hotk
;
360 * The hotkey driver declaration
362 static int asus_hotk_add(struct acpi_device
*device
);
363 static int asus_hotk_remove(struct acpi_device
*device
, int type
);
364 static struct acpi_driver asus_hotk_driver
= {
365 .name
= ACPI_HOTK_NAME
,
366 .class = ACPI_HOTK_CLASS
,
367 .ids
= ACPI_HOTK_HID
,
369 .add
= asus_hotk_add
,
370 .remove
= asus_hotk_remove
,
375 * This function evaluates an ACPI method, given an int as parameter, the
376 * method is searched within the scope of the handle, can be NULL. The output
377 * of the method is written is output, which can also be NULL
379 * returns 1 if write is successful, 0 else.
381 static int write_acpi_int(acpi_handle handle
, const char *method
, int val
,
382 struct acpi_buffer
*output
)
384 struct acpi_object_list params
; //list of input parameters (an int here)
385 union acpi_object in_obj
; //the only param we use
389 params
.pointer
= &in_obj
;
390 in_obj
.type
= ACPI_TYPE_INTEGER
;
391 in_obj
.integer
.value
= val
;
393 status
= acpi_evaluate_object(handle
, (char *)method
, ¶ms
, output
);
394 return (status
== AE_OK
);
397 static int read_acpi_int(acpi_handle handle
, const char *method
, int *val
)
399 struct acpi_buffer output
;
400 union acpi_object out_obj
;
403 output
.length
= sizeof(out_obj
);
404 output
.pointer
= &out_obj
;
406 status
= acpi_evaluate_object(handle
, (char *)method
, NULL
, &output
);
407 *val
= out_obj
.integer
.value
;
408 return (status
== AE_OK
) && (out_obj
.type
== ACPI_TYPE_INTEGER
);
412 * We write our info in page, we begin at offset off and cannot write more
413 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
414 * number of bytes written in page
417 proc_read_info(char *page
, char **start
, off_t off
, int count
, int *eof
,
422 char buf
[16]; //enough for all info
424 * We use the easy way, we don't care of off and count, so we don't set eof
428 len
+= sprintf(page
, ACPI_HOTK_NAME
" " ASUS_ACPI_VERSION
"\n");
429 len
+= sprintf(page
+ len
, "Model reference : %s\n",
430 hotk
->methods
->name
);
432 * The SFUN method probably allows the original driver to get the list
433 * of features supported by a given model. For now, 0x0100 or 0x0800
434 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
435 * The significance of others is yet to be found.
437 if (read_acpi_int(hotk
->handle
, "SFUN", &temp
))
439 sprintf(page
+ len
, "SFUN value : 0x%04x\n", temp
);
441 * Another value for userspace: the ASYM method returns 0x02 for
442 * battery low and 0x04 for battery critical, its readings tend to be
443 * more accurate than those provided by _BST.
444 * Note: since not all the laptops provide this method, errors are
447 if (read_acpi_int(hotk
->handle
, "ASYM", &temp
))
449 sprintf(page
+ len
, "ASYM value : 0x%04x\n", temp
);
451 snprintf(buf
, 16, "%d", asus_info
->length
);
452 len
+= sprintf(page
+ len
, "DSDT length : %s\n", buf
);
453 snprintf(buf
, 16, "%d", asus_info
->checksum
);
454 len
+= sprintf(page
+ len
, "DSDT checksum : %s\n", buf
);
455 snprintf(buf
, 16, "%d", asus_info
->revision
);
456 len
+= sprintf(page
+ len
, "DSDT revision : %s\n", buf
);
457 snprintf(buf
, 7, "%s", asus_info
->oem_id
);
458 len
+= sprintf(page
+ len
, "OEM id : %s\n", buf
);
459 snprintf(buf
, 9, "%s", asus_info
->oem_table_id
);
460 len
+= sprintf(page
+ len
, "OEM table id : %s\n", buf
);
461 snprintf(buf
, 16, "%x", asus_info
->oem_revision
);
462 len
+= sprintf(page
+ len
, "OEM revision : 0x%s\n", buf
);
463 snprintf(buf
, 5, "%s", asus_info
->asl_compiler_id
);
464 len
+= sprintf(page
+ len
, "ASL comp vendor id : %s\n", buf
);
465 snprintf(buf
, 16, "%x", asus_info
->asl_compiler_revision
);
466 len
+= sprintf(page
+ len
, "ASL comp revision : 0x%s\n", buf
);
474 * We write our info in page, we begin at offset off and cannot write more
475 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
476 * number of bytes written in page
479 /* Generic LED functions */
480 static int read_led(const char *ledname
, int ledmask
)
485 if (read_acpi_int(NULL
, ledname
, &led_status
))
488 printk(KERN_WARNING
"Asus ACPI: Error reading LED "
491 return (hotk
->status
& ledmask
) ? 1 : 0;
494 static int parse_arg(const char __user
* buf
, unsigned long count
, int *val
)
501 if (copy_from_user(s
, buf
, count
))
504 if (sscanf(s
, "%i", val
) != 1)
509 /* FIXME: kill extraneous args so it can be called independently */
511 write_led(const char __user
* buffer
, unsigned long count
,
512 char *ledname
, int ledmask
, int invert
)
517 count
= parse_arg(buffer
, count
, &value
);
519 led_out
= value
? 1 : 0;
522 (led_out
) ? (hotk
->status
| ledmask
) : (hotk
->status
& ~ledmask
);
524 if (invert
) /* invert target value */
525 led_out
= !led_out
& 0x1;
527 if (!write_acpi_int(hotk
->handle
, ledname
, led_out
, NULL
))
528 printk(KERN_WARNING
"Asus ACPI: LED (%s) write failed\n",
535 * Proc handlers for MLED
538 proc_read_mled(char *page
, char **start
, off_t off
, int count
, int *eof
,
541 return sprintf(page
, "%d\n",
542 read_led(hotk
->methods
->mled_status
, MLED_ON
));
546 proc_write_mled(struct file
*file
, const char __user
* buffer
,
547 unsigned long count
, void *data
)
549 return write_led(buffer
, count
, hotk
->methods
->mt_mled
, MLED_ON
, 1);
553 * Proc handlers for WLED
556 proc_read_wled(char *page
, char **start
, off_t off
, int count
, int *eof
,
559 return sprintf(page
, "%d\n",
560 read_led(hotk
->methods
->wled_status
, WLED_ON
));
564 proc_write_wled(struct file
*file
, const char __user
* buffer
,
565 unsigned long count
, void *data
)
567 return write_led(buffer
, count
, hotk
->methods
->mt_wled
, WLED_ON
, 0);
571 * Proc handlers for TLED
574 proc_read_tled(char *page
, char **start
, off_t off
, int count
, int *eof
,
577 return sprintf(page
, "%d\n",
578 read_led(hotk
->methods
->tled_status
, TLED_ON
));
582 proc_write_tled(struct file
*file
, const char __user
* buffer
,
583 unsigned long count
, void *data
)
585 return write_led(buffer
, count
, hotk
->methods
->mt_tled
, TLED_ON
, 0);
588 static int get_lcd_state(void)
592 if (hotk
->model
!= L3H
) {
593 /* We don't have to check anything if we are here */
594 if (!read_acpi_int(NULL
, hotk
->methods
->lcd_status
, &lcd
))
596 "Asus ACPI: Error reading LCD status\n");
598 if (hotk
->model
== L2D
)
600 } else { /* L3H and the like have to be handled differently */
601 acpi_status status
= 0;
602 struct acpi_object_list input
;
603 union acpi_object mt_params
[2];
604 struct acpi_buffer output
;
605 union acpi_object out_obj
;
608 input
.pointer
= mt_params
;
609 /* Note: the following values are partly guessed up, but
610 otherwise they seem to work */
611 mt_params
[0].type
= ACPI_TYPE_INTEGER
;
612 mt_params
[0].integer
.value
= 0x02;
613 mt_params
[1].type
= ACPI_TYPE_INTEGER
;
614 mt_params
[1].integer
.value
= 0x02;
616 output
.length
= sizeof(out_obj
);
617 output
.pointer
= &out_obj
;
620 acpi_evaluate_object(NULL
, hotk
->methods
->lcd_status
,
624 if (out_obj
.type
== ACPI_TYPE_INTEGER
)
625 /* That's what the AML code does */
626 lcd
= out_obj
.integer
.value
>> 8;
632 static int set_lcd_state(int value
)
635 acpi_status status
= 0;
638 if (lcd
!= get_lcd_state()) {
640 if (hotk
->model
!= L3H
) {
642 acpi_evaluate_object(NULL
,
643 hotk
->methods
->mt_lcd_switch
,
645 } else { /* L3H and the like have to be handled differently */
647 (hotk
->handle
, hotk
->methods
->mt_lcd_switch
, 0x07,
650 /* L3H's AML executes EHK (0x07) upon Fn+F7 keypress,
651 the exact behaviour is simulated here */
653 if (ACPI_FAILURE(status
))
654 printk(KERN_WARNING
"Asus ACPI: Error switching LCD\n");
661 proc_read_lcd(char *page
, char **start
, off_t off
, int count
, int *eof
,
664 return sprintf(page
, "%d\n", get_lcd_state());
668 proc_write_lcd(struct file
*file
, const char __user
* buffer
,
669 unsigned long count
, void *data
)
673 count
= parse_arg(buffer
, count
, &value
);
675 set_lcd_state(value
);
679 static int read_brightness(void)
683 if (hotk
->methods
->brightness_get
) { /* SPLV/GPLV laptop */
684 if (!read_acpi_int(hotk
->handle
, hotk
->methods
->brightness_get
,
687 "Asus ACPI: Error reading brightness\n");
688 } else if (hotk
->methods
->brightness_status
) { /* For D1 for example */
689 if (!read_acpi_int(NULL
, hotk
->methods
->brightness_status
,
692 "Asus ACPI: Error reading brightness\n");
693 } else /* No GPLV method */
694 value
= hotk
->brightness
;
699 * Change the brightness level
701 static void set_brightness(int value
)
703 acpi_status status
= 0;
706 if (hotk
->methods
->brightness_set
) {
707 if (!write_acpi_int(hotk
->handle
, hotk
->methods
->brightness_set
,
710 "Asus ACPI: Error changing brightness\n");
714 /* No SPLV method if we are here, act as appropriate */
715 value
-= read_brightness();
717 status
= acpi_evaluate_object(NULL
, (value
> 0) ?
718 hotk
->methods
->brightness_up
:
719 hotk
->methods
->brightness_down
,
721 (value
> 0) ? value
-- : value
++;
722 if (ACPI_FAILURE(status
))
724 "Asus ACPI: Error changing brightness\n");
730 proc_read_brn(char *page
, char **start
, off_t off
, int count
, int *eof
,
733 return sprintf(page
, "%d\n", read_brightness());
737 proc_write_brn(struct file
*file
, const char __user
* buffer
,
738 unsigned long count
, void *data
)
742 count
= parse_arg(buffer
, count
, &value
);
744 value
= (0 < value
) ? ((15 < value
) ? 15 : value
) : 0;
745 /* 0 <= value <= 15 */
746 set_brightness(value
);
747 } else if (count
< 0) {
748 printk(KERN_WARNING
"Asus ACPI: Error reading user input\n");
754 static void set_display(int value
)
756 /* no sanity check needed for now */
757 if (!write_acpi_int(hotk
->handle
, hotk
->methods
->display_set
,
759 printk(KERN_WARNING
"Asus ACPI: Error setting display\n");
764 * Now, *this* one could be more user-friendly, but so far, no-one has
765 * complained. The significance of bits is the same as in proc_write_disp()
768 proc_read_disp(char *page
, char **start
, off_t off
, int count
, int *eof
,
773 if (!read_acpi_int(hotk
->handle
, hotk
->methods
->display_get
, &value
))
775 "Asus ACPI: Error reading display status\n");
776 value
&= 0x07; /* needed for some models, shouldn't hurt others */
777 return sprintf(page
, "%d\n", value
);
781 * Experimental support for display switching. As of now: 1 should activate
782 * the LCD output, 2 should do for CRT, and 4 for TV-Out. Any combination
783 * (bitwise) of these will suffice. I never actually tested 3 displays hooked up
784 * simultaneously, so be warned. See the acpi4asus README for more info.
787 proc_write_disp(struct file
*file
, const char __user
* buffer
,
788 unsigned long count
, void *data
)
792 count
= parse_arg(buffer
, count
, &value
);
796 printk(KERN_WARNING
"Asus ACPI: Error reading user input\n");
801 typedef int (proc_readfunc
) (char *page
, char **start
, off_t off
, int count
,
802 int *eof
, void *data
);
803 typedef int (proc_writefunc
) (struct file
* file
, const char __user
* buffer
,
804 unsigned long count
, void *data
);
807 asus_proc_add(char *name
, proc_writefunc
* writefunc
,
808 proc_readfunc
* readfunc
, mode_t mode
,
809 struct acpi_device
*device
)
811 struct proc_dir_entry
*proc
=
812 create_proc_entry(name
, mode
, acpi_device_dir(device
));
814 printk(KERN_WARNING
" Unable to create %s fs entry\n", name
);
817 proc
->write_proc
= writefunc
;
818 proc
->read_proc
= readfunc
;
819 proc
->data
= acpi_driver_data(device
);
820 proc
->owner
= THIS_MODULE
;
821 proc
->uid
= asus_uid
;
822 proc
->gid
= asus_gid
;
826 static int asus_hotk_add_fs(struct acpi_device
*device
)
828 struct proc_dir_entry
*proc
;
832 * If parameter uid or gid is not changed, keep the default setting for
833 * our proc entries (-rw-rw-rw-) else, it means we care about security,
834 * and then set to -rw-rw----
837 if ((asus_uid
== 0) && (asus_gid
== 0)) {
838 mode
= S_IFREG
| S_IRUGO
| S_IWUGO
;
840 mode
= S_IFREG
| S_IRUSR
| S_IRGRP
| S_IWUSR
| S_IWGRP
;
841 printk(KERN_WARNING
" asus_uid and asus_gid parameters are "
842 "deprecated, use chown and chmod instead!\n");
845 acpi_device_dir(device
) = asus_proc_dir
;
846 if (!acpi_device_dir(device
))
849 proc
= create_proc_entry(PROC_INFO
, mode
, acpi_device_dir(device
));
851 proc
->read_proc
= proc_read_info
;
852 proc
->data
= acpi_driver_data(device
);
853 proc
->owner
= THIS_MODULE
;
854 proc
->uid
= asus_uid
;
855 proc
->gid
= asus_gid
;
857 printk(KERN_WARNING
" Unable to create " PROC_INFO
861 if (hotk
->methods
->mt_wled
) {
862 asus_proc_add(PROC_WLED
, &proc_write_wled
, &proc_read_wled
,
866 if (hotk
->methods
->mt_mled
) {
867 asus_proc_add(PROC_MLED
, &proc_write_mled
, &proc_read_mled
,
871 if (hotk
->methods
->mt_tled
) {
872 asus_proc_add(PROC_TLED
, &proc_write_tled
, &proc_read_tled
,
877 * We need both read node and write method as LCD switch is also accessible
880 if (hotk
->methods
->mt_lcd_switch
&& hotk
->methods
->lcd_status
) {
881 asus_proc_add(PROC_LCD
, &proc_write_lcd
, &proc_read_lcd
, mode
,
885 if ((hotk
->methods
->brightness_up
&& hotk
->methods
->brightness_down
) ||
886 (hotk
->methods
->brightness_get
&& hotk
->methods
->brightness_set
)) {
887 asus_proc_add(PROC_BRN
, &proc_write_brn
, &proc_read_brn
, mode
,
891 if (hotk
->methods
->display_set
) {
892 asus_proc_add(PROC_DISP
, &proc_write_disp
, &proc_read_disp
,
899 static int asus_hotk_remove_fs(struct acpi_device
*device
)
901 if (acpi_device_dir(device
)) {
902 remove_proc_entry(PROC_INFO
, acpi_device_dir(device
));
903 if (hotk
->methods
->mt_wled
)
904 remove_proc_entry(PROC_WLED
, acpi_device_dir(device
));
905 if (hotk
->methods
->mt_mled
)
906 remove_proc_entry(PROC_MLED
, acpi_device_dir(device
));
907 if (hotk
->methods
->mt_tled
)
908 remove_proc_entry(PROC_TLED
, acpi_device_dir(device
));
909 if (hotk
->methods
->mt_lcd_switch
&& hotk
->methods
->lcd_status
)
910 remove_proc_entry(PROC_LCD
, acpi_device_dir(device
));
911 if ((hotk
->methods
->brightness_up
912 && hotk
->methods
->brightness_down
)
913 || (hotk
->methods
->brightness_get
914 && hotk
->methods
->brightness_set
))
915 remove_proc_entry(PROC_BRN
, acpi_device_dir(device
));
916 if (hotk
->methods
->display_set
)
917 remove_proc_entry(PROC_DISP
, acpi_device_dir(device
));
922 static void asus_hotk_notify(acpi_handle handle
, u32 event
, void *data
)
924 /* TODO Find a better way to handle events count. */
928 if ((event
& ~((u32
) BR_UP
)) < 16) {
929 hotk
->brightness
= (event
& ~((u32
) BR_UP
));
930 } else if ((event
& ~((u32
) BR_DOWN
)) < 16) {
931 hotk
->brightness
= (event
& ~((u32
) BR_DOWN
));
934 acpi_bus_generate_event(hotk
->device
, event
,
935 hotk
->event_count
[event
% 128]++);
941 * This function is used to initialize the hotk with right values. In this
942 * method, we can make all the detection we want, and modify the hotk struct
944 static int asus_hotk_get_info(void)
946 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
947 struct acpi_buffer dsdt
= { ACPI_ALLOCATE_BUFFER
, NULL
};
948 union acpi_object
*model
= NULL
;
953 * Get DSDT headers early enough to allow for differentiating between
954 * models, but late enough to allow acpi_bus_register_driver() to fail
955 * before doing anything ACPI-specific. Should we encounter a machine,
956 * which needs special handling (i.e. its hotkey device has a different
957 * HID), this bit will be moved. A global variable asus_info contains
960 status
= acpi_get_table(ACPI_TABLE_ID_DSDT
, 1, &dsdt
);
961 if (ACPI_FAILURE(status
))
962 printk(KERN_WARNING
" Couldn't get the DSDT table header\n");
964 asus_info
= (struct acpi_table_header
*)dsdt
.pointer
;
966 /* We have to write 0 on init this far for all ASUS models */
967 if (!write_acpi_int(hotk
->handle
, "INIT", 0, &buffer
)) {
968 printk(KERN_ERR
" Hotkey initialization failed\n");
972 /* This needs to be called for some laptops to init properly */
973 if (!read_acpi_int(hotk
->handle
, "BSTS", &bsts_result
))
974 printk(KERN_WARNING
" Error calling BSTS\n");
975 else if (bsts_result
)
976 printk(KERN_NOTICE
" BSTS called, 0x%02x returned\n",
979 /* This is unlikely with implicit return */
980 if (buffer
.pointer
== NULL
)
983 model
= (union acpi_object
*)buffer
.pointer
;
985 * Samsung P30 has a device with a valid _HID whose INIT does not
986 * return anything. It used to be possible to catch this exception,
987 * but the implicit return code will now happily confuse the
988 * driver. We assume that every ACPI_TYPE_STRING is a valid model
989 * identifier but it's still possible to get completely bogus data.
991 if (model
->type
== ACPI_TYPE_STRING
) {
992 printk(KERN_NOTICE
" %s model detected, ",
993 model
->string
.pointer
);
995 if (asus_info
&& /* Samsung P30 */
996 strncmp(asus_info
->oem_table_id
, "ODEM", 4) == 0) {
999 " 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
];
1013 hotk
->model
= END_MODEL
;
1014 if (strncmp(model
->string
.pointer
, "L3D", 3) == 0)
1016 else if (strncmp(model
->string
.pointer
, "L3H", 3) == 0 ||
1017 strncmp(model
->string
.pointer
, "L2E", 3) == 0)
1019 else if (strncmp(model
->string
.pointer
, "L3", 2) == 0 ||
1020 strncmp(model
->string
.pointer
, "L2B", 3) == 0)
1022 else if (strncmp(model
->string
.pointer
, "L8L", 3) == 0)
1024 else if (strncmp(model
->string
.pointer
, "L4R", 3) == 0)
1026 else if (strncmp(model
->string
.pointer
, "M6N", 3) == 0)
1028 else if (strncmp(model
->string
.pointer
, "M6R", 3) == 0 ||
1029 strncmp(model
->string
.pointer
, "A3G", 3) == 0)
1031 else if (strncmp(model
->string
.pointer
, "M2N", 3) == 0 ||
1032 strncmp(model
->string
.pointer
, "M3N", 3) == 0 ||
1033 strncmp(model
->string
.pointer
, "M5N", 3) == 0 ||
1034 strncmp(model
->string
.pointer
, "M6N", 3) == 0 ||
1035 strncmp(model
->string
.pointer
, "S1N", 3) == 0 ||
1036 strncmp(model
->string
.pointer
, "S5N", 3) == 0 ||
1037 strncmp(model
->string
.pointer
, "W1N", 3) == 0)
1039 else if (strncmp(model
->string
.pointer
, "M1", 2) == 0)
1041 else if (strncmp(model
->string
.pointer
, "M2", 2) == 0 ||
1042 strncmp(model
->string
.pointer
, "L4E", 3) == 0)
1044 else if (strncmp(model
->string
.pointer
, "L2", 2) == 0)
1046 else if (strncmp(model
->string
.pointer
, "L8", 2) == 0)
1048 else if (strncmp(model
->string
.pointer
, "D1", 2) == 0)
1050 else if (strncmp(model
->string
.pointer
, "A1", 2) == 0)
1052 else if (strncmp(model
->string
.pointer
, "A2", 2) == 0)
1054 else if (strncmp(model
->string
.pointer
, "J1", 2) == 0)
1056 else if (strncmp(model
->string
.pointer
, "L5", 2) == 0)
1059 if (hotk
->model
== END_MODEL
) {
1060 printk("unsupported, trying default values, supply the "
1061 "developers with your DSDT\n");
1064 printk("supported\n");
1067 hotk
->methods
= &model_conf
[hotk
->model
];
1069 /* Sort of per-model blacklist */
1070 if (strncmp(model
->string
.pointer
, "L2B", 3) == 0)
1071 hotk
->methods
->lcd_status
= NULL
;
1072 /* L2B is similar enough to L3C to use its settings, with this only
1074 else if (strncmp(model
->string
.pointer
, "A3G", 3) == 0)
1075 hotk
->methods
->lcd_status
= "\\BLFG";
1076 /* A3G is like M6R */
1077 else if (strncmp(model
->string
.pointer
, "S5N", 3) == 0 ||
1078 strncmp(model
->string
.pointer
, "M5N", 3) == 0)
1079 hotk
->methods
->mt_mled
= NULL
;
1080 /* S5N and M5N have no MLED */
1081 else if (strncmp(model
->string
.pointer
, "M2N", 3) == 0 ||
1082 strncmp(model
->string
.pointer
, "W1N", 3) == 0)
1083 hotk
->methods
->mt_wled
= "WLED";
1084 /* M2N and W1N have a usable WLED */
1085 else if (asus_info
) {
1086 if (strncmp(asus_info
->oem_table_id
, "L1", 2) == 0)
1087 hotk
->methods
->mled_status
= NULL
;
1088 /* S1300A reports L84F, but L1400B too, account for that */
1096 static int asus_hotk_check(void)
1100 result
= acpi_bus_get_status(hotk
->device
);
1104 if (hotk
->device
->status
.present
) {
1105 result
= asus_hotk_get_info();
1107 printk(KERN_ERR
" Hotkey device not present, aborting\n");
1114 static int asus_hotk_found
;
1116 static int asus_hotk_add(struct acpi_device
*device
)
1118 acpi_status status
= AE_OK
;
1124 printk(KERN_NOTICE
"Asus Laptop ACPI Extras version %s\n",
1128 (struct asus_hotk
*)kmalloc(sizeof(struct asus_hotk
), GFP_KERNEL
);
1131 memset(hotk
, 0, sizeof(struct asus_hotk
));
1133 hotk
->handle
= device
->handle
;
1134 strcpy(acpi_device_name(device
), ACPI_HOTK_DEVICE_NAME
);
1135 strcpy(acpi_device_class(device
), ACPI_HOTK_CLASS
);
1136 acpi_driver_data(device
) = hotk
;
1137 hotk
->device
= device
;
1139 result
= asus_hotk_check();
1143 result
= asus_hotk_add_fs(device
);
1148 * We install the handler, it will receive the hotk in parameter, so, we
1149 * could add other data to the hotk struct
1151 status
= acpi_install_notify_handler(hotk
->handle
, ACPI_SYSTEM_NOTIFY
,
1152 asus_hotk_notify
, hotk
);
1153 if (ACPI_FAILURE(status
))
1154 printk(KERN_ERR
" Error installing notify handler\n");
1156 /* For laptops without GPLV: init the hotk->brightness value */
1157 if ((!hotk
->methods
->brightness_get
)
1158 && (!hotk
->methods
->brightness_status
)
1159 && (hotk
->methods
->brightness_up
&& hotk
->methods
->brightness_down
)) {
1161 acpi_evaluate_object(NULL
, hotk
->methods
->brightness_down
,
1163 if (ACPI_FAILURE(status
))
1164 printk(KERN_WARNING
" Error changing brightness\n");
1167 acpi_evaluate_object(NULL
,
1168 hotk
->methods
->brightness_up
,
1170 if (ACPI_FAILURE(status
))
1171 printk(KERN_WARNING
" Strange, error changing"
1176 asus_hotk_found
= 1;
1186 static int asus_hotk_remove(struct acpi_device
*device
, int type
)
1188 acpi_status status
= 0;
1190 if (!device
|| !acpi_driver_data(device
))
1193 status
= acpi_remove_notify_handler(hotk
->handle
, ACPI_SYSTEM_NOTIFY
,
1195 if (ACPI_FAILURE(status
))
1196 printk(KERN_ERR
"Asus ACPI: Error removing notify handler\n");
1198 asus_hotk_remove_fs(device
);
1205 static int __init
asus_acpi_init(void)
1212 if (!acpi_specific_hotkey_enabled
) {
1213 printk(KERN_ERR
"Using generic hotkey driver\n");
1216 asus_proc_dir
= proc_mkdir(PROC_ASUS
, acpi_root_dir
);
1217 if (!asus_proc_dir
) {
1218 printk(KERN_ERR
"Asus ACPI: Unable to create /proc entry\n");
1221 asus_proc_dir
->owner
= THIS_MODULE
;
1223 result
= acpi_bus_register_driver(&asus_hotk_driver
);
1225 remove_proc_entry(PROC_ASUS
, acpi_root_dir
);
1230 * This is a bit of a kludge. We only want this module loaded
1231 * for ASUS systems, but there's currently no way to probe the
1232 * ACPI namespace for ASUS HIDs. So we just return failure if
1233 * we didn't find one, which will cause the module to be
1236 if (!asus_hotk_found
) {
1237 acpi_bus_unregister_driver(&asus_hotk_driver
);
1238 remove_proc_entry(PROC_ASUS
, acpi_root_dir
);
1245 static void __exit
asus_acpi_exit(void)
1247 acpi_bus_unregister_driver(&asus_hotk_driver
);
1248 remove_proc_entry(PROC_ASUS
, acpi_root_dir
);
1255 module_init(asus_acpi_init
);
1256 module_exit(asus_acpi_exit
);