2 * ibm_acpi.c - IBM ThinkPad ACPI Extras
5 * Copyright (C) 2004 Borislav Deianov
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
23 * 2004-08-09 0.1 initial release, support for X series
24 * 2004-08-14 0.2 support for T series, X20
25 * bluetooth enable/disable
26 * hotkey events disabled by default
27 * removed fan control, currently useless
28 * 2004-08-17 0.3 support for R40
29 * lcd off, brightness control
31 * 2004-09-16 0.4 support for module parameters
32 * hotkey mask can be prefixed by 0x
33 * video output switching
34 * video expansion control
35 * ultrabay eject support
36 * removed lcd brightness/on/off control, didn't work
37 * 2004-10-18 0.5 thinklight support on A21e, G40, R32, T20, T21, X20
38 * proc file format changed
39 * video_switch command
40 * experimental cmos control
41 * experimental led control
42 * experimental acpi sounds
43 * 2004-10-19 0.6 use acpi_bus_register_driver() to claim HKEY device
44 * 2004-10-23 0.7 fix module loading on A21e, A22p, T20, T21, X20
45 * fix LED control on A21e
46 * 2004-11-08 0.8 fix init error case, don't return from a macro
47 * thanks to Chris Wright <chrisw@osdl.org>
50 #define IBM_VERSION "0.8"
52 #include <linux/kernel.h>
53 #include <linux/module.h>
54 #include <linux/init.h>
55 #include <linux/types.h>
56 #include <linux/proc_fs.h>
57 #include <asm/uaccess.h>
59 #include <acpi/acpi_drivers.h>
60 #include <acpi/acnamesp.h>
62 #define IBM_NAME "ibm"
63 #define IBM_DESC "IBM ThinkPad ACPI Extras"
64 #define IBM_FILE "ibm_acpi"
65 #define IBM_URL "http://ibm-acpi.sf.net/"
67 #define IBM_DIR IBM_NAME
69 #define IBM_LOG IBM_FILE ": "
70 #define IBM_ERR KERN_ERR IBM_LOG
71 #define IBM_NOTICE KERN_NOTICE IBM_LOG
72 #define IBM_INFO KERN_INFO IBM_LOG
73 #define IBM_DEBUG KERN_DEBUG IBM_LOG
75 #define IBM_MAX_ACPI_ARGS 3
77 #define __unused __attribute__ ((unused))
79 static int experimental
;
80 module_param(experimental
, int, 0);
82 static acpi_handle root_handle
= NULL
;
84 #define IBM_HANDLE(object, parent, paths...) \
85 static acpi_handle object##_handle; \
86 static acpi_handle *object##_parent = &parent##_handle; \
87 static char *object##_paths[] = { paths }
90 "\\_SB.PCI0.ISA.EC", /* A21e, A22p, T20, T21, X20 */
91 "\\_SB.PCI0.LPC.EC", /* all others */
95 "\\_SB.PCI0.VID", /* A21e, G40, X30, X40 */
96 "\\_SB.PCI0.AGP.VID", /* all others */
99 IBM_HANDLE(cmos
, root
,
100 "\\UCMS", /* R50, R50p, R51, T4x, X31, X40 */
101 "\\CMOS", /* A3x, G40, R32, T23, T30, X22, X24, X30 */
102 "\\CMS", /* R40, R40e */
103 ); /* A21e, A22p, T20, T21, X20 */
105 IBM_HANDLE(dock
, root
,
106 "\\_SB.GDCK", /* X30, X31, X40 */
107 "\\_SB.PCI0.DOCK", /* A22p, T20, T21, X20 */
108 "\\_SB.PCI0.PCI1.DOCK", /* all others */
109 ); /* A21e, G40, R32, R40, R40e */
111 IBM_HANDLE(bay
, root
,
112 "\\_SB.PCI0.IDE0.SCND.MSTR"); /* all except A21e */
113 IBM_HANDLE(bayej
, root
,
114 "\\_SB.PCI0.IDE0.SCND.MSTR._EJ0"); /* all except A2x, A3x */
116 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A22p, T20, T21, X20 */
117 IBM_HANDLE(hkey
, ec
, "HKEY"); /* all */
118 IBM_HANDLE(led
, ec
, "LED"); /* all except A21e, A22p, T20, T21, X20 */
119 IBM_HANDLE(sysl
, ec
, "SYSL"); /* A21e, A22p, T20, T21, X20 */
120 IBM_HANDLE(bled
, ec
, "BLED"); /* A22p, T20, T21, X20 */
121 IBM_HANDLE(beep
, ec
, "BEEP"); /* all models */
127 struct acpi_driver
*driver
;
129 int (*init
) (struct ibm_struct
*);
130 int (*read
) (struct ibm_struct
*, char *);
131 int (*write
) (struct ibm_struct
*, char *);
132 void (*exit
) (struct ibm_struct
*);
134 void (*notify
) (struct ibm_struct
*, u32
);
137 struct acpi_device
*device
;
139 int driver_registered
;
142 int notify_installed
;
158 static struct proc_dir_entry
*proc_dir
= NULL
;
160 #define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off")
161 #define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
162 #define strlencmp(a,b) (strncmp((a), (b), strlen(b)))
164 static int acpi_evalf(acpi_handle handle
,
165 void *res
, char *method
, char *fmt
, ...)
168 struct acpi_object_list params
;
169 union acpi_object in_objs
[IBM_MAX_ACPI_ARGS
];
170 struct acpi_buffer result
;
171 union acpi_object out_obj
;
179 printk(IBM_ERR
"acpi_evalf() called with empty format\n");
192 params
.pointer
= &in_objs
[0];
199 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
200 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
202 /* add more types as needed */
204 printk(IBM_ERR
"acpi_evalf() called "
205 "with invalid format character '%c'\n", c
);
211 result
.length
= sizeof(out_obj
);
212 result
.pointer
= &out_obj
;
214 status
= acpi_evaluate_object(handle
, method
, ¶ms
, &result
);
219 *(int *)res
= out_obj
.integer
.value
;
220 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
223 success
= status
== AE_OK
;
225 /* add more types as needed */
227 printk(IBM_ERR
"acpi_evalf() called "
228 "with invalid format character '%c'\n", res_type
);
232 if (!success
&& !quiet
)
233 printk(IBM_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
234 method
, fmt0
, status
);
239 static void __unused
acpi_print_int(acpi_handle handle
, char *method
)
243 if (acpi_evalf(handle
, &i
, method
, "d"))
244 printk(IBM_INFO
"%s = 0x%x\n", method
, i
);
246 printk(IBM_ERR
"error calling %s\n", method
);
249 static char *next_cmd(char **cmds
)
254 while ((end
= strchr(start
, ',')) && end
== start
)
265 static int driver_init(struct ibm_struct
*ibm
)
267 printk(IBM_INFO
"%s v%s\n", IBM_DESC
, IBM_VERSION
);
268 printk(IBM_INFO
"%s\n", IBM_URL
);
273 static int driver_read(struct ibm_struct
*ibm
, char *p
)
277 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", IBM_DESC
);
278 len
+= sprintf(p
+ len
, "version:\t%s\n", IBM_VERSION
);
283 static int hotkey_get(struct ibm_struct
*ibm
, int *status
, int *mask
)
285 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
287 if (ibm
->supported
) {
288 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "qd"))
291 *mask
= ibm
->state
.hotkey
.mask
;
296 static int hotkey_set(struct ibm_struct
*ibm
, int status
, int mask
)
300 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
306 for (i
=0; i
<32; i
++) {
307 int bit
= ((1 << i
) & mask
) != 0;
308 if (!acpi_evalf(hkey_handle
, NULL
, "MHKM", "vdd", i
+1, bit
))
315 static int hotkey_init(struct ibm_struct
*ibm
)
320 ret
= hotkey_get(ibm
,
321 &ibm
->state
.hotkey
.status
,
322 &ibm
->state
.hotkey
.mask
);
324 /* mask not supported on A21e, A22p, T20, T21, X20, X22, X24 */
326 ret
= hotkey_get(ibm
,
327 &ibm
->state
.hotkey
.status
,
328 &ibm
->state
.hotkey
.mask
);
334 static int hotkey_read(struct ibm_struct
*ibm
, char *p
)
339 if (hotkey_get(ibm
, &status
, &mask
) < 0)
342 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
343 if (ibm
->supported
) {
344 len
+= sprintf(p
+ len
, "mask:\t\t0x%04x\n", mask
);
345 len
+= sprintf(p
+ len
,
346 "commands:\tenable, disable, reset, <mask>\n");
348 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
349 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
355 static int hotkey_write(struct ibm_struct
*ibm
, char *buf
)
361 if (hotkey_get(ibm
, &status
, &mask
) < 0)
364 while ((cmd
= next_cmd(&buf
))) {
365 if (strlencmp(cmd
, "enable") == 0) {
367 } else if (strlencmp(cmd
, "disable") == 0) {
369 } else if (strlencmp(cmd
, "reset") == 0) {
370 status
= ibm
->state
.hotkey
.status
;
371 mask
= ibm
->state
.hotkey
.mask
;
372 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
374 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
381 if (do_cmd
&& hotkey_set(ibm
, status
, mask
) < 0)
387 static void hotkey_exit(struct ibm_struct
*ibm
)
389 hotkey_set(ibm
, ibm
->state
.hotkey
.status
, ibm
->state
.hotkey
.mask
);
392 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
396 if (acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d"))
397 acpi_bus_generate_event(ibm
->device
, event
, hkey
);
399 printk(IBM_ERR
"unknown hotkey event %d\n", event
);
400 acpi_bus_generate_event(ibm
->device
, event
, 0);
404 static int bluetooth_init(struct ibm_struct
*ibm
)
406 /* bluetooth not supported on A21e, G40, T20, T21, X20 */
407 ibm
->supported
= acpi_evalf(hkey_handle
, NULL
, "GBDC", "qv");
412 static int bluetooth_status(struct ibm_struct
*ibm
)
416 if (!ibm
->supported
|| !acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
422 static int bluetooth_read(struct ibm_struct
*ibm
, char *p
)
425 int status
= bluetooth_status(ibm
);
428 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
429 else if (!(status
& 1))
430 len
+= sprintf(p
+ len
, "status:\t\tnot installed\n");
432 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 1));
433 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
439 static int bluetooth_write(struct ibm_struct
*ibm
, char *buf
)
441 int status
= bluetooth_status(ibm
);
448 while ((cmd
= next_cmd(&buf
))) {
449 if (strlencmp(cmd
, "enable") == 0) {
451 } else if (strlencmp(cmd
, "disable") == 0) {
458 if (do_cmd
&& !acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
464 static int video_init(struct ibm_struct
*ibm
)
466 if (!acpi_evalf(vid_handle
,
467 &ibm
->state
.video
.autoswitch
, "^VDEE", "d"))
473 static int video_status(struct ibm_struct
*ibm
)
478 acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1);
479 if (acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
482 acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0);
483 if (acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
485 if (acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
488 if (acpi_evalf(vid_handle
, &i
, "^VDEE", "d"))
489 status
|= 0x10 * (i
& 1);
494 static int video_read(struct ibm_struct
*ibm
, char *p
)
496 int status
= video_status(ibm
);
499 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
500 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
501 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
502 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(status
, 4));
503 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable, "
504 "crt_enable, crt_disable\n");
505 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable, "
506 "auto_enable, auto_disable\n");
507 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
512 static int video_write(struct ibm_struct
*ibm
, char *buf
)
515 int enable
, disable
, status
;
517 enable
= disable
= 0;
519 while ((cmd
= next_cmd(&buf
))) {
520 if (strlencmp(cmd
, "lcd_enable") == 0) {
522 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
524 } else if (strlencmp(cmd
, "crt_enable") == 0) {
526 } else if (strlencmp(cmd
, "crt_disable") == 0) {
528 } else if (strlencmp(cmd
, "dvi_enable") == 0) {
530 } else if (strlencmp(cmd
, "dvi_disable") == 0) {
532 } else if (strlencmp(cmd
, "auto_enable") == 0) {
533 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
535 } else if (strlencmp(cmd
, "auto_disable") == 0) {
536 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 0))
538 } else if (strlencmp(cmd
, "video_switch") == 0) {
540 if (!acpi_evalf(vid_handle
, &autoswitch
, "^VDEE", "d"))
542 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
544 if (!acpi_evalf(vid_handle
, NULL
, "VSWT", "v"))
546 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd",
549 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
550 if (!acpi_evalf(NULL
, NULL
, "\\VEXP", "v"))
556 if (enable
|| disable
) {
557 status
= (video_status(ibm
) & 0x0f & ~disable
) | enable
;
558 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80))
560 if (!acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1))
567 static void video_exit(struct ibm_struct
*ibm
)
569 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd",
570 ibm
->state
.video
.autoswitch
);
573 static int light_init(struct ibm_struct
*ibm
)
575 /* kblt not supported on G40, R32, X20 */
576 ibm
->supported
= acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
581 static int light_read(struct ibm_struct
*ibm
, char *p
)
586 if (ibm
->supported
) {
587 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
589 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
591 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
593 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
598 static int light_write(struct ibm_struct
*ibm
, char *buf
)
600 int cmos_cmd
, lght_cmd
;
604 while ((cmd
= next_cmd(&buf
))) {
605 if (strlencmp(cmd
, "on") == 0) {
608 } else if (strlencmp(cmd
, "off") == 0) {
614 success
= cmos_handle
?
615 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
616 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
624 static int _sta(acpi_handle handle
)
628 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
634 #define dock_docked() (_sta(dock_handle) & 1)
636 static int dock_read(struct ibm_struct
*ibm
, char *p
)
639 int docked
= dock_docked();
642 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
644 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
646 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
647 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
653 static int dock_write(struct ibm_struct
*ibm
, char *buf
)
660 while ((cmd
= next_cmd(&buf
))) {
661 if (strlencmp(cmd
, "undock") == 0) {
662 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0))
664 if (!acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
666 } else if (strlencmp(cmd
, "dock") == 0) {
667 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
676 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
678 int docked
= dock_docked();
680 if (event
== 3 && docked
)
681 acpi_bus_generate_event(ibm
->device
, event
, 1); /* button */
682 else if (event
== 3 && !docked
)
683 acpi_bus_generate_event(ibm
->device
, event
, 2); /* undock */
684 else if (event
== 0 && docked
)
685 acpi_bus_generate_event(ibm
->device
, event
, 3); /* dock */
687 printk(IBM_ERR
"unknown dock event %d, status %d\n",
688 event
, _sta(dock_handle
));
689 acpi_bus_generate_event(ibm
->device
, event
, 0); /* unknown */
693 #define bay_occupied() (_sta(bay_handle) & 1)
695 static int bay_init(struct ibm_struct
*ibm
)
697 /* bay not supported on A21e, A22p, A31, A31p, G40, R32, R40e */
698 ibm
->supported
= bay_handle
&& bayej_handle
&&
699 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
704 static int bay_read(struct ibm_struct
*ibm
, char *p
)
707 int occupied
= bay_occupied();
710 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
712 len
+= sprintf(p
+ len
, "status:\t\tunoccupied\n");
714 len
+= sprintf(p
+ len
, "status:\t\toccupied\n");
715 len
+= sprintf(p
+ len
, "commands:\teject\n");
721 static int bay_write(struct ibm_struct
*ibm
, char *buf
)
725 while ((cmd
= next_cmd(&buf
))) {
726 if (strlencmp(cmd
, "eject") == 0) {
727 if (!ibm
->supported
||
728 !acpi_evalf(bay_handle
, NULL
, "_EJ0", "vd", 1))
737 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
739 acpi_bus_generate_event(ibm
->device
, event
, 0);
742 static int cmos_read(struct ibm_struct
*ibm
, char *p
)
746 /* cmos not supported on A21e, A22p, T20, T21, X20 */
748 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
750 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
751 len
+= sprintf(p
+ len
, "commands:\t<int>\n");
757 static int cmos_write(struct ibm_struct
*ibm
, char *buf
)
765 while ((cmd
= next_cmd(&buf
))) {
766 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1) {
771 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
778 static int led_read(struct ibm_struct
*ibm
, char *p
)
782 len
+= sprintf(p
+ len
, "commands:\t"
783 "<int> on, <int> off, <int> blink\n");
788 static int led_write(struct ibm_struct
*ibm
, char *buf
)
792 int led_cmd
, sysl_cmd
, bled_a
, bled_b
;
794 while ((cmd
= next_cmd(&buf
))) {
795 if (sscanf(cmd
, "%u", &led
) != 1)
798 if (strstr(cmd
, "blink")) {
803 } else if (strstr(cmd
, "on")) {
808 } else if (strstr(cmd
, "off")) {
809 led_cmd
= sysl_cmd
= bled_a
= bled_b
= 0;
814 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
817 } else if (led
< 2) {
818 if (acpi_evalf(sysl_handle
, NULL
, NULL
, "vdd",
821 } else if (led
== 2 && bled_handle
) {
822 if (acpi_evalf(bled_handle
, NULL
, NULL
, "vdd",
832 static int beep_read(struct ibm_struct
*ibm
, char *p
)
836 len
+= sprintf(p
+ len
, "commands:\t<int>\n");
841 static int beep_write(struct ibm_struct
*ibm
, char *buf
)
846 while ((cmd
= next_cmd(&buf
))) {
847 if (sscanf(cmd
, "%u", &beep_cmd
) == 1) {
852 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vd", beep_cmd
))
859 static struct ibm_struct ibms
[] = {
870 .write
= hotkey_write
,
872 .notify
= hotkey_notify
,
873 .handle
= &hkey_handle
,
874 .type
= ACPI_DEVICE_NOTIFY
,
878 .init
= bluetooth_init
,
879 .read
= bluetooth_read
,
880 .write
= bluetooth_write
,
886 .write
= video_write
,
893 .write
= light_write
,
899 .notify
= dock_notify
,
900 .handle
= &dock_handle
,
901 .type
= ACPI_SYSTEM_NOTIFY
,
908 .notify
= bay_notify
,
909 .handle
= &bay_handle
,
910 .type
= ACPI_SYSTEM_NOTIFY
,
931 #define NUM_IBMS (sizeof(ibms)/sizeof(ibms[0]))
933 static int dispatch_read(char *page
, char **start
, off_t off
, int count
,
934 int *eof
, void *data
)
936 struct ibm_struct
*ibm
= (struct ibm_struct
*)data
;
939 if (!ibm
|| !ibm
->read
)
942 len
= ibm
->read(ibm
, page
);
946 if (len
<= off
+ count
)
958 static int dispatch_write(struct file
*file
, const char __user
*userbuf
,
959 unsigned long count
, void *data
)
961 struct ibm_struct
*ibm
= (struct ibm_struct
*)data
;
965 if (!ibm
|| !ibm
->write
)
968 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
972 if (copy_from_user(kernbuf
, userbuf
, count
)) {
978 strcat(kernbuf
, ",");
979 ret
= ibm
->write(ibm
, kernbuf
);
988 static void dispatch_notify(acpi_handle handle
, u32 event
, void *data
)
990 struct ibm_struct
*ibm
= (struct ibm_struct
*)data
;
992 if (!ibm
|| !ibm
->notify
)
995 ibm
->notify(ibm
, event
);
998 static int setup_notify(struct ibm_struct
*ibm
)
1006 ret
= acpi_bus_get_device(*ibm
->handle
, &ibm
->device
);
1008 printk(IBM_ERR
"%s device not present\n", ibm
->name
);
1012 acpi_driver_data(ibm
->device
) = ibm
;
1013 sprintf(acpi_device_class(ibm
->device
), "%s/%s", IBM_NAME
, ibm
->name
);
1015 status
= acpi_install_notify_handler(*ibm
->handle
, ibm
->type
,
1016 dispatch_notify
, ibm
);
1017 if (ACPI_FAILURE(status
)) {
1018 printk(IBM_ERR
"acpi_install_notify_handler(%s) failed: %d\n",
1023 ibm
->notify_installed
= 1;
1028 static int device_add(struct acpi_device
*device
)
1033 static int register_driver(struct ibm_struct
*ibm
)
1037 ibm
->driver
= kmalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
1039 printk(IBM_ERR
"kmalloc(ibm->driver) failed\n");
1043 memset(ibm
->driver
, 0, sizeof(struct acpi_driver
));
1044 sprintf(ibm
->driver
->name
, "%s/%s", IBM_NAME
, ibm
->name
);
1045 ibm
->driver
->ids
= ibm
->hid
;
1046 ibm
->driver
->ops
.add
= &device_add
;
1048 ret
= acpi_bus_register_driver(ibm
->driver
);
1050 printk(IBM_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
1058 static int ibm_init(struct ibm_struct
*ibm
)
1061 struct proc_dir_entry
*entry
;
1063 if (ibm
->experimental
&& !experimental
)
1067 ret
= register_driver(ibm
);
1070 ibm
->driver_registered
= 1;
1074 ret
= ibm
->init(ibm
);
1077 ibm
->init_called
= 1;
1080 entry
= create_proc_entry(ibm
->name
, S_IFREG
| S_IRUGO
| S_IWUSR
,
1083 printk(IBM_ERR
"unable to create proc entry %s\n", ibm
->name
);
1086 entry
->owner
= THIS_MODULE
;
1087 ibm
->proc_created
= 1;
1091 entry
->read_proc
= &dispatch_read
;
1093 entry
->write_proc
= &dispatch_write
;
1096 ret
= setup_notify(ibm
);
1104 static void ibm_exit(struct ibm_struct
*ibm
)
1106 if (ibm
->notify_installed
)
1107 acpi_remove_notify_handler(*ibm
->handle
, ibm
->type
,
1110 if (ibm
->proc_created
)
1111 remove_proc_entry(ibm
->name
, proc_dir
);
1113 if (ibm
->init_called
&& ibm
->exit
)
1116 if (ibm
->driver_registered
) {
1117 acpi_bus_unregister_driver(ibm
->driver
);
1122 static int ibm_handle_init(char *name
,
1123 acpi_handle
*handle
, acpi_handle parent
,
1124 char **paths
, int num_paths
, int required
)
1129 for (i
=0; i
<num_paths
; i
++) {
1130 status
= acpi_get_handle(parent
, paths
[i
], handle
);
1131 if (ACPI_SUCCESS(status
))
1138 printk(IBM_ERR
"%s object not found\n", name
);
1145 #define IBM_HANDLE_INIT(object, required) \
1146 ibm_handle_init(#object, &object##_handle, *object##_parent, \
1147 object##_paths, sizeof(object##_paths)/sizeof(char*), required)
1150 static int set_ibm_param(const char *val
, struct kernel_param
*kp
)
1153 char arg_with_comma
[32];
1155 if (strlen(val
) > 30)
1158 strcpy(arg_with_comma
, val
);
1159 strcat(arg_with_comma
, ",");
1161 for (i
=0; i
<NUM_IBMS
; i
++)
1162 if (strcmp(ibms
[i
].name
, kp
->name
) == 0)
1163 return ibms
[i
].write(&ibms
[i
], arg_with_comma
);
1168 #define IBM_PARAM(feature) \
1169 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
1171 static void acpi_ibm_exit(void)
1175 for (i
=NUM_IBMS
-1; i
>=0; i
--)
1178 remove_proc_entry(IBM_DIR
, acpi_root_dir
);
1181 static int __init
acpi_ibm_init(void)
1188 /* these handles are required */
1189 if (IBM_HANDLE_INIT(ec
, 1) < 0 ||
1190 IBM_HANDLE_INIT(hkey
, 1) < 0 ||
1191 IBM_HANDLE_INIT(vid
, 1) < 0 ||
1192 IBM_HANDLE_INIT(beep
, 1) < 0)
1195 /* these handles have alternatives */
1196 IBM_HANDLE_INIT(lght
, 0);
1197 if (IBM_HANDLE_INIT(cmos
, !lght_handle
) < 0)
1199 IBM_HANDLE_INIT(sysl
, 0);
1200 if (IBM_HANDLE_INIT(led
, !sysl_handle
) < 0)
1203 /* these handles are not required */
1204 IBM_HANDLE_INIT(dock
, 0);
1205 IBM_HANDLE_INIT(bay
, 0);
1206 IBM_HANDLE_INIT(bayej
, 0);
1207 IBM_HANDLE_INIT(bled
, 0);
1209 proc_dir
= proc_mkdir(IBM_DIR
, acpi_root_dir
);
1211 printk(IBM_ERR
"unable to create proc dir %s", IBM_DIR
);
1214 proc_dir
->owner
= THIS_MODULE
;
1216 for (i
=0; i
<NUM_IBMS
; i
++) {
1217 ret
= ibm_init(&ibms
[i
]);
1227 module_init(acpi_ibm_init
);
1228 module_exit(acpi_ibm_exit
);
1230 MODULE_AUTHOR("Borislav Deianov");
1231 MODULE_DESCRIPTION(IBM_DESC
);
1232 MODULE_LICENSE("GPL");
1235 IBM_PARAM(bluetooth
);