ACPI: thinkpad-acpi: prepare for device model conversion
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / misc / thinkpad_acpi.c
blob869c2076cd1e494a0197b7a9ae776367e2592e04
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 drv_acpi_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_acpi_notify(acpi_handle handle, u32 event, void *data)
300 struct ibm_struct *ibm = data;
302 if (!ibm || !ibm->acpi || !ibm->acpi->notify)
303 return;
305 ibm->acpi->notify(ibm, event);
308 static int __init setup_acpi_notify(struct ibm_struct *ibm)
310 acpi_status status;
311 int ret;
313 BUG_ON(!ibm->acpi);
315 if (!*ibm->acpi->handle)
316 return 0;
318 dbg_printk(TPACPI_DBG_INIT,
319 "setting up ACPI notify for %s\n", ibm->name);
321 ret = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device);
322 if (ret < 0) {
323 printk(IBM_ERR "%s device not present\n", ibm->name);
324 return -ENODEV;
327 acpi_driver_data(ibm->acpi->device) = ibm;
328 sprintf(acpi_device_class(ibm->acpi->device), "%s/%s",
329 IBM_ACPI_EVENT_PREFIX,
330 ibm->name);
332 status = acpi_install_notify_handler(*ibm->acpi->handle,
333 ibm->acpi->type, dispatch_acpi_notify, ibm);
334 if (ACPI_FAILURE(status)) {
335 if (status == AE_ALREADY_EXISTS) {
336 printk(IBM_NOTICE "another device driver is already handling %s events\n",
337 ibm->name);
338 } else {
339 printk(IBM_ERR "acpi_install_notify_handler(%s) failed: %d\n",
340 ibm->name, status);
342 return -ENODEV;
344 ibm->flags.acpi_notify_installed = 1;
345 return 0;
348 static int __init tpacpi_device_add(struct acpi_device *device)
350 return 0;
353 static int __init register_tpacpi_subdriver(struct ibm_struct *ibm)
355 int ret;
357 dbg_printk(TPACPI_DBG_INIT,
358 "registering %s as an ACPI driver\n", ibm->name);
360 BUG_ON(!ibm->acpi);
362 ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL);
363 if (!ibm->acpi->driver) {
364 printk(IBM_ERR "kzalloc(ibm->driver) failed\n");
365 return -ENOMEM;
368 sprintf(ibm->acpi->driver->name, "%s_%s", IBM_NAME, ibm->name);
369 ibm->acpi->driver->ids = ibm->acpi->hid;
370 ibm->acpi->driver->ops.add = &tpacpi_device_add;
372 ret = acpi_bus_register_driver(ibm->acpi->driver);
373 if (ret < 0) {
374 printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n",
375 ibm->acpi->hid, ret);
376 kfree(ibm->acpi->driver);
377 ibm->acpi->driver = NULL;
378 } else if (!ret)
379 ibm->flags.acpi_driver_registered = 1;
381 return ret;
385 /****************************************************************************
386 ****************************************************************************
388 * Procfs Helpers
390 ****************************************************************************
391 ****************************************************************************/
393 static int dispatch_procfs_read(char *page, char **start, off_t off,
394 int count, int *eof, void *data)
396 struct ibm_struct *ibm = data;
397 int len;
399 if (!ibm || !ibm->read)
400 return -EINVAL;
402 len = ibm->read(page);
403 if (len < 0)
404 return len;
406 if (len <= off + count)
407 *eof = 1;
408 *start = page + off;
409 len -= off;
410 if (len > count)
411 len = count;
412 if (len < 0)
413 len = 0;
415 return len;
418 static int dispatch_procfs_write(struct file *file,
419 const char __user * userbuf,
420 unsigned long count, void *data)
422 struct ibm_struct *ibm = data;
423 char *kernbuf;
424 int ret;
426 if (!ibm || !ibm->write)
427 return -EINVAL;
429 kernbuf = kmalloc(count + 2, GFP_KERNEL);
430 if (!kernbuf)
431 return -ENOMEM;
433 if (copy_from_user(kernbuf, userbuf, count)) {
434 kfree(kernbuf);
435 return -EFAULT;
438 kernbuf[count] = 0;
439 strcat(kernbuf, ",");
440 ret = ibm->write(kernbuf);
441 if (ret == 0)
442 ret = count;
444 kfree(kernbuf);
446 return ret;
449 static char *next_cmd(char **cmds)
451 char *start = *cmds;
452 char *end;
454 while ((end = strchr(start, ',')) && end == start)
455 start = end + 1;
457 if (!end)
458 return NULL;
460 *end = 0;
461 *cmds = end + 1;
462 return start;
466 /****************************************************************************
467 ****************************************************************************
469 * Subdrivers
471 ****************************************************************************
472 ****************************************************************************/
474 /*************************************************************************
475 * thinkpad-acpi init subdriver
478 static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm)
480 printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION);
481 printk(IBM_INFO "%s\n", IBM_URL);
483 if (ibm_thinkpad_ec_found)
484 printk(IBM_INFO "ThinkPad EC firmware %s\n",
485 ibm_thinkpad_ec_found);
487 return 0;
490 static int thinkpad_acpi_driver_read(char *p)
492 int len = 0;
494 len += sprintf(p + len, "driver:\t\t%s\n", IBM_DESC);
495 len += sprintf(p + len, "version:\t%s\n", IBM_VERSION);
497 return len;
500 static struct ibm_struct thinkpad_acpi_driver_data = {
501 .name = "driver",
502 .read = thinkpad_acpi_driver_read,
505 /*************************************************************************
506 * Hotkey subdriver
509 static int hotkey_orig_status;
510 static int hotkey_orig_mask;
512 static int __init hotkey_init(struct ibm_init_struct *iibm)
514 vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n");
516 IBM_ACPIHANDLE_INIT(hkey);
518 /* hotkey not supported on 570 */
519 tp_features.hotkey = hkey_handle != NULL;
521 vdbg_printk(TPACPI_DBG_INIT, "hotkeys are %s\n",
522 str_supported(tp_features.hotkey));
524 if (tp_features.hotkey) {
525 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
526 A30, R30, R31, T20-22, X20-21, X22-24 */
527 tp_features.hotkey_mask =
528 acpi_evalf(hkey_handle, NULL, "DHKN", "qv");
530 vdbg_printk(TPACPI_DBG_INIT, "hotkey masks are %s\n",
531 str_supported(tp_features.hotkey_mask));
533 if (!hotkey_get(&hotkey_orig_status, &hotkey_orig_mask))
534 return -ENODEV;
537 return (tp_features.hotkey)? 0 : 1;
540 static void hotkey_exit(void)
542 if (tp_features.hotkey) {
543 dbg_printk(TPACPI_DBG_EXIT, "restoring original hotkey mask\n");
544 hotkey_set(hotkey_orig_status, hotkey_orig_mask);
548 static void hotkey_notify(struct ibm_struct *ibm, u32 event)
550 int hkey;
552 if (acpi_evalf(hkey_handle, &hkey, "MHKP", "d"))
553 acpi_bus_generate_event(ibm->acpi->device, event, hkey);
554 else {
555 printk(IBM_ERR "unknown hotkey event %d\n", event);
556 acpi_bus_generate_event(ibm->acpi->device, event, 0);
560 static int hotkey_get(int *status, int *mask)
562 if (!acpi_evalf(hkey_handle, status, "DHKC", "d"))
563 return 0;
565 if (tp_features.hotkey_mask)
566 if (!acpi_evalf(hkey_handle, mask, "DHKN", "d"))
567 return 0;
569 return 1;
572 static int hotkey_set(int status, int mask)
574 int i;
576 if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status))
577 return 0;
579 if (tp_features.hotkey_mask)
580 for (i = 0; i < 32; i++) {
581 int bit = ((1 << i) & mask) != 0;
582 if (!acpi_evalf(hkey_handle,
583 NULL, "MHKM", "vdd", i + 1, bit))
584 return 0;
587 return 1;
590 static int hotkey_read(char *p)
592 int status, mask;
593 int len = 0;
595 if (!tp_features.hotkey) {
596 len += sprintf(p + len, "status:\t\tnot supported\n");
597 return len;
600 if (!hotkey_get(&status, &mask))
601 return -EIO;
603 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0));
604 if (tp_features.hotkey_mask) {
605 len += sprintf(p + len, "mask:\t\t0x%04x\n", mask);
606 len += sprintf(p + len,
607 "commands:\tenable, disable, reset, <mask>\n");
608 } else {
609 len += sprintf(p + len, "mask:\t\tnot supported\n");
610 len += sprintf(p + len, "commands:\tenable, disable, reset\n");
613 return len;
616 static int hotkey_write(char *buf)
618 int status, mask;
619 char *cmd;
620 int do_cmd = 0;
622 if (!tp_features.hotkey)
623 return -ENODEV;
625 if (!hotkey_get(&status, &mask))
626 return -EIO;
628 while ((cmd = next_cmd(&buf))) {
629 if (strlencmp(cmd, "enable") == 0) {
630 status = 1;
631 } else if (strlencmp(cmd, "disable") == 0) {
632 status = 0;
633 } else if (strlencmp(cmd, "reset") == 0) {
634 status = hotkey_orig_status;
635 mask = hotkey_orig_mask;
636 } else if (sscanf(cmd, "0x%x", &mask) == 1) {
637 /* mask set */
638 } else if (sscanf(cmd, "%x", &mask) == 1) {
639 /* mask set */
640 } else
641 return -EINVAL;
642 do_cmd = 1;
645 if (do_cmd && !hotkey_set(status, mask))
646 return -EIO;
648 return 0;
651 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = {
652 .hid = IBM_HKEY_HID,
653 .notify = hotkey_notify,
654 .handle = &hkey_handle,
655 .type = ACPI_DEVICE_NOTIFY,
658 static struct ibm_struct hotkey_driver_data = {
659 .name = "hotkey",
660 .read = hotkey_read,
661 .write = hotkey_write,
662 .exit = hotkey_exit,
663 .acpi = &ibm_hotkey_acpidriver,
666 /*************************************************************************
667 * Bluetooth subdriver
670 static int __init bluetooth_init(struct ibm_init_struct *iibm)
672 vdbg_printk(TPACPI_DBG_INIT, "initializing bluetooth subdriver\n");
674 IBM_ACPIHANDLE_INIT(hkey);
676 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
677 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
678 tp_features.bluetooth = hkey_handle &&
679 acpi_evalf(hkey_handle, NULL, "GBDC", "qv");
681 vdbg_printk(TPACPI_DBG_INIT, "bluetooth is %s\n",
682 str_supported(tp_features.bluetooth));
684 return (tp_features.bluetooth)? 0 : 1;
687 static int bluetooth_status(void)
689 int status;
691 if (!tp_features.bluetooth ||
692 !acpi_evalf(hkey_handle, &status, "GBDC", "d"))
693 status = 0;
695 return status;
698 static int bluetooth_read(char *p)
700 int len = 0;
701 int status = bluetooth_status();
703 if (!tp_features.bluetooth)
704 len += sprintf(p + len, "status:\t\tnot supported\n");
705 else if (!(status & 1))
706 len += sprintf(p + len, "status:\t\tnot installed\n");
707 else {
708 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 1));
709 len += sprintf(p + len, "commands:\tenable, disable\n");
712 return len;
715 static int bluetooth_write(char *buf)
717 int status = bluetooth_status();
718 char *cmd;
719 int do_cmd = 0;
721 if (!tp_features.bluetooth)
722 return -ENODEV;
724 while ((cmd = next_cmd(&buf))) {
725 if (strlencmp(cmd, "enable") == 0) {
726 status |= 2;
727 } else if (strlencmp(cmd, "disable") == 0) {
728 status &= ~2;
729 } else
730 return -EINVAL;
731 do_cmd = 1;
734 if (do_cmd && !acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status))
735 return -EIO;
737 return 0;
740 static struct ibm_struct bluetooth_driver_data = {
741 .name = "bluetooth",
742 .read = bluetooth_read,
743 .write = bluetooth_write,
746 /*************************************************************************
747 * Wan subdriver
750 static int __init wan_init(struct ibm_init_struct *iibm)
752 vdbg_printk(TPACPI_DBG_INIT, "initializing wan subdriver\n");
754 IBM_ACPIHANDLE_INIT(hkey);
756 tp_features.wan = hkey_handle &&
757 acpi_evalf(hkey_handle, NULL, "GWAN", "qv");
759 vdbg_printk(TPACPI_DBG_INIT, "wan is %s\n",
760 str_supported(tp_features.wan));
762 return (tp_features.wan)? 0 : 1;
765 static int wan_status(void)
767 int status;
769 if (!tp_features.wan ||
770 !acpi_evalf(hkey_handle, &status, "GWAN", "d"))
771 status = 0;
773 return status;
776 static int wan_read(char *p)
778 int len = 0;
779 int status = wan_status();
781 if (!tp_features.wan)
782 len += sprintf(p + len, "status:\t\tnot supported\n");
783 else if (!(status & 1))
784 len += sprintf(p + len, "status:\t\tnot installed\n");
785 else {
786 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 1));
787 len += sprintf(p + len, "commands:\tenable, disable\n");
790 return len;
793 static int wan_write(char *buf)
795 int status = wan_status();
796 char *cmd;
797 int do_cmd = 0;
799 if (!tp_features.wan)
800 return -ENODEV;
802 while ((cmd = next_cmd(&buf))) {
803 if (strlencmp(cmd, "enable") == 0) {
804 status |= 2;
805 } else if (strlencmp(cmd, "disable") == 0) {
806 status &= ~2;
807 } else
808 return -EINVAL;
809 do_cmd = 1;
812 if (do_cmd && !acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status))
813 return -EIO;
815 return 0;
818 static struct ibm_struct wan_driver_data = {
819 .name = "wan",
820 .read = wan_read,
821 .write = wan_write,
822 .flags.experimental = 1,
825 /*************************************************************************
826 * Video subdriver
829 static enum video_access_mode video_supported;
830 static int video_orig_autosw;
832 IBM_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */
833 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
834 "\\_SB.PCI0.VID0", /* 770e */
835 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
836 "\\_SB.PCI0.AGP.VID", /* all others */
837 ); /* R30, R31 */
839 IBM_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */
841 static int __init video_init(struct ibm_init_struct *iibm)
843 int ivga;
845 vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n");
847 IBM_ACPIHANDLE_INIT(vid);
848 IBM_ACPIHANDLE_INIT(vid2);
850 if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga)
851 /* G41, assume IVGA doesn't change */
852 vid_handle = vid2_handle;
854 if (!vid_handle)
855 /* video switching not supported on R30, R31 */
856 video_supported = TPACPI_VIDEO_NONE;
857 else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd"))
858 /* 570 */
859 video_supported = TPACPI_VIDEO_570;
860 else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd"))
861 /* 600e/x, 770e, 770x */
862 video_supported = TPACPI_VIDEO_770;
863 else
864 /* all others */
865 video_supported = TPACPI_VIDEO_NEW;
867 vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n",
868 str_supported(video_supported != TPACPI_VIDEO_NONE),
869 video_supported);
871 return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1;
874 static void video_exit(void)
876 dbg_printk(TPACPI_DBG_EXIT, "restoring original video autoswitch mode\n");
877 acpi_evalf(vid_handle, NULL, "_DOS", "vd", video_orig_autosw);
880 static int video_status(void)
882 int status = 0;
883 int i;
885 if (video_supported == TPACPI_VIDEO_570) {
886 if (acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", 0x87))
887 status = i & 3;
888 } else if (video_supported == TPACPI_VIDEO_770) {
889 if (acpi_evalf(NULL, &i, "\\VCDL", "d"))
890 status |= 0x01 * i;
891 if (acpi_evalf(NULL, &i, "\\VCDC", "d"))
892 status |= 0x02 * i;
893 } else if (video_supported == TPACPI_VIDEO_NEW) {
894 acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1);
895 if (acpi_evalf(NULL, &i, "\\VCDC", "d"))
896 status |= 0x02 * i;
898 acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0);
899 if (acpi_evalf(NULL, &i, "\\VCDL", "d"))
900 status |= 0x01 * i;
901 if (acpi_evalf(NULL, &i, "\\VCDD", "d"))
902 status |= 0x08 * i;
905 return status;
908 static int video_autosw(void)
910 int autosw = 0;
912 if (video_supported == TPACPI_VIDEO_570)
913 acpi_evalf(vid_handle, &autosw, "SWIT", "d");
914 else if (video_supported == TPACPI_VIDEO_770 ||
915 video_supported == TPACPI_VIDEO_NEW)
916 acpi_evalf(vid_handle, &autosw, "^VDEE", "d");
918 return autosw & 1;
921 static int video_switch(void)
923 int autosw = video_autosw();
924 int ret;
926 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
927 return -EIO;
928 ret = video_supported == TPACPI_VIDEO_570 ?
929 acpi_evalf(ec_handle, NULL, "_Q16", "v") :
930 acpi_evalf(vid_handle, NULL, "VSWT", "v");
931 acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw);
933 return ret;
936 static int video_expand(void)
938 if (video_supported == TPACPI_VIDEO_570)
939 return acpi_evalf(ec_handle, NULL, "_Q17", "v");
940 else if (video_supported == TPACPI_VIDEO_770)
941 return acpi_evalf(vid_handle, NULL, "VEXP", "v");
942 else
943 return acpi_evalf(NULL, NULL, "\\VEXP", "v");
946 static int video_switch2(int status)
948 int ret;
950 if (video_supported == TPACPI_VIDEO_570) {
951 ret = acpi_evalf(NULL, NULL,
952 "\\_SB.PHS2", "vdd", 0x8b, status | 0x80);
953 } else if (video_supported == TPACPI_VIDEO_770) {
954 int autosw = video_autosw();
955 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
956 return -EIO;
958 ret = acpi_evalf(vid_handle, NULL,
959 "ASWT", "vdd", status * 0x100, 0);
961 acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw);
962 } else {
963 ret = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) &&
964 acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1);
967 return ret;
970 static int video_read(char *p)
972 int status = video_status();
973 int autosw = video_autosw();
974 int len = 0;
976 if (!video_supported) {
977 len += sprintf(p + len, "status:\t\tnot supported\n");
978 return len;
981 len += sprintf(p + len, "status:\t\tsupported\n");
982 len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0));
983 len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1));
984 if (video_supported == TPACPI_VIDEO_NEW)
985 len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3));
986 len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0));
987 len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n");
988 len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n");
989 if (video_supported == TPACPI_VIDEO_NEW)
990 len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n");
991 len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n");
992 len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n");
994 return len;
997 static int video_write(char *buf)
999 char *cmd;
1000 int enable, disable, status;
1002 if (!video_supported)
1003 return -ENODEV;
1005 enable = disable = 0;
1007 while ((cmd = next_cmd(&buf))) {
1008 if (strlencmp(cmd, "lcd_enable") == 0) {
1009 enable |= 0x01;
1010 } else if (strlencmp(cmd, "lcd_disable") == 0) {
1011 disable |= 0x01;
1012 } else if (strlencmp(cmd, "crt_enable") == 0) {
1013 enable |= 0x02;
1014 } else if (strlencmp(cmd, "crt_disable") == 0) {
1015 disable |= 0x02;
1016 } else if (video_supported == TPACPI_VIDEO_NEW &&
1017 strlencmp(cmd, "dvi_enable") == 0) {
1018 enable |= 0x08;
1019 } else if (video_supported == TPACPI_VIDEO_NEW &&
1020 strlencmp(cmd, "dvi_disable") == 0) {
1021 disable |= 0x08;
1022 } else if (strlencmp(cmd, "auto_enable") == 0) {
1023 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
1024 return -EIO;
1025 } else if (strlencmp(cmd, "auto_disable") == 0) {
1026 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 0))
1027 return -EIO;
1028 } else if (strlencmp(cmd, "video_switch") == 0) {
1029 if (!video_switch())
1030 return -EIO;
1031 } else if (strlencmp(cmd, "expand_toggle") == 0) {
1032 if (!video_expand())
1033 return -EIO;
1034 } else
1035 return -EINVAL;
1038 if (enable || disable) {
1039 status = (video_status() & 0x0f & ~disable) | enable;
1040 if (!video_switch2(status))
1041 return -EIO;
1044 return 0;
1047 static struct ibm_struct video_driver_data = {
1048 .name = "video",
1049 .read = video_read,
1050 .write = video_write,
1051 .exit = video_exit,
1054 /*************************************************************************
1055 * Light (thinklight) subdriver
1058 IBM_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
1059 IBM_HANDLE(ledb, ec, "LEDB"); /* G4x */
1061 static int __init light_init(struct ibm_init_struct *iibm)
1063 vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n");
1065 IBM_ACPIHANDLE_INIT(ledb);
1066 IBM_ACPIHANDLE_INIT(lght);
1067 IBM_ACPIHANDLE_INIT(cmos);
1069 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
1070 tp_features.light = (cmos_handle || lght_handle) && !ledb_handle;
1072 if (tp_features.light)
1073 /* light status not supported on
1074 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
1075 tp_features.light_status =
1076 acpi_evalf(ec_handle, NULL, "KBLT", "qv");
1078 vdbg_printk(TPACPI_DBG_INIT, "light is %s\n",
1079 str_supported(tp_features.light));
1081 return (tp_features.light)? 0 : 1;
1084 static int light_read(char *p)
1086 int len = 0;
1087 int status = 0;
1089 if (!tp_features.light) {
1090 len += sprintf(p + len, "status:\t\tnot supported\n");
1091 } else if (!tp_features.light_status) {
1092 len += sprintf(p + len, "status:\t\tunknown\n");
1093 len += sprintf(p + len, "commands:\ton, off\n");
1094 } else {
1095 if (!acpi_evalf(ec_handle, &status, "KBLT", "d"))
1096 return -EIO;
1097 len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0));
1098 len += sprintf(p + len, "commands:\ton, off\n");
1101 return len;
1104 static int light_write(char *buf)
1106 int cmos_cmd, lght_cmd;
1107 char *cmd;
1108 int success;
1110 if (!tp_features.light)
1111 return -ENODEV;
1113 while ((cmd = next_cmd(&buf))) {
1114 if (strlencmp(cmd, "on") == 0) {
1115 cmos_cmd = 0x0c;
1116 lght_cmd = 1;
1117 } else if (strlencmp(cmd, "off") == 0) {
1118 cmos_cmd = 0x0d;
1119 lght_cmd = 0;
1120 } else
1121 return -EINVAL;
1123 success = cmos_handle ?
1124 acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd) :
1125 acpi_evalf(lght_handle, NULL, NULL, "vd", lght_cmd);
1126 if (!success)
1127 return -EIO;
1130 return 0;
1133 static struct ibm_struct light_driver_data = {
1134 .name = "light",
1135 .read = light_read,
1136 .write = light_write,
1139 /*************************************************************************
1140 * Dock subdriver
1143 #ifdef CONFIG_THINKPAD_ACPI_DOCK
1145 IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */
1146 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
1147 "\\_SB.PCI0.PCI1.DOCK", /* all others */
1148 "\\_SB.PCI.ISA.SLCE", /* 570 */
1149 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
1151 /* don't list other alternatives as we install a notify handler on the 570 */
1152 IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */
1154 #define dock_docked() (_sta(dock_handle) & 1)
1156 static int __init dock_init(struct ibm_init_struct *iibm)
1158 vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver\n");
1160 IBM_ACPIHANDLE_INIT(dock);
1161 IBM_ACPIHANDLE_INIT(pci);
1163 vdbg_printk(TPACPI_DBG_INIT, "dock is %s\n",
1164 str_supported(dock_handle != NULL));
1166 return (dock_handle)? 0 : 1;
1169 static void dock_notify(struct ibm_struct *ibm, u32 event)
1171 int docked = dock_docked();
1172 int pci = ibm->acpi->hid && strstr(ibm->acpi->hid, IBM_PCI_HID);
1174 if (event == 1 && !pci) /* 570 */
1175 acpi_bus_generate_event(ibm->acpi->device, event, 1); /* button */
1176 else if (event == 1 && pci) /* 570 */
1177 acpi_bus_generate_event(ibm->acpi->device, event, 3); /* dock */
1178 else if (event == 3 && docked)
1179 acpi_bus_generate_event(ibm->acpi->device, event, 1); /* button */
1180 else if (event == 3 && !docked)
1181 acpi_bus_generate_event(ibm->acpi->device, event, 2); /* undock */
1182 else if (event == 0 && docked)
1183 acpi_bus_generate_event(ibm->acpi->device, event, 3); /* dock */
1184 else {
1185 printk(IBM_ERR "unknown dock event %d, status %d\n",
1186 event, _sta(dock_handle));
1187 acpi_bus_generate_event(ibm->acpi->device, event, 0); /* unknown */
1191 static int dock_read(char *p)
1193 int len = 0;
1194 int docked = dock_docked();
1196 if (!dock_handle)
1197 len += sprintf(p + len, "status:\t\tnot supported\n");
1198 else if (!docked)
1199 len += sprintf(p + len, "status:\t\tundocked\n");
1200 else {
1201 len += sprintf(p + len, "status:\t\tdocked\n");
1202 len += sprintf(p + len, "commands:\tdock, undock\n");
1205 return len;
1208 static int dock_write(char *buf)
1210 char *cmd;
1212 if (!dock_docked())
1213 return -ENODEV;
1215 while ((cmd = next_cmd(&buf))) {
1216 if (strlencmp(cmd, "undock") == 0) {
1217 if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0) ||
1218 !acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1))
1219 return -EIO;
1220 } else if (strlencmp(cmd, "dock") == 0) {
1221 if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1))
1222 return -EIO;
1223 } else
1224 return -EINVAL;
1227 return 0;
1230 static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = {
1232 .notify = dock_notify,
1233 .handle = &dock_handle,
1234 .type = ACPI_SYSTEM_NOTIFY,
1237 .hid = IBM_PCI_HID,
1238 .notify = dock_notify,
1239 .handle = &pci_handle,
1240 .type = ACPI_SYSTEM_NOTIFY,
1244 static struct ibm_struct dock_driver_data[2] = {
1246 .name = "dock",
1247 .read = dock_read,
1248 .write = dock_write,
1249 .acpi = &ibm_dock_acpidriver[0],
1252 .name = "dock",
1253 .acpi = &ibm_dock_acpidriver[1],
1257 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
1259 /*************************************************************************
1260 * Bay subdriver
1263 #ifdef CONFIG_THINKPAD_ACPI_BAY
1264 IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
1265 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
1266 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
1267 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
1268 ); /* A21e, R30, R31 */
1269 IBM_HANDLE(bay_ej, bay, "_EJ3", /* 600e/x, A2xm/p, A3x */
1270 "_EJ0", /* all others */
1271 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
1272 IBM_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
1273 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
1274 ); /* all others */
1275 IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */
1276 "_EJ0", /* 770x */
1277 ); /* all others */
1279 static int __init bay_init(struct ibm_init_struct *iibm)
1281 vdbg_printk(TPACPI_DBG_INIT, "initializing bay subdriver\n");
1283 IBM_ACPIHANDLE_INIT(bay);
1284 if (bay_handle)
1285 IBM_ACPIHANDLE_INIT(bay_ej);
1286 IBM_ACPIHANDLE_INIT(bay2);
1287 if (bay2_handle)
1288 IBM_ACPIHANDLE_INIT(bay2_ej);
1290 tp_features.bay_status = bay_handle &&
1291 acpi_evalf(bay_handle, NULL, "_STA", "qv");
1292 tp_features.bay_status2 = bay2_handle &&
1293 acpi_evalf(bay2_handle, NULL, "_STA", "qv");
1295 tp_features.bay_eject = bay_handle && bay_ej_handle &&
1296 (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental);
1297 tp_features.bay_eject2 = bay2_handle && bay2_ej_handle &&
1298 (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental);
1300 vdbg_printk(TPACPI_DBG_INIT,
1301 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
1302 str_supported(tp_features.bay_status),
1303 str_supported(tp_features.bay_eject),
1304 str_supported(tp_features.bay_status2),
1305 str_supported(tp_features.bay_eject2));
1307 return (tp_features.bay_status || tp_features.bay_eject ||
1308 tp_features.bay_status2 || tp_features.bay_eject2)? 0 : 1;
1311 static void bay_notify(struct ibm_struct *ibm, u32 event)
1313 acpi_bus_generate_event(ibm->acpi->device, event, 0);
1316 #define bay_occupied(b) (_sta(b##_handle) & 1)
1318 static int bay_read(char *p)
1320 int len = 0;
1321 int occupied = bay_occupied(bay);
1322 int occupied2 = bay_occupied(bay2);
1323 int eject, eject2;
1325 len += sprintf(p + len, "status:\t\t%s\n",
1326 tp_features.bay_status ?
1327 (occupied ? "occupied" : "unoccupied") :
1328 "not supported");
1329 if (tp_features.bay_status2)
1330 len += sprintf(p + len, "status2:\t%s\n", occupied2 ?
1331 "occupied" : "unoccupied");
1333 eject = tp_features.bay_eject && occupied;
1334 eject2 = tp_features.bay_eject2 && occupied2;
1336 if (eject && eject2)
1337 len += sprintf(p + len, "commands:\teject, eject2\n");
1338 else if (eject)
1339 len += sprintf(p + len, "commands:\teject\n");
1340 else if (eject2)
1341 len += sprintf(p + len, "commands:\teject2\n");
1343 return len;
1346 static int bay_write(char *buf)
1348 char *cmd;
1350 if (!tp_features.bay_eject && !tp_features.bay_eject2)
1351 return -ENODEV;
1353 while ((cmd = next_cmd(&buf))) {
1354 if (tp_features.bay_eject && strlencmp(cmd, "eject") == 0) {
1355 if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1))
1356 return -EIO;
1357 } else if (tp_features.bay_eject2 &&
1358 strlencmp(cmd, "eject2") == 0) {
1359 if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1))
1360 return -EIO;
1361 } else
1362 return -EINVAL;
1365 return 0;
1368 static struct tp_acpi_drv_struct ibm_bay_acpidriver = {
1369 .notify = bay_notify,
1370 .handle = &bay_handle,
1371 .type = ACPI_SYSTEM_NOTIFY,
1374 static struct ibm_struct bay_driver_data = {
1375 .name = "bay",
1376 .read = bay_read,
1377 .write = bay_write,
1378 .acpi = &ibm_bay_acpidriver,
1381 #endif /* CONFIG_THINKPAD_ACPI_BAY */
1383 /*************************************************************************
1384 * CMOS subdriver
1387 static int __init cmos_init(struct ibm_init_struct *iibm)
1389 vdbg_printk(TPACPI_DBG_INIT,
1390 "initializing cmos commands subdriver\n");
1392 IBM_ACPIHANDLE_INIT(cmos);
1394 vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n",
1395 str_supported(cmos_handle != NULL));
1396 return (cmos_handle)? 0 : 1;
1399 static int cmos_eval(int cmos_cmd)
1401 if (cmos_handle)
1402 return acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd);
1403 else
1404 return 1;
1407 static int cmos_read(char *p)
1409 int len = 0;
1411 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1412 R30, R31, T20-22, X20-21 */
1413 if (!cmos_handle)
1414 len += sprintf(p + len, "status:\t\tnot supported\n");
1415 else {
1416 len += sprintf(p + len, "status:\t\tsupported\n");
1417 len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n");
1420 return len;
1423 static int cmos_write(char *buf)
1425 char *cmd;
1426 int cmos_cmd;
1428 if (!cmos_handle)
1429 return -EINVAL;
1431 while ((cmd = next_cmd(&buf))) {
1432 if (sscanf(cmd, "%u", &cmos_cmd) == 1 &&
1433 cmos_cmd >= 0 && cmos_cmd <= 21) {
1434 /* cmos_cmd set */
1435 } else
1436 return -EINVAL;
1438 if (!cmos_eval(cmos_cmd))
1439 return -EIO;
1442 return 0;
1445 static struct ibm_struct cmos_driver_data = {
1446 .name = "cmos",
1447 .read = cmos_read,
1448 .write = cmos_write,
1451 /*************************************************************************
1452 * LED subdriver
1455 static enum led_access_mode led_supported;
1457 IBM_HANDLE(led, ec, "SLED", /* 570 */
1458 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1459 "LED", /* all others */
1460 ); /* R30, R31 */
1462 static int __init led_init(struct ibm_init_struct *iibm)
1464 vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n");
1466 IBM_ACPIHANDLE_INIT(led);
1468 if (!led_handle)
1469 /* led not supported on R30, R31 */
1470 led_supported = TPACPI_LED_NONE;
1471 else if (strlencmp(led_path, "SLED") == 0)
1472 /* 570 */
1473 led_supported = TPACPI_LED_570;
1474 else if (strlencmp(led_path, "SYSL") == 0)
1475 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1476 led_supported = TPACPI_LED_OLD;
1477 else
1478 /* all others */
1479 led_supported = TPACPI_LED_NEW;
1481 vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n",
1482 str_supported(led_supported), led_supported);
1484 return (led_supported != TPACPI_LED_NONE)? 0 : 1;
1487 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
1489 static int led_read(char *p)
1491 int len = 0;
1493 if (!led_supported) {
1494 len += sprintf(p + len, "status:\t\tnot supported\n");
1495 return len;
1497 len += sprintf(p + len, "status:\t\tsupported\n");
1499 if (led_supported == TPACPI_LED_570) {
1500 /* 570 */
1501 int i, status;
1502 for (i = 0; i < 8; i++) {
1503 if (!acpi_evalf(ec_handle,
1504 &status, "GLED", "dd", 1 << i))
1505 return -EIO;
1506 len += sprintf(p + len, "%d:\t\t%s\n",
1507 i, led_status(status));
1511 len += sprintf(p + len, "commands:\t"
1512 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
1514 return len;
1517 /* off, on, blink */
1518 static const int led_sled_arg1[] = { 0, 1, 3 };
1519 static const int led_exp_hlbl[] = { 0, 0, 1 }; /* led# * */
1520 static const int led_exp_hlcl[] = { 0, 1, 1 }; /* led# * */
1521 static const int led_led_arg1[] = { 0, 0x80, 0xc0 };
1523 static int led_write(char *buf)
1525 char *cmd;
1526 int led, ind, ret;
1528 if (!led_supported)
1529 return -ENODEV;
1531 while ((cmd = next_cmd(&buf))) {
1532 if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 7)
1533 return -EINVAL;
1535 if (strstr(cmd, "off")) {
1536 ind = 0;
1537 } else if (strstr(cmd, "on")) {
1538 ind = 1;
1539 } else if (strstr(cmd, "blink")) {
1540 ind = 2;
1541 } else
1542 return -EINVAL;
1544 if (led_supported == TPACPI_LED_570) {
1545 /* 570 */
1546 led = 1 << led;
1547 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
1548 led, led_sled_arg1[ind]))
1549 return -EIO;
1550 } else if (led_supported == TPACPI_LED_OLD) {
1551 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
1552 led = 1 << led;
1553 ret = ec_write(TPACPI_LED_EC_HLMS, led);
1554 if (ret >= 0)
1555 ret =
1556 ec_write(TPACPI_LED_EC_HLBL,
1557 led * led_exp_hlbl[ind]);
1558 if (ret >= 0)
1559 ret =
1560 ec_write(TPACPI_LED_EC_HLCL,
1561 led * led_exp_hlcl[ind]);
1562 if (ret < 0)
1563 return ret;
1564 } else {
1565 /* all others */
1566 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
1567 led, led_led_arg1[ind]))
1568 return -EIO;
1572 return 0;
1575 static struct ibm_struct led_driver_data = {
1576 .name = "led",
1577 .read = led_read,
1578 .write = led_write,
1581 /*************************************************************************
1582 * Beep subdriver
1585 IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */
1587 static int __init beep_init(struct ibm_init_struct *iibm)
1589 vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n");
1591 IBM_ACPIHANDLE_INIT(beep);
1593 vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n",
1594 str_supported(beep_handle != NULL));
1596 return (beep_handle)? 0 : 1;
1599 static int beep_read(char *p)
1601 int len = 0;
1603 if (!beep_handle)
1604 len += sprintf(p + len, "status:\t\tnot supported\n");
1605 else {
1606 len += sprintf(p + len, "status:\t\tsupported\n");
1607 len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n");
1610 return len;
1613 static int beep_write(char *buf)
1615 char *cmd;
1616 int beep_cmd;
1618 if (!beep_handle)
1619 return -ENODEV;
1621 while ((cmd = next_cmd(&buf))) {
1622 if (sscanf(cmd, "%u", &beep_cmd) == 1 &&
1623 beep_cmd >= 0 && beep_cmd <= 17) {
1624 /* beep_cmd set */
1625 } else
1626 return -EINVAL;
1627 if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", beep_cmd, 0))
1628 return -EIO;
1631 return 0;
1634 static struct ibm_struct beep_driver_data = {
1635 .name = "beep",
1636 .read = beep_read,
1637 .write = beep_write,
1640 /*************************************************************************
1641 * Thermal subdriver
1644 static enum thermal_access_mode thermal_read_mode;
1646 static int __init thermal_init(struct ibm_init_struct *iibm)
1648 u8 t, ta1, ta2;
1649 int i;
1650 int acpi_tmp7;
1652 vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n");
1654 acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv");
1656 if (ibm_thinkpad_ec_found && experimental) {
1658 * Direct EC access mode: sensors at registers
1659 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
1660 * non-implemented, thermal sensors return 0x80 when
1661 * not available
1664 ta1 = ta2 = 0;
1665 for (i = 0; i < 8; i++) {
1666 if (likely(acpi_ec_read(0x78 + i, &t))) {
1667 ta1 |= t;
1668 } else {
1669 ta1 = 0;
1670 break;
1672 if (likely(acpi_ec_read(0xC0 + i, &t))) {
1673 ta2 |= t;
1674 } else {
1675 ta1 = 0;
1676 break;
1679 if (ta1 == 0) {
1680 /* This is sheer paranoia, but we handle it anyway */
1681 if (acpi_tmp7) {
1682 printk(IBM_ERR
1683 "ThinkPad ACPI EC access misbehaving, "
1684 "falling back to ACPI TMPx access mode\n");
1685 thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07;
1686 } else {
1687 printk(IBM_ERR
1688 "ThinkPad ACPI EC access misbehaving, "
1689 "disabling thermal sensors access\n");
1690 thermal_read_mode = TPACPI_THERMAL_NONE;
1692 } else {
1693 thermal_read_mode =
1694 (ta2 != 0) ?
1695 TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8;
1697 } else if (acpi_tmp7) {
1698 if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) {
1699 /* 600e/x, 770e, 770x */
1700 thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT;
1701 } else {
1702 /* Standard ACPI TMPx access, max 8 sensors */
1703 thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07;
1705 } else {
1706 /* temperatures not supported on 570, G4x, R30, R31, R32 */
1707 thermal_read_mode = TPACPI_THERMAL_NONE;
1710 vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n",
1711 str_supported(thermal_read_mode != TPACPI_THERMAL_NONE),
1712 thermal_read_mode);
1714 return (thermal_read_mode != TPACPI_THERMAL_NONE)? 0 : 1;
1717 static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
1719 int i, t;
1720 s8 tmp;
1721 char tmpi[] = "TMPi";
1723 if (!s)
1724 return -EINVAL;
1726 switch (thermal_read_mode) {
1727 #if TPACPI_MAX_THERMAL_SENSORS >= 16
1728 case TPACPI_THERMAL_TPEC_16:
1729 for (i = 0; i < 8; i++) {
1730 if (!acpi_ec_read(0xC0 + i, &tmp))
1731 return -EIO;
1732 s->temp[i + 8] = tmp * 1000;
1734 /* fallthrough */
1735 #endif
1736 case TPACPI_THERMAL_TPEC_8:
1737 for (i = 0; i < 8; i++) {
1738 if (!acpi_ec_read(0x78 + i, &tmp))
1739 return -EIO;
1740 s->temp[i] = tmp * 1000;
1742 return (thermal_read_mode == TPACPI_THERMAL_TPEC_16) ? 16 : 8;
1744 case TPACPI_THERMAL_ACPI_UPDT:
1745 if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
1746 return -EIO;
1747 for (i = 0; i < 8; i++) {
1748 tmpi[3] = '0' + i;
1749 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
1750 return -EIO;
1751 s->temp[i] = (t - 2732) * 100;
1753 return 8;
1755 case TPACPI_THERMAL_ACPI_TMP07:
1756 for (i = 0; i < 8; i++) {
1757 tmpi[3] = '0' + i;
1758 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
1759 return -EIO;
1760 s->temp[i] = t * 1000;
1762 return 8;
1764 case TPACPI_THERMAL_NONE:
1765 default:
1766 return 0;
1770 static int thermal_read(char *p)
1772 int len = 0;
1773 int n, i;
1774 struct ibm_thermal_sensors_struct t;
1776 n = thermal_get_sensors(&t);
1777 if (unlikely(n < 0))
1778 return n;
1780 len += sprintf(p + len, "temperatures:\t");
1782 if (n > 0) {
1783 for (i = 0; i < (n - 1); i++)
1784 len += sprintf(p + len, "%d ", t.temp[i] / 1000);
1785 len += sprintf(p + len, "%d\n", t.temp[i] / 1000);
1786 } else
1787 len += sprintf(p + len, "not supported\n");
1789 return len;
1792 static struct ibm_struct thermal_driver_data = {
1793 .name = "thermal",
1794 .read = thermal_read,
1797 /*************************************************************************
1798 * EC Dump subdriver
1801 static u8 ecdump_regs[256];
1803 static int ecdump_read(char *p)
1805 int len = 0;
1806 int i, j;
1807 u8 v;
1809 len += sprintf(p + len, "EC "
1810 " +00 +01 +02 +03 +04 +05 +06 +07"
1811 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
1812 for (i = 0; i < 256; i += 16) {
1813 len += sprintf(p + len, "EC 0x%02x:", i);
1814 for (j = 0; j < 16; j++) {
1815 if (!acpi_ec_read(i + j, &v))
1816 break;
1817 if (v != ecdump_regs[i + j])
1818 len += sprintf(p + len, " *%02x", v);
1819 else
1820 len += sprintf(p + len, " %02x", v);
1821 ecdump_regs[i + j] = v;
1823 len += sprintf(p + len, "\n");
1824 if (j != 16)
1825 break;
1828 /* These are way too dangerous to advertise openly... */
1829 #if 0
1830 len += sprintf(p + len, "commands:\t0x<offset> 0x<value>"
1831 " (<offset> is 00-ff, <value> is 00-ff)\n");
1832 len += sprintf(p + len, "commands:\t0x<offset> <value> "
1833 " (<offset> is 00-ff, <value> is 0-255)\n");
1834 #endif
1835 return len;
1838 static int ecdump_write(char *buf)
1840 char *cmd;
1841 int i, v;
1843 while ((cmd = next_cmd(&buf))) {
1844 if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) {
1845 /* i and v set */
1846 } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) {
1847 /* i and v set */
1848 } else
1849 return -EINVAL;
1850 if (i >= 0 && i < 256 && v >= 0 && v < 256) {
1851 if (!acpi_ec_write(i, v))
1852 return -EIO;
1853 } else
1854 return -EINVAL;
1857 return 0;
1860 static struct ibm_struct ecdump_driver_data = {
1861 .name = "ecdump",
1862 .read = ecdump_read,
1863 .write = ecdump_write,
1864 .flags.experimental = 1,
1867 /*************************************************************************
1868 * Backlight/brightness subdriver
1871 static struct backlight_device *ibm_backlight_device = NULL;
1873 static struct backlight_ops ibm_backlight_data = {
1874 .get_brightness = brightness_get,
1875 .update_status = brightness_update_status,
1878 static int __init brightness_init(struct ibm_init_struct *iibm)
1880 int b;
1882 vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n");
1884 b = brightness_get(NULL);
1885 if (b < 0)
1886 return b;
1888 ibm_backlight_device = backlight_device_register("ibm", NULL, NULL,
1889 &ibm_backlight_data);
1890 if (IS_ERR(ibm_backlight_device)) {
1891 printk(IBM_ERR "Could not register backlight device\n");
1892 return PTR_ERR(ibm_backlight_device);
1894 vdbg_printk(TPACPI_DBG_INIT, "brightness is supported\n");
1896 ibm_backlight_device->props.max_brightness = 7;
1897 ibm_backlight_device->props.brightness = b;
1898 backlight_update_status(ibm_backlight_device);
1900 return 0;
1903 static void brightness_exit(void)
1905 if (ibm_backlight_device) {
1906 vdbg_printk(TPACPI_DBG_EXIT,
1907 "calling backlight_device_unregister()\n");
1908 backlight_device_unregister(ibm_backlight_device);
1909 ibm_backlight_device = NULL;
1913 static int brightness_update_status(struct backlight_device *bd)
1915 return brightness_set(
1916 (bd->props.fb_blank == FB_BLANK_UNBLANK &&
1917 bd->props.power == FB_BLANK_UNBLANK) ?
1918 bd->props.brightness : 0);
1921 static int brightness_get(struct backlight_device *bd)
1923 u8 level;
1924 if (!acpi_ec_read(brightness_offset, &level))
1925 return -EIO;
1927 level &= 0x7;
1929 return level;
1932 static int brightness_set(int value)
1934 int cmos_cmd, inc, i;
1935 int current_value = brightness_get(NULL);
1937 value &= 7;
1939 cmos_cmd = value > current_value ? TP_CMOS_BRIGHTNESS_UP : TP_CMOS_BRIGHTNESS_DOWN;
1940 inc = value > current_value ? 1 : -1;
1941 for (i = current_value; i != value; i += inc) {
1942 if (!cmos_eval(cmos_cmd))
1943 return -EIO;
1944 if (!acpi_ec_write(brightness_offset, i + inc))
1945 return -EIO;
1948 return 0;
1951 static int brightness_read(char *p)
1953 int len = 0;
1954 int level;
1956 if ((level = brightness_get(NULL)) < 0) {
1957 len += sprintf(p + len, "level:\t\tunreadable\n");
1958 } else {
1959 len += sprintf(p + len, "level:\t\t%d\n", level & 0x7);
1960 len += sprintf(p + len, "commands:\tup, down\n");
1961 len += sprintf(p + len, "commands:\tlevel <level>"
1962 " (<level> is 0-7)\n");
1965 return len;
1968 static int brightness_write(char *buf)
1970 int level;
1971 int new_level;
1972 char *cmd;
1974 while ((cmd = next_cmd(&buf))) {
1975 if ((level = brightness_get(NULL)) < 0)
1976 return level;
1977 level &= 7;
1979 if (strlencmp(cmd, "up") == 0) {
1980 new_level = level == 7 ? 7 : level + 1;
1981 } else if (strlencmp(cmd, "down") == 0) {
1982 new_level = level == 0 ? 0 : level - 1;
1983 } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
1984 new_level >= 0 && new_level <= 7) {
1985 /* new_level set */
1986 } else
1987 return -EINVAL;
1989 brightness_set(new_level);
1992 return 0;
1995 static struct ibm_struct brightness_driver_data = {
1996 .name = "brightness",
1997 .read = brightness_read,
1998 .write = brightness_write,
1999 .exit = brightness_exit,
2002 /*************************************************************************
2003 * Volume subdriver
2006 static int volume_read(char *p)
2008 int len = 0;
2009 u8 level;
2011 if (!acpi_ec_read(volume_offset, &level)) {
2012 len += sprintf(p + len, "level:\t\tunreadable\n");
2013 } else {
2014 len += sprintf(p + len, "level:\t\t%d\n", level & 0xf);
2015 len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6));
2016 len += sprintf(p + len, "commands:\tup, down, mute\n");
2017 len += sprintf(p + len, "commands:\tlevel <level>"
2018 " (<level> is 0-15)\n");
2021 return len;
2024 static int volume_write(char *buf)
2026 int cmos_cmd, inc, i;
2027 u8 level, mute;
2028 int new_level, new_mute;
2029 char *cmd;
2031 while ((cmd = next_cmd(&buf))) {
2032 if (!acpi_ec_read(volume_offset, &level))
2033 return -EIO;
2034 new_mute = mute = level & 0x40;
2035 new_level = level = level & 0xf;
2037 if (strlencmp(cmd, "up") == 0) {
2038 if (mute)
2039 new_mute = 0;
2040 else
2041 new_level = level == 15 ? 15 : level + 1;
2042 } else if (strlencmp(cmd, "down") == 0) {
2043 if (mute)
2044 new_mute = 0;
2045 else
2046 new_level = level == 0 ? 0 : level - 1;
2047 } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
2048 new_level >= 0 && new_level <= 15) {
2049 /* new_level set */
2050 } else if (strlencmp(cmd, "mute") == 0) {
2051 new_mute = 0x40;
2052 } else
2053 return -EINVAL;
2055 if (new_level != level) { /* mute doesn't change */
2056 cmos_cmd = new_level > level ? TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN;
2057 inc = new_level > level ? 1 : -1;
2059 if (mute && (!cmos_eval(cmos_cmd) ||
2060 !acpi_ec_write(volume_offset, level)))
2061 return -EIO;
2063 for (i = level; i != new_level; i += inc)
2064 if (!cmos_eval(cmos_cmd) ||
2065 !acpi_ec_write(volume_offset, i + inc))
2066 return -EIO;
2068 if (mute && (!cmos_eval(TP_CMOS_VOLUME_MUTE) ||
2069 !acpi_ec_write(volume_offset,
2070 new_level + mute)))
2071 return -EIO;
2074 if (new_mute != mute) { /* level doesn't change */
2075 cmos_cmd = new_mute ? TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP;
2077 if (!cmos_eval(cmos_cmd) ||
2078 !acpi_ec_write(volume_offset, level + new_mute))
2079 return -EIO;
2083 return 0;
2086 static struct ibm_struct volume_driver_data = {
2087 .name = "volume",
2088 .read = volume_read,
2089 .write = volume_write,
2092 /*************************************************************************
2093 * Fan subdriver
2097 * FAN ACCESS MODES
2099 * TPACPI_FAN_RD_ACPI_GFAN:
2100 * ACPI GFAN method: returns fan level
2102 * see TPACPI_FAN_WR_ACPI_SFAN
2103 * EC 0x2f (HFSP) not available if GFAN exists
2105 * TPACPI_FAN_WR_ACPI_SFAN:
2106 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
2108 * EC 0x2f (HFSP) might be available *for reading*, but do not use
2109 * it for writing.
2111 * TPACPI_FAN_WR_TPEC:
2112 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
2113 * Supported on almost all ThinkPads
2115 * Fan speed changes of any sort (including those caused by the
2116 * disengaged mode) are usually done slowly by the firmware as the
2117 * maximum ammount of fan duty cycle change per second seems to be
2118 * limited.
2120 * Reading is not available if GFAN exists.
2121 * Writing is not available if SFAN exists.
2123 * Bits
2124 * 7 automatic mode engaged;
2125 * (default operation mode of the ThinkPad)
2126 * fan level is ignored in this mode.
2127 * 6 full speed mode (takes precedence over bit 7);
2128 * not available on all thinkpads. May disable
2129 * the tachometer while the fan controller ramps up
2130 * the speed (which can take up to a few *minutes*).
2131 * Speeds up fan to 100% duty-cycle, which is far above
2132 * the standard RPM levels. It is not impossible that
2133 * it could cause hardware damage.
2134 * 5-3 unused in some models. Extra bits for fan level
2135 * in others, but still useless as all values above
2136 * 7 map to the same speed as level 7 in these models.
2137 * 2-0 fan level (0..7 usually)
2138 * 0x00 = stop
2139 * 0x07 = max (set when temperatures critical)
2140 * Some ThinkPads may have other levels, see
2141 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
2143 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
2144 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
2145 * does so, its initial value is meaningless (0x07).
2147 * For firmware bugs, refer to:
2148 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
2150 * ----
2152 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
2153 * Main fan tachometer reading (in RPM)
2155 * This register is present on all ThinkPads with a new-style EC, and
2156 * it is known not to be present on the A21m/e, and T22, as there is
2157 * something else in offset 0x84 according to the ACPI DSDT. Other
2158 * ThinkPads from this same time period (and earlier) probably lack the
2159 * tachometer as well.
2161 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
2162 * was never fixed by IBM to report the EC firmware version string
2163 * probably support the tachometer (like the early X models), so
2164 * detecting it is quite hard. We need more data to know for sure.
2166 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
2167 * might result.
2169 * FIRMWARE BUG: may go stale while the EC is switching to full speed
2170 * mode.
2172 * For firmware bugs, refer to:
2173 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
2175 * TPACPI_FAN_WR_ACPI_FANS:
2176 * ThinkPad X31, X40, X41. Not available in the X60.
2178 * FANS ACPI handle: takes three arguments: low speed, medium speed,
2179 * high speed. ACPI DSDT seems to map these three speeds to levels
2180 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
2181 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
2183 * The speeds are stored on handles
2184 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
2186 * There are three default speed sets, acessible as handles:
2187 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
2189 * ACPI DSDT switches which set is in use depending on various
2190 * factors.
2192 * TPACPI_FAN_WR_TPEC is also available and should be used to
2193 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
2194 * but the ACPI tables just mention level 7.
2197 static enum fan_status_access_mode fan_status_access_mode;
2198 static enum fan_control_access_mode fan_control_access_mode;
2199 static enum fan_control_commands fan_control_commands;
2201 static u8 fan_control_initial_status;
2203 static void fan_watchdog_fire(struct work_struct *ignored);
2204 static int fan_watchdog_maxinterval;
2205 static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire);
2207 IBM_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */
2208 IBM_HANDLE(gfan, ec, "GFAN", /* 570 */
2209 "\\FSPD", /* 600e/x, 770e, 770x */
2210 ); /* all others */
2211 IBM_HANDLE(sfan, ec, "SFAN", /* 570 */
2212 "JFNS", /* 770x-JL */
2213 ); /* all others */
2215 static int __init fan_init(struct ibm_init_struct *iibm)
2217 vdbg_printk(TPACPI_DBG_INIT, "initializing fan subdriver\n");
2219 fan_status_access_mode = TPACPI_FAN_NONE;
2220 fan_control_access_mode = TPACPI_FAN_WR_NONE;
2221 fan_control_commands = 0;
2222 fan_watchdog_maxinterval = 0;
2223 tp_features.fan_ctrl_status_undef = 0;
2225 IBM_ACPIHANDLE_INIT(fans);
2226 IBM_ACPIHANDLE_INIT(gfan);
2227 IBM_ACPIHANDLE_INIT(sfan);
2229 if (gfan_handle) {
2230 /* 570, 600e/x, 770e, 770x */
2231 fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN;
2232 } else {
2233 /* all other ThinkPads: note that even old-style
2234 * ThinkPad ECs supports the fan control register */
2235 if (likely(acpi_ec_read(fan_status_offset,
2236 &fan_control_initial_status))) {
2237 fan_status_access_mode = TPACPI_FAN_RD_TPEC;
2239 /* In some ThinkPads, neither the EC nor the ACPI
2240 * DSDT initialize the fan status, and it ends up
2241 * being set to 0x07 when it *could* be either
2242 * 0x07 or 0x80.
2244 * Enable for TP-1Y (T43), TP-78 (R51e),
2245 * TP-76 (R52), TP-70 (T43, R52), which are known
2246 * to be buggy. */
2247 if (fan_control_initial_status == 0x07 &&
2248 ibm_thinkpad_ec_found &&
2249 ((ibm_thinkpad_ec_found[0] == '1' &&
2250 ibm_thinkpad_ec_found[1] == 'Y') ||
2251 (ibm_thinkpad_ec_found[0] == '7' &&
2252 (ibm_thinkpad_ec_found[1] == '6' ||
2253 ibm_thinkpad_ec_found[1] == '8' ||
2254 ibm_thinkpad_ec_found[1] == '0'))
2255 )) {
2256 printk(IBM_NOTICE
2257 "fan_init: initial fan status is "
2258 "unknown, assuming it is in auto "
2259 "mode\n");
2260 tp_features.fan_ctrl_status_undef = 1;
2262 } else {
2263 printk(IBM_ERR
2264 "ThinkPad ACPI EC access misbehaving, "
2265 "fan status and control unavailable\n");
2266 return 1;
2270 if (sfan_handle) {
2271 /* 570, 770x-JL */
2272 fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN;
2273 fan_control_commands |=
2274 TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE;
2275 } else {
2276 if (!gfan_handle) {
2277 /* gfan without sfan means no fan control */
2278 /* all other models implement TP EC 0x2f control */
2280 if (fans_handle) {
2281 /* X31, X40, X41 */
2282 fan_control_access_mode =
2283 TPACPI_FAN_WR_ACPI_FANS;
2284 fan_control_commands |=
2285 TPACPI_FAN_CMD_SPEED |
2286 TPACPI_FAN_CMD_LEVEL |
2287 TPACPI_FAN_CMD_ENABLE;
2288 } else {
2289 fan_control_access_mode = TPACPI_FAN_WR_TPEC;
2290 fan_control_commands |=
2291 TPACPI_FAN_CMD_LEVEL |
2292 TPACPI_FAN_CMD_ENABLE;
2297 vdbg_printk(TPACPI_DBG_INIT, "fan is %s, modes %d, %d\n",
2298 str_supported(fan_status_access_mode != TPACPI_FAN_NONE ||
2299 fan_control_access_mode != TPACPI_FAN_WR_NONE),
2300 fan_status_access_mode, fan_control_access_mode);
2302 return (fan_status_access_mode != TPACPI_FAN_NONE ||
2303 fan_control_access_mode != TPACPI_FAN_WR_NONE)?
2304 0 : 1;
2307 static int fan_get_status(u8 *status)
2309 u8 s;
2311 /* TODO:
2312 * Add TPACPI_FAN_RD_ACPI_FANS ? */
2314 switch (fan_status_access_mode) {
2315 case TPACPI_FAN_RD_ACPI_GFAN:
2316 /* 570, 600e/x, 770e, 770x */
2318 if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d")))
2319 return -EIO;
2321 if (likely(status))
2322 *status = s & 0x07;
2324 break;
2326 case TPACPI_FAN_RD_TPEC:
2327 /* all except 570, 600e/x, 770e, 770x */
2328 if (unlikely(!acpi_ec_read(fan_status_offset, &s)))
2329 return -EIO;
2331 if (likely(status))
2332 *status = s;
2334 break;
2336 default:
2337 return -ENXIO;
2340 return 0;
2343 static void fan_exit(void)
2345 vdbg_printk(TPACPI_DBG_EXIT, "cancelling any pending watchdogs\n");
2346 cancel_delayed_work(&fan_watchdog_task);
2347 flush_scheduled_work();
2350 static int fan_get_speed(unsigned int *speed)
2352 u8 hi, lo;
2354 switch (fan_status_access_mode) {
2355 case TPACPI_FAN_RD_TPEC:
2356 /* all except 570, 600e/x, 770e, 770x */
2357 if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) ||
2358 !acpi_ec_read(fan_rpm_offset + 1, &hi)))
2359 return -EIO;
2361 if (likely(speed))
2362 *speed = (hi << 8) | lo;
2364 break;
2366 default:
2367 return -ENXIO;
2370 return 0;
2373 static void fan_watchdog_fire(struct work_struct *ignored)
2375 printk(IBM_NOTICE "fan watchdog: enabling fan\n");
2376 if (fan_set_enable()) {
2377 printk(IBM_ERR "fan watchdog: error while enabling fan\n");
2378 /* reschedule for later */
2379 fan_watchdog_reset();
2383 static void fan_watchdog_reset(void)
2385 static int fan_watchdog_active = 0;
2387 if (fan_watchdog_active)
2388 cancel_delayed_work(&fan_watchdog_task);
2390 if (fan_watchdog_maxinterval > 0) {
2391 fan_watchdog_active = 1;
2392 if (!schedule_delayed_work(&fan_watchdog_task,
2393 msecs_to_jiffies(fan_watchdog_maxinterval
2394 * 1000))) {
2395 printk(IBM_ERR "failed to schedule the fan watchdog, "
2396 "watchdog will not trigger\n");
2398 } else
2399 fan_watchdog_active = 0;
2402 static int fan_set_level(int level)
2404 switch (fan_control_access_mode) {
2405 case TPACPI_FAN_WR_ACPI_SFAN:
2406 if (level >= 0 && level <= 7) {
2407 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level))
2408 return -EIO;
2409 } else
2410 return -EINVAL;
2411 break;
2413 case TPACPI_FAN_WR_ACPI_FANS:
2414 case TPACPI_FAN_WR_TPEC:
2415 if ((level != TP_EC_FAN_AUTO) &&
2416 (level != TP_EC_FAN_FULLSPEED) &&
2417 ((level < 0) || (level > 7)))
2418 return -EINVAL;
2420 if (!acpi_ec_write(fan_status_offset, level))
2421 return -EIO;
2422 else
2423 tp_features.fan_ctrl_status_undef = 0;
2424 break;
2426 default:
2427 return -ENXIO;
2429 return 0;
2432 static int fan_set_enable(void)
2434 u8 s;
2435 int rc;
2437 switch (fan_control_access_mode) {
2438 case TPACPI_FAN_WR_ACPI_FANS:
2439 case TPACPI_FAN_WR_TPEC:
2440 if ((rc = fan_get_status(&s)) < 0)
2441 return rc;
2443 /* Don't go out of emergency fan mode */
2444 if (s != 7)
2445 s = TP_EC_FAN_AUTO;
2447 if (!acpi_ec_write(fan_status_offset, s))
2448 return -EIO;
2449 else
2450 tp_features.fan_ctrl_status_undef = 0;
2451 break;
2453 case TPACPI_FAN_WR_ACPI_SFAN:
2454 if ((rc = fan_get_status(&s)) < 0)
2455 return rc;
2457 s &= 0x07;
2459 /* Set fan to at least level 4 */
2460 if (s < 4)
2461 s = 4;
2463 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s))
2464 return -EIO;
2465 break;
2467 default:
2468 return -ENXIO;
2470 return 0;
2473 static int fan_set_disable(void)
2475 switch (fan_control_access_mode) {
2476 case TPACPI_FAN_WR_ACPI_FANS:
2477 case TPACPI_FAN_WR_TPEC:
2478 if (!acpi_ec_write(fan_status_offset, 0x00))
2479 return -EIO;
2480 else
2481 tp_features.fan_ctrl_status_undef = 0;
2482 break;
2484 case TPACPI_FAN_WR_ACPI_SFAN:
2485 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00))
2486 return -EIO;
2487 break;
2489 default:
2490 return -ENXIO;
2492 return 0;
2495 static int fan_set_speed(int speed)
2497 switch (fan_control_access_mode) {
2498 case TPACPI_FAN_WR_ACPI_FANS:
2499 if (speed >= 0 && speed <= 65535) {
2500 if (!acpi_evalf(fans_handle, NULL, NULL, "vddd",
2501 speed, speed, speed))
2502 return -EIO;
2503 } else
2504 return -EINVAL;
2505 break;
2507 default:
2508 return -ENXIO;
2510 return 0;
2513 static int fan_read(char *p)
2515 int len = 0;
2516 int rc;
2517 u8 status;
2518 unsigned int speed = 0;
2520 switch (fan_status_access_mode) {
2521 case TPACPI_FAN_RD_ACPI_GFAN:
2522 /* 570, 600e/x, 770e, 770x */
2523 if ((rc = fan_get_status(&status)) < 0)
2524 return rc;
2526 len += sprintf(p + len, "status:\t\t%s\n"
2527 "level:\t\t%d\n",
2528 (status != 0) ? "enabled" : "disabled", status);
2529 break;
2531 case TPACPI_FAN_RD_TPEC:
2532 /* all except 570, 600e/x, 770e, 770x */
2533 if ((rc = fan_get_status(&status)) < 0)
2534 return rc;
2536 if (unlikely(tp_features.fan_ctrl_status_undef)) {
2537 if (status != fan_control_initial_status)
2538 tp_features.fan_ctrl_status_undef = 0;
2539 else
2540 /* Return most likely status. In fact, it
2541 * might be the only possible status */
2542 status = TP_EC_FAN_AUTO;
2545 len += sprintf(p + len, "status:\t\t%s\n",
2546 (status != 0) ? "enabled" : "disabled");
2548 if ((rc = fan_get_speed(&speed)) < 0)
2549 return rc;
2551 len += sprintf(p + len, "speed:\t\t%d\n", speed);
2553 if (status & TP_EC_FAN_FULLSPEED)
2554 /* Disengaged mode takes precedence */
2555 len += sprintf(p + len, "level:\t\tdisengaged\n");
2556 else if (status & TP_EC_FAN_AUTO)
2557 len += sprintf(p + len, "level:\t\tauto\n");
2558 else
2559 len += sprintf(p + len, "level:\t\t%d\n", status);
2560 break;
2562 case TPACPI_FAN_NONE:
2563 default:
2564 len += sprintf(p + len, "status:\t\tnot supported\n");
2567 if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) {
2568 len += sprintf(p + len, "commands:\tlevel <level>");
2570 switch (fan_control_access_mode) {
2571 case TPACPI_FAN_WR_ACPI_SFAN:
2572 len += sprintf(p + len, " (<level> is 0-7)\n");
2573 break;
2575 default:
2576 len += sprintf(p + len, " (<level> is 0-7, "
2577 "auto, disengaged)\n");
2578 break;
2582 if (fan_control_commands & TPACPI_FAN_CMD_ENABLE)
2583 len += sprintf(p + len, "commands:\tenable, disable\n"
2584 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
2585 "1-120 (seconds))\n");
2587 if (fan_control_commands & TPACPI_FAN_CMD_SPEED)
2588 len += sprintf(p + len, "commands:\tspeed <speed>"
2589 " (<speed> is 0-65535)\n");
2591 return len;
2594 static int fan_write_cmd_level(const char *cmd, int *rc)
2596 int level;
2598 if (strlencmp(cmd, "level auto") == 0)
2599 level = TP_EC_FAN_AUTO;
2600 else if (strlencmp(cmd, "level disengaged") == 0)
2601 level = TP_EC_FAN_FULLSPEED;
2602 else if (sscanf(cmd, "level %d", &level) != 1)
2603 return 0;
2605 if ((*rc = fan_set_level(level)) == -ENXIO)
2606 printk(IBM_ERR "level command accepted for unsupported "
2607 "access mode %d", fan_control_access_mode);
2609 return 1;
2612 static int fan_write_cmd_enable(const char *cmd, int *rc)
2614 if (strlencmp(cmd, "enable") != 0)
2615 return 0;
2617 if ((*rc = fan_set_enable()) == -ENXIO)
2618 printk(IBM_ERR "enable command accepted for unsupported "
2619 "access mode %d", fan_control_access_mode);
2621 return 1;
2624 static int fan_write_cmd_disable(const char *cmd, int *rc)
2626 if (strlencmp(cmd, "disable") != 0)
2627 return 0;
2629 if ((*rc = fan_set_disable()) == -ENXIO)
2630 printk(IBM_ERR "disable command accepted for unsupported "
2631 "access mode %d", fan_control_access_mode);
2633 return 1;
2636 static int fan_write_cmd_speed(const char *cmd, int *rc)
2638 int speed;
2640 /* TODO:
2641 * Support speed <low> <medium> <high> ? */
2643 if (sscanf(cmd, "speed %d", &speed) != 1)
2644 return 0;
2646 if ((*rc = fan_set_speed(speed)) == -ENXIO)
2647 printk(IBM_ERR "speed command accepted for unsupported "
2648 "access mode %d", fan_control_access_mode);
2650 return 1;
2653 static int fan_write_cmd_watchdog(const char *cmd, int *rc)
2655 int interval;
2657 if (sscanf(cmd, "watchdog %d", &interval) != 1)
2658 return 0;
2660 if (interval < 0 || interval > 120)
2661 *rc = -EINVAL;
2662 else
2663 fan_watchdog_maxinterval = interval;
2665 return 1;
2668 static int fan_write(char *buf)
2670 char *cmd;
2671 int rc = 0;
2673 while (!rc && (cmd = next_cmd(&buf))) {
2674 if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) &&
2675 fan_write_cmd_level(cmd, &rc)) &&
2676 !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) &&
2677 (fan_write_cmd_enable(cmd, &rc) ||
2678 fan_write_cmd_disable(cmd, &rc) ||
2679 fan_write_cmd_watchdog(cmd, &rc))) &&
2680 !((fan_control_commands & TPACPI_FAN_CMD_SPEED) &&
2681 fan_write_cmd_speed(cmd, &rc))
2683 rc = -EINVAL;
2684 else if (!rc)
2685 fan_watchdog_reset();
2688 return rc;
2691 static struct ibm_struct fan_driver_data = {
2692 .name = "fan",
2693 .read = fan_read,
2694 .write = fan_write,
2695 .exit = fan_exit,
2696 .flags.experimental = 1,
2699 /****************************************************************************
2700 ****************************************************************************
2702 * Infrastructure
2704 ****************************************************************************
2705 ****************************************************************************/
2707 /* /proc support */
2708 static struct proc_dir_entry *proc_dir = NULL;
2710 /* Subdriver registry */
2711 static LIST_HEAD(tpacpi_all_drivers);
2715 * Module and infrastructure proble, init and exit handling
2718 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
2719 static const char * __init str_supported(int is_supported)
2721 static char text_unsupported[] __initdata = "not supported";
2723 return (is_supported)? &text_unsupported[4] : &text_unsupported[0];
2725 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
2727 static int __init ibm_init(struct ibm_init_struct *iibm)
2729 int ret;
2730 struct ibm_struct *ibm = iibm->data;
2731 struct proc_dir_entry *entry;
2733 BUG_ON(ibm == NULL);
2735 INIT_LIST_HEAD(&ibm->all_drivers);
2737 if (ibm->flags.experimental && !experimental)
2738 return 0;
2740 dbg_printk(TPACPI_DBG_INIT,
2741 "probing for %s\n", ibm->name);
2743 if (iibm->init) {
2744 ret = iibm->init(iibm);
2745 if (ret > 0)
2746 return 0; /* probe failed */
2747 if (ret)
2748 return ret;
2750 ibm->flags.init_called = 1;
2753 if (ibm->acpi) {
2754 if (ibm->acpi->hid) {
2755 ret = register_tpacpi_subdriver(ibm);
2756 if (ret)
2757 goto err_out;
2760 if (ibm->acpi->notify) {
2761 ret = setup_acpi_notify(ibm);
2762 if (ret == -ENODEV) {
2763 printk(IBM_NOTICE "disabling subdriver %s\n",
2764 ibm->name);
2765 ret = 0;
2766 goto err_out;
2768 if (ret < 0)
2769 goto err_out;
2773 dbg_printk(TPACPI_DBG_INIT,
2774 "%s installed\n", ibm->name);
2776 if (ibm->read) {
2777 entry = create_proc_entry(ibm->name,
2778 S_IFREG | S_IRUGO | S_IWUSR,
2779 proc_dir);
2780 if (!entry) {
2781 printk(IBM_ERR "unable to create proc entry %s\n",
2782 ibm->name);
2783 ret = -ENODEV;
2784 goto err_out;
2786 entry->owner = THIS_MODULE;
2787 entry->data = ibm;
2788 entry->read_proc = &dispatch_procfs_read;
2789 if (ibm->write)
2790 entry->write_proc = &dispatch_procfs_write;
2791 ibm->flags.proc_created = 1;
2794 list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers);
2796 return 0;
2798 err_out:
2799 dbg_printk(TPACPI_DBG_INIT,
2800 "%s: at error exit path with result %d\n",
2801 ibm->name, ret);
2803 ibm_exit(ibm);
2804 return (ret < 0)? ret : 0;
2807 static void ibm_exit(struct ibm_struct *ibm)
2809 dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name);
2811 list_del_init(&ibm->all_drivers);
2813 if (ibm->flags.acpi_notify_installed) {
2814 dbg_printk(TPACPI_DBG_EXIT,
2815 "%s: acpi_remove_notify_handler\n", ibm->name);
2816 BUG_ON(!ibm->acpi);
2817 acpi_remove_notify_handler(*ibm->acpi->handle,
2818 ibm->acpi->type,
2819 dispatch_acpi_notify);
2820 ibm->flags.acpi_notify_installed = 0;
2821 ibm->flags.acpi_notify_installed = 0;
2824 if (ibm->flags.proc_created) {
2825 dbg_printk(TPACPI_DBG_EXIT,
2826 "%s: remove_proc_entry\n", ibm->name);
2827 remove_proc_entry(ibm->name, proc_dir);
2828 ibm->flags.proc_created = 0;
2831 if (ibm->flags.acpi_driver_registered) {
2832 dbg_printk(TPACPI_DBG_EXIT,
2833 "%s: acpi_bus_unregister_driver\n", ibm->name);
2834 BUG_ON(!ibm->acpi);
2835 acpi_bus_unregister_driver(ibm->acpi->driver);
2836 kfree(ibm->acpi->driver);
2837 ibm->acpi->driver = NULL;
2838 ibm->flags.acpi_driver_registered = 0;
2841 if (ibm->flags.init_called && ibm->exit) {
2842 ibm->exit();
2843 ibm->flags.init_called = 0;
2846 dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name);
2849 /* Probing */
2851 static char *ibm_thinkpad_ec_found = NULL;
2853 static char* __init check_dmi_for_ec(void)
2855 struct dmi_device *dev = NULL;
2856 char ec_fw_string[18];
2859 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
2860 * X32 or newer, all Z series; Some models must have an
2861 * up-to-date BIOS or they will not be detected.
2863 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
2865 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
2866 if (sscanf(dev->name,
2867 "IBM ThinkPad Embedded Controller -[%17c",
2868 ec_fw_string) == 1) {
2869 ec_fw_string[sizeof(ec_fw_string) - 1] = 0;
2870 ec_fw_string[strcspn(ec_fw_string, " ]")] = 0;
2871 return kstrdup(ec_fw_string, GFP_KERNEL);
2874 return NULL;
2877 static int __init probe_for_thinkpad(void)
2879 int is_thinkpad;
2881 if (acpi_disabled)
2882 return -ENODEV;
2885 * Non-ancient models have better DMI tagging, but very old models
2886 * don't.
2888 is_thinkpad = dmi_name_in_vendors("ThinkPad");
2890 /* ec is required because many other handles are relative to it */
2891 IBM_ACPIHANDLE_INIT(ec);
2892 if (!ec_handle) {
2893 if (is_thinkpad)
2894 printk(IBM_ERR
2895 "Not yet supported ThinkPad detected!\n");
2896 return -ENODEV;
2900 * Risks a regression on very old machines, but reduces potential
2901 * false positives a damn great deal
2903 if (!is_thinkpad)
2904 is_thinkpad = dmi_name_in_vendors("IBM");
2906 if (!is_thinkpad && !force_load)
2907 return -ENODEV;
2909 return 0;
2913 /* Module init, exit, parameters */
2915 static struct ibm_init_struct ibms_init[] __initdata = {
2917 .init = thinkpad_acpi_driver_init,
2918 .data = &thinkpad_acpi_driver_data,
2921 .init = hotkey_init,
2922 .data = &hotkey_driver_data,
2925 .init = bluetooth_init,
2926 .data = &bluetooth_driver_data,
2929 .init = wan_init,
2930 .data = &wan_driver_data,
2933 .init = video_init,
2934 .data = &video_driver_data,
2937 .init = light_init,
2938 .data = &light_driver_data,
2940 #ifdef CONFIG_THINKPAD_ACPI_DOCK
2942 .init = dock_init,
2943 .data = &dock_driver_data[0],
2946 .data = &dock_driver_data[1],
2948 #endif
2949 #ifdef CONFIG_THINKPAD_ACPI_BAY
2951 .init = bay_init,
2952 .data = &bay_driver_data,
2954 #endif
2956 .init = cmos_init,
2957 .data = &cmos_driver_data,
2960 .init = led_init,
2961 .data = &led_driver_data,
2964 .init = beep_init,
2965 .data = &beep_driver_data,
2968 .init = thermal_init,
2969 .data = &thermal_driver_data,
2972 .data = &ecdump_driver_data,
2975 .init = brightness_init,
2976 .data = &brightness_driver_data,
2979 .data = &volume_driver_data,
2982 .init = fan_init,
2983 .data = &fan_driver_data,
2987 static int __init set_ibm_param(const char *val, struct kernel_param *kp)
2989 unsigned int i;
2990 struct ibm_struct *ibm;
2992 for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
2993 ibm = ibms_init[i].data;
2994 BUG_ON(ibm == NULL);
2996 if (strcmp(ibm->name, kp->name) == 0 && ibm->write) {
2997 if (strlen(val) > sizeof(ibms_init[i].param) - 2)
2998 return -ENOSPC;
2999 strcpy(ibms_init[i].param, val);
3000 strcat(ibms_init[i].param, ",");
3001 return 0;
3005 return -EINVAL;
3008 static int experimental;
3009 module_param(experimental, int, 0);
3011 static u32 dbg_level;
3012 module_param_named(debug, dbg_level, uint, 0);
3014 static int force_load;
3015 module_param(force_load, int, 0);
3017 #define IBM_PARAM(feature) \
3018 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
3020 IBM_PARAM(hotkey);
3021 IBM_PARAM(bluetooth);
3022 IBM_PARAM(video);
3023 IBM_PARAM(light);
3024 #ifdef CONFIG_THINKPAD_ACPI_DOCK
3025 IBM_PARAM(dock);
3026 #endif
3027 #ifdef CONFIG_THINKPAD_ACPI_BAY
3028 IBM_PARAM(bay);
3029 #endif /* CONFIG_THINKPAD_ACPI_BAY */
3030 IBM_PARAM(cmos);
3031 IBM_PARAM(led);
3032 IBM_PARAM(beep);
3033 IBM_PARAM(ecdump);
3034 IBM_PARAM(brightness);
3035 IBM_PARAM(volume);
3036 IBM_PARAM(fan);
3038 static int __init thinkpad_acpi_module_init(void)
3040 int ret, i;
3042 ret = probe_for_thinkpad();
3043 if (ret)
3044 return ret;
3046 ibm_thinkpad_ec_found = check_dmi_for_ec();
3047 IBM_ACPIHANDLE_INIT(ecrd);
3048 IBM_ACPIHANDLE_INIT(ecwr);
3050 proc_dir = proc_mkdir(IBM_PROC_DIR, acpi_root_dir);
3051 if (!proc_dir) {
3052 printk(IBM_ERR "unable to create proc dir " IBM_PROC_DIR);
3053 thinkpad_acpi_module_exit();
3054 return -ENODEV;
3056 proc_dir->owner = THIS_MODULE;
3058 for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
3059 ret = ibm_init(&ibms_init[i]);
3060 if (ret >= 0 && *ibms_init[i].param)
3061 ret = ibms_init[i].data->write(ibms_init[i].param);
3062 if (ret < 0) {
3063 thinkpad_acpi_module_exit();
3064 return ret;
3068 return 0;
3071 static void thinkpad_acpi_module_exit(void)
3073 struct ibm_struct *ibm, *itmp;
3075 list_for_each_entry_safe_reverse(ibm, itmp,
3076 &tpacpi_all_drivers,
3077 all_drivers) {
3078 ibm_exit(ibm);
3081 dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n");
3083 if (proc_dir)
3084 remove_proc_entry(IBM_PROC_DIR, acpi_root_dir);
3086 kfree(ibm_thinkpad_ec_found);
3089 module_init(thinkpad_acpi_module_init);
3090 module_exit(thinkpad_acpi_module_exit);