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 vdbg_printk(TPACPI_DBG_INIT, "trying to locate ACPI handle for %s\n",
302 for (i = 0; i < num_paths; i++) {
303 status = acpi_get_handle(parent, paths[i], handle);
304 if (ACPI_SUCCESS(status)) {
306 dbg_printk(TPACPI_DBG_INIT,
307 "Found ACPI handle %s for %s\n",
313 vdbg_printk(TPACPI_DBG_INIT, "ACPI handle for %s not found\n",
318 static void dispatch_acpi_notify(acpi_handle handle, u32 event, void *data)
320 struct ibm_struct *ibm = data;
322 if (!ibm || !ibm->acpi || !ibm->acpi->notify)
325 ibm->acpi->notify(ibm, event);
328 static int __init setup_acpi_notify(struct ibm_struct *ibm)
335 if (!*ibm->acpi->handle)
338 vdbg_printk(TPACPI_DBG_INIT,
339 "setting up ACPI notify for %s\n", ibm->name);
341 rc = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device);
343 printk(IBM_ERR "acpi_bus_get_device(%s) failed: %d\n",
348 acpi_driver_data(ibm->acpi->device) = ibm;
349 sprintf(acpi_device_class(ibm->acpi->device), "%s/%s",
350 IBM_ACPI_EVENT_PREFIX,
353 status = acpi_install_notify_handler(*ibm->acpi->handle,
354 ibm->acpi->type, dispatch_acpi_notify, ibm);
355 if (ACPI_FAILURE(status)) {
356 if (status == AE_ALREADY_EXISTS) {
357 printk(IBM_NOTICE "another device driver is already handling %s events\n",
360 printk(IBM_ERR "acpi_install_notify_handler(%s) failed: %d\n",
365 ibm->flags.acpi_notify_installed = 1;
369 static int __init tpacpi_device_add(struct acpi_device *device)
374 static int __init register_tpacpi_subdriver(struct ibm_struct *ibm)
378 dbg_printk(TPACPI_DBG_INIT,
379 "registering %s as an ACPI driver\n", ibm->name);
383 ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL);
384 if (!ibm->acpi->driver) {
385 printk(IBM_ERR "kzalloc(ibm->driver) failed\n");
389 sprintf(ibm->acpi->driver->name, "%s_%s", IBM_NAME, ibm->name);
390 ibm->acpi->driver->ids = ibm->acpi->hid;
391 ibm->acpi->driver->ops.add = &tpacpi_device_add;
393 rc = acpi_bus_register_driver(ibm->acpi->driver);
395 printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n",
397 kfree(ibm->acpi->driver);
398 ibm->acpi->driver = NULL;
400 ibm->flags.acpi_driver_registered = 1;
406 /****************************************************************************
407 ****************************************************************************
411 ****************************************************************************
412 ****************************************************************************/
414 static int dispatch_procfs_read(char *page, char **start, off_t off,
415 int count, int *eof, void *data)
417 struct ibm_struct *ibm = data;
420 if (!ibm || !ibm->read)
423 len = ibm->read(page);
427 if (len <= off + count)
439 static int dispatch_procfs_write(struct file *file,
440 const char __user * userbuf,
441 unsigned long count, void *data)
443 struct ibm_struct *ibm = data;
447 if (!ibm || !ibm->write)
450 kernbuf = kmalloc(count + 2, GFP_KERNEL);
454 if (copy_from_user(kernbuf, userbuf, count)) {
460 strcat(kernbuf, ",");
461 ret = ibm->write(kernbuf);
470 static char *next_cmd(char **cmds)
475 while ((end = strchr(start, ',')) && end == start)
487 /****************************************************************************
488 ****************************************************************************
490 * Device model: hwmon and platform
492 ****************************************************************************
493 ****************************************************************************/
495 static struct platform_device *tpacpi_pdev = NULL;
496 static struct class_device *tpacpi_hwmon = NULL;
498 static struct platform_driver tpacpi_pdriver = {
500 .name = IBM_DRVR_NAME,
501 .owner = THIS_MODULE,
506 /*************************************************************************
507 * thinkpad-acpi driver attributes
510 /* interface_version --------------------------------------------------- */
511 static ssize_t tpacpi_driver_interface_version_show(
512 struct device_driver *drv,
515 return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION);
518 static DRIVER_ATTR(interface_version, S_IRUGO,
519 tpacpi_driver_interface_version_show, NULL);
521 /* debug_level --------------------------------------------------------- */
522 static ssize_t tpacpi_driver_debug_show(struct device_driver *drv,
525 return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level);
528 static ssize_t tpacpi_driver_debug_store(struct device_driver *drv,
529 const char *buf, size_t count)
533 if (parse_strtoul(buf, 0xffff, &t))
541 static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
542 tpacpi_driver_debug_show, tpacpi_driver_debug_store);
544 /* version ------------------------------------------------------------- */
545 static ssize_t tpacpi_driver_version_show(struct device_driver *drv,
548 return snprintf(buf, PAGE_SIZE, "%s v%s\n", IBM_DESC, IBM_VERSION);
551 static DRIVER_ATTR(version, S_IRUGO,
552 tpacpi_driver_version_show, NULL);
554 /* --------------------------------------------------------------------- */
556 static struct driver_attribute* tpacpi_driver_attributes[] = {
557 &driver_attr_debug_level, &driver_attr_version,
558 &driver_attr_interface_version,
561 static int __init tpacpi_create_driver_attributes(struct device_driver *drv)
567 while (!res && i < ARRAY_SIZE(tpacpi_driver_attributes)) {
568 res = driver_create_file(drv, tpacpi_driver_attributes[i]);
575 static void tpacpi_remove_driver_attributes(struct device_driver *drv)
579 for(i = 0; i < ARRAY_SIZE(tpacpi_driver_attributes); i++)
580 driver_remove_file(drv, tpacpi_driver_attributes[i]);
583 /*************************************************************************
584 * sysfs support helpers
587 struct attribute_set_obj {
588 struct attribute_set s;
590 } __attribute__((packed));
592 static struct attribute_set *create_attr_set(unsigned int max_members,
595 struct attribute_set_obj *sobj;
597 if (max_members == 0)
600 /* Allocates space for implicit NULL at the end too */
601 sobj = kzalloc(sizeof(struct attribute_set_obj) +
602 max_members * sizeof(struct attribute *),
606 sobj->s.max_members = max_members;
607 sobj->s.group.attrs = &sobj->a;
608 sobj->s.group.name = name;
613 /* not multi-threaded safe, use it in a single thread per set */
614 static int add_to_attr_set(struct attribute_set* s, struct attribute *attr)
619 if (s->members >= s->max_members)
622 s->group.attrs[s->members] = attr;
628 static int add_many_to_attr_set(struct attribute_set* s,
629 struct attribute **attr,
634 for (i = 0; i < count; i++) {
635 res = add_to_attr_set(s, attr[i]);
643 static void delete_attr_set(struct attribute_set* s, struct kobject *kobj)
645 sysfs_remove_group(kobj, &s->group);
649 static int parse_strtoul(const char *buf,
650 unsigned long max, unsigned long *value)
654 *value = simple_strtoul(buf, &endp, 0);
655 while (*endp && isspace(*endp))
657 if (*endp || *value > max)
663 /****************************************************************************
664 ****************************************************************************
668 ****************************************************************************
669 ****************************************************************************/
671 /*************************************************************************
672 * thinkpad-acpi init subdriver
675 static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm)
677 printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION);
678 printk(IBM_INFO "%s\n", IBM_URL);
680 if (ibm_thinkpad_ec_found)
681 printk(IBM_INFO "ThinkPad EC firmware %s\n",
682 ibm_thinkpad_ec_found);
687 static int thinkpad_acpi_driver_read(char *p)
691 len += sprintf(p + len, "driver:\t\t%s\n", IBM_DESC);
692 len += sprintf(p + len, "version:\t%s\n", IBM_VERSION);
697 static struct ibm_struct thinkpad_acpi_driver_data = {
699 .read = thinkpad_acpi_driver_read,
702 /*************************************************************************
706 static int hotkey_orig_status;
707 static int hotkey_orig_mask;
709 static int __init hotkey_init(struct ibm_init_struct *iibm)
713 vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n");
715 IBM_ACPIHANDLE_INIT(hkey);
716 mutex_init(&hotkey_mutex);
718 /* hotkey not supported on 570 */
719 tp_features.hotkey = hkey_handle != NULL;
721 vdbg_printk(TPACPI_DBG_INIT, "hotkeys are %s\n",
722 str_supported(tp_features.hotkey));
724 if (tp_features.hotkey) {
725 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
726 A30, R30, R31, T20-22, X20-21, X22-24 */
727 tp_features.hotkey_mask =
728 acpi_evalf(hkey_handle, NULL, "DHKN", "qv");
730 vdbg_printk(TPACPI_DBG_INIT, "hotkey masks are %s\n",
731 str_supported(tp_features.hotkey_mask));
733 res = hotkey_get(&hotkey_orig_status, &hotkey_orig_mask);
738 return (tp_features.hotkey)? 0 : 1;
741 static void hotkey_exit(void)
745 if (tp_features.hotkey) {
746 dbg_printk(TPACPI_DBG_EXIT, "restoring original hotkey mask\n");
747 res = hotkey_set(hotkey_orig_status, hotkey_orig_mask);
749 printk(IBM_ERR "failed to restore hotkey to BIOS defaults\n");
753 static void hotkey_notify(struct ibm_struct *ibm, u32 event)
757 if (acpi_evalf(hkey_handle, &hkey, "MHKP", "d"))
758 acpi_bus_generate_event(ibm->acpi->device, event, hkey);
760 printk(IBM_ERR "unknown hotkey event %d\n", event);
761 acpi_bus_generate_event(ibm->acpi->device, event, 0);
766 * Call with hotkey_mutex held
768 static int hotkey_get(int *status, int *mask)
770 if (!acpi_evalf(hkey_handle, status, "DHKC", "d"))
773 if (tp_features.hotkey_mask)
774 if (!acpi_evalf(hkey_handle, mask, "DHKN", "d"))
781 * Call with hotkey_mutex held
783 static int hotkey_set(int status, int mask)
787 if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status))
790 if (tp_features.hotkey_mask)
791 for (i = 0; i < 32; i++) {
792 int bit = ((1 << i) & mask) != 0;
793 if (!acpi_evalf(hkey_handle,
794 NULL, "MHKM", "vdd", i + 1, bit))
801 static int hotkey_read(char *p)
803 int res, status, mask;
806 if (!tp_features.hotkey) {
807 len += sprintf(p + len, "status:\t\tnot supported\n");
811 res = mutex_lock_interruptible(&hotkey_mutex);
814 res = hotkey_get(&status, &mask);
815 mutex_unlock(&hotkey_mutex);
819 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0));
820 if (tp_features.hotkey_mask) {
821 len += sprintf(p + len, "mask:\t\t0x%04x\n", mask);
822 len += sprintf(p + len,
823 "commands:\tenable, disable, reset, <mask>\n");
825 len += sprintf(p + len, "mask:\t\tnot supported\n");
826 len += sprintf(p + len, "commands:\tenable, disable, reset\n");
832 static int hotkey_write(char *buf)
834 int res, status, mask;
838 if (!tp_features.hotkey)
841 res = mutex_lock_interruptible(&hotkey_mutex);
845 res = hotkey_get(&status, &mask);
850 while ((cmd = next_cmd(&buf))) {
851 if (strlencmp(cmd, "enable") == 0) {
853 } else if (strlencmp(cmd, "disable") == 0) {
855 } else if (strlencmp(cmd, "reset") == 0) {
856 status = hotkey_orig_status;
857 mask = hotkey_orig_mask;
858 } else if (sscanf(cmd, "0x%x", &mask) == 1) {
860 } else if (sscanf(cmd, "%x", &mask) == 1) {
870 res = hotkey_set(status, mask);
873 mutex_unlock(&hotkey_mutex);
877 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = {
879 .notify = hotkey_notify,
880 .handle = &hkey_handle,
881 .type = ACPI_DEVICE_NOTIFY,
884 static struct ibm_struct hotkey_driver_data = {
887 .write = hotkey_write,
889 .acpi = &ibm_hotkey_acpidriver,
892 /*************************************************************************
893 * Bluetooth subdriver
896 static int __init bluetooth_init(struct ibm_init_struct *iibm)
900 vdbg_printk(TPACPI_DBG_INIT, "initializing bluetooth subdriver\n");
902 IBM_ACPIHANDLE_INIT(hkey);
904 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
905 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
906 tp_features.bluetooth = hkey_handle &&
907 acpi_evalf(hkey_handle, &status, "GBDC", "qd");
909 vdbg_printk(TPACPI_DBG_INIT, "bluetooth is %s, status 0x%02x\n",
910 str_supported(tp_features.bluetooth),
913 if (tp_features.bluetooth &&
914 !(status & TP_ACPI_BLUETOOTH_HWPRESENT)) {
915 /* no bluetooth hardware present in system */
916 tp_features.bluetooth = 0;
917 dbg_printk(TPACPI_DBG_INIT,
918 "bluetooth hardware not installed\n");
921 return (tp_features.bluetooth)? 0 : 1;
924 static int bluetooth_get_radiosw(void)
928 if (!tp_features.bluetooth)
931 if (!acpi_evalf(hkey_handle, &status, "GBDC", "d"))
934 return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0);
937 static int bluetooth_set_radiosw(int radio_on)
941 if (!tp_features.bluetooth)
944 if (!acpi_evalf(hkey_handle, &status, "GBDC", "d"))
947 status |= TP_ACPI_BLUETOOTH_RADIOSSW;
949 status &= ~TP_ACPI_BLUETOOTH_RADIOSSW;
950 if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status))
956 static int bluetooth_read(char *p)
959 int status = bluetooth_get_radiosw();
961 if (!tp_features.bluetooth)
962 len += sprintf(p + len, "status:\t\tnot supported\n");
964 len += sprintf(p + len, "status:\t\t%s\n",
965 (status)? "enabled" : "disabled");
966 len += sprintf(p + len, "commands:\tenable, disable\n");
972 static int bluetooth_write(char *buf)
976 if (!tp_features.bluetooth)
979 while ((cmd = next_cmd(&buf))) {
980 if (strlencmp(cmd, "enable") == 0) {
981 bluetooth_set_radiosw(1);
982 } else if (strlencmp(cmd, "disable") == 0) {
983 bluetooth_set_radiosw(0);
991 static struct ibm_struct bluetooth_driver_data = {
993 .read = bluetooth_read,
994 .write = bluetooth_write,
997 /*************************************************************************
1001 static int __init wan_init(struct ibm_init_struct *iibm)
1005 vdbg_printk(TPACPI_DBG_INIT, "initializing wan subdriver\n");
1007 IBM_ACPIHANDLE_INIT(hkey);
1009 tp_features.wan = hkey_handle &&
1010 acpi_evalf(hkey_handle, &status, "GWAN", "qd");
1012 vdbg_printk(TPACPI_DBG_INIT, "wan is %s, status 0x%02x\n",
1013 str_supported(tp_features.wan),
1016 if (tp_features.wan &&
1017 !(status & TP_ACPI_WANCARD_HWPRESENT)) {
1018 /* no wan hardware present in system */
1019 tp_features.wan = 0;
1020 dbg_printk(TPACPI_DBG_INIT,
1021 "wan hardware not installed\n");
1024 return (tp_features.wan)? 0 : 1;
1027 static int wan_get_radiosw(void)
1031 if (!tp_features.wan)
1034 if (!acpi_evalf(hkey_handle, &status, "GWAN", "d"))
1037 return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0);
1040 static int wan_set_radiosw(int radio_on)
1044 if (!tp_features.wan)
1047 if (!acpi_evalf(hkey_handle, &status, "GWAN", "d"))
1050 status |= TP_ACPI_WANCARD_RADIOSSW;
1052 status &= ~TP_ACPI_WANCARD_RADIOSSW;
1053 if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status))
1059 static int wan_read(char *p)
1062 int status = wan_get_radiosw();
1064 if (!tp_features.wan)
1065 len += sprintf(p + len, "status:\t\tnot supported\n");
1067 len += sprintf(p + len, "status:\t\t%s\n",
1068 (status)? "enabled" : "disabled");
1069 len += sprintf(p + len, "commands:\tenable, disable\n");
1075 static int wan_write(char *buf)
1079 if (!tp_features.wan)
1082 while ((cmd = next_cmd(&buf))) {
1083 if (strlencmp(cmd, "enable") == 0) {
1085 } else if (strlencmp(cmd, "disable") == 0) {
1094 static struct ibm_struct wan_driver_data = {
1098 .flags.experimental = 1,
1101 /*************************************************************************
1105 static enum video_access_mode video_supported;
1106 static int video_orig_autosw;
1108 IBM_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */
1109 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
1110 "\\_SB.PCI0.VID0", /* 770e */
1111 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
1112 "\\_SB.PCI0.AGP.VID", /* all others */
1115 IBM_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */
1117 static int __init video_init(struct ibm_init_struct *iibm)
1121 vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n");
1123 IBM_ACPIHANDLE_INIT(vid);
1124 IBM_ACPIHANDLE_INIT(vid2);
1126 if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga)
1127 /* G41, assume IVGA doesn't change */
1128 vid_handle = vid2_handle;
1131 /* video switching not supported on R30, R31 */
1132 video_supported = TPACPI_VIDEO_NONE;
1133 else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd"))
1135 video_supported = TPACPI_VIDEO_570;
1136 else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd"))
1137 /* 600e/x, 770e, 770x */
1138 video_supported = TPACPI_VIDEO_770;
1141 video_supported = TPACPI_VIDEO_NEW;
1143 vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n",
1144 str_supported(video_supported != TPACPI_VIDEO_NONE),
1147 return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1;
1150 static void video_exit(void)
1152 dbg_printk(TPACPI_DBG_EXIT,
1153 "restoring original video autoswitch mode\n");
1154 if (video_autosw_set(video_orig_autosw))
1155 printk(IBM_ERR "error while trying to restore original "
1156 "video autoswitch mode\n");
1159 static int video_outputsw_get(void)
1164 switch (video_supported) {
1165 case TPACPI_VIDEO_570:
1166 if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd",
1167 TP_ACPI_VIDEO_570_PHSCMD))
1169 status = i & TP_ACPI_VIDEO_570_PHSMASK;
1171 case TPACPI_VIDEO_770:
1172 if (!acpi_evalf(NULL, &i, "\\VCDL", "d"))
1175 status |= TP_ACPI_VIDEO_S_LCD;
1176 if (!acpi_evalf(NULL, &i, "\\VCDC", "d"))
1179 status |= TP_ACPI_VIDEO_S_CRT;
1181 case TPACPI_VIDEO_NEW:
1182 if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) ||
1183 !acpi_evalf(NULL, &i, "\\VCDC", "d"))
1186 status |= TP_ACPI_VIDEO_S_CRT;
1188 if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) ||
1189 !acpi_evalf(NULL, &i, "\\VCDL", "d"))
1192 status |= TP_ACPI_VIDEO_S_LCD;
1193 if (!acpi_evalf(NULL, &i, "\\VCDD", "d"))
1196 status |= TP_ACPI_VIDEO_S_DVI;
1205 static int video_outputsw_set(int status)
1210 switch (video_supported) {
1211 case TPACPI_VIDEO_570:
1212 res = acpi_evalf(NULL, NULL,
1213 "\\_SB.PHS2", "vdd",
1214 TP_ACPI_VIDEO_570_PHS2CMD,
1215 status | TP_ACPI_VIDEO_570_PHS2SET);
1217 case TPACPI_VIDEO_770:
1218 autosw = video_autosw_get();
1222 res = video_autosw_set(1);
1225 res = acpi_evalf(vid_handle, NULL,
1226 "ASWT", "vdd", status * 0x100, 0);
1227 if (!autosw && video_autosw_set(autosw)) {
1228 printk(IBM_ERR "video auto-switch left enabled due to error\n");
1232 case TPACPI_VIDEO_NEW:
1233 res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) &&
1234 acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1);
1240 return (res)? 0 : -EIO;
1243 static int video_autosw_get(void)
1247 switch (video_supported) {
1248 case TPACPI_VIDEO_570:
1249 if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d"))
1252 case TPACPI_VIDEO_770:
1253 case TPACPI_VIDEO_NEW:
1254 if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d"))
1264 static int video_autosw_set(int enable)
1266 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0))
1271 static int video_outputsw_cycle(void)
1273 int autosw = video_autosw_get();
1279 switch (video_supported) {
1280 case TPACPI_VIDEO_570:
1281 res = video_autosw_set(1);
1284 res = acpi_evalf(ec_handle, NULL, "_Q16", "v");
1286 case TPACPI_VIDEO_770:
1287 case TPACPI_VIDEO_NEW:
1288 res = video_autosw_set(1);
1291 res = acpi_evalf(vid_handle, NULL, "VSWT", "v");
1296 if (!autosw && video_autosw_set(autosw)) {
1297 printk(IBM_ERR "video auto-switch left enabled due to error\n");
1301 return (res)? 0 : -EIO;
1304 static int video_expand_toggle(void)
1306 switch (video_supported) {
1307 case TPACPI_VIDEO_570:
1308 return acpi_evalf(ec_handle, NULL, "_Q17", "v")?
1310 case TPACPI_VIDEO_770:
1311 return acpi_evalf(vid_handle, NULL, "VEXP", "v")?
1313 case TPACPI_VIDEO_NEW:
1314 return acpi_evalf(NULL, NULL, "\\VEXP", "v")?
1322 static int video_read(char *p)
1327 if (video_supported == TPACPI_VIDEO_NONE) {
1328 len += sprintf(p + len, "status:\t\tnot supported\n");
1332 status = video_outputsw_get();
1336 autosw = video_autosw_get();
1340 len += sprintf(p + len, "status:\t\tsupported\n");
1341 len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0));
1342 len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1));
1343 if (video_supported == TPACPI_VIDEO_NEW)
1344 len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3));
1345 len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0));
1346 len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n");
1347 len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n");
1348 if (video_supported == TPACPI_VIDEO_NEW)
1349 len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n");
1350 len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n");
1351 len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n");
1356 static int video_write(char *buf)
1359 int enable, disable, status;
1362 if (video_supported == TPACPI_VIDEO_NONE)
1368 while ((cmd = next_cmd(&buf))) {
1369 if (strlencmp(cmd, "lcd_enable") == 0) {
1370 enable |= TP_ACPI_VIDEO_S_LCD;
1371 } else if (strlencmp(cmd, "lcd_disable") == 0) {
1372 disable |= TP_ACPI_VIDEO_S_LCD;
1373 } else if (strlencmp(cmd, "crt_enable") == 0) {
1374 enable |= TP_ACPI_VIDEO_S_CRT;
1375 } else if (strlencmp(cmd, "crt_disable") == 0) {
1376 disable |= TP_ACPI_VIDEO_S_CRT;
1377 } else if (video_supported == TPACPI_VIDEO_NEW &&
1378 strlencmp(cmd, "dvi_enable") == 0) {
1379 enable |= TP_ACPI_VIDEO_S_DVI;
1380 } else if (video_supported == TPACPI_VIDEO_NEW &&
1381 strlencmp(cmd, "dvi_disable") == 0) {
1382 disable |= TP_ACPI_VIDEO_S_DVI;
1383 } else if (strlencmp(cmd, "auto_enable") == 0) {
1384 res = video_autosw_set(1);
1387 } else if (strlencmp(cmd, "auto_disable") == 0) {
1388 res = video_autosw_set(0);
1391 } else if (strlencmp(cmd, "video_switch") == 0) {
1392 res = video_outputsw_cycle();
1395 } else if (strlencmp(cmd, "expand_toggle") == 0) {
1396 res = video_expand_toggle();
1403 if (enable || disable) {
1404 status = video_outputsw_get();
1407 res = video_outputsw_set((status & ~disable) | enable);
1415 static struct ibm_struct video_driver_data = {
1418 .write = video_write,
1422 /*************************************************************************
1423 * Light (thinklight) subdriver
1426 IBM_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
1427 IBM_HANDLE(ledb, ec, "LEDB"); /* G4x */
1429 static int __init light_init(struct ibm_init_struct *iibm)
1431 vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n");
1433 IBM_ACPIHANDLE_INIT(ledb);
1434 IBM_ACPIHANDLE_INIT(lght);
1435 IBM_ACPIHANDLE_INIT(cmos);
1437 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
1438 tp_features.light = (cmos_handle || lght_handle) && !ledb_handle;
1440 if (tp_features.light)
1441 /* light status not supported on
1442 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
1443 tp_features.light_status =
1444 acpi_evalf(ec_handle, NULL, "KBLT", "qv");
1446 vdbg_printk(TPACPI_DBG_INIT, "light is %s\n",
1447 str_supported(tp_features.light));
1449 return (tp_features.light)? 0 : 1;
1452 static int light_read(char *p)
1457 if (!tp_features.light) {
1458 len += sprintf(p + len, "status:\t\tnot supported\n");
1459 } else if (!tp_features.light_status) {
1460 len += sprintf(p + len, "status:\t\tunknown\n");
1461 len += sprintf(p + len, "commands:\ton, off\n");
1463 if (!acpi_evalf(ec_handle, &status, "KBLT", "d"))
1465 len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0));
1466 len += sprintf(p + len, "commands:\ton, off\n");
1472 static int light_write(char *buf)
1474 int cmos_cmd, lght_cmd;
1478 if (!tp_features.light)
1481 while ((cmd = next_cmd(&buf))) {
1482 if (strlencmp(cmd, "on") == 0) {
1485 } else if (strlencmp(cmd, "off") == 0) {
1491 success = cmos_handle ?
1492 acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd) :
1493 acpi_evalf(lght_handle, NULL, NULL, "vd", lght_cmd);
1501 static struct ibm_struct light_driver_data = {
1504 .write = light_write,
1507 /*************************************************************************
1511 #ifdef CONFIG_THINKPAD_ACPI_DOCK
1513 IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */
1514 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
1515 "\\_SB.PCI0.PCI1.DOCK", /* all others */
1516 "\\_SB.PCI.ISA.SLCE", /* 570 */
1517 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
1519 /* don't list other alternatives as we install a notify handler on the 570 */
1520 IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */
1522 static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = {
1524 .notify = dock_notify,
1525 .handle = &dock_handle,
1526 .type = ACPI_SYSTEM_NOTIFY,
1530 .notify = dock_notify,
1531 .handle = &pci_handle,
1532 .type = ACPI_SYSTEM_NOTIFY,
1536 static struct ibm_struct dock_driver_data[2] = {
1540 .write = dock_write,
1541 .acpi = &ibm_dock_acpidriver[0],
1545 .acpi = &ibm_dock_acpidriver[1],
1549 #define dock_docked() (_sta(dock_handle) & 1)
1551 static int __init dock_init(struct ibm_init_struct *iibm)
1553 vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver\n");
1555 IBM_ACPIHANDLE_INIT(dock);
1557 vdbg_printk(TPACPI_DBG_INIT, "dock is %s\n",
1558 str_supported(dock_handle != NULL));
1560 return (dock_handle)? 0 : 1;
1563 static int __init dock_init2(struct ibm_init_struct *iibm)
1567 vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver part 2\n");
1569 if (dock_driver_data[0].flags.acpi_driver_registered &&
1570 dock_driver_data[0].flags.acpi_notify_installed) {
1571 IBM_ACPIHANDLE_INIT(pci);
1572 dock2_needed = (pci_handle != NULL);
1573 vdbg_printk(TPACPI_DBG_INIT,
1574 "dock PCI handler for the TP 570 is %s\n",
1575 str_supported(dock2_needed));
1577 vdbg_printk(TPACPI_DBG_INIT,
1578 "dock subdriver part 2 not required\n");
1582 return (dock2_needed)? 0 : 1;
1585 static void dock_notify(struct ibm_struct *ibm, u32 event)
1587 int docked = dock_docked();
1588 int pci = ibm->acpi->hid && strstr(ibm->acpi->hid, IBM_PCI_HID);
1590 if (event == 1 && !pci) /* 570 */
1591 acpi_bus_generate_event(ibm->acpi->device, event, 1); /* button */
1592 else if (event == 1 && pci) /* 570 */
1593 acpi_bus_generate_event(ibm->acpi->device, event, 3); /* dock */
1594 else if (event == 3 && docked)
1595 acpi_bus_generate_event(ibm->acpi->device, event, 1); /* button */
1596 else if (event == 3 && !docked)
1597 acpi_bus_generate_event(ibm->acpi->device, event, 2); /* undock */
1598 else if (event == 0 && docked)
1599 acpi_bus_generate_event(ibm->acpi->device, event, 3); /* dock */
1601 printk(IBM_ERR "unknown dock event %d, status %d\n",
1602 event, _sta(dock_handle));
1603 acpi_bus_generate_event(ibm->acpi->device, event, 0); /* unknown */
1607 static int dock_read(char *p)
1610 int docked = dock_docked();
1613 len += sprintf(p + len, "status:\t\tnot supported\n");
1615 len += sprintf(p + len, "status:\t\tundocked\n");
1617 len += sprintf(p + len, "status:\t\tdocked\n");
1618 len += sprintf(p + len, "commands:\tdock, undock\n");
1624 static int dock_write(char *buf)
1631 while ((cmd = next_cmd(&buf))) {
1632 if (strlencmp(cmd, "undock") == 0) {
1633 if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0) ||
1634 !acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1))
1636 } else if (strlencmp(cmd, "dock") == 0) {
1637 if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1))
1646 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
1648 /*************************************************************************
1652 #ifdef CONFIG_THINKPAD_ACPI_BAY
1653 IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
1654 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
1655 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
1656 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
1657 ); /* A21e, R30, R31 */
1658 IBM_HANDLE(bay_ej, bay, "_EJ3", /* 600e/x, A2xm/p, A3x */
1659 "_EJ0", /* all others */
1660 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
1661 IBM_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
1662 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
1664 IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */
1668 static int __init bay_init(struct ibm_init_struct *iibm)
1670 vdbg_printk(TPACPI_DBG_INIT, "initializing bay subdriver\n");
1672 IBM_ACPIHANDLE_INIT(bay);
1674 IBM_ACPIHANDLE_INIT(bay_ej);
1675 IBM_ACPIHANDLE_INIT(bay2);
1677 IBM_ACPIHANDLE_INIT(bay2_ej);
1679 tp_features.bay_status = bay_handle &&
1680 acpi_evalf(bay_handle, NULL, "_STA", "qv");
1681 tp_features.bay_status2 = bay2_handle &&
1682 acpi_evalf(bay2_handle, NULL, "_STA", "qv");
1684 tp_features.bay_eject = bay_handle && bay_ej_handle &&
1685 (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental);
1686 tp_features.bay_eject2 = bay2_handle && bay2_ej_handle &&
1687 (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental);
1689 vdbg_printk(TPACPI_DBG_INIT,
1690 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
1691 str_supported(tp_features.bay_status),
1692 str_supported(tp_features.bay_eject),
1693 str_supported(tp_features.bay_status2),
1694 str_supported(tp_features.bay_eject2));
1696 return (tp_features.bay_status || tp_features.bay_eject ||
1697 tp_features.bay_status2 || tp_features.bay_eject2)? 0 : 1;
1700 static void bay_notify(struct ibm_struct *ibm, u32 event)
1702 acpi_bus_generate_event(ibm->acpi->device, event, 0);
1705 #define bay_occupied(b) (_sta(b##_handle) & 1)
1707 static int bay_read(char *p)
1710 int occupied = bay_occupied(bay);
1711 int occupied2 = bay_occupied(bay2);
1714 len += sprintf(p + len, "status:\t\t%s\n",
1715 tp_features.bay_status ?
1716 (occupied ? "occupied" : "unoccupied") :
1718 if (tp_features.bay_status2)
1719 len += sprintf(p + len, "status2:\t%s\n", occupied2 ?
1720 "occupied" : "unoccupied");
1722 eject = tp_features.bay_eject && occupied;
1723 eject2 = tp_features.bay_eject2 && occupied2;
1725 if (eject && eject2)
1726 len += sprintf(p + len, "commands:\teject, eject2\n");
1728 len += sprintf(p + len, "commands:\teject\n");
1730 len += sprintf(p + len, "commands:\teject2\n");
1735 static int bay_write(char *buf)
1739 if (!tp_features.bay_eject && !tp_features.bay_eject2)
1742 while ((cmd = next_cmd(&buf))) {
1743 if (tp_features.bay_eject && strlencmp(cmd, "eject") == 0) {
1744 if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1))
1746 } else if (tp_features.bay_eject2 &&
1747 strlencmp(cmd, "eject2") == 0) {
1748 if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1))
1757 static struct tp_acpi_drv_struct ibm_bay_acpidriver = {
1758 .notify = bay_notify,
1759 .handle = &bay_handle,
1760 .type = ACPI_SYSTEM_NOTIFY,
1763 static struct ibm_struct bay_driver_data = {
1767 .acpi = &ibm_bay_acpidriver,
1770 #endif /* CONFIG_THINKPAD_ACPI_BAY */
1772 /*************************************************************************
1776 /* sysfs cmos_command -------------------------------------------------- */
1777 static ssize_t cmos_command_store(struct device *dev,
1778 struct device_attribute *attr,
1779 const char *buf, size_t count)
1781 unsigned long cmos_cmd;
1784 if (parse_strtoul(buf, 21, &cmos_cmd))
1787 res = issue_thinkpad_cmos_command(cmos_cmd);
1788 return (res)? res : count;
1791 static struct device_attribute dev_attr_cmos_command =
1792 __ATTR(cmos_command, S_IWUSR, NULL, cmos_command_store);
1794 /* --------------------------------------------------------------------- */
1796 static int __init cmos_init(struct ibm_init_struct *iibm)
1800 vdbg_printk(TPACPI_DBG_INIT,
1801 "initializing cmos commands subdriver\n");
1803 IBM_ACPIHANDLE_INIT(cmos);
1805 vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n",
1806 str_supported(cmos_handle != NULL));
1808 res = device_create_file(&tpacpi_pdev->dev, &dev_attr_cmos_command);
1812 return (cmos_handle)? 0 : 1;
1815 static void cmos_exit(void)
1817 device_remove_file(&tpacpi_pdev->dev, &dev_attr_cmos_command);
1820 static int cmos_read(char *p)
1824 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1825 R30, R31, T20-22, X20-21 */
1827 len += sprintf(p + len, "status:\t\tnot supported\n");
1829 len += sprintf(p + len, "status:\t\tsupported\n");
1830 len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n");
1836 static int cmos_write(char *buf)
1841 while ((cmd = next_cmd(&buf))) {
1842 if (sscanf(cmd, "%u", &cmos_cmd) == 1 &&
1843 cmos_cmd >= 0 && cmos_cmd <= 21) {
1848 res = issue_thinkpad_cmos_command(cmos_cmd);
1856 static struct ibm_struct cmos_driver_data = {
1859 .write = cmos_write,
1863 /*************************************************************************
1867 static enum led_access_mode led_supported;
1869 IBM_HANDLE(led, ec, "SLED", /* 570 */
1870 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1871 "LED", /* all others */
1874 static int __init led_init(struct ibm_init_struct *iibm)
1876 vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n");
1878 IBM_ACPIHANDLE_INIT(led);
1881 /* led not supported on R30, R31 */
1882 led_supported = TPACPI_LED_NONE;
1883 else if (strlencmp(led_path, "SLED") == 0)
1885 led_supported = TPACPI_LED_570;
1886 else if (strlencmp(led_path, "SYSL") == 0)
1887 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1888 led_supported = TPACPI_LED_OLD;
1891 led_supported = TPACPI_LED_NEW;
1893 vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n",
1894 str_supported(led_supported), led_supported);
1896 return (led_supported != TPACPI_LED_NONE)? 0 : 1;
1899 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
1901 static int led_read(char *p)
1905 if (!led_supported) {
1906 len += sprintf(p + len, "status:\t\tnot supported\n");
1909 len += sprintf(p + len, "status:\t\tsupported\n");
1911 if (led_supported == TPACPI_LED_570) {
1914 for (i = 0; i < 8; i++) {
1915 if (!acpi_evalf(ec_handle,
1916 &status, "GLED", "dd", 1 << i))
1918 len += sprintf(p + len, "%d:\t\t%s\n",
1919 i, led_status(status));
1923 len += sprintf(p + len, "commands:\t"
1924 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
1929 /* off, on, blink */
1930 static const int led_sled_arg1[] = { 0, 1, 3 };
1931 static const int led_exp_hlbl[] = { 0, 0, 1 }; /* led# * */
1932 static const int led_exp_hlcl[] = { 0, 1, 1 }; /* led# * */
1933 static const int led_led_arg1[] = { 0, 0x80, 0xc0 };
1935 static int led_write(char *buf)
1943 while ((cmd = next_cmd(&buf))) {
1944 if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 7)
1947 if (strstr(cmd, "off")) {
1949 } else if (strstr(cmd, "on")) {
1951 } else if (strstr(cmd, "blink")) {
1956 if (led_supported == TPACPI_LED_570) {
1959 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
1960 led, led_sled_arg1[ind]))
1962 } else if (led_supported == TPACPI_LED_OLD) {
1963 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
1965 ret = ec_write(TPACPI_LED_EC_HLMS, led);
1968 ec_write(TPACPI_LED_EC_HLBL,
1969 led * led_exp_hlbl[ind]);
1972 ec_write(TPACPI_LED_EC_HLCL,
1973 led * led_exp_hlcl[ind]);
1978 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
1979 led, led_led_arg1[ind]))
1987 static struct ibm_struct led_driver_data = {
1993 /*************************************************************************
1997 IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */
1999 static int __init beep_init(struct ibm_init_struct *iibm)
2001 vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n");
2003 IBM_ACPIHANDLE_INIT(beep);
2005 vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n",
2006 str_supported(beep_handle != NULL));
2008 return (beep_handle)? 0 : 1;
2011 static int beep_read(char *p)
2016 len += sprintf(p + len, "status:\t\tnot supported\n");
2018 len += sprintf(p + len, "status:\t\tsupported\n");
2019 len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n");
2025 static int beep_write(char *buf)
2033 while ((cmd = next_cmd(&buf))) {
2034 if (sscanf(cmd, "%u", &beep_cmd) == 1 &&
2035 beep_cmd >= 0 && beep_cmd <= 17) {
2039 if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", beep_cmd, 0))
2046 static struct ibm_struct beep_driver_data = {
2049 .write = beep_write,
2052 /*************************************************************************
2056 static enum thermal_access_mode thermal_read_mode;
2058 /* sysfs temp##_input -------------------------------------------------- */
2060 static ssize_t thermal_temp_input_show(struct device *dev,
2061 struct device_attribute *attr,
2064 struct sensor_device_attribute *sensor_attr =
2065 to_sensor_dev_attr(attr);
2066 int idx = sensor_attr->index;
2070 res = thermal_get_sensor(idx, &value);
2073 if (value == TP_EC_THERMAL_TMP_NA * 1000)
2076 return snprintf(buf, PAGE_SIZE, "%d\n", value);
2079 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
2080 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB)
2082 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input[] = {
2083 THERMAL_SENSOR_ATTR_TEMP(1, 0),
2084 THERMAL_SENSOR_ATTR_TEMP(2, 1),
2085 THERMAL_SENSOR_ATTR_TEMP(3, 2),
2086 THERMAL_SENSOR_ATTR_TEMP(4, 3),
2087 THERMAL_SENSOR_ATTR_TEMP(5, 4),
2088 THERMAL_SENSOR_ATTR_TEMP(6, 5),
2089 THERMAL_SENSOR_ATTR_TEMP(7, 6),
2090 THERMAL_SENSOR_ATTR_TEMP(8, 7),
2091 THERMAL_SENSOR_ATTR_TEMP(9, 8),
2092 THERMAL_SENSOR_ATTR_TEMP(10, 9),
2093 THERMAL_SENSOR_ATTR_TEMP(11, 10),
2094 THERMAL_SENSOR_ATTR_TEMP(12, 11),
2095 THERMAL_SENSOR_ATTR_TEMP(13, 12),
2096 THERMAL_SENSOR_ATTR_TEMP(14, 13),
2097 THERMAL_SENSOR_ATTR_TEMP(15, 14),
2098 THERMAL_SENSOR_ATTR_TEMP(16, 15),
2101 #define THERMAL_ATTRS(X) \
2102 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
2104 static struct attribute *thermal_temp_input_attr[] = {
2124 static const struct attribute_group thermal_temp_input16_group = {
2125 .attrs = thermal_temp_input_attr
2128 static const struct attribute_group thermal_temp_input8_group = {
2129 .attrs = &thermal_temp_input_attr[8]
2132 #undef THERMAL_SENSOR_ATTR_TEMP
2133 #undef THERMAL_ATTRS
2135 /* --------------------------------------------------------------------- */
2137 static int __init thermal_init(struct ibm_init_struct *iibm)
2144 vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n");
2146 acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv");
2148 if (ibm_thinkpad_ec_found && experimental) {
2150 * Direct EC access mode: sensors at registers
2151 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
2152 * non-implemented, thermal sensors return 0x80 when
2157 for (i = 0; i < 8; i++) {
2158 if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) {
2164 if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) {
2172 /* This is sheer paranoia, but we handle it anyway */
2175 "ThinkPad ACPI EC access misbehaving, "
2176 "falling back to ACPI TMPx access mode\n");
2177 thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07;
2180 "ThinkPad ACPI EC access misbehaving, "
2181 "disabling thermal sensors access\n");
2182 thermal_read_mode = TPACPI_THERMAL_NONE;
2187 TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8;
2189 } else if (acpi_tmp7) {
2190 if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) {
2191 /* 600e/x, 770e, 770x */
2192 thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT;
2194 /* Standard ACPI TMPx access, max 8 sensors */
2195 thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07;
2198 /* temperatures not supported on 570, G4x, R30, R31, R32 */
2199 thermal_read_mode = TPACPI_THERMAL_NONE;
2202 vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n",
2203 str_supported(thermal_read_mode != TPACPI_THERMAL_NONE),
2206 switch(thermal_read_mode) {
2207 case TPACPI_THERMAL_TPEC_16:
2208 res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
2209 &thermal_temp_input16_group);
2213 case TPACPI_THERMAL_TPEC_8:
2214 case TPACPI_THERMAL_ACPI_TMP07:
2215 case TPACPI_THERMAL_ACPI_UPDT:
2216 res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
2217 &thermal_temp_input8_group);
2221 case TPACPI_THERMAL_NONE:
2229 static void thermal_exit(void)
2231 switch(thermal_read_mode) {
2232 case TPACPI_THERMAL_TPEC_16:
2233 sysfs_remove_group(&tpacpi_pdev->dev.kobj,
2234 &thermal_temp_input16_group);
2236 case TPACPI_THERMAL_TPEC_8:
2237 case TPACPI_THERMAL_ACPI_TMP07:
2238 case TPACPI_THERMAL_ACPI_UPDT:
2239 sysfs_remove_group(&tpacpi_pdev->dev.kobj,
2240 &thermal_temp_input16_group);
2242 case TPACPI_THERMAL_NONE:
2248 /* idx is zero-based */
2249 static int thermal_get_sensor(int idx, s32 *value)
2255 t = TP_EC_THERMAL_TMP0;
2257 switch (thermal_read_mode) {
2258 #if TPACPI_MAX_THERMAL_SENSORS >= 16
2259 case TPACPI_THERMAL_TPEC_16:
2260 if (idx >= 8 && idx <= 15) {
2261 t = TP_EC_THERMAL_TMP8;
2266 case TPACPI_THERMAL_TPEC_8:
2268 if (!acpi_ec_read(t + idx, &tmp))
2270 *value = tmp * 1000;
2275 case TPACPI_THERMAL_ACPI_UPDT:
2277 snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
2278 if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
2280 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
2282 *value = (t - 2732) * 100;
2287 case TPACPI_THERMAL_ACPI_TMP07:
2289 snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
2290 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
2297 case TPACPI_THERMAL_NONE:
2305 static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
2316 if (thermal_read_mode == TPACPI_THERMAL_TPEC_16)
2319 for(i = 0 ; i < n; i++) {
2320 res = thermal_get_sensor(i, &s->temp[i]);
2328 static int thermal_read(char *p)
2332 struct ibm_thermal_sensors_struct t;
2334 n = thermal_get_sensors(&t);
2335 if (unlikely(n < 0))
2338 len += sprintf(p + len, "temperatures:\t");
2341 for (i = 0; i < (n - 1); i++)
2342 len += sprintf(p + len, "%d ", t.temp[i] / 1000);
2343 len += sprintf(p + len, "%d\n", t.temp[i] / 1000);
2345 len += sprintf(p + len, "not supported\n");
2350 static struct ibm_struct thermal_driver_data = {
2352 .read = thermal_read,
2353 .exit = thermal_exit,
2356 /*************************************************************************
2360 static u8 ecdump_regs[256];
2362 static int ecdump_read(char *p)
2368 len += sprintf(p + len, "EC "
2369 " +00 +01 +02 +03 +04 +05 +06 +07"
2370 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
2371 for (i = 0; i < 256; i += 16) {
2372 len += sprintf(p + len, "EC 0x%02x:", i);
2373 for (j = 0; j < 16; j++) {
2374 if (!acpi_ec_read(i + j, &v))
2376 if (v != ecdump_regs[i + j])
2377 len += sprintf(p + len, " *%02x", v);
2379 len += sprintf(p + len, " %02x", v);
2380 ecdump_regs[i + j] = v;
2382 len += sprintf(p + len, "\n");
2387 /* These are way too dangerous to advertise openly... */
2389 len += sprintf(p + len, "commands:\t0x<offset> 0x<value>"
2390 " (<offset> is 00-ff, <value> is 00-ff)\n");
2391 len += sprintf(p + len, "commands:\t0x<offset> <value> "
2392 " (<offset> is 00-ff, <value> is 0-255)\n");
2397 static int ecdump_write(char *buf)
2402 while ((cmd = next_cmd(&buf))) {
2403 if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) {
2405 } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) {
2409 if (i >= 0 && i < 256 && v >= 0 && v < 256) {
2410 if (!acpi_ec_write(i, v))
2419 static struct ibm_struct ecdump_driver_data = {
2421 .read = ecdump_read,
2422 .write = ecdump_write,
2423 .flags.experimental = 1,
2426 /*************************************************************************
2427 * Backlight/brightness subdriver
2430 static struct backlight_device *ibm_backlight_device = NULL;
2432 static struct backlight_ops ibm_backlight_data = {
2433 .get_brightness = brightness_get,
2434 .update_status = brightness_update_status,
2437 static int __init brightness_init(struct ibm_init_struct *iibm)
2441 vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n");
2443 b = brightness_get(NULL);
2447 ibm_backlight_device = backlight_device_register(
2448 TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL,
2449 &ibm_backlight_data);
2450 if (IS_ERR(ibm_backlight_device)) {
2451 printk(IBM_ERR "Could not register backlight device\n");
2452 return PTR_ERR(ibm_backlight_device);
2454 vdbg_printk(TPACPI_DBG_INIT, "brightness is supported\n");
2456 ibm_backlight_device->props.max_brightness = 7;
2457 ibm_backlight_device->props.brightness = b;
2458 backlight_update_status(ibm_backlight_device);
2463 static void brightness_exit(void)
2465 if (ibm_backlight_device) {
2466 vdbg_printk(TPACPI_DBG_EXIT,
2467 "calling backlight_device_unregister()\n");
2468 backlight_device_unregister(ibm_backlight_device);
2469 ibm_backlight_device = NULL;
2473 static int brightness_update_status(struct backlight_device *bd)
2475 return brightness_set(
2476 (bd->props.fb_blank == FB_BLANK_UNBLANK &&
2477 bd->props.power == FB_BLANK_UNBLANK) ?
2478 bd->props.brightness : 0);
2481 static int brightness_get(struct backlight_device *bd)
2484 if (!acpi_ec_read(brightness_offset, &level))
2492 static int brightness_set(int value)
2494 int cmos_cmd, inc, i;
2495 int current_value = brightness_get(NULL);
2499 cmos_cmd = value > current_value ? TP_CMOS_BRIGHTNESS_UP : TP_CMOS_BRIGHTNESS_DOWN;
2500 inc = value > current_value ? 1 : -1;
2501 for (i = current_value; i != value; i += inc) {
2502 if (issue_thinkpad_cmos_command(cmos_cmd))
2504 if (!acpi_ec_write(brightness_offset, i + inc))
2511 static int brightness_read(char *p)
2516 if ((level = brightness_get(NULL)) < 0) {
2517 len += sprintf(p + len, "level:\t\tunreadable\n");
2519 len += sprintf(p + len, "level:\t\t%d\n", level & 0x7);
2520 len += sprintf(p + len, "commands:\tup, down\n");
2521 len += sprintf(p + len, "commands:\tlevel <level>"
2522 " (<level> is 0-7)\n");
2528 static int brightness_write(char *buf)
2534 while ((cmd = next_cmd(&buf))) {
2535 if ((level = brightness_get(NULL)) < 0)
2539 if (strlencmp(cmd, "up") == 0) {
2540 new_level = level == 7 ? 7 : level + 1;
2541 } else if (strlencmp(cmd, "down") == 0) {
2542 new_level = level == 0 ? 0 : level - 1;
2543 } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
2544 new_level >= 0 && new_level <= 7) {
2549 brightness_set(new_level);
2555 static struct ibm_struct brightness_driver_data = {
2556 .name = "brightness",
2557 .read = brightness_read,
2558 .write = brightness_write,
2559 .exit = brightness_exit,
2562 /*************************************************************************
2566 static int volume_read(char *p)
2571 if (!acpi_ec_read(volume_offset, &level)) {
2572 len += sprintf(p + len, "level:\t\tunreadable\n");
2574 len += sprintf(p + len, "level:\t\t%d\n", level & 0xf);
2575 len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6));
2576 len += sprintf(p + len, "commands:\tup, down, mute\n");
2577 len += sprintf(p + len, "commands:\tlevel <level>"
2578 " (<level> is 0-15)\n");
2584 static int volume_write(char *buf)
2586 int cmos_cmd, inc, i;
2588 int new_level, new_mute;
2591 while ((cmd = next_cmd(&buf))) {
2592 if (!acpi_ec_read(volume_offset, &level))
2594 new_mute = mute = level & 0x40;
2595 new_level = level = level & 0xf;
2597 if (strlencmp(cmd, "up") == 0) {
2601 new_level = level == 15 ? 15 : level + 1;
2602 } else if (strlencmp(cmd, "down") == 0) {
2606 new_level = level == 0 ? 0 : level - 1;
2607 } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
2608 new_level >= 0 && new_level <= 15) {
2610 } else if (strlencmp(cmd, "mute") == 0) {
2615 if (new_level != level) { /* mute doesn't change */
2616 cmos_cmd = new_level > level ? TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN;
2617 inc = new_level > level ? 1 : -1;
2619 if (mute && (issue_thinkpad_cmos_command(cmos_cmd) ||
2620 !acpi_ec_write(volume_offset, level)))
2623 for (i = level; i != new_level; i += inc)
2624 if (issue_thinkpad_cmos_command(cmos_cmd) ||
2625 !acpi_ec_write(volume_offset, i + inc))
2628 if (mute && (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE) ||
2629 !acpi_ec_write(volume_offset,
2634 if (new_mute != mute) { /* level doesn't change */
2635 cmos_cmd = new_mute ? TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP;
2637 if (issue_thinkpad_cmos_command(cmos_cmd) ||
2638 !acpi_ec_write(volume_offset, level + new_mute))
2646 static struct ibm_struct volume_driver_data = {
2648 .read = volume_read,
2649 .write = volume_write,
2652 /*************************************************************************
2659 * TPACPI_FAN_RD_ACPI_GFAN:
2660 * ACPI GFAN method: returns fan level
2662 * see TPACPI_FAN_WR_ACPI_SFAN
2663 * EC 0x2f (HFSP) not available if GFAN exists
2665 * TPACPI_FAN_WR_ACPI_SFAN:
2666 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
2668 * EC 0x2f (HFSP) might be available *for reading*, but do not use
2671 * TPACPI_FAN_WR_TPEC:
2672 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
2673 * Supported on almost all ThinkPads
2675 * Fan speed changes of any sort (including those caused by the
2676 * disengaged mode) are usually done slowly by the firmware as the
2677 * maximum ammount of fan duty cycle change per second seems to be
2680 * Reading is not available if GFAN exists.
2681 * Writing is not available if SFAN exists.
2684 * 7 automatic mode engaged;
2685 * (default operation mode of the ThinkPad)
2686 * fan level is ignored in this mode.
2687 * 6 full speed mode (takes precedence over bit 7);
2688 * not available on all thinkpads. May disable
2689 * the tachometer while the fan controller ramps up
2690 * the speed (which can take up to a few *minutes*).
2691 * Speeds up fan to 100% duty-cycle, which is far above
2692 * the standard RPM levels. It is not impossible that
2693 * it could cause hardware damage.
2694 * 5-3 unused in some models. Extra bits for fan level
2695 * in others, but still useless as all values above
2696 * 7 map to the same speed as level 7 in these models.
2697 * 2-0 fan level (0..7 usually)
2699 * 0x07 = max (set when temperatures critical)
2700 * Some ThinkPads may have other levels, see
2701 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
2703 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
2704 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
2705 * does so, its initial value is meaningless (0x07).
2707 * For firmware bugs, refer to:
2708 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
2712 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
2713 * Main fan tachometer reading (in RPM)
2715 * This register is present on all ThinkPads with a new-style EC, and
2716 * it is known not to be present on the A21m/e, and T22, as there is
2717 * something else in offset 0x84 according to the ACPI DSDT. Other
2718 * ThinkPads from this same time period (and earlier) probably lack the
2719 * tachometer as well.
2721 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
2722 * was never fixed by IBM to report the EC firmware version string
2723 * probably support the tachometer (like the early X models), so
2724 * detecting it is quite hard. We need more data to know for sure.
2726 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
2729 * FIRMWARE BUG: may go stale while the EC is switching to full speed
2732 * For firmware bugs, refer to:
2733 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
2735 * TPACPI_FAN_WR_ACPI_FANS:
2736 * ThinkPad X31, X40, X41. Not available in the X60.
2738 * FANS ACPI handle: takes three arguments: low speed, medium speed,
2739 * high speed. ACPI DSDT seems to map these three speeds to levels
2740 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
2741 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
2743 * The speeds are stored on handles
2744 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
2746 * There are three default speed sets, acessible as handles:
2747 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
2749 * ACPI DSDT switches which set is in use depending on various
2752 * TPACPI_FAN_WR_TPEC is also available and should be used to
2753 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
2754 * but the ACPI tables just mention level 7.
2757 static enum fan_status_access_mode fan_status_access_mode;
2758 static enum fan_control_access_mode fan_control_access_mode;
2759 static enum fan_control_commands fan_control_commands;
2761 static u8 fan_control_initial_status;
2762 static u8 fan_control_desired_level;
2764 static void fan_watchdog_fire(struct work_struct *ignored);
2765 static int fan_watchdog_maxinterval;
2766 static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire);
2768 IBM_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */
2769 IBM_HANDLE(gfan, ec, "GFAN", /* 570 */
2770 "\\FSPD", /* 600e/x, 770e, 770x */
2772 IBM_HANDLE(sfan, ec, "SFAN", /* 570 */
2773 "JFNS", /* 770x-JL */
2777 * SYSFS fan layout: hwmon compatible (device)
2780 * 0: "disengaged" mode
2782 * 2: native EC "auto" mode (recommended, hardware default)
2784 * pwm*: set speed in manual mode, ignored otherwise.
2785 * 0 is level 0; 255 is level 7. Intermediate points done with linear
2788 * fan*_input: tachometer reading, RPM
2791 * SYSFS fan layout: extensions
2793 * fan_watchdog (driver):
2794 * fan watchdog interval in seconds, 0 disables (default), max 120
2797 /* sysfs fan pwm1_enable ----------------------------------------------- */
2798 static ssize_t fan_pwm1_enable_show(struct device *dev,
2799 struct device_attribute *attr,
2805 res = fan_get_status_safe(&status);
2809 if (unlikely(tp_features.fan_ctrl_status_undef)) {
2810 if (status != fan_control_initial_status) {
2811 tp_features.fan_ctrl_status_undef = 0;
2813 /* Return most likely status. In fact, it
2814 * might be the only possible status */
2815 status = TP_EC_FAN_AUTO;
2819 if (status & TP_EC_FAN_FULLSPEED) {
2821 } else if (status & TP_EC_FAN_AUTO) {
2826 return snprintf(buf, PAGE_SIZE, "%d\n", mode);
2829 static ssize_t fan_pwm1_enable_store(struct device *dev,
2830 struct device_attribute *attr,
2831 const char *buf, size_t count)
2836 if (parse_strtoul(buf, 2, &t))
2841 level = TP_EC_FAN_FULLSPEED;
2844 level = TPACPI_FAN_LAST_LEVEL;
2847 level = TP_EC_FAN_AUTO;
2850 /* reserved for software-controlled auto mode */
2856 res = fan_set_level_safe(level);
2862 fan_watchdog_reset();
2867 static struct device_attribute dev_attr_fan_pwm1_enable =
2868 __ATTR(pwm1_enable, S_IWUSR | S_IRUGO,
2869 fan_pwm1_enable_show, fan_pwm1_enable_store);
2871 /* sysfs fan pwm1 ------------------------------------------------------ */
2872 static ssize_t fan_pwm1_show(struct device *dev,
2873 struct device_attribute *attr,
2879 res = fan_get_status_safe(&status);
2883 if (unlikely(tp_features.fan_ctrl_status_undef)) {
2884 if (status != fan_control_initial_status) {
2885 tp_features.fan_ctrl_status_undef = 0;
2887 status = TP_EC_FAN_AUTO;
2892 (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) != 0)
2893 status = fan_control_desired_level;
2898 return snprintf(buf, PAGE_SIZE, "%u\n", (status * 255) / 7);
2901 static ssize_t fan_pwm1_store(struct device *dev,
2902 struct device_attribute *attr,
2903 const char *buf, size_t count)
2907 u8 status, newlevel;
2909 if (parse_strtoul(buf, 255, &s))
2912 /* scale down from 0-255 to 0-7 */
2913 newlevel = (s >> 5) & 0x07;
2915 rc = mutex_lock_interruptible(&fan_mutex);
2919 rc = fan_get_status(&status);
2920 if (!rc && (status &
2921 (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) {
2922 rc = fan_set_level(newlevel);
2926 fan_update_desired_level(newlevel);
2927 fan_watchdog_reset();
2931 mutex_unlock(&fan_mutex);
2932 return (rc)? rc : count;
2935 static struct device_attribute dev_attr_fan_pwm1 =
2936 __ATTR(pwm1, S_IWUSR | S_IRUGO,
2937 fan_pwm1_show, fan_pwm1_store);
2939 /* sysfs fan fan1_input ------------------------------------------------ */
2940 static ssize_t fan_fan1_input_show(struct device *dev,
2941 struct device_attribute *attr,
2947 res = fan_get_speed(&speed);
2951 return snprintf(buf, PAGE_SIZE, "%u\n", speed);
2954 static struct device_attribute dev_attr_fan_fan1_input =
2955 __ATTR(fan1_input, S_IRUGO,
2956 fan_fan1_input_show, NULL);
2958 /* sysfs fan fan_watchdog (driver) ------------------------------------- */
2959 static ssize_t fan_fan_watchdog_show(struct device_driver *drv,
2962 return snprintf(buf, PAGE_SIZE, "%u\n", fan_watchdog_maxinterval);
2965 static ssize_t fan_fan_watchdog_store(struct device_driver *drv,
2966 const char *buf, size_t count)
2970 if (parse_strtoul(buf, 120, &t))
2973 if (!fan_control_allowed)
2976 fan_watchdog_maxinterval = t;
2977 fan_watchdog_reset();
2982 static DRIVER_ATTR(fan_watchdog, S_IWUSR | S_IRUGO,
2983 fan_fan_watchdog_show, fan_fan_watchdog_store);
2985 /* --------------------------------------------------------------------- */
2986 static struct attribute *fan_attributes[] = {
2987 &dev_attr_fan_pwm1_enable.attr, &dev_attr_fan_pwm1.attr,
2988 &dev_attr_fan_fan1_input.attr,
2992 static const struct attribute_group fan_attr_group = {
2993 .attrs = fan_attributes,
2996 static int __init fan_init(struct ibm_init_struct *iibm)
3000 vdbg_printk(TPACPI_DBG_INIT, "initializing fan subdriver\n");
3002 mutex_init(&fan_mutex);
3003 fan_status_access_mode = TPACPI_FAN_NONE;
3004 fan_control_access_mode = TPACPI_FAN_WR_NONE;
3005 fan_control_commands = 0;
3006 fan_watchdog_maxinterval = 0;
3007 tp_features.fan_ctrl_status_undef = 0;
3008 fan_control_desired_level = 7;
3010 IBM_ACPIHANDLE_INIT(fans);
3011 IBM_ACPIHANDLE_INIT(gfan);
3012 IBM_ACPIHANDLE_INIT(sfan);
3015 /* 570, 600e/x, 770e, 770x */
3016 fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN;
3018 /* all other ThinkPads: note that even old-style
3019 * ThinkPad ECs supports the fan control register */
3020 if (likely(acpi_ec_read(fan_status_offset,
3021 &fan_control_initial_status))) {
3022 fan_status_access_mode = TPACPI_FAN_RD_TPEC;
3024 /* In some ThinkPads, neither the EC nor the ACPI
3025 * DSDT initialize the fan status, and it ends up
3026 * being set to 0x07 when it *could* be either
3029 * Enable for TP-1Y (T43), TP-78 (R51e),
3030 * TP-76 (R52), TP-70 (T43, R52), which are known
3032 if (fan_control_initial_status == 0x07 &&
3033 ibm_thinkpad_ec_found &&
3034 ((ibm_thinkpad_ec_found[0] == '1' &&
3035 ibm_thinkpad_ec_found[1] == 'Y') ||
3036 (ibm_thinkpad_ec_found[0] == '7' &&
3037 (ibm_thinkpad_ec_found[1] == '6' ||
3038 ibm_thinkpad_ec_found[1] == '8' ||
3039 ibm_thinkpad_ec_found[1] == '0'))
3042 "fan_init: initial fan status is "
3043 "unknown, assuming it is in auto "
3045 tp_features.fan_ctrl_status_undef = 1;
3049 "ThinkPad ACPI EC access misbehaving, "
3050 "fan status and control unavailable\n");
3057 fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN;
3058 fan_control_commands |=
3059 TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE;
3062 /* gfan without sfan means no fan control */
3063 /* all other models implement TP EC 0x2f control */
3067 fan_control_access_mode =
3068 TPACPI_FAN_WR_ACPI_FANS;
3069 fan_control_commands |=
3070 TPACPI_FAN_CMD_SPEED |
3071 TPACPI_FAN_CMD_LEVEL |
3072 TPACPI_FAN_CMD_ENABLE;
3074 fan_control_access_mode = TPACPI_FAN_WR_TPEC;
3075 fan_control_commands |=
3076 TPACPI_FAN_CMD_LEVEL |
3077 TPACPI_FAN_CMD_ENABLE;
3082 vdbg_printk(TPACPI_DBG_INIT, "fan is %s, modes %d, %d\n",
3083 str_supported(fan_status_access_mode != TPACPI_FAN_NONE ||
3084 fan_control_access_mode != TPACPI_FAN_WR_NONE),
3085 fan_status_access_mode, fan_control_access_mode);
3087 /* fan control master switch */
3088 if (!fan_control_allowed) {
3089 fan_control_access_mode = TPACPI_FAN_WR_NONE;
3090 fan_control_commands = 0;
3091 dbg_printk(TPACPI_DBG_INIT,
3092 "fan control features disabled by parameter\n");
3095 /* update fan_control_desired_level */
3096 if (fan_status_access_mode != TPACPI_FAN_NONE)
3097 fan_get_status_safe(NULL);
3099 if (fan_status_access_mode != TPACPI_FAN_NONE ||
3100 fan_control_access_mode != TPACPI_FAN_WR_NONE) {
3101 rc = sysfs_create_group(&tpacpi_pdev->dev.kobj,
3104 rc = driver_create_file(&tpacpi_pdriver.driver,
3105 &driver_attr_fan_watchdog);
3114 * Call with fan_mutex held
3116 static void fan_update_desired_level(u8 status)
3119 (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) {
3121 fan_control_desired_level = 7;
3123 fan_control_desired_level = status;
3127 static int fan_get_status(u8 *status)
3132 * Add TPACPI_FAN_RD_ACPI_FANS ? */
3134 switch (fan_status_access_mode) {
3135 case TPACPI_FAN_RD_ACPI_GFAN:
3136 /* 570, 600e/x, 770e, 770x */
3138 if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d")))
3146 case TPACPI_FAN_RD_TPEC:
3147 /* all except 570, 600e/x, 770e, 770x */
3148 if (unlikely(!acpi_ec_read(fan_status_offset, &s)))
3163 static int fan_get_status_safe(u8 *status)
3168 rc = mutex_lock_interruptible(&fan_mutex);
3171 rc = fan_get_status(&s);
3173 fan_update_desired_level(s);
3174 mutex_unlock(&fan_mutex);
3182 static void fan_exit(void)
3184 vdbg_printk(TPACPI_DBG_EXIT, "cancelling any pending fan watchdog tasks\n");
3186 /* FIXME: can we really do this unconditionally? */
3187 sysfs_remove_group(&tpacpi_pdev->dev.kobj, &fan_attr_group);
3188 driver_remove_file(&tpacpi_pdriver.driver, &driver_attr_fan_watchdog);
3190 cancel_delayed_work(&fan_watchdog_task);
3191 flush_scheduled_work();
3194 static int fan_get_speed(unsigned int *speed)
3198 switch (fan_status_access_mode) {
3199 case TPACPI_FAN_RD_TPEC:
3200 /* all except 570, 600e/x, 770e, 770x */
3201 if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) ||
3202 !acpi_ec_read(fan_rpm_offset + 1, &hi)))
3206 *speed = (hi << 8) | lo;
3217 static void fan_watchdog_fire(struct work_struct *ignored)
3221 printk(IBM_NOTICE "fan watchdog: enabling fan\n");
3222 rc = fan_set_enable();
3224 printk(IBM_ERR "fan watchdog: error %d while enabling fan, "
3225 "will try again later...\n", -rc);
3226 /* reschedule for later */
3227 fan_watchdog_reset();
3231 static void fan_watchdog_reset(void)
3233 static int fan_watchdog_active = 0;
3235 if (fan_control_access_mode == TPACPI_FAN_WR_NONE)
3238 if (fan_watchdog_active)
3239 cancel_delayed_work(&fan_watchdog_task);
3241 if (fan_watchdog_maxinterval > 0) {
3242 fan_watchdog_active = 1;
3243 if (!schedule_delayed_work(&fan_watchdog_task,
3244 msecs_to_jiffies(fan_watchdog_maxinterval
3246 printk(IBM_ERR "failed to schedule the fan watchdog, "
3247 "watchdog will not trigger\n");
3250 fan_watchdog_active = 0;
3253 static int fan_set_level(int level)
3255 if (!fan_control_allowed)
3258 switch (fan_control_access_mode) {
3259 case TPACPI_FAN_WR_ACPI_SFAN:
3260 if (level >= 0 && level <= 7) {
3261 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level))
3267 case TPACPI_FAN_WR_ACPI_FANS:
3268 case TPACPI_FAN_WR_TPEC:
3269 if ((level != TP_EC_FAN_AUTO) &&
3270 (level != TP_EC_FAN_FULLSPEED) &&
3271 ((level < 0) || (level > 7)))
3274 /* safety net should the EC not support AUTO
3275 * or FULLSPEED mode bits and just ignore them */
3276 if (level & TP_EC_FAN_FULLSPEED)
3277 level |= 7; /* safety min speed 7 */
3278 else if (level & TP_EC_FAN_FULLSPEED)
3279 level |= 4; /* safety min speed 4 */
3281 if (!acpi_ec_write(fan_status_offset, level))
3284 tp_features.fan_ctrl_status_undef = 0;
3293 static int fan_set_level_safe(int level)
3297 if (!fan_control_allowed)
3300 rc = mutex_lock_interruptible(&fan_mutex);
3304 if (level == TPACPI_FAN_LAST_LEVEL)
3305 level = fan_control_desired_level;
3307 rc = fan_set_level(level);
3309 fan_update_desired_level(level);
3311 mutex_unlock(&fan_mutex);
3315 static int fan_set_enable(void)
3320 if (!fan_control_allowed)
3323 rc = mutex_lock_interruptible(&fan_mutex);
3327 switch (fan_control_access_mode) {
3328 case TPACPI_FAN_WR_ACPI_FANS:
3329 case TPACPI_FAN_WR_TPEC:
3330 rc = fan_get_status(&s);
3334 /* Don't go out of emergency fan mode */
3337 s |= TP_EC_FAN_AUTO | 4; /* min fan speed 4 */
3340 if (!acpi_ec_write(fan_status_offset, s))
3343 tp_features.fan_ctrl_status_undef = 0;
3348 case TPACPI_FAN_WR_ACPI_SFAN:
3349 rc = fan_get_status(&s);
3355 /* Set fan to at least level 4 */
3358 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s))
3368 mutex_unlock(&fan_mutex);
3372 static int fan_set_disable(void)
3376 if (!fan_control_allowed)
3379 rc = mutex_lock_interruptible(&fan_mutex);
3384 switch (fan_control_access_mode) {
3385 case TPACPI_FAN_WR_ACPI_FANS:
3386 case TPACPI_FAN_WR_TPEC:
3387 if (!acpi_ec_write(fan_status_offset, 0x00))
3390 fan_control_desired_level = 0;
3391 tp_features.fan_ctrl_status_undef = 0;
3395 case TPACPI_FAN_WR_ACPI_SFAN:
3396 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00))
3399 fan_control_desired_level = 0;
3407 mutex_unlock(&fan_mutex);
3411 static int fan_set_speed(int speed)
3415 if (!fan_control_allowed)
3418 rc = mutex_lock_interruptible(&fan_mutex);
3423 switch (fan_control_access_mode) {
3424 case TPACPI_FAN_WR_ACPI_FANS:
3425 if (speed >= 0 && speed <= 65535) {
3426 if (!acpi_evalf(fans_handle, NULL, NULL, "vddd",
3427 speed, speed, speed))
3437 mutex_unlock(&fan_mutex);
3441 static int fan_read(char *p)
3446 unsigned int speed = 0;
3448 switch (fan_status_access_mode) {
3449 case TPACPI_FAN_RD_ACPI_GFAN:
3450 /* 570, 600e/x, 770e, 770x */
3451 if ((rc = fan_get_status_safe(&status)) < 0)
3454 len += sprintf(p + len, "status:\t\t%s\n"
3456 (status != 0) ? "enabled" : "disabled", status);
3459 case TPACPI_FAN_RD_TPEC:
3460 /* all except 570, 600e/x, 770e, 770x */
3461 if ((rc = fan_get_status_safe(&status)) < 0)
3464 if (unlikely(tp_features.fan_ctrl_status_undef)) {
3465 if (status != fan_control_initial_status)
3466 tp_features.fan_ctrl_status_undef = 0;
3468 /* Return most likely status. In fact, it
3469 * might be the only possible status */
3470 status = TP_EC_FAN_AUTO;
3473 len += sprintf(p + len, "status:\t\t%s\n",
3474 (status != 0) ? "enabled" : "disabled");
3476 if ((rc = fan_get_speed(&speed)) < 0)
3479 len += sprintf(p + len, "speed:\t\t%d\n", speed);
3481 if (status & TP_EC_FAN_FULLSPEED)
3482 /* Disengaged mode takes precedence */
3483 len += sprintf(p + len, "level:\t\tdisengaged\n");
3484 else if (status & TP_EC_FAN_AUTO)
3485 len += sprintf(p + len, "level:\t\tauto\n");
3487 len += sprintf(p + len, "level:\t\t%d\n", status);
3490 case TPACPI_FAN_NONE:
3492 len += sprintf(p + len, "status:\t\tnot supported\n");
3495 if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) {
3496 len += sprintf(p + len, "commands:\tlevel <level>");
3498 switch (fan_control_access_mode) {
3499 case TPACPI_FAN_WR_ACPI_SFAN:
3500 len += sprintf(p + len, " (<level> is 0-7)\n");
3504 len += sprintf(p + len, " (<level> is 0-7, "
3505 "auto, disengaged, full-speed)\n");
3510 if (fan_control_commands & TPACPI_FAN_CMD_ENABLE)
3511 len += sprintf(p + len, "commands:\tenable, disable\n"
3512 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
3513 "1-120 (seconds))\n");
3515 if (fan_control_commands & TPACPI_FAN_CMD_SPEED)
3516 len += sprintf(p + len, "commands:\tspeed <speed>"
3517 " (<speed> is 0-65535)\n");
3522 static int fan_write_cmd_level(const char *cmd, int *rc)
3526 if (strlencmp(cmd, "level auto") == 0)
3527 level = TP_EC_FAN_AUTO;
3528 else if ((strlencmp(cmd, "level disengaged") == 0) |
3529 (strlencmp(cmd, "level full-speed") == 0))
3530 level = TP_EC_FAN_FULLSPEED;
3531 else if (sscanf(cmd, "level %d", &level) != 1)
3534 if ((*rc = fan_set_level_safe(level)) == -ENXIO)
3535 printk(IBM_ERR "level command accepted for unsupported "
3536 "access mode %d", fan_control_access_mode);
3541 static int fan_write_cmd_enable(const char *cmd, int *rc)
3543 if (strlencmp(cmd, "enable") != 0)
3546 if ((*rc = fan_set_enable()) == -ENXIO)
3547 printk(IBM_ERR "enable command accepted for unsupported "
3548 "access mode %d", fan_control_access_mode);
3553 static int fan_write_cmd_disable(const char *cmd, int *rc)
3555 if (strlencmp(cmd, "disable") != 0)
3558 if ((*rc = fan_set_disable()) == -ENXIO)
3559 printk(IBM_ERR "disable command accepted for unsupported "
3560 "access mode %d", fan_control_access_mode);
3565 static int fan_write_cmd_speed(const char *cmd, int *rc)
3570 * Support speed <low> <medium> <high> ? */
3572 if (sscanf(cmd, "speed %d", &speed) != 1)
3575 if ((*rc = fan_set_speed(speed)) == -ENXIO)
3576 printk(IBM_ERR "speed command accepted for unsupported "
3577 "access mode %d", fan_control_access_mode);
3582 static int fan_write_cmd_watchdog(const char *cmd, int *rc)
3586 if (sscanf(cmd, "watchdog %d", &interval) != 1)
3589 if (interval < 0 || interval > 120)
3592 fan_watchdog_maxinterval = interval;
3597 static int fan_write(char *buf)
3602 while (!rc && (cmd = next_cmd(&buf))) {
3603 if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) &&
3604 fan_write_cmd_level(cmd, &rc)) &&
3605 !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) &&
3606 (fan_write_cmd_enable(cmd, &rc) ||
3607 fan_write_cmd_disable(cmd, &rc) ||
3608 fan_write_cmd_watchdog(cmd, &rc))) &&
3609 !((fan_control_commands & TPACPI_FAN_CMD_SPEED) &&
3610 fan_write_cmd_speed(cmd, &rc))
3614 fan_watchdog_reset();
3620 static struct ibm_struct fan_driver_data = {
3627 /****************************************************************************
3628 ****************************************************************************
3632 ****************************************************************************
3633 ****************************************************************************/
3636 static struct proc_dir_entry *proc_dir = NULL;
3638 /* Subdriver registry */
3639 static LIST_HEAD(tpacpi_all_drivers);
3643 * Module and infrastructure proble, init and exit handling
3646 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
3647 static const char * __init str_supported(int is_supported)
3649 static char text_unsupported[] __initdata = "not supported";
3651 return (is_supported)? &text_unsupported[4] : &text_unsupported[0];
3653 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
3655 static int __init ibm_init(struct ibm_init_struct *iibm)
3658 struct ibm_struct *ibm = iibm->data;
3659 struct proc_dir_entry *entry;
3661 BUG_ON(ibm == NULL);
3663 INIT_LIST_HEAD(&ibm->all_drivers);
3665 if (ibm->flags.experimental && !experimental)
3668 dbg_printk(TPACPI_DBG_INIT,
3669 "probing for %s\n", ibm->name);
3672 ret = iibm->init(iibm);
3674 return 0; /* probe failed */
3678 ibm->flags.init_called = 1;
3682 if (ibm->acpi->hid) {
3683 ret = register_tpacpi_subdriver(ibm);
3688 if (ibm->acpi->notify) {
3689 ret = setup_acpi_notify(ibm);
3690 if (ret == -ENODEV) {
3691 printk(IBM_NOTICE "disabling subdriver %s\n",
3701 dbg_printk(TPACPI_DBG_INIT,
3702 "%s installed\n", ibm->name);
3705 entry = create_proc_entry(ibm->name,
3706 S_IFREG | S_IRUGO | S_IWUSR,
3709 printk(IBM_ERR "unable to create proc entry %s\n",
3714 entry->owner = THIS_MODULE;
3716 entry->read_proc = &dispatch_procfs_read;
3718 entry->write_proc = &dispatch_procfs_write;
3719 ibm->flags.proc_created = 1;
3722 list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers);
3727 dbg_printk(TPACPI_DBG_INIT,
3728 "%s: at error exit path with result %d\n",
3732 return (ret < 0)? ret : 0;
3735 static void ibm_exit(struct ibm_struct *ibm)
3737 dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name);
3739 list_del_init(&ibm->all_drivers);
3741 if (ibm->flags.acpi_notify_installed) {
3742 dbg_printk(TPACPI_DBG_EXIT,
3743 "%s: acpi_remove_notify_handler\n", ibm->name);
3745 acpi_remove_notify_handler(*ibm->acpi->handle,
3747 dispatch_acpi_notify);
3748 ibm->flags.acpi_notify_installed = 0;
3749 ibm->flags.acpi_notify_installed = 0;
3752 if (ibm->flags.proc_created) {
3753 dbg_printk(TPACPI_DBG_EXIT,
3754 "%s: remove_proc_entry\n", ibm->name);
3755 remove_proc_entry(ibm->name, proc_dir);
3756 ibm->flags.proc_created = 0;
3759 if (ibm->flags.acpi_driver_registered) {
3760 dbg_printk(TPACPI_DBG_EXIT,
3761 "%s: acpi_bus_unregister_driver\n", ibm->name);
3763 acpi_bus_unregister_driver(ibm->acpi->driver);
3764 kfree(ibm->acpi->driver);
3765 ibm->acpi->driver = NULL;
3766 ibm->flags.acpi_driver_registered = 0;
3769 if (ibm->flags.init_called && ibm->exit) {
3771 ibm->flags.init_called = 0;
3774 dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name);
3779 static char *ibm_thinkpad_ec_found = NULL;
3781 static char* __init check_dmi_for_ec(void)
3783 struct dmi_device *dev = NULL;
3784 char ec_fw_string[18];
3787 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
3788 * X32 or newer, all Z series; Some models must have an
3789 * up-to-date BIOS or they will not be detected.
3791 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
3793 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
3794 if (sscanf(dev->name,
3795 "IBM ThinkPad Embedded Controller -[%17c",
3796 ec_fw_string) == 1) {
3797 ec_fw_string[sizeof(ec_fw_string) - 1] = 0;
3798 ec_fw_string[strcspn(ec_fw_string, " ]")] = 0;
3799 return kstrdup(ec_fw_string, GFP_KERNEL);
3805 static int __init probe_for_thinkpad(void)
3813 * Non-ancient models have better DMI tagging, but very old models
3816 is_thinkpad = dmi_name_in_vendors("ThinkPad");
3818 /* ec is required because many other handles are relative to it */
3819 IBM_ACPIHANDLE_INIT(ec);
3823 "Not yet supported ThinkPad detected!\n");
3828 * Risks a regression on very old machines, but reduces potential
3829 * false positives a damn great deal
3832 is_thinkpad = dmi_name_in_vendors("IBM");
3834 if (!is_thinkpad && !force_load)
3841 /* Module init, exit, parameters */
3843 static struct ibm_init_struct ibms_init[] __initdata = {
3845 .init = thinkpad_acpi_driver_init,
3846 .data = &thinkpad_acpi_driver_data,
3849 .init = hotkey_init,
3850 .data = &hotkey_driver_data,
3853 .init = bluetooth_init,
3854 .data = &bluetooth_driver_data,
3858 .data = &wan_driver_data,
3862 .data = &video_driver_data,
3866 .data = &light_driver_data,
3868 #ifdef CONFIG_THINKPAD_ACPI_DOCK
3871 .data = &dock_driver_data[0],
3875 .data = &dock_driver_data[1],
3878 #ifdef CONFIG_THINKPAD_ACPI_BAY
3881 .data = &bay_driver_data,
3886 .data = &cmos_driver_data,
3890 .data = &led_driver_data,
3894 .data = &beep_driver_data,
3897 .init = thermal_init,
3898 .data = &thermal_driver_data,
3901 .data = &ecdump_driver_data,
3904 .init = brightness_init,
3905 .data = &brightness_driver_data,
3908 .data = &volume_driver_data,
3912 .data = &fan_driver_data,
3916 static int __init set_ibm_param(const char *val, struct kernel_param *kp)
3919 struct ibm_struct *ibm;
3921 for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
3922 ibm = ibms_init[i].data;
3923 BUG_ON(ibm == NULL);
3925 if (strcmp(ibm->name, kp->name) == 0 && ibm->write) {
3926 if (strlen(val) > sizeof(ibms_init[i].param) - 2)
3928 strcpy(ibms_init[i].param, val);
3929 strcat(ibms_init[i].param, ",");
3937 static int experimental;
3938 module_param(experimental, int, 0);
3940 static u32 dbg_level;
3941 module_param_named(debug, dbg_level, uint, 0);
3943 static int force_load;
3944 module_param(force_load, int, 0);
3946 static int fan_control_allowed;
3947 module_param_named(fan_control, fan_control_allowed, int, 0);
3949 #define IBM_PARAM(feature) \
3950 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
3953 IBM_PARAM(bluetooth);
3956 #ifdef CONFIG_THINKPAD_ACPI_DOCK
3959 #ifdef CONFIG_THINKPAD_ACPI_BAY
3961 #endif /* CONFIG_THINKPAD_ACPI_BAY */
3966 IBM_PARAM(brightness);
3970 static int __init thinkpad_acpi_module_init(void)
3974 /* Driver-level probe */
3975 ret = probe_for_thinkpad();
3979 /* Driver initialization */
3980 ibm_thinkpad_ec_found = check_dmi_for_ec();
3981 IBM_ACPIHANDLE_INIT(ecrd);
3982 IBM_ACPIHANDLE_INIT(ecwr);
3984 proc_dir = proc_mkdir(IBM_PROC_DIR, acpi_root_dir);
3986 printk(IBM_ERR "unable to create proc dir " IBM_PROC_DIR);
3987 thinkpad_acpi_module_exit();
3990 proc_dir->owner = THIS_MODULE;
3992 ret = platform_driver_register(&tpacpi_pdriver);
3994 printk(IBM_ERR "unable to register platform driver\n");
3995 thinkpad_acpi_module_exit();
3998 ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver);
4000 printk(IBM_ERR "unable to create sysfs driver attributes\n");
4001 thinkpad_acpi_module_exit();
4006 /* Device initialization */
4007 tpacpi_pdev = platform_device_register_simple(IBM_DRVR_NAME, -1,
4009 if (IS_ERR(tpacpi_pdev)) {
4010 ret = PTR_ERR(tpacpi_pdev);
4012 printk(IBM_ERR "unable to register platform device\n");
4013 thinkpad_acpi_module_exit();
4016 tpacpi_hwmon = hwmon_device_register(&tpacpi_pdev->dev);
4017 if (IS_ERR(tpacpi_hwmon)) {
4018 ret = PTR_ERR(tpacpi_hwmon);
4019 tpacpi_hwmon = NULL;
4020 printk(IBM_ERR "unable to register hwmon device\n");
4021 thinkpad_acpi_module_exit();
4024 for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
4025 ret = ibm_init(&ibms_init[i]);
4026 if (ret >= 0 && *ibms_init[i].param)
4027 ret = ibms_init[i].data->write(ibms_init[i].param);
4029 thinkpad_acpi_module_exit();
4037 static void thinkpad_acpi_module_exit(void)
4039 struct ibm_struct *ibm, *itmp;
4041 list_for_each_entry_safe_reverse(ibm, itmp,
4042 &tpacpi_all_drivers,
4047 dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n");
4050 hwmon_device_unregister(tpacpi_hwmon);
4053 platform_device_unregister(tpacpi_pdev);
4055 tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver);
4056 platform_driver_unregister(&tpacpi_pdriver);
4059 remove_proc_entry(IBM_PROC_DIR, acpi_root_dir);
4061 kfree(ibm_thinkpad_ec_found);
4064 module_init(thinkpad_acpi_module_init);
4065 module_exit(thinkpad_acpi_module_exit);