ACPI: thinkpad-acpi: use bitfields for module flags
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / misc / thinkpad_acpi.c
blob14f2751eaa32f6f1349950e4da4b36667a9d00e2
1 /*
2 * thinkpad_acpi.c - ThinkPad ACPI Extras
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006-2007 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 * 02110-1301, USA.
24 #define IBM_VERSION "0.14"
27 * Changelog:
28 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
29 * drivers/misc.
31 * 2006-11-22 0.13 new maintainer
32 * changelog now lives in git commit history, and will
33 * not be updated further in-file.
35 * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels
36 * 2005-03-17 0.11 support for 600e, 770x
37 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
38 * support for 770e, G41
39 * G40 and G41 don't have a thinklight
40 * temperatures no longer experimental
41 * experimental brightness control
42 * experimental volume control
43 * experimental fan enable/disable
44 * 2005-01-16 0.10 fix module loading on R30, R31
45 * 2005-01-16 0.9 support for 570, R30, R31
46 * ultrabay support on A22p, A3x
47 * limit arg for cmos, led, beep, drop experimental status
48 * more capable led control on A21e, A22p, T20-22, X20
49 * experimental temperatures and fan speed
50 * experimental embedded controller register dump
51 * mark more functions as __init, drop incorrect __exit
52 * use MODULE_VERSION
53 * thanks to Henrik Brix Andersen <brix@gentoo.org>
54 * fix parameter passing on module loading
55 * thanks to Rusty Russell <rusty@rustcorp.com.au>
56 * thanks to Jim Radford <radford@blackbean.org>
57 * 2004-11-08 0.8 fix init error case, don't return from a macro
58 * thanks to Chris Wright <chrisw@osdl.org>
59 * 2004-10-23 0.7 fix module loading on A21e, A22p, T20, T21, X20
60 * fix led control on A21e
61 * 2004-10-19 0.6 use acpi_bus_register_driver() to claim HKEY device
62 * 2004-10-18 0.5 thinklight support on A21e, G40, R32, T20, T21, X20
63 * proc file format changed
64 * video_switch command
65 * experimental cmos control
66 * experimental led control
67 * experimental acpi sounds
68 * 2004-09-16 0.4 support for module parameters
69 * hotkey mask can be prefixed by 0x
70 * video output switching
71 * video expansion control
72 * ultrabay eject support
73 * removed lcd brightness/on/off control, didn't work
74 * 2004-08-17 0.3 support for R40
75 * lcd off, brightness control
76 * thinklight on/off
77 * 2004-08-14 0.2 support for T series, X20
78 * bluetooth enable/disable
79 * hotkey events disabled by default
80 * removed fan control, currently useless
81 * 2004-08-09 0.1 initial release, support for X series
84 #include "thinkpad_acpi.h"
86 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
87 MODULE_DESCRIPTION(IBM_DESC);
88 MODULE_VERSION(IBM_VERSION);
89 MODULE_LICENSE("GPL");
91 /* Please remove this in year 2009 */
92 MODULE_ALIAS("ibm_acpi");
94 #define __unused __attribute__ ((unused))
96 /****************************************************************************
97 ****************************************************************************
99 * ACPI Helpers and device model
101 ****************************************************************************
102 ****************************************************************************/
104 /*************************************************************************
105 * ACPI basic handles
108 static acpi_handle root_handle = NULL;
110 #define IBM_HANDLE(object, parent, paths...) \
111 static acpi_handle object##_handle; \
112 static acpi_handle *object##_parent = &parent##_handle; \
113 static char *object##_path; \
114 static char *object##_paths[] = { paths }
116 IBM_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
117 "\\_SB.PCI.ISA.EC", /* 570 */
118 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
119 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
120 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
121 "\\_SB.PCI0.ICH3.EC0", /* R31 */
122 "\\_SB.PCI0.LPC.EC", /* all others */
125 IBM_HANDLE(ecrd, ec, "ECRD"); /* 570 */
126 IBM_HANDLE(ecwr, ec, "ECWR"); /* 570 */
129 /*************************************************************************
130 * Misc ACPI handles
133 IBM_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
134 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
135 "\\CMS", /* R40, R40e */
136 ); /* all others */
138 IBM_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
139 "^HKEY", /* R30, R31 */
140 "HKEY", /* all others */
141 ); /* 570 */
144 /*************************************************************************
145 * ACPI helpers
148 static int acpi_evalf(acpi_handle handle,
149 void *res, char *method, char *fmt, ...)
151 char *fmt0 = fmt;
152 struct acpi_object_list params;
153 union acpi_object in_objs[IBM_MAX_ACPI_ARGS];
154 struct acpi_buffer result, *resultp;
155 union acpi_object out_obj;
156 acpi_status status;
157 va_list ap;
158 char res_type;
159 int success;
160 int quiet;
162 if (!*fmt) {
163 printk(IBM_ERR "acpi_evalf() called with empty format\n");
164 return 0;
167 if (*fmt == 'q') {
168 quiet = 1;
169 fmt++;
170 } else
171 quiet = 0;
173 res_type = *(fmt++);
175 params.count = 0;
176 params.pointer = &in_objs[0];
178 va_start(ap, fmt);
179 while (*fmt) {
180 char c = *(fmt++);
181 switch (c) {
182 case 'd': /* int */
183 in_objs[params.count].integer.value = va_arg(ap, int);
184 in_objs[params.count++].type = ACPI_TYPE_INTEGER;
185 break;
186 /* add more types as needed */
187 default:
188 printk(IBM_ERR "acpi_evalf() called "
189 "with invalid format character '%c'\n", c);
190 return 0;
193 va_end(ap);
195 if (res_type != 'v') {
196 result.length = sizeof(out_obj);
197 result.pointer = &out_obj;
198 resultp = &result;
199 } else
200 resultp = NULL;
202 status = acpi_evaluate_object(handle, method, &params, resultp);
204 switch (res_type) {
205 case 'd': /* int */
206 if (res)
207 *(int *)res = out_obj.integer.value;
208 success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER;
209 break;
210 case 'v': /* void */
211 success = status == AE_OK;
212 break;
213 /* add more types as needed */
214 default:
215 printk(IBM_ERR "acpi_evalf() called "
216 "with invalid format character '%c'\n", res_type);
217 return 0;
220 if (!success && !quiet)
221 printk(IBM_ERR "acpi_evalf(%s, %s, ...) failed: %d\n",
222 method, fmt0, status);
224 return success;
227 static void __unused acpi_print_int(acpi_handle handle, char *method)
229 int i;
231 if (acpi_evalf(handle, &i, method, "d"))
232 printk(IBM_INFO "%s = 0x%x\n", method, i);
233 else
234 printk(IBM_ERR "error calling %s\n", method);
237 static int acpi_ec_read(int i, u8 * p)
239 int v;
241 if (ecrd_handle) {
242 if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i))
243 return 0;
244 *p = v;
245 } else {
246 if (ec_read(i, p) < 0)
247 return 0;
250 return 1;
253 static int acpi_ec_write(int i, u8 v)
255 if (ecwr_handle) {
256 if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v))
257 return 0;
258 } else {
259 if (ec_write(i, v) < 0)
260 return 0;
263 return 1;
266 static int _sta(acpi_handle handle)
268 int status;
270 if (!handle || !acpi_evalf(handle, &status, "_STA", "d"))
271 status = 0;
273 return status;
276 /*************************************************************************
277 * ACPI device model
280 static void ibm_handle_init(char *name,
281 acpi_handle *handle, acpi_handle parent,
282 char **paths, int num_paths, char **path)
284 int i;
285 acpi_status status;
287 for (i = 0; i < num_paths; i++) {
288 status = acpi_get_handle(parent, paths[i], handle);
289 if (ACPI_SUCCESS(status)) {
290 *path = paths[i];
291 return;
295 *handle = NULL;
298 static void dispatch_notify(acpi_handle handle, u32 event, void *data)
300 struct ibm_struct *ibm = data;
302 if (!ibm || !ibm->notify)
303 return;
305 ibm->notify(ibm, event);
308 static int __init setup_notify(struct ibm_struct *ibm)
310 acpi_status status;
311 int ret;
313 if (!*ibm->handle)
314 return 0;
316 dbg_printk(TPACPI_DBG_INIT,
317 "setting up ACPI notify for %s\n", ibm->name);
319 ret = acpi_bus_get_device(*ibm->handle, &ibm->device);
320 if (ret < 0) {
321 printk(IBM_ERR "%s device not present\n", ibm->name);
322 return -ENODEV;
325 acpi_driver_data(ibm->device) = ibm;
326 sprintf(acpi_device_class(ibm->device), "%s/%s",
327 IBM_ACPI_EVENT_PREFIX,
328 ibm->name);
330 status = acpi_install_notify_handler(*ibm->handle, ibm->type,
331 dispatch_notify, ibm);
332 if (ACPI_FAILURE(status)) {
333 if (status == AE_ALREADY_EXISTS) {
334 printk(IBM_NOTICE "another device driver is already handling %s events\n",
335 ibm->name);
336 } else {
337 printk(IBM_ERR "acpi_install_notify_handler(%s) failed: %d\n",
338 ibm->name, status);
340 return -ENODEV;
342 ibm->flags.notify_installed = 1;
343 return 0;
346 static int __init ibm_device_add(struct acpi_device *device)
348 return 0;
351 static int __init register_tpacpi_subdriver(struct ibm_struct *ibm)
353 int ret;
355 dbg_printk(TPACPI_DBG_INIT,
356 "registering %s as an ACPI driver\n", ibm->name);
358 ibm->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL);
359 if (!ibm->driver) {
360 printk(IBM_ERR "kzalloc(ibm->driver) failed\n");
361 return -ENOMEM;
364 sprintf(ibm->driver->name, "%s_%s", IBM_NAME, ibm->name);
365 ibm->driver->ids = ibm->hid;
366 ibm->driver->ops.add = &ibm_device_add;
368 ret = acpi_bus_register_driver(ibm->driver);
369 if (ret < 0) {
370 printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n",
371 ibm->hid, ret);
372 kfree(ibm->driver);
373 ibm->driver = NULL;
374 } else if (!ret)
375 ibm->flags.driver_registered = 1;
377 return ret;
381 /****************************************************************************
382 ****************************************************************************
384 * Procfs Helpers
386 ****************************************************************************
387 ****************************************************************************/
389 static int dispatch_read(char *page, char **start, off_t off, int count,
390 int *eof, void *data)
392 struct ibm_struct *ibm = data;
393 int len;
395 if (!ibm || !ibm->read)
396 return -EINVAL;
398 len = ibm->read(page);
399 if (len < 0)
400 return len;
402 if (len <= off + count)
403 *eof = 1;
404 *start = page + off;
405 len -= off;
406 if (len > count)
407 len = count;
408 if (len < 0)
409 len = 0;
411 return len;
414 static int dispatch_write(struct file *file, const char __user * userbuf,
415 unsigned long count, void *data)
417 struct ibm_struct *ibm = data;
418 char *kernbuf;
419 int ret;
421 if (!ibm || !ibm->write)
422 return -EINVAL;
424 kernbuf = kmalloc(count + 2, GFP_KERNEL);
425 if (!kernbuf)
426 return -ENOMEM;
428 if (copy_from_user(kernbuf, userbuf, count)) {
429 kfree(kernbuf);
430 return -EFAULT;
433 kernbuf[count] = 0;
434 strcat(kernbuf, ",");
435 ret = ibm->write(kernbuf);
436 if (ret == 0)
437 ret = count;
439 kfree(kernbuf);
441 return ret;
444 static char *next_cmd(char **cmds)
446 char *start = *cmds;
447 char *end;
449 while ((end = strchr(start, ',')) && end == start)
450 start = end + 1;
452 if (!end)
453 return NULL;
455 *end = 0;
456 *cmds = end + 1;
457 return start;
461 /****************************************************************************
462 ****************************************************************************
464 * Subdrivers
466 ****************************************************************************
467 ****************************************************************************/
469 /*************************************************************************
470 * thinkpad-acpi init subdriver
473 static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm)
475 printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION);
476 printk(IBM_INFO "%s\n", IBM_URL);
478 if (ibm_thinkpad_ec_found)
479 printk(IBM_INFO "ThinkPad EC firmware %s\n",
480 ibm_thinkpad_ec_found);
482 return 0;
485 static int thinkpad_acpi_driver_read(char *p)
487 int len = 0;
489 len += sprintf(p + len, "driver:\t\t%s\n", IBM_DESC);
490 len += sprintf(p + len, "version:\t%s\n", IBM_VERSION);
492 return len;
495 static struct ibm_struct thinkpad_acpi_driver_data = {
496 .name = "driver",
497 .read = thinkpad_acpi_driver_read,
500 /*************************************************************************
501 * Hotkey subdriver
504 static int hotkey_orig_status;
505 static int hotkey_orig_mask;
507 static int __init hotkey_init(struct ibm_init_struct *iibm)
509 vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n");
511 IBM_HANDLE_INIT(hkey);
513 /* hotkey not supported on 570 */
514 tp_features.hotkey = hkey_handle != NULL;
516 vdbg_printk(TPACPI_DBG_INIT, "hotkeys are %s\n",
517 str_supported(tp_features.hotkey));
519 if (tp_features.hotkey) {
520 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
521 A30, R30, R31, T20-22, X20-21, X22-24 */
522 tp_features.hotkey_mask =
523 acpi_evalf(hkey_handle, NULL, "DHKN", "qv");
525 vdbg_printk(TPACPI_DBG_INIT, "hotkey masks are %s\n",
526 str_supported(tp_features.hotkey_mask));
528 if (!hotkey_get(&hotkey_orig_status, &hotkey_orig_mask))
529 return -ENODEV;
532 return (tp_features.hotkey)? 0 : 1;
535 static void hotkey_exit(void)
537 if (tp_features.hotkey) {
538 dbg_printk(TPACPI_DBG_EXIT, "restoring original hotkey mask\n");
539 hotkey_set(hotkey_orig_status, hotkey_orig_mask);
543 static void hotkey_notify(struct ibm_struct *ibm, u32 event)
545 int hkey;
547 if (acpi_evalf(hkey_handle, &hkey, "MHKP", "d"))
548 acpi_bus_generate_event(ibm->device, event, hkey);
549 else {
550 printk(IBM_ERR "unknown hotkey event %d\n", event);
551 acpi_bus_generate_event(ibm->device, event, 0);
555 static int hotkey_get(int *status, int *mask)
557 if (!acpi_evalf(hkey_handle, status, "DHKC", "d"))
558 return 0;
560 if (tp_features.hotkey_mask)
561 if (!acpi_evalf(hkey_handle, mask, "DHKN", "d"))
562 return 0;
564 return 1;
567 static int hotkey_set(int status, int mask)
569 int i;
571 if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status))
572 return 0;
574 if (tp_features.hotkey_mask)
575 for (i = 0; i < 32; i++) {
576 int bit = ((1 << i) & mask) != 0;
577 if (!acpi_evalf(hkey_handle,
578 NULL, "MHKM", "vdd", i + 1, bit))
579 return 0;
582 return 1;
585 static int hotkey_read(char *p)
587 int status, mask;
588 int len = 0;
590 if (!tp_features.hotkey) {
591 len += sprintf(p + len, "status:\t\tnot supported\n");
592 return len;
595 if (!hotkey_get(&status, &mask))
596 return -EIO;
598 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0));
599 if (tp_features.hotkey_mask) {
600 len += sprintf(p + len, "mask:\t\t0x%04x\n", mask);
601 len += sprintf(p + len,
602 "commands:\tenable, disable, reset, <mask>\n");
603 } else {
604 len += sprintf(p + len, "mask:\t\tnot supported\n");
605 len += sprintf(p + len, "commands:\tenable, disable, reset\n");
608 return len;
611 static int hotkey_write(char *buf)
613 int status, mask;
614 char *cmd;
615 int do_cmd = 0;
617 if (!tp_features.hotkey)
618 return -ENODEV;
620 if (!hotkey_get(&status, &mask))
621 return -EIO;
623 while ((cmd = next_cmd(&buf))) {
624 if (strlencmp(cmd, "enable") == 0) {
625 status = 1;
626 } else if (strlencmp(cmd, "disable") == 0) {
627 status = 0;
628 } else if (strlencmp(cmd, "reset") == 0) {
629 status = hotkey_orig_status;
630 mask = hotkey_orig_mask;
631 } else if (sscanf(cmd, "0x%x", &mask) == 1) {
632 /* mask set */
633 } else if (sscanf(cmd, "%x", &mask) == 1) {
634 /* mask set */
635 } else
636 return -EINVAL;
637 do_cmd = 1;
640 if (do_cmd && !hotkey_set(status, mask))
641 return -EIO;
643 return 0;
646 static struct ibm_struct hotkey_driver_data = {
647 .name = "hotkey",
648 .hid = IBM_HKEY_HID,
649 .read = hotkey_read,
650 .write = hotkey_write,
651 .exit = hotkey_exit,
652 .notify = hotkey_notify,
653 .handle = &hkey_handle,
654 .type = ACPI_DEVICE_NOTIFY,
657 /*************************************************************************
658 * Bluetooth subdriver
661 static int __init bluetooth_init(struct ibm_init_struct *iibm)
663 vdbg_printk(TPACPI_DBG_INIT, "initializing bluetooth subdriver\n");
665 IBM_HANDLE_INIT(hkey);
667 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
668 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
669 tp_features.bluetooth = hkey_handle &&
670 acpi_evalf(hkey_handle, NULL, "GBDC", "qv");
672 vdbg_printk(TPACPI_DBG_INIT, "bluetooth is %s\n",
673 str_supported(tp_features.bluetooth));
675 return (tp_features.bluetooth)? 0 : 1;
678 static int bluetooth_status(void)
680 int status;
682 if (!tp_features.bluetooth ||
683 !acpi_evalf(hkey_handle, &status, "GBDC", "d"))
684 status = 0;
686 return status;
689 static int bluetooth_read(char *p)
691 int len = 0;
692 int status = bluetooth_status();
694 if (!tp_features.bluetooth)
695 len += sprintf(p + len, "status:\t\tnot supported\n");
696 else if (!(status & 1))
697 len += sprintf(p + len, "status:\t\tnot installed\n");
698 else {
699 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 1));
700 len += sprintf(p + len, "commands:\tenable, disable\n");
703 return len;
706 static int bluetooth_write(char *buf)
708 int status = bluetooth_status();
709 char *cmd;
710 int do_cmd = 0;
712 if (!tp_features.bluetooth)
713 return -ENODEV;
715 while ((cmd = next_cmd(&buf))) {
716 if (strlencmp(cmd, "enable") == 0) {
717 status |= 2;
718 } else if (strlencmp(cmd, "disable") == 0) {
719 status &= ~2;
720 } else
721 return -EINVAL;
722 do_cmd = 1;
725 if (do_cmd && !acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status))
726 return -EIO;
728 return 0;
731 static struct ibm_struct bluetooth_driver_data = {
732 .name = "bluetooth",
733 .read = bluetooth_read,
734 .write = bluetooth_write,
737 /*************************************************************************
738 * Wan subdriver
741 static int __init wan_init(struct ibm_init_struct *iibm)
743 vdbg_printk(TPACPI_DBG_INIT, "initializing wan subdriver\n");
745 IBM_HANDLE_INIT(hkey);
747 tp_features.wan = hkey_handle &&
748 acpi_evalf(hkey_handle, NULL, "GWAN", "qv");
750 vdbg_printk(TPACPI_DBG_INIT, "wan is %s\n",
751 str_supported(tp_features.wan));
753 return (tp_features.wan)? 0 : 1;
756 static int wan_status(void)
758 int status;
760 if (!tp_features.wan ||
761 !acpi_evalf(hkey_handle, &status, "GWAN", "d"))
762 status = 0;
764 return status;
767 static int wan_read(char *p)
769 int len = 0;
770 int status = wan_status();
772 if (!tp_features.wan)
773 len += sprintf(p + len, "status:\t\tnot supported\n");
774 else if (!(status & 1))
775 len += sprintf(p + len, "status:\t\tnot installed\n");
776 else {
777 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 1));
778 len += sprintf(p + len, "commands:\tenable, disable\n");
781 return len;
784 static int wan_write(char *buf)
786 int status = wan_status();
787 char *cmd;
788 int do_cmd = 0;
790 if (!tp_features.wan)
791 return -ENODEV;
793 while ((cmd = next_cmd(&buf))) {
794 if (strlencmp(cmd, "enable") == 0) {
795 status |= 2;
796 } else if (strlencmp(cmd, "disable") == 0) {
797 status &= ~2;
798 } else
799 return -EINVAL;
800 do_cmd = 1;
803 if (do_cmd && !acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status))
804 return -EIO;
806 return 0;
809 static struct ibm_struct wan_driver_data = {
810 .name = "wan",
811 .read = wan_read,
812 .write = wan_write,
813 .flags.experimental = 1,
816 /*************************************************************************
817 * Video subdriver
820 static enum video_access_mode video_supported;
821 static int video_orig_autosw;
823 IBM_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */
824 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
825 "\\_SB.PCI0.VID0", /* 770e */
826 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
827 "\\_SB.PCI0.AGP.VID", /* all others */
828 ); /* R30, R31 */
830 IBM_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */
832 static int __init video_init(struct ibm_init_struct *iibm)
834 int ivga;
836 vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n");
838 IBM_HANDLE_INIT(vid);
839 IBM_HANDLE_INIT(vid2);
841 if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga)
842 /* G41, assume IVGA doesn't change */
843 vid_handle = vid2_handle;
845 if (!vid_handle)
846 /* video switching not supported on R30, R31 */
847 video_supported = TPACPI_VIDEO_NONE;
848 else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd"))
849 /* 570 */
850 video_supported = TPACPI_VIDEO_570;
851 else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd"))
852 /* 600e/x, 770e, 770x */
853 video_supported = TPACPI_VIDEO_770;
854 else
855 /* all others */
856 video_supported = TPACPI_VIDEO_NEW;
858 vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n",
859 str_supported(video_supported != TPACPI_VIDEO_NONE),
860 video_supported);
862 return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1;
865 static void video_exit(void)
867 dbg_printk(TPACPI_DBG_EXIT, "restoring original video autoswitch mode\n");
868 acpi_evalf(vid_handle, NULL, "_DOS", "vd", video_orig_autosw);
871 static int video_status(void)
873 int status = 0;
874 int i;
876 if (video_supported == TPACPI_VIDEO_570) {
877 if (acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", 0x87))
878 status = i & 3;
879 } else if (video_supported == TPACPI_VIDEO_770) {
880 if (acpi_evalf(NULL, &i, "\\VCDL", "d"))
881 status |= 0x01 * i;
882 if (acpi_evalf(NULL, &i, "\\VCDC", "d"))
883 status |= 0x02 * i;
884 } else if (video_supported == TPACPI_VIDEO_NEW) {
885 acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1);
886 if (acpi_evalf(NULL, &i, "\\VCDC", "d"))
887 status |= 0x02 * i;
889 acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0);
890 if (acpi_evalf(NULL, &i, "\\VCDL", "d"))
891 status |= 0x01 * i;
892 if (acpi_evalf(NULL, &i, "\\VCDD", "d"))
893 status |= 0x08 * i;
896 return status;
899 static int video_autosw(void)
901 int autosw = 0;
903 if (video_supported == TPACPI_VIDEO_570)
904 acpi_evalf(vid_handle, &autosw, "SWIT", "d");
905 else if (video_supported == TPACPI_VIDEO_770 ||
906 video_supported == TPACPI_VIDEO_NEW)
907 acpi_evalf(vid_handle, &autosw, "^VDEE", "d");
909 return autosw & 1;
912 static int video_switch(void)
914 int autosw = video_autosw();
915 int ret;
917 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
918 return -EIO;
919 ret = video_supported == TPACPI_VIDEO_570 ?
920 acpi_evalf(ec_handle, NULL, "_Q16", "v") :
921 acpi_evalf(vid_handle, NULL, "VSWT", "v");
922 acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw);
924 return ret;
927 static int video_expand(void)
929 if (video_supported == TPACPI_VIDEO_570)
930 return acpi_evalf(ec_handle, NULL, "_Q17", "v");
931 else if (video_supported == TPACPI_VIDEO_770)
932 return acpi_evalf(vid_handle, NULL, "VEXP", "v");
933 else
934 return acpi_evalf(NULL, NULL, "\\VEXP", "v");
937 static int video_switch2(int status)
939 int ret;
941 if (video_supported == TPACPI_VIDEO_570) {
942 ret = acpi_evalf(NULL, NULL,
943 "\\_SB.PHS2", "vdd", 0x8b, status | 0x80);
944 } else if (video_supported == TPACPI_VIDEO_770) {
945 int autosw = video_autosw();
946 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
947 return -EIO;
949 ret = acpi_evalf(vid_handle, NULL,
950 "ASWT", "vdd", status * 0x100, 0);
952 acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw);
953 } else {
954 ret = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) &&
955 acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1);
958 return ret;
961 static int video_read(char *p)
963 int status = video_status();
964 int autosw = video_autosw();
965 int len = 0;
967 if (!video_supported) {
968 len += sprintf(p + len, "status:\t\tnot supported\n");
969 return len;
972 len += sprintf(p + len, "status:\t\tsupported\n");
973 len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0));
974 len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1));
975 if (video_supported == TPACPI_VIDEO_NEW)
976 len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3));
977 len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0));
978 len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n");
979 len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n");
980 if (video_supported == TPACPI_VIDEO_NEW)
981 len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n");
982 len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n");
983 len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n");
985 return len;
988 static int video_write(char *buf)
990 char *cmd;
991 int enable, disable, status;
993 if (!video_supported)
994 return -ENODEV;
996 enable = disable = 0;
998 while ((cmd = next_cmd(&buf))) {
999 if (strlencmp(cmd, "lcd_enable") == 0) {
1000 enable |= 0x01;
1001 } else if (strlencmp(cmd, "lcd_disable") == 0) {
1002 disable |= 0x01;
1003 } else if (strlencmp(cmd, "crt_enable") == 0) {
1004 enable |= 0x02;
1005 } else if (strlencmp(cmd, "crt_disable") == 0) {
1006 disable |= 0x02;
1007 } else if (video_supported == TPACPI_VIDEO_NEW &&
1008 strlencmp(cmd, "dvi_enable") == 0) {
1009 enable |= 0x08;
1010 } else if (video_supported == TPACPI_VIDEO_NEW &&
1011 strlencmp(cmd, "dvi_disable") == 0) {
1012 disable |= 0x08;
1013 } else if (strlencmp(cmd, "auto_enable") == 0) {
1014 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
1015 return -EIO;
1016 } else if (strlencmp(cmd, "auto_disable") == 0) {
1017 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 0))
1018 return -EIO;
1019 } else if (strlencmp(cmd, "video_switch") == 0) {
1020 if (!video_switch())
1021 return -EIO;
1022 } else if (strlencmp(cmd, "expand_toggle") == 0) {
1023 if (!video_expand())
1024 return -EIO;
1025 } else
1026 return -EINVAL;
1029 if (enable || disable) {
1030 status = (video_status() & 0x0f & ~disable) | enable;
1031 if (!video_switch2(status))
1032 return -EIO;
1035 return 0;
1038 static struct ibm_struct video_driver_data = {
1039 .name = "video",
1040 .read = video_read,
1041 .write = video_write,
1042 .exit = video_exit,
1045 /*************************************************************************
1046 * Light (thinklight) subdriver
1049 IBM_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
1050 IBM_HANDLE(ledb, ec, "LEDB"); /* G4x */
1052 static int __init light_init(struct ibm_init_struct *iibm)
1054 vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n");
1056 IBM_HANDLE_INIT(ledb);
1057 IBM_HANDLE_INIT(lght);
1058 IBM_HANDLE_INIT(cmos);
1060 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
1061 tp_features.light = (cmos_handle || lght_handle) && !ledb_handle;
1063 if (tp_features.light)
1064 /* light status not supported on
1065 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
1066 tp_features.light_status =
1067 acpi_evalf(ec_handle, NULL, "KBLT", "qv");
1069 vdbg_printk(TPACPI_DBG_INIT, "light is %s\n",
1070 str_supported(tp_features.light));
1072 return (tp_features.light)? 0 : 1;
1075 static int light_read(char *p)
1077 int len = 0;
1078 int status = 0;
1080 if (!tp_features.light) {
1081 len += sprintf(p + len, "status:\t\tnot supported\n");
1082 } else if (!tp_features.light_status) {
1083 len += sprintf(p + len, "status:\t\tunknown\n");
1084 len += sprintf(p + len, "commands:\ton, off\n");
1085 } else {
1086 if (!acpi_evalf(ec_handle, &status, "KBLT", "d"))
1087 return -EIO;
1088 len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0));
1089 len += sprintf(p + len, "commands:\ton, off\n");
1092 return len;
1095 static int light_write(char *buf)
1097 int cmos_cmd, lght_cmd;
1098 char *cmd;
1099 int success;
1101 if (!tp_features.light)
1102 return -ENODEV;
1104 while ((cmd = next_cmd(&buf))) {
1105 if (strlencmp(cmd, "on") == 0) {
1106 cmos_cmd = 0x0c;
1107 lght_cmd = 1;
1108 } else if (strlencmp(cmd, "off") == 0) {
1109 cmos_cmd = 0x0d;
1110 lght_cmd = 0;
1111 } else
1112 return -EINVAL;
1114 success = cmos_handle ?
1115 acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd) :
1116 acpi_evalf(lght_handle, NULL, NULL, "vd", lght_cmd);
1117 if (!success)
1118 return -EIO;
1121 return 0;
1124 static struct ibm_struct light_driver_data = {
1125 .name = "light",
1126 .read = light_read,
1127 .write = light_write,
1130 /*************************************************************************
1131 * Dock subdriver
1134 #ifdef CONFIG_THINKPAD_ACPI_DOCK
1136 IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */
1137 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
1138 "\\_SB.PCI0.PCI1.DOCK", /* all others */
1139 "\\_SB.PCI.ISA.SLCE", /* 570 */
1140 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
1142 /* don't list other alternatives as we install a notify handler on the 570 */
1143 IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */
1145 #define dock_docked() (_sta(dock_handle) & 1)
1147 static int __init dock_init(struct ibm_init_struct *iibm)
1149 vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver\n");
1151 IBM_HANDLE_INIT(dock);
1152 IBM_HANDLE_INIT(pci);
1154 vdbg_printk(TPACPI_DBG_INIT, "dock is %s\n",
1155 str_supported(dock_handle != NULL));
1157 return (dock_handle)? 0 : 1;
1160 static void dock_notify(struct ibm_struct *ibm, u32 event)
1162 int docked = dock_docked();
1163 int pci = ibm->hid && strstr(ibm->hid, IBM_PCI_HID);
1165 if (event == 1 && !pci) /* 570 */
1166 acpi_bus_generate_event(ibm->device, event, 1); /* button */
1167 else if (event == 1 && pci) /* 570 */
1168 acpi_bus_generate_event(ibm->device, event, 3); /* dock */
1169 else if (event == 3 && docked)
1170 acpi_bus_generate_event(ibm->device, event, 1); /* button */
1171 else if (event == 3 && !docked)
1172 acpi_bus_generate_event(ibm->device, event, 2); /* undock */
1173 else if (event == 0 && docked)
1174 acpi_bus_generate_event(ibm->device, event, 3); /* dock */
1175 else {
1176 printk(IBM_ERR "unknown dock event %d, status %d\n",
1177 event, _sta(dock_handle));
1178 acpi_bus_generate_event(ibm->device, event, 0); /* unknown */
1182 static int dock_read(char *p)
1184 int len = 0;
1185 int docked = dock_docked();
1187 if (!dock_handle)
1188 len += sprintf(p + len, "status:\t\tnot supported\n");
1189 else if (!docked)
1190 len += sprintf(p + len, "status:\t\tundocked\n");
1191 else {
1192 len += sprintf(p + len, "status:\t\tdocked\n");
1193 len += sprintf(p + len, "commands:\tdock, undock\n");
1196 return len;
1199 static int dock_write(char *buf)
1201 char *cmd;
1203 if (!dock_docked())
1204 return -ENODEV;
1206 while ((cmd = next_cmd(&buf))) {
1207 if (strlencmp(cmd, "undock") == 0) {
1208 if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0) ||
1209 !acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1))
1210 return -EIO;
1211 } else if (strlencmp(cmd, "dock") == 0) {
1212 if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1))
1213 return -EIO;
1214 } else
1215 return -EINVAL;
1218 return 0;
1221 static struct ibm_struct dock_driver_data[2] = {
1223 .name = "dock",
1224 .read = dock_read,
1225 .write = dock_write,
1226 .notify = dock_notify,
1227 .handle = &dock_handle,
1228 .type = ACPI_SYSTEM_NOTIFY,
1231 .name = "dock",
1232 .hid = IBM_PCI_HID,
1233 .notify = dock_notify,
1234 .handle = &pci_handle,
1235 .type = ACPI_SYSTEM_NOTIFY,
1239 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
1241 /*************************************************************************
1242 * Bay subdriver
1245 #ifdef CONFIG_THINKPAD_ACPI_BAY
1246 IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
1247 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
1248 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
1249 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
1250 ); /* A21e, R30, R31 */
1251 IBM_HANDLE(bay_ej, bay, "_EJ3", /* 600e/x, A2xm/p, A3x */
1252 "_EJ0", /* all others */
1253 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
1254 IBM_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
1255 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
1256 ); /* all others */
1257 IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */
1258 "_EJ0", /* 770x */
1259 ); /* all others */
1261 static int __init bay_init(struct ibm_init_struct *iibm)
1263 vdbg_printk(TPACPI_DBG_INIT, "initializing bay subdriver\n");
1265 IBM_HANDLE_INIT(bay);
1266 if (bay_handle)
1267 IBM_HANDLE_INIT(bay_ej);
1268 IBM_HANDLE_INIT(bay2);
1269 if (bay2_handle)
1270 IBM_HANDLE_INIT(bay2_ej);
1272 tp_features.bay_status = bay_handle &&
1273 acpi_evalf(bay_handle, NULL, "_STA", "qv");
1274 tp_features.bay_status2 = bay2_handle &&
1275 acpi_evalf(bay2_handle, NULL, "_STA", "qv");
1277 tp_features.bay_eject = bay_handle && bay_ej_handle &&
1278 (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental);
1279 tp_features.bay_eject2 = bay2_handle && bay2_ej_handle &&
1280 (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental);
1282 vdbg_printk(TPACPI_DBG_INIT,
1283 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
1284 str_supported(tp_features.bay_status),
1285 str_supported(tp_features.bay_eject),
1286 str_supported(tp_features.bay_status2),
1287 str_supported(tp_features.bay_eject2));
1289 return (tp_features.bay_status || tp_features.bay_eject ||
1290 tp_features.bay_status2 || tp_features.bay_eject2)? 0 : 1;
1293 static void bay_notify(struct ibm_struct *ibm, u32 event)
1295 acpi_bus_generate_event(ibm->device, event, 0);
1298 #define bay_occupied(b) (_sta(b##_handle) & 1)
1300 static int bay_read(char *p)
1302 int len = 0;
1303 int occupied = bay_occupied(bay);
1304 int occupied2 = bay_occupied(bay2);
1305 int eject, eject2;
1307 len += sprintf(p + len, "status:\t\t%s\n",
1308 tp_features.bay_status ?
1309 (occupied ? "occupied" : "unoccupied") :
1310 "not supported");
1311 if (tp_features.bay_status2)
1312 len += sprintf(p + len, "status2:\t%s\n", occupied2 ?
1313 "occupied" : "unoccupied");
1315 eject = tp_features.bay_eject && occupied;
1316 eject2 = tp_features.bay_eject2 && occupied2;
1318 if (eject && eject2)
1319 len += sprintf(p + len, "commands:\teject, eject2\n");
1320 else if (eject)
1321 len += sprintf(p + len, "commands:\teject\n");
1322 else if (eject2)
1323 len += sprintf(p + len, "commands:\teject2\n");
1325 return len;
1328 static int bay_write(char *buf)
1330 char *cmd;
1332 if (!tp_features.bay_eject && !tp_features.bay_eject2)
1333 return -ENODEV;
1335 while ((cmd = next_cmd(&buf))) {
1336 if (tp_features.bay_eject && strlencmp(cmd, "eject") == 0) {
1337 if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1))
1338 return -EIO;
1339 } else if (tp_features.bay_eject2 &&
1340 strlencmp(cmd, "eject2") == 0) {
1341 if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1))
1342 return -EIO;
1343 } else
1344 return -EINVAL;
1347 return 0;
1350 static struct ibm_struct bay_driver_data = {
1351 .name = "bay",
1352 .read = bay_read,
1353 .write = bay_write,
1354 .notify = bay_notify,
1355 .handle = &bay_handle,
1356 .type = ACPI_SYSTEM_NOTIFY,
1359 #endif /* CONFIG_THINKPAD_ACPI_BAY */
1361 /*************************************************************************
1362 * CMOS subdriver
1365 static int __init cmos_init(struct ibm_init_struct *iibm)
1367 vdbg_printk(TPACPI_DBG_INIT,
1368 "initializing cmos commands subdriver\n");
1370 IBM_HANDLE_INIT(cmos);
1372 vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n",
1373 str_supported(cmos_handle != NULL));
1374 return (cmos_handle)? 0 : 1;
1377 static int cmos_eval(int cmos_cmd)
1379 if (cmos_handle)
1380 return acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd);
1381 else
1382 return 1;
1385 static int cmos_read(char *p)
1387 int len = 0;
1389 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1390 R30, R31, T20-22, X20-21 */
1391 if (!cmos_handle)
1392 len += sprintf(p + len, "status:\t\tnot supported\n");
1393 else {
1394 len += sprintf(p + len, "status:\t\tsupported\n");
1395 len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n");
1398 return len;
1401 static int cmos_write(char *buf)
1403 char *cmd;
1404 int cmos_cmd;
1406 if (!cmos_handle)
1407 return -EINVAL;
1409 while ((cmd = next_cmd(&buf))) {
1410 if (sscanf(cmd, "%u", &cmos_cmd) == 1 &&
1411 cmos_cmd >= 0 && cmos_cmd <= 21) {
1412 /* cmos_cmd set */
1413 } else
1414 return -EINVAL;
1416 if (!cmos_eval(cmos_cmd))
1417 return -EIO;
1420 return 0;
1423 static struct ibm_struct cmos_driver_data = {
1424 .name = "cmos",
1425 .read = cmos_read,
1426 .write = cmos_write,
1429 /*************************************************************************
1430 * LED subdriver
1433 static enum led_access_mode led_supported;
1435 IBM_HANDLE(led, ec, "SLED", /* 570 */
1436 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1437 "LED", /* all others */
1438 ); /* R30, R31 */
1440 static int __init led_init(struct ibm_init_struct *iibm)
1442 vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n");
1444 IBM_HANDLE_INIT(led);
1446 if (!led_handle)
1447 /* led not supported on R30, R31 */
1448 led_supported = TPACPI_LED_NONE;
1449 else if (strlencmp(led_path, "SLED") == 0)
1450 /* 570 */
1451 led_supported = TPACPI_LED_570;
1452 else if (strlencmp(led_path, "SYSL") == 0)
1453 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1454 led_supported = TPACPI_LED_OLD;
1455 else
1456 /* all others */
1457 led_supported = TPACPI_LED_NEW;
1459 vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n",
1460 str_supported(led_supported), led_supported);
1462 return (led_supported != TPACPI_LED_NONE)? 0 : 1;
1465 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
1467 static int led_read(char *p)
1469 int len = 0;
1471 if (!led_supported) {
1472 len += sprintf(p + len, "status:\t\tnot supported\n");
1473 return len;
1475 len += sprintf(p + len, "status:\t\tsupported\n");
1477 if (led_supported == TPACPI_LED_570) {
1478 /* 570 */
1479 int i, status;
1480 for (i = 0; i < 8; i++) {
1481 if (!acpi_evalf(ec_handle,
1482 &status, "GLED", "dd", 1 << i))
1483 return -EIO;
1484 len += sprintf(p + len, "%d:\t\t%s\n",
1485 i, led_status(status));
1489 len += sprintf(p + len, "commands:\t"
1490 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
1492 return len;
1495 /* off, on, blink */
1496 static const int led_sled_arg1[] = { 0, 1, 3 };
1497 static const int led_exp_hlbl[] = { 0, 0, 1 }; /* led# * */
1498 static const int led_exp_hlcl[] = { 0, 1, 1 }; /* led# * */
1499 static const int led_led_arg1[] = { 0, 0x80, 0xc0 };
1501 static int led_write(char *buf)
1503 char *cmd;
1504 int led, ind, ret;
1506 if (!led_supported)
1507 return -ENODEV;
1509 while ((cmd = next_cmd(&buf))) {
1510 if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 7)
1511 return -EINVAL;
1513 if (strstr(cmd, "off")) {
1514 ind = 0;
1515 } else if (strstr(cmd, "on")) {
1516 ind = 1;
1517 } else if (strstr(cmd, "blink")) {
1518 ind = 2;
1519 } else
1520 return -EINVAL;
1522 if (led_supported == TPACPI_LED_570) {
1523 /* 570 */
1524 led = 1 << led;
1525 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
1526 led, led_sled_arg1[ind]))
1527 return -EIO;
1528 } else if (led_supported == TPACPI_LED_OLD) {
1529 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
1530 led = 1 << led;
1531 ret = ec_write(TPACPI_LED_EC_HLMS, led);
1532 if (ret >= 0)
1533 ret =
1534 ec_write(TPACPI_LED_EC_HLBL,
1535 led * led_exp_hlbl[ind]);
1536 if (ret >= 0)
1537 ret =
1538 ec_write(TPACPI_LED_EC_HLCL,
1539 led * led_exp_hlcl[ind]);
1540 if (ret < 0)
1541 return ret;
1542 } else {
1543 /* all others */
1544 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
1545 led, led_led_arg1[ind]))
1546 return -EIO;
1550 return 0;
1553 static struct ibm_struct led_driver_data = {
1554 .name = "led",
1555 .read = led_read,
1556 .write = led_write,
1559 /*************************************************************************
1560 * Beep subdriver
1563 IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */
1565 static int __init beep_init(struct ibm_init_struct *iibm)
1567 vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n");
1569 IBM_HANDLE_INIT(beep);
1571 vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n",
1572 str_supported(beep_handle != NULL));
1574 return (beep_handle)? 0 : 1;
1577 static int beep_read(char *p)
1579 int len = 0;
1581 if (!beep_handle)
1582 len += sprintf(p + len, "status:\t\tnot supported\n");
1583 else {
1584 len += sprintf(p + len, "status:\t\tsupported\n");
1585 len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n");
1588 return len;
1591 static int beep_write(char *buf)
1593 char *cmd;
1594 int beep_cmd;
1596 if (!beep_handle)
1597 return -ENODEV;
1599 while ((cmd = next_cmd(&buf))) {
1600 if (sscanf(cmd, "%u", &beep_cmd) == 1 &&
1601 beep_cmd >= 0 && beep_cmd <= 17) {
1602 /* beep_cmd set */
1603 } else
1604 return -EINVAL;
1605 if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", beep_cmd, 0))
1606 return -EIO;
1609 return 0;
1612 static struct ibm_struct beep_driver_data = {
1613 .name = "beep",
1614 .read = beep_read,
1615 .write = beep_write,
1618 /*************************************************************************
1619 * Thermal subdriver
1622 static enum thermal_access_mode thermal_read_mode;
1624 static int __init thermal_init(struct ibm_init_struct *iibm)
1626 u8 t, ta1, ta2;
1627 int i;
1628 int acpi_tmp7;
1630 vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n");
1632 acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv");
1634 if (ibm_thinkpad_ec_found && experimental) {
1636 * Direct EC access mode: sensors at registers
1637 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
1638 * non-implemented, thermal sensors return 0x80 when
1639 * not available
1642 ta1 = ta2 = 0;
1643 for (i = 0; i < 8; i++) {
1644 if (likely(acpi_ec_read(0x78 + i, &t))) {
1645 ta1 |= t;
1646 } else {
1647 ta1 = 0;
1648 break;
1650 if (likely(acpi_ec_read(0xC0 + i, &t))) {
1651 ta2 |= t;
1652 } else {
1653 ta1 = 0;
1654 break;
1657 if (ta1 == 0) {
1658 /* This is sheer paranoia, but we handle it anyway */
1659 if (acpi_tmp7) {
1660 printk(IBM_ERR
1661 "ThinkPad ACPI EC access misbehaving, "
1662 "falling back to ACPI TMPx access mode\n");
1663 thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07;
1664 } else {
1665 printk(IBM_ERR
1666 "ThinkPad ACPI EC access misbehaving, "
1667 "disabling thermal sensors access\n");
1668 thermal_read_mode = TPACPI_THERMAL_NONE;
1670 } else {
1671 thermal_read_mode =
1672 (ta2 != 0) ?
1673 TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8;
1675 } else if (acpi_tmp7) {
1676 if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) {
1677 /* 600e/x, 770e, 770x */
1678 thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT;
1679 } else {
1680 /* Standard ACPI TMPx access, max 8 sensors */
1681 thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07;
1683 } else {
1684 /* temperatures not supported on 570, G4x, R30, R31, R32 */
1685 thermal_read_mode = TPACPI_THERMAL_NONE;
1688 vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n",
1689 str_supported(thermal_read_mode != TPACPI_THERMAL_NONE),
1690 thermal_read_mode);
1692 return (thermal_read_mode != TPACPI_THERMAL_NONE)? 0 : 1;
1695 static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
1697 int i, t;
1698 s8 tmp;
1699 char tmpi[] = "TMPi";
1701 if (!s)
1702 return -EINVAL;
1704 switch (thermal_read_mode) {
1705 #if TPACPI_MAX_THERMAL_SENSORS >= 16
1706 case TPACPI_THERMAL_TPEC_16:
1707 for (i = 0; i < 8; i++) {
1708 if (!acpi_ec_read(0xC0 + i, &tmp))
1709 return -EIO;
1710 s->temp[i + 8] = tmp * 1000;
1712 /* fallthrough */
1713 #endif
1714 case TPACPI_THERMAL_TPEC_8:
1715 for (i = 0; i < 8; i++) {
1716 if (!acpi_ec_read(0x78 + i, &tmp))
1717 return -EIO;
1718 s->temp[i] = tmp * 1000;
1720 return (thermal_read_mode == TPACPI_THERMAL_TPEC_16) ? 16 : 8;
1722 case TPACPI_THERMAL_ACPI_UPDT:
1723 if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
1724 return -EIO;
1725 for (i = 0; i < 8; i++) {
1726 tmpi[3] = '0' + i;
1727 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
1728 return -EIO;
1729 s->temp[i] = (t - 2732) * 100;
1731 return 8;
1733 case TPACPI_THERMAL_ACPI_TMP07:
1734 for (i = 0; i < 8; i++) {
1735 tmpi[3] = '0' + i;
1736 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
1737 return -EIO;
1738 s->temp[i] = t * 1000;
1740 return 8;
1742 case TPACPI_THERMAL_NONE:
1743 default:
1744 return 0;
1748 static int thermal_read(char *p)
1750 int len = 0;
1751 int n, i;
1752 struct ibm_thermal_sensors_struct t;
1754 n = thermal_get_sensors(&t);
1755 if (unlikely(n < 0))
1756 return n;
1758 len += sprintf(p + len, "temperatures:\t");
1760 if (n > 0) {
1761 for (i = 0; i < (n - 1); i++)
1762 len += sprintf(p + len, "%d ", t.temp[i] / 1000);
1763 len += sprintf(p + len, "%d\n", t.temp[i] / 1000);
1764 } else
1765 len += sprintf(p + len, "not supported\n");
1767 return len;
1770 static struct ibm_struct thermal_driver_data = {
1771 .name = "thermal",
1772 .read = thermal_read,
1775 /*************************************************************************
1776 * EC Dump subdriver
1779 static u8 ecdump_regs[256];
1781 static int ecdump_read(char *p)
1783 int len = 0;
1784 int i, j;
1785 u8 v;
1787 len += sprintf(p + len, "EC "
1788 " +00 +01 +02 +03 +04 +05 +06 +07"
1789 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
1790 for (i = 0; i < 256; i += 16) {
1791 len += sprintf(p + len, "EC 0x%02x:", i);
1792 for (j = 0; j < 16; j++) {
1793 if (!acpi_ec_read(i + j, &v))
1794 break;
1795 if (v != ecdump_regs[i + j])
1796 len += sprintf(p + len, " *%02x", v);
1797 else
1798 len += sprintf(p + len, " %02x", v);
1799 ecdump_regs[i + j] = v;
1801 len += sprintf(p + len, "\n");
1802 if (j != 16)
1803 break;
1806 /* These are way too dangerous to advertise openly... */
1807 #if 0
1808 len += sprintf(p + len, "commands:\t0x<offset> 0x<value>"
1809 " (<offset> is 00-ff, <value> is 00-ff)\n");
1810 len += sprintf(p + len, "commands:\t0x<offset> <value> "
1811 " (<offset> is 00-ff, <value> is 0-255)\n");
1812 #endif
1813 return len;
1816 static int ecdump_write(char *buf)
1818 char *cmd;
1819 int i, v;
1821 while ((cmd = next_cmd(&buf))) {
1822 if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) {
1823 /* i and v set */
1824 } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) {
1825 /* i and v set */
1826 } else
1827 return -EINVAL;
1828 if (i >= 0 && i < 256 && v >= 0 && v < 256) {
1829 if (!acpi_ec_write(i, v))
1830 return -EIO;
1831 } else
1832 return -EINVAL;
1835 return 0;
1838 static struct ibm_struct ecdump_driver_data = {
1839 .name = "ecdump",
1840 .read = ecdump_read,
1841 .write = ecdump_write,
1842 .flags.experimental = 1,
1845 /*************************************************************************
1846 * Backlight/brightness subdriver
1849 static struct backlight_device *ibm_backlight_device = NULL;
1851 static struct backlight_ops ibm_backlight_data = {
1852 .get_brightness = brightness_get,
1853 .update_status = brightness_update_status,
1856 static int __init brightness_init(struct ibm_init_struct *iibm)
1858 int b;
1860 vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n");
1862 b = brightness_get(NULL);
1863 if (b < 0)
1864 return b;
1866 ibm_backlight_device = backlight_device_register("ibm", NULL, NULL,
1867 &ibm_backlight_data);
1868 if (IS_ERR(ibm_backlight_device)) {
1869 printk(IBM_ERR "Could not register backlight device\n");
1870 return PTR_ERR(ibm_backlight_device);
1872 vdbg_printk(TPACPI_DBG_INIT, "brightness is supported\n");
1874 ibm_backlight_device->props.max_brightness = 7;
1875 ibm_backlight_device->props.brightness = b;
1876 backlight_update_status(ibm_backlight_device);
1878 return 0;
1881 static void brightness_exit(void)
1883 if (ibm_backlight_device) {
1884 vdbg_printk(TPACPI_DBG_EXIT,
1885 "calling backlight_device_unregister()\n");
1886 backlight_device_unregister(ibm_backlight_device);
1887 ibm_backlight_device = NULL;
1891 static int brightness_update_status(struct backlight_device *bd)
1893 return brightness_set(
1894 (bd->props.fb_blank == FB_BLANK_UNBLANK &&
1895 bd->props.power == FB_BLANK_UNBLANK) ?
1896 bd->props.brightness : 0);
1899 static int brightness_get(struct backlight_device *bd)
1901 u8 level;
1902 if (!acpi_ec_read(brightness_offset, &level))
1903 return -EIO;
1905 level &= 0x7;
1907 return level;
1910 static int brightness_set(int value)
1912 int cmos_cmd, inc, i;
1913 int current_value = brightness_get(NULL);
1915 value &= 7;
1917 cmos_cmd = value > current_value ? TP_CMOS_BRIGHTNESS_UP : TP_CMOS_BRIGHTNESS_DOWN;
1918 inc = value > current_value ? 1 : -1;
1919 for (i = current_value; i != value; i += inc) {
1920 if (!cmos_eval(cmos_cmd))
1921 return -EIO;
1922 if (!acpi_ec_write(brightness_offset, i + inc))
1923 return -EIO;
1926 return 0;
1929 static int brightness_read(char *p)
1931 int len = 0;
1932 int level;
1934 if ((level = brightness_get(NULL)) < 0) {
1935 len += sprintf(p + len, "level:\t\tunreadable\n");
1936 } else {
1937 len += sprintf(p + len, "level:\t\t%d\n", level & 0x7);
1938 len += sprintf(p + len, "commands:\tup, down\n");
1939 len += sprintf(p + len, "commands:\tlevel <level>"
1940 " (<level> is 0-7)\n");
1943 return len;
1946 static int brightness_write(char *buf)
1948 int level;
1949 int new_level;
1950 char *cmd;
1952 while ((cmd = next_cmd(&buf))) {
1953 if ((level = brightness_get(NULL)) < 0)
1954 return level;
1955 level &= 7;
1957 if (strlencmp(cmd, "up") == 0) {
1958 new_level = level == 7 ? 7 : level + 1;
1959 } else if (strlencmp(cmd, "down") == 0) {
1960 new_level = level == 0 ? 0 : level - 1;
1961 } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
1962 new_level >= 0 && new_level <= 7) {
1963 /* new_level set */
1964 } else
1965 return -EINVAL;
1967 brightness_set(new_level);
1970 return 0;
1973 static struct ibm_struct brightness_driver_data = {
1974 .name = "brightness",
1975 .read = brightness_read,
1976 .write = brightness_write,
1977 .exit = brightness_exit,
1980 /*************************************************************************
1981 * Volume subdriver
1984 static int volume_read(char *p)
1986 int len = 0;
1987 u8 level;
1989 if (!acpi_ec_read(volume_offset, &level)) {
1990 len += sprintf(p + len, "level:\t\tunreadable\n");
1991 } else {
1992 len += sprintf(p + len, "level:\t\t%d\n", level & 0xf);
1993 len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6));
1994 len += sprintf(p + len, "commands:\tup, down, mute\n");
1995 len += sprintf(p + len, "commands:\tlevel <level>"
1996 " (<level> is 0-15)\n");
1999 return len;
2002 static int volume_write(char *buf)
2004 int cmos_cmd, inc, i;
2005 u8 level, mute;
2006 int new_level, new_mute;
2007 char *cmd;
2009 while ((cmd = next_cmd(&buf))) {
2010 if (!acpi_ec_read(volume_offset, &level))
2011 return -EIO;
2012 new_mute = mute = level & 0x40;
2013 new_level = level = level & 0xf;
2015 if (strlencmp(cmd, "up") == 0) {
2016 if (mute)
2017 new_mute = 0;
2018 else
2019 new_level = level == 15 ? 15 : level + 1;
2020 } else if (strlencmp(cmd, "down") == 0) {
2021 if (mute)
2022 new_mute = 0;
2023 else
2024 new_level = level == 0 ? 0 : level - 1;
2025 } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
2026 new_level >= 0 && new_level <= 15) {
2027 /* new_level set */
2028 } else if (strlencmp(cmd, "mute") == 0) {
2029 new_mute = 0x40;
2030 } else
2031 return -EINVAL;
2033 if (new_level != level) { /* mute doesn't change */
2034 cmos_cmd = new_level > level ? TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN;
2035 inc = new_level > level ? 1 : -1;
2037 if (mute && (!cmos_eval(cmos_cmd) ||
2038 !acpi_ec_write(volume_offset, level)))
2039 return -EIO;
2041 for (i = level; i != new_level; i += inc)
2042 if (!cmos_eval(cmos_cmd) ||
2043 !acpi_ec_write(volume_offset, i + inc))
2044 return -EIO;
2046 if (mute && (!cmos_eval(TP_CMOS_VOLUME_MUTE) ||
2047 !acpi_ec_write(volume_offset,
2048 new_level + mute)))
2049 return -EIO;
2052 if (new_mute != mute) { /* level doesn't change */
2053 cmos_cmd = new_mute ? TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP;
2055 if (!cmos_eval(cmos_cmd) ||
2056 !acpi_ec_write(volume_offset, level + new_mute))
2057 return -EIO;
2061 return 0;
2064 static struct ibm_struct volume_driver_data = {
2065 .name = "volume",
2066 .read = volume_read,
2067 .write = volume_write,
2070 /*************************************************************************
2071 * Fan subdriver
2075 * FAN ACCESS MODES
2077 * TPACPI_FAN_RD_ACPI_GFAN:
2078 * ACPI GFAN method: returns fan level
2080 * see TPACPI_FAN_WR_ACPI_SFAN
2081 * EC 0x2f (HFSP) not available if GFAN exists
2083 * TPACPI_FAN_WR_ACPI_SFAN:
2084 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
2086 * EC 0x2f (HFSP) might be available *for reading*, but do not use
2087 * it for writing.
2089 * TPACPI_FAN_WR_TPEC:
2090 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
2091 * Supported on almost all ThinkPads
2093 * Fan speed changes of any sort (including those caused by the
2094 * disengaged mode) are usually done slowly by the firmware as the
2095 * maximum ammount of fan duty cycle change per second seems to be
2096 * limited.
2098 * Reading is not available if GFAN exists.
2099 * Writing is not available if SFAN exists.
2101 * Bits
2102 * 7 automatic mode engaged;
2103 * (default operation mode of the ThinkPad)
2104 * fan level is ignored in this mode.
2105 * 6 full speed mode (takes precedence over bit 7);
2106 * not available on all thinkpads. May disable
2107 * the tachometer while the fan controller ramps up
2108 * the speed (which can take up to a few *minutes*).
2109 * Speeds up fan to 100% duty-cycle, which is far above
2110 * the standard RPM levels. It is not impossible that
2111 * it could cause hardware damage.
2112 * 5-3 unused in some models. Extra bits for fan level
2113 * in others, but still useless as all values above
2114 * 7 map to the same speed as level 7 in these models.
2115 * 2-0 fan level (0..7 usually)
2116 * 0x00 = stop
2117 * 0x07 = max (set when temperatures critical)
2118 * Some ThinkPads may have other levels, see
2119 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
2121 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
2122 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
2123 * does so, its initial value is meaningless (0x07).
2125 * For firmware bugs, refer to:
2126 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
2128 * ----
2130 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
2131 * Main fan tachometer reading (in RPM)
2133 * This register is present on all ThinkPads with a new-style EC, and
2134 * it is known not to be present on the A21m/e, and T22, as there is
2135 * something else in offset 0x84 according to the ACPI DSDT. Other
2136 * ThinkPads from this same time period (and earlier) probably lack the
2137 * tachometer as well.
2139 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
2140 * was never fixed by IBM to report the EC firmware version string
2141 * probably support the tachometer (like the early X models), so
2142 * detecting it is quite hard. We need more data to know for sure.
2144 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
2145 * might result.
2147 * FIRMWARE BUG: may go stale while the EC is switching to full speed
2148 * mode.
2150 * For firmware bugs, refer to:
2151 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
2153 * TPACPI_FAN_WR_ACPI_FANS:
2154 * ThinkPad X31, X40, X41. Not available in the X60.
2156 * FANS ACPI handle: takes three arguments: low speed, medium speed,
2157 * high speed. ACPI DSDT seems to map these three speeds to levels
2158 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
2159 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
2161 * The speeds are stored on handles
2162 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
2164 * There are three default speed sets, acessible as handles:
2165 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
2167 * ACPI DSDT switches which set is in use depending on various
2168 * factors.
2170 * TPACPI_FAN_WR_TPEC is also available and should be used to
2171 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
2172 * but the ACPI tables just mention level 7.
2175 static enum fan_status_access_mode fan_status_access_mode;
2176 static enum fan_control_access_mode fan_control_access_mode;
2177 static enum fan_control_commands fan_control_commands;
2179 static u8 fan_control_initial_status;
2181 static void fan_watchdog_fire(struct work_struct *ignored);
2182 static int fan_watchdog_maxinterval;
2183 static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire);
2185 IBM_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */
2186 IBM_HANDLE(gfan, ec, "GFAN", /* 570 */
2187 "\\FSPD", /* 600e/x, 770e, 770x */
2188 ); /* all others */
2189 IBM_HANDLE(sfan, ec, "SFAN", /* 570 */
2190 "JFNS", /* 770x-JL */
2191 ); /* all others */
2193 static int __init fan_init(struct ibm_init_struct *iibm)
2195 vdbg_printk(TPACPI_DBG_INIT, "initializing fan subdriver\n");
2197 fan_status_access_mode = TPACPI_FAN_NONE;
2198 fan_control_access_mode = TPACPI_FAN_WR_NONE;
2199 fan_control_commands = 0;
2200 fan_watchdog_maxinterval = 0;
2201 tp_features.fan_ctrl_status_undef = 0;
2203 IBM_HANDLE_INIT(fans);
2204 IBM_HANDLE_INIT(gfan);
2205 IBM_HANDLE_INIT(sfan);
2207 if (gfan_handle) {
2208 /* 570, 600e/x, 770e, 770x */
2209 fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN;
2210 } else {
2211 /* all other ThinkPads: note that even old-style
2212 * ThinkPad ECs supports the fan control register */
2213 if (likely(acpi_ec_read(fan_status_offset,
2214 &fan_control_initial_status))) {
2215 fan_status_access_mode = TPACPI_FAN_RD_TPEC;
2217 /* In some ThinkPads, neither the EC nor the ACPI
2218 * DSDT initialize the fan status, and it ends up
2219 * being set to 0x07 when it *could* be either
2220 * 0x07 or 0x80.
2222 * Enable for TP-1Y (T43), TP-78 (R51e),
2223 * TP-76 (R52), TP-70 (T43, R52), which are known
2224 * to be buggy. */
2225 if (fan_control_initial_status == 0x07 &&
2226 ibm_thinkpad_ec_found &&
2227 ((ibm_thinkpad_ec_found[0] == '1' &&
2228 ibm_thinkpad_ec_found[1] == 'Y') ||
2229 (ibm_thinkpad_ec_found[0] == '7' &&
2230 (ibm_thinkpad_ec_found[1] == '6' ||
2231 ibm_thinkpad_ec_found[1] == '8' ||
2232 ibm_thinkpad_ec_found[1] == '0'))
2233 )) {
2234 printk(IBM_NOTICE
2235 "fan_init: initial fan status is "
2236 "unknown, assuming it is in auto "
2237 "mode\n");
2238 tp_features.fan_ctrl_status_undef = 1;
2240 } else {
2241 printk(IBM_ERR
2242 "ThinkPad ACPI EC access misbehaving, "
2243 "fan status and control unavailable\n");
2244 return 1;
2248 if (sfan_handle) {
2249 /* 570, 770x-JL */
2250 fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN;
2251 fan_control_commands |=
2252 TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE;
2253 } else {
2254 if (!gfan_handle) {
2255 /* gfan without sfan means no fan control */
2256 /* all other models implement TP EC 0x2f control */
2258 if (fans_handle) {
2259 /* X31, X40, X41 */
2260 fan_control_access_mode =
2261 TPACPI_FAN_WR_ACPI_FANS;
2262 fan_control_commands |=
2263 TPACPI_FAN_CMD_SPEED |
2264 TPACPI_FAN_CMD_LEVEL |
2265 TPACPI_FAN_CMD_ENABLE;
2266 } else {
2267 fan_control_access_mode = TPACPI_FAN_WR_TPEC;
2268 fan_control_commands |=
2269 TPACPI_FAN_CMD_LEVEL |
2270 TPACPI_FAN_CMD_ENABLE;
2275 vdbg_printk(TPACPI_DBG_INIT, "fan is %s, modes %d, %d\n",
2276 str_supported(fan_status_access_mode != TPACPI_FAN_NONE ||
2277 fan_control_access_mode != TPACPI_FAN_WR_NONE),
2278 fan_status_access_mode, fan_control_access_mode);
2280 return (fan_status_access_mode != TPACPI_FAN_NONE ||
2281 fan_control_access_mode != TPACPI_FAN_WR_NONE)?
2282 0 : 1;
2285 static int fan_get_status(u8 *status)
2287 u8 s;
2289 /* TODO:
2290 * Add TPACPI_FAN_RD_ACPI_FANS ? */
2292 switch (fan_status_access_mode) {
2293 case TPACPI_FAN_RD_ACPI_GFAN:
2294 /* 570, 600e/x, 770e, 770x */
2296 if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d")))
2297 return -EIO;
2299 if (likely(status))
2300 *status = s & 0x07;
2302 break;
2304 case TPACPI_FAN_RD_TPEC:
2305 /* all except 570, 600e/x, 770e, 770x */
2306 if (unlikely(!acpi_ec_read(fan_status_offset, &s)))
2307 return -EIO;
2309 if (likely(status))
2310 *status = s;
2312 break;
2314 default:
2315 return -ENXIO;
2318 return 0;
2321 static void fan_exit(void)
2323 vdbg_printk(TPACPI_DBG_EXIT, "cancelling any pending watchdogs\n");
2324 cancel_delayed_work(&fan_watchdog_task);
2325 flush_scheduled_work();
2328 static int fan_get_speed(unsigned int *speed)
2330 u8 hi, lo;
2332 switch (fan_status_access_mode) {
2333 case TPACPI_FAN_RD_TPEC:
2334 /* all except 570, 600e/x, 770e, 770x */
2335 if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) ||
2336 !acpi_ec_read(fan_rpm_offset + 1, &hi)))
2337 return -EIO;
2339 if (likely(speed))
2340 *speed = (hi << 8) | lo;
2342 break;
2344 default:
2345 return -ENXIO;
2348 return 0;
2351 static void fan_watchdog_fire(struct work_struct *ignored)
2353 printk(IBM_NOTICE "fan watchdog: enabling fan\n");
2354 if (fan_set_enable()) {
2355 printk(IBM_ERR "fan watchdog: error while enabling fan\n");
2356 /* reschedule for later */
2357 fan_watchdog_reset();
2361 static void fan_watchdog_reset(void)
2363 static int fan_watchdog_active = 0;
2365 if (fan_watchdog_active)
2366 cancel_delayed_work(&fan_watchdog_task);
2368 if (fan_watchdog_maxinterval > 0) {
2369 fan_watchdog_active = 1;
2370 if (!schedule_delayed_work(&fan_watchdog_task,
2371 msecs_to_jiffies(fan_watchdog_maxinterval
2372 * 1000))) {
2373 printk(IBM_ERR "failed to schedule the fan watchdog, "
2374 "watchdog will not trigger\n");
2376 } else
2377 fan_watchdog_active = 0;
2380 static int fan_set_level(int level)
2382 switch (fan_control_access_mode) {
2383 case TPACPI_FAN_WR_ACPI_SFAN:
2384 if (level >= 0 && level <= 7) {
2385 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level))
2386 return -EIO;
2387 } else
2388 return -EINVAL;
2389 break;
2391 case TPACPI_FAN_WR_ACPI_FANS:
2392 case TPACPI_FAN_WR_TPEC:
2393 if ((level != TP_EC_FAN_AUTO) &&
2394 (level != TP_EC_FAN_FULLSPEED) &&
2395 ((level < 0) || (level > 7)))
2396 return -EINVAL;
2398 if (!acpi_ec_write(fan_status_offset, level))
2399 return -EIO;
2400 else
2401 tp_features.fan_ctrl_status_undef = 0;
2402 break;
2404 default:
2405 return -ENXIO;
2407 return 0;
2410 static int fan_set_enable(void)
2412 u8 s;
2413 int rc;
2415 switch (fan_control_access_mode) {
2416 case TPACPI_FAN_WR_ACPI_FANS:
2417 case TPACPI_FAN_WR_TPEC:
2418 if ((rc = fan_get_status(&s)) < 0)
2419 return rc;
2421 /* Don't go out of emergency fan mode */
2422 if (s != 7)
2423 s = TP_EC_FAN_AUTO;
2425 if (!acpi_ec_write(fan_status_offset, s))
2426 return -EIO;
2427 else
2428 tp_features.fan_ctrl_status_undef = 0;
2429 break;
2431 case TPACPI_FAN_WR_ACPI_SFAN:
2432 if ((rc = fan_get_status(&s)) < 0)
2433 return rc;
2435 s &= 0x07;
2437 /* Set fan to at least level 4 */
2438 if (s < 4)
2439 s = 4;
2441 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s))
2442 return -EIO;
2443 break;
2445 default:
2446 return -ENXIO;
2448 return 0;
2451 static int fan_set_disable(void)
2453 switch (fan_control_access_mode) {
2454 case TPACPI_FAN_WR_ACPI_FANS:
2455 case TPACPI_FAN_WR_TPEC:
2456 if (!acpi_ec_write(fan_status_offset, 0x00))
2457 return -EIO;
2458 else
2459 tp_features.fan_ctrl_status_undef = 0;
2460 break;
2462 case TPACPI_FAN_WR_ACPI_SFAN:
2463 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00))
2464 return -EIO;
2465 break;
2467 default:
2468 return -ENXIO;
2470 return 0;
2473 static int fan_set_speed(int speed)
2475 switch (fan_control_access_mode) {
2476 case TPACPI_FAN_WR_ACPI_FANS:
2477 if (speed >= 0 && speed <= 65535) {
2478 if (!acpi_evalf(fans_handle, NULL, NULL, "vddd",
2479 speed, speed, speed))
2480 return -EIO;
2481 } else
2482 return -EINVAL;
2483 break;
2485 default:
2486 return -ENXIO;
2488 return 0;
2491 static int fan_read(char *p)
2493 int len = 0;
2494 int rc;
2495 u8 status;
2496 unsigned int speed = 0;
2498 switch (fan_status_access_mode) {
2499 case TPACPI_FAN_RD_ACPI_GFAN:
2500 /* 570, 600e/x, 770e, 770x */
2501 if ((rc = fan_get_status(&status)) < 0)
2502 return rc;
2504 len += sprintf(p + len, "status:\t\t%s\n"
2505 "level:\t\t%d\n",
2506 (status != 0) ? "enabled" : "disabled", status);
2507 break;
2509 case TPACPI_FAN_RD_TPEC:
2510 /* all except 570, 600e/x, 770e, 770x */
2511 if ((rc = fan_get_status(&status)) < 0)
2512 return rc;
2514 if (unlikely(tp_features.fan_ctrl_status_undef)) {
2515 if (status != fan_control_initial_status)
2516 tp_features.fan_ctrl_status_undef = 0;
2517 else
2518 /* Return most likely status. In fact, it
2519 * might be the only possible status */
2520 status = TP_EC_FAN_AUTO;
2523 len += sprintf(p + len, "status:\t\t%s\n",
2524 (status != 0) ? "enabled" : "disabled");
2526 if ((rc = fan_get_speed(&speed)) < 0)
2527 return rc;
2529 len += sprintf(p + len, "speed:\t\t%d\n", speed);
2531 if (status & TP_EC_FAN_FULLSPEED)
2532 /* Disengaged mode takes precedence */
2533 len += sprintf(p + len, "level:\t\tdisengaged\n");
2534 else if (status & TP_EC_FAN_AUTO)
2535 len += sprintf(p + len, "level:\t\tauto\n");
2536 else
2537 len += sprintf(p + len, "level:\t\t%d\n", status);
2538 break;
2540 case TPACPI_FAN_NONE:
2541 default:
2542 len += sprintf(p + len, "status:\t\tnot supported\n");
2545 if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) {
2546 len += sprintf(p + len, "commands:\tlevel <level>");
2548 switch (fan_control_access_mode) {
2549 case TPACPI_FAN_WR_ACPI_SFAN:
2550 len += sprintf(p + len, " (<level> is 0-7)\n");
2551 break;
2553 default:
2554 len += sprintf(p + len, " (<level> is 0-7, "
2555 "auto, disengaged)\n");
2556 break;
2560 if (fan_control_commands & TPACPI_FAN_CMD_ENABLE)
2561 len += sprintf(p + len, "commands:\tenable, disable\n"
2562 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
2563 "1-120 (seconds))\n");
2565 if (fan_control_commands & TPACPI_FAN_CMD_SPEED)
2566 len += sprintf(p + len, "commands:\tspeed <speed>"
2567 " (<speed> is 0-65535)\n");
2569 return len;
2572 static int fan_write_cmd_level(const char *cmd, int *rc)
2574 int level;
2576 if (strlencmp(cmd, "level auto") == 0)
2577 level = TP_EC_FAN_AUTO;
2578 else if (strlencmp(cmd, "level disengaged") == 0)
2579 level = TP_EC_FAN_FULLSPEED;
2580 else if (sscanf(cmd, "level %d", &level) != 1)
2581 return 0;
2583 if ((*rc = fan_set_level(level)) == -ENXIO)
2584 printk(IBM_ERR "level command accepted for unsupported "
2585 "access mode %d", fan_control_access_mode);
2587 return 1;
2590 static int fan_write_cmd_enable(const char *cmd, int *rc)
2592 if (strlencmp(cmd, "enable") != 0)
2593 return 0;
2595 if ((*rc = fan_set_enable()) == -ENXIO)
2596 printk(IBM_ERR "enable command accepted for unsupported "
2597 "access mode %d", fan_control_access_mode);
2599 return 1;
2602 static int fan_write_cmd_disable(const char *cmd, int *rc)
2604 if (strlencmp(cmd, "disable") != 0)
2605 return 0;
2607 if ((*rc = fan_set_disable()) == -ENXIO)
2608 printk(IBM_ERR "disable command accepted for unsupported "
2609 "access mode %d", fan_control_access_mode);
2611 return 1;
2614 static int fan_write_cmd_speed(const char *cmd, int *rc)
2616 int speed;
2618 /* TODO:
2619 * Support speed <low> <medium> <high> ? */
2621 if (sscanf(cmd, "speed %d", &speed) != 1)
2622 return 0;
2624 if ((*rc = fan_set_speed(speed)) == -ENXIO)
2625 printk(IBM_ERR "speed command accepted for unsupported "
2626 "access mode %d", fan_control_access_mode);
2628 return 1;
2631 static int fan_write_cmd_watchdog(const char *cmd, int *rc)
2633 int interval;
2635 if (sscanf(cmd, "watchdog %d", &interval) != 1)
2636 return 0;
2638 if (interval < 0 || interval > 120)
2639 *rc = -EINVAL;
2640 else
2641 fan_watchdog_maxinterval = interval;
2643 return 1;
2646 static int fan_write(char *buf)
2648 char *cmd;
2649 int rc = 0;
2651 while (!rc && (cmd = next_cmd(&buf))) {
2652 if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) &&
2653 fan_write_cmd_level(cmd, &rc)) &&
2654 !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) &&
2655 (fan_write_cmd_enable(cmd, &rc) ||
2656 fan_write_cmd_disable(cmd, &rc) ||
2657 fan_write_cmd_watchdog(cmd, &rc))) &&
2658 !((fan_control_commands & TPACPI_FAN_CMD_SPEED) &&
2659 fan_write_cmd_speed(cmd, &rc))
2661 rc = -EINVAL;
2662 else if (!rc)
2663 fan_watchdog_reset();
2666 return rc;
2669 static struct ibm_struct fan_driver_data = {
2670 .name = "fan",
2671 .read = fan_read,
2672 .write = fan_write,
2673 .exit = fan_exit,
2674 .flags.experimental = 1,
2677 /****************************************************************************
2678 ****************************************************************************
2680 * Infrastructure
2682 ****************************************************************************
2683 ****************************************************************************/
2685 /* /proc support */
2686 static struct proc_dir_entry *proc_dir = NULL;
2688 /* Subdriver registry */
2689 static LIST_HEAD(tpacpi_all_drivers);
2693 * Module and infrastructure proble, init and exit handling
2696 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
2697 static const char * __init str_supported(int is_supported)
2699 static char text_unsupported[] __initdata = "not supported";
2701 return (is_supported)? &text_unsupported[4] : &text_unsupported[0];
2703 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
2705 static int __init ibm_init(struct ibm_init_struct *iibm)
2707 int ret;
2708 struct ibm_struct *ibm = iibm->data;
2709 struct proc_dir_entry *entry;
2711 BUG_ON(ibm == NULL);
2713 INIT_LIST_HEAD(&ibm->all_drivers);
2715 if (ibm->flags.experimental && !experimental)
2716 return 0;
2718 dbg_printk(TPACPI_DBG_INIT,
2719 "probing for %s\n", ibm->name);
2721 if (iibm->init) {
2722 ret = iibm->init(iibm);
2723 if (ret > 0)
2724 return 0; /* probe failed */
2725 if (ret)
2726 return ret;
2728 ibm->flags.init_called = 1;
2731 if (ibm->hid) {
2732 ret = register_tpacpi_subdriver(ibm);
2733 if (ret)
2734 goto err_out;
2737 if (ibm->notify) {
2738 ret = setup_notify(ibm);
2739 if (ret == -ENODEV) {
2740 printk(IBM_NOTICE "disabling subdriver %s\n",
2741 ibm->name);
2742 ret = 0;
2743 goto err_out;
2745 if (ret < 0)
2746 goto err_out;
2749 dbg_printk(TPACPI_DBG_INIT,
2750 "%s installed\n", ibm->name);
2752 if (ibm->read) {
2753 entry = create_proc_entry(ibm->name,
2754 S_IFREG | S_IRUGO | S_IWUSR,
2755 proc_dir);
2756 if (!entry) {
2757 printk(IBM_ERR "unable to create proc entry %s\n",
2758 ibm->name);
2759 ret = -ENODEV;
2760 goto err_out;
2762 entry->owner = THIS_MODULE;
2763 entry->data = ibm;
2764 entry->read_proc = &dispatch_read;
2765 if (ibm->write)
2766 entry->write_proc = &dispatch_write;
2767 ibm->flags.proc_created = 1;
2770 list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers);
2772 return 0;
2774 err_out:
2775 dbg_printk(TPACPI_DBG_INIT,
2776 "%s: at error exit path with result %d\n",
2777 ibm->name, ret);
2779 ibm_exit(ibm);
2780 return (ret < 0)? ret : 0;
2783 static void ibm_exit(struct ibm_struct *ibm)
2785 dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name);
2787 list_del_init(&ibm->all_drivers);
2789 if (ibm->flags.notify_installed) {
2790 dbg_printk(TPACPI_DBG_EXIT,
2791 "%s: acpi_remove_notify_handler\n", ibm->name);
2792 acpi_remove_notify_handler(*ibm->handle, ibm->type,
2793 dispatch_notify);
2794 ibm->flags.notify_installed = 0;
2797 if (ibm->flags.proc_created) {
2798 dbg_printk(TPACPI_DBG_EXIT,
2799 "%s: remove_proc_entry\n", ibm->name);
2800 remove_proc_entry(ibm->name, proc_dir);
2801 ibm->flags.proc_created = 0;
2804 if (ibm->flags.driver_registered) {
2805 dbg_printk(TPACPI_DBG_EXIT,
2806 "%s: acpi_bus_unregister_driver\n", ibm->name);
2807 acpi_bus_unregister_driver(ibm->driver);
2808 kfree(ibm->driver);
2809 ibm->driver = NULL;
2810 ibm->flags.driver_registered = 0;
2813 if (ibm->flags.init_called && ibm->exit) {
2814 ibm->exit();
2815 ibm->flags.init_called = 0;
2818 dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name);
2821 /* Probing */
2823 static char *ibm_thinkpad_ec_found = NULL;
2825 static char* __init check_dmi_for_ec(void)
2827 struct dmi_device *dev = NULL;
2828 char ec_fw_string[18];
2831 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
2832 * X32 or newer, all Z series; Some models must have an
2833 * up-to-date BIOS or they will not be detected.
2835 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
2837 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
2838 if (sscanf(dev->name,
2839 "IBM ThinkPad Embedded Controller -[%17c",
2840 ec_fw_string) == 1) {
2841 ec_fw_string[sizeof(ec_fw_string) - 1] = 0;
2842 ec_fw_string[strcspn(ec_fw_string, " ]")] = 0;
2843 return kstrdup(ec_fw_string, GFP_KERNEL);
2846 return NULL;
2849 static int __init probe_for_thinkpad(void)
2851 int is_thinkpad;
2853 if (acpi_disabled)
2854 return -ENODEV;
2857 * Non-ancient models have better DMI tagging, but very old models
2858 * don't.
2860 is_thinkpad = dmi_name_in_vendors("ThinkPad");
2862 /* ec is required because many other handles are relative to it */
2863 IBM_HANDLE_INIT(ec);
2864 if (!ec_handle) {
2865 if (is_thinkpad)
2866 printk(IBM_ERR
2867 "Not yet supported ThinkPad detected!\n");
2868 return -ENODEV;
2872 * Risks a regression on very old machines, but reduces potential
2873 * false positives a damn great deal
2875 if (!is_thinkpad)
2876 is_thinkpad = dmi_name_in_vendors("IBM");
2878 if (!is_thinkpad && !force_load)
2879 return -ENODEV;
2881 return 0;
2885 /* Module init, exit, parameters */
2887 static struct ibm_init_struct ibms_init[] __initdata = {
2889 .init = thinkpad_acpi_driver_init,
2890 .data = &thinkpad_acpi_driver_data,
2893 .init = hotkey_init,
2894 .data = &hotkey_driver_data,
2897 .init = bluetooth_init,
2898 .data = &bluetooth_driver_data,
2901 .init = wan_init,
2902 .data = &wan_driver_data,
2905 .init = video_init,
2906 .data = &video_driver_data,
2909 .init = light_init,
2910 .data = &light_driver_data,
2912 #ifdef CONFIG_THINKPAD_ACPI_DOCK
2914 .init = dock_init,
2915 .data = &dock_driver_data[0],
2918 .data = &dock_driver_data[1],
2920 #endif
2921 #ifdef CONFIG_THINKPAD_ACPI_BAY
2923 .init = bay_init,
2924 .data = &bay_driver_data,
2926 #endif
2928 .init = cmos_init,
2929 .data = &cmos_driver_data,
2932 .init = led_init,
2933 .data = &led_driver_data,
2936 .init = beep_init,
2937 .data = &beep_driver_data,
2940 .init = thermal_init,
2941 .data = &thermal_driver_data,
2944 .data = &ecdump_driver_data,
2947 .init = brightness_init,
2948 .data = &brightness_driver_data,
2951 .data = &volume_driver_data,
2954 .init = fan_init,
2955 .data = &fan_driver_data,
2959 static int __init set_ibm_param(const char *val, struct kernel_param *kp)
2961 unsigned int i;
2962 struct ibm_struct *ibm;
2964 for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
2965 ibm = ibms_init[i].data;
2966 BUG_ON(ibm == NULL);
2968 if (strcmp(ibm->name, kp->name) == 0 && ibm->write) {
2969 if (strlen(val) > sizeof(ibms_init[i].param) - 2)
2970 return -ENOSPC;
2971 strcpy(ibms_init[i].param, val);
2972 strcat(ibms_init[i].param, ",");
2973 return 0;
2977 return -EINVAL;
2980 static int experimental;
2981 module_param(experimental, int, 0);
2983 static u32 dbg_level;
2984 module_param_named(debug, dbg_level, uint, 0);
2986 static int force_load;
2987 module_param(force_load, int, 0);
2989 #define IBM_PARAM(feature) \
2990 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
2992 IBM_PARAM(hotkey);
2993 IBM_PARAM(bluetooth);
2994 IBM_PARAM(video);
2995 IBM_PARAM(light);
2996 #ifdef CONFIG_THINKPAD_ACPI_DOCK
2997 IBM_PARAM(dock);
2998 #endif
2999 #ifdef CONFIG_THINKPAD_ACPI_BAY
3000 IBM_PARAM(bay);
3001 #endif /* CONFIG_THINKPAD_ACPI_BAY */
3002 IBM_PARAM(cmos);
3003 IBM_PARAM(led);
3004 IBM_PARAM(beep);
3005 IBM_PARAM(ecdump);
3006 IBM_PARAM(brightness);
3007 IBM_PARAM(volume);
3008 IBM_PARAM(fan);
3010 static int __init thinkpad_acpi_module_init(void)
3012 int ret, i;
3014 ret = probe_for_thinkpad();
3015 if (ret)
3016 return ret;
3018 ibm_thinkpad_ec_found = check_dmi_for_ec();
3019 IBM_HANDLE_INIT(ecrd);
3020 IBM_HANDLE_INIT(ecwr);
3022 proc_dir = proc_mkdir(IBM_DIR, acpi_root_dir);
3023 if (!proc_dir) {
3024 printk(IBM_ERR "unable to create proc dir %s", IBM_DIR);
3025 thinkpad_acpi_module_exit();
3026 return -ENODEV;
3028 proc_dir->owner = THIS_MODULE;
3030 for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
3031 ret = ibm_init(&ibms_init[i]);
3032 if (ret >= 0 && *ibms_init[i].param)
3033 ret = ibms_init[i].data->write(ibms_init[i].param);
3034 if (ret < 0) {
3035 thinkpad_acpi_module_exit();
3036 return ret;
3040 return 0;
3043 static void thinkpad_acpi_module_exit(void)
3045 struct ibm_struct *ibm, *itmp;
3047 list_for_each_entry_safe_reverse(ibm, itmp,
3048 &tpacpi_all_drivers,
3049 all_drivers) {
3050 ibm_exit(ibm);
3053 dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n");
3055 if (proc_dir)
3056 remove_proc_entry(IBM_DIR, acpi_root_dir);
3058 if (ibm_thinkpad_ec_found)
3059 kfree(ibm_thinkpad_ec_found);
3062 module_init(thinkpad_acpi_module_init);
3063 module_exit(thinkpad_acpi_module_exit);