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 0x010000
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");
96 * DMI matching for module autoloading
98 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
99 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
101 * Only models listed in thinkwiki will be supported, so add yours
102 * if it is not there yet.
104 #define IBM_BIOS_MODULE_ALIAS(__type) \
105 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW")
107 /* Non-ancient thinkpads */
108 MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*");
109 MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*");
111 /* Ancient thinkpad BIOSes have to be identified by
112 * BIOS type or model number, and there are far less
113 * BIOS types than model numbers... */
114 IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]");
115 IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]");
116 IBM_BIOS_MODULE_ALIAS("K[U,X-Z]");
118 #define __unused __attribute__ ((unused))
120 /****************************************************************************
121 ****************************************************************************
123 * ACPI Helpers and device model
125 ****************************************************************************
126 ****************************************************************************/
128 /*************************************************************************
132 static acpi_handle root_handle;
134 #define IBM_HANDLE(object, parent, paths...) \
135 static acpi_handle object##_handle; \
136 static acpi_handle *object##_parent = &parent##_handle; \
137 static char *object##_path; \
138 static char *object##_paths[] = { paths }
140 IBM_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
141 "\\_SB.PCI.ISA.EC", /* 570 */
142 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
143 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
144 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
145 "\\_SB.PCI0.ICH3.EC0", /* R31 */
146 "\\_SB.PCI0.LPC.EC", /* all others */
149 IBM_HANDLE(ecrd, ec, "ECRD"); /* 570 */
150 IBM_HANDLE(ecwr, ec, "ECWR"); /* 570 */
153 /*************************************************************************
157 IBM_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
158 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
159 "\\CMS", /* R40, R40e */
162 IBM_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
163 "^HKEY", /* R30, R31 */
164 "HKEY", /* all others */
168 /*************************************************************************
172 static int acpi_evalf(acpi_handle handle,
173 void *res, char *method, char *fmt, ...)
176 struct acpi_object_list params;
177 union acpi_object in_objs[IBM_MAX_ACPI_ARGS];
178 struct acpi_buffer result, *resultp;
179 union acpi_object out_obj;
187 printk(IBM_ERR "acpi_evalf() called with empty format\n");
200 params.pointer = &in_objs[0];
207 in_objs[params.count].integer.value = va_arg(ap, int);
208 in_objs[params.count++].type = ACPI_TYPE_INTEGER;
210 /* add more types as needed */
212 printk(IBM_ERR "acpi_evalf() called "
213 "with invalid format character '%c'\n", c);
219 if (res_type != 'v') {
220 result.length = sizeof(out_obj);
221 result.pointer = &out_obj;
226 status = acpi_evaluate_object(handle, method, ¶ms, resultp);
231 *(int *)res = out_obj.integer.value;
232 success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER;
235 success = status == AE_OK;
237 /* add more types as needed */
239 printk(IBM_ERR "acpi_evalf() called "
240 "with invalid format character '%c'\n", res_type);
244 if (!success && !quiet)
245 printk(IBM_ERR "acpi_evalf(%s, %s, ...) failed: %d\n",
246 method, fmt0, status);
251 static void __unused acpi_print_int(acpi_handle handle, char *method)
255 if (acpi_evalf(handle, &i, method, "d"))
256 printk(IBM_INFO "%s = 0x%x\n", method, i);
258 printk(IBM_ERR "error calling %s\n", method);
261 static int acpi_ec_read(int i, u8 * p)
266 if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i))
270 if (ec_read(i, p) < 0)
277 static int acpi_ec_write(int i, u8 v)
280 if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v))
283 if (ec_write(i, v) < 0)
290 static int _sta(acpi_handle handle)
294 if (!handle || !acpi_evalf(handle, &status, "_STA", "d"))
300 static int issue_thinkpad_cmos_command(int cmos_cmd)
305 if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd))
311 /*************************************************************************
315 static void drv_acpi_handle_init(char *name,
316 acpi_handle *handle, acpi_handle parent,
317 char **paths, int num_paths, char **path)
322 vdbg_printk(TPACPI_DBG_INIT, "trying to locate ACPI handle for %s\n",
325 for (i = 0; i < num_paths; i++) {
326 status = acpi_get_handle(parent, paths[i], handle);
327 if (ACPI_SUCCESS(status)) {
329 dbg_printk(TPACPI_DBG_INIT,
330 "Found ACPI handle %s for %s\n",
336 vdbg_printk(TPACPI_DBG_INIT, "ACPI handle for %s not found\n",
341 static void dispatch_acpi_notify(acpi_handle handle, u32 event, void *data)
343 struct ibm_struct *ibm = data;
345 if (!ibm || !ibm->acpi || !ibm->acpi->notify)
348 ibm->acpi->notify(ibm, event);
351 static int __init setup_acpi_notify(struct ibm_struct *ibm)
358 if (!*ibm->acpi->handle)
361 vdbg_printk(TPACPI_DBG_INIT,
362 "setting up ACPI notify for %s\n", ibm->name);
364 rc = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device);
366 printk(IBM_ERR "acpi_bus_get_device(%s) failed: %d\n",
371 acpi_driver_data(ibm->acpi->device) = ibm;
372 sprintf(acpi_device_class(ibm->acpi->device), "%s/%s",
373 IBM_ACPI_EVENT_PREFIX,
376 status = acpi_install_notify_handler(*ibm->acpi->handle,
377 ibm->acpi->type, dispatch_acpi_notify, ibm);
378 if (ACPI_FAILURE(status)) {
379 if (status == AE_ALREADY_EXISTS) {
380 printk(IBM_NOTICE "another device driver is already handling %s events\n",
383 printk(IBM_ERR "acpi_install_notify_handler(%s) failed: %d\n",
388 ibm->flags.acpi_notify_installed = 1;
392 static int __init tpacpi_device_add(struct acpi_device *device)
397 static int __init register_tpacpi_subdriver(struct ibm_struct *ibm)
401 dbg_printk(TPACPI_DBG_INIT,
402 "registering %s as an ACPI driver\n", ibm->name);
406 ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL);
407 if (!ibm->acpi->driver) {
408 printk(IBM_ERR "kzalloc(ibm->driver) failed\n");
412 sprintf(ibm->acpi->driver->name, "%s_%s", IBM_NAME, ibm->name);
413 ibm->acpi->driver->ids = ibm->acpi->hid;
414 ibm->acpi->driver->ops.add = &tpacpi_device_add;
416 rc = acpi_bus_register_driver(ibm->acpi->driver);
418 printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n",
420 kfree(ibm->acpi->driver);
421 ibm->acpi->driver = NULL;
423 ibm->flags.acpi_driver_registered = 1;
429 /****************************************************************************
430 ****************************************************************************
434 ****************************************************************************
435 ****************************************************************************/
437 static int dispatch_procfs_read(char *page, char **start, off_t off,
438 int count, int *eof, void *data)
440 struct ibm_struct *ibm = data;
443 if (!ibm || !ibm->read)
446 len = ibm->read(page);
450 if (len <= off + count)
462 static int dispatch_procfs_write(struct file *file,
463 const char __user * userbuf,
464 unsigned long count, void *data)
466 struct ibm_struct *ibm = data;
470 if (!ibm || !ibm->write)
473 kernbuf = kmalloc(count + 2, GFP_KERNEL);
477 if (copy_from_user(kernbuf, userbuf, count)) {
483 strcat(kernbuf, ",");
484 ret = ibm->write(kernbuf);
493 static char *next_cmd(char **cmds)
498 while ((end = strchr(start, ',')) && end == start)
510 /****************************************************************************
511 ****************************************************************************
513 * Device model: input, hwmon and platform
515 ****************************************************************************
516 ****************************************************************************/
518 static struct platform_device *tpacpi_pdev;
519 static struct class_device *tpacpi_hwmon;
520 static struct input_dev *tpacpi_inputdev;
523 static int tpacpi_resume_handler(struct platform_device *pdev)
525 struct ibm_struct *ibm, *itmp;
527 list_for_each_entry_safe(ibm, itmp,
537 static struct platform_driver tpacpi_pdriver = {
539 .name = IBM_DRVR_NAME,
540 .owner = THIS_MODULE,
542 .resume = tpacpi_resume_handler,
546 /*************************************************************************
547 * thinkpad-acpi driver attributes
550 /* interface_version --------------------------------------------------- */
551 static ssize_t tpacpi_driver_interface_version_show(
552 struct device_driver *drv,
555 return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION);
558 static DRIVER_ATTR(interface_version, S_IRUGO,
559 tpacpi_driver_interface_version_show, NULL);
561 /* debug_level --------------------------------------------------------- */
562 static ssize_t tpacpi_driver_debug_show(struct device_driver *drv,
565 return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level);
568 static ssize_t tpacpi_driver_debug_store(struct device_driver *drv,
569 const char *buf, size_t count)
573 if (parse_strtoul(buf, 0xffff, &t))
581 static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
582 tpacpi_driver_debug_show, tpacpi_driver_debug_store);
584 /* version ------------------------------------------------------------- */
585 static ssize_t tpacpi_driver_version_show(struct device_driver *drv,
588 return snprintf(buf, PAGE_SIZE, "%s v%s\n", IBM_DESC, IBM_VERSION);
591 static DRIVER_ATTR(version, S_IRUGO,
592 tpacpi_driver_version_show, NULL);
594 /* --------------------------------------------------------------------- */
596 static struct driver_attribute* tpacpi_driver_attributes[] = {
597 &driver_attr_debug_level, &driver_attr_version,
598 &driver_attr_interface_version,
601 static int __init tpacpi_create_driver_attributes(struct device_driver *drv)
607 while (!res && i < ARRAY_SIZE(tpacpi_driver_attributes)) {
608 res = driver_create_file(drv, tpacpi_driver_attributes[i]);
615 static void tpacpi_remove_driver_attributes(struct device_driver *drv)
619 for(i = 0; i < ARRAY_SIZE(tpacpi_driver_attributes); i++)
620 driver_remove_file(drv, tpacpi_driver_attributes[i]);
623 /*************************************************************************
624 * sysfs support helpers
627 struct attribute_set_obj {
628 struct attribute_set s;
630 } __attribute__((packed));
632 static struct attribute_set *create_attr_set(unsigned int max_members,
635 struct attribute_set_obj *sobj;
637 if (max_members == 0)
640 /* Allocates space for implicit NULL at the end too */
641 sobj = kzalloc(sizeof(struct attribute_set_obj) +
642 max_members * sizeof(struct attribute *),
646 sobj->s.max_members = max_members;
647 sobj->s.group.attrs = &sobj->a;
648 sobj->s.group.name = name;
653 /* not multi-threaded safe, use it in a single thread per set */
654 static int add_to_attr_set(struct attribute_set* s, struct attribute *attr)
659 if (s->members >= s->max_members)
662 s->group.attrs[s->members] = attr;
668 static int add_many_to_attr_set(struct attribute_set* s,
669 struct attribute **attr,
674 for (i = 0; i < count; i++) {
675 res = add_to_attr_set(s, attr[i]);
683 static void delete_attr_set(struct attribute_set* s, struct kobject *kobj)
685 sysfs_remove_group(kobj, &s->group);
689 static int parse_strtoul(const char *buf,
690 unsigned long max, unsigned long *value)
694 *value = simple_strtoul(buf, &endp, 0);
695 while (*endp && isspace(*endp))
697 if (*endp || *value > max)
703 /****************************************************************************
704 ****************************************************************************
708 ****************************************************************************
709 ****************************************************************************/
711 /*************************************************************************
712 * thinkpad-acpi init subdriver
715 static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm)
717 printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION);
718 printk(IBM_INFO "%s\n", IBM_URL);
720 printk(IBM_INFO "ThinkPad BIOS %s, EC %s\n",
721 (thinkpad_id.bios_version_str) ?
722 thinkpad_id.bios_version_str : "unknown",
723 (thinkpad_id.ec_version_str) ?
724 thinkpad_id.ec_version_str : "unknown");
726 if (thinkpad_id.vendor && thinkpad_id.model_str)
727 printk(IBM_INFO "%s %s\n",
728 (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ?
729 "IBM" : ((thinkpad_id.vendor ==
730 PCI_VENDOR_ID_LENOVO) ?
731 "Lenovo" : "Unknown vendor"),
732 thinkpad_id.model_str);
737 static int thinkpad_acpi_driver_read(char *p)
741 len += sprintf(p + len, "driver:\t\t%s\n", IBM_DESC);
742 len += sprintf(p + len, "version:\t%s\n", IBM_VERSION);
747 static struct ibm_struct thinkpad_acpi_driver_data = {
749 .read = thinkpad_acpi_driver_read,
752 /*************************************************************************
756 static int hotkey_orig_status;
757 static u32 hotkey_orig_mask;
758 static u32 hotkey_all_mask;
759 static u32 hotkey_reserved_mask;
761 static u16 hotkey_keycode_map[] = {
762 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
763 KEY_FN_F1, KEY_FN_F2, KEY_FN_F3, KEY_SLEEP,
764 KEY_FN_F5, KEY_FN_F6, KEY_FN_F7, KEY_FN_F8,
765 KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND,
766 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
767 KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */
768 KEY_UNKNOWN, /* 0x0D: FN+INSERT */
769 KEY_UNKNOWN, /* 0x0E: FN+DELETE */
770 KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */
771 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
772 KEY_RESERVED, /* 0x10: FN+END (brightness down) */
773 KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */
774 KEY_UNKNOWN, /* 0x12: FN+PGDOWN */
775 KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */
776 KEY_RESERVED, /* 0x14: VOLUME UP */
777 KEY_RESERVED, /* 0x15: VOLUME DOWN */
778 KEY_RESERVED, /* 0x16: MUTE */
779 KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */
780 /* (assignments unknown, please report if found) */
781 KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
782 KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
785 static struct attribute_set *hotkey_dev_attributes;
787 static int hotkey_get_wlsw(int *status)
789 if (!acpi_evalf(hkey_handle, status, "WLSW", "d"))
794 /* sysfs hotkey enable ------------------------------------------------- */
795 static ssize_t hotkey_enable_show(struct device *dev,
796 struct device_attribute *attr,
802 res = hotkey_get(&status, &mask);
806 return snprintf(buf, PAGE_SIZE, "%d\n", status);
809 static ssize_t hotkey_enable_store(struct device *dev,
810 struct device_attribute *attr,
811 const char *buf, size_t count)
817 if (parse_strtoul(buf, 1, &t))
820 res = hotkey_get(&status, &mask);
822 res = hotkey_set(t, mask);
824 return (res) ? res : count;
827 static struct device_attribute dev_attr_hotkey_enable =
828 __ATTR(hotkey_enable, S_IWUSR | S_IRUGO,
829 hotkey_enable_show, hotkey_enable_store);
831 /* sysfs hotkey mask --------------------------------------------------- */
832 static ssize_t hotkey_mask_show(struct device *dev,
833 struct device_attribute *attr,
839 res = hotkey_get(&status, &mask);
843 return snprintf(buf, PAGE_SIZE, "0x%08x\n", mask);
846 static ssize_t hotkey_mask_store(struct device *dev,
847 struct device_attribute *attr,
848 const char *buf, size_t count)
854 if (parse_strtoul(buf, 0xffffffffUL, &t))
857 res = hotkey_get(&status, &mask);
859 hotkey_set(status, t);
861 return (res) ? res : count;
864 static struct device_attribute dev_attr_hotkey_mask =
865 __ATTR(hotkey_mask, S_IWUSR | S_IRUGO,
866 hotkey_mask_show, hotkey_mask_store);
868 /* sysfs hotkey bios_enabled ------------------------------------------- */
869 static ssize_t hotkey_bios_enabled_show(struct device *dev,
870 struct device_attribute *attr,
873 return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_orig_status);
876 static struct device_attribute dev_attr_hotkey_bios_enabled =
877 __ATTR(hotkey_bios_enabled, S_IRUGO, hotkey_bios_enabled_show, NULL);
879 /* sysfs hotkey bios_mask ---------------------------------------------- */
880 static ssize_t hotkey_bios_mask_show(struct device *dev,
881 struct device_attribute *attr,
884 return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_orig_mask);
887 static struct device_attribute dev_attr_hotkey_bios_mask =
888 __ATTR(hotkey_bios_mask, S_IRUGO, hotkey_bios_mask_show, NULL);
890 /* sysfs hotkey all_mask ----------------------------------------------- */
891 static ssize_t hotkey_all_mask_show(struct device *dev,
892 struct device_attribute *attr,
895 return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_all_mask);
898 static struct device_attribute dev_attr_hotkey_all_mask =
899 __ATTR(hotkey_all_mask, S_IRUGO, hotkey_all_mask_show, NULL);
901 /* sysfs hotkey recommended_mask --------------------------------------- */
902 static ssize_t hotkey_recommended_mask_show(struct device *dev,
903 struct device_attribute *attr,
906 return snprintf(buf, PAGE_SIZE, "0x%08x\n",
907 hotkey_all_mask & ~hotkey_reserved_mask);
910 static struct device_attribute dev_attr_hotkey_recommended_mask =
911 __ATTR(hotkey_recommended_mask, S_IRUGO,
912 hotkey_recommended_mask_show, NULL);
914 /* sysfs hotkey radio_sw ----------------------------------------------- */
915 static ssize_t hotkey_radio_sw_show(struct device *dev,
916 struct device_attribute *attr,
920 res = hotkey_get_wlsw(&s);
924 return snprintf(buf, PAGE_SIZE, "%d\n", !!s);
927 static struct device_attribute dev_attr_hotkey_radio_sw =
928 __ATTR(hotkey_radio_sw, S_IRUGO, hotkey_radio_sw_show, NULL);
930 /* --------------------------------------------------------------------- */
932 static struct attribute *hotkey_mask_attributes[] = {
933 &dev_attr_hotkey_mask.attr,
934 &dev_attr_hotkey_bios_enabled.attr,
935 &dev_attr_hotkey_bios_mask.attr,
936 &dev_attr_hotkey_all_mask.attr,
937 &dev_attr_hotkey_recommended_mask.attr,
940 static int __init hotkey_init(struct ibm_init_struct *iibm)
945 vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n");
947 BUG_ON(!tpacpi_inputdev);
949 IBM_ACPIHANDLE_INIT(hkey);
950 mutex_init(&hotkey_mutex);
952 /* hotkey not supported on 570 */
953 tp_features.hotkey = hkey_handle != NULL;
955 vdbg_printk(TPACPI_DBG_INIT, "hotkeys are %s\n",
956 str_supported(tp_features.hotkey));
958 if (tp_features.hotkey) {
959 hotkey_dev_attributes = create_attr_set(7, NULL);
960 if (!hotkey_dev_attributes)
962 res = add_to_attr_set(hotkey_dev_attributes,
963 &dev_attr_hotkey_enable.attr);
967 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
968 A30, R30, R31, T20-22, X20-21, X22-24 */
969 tp_features.hotkey_mask =
970 acpi_evalf(hkey_handle, NULL, "DHKN", "qv");
972 vdbg_printk(TPACPI_DBG_INIT, "hotkey masks are %s\n",
973 str_supported(tp_features.hotkey_mask));
975 if (tp_features.hotkey_mask) {
976 /* MHKA available in A31, R40, R40e, T4x, X31, and later */
977 if (!acpi_evalf(hkey_handle, &hotkey_all_mask,
979 hotkey_all_mask = 0x080cU; /* FN+F12, FN+F4, FN+F3 */
982 res = hotkey_get(&hotkey_orig_status, &hotkey_orig_mask);
983 if (!res && tp_features.hotkey_mask) {
984 res = add_many_to_attr_set(hotkey_dev_attributes,
985 hotkey_mask_attributes,
986 ARRAY_SIZE(hotkey_mask_attributes));
989 /* Not all thinkpads have a hardware radio switch */
990 if (!res && acpi_evalf(hkey_handle, &status, "WLSW", "qd")) {
991 tp_features.hotkey_wlsw = 1;
993 "radio switch found; radios are %s\n",
995 res = add_to_attr_set(hotkey_dev_attributes,
996 &dev_attr_hotkey_radio_sw.attr);
1000 res = register_attr_set_with_sysfs(
1001 hotkey_dev_attributes,
1002 &tpacpi_pdev->dev.kobj);
1006 #ifndef CONFIG_THINKPAD_ACPI_INPUT_ENABLED
1007 for (i = 0; i < 12; i++)
1008 hotkey_keycode_map[i] = KEY_UNKNOWN;
1009 #endif /* ! CONFIG_THINKPAD_ACPI_INPUT_ENABLED */
1011 set_bit(EV_KEY, tpacpi_inputdev->evbit);
1012 set_bit(EV_MSC, tpacpi_inputdev->evbit);
1013 set_bit(MSC_SCAN, tpacpi_inputdev->mscbit);
1014 tpacpi_inputdev->keycodesize = sizeof(hotkey_keycode_map[0]);
1015 tpacpi_inputdev->keycodemax = ARRAY_SIZE(hotkey_keycode_map);
1016 tpacpi_inputdev->keycode = &hotkey_keycode_map;
1017 for (i = 0; i < ARRAY_SIZE(hotkey_keycode_map); i++) {
1018 if (hotkey_keycode_map[i] != KEY_RESERVED) {
1019 set_bit(hotkey_keycode_map[i],
1020 tpacpi_inputdev->keybit);
1022 if (i < sizeof(hotkey_reserved_mask)*8)
1023 hotkey_reserved_mask |= 1 << i;
1027 if (tp_features.hotkey_wlsw) {
1028 set_bit(EV_SW, tpacpi_inputdev->evbit);
1029 set_bit(SW_RADIO, tpacpi_inputdev->swbit);
1032 #ifdef CONFIG_THINKPAD_ACPI_INPUT_ENABLED
1033 dbg_printk(TPACPI_DBG_INIT,
1034 "enabling hot key handling\n");
1035 res = hotkey_set(1, (hotkey_all_mask & ~hotkey_reserved_mask)
1036 | hotkey_orig_mask);
1039 #endif /* CONFIG_THINKPAD_ACPI_INPUT_ENABLED */
1042 return (tp_features.hotkey)? 0 : 1;
1045 static void hotkey_exit(void)
1049 if (tp_features.hotkey) {
1050 dbg_printk(TPACPI_DBG_EXIT, "restoring original hotkey mask\n");
1051 res = hotkey_set(hotkey_orig_status, hotkey_orig_mask);
1053 printk(IBM_ERR "failed to restore hotkey to BIOS defaults\n");
1056 if (hotkey_dev_attributes) {
1057 delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj);
1058 hotkey_dev_attributes = NULL;
1062 static void tpacpi_input_send_key(unsigned int scancode,
1063 unsigned int keycode)
1065 if (keycode != KEY_RESERVED) {
1066 input_report_key(tpacpi_inputdev, keycode, 1);
1067 if (keycode == KEY_UNKNOWN)
1068 input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN,
1070 input_sync(tpacpi_inputdev);
1072 input_report_key(tpacpi_inputdev, keycode, 0);
1073 if (keycode == KEY_UNKNOWN)
1074 input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN,
1076 input_sync(tpacpi_inputdev);
1080 static void tpacpi_input_send_radiosw(void)
1084 if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&wlsw))
1085 input_report_switch(tpacpi_inputdev,
1089 static void hotkey_notify(struct ibm_struct *ibm, u32 event)
1092 unsigned int keycode, scancode;
1095 if (event == 0x80 && acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) {
1096 if (tpacpi_inputdev->users > 0) {
1097 switch (hkey >> 12) {
1099 /* 0x1000-0x1FFF: key presses */
1100 scancode = hkey & 0xfff;
1101 if (scancode > 0 && scancode < 0x21) {
1103 keycode = hotkey_keycode_map[scancode];
1104 tpacpi_input_send_key(scancode, keycode);
1105 sendacpi = (keycode == KEY_RESERVED
1106 || keycode == KEY_UNKNOWN);
1109 "hotkey 0x%04x out of range for keyboard map\n",
1114 /* 0x5000-0x5FFF: LID */
1115 /* we don't handle it through this path, just
1116 * eat up known LID events */
1117 if (hkey != 0x5001 && hkey != 0x5002) {
1119 "unknown LID-related hotkey event: 0x%04x\n",
1124 /* 0x7000-0x7FFF: misc */
1125 if (tp_features.hotkey_wlsw && hkey == 0x7000) {
1126 tpacpi_input_send_radiosw();
1130 /* fallthrough to default */
1132 /* case 2: dock-related */
1133 /* 0x2305 - T43 waking up due to bay lever eject while aslept */
1134 /* case 3: ultra-bay related. maybe bay in dock? */
1135 /* 0x3003 - T43 after wake up by bay lever eject (0x2305) */
1136 printk(IBM_NOTICE "unhandled hotkey event 0x%04x\n", hkey);
1141 acpi_bus_generate_event(ibm->acpi->device, event, hkey);
1143 printk(IBM_ERR "unknown hotkey notification event %d\n", event);
1144 acpi_bus_generate_event(ibm->acpi->device, event, 0);
1148 static void hotkey_resume(void)
1150 tpacpi_input_send_radiosw();
1154 * Call with hotkey_mutex held
1156 static int hotkey_get(int *status, u32 *mask)
1158 if (!acpi_evalf(hkey_handle, status, "DHKC", "d"))
1161 if (tp_features.hotkey_mask)
1162 if (!acpi_evalf(hkey_handle, mask, "DHKN", "d"))
1169 * Call with hotkey_mutex held
1171 static int hotkey_set(int status, u32 mask)
1175 if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status))
1178 if (tp_features.hotkey_mask)
1179 for (i = 0; i < 32; i++) {
1180 int bit = ((1 << i) & mask) != 0;
1181 if (!acpi_evalf(hkey_handle,
1182 NULL, "MHKM", "vdd", i + 1, bit))
1189 /* procfs -------------------------------------------------------------- */
1190 static int hotkey_read(char *p)
1196 if (!tp_features.hotkey) {
1197 len += sprintf(p + len, "status:\t\tnot supported\n");
1201 res = mutex_lock_interruptible(&hotkey_mutex);
1204 res = hotkey_get(&status, &mask);
1205 mutex_unlock(&hotkey_mutex);
1209 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0));
1210 if (tp_features.hotkey_mask) {
1211 len += sprintf(p + len, "mask:\t\t0x%08x\n", mask);
1212 len += sprintf(p + len,
1213 "commands:\tenable, disable, reset, <mask>\n");
1215 len += sprintf(p + len, "mask:\t\tnot supported\n");
1216 len += sprintf(p + len, "commands:\tenable, disable, reset\n");
1222 static int hotkey_write(char *buf)
1229 if (!tp_features.hotkey)
1232 res = mutex_lock_interruptible(&hotkey_mutex);
1236 res = hotkey_get(&status, &mask);
1241 while ((cmd = next_cmd(&buf))) {
1242 if (strlencmp(cmd, "enable") == 0) {
1244 } else if (strlencmp(cmd, "disable") == 0) {
1246 } else if (strlencmp(cmd, "reset") == 0) {
1247 status = hotkey_orig_status;
1248 mask = hotkey_orig_mask;
1249 } else if (sscanf(cmd, "0x%x", &mask) == 1) {
1251 } else if (sscanf(cmd, "%x", &mask) == 1) {
1261 res = hotkey_set(status, mask);
1264 mutex_unlock(&hotkey_mutex);
1268 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = {
1269 .hid = IBM_HKEY_HID,
1270 .notify = hotkey_notify,
1271 .handle = &hkey_handle,
1272 .type = ACPI_DEVICE_NOTIFY,
1275 static struct ibm_struct hotkey_driver_data = {
1277 .read = hotkey_read,
1278 .write = hotkey_write,
1279 .exit = hotkey_exit,
1280 .resume = hotkey_resume,
1281 .acpi = &ibm_hotkey_acpidriver,
1284 /*************************************************************************
1285 * Bluetooth subdriver
1288 /* sysfs bluetooth enable ---------------------------------------------- */
1289 static ssize_t bluetooth_enable_show(struct device *dev,
1290 struct device_attribute *attr,
1295 status = bluetooth_get_radiosw();
1299 return snprintf(buf, PAGE_SIZE, "%d\n", status ? 1 : 0);
1302 static ssize_t bluetooth_enable_store(struct device *dev,
1303 struct device_attribute *attr,
1304 const char *buf, size_t count)
1309 if (parse_strtoul(buf, 1, &t))
1312 res = bluetooth_set_radiosw(t);
1314 return (res) ? res : count;
1317 static struct device_attribute dev_attr_bluetooth_enable =
1318 __ATTR(bluetooth_enable, S_IWUSR | S_IRUGO,
1319 bluetooth_enable_show, bluetooth_enable_store);
1321 /* --------------------------------------------------------------------- */
1323 static struct attribute *bluetooth_attributes[] = {
1324 &dev_attr_bluetooth_enable.attr,
1328 static const struct attribute_group bluetooth_attr_group = {
1329 .attrs = bluetooth_attributes,
1332 static int __init bluetooth_init(struct ibm_init_struct *iibm)
1337 vdbg_printk(TPACPI_DBG_INIT, "initializing bluetooth subdriver\n");
1339 IBM_ACPIHANDLE_INIT(hkey);
1341 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1342 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
1343 tp_features.bluetooth = hkey_handle &&
1344 acpi_evalf(hkey_handle, &status, "GBDC", "qd");
1346 vdbg_printk(TPACPI_DBG_INIT, "bluetooth is %s, status 0x%02x\n",
1347 str_supported(tp_features.bluetooth),
1350 if (tp_features.bluetooth) {
1351 if (!(status & TP_ACPI_BLUETOOTH_HWPRESENT)) {
1352 /* no bluetooth hardware present in system */
1353 tp_features.bluetooth = 0;
1354 dbg_printk(TPACPI_DBG_INIT,
1355 "bluetooth hardware not installed\n");
1357 res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
1358 &bluetooth_attr_group);
1364 return (tp_features.bluetooth)? 0 : 1;
1367 static void bluetooth_exit(void)
1369 sysfs_remove_group(&tpacpi_pdev->dev.kobj,
1370 &bluetooth_attr_group);
1373 static int bluetooth_get_radiosw(void)
1377 if (!tp_features.bluetooth)
1380 if (!acpi_evalf(hkey_handle, &status, "GBDC", "d"))
1383 return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0);
1386 static int bluetooth_set_radiosw(int radio_on)
1390 if (!tp_features.bluetooth)
1393 if (!acpi_evalf(hkey_handle, &status, "GBDC", "d"))
1396 status |= TP_ACPI_BLUETOOTH_RADIOSSW;
1398 status &= ~TP_ACPI_BLUETOOTH_RADIOSSW;
1399 if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status))
1405 /* procfs -------------------------------------------------------------- */
1406 static int bluetooth_read(char *p)
1409 int status = bluetooth_get_radiosw();
1411 if (!tp_features.bluetooth)
1412 len += sprintf(p + len, "status:\t\tnot supported\n");
1414 len += sprintf(p + len, "status:\t\t%s\n",
1415 (status)? "enabled" : "disabled");
1416 len += sprintf(p + len, "commands:\tenable, disable\n");
1422 static int bluetooth_write(char *buf)
1426 if (!tp_features.bluetooth)
1429 while ((cmd = next_cmd(&buf))) {
1430 if (strlencmp(cmd, "enable") == 0) {
1431 bluetooth_set_radiosw(1);
1432 } else if (strlencmp(cmd, "disable") == 0) {
1433 bluetooth_set_radiosw(0);
1441 static struct ibm_struct bluetooth_driver_data = {
1442 .name = "bluetooth",
1443 .read = bluetooth_read,
1444 .write = bluetooth_write,
1445 .exit = bluetooth_exit,
1448 /*************************************************************************
1452 /* sysfs wan enable ---------------------------------------------------- */
1453 static ssize_t wan_enable_show(struct device *dev,
1454 struct device_attribute *attr,
1459 status = wan_get_radiosw();
1463 return snprintf(buf, PAGE_SIZE, "%d\n", status ? 1 : 0);
1466 static ssize_t wan_enable_store(struct device *dev,
1467 struct device_attribute *attr,
1468 const char *buf, size_t count)
1473 if (parse_strtoul(buf, 1, &t))
1476 res = wan_set_radiosw(t);
1478 return (res) ? res : count;
1481 static struct device_attribute dev_attr_wan_enable =
1482 __ATTR(wwan_enable, S_IWUSR | S_IRUGO,
1483 wan_enable_show, wan_enable_store);
1485 /* --------------------------------------------------------------------- */
1487 static struct attribute *wan_attributes[] = {
1488 &dev_attr_wan_enable.attr,
1492 static const struct attribute_group wan_attr_group = {
1493 .attrs = wan_attributes,
1496 static int __init wan_init(struct ibm_init_struct *iibm)
1501 vdbg_printk(TPACPI_DBG_INIT, "initializing wan subdriver\n");
1503 IBM_ACPIHANDLE_INIT(hkey);
1505 tp_features.wan = hkey_handle &&
1506 acpi_evalf(hkey_handle, &status, "GWAN", "qd");
1508 vdbg_printk(TPACPI_DBG_INIT, "wan is %s, status 0x%02x\n",
1509 str_supported(tp_features.wan),
1512 if (tp_features.wan) {
1513 if (!(status & TP_ACPI_WANCARD_HWPRESENT)) {
1514 /* no wan hardware present in system */
1515 tp_features.wan = 0;
1516 dbg_printk(TPACPI_DBG_INIT,
1517 "wan hardware not installed\n");
1519 res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
1526 return (tp_features.wan)? 0 : 1;
1529 static void wan_exit(void)
1531 sysfs_remove_group(&tpacpi_pdev->dev.kobj,
1535 static int wan_get_radiosw(void)
1539 if (!tp_features.wan)
1542 if (!acpi_evalf(hkey_handle, &status, "GWAN", "d"))
1545 return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0);
1548 static int wan_set_radiosw(int radio_on)
1552 if (!tp_features.wan)
1555 if (!acpi_evalf(hkey_handle, &status, "GWAN", "d"))
1558 status |= TP_ACPI_WANCARD_RADIOSSW;
1560 status &= ~TP_ACPI_WANCARD_RADIOSSW;
1561 if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status))
1567 /* procfs -------------------------------------------------------------- */
1568 static int wan_read(char *p)
1571 int status = wan_get_radiosw();
1573 if (!tp_features.wan)
1574 len += sprintf(p + len, "status:\t\tnot supported\n");
1576 len += sprintf(p + len, "status:\t\t%s\n",
1577 (status)? "enabled" : "disabled");
1578 len += sprintf(p + len, "commands:\tenable, disable\n");
1584 static int wan_write(char *buf)
1588 if (!tp_features.wan)
1591 while ((cmd = next_cmd(&buf))) {
1592 if (strlencmp(cmd, "enable") == 0) {
1594 } else if (strlencmp(cmd, "disable") == 0) {
1603 static struct ibm_struct wan_driver_data = {
1608 .flags.experimental = 1,
1611 /*************************************************************************
1615 static enum video_access_mode video_supported;
1616 static int video_orig_autosw;
1618 IBM_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */
1619 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
1620 "\\_SB.PCI0.VID0", /* 770e */
1621 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
1622 "\\_SB.PCI0.AGP.VID", /* all others */
1625 IBM_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */
1627 static int __init video_init(struct ibm_init_struct *iibm)
1631 vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n");
1633 IBM_ACPIHANDLE_INIT(vid);
1634 IBM_ACPIHANDLE_INIT(vid2);
1636 if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga)
1637 /* G41, assume IVGA doesn't change */
1638 vid_handle = vid2_handle;
1641 /* video switching not supported on R30, R31 */
1642 video_supported = TPACPI_VIDEO_NONE;
1643 else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd"))
1645 video_supported = TPACPI_VIDEO_570;
1646 else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd"))
1647 /* 600e/x, 770e, 770x */
1648 video_supported = TPACPI_VIDEO_770;
1651 video_supported = TPACPI_VIDEO_NEW;
1653 vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n",
1654 str_supported(video_supported != TPACPI_VIDEO_NONE),
1657 return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1;
1660 static void video_exit(void)
1662 dbg_printk(TPACPI_DBG_EXIT,
1663 "restoring original video autoswitch mode\n");
1664 if (video_autosw_set(video_orig_autosw))
1665 printk(IBM_ERR "error while trying to restore original "
1666 "video autoswitch mode\n");
1669 static int video_outputsw_get(void)
1674 switch (video_supported) {
1675 case TPACPI_VIDEO_570:
1676 if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd",
1677 TP_ACPI_VIDEO_570_PHSCMD))
1679 status = i & TP_ACPI_VIDEO_570_PHSMASK;
1681 case TPACPI_VIDEO_770:
1682 if (!acpi_evalf(NULL, &i, "\\VCDL", "d"))
1685 status |= TP_ACPI_VIDEO_S_LCD;
1686 if (!acpi_evalf(NULL, &i, "\\VCDC", "d"))
1689 status |= TP_ACPI_VIDEO_S_CRT;
1691 case TPACPI_VIDEO_NEW:
1692 if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) ||
1693 !acpi_evalf(NULL, &i, "\\VCDC", "d"))
1696 status |= TP_ACPI_VIDEO_S_CRT;
1698 if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) ||
1699 !acpi_evalf(NULL, &i, "\\VCDL", "d"))
1702 status |= TP_ACPI_VIDEO_S_LCD;
1703 if (!acpi_evalf(NULL, &i, "\\VCDD", "d"))
1706 status |= TP_ACPI_VIDEO_S_DVI;
1715 static int video_outputsw_set(int status)
1720 switch (video_supported) {
1721 case TPACPI_VIDEO_570:
1722 res = acpi_evalf(NULL, NULL,
1723 "\\_SB.PHS2", "vdd",
1724 TP_ACPI_VIDEO_570_PHS2CMD,
1725 status | TP_ACPI_VIDEO_570_PHS2SET);
1727 case TPACPI_VIDEO_770:
1728 autosw = video_autosw_get();
1732 res = video_autosw_set(1);
1735 res = acpi_evalf(vid_handle, NULL,
1736 "ASWT", "vdd", status * 0x100, 0);
1737 if (!autosw && video_autosw_set(autosw)) {
1738 printk(IBM_ERR "video auto-switch left enabled due to error\n");
1742 case TPACPI_VIDEO_NEW:
1743 res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) &&
1744 acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1);
1750 return (res)? 0 : -EIO;
1753 static int video_autosw_get(void)
1757 switch (video_supported) {
1758 case TPACPI_VIDEO_570:
1759 if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d"))
1762 case TPACPI_VIDEO_770:
1763 case TPACPI_VIDEO_NEW:
1764 if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d"))
1774 static int video_autosw_set(int enable)
1776 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0))
1781 static int video_outputsw_cycle(void)
1783 int autosw = video_autosw_get();
1789 switch (video_supported) {
1790 case TPACPI_VIDEO_570:
1791 res = video_autosw_set(1);
1794 res = acpi_evalf(ec_handle, NULL, "_Q16", "v");
1796 case TPACPI_VIDEO_770:
1797 case TPACPI_VIDEO_NEW:
1798 res = video_autosw_set(1);
1801 res = acpi_evalf(vid_handle, NULL, "VSWT", "v");
1806 if (!autosw && video_autosw_set(autosw)) {
1807 printk(IBM_ERR "video auto-switch left enabled due to error\n");
1811 return (res)? 0 : -EIO;
1814 static int video_expand_toggle(void)
1816 switch (video_supported) {
1817 case TPACPI_VIDEO_570:
1818 return acpi_evalf(ec_handle, NULL, "_Q17", "v")?
1820 case TPACPI_VIDEO_770:
1821 return acpi_evalf(vid_handle, NULL, "VEXP", "v")?
1823 case TPACPI_VIDEO_NEW:
1824 return acpi_evalf(NULL, NULL, "\\VEXP", "v")?
1832 static int video_read(char *p)
1837 if (video_supported == TPACPI_VIDEO_NONE) {
1838 len += sprintf(p + len, "status:\t\tnot supported\n");
1842 status = video_outputsw_get();
1846 autosw = video_autosw_get();
1850 len += sprintf(p + len, "status:\t\tsupported\n");
1851 len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0));
1852 len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1));
1853 if (video_supported == TPACPI_VIDEO_NEW)
1854 len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3));
1855 len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0));
1856 len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n");
1857 len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n");
1858 if (video_supported == TPACPI_VIDEO_NEW)
1859 len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n");
1860 len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n");
1861 len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n");
1866 static int video_write(char *buf)
1869 int enable, disable, status;
1872 if (video_supported == TPACPI_VIDEO_NONE)
1878 while ((cmd = next_cmd(&buf))) {
1879 if (strlencmp(cmd, "lcd_enable") == 0) {
1880 enable |= TP_ACPI_VIDEO_S_LCD;
1881 } else if (strlencmp(cmd, "lcd_disable") == 0) {
1882 disable |= TP_ACPI_VIDEO_S_LCD;
1883 } else if (strlencmp(cmd, "crt_enable") == 0) {
1884 enable |= TP_ACPI_VIDEO_S_CRT;
1885 } else if (strlencmp(cmd, "crt_disable") == 0) {
1886 disable |= TP_ACPI_VIDEO_S_CRT;
1887 } else if (video_supported == TPACPI_VIDEO_NEW &&
1888 strlencmp(cmd, "dvi_enable") == 0) {
1889 enable |= TP_ACPI_VIDEO_S_DVI;
1890 } else if (video_supported == TPACPI_VIDEO_NEW &&
1891 strlencmp(cmd, "dvi_disable") == 0) {
1892 disable |= TP_ACPI_VIDEO_S_DVI;
1893 } else if (strlencmp(cmd, "auto_enable") == 0) {
1894 res = video_autosw_set(1);
1897 } else if (strlencmp(cmd, "auto_disable") == 0) {
1898 res = video_autosw_set(0);
1901 } else if (strlencmp(cmd, "video_switch") == 0) {
1902 res = video_outputsw_cycle();
1905 } else if (strlencmp(cmd, "expand_toggle") == 0) {
1906 res = video_expand_toggle();
1913 if (enable || disable) {
1914 status = video_outputsw_get();
1917 res = video_outputsw_set((status & ~disable) | enable);
1925 static struct ibm_struct video_driver_data = {
1928 .write = video_write,
1932 /*************************************************************************
1933 * Light (thinklight) subdriver
1936 IBM_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
1937 IBM_HANDLE(ledb, ec, "LEDB"); /* G4x */
1939 static int __init light_init(struct ibm_init_struct *iibm)
1941 vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n");
1943 IBM_ACPIHANDLE_INIT(ledb);
1944 IBM_ACPIHANDLE_INIT(lght);
1945 IBM_ACPIHANDLE_INIT(cmos);
1947 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
1948 tp_features.light = (cmos_handle || lght_handle) && !ledb_handle;
1950 if (tp_features.light)
1951 /* light status not supported on
1952 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
1953 tp_features.light_status =
1954 acpi_evalf(ec_handle, NULL, "KBLT", "qv");
1956 vdbg_printk(TPACPI_DBG_INIT, "light is %s\n",
1957 str_supported(tp_features.light));
1959 return (tp_features.light)? 0 : 1;
1962 static int light_read(char *p)
1967 if (!tp_features.light) {
1968 len += sprintf(p + len, "status:\t\tnot supported\n");
1969 } else if (!tp_features.light_status) {
1970 len += sprintf(p + len, "status:\t\tunknown\n");
1971 len += sprintf(p + len, "commands:\ton, off\n");
1973 if (!acpi_evalf(ec_handle, &status, "KBLT", "d"))
1975 len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0));
1976 len += sprintf(p + len, "commands:\ton, off\n");
1982 static int light_write(char *buf)
1984 int cmos_cmd, lght_cmd;
1988 if (!tp_features.light)
1991 while ((cmd = next_cmd(&buf))) {
1992 if (strlencmp(cmd, "on") == 0) {
1995 } else if (strlencmp(cmd, "off") == 0) {
2001 success = cmos_handle ?
2002 acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd) :
2003 acpi_evalf(lght_handle, NULL, NULL, "vd", lght_cmd);
2011 static struct ibm_struct light_driver_data = {
2014 .write = light_write,
2017 /*************************************************************************
2021 #ifdef CONFIG_THINKPAD_ACPI_DOCK
2023 IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */
2024 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
2025 "\\_SB.PCI0.PCI1.DOCK", /* all others */
2026 "\\_SB.PCI.ISA.SLCE", /* 570 */
2027 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
2029 /* don't list other alternatives as we install a notify handler on the 570 */
2030 IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */
2032 static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = {
2034 .notify = dock_notify,
2035 .handle = &dock_handle,
2036 .type = ACPI_SYSTEM_NOTIFY,
2039 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
2040 * We just use it to get notifications of dock hotplug
2041 * in very old thinkpads */
2042 .hid = PCI_ROOT_HID_STRING,
2043 .notify = dock_notify,
2044 .handle = &pci_handle,
2045 .type = ACPI_SYSTEM_NOTIFY,
2049 static struct ibm_struct dock_driver_data[2] = {
2053 .write = dock_write,
2054 .acpi = &ibm_dock_acpidriver[0],
2058 .acpi = &ibm_dock_acpidriver[1],
2062 #define dock_docked() (_sta(dock_handle) & 1)
2064 static int __init dock_init(struct ibm_init_struct *iibm)
2066 vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver\n");
2068 IBM_ACPIHANDLE_INIT(dock);
2070 vdbg_printk(TPACPI_DBG_INIT, "dock is %s\n",
2071 str_supported(dock_handle != NULL));
2073 return (dock_handle)? 0 : 1;
2076 static int __init dock_init2(struct ibm_init_struct *iibm)
2080 vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver part 2\n");
2082 if (dock_driver_data[0].flags.acpi_driver_registered &&
2083 dock_driver_data[0].flags.acpi_notify_installed) {
2084 IBM_ACPIHANDLE_INIT(pci);
2085 dock2_needed = (pci_handle != NULL);
2086 vdbg_printk(TPACPI_DBG_INIT,
2087 "dock PCI handler for the TP 570 is %s\n",
2088 str_supported(dock2_needed));
2090 vdbg_printk(TPACPI_DBG_INIT,
2091 "dock subdriver part 2 not required\n");
2095 return (dock2_needed)? 0 : 1;
2098 static void dock_notify(struct ibm_struct *ibm, u32 event)
2100 int docked = dock_docked();
2101 int pci = ibm->acpi->hid && strstr(ibm->acpi->hid, PCI_ROOT_HID_STRING);
2103 if (event == 1 && !pci) /* 570 */
2104 acpi_bus_generate_event(ibm->acpi->device, event, 1); /* button */
2105 else if (event == 1 && pci) /* 570 */
2106 acpi_bus_generate_event(ibm->acpi->device, event, 3); /* dock */
2107 else if (event == 3 && docked)
2108 acpi_bus_generate_event(ibm->acpi->device, event, 1); /* button */
2109 else if (event == 3 && !docked)
2110 acpi_bus_generate_event(ibm->acpi->device, event, 2); /* undock */
2111 else if (event == 0 && docked)
2112 acpi_bus_generate_event(ibm->acpi->device, event, 3); /* dock */
2114 printk(IBM_ERR "unknown dock event %d, status %d\n",
2115 event, _sta(dock_handle));
2116 acpi_bus_generate_event(ibm->acpi->device, event, 0); /* unknown */
2120 static int dock_read(char *p)
2123 int docked = dock_docked();
2126 len += sprintf(p + len, "status:\t\tnot supported\n");
2128 len += sprintf(p + len, "status:\t\tundocked\n");
2130 len += sprintf(p + len, "status:\t\tdocked\n");
2131 len += sprintf(p + len, "commands:\tdock, undock\n");
2137 static int dock_write(char *buf)
2144 while ((cmd = next_cmd(&buf))) {
2145 if (strlencmp(cmd, "undock") == 0) {
2146 if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0) ||
2147 !acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1))
2149 } else if (strlencmp(cmd, "dock") == 0) {
2150 if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1))
2159 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
2161 /*************************************************************************
2165 #ifdef CONFIG_THINKPAD_ACPI_BAY
2166 IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
2167 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
2168 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
2169 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
2170 ); /* A21e, R30, R31 */
2171 IBM_HANDLE(bay_ej, bay, "_EJ3", /* 600e/x, A2xm/p, A3x */
2172 "_EJ0", /* all others */
2173 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
2174 IBM_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
2175 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
2177 IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */
2181 static int __init bay_init(struct ibm_init_struct *iibm)
2183 vdbg_printk(TPACPI_DBG_INIT, "initializing bay subdriver\n");
2185 IBM_ACPIHANDLE_INIT(bay);
2187 IBM_ACPIHANDLE_INIT(bay_ej);
2188 IBM_ACPIHANDLE_INIT(bay2);
2190 IBM_ACPIHANDLE_INIT(bay2_ej);
2192 tp_features.bay_status = bay_handle &&
2193 acpi_evalf(bay_handle, NULL, "_STA", "qv");
2194 tp_features.bay_status2 = bay2_handle &&
2195 acpi_evalf(bay2_handle, NULL, "_STA", "qv");
2197 tp_features.bay_eject = bay_handle && bay_ej_handle &&
2198 (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental);
2199 tp_features.bay_eject2 = bay2_handle && bay2_ej_handle &&
2200 (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental);
2202 vdbg_printk(TPACPI_DBG_INIT,
2203 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
2204 str_supported(tp_features.bay_status),
2205 str_supported(tp_features.bay_eject),
2206 str_supported(tp_features.bay_status2),
2207 str_supported(tp_features.bay_eject2));
2209 return (tp_features.bay_status || tp_features.bay_eject ||
2210 tp_features.bay_status2 || tp_features.bay_eject2)? 0 : 1;
2213 static void bay_notify(struct ibm_struct *ibm, u32 event)
2215 acpi_bus_generate_event(ibm->acpi->device, event, 0);
2218 #define bay_occupied(b) (_sta(b##_handle) & 1)
2220 static int bay_read(char *p)
2223 int occupied = bay_occupied(bay);
2224 int occupied2 = bay_occupied(bay2);
2227 len += sprintf(p + len, "status:\t\t%s\n",
2228 tp_features.bay_status ?
2229 (occupied ? "occupied" : "unoccupied") :
2231 if (tp_features.bay_status2)
2232 len += sprintf(p + len, "status2:\t%s\n", occupied2 ?
2233 "occupied" : "unoccupied");
2235 eject = tp_features.bay_eject && occupied;
2236 eject2 = tp_features.bay_eject2 && occupied2;
2238 if (eject && eject2)
2239 len += sprintf(p + len, "commands:\teject, eject2\n");
2241 len += sprintf(p + len, "commands:\teject\n");
2243 len += sprintf(p + len, "commands:\teject2\n");
2248 static int bay_write(char *buf)
2252 if (!tp_features.bay_eject && !tp_features.bay_eject2)
2255 while ((cmd = next_cmd(&buf))) {
2256 if (tp_features.bay_eject && strlencmp(cmd, "eject") == 0) {
2257 if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1))
2259 } else if (tp_features.bay_eject2 &&
2260 strlencmp(cmd, "eject2") == 0) {
2261 if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1))
2270 static struct tp_acpi_drv_struct ibm_bay_acpidriver = {
2271 .notify = bay_notify,
2272 .handle = &bay_handle,
2273 .type = ACPI_SYSTEM_NOTIFY,
2276 static struct ibm_struct bay_driver_data = {
2280 .acpi = &ibm_bay_acpidriver,
2283 #endif /* CONFIG_THINKPAD_ACPI_BAY */
2285 /*************************************************************************
2289 /* sysfs cmos_command -------------------------------------------------- */
2290 static ssize_t cmos_command_store(struct device *dev,
2291 struct device_attribute *attr,
2292 const char *buf, size_t count)
2294 unsigned long cmos_cmd;
2297 if (parse_strtoul(buf, 21, &cmos_cmd))
2300 res = issue_thinkpad_cmos_command(cmos_cmd);
2301 return (res)? res : count;
2304 static struct device_attribute dev_attr_cmos_command =
2305 __ATTR(cmos_command, S_IWUSR, NULL, cmos_command_store);
2307 /* --------------------------------------------------------------------- */
2309 static int __init cmos_init(struct ibm_init_struct *iibm)
2313 vdbg_printk(TPACPI_DBG_INIT,
2314 "initializing cmos commands subdriver\n");
2316 IBM_ACPIHANDLE_INIT(cmos);
2318 vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n",
2319 str_supported(cmos_handle != NULL));
2321 res = device_create_file(&tpacpi_pdev->dev, &dev_attr_cmos_command);
2325 return (cmos_handle)? 0 : 1;
2328 static void cmos_exit(void)
2330 device_remove_file(&tpacpi_pdev->dev, &dev_attr_cmos_command);
2333 static int cmos_read(char *p)
2337 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2338 R30, R31, T20-22, X20-21 */
2340 len += sprintf(p + len, "status:\t\tnot supported\n");
2342 len += sprintf(p + len, "status:\t\tsupported\n");
2343 len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n");
2349 static int cmos_write(char *buf)
2354 while ((cmd = next_cmd(&buf))) {
2355 if (sscanf(cmd, "%u", &cmos_cmd) == 1 &&
2356 cmos_cmd >= 0 && cmos_cmd <= 21) {
2361 res = issue_thinkpad_cmos_command(cmos_cmd);
2369 static struct ibm_struct cmos_driver_data = {
2372 .write = cmos_write,
2376 /*************************************************************************
2380 static enum led_access_mode led_supported;
2382 IBM_HANDLE(led, ec, "SLED", /* 570 */
2383 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2384 "LED", /* all others */
2387 static int __init led_init(struct ibm_init_struct *iibm)
2389 vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n");
2391 IBM_ACPIHANDLE_INIT(led);
2394 /* led not supported on R30, R31 */
2395 led_supported = TPACPI_LED_NONE;
2396 else if (strlencmp(led_path, "SLED") == 0)
2398 led_supported = TPACPI_LED_570;
2399 else if (strlencmp(led_path, "SYSL") == 0)
2400 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2401 led_supported = TPACPI_LED_OLD;
2404 led_supported = TPACPI_LED_NEW;
2406 vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n",
2407 str_supported(led_supported), led_supported);
2409 return (led_supported != TPACPI_LED_NONE)? 0 : 1;
2412 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
2414 static int led_read(char *p)
2418 if (!led_supported) {
2419 len += sprintf(p + len, "status:\t\tnot supported\n");
2422 len += sprintf(p + len, "status:\t\tsupported\n");
2424 if (led_supported == TPACPI_LED_570) {
2427 for (i = 0; i < 8; i++) {
2428 if (!acpi_evalf(ec_handle,
2429 &status, "GLED", "dd", 1 << i))
2431 len += sprintf(p + len, "%d:\t\t%s\n",
2432 i, led_status(status));
2436 len += sprintf(p + len, "commands:\t"
2437 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
2442 /* off, on, blink */
2443 static const int led_sled_arg1[] = { 0, 1, 3 };
2444 static const int led_exp_hlbl[] = { 0, 0, 1 }; /* led# * */
2445 static const int led_exp_hlcl[] = { 0, 1, 1 }; /* led# * */
2446 static const int led_led_arg1[] = { 0, 0x80, 0xc0 };
2448 static int led_write(char *buf)
2456 while ((cmd = next_cmd(&buf))) {
2457 if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 7)
2460 if (strstr(cmd, "off")) {
2462 } else if (strstr(cmd, "on")) {
2464 } else if (strstr(cmd, "blink")) {
2469 if (led_supported == TPACPI_LED_570) {
2472 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
2473 led, led_sled_arg1[ind]))
2475 } else if (led_supported == TPACPI_LED_OLD) {
2476 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
2478 ret = ec_write(TPACPI_LED_EC_HLMS, led);
2481 ec_write(TPACPI_LED_EC_HLBL,
2482 led * led_exp_hlbl[ind]);
2485 ec_write(TPACPI_LED_EC_HLCL,
2486 led * led_exp_hlcl[ind]);
2491 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
2492 led, led_led_arg1[ind]))
2500 static struct ibm_struct led_driver_data = {
2506 /*************************************************************************
2510 IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */
2512 static int __init beep_init(struct ibm_init_struct *iibm)
2514 vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n");
2516 IBM_ACPIHANDLE_INIT(beep);
2518 vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n",
2519 str_supported(beep_handle != NULL));
2521 return (beep_handle)? 0 : 1;
2524 static int beep_read(char *p)
2529 len += sprintf(p + len, "status:\t\tnot supported\n");
2531 len += sprintf(p + len, "status:\t\tsupported\n");
2532 len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n");
2538 static int beep_write(char *buf)
2546 while ((cmd = next_cmd(&buf))) {
2547 if (sscanf(cmd, "%u", &beep_cmd) == 1 &&
2548 beep_cmd >= 0 && beep_cmd <= 17) {
2552 if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", beep_cmd, 0))
2559 static struct ibm_struct beep_driver_data = {
2562 .write = beep_write,
2565 /*************************************************************************
2569 static enum thermal_access_mode thermal_read_mode;
2571 /* sysfs temp##_input -------------------------------------------------- */
2573 static ssize_t thermal_temp_input_show(struct device *dev,
2574 struct device_attribute *attr,
2577 struct sensor_device_attribute *sensor_attr =
2578 to_sensor_dev_attr(attr);
2579 int idx = sensor_attr->index;
2583 res = thermal_get_sensor(idx, &value);
2586 if (value == TP_EC_THERMAL_TMP_NA * 1000)
2589 return snprintf(buf, PAGE_SIZE, "%d\n", value);
2592 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
2593 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB)
2595 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input[] = {
2596 THERMAL_SENSOR_ATTR_TEMP(1, 0),
2597 THERMAL_SENSOR_ATTR_TEMP(2, 1),
2598 THERMAL_SENSOR_ATTR_TEMP(3, 2),
2599 THERMAL_SENSOR_ATTR_TEMP(4, 3),
2600 THERMAL_SENSOR_ATTR_TEMP(5, 4),
2601 THERMAL_SENSOR_ATTR_TEMP(6, 5),
2602 THERMAL_SENSOR_ATTR_TEMP(7, 6),
2603 THERMAL_SENSOR_ATTR_TEMP(8, 7),
2604 THERMAL_SENSOR_ATTR_TEMP(9, 8),
2605 THERMAL_SENSOR_ATTR_TEMP(10, 9),
2606 THERMAL_SENSOR_ATTR_TEMP(11, 10),
2607 THERMAL_SENSOR_ATTR_TEMP(12, 11),
2608 THERMAL_SENSOR_ATTR_TEMP(13, 12),
2609 THERMAL_SENSOR_ATTR_TEMP(14, 13),
2610 THERMAL_SENSOR_ATTR_TEMP(15, 14),
2611 THERMAL_SENSOR_ATTR_TEMP(16, 15),
2614 #define THERMAL_ATTRS(X) \
2615 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
2617 static struct attribute *thermal_temp_input_attr[] = {
2637 static const struct attribute_group thermal_temp_input16_group = {
2638 .attrs = thermal_temp_input_attr
2641 static const struct attribute_group thermal_temp_input8_group = {
2642 .attrs = &thermal_temp_input_attr[8]
2645 #undef THERMAL_SENSOR_ATTR_TEMP
2646 #undef THERMAL_ATTRS
2648 /* --------------------------------------------------------------------- */
2650 static int __init thermal_init(struct ibm_init_struct *iibm)
2657 vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n");
2659 acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv");
2661 if (thinkpad_id.ec_model && experimental) {
2663 * Direct EC access mode: sensors at registers
2664 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
2665 * non-implemented, thermal sensors return 0x80 when
2670 for (i = 0; i < 8; i++) {
2671 if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) {
2677 if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) {
2685 /* This is sheer paranoia, but we handle it anyway */
2688 "ThinkPad ACPI EC access misbehaving, "
2689 "falling back to ACPI TMPx access mode\n");
2690 thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07;
2693 "ThinkPad ACPI EC access misbehaving, "
2694 "disabling thermal sensors access\n");
2695 thermal_read_mode = TPACPI_THERMAL_NONE;
2700 TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8;
2702 } else if (acpi_tmp7) {
2703 if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) {
2704 /* 600e/x, 770e, 770x */
2705 thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT;
2707 /* Standard ACPI TMPx access, max 8 sensors */
2708 thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07;
2711 /* temperatures not supported on 570, G4x, R30, R31, R32 */
2712 thermal_read_mode = TPACPI_THERMAL_NONE;
2715 vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n",
2716 str_supported(thermal_read_mode != TPACPI_THERMAL_NONE),
2719 switch(thermal_read_mode) {
2720 case TPACPI_THERMAL_TPEC_16:
2721 res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
2722 &thermal_temp_input16_group);
2726 case TPACPI_THERMAL_TPEC_8:
2727 case TPACPI_THERMAL_ACPI_TMP07:
2728 case TPACPI_THERMAL_ACPI_UPDT:
2729 res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
2730 &thermal_temp_input8_group);
2734 case TPACPI_THERMAL_NONE:
2742 static void thermal_exit(void)
2744 switch(thermal_read_mode) {
2745 case TPACPI_THERMAL_TPEC_16:
2746 sysfs_remove_group(&tpacpi_pdev->dev.kobj,
2747 &thermal_temp_input16_group);
2749 case TPACPI_THERMAL_TPEC_8:
2750 case TPACPI_THERMAL_ACPI_TMP07:
2751 case TPACPI_THERMAL_ACPI_UPDT:
2752 sysfs_remove_group(&tpacpi_pdev->dev.kobj,
2753 &thermal_temp_input16_group);
2755 case TPACPI_THERMAL_NONE:
2761 /* idx is zero-based */
2762 static int thermal_get_sensor(int idx, s32 *value)
2768 t = TP_EC_THERMAL_TMP0;
2770 switch (thermal_read_mode) {
2771 #if TPACPI_MAX_THERMAL_SENSORS >= 16
2772 case TPACPI_THERMAL_TPEC_16:
2773 if (idx >= 8 && idx <= 15) {
2774 t = TP_EC_THERMAL_TMP8;
2779 case TPACPI_THERMAL_TPEC_8:
2781 if (!acpi_ec_read(t + idx, &tmp))
2783 *value = tmp * 1000;
2788 case TPACPI_THERMAL_ACPI_UPDT:
2790 snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
2791 if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
2793 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
2795 *value = (t - 2732) * 100;
2800 case TPACPI_THERMAL_ACPI_TMP07:
2802 snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
2803 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
2810 case TPACPI_THERMAL_NONE:
2818 static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
2829 if (thermal_read_mode == TPACPI_THERMAL_TPEC_16)
2832 for(i = 0 ; i < n; i++) {
2833 res = thermal_get_sensor(i, &s->temp[i]);
2841 static int thermal_read(char *p)
2845 struct ibm_thermal_sensors_struct t;
2847 n = thermal_get_sensors(&t);
2848 if (unlikely(n < 0))
2851 len += sprintf(p + len, "temperatures:\t");
2854 for (i = 0; i < (n - 1); i++)
2855 len += sprintf(p + len, "%d ", t.temp[i] / 1000);
2856 len += sprintf(p + len, "%d\n", t.temp[i] / 1000);
2858 len += sprintf(p + len, "not supported\n");
2863 static struct ibm_struct thermal_driver_data = {
2865 .read = thermal_read,
2866 .exit = thermal_exit,
2869 /*************************************************************************
2873 static u8 ecdump_regs[256];
2875 static int ecdump_read(char *p)
2881 len += sprintf(p + len, "EC "
2882 " +00 +01 +02 +03 +04 +05 +06 +07"
2883 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
2884 for (i = 0; i < 256; i += 16) {
2885 len += sprintf(p + len, "EC 0x%02x:", i);
2886 for (j = 0; j < 16; j++) {
2887 if (!acpi_ec_read(i + j, &v))
2889 if (v != ecdump_regs[i + j])
2890 len += sprintf(p + len, " *%02x", v);
2892 len += sprintf(p + len, " %02x", v);
2893 ecdump_regs[i + j] = v;
2895 len += sprintf(p + len, "\n");
2900 /* These are way too dangerous to advertise openly... */
2902 len += sprintf(p + len, "commands:\t0x<offset> 0x<value>"
2903 " (<offset> is 00-ff, <value> is 00-ff)\n");
2904 len += sprintf(p + len, "commands:\t0x<offset> <value> "
2905 " (<offset> is 00-ff, <value> is 0-255)\n");
2910 static int ecdump_write(char *buf)
2915 while ((cmd = next_cmd(&buf))) {
2916 if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) {
2918 } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) {
2922 if (i >= 0 && i < 256 && v >= 0 && v < 256) {
2923 if (!acpi_ec_write(i, v))
2932 static struct ibm_struct ecdump_driver_data = {
2934 .read = ecdump_read,
2935 .write = ecdump_write,
2936 .flags.experimental = 1,
2939 /*************************************************************************
2940 * Backlight/brightness subdriver
2943 static struct backlight_device *ibm_backlight_device;
2945 static struct backlight_ops ibm_backlight_data = {
2946 .get_brightness = brightness_get,
2947 .update_status = brightness_update_status,
2950 static int __init brightness_init(struct ibm_init_struct *iibm)
2954 vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n");
2956 if (!brightness_mode) {
2957 if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO)
2958 brightness_mode = 2;
2960 brightness_mode = 3;
2962 dbg_printk(TPACPI_DBG_INIT, "selected brightness_mode=%d\n",
2966 if (brightness_mode > 3)
2969 b = brightness_get(NULL);
2973 ibm_backlight_device = backlight_device_register(
2974 TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL,
2975 &ibm_backlight_data);
2976 if (IS_ERR(ibm_backlight_device)) {
2977 printk(IBM_ERR "Could not register backlight device\n");
2978 return PTR_ERR(ibm_backlight_device);
2980 vdbg_printk(TPACPI_DBG_INIT, "brightness is supported\n");
2982 ibm_backlight_device->props.max_brightness = 7;
2983 ibm_backlight_device->props.brightness = b;
2984 backlight_update_status(ibm_backlight_device);
2989 static void brightness_exit(void)
2991 if (ibm_backlight_device) {
2992 vdbg_printk(TPACPI_DBG_EXIT,
2993 "calling backlight_device_unregister()\n");
2994 backlight_device_unregister(ibm_backlight_device);
2995 ibm_backlight_device = NULL;
2999 static int brightness_update_status(struct backlight_device *bd)
3001 return brightness_set(
3002 (bd->props.fb_blank == FB_BLANK_UNBLANK &&
3003 bd->props.power == FB_BLANK_UNBLANK) ?
3004 bd->props.brightness : 0);
3008 * ThinkPads can read brightness from two places: EC 0x31, or
3009 * CMOS NVRAM byte 0x5E, bits 0-3.
3011 static int brightness_get(struct backlight_device *bd)
3013 u8 lec = 0, lcmos = 0, level = 0;
3015 if (brightness_mode & 1) {
3016 if (!acpi_ec_read(brightness_offset, &lec))
3021 if (brightness_mode & 2) {
3022 lcmos = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS)
3023 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS)
3024 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS;
3028 if (brightness_mode == 3 && lec != lcmos) {
3030 "CMOS NVRAM (%u) and EC (%u) do not agree "
3031 "on display brightness level\n",
3032 (unsigned int) lcmos,
3033 (unsigned int) lec);
3040 static int brightness_set(int value)
3042 int cmos_cmd, inc, i;
3043 int current_value = brightness_get(NULL);
3048 cmos_cmd = value > current_value ?
3049 TP_CMOS_BRIGHTNESS_UP :
3050 TP_CMOS_BRIGHTNESS_DOWN;
3051 inc = value > current_value ? 1 : -1;
3053 for (i = current_value; i != value; i += inc) {
3054 if ((brightness_mode & 2) &&
3055 issue_thinkpad_cmos_command(cmos_cmd))
3057 if ((brightness_mode & 1) &&
3058 !acpi_ec_write(brightness_offset, i + inc))
3065 static int brightness_read(char *p)
3070 if ((level = brightness_get(NULL)) < 0) {
3071 len += sprintf(p + len, "level:\t\tunreadable\n");
3073 len += sprintf(p + len, "level:\t\t%d\n", level & 0x7);
3074 len += sprintf(p + len, "commands:\tup, down\n");
3075 len += sprintf(p + len, "commands:\tlevel <level>"
3076 " (<level> is 0-7)\n");
3082 static int brightness_write(char *buf)
3088 while ((cmd = next_cmd(&buf))) {
3089 if ((level = brightness_get(NULL)) < 0)
3093 if (strlencmp(cmd, "up") == 0) {
3094 new_level = level == 7 ? 7 : level + 1;
3095 } else if (strlencmp(cmd, "down") == 0) {
3096 new_level = level == 0 ? 0 : level - 1;
3097 } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
3098 new_level >= 0 && new_level <= 7) {
3103 brightness_set(new_level);
3109 static struct ibm_struct brightness_driver_data = {
3110 .name = "brightness",
3111 .read = brightness_read,
3112 .write = brightness_write,
3113 .exit = brightness_exit,
3116 /*************************************************************************
3120 static int volume_read(char *p)
3125 if (!acpi_ec_read(volume_offset, &level)) {
3126 len += sprintf(p + len, "level:\t\tunreadable\n");
3128 len += sprintf(p + len, "level:\t\t%d\n", level & 0xf);
3129 len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6));
3130 len += sprintf(p + len, "commands:\tup, down, mute\n");
3131 len += sprintf(p + len, "commands:\tlevel <level>"
3132 " (<level> is 0-15)\n");
3138 static int volume_write(char *buf)
3140 int cmos_cmd, inc, i;
3142 int new_level, new_mute;
3145 while ((cmd = next_cmd(&buf))) {
3146 if (!acpi_ec_read(volume_offset, &level))
3148 new_mute = mute = level & 0x40;
3149 new_level = level = level & 0xf;
3151 if (strlencmp(cmd, "up") == 0) {
3155 new_level = level == 15 ? 15 : level + 1;
3156 } else if (strlencmp(cmd, "down") == 0) {
3160 new_level = level == 0 ? 0 : level - 1;
3161 } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
3162 new_level >= 0 && new_level <= 15) {
3164 } else if (strlencmp(cmd, "mute") == 0) {
3169 if (new_level != level) { /* mute doesn't change */
3170 cmos_cmd = new_level > level ? TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN;
3171 inc = new_level > level ? 1 : -1;
3173 if (mute && (issue_thinkpad_cmos_command(cmos_cmd) ||
3174 !acpi_ec_write(volume_offset, level)))
3177 for (i = level; i != new_level; i += inc)
3178 if (issue_thinkpad_cmos_command(cmos_cmd) ||
3179 !acpi_ec_write(volume_offset, i + inc))
3182 if (mute && (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE) ||
3183 !acpi_ec_write(volume_offset,
3188 if (new_mute != mute) { /* level doesn't change */
3189 cmos_cmd = new_mute ? TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP;
3191 if (issue_thinkpad_cmos_command(cmos_cmd) ||
3192 !acpi_ec_write(volume_offset, level + new_mute))
3200 static struct ibm_struct volume_driver_data = {
3202 .read = volume_read,
3203 .write = volume_write,
3206 /*************************************************************************
3213 * TPACPI_FAN_RD_ACPI_GFAN:
3214 * ACPI GFAN method: returns fan level
3216 * see TPACPI_FAN_WR_ACPI_SFAN
3217 * EC 0x2f (HFSP) not available if GFAN exists
3219 * TPACPI_FAN_WR_ACPI_SFAN:
3220 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
3222 * EC 0x2f (HFSP) might be available *for reading*, but do not use
3225 * TPACPI_FAN_WR_TPEC:
3226 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
3227 * Supported on almost all ThinkPads
3229 * Fan speed changes of any sort (including those caused by the
3230 * disengaged mode) are usually done slowly by the firmware as the
3231 * maximum ammount of fan duty cycle change per second seems to be
3234 * Reading is not available if GFAN exists.
3235 * Writing is not available if SFAN exists.
3238 * 7 automatic mode engaged;
3239 * (default operation mode of the ThinkPad)
3240 * fan level is ignored in this mode.
3241 * 6 full speed mode (takes precedence over bit 7);
3242 * not available on all thinkpads. May disable
3243 * the tachometer while the fan controller ramps up
3244 * the speed (which can take up to a few *minutes*).
3245 * Speeds up fan to 100% duty-cycle, which is far above
3246 * the standard RPM levels. It is not impossible that
3247 * it could cause hardware damage.
3248 * 5-3 unused in some models. Extra bits for fan level
3249 * in others, but still useless as all values above
3250 * 7 map to the same speed as level 7 in these models.
3251 * 2-0 fan level (0..7 usually)
3253 * 0x07 = max (set when temperatures critical)
3254 * Some ThinkPads may have other levels, see
3255 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
3257 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
3258 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
3259 * does so, its initial value is meaningless (0x07).
3261 * For firmware bugs, refer to:
3262 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3266 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
3267 * Main fan tachometer reading (in RPM)
3269 * This register is present on all ThinkPads with a new-style EC, and
3270 * it is known not to be present on the A21m/e, and T22, as there is
3271 * something else in offset 0x84 according to the ACPI DSDT. Other
3272 * ThinkPads from this same time period (and earlier) probably lack the
3273 * tachometer as well.
3275 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
3276 * was never fixed by IBM to report the EC firmware version string
3277 * probably support the tachometer (like the early X models), so
3278 * detecting it is quite hard. We need more data to know for sure.
3280 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
3283 * FIRMWARE BUG: may go stale while the EC is switching to full speed
3286 * For firmware bugs, refer to:
3287 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3289 * TPACPI_FAN_WR_ACPI_FANS:
3290 * ThinkPad X31, X40, X41. Not available in the X60.
3292 * FANS ACPI handle: takes three arguments: low speed, medium speed,
3293 * high speed. ACPI DSDT seems to map these three speeds to levels
3294 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
3295 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
3297 * The speeds are stored on handles
3298 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
3300 * There are three default speed sets, acessible as handles:
3301 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
3303 * ACPI DSDT switches which set is in use depending on various
3306 * TPACPI_FAN_WR_TPEC is also available and should be used to
3307 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
3308 * but the ACPI tables just mention level 7.
3311 static enum fan_status_access_mode fan_status_access_mode;
3312 static enum fan_control_access_mode fan_control_access_mode;
3313 static enum fan_control_commands fan_control_commands;
3315 static u8 fan_control_initial_status;
3316 static u8 fan_control_desired_level;
3318 static void fan_watchdog_fire(struct work_struct *ignored);
3319 static int fan_watchdog_maxinterval;
3320 static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire);
3322 IBM_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */
3323 IBM_HANDLE(gfan, ec, "GFAN", /* 570 */
3324 "\\FSPD", /* 600e/x, 770e, 770x */
3326 IBM_HANDLE(sfan, ec, "SFAN", /* 570 */
3327 "JFNS", /* 770x-JL */
3331 * SYSFS fan layout: hwmon compatible (device)
3334 * 0: "disengaged" mode
3336 * 2: native EC "auto" mode (recommended, hardware default)
3338 * pwm*: set speed in manual mode, ignored otherwise.
3339 * 0 is level 0; 255 is level 7. Intermediate points done with linear
3342 * fan*_input: tachometer reading, RPM
3345 * SYSFS fan layout: extensions
3347 * fan_watchdog (driver):
3348 * fan watchdog interval in seconds, 0 disables (default), max 120
3351 /* sysfs fan pwm1_enable ----------------------------------------------- */
3352 static ssize_t fan_pwm1_enable_show(struct device *dev,
3353 struct device_attribute *attr,
3359 res = fan_get_status_safe(&status);
3363 if (unlikely(tp_features.fan_ctrl_status_undef)) {
3364 if (status != fan_control_initial_status) {
3365 tp_features.fan_ctrl_status_undef = 0;
3367 /* Return most likely status. In fact, it
3368 * might be the only possible status */
3369 status = TP_EC_FAN_AUTO;
3373 if (status & TP_EC_FAN_FULLSPEED) {
3375 } else if (status & TP_EC_FAN_AUTO) {
3380 return snprintf(buf, PAGE_SIZE, "%d\n", mode);
3383 static ssize_t fan_pwm1_enable_store(struct device *dev,
3384 struct device_attribute *attr,
3385 const char *buf, size_t count)
3390 if (parse_strtoul(buf, 2, &t))
3395 level = TP_EC_FAN_FULLSPEED;
3398 level = TPACPI_FAN_LAST_LEVEL;
3401 level = TP_EC_FAN_AUTO;
3404 /* reserved for software-controlled auto mode */
3410 res = fan_set_level_safe(level);
3416 fan_watchdog_reset();
3421 static struct device_attribute dev_attr_fan_pwm1_enable =
3422 __ATTR(pwm1_enable, S_IWUSR | S_IRUGO,
3423 fan_pwm1_enable_show, fan_pwm1_enable_store);
3425 /* sysfs fan pwm1 ------------------------------------------------------ */
3426 static ssize_t fan_pwm1_show(struct device *dev,
3427 struct device_attribute *attr,
3433 res = fan_get_status_safe(&status);
3437 if (unlikely(tp_features.fan_ctrl_status_undef)) {
3438 if (status != fan_control_initial_status) {
3439 tp_features.fan_ctrl_status_undef = 0;
3441 status = TP_EC_FAN_AUTO;
3446 (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) != 0)
3447 status = fan_control_desired_level;
3452 return snprintf(buf, PAGE_SIZE, "%u\n", (status * 255) / 7);
3455 static ssize_t fan_pwm1_store(struct device *dev,
3456 struct device_attribute *attr,
3457 const char *buf, size_t count)
3461 u8 status, newlevel;
3463 if (parse_strtoul(buf, 255, &s))
3466 /* scale down from 0-255 to 0-7 */
3467 newlevel = (s >> 5) & 0x07;
3469 rc = mutex_lock_interruptible(&fan_mutex);
3473 rc = fan_get_status(&status);
3474 if (!rc && (status &
3475 (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) {
3476 rc = fan_set_level(newlevel);
3480 fan_update_desired_level(newlevel);
3481 fan_watchdog_reset();
3485 mutex_unlock(&fan_mutex);
3486 return (rc)? rc : count;
3489 static struct device_attribute dev_attr_fan_pwm1 =
3490 __ATTR(pwm1, S_IWUSR | S_IRUGO,
3491 fan_pwm1_show, fan_pwm1_store);
3493 /* sysfs fan fan1_input ------------------------------------------------ */
3494 static ssize_t fan_fan1_input_show(struct device *dev,
3495 struct device_attribute *attr,
3501 res = fan_get_speed(&speed);
3505 return snprintf(buf, PAGE_SIZE, "%u\n", speed);
3508 static struct device_attribute dev_attr_fan_fan1_input =
3509 __ATTR(fan1_input, S_IRUGO,
3510 fan_fan1_input_show, NULL);
3512 /* sysfs fan fan_watchdog (driver) ------------------------------------- */
3513 static ssize_t fan_fan_watchdog_show(struct device_driver *drv,
3516 return snprintf(buf, PAGE_SIZE, "%u\n", fan_watchdog_maxinterval);
3519 static ssize_t fan_fan_watchdog_store(struct device_driver *drv,
3520 const char *buf, size_t count)
3524 if (parse_strtoul(buf, 120, &t))
3527 if (!fan_control_allowed)
3530 fan_watchdog_maxinterval = t;
3531 fan_watchdog_reset();
3536 static DRIVER_ATTR(fan_watchdog, S_IWUSR | S_IRUGO,
3537 fan_fan_watchdog_show, fan_fan_watchdog_store);
3539 /* --------------------------------------------------------------------- */
3540 static struct attribute *fan_attributes[] = {
3541 &dev_attr_fan_pwm1_enable.attr, &dev_attr_fan_pwm1.attr,
3542 &dev_attr_fan_fan1_input.attr,
3546 static const struct attribute_group fan_attr_group = {
3547 .attrs = fan_attributes,
3550 static int __init fan_init(struct ibm_init_struct *iibm)
3554 vdbg_printk(TPACPI_DBG_INIT, "initializing fan subdriver\n");
3556 mutex_init(&fan_mutex);
3557 fan_status_access_mode = TPACPI_FAN_NONE;
3558 fan_control_access_mode = TPACPI_FAN_WR_NONE;
3559 fan_control_commands = 0;
3560 fan_watchdog_maxinterval = 0;
3561 tp_features.fan_ctrl_status_undef = 0;
3562 fan_control_desired_level = 7;
3564 IBM_ACPIHANDLE_INIT(fans);
3565 IBM_ACPIHANDLE_INIT(gfan);
3566 IBM_ACPIHANDLE_INIT(sfan);
3569 /* 570, 600e/x, 770e, 770x */
3570 fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN;
3572 /* all other ThinkPads: note that even old-style
3573 * ThinkPad ECs supports the fan control register */
3574 if (likely(acpi_ec_read(fan_status_offset,
3575 &fan_control_initial_status))) {
3576 fan_status_access_mode = TPACPI_FAN_RD_TPEC;
3578 /* In some ThinkPads, neither the EC nor the ACPI
3579 * DSDT initialize the fan status, and it ends up
3580 * being set to 0x07 when it *could* be either
3583 * Enable for TP-1Y (T43), TP-78 (R51e),
3584 * TP-76 (R52), TP-70 (T43, R52), which are known
3586 if (fan_control_initial_status == 0x07) {
3587 switch (thinkpad_id.ec_model) {
3588 case 0x5931: /* TP-1Y */
3589 case 0x3837: /* TP-78 */
3590 case 0x3637: /* TP-76 */
3591 case 0x3037: /* TP-70 */
3593 "fan_init: initial fan status is "
3594 "unknown, assuming it is in auto "
3596 tp_features.fan_ctrl_status_undef = 1;
3602 "ThinkPad ACPI EC access misbehaving, "
3603 "fan status and control unavailable\n");
3610 fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN;
3611 fan_control_commands |=
3612 TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE;
3615 /* gfan without sfan means no fan control */
3616 /* all other models implement TP EC 0x2f control */
3620 fan_control_access_mode =
3621 TPACPI_FAN_WR_ACPI_FANS;
3622 fan_control_commands |=
3623 TPACPI_FAN_CMD_SPEED |
3624 TPACPI_FAN_CMD_LEVEL |
3625 TPACPI_FAN_CMD_ENABLE;
3627 fan_control_access_mode = TPACPI_FAN_WR_TPEC;
3628 fan_control_commands |=
3629 TPACPI_FAN_CMD_LEVEL |
3630 TPACPI_FAN_CMD_ENABLE;
3635 vdbg_printk(TPACPI_DBG_INIT, "fan is %s, modes %d, %d\n",
3636 str_supported(fan_status_access_mode != TPACPI_FAN_NONE ||
3637 fan_control_access_mode != TPACPI_FAN_WR_NONE),
3638 fan_status_access_mode, fan_control_access_mode);
3640 /* fan control master switch */
3641 if (!fan_control_allowed) {
3642 fan_control_access_mode = TPACPI_FAN_WR_NONE;
3643 fan_control_commands = 0;
3644 dbg_printk(TPACPI_DBG_INIT,
3645 "fan control features disabled by parameter\n");
3648 /* update fan_control_desired_level */
3649 if (fan_status_access_mode != TPACPI_FAN_NONE)
3650 fan_get_status_safe(NULL);
3652 if (fan_status_access_mode != TPACPI_FAN_NONE ||
3653 fan_control_access_mode != TPACPI_FAN_WR_NONE) {
3654 rc = sysfs_create_group(&tpacpi_pdev->dev.kobj,
3657 rc = driver_create_file(&tpacpi_pdriver.driver,
3658 &driver_attr_fan_watchdog);
3667 * Call with fan_mutex held
3669 static void fan_update_desired_level(u8 status)
3672 (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) {
3674 fan_control_desired_level = 7;
3676 fan_control_desired_level = status;
3680 static int fan_get_status(u8 *status)
3685 * Add TPACPI_FAN_RD_ACPI_FANS ? */
3687 switch (fan_status_access_mode) {
3688 case TPACPI_FAN_RD_ACPI_GFAN:
3689 /* 570, 600e/x, 770e, 770x */
3691 if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d")))
3699 case TPACPI_FAN_RD_TPEC:
3700 /* all except 570, 600e/x, 770e, 770x */
3701 if (unlikely(!acpi_ec_read(fan_status_offset, &s)))
3716 static int fan_get_status_safe(u8 *status)
3721 rc = mutex_lock_interruptible(&fan_mutex);
3724 rc = fan_get_status(&s);
3726 fan_update_desired_level(s);
3727 mutex_unlock(&fan_mutex);
3735 static void fan_exit(void)
3737 vdbg_printk(TPACPI_DBG_EXIT, "cancelling any pending fan watchdog tasks\n");
3739 /* FIXME: can we really do this unconditionally? */
3740 sysfs_remove_group(&tpacpi_pdev->dev.kobj, &fan_attr_group);
3741 driver_remove_file(&tpacpi_pdriver.driver, &driver_attr_fan_watchdog);
3743 cancel_delayed_work(&fan_watchdog_task);
3744 flush_scheduled_work();
3747 static int fan_get_speed(unsigned int *speed)
3751 switch (fan_status_access_mode) {
3752 case TPACPI_FAN_RD_TPEC:
3753 /* all except 570, 600e/x, 770e, 770x */
3754 if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) ||
3755 !acpi_ec_read(fan_rpm_offset + 1, &hi)))
3759 *speed = (hi << 8) | lo;
3770 static void fan_watchdog_fire(struct work_struct *ignored)
3774 printk(IBM_NOTICE "fan watchdog: enabling fan\n");
3775 rc = fan_set_enable();
3777 printk(IBM_ERR "fan watchdog: error %d while enabling fan, "
3778 "will try again later...\n", -rc);
3779 /* reschedule for later */
3780 fan_watchdog_reset();
3784 static void fan_watchdog_reset(void)
3786 static int fan_watchdog_active;
3788 if (fan_control_access_mode == TPACPI_FAN_WR_NONE)
3791 if (fan_watchdog_active)
3792 cancel_delayed_work(&fan_watchdog_task);
3794 if (fan_watchdog_maxinterval > 0) {
3795 fan_watchdog_active = 1;
3796 if (!schedule_delayed_work(&fan_watchdog_task,
3797 msecs_to_jiffies(fan_watchdog_maxinterval
3799 printk(IBM_ERR "failed to schedule the fan watchdog, "
3800 "watchdog will not trigger\n");
3803 fan_watchdog_active = 0;
3806 static int fan_set_level(int level)
3808 if (!fan_control_allowed)
3811 switch (fan_control_access_mode) {
3812 case TPACPI_FAN_WR_ACPI_SFAN:
3813 if (level >= 0 && level <= 7) {
3814 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level))
3820 case TPACPI_FAN_WR_ACPI_FANS:
3821 case TPACPI_FAN_WR_TPEC:
3822 if ((level != TP_EC_FAN_AUTO) &&
3823 (level != TP_EC_FAN_FULLSPEED) &&
3824 ((level < 0) || (level > 7)))
3827 /* safety net should the EC not support AUTO
3828 * or FULLSPEED mode bits and just ignore them */
3829 if (level & TP_EC_FAN_FULLSPEED)
3830 level |= 7; /* safety min speed 7 */
3831 else if (level & TP_EC_FAN_FULLSPEED)
3832 level |= 4; /* safety min speed 4 */
3834 if (!acpi_ec_write(fan_status_offset, level))
3837 tp_features.fan_ctrl_status_undef = 0;
3846 static int fan_set_level_safe(int level)
3850 if (!fan_control_allowed)
3853 rc = mutex_lock_interruptible(&fan_mutex);
3857 if (level == TPACPI_FAN_LAST_LEVEL)
3858 level = fan_control_desired_level;
3860 rc = fan_set_level(level);
3862 fan_update_desired_level(level);
3864 mutex_unlock(&fan_mutex);
3868 static int fan_set_enable(void)
3873 if (!fan_control_allowed)
3876 rc = mutex_lock_interruptible(&fan_mutex);
3880 switch (fan_control_access_mode) {
3881 case TPACPI_FAN_WR_ACPI_FANS:
3882 case TPACPI_FAN_WR_TPEC:
3883 rc = fan_get_status(&s);
3887 /* Don't go out of emergency fan mode */
3890 s |= TP_EC_FAN_AUTO | 4; /* min fan speed 4 */
3893 if (!acpi_ec_write(fan_status_offset, s))
3896 tp_features.fan_ctrl_status_undef = 0;
3901 case TPACPI_FAN_WR_ACPI_SFAN:
3902 rc = fan_get_status(&s);
3908 /* Set fan to at least level 4 */
3911 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s))
3921 mutex_unlock(&fan_mutex);
3925 static int fan_set_disable(void)
3929 if (!fan_control_allowed)
3932 rc = mutex_lock_interruptible(&fan_mutex);
3937 switch (fan_control_access_mode) {
3938 case TPACPI_FAN_WR_ACPI_FANS:
3939 case TPACPI_FAN_WR_TPEC:
3940 if (!acpi_ec_write(fan_status_offset, 0x00))
3943 fan_control_desired_level = 0;
3944 tp_features.fan_ctrl_status_undef = 0;
3948 case TPACPI_FAN_WR_ACPI_SFAN:
3949 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00))
3952 fan_control_desired_level = 0;
3960 mutex_unlock(&fan_mutex);
3964 static int fan_set_speed(int speed)
3968 if (!fan_control_allowed)
3971 rc = mutex_lock_interruptible(&fan_mutex);
3976 switch (fan_control_access_mode) {
3977 case TPACPI_FAN_WR_ACPI_FANS:
3978 if (speed >= 0 && speed <= 65535) {
3979 if (!acpi_evalf(fans_handle, NULL, NULL, "vddd",
3980 speed, speed, speed))
3990 mutex_unlock(&fan_mutex);
3994 static int fan_read(char *p)
3999 unsigned int speed = 0;
4001 switch (fan_status_access_mode) {
4002 case TPACPI_FAN_RD_ACPI_GFAN:
4003 /* 570, 600e/x, 770e, 770x */
4004 if ((rc = fan_get_status_safe(&status)) < 0)
4007 len += sprintf(p + len, "status:\t\t%s\n"
4009 (status != 0) ? "enabled" : "disabled", status);
4012 case TPACPI_FAN_RD_TPEC:
4013 /* all except 570, 600e/x, 770e, 770x */
4014 if ((rc = fan_get_status_safe(&status)) < 0)
4017 if (unlikely(tp_features.fan_ctrl_status_undef)) {
4018 if (status != fan_control_initial_status)
4019 tp_features.fan_ctrl_status_undef = 0;
4021 /* Return most likely status. In fact, it
4022 * might be the only possible status */
4023 status = TP_EC_FAN_AUTO;
4026 len += sprintf(p + len, "status:\t\t%s\n",
4027 (status != 0) ? "enabled" : "disabled");
4029 if ((rc = fan_get_speed(&speed)) < 0)
4032 len += sprintf(p + len, "speed:\t\t%d\n", speed);
4034 if (status & TP_EC_FAN_FULLSPEED)
4035 /* Disengaged mode takes precedence */
4036 len += sprintf(p + len, "level:\t\tdisengaged\n");
4037 else if (status & TP_EC_FAN_AUTO)
4038 len += sprintf(p + len, "level:\t\tauto\n");
4040 len += sprintf(p + len, "level:\t\t%d\n", status);
4043 case TPACPI_FAN_NONE:
4045 len += sprintf(p + len, "status:\t\tnot supported\n");
4048 if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) {
4049 len += sprintf(p + len, "commands:\tlevel <level>");
4051 switch (fan_control_access_mode) {
4052 case TPACPI_FAN_WR_ACPI_SFAN:
4053 len += sprintf(p + len, " (<level> is 0-7)\n");
4057 len += sprintf(p + len, " (<level> is 0-7, "
4058 "auto, disengaged, full-speed)\n");
4063 if (fan_control_commands & TPACPI_FAN_CMD_ENABLE)
4064 len += sprintf(p + len, "commands:\tenable, disable\n"
4065 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
4066 "1-120 (seconds))\n");
4068 if (fan_control_commands & TPACPI_FAN_CMD_SPEED)
4069 len += sprintf(p + len, "commands:\tspeed <speed>"
4070 " (<speed> is 0-65535)\n");
4075 static int fan_write_cmd_level(const char *cmd, int *rc)
4079 if (strlencmp(cmd, "level auto") == 0)
4080 level = TP_EC_FAN_AUTO;
4081 else if ((strlencmp(cmd, "level disengaged") == 0) |
4082 (strlencmp(cmd, "level full-speed") == 0))
4083 level = TP_EC_FAN_FULLSPEED;
4084 else if (sscanf(cmd, "level %d", &level) != 1)
4087 if ((*rc = fan_set_level_safe(level)) == -ENXIO)
4088 printk(IBM_ERR "level command accepted for unsupported "
4089 "access mode %d", fan_control_access_mode);
4094 static int fan_write_cmd_enable(const char *cmd, int *rc)
4096 if (strlencmp(cmd, "enable") != 0)
4099 if ((*rc = fan_set_enable()) == -ENXIO)
4100 printk(IBM_ERR "enable command accepted for unsupported "
4101 "access mode %d", fan_control_access_mode);
4106 static int fan_write_cmd_disable(const char *cmd, int *rc)
4108 if (strlencmp(cmd, "disable") != 0)
4111 if ((*rc = fan_set_disable()) == -ENXIO)
4112 printk(IBM_ERR "disable command accepted for unsupported "
4113 "access mode %d", fan_control_access_mode);
4118 static int fan_write_cmd_speed(const char *cmd, int *rc)
4123 * Support speed <low> <medium> <high> ? */
4125 if (sscanf(cmd, "speed %d", &speed) != 1)
4128 if ((*rc = fan_set_speed(speed)) == -ENXIO)
4129 printk(IBM_ERR "speed command accepted for unsupported "
4130 "access mode %d", fan_control_access_mode);
4135 static int fan_write_cmd_watchdog(const char *cmd, int *rc)
4139 if (sscanf(cmd, "watchdog %d", &interval) != 1)
4142 if (interval < 0 || interval > 120)
4145 fan_watchdog_maxinterval = interval;
4150 static int fan_write(char *buf)
4155 while (!rc && (cmd = next_cmd(&buf))) {
4156 if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) &&
4157 fan_write_cmd_level(cmd, &rc)) &&
4158 !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) &&
4159 (fan_write_cmd_enable(cmd, &rc) ||
4160 fan_write_cmd_disable(cmd, &rc) ||
4161 fan_write_cmd_watchdog(cmd, &rc))) &&
4162 !((fan_control_commands & TPACPI_FAN_CMD_SPEED) &&
4163 fan_write_cmd_speed(cmd, &rc))
4167 fan_watchdog_reset();
4173 static struct ibm_struct fan_driver_data = {
4180 /****************************************************************************
4181 ****************************************************************************
4185 ****************************************************************************
4186 ****************************************************************************/
4189 static struct proc_dir_entry *proc_dir;
4191 /* Subdriver registry */
4192 static LIST_HEAD(tpacpi_all_drivers);
4196 * Module and infrastructure proble, init and exit handling
4199 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
4200 static const char * __init str_supported(int is_supported)
4202 static char text_unsupported[] __initdata = "not supported";
4204 return (is_supported)? &text_unsupported[4] : &text_unsupported[0];
4206 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
4208 static int __init ibm_init(struct ibm_init_struct *iibm)
4211 struct ibm_struct *ibm = iibm->data;
4212 struct proc_dir_entry *entry;
4214 BUG_ON(ibm == NULL);
4216 INIT_LIST_HEAD(&ibm->all_drivers);
4218 if (ibm->flags.experimental && !experimental)
4221 dbg_printk(TPACPI_DBG_INIT,
4222 "probing for %s\n", ibm->name);
4225 ret = iibm->init(iibm);
4227 return 0; /* probe failed */
4231 ibm->flags.init_called = 1;
4235 if (ibm->acpi->hid) {
4236 ret = register_tpacpi_subdriver(ibm);
4241 if (ibm->acpi->notify) {
4242 ret = setup_acpi_notify(ibm);
4243 if (ret == -ENODEV) {
4244 printk(IBM_NOTICE "disabling subdriver %s\n",
4254 dbg_printk(TPACPI_DBG_INIT,
4255 "%s installed\n", ibm->name);
4258 entry = create_proc_entry(ibm->name,
4259 S_IFREG | S_IRUGO | S_IWUSR,
4262 printk(IBM_ERR "unable to create proc entry %s\n",
4267 entry->owner = THIS_MODULE;
4269 entry->read_proc = &dispatch_procfs_read;
4271 entry->write_proc = &dispatch_procfs_write;
4272 ibm->flags.proc_created = 1;
4275 list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers);
4280 dbg_printk(TPACPI_DBG_INIT,
4281 "%s: at error exit path with result %d\n",
4285 return (ret < 0)? ret : 0;
4288 static void ibm_exit(struct ibm_struct *ibm)
4290 dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name);
4292 list_del_init(&ibm->all_drivers);
4294 if (ibm->flags.acpi_notify_installed) {
4295 dbg_printk(TPACPI_DBG_EXIT,
4296 "%s: acpi_remove_notify_handler\n", ibm->name);
4298 acpi_remove_notify_handler(*ibm->acpi->handle,
4300 dispatch_acpi_notify);
4301 ibm->flags.acpi_notify_installed = 0;
4302 ibm->flags.acpi_notify_installed = 0;
4305 if (ibm->flags.proc_created) {
4306 dbg_printk(TPACPI_DBG_EXIT,
4307 "%s: remove_proc_entry\n", ibm->name);
4308 remove_proc_entry(ibm->name, proc_dir);
4309 ibm->flags.proc_created = 0;
4312 if (ibm->flags.acpi_driver_registered) {
4313 dbg_printk(TPACPI_DBG_EXIT,
4314 "%s: acpi_bus_unregister_driver\n", ibm->name);
4316 acpi_bus_unregister_driver(ibm->acpi->driver);
4317 kfree(ibm->acpi->driver);
4318 ibm->acpi->driver = NULL;
4319 ibm->flags.acpi_driver_registered = 0;
4322 if (ibm->flags.init_called && ibm->exit) {
4324 ibm->flags.init_called = 0;
4327 dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name);
4332 static void __init get_thinkpad_model_data(struct thinkpad_id_data *tp)
4334 struct dmi_device *dev = NULL;
4335 char ec_fw_string[18];
4340 memset(tp, 0, sizeof(*tp));
4342 if (dmi_name_in_vendors("IBM"))
4343 tp->vendor = PCI_VENDOR_ID_IBM;
4344 else if (dmi_name_in_vendors("LENOVO"))
4345 tp->vendor = PCI_VENDOR_ID_LENOVO;
4349 tp->bios_version_str = kstrdup(dmi_get_system_info(DMI_BIOS_VERSION),
4351 if (!tp->bios_version_str)
4353 tp->bios_model = tp->bios_version_str[0]
4354 | (tp->bios_version_str[1] << 8);
4357 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
4358 * X32 or newer, all Z series; Some models must have an
4359 * up-to-date BIOS or they will not be detected.
4361 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
4363 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
4364 if (sscanf(dev->name,
4365 "IBM ThinkPad Embedded Controller -[%17c",
4366 ec_fw_string) == 1) {
4367 ec_fw_string[sizeof(ec_fw_string) - 1] = 0;
4368 ec_fw_string[strcspn(ec_fw_string, " ]")] = 0;
4370 tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL);
4371 tp->ec_model = ec_fw_string[0]
4372 | (ec_fw_string[1] << 8);
4377 tp->model_str = kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION),
4379 if (strnicmp(tp->model_str, "ThinkPad", 8) != 0) {
4380 kfree(tp->model_str);
4381 tp->model_str = NULL;
4385 static int __init probe_for_thinkpad(void)
4393 * Non-ancient models have better DMI tagging, but very old models
4396 is_thinkpad = (thinkpad_id.model_str != NULL);
4398 /* ec is required because many other handles are relative to it */
4399 IBM_ACPIHANDLE_INIT(ec);
4403 "Not yet supported ThinkPad detected!\n");
4408 * Risks a regression on very old machines, but reduces potential
4409 * false positives a damn great deal
4412 is_thinkpad = (thinkpad_id.vendor == PCI_VENDOR_ID_IBM);
4414 if (!is_thinkpad && !force_load)
4421 /* Module init, exit, parameters */
4423 static struct ibm_init_struct ibms_init[] __initdata = {
4425 .init = thinkpad_acpi_driver_init,
4426 .data = &thinkpad_acpi_driver_data,
4429 .init = hotkey_init,
4430 .data = &hotkey_driver_data,
4433 .init = bluetooth_init,
4434 .data = &bluetooth_driver_data,
4438 .data = &wan_driver_data,
4442 .data = &video_driver_data,
4446 .data = &light_driver_data,
4448 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4451 .data = &dock_driver_data[0],
4455 .data = &dock_driver_data[1],
4458 #ifdef CONFIG_THINKPAD_ACPI_BAY
4461 .data = &bay_driver_data,
4466 .data = &cmos_driver_data,
4470 .data = &led_driver_data,
4474 .data = &beep_driver_data,
4477 .init = thermal_init,
4478 .data = &thermal_driver_data,
4481 .data = &ecdump_driver_data,
4484 .init = brightness_init,
4485 .data = &brightness_driver_data,
4488 .data = &volume_driver_data,
4492 .data = &fan_driver_data,
4496 static int __init set_ibm_param(const char *val, struct kernel_param *kp)
4499 struct ibm_struct *ibm;
4501 for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
4502 ibm = ibms_init[i].data;
4503 BUG_ON(ibm == NULL);
4505 if (strcmp(ibm->name, kp->name) == 0 && ibm->write) {
4506 if (strlen(val) > sizeof(ibms_init[i].param) - 2)
4508 strcpy(ibms_init[i].param, val);
4509 strcat(ibms_init[i].param, ",");
4517 static int experimental;
4518 module_param(experimental, int, 0);
4520 static u32 dbg_level;
4521 module_param_named(debug, dbg_level, uint, 0);
4523 static int force_load;
4524 module_param(force_load, bool, 0);
4526 static int fan_control_allowed;
4527 module_param_named(fan_control, fan_control_allowed, bool, 0);
4529 static int brightness_mode;
4530 module_param_named(brightness_mode, brightness_mode, int, 0);
4532 #define IBM_PARAM(feature) \
4533 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
4536 IBM_PARAM(bluetooth);
4539 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4542 #ifdef CONFIG_THINKPAD_ACPI_BAY
4544 #endif /* CONFIG_THINKPAD_ACPI_BAY */
4549 IBM_PARAM(brightness);
4553 static int __init thinkpad_acpi_module_init(void)
4557 /* Driver-level probe */
4559 get_thinkpad_model_data(&thinkpad_id);
4560 ret = probe_for_thinkpad();
4562 thinkpad_acpi_module_exit();
4566 /* Driver initialization */
4568 IBM_ACPIHANDLE_INIT(ecrd);
4569 IBM_ACPIHANDLE_INIT(ecwr);
4571 proc_dir = proc_mkdir(IBM_PROC_DIR, acpi_root_dir);
4573 printk(IBM_ERR "unable to create proc dir " IBM_PROC_DIR);
4574 thinkpad_acpi_module_exit();
4577 proc_dir->owner = THIS_MODULE;
4579 ret = platform_driver_register(&tpacpi_pdriver);
4581 printk(IBM_ERR "unable to register platform driver\n");
4582 thinkpad_acpi_module_exit();
4585 ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver);
4587 printk(IBM_ERR "unable to create sysfs driver attributes\n");
4588 thinkpad_acpi_module_exit();
4593 /* Device initialization */
4594 tpacpi_pdev = platform_device_register_simple(IBM_DRVR_NAME, -1,
4596 if (IS_ERR(tpacpi_pdev)) {
4597 ret = PTR_ERR(tpacpi_pdev);
4599 printk(IBM_ERR "unable to register platform device\n");
4600 thinkpad_acpi_module_exit();
4603 tpacpi_hwmon = hwmon_device_register(&tpacpi_pdev->dev);
4604 if (IS_ERR(tpacpi_hwmon)) {
4605 ret = PTR_ERR(tpacpi_hwmon);
4606 tpacpi_hwmon = NULL;
4607 printk(IBM_ERR "unable to register hwmon device\n");
4608 thinkpad_acpi_module_exit();
4611 tpacpi_inputdev = input_allocate_device();
4612 if (!tpacpi_inputdev) {
4613 printk(IBM_ERR "unable to allocate input device\n");
4614 thinkpad_acpi_module_exit();
4617 /* Prepare input device, but don't register */
4618 tpacpi_inputdev->name = "ThinkPad Extra Buttons";
4619 tpacpi_inputdev->phys = IBM_DRVR_NAME "/input0";
4620 tpacpi_inputdev->id.bustype = BUS_HOST;
4621 tpacpi_inputdev->id.vendor = TPACPI_HKEY_INPUT_VENDOR;
4622 tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT;
4623 tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION;
4625 for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
4626 ret = ibm_init(&ibms_init[i]);
4627 if (ret >= 0 && *ibms_init[i].param)
4628 ret = ibms_init[i].data->write(ibms_init[i].param);
4630 thinkpad_acpi_module_exit();
4634 ret = input_register_device(tpacpi_inputdev);
4636 printk(IBM_ERR "unable to register input device\n");
4637 thinkpad_acpi_module_exit();
4640 tp_features.input_device_registered = 1;
4646 static void thinkpad_acpi_module_exit(void)
4648 struct ibm_struct *ibm, *itmp;
4650 list_for_each_entry_safe_reverse(ibm, itmp,
4651 &tpacpi_all_drivers,
4656 dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n");
4658 if (tpacpi_inputdev) {
4659 if (tp_features.input_device_registered)
4660 input_unregister_device(tpacpi_inputdev);
4662 input_free_device(tpacpi_inputdev);
4666 hwmon_device_unregister(tpacpi_hwmon);
4669 platform_device_unregister(tpacpi_pdev);
4671 tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver);
4672 platform_driver_unregister(&tpacpi_pdriver);
4675 remove_proc_entry(IBM_PROC_DIR, acpi_root_dir);
4677 kfree(thinkpad_id.bios_version_str);
4678 kfree(thinkpad_id.ec_version_str);
4679 kfree(thinkpad_id.model_str);
4682 module_init(thinkpad_acpi_module_init);
4683 module_exit(thinkpad_acpi_module_exit);