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
24 #define IBM_VERSION "0.14"
25 #define TPACPI_SYSFS_VERSION 0x000100
29 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
32 * 2006-11-22 0.13 new maintainer
33 * changelog now lives in git commit history, and will
34 * not be updated further in-file.
36 * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels
37 * 2005-03-17 0.11 support for 600e, 770x
38 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
39 * support for 770e, G41
40 * G40 and G41 don't have a thinklight
41 * temperatures no longer experimental
42 * experimental brightness control
43 * experimental volume control
44 * experimental fan enable/disable
45 * 2005-01-16 0.10 fix module loading on R30, R31
46 * 2005-01-16 0.9 support for 570, R30, R31
47 * ultrabay support on A22p, A3x
48 * limit arg for cmos, led, beep, drop experimental status
49 * more capable led control on A21e, A22p, T20-22, X20
50 * experimental temperatures and fan speed
51 * experimental embedded controller register dump
52 * mark more functions as __init, drop incorrect __exit
54 * thanks to Henrik Brix Andersen <brix@gentoo.org>
55 * fix parameter passing on module loading
56 * thanks to Rusty Russell <rusty@rustcorp.com.au>
57 * thanks to Jim Radford <radford@blackbean.org>
58 * 2004-11-08 0.8 fix init error case, don't return from a macro
59 * thanks to Chris Wright <chrisw@osdl.org>
60 * 2004-10-23 0.7 fix module loading on A21e, A22p, T20, T21, X20
61 * fix led control on A21e
62 * 2004-10-19 0.6 use acpi_bus_register_driver() to claim HKEY device
63 * 2004-10-18 0.5 thinklight support on A21e, G40, R32, T20, T21, X20
64 * proc file format changed
65 * video_switch command
66 * experimental cmos control
67 * experimental led control
68 * experimental acpi sounds
69 * 2004-09-16 0.4 support for module parameters
70 * hotkey mask can be prefixed by 0x
71 * video output switching
72 * video expansion control
73 * ultrabay eject support
74 * removed lcd brightness/on/off control, didn't work
75 * 2004-08-17 0.3 support for R40
76 * lcd off, brightness control
78 * 2004-08-14 0.2 support for T series, X20
79 * bluetooth enable/disable
80 * hotkey events disabled by default
81 * removed fan control, currently useless
82 * 2004-08-09 0.1 initial release, support for X series
85 #include "thinkpad_acpi.h"
87 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
88 MODULE_DESCRIPTION(IBM_DESC);
89 MODULE_VERSION(IBM_VERSION);
90 MODULE_LICENSE("GPL");
92 /* Please remove this in year 2009 */
93 MODULE_ALIAS("ibm_acpi");
95 #define __unused __attribute__ ((unused))
97 /****************************************************************************
98 ****************************************************************************
100 * ACPI Helpers and device model
102 ****************************************************************************
103 ****************************************************************************/
105 /*************************************************************************
109 static acpi_handle root_handle = NULL;
111 #define IBM_HANDLE(object, parent, paths...) \
112 static acpi_handle object##_handle; \
113 static acpi_handle *object##_parent = &parent##_handle; \
114 static char *object##_path; \
115 static char *object##_paths[] = { paths }
117 IBM_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
118 "\\_SB.PCI.ISA.EC", /* 570 */
119 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
120 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
121 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
122 "\\_SB.PCI0.ICH3.EC0", /* R31 */
123 "\\_SB.PCI0.LPC.EC", /* all others */
126 IBM_HANDLE(ecrd, ec, "ECRD"); /* 570 */
127 IBM_HANDLE(ecwr, ec, "ECWR"); /* 570 */
130 /*************************************************************************
134 IBM_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
135 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
136 "\\CMS", /* R40, R40e */
139 IBM_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
140 "^HKEY", /* R30, R31 */
141 "HKEY", /* all others */
145 /*************************************************************************
149 static int acpi_evalf(acpi_handle handle,
150 void *res, char *method, char *fmt, ...)
153 struct acpi_object_list params;
154 union acpi_object in_objs[IBM_MAX_ACPI_ARGS];
155 struct acpi_buffer result, *resultp;
156 union acpi_object out_obj;
164 printk(IBM_ERR "acpi_evalf() called with empty format\n");
177 params.pointer = &in_objs[0];
184 in_objs[params.count].integer.value = va_arg(ap, int);
185 in_objs[params.count++].type = ACPI_TYPE_INTEGER;
187 /* add more types as needed */
189 printk(IBM_ERR "acpi_evalf() called "
190 "with invalid format character '%c'\n", c);
196 if (res_type != 'v') {
197 result.length = sizeof(out_obj);
198 result.pointer = &out_obj;
203 status = acpi_evaluate_object(handle, method, ¶ms, resultp);
208 *(int *)res = out_obj.integer.value;
209 success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER;
212 success = status == AE_OK;
214 /* add more types as needed */
216 printk(IBM_ERR "acpi_evalf() called "
217 "with invalid format character '%c'\n", res_type);
221 if (!success && !quiet)
222 printk(IBM_ERR "acpi_evalf(%s, %s, ...) failed: %d\n",
223 method, fmt0, status);
228 static void __unused acpi_print_int(acpi_handle handle, char *method)
232 if (acpi_evalf(handle, &i, method, "d"))
233 printk(IBM_INFO "%s = 0x%x\n", method, i);
235 printk(IBM_ERR "error calling %s\n", method);
238 static int acpi_ec_read(int i, u8 * p)
243 if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i))
247 if (ec_read(i, p) < 0)
254 static int acpi_ec_write(int i, u8 v)
257 if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v))
260 if (ec_write(i, v) < 0)
267 static int _sta(acpi_handle handle)
271 if (!handle || !acpi_evalf(handle, &status, "_STA", "d"))
277 static int issue_thinkpad_cmos_command(int cmos_cmd)
282 if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd))
288 /*************************************************************************
292 static void drv_acpi_handle_init(char *name,
293 acpi_handle *handle, acpi_handle parent,
294 char **paths, int num_paths, char **path)
299 for (i = 0; i < num_paths; i++) {
300 status = acpi_get_handle(parent, paths[i], handle);
301 if (ACPI_SUCCESS(status)) {
310 static void dispatch_acpi_notify(acpi_handle handle, u32 event, void *data)
312 struct ibm_struct *ibm = data;
314 if (!ibm || !ibm->acpi || !ibm->acpi->notify)
317 ibm->acpi->notify(ibm, event);
320 static int __init setup_acpi_notify(struct ibm_struct *ibm)
327 if (!*ibm->acpi->handle)
330 dbg_printk(TPACPI_DBG_INIT,
331 "setting up ACPI notify for %s\n", ibm->name);
333 ret = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device);
335 printk(IBM_ERR "%s device not present\n", ibm->name);
339 acpi_driver_data(ibm->acpi->device) = ibm;
340 sprintf(acpi_device_class(ibm->acpi->device), "%s/%s",
341 IBM_ACPI_EVENT_PREFIX,
344 status = acpi_install_notify_handler(*ibm->acpi->handle,
345 ibm->acpi->type, dispatch_acpi_notify, ibm);
346 if (ACPI_FAILURE(status)) {
347 if (status == AE_ALREADY_EXISTS) {
348 printk(IBM_NOTICE "another device driver is already handling %s events\n",
351 printk(IBM_ERR "acpi_install_notify_handler(%s) failed: %d\n",
356 ibm->flags.acpi_notify_installed = 1;
360 static int __init tpacpi_device_add(struct acpi_device *device)
365 static int __init register_tpacpi_subdriver(struct ibm_struct *ibm)
369 dbg_printk(TPACPI_DBG_INIT,
370 "registering %s as an ACPI driver\n", ibm->name);
374 ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL);
375 if (!ibm->acpi->driver) {
376 printk(IBM_ERR "kzalloc(ibm->driver) failed\n");
380 sprintf(ibm->acpi->driver->name, "%s_%s", IBM_NAME, ibm->name);
381 ibm->acpi->driver->ids = ibm->acpi->hid;
382 ibm->acpi->driver->ops.add = &tpacpi_device_add;
384 ret = acpi_bus_register_driver(ibm->acpi->driver);
386 printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n",
387 ibm->acpi->hid, ret);
388 kfree(ibm->acpi->driver);
389 ibm->acpi->driver = NULL;
391 ibm->flags.acpi_driver_registered = 1;
397 /****************************************************************************
398 ****************************************************************************
402 ****************************************************************************
403 ****************************************************************************/
405 static int dispatch_procfs_read(char *page, char **start, off_t off,
406 int count, int *eof, void *data)
408 struct ibm_struct *ibm = data;
411 if (!ibm || !ibm->read)
414 len = ibm->read(page);
418 if (len <= off + count)
430 static int dispatch_procfs_write(struct file *file,
431 const char __user * userbuf,
432 unsigned long count, void *data)
434 struct ibm_struct *ibm = data;
438 if (!ibm || !ibm->write)
441 kernbuf = kmalloc(count + 2, GFP_KERNEL);
445 if (copy_from_user(kernbuf, userbuf, count)) {
451 strcat(kernbuf, ",");
452 ret = ibm->write(kernbuf);
461 static char *next_cmd(char **cmds)
466 while ((end = strchr(start, ',')) && end == start)
478 /****************************************************************************
479 ****************************************************************************
481 * Device model: hwmon and platform
483 ****************************************************************************
484 ****************************************************************************/
486 static struct platform_device *tpacpi_pdev = NULL;
487 static struct class_device *tpacpi_hwmon = NULL;
489 static struct platform_driver tpacpi_pdriver = {
491 .name = IBM_DRVR_NAME,
492 .owner = THIS_MODULE,
497 /*************************************************************************
498 * thinkpad-acpi driver attributes
501 /* interface_version --------------------------------------------------- */
502 static ssize_t tpacpi_driver_interface_version_show(
503 struct device_driver *drv,
506 return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION);
509 static DRIVER_ATTR(interface_version, S_IRUGO,
510 tpacpi_driver_interface_version_show, NULL);
512 /* debug_level --------------------------------------------------------- */
513 static ssize_t tpacpi_driver_debug_show(struct device_driver *drv,
516 return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level);
519 static ssize_t tpacpi_driver_debug_store(struct device_driver *drv,
520 const char *buf, size_t count)
525 t = simple_strtoul(buf, &endp, 0);
526 while (*endp && isspace(*endp))
536 static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
537 tpacpi_driver_debug_show, tpacpi_driver_debug_store);
539 /* version ------------------------------------------------------------- */
540 static ssize_t tpacpi_driver_version_show(struct device_driver *drv,
543 return snprintf(buf, PAGE_SIZE, "%s v%s\n", IBM_DESC, IBM_VERSION);
546 static DRIVER_ATTR(version, S_IRUGO,
547 tpacpi_driver_version_show, NULL);
549 /* --------------------------------------------------------------------- */
551 static struct driver_attribute* tpacpi_driver_attributes[] = {
552 &driver_attr_debug_level, &driver_attr_version,
553 &driver_attr_interface_version,
556 static int __init tpacpi_create_driver_attributes(struct device_driver *drv)
562 while (!res && i < ARRAY_SIZE(tpacpi_driver_attributes)) {
563 res = driver_create_file(drv, tpacpi_driver_attributes[i]);
570 static void tpacpi_remove_driver_attributes(struct device_driver *drv)
574 for(i = 0; i < ARRAY_SIZE(tpacpi_driver_attributes); i++)
575 driver_remove_file(drv, tpacpi_driver_attributes[i]);
578 /****************************************************************************
579 ****************************************************************************
583 ****************************************************************************
584 ****************************************************************************/
586 /*************************************************************************
587 * thinkpad-acpi init subdriver
590 static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm)
592 printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION);
593 printk(IBM_INFO "%s\n", IBM_URL);
595 if (ibm_thinkpad_ec_found)
596 printk(IBM_INFO "ThinkPad EC firmware %s\n",
597 ibm_thinkpad_ec_found);
602 static int thinkpad_acpi_driver_read(char *p)
606 len += sprintf(p + len, "driver:\t\t%s\n", IBM_DESC);
607 len += sprintf(p + len, "version:\t%s\n", IBM_VERSION);
612 static struct ibm_struct thinkpad_acpi_driver_data = {
614 .read = thinkpad_acpi_driver_read,
617 /*************************************************************************
621 static int hotkey_orig_status;
622 static int hotkey_orig_mask;
624 static int __init hotkey_init(struct ibm_init_struct *iibm)
628 vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n");
630 IBM_ACPIHANDLE_INIT(hkey);
632 /* hotkey not supported on 570 */
633 tp_features.hotkey = hkey_handle != NULL;
635 vdbg_printk(TPACPI_DBG_INIT, "hotkeys are %s\n",
636 str_supported(tp_features.hotkey));
638 if (tp_features.hotkey) {
639 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
640 A30, R30, R31, T20-22, X20-21, X22-24 */
641 tp_features.hotkey_mask =
642 acpi_evalf(hkey_handle, NULL, "DHKN", "qv");
644 vdbg_printk(TPACPI_DBG_INIT, "hotkey masks are %s\n",
645 str_supported(tp_features.hotkey_mask));
647 res = hotkey_get(&hotkey_orig_status, &hotkey_orig_mask);
652 return (tp_features.hotkey)? 0 : 1;
655 static void hotkey_exit(void)
659 if (tp_features.hotkey) {
660 dbg_printk(TPACPI_DBG_EXIT, "restoring original hotkey mask\n");
661 res = hotkey_set(hotkey_orig_status, hotkey_orig_mask);
663 printk(IBM_ERR "failed to restore hotkey to BIOS defaults\n");
667 static void hotkey_notify(struct ibm_struct *ibm, u32 event)
671 if (acpi_evalf(hkey_handle, &hkey, "MHKP", "d"))
672 acpi_bus_generate_event(ibm->acpi->device, event, hkey);
674 printk(IBM_ERR "unknown hotkey event %d\n", event);
675 acpi_bus_generate_event(ibm->acpi->device, event, 0);
679 static int hotkey_get(int *status, int *mask)
681 if (!acpi_evalf(hkey_handle, status, "DHKC", "d"))
684 if (tp_features.hotkey_mask)
685 if (!acpi_evalf(hkey_handle, mask, "DHKN", "d"))
691 static int hotkey_set(int status, int mask)
695 if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status))
698 if (tp_features.hotkey_mask)
699 for (i = 0; i < 32; i++) {
700 int bit = ((1 << i) & mask) != 0;
701 if (!acpi_evalf(hkey_handle,
702 NULL, "MHKM", "vdd", i + 1, bit))
709 static int hotkey_read(char *p)
711 int res, status, mask;
714 if (!tp_features.hotkey) {
715 len += sprintf(p + len, "status:\t\tnot supported\n");
719 res = hotkey_get(&status, &mask);
723 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0));
724 if (tp_features.hotkey_mask) {
725 len += sprintf(p + len, "mask:\t\t0x%04x\n", mask);
726 len += sprintf(p + len,
727 "commands:\tenable, disable, reset, <mask>\n");
729 len += sprintf(p + len, "mask:\t\tnot supported\n");
730 len += sprintf(p + len, "commands:\tenable, disable, reset\n");
736 static int hotkey_write(char *buf)
738 int res, status, mask;
742 if (!tp_features.hotkey)
745 res = hotkey_get(&status, &mask);
749 while ((cmd = next_cmd(&buf))) {
750 if (strlencmp(cmd, "enable") == 0) {
752 } else if (strlencmp(cmd, "disable") == 0) {
754 } else if (strlencmp(cmd, "reset") == 0) {
755 status = hotkey_orig_status;
756 mask = hotkey_orig_mask;
757 } else if (sscanf(cmd, "0x%x", &mask) == 1) {
759 } else if (sscanf(cmd, "%x", &mask) == 1) {
767 res = hotkey_set(status, mask);
775 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = {
777 .notify = hotkey_notify,
778 .handle = &hkey_handle,
779 .type = ACPI_DEVICE_NOTIFY,
782 static struct ibm_struct hotkey_driver_data = {
785 .write = hotkey_write,
787 .acpi = &ibm_hotkey_acpidriver,
790 /*************************************************************************
791 * Bluetooth subdriver
794 static int __init bluetooth_init(struct ibm_init_struct *iibm)
798 vdbg_printk(TPACPI_DBG_INIT, "initializing bluetooth subdriver\n");
800 IBM_ACPIHANDLE_INIT(hkey);
802 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
803 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
804 tp_features.bluetooth = hkey_handle &&
805 acpi_evalf(hkey_handle, &status, "GBDC", "qd");
807 vdbg_printk(TPACPI_DBG_INIT, "bluetooth is %s, status 0x%02x\n",
808 str_supported(tp_features.bluetooth),
811 if (tp_features.bluetooth &&
812 !(status & TP_ACPI_BLUETOOTH_HWPRESENT)) {
813 /* no bluetooth hardware present in system */
814 tp_features.bluetooth = 0;
815 dbg_printk(TPACPI_DBG_INIT,
816 "bluetooth hardware not installed\n");
819 return (tp_features.bluetooth)? 0 : 1;
822 static int bluetooth_get_radiosw(void)
826 if (!tp_features.bluetooth)
829 if (!acpi_evalf(hkey_handle, &status, "GBDC", "d"))
832 return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0);
835 static int bluetooth_set_radiosw(int radio_on)
839 if (!tp_features.bluetooth)
842 if (!acpi_evalf(hkey_handle, &status, "GBDC", "d"))
845 status |= TP_ACPI_BLUETOOTH_RADIOSSW;
847 status &= ~TP_ACPI_BLUETOOTH_RADIOSSW;
848 if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status))
854 static int bluetooth_read(char *p)
857 int status = bluetooth_get_radiosw();
859 if (!tp_features.bluetooth)
860 len += sprintf(p + len, "status:\t\tnot supported\n");
862 len += sprintf(p + len, "status:\t\t%s\n",
863 (status)? "enabled" : "disabled");
864 len += sprintf(p + len, "commands:\tenable, disable\n");
870 static int bluetooth_write(char *buf)
874 if (!tp_features.bluetooth)
877 while ((cmd = next_cmd(&buf))) {
878 if (strlencmp(cmd, "enable") == 0) {
879 bluetooth_set_radiosw(1);
880 } else if (strlencmp(cmd, "disable") == 0) {
881 bluetooth_set_radiosw(0);
889 static struct ibm_struct bluetooth_driver_data = {
891 .read = bluetooth_read,
892 .write = bluetooth_write,
895 /*************************************************************************
899 static int __init wan_init(struct ibm_init_struct *iibm)
903 vdbg_printk(TPACPI_DBG_INIT, "initializing wan subdriver\n");
905 IBM_ACPIHANDLE_INIT(hkey);
907 tp_features.wan = hkey_handle &&
908 acpi_evalf(hkey_handle, &status, "GWAN", "qd");
910 vdbg_printk(TPACPI_DBG_INIT, "wan is %s, status 0x%02x\n",
911 str_supported(tp_features.wan),
914 if (tp_features.wan &&
915 !(status & TP_ACPI_WANCARD_HWPRESENT)) {
916 /* no wan hardware present in system */
918 dbg_printk(TPACPI_DBG_INIT,
919 "wan hardware not installed\n");
922 return (tp_features.wan)? 0 : 1;
925 static int wan_get_radiosw(void)
929 if (!tp_features.wan)
932 if (!acpi_evalf(hkey_handle, &status, "GWAN", "d"))
935 return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0);
938 static int wan_set_radiosw(int radio_on)
942 if (!tp_features.wan)
945 if (!acpi_evalf(hkey_handle, &status, "GWAN", "d"))
948 status |= TP_ACPI_WANCARD_RADIOSSW;
950 status &= ~TP_ACPI_WANCARD_RADIOSSW;
951 if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status))
957 static int wan_read(char *p)
960 int status = wan_get_radiosw();
962 if (!tp_features.wan)
963 len += sprintf(p + len, "status:\t\tnot supported\n");
965 len += sprintf(p + len, "status:\t\t%s\n",
966 (status)? "enabled" : "disabled");
967 len += sprintf(p + len, "commands:\tenable, disable\n");
973 static int wan_write(char *buf)
977 if (!tp_features.wan)
980 while ((cmd = next_cmd(&buf))) {
981 if (strlencmp(cmd, "enable") == 0) {
983 } else if (strlencmp(cmd, "disable") == 0) {
992 static struct ibm_struct wan_driver_data = {
996 .flags.experimental = 1,
999 /*************************************************************************
1003 static enum video_access_mode video_supported;
1004 static int video_orig_autosw;
1006 IBM_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */
1007 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
1008 "\\_SB.PCI0.VID0", /* 770e */
1009 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
1010 "\\_SB.PCI0.AGP.VID", /* all others */
1013 IBM_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */
1015 static int __init video_init(struct ibm_init_struct *iibm)
1019 vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n");
1021 IBM_ACPIHANDLE_INIT(vid);
1022 IBM_ACPIHANDLE_INIT(vid2);
1024 if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga)
1025 /* G41, assume IVGA doesn't change */
1026 vid_handle = vid2_handle;
1029 /* video switching not supported on R30, R31 */
1030 video_supported = TPACPI_VIDEO_NONE;
1031 else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd"))
1033 video_supported = TPACPI_VIDEO_570;
1034 else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd"))
1035 /* 600e/x, 770e, 770x */
1036 video_supported = TPACPI_VIDEO_770;
1039 video_supported = TPACPI_VIDEO_NEW;
1041 vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n",
1042 str_supported(video_supported != TPACPI_VIDEO_NONE),
1045 return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1;
1048 static void video_exit(void)
1050 dbg_printk(TPACPI_DBG_EXIT,
1051 "restoring original video autoswitch mode\n");
1052 if (video_autosw_set(video_orig_autosw))
1053 printk(IBM_ERR "error while trying to restore original "
1054 "video autoswitch mode\n");
1057 static int video_outputsw_get(void)
1062 switch (video_supported) {
1063 case TPACPI_VIDEO_570:
1064 if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd",
1065 TP_ACPI_VIDEO_570_PHSCMD))
1067 status = i & TP_ACPI_VIDEO_570_PHSMASK;
1069 case TPACPI_VIDEO_770:
1070 if (!acpi_evalf(NULL, &i, "\\VCDL", "d"))
1073 status |= TP_ACPI_VIDEO_S_LCD;
1074 if (!acpi_evalf(NULL, &i, "\\VCDC", "d"))
1077 status |= TP_ACPI_VIDEO_S_CRT;
1079 case TPACPI_VIDEO_NEW:
1080 if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) ||
1081 !acpi_evalf(NULL, &i, "\\VCDC", "d"))
1084 status |= TP_ACPI_VIDEO_S_CRT;
1086 if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) ||
1087 !acpi_evalf(NULL, &i, "\\VCDL", "d"))
1090 status |= TP_ACPI_VIDEO_S_LCD;
1091 if (!acpi_evalf(NULL, &i, "\\VCDD", "d"))
1094 status |= TP_ACPI_VIDEO_S_DVI;
1103 static int video_outputsw_set(int status)
1108 switch (video_supported) {
1109 case TPACPI_VIDEO_570:
1110 res = acpi_evalf(NULL, NULL,
1111 "\\_SB.PHS2", "vdd",
1112 TP_ACPI_VIDEO_570_PHS2CMD,
1113 status | TP_ACPI_VIDEO_570_PHS2SET);
1115 case TPACPI_VIDEO_770:
1116 autosw = video_autosw_get();
1120 res = video_autosw_set(1);
1123 res = acpi_evalf(vid_handle, NULL,
1124 "ASWT", "vdd", status * 0x100, 0);
1125 if (!autosw && video_autosw_set(autosw)) {
1126 printk(IBM_ERR "video auto-switch left enabled due to error\n");
1130 case TPACPI_VIDEO_NEW:
1131 res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) &&
1132 acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1);
1138 return (res)? 0 : -EIO;
1141 static int video_autosw_get(void)
1145 switch (video_supported) {
1146 case TPACPI_VIDEO_570:
1147 if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d"))
1150 case TPACPI_VIDEO_770:
1151 case TPACPI_VIDEO_NEW:
1152 if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d"))
1162 static int video_autosw_set(int enable)
1164 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0))
1169 static int video_outputsw_cycle(void)
1171 int autosw = video_autosw_get();
1177 switch (video_supported) {
1178 case TPACPI_VIDEO_570:
1179 res = video_autosw_set(1);
1182 res = acpi_evalf(ec_handle, NULL, "_Q16", "v");
1184 case TPACPI_VIDEO_770:
1185 case TPACPI_VIDEO_NEW:
1186 res = video_autosw_set(1);
1189 res = acpi_evalf(vid_handle, NULL, "VSWT", "v");
1194 if (!autosw && video_autosw_set(autosw)) {
1195 printk(IBM_ERR "video auto-switch left enabled due to error\n");
1199 return (res)? 0 : -EIO;
1202 static int video_expand_toggle(void)
1204 switch (video_supported) {
1205 case TPACPI_VIDEO_570:
1206 return acpi_evalf(ec_handle, NULL, "_Q17", "v")?
1208 case TPACPI_VIDEO_770:
1209 return acpi_evalf(vid_handle, NULL, "VEXP", "v")?
1211 case TPACPI_VIDEO_NEW:
1212 return acpi_evalf(NULL, NULL, "\\VEXP", "v")?
1220 static int video_read(char *p)
1225 if (video_supported == TPACPI_VIDEO_NONE) {
1226 len += sprintf(p + len, "status:\t\tnot supported\n");
1230 status = video_outputsw_get();
1234 autosw = video_autosw_get();
1238 len += sprintf(p + len, "status:\t\tsupported\n");
1239 len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0));
1240 len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1));
1241 if (video_supported == TPACPI_VIDEO_NEW)
1242 len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3));
1243 len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0));
1244 len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n");
1245 len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n");
1246 if (video_supported == TPACPI_VIDEO_NEW)
1247 len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n");
1248 len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n");
1249 len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n");
1254 static int video_write(char *buf)
1257 int enable, disable, status;
1260 if (video_supported == TPACPI_VIDEO_NONE)
1266 while ((cmd = next_cmd(&buf))) {
1267 if (strlencmp(cmd, "lcd_enable") == 0) {
1268 enable |= TP_ACPI_VIDEO_S_LCD;
1269 } else if (strlencmp(cmd, "lcd_disable") == 0) {
1270 disable |= TP_ACPI_VIDEO_S_LCD;
1271 } else if (strlencmp(cmd, "crt_enable") == 0) {
1272 enable |= TP_ACPI_VIDEO_S_CRT;
1273 } else if (strlencmp(cmd, "crt_disable") == 0) {
1274 disable |= TP_ACPI_VIDEO_S_CRT;
1275 } else if (video_supported == TPACPI_VIDEO_NEW &&
1276 strlencmp(cmd, "dvi_enable") == 0) {
1277 enable |= TP_ACPI_VIDEO_S_DVI;
1278 } else if (video_supported == TPACPI_VIDEO_NEW &&
1279 strlencmp(cmd, "dvi_disable") == 0) {
1280 disable |= TP_ACPI_VIDEO_S_DVI;
1281 } else if (strlencmp(cmd, "auto_enable") == 0) {
1282 res = video_autosw_set(1);
1285 } else if (strlencmp(cmd, "auto_disable") == 0) {
1286 res = video_autosw_set(0);
1289 } else if (strlencmp(cmd, "video_switch") == 0) {
1290 res = video_outputsw_cycle();
1293 } else if (strlencmp(cmd, "expand_toggle") == 0) {
1294 res = video_expand_toggle();
1301 if (enable || disable) {
1302 status = video_outputsw_get();
1305 res = video_outputsw_set((status & ~disable) | enable);
1313 static struct ibm_struct video_driver_data = {
1316 .write = video_write,
1320 /*************************************************************************
1321 * Light (thinklight) subdriver
1324 IBM_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
1325 IBM_HANDLE(ledb, ec, "LEDB"); /* G4x */
1327 static int __init light_init(struct ibm_init_struct *iibm)
1329 vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n");
1331 IBM_ACPIHANDLE_INIT(ledb);
1332 IBM_ACPIHANDLE_INIT(lght);
1333 IBM_ACPIHANDLE_INIT(cmos);
1335 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
1336 tp_features.light = (cmos_handle || lght_handle) && !ledb_handle;
1338 if (tp_features.light)
1339 /* light status not supported on
1340 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
1341 tp_features.light_status =
1342 acpi_evalf(ec_handle, NULL, "KBLT", "qv");
1344 vdbg_printk(TPACPI_DBG_INIT, "light is %s\n",
1345 str_supported(tp_features.light));
1347 return (tp_features.light)? 0 : 1;
1350 static int light_read(char *p)
1355 if (!tp_features.light) {
1356 len += sprintf(p + len, "status:\t\tnot supported\n");
1357 } else if (!tp_features.light_status) {
1358 len += sprintf(p + len, "status:\t\tunknown\n");
1359 len += sprintf(p + len, "commands:\ton, off\n");
1361 if (!acpi_evalf(ec_handle, &status, "KBLT", "d"))
1363 len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0));
1364 len += sprintf(p + len, "commands:\ton, off\n");
1370 static int light_write(char *buf)
1372 int cmos_cmd, lght_cmd;
1376 if (!tp_features.light)
1379 while ((cmd = next_cmd(&buf))) {
1380 if (strlencmp(cmd, "on") == 0) {
1383 } else if (strlencmp(cmd, "off") == 0) {
1389 success = cmos_handle ?
1390 acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd) :
1391 acpi_evalf(lght_handle, NULL, NULL, "vd", lght_cmd);
1399 static struct ibm_struct light_driver_data = {
1402 .write = light_write,
1405 /*************************************************************************
1409 #ifdef CONFIG_THINKPAD_ACPI_DOCK
1411 IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */
1412 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
1413 "\\_SB.PCI0.PCI1.DOCK", /* all others */
1414 "\\_SB.PCI.ISA.SLCE", /* 570 */
1415 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
1417 /* don't list other alternatives as we install a notify handler on the 570 */
1418 IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */
1420 #define dock_docked() (_sta(dock_handle) & 1)
1422 static int __init dock_init(struct ibm_init_struct *iibm)
1424 vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver\n");
1426 IBM_ACPIHANDLE_INIT(dock);
1427 IBM_ACPIHANDLE_INIT(pci);
1429 vdbg_printk(TPACPI_DBG_INIT, "dock is %s\n",
1430 str_supported(dock_handle != NULL));
1432 return (dock_handle)? 0 : 1;
1435 static void dock_notify(struct ibm_struct *ibm, u32 event)
1437 int docked = dock_docked();
1438 int pci = ibm->acpi->hid && strstr(ibm->acpi->hid, IBM_PCI_HID);
1440 if (event == 1 && !pci) /* 570 */
1441 acpi_bus_generate_event(ibm->acpi->device, event, 1); /* button */
1442 else if (event == 1 && pci) /* 570 */
1443 acpi_bus_generate_event(ibm->acpi->device, event, 3); /* dock */
1444 else if (event == 3 && docked)
1445 acpi_bus_generate_event(ibm->acpi->device, event, 1); /* button */
1446 else if (event == 3 && !docked)
1447 acpi_bus_generate_event(ibm->acpi->device, event, 2); /* undock */
1448 else if (event == 0 && docked)
1449 acpi_bus_generate_event(ibm->acpi->device, event, 3); /* dock */
1451 printk(IBM_ERR "unknown dock event %d, status %d\n",
1452 event, _sta(dock_handle));
1453 acpi_bus_generate_event(ibm->acpi->device, event, 0); /* unknown */
1457 static int dock_read(char *p)
1460 int docked = dock_docked();
1463 len += sprintf(p + len, "status:\t\tnot supported\n");
1465 len += sprintf(p + len, "status:\t\tundocked\n");
1467 len += sprintf(p + len, "status:\t\tdocked\n");
1468 len += sprintf(p + len, "commands:\tdock, undock\n");
1474 static int dock_write(char *buf)
1481 while ((cmd = next_cmd(&buf))) {
1482 if (strlencmp(cmd, "undock") == 0) {
1483 if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0) ||
1484 !acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1))
1486 } else if (strlencmp(cmd, "dock") == 0) {
1487 if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1))
1496 static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = {
1498 .notify = dock_notify,
1499 .handle = &dock_handle,
1500 .type = ACPI_SYSTEM_NOTIFY,
1504 .notify = dock_notify,
1505 .handle = &pci_handle,
1506 .type = ACPI_SYSTEM_NOTIFY,
1510 static struct ibm_struct dock_driver_data[2] = {
1514 .write = dock_write,
1515 .acpi = &ibm_dock_acpidriver[0],
1519 .acpi = &ibm_dock_acpidriver[1],
1523 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
1525 /*************************************************************************
1529 #ifdef CONFIG_THINKPAD_ACPI_BAY
1530 IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
1531 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
1532 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
1533 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
1534 ); /* A21e, R30, R31 */
1535 IBM_HANDLE(bay_ej, bay, "_EJ3", /* 600e/x, A2xm/p, A3x */
1536 "_EJ0", /* all others */
1537 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
1538 IBM_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
1539 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
1541 IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */
1545 static int __init bay_init(struct ibm_init_struct *iibm)
1547 vdbg_printk(TPACPI_DBG_INIT, "initializing bay subdriver\n");
1549 IBM_ACPIHANDLE_INIT(bay);
1551 IBM_ACPIHANDLE_INIT(bay_ej);
1552 IBM_ACPIHANDLE_INIT(bay2);
1554 IBM_ACPIHANDLE_INIT(bay2_ej);
1556 tp_features.bay_status = bay_handle &&
1557 acpi_evalf(bay_handle, NULL, "_STA", "qv");
1558 tp_features.bay_status2 = bay2_handle &&
1559 acpi_evalf(bay2_handle, NULL, "_STA", "qv");
1561 tp_features.bay_eject = bay_handle && bay_ej_handle &&
1562 (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental);
1563 tp_features.bay_eject2 = bay2_handle && bay2_ej_handle &&
1564 (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental);
1566 vdbg_printk(TPACPI_DBG_INIT,
1567 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
1568 str_supported(tp_features.bay_status),
1569 str_supported(tp_features.bay_eject),
1570 str_supported(tp_features.bay_status2),
1571 str_supported(tp_features.bay_eject2));
1573 return (tp_features.bay_status || tp_features.bay_eject ||
1574 tp_features.bay_status2 || tp_features.bay_eject2)? 0 : 1;
1577 static void bay_notify(struct ibm_struct *ibm, u32 event)
1579 acpi_bus_generate_event(ibm->acpi->device, event, 0);
1582 #define bay_occupied(b) (_sta(b##_handle) & 1)
1584 static int bay_read(char *p)
1587 int occupied = bay_occupied(bay);
1588 int occupied2 = bay_occupied(bay2);
1591 len += sprintf(p + len, "status:\t\t%s\n",
1592 tp_features.bay_status ?
1593 (occupied ? "occupied" : "unoccupied") :
1595 if (tp_features.bay_status2)
1596 len += sprintf(p + len, "status2:\t%s\n", occupied2 ?
1597 "occupied" : "unoccupied");
1599 eject = tp_features.bay_eject && occupied;
1600 eject2 = tp_features.bay_eject2 && occupied2;
1602 if (eject && eject2)
1603 len += sprintf(p + len, "commands:\teject, eject2\n");
1605 len += sprintf(p + len, "commands:\teject\n");
1607 len += sprintf(p + len, "commands:\teject2\n");
1612 static int bay_write(char *buf)
1616 if (!tp_features.bay_eject && !tp_features.bay_eject2)
1619 while ((cmd = next_cmd(&buf))) {
1620 if (tp_features.bay_eject && strlencmp(cmd, "eject") == 0) {
1621 if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1))
1623 } else if (tp_features.bay_eject2 &&
1624 strlencmp(cmd, "eject2") == 0) {
1625 if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1))
1634 static struct tp_acpi_drv_struct ibm_bay_acpidriver = {
1635 .notify = bay_notify,
1636 .handle = &bay_handle,
1637 .type = ACPI_SYSTEM_NOTIFY,
1640 static struct ibm_struct bay_driver_data = {
1644 .acpi = &ibm_bay_acpidriver,
1647 #endif /* CONFIG_THINKPAD_ACPI_BAY */
1649 /*************************************************************************
1653 static int __init cmos_init(struct ibm_init_struct *iibm)
1655 vdbg_printk(TPACPI_DBG_INIT,
1656 "initializing cmos commands subdriver\n");
1658 IBM_ACPIHANDLE_INIT(cmos);
1660 vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n",
1661 str_supported(cmos_handle != NULL));
1662 return (cmos_handle)? 0 : 1;
1665 static int cmos_read(char *p)
1669 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1670 R30, R31, T20-22, X20-21 */
1672 len += sprintf(p + len, "status:\t\tnot supported\n");
1674 len += sprintf(p + len, "status:\t\tsupported\n");
1675 len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n");
1681 static int cmos_write(char *buf)
1686 while ((cmd = next_cmd(&buf))) {
1687 if (sscanf(cmd, "%u", &cmos_cmd) == 1 &&
1688 cmos_cmd >= 0 && cmos_cmd <= 21) {
1693 res = issue_thinkpad_cmos_command(cmos_cmd);
1701 static struct ibm_struct cmos_driver_data = {
1704 .write = cmos_write,
1707 /*************************************************************************
1711 static enum led_access_mode led_supported;
1713 IBM_HANDLE(led, ec, "SLED", /* 570 */
1714 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1715 "LED", /* all others */
1718 static int __init led_init(struct ibm_init_struct *iibm)
1720 vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n");
1722 IBM_ACPIHANDLE_INIT(led);
1725 /* led not supported on R30, R31 */
1726 led_supported = TPACPI_LED_NONE;
1727 else if (strlencmp(led_path, "SLED") == 0)
1729 led_supported = TPACPI_LED_570;
1730 else if (strlencmp(led_path, "SYSL") == 0)
1731 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1732 led_supported = TPACPI_LED_OLD;
1735 led_supported = TPACPI_LED_NEW;
1737 vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n",
1738 str_supported(led_supported), led_supported);
1740 return (led_supported != TPACPI_LED_NONE)? 0 : 1;
1743 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
1745 static int led_read(char *p)
1749 if (!led_supported) {
1750 len += sprintf(p + len, "status:\t\tnot supported\n");
1753 len += sprintf(p + len, "status:\t\tsupported\n");
1755 if (led_supported == TPACPI_LED_570) {
1758 for (i = 0; i < 8; i++) {
1759 if (!acpi_evalf(ec_handle,
1760 &status, "GLED", "dd", 1 << i))
1762 len += sprintf(p + len, "%d:\t\t%s\n",
1763 i, led_status(status));
1767 len += sprintf(p + len, "commands:\t"
1768 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
1773 /* off, on, blink */
1774 static const int led_sled_arg1[] = { 0, 1, 3 };
1775 static const int led_exp_hlbl[] = { 0, 0, 1 }; /* led# * */
1776 static const int led_exp_hlcl[] = { 0, 1, 1 }; /* led# * */
1777 static const int led_led_arg1[] = { 0, 0x80, 0xc0 };
1779 static int led_write(char *buf)
1787 while ((cmd = next_cmd(&buf))) {
1788 if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 7)
1791 if (strstr(cmd, "off")) {
1793 } else if (strstr(cmd, "on")) {
1795 } else if (strstr(cmd, "blink")) {
1800 if (led_supported == TPACPI_LED_570) {
1803 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
1804 led, led_sled_arg1[ind]))
1806 } else if (led_supported == TPACPI_LED_OLD) {
1807 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
1809 ret = ec_write(TPACPI_LED_EC_HLMS, led);
1812 ec_write(TPACPI_LED_EC_HLBL,
1813 led * led_exp_hlbl[ind]);
1816 ec_write(TPACPI_LED_EC_HLCL,
1817 led * led_exp_hlcl[ind]);
1822 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
1823 led, led_led_arg1[ind]))
1831 static struct ibm_struct led_driver_data = {
1837 /*************************************************************************
1841 IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */
1843 static int __init beep_init(struct ibm_init_struct *iibm)
1845 vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n");
1847 IBM_ACPIHANDLE_INIT(beep);
1849 vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n",
1850 str_supported(beep_handle != NULL));
1852 return (beep_handle)? 0 : 1;
1855 static int beep_read(char *p)
1860 len += sprintf(p + len, "status:\t\tnot supported\n");
1862 len += sprintf(p + len, "status:\t\tsupported\n");
1863 len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n");
1869 static int beep_write(char *buf)
1877 while ((cmd = next_cmd(&buf))) {
1878 if (sscanf(cmd, "%u", &beep_cmd) == 1 &&
1879 beep_cmd >= 0 && beep_cmd <= 17) {
1883 if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", beep_cmd, 0))
1890 static struct ibm_struct beep_driver_data = {
1893 .write = beep_write,
1896 /*************************************************************************
1900 static enum thermal_access_mode thermal_read_mode;
1902 static int __init thermal_init(struct ibm_init_struct *iibm)
1908 vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n");
1910 acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv");
1912 if (ibm_thinkpad_ec_found && experimental) {
1914 * Direct EC access mode: sensors at registers
1915 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
1916 * non-implemented, thermal sensors return 0x80 when
1921 for (i = 0; i < 8; i++) {
1922 if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) {
1928 if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) {
1936 /* This is sheer paranoia, but we handle it anyway */
1939 "ThinkPad ACPI EC access misbehaving, "
1940 "falling back to ACPI TMPx access mode\n");
1941 thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07;
1944 "ThinkPad ACPI EC access misbehaving, "
1945 "disabling thermal sensors access\n");
1946 thermal_read_mode = TPACPI_THERMAL_NONE;
1951 TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8;
1953 } else if (acpi_tmp7) {
1954 if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) {
1955 /* 600e/x, 770e, 770x */
1956 thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT;
1958 /* Standard ACPI TMPx access, max 8 sensors */
1959 thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07;
1962 /* temperatures not supported on 570, G4x, R30, R31, R32 */
1963 thermal_read_mode = TPACPI_THERMAL_NONE;
1966 vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n",
1967 str_supported(thermal_read_mode != TPACPI_THERMAL_NONE),
1970 return (thermal_read_mode != TPACPI_THERMAL_NONE)? 0 : 1;
1973 /* idx is zero-based */
1974 static int thermal_get_sensor(int idx, s32 *value)
1980 t = TP_EC_THERMAL_TMP0;
1982 switch (thermal_read_mode) {
1983 #if TPACPI_MAX_THERMAL_SENSORS >= 16
1984 case TPACPI_THERMAL_TPEC_16:
1985 if (idx >= 8 && idx <= 15) {
1986 t = TP_EC_THERMAL_TMP8;
1991 case TPACPI_THERMAL_TPEC_8:
1993 if (!acpi_ec_read(t + idx, &tmp))
1995 *value = tmp * 1000;
2000 case TPACPI_THERMAL_ACPI_UPDT:
2002 snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
2003 if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
2005 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
2007 *value = (t - 2732) * 100;
2012 case TPACPI_THERMAL_ACPI_TMP07:
2014 snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
2015 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
2022 case TPACPI_THERMAL_NONE:
2030 static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
2041 if (thermal_read_mode == TPACPI_THERMAL_TPEC_16)
2044 for(i = 0 ; i < n; i++) {
2045 res = thermal_get_sensor(i, &s->temp[i]);
2053 static int thermal_read(char *p)
2057 struct ibm_thermal_sensors_struct t;
2059 n = thermal_get_sensors(&t);
2060 if (unlikely(n < 0))
2063 len += sprintf(p + len, "temperatures:\t");
2066 for (i = 0; i < (n - 1); i++)
2067 len += sprintf(p + len, "%d ", t.temp[i] / 1000);
2068 len += sprintf(p + len, "%d\n", t.temp[i] / 1000);
2070 len += sprintf(p + len, "not supported\n");
2075 static struct ibm_struct thermal_driver_data = {
2077 .read = thermal_read,
2080 /*************************************************************************
2084 static u8 ecdump_regs[256];
2086 static int ecdump_read(char *p)
2092 len += sprintf(p + len, "EC "
2093 " +00 +01 +02 +03 +04 +05 +06 +07"
2094 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
2095 for (i = 0; i < 256; i += 16) {
2096 len += sprintf(p + len, "EC 0x%02x:", i);
2097 for (j = 0; j < 16; j++) {
2098 if (!acpi_ec_read(i + j, &v))
2100 if (v != ecdump_regs[i + j])
2101 len += sprintf(p + len, " *%02x", v);
2103 len += sprintf(p + len, " %02x", v);
2104 ecdump_regs[i + j] = v;
2106 len += sprintf(p + len, "\n");
2111 /* These are way too dangerous to advertise openly... */
2113 len += sprintf(p + len, "commands:\t0x<offset> 0x<value>"
2114 " (<offset> is 00-ff, <value> is 00-ff)\n");
2115 len += sprintf(p + len, "commands:\t0x<offset> <value> "
2116 " (<offset> is 00-ff, <value> is 0-255)\n");
2121 static int ecdump_write(char *buf)
2126 while ((cmd = next_cmd(&buf))) {
2127 if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) {
2129 } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) {
2133 if (i >= 0 && i < 256 && v >= 0 && v < 256) {
2134 if (!acpi_ec_write(i, v))
2143 static struct ibm_struct ecdump_driver_data = {
2145 .read = ecdump_read,
2146 .write = ecdump_write,
2147 .flags.experimental = 1,
2150 /*************************************************************************
2151 * Backlight/brightness subdriver
2154 static struct backlight_device *ibm_backlight_device = NULL;
2156 static struct backlight_ops ibm_backlight_data = {
2157 .get_brightness = brightness_get,
2158 .update_status = brightness_update_status,
2161 static int __init brightness_init(struct ibm_init_struct *iibm)
2165 vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n");
2167 b = brightness_get(NULL);
2171 ibm_backlight_device = backlight_device_register("ibm", NULL, NULL,
2172 &ibm_backlight_data);
2173 if (IS_ERR(ibm_backlight_device)) {
2174 printk(IBM_ERR "Could not register backlight device\n");
2175 return PTR_ERR(ibm_backlight_device);
2177 vdbg_printk(TPACPI_DBG_INIT, "brightness is supported\n");
2179 ibm_backlight_device->props.max_brightness = 7;
2180 ibm_backlight_device->props.brightness = b;
2181 backlight_update_status(ibm_backlight_device);
2186 static void brightness_exit(void)
2188 if (ibm_backlight_device) {
2189 vdbg_printk(TPACPI_DBG_EXIT,
2190 "calling backlight_device_unregister()\n");
2191 backlight_device_unregister(ibm_backlight_device);
2192 ibm_backlight_device = NULL;
2196 static int brightness_update_status(struct backlight_device *bd)
2198 return brightness_set(
2199 (bd->props.fb_blank == FB_BLANK_UNBLANK &&
2200 bd->props.power == FB_BLANK_UNBLANK) ?
2201 bd->props.brightness : 0);
2204 static int brightness_get(struct backlight_device *bd)
2207 if (!acpi_ec_read(brightness_offset, &level))
2215 static int brightness_set(int value)
2217 int cmos_cmd, inc, i;
2218 int current_value = brightness_get(NULL);
2222 cmos_cmd = value > current_value ? TP_CMOS_BRIGHTNESS_UP : TP_CMOS_BRIGHTNESS_DOWN;
2223 inc = value > current_value ? 1 : -1;
2224 for (i = current_value; i != value; i += inc) {
2225 if (issue_thinkpad_cmos_command(cmos_cmd))
2227 if (!acpi_ec_write(brightness_offset, i + inc))
2234 static int brightness_read(char *p)
2239 if ((level = brightness_get(NULL)) < 0) {
2240 len += sprintf(p + len, "level:\t\tunreadable\n");
2242 len += sprintf(p + len, "level:\t\t%d\n", level & 0x7);
2243 len += sprintf(p + len, "commands:\tup, down\n");
2244 len += sprintf(p + len, "commands:\tlevel <level>"
2245 " (<level> is 0-7)\n");
2251 static int brightness_write(char *buf)
2257 while ((cmd = next_cmd(&buf))) {
2258 if ((level = brightness_get(NULL)) < 0)
2262 if (strlencmp(cmd, "up") == 0) {
2263 new_level = level == 7 ? 7 : level + 1;
2264 } else if (strlencmp(cmd, "down") == 0) {
2265 new_level = level == 0 ? 0 : level - 1;
2266 } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
2267 new_level >= 0 && new_level <= 7) {
2272 brightness_set(new_level);
2278 static struct ibm_struct brightness_driver_data = {
2279 .name = "brightness",
2280 .read = brightness_read,
2281 .write = brightness_write,
2282 .exit = brightness_exit,
2285 /*************************************************************************
2289 static int volume_read(char *p)
2294 if (!acpi_ec_read(volume_offset, &level)) {
2295 len += sprintf(p + len, "level:\t\tunreadable\n");
2297 len += sprintf(p + len, "level:\t\t%d\n", level & 0xf);
2298 len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6));
2299 len += sprintf(p + len, "commands:\tup, down, mute\n");
2300 len += sprintf(p + len, "commands:\tlevel <level>"
2301 " (<level> is 0-15)\n");
2307 static int volume_write(char *buf)
2309 int cmos_cmd, inc, i;
2311 int new_level, new_mute;
2314 while ((cmd = next_cmd(&buf))) {
2315 if (!acpi_ec_read(volume_offset, &level))
2317 new_mute = mute = level & 0x40;
2318 new_level = level = level & 0xf;
2320 if (strlencmp(cmd, "up") == 0) {
2324 new_level = level == 15 ? 15 : level + 1;
2325 } else if (strlencmp(cmd, "down") == 0) {
2329 new_level = level == 0 ? 0 : level - 1;
2330 } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
2331 new_level >= 0 && new_level <= 15) {
2333 } else if (strlencmp(cmd, "mute") == 0) {
2338 if (new_level != level) { /* mute doesn't change */
2339 cmos_cmd = new_level > level ? TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN;
2340 inc = new_level > level ? 1 : -1;
2342 if (mute && (issue_thinkpad_cmos_command(cmos_cmd) ||
2343 !acpi_ec_write(volume_offset, level)))
2346 for (i = level; i != new_level; i += inc)
2347 if (issue_thinkpad_cmos_command(cmos_cmd) ||
2348 !acpi_ec_write(volume_offset, i + inc))
2351 if (mute && (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE) ||
2352 !acpi_ec_write(volume_offset,
2357 if (new_mute != mute) { /* level doesn't change */
2358 cmos_cmd = new_mute ? TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP;
2360 if (issue_thinkpad_cmos_command(cmos_cmd) ||
2361 !acpi_ec_write(volume_offset, level + new_mute))
2369 static struct ibm_struct volume_driver_data = {
2371 .read = volume_read,
2372 .write = volume_write,
2375 /*************************************************************************
2382 * TPACPI_FAN_RD_ACPI_GFAN:
2383 * ACPI GFAN method: returns fan level
2385 * see TPACPI_FAN_WR_ACPI_SFAN
2386 * EC 0x2f (HFSP) not available if GFAN exists
2388 * TPACPI_FAN_WR_ACPI_SFAN:
2389 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
2391 * EC 0x2f (HFSP) might be available *for reading*, but do not use
2394 * TPACPI_FAN_WR_TPEC:
2395 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
2396 * Supported on almost all ThinkPads
2398 * Fan speed changes of any sort (including those caused by the
2399 * disengaged mode) are usually done slowly by the firmware as the
2400 * maximum ammount of fan duty cycle change per second seems to be
2403 * Reading is not available if GFAN exists.
2404 * Writing is not available if SFAN exists.
2407 * 7 automatic mode engaged;
2408 * (default operation mode of the ThinkPad)
2409 * fan level is ignored in this mode.
2410 * 6 full speed mode (takes precedence over bit 7);
2411 * not available on all thinkpads. May disable
2412 * the tachometer while the fan controller ramps up
2413 * the speed (which can take up to a few *minutes*).
2414 * Speeds up fan to 100% duty-cycle, which is far above
2415 * the standard RPM levels. It is not impossible that
2416 * it could cause hardware damage.
2417 * 5-3 unused in some models. Extra bits for fan level
2418 * in others, but still useless as all values above
2419 * 7 map to the same speed as level 7 in these models.
2420 * 2-0 fan level (0..7 usually)
2422 * 0x07 = max (set when temperatures critical)
2423 * Some ThinkPads may have other levels, see
2424 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
2426 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
2427 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
2428 * does so, its initial value is meaningless (0x07).
2430 * For firmware bugs, refer to:
2431 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
2435 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
2436 * Main fan tachometer reading (in RPM)
2438 * This register is present on all ThinkPads with a new-style EC, and
2439 * it is known not to be present on the A21m/e, and T22, as there is
2440 * something else in offset 0x84 according to the ACPI DSDT. Other
2441 * ThinkPads from this same time period (and earlier) probably lack the
2442 * tachometer as well.
2444 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
2445 * was never fixed by IBM to report the EC firmware version string
2446 * probably support the tachometer (like the early X models), so
2447 * detecting it is quite hard. We need more data to know for sure.
2449 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
2452 * FIRMWARE BUG: may go stale while the EC is switching to full speed
2455 * For firmware bugs, refer to:
2456 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
2458 * TPACPI_FAN_WR_ACPI_FANS:
2459 * ThinkPad X31, X40, X41. Not available in the X60.
2461 * FANS ACPI handle: takes three arguments: low speed, medium speed,
2462 * high speed. ACPI DSDT seems to map these three speeds to levels
2463 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
2464 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
2466 * The speeds are stored on handles
2467 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
2469 * There are three default speed sets, acessible as handles:
2470 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
2472 * ACPI DSDT switches which set is in use depending on various
2475 * TPACPI_FAN_WR_TPEC is also available and should be used to
2476 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
2477 * but the ACPI tables just mention level 7.
2480 static enum fan_status_access_mode fan_status_access_mode;
2481 static enum fan_control_access_mode fan_control_access_mode;
2482 static enum fan_control_commands fan_control_commands;
2484 static u8 fan_control_initial_status;
2486 static void fan_watchdog_fire(struct work_struct *ignored);
2487 static int fan_watchdog_maxinterval;
2488 static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire);
2490 IBM_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */
2491 IBM_HANDLE(gfan, ec, "GFAN", /* 570 */
2492 "\\FSPD", /* 600e/x, 770e, 770x */
2494 IBM_HANDLE(sfan, ec, "SFAN", /* 570 */
2495 "JFNS", /* 770x-JL */
2498 static int __init fan_init(struct ibm_init_struct *iibm)
2500 vdbg_printk(TPACPI_DBG_INIT, "initializing fan subdriver\n");
2502 fan_status_access_mode = TPACPI_FAN_NONE;
2503 fan_control_access_mode = TPACPI_FAN_WR_NONE;
2504 fan_control_commands = 0;
2505 fan_watchdog_maxinterval = 0;
2506 tp_features.fan_ctrl_status_undef = 0;
2508 IBM_ACPIHANDLE_INIT(fans);
2509 IBM_ACPIHANDLE_INIT(gfan);
2510 IBM_ACPIHANDLE_INIT(sfan);
2513 /* 570, 600e/x, 770e, 770x */
2514 fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN;
2516 /* all other ThinkPads: note that even old-style
2517 * ThinkPad ECs supports the fan control register */
2518 if (likely(acpi_ec_read(fan_status_offset,
2519 &fan_control_initial_status))) {
2520 fan_status_access_mode = TPACPI_FAN_RD_TPEC;
2522 /* In some ThinkPads, neither the EC nor the ACPI
2523 * DSDT initialize the fan status, and it ends up
2524 * being set to 0x07 when it *could* be either
2527 * Enable for TP-1Y (T43), TP-78 (R51e),
2528 * TP-76 (R52), TP-70 (T43, R52), which are known
2530 if (fan_control_initial_status == 0x07 &&
2531 ibm_thinkpad_ec_found &&
2532 ((ibm_thinkpad_ec_found[0] == '1' &&
2533 ibm_thinkpad_ec_found[1] == 'Y') ||
2534 (ibm_thinkpad_ec_found[0] == '7' &&
2535 (ibm_thinkpad_ec_found[1] == '6' ||
2536 ibm_thinkpad_ec_found[1] == '8' ||
2537 ibm_thinkpad_ec_found[1] == '0'))
2540 "fan_init: initial fan status is "
2541 "unknown, assuming it is in auto "
2543 tp_features.fan_ctrl_status_undef = 1;
2547 "ThinkPad ACPI EC access misbehaving, "
2548 "fan status and control unavailable\n");
2555 fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN;
2556 fan_control_commands |=
2557 TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE;
2560 /* gfan without sfan means no fan control */
2561 /* all other models implement TP EC 0x2f control */
2565 fan_control_access_mode =
2566 TPACPI_FAN_WR_ACPI_FANS;
2567 fan_control_commands |=
2568 TPACPI_FAN_CMD_SPEED |
2569 TPACPI_FAN_CMD_LEVEL |
2570 TPACPI_FAN_CMD_ENABLE;
2572 fan_control_access_mode = TPACPI_FAN_WR_TPEC;
2573 fan_control_commands |=
2574 TPACPI_FAN_CMD_LEVEL |
2575 TPACPI_FAN_CMD_ENABLE;
2580 vdbg_printk(TPACPI_DBG_INIT, "fan is %s, modes %d, %d\n",
2581 str_supported(fan_status_access_mode != TPACPI_FAN_NONE ||
2582 fan_control_access_mode != TPACPI_FAN_WR_NONE),
2583 fan_status_access_mode, fan_control_access_mode);
2585 return (fan_status_access_mode != TPACPI_FAN_NONE ||
2586 fan_control_access_mode != TPACPI_FAN_WR_NONE)?
2590 static int fan_get_status(u8 *status)
2595 * Add TPACPI_FAN_RD_ACPI_FANS ? */
2597 switch (fan_status_access_mode) {
2598 case TPACPI_FAN_RD_ACPI_GFAN:
2599 /* 570, 600e/x, 770e, 770x */
2601 if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d")))
2609 case TPACPI_FAN_RD_TPEC:
2610 /* all except 570, 600e/x, 770e, 770x */
2611 if (unlikely(!acpi_ec_read(fan_status_offset, &s)))
2626 static void fan_exit(void)
2628 vdbg_printk(TPACPI_DBG_EXIT, "cancelling any pending fan watchdog tasks\n");
2629 cancel_delayed_work(&fan_watchdog_task);
2630 flush_scheduled_work();
2633 static int fan_get_speed(unsigned int *speed)
2637 switch (fan_status_access_mode) {
2638 case TPACPI_FAN_RD_TPEC:
2639 /* all except 570, 600e/x, 770e, 770x */
2640 if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) ||
2641 !acpi_ec_read(fan_rpm_offset + 1, &hi)))
2645 *speed = (hi << 8) | lo;
2656 static void fan_watchdog_fire(struct work_struct *ignored)
2660 printk(IBM_NOTICE "fan watchdog: enabling fan\n");
2661 rc = fan_set_enable();
2663 printk(IBM_ERR "fan watchdog: error %d while enabling fan, "
2664 "will try again later...\n", -rc);
2665 /* reschedule for later */
2666 fan_watchdog_reset();
2670 static void fan_watchdog_reset(void)
2672 static int fan_watchdog_active = 0;
2674 if (fan_watchdog_active)
2675 cancel_delayed_work(&fan_watchdog_task);
2677 if (fan_watchdog_maxinterval > 0) {
2678 fan_watchdog_active = 1;
2679 if (!schedule_delayed_work(&fan_watchdog_task,
2680 msecs_to_jiffies(fan_watchdog_maxinterval
2682 printk(IBM_ERR "failed to schedule the fan watchdog, "
2683 "watchdog will not trigger\n");
2686 fan_watchdog_active = 0;
2689 static int fan_set_level(int level)
2691 switch (fan_control_access_mode) {
2692 case TPACPI_FAN_WR_ACPI_SFAN:
2693 if (level >= 0 && level <= 7) {
2694 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level))
2700 case TPACPI_FAN_WR_ACPI_FANS:
2701 case TPACPI_FAN_WR_TPEC:
2702 if ((level != TP_EC_FAN_AUTO) &&
2703 (level != TP_EC_FAN_FULLSPEED) &&
2704 ((level < 0) || (level > 7)))
2707 if (!acpi_ec_write(fan_status_offset, level))
2710 tp_features.fan_ctrl_status_undef = 0;
2719 static int fan_set_enable(void)
2724 switch (fan_control_access_mode) {
2725 case TPACPI_FAN_WR_ACPI_FANS:
2726 case TPACPI_FAN_WR_TPEC:
2727 if ((rc = fan_get_status(&s)) < 0)
2730 /* Don't go out of emergency fan mode */
2734 if (!acpi_ec_write(fan_status_offset, s))
2737 tp_features.fan_ctrl_status_undef = 0;
2740 case TPACPI_FAN_WR_ACPI_SFAN:
2741 if ((rc = fan_get_status(&s)) < 0)
2746 /* Set fan to at least level 4 */
2750 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s))
2760 static int fan_set_disable(void)
2762 switch (fan_control_access_mode) {
2763 case TPACPI_FAN_WR_ACPI_FANS:
2764 case TPACPI_FAN_WR_TPEC:
2765 if (!acpi_ec_write(fan_status_offset, 0x00))
2768 tp_features.fan_ctrl_status_undef = 0;
2771 case TPACPI_FAN_WR_ACPI_SFAN:
2772 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00))
2782 static int fan_set_speed(int speed)
2784 switch (fan_control_access_mode) {
2785 case TPACPI_FAN_WR_ACPI_FANS:
2786 if (speed >= 0 && speed <= 65535) {
2787 if (!acpi_evalf(fans_handle, NULL, NULL, "vddd",
2788 speed, speed, speed))
2800 static int fan_read(char *p)
2805 unsigned int speed = 0;
2807 switch (fan_status_access_mode) {
2808 case TPACPI_FAN_RD_ACPI_GFAN:
2809 /* 570, 600e/x, 770e, 770x */
2810 if ((rc = fan_get_status(&status)) < 0)
2813 len += sprintf(p + len, "status:\t\t%s\n"
2815 (status != 0) ? "enabled" : "disabled", status);
2818 case TPACPI_FAN_RD_TPEC:
2819 /* all except 570, 600e/x, 770e, 770x */
2820 if ((rc = fan_get_status(&status)) < 0)
2823 if (unlikely(tp_features.fan_ctrl_status_undef)) {
2824 if (status != fan_control_initial_status)
2825 tp_features.fan_ctrl_status_undef = 0;
2827 /* Return most likely status. In fact, it
2828 * might be the only possible status */
2829 status = TP_EC_FAN_AUTO;
2832 len += sprintf(p + len, "status:\t\t%s\n",
2833 (status != 0) ? "enabled" : "disabled");
2835 if ((rc = fan_get_speed(&speed)) < 0)
2838 len += sprintf(p + len, "speed:\t\t%d\n", speed);
2840 if (status & TP_EC_FAN_FULLSPEED)
2841 /* Disengaged mode takes precedence */
2842 len += sprintf(p + len, "level:\t\tdisengaged\n");
2843 else if (status & TP_EC_FAN_AUTO)
2844 len += sprintf(p + len, "level:\t\tauto\n");
2846 len += sprintf(p + len, "level:\t\t%d\n", status);
2849 case TPACPI_FAN_NONE:
2851 len += sprintf(p + len, "status:\t\tnot supported\n");
2854 if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) {
2855 len += sprintf(p + len, "commands:\tlevel <level>");
2857 switch (fan_control_access_mode) {
2858 case TPACPI_FAN_WR_ACPI_SFAN:
2859 len += sprintf(p + len, " (<level> is 0-7)\n");
2863 len += sprintf(p + len, " (<level> is 0-7, "
2864 "auto, disengaged)\n");
2869 if (fan_control_commands & TPACPI_FAN_CMD_ENABLE)
2870 len += sprintf(p + len, "commands:\tenable, disable\n"
2871 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
2872 "1-120 (seconds))\n");
2874 if (fan_control_commands & TPACPI_FAN_CMD_SPEED)
2875 len += sprintf(p + len, "commands:\tspeed <speed>"
2876 " (<speed> is 0-65535)\n");
2881 static int fan_write_cmd_level(const char *cmd, int *rc)
2885 if (strlencmp(cmd, "level auto") == 0)
2886 level = TP_EC_FAN_AUTO;
2887 else if (strlencmp(cmd, "level disengaged") == 0)
2888 level = TP_EC_FAN_FULLSPEED;
2889 else if (sscanf(cmd, "level %d", &level) != 1)
2892 if ((*rc = fan_set_level(level)) == -ENXIO)
2893 printk(IBM_ERR "level command accepted for unsupported "
2894 "access mode %d", fan_control_access_mode);
2899 static int fan_write_cmd_enable(const char *cmd, int *rc)
2901 if (strlencmp(cmd, "enable") != 0)
2904 if ((*rc = fan_set_enable()) == -ENXIO)
2905 printk(IBM_ERR "enable command accepted for unsupported "
2906 "access mode %d", fan_control_access_mode);
2911 static int fan_write_cmd_disable(const char *cmd, int *rc)
2913 if (strlencmp(cmd, "disable") != 0)
2916 if ((*rc = fan_set_disable()) == -ENXIO)
2917 printk(IBM_ERR "disable command accepted for unsupported "
2918 "access mode %d", fan_control_access_mode);
2923 static int fan_write_cmd_speed(const char *cmd, int *rc)
2928 * Support speed <low> <medium> <high> ? */
2930 if (sscanf(cmd, "speed %d", &speed) != 1)
2933 if ((*rc = fan_set_speed(speed)) == -ENXIO)
2934 printk(IBM_ERR "speed command accepted for unsupported "
2935 "access mode %d", fan_control_access_mode);
2940 static int fan_write_cmd_watchdog(const char *cmd, int *rc)
2944 if (sscanf(cmd, "watchdog %d", &interval) != 1)
2947 if (interval < 0 || interval > 120)
2950 fan_watchdog_maxinterval = interval;
2955 static int fan_write(char *buf)
2960 while (!rc && (cmd = next_cmd(&buf))) {
2961 if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) &&
2962 fan_write_cmd_level(cmd, &rc)) &&
2963 !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) &&
2964 (fan_write_cmd_enable(cmd, &rc) ||
2965 fan_write_cmd_disable(cmd, &rc) ||
2966 fan_write_cmd_watchdog(cmd, &rc))) &&
2967 !((fan_control_commands & TPACPI_FAN_CMD_SPEED) &&
2968 fan_write_cmd_speed(cmd, &rc))
2972 fan_watchdog_reset();
2978 static struct ibm_struct fan_driver_data = {
2983 .flags.experimental = 1,
2986 /****************************************************************************
2987 ****************************************************************************
2991 ****************************************************************************
2992 ****************************************************************************/
2995 static struct proc_dir_entry *proc_dir = NULL;
2997 /* Subdriver registry */
2998 static LIST_HEAD(tpacpi_all_drivers);
3002 * Module and infrastructure proble, init and exit handling
3005 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
3006 static const char * __init str_supported(int is_supported)
3008 static char text_unsupported[] __initdata = "not supported";
3010 return (is_supported)? &text_unsupported[4] : &text_unsupported[0];
3012 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
3014 static int __init ibm_init(struct ibm_init_struct *iibm)
3017 struct ibm_struct *ibm = iibm->data;
3018 struct proc_dir_entry *entry;
3020 BUG_ON(ibm == NULL);
3022 INIT_LIST_HEAD(&ibm->all_drivers);
3024 if (ibm->flags.experimental && !experimental)
3027 dbg_printk(TPACPI_DBG_INIT,
3028 "probing for %s\n", ibm->name);
3031 ret = iibm->init(iibm);
3033 return 0; /* probe failed */
3037 ibm->flags.init_called = 1;
3041 if (ibm->acpi->hid) {
3042 ret = register_tpacpi_subdriver(ibm);
3047 if (ibm->acpi->notify) {
3048 ret = setup_acpi_notify(ibm);
3049 if (ret == -ENODEV) {
3050 printk(IBM_NOTICE "disabling subdriver %s\n",
3060 dbg_printk(TPACPI_DBG_INIT,
3061 "%s installed\n", ibm->name);
3064 entry = create_proc_entry(ibm->name,
3065 S_IFREG | S_IRUGO | S_IWUSR,
3068 printk(IBM_ERR "unable to create proc entry %s\n",
3073 entry->owner = THIS_MODULE;
3075 entry->read_proc = &dispatch_procfs_read;
3077 entry->write_proc = &dispatch_procfs_write;
3078 ibm->flags.proc_created = 1;
3081 list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers);
3086 dbg_printk(TPACPI_DBG_INIT,
3087 "%s: at error exit path with result %d\n",
3091 return (ret < 0)? ret : 0;
3094 static void ibm_exit(struct ibm_struct *ibm)
3096 dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name);
3098 list_del_init(&ibm->all_drivers);
3100 if (ibm->flags.acpi_notify_installed) {
3101 dbg_printk(TPACPI_DBG_EXIT,
3102 "%s: acpi_remove_notify_handler\n", ibm->name);
3104 acpi_remove_notify_handler(*ibm->acpi->handle,
3106 dispatch_acpi_notify);
3107 ibm->flags.acpi_notify_installed = 0;
3108 ibm->flags.acpi_notify_installed = 0;
3111 if (ibm->flags.proc_created) {
3112 dbg_printk(TPACPI_DBG_EXIT,
3113 "%s: remove_proc_entry\n", ibm->name);
3114 remove_proc_entry(ibm->name, proc_dir);
3115 ibm->flags.proc_created = 0;
3118 if (ibm->flags.acpi_driver_registered) {
3119 dbg_printk(TPACPI_DBG_EXIT,
3120 "%s: acpi_bus_unregister_driver\n", ibm->name);
3122 acpi_bus_unregister_driver(ibm->acpi->driver);
3123 kfree(ibm->acpi->driver);
3124 ibm->acpi->driver = NULL;
3125 ibm->flags.acpi_driver_registered = 0;
3128 if (ibm->flags.init_called && ibm->exit) {
3130 ibm->flags.init_called = 0;
3133 dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name);
3138 static char *ibm_thinkpad_ec_found = NULL;
3140 static char* __init check_dmi_for_ec(void)
3142 struct dmi_device *dev = NULL;
3143 char ec_fw_string[18];
3146 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
3147 * X32 or newer, all Z series; Some models must have an
3148 * up-to-date BIOS or they will not be detected.
3150 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
3152 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
3153 if (sscanf(dev->name,
3154 "IBM ThinkPad Embedded Controller -[%17c",
3155 ec_fw_string) == 1) {
3156 ec_fw_string[sizeof(ec_fw_string) - 1] = 0;
3157 ec_fw_string[strcspn(ec_fw_string, " ]")] = 0;
3158 return kstrdup(ec_fw_string, GFP_KERNEL);
3164 static int __init probe_for_thinkpad(void)
3172 * Non-ancient models have better DMI tagging, but very old models
3175 is_thinkpad = dmi_name_in_vendors("ThinkPad");
3177 /* ec is required because many other handles are relative to it */
3178 IBM_ACPIHANDLE_INIT(ec);
3182 "Not yet supported ThinkPad detected!\n");
3187 * Risks a regression on very old machines, but reduces potential
3188 * false positives a damn great deal
3191 is_thinkpad = dmi_name_in_vendors("IBM");
3193 if (!is_thinkpad && !force_load)
3200 /* Module init, exit, parameters */
3202 static struct ibm_init_struct ibms_init[] __initdata = {
3204 .init = thinkpad_acpi_driver_init,
3205 .data = &thinkpad_acpi_driver_data,
3208 .init = hotkey_init,
3209 .data = &hotkey_driver_data,
3212 .init = bluetooth_init,
3213 .data = &bluetooth_driver_data,
3217 .data = &wan_driver_data,
3221 .data = &video_driver_data,
3225 .data = &light_driver_data,
3227 #ifdef CONFIG_THINKPAD_ACPI_DOCK
3230 .data = &dock_driver_data[0],
3233 .data = &dock_driver_data[1],
3236 #ifdef CONFIG_THINKPAD_ACPI_BAY
3239 .data = &bay_driver_data,
3244 .data = &cmos_driver_data,
3248 .data = &led_driver_data,
3252 .data = &beep_driver_data,
3255 .init = thermal_init,
3256 .data = &thermal_driver_data,
3259 .data = &ecdump_driver_data,
3262 .init = brightness_init,
3263 .data = &brightness_driver_data,
3266 .data = &volume_driver_data,
3270 .data = &fan_driver_data,
3274 static int __init set_ibm_param(const char *val, struct kernel_param *kp)
3277 struct ibm_struct *ibm;
3279 for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
3280 ibm = ibms_init[i].data;
3281 BUG_ON(ibm == NULL);
3283 if (strcmp(ibm->name, kp->name) == 0 && ibm->write) {
3284 if (strlen(val) > sizeof(ibms_init[i].param) - 2)
3286 strcpy(ibms_init[i].param, val);
3287 strcat(ibms_init[i].param, ",");
3295 static int experimental;
3296 module_param(experimental, int, 0);
3298 static u32 dbg_level;
3299 module_param_named(debug, dbg_level, uint, 0);
3301 static int force_load;
3302 module_param(force_load, int, 0);
3304 #define IBM_PARAM(feature) \
3305 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
3308 IBM_PARAM(bluetooth);
3311 #ifdef CONFIG_THINKPAD_ACPI_DOCK
3314 #ifdef CONFIG_THINKPAD_ACPI_BAY
3316 #endif /* CONFIG_THINKPAD_ACPI_BAY */
3321 IBM_PARAM(brightness);
3325 static int __init thinkpad_acpi_module_init(void)
3329 /* Driver-level probe */
3330 ret = probe_for_thinkpad();
3334 /* Driver initialization */
3335 ibm_thinkpad_ec_found = check_dmi_for_ec();
3336 IBM_ACPIHANDLE_INIT(ecrd);
3337 IBM_ACPIHANDLE_INIT(ecwr);
3339 proc_dir = proc_mkdir(IBM_PROC_DIR, acpi_root_dir);
3341 printk(IBM_ERR "unable to create proc dir " IBM_PROC_DIR);
3342 thinkpad_acpi_module_exit();
3345 proc_dir->owner = THIS_MODULE;
3347 ret = platform_driver_register(&tpacpi_pdriver);
3349 printk(IBM_ERR "unable to register platform driver\n");
3350 thinkpad_acpi_module_exit();
3353 ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver);
3355 printk(IBM_ERR "unable to create sysfs driver attributes\n");
3356 thinkpad_acpi_module_exit();
3361 /* Device initialization */
3362 tpacpi_pdev = platform_device_register_simple(IBM_DRVR_NAME, -1,
3364 if (IS_ERR(tpacpi_pdev)) {
3365 ret = PTR_ERR(tpacpi_pdev);
3367 printk(IBM_ERR "unable to register platform device\n");
3368 thinkpad_acpi_module_exit();
3371 tpacpi_hwmon = hwmon_device_register(&tpacpi_pdev->dev);
3372 if (IS_ERR(tpacpi_hwmon)) {
3373 ret = PTR_ERR(tpacpi_hwmon);
3374 tpacpi_hwmon = NULL;
3375 printk(IBM_ERR "unable to register hwmon device\n");
3376 thinkpad_acpi_module_exit();
3379 for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
3380 ret = ibm_init(&ibms_init[i]);
3381 if (ret >= 0 && *ibms_init[i].param)
3382 ret = ibms_init[i].data->write(ibms_init[i].param);
3384 thinkpad_acpi_module_exit();
3392 static void thinkpad_acpi_module_exit(void)
3394 struct ibm_struct *ibm, *itmp;
3396 list_for_each_entry_safe_reverse(ibm, itmp,
3397 &tpacpi_all_drivers,
3402 dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n");
3405 hwmon_device_unregister(tpacpi_hwmon);
3408 platform_device_unregister(tpacpi_pdev);
3410 tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver);
3411 platform_driver_unregister(&tpacpi_pdriver);
3414 remove_proc_entry(IBM_PROC_DIR, acpi_root_dir);
3416 kfree(ibm_thinkpad_ec_found);
3419 module_init(thinkpad_acpi_module_init);
3420 module_exit(thinkpad_acpi_module_exit);