]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/acpi/asus_acpi.c
ACPI: asus_acpi: rework model detection
[linux-2.6-omap-h63xx.git] / drivers / acpi / asus_acpi.c
1 /*
2  *  asus_acpi.c - Asus Laptop ACPI Extras
3  *
4  *
5  *  Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor
6  *
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.
11  *
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.
16  *
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
20  *
21  *
22  *  The development page for this driver is located at
23  *  http://sourceforge.net/projects/acpi4asus/
24  *
25  *  Credits:
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
30  *
31  */
32
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>
41
42 #define ASUS_ACPI_VERSION "0.30"
43
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"
54
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"
59
60 /*
61  * Some events we use, same for all Asus
62  */
63 #define BR_UP       0x10
64 #define BR_DOWN     0x20
65
66 /*
67  * Flags for hotk status
68  */
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
73
74 MODULE_AUTHOR("Julien Lerouge, Karol Kozimor");
75 MODULE_DESCRIPTION(ACPI_HOTK_NAME);
76 MODULE_LICENSE("GPL");
77
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");
84
85 /* For each model, all features implemented, 
86  * those marked with R are relative to HOTK, A for absolute */
87 struct model_data {
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
107 };
108
109 /*
110  * This is the main structure, we can use it to store anything interesting
111  * about the hotk device
112  */
113 struct asus_hotk {
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
120         enum {
121                 A1x = 0,        //A1340D, A1300F
122                 A2x,            //A2500H
123                 A4G,            //A4700G
124                 D1x,            //D1
125                 L2D,            //L2000D
126                 L3C,            //L3800C
127                 L3D,            //L3400D
128                 L3H,            //L3H, L2000E, L5D
129                 L4R,            //L4500R
130                 L5x,            //L5800C 
131                 L8L,            //L8400L
132                 M1A,            //M1300A
133                 M2E,            //M2400E, L4400L
134                 M6N,            //M6800N, W3400N
135                 M6R,            //M6700R, A3000G
136                 P30,            //Samsung P30
137                 S1x,            //S1300A, but also L1400B and M2400A (L84F)
138                 S2x,            //S200 (J1 reported), Victor MP-XP7210
139                 W1N,            //W1000N
140                 W5A,            //W5A
141                 xxN,            //M2400N, M3700N, M5200N, M6800N, S1300N, S5200N
142                 //(Centrino)
143                 END_MODEL
144         } model;                //Models currently supported
145         u16 event_count[128];   //count for each event TODO make this better
146 };
147
148 /* Here we go */
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."
156
157 static struct model_data model_conf[END_MODEL] = {
158         /*
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 ?
161          */
162
163         {
164          .name = "A1x",
165          .mt_mled = "MLED",
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"},
171
172         {
173          .name = "A2x",
174          .mt_mled = "MLED",
175          .mt_wled = "WLED",
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"},
183
184         {
185          .name = "A4G",
186          .mt_mled = "MLED",
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"},
193
194         {
195          .name = "D1x",
196          .mt_mled = "MLED",
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"},
204
205         {
206          .name = "L2D",
207          .mt_mled = "MLED",
208          .mled_status = "\\SGP6",
209          .mt_wled = "WLED",
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"},
217
218         {
219          .name = "L3C",
220          .mt_mled = "MLED",
221          .mt_wled = "WLED",
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"},
228
229         {
230          .name = "L3D",
231          .mt_mled = "MLED",
232          .mled_status = "\\MALD",
233          .mt_wled = "WLED",
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"},
240
241         {
242          .name = "L3H",
243          .mt_mled = "MLED",
244          .mt_wled = "WLED",
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"},
251
252         {
253          .name = "L4R",
254          .mt_mled = "MLED",
255          .mt_wled = "WLED",
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"},
263
264         {
265          .name = "L5x",
266          .mt_mled = "MLED",
267 /* WLED present, but not controlled by ACPI */
268          .mt_tled = "TLED",
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"},
275
276         {
277          .name = "L8L"
278 /* No features, but at least support the hotkeys */
279          },
280
281         {
282          .name = "M1A",
283          .mt_mled = "MLED",
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"},
291
292         {
293          .name = "M2E",
294          .mt_mled = "MLED",
295          .mt_wled = "WLED",
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"},
302
303         {
304          .name = "M6N",
305          .mt_mled = "MLED",
306          .mt_wled = "WLED",
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"},
314         {
315          .name = "M6R",
316          .mt_mled = "MLED",
317          .mt_wled = "WLED",
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"},
324
325         {
326          .name = "P30",
327          .mt_wled = "WLED",
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"},
335
336         {
337          .name = "S1x",
338          .mt_mled = "MLED",
339          .mled_status = "\\EMLE",
340          .mt_wled = "WLED",
341          .mt_lcd_switch = S1x_PREFIX "Q10",
342          .lcd_status = "\\PNOF",
343          .brightness_set = "SPLV",
344          .brightness_get = "GPLV"},
345
346         {
347          .name = "S2x",
348          .mt_mled = "MLED",
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"},
354
355         {
356          .name = "W1N",
357          .mt_mled = "MLED",
358          .mt_wled = "WLED",
359          .mt_ledd = "SLCM",
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"},
366
367         {
368          .name = "W5A",
369          .mt_bt_switch = "BLED",
370          .mt_wled = "WLED",
371          .mt_lcd_switch = xxN_PREFIX "_Q10",
372          .brightness_set = "SPLV",
373          .brightness_get = "GPLV",
374          .display_set = "SDSP",
375          .display_get = "\\ADVG"},
376
377         {
378          .name = "xxN",
379          .mt_mled = "MLED",
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"}
387 };
388
389 /* procdir we use */
390 static struct proc_dir_entry *asus_proc_dir;
391
392 /*
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
396  */
397 static struct acpi_table_header *asus_info;
398
399 /* The actual device the driver binds to */
400 static struct asus_hotk *hotk;
401
402 /*
403  * The hotkey driver declaration
404  */
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,
411         .ops = {
412                 .add = asus_hotk_add,
413                 .remove = asus_hotk_remove,
414                 },
415 };
416
417 /* 
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
421  *
422  * returns 1 if write is successful, 0 else. 
423  */
424 static int write_acpi_int(acpi_handle handle, const char *method, int val,
425                           struct acpi_buffer *output)
426 {
427         struct acpi_object_list params; //list of input parameters (an int here)
428         union acpi_object in_obj;       //the only param we use
429         acpi_status status;
430
431         params.count = 1;
432         params.pointer = &in_obj;
433         in_obj.type = ACPI_TYPE_INTEGER;
434         in_obj.integer.value = val;
435
436         status = acpi_evaluate_object(handle, (char *)method, &params, output);
437         return (status == AE_OK);
438 }
439
440 static int read_acpi_int(acpi_handle handle, const char *method, int *val)
441 {
442         struct acpi_buffer output;
443         union acpi_object out_obj;
444         acpi_status status;
445
446         output.length = sizeof(out_obj);
447         output.pointer = &out_obj;
448
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);
452 }
453
454 /*
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
458  */
459 static int
460 proc_read_info(char *page, char **start, off_t off, int count, int *eof,
461                void *data)
462 {
463         int len = 0;
464         int temp;
465         char buf[16];           //enough for all info
466         /*
467          * We use the easy way, we don't care of off and count, so we don't set eof
468          * to 1
469          */
470
471         len += sprintf(page, ACPI_HOTK_NAME " " ASUS_ACPI_VERSION "\n");
472         len += sprintf(page + len, "Model reference    : %s\n",
473                        hotk->methods->name);
474         /* 
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.
479          */
480         if (read_acpi_int(hotk->handle, "SFUN", &temp))
481                 len +=
482                     sprintf(page + len, "SFUN value         : 0x%04x\n", temp);
483         /*
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
488          * silently ignored.
489          */
490         if (read_acpi_int(hotk->handle, "ASYM", &temp))
491                 len +=
492                     sprintf(page + len, "ASYM value         : 0x%04x\n", temp);
493         if (asus_info) {
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);
510         }
511
512         return len;
513 }
514
515 /*
516  * /proc handlers
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
520  */
521
522 /* Generic LED functions */
523 static int read_led(const char *ledname, int ledmask)
524 {
525         if (ledname) {
526                 int led_status;
527
528                 if (read_acpi_int(NULL, ledname, &led_status))
529                         return led_status;
530                 else
531                         printk(KERN_WARNING "Asus ACPI: Error reading LED "
532                                "status\n");
533         }
534         return (hotk->status & ledmask) ? 1 : 0;
535 }
536
537 static int parse_arg(const char __user * buf, unsigned long count, int *val)
538 {
539         char s[32];
540         if (!count)
541                 return 0;
542         if (count > 31)
543                 return -EINVAL;
544         if (copy_from_user(s, buf, count))
545                 return -EFAULT;
546         s[count] = 0;
547         if (sscanf(s, "%i", val) != 1)
548                 return -EINVAL;
549         return count;
550 }
551
552 /* FIXME: kill extraneous args so it can be called independently */
553 static int
554 write_led(const char __user * buffer, unsigned long count,
555           char *ledname, int ledmask, int invert)
556 {
557         int value;
558         int led_out = 0;
559
560         count = parse_arg(buffer, count, &value);
561         if (count > 0)
562                 led_out = value ? 1 : 0;
563
564         hotk->status =
565             (led_out) ? (hotk->status | ledmask) : (hotk->status & ~ledmask);
566
567         if (invert)             /* invert target value */
568                 led_out = !led_out & 0x1;
569
570         if (!write_acpi_int(hotk->handle, ledname, led_out, NULL))
571                 printk(KERN_WARNING "Asus ACPI: LED (%s) write failed\n",
572                        ledname);
573
574         return count;
575 }
576
577 /*
578  * Proc handlers for MLED
579  */
580 static int
581 proc_read_mled(char *page, char **start, off_t off, int count, int *eof,
582                void *data)
583 {
584         return sprintf(page, "%d\n",
585                        read_led(hotk->methods->mled_status, MLED_ON));
586 }
587
588 static int
589 proc_write_mled(struct file *file, const char __user * buffer,
590                 unsigned long count, void *data)
591 {
592         return write_led(buffer, count, hotk->methods->mt_mled, MLED_ON, 1);
593 }
594
595 /*
596  * Proc handlers for LED display
597  */
598 static int
599 proc_read_ledd(char *page, char **start, off_t off, int count, int *eof,
600                void *data)
601 {
602         return sprintf(page, "0x%08x\n", hotk->ledd_status);
603 }
604
605 static int
606 proc_write_ledd(struct file *file, const char __user * buffer,
607                 unsigned long count, void *data)
608 {
609         int value;
610
611         count = parse_arg(buffer, count, &value);
612         if (count > 0) {
613                 if (!write_acpi_int
614                     (hotk->handle, hotk->methods->mt_ledd, value, NULL))
615                         printk(KERN_WARNING
616                                "Asus ACPI: LED display write failed\n");
617                 else
618                         hotk->ledd_status = (u32) value;
619         } else if (count < 0)
620                 printk(KERN_WARNING "Asus ACPI: Error reading user input\n");
621
622         return count;
623 }
624
625 /*
626  * Proc handlers for WLED
627  */
628 static int
629 proc_read_wled(char *page, char **start, off_t off, int count, int *eof,
630                void *data)
631 {
632         return sprintf(page, "%d\n",
633                        read_led(hotk->methods->wled_status, WLED_ON));
634 }
635
636 static int
637 proc_write_wled(struct file *file, const char __user * buffer,
638                 unsigned long count, void *data)
639 {
640         return write_led(buffer, count, hotk->methods->mt_wled, WLED_ON, 0);
641 }
642
643 /*
644  * Proc handlers for Bluetooth
645  */
646 static int
647 proc_read_bluetooth(char *page, char **start, off_t off, int count, int *eof,
648                     void *data)
649 {
650         return sprintf(page, "%d\n", read_led(hotk->methods->bt_status, BT_ON));
651 }
652
653 static int
654 proc_write_bluetooth(struct file *file, const char __user * buffer,
655                      unsigned long count, void *data)
656 {
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);
660 }
661
662 /*
663  * Proc handlers for TLED
664  */
665 static int
666 proc_read_tled(char *page, char **start, off_t off, int count, int *eof,
667                void *data)
668 {
669         return sprintf(page, "%d\n",
670                        read_led(hotk->methods->tled_status, TLED_ON));
671 }
672
673 static int
674 proc_write_tled(struct file *file, const char __user * buffer,
675                 unsigned long count, void *data)
676 {
677         return write_led(buffer, count, hotk->methods->mt_tled, TLED_ON, 0);
678 }
679
680 static int get_lcd_state(void)
681 {
682         int lcd = 0;
683
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))
687                         printk(KERN_WARNING
688                                "Asus ACPI: Error reading LCD status\n");
689
690                 if (hotk->model == L2D)
691                         lcd = ~lcd;
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;
698
699                 input.count = 2;
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;
707
708                 output.length = sizeof(out_obj);
709                 output.pointer = &out_obj;
710
711                 status =
712                     acpi_evaluate_object(NULL, hotk->methods->lcd_status,
713                                          &input, &output);
714                 if (status != AE_OK)
715                         return -1;
716                 if (out_obj.type == ACPI_TYPE_INTEGER)
717                         /* That's what the AML code does */
718                         lcd = out_obj.integer.value >> 8;
719         }
720
721         return (lcd & 1);
722 }
723
724 static int set_lcd_state(int value)
725 {
726         int lcd = 0;
727         acpi_status status = 0;
728
729         lcd = value ? 1 : 0;
730         if (lcd != get_lcd_state()) {
731                 /* switch */
732                 if (hotk->model != L3H) {
733                         status =
734                             acpi_evaluate_object(NULL,
735                                                  hotk->methods->mt_lcd_switch,
736                                                  NULL, NULL);
737                 } else {        /* L3H and the like have to be handled differently */
738                         if (!write_acpi_int
739                             (hotk->handle, hotk->methods->mt_lcd_switch, 0x07,
740                              NULL))
741                                 status = AE_ERROR;
742                         /* L3H's AML executes EHK (0x07) upon Fn+F7 keypress, 
743                            the exact behaviour is simulated here */
744                 }
745                 if (ACPI_FAILURE(status))
746                         printk(KERN_WARNING "Asus ACPI: Error switching LCD\n");
747         }
748         return 0;
749
750 }
751
752 static int
753 proc_read_lcd(char *page, char **start, off_t off, int count, int *eof,
754               void *data)
755 {
756         return sprintf(page, "%d\n", get_lcd_state());
757 }
758
759 static int
760 proc_write_lcd(struct file *file, const char __user * buffer,
761                unsigned long count, void *data)
762 {
763         int value;
764
765         count = parse_arg(buffer, count, &value);
766         if (count > 0)
767                 set_lcd_state(value);
768         return count;
769 }
770
771 static int read_brightness(void)
772 {
773         int value;
774
775         if (hotk->methods->brightness_get) {    /* SPLV/GPLV laptop */
776                 if (!read_acpi_int(hotk->handle, hotk->methods->brightness_get,
777                                    &value))
778                         printk(KERN_WARNING
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,
782                                    &value))
783                         printk(KERN_WARNING
784                                "Asus ACPI: Error reading brightness\n");
785         } else                  /* No GPLV method */
786                 value = hotk->brightness;
787         return value;
788 }
789
790 /*
791  * Change the brightness level
792  */
793 static void set_brightness(int value)
794 {
795         acpi_status status = 0;
796
797         /* SPLV laptop */
798         if (hotk->methods->brightness_set) {
799                 if (!write_acpi_int(hotk->handle, hotk->methods->brightness_set,
800                                     value, NULL))
801                         printk(KERN_WARNING
802                                "Asus ACPI: Error changing brightness\n");
803                 return;
804         }
805
806         /* No SPLV method if we are here, act as appropriate */
807         value -= read_brightness();
808         while (value != 0) {
809                 status = acpi_evaluate_object(NULL, (value > 0) ?
810                                               hotk->methods->brightness_up :
811                                               hotk->methods->brightness_down,
812                                               NULL, NULL);
813                 (value > 0) ? value-- : value++;
814                 if (ACPI_FAILURE(status))
815                         printk(KERN_WARNING
816                                "Asus ACPI: Error changing brightness\n");
817         }
818         return;
819 }
820
821 static int
822 proc_read_brn(char *page, char **start, off_t off, int count, int *eof,
823               void *data)
824 {
825         return sprintf(page, "%d\n", read_brightness());
826 }
827
828 static int
829 proc_write_brn(struct file *file, const char __user * buffer,
830                unsigned long count, void *data)
831 {
832         int value;
833
834         count = parse_arg(buffer, count, &value);
835         if (count > 0) {
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");
841         }
842
843         return count;
844 }
845
846 static void set_display(int value)
847 {
848         /* no sanity check needed for now */
849         if (!write_acpi_int(hotk->handle, hotk->methods->display_set,
850                             value, NULL))
851                 printk(KERN_WARNING "Asus ACPI: Error setting display\n");
852         return;
853 }
854
855 /*
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()
858  */
859 static int
860 proc_read_disp(char *page, char **start, off_t off, int count, int *eof,
861                void *data)
862 {
863         int value = 0;
864
865         if (!read_acpi_int(hotk->handle, hotk->methods->display_get, &value))
866                 printk(KERN_WARNING
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);
870 }
871
872 /*
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.
877  */
878 static int
879 proc_write_disp(struct file *file, const char __user * buffer,
880                 unsigned long count, void *data)
881 {
882         int value;
883
884         count = parse_arg(buffer, count, &value);
885         if (count > 0)
886                 set_display(value);
887         else if (count < 0)
888                 printk(KERN_WARNING "Asus ACPI: Error reading user input\n");
889
890         return count;
891 }
892
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);
897
898 static int
899 asus_proc_add(char *name, proc_writefunc * writefunc,
900                      proc_readfunc * readfunc, mode_t mode,
901                      struct acpi_device *device)
902 {
903         struct proc_dir_entry *proc =
904             create_proc_entry(name, mode, acpi_device_dir(device));
905         if (!proc) {
906                 printk(KERN_WARNING "  Unable to create %s fs entry\n", name);
907                 return -1;
908         }
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;
915         return 0;
916 }
917
918 static int asus_hotk_add_fs(struct acpi_device *device)
919 {
920         struct proc_dir_entry *proc;
921         mode_t mode;
922
923         /*
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----
927          */
928
929         if ((asus_uid == 0) && (asus_gid == 0)) {
930                 mode = S_IFREG | S_IRUGO | S_IWUGO;
931         } else {
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");
935         }
936
937         acpi_device_dir(device) = asus_proc_dir;
938         if (!acpi_device_dir(device))
939                 return -ENODEV;
940
941         proc = create_proc_entry(PROC_INFO, mode, acpi_device_dir(device));
942         if (proc) {
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;
948         } else {
949                 printk(KERN_WARNING "  Unable to create " PROC_INFO
950                        " fs entry\n");
951         }
952
953         if (hotk->methods->mt_wled) {
954                 asus_proc_add(PROC_WLED, &proc_write_wled, &proc_read_wled,
955                               mode, device);
956         }
957
958         if (hotk->methods->mt_ledd) {
959                 asus_proc_add(PROC_LEDD, &proc_write_ledd, &proc_read_ledd,
960                               mode, device);
961         }
962
963         if (hotk->methods->mt_mled) {
964                 asus_proc_add(PROC_MLED, &proc_write_mled, &proc_read_mled,
965                               mode, device);
966         }
967
968         if (hotk->methods->mt_tled) {
969                 asus_proc_add(PROC_TLED, &proc_write_tled, &proc_read_tled,
970                               mode, device);
971         }
972
973         if (hotk->methods->mt_bt_switch) {
974                 asus_proc_add(PROC_BT, &proc_write_bluetooth,
975                               &proc_read_bluetooth, mode, device);
976         }
977
978         /* 
979          * We need both read node and write method as LCD switch is also accessible
980          * from keyboard 
981          */
982         if (hotk->methods->mt_lcd_switch && hotk->methods->lcd_status) {
983                 asus_proc_add(PROC_LCD, &proc_write_lcd, &proc_read_lcd, mode,
984                               device);
985         }
986
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,
990                               device);
991         }
992
993         if (hotk->methods->display_set) {
994                 asus_proc_add(PROC_DISP, &proc_write_disp, &proc_read_disp,
995                               mode, device);
996         }
997
998         return 0;
999 }
1000
1001 static int asus_hotk_remove_fs(struct acpi_device *device)
1002 {
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));
1024         }
1025         return 0;
1026 }
1027
1028 static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
1029 {
1030         /* TODO Find a better way to handle events count. */
1031         if (!hotk)
1032                 return;
1033
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));
1038         }
1039
1040         acpi_bus_generate_event(hotk->device, event,
1041                                 hotk->event_count[event % 128]++);
1042
1043         return;
1044 }
1045
1046 /*
1047  * Match the model string to the list of supported models. Return END_MODEL if
1048  * no match or model is NULL.
1049  */
1050 static int asus_model_match(char *model)
1051 {
1052         if (model == NULL)
1053                 return END_MODEL;
1054
1055         if (strncmp(model, "L3D", 3) == 0)
1056                 return L3D;
1057         else if (strncmp(model, "L2E", 3) == 0 ||
1058                  strncmp(model, "L3H", 3) == 0 || strncmp(model, "L5D", 3) == 0)
1059                 return L3H;
1060         else if (strncmp(model, "L3", 2) == 0 || strncmp(model, "L2B", 3) == 0)
1061                 return L3C;
1062         else if (strncmp(model, "L8L", 3) == 0)
1063                 return L8L;
1064         else if (strncmp(model, "L4R", 3) == 0)
1065                 return L4R;
1066         else if (strncmp(model, "M6N", 3) == 0 || strncmp(model, "W3N", 3) == 0)
1067                 return M6N;
1068         else if (strncmp(model, "M6R", 3) == 0 || strncmp(model, "A3G", 3) == 0)
1069                 return M6R;
1070         else if (strncmp(model, "M2N", 3) == 0 ||
1071                  strncmp(model, "M3N", 3) == 0 ||
1072                  strncmp(model, "M5N", 3) == 0 ||
1073                  strncmp(model, "M6N", 3) == 0 ||
1074                  strncmp(model, "S1N", 3) == 0 ||
1075                  strncmp(model, "S5N", 3) == 0 || strncmp(model, "W1N", 3) == 0)
1076                 return xxN;
1077         else if (strncmp(model, "M1", 2) == 0)
1078                 return M1A;
1079         else if (strncmp(model, "M2", 2) == 0 || strncmp(model, "L4E", 3) == 0)
1080                 return M2E;
1081         else if (strncmp(model, "L2", 2) == 0)
1082                 return L2D;
1083         else if (strncmp(model, "L8", 2) == 0)
1084                 return S1x;
1085         else if (strncmp(model, "D1", 2) == 0)
1086                 return D1x;
1087         else if (strncmp(model, "A1", 2) == 0)
1088                 return A1x;
1089         else if (strncmp(model, "A2", 2) == 0)
1090                 return A2x;
1091         else if (strncmp(model, "J1", 2) == 0)
1092                 return S2x;
1093         else if (strncmp(model, "L5", 2) == 0)
1094                 return L5x;
1095         else if (strncmp(model, "A4G", 3) == 0)
1096                 return A4G;
1097         else if (strncmp(model, "W1N", 3) == 0)
1098                 return W1N;
1099         else if (strncmp(model, "W5A", 3) == 0)
1100                 return W5A;
1101         else
1102                 return END_MODEL;
1103 }
1104
1105 /*
1106  * This function is used to initialize the hotk with right values. In this
1107  * method, we can make all the detection we want, and modify the hotk struct
1108  */
1109 static int asus_hotk_get_info(void)
1110 {
1111         struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1112         struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL };
1113         union acpi_object *model = NULL;
1114         int bsts_result;
1115         char *string = NULL;
1116         acpi_status status;
1117
1118         /*
1119          * Get DSDT headers early enough to allow for differentiating between 
1120          * models, but late enough to allow acpi_bus_register_driver() to fail 
1121          * before doing anything ACPI-specific. Should we encounter a machine,
1122          * which needs special handling (i.e. its hotkey device has a different
1123          * HID), this bit will be moved. A global variable asus_info contains
1124          * the DSDT header.
1125          */
1126         status = acpi_get_table(ACPI_TABLE_ID_DSDT, 1, &dsdt);
1127         if (ACPI_FAILURE(status))
1128                 printk(KERN_WARNING "  Couldn't get the DSDT table header\n");
1129         else
1130                 asus_info = (struct acpi_table_header *)dsdt.pointer;
1131
1132         /* We have to write 0 on init this far for all ASUS models */
1133         if (!write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
1134                 printk(KERN_ERR "  Hotkey initialization failed\n");
1135                 return -ENODEV;
1136         }
1137
1138         /* This needs to be called for some laptops to init properly */
1139         if (!read_acpi_int(hotk->handle, "BSTS", &bsts_result))
1140                 printk(KERN_WARNING "  Error calling BSTS\n");
1141         else if (bsts_result)
1142                 printk(KERN_NOTICE "  BSTS called, 0x%02x returned\n",
1143                        bsts_result);
1144
1145         /*
1146          * Try to match the object returned by INIT to the specific model.
1147          * Handle every possible object (or the lack of thereof) the DSDT 
1148          * writers might throw at us. When in trouble, we pass NULL to 
1149          * asus_model_match() and try something completely different.
1150          */
1151         if (buffer.pointer) {
1152                 model = (union acpi_object *)buffer.pointer;
1153                 switch (model->type) {
1154                 case ACPI_TYPE_STRING:
1155                         string = model->string.pointer;
1156                         break;
1157                 case ACPI_TYPE_BUFFER:
1158                         string = model->buffer.pointer;
1159                         break;
1160                 default:
1161                         kfree(model);
1162                         break;
1163                 }
1164         }
1165         hotk->model = asus_model_match(string);
1166         if (hotk->model == END_MODEL) { /* match failed */
1167                 if (asus_info &&
1168                     strncmp(asus_info->oem_table_id, "ODEM", 4) == 0) {
1169                         hotk->model = P30;
1170                         printk(KERN_NOTICE
1171                                "  Samsung P30 detected, supported\n");
1172                 } else {
1173                         hotk->model = M2E;
1174                         printk(KERN_NOTICE "  unsupported model %s, trying "
1175                                "default values\n", string);
1176                         printk(KERN_NOTICE
1177                                "  send /proc/acpi/dsdt to the developers\n");
1178                 }
1179                 hotk->methods = &model_conf[hotk->model];
1180                 return AE_OK;
1181         }
1182         hotk->methods = &model_conf[hotk->model];
1183         printk(KERN_NOTICE "  %s model detected, supported\n", string);
1184
1185         /* Sort of per-model blacklist */
1186         if (strncmp(string, "L2B", 3) == 0)
1187                 hotk->methods->lcd_status = NULL;
1188         /* L2B is similar enough to L3C to use its settings, with this only 
1189            exception */
1190         else if (strncmp(string, "A3G", 3) == 0)
1191                 hotk->methods->lcd_status = "\\BLFG";
1192         /* A3G is like M6R */
1193         else if (strncmp(string, "S5N", 3) == 0 ||
1194                  strncmp(string, "M5N", 3) == 0 ||
1195                  strncmp(string, "W3N", 3) == 0)
1196                 hotk->methods->mt_mled = NULL;
1197         /* S5N, M5N and W3N have no MLED */
1198         else if (strncmp(string, "L5D", 3) == 0)
1199                 hotk->methods->mt_wled = NULL;
1200         /* L5D's WLED is not controlled by ACPI */
1201         else if (strncmp(string, "M2N", 3) == 0)
1202                 hotk->methods->mt_wled = "WLED";
1203         /* M2N has a usable WLED */
1204         else if (asus_info) {
1205                 if (strncmp(asus_info->oem_table_id, "L1", 2) == 0)
1206                         hotk->methods->mled_status = NULL;
1207                 /* S1300A reports L84F, but L1400B too, account for that */
1208         }
1209
1210         kfree(model);
1211
1212         return AE_OK;
1213 }
1214
1215 static int asus_hotk_check(void)
1216 {
1217         int result = 0;
1218
1219         result = acpi_bus_get_status(hotk->device);
1220         if (result)
1221                 return result;
1222
1223         if (hotk->device->status.present) {
1224                 result = asus_hotk_get_info();
1225         } else {
1226                 printk(KERN_ERR "  Hotkey device not present, aborting\n");
1227                 return -EINVAL;
1228         }
1229
1230         return result;
1231 }
1232
1233 static int asus_hotk_found;
1234
1235 static int asus_hotk_add(struct acpi_device *device)
1236 {
1237         acpi_status status = AE_OK;
1238         int result;
1239
1240         if (!device)
1241                 return -EINVAL;
1242
1243         printk(KERN_NOTICE "Asus Laptop ACPI Extras version %s\n",
1244                ASUS_ACPI_VERSION);
1245
1246         hotk =
1247             (struct asus_hotk *)kmalloc(sizeof(struct asus_hotk), GFP_KERNEL);
1248         if (!hotk)
1249                 return -ENOMEM;
1250         memset(hotk, 0, sizeof(struct asus_hotk));
1251
1252         hotk->handle = device->handle;
1253         strcpy(acpi_device_name(device), ACPI_HOTK_DEVICE_NAME);
1254         strcpy(acpi_device_class(device), ACPI_HOTK_CLASS);
1255         acpi_driver_data(device) = hotk;
1256         hotk->device = device;
1257
1258         result = asus_hotk_check();
1259         if (result)
1260                 goto end;
1261
1262         result = asus_hotk_add_fs(device);
1263         if (result)
1264                 goto end;
1265
1266         /*
1267          * We install the handler, it will receive the hotk in parameter, so, we
1268          * could add other data to the hotk struct
1269          */
1270         status = acpi_install_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
1271                                              asus_hotk_notify, hotk);
1272         if (ACPI_FAILURE(status))
1273                 printk(KERN_ERR "  Error installing notify handler\n");
1274
1275         /* For laptops without GPLV: init the hotk->brightness value */
1276         if ((!hotk->methods->brightness_get)
1277             && (!hotk->methods->brightness_status)
1278             && (hotk->methods->brightness_up && hotk->methods->brightness_down)) {
1279                 status =
1280                     acpi_evaluate_object(NULL, hotk->methods->brightness_down,
1281                                          NULL, NULL);
1282                 if (ACPI_FAILURE(status))
1283                         printk(KERN_WARNING "  Error changing brightness\n");
1284                 else {
1285                         status =
1286                             acpi_evaluate_object(NULL,
1287                                                  hotk->methods->brightness_up,
1288                                                  NULL, NULL);
1289                         if (ACPI_FAILURE(status))
1290                                 printk(KERN_WARNING "  Strange, error changing"
1291                                        " brightness\n");
1292                 }
1293         }
1294
1295         asus_hotk_found = 1;
1296
1297         /* LED display is off by default */
1298         hotk->ledd_status = 0xFFF;
1299
1300       end:
1301         if (result) {
1302                 kfree(hotk);
1303         }
1304
1305         return result;
1306 }
1307
1308 static int asus_hotk_remove(struct acpi_device *device, int type)
1309 {
1310         acpi_status status = 0;
1311
1312         if (!device || !acpi_driver_data(device))
1313                 return -EINVAL;
1314
1315         status = acpi_remove_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
1316                                             asus_hotk_notify);
1317         if (ACPI_FAILURE(status))
1318                 printk(KERN_ERR "Asus ACPI: Error removing notify handler\n");
1319
1320         asus_hotk_remove_fs(device);
1321
1322         kfree(hotk);
1323
1324         return 0;
1325 }
1326
1327 static int __init asus_acpi_init(void)
1328 {
1329         int result;
1330
1331         if (acpi_disabled)
1332                 return -ENODEV;
1333
1334         if (!acpi_specific_hotkey_enabled) {
1335                 printk(KERN_ERR "Using generic hotkey driver\n");
1336                 return -ENODEV;
1337         }
1338         asus_proc_dir = proc_mkdir(PROC_ASUS, acpi_root_dir);
1339         if (!asus_proc_dir) {
1340                 printk(KERN_ERR "Asus ACPI: Unable to create /proc entry\n");
1341                 return -ENODEV;
1342         }
1343         asus_proc_dir->owner = THIS_MODULE;
1344
1345         result = acpi_bus_register_driver(&asus_hotk_driver);
1346         if (result < 0) {
1347                 remove_proc_entry(PROC_ASUS, acpi_root_dir);
1348                 return result;
1349         }
1350
1351         /*
1352          * This is a bit of a kludge.  We only want this module loaded
1353          * for ASUS systems, but there's currently no way to probe the
1354          * ACPI namespace for ASUS HIDs.  So we just return failure if
1355          * we didn't find one, which will cause the module to be
1356          * unloaded.
1357          */
1358         if (!asus_hotk_found) {
1359                 acpi_bus_unregister_driver(&asus_hotk_driver);
1360                 remove_proc_entry(PROC_ASUS, acpi_root_dir);
1361                 return result;
1362         }
1363
1364         return 0;
1365 }
1366
1367 static void __exit asus_acpi_exit(void)
1368 {
1369         acpi_bus_unregister_driver(&asus_hotk_driver);
1370         remove_proc_entry(PROC_ASUS, acpi_root_dir);
1371
1372         kfree(asus_info);
1373
1374         return;
1375 }
1376
1377 module_init(asus_acpi_init);
1378 module_exit(asus_acpi_exit);