2 * ibm_acpi.c - IBM ThinkPad ACPI Extras
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
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 #define IBM_VERSION "0.12a"
27 * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels
28 * 2005-03-17 0.11 support for 600e, 770x
29 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
30 * support for 770e, G41
31 * G40 and G41 don't have a thinklight
32 * temperatures no longer experimental
33 * experimental brightness control
34 * experimental volume control
35 * experimental fan enable/disable
36 * 2005-01-16 0.10 fix module loading on R30, R31
37 * 2005-01-16 0.9 support for 570, R30, R31
38 * ultrabay support on A22p, A3x
39 * limit arg for cmos, led, beep, drop experimental status
40 * more capable led control on A21e, A22p, T20-22, X20
41 * experimental temperatures and fan speed
42 * experimental embedded controller register dump
43 * mark more functions as __init, drop incorrect __exit
45 * thanks to Henrik Brix Andersen <brix@gentoo.org>
46 * fix parameter passing on module loading
47 * thanks to Rusty Russell <rusty@rustcorp.com.au>
48 * thanks to Jim Radford <radford@blackbean.org>
49 * 2004-11-08 0.8 fix init error case, don't return from a macro
50 * thanks to Chris Wright <chrisw@osdl.org>
51 * 2004-10-23 0.7 fix module loading on A21e, A22p, T20, T21, X20
52 * fix led control on A21e
53 * 2004-10-19 0.6 use acpi_bus_register_driver() to claim HKEY device
54 * 2004-10-18 0.5 thinklight support on A21e, G40, R32, T20, T21, X20
55 * proc file format changed
56 * video_switch command
57 * experimental cmos control
58 * experimental led control
59 * experimental acpi sounds
60 * 2004-09-16 0.4 support for module parameters
61 * hotkey mask can be prefixed by 0x
62 * video output switching
63 * video expansion control
64 * ultrabay eject support
65 * removed lcd brightness/on/off control, didn't work
66 * 2004-08-17 0.3 support for R40
67 * lcd off, brightness control
69 * 2004-08-14 0.2 support for T series, X20
70 * bluetooth enable/disable
71 * hotkey events disabled by default
72 * removed fan control, currently useless
73 * 2004-08-09 0.1 initial release, support for X series
76 #include <linux/kernel.h>
77 #include <linux/module.h>
78 #include <linux/init.h>
79 #include <linux/types.h>
80 #include <linux/proc_fs.h>
81 #include <linux/backlight.h>
82 #include <asm/uaccess.h>
84 #include <acpi/acpi_drivers.h>
85 #include <acpi/acnamesp.h>
87 #define IBM_NAME "ibm"
88 #define IBM_DESC "IBM ThinkPad ACPI Extras"
89 #define IBM_FILE "ibm_acpi"
90 #define IBM_URL "http://ibm-acpi.sf.net/"
92 MODULE_AUTHOR("Borislav Deianov");
93 MODULE_DESCRIPTION(IBM_DESC
);
94 MODULE_VERSION(IBM_VERSION
);
95 MODULE_LICENSE("GPL");
97 #define IBM_DIR IBM_NAME
99 #define IBM_LOG IBM_FILE ": "
100 #define IBM_ERR KERN_ERR IBM_LOG
101 #define IBM_NOTICE KERN_NOTICE IBM_LOG
102 #define IBM_INFO KERN_INFO IBM_LOG
103 #define IBM_DEBUG KERN_DEBUG IBM_LOG
105 #define IBM_MAX_ACPI_ARGS 3
107 #define __unused __attribute__ ((unused))
109 static int experimental
;
110 module_param(experimental
, int, 0);
112 static acpi_handle root_handle
= NULL
;
114 #define IBM_HANDLE(object, parent, paths...) \
115 static acpi_handle object##_handle; \
116 static acpi_handle *object##_parent = &parent##_handle; \
117 static char *object##_path; \
118 static char *object##_paths[] = { paths }
121 * The following models are supported to various degrees:
123 * 570, 600e, 600x, 770e, 770x
124 * A20m, A21e, A21m, A21p, A22p, A30, A30p, A31, A31p
126 * R30, R31, R32, R40, R40e, R50, R50e, R50p, R51
127 * T20, T21, T22, T23, T30, T40, T40p, T41, T41p, T42, T42p, T43
128 * X20, X21, X22, X23, X24, X30, X31, X40
130 * The following models have no supported features:
134 * Still missing DSDTs for the following models:
142 IBM_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
143 "\\_SB.PCI.ISA.EC", /* 570 */
144 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
145 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
146 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
147 "\\_SB.PCI0.ICH3.EC0", /* R31 */
148 "\\_SB.PCI0.LPC.EC", /* all others */
151 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
152 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
153 "\\_SB.PCI0.VID0", /* 770e */
154 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
155 "\\_SB.PCI0.AGP.VID", /* all others */
158 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
160 IBM_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
161 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
162 "\\CMS", /* R40, R40e */
164 #ifdef CONFIG_ACPI_IBM_DOCK
165 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
166 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
167 "\\_SB.PCI0.PCI1.DOCK", /* all others */
168 "\\_SB.PCI.ISA.SLCE", /* 570 */
169 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
171 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
172 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
173 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
174 ); /* A21e, R30, R31 */
176 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
177 "_EJ0", /* all others */
178 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
180 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
181 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
184 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
188 /* don't list other alternatives as we install a notify handler on the 570 */
189 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
191 IBM_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
192 "^HKEY", /* R30, R31 */
193 "HKEY", /* all others */
196 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
197 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
199 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
200 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
201 "LED", /* all others */
204 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
205 IBM_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
206 IBM_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
207 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40 */
209 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
210 "\\FSPD", /* 600e/x, 770e, 770x */
213 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
214 "JFNS", /* 770x-JL */
217 #define IBM_HKEY_HID "IBM0068"
218 #define IBM_PCI_HID "PNP0A03"
225 struct acpi_driver
*driver
;
228 int (*read
) (char *);
229 int (*write
) (char *);
232 void (*notify
) (struct ibm_struct
*, u32
);
235 struct acpi_device
*device
;
237 int driver_registered
;
240 int notify_installed
;
245 static struct proc_dir_entry
*proc_dir
= NULL
;
247 static struct backlight_device
*ibm_backlight_device
;
249 #define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off")
250 #define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
251 #define strlencmp(a,b) (strncmp((a), (b), strlen(b)))
253 static int acpi_evalf(acpi_handle handle
,
254 void *res
, char *method
, char *fmt
, ...)
257 struct acpi_object_list params
;
258 union acpi_object in_objs
[IBM_MAX_ACPI_ARGS
];
259 struct acpi_buffer result
, *resultp
;
260 union acpi_object out_obj
;
268 printk(IBM_ERR
"acpi_evalf() called with empty format\n");
281 params
.pointer
= &in_objs
[0];
288 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
289 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
291 /* add more types as needed */
293 printk(IBM_ERR
"acpi_evalf() called "
294 "with invalid format character '%c'\n", c
);
300 if (res_type
!= 'v') {
301 result
.length
= sizeof(out_obj
);
302 result
.pointer
= &out_obj
;
307 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
312 *(int *)res
= out_obj
.integer
.value
;
313 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
316 success
= status
== AE_OK
;
318 /* add more types as needed */
320 printk(IBM_ERR
"acpi_evalf() called "
321 "with invalid format character '%c'\n", res_type
);
325 if (!success
&& !quiet
)
326 printk(IBM_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
327 method
, fmt0
, status
);
332 static void __unused
acpi_print_int(acpi_handle handle
, char *method
)
336 if (acpi_evalf(handle
, &i
, method
, "d"))
337 printk(IBM_INFO
"%s = 0x%x\n", method
, i
);
339 printk(IBM_ERR
"error calling %s\n", method
);
342 static char *next_cmd(char **cmds
)
347 while ((end
= strchr(start
, ',')) && end
== start
)
358 static int driver_init(void)
360 printk(IBM_INFO
"%s v%s\n", IBM_DESC
, IBM_VERSION
);
361 printk(IBM_INFO
"%s\n", IBM_URL
);
366 static int driver_read(char *p
)
370 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", IBM_DESC
);
371 len
+= sprintf(p
+ len
, "version:\t%s\n", IBM_VERSION
);
376 static int hotkey_supported
;
377 static int hotkey_mask_supported
;
378 static int hotkey_orig_status
;
379 static int hotkey_orig_mask
;
381 static int hotkey_get(int *status
, int *mask
)
383 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
386 if (hotkey_mask_supported
)
387 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
393 static int hotkey_set(int status
, int mask
)
397 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
400 if (hotkey_mask_supported
)
401 for (i
= 0; i
< 32; i
++) {
402 int bit
= ((1 << i
) & mask
) != 0;
403 if (!acpi_evalf(hkey_handle
,
404 NULL
, "MHKM", "vdd", i
+ 1, bit
))
411 static int hotkey_init(void)
413 /* hotkey not supported on 570 */
414 hotkey_supported
= hkey_handle
!= NULL
;
416 if (hotkey_supported
) {
417 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
418 A30, R30, R31, T20-22, X20-21, X22-24 */
419 hotkey_mask_supported
=
420 acpi_evalf(hkey_handle
, NULL
, "DHKN", "qv");
422 if (!hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
))
429 static int hotkey_read(char *p
)
434 if (!hotkey_supported
) {
435 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
439 if (!hotkey_get(&status
, &mask
))
442 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
443 if (hotkey_mask_supported
) {
444 len
+= sprintf(p
+ len
, "mask:\t\t0x%04x\n", mask
);
445 len
+= sprintf(p
+ len
,
446 "commands:\tenable, disable, reset, <mask>\n");
448 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
449 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
455 static int hotkey_write(char *buf
)
461 if (!hotkey_supported
)
464 if (!hotkey_get(&status
, &mask
))
467 while ((cmd
= next_cmd(&buf
))) {
468 if (strlencmp(cmd
, "enable") == 0) {
470 } else if (strlencmp(cmd
, "disable") == 0) {
472 } else if (strlencmp(cmd
, "reset") == 0) {
473 status
= hotkey_orig_status
;
474 mask
= hotkey_orig_mask
;
475 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
477 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
484 if (do_cmd
&& !hotkey_set(status
, mask
))
490 static void hotkey_exit(void)
492 if (hotkey_supported
)
493 hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
496 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
500 if (acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d"))
501 acpi_bus_generate_event(ibm
->device
, event
, hkey
);
503 printk(IBM_ERR
"unknown hotkey event %d\n", event
);
504 acpi_bus_generate_event(ibm
->device
, event
, 0);
508 static int bluetooth_supported
;
510 static int bluetooth_init(void)
512 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
513 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
514 bluetooth_supported
= hkey_handle
&&
515 acpi_evalf(hkey_handle
, NULL
, "GBDC", "qv");
520 static int bluetooth_status(void)
524 if (!bluetooth_supported
||
525 !acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
531 static int bluetooth_read(char *p
)
534 int status
= bluetooth_status();
536 if (!bluetooth_supported
)
537 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
538 else if (!(status
& 1))
539 len
+= sprintf(p
+ len
, "status:\t\tnot installed\n");
541 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 1));
542 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
548 static int bluetooth_write(char *buf
)
550 int status
= bluetooth_status();
554 if (!bluetooth_supported
)
557 while ((cmd
= next_cmd(&buf
))) {
558 if (strlencmp(cmd
, "enable") == 0) {
560 } else if (strlencmp(cmd
, "disable") == 0) {
567 if (do_cmd
&& !acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
573 static int wan_supported
;
575 static int wan_init(void)
577 wan_supported
= hkey_handle
&&
578 acpi_evalf(hkey_handle
, NULL
, "GWAN", "qv");
583 static int wan_status(void)
587 if (!wan_supported
|| !acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
593 static int wan_read(char *p
)
596 int status
= wan_status();
599 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
600 else if (!(status
& 1))
601 len
+= sprintf(p
+ len
, "status:\t\tnot installed\n");
603 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 1));
604 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
610 static int wan_write(char *buf
)
612 int status
= wan_status();
619 while ((cmd
= next_cmd(&buf
))) {
620 if (strlencmp(cmd
, "enable") == 0) {
622 } else if (strlencmp(cmd
, "disable") == 0) {
629 if (do_cmd
&& !acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
635 static int video_supported
;
636 static int video_orig_autosw
;
642 static int video_init(void)
646 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
647 /* G41, assume IVGA doesn't change */
648 vid_handle
= vid2_handle
;
651 /* video switching not supported on R30, R31 */
653 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
655 video_supported
= VIDEO_570
;
656 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
657 /* 600e/x, 770e, 770x */
658 video_supported
= VIDEO_770
;
661 video_supported
= VIDEO_NEW
;
666 static int video_status(void)
671 if (video_supported
== VIDEO_570
) {
672 if (acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd", 0x87))
674 } else if (video_supported
== VIDEO_770
) {
675 if (acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
677 if (acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
679 } else if (video_supported
== VIDEO_NEW
) {
680 acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1);
681 if (acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
684 acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0);
685 if (acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
687 if (acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
694 static int video_autosw(void)
698 if (video_supported
== VIDEO_570
)
699 acpi_evalf(vid_handle
, &autosw
, "SWIT", "d");
700 else if (video_supported
== VIDEO_770
|| video_supported
== VIDEO_NEW
)
701 acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d");
706 static int video_read(char *p
)
708 int status
= video_status();
709 int autosw
= video_autosw();
712 if (!video_supported
) {
713 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
717 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
718 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
719 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
720 if (video_supported
== VIDEO_NEW
)
721 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
722 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
723 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
724 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
725 if (video_supported
== VIDEO_NEW
)
726 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
727 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
728 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
733 static int video_switch(void)
735 int autosw
= video_autosw();
738 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
740 ret
= video_supported
== VIDEO_570
?
741 acpi_evalf(ec_handle
, NULL
, "_Q16", "v") :
742 acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
743 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", autosw
);
748 static int video_expand(void)
750 if (video_supported
== VIDEO_570
)
751 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v");
752 else if (video_supported
== VIDEO_770
)
753 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v");
755 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v");
758 static int video_switch2(int status
)
762 if (video_supported
== VIDEO_570
) {
763 ret
= acpi_evalf(NULL
, NULL
,
764 "\\_SB.PHS2", "vdd", 0x8b, status
| 0x80);
765 } else if (video_supported
== VIDEO_770
) {
766 int autosw
= video_autosw();
767 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
770 ret
= acpi_evalf(vid_handle
, NULL
,
771 "ASWT", "vdd", status
* 0x100, 0);
773 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", autosw
);
775 ret
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
776 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
782 static int video_write(char *buf
)
785 int enable
, disable
, status
;
787 if (!video_supported
)
790 enable
= disable
= 0;
792 while ((cmd
= next_cmd(&buf
))) {
793 if (strlencmp(cmd
, "lcd_enable") == 0) {
795 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
797 } else if (strlencmp(cmd
, "crt_enable") == 0) {
799 } else if (strlencmp(cmd
, "crt_disable") == 0) {
801 } else if (video_supported
== VIDEO_NEW
&&
802 strlencmp(cmd
, "dvi_enable") == 0) {
804 } else if (video_supported
== VIDEO_NEW
&&
805 strlencmp(cmd
, "dvi_disable") == 0) {
807 } else if (strlencmp(cmd
, "auto_enable") == 0) {
808 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
810 } else if (strlencmp(cmd
, "auto_disable") == 0) {
811 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 0))
813 } else if (strlencmp(cmd
, "video_switch") == 0) {
816 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
823 if (enable
|| disable
) {
824 status
= (video_status() & 0x0f & ~disable
) | enable
;
825 if (!video_switch2(status
))
832 static void video_exit(void)
834 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", video_orig_autosw
);
837 static int light_supported
;
838 static int light_status_supported
;
840 static int light_init(void)
842 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
843 light_supported
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
846 /* light status not supported on
847 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
848 light_status_supported
= acpi_evalf(ec_handle
, NULL
,
854 static int light_read(char *p
)
859 if (!light_supported
) {
860 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
861 } else if (!light_status_supported
) {
862 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
863 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
865 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
867 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
868 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
874 static int light_write(char *buf
)
876 int cmos_cmd
, lght_cmd
;
880 if (!light_supported
)
883 while ((cmd
= next_cmd(&buf
))) {
884 if (strlencmp(cmd
, "on") == 0) {
887 } else if (strlencmp(cmd
, "off") == 0) {
893 success
= cmos_handle
?
894 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
895 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
903 static int _sta(acpi_handle handle
)
907 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
913 #ifdef CONFIG_ACPI_IBM_DOCK
914 #define dock_docked() (_sta(dock_handle) & 1)
916 static int dock_read(char *p
)
919 int docked
= dock_docked();
922 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
924 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
926 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
927 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
933 static int dock_write(char *buf
)
940 while ((cmd
= next_cmd(&buf
))) {
941 if (strlencmp(cmd
, "undock") == 0) {
942 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
943 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
945 } else if (strlencmp(cmd
, "dock") == 0) {
946 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
955 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
957 int docked
= dock_docked();
958 int pci
= ibm
->hid
&& strstr(ibm
->hid
, IBM_PCI_HID
);
960 if (event
== 1 && !pci
) /* 570 */
961 acpi_bus_generate_event(ibm
->device
, event
, 1); /* button */
962 else if (event
== 1 && pci
) /* 570 */
963 acpi_bus_generate_event(ibm
->device
, event
, 3); /* dock */
964 else if (event
== 3 && docked
)
965 acpi_bus_generate_event(ibm
->device
, event
, 1); /* button */
966 else if (event
== 3 && !docked
)
967 acpi_bus_generate_event(ibm
->device
, event
, 2); /* undock */
968 else if (event
== 0 && docked
)
969 acpi_bus_generate_event(ibm
->device
, event
, 3); /* dock */
971 printk(IBM_ERR
"unknown dock event %d, status %d\n",
972 event
, _sta(dock_handle
));
973 acpi_bus_generate_event(ibm
->device
, event
, 0); /* unknown */
978 static int bay_status_supported
;
979 static int bay_status2_supported
;
980 static int bay_eject_supported
;
981 static int bay_eject2_supported
;
983 static int bay_init(void)
985 bay_status_supported
= bay_handle
&&
986 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
987 bay_status2_supported
= bay2_handle
&&
988 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
990 bay_eject_supported
= bay_handle
&& bay_ej_handle
&&
991 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
992 bay_eject2_supported
= bay2_handle
&& bay2_ej_handle
&&
993 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
998 #define bay_occupied(b) (_sta(b##_handle) & 1)
1000 static int bay_read(char *p
)
1003 int occupied
= bay_occupied(bay
);
1004 int occupied2
= bay_occupied(bay2
);
1007 len
+= sprintf(p
+ len
, "status:\t\t%s\n", bay_status_supported
?
1008 (occupied
? "occupied" : "unoccupied") :
1010 if (bay_status2_supported
)
1011 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
1012 "occupied" : "unoccupied");
1014 eject
= bay_eject_supported
&& occupied
;
1015 eject2
= bay_eject2_supported
&& occupied2
;
1017 if (eject
&& eject2
)
1018 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
1020 len
+= sprintf(p
+ len
, "commands:\teject\n");
1022 len
+= sprintf(p
+ len
, "commands:\teject2\n");
1027 static int bay_write(char *buf
)
1031 if (!bay_eject_supported
&& !bay_eject2_supported
)
1034 while ((cmd
= next_cmd(&buf
))) {
1035 if (bay_eject_supported
&& strlencmp(cmd
, "eject") == 0) {
1036 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
1038 } else if (bay_eject2_supported
&&
1039 strlencmp(cmd
, "eject2") == 0) {
1040 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
1049 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
1051 acpi_bus_generate_event(ibm
->device
, event
, 0);
1054 static int cmos_read(char *p
)
1058 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1059 R30, R31, T20-22, X20-21 */
1061 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1063 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1064 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
1070 static int cmos_eval(int cmos_cmd
)
1073 return acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
);
1078 static int cmos_write(char *buf
)
1086 while ((cmd
= next_cmd(&buf
))) {
1087 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
1088 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
1093 if (!cmos_eval(cmos_cmd
))
1100 static int led_supported
;
1106 static int led_init(void)
1109 /* led not supported on R30, R31 */
1111 else if (strlencmp(led_path
, "SLED") == 0)
1113 led_supported
= LED_570
;
1114 else if (strlencmp(led_path
, "SYSL") == 0)
1115 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1116 led_supported
= LED_OLD
;
1119 led_supported
= LED_NEW
;
1124 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
1126 static int led_read(char *p
)
1130 if (!led_supported
) {
1131 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1134 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1136 if (led_supported
== LED_570
) {
1139 for (i
= 0; i
< 8; i
++) {
1140 if (!acpi_evalf(ec_handle
,
1141 &status
, "GLED", "dd", 1 << i
))
1143 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
1144 i
, led_status(status
));
1148 len
+= sprintf(p
+ len
, "commands:\t"
1149 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
1154 /* off, on, blink */
1155 static const int led_sled_arg1
[] = { 0, 1, 3 };
1156 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
1157 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
1158 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
1160 #define EC_HLCL 0x0c
1161 #define EC_HLBL 0x0d
1162 #define EC_HLMS 0x0e
1164 static int led_write(char *buf
)
1172 while ((cmd
= next_cmd(&buf
))) {
1173 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
1176 if (strstr(cmd
, "off")) {
1178 } else if (strstr(cmd
, "on")) {
1180 } else if (strstr(cmd
, "blink")) {
1185 if (led_supported
== LED_570
) {
1188 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
1189 led
, led_sled_arg1
[ind
]))
1191 } else if (led_supported
== LED_OLD
) {
1192 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
1194 ret
= ec_write(EC_HLMS
, led
);
1197 ec_write(EC_HLBL
, led
* led_exp_hlbl
[ind
]);
1200 ec_write(EC_HLCL
, led
* led_exp_hlcl
[ind
]);
1205 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
1206 led
, led_led_arg1
[ind
]))
1214 static int beep_read(char *p
)
1219 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1221 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1222 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
1228 static int beep_write(char *buf
)
1236 while ((cmd
= next_cmd(&buf
))) {
1237 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
1238 beep_cmd
>= 0 && beep_cmd
<= 17) {
1242 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
1249 static int acpi_ec_read(int i
, u8
* p
)
1254 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
1258 if (ec_read(i
, p
) < 0)
1265 static int acpi_ec_write(int i
, u8 v
)
1268 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
1271 if (ec_write(i
, v
) < 0)
1278 static int thermal_tmp_supported
;
1279 static int thermal_updt_supported
;
1281 static int thermal_init(void)
1283 /* temperatures not supported on 570, G4x, R30, R31, R32 */
1284 thermal_tmp_supported
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
1286 /* 600e/x, 770e, 770x */
1287 thermal_updt_supported
= acpi_evalf(ec_handle
, NULL
, "UPDT", "qv");
1292 static int thermal_read(char *p
)
1296 if (!thermal_tmp_supported
)
1297 len
+= sprintf(p
+ len
, "temperatures:\tnot supported\n");
1300 char tmpi
[] = "TMPi";
1303 if (thermal_updt_supported
)
1304 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
1307 for (i
= 0; i
< 8; i
++) {
1309 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
1311 if (thermal_updt_supported
)
1312 tmp
[i
] = (t
- 2732 + 5) / 10;
1317 len
+= sprintf(p
+ len
,
1318 "temperatures:\t%d %d %d %d %d %d %d %d\n",
1319 tmp
[0], tmp
[1], tmp
[2], tmp
[3],
1320 tmp
[4], tmp
[5], tmp
[6], tmp
[7]);
1326 static u8 ecdump_regs
[256];
1328 static int ecdump_read(char *p
)
1334 len
+= sprintf(p
+ len
, "EC "
1335 " +00 +01 +02 +03 +04 +05 +06 +07"
1336 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
1337 for (i
= 0; i
< 256; i
+= 16) {
1338 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
1339 for (j
= 0; j
< 16; j
++) {
1340 if (!acpi_ec_read(i
+ j
, &v
))
1342 if (v
!= ecdump_regs
[i
+ j
])
1343 len
+= sprintf(p
+ len
, " *%02x", v
);
1345 len
+= sprintf(p
+ len
, " %02x", v
);
1346 ecdump_regs
[i
+ j
] = v
;
1348 len
+= sprintf(p
+ len
, "\n");
1353 /* These are way too dangerous to advertise openly... */
1355 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
1356 " (<offset> is 00-ff, <value> is 00-ff)\n");
1357 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
1358 " (<offset> is 00-ff, <value> is 0-255)\n");
1363 static int ecdump_write(char *buf
)
1368 while ((cmd
= next_cmd(&buf
))) {
1369 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
1371 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
1375 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
1376 if (!acpi_ec_write(i
, v
))
1385 static int brightness_offset
= 0x31;
1387 static int brightness_get(struct backlight_device
*bd
)
1390 if (!acpi_ec_read(brightness_offset
, &level
))
1397 static int brightness_read(char *p
)
1402 if ((level
= brightness_get(NULL
)) < 0) {
1403 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
1405 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0x7);
1406 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
1407 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
1408 " (<level> is 0-7)\n");
1414 #define BRIGHTNESS_UP 4
1415 #define BRIGHTNESS_DOWN 5
1417 static int brightness_set(int value
)
1419 int cmos_cmd
, inc
, i
;
1420 int current_value
= brightness_get(NULL
);
1424 cmos_cmd
= value
> current_value
? BRIGHTNESS_UP
: BRIGHTNESS_DOWN
;
1425 inc
= value
> current_value
? 1 : -1;
1426 for (i
= current_value
; i
!= value
; i
+= inc
) {
1427 if (!cmos_eval(cmos_cmd
))
1429 if (!acpi_ec_write(brightness_offset
, i
+ inc
))
1436 static int brightness_write(char *buf
)
1442 while ((cmd
= next_cmd(&buf
))) {
1443 if ((level
= brightness_get(NULL
)) < 0)
1447 if (strlencmp(cmd
, "up") == 0) {
1448 new_level
= level
== 7 ? 7 : level
+ 1;
1449 } else if (strlencmp(cmd
, "down") == 0) {
1450 new_level
= level
== 0 ? 0 : level
- 1;
1451 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
1452 new_level
>= 0 && new_level
<= 7) {
1457 brightness_set(new_level
);
1463 static int brightness_update_status(struct backlight_device
*bd
)
1465 return brightness_set(bd
->props
->brightness
);
1468 static int volume_offset
= 0x30;
1470 static int volume_read(char *p
)
1475 if (!acpi_ec_read(volume_offset
, &level
)) {
1476 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
1478 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
1479 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
1480 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
1481 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
1482 " (<level> is 0-15)\n");
1488 #define VOLUME_DOWN 0
1490 #define VOLUME_MUTE 2
1492 static int volume_write(char *buf
)
1494 int cmos_cmd
, inc
, i
;
1496 int new_level
, new_mute
;
1499 while ((cmd
= next_cmd(&buf
))) {
1500 if (!acpi_ec_read(volume_offset
, &level
))
1502 new_mute
= mute
= level
& 0x40;
1503 new_level
= level
= level
& 0xf;
1505 if (strlencmp(cmd
, "up") == 0) {
1509 new_level
= level
== 15 ? 15 : level
+ 1;
1510 } else if (strlencmp(cmd
, "down") == 0) {
1514 new_level
= level
== 0 ? 0 : level
- 1;
1515 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
1516 new_level
>= 0 && new_level
<= 15) {
1518 } else if (strlencmp(cmd
, "mute") == 0) {
1523 if (new_level
!= level
) { /* mute doesn't change */
1524 cmos_cmd
= new_level
> level
? VOLUME_UP
: VOLUME_DOWN
;
1525 inc
= new_level
> level
? 1 : -1;
1527 if (mute
&& (!cmos_eval(cmos_cmd
) ||
1528 !acpi_ec_write(volume_offset
, level
)))
1531 for (i
= level
; i
!= new_level
; i
+= inc
)
1532 if (!cmos_eval(cmos_cmd
) ||
1533 !acpi_ec_write(volume_offset
, i
+ inc
))
1536 if (mute
&& (!cmos_eval(VOLUME_MUTE
) ||
1537 !acpi_ec_write(volume_offset
,
1542 if (new_mute
!= mute
) { /* level doesn't change */
1543 cmos_cmd
= new_mute
? VOLUME_MUTE
: VOLUME_UP
;
1545 if (!cmos_eval(cmos_cmd
) ||
1546 !acpi_ec_write(volume_offset
, level
+ new_mute
))
1554 static int fan_status_offset
= 0x2f;
1555 static int fan_rpm_offset
= 0x84;
1557 static int fan_read(char *p
)
1564 /* 570, 600e/x, 770e, 770x */
1565 if (!acpi_evalf(gfan_handle
, &s
, NULL
, "d"))
1568 len
+= sprintf(p
+ len
, "level:\t\t%d\n", s
);
1570 /* all except 570, 600e/x, 770e, 770x */
1571 if (!acpi_ec_read(fan_status_offset
, &status
))
1572 len
+= sprintf(p
+ len
, "status:\t\tunreadable\n");
1574 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1575 enabled(status
, 7));
1577 if (!acpi_ec_read(fan_rpm_offset
, &lo
) ||
1578 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
))
1579 len
+= sprintf(p
+ len
, "speed:\t\tunreadable\n");
1581 len
+= sprintf(p
+ len
, "speed:\t\t%d\n",
1587 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
1588 " (<level> is 0-7)\n");
1590 /* all except 570, 600e/x, 770e, 770x */
1591 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1594 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
1595 " (<speed> is 0-65535)\n");
1600 static int fan_write(char *buf
)
1605 while ((cmd
= next_cmd(&buf
))) {
1607 sscanf(cmd
, "level %d", &level
) == 1 &&
1608 level
>= 0 && level
<= 7) {
1610 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
1612 } else if (!gfan_handle
&& strlencmp(cmd
, "enable") == 0) {
1613 /* all except 570, 600e/x, 770e, 770x */
1614 if (!acpi_ec_write(fan_status_offset
, 0x80))
1616 } else if (!gfan_handle
&& strlencmp(cmd
, "disable") == 0) {
1617 /* all except 570, 600e/x, 770e, 770x */
1618 if (!acpi_ec_write(fan_status_offset
, 0x00))
1620 } else if (fans_handle
&&
1621 sscanf(cmd
, "speed %d", &speed
) == 1 &&
1622 speed
>= 0 && speed
<= 65535) {
1624 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
1625 speed
, speed
, speed
))
1634 static struct ibm_struct ibms
[] = {
1637 .init
= driver_init
,
1638 .read
= driver_read
,
1642 .hid
= IBM_HKEY_HID
,
1643 .init
= hotkey_init
,
1644 .read
= hotkey_read
,
1645 .write
= hotkey_write
,
1646 .exit
= hotkey_exit
,
1647 .notify
= hotkey_notify
,
1648 .handle
= &hkey_handle
,
1649 .type
= ACPI_DEVICE_NOTIFY
,
1652 .name
= "bluetooth",
1653 .init
= bluetooth_init
,
1654 .read
= bluetooth_read
,
1655 .write
= bluetooth_write
,
1668 .write
= video_write
,
1675 .write
= light_write
,
1677 #ifdef CONFIG_ACPI_IBM_DOCK
1681 .write
= dock_write
,
1682 .notify
= dock_notify
,
1683 .handle
= &dock_handle
,
1684 .type
= ACPI_SYSTEM_NOTIFY
,
1689 .notify
= dock_notify
,
1690 .handle
= &pci_handle
,
1691 .type
= ACPI_SYSTEM_NOTIFY
,
1699 .notify
= bay_notify
,
1700 .handle
= &bay_handle
,
1701 .type
= ACPI_SYSTEM_NOTIFY
,
1706 .write
= cmos_write
,
1717 .write
= beep_write
,
1721 .init
= thermal_init
,
1722 .read
= thermal_read
,
1726 .read
= ecdump_read
,
1727 .write
= ecdump_write
,
1731 .name
= "brightness",
1732 .read
= brightness_read
,
1733 .write
= brightness_write
,
1737 .read
= volume_read
,
1738 .write
= volume_write
,
1748 static int dispatch_read(char *page
, char **start
, off_t off
, int count
,
1749 int *eof
, void *data
)
1751 struct ibm_struct
*ibm
= data
;
1754 if (!ibm
|| !ibm
->read
)
1757 len
= ibm
->read(page
);
1761 if (len
<= off
+ count
)
1763 *start
= page
+ off
;
1773 static int dispatch_write(struct file
*file
, const char __user
* userbuf
,
1774 unsigned long count
, void *data
)
1776 struct ibm_struct
*ibm
= data
;
1780 if (!ibm
|| !ibm
->write
)
1783 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
1787 if (copy_from_user(kernbuf
, userbuf
, count
)) {
1793 strcat(kernbuf
, ",");
1794 ret
= ibm
->write(kernbuf
);
1803 static void dispatch_notify(acpi_handle handle
, u32 event
, void *data
)
1805 struct ibm_struct
*ibm
= data
;
1807 if (!ibm
|| !ibm
->notify
)
1810 ibm
->notify(ibm
, event
);
1813 static int __init
setup_notify(struct ibm_struct
*ibm
)
1821 ret
= acpi_bus_get_device(*ibm
->handle
, &ibm
->device
);
1823 printk(IBM_ERR
"%s device not present\n", ibm
->name
);
1827 acpi_driver_data(ibm
->device
) = ibm
;
1828 sprintf(acpi_device_class(ibm
->device
), "%s/%s", IBM_NAME
, ibm
->name
);
1830 status
= acpi_install_notify_handler(*ibm
->handle
, ibm
->type
,
1831 dispatch_notify
, ibm
);
1832 if (ACPI_FAILURE(status
)) {
1833 printk(IBM_ERR
"acpi_install_notify_handler(%s) failed: %d\n",
1841 static int __init
ibm_device_add(struct acpi_device
*device
)
1846 static int __init
register_driver(struct ibm_struct
*ibm
)
1850 ibm
->driver
= kmalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
1852 printk(IBM_ERR
"kmalloc(ibm->driver) failed\n");
1856 memset(ibm
->driver
, 0, sizeof(struct acpi_driver
));
1857 sprintf(ibm
->driver
->name
, "%s_%s", IBM_NAME
, ibm
->name
);
1858 ibm
->driver
->ids
= ibm
->hid
;
1859 ibm
->driver
->ops
.add
= &ibm_device_add
;
1861 ret
= acpi_bus_register_driver(ibm
->driver
);
1863 printk(IBM_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
1871 static int __init
ibm_init(struct ibm_struct
*ibm
)
1874 struct proc_dir_entry
*entry
;
1876 if (ibm
->experimental
&& !experimental
)
1880 ret
= register_driver(ibm
);
1883 ibm
->driver_registered
= 1;
1890 ibm
->init_called
= 1;
1894 entry
= create_proc_entry(ibm
->name
,
1895 S_IFREG
| S_IRUGO
| S_IWUSR
,
1898 printk(IBM_ERR
"unable to create proc entry %s\n",
1902 entry
->owner
= THIS_MODULE
;
1904 entry
->read_proc
= &dispatch_read
;
1906 entry
->write_proc
= &dispatch_write
;
1907 ibm
->proc_created
= 1;
1911 ret
= setup_notify(ibm
);
1914 ibm
->notify_installed
= 1;
1920 static void ibm_exit(struct ibm_struct
*ibm
)
1922 if (ibm
->notify_installed
)
1923 acpi_remove_notify_handler(*ibm
->handle
, ibm
->type
,
1926 if (ibm
->proc_created
)
1927 remove_proc_entry(ibm
->name
, proc_dir
);
1929 if (ibm
->init_called
&& ibm
->exit
)
1932 if (ibm
->driver_registered
) {
1933 acpi_bus_unregister_driver(ibm
->driver
);
1938 static void __init
ibm_handle_init(char *name
,
1939 acpi_handle
* handle
, acpi_handle parent
,
1940 char **paths
, int num_paths
, char **path
)
1945 for (i
= 0; i
< num_paths
; i
++) {
1946 status
= acpi_get_handle(parent
, paths
[i
], handle
);
1947 if (ACPI_SUCCESS(status
)) {
1956 #define IBM_HANDLE_INIT(object) \
1957 ibm_handle_init(#object, &object##_handle, *object##_parent, \
1958 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
1960 static int set_ibm_param(const char *val
, struct kernel_param
*kp
)
1964 for (i
= 0; i
< ARRAY_SIZE(ibms
); i
++)
1965 if (strcmp(ibms
[i
].name
, kp
->name
) == 0 && ibms
[i
].write
) {
1966 if (strlen(val
) > sizeof(ibms
[i
].param
) - 2)
1968 strcpy(ibms
[i
].param
, val
);
1969 strcat(ibms
[i
].param
, ",");
1976 #define IBM_PARAM(feature) \
1977 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
1980 IBM_PARAM(bluetooth
);
1983 #ifdef CONFIG_ACPI_IBM_DOCK
1991 IBM_PARAM(brightness
);
1995 static struct backlight_properties ibm_backlight_data
= {
1996 .owner
= THIS_MODULE
,
1997 .get_brightness
= brightness_get
,
1998 .update_status
= brightness_update_status
,
1999 .max_brightness
= 7,
2002 static void acpi_ibm_exit(void)
2006 if (ibm_backlight_device
)
2007 backlight_device_unregister(ibm_backlight_device
);
2009 for (i
= ARRAY_SIZE(ibms
) - 1; i
>= 0; i
--)
2012 remove_proc_entry(IBM_DIR
, acpi_root_dir
);
2015 static int __init
acpi_ibm_init(void)
2022 if (!acpi_specific_hotkey_enabled
) {
2023 printk(IBM_ERR
"using generic hotkey driver\n");
2027 /* ec is required because many other handles are relative to it */
2028 IBM_HANDLE_INIT(ec
);
2030 printk(IBM_ERR
"ec object not found\n");
2034 /* these handles are not required */
2035 IBM_HANDLE_INIT(vid
);
2036 IBM_HANDLE_INIT(vid2
);
2037 IBM_HANDLE_INIT(ledb
);
2038 IBM_HANDLE_INIT(led
);
2039 IBM_HANDLE_INIT(hkey
);
2040 IBM_HANDLE_INIT(lght
);
2041 IBM_HANDLE_INIT(cmos
);
2042 #ifdef CONFIG_ACPI_IBM_DOCK
2043 IBM_HANDLE_INIT(dock
);
2045 IBM_HANDLE_INIT(pci
);
2046 IBM_HANDLE_INIT(bay
);
2048 IBM_HANDLE_INIT(bay_ej
);
2049 IBM_HANDLE_INIT(bay2
);
2051 IBM_HANDLE_INIT(bay2_ej
);
2052 IBM_HANDLE_INIT(beep
);
2053 IBM_HANDLE_INIT(ecrd
);
2054 IBM_HANDLE_INIT(ecwr
);
2055 IBM_HANDLE_INIT(fans
);
2056 IBM_HANDLE_INIT(gfan
);
2057 IBM_HANDLE_INIT(sfan
);
2059 proc_dir
= proc_mkdir(IBM_DIR
, acpi_root_dir
);
2061 printk(IBM_ERR
"unable to create proc dir %s", IBM_DIR
);
2064 proc_dir
->owner
= THIS_MODULE
;
2066 for (i
= 0; i
< ARRAY_SIZE(ibms
); i
++) {
2067 ret
= ibm_init(&ibms
[i
]);
2068 if (ret
>= 0 && *ibms
[i
].param
)
2069 ret
= ibms
[i
].write(ibms
[i
].param
);
2076 ibm_backlight_device
= backlight_device_register("ibm", NULL
,
2077 &ibm_backlight_data
);
2078 if (IS_ERR(ibm_backlight_device
)) {
2079 printk(IBM_ERR
"Could not register ibm backlight device\n");
2080 ibm_backlight_device
= NULL
;
2087 module_init(acpi_ibm_init
);
2088 module_exit(acpi_ibm_exit
);