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 }
89 IBM_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC", /* A21e, A22p, T20, T21, X20 */
90 "\\_SB.PCI0.LPC.EC", /* all others */
93 IBM_HANDLE(vid, root, "\\_SB.PCI0.VID", /* A21e, G40, X30, X40 */
94 "\\_SB.PCI0.AGP.VID", /* all others */
97 IBM_HANDLE(cmos, root, "\\UCMS", /* R50, R50p, R51, T4x, X31, X40 */
98 "\\CMOS", /* A3x, G40, R32, T23, T30, X22, X24, X30 */
99 "\\CMS", /* R40, R40e */
100 ); /* A21e, A22p, T20, T21, X20 */
102 IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */
103 "\\_SB.PCI0.DOCK", /* A22p, T20, T21, X20 */
104 "\\_SB.PCI0.PCI1.DOCK", /* all others */
105 ); /* A21e, G40, R32, R40, R40e */
107 IBM_HANDLE(bay, root, "\\_SB.PCI0.IDE0.SCND.MSTR"); /* all except A21e */
108 IBM_HANDLE(bayej, root, "\\_SB.PCI0.IDE0.SCND.MSTR._EJ0"); /* all except A2x, A3x */
110 IBM_HANDLE(lght, root, "\\LGHT"); /* A21e, A22p, T20, T21, X20 */
111 IBM_HANDLE(hkey, ec, "HKEY"); /* all */
112 IBM_HANDLE(led, ec, "LED"); /* all except A21e, A22p, T20, T21, X20 */
113 IBM_HANDLE(sysl, ec, "SYSL"); /* A21e, A22p, T20, T21, X20 */
114 IBM_HANDLE(bled, ec, "BLED"); /* A22p, T20, T21, X20 */
115 IBM_HANDLE(beep, ec, "BEEP"); /* all models */
121 struct acpi_driver *driver;
123 int (*init) (struct ibm_struct *);
124 int (*read) (struct ibm_struct *, char *);
125 int (*write) (struct ibm_struct *, char *);
126 void (*exit) (struct ibm_struct *);
128 void (*notify) (struct ibm_struct *, u32);
131 struct acpi_device *device;
133 int driver_registered;
136 int notify_installed;
152 static struct proc_dir_entry *proc_dir = NULL;
154 #define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off")
155 #define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
156 #define strlencmp(a,b) (strncmp((a), (b), strlen(b)))
158 static int acpi_evalf(acpi_handle handle,
159 void *res, char *method, char *fmt, ...)
162 struct acpi_object_list params;
163 union acpi_object in_objs[IBM_MAX_ACPI_ARGS];
164 struct acpi_buffer result;
165 union acpi_object out_obj;
173 printk(IBM_ERR "acpi_evalf() called with empty format\n");
186 params.pointer = &in_objs[0];
193 in_objs[params.count].integer.value = va_arg(ap, int);
194 in_objs[params.count++].type = ACPI_TYPE_INTEGER;
196 /* add more types as needed */
198 printk(IBM_ERR "acpi_evalf() called "
199 "with invalid format character '%c'\n", c);
205 result.length = sizeof(out_obj);
206 result.pointer = &out_obj;
208 status = acpi_evaluate_object(handle, method, ¶ms, &result);
213 *(int *)res = out_obj.integer.value;
214 success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER;
217 success = status == AE_OK;
219 /* add more types as needed */
221 printk(IBM_ERR "acpi_evalf() called "
222 "with invalid format character '%c'\n", res_type);
226 if (!success && !quiet)
227 printk(IBM_ERR "acpi_evalf(%s, %s, ...) failed: %d\n",
228 method, fmt0, status);
233 static void __unused acpi_print_int(acpi_handle handle, char *method)
237 if (acpi_evalf(handle, &i, method, "d"))
238 printk(IBM_INFO "%s = 0x%x\n", method, i);
240 printk(IBM_ERR "error calling %s\n", method);
243 static char *next_cmd(char **cmds)
248 while ((end = strchr(start, ',')) && end == start)
259 static int driver_init(struct ibm_struct *ibm)
261 printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION);
262 printk(IBM_INFO "%s\n", IBM_URL);
267 static int driver_read(struct ibm_struct *ibm, char *p)
271 len += sprintf(p + len, "driver:\t\t%s\n", IBM_DESC);
272 len += sprintf(p + len, "version:\t%s\n", IBM_VERSION);
277 static int hotkey_get(struct ibm_struct *ibm, int *status, int *mask)
279 if (!acpi_evalf(hkey_handle, status, "DHKC", "d"))
281 if (ibm->supported) {
282 if (!acpi_evalf(hkey_handle, mask, "DHKN", "qd"))
285 *mask = ibm->state.hotkey.mask;
290 static int hotkey_set(struct ibm_struct *ibm, int status, int mask)
294 if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status))
300 for (i = 0; i < 32; i++) {
301 int bit = ((1 << i) & mask) != 0;
302 if (!acpi_evalf(hkey_handle, NULL, "MHKM", "vdd", i + 1, bit))
309 static int hotkey_init(struct ibm_struct *ibm)
314 ret = hotkey_get(ibm,
315 &ibm->state.hotkey.status, &ibm->state.hotkey.mask);
317 /* mask not supported on A21e, A22p, T20, T21, X20, X22, X24 */
319 ret = hotkey_get(ibm,
320 &ibm->state.hotkey.status,
321 &ibm->state.hotkey.mask);
327 static int hotkey_read(struct ibm_struct *ibm, char *p)
332 if (hotkey_get(ibm, &status, &mask) < 0)
335 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0));
336 if (ibm->supported) {
337 len += sprintf(p + len, "mask:\t\t0x%04x\n", mask);
338 len += sprintf(p + len,
339 "commands:\tenable, disable, reset, <mask>\n");
341 len += sprintf(p + len, "mask:\t\tnot supported\n");
342 len += sprintf(p + len, "commands:\tenable, disable, reset\n");
348 static int hotkey_write(struct ibm_struct *ibm, char *buf)
354 if (hotkey_get(ibm, &status, &mask) < 0)
357 while ((cmd = next_cmd(&buf))) {
358 if (strlencmp(cmd, "enable") == 0) {
360 } else if (strlencmp(cmd, "disable") == 0) {
362 } else if (strlencmp(cmd, "reset") == 0) {
363 status = ibm->state.hotkey.status;
364 mask = ibm->state.hotkey.mask;
365 } else if (sscanf(cmd, "0x%x", &mask) == 1) {
367 } else if (sscanf(cmd, "%x", &mask) == 1) {
374 if (do_cmd && hotkey_set(ibm, status, mask) < 0)
380 static void hotkey_exit(struct ibm_struct *ibm)
382 hotkey_set(ibm, ibm->state.hotkey.status, ibm->state.hotkey.mask);
385 static void hotkey_notify(struct ibm_struct *ibm, u32 event)
389 if (acpi_evalf(hkey_handle, &hkey, "MHKP", "d"))
390 acpi_bus_generate_event(ibm->device, event, hkey);
392 printk(IBM_ERR "unknown hotkey event %d\n", event);
393 acpi_bus_generate_event(ibm->device, event, 0);
397 static int bluetooth_init(struct ibm_struct *ibm)
399 /* bluetooth not supported on A21e, G40, T20, T21, X20 */
400 ibm->supported = acpi_evalf(hkey_handle, NULL, "GBDC", "qv");
405 static int bluetooth_status(struct ibm_struct *ibm)
409 if (!ibm->supported || !acpi_evalf(hkey_handle, &status, "GBDC", "d"))
415 static int bluetooth_read(struct ibm_struct *ibm, char *p)
418 int status = bluetooth_status(ibm);
421 len += sprintf(p + len, "status:\t\tnot supported\n");
422 else if (!(status & 1))
423 len += sprintf(p + len, "status:\t\tnot installed\n");
425 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 1));
426 len += sprintf(p + len, "commands:\tenable, disable\n");
432 static int bluetooth_write(struct ibm_struct *ibm, char *buf)
434 int status = bluetooth_status(ibm);
441 while ((cmd = next_cmd(&buf))) {
442 if (strlencmp(cmd, "enable") == 0) {
444 } else if (strlencmp(cmd, "disable") == 0) {
451 if (do_cmd && !acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status))
457 static int video_init(struct ibm_struct *ibm)
459 if (!acpi_evalf(vid_handle, &ibm->state.video.autoswitch, "^VDEE", "d"))
465 static int video_status(struct ibm_struct *ibm)
470 acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1);
471 if (acpi_evalf(NULL, &i, "\\VCDC", "d"))
474 acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0);
475 if (acpi_evalf(NULL, &i, "\\VCDL", "d"))
477 if (acpi_evalf(NULL, &i, "\\VCDD", "d"))
480 if (acpi_evalf(vid_handle, &i, "^VDEE", "d"))
481 status |= 0x10 * (i & 1);
486 static int video_read(struct ibm_struct *ibm, char *p)
488 int status = video_status(ibm);
491 len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0));
492 len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1));
493 len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3));
494 len += sprintf(p + len, "auto:\t\t%s\n", enabled(status, 4));
495 len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable, "
496 "crt_enable, crt_disable\n");
497 len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable, "
498 "auto_enable, auto_disable\n");
499 len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n");
504 static int video_write(struct ibm_struct *ibm, char *buf)
507 int enable, disable, status;
509 enable = disable = 0;
511 while ((cmd = next_cmd(&buf))) {
512 if (strlencmp(cmd, "lcd_enable") == 0) {
514 } else if (strlencmp(cmd, "lcd_disable") == 0) {
516 } else if (strlencmp(cmd, "crt_enable") == 0) {
518 } else if (strlencmp(cmd, "crt_disable") == 0) {
520 } else if (strlencmp(cmd, "dvi_enable") == 0) {
522 } else if (strlencmp(cmd, "dvi_disable") == 0) {
524 } else if (strlencmp(cmd, "auto_enable") == 0) {
525 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
527 } else if (strlencmp(cmd, "auto_disable") == 0) {
528 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 0))
530 } else if (strlencmp(cmd, "video_switch") == 0) {
532 if (!acpi_evalf(vid_handle, &autoswitch, "^VDEE", "d"))
534 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
536 if (!acpi_evalf(vid_handle, NULL, "VSWT", "v"))
538 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd",
541 } else if (strlencmp(cmd, "expand_toggle") == 0) {
542 if (!acpi_evalf(NULL, NULL, "\\VEXP", "v"))
548 if (enable || disable) {
549 status = (video_status(ibm) & 0x0f & ~disable) | enable;
550 if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80))
552 if (!acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1))
559 static void video_exit(struct ibm_struct *ibm)
561 acpi_evalf(vid_handle, NULL, "_DOS", "vd", ibm->state.video.autoswitch);
564 static int light_init(struct ibm_struct *ibm)
566 /* kblt not supported on G40, R32, X20 */
567 ibm->supported = acpi_evalf(ec_handle, NULL, "KBLT", "qv");
572 static int light_read(struct ibm_struct *ibm, char *p)
577 if (ibm->supported) {
578 if (!acpi_evalf(ec_handle, &status, "KBLT", "d"))
580 len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0));
582 len += sprintf(p + len, "status:\t\tunknown\n");
584 len += sprintf(p + len, "commands:\ton, off\n");
589 static int light_write(struct ibm_struct *ibm, char *buf)
591 int cmos_cmd, lght_cmd;
595 while ((cmd = next_cmd(&buf))) {
596 if (strlencmp(cmd, "on") == 0) {
599 } else if (strlencmp(cmd, "off") == 0) {
605 success = cmos_handle ?
606 acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd) :
607 acpi_evalf(lght_handle, NULL, NULL, "vd", lght_cmd);
615 static int _sta(acpi_handle handle)
619 if (!handle || !acpi_evalf(handle, &status, "_STA", "d"))
625 #define dock_docked() (_sta(dock_handle) & 1)
627 static int dock_read(struct ibm_struct *ibm, char *p)
630 int docked = dock_docked();
633 len += sprintf(p + len, "status:\t\tnot supported\n");
635 len += sprintf(p + len, "status:\t\tundocked\n");
637 len += sprintf(p + len, "status:\t\tdocked\n");
638 len += sprintf(p + len, "commands:\tdock, undock\n");
644 static int dock_write(struct ibm_struct *ibm, char *buf)
651 while ((cmd = next_cmd(&buf))) {
652 if (strlencmp(cmd, "undock") == 0) {
653 if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0))
655 if (!acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1))
657 } else if (strlencmp(cmd, "dock") == 0) {
658 if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1))
667 static void dock_notify(struct ibm_struct *ibm, u32 event)
669 int docked = dock_docked();
671 if (event == 3 && docked)
672 acpi_bus_generate_event(ibm->device, event, 1); /* button */
673 else if (event == 3 && !docked)
674 acpi_bus_generate_event(ibm->device, event, 2); /* undock */
675 else if (event == 0 && docked)
676 acpi_bus_generate_event(ibm->device, event, 3); /* dock */
678 printk(IBM_ERR "unknown dock event %d, status %d\n",
679 event, _sta(dock_handle));
680 acpi_bus_generate_event(ibm->device, event, 0); /* unknown */
684 #define bay_occupied() (_sta(bay_handle) & 1)
686 static int bay_init(struct ibm_struct *ibm)
688 /* bay not supported on A21e, A22p, A31, A31p, G40, R32, R40e */
689 ibm->supported = bay_handle && bayej_handle &&
690 acpi_evalf(bay_handle, NULL, "_STA", "qv");
695 static int bay_read(struct ibm_struct *ibm, char *p)
698 int occupied = bay_occupied();
701 len += sprintf(p + len, "status:\t\tnot supported\n");
703 len += sprintf(p + len, "status:\t\tunoccupied\n");
705 len += sprintf(p + len, "status:\t\toccupied\n");
706 len += sprintf(p + len, "commands:\teject\n");
712 static int bay_write(struct ibm_struct *ibm, char *buf)
716 while ((cmd = next_cmd(&buf))) {
717 if (strlencmp(cmd, "eject") == 0) {
718 if (!ibm->supported ||
719 !acpi_evalf(bay_handle, NULL, "_EJ0", "vd", 1))
728 static void bay_notify(struct ibm_struct *ibm, u32 event)
730 acpi_bus_generate_event(ibm->device, event, 0);
733 static int cmos_read(struct ibm_struct *ibm, char *p)
737 /* cmos not supported on A21e, A22p, T20, T21, X20 */
739 len += sprintf(p + len, "status:\t\tnot supported\n");
741 len += sprintf(p + len, "status:\t\tsupported\n");
742 len += sprintf(p + len, "commands:\t<int>\n");
748 static int cmos_write(struct ibm_struct *ibm, char *buf)
756 while ((cmd = next_cmd(&buf))) {
757 if (sscanf(cmd, "%u", &cmos_cmd) == 1) {
762 if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd))
769 static int led_read(struct ibm_struct *ibm, char *p)
773 len += sprintf(p + len, "commands:\t"
774 "<int> on, <int> off, <int> blink\n");
779 static int led_write(struct ibm_struct *ibm, char *buf)
783 int led_cmd, sysl_cmd, bled_a, bled_b;
785 while ((cmd = next_cmd(&buf))) {
786 if (sscanf(cmd, "%u", &led) != 1)
789 if (strstr(cmd, "blink")) {
794 } else if (strstr(cmd, "on")) {
799 } else if (strstr(cmd, "off")) {
800 led_cmd = sysl_cmd = bled_a = bled_b = 0;
805 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
808 } else if (led < 2) {
809 if (acpi_evalf(sysl_handle, NULL, NULL, "vdd",
812 } else if (led == 2 && bled_handle) {
813 if (acpi_evalf(bled_handle, NULL, NULL, "vdd",
823 static int beep_read(struct ibm_struct *ibm, char *p)
827 len += sprintf(p + len, "commands:\t<int>\n");
832 static int beep_write(struct ibm_struct *ibm, char *buf)
837 while ((cmd = next_cmd(&buf))) {
838 if (sscanf(cmd, "%u", &beep_cmd) == 1) {
843 if (!acpi_evalf(beep_handle, NULL, NULL, "vd", beep_cmd))
850 static struct ibm_struct ibms[] = {
861 .write = hotkey_write,
863 .notify = hotkey_notify,
864 .handle = &hkey_handle,
865 .type = ACPI_DEVICE_NOTIFY,
869 .init = bluetooth_init,
870 .read = bluetooth_read,
871 .write = bluetooth_write,
877 .write = video_write,
884 .write = light_write,
890 .notify = dock_notify,
891 .handle = &dock_handle,
892 .type = ACPI_SYSTEM_NOTIFY,
899 .notify = bay_notify,
900 .handle = &bay_handle,
901 .type = ACPI_SYSTEM_NOTIFY,
923 #define NUM_IBMS (sizeof(ibms)/sizeof(ibms[0]))
925 static int dispatch_read(char *page, char **start, off_t off, int count,
926 int *eof, void *data)
928 struct ibm_struct *ibm = (struct ibm_struct *)data;
931 if (!ibm || !ibm->read)
934 len = ibm->read(ibm, page);
938 if (len <= off + count)
950 static int dispatch_write(struct file *file, const char __user * userbuf,
951 unsigned long count, void *data)
953 struct ibm_struct *ibm = (struct ibm_struct *)data;
957 if (!ibm || !ibm->write)
960 kernbuf = kmalloc(count + 2, GFP_KERNEL);
964 if (copy_from_user(kernbuf, userbuf, count)) {
970 strcat(kernbuf, ",");
971 ret = ibm->write(ibm, kernbuf);
980 static void dispatch_notify(acpi_handle handle, u32 event, void *data)
982 struct ibm_struct *ibm = (struct ibm_struct *)data;
984 if (!ibm || !ibm->notify)
987 ibm->notify(ibm, event);
990 static int setup_notify(struct ibm_struct *ibm)
998 ret = acpi_bus_get_device(*ibm->handle, &ibm->device);
1000 printk(IBM_ERR "%s device not present\n", ibm->name);
1004 acpi_driver_data(ibm->device) = ibm;
1005 sprintf(acpi_device_class(ibm->device), "%s/%s", IBM_NAME, ibm->name);
1007 status = acpi_install_notify_handler(*ibm->handle, ibm->type,
1008 dispatch_notify, ibm);
1009 if (ACPI_FAILURE(status)) {
1010 printk(IBM_ERR "acpi_install_notify_handler(%s) failed: %d\n",
1015 ibm->notify_installed = 1;
1020 static int ibmacpi_device_add(struct acpi_device *device)
1025 static int register_driver(struct ibm_struct *ibm)
1029 ibm->driver = kmalloc(sizeof(struct acpi_driver), GFP_KERNEL);
1031 printk(IBM_ERR "kmalloc(ibm->driver) failed\n");
1035 memset(ibm->driver, 0, sizeof(struct acpi_driver));
1036 sprintf(ibm->driver->name, "%s/%s", IBM_NAME, ibm->name);
1037 ibm->driver->ids = ibm->hid;
1038 ibm->driver->ops.add = &ibmacpi_device_add;
1040 ret = acpi_bus_register_driver(ibm->driver);
1042 printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n",
1050 static int ibm_init(struct ibm_struct *ibm)
1053 struct proc_dir_entry *entry;
1055 if (ibm->experimental && !experimental)
1059 ret = register_driver(ibm);
1062 ibm->driver_registered = 1;
1066 ret = ibm->init(ibm);
1069 ibm->init_called = 1;
1072 entry = create_proc_entry(ibm->name, S_IFREG | S_IRUGO | S_IWUSR,
1075 printk(IBM_ERR "unable to create proc entry %s\n", ibm->name);
1078 entry->owner = THIS_MODULE;
1079 ibm->proc_created = 1;
1083 entry->read_proc = &dispatch_read;
1085 entry->write_proc = &dispatch_write;
1088 ret = setup_notify(ibm);
1096 static void ibm_exit(struct ibm_struct *ibm)
1098 if (ibm->notify_installed)
1099 acpi_remove_notify_handler(*ibm->handle, ibm->type,
1102 if (ibm->proc_created)
1103 remove_proc_entry(ibm->name, proc_dir);
1105 if (ibm->init_called && ibm->exit)
1108 if (ibm->driver_registered) {
1109 acpi_bus_unregister_driver(ibm->driver);
1114 static int ibm_handle_init(char *name,
1115 acpi_handle * handle, acpi_handle parent,
1116 char **paths, int num_paths, int required)
1121 for (i = 0; i < num_paths; i++) {
1122 status = acpi_get_handle(parent, paths[i], handle);
1123 if (ACPI_SUCCESS(status))
1130 printk(IBM_ERR "%s object not found\n", name);
1137 #define IBM_HANDLE_INIT(object, required) \
1138 ibm_handle_init(#object, &object##_handle, *object##_parent, \
1139 object##_paths, sizeof(object##_paths)/sizeof(char*), required)
1141 static int set_ibm_param(const char *val, struct kernel_param *kp)
1144 char arg_with_comma[32];
1146 if (strlen(val) > 30)
1149 strcpy(arg_with_comma, val);
1150 strcat(arg_with_comma, ",");
1152 for (i = 0; i < NUM_IBMS; i++)
1153 if (strcmp(ibms[i].name, kp->name) == 0)
1154 return ibms[i].write(&ibms[i], arg_with_comma);
1159 #define IBM_PARAM(feature) \
1160 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
1162 static void acpi_ibm_exit(void)
1166 for (i = NUM_IBMS - 1; i >= 0; i--)
1169 remove_proc_entry(IBM_DIR, acpi_root_dir);
1172 static int __init acpi_ibm_init(void)
1179 if (!acpi_specific_hotkey_enabled) {
1180 printk(IBM_ERR "Using generic hotkey driver\n");
1183 /* these handles are required */
1184 if (IBM_HANDLE_INIT(ec, 1) < 0 ||
1185 IBM_HANDLE_INIT(hkey, 1) < 0 ||
1186 IBM_HANDLE_INIT(vid, 1) < 0 || IBM_HANDLE_INIT(beep, 1) < 0)
1189 /* these handles have alternatives */
1190 IBM_HANDLE_INIT(lght, 0);
1191 if (IBM_HANDLE_INIT(cmos, !lght_handle) < 0)
1193 IBM_HANDLE_INIT(sysl, 0);
1194 if (IBM_HANDLE_INIT(led, !sysl_handle) < 0)
1197 /* these handles are not required */
1198 IBM_HANDLE_INIT(dock, 0);
1199 IBM_HANDLE_INIT(bay, 0);
1200 IBM_HANDLE_INIT(bayej, 0);
1201 IBM_HANDLE_INIT(bled, 0);
1203 proc_dir = proc_mkdir(IBM_DIR, acpi_root_dir);
1205 printk(IBM_ERR "unable to create proc dir %s", IBM_DIR);
1208 proc_dir->owner = THIS_MODULE;
1210 for (i = 0; i < NUM_IBMS; i++) {
1211 ret = ibm_init(&ibms[i]);
1221 module_init(acpi_ibm_init);
1222 module_exit(acpi_ibm_exit);
1224 MODULE_AUTHOR("Borislav Deianov");
1225 MODULE_DESCRIPTION(IBM_DESC);
1226 MODULE_LICENSE("GPL");
1229 IBM_PARAM(bluetooth);