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.15"
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;
763 static struct attribute_set *hotkey_dev_attributes;
765 static int hotkey_get_wlsw(int *status)
767 if (!acpi_evalf(hkey_handle, status, "WLSW", "d"))
772 /* sysfs hotkey enable ------------------------------------------------- */
773 static ssize_t hotkey_enable_show(struct device *dev,
774 struct device_attribute *attr,
780 res = hotkey_get(&status, &mask);
784 return snprintf(buf, PAGE_SIZE, "%d\n", status);
787 static ssize_t hotkey_enable_store(struct device *dev,
788 struct device_attribute *attr,
789 const char *buf, size_t count)
795 if (parse_strtoul(buf, 1, &t))
798 res = hotkey_get(&status, &mask);
800 res = hotkey_set(t, mask);
802 return (res) ? res : count;
805 static struct device_attribute dev_attr_hotkey_enable =
806 __ATTR(hotkey_enable, S_IWUSR | S_IRUGO,
807 hotkey_enable_show, hotkey_enable_store);
809 /* sysfs hotkey mask --------------------------------------------------- */
810 static ssize_t hotkey_mask_show(struct device *dev,
811 struct device_attribute *attr,
817 res = hotkey_get(&status, &mask);
821 return snprintf(buf, PAGE_SIZE, "0x%08x\n", mask);
824 static ssize_t hotkey_mask_store(struct device *dev,
825 struct device_attribute *attr,
826 const char *buf, size_t count)
832 if (parse_strtoul(buf, 0xffffffffUL, &t))
835 res = hotkey_get(&status, &mask);
837 hotkey_set(status, t);
839 return (res) ? res : count;
842 static struct device_attribute dev_attr_hotkey_mask =
843 __ATTR(hotkey_mask, S_IWUSR | S_IRUGO,
844 hotkey_mask_show, hotkey_mask_store);
846 /* sysfs hotkey bios_enabled ------------------------------------------- */
847 static ssize_t hotkey_bios_enabled_show(struct device *dev,
848 struct device_attribute *attr,
851 return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_orig_status);
854 static struct device_attribute dev_attr_hotkey_bios_enabled =
855 __ATTR(hotkey_bios_enabled, S_IRUGO, hotkey_bios_enabled_show, NULL);
857 /* sysfs hotkey bios_mask ---------------------------------------------- */
858 static ssize_t hotkey_bios_mask_show(struct device *dev,
859 struct device_attribute *attr,
862 return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_orig_mask);
865 static struct device_attribute dev_attr_hotkey_bios_mask =
866 __ATTR(hotkey_bios_mask, S_IRUGO, hotkey_bios_mask_show, NULL);
868 /* sysfs hotkey all_mask ----------------------------------------------- */
869 static ssize_t hotkey_all_mask_show(struct device *dev,
870 struct device_attribute *attr,
873 return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_all_mask);
876 static struct device_attribute dev_attr_hotkey_all_mask =
877 __ATTR(hotkey_all_mask, S_IRUGO, hotkey_all_mask_show, NULL);
879 /* sysfs hotkey recommended_mask --------------------------------------- */
880 static ssize_t hotkey_recommended_mask_show(struct device *dev,
881 struct device_attribute *attr,
884 return snprintf(buf, PAGE_SIZE, "0x%08x\n",
885 hotkey_all_mask & ~hotkey_reserved_mask);
888 static struct device_attribute dev_attr_hotkey_recommended_mask =
889 __ATTR(hotkey_recommended_mask, S_IRUGO,
890 hotkey_recommended_mask_show, NULL);
892 /* sysfs hotkey radio_sw ----------------------------------------------- */
893 static ssize_t hotkey_radio_sw_show(struct device *dev,
894 struct device_attribute *attr,
898 res = hotkey_get_wlsw(&s);
902 return snprintf(buf, PAGE_SIZE, "%d\n", !!s);
905 static struct device_attribute dev_attr_hotkey_radio_sw =
906 __ATTR(hotkey_radio_sw, S_IRUGO, hotkey_radio_sw_show, NULL);
908 /* --------------------------------------------------------------------- */
910 static struct attribute *hotkey_mask_attributes[] = {
911 &dev_attr_hotkey_mask.attr,
912 &dev_attr_hotkey_bios_enabled.attr,
913 &dev_attr_hotkey_bios_mask.attr,
914 &dev_attr_hotkey_all_mask.attr,
915 &dev_attr_hotkey_recommended_mask.attr,
918 static int __init hotkey_init(struct ibm_init_struct *iibm)
921 static u16 ibm_keycode_map[] __initdata = {
922 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
923 KEY_FN_F1, KEY_FN_F2, KEY_COFFEE, KEY_SLEEP,
924 KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8,
925 KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND,
926 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
927 KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */
928 KEY_UNKNOWN, /* 0x0D: FN+INSERT */
929 KEY_UNKNOWN, /* 0x0E: FN+DELETE */
930 KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */
931 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
932 KEY_RESERVED, /* 0x10: FN+END (brightness down) */
933 KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */
934 KEY_UNKNOWN, /* 0x12: FN+PGDOWN */
935 KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */
936 KEY_RESERVED, /* 0x14: VOLUME UP */
937 KEY_RESERVED, /* 0x15: VOLUME DOWN */
938 KEY_RESERVED, /* 0x16: MUTE */
939 KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */
940 /* (assignments unknown, please report if found) */
941 KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
942 KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
944 static u16 lenovo_keycode_map[] __initdata = {
945 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
946 KEY_FN_F1, KEY_COFFEE, KEY_BATTERY, KEY_SLEEP,
947 KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8,
948 KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND,
949 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
950 KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */
951 KEY_UNKNOWN, /* 0x0D: FN+INSERT */
952 KEY_UNKNOWN, /* 0x0E: FN+DELETE */
953 KEY_BRIGHTNESSUP, /* 0x0F: FN+HOME (brightness up) */
954 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
955 KEY_BRIGHTNESSDOWN, /* 0x10: FN+END (brightness down) */
956 KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */
957 KEY_UNKNOWN, /* 0x12: FN+PGDOWN */
958 KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */
959 KEY_RESERVED, /* 0x14: VOLUME UP */
960 KEY_RESERVED, /* 0x15: VOLUME DOWN */
961 KEY_RESERVED, /* 0x16: MUTE */
962 KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */
963 /* (assignments unknown, please report if found) */
964 KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
965 KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
968 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
969 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
970 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
975 vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n");
977 BUG_ON(!tpacpi_inputdev);
979 IBM_ACPIHANDLE_INIT(hkey);
980 mutex_init(&hotkey_mutex);
982 /* hotkey not supported on 570 */
983 tp_features.hotkey = hkey_handle != NULL;
985 vdbg_printk(TPACPI_DBG_INIT, "hotkeys are %s\n",
986 str_supported(tp_features.hotkey));
988 if (tp_features.hotkey) {
989 hotkey_dev_attributes = create_attr_set(7, NULL);
990 if (!hotkey_dev_attributes)
992 res = add_to_attr_set(hotkey_dev_attributes,
993 &dev_attr_hotkey_enable.attr);
997 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
998 A30, R30, R31, T20-22, X20-21, X22-24 */
999 tp_features.hotkey_mask =
1000 acpi_evalf(hkey_handle, NULL, "DHKN", "qv");
1002 vdbg_printk(TPACPI_DBG_INIT, "hotkey masks are %s\n",
1003 str_supported(tp_features.hotkey_mask));
1005 if (tp_features.hotkey_mask) {
1006 /* MHKA available in A31, R40, R40e, T4x, X31, and later */
1007 if (!acpi_evalf(hkey_handle, &hotkey_all_mask,
1009 hotkey_all_mask = 0x080cU; /* FN+F12, FN+F4, FN+F3 */
1012 res = hotkey_get(&hotkey_orig_status, &hotkey_orig_mask);
1013 if (!res && tp_features.hotkey_mask) {
1014 res = add_many_to_attr_set(hotkey_dev_attributes,
1015 hotkey_mask_attributes,
1016 ARRAY_SIZE(hotkey_mask_attributes));
1019 /* Not all thinkpads have a hardware radio switch */
1020 if (!res && acpi_evalf(hkey_handle, &status, "WLSW", "qd")) {
1021 tp_features.hotkey_wlsw = 1;
1023 "radio switch found; radios are %s\n",
1024 enabled(status, 0));
1025 res = add_to_attr_set(hotkey_dev_attributes,
1026 &dev_attr_hotkey_radio_sw.attr);
1030 res = register_attr_set_with_sysfs(
1031 hotkey_dev_attributes,
1032 &tpacpi_pdev->dev.kobj);
1036 /* Set up key map */
1038 hotkey_keycode_map = kmalloc(TPACPI_HOTKEY_MAP_SIZE,
1040 if (!hotkey_keycode_map) {
1041 printk(IBM_ERR "failed to allocate memory for key map\n");
1045 if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) {
1046 dbg_printk(TPACPI_DBG_INIT,
1047 "using Lenovo default hot key map\n");
1048 memcpy(hotkey_keycode_map, &lenovo_keycode_map,
1049 TPACPI_HOTKEY_MAP_SIZE);
1051 dbg_printk(TPACPI_DBG_INIT,
1052 "using IBM default hot key map\n");
1053 memcpy(hotkey_keycode_map, &ibm_keycode_map,
1054 TPACPI_HOTKEY_MAP_SIZE);
1057 #ifndef CONFIG_THINKPAD_ACPI_INPUT_ENABLED
1058 for (i = 0; i < 12; i++)
1059 hotkey_keycode_map[i] = KEY_UNKNOWN;
1060 #endif /* ! CONFIG_THINKPAD_ACPI_INPUT_ENABLED */
1062 set_bit(EV_KEY, tpacpi_inputdev->evbit);
1063 set_bit(EV_MSC, tpacpi_inputdev->evbit);
1064 set_bit(MSC_SCAN, tpacpi_inputdev->mscbit);
1065 tpacpi_inputdev->keycodesize = TPACPI_HOTKEY_MAP_TYPESIZE;
1066 tpacpi_inputdev->keycodemax = TPACPI_HOTKEY_MAP_LEN;
1067 tpacpi_inputdev->keycode = hotkey_keycode_map;
1068 for (i = 0; i < TPACPI_HOTKEY_MAP_LEN; i++) {
1069 if (hotkey_keycode_map[i] != KEY_RESERVED) {
1070 set_bit(hotkey_keycode_map[i],
1071 tpacpi_inputdev->keybit);
1073 if (i < sizeof(hotkey_reserved_mask)*8)
1074 hotkey_reserved_mask |= 1 << i;
1078 if (tp_features.hotkey_wlsw) {
1079 set_bit(EV_SW, tpacpi_inputdev->evbit);
1080 set_bit(SW_RADIO, tpacpi_inputdev->swbit);
1083 #ifdef CONFIG_THINKPAD_ACPI_INPUT_ENABLED
1084 dbg_printk(TPACPI_DBG_INIT,
1085 "enabling hot key handling\n");
1086 res = hotkey_set(1, (hotkey_all_mask & ~hotkey_reserved_mask)
1087 | hotkey_orig_mask);
1090 #endif /* CONFIG_THINKPAD_ACPI_INPUT_ENABLED */
1093 return (tp_features.hotkey)? 0 : 1;
1096 static void hotkey_exit(void)
1100 if (tp_features.hotkey) {
1101 dbg_printk(TPACPI_DBG_EXIT, "restoring original hotkey mask\n");
1102 res = hotkey_set(hotkey_orig_status, hotkey_orig_mask);
1104 printk(IBM_ERR "failed to restore hotkey to BIOS defaults\n");
1107 if (hotkey_dev_attributes) {
1108 delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj);
1109 hotkey_dev_attributes = NULL;
1113 static void tpacpi_input_send_key(unsigned int scancode,
1114 unsigned int keycode)
1116 if (keycode != KEY_RESERVED) {
1117 input_report_key(tpacpi_inputdev, keycode, 1);
1118 if (keycode == KEY_UNKNOWN)
1119 input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN,
1121 input_sync(tpacpi_inputdev);
1123 input_report_key(tpacpi_inputdev, keycode, 0);
1124 if (keycode == KEY_UNKNOWN)
1125 input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN,
1127 input_sync(tpacpi_inputdev);
1131 static void tpacpi_input_send_radiosw(void)
1135 if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&wlsw))
1136 input_report_switch(tpacpi_inputdev,
1140 static void hotkey_notify(struct ibm_struct *ibm, u32 event)
1143 unsigned int keycode, scancode;
1146 if (event == 0x80 && acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) {
1147 if (tpacpi_inputdev->users > 0) {
1148 switch (hkey >> 12) {
1150 /* 0x1000-0x1FFF: key presses */
1151 scancode = hkey & 0xfff;
1152 if (scancode > 0 && scancode < 0x21) {
1154 keycode = hotkey_keycode_map[scancode];
1155 tpacpi_input_send_key(scancode, keycode);
1156 sendacpi = (keycode == KEY_RESERVED
1157 || keycode == KEY_UNKNOWN);
1160 "hotkey 0x%04x out of range for keyboard map\n",
1165 /* 0x5000-0x5FFF: LID */
1166 /* we don't handle it through this path, just
1167 * eat up known LID events */
1168 if (hkey != 0x5001 && hkey != 0x5002) {
1170 "unknown LID-related hotkey event: 0x%04x\n",
1175 /* 0x7000-0x7FFF: misc */
1176 if (tp_features.hotkey_wlsw && hkey == 0x7000) {
1177 tpacpi_input_send_radiosw();
1181 /* fallthrough to default */
1183 /* case 2: dock-related */
1184 /* 0x2305 - T43 waking up due to bay lever eject while aslept */
1185 /* case 3: ultra-bay related. maybe bay in dock? */
1186 /* 0x3003 - T43 after wake up by bay lever eject (0x2305) */
1187 printk(IBM_NOTICE "unhandled hotkey event 0x%04x\n", hkey);
1192 acpi_bus_generate_event(ibm->acpi->device, event, hkey);
1194 printk(IBM_ERR "unknown hotkey notification event %d\n", event);
1195 acpi_bus_generate_event(ibm->acpi->device, event, 0);
1199 static void hotkey_resume(void)
1201 tpacpi_input_send_radiosw();
1205 * Call with hotkey_mutex held
1207 static int hotkey_get(int *status, u32 *mask)
1209 if (!acpi_evalf(hkey_handle, status, "DHKC", "d"))
1212 if (tp_features.hotkey_mask)
1213 if (!acpi_evalf(hkey_handle, mask, "DHKN", "d"))
1220 * Call with hotkey_mutex held
1222 static int hotkey_set(int status, u32 mask)
1226 if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status))
1229 if (tp_features.hotkey_mask)
1230 for (i = 0; i < 32; i++) {
1231 int bit = ((1 << i) & mask) != 0;
1232 if (!acpi_evalf(hkey_handle,
1233 NULL, "MHKM", "vdd", i + 1, bit))
1240 /* procfs -------------------------------------------------------------- */
1241 static int hotkey_read(char *p)
1247 if (!tp_features.hotkey) {
1248 len += sprintf(p + len, "status:\t\tnot supported\n");
1252 res = mutex_lock_interruptible(&hotkey_mutex);
1255 res = hotkey_get(&status, &mask);
1256 mutex_unlock(&hotkey_mutex);
1260 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0));
1261 if (tp_features.hotkey_mask) {
1262 len += sprintf(p + len, "mask:\t\t0x%08x\n", mask);
1263 len += sprintf(p + len,
1264 "commands:\tenable, disable, reset, <mask>\n");
1266 len += sprintf(p + len, "mask:\t\tnot supported\n");
1267 len += sprintf(p + len, "commands:\tenable, disable, reset\n");
1273 static int hotkey_write(char *buf)
1280 if (!tp_features.hotkey)
1283 res = mutex_lock_interruptible(&hotkey_mutex);
1287 res = hotkey_get(&status, &mask);
1292 while ((cmd = next_cmd(&buf))) {
1293 if (strlencmp(cmd, "enable") == 0) {
1295 } else if (strlencmp(cmd, "disable") == 0) {
1297 } else if (strlencmp(cmd, "reset") == 0) {
1298 status = hotkey_orig_status;
1299 mask = hotkey_orig_mask;
1300 } else if (sscanf(cmd, "0x%x", &mask) == 1) {
1302 } else if (sscanf(cmd, "%x", &mask) == 1) {
1312 res = hotkey_set(status, mask);
1315 mutex_unlock(&hotkey_mutex);
1319 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = {
1320 .hid = IBM_HKEY_HID,
1321 .notify = hotkey_notify,
1322 .handle = &hkey_handle,
1323 .type = ACPI_DEVICE_NOTIFY,
1326 static struct ibm_struct hotkey_driver_data = {
1328 .read = hotkey_read,
1329 .write = hotkey_write,
1330 .exit = hotkey_exit,
1331 .resume = hotkey_resume,
1332 .acpi = &ibm_hotkey_acpidriver,
1335 /*************************************************************************
1336 * Bluetooth subdriver
1339 /* sysfs bluetooth enable ---------------------------------------------- */
1340 static ssize_t bluetooth_enable_show(struct device *dev,
1341 struct device_attribute *attr,
1346 status = bluetooth_get_radiosw();
1350 return snprintf(buf, PAGE_SIZE, "%d\n", status ? 1 : 0);
1353 static ssize_t bluetooth_enable_store(struct device *dev,
1354 struct device_attribute *attr,
1355 const char *buf, size_t count)
1360 if (parse_strtoul(buf, 1, &t))
1363 res = bluetooth_set_radiosw(t);
1365 return (res) ? res : count;
1368 static struct device_attribute dev_attr_bluetooth_enable =
1369 __ATTR(bluetooth_enable, S_IWUSR | S_IRUGO,
1370 bluetooth_enable_show, bluetooth_enable_store);
1372 /* --------------------------------------------------------------------- */
1374 static struct attribute *bluetooth_attributes[] = {
1375 &dev_attr_bluetooth_enable.attr,
1379 static const struct attribute_group bluetooth_attr_group = {
1380 .attrs = bluetooth_attributes,
1383 static int __init bluetooth_init(struct ibm_init_struct *iibm)
1388 vdbg_printk(TPACPI_DBG_INIT, "initializing bluetooth subdriver\n");
1390 IBM_ACPIHANDLE_INIT(hkey);
1392 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1393 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
1394 tp_features.bluetooth = hkey_handle &&
1395 acpi_evalf(hkey_handle, &status, "GBDC", "qd");
1397 vdbg_printk(TPACPI_DBG_INIT, "bluetooth is %s, status 0x%02x\n",
1398 str_supported(tp_features.bluetooth),
1401 if (tp_features.bluetooth) {
1402 if (!(status & TP_ACPI_BLUETOOTH_HWPRESENT)) {
1403 /* no bluetooth hardware present in system */
1404 tp_features.bluetooth = 0;
1405 dbg_printk(TPACPI_DBG_INIT,
1406 "bluetooth hardware not installed\n");
1408 res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
1409 &bluetooth_attr_group);
1415 return (tp_features.bluetooth)? 0 : 1;
1418 static void bluetooth_exit(void)
1420 sysfs_remove_group(&tpacpi_pdev->dev.kobj,
1421 &bluetooth_attr_group);
1424 static int bluetooth_get_radiosw(void)
1428 if (!tp_features.bluetooth)
1431 if (!acpi_evalf(hkey_handle, &status, "GBDC", "d"))
1434 return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0);
1437 static int bluetooth_set_radiosw(int radio_on)
1441 if (!tp_features.bluetooth)
1444 if (!acpi_evalf(hkey_handle, &status, "GBDC", "d"))
1447 status |= TP_ACPI_BLUETOOTH_RADIOSSW;
1449 status &= ~TP_ACPI_BLUETOOTH_RADIOSSW;
1450 if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status))
1456 /* procfs -------------------------------------------------------------- */
1457 static int bluetooth_read(char *p)
1460 int status = bluetooth_get_radiosw();
1462 if (!tp_features.bluetooth)
1463 len += sprintf(p + len, "status:\t\tnot supported\n");
1465 len += sprintf(p + len, "status:\t\t%s\n",
1466 (status)? "enabled" : "disabled");
1467 len += sprintf(p + len, "commands:\tenable, disable\n");
1473 static int bluetooth_write(char *buf)
1477 if (!tp_features.bluetooth)
1480 while ((cmd = next_cmd(&buf))) {
1481 if (strlencmp(cmd, "enable") == 0) {
1482 bluetooth_set_radiosw(1);
1483 } else if (strlencmp(cmd, "disable") == 0) {
1484 bluetooth_set_radiosw(0);
1492 static struct ibm_struct bluetooth_driver_data = {
1493 .name = "bluetooth",
1494 .read = bluetooth_read,
1495 .write = bluetooth_write,
1496 .exit = bluetooth_exit,
1499 /*************************************************************************
1503 /* sysfs wan enable ---------------------------------------------------- */
1504 static ssize_t wan_enable_show(struct device *dev,
1505 struct device_attribute *attr,
1510 status = wan_get_radiosw();
1514 return snprintf(buf, PAGE_SIZE, "%d\n", status ? 1 : 0);
1517 static ssize_t wan_enable_store(struct device *dev,
1518 struct device_attribute *attr,
1519 const char *buf, size_t count)
1524 if (parse_strtoul(buf, 1, &t))
1527 res = wan_set_radiosw(t);
1529 return (res) ? res : count;
1532 static struct device_attribute dev_attr_wan_enable =
1533 __ATTR(wwan_enable, S_IWUSR | S_IRUGO,
1534 wan_enable_show, wan_enable_store);
1536 /* --------------------------------------------------------------------- */
1538 static struct attribute *wan_attributes[] = {
1539 &dev_attr_wan_enable.attr,
1543 static const struct attribute_group wan_attr_group = {
1544 .attrs = wan_attributes,
1547 static int __init wan_init(struct ibm_init_struct *iibm)
1552 vdbg_printk(TPACPI_DBG_INIT, "initializing wan subdriver\n");
1554 IBM_ACPIHANDLE_INIT(hkey);
1556 tp_features.wan = hkey_handle &&
1557 acpi_evalf(hkey_handle, &status, "GWAN", "qd");
1559 vdbg_printk(TPACPI_DBG_INIT, "wan is %s, status 0x%02x\n",
1560 str_supported(tp_features.wan),
1563 if (tp_features.wan) {
1564 if (!(status & TP_ACPI_WANCARD_HWPRESENT)) {
1565 /* no wan hardware present in system */
1566 tp_features.wan = 0;
1567 dbg_printk(TPACPI_DBG_INIT,
1568 "wan hardware not installed\n");
1570 res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
1577 return (tp_features.wan)? 0 : 1;
1580 static void wan_exit(void)
1582 sysfs_remove_group(&tpacpi_pdev->dev.kobj,
1586 static int wan_get_radiosw(void)
1590 if (!tp_features.wan)
1593 if (!acpi_evalf(hkey_handle, &status, "GWAN", "d"))
1596 return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0);
1599 static int wan_set_radiosw(int radio_on)
1603 if (!tp_features.wan)
1606 if (!acpi_evalf(hkey_handle, &status, "GWAN", "d"))
1609 status |= TP_ACPI_WANCARD_RADIOSSW;
1611 status &= ~TP_ACPI_WANCARD_RADIOSSW;
1612 if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status))
1618 /* procfs -------------------------------------------------------------- */
1619 static int wan_read(char *p)
1622 int status = wan_get_radiosw();
1624 if (!tp_features.wan)
1625 len += sprintf(p + len, "status:\t\tnot supported\n");
1627 len += sprintf(p + len, "status:\t\t%s\n",
1628 (status)? "enabled" : "disabled");
1629 len += sprintf(p + len, "commands:\tenable, disable\n");
1635 static int wan_write(char *buf)
1639 if (!tp_features.wan)
1642 while ((cmd = next_cmd(&buf))) {
1643 if (strlencmp(cmd, "enable") == 0) {
1645 } else if (strlencmp(cmd, "disable") == 0) {
1654 static struct ibm_struct wan_driver_data = {
1659 .flags.experimental = 1,
1662 /*************************************************************************
1666 static enum video_access_mode video_supported;
1667 static int video_orig_autosw;
1669 IBM_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */
1670 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
1671 "\\_SB.PCI0.VID0", /* 770e */
1672 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
1673 "\\_SB.PCI0.AGP.VID", /* all others */
1676 IBM_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */
1678 static int __init video_init(struct ibm_init_struct *iibm)
1682 vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n");
1684 IBM_ACPIHANDLE_INIT(vid);
1685 IBM_ACPIHANDLE_INIT(vid2);
1687 if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga)
1688 /* G41, assume IVGA doesn't change */
1689 vid_handle = vid2_handle;
1692 /* video switching not supported on R30, R31 */
1693 video_supported = TPACPI_VIDEO_NONE;
1694 else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd"))
1696 video_supported = TPACPI_VIDEO_570;
1697 else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd"))
1698 /* 600e/x, 770e, 770x */
1699 video_supported = TPACPI_VIDEO_770;
1702 video_supported = TPACPI_VIDEO_NEW;
1704 vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n",
1705 str_supported(video_supported != TPACPI_VIDEO_NONE),
1708 return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1;
1711 static void video_exit(void)
1713 dbg_printk(TPACPI_DBG_EXIT,
1714 "restoring original video autoswitch mode\n");
1715 if (video_autosw_set(video_orig_autosw))
1716 printk(IBM_ERR "error while trying to restore original "
1717 "video autoswitch mode\n");
1720 static int video_outputsw_get(void)
1725 switch (video_supported) {
1726 case TPACPI_VIDEO_570:
1727 if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd",
1728 TP_ACPI_VIDEO_570_PHSCMD))
1730 status = i & TP_ACPI_VIDEO_570_PHSMASK;
1732 case TPACPI_VIDEO_770:
1733 if (!acpi_evalf(NULL, &i, "\\VCDL", "d"))
1736 status |= TP_ACPI_VIDEO_S_LCD;
1737 if (!acpi_evalf(NULL, &i, "\\VCDC", "d"))
1740 status |= TP_ACPI_VIDEO_S_CRT;
1742 case TPACPI_VIDEO_NEW:
1743 if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) ||
1744 !acpi_evalf(NULL, &i, "\\VCDC", "d"))
1747 status |= TP_ACPI_VIDEO_S_CRT;
1749 if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) ||
1750 !acpi_evalf(NULL, &i, "\\VCDL", "d"))
1753 status |= TP_ACPI_VIDEO_S_LCD;
1754 if (!acpi_evalf(NULL, &i, "\\VCDD", "d"))
1757 status |= TP_ACPI_VIDEO_S_DVI;
1766 static int video_outputsw_set(int status)
1771 switch (video_supported) {
1772 case TPACPI_VIDEO_570:
1773 res = acpi_evalf(NULL, NULL,
1774 "\\_SB.PHS2", "vdd",
1775 TP_ACPI_VIDEO_570_PHS2CMD,
1776 status | TP_ACPI_VIDEO_570_PHS2SET);
1778 case TPACPI_VIDEO_770:
1779 autosw = video_autosw_get();
1783 res = video_autosw_set(1);
1786 res = acpi_evalf(vid_handle, NULL,
1787 "ASWT", "vdd", status * 0x100, 0);
1788 if (!autosw && video_autosw_set(autosw)) {
1789 printk(IBM_ERR "video auto-switch left enabled due to error\n");
1793 case TPACPI_VIDEO_NEW:
1794 res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) &&
1795 acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1);
1801 return (res)? 0 : -EIO;
1804 static int video_autosw_get(void)
1808 switch (video_supported) {
1809 case TPACPI_VIDEO_570:
1810 if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d"))
1813 case TPACPI_VIDEO_770:
1814 case TPACPI_VIDEO_NEW:
1815 if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d"))
1825 static int video_autosw_set(int enable)
1827 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0))
1832 static int video_outputsw_cycle(void)
1834 int autosw = video_autosw_get();
1840 switch (video_supported) {
1841 case TPACPI_VIDEO_570:
1842 res = video_autosw_set(1);
1845 res = acpi_evalf(ec_handle, NULL, "_Q16", "v");
1847 case TPACPI_VIDEO_770:
1848 case TPACPI_VIDEO_NEW:
1849 res = video_autosw_set(1);
1852 res = acpi_evalf(vid_handle, NULL, "VSWT", "v");
1857 if (!autosw && video_autosw_set(autosw)) {
1858 printk(IBM_ERR "video auto-switch left enabled due to error\n");
1862 return (res)? 0 : -EIO;
1865 static int video_expand_toggle(void)
1867 switch (video_supported) {
1868 case TPACPI_VIDEO_570:
1869 return acpi_evalf(ec_handle, NULL, "_Q17", "v")?
1871 case TPACPI_VIDEO_770:
1872 return acpi_evalf(vid_handle, NULL, "VEXP", "v")?
1874 case TPACPI_VIDEO_NEW:
1875 return acpi_evalf(NULL, NULL, "\\VEXP", "v")?
1883 static int video_read(char *p)
1888 if (video_supported == TPACPI_VIDEO_NONE) {
1889 len += sprintf(p + len, "status:\t\tnot supported\n");
1893 status = video_outputsw_get();
1897 autosw = video_autosw_get();
1901 len += sprintf(p + len, "status:\t\tsupported\n");
1902 len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0));
1903 len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1));
1904 if (video_supported == TPACPI_VIDEO_NEW)
1905 len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3));
1906 len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0));
1907 len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n");
1908 len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n");
1909 if (video_supported == TPACPI_VIDEO_NEW)
1910 len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n");
1911 len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n");
1912 len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n");
1917 static int video_write(char *buf)
1920 int enable, disable, status;
1923 if (video_supported == TPACPI_VIDEO_NONE)
1929 while ((cmd = next_cmd(&buf))) {
1930 if (strlencmp(cmd, "lcd_enable") == 0) {
1931 enable |= TP_ACPI_VIDEO_S_LCD;
1932 } else if (strlencmp(cmd, "lcd_disable") == 0) {
1933 disable |= TP_ACPI_VIDEO_S_LCD;
1934 } else if (strlencmp(cmd, "crt_enable") == 0) {
1935 enable |= TP_ACPI_VIDEO_S_CRT;
1936 } else if (strlencmp(cmd, "crt_disable") == 0) {
1937 disable |= TP_ACPI_VIDEO_S_CRT;
1938 } else if (video_supported == TPACPI_VIDEO_NEW &&
1939 strlencmp(cmd, "dvi_enable") == 0) {
1940 enable |= TP_ACPI_VIDEO_S_DVI;
1941 } else if (video_supported == TPACPI_VIDEO_NEW &&
1942 strlencmp(cmd, "dvi_disable") == 0) {
1943 disable |= TP_ACPI_VIDEO_S_DVI;
1944 } else if (strlencmp(cmd, "auto_enable") == 0) {
1945 res = video_autosw_set(1);
1948 } else if (strlencmp(cmd, "auto_disable") == 0) {
1949 res = video_autosw_set(0);
1952 } else if (strlencmp(cmd, "video_switch") == 0) {
1953 res = video_outputsw_cycle();
1956 } else if (strlencmp(cmd, "expand_toggle") == 0) {
1957 res = video_expand_toggle();
1964 if (enable || disable) {
1965 status = video_outputsw_get();
1968 res = video_outputsw_set((status & ~disable) | enable);
1976 static struct ibm_struct video_driver_data = {
1979 .write = video_write,
1983 /*************************************************************************
1984 * Light (thinklight) subdriver
1987 IBM_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
1988 IBM_HANDLE(ledb, ec, "LEDB"); /* G4x */
1990 static int __init light_init(struct ibm_init_struct *iibm)
1992 vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n");
1994 IBM_ACPIHANDLE_INIT(ledb);
1995 IBM_ACPIHANDLE_INIT(lght);
1996 IBM_ACPIHANDLE_INIT(cmos);
1998 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
1999 tp_features.light = (cmos_handle || lght_handle) && !ledb_handle;
2001 if (tp_features.light)
2002 /* light status not supported on
2003 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
2004 tp_features.light_status =
2005 acpi_evalf(ec_handle, NULL, "KBLT", "qv");
2007 vdbg_printk(TPACPI_DBG_INIT, "light is %s\n",
2008 str_supported(tp_features.light));
2010 return (tp_features.light)? 0 : 1;
2013 static int light_read(char *p)
2018 if (!tp_features.light) {
2019 len += sprintf(p + len, "status:\t\tnot supported\n");
2020 } else if (!tp_features.light_status) {
2021 len += sprintf(p + len, "status:\t\tunknown\n");
2022 len += sprintf(p + len, "commands:\ton, off\n");
2024 if (!acpi_evalf(ec_handle, &status, "KBLT", "d"))
2026 len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0));
2027 len += sprintf(p + len, "commands:\ton, off\n");
2033 static int light_write(char *buf)
2035 int cmos_cmd, lght_cmd;
2039 if (!tp_features.light)
2042 while ((cmd = next_cmd(&buf))) {
2043 if (strlencmp(cmd, "on") == 0) {
2046 } else if (strlencmp(cmd, "off") == 0) {
2052 success = cmos_handle ?
2053 acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd) :
2054 acpi_evalf(lght_handle, NULL, NULL, "vd", lght_cmd);
2062 static struct ibm_struct light_driver_data = {
2065 .write = light_write,
2068 /*************************************************************************
2072 #ifdef CONFIG_THINKPAD_ACPI_DOCK
2074 IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */
2075 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
2076 "\\_SB.PCI0.PCI1.DOCK", /* all others */
2077 "\\_SB.PCI.ISA.SLCE", /* 570 */
2078 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
2080 /* don't list other alternatives as we install a notify handler on the 570 */
2081 IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */
2083 static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = {
2085 .notify = dock_notify,
2086 .handle = &dock_handle,
2087 .type = ACPI_SYSTEM_NOTIFY,
2090 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
2091 * We just use it to get notifications of dock hotplug
2092 * in very old thinkpads */
2093 .hid = PCI_ROOT_HID_STRING,
2094 .notify = dock_notify,
2095 .handle = &pci_handle,
2096 .type = ACPI_SYSTEM_NOTIFY,
2100 static struct ibm_struct dock_driver_data[2] = {
2104 .write = dock_write,
2105 .acpi = &ibm_dock_acpidriver[0],
2109 .acpi = &ibm_dock_acpidriver[1],
2113 #define dock_docked() (_sta(dock_handle) & 1)
2115 static int __init dock_init(struct ibm_init_struct *iibm)
2117 vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver\n");
2119 IBM_ACPIHANDLE_INIT(dock);
2121 vdbg_printk(TPACPI_DBG_INIT, "dock is %s\n",
2122 str_supported(dock_handle != NULL));
2124 return (dock_handle)? 0 : 1;
2127 static int __init dock_init2(struct ibm_init_struct *iibm)
2131 vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver part 2\n");
2133 if (dock_driver_data[0].flags.acpi_driver_registered &&
2134 dock_driver_data[0].flags.acpi_notify_installed) {
2135 IBM_ACPIHANDLE_INIT(pci);
2136 dock2_needed = (pci_handle != NULL);
2137 vdbg_printk(TPACPI_DBG_INIT,
2138 "dock PCI handler for the TP 570 is %s\n",
2139 str_supported(dock2_needed));
2141 vdbg_printk(TPACPI_DBG_INIT,
2142 "dock subdriver part 2 not required\n");
2146 return (dock2_needed)? 0 : 1;
2149 static void dock_notify(struct ibm_struct *ibm, u32 event)
2151 int docked = dock_docked();
2152 int pci = ibm->acpi->hid && strstr(ibm->acpi->hid, PCI_ROOT_HID_STRING);
2154 if (event == 1 && !pci) /* 570 */
2155 acpi_bus_generate_event(ibm->acpi->device, event, 1); /* button */
2156 else if (event == 1 && pci) /* 570 */
2157 acpi_bus_generate_event(ibm->acpi->device, event, 3); /* dock */
2158 else if (event == 3 && docked)
2159 acpi_bus_generate_event(ibm->acpi->device, event, 1); /* button */
2160 else if (event == 3 && !docked)
2161 acpi_bus_generate_event(ibm->acpi->device, event, 2); /* undock */
2162 else if (event == 0 && docked)
2163 acpi_bus_generate_event(ibm->acpi->device, event, 3); /* dock */
2165 printk(IBM_ERR "unknown dock event %d, status %d\n",
2166 event, _sta(dock_handle));
2167 acpi_bus_generate_event(ibm->acpi->device, event, 0); /* unknown */
2171 static int dock_read(char *p)
2174 int docked = dock_docked();
2177 len += sprintf(p + len, "status:\t\tnot supported\n");
2179 len += sprintf(p + len, "status:\t\tundocked\n");
2181 len += sprintf(p + len, "status:\t\tdocked\n");
2182 len += sprintf(p + len, "commands:\tdock, undock\n");
2188 static int dock_write(char *buf)
2195 while ((cmd = next_cmd(&buf))) {
2196 if (strlencmp(cmd, "undock") == 0) {
2197 if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0) ||
2198 !acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1))
2200 } else if (strlencmp(cmd, "dock") == 0) {
2201 if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1))
2210 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
2212 /*************************************************************************
2216 #ifdef CONFIG_THINKPAD_ACPI_BAY
2217 IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
2218 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
2219 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
2220 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
2221 ); /* A21e, R30, R31 */
2222 IBM_HANDLE(bay_ej, bay, "_EJ3", /* 600e/x, A2xm/p, A3x */
2223 "_EJ0", /* all others */
2224 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
2225 IBM_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
2226 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
2228 IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */
2232 static int __init bay_init(struct ibm_init_struct *iibm)
2234 vdbg_printk(TPACPI_DBG_INIT, "initializing bay subdriver\n");
2236 IBM_ACPIHANDLE_INIT(bay);
2238 IBM_ACPIHANDLE_INIT(bay_ej);
2239 IBM_ACPIHANDLE_INIT(bay2);
2241 IBM_ACPIHANDLE_INIT(bay2_ej);
2243 tp_features.bay_status = bay_handle &&
2244 acpi_evalf(bay_handle, NULL, "_STA", "qv");
2245 tp_features.bay_status2 = bay2_handle &&
2246 acpi_evalf(bay2_handle, NULL, "_STA", "qv");
2248 tp_features.bay_eject = bay_handle && bay_ej_handle &&
2249 (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental);
2250 tp_features.bay_eject2 = bay2_handle && bay2_ej_handle &&
2251 (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental);
2253 vdbg_printk(TPACPI_DBG_INIT,
2254 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
2255 str_supported(tp_features.bay_status),
2256 str_supported(tp_features.bay_eject),
2257 str_supported(tp_features.bay_status2),
2258 str_supported(tp_features.bay_eject2));
2260 return (tp_features.bay_status || tp_features.bay_eject ||
2261 tp_features.bay_status2 || tp_features.bay_eject2)? 0 : 1;
2264 static void bay_notify(struct ibm_struct *ibm, u32 event)
2266 acpi_bus_generate_event(ibm->acpi->device, event, 0);
2269 #define bay_occupied(b) (_sta(b##_handle) & 1)
2271 static int bay_read(char *p)
2274 int occupied = bay_occupied(bay);
2275 int occupied2 = bay_occupied(bay2);
2278 len += sprintf(p + len, "status:\t\t%s\n",
2279 tp_features.bay_status ?
2280 (occupied ? "occupied" : "unoccupied") :
2282 if (tp_features.bay_status2)
2283 len += sprintf(p + len, "status2:\t%s\n", occupied2 ?
2284 "occupied" : "unoccupied");
2286 eject = tp_features.bay_eject && occupied;
2287 eject2 = tp_features.bay_eject2 && occupied2;
2289 if (eject && eject2)
2290 len += sprintf(p + len, "commands:\teject, eject2\n");
2292 len += sprintf(p + len, "commands:\teject\n");
2294 len += sprintf(p + len, "commands:\teject2\n");
2299 static int bay_write(char *buf)
2303 if (!tp_features.bay_eject && !tp_features.bay_eject2)
2306 while ((cmd = next_cmd(&buf))) {
2307 if (tp_features.bay_eject && strlencmp(cmd, "eject") == 0) {
2308 if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1))
2310 } else if (tp_features.bay_eject2 &&
2311 strlencmp(cmd, "eject2") == 0) {
2312 if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1))
2321 static struct tp_acpi_drv_struct ibm_bay_acpidriver = {
2322 .notify = bay_notify,
2323 .handle = &bay_handle,
2324 .type = ACPI_SYSTEM_NOTIFY,
2327 static struct ibm_struct bay_driver_data = {
2331 .acpi = &ibm_bay_acpidriver,
2334 #endif /* CONFIG_THINKPAD_ACPI_BAY */
2336 /*************************************************************************
2340 /* sysfs cmos_command -------------------------------------------------- */
2341 static ssize_t cmos_command_store(struct device *dev,
2342 struct device_attribute *attr,
2343 const char *buf, size_t count)
2345 unsigned long cmos_cmd;
2348 if (parse_strtoul(buf, 21, &cmos_cmd))
2351 res = issue_thinkpad_cmos_command(cmos_cmd);
2352 return (res)? res : count;
2355 static struct device_attribute dev_attr_cmos_command =
2356 __ATTR(cmos_command, S_IWUSR, NULL, cmos_command_store);
2358 /* --------------------------------------------------------------------- */
2360 static int __init cmos_init(struct ibm_init_struct *iibm)
2364 vdbg_printk(TPACPI_DBG_INIT,
2365 "initializing cmos commands subdriver\n");
2367 IBM_ACPIHANDLE_INIT(cmos);
2369 vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n",
2370 str_supported(cmos_handle != NULL));
2372 res = device_create_file(&tpacpi_pdev->dev, &dev_attr_cmos_command);
2376 return (cmos_handle)? 0 : 1;
2379 static void cmos_exit(void)
2381 device_remove_file(&tpacpi_pdev->dev, &dev_attr_cmos_command);
2384 static int cmos_read(char *p)
2388 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2389 R30, R31, T20-22, X20-21 */
2391 len += sprintf(p + len, "status:\t\tnot supported\n");
2393 len += sprintf(p + len, "status:\t\tsupported\n");
2394 len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n");
2400 static int cmos_write(char *buf)
2405 while ((cmd = next_cmd(&buf))) {
2406 if (sscanf(cmd, "%u", &cmos_cmd) == 1 &&
2407 cmos_cmd >= 0 && cmos_cmd <= 21) {
2412 res = issue_thinkpad_cmos_command(cmos_cmd);
2420 static struct ibm_struct cmos_driver_data = {
2423 .write = cmos_write,
2427 /*************************************************************************
2431 static enum led_access_mode led_supported;
2433 IBM_HANDLE(led, ec, "SLED", /* 570 */
2434 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2435 "LED", /* all others */
2438 static int __init led_init(struct ibm_init_struct *iibm)
2440 vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n");
2442 IBM_ACPIHANDLE_INIT(led);
2445 /* led not supported on R30, R31 */
2446 led_supported = TPACPI_LED_NONE;
2447 else if (strlencmp(led_path, "SLED") == 0)
2449 led_supported = TPACPI_LED_570;
2450 else if (strlencmp(led_path, "SYSL") == 0)
2451 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2452 led_supported = TPACPI_LED_OLD;
2455 led_supported = TPACPI_LED_NEW;
2457 vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n",
2458 str_supported(led_supported), led_supported);
2460 return (led_supported != TPACPI_LED_NONE)? 0 : 1;
2463 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
2465 static int led_read(char *p)
2469 if (!led_supported) {
2470 len += sprintf(p + len, "status:\t\tnot supported\n");
2473 len += sprintf(p + len, "status:\t\tsupported\n");
2475 if (led_supported == TPACPI_LED_570) {
2478 for (i = 0; i < 8; i++) {
2479 if (!acpi_evalf(ec_handle,
2480 &status, "GLED", "dd", 1 << i))
2482 len += sprintf(p + len, "%d:\t\t%s\n",
2483 i, led_status(status));
2487 len += sprintf(p + len, "commands:\t"
2488 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
2493 /* off, on, blink */
2494 static const int led_sled_arg1[] = { 0, 1, 3 };
2495 static const int led_exp_hlbl[] = { 0, 0, 1 }; /* led# * */
2496 static const int led_exp_hlcl[] = { 0, 1, 1 }; /* led# * */
2497 static const int led_led_arg1[] = { 0, 0x80, 0xc0 };
2499 static int led_write(char *buf)
2507 while ((cmd = next_cmd(&buf))) {
2508 if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 7)
2511 if (strstr(cmd, "off")) {
2513 } else if (strstr(cmd, "on")) {
2515 } else if (strstr(cmd, "blink")) {
2520 if (led_supported == TPACPI_LED_570) {
2523 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
2524 led, led_sled_arg1[ind]))
2526 } else if (led_supported == TPACPI_LED_OLD) {
2527 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
2529 ret = ec_write(TPACPI_LED_EC_HLMS, led);
2532 ec_write(TPACPI_LED_EC_HLBL,
2533 led * led_exp_hlbl[ind]);
2536 ec_write(TPACPI_LED_EC_HLCL,
2537 led * led_exp_hlcl[ind]);
2542 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
2543 led, led_led_arg1[ind]))
2551 static struct ibm_struct led_driver_data = {
2557 /*************************************************************************
2561 IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */
2563 static int __init beep_init(struct ibm_init_struct *iibm)
2565 vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n");
2567 IBM_ACPIHANDLE_INIT(beep);
2569 vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n",
2570 str_supported(beep_handle != NULL));
2572 return (beep_handle)? 0 : 1;
2575 static int beep_read(char *p)
2580 len += sprintf(p + len, "status:\t\tnot supported\n");
2582 len += sprintf(p + len, "status:\t\tsupported\n");
2583 len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n");
2589 static int beep_write(char *buf)
2597 while ((cmd = next_cmd(&buf))) {
2598 if (sscanf(cmd, "%u", &beep_cmd) == 1 &&
2599 beep_cmd >= 0 && beep_cmd <= 17) {
2603 if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", beep_cmd, 0))
2610 static struct ibm_struct beep_driver_data = {
2613 .write = beep_write,
2616 /*************************************************************************
2620 static enum thermal_access_mode thermal_read_mode;
2622 /* sysfs temp##_input -------------------------------------------------- */
2624 static ssize_t thermal_temp_input_show(struct device *dev,
2625 struct device_attribute *attr,
2628 struct sensor_device_attribute *sensor_attr =
2629 to_sensor_dev_attr(attr);
2630 int idx = sensor_attr->index;
2634 res = thermal_get_sensor(idx, &value);
2637 if (value == TP_EC_THERMAL_TMP_NA * 1000)
2640 return snprintf(buf, PAGE_SIZE, "%d\n", value);
2643 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
2644 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB)
2646 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input[] = {
2647 THERMAL_SENSOR_ATTR_TEMP(1, 0),
2648 THERMAL_SENSOR_ATTR_TEMP(2, 1),
2649 THERMAL_SENSOR_ATTR_TEMP(3, 2),
2650 THERMAL_SENSOR_ATTR_TEMP(4, 3),
2651 THERMAL_SENSOR_ATTR_TEMP(5, 4),
2652 THERMAL_SENSOR_ATTR_TEMP(6, 5),
2653 THERMAL_SENSOR_ATTR_TEMP(7, 6),
2654 THERMAL_SENSOR_ATTR_TEMP(8, 7),
2655 THERMAL_SENSOR_ATTR_TEMP(9, 8),
2656 THERMAL_SENSOR_ATTR_TEMP(10, 9),
2657 THERMAL_SENSOR_ATTR_TEMP(11, 10),
2658 THERMAL_SENSOR_ATTR_TEMP(12, 11),
2659 THERMAL_SENSOR_ATTR_TEMP(13, 12),
2660 THERMAL_SENSOR_ATTR_TEMP(14, 13),
2661 THERMAL_SENSOR_ATTR_TEMP(15, 14),
2662 THERMAL_SENSOR_ATTR_TEMP(16, 15),
2665 #define THERMAL_ATTRS(X) \
2666 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
2668 static struct attribute *thermal_temp_input_attr[] = {
2688 static const struct attribute_group thermal_temp_input16_group = {
2689 .attrs = thermal_temp_input_attr
2692 static const struct attribute_group thermal_temp_input8_group = {
2693 .attrs = &thermal_temp_input_attr[8]
2696 #undef THERMAL_SENSOR_ATTR_TEMP
2697 #undef THERMAL_ATTRS
2699 /* --------------------------------------------------------------------- */
2701 static int __init thermal_init(struct ibm_init_struct *iibm)
2708 vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n");
2710 acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv");
2712 if (thinkpad_id.ec_model) {
2714 * Direct EC access mode: sensors at registers
2715 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
2716 * non-implemented, thermal sensors return 0x80 when
2721 for (i = 0; i < 8; i++) {
2722 if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) {
2728 if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) {
2736 /* This is sheer paranoia, but we handle it anyway */
2739 "ThinkPad ACPI EC access misbehaving, "
2740 "falling back to ACPI TMPx access mode\n");
2741 thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07;
2744 "ThinkPad ACPI EC access misbehaving, "
2745 "disabling thermal sensors access\n");
2746 thermal_read_mode = TPACPI_THERMAL_NONE;
2751 TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8;
2753 } else if (acpi_tmp7) {
2754 if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) {
2755 /* 600e/x, 770e, 770x */
2756 thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT;
2758 /* Standard ACPI TMPx access, max 8 sensors */
2759 thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07;
2762 /* temperatures not supported on 570, G4x, R30, R31, R32 */
2763 thermal_read_mode = TPACPI_THERMAL_NONE;
2766 vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n",
2767 str_supported(thermal_read_mode != TPACPI_THERMAL_NONE),
2770 switch(thermal_read_mode) {
2771 case TPACPI_THERMAL_TPEC_16:
2772 res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
2773 &thermal_temp_input16_group);
2777 case TPACPI_THERMAL_TPEC_8:
2778 case TPACPI_THERMAL_ACPI_TMP07:
2779 case TPACPI_THERMAL_ACPI_UPDT:
2780 res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
2781 &thermal_temp_input8_group);
2785 case TPACPI_THERMAL_NONE:
2793 static void thermal_exit(void)
2795 switch(thermal_read_mode) {
2796 case TPACPI_THERMAL_TPEC_16:
2797 sysfs_remove_group(&tpacpi_pdev->dev.kobj,
2798 &thermal_temp_input16_group);
2800 case TPACPI_THERMAL_TPEC_8:
2801 case TPACPI_THERMAL_ACPI_TMP07:
2802 case TPACPI_THERMAL_ACPI_UPDT:
2803 sysfs_remove_group(&tpacpi_pdev->dev.kobj,
2804 &thermal_temp_input16_group);
2806 case TPACPI_THERMAL_NONE:
2812 /* idx is zero-based */
2813 static int thermal_get_sensor(int idx, s32 *value)
2819 t = TP_EC_THERMAL_TMP0;
2821 switch (thermal_read_mode) {
2822 #if TPACPI_MAX_THERMAL_SENSORS >= 16
2823 case TPACPI_THERMAL_TPEC_16:
2824 if (idx >= 8 && idx <= 15) {
2825 t = TP_EC_THERMAL_TMP8;
2830 case TPACPI_THERMAL_TPEC_8:
2832 if (!acpi_ec_read(t + idx, &tmp))
2834 *value = tmp * 1000;
2839 case TPACPI_THERMAL_ACPI_UPDT:
2841 snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
2842 if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
2844 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
2846 *value = (t - 2732) * 100;
2851 case TPACPI_THERMAL_ACPI_TMP07:
2853 snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
2854 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
2856 if (t > 127 || t < -127)
2857 t = TP_EC_THERMAL_TMP_NA;
2863 case TPACPI_THERMAL_NONE:
2871 static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
2882 if (thermal_read_mode == TPACPI_THERMAL_TPEC_16)
2885 for(i = 0 ; i < n; i++) {
2886 res = thermal_get_sensor(i, &s->temp[i]);
2894 static int thermal_read(char *p)
2898 struct ibm_thermal_sensors_struct t;
2900 n = thermal_get_sensors(&t);
2901 if (unlikely(n < 0))
2904 len += sprintf(p + len, "temperatures:\t");
2907 for (i = 0; i < (n - 1); i++)
2908 len += sprintf(p + len, "%d ", t.temp[i] / 1000);
2909 len += sprintf(p + len, "%d\n", t.temp[i] / 1000);
2911 len += sprintf(p + len, "not supported\n");
2916 static struct ibm_struct thermal_driver_data = {
2918 .read = thermal_read,
2919 .exit = thermal_exit,
2922 /*************************************************************************
2926 static u8 ecdump_regs[256];
2928 static int ecdump_read(char *p)
2934 len += sprintf(p + len, "EC "
2935 " +00 +01 +02 +03 +04 +05 +06 +07"
2936 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
2937 for (i = 0; i < 256; i += 16) {
2938 len += sprintf(p + len, "EC 0x%02x:", i);
2939 for (j = 0; j < 16; j++) {
2940 if (!acpi_ec_read(i + j, &v))
2942 if (v != ecdump_regs[i + j])
2943 len += sprintf(p + len, " *%02x", v);
2945 len += sprintf(p + len, " %02x", v);
2946 ecdump_regs[i + j] = v;
2948 len += sprintf(p + len, "\n");
2953 /* These are way too dangerous to advertise openly... */
2955 len += sprintf(p + len, "commands:\t0x<offset> 0x<value>"
2956 " (<offset> is 00-ff, <value> is 00-ff)\n");
2957 len += sprintf(p + len, "commands:\t0x<offset> <value> "
2958 " (<offset> is 00-ff, <value> is 0-255)\n");
2963 static int ecdump_write(char *buf)
2968 while ((cmd = next_cmd(&buf))) {
2969 if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) {
2971 } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) {
2975 if (i >= 0 && i < 256 && v >= 0 && v < 256) {
2976 if (!acpi_ec_write(i, v))
2985 static struct ibm_struct ecdump_driver_data = {
2987 .read = ecdump_read,
2988 .write = ecdump_write,
2989 .flags.experimental = 1,
2992 /*************************************************************************
2993 * Backlight/brightness subdriver
2996 static struct backlight_device *ibm_backlight_device;
2998 static struct backlight_ops ibm_backlight_data = {
2999 .get_brightness = brightness_get,
3000 .update_status = brightness_update_status,
3003 static struct mutex brightness_mutex;
3005 static int __init brightness_init(struct ibm_init_struct *iibm)
3009 vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n");
3011 mutex_init(&brightness_mutex);
3013 if (!brightness_mode) {
3014 if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO)
3015 brightness_mode = 2;
3017 brightness_mode = 3;
3019 dbg_printk(TPACPI_DBG_INIT, "selected brightness_mode=%d\n",
3023 if (brightness_mode > 3)
3026 b = brightness_get(NULL);
3030 ibm_backlight_device = backlight_device_register(
3031 TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL,
3032 &ibm_backlight_data);
3033 if (IS_ERR(ibm_backlight_device)) {
3034 printk(IBM_ERR "Could not register backlight device\n");
3035 return PTR_ERR(ibm_backlight_device);
3037 vdbg_printk(TPACPI_DBG_INIT, "brightness is supported\n");
3039 ibm_backlight_device->props.max_brightness = 7;
3040 ibm_backlight_device->props.brightness = b;
3041 backlight_update_status(ibm_backlight_device);
3046 static void brightness_exit(void)
3048 if (ibm_backlight_device) {
3049 vdbg_printk(TPACPI_DBG_EXIT,
3050 "calling backlight_device_unregister()\n");
3051 backlight_device_unregister(ibm_backlight_device);
3052 ibm_backlight_device = NULL;
3056 static int brightness_update_status(struct backlight_device *bd)
3058 return brightness_set(
3059 (bd->props.fb_blank == FB_BLANK_UNBLANK &&
3060 bd->props.power == FB_BLANK_UNBLANK) ?
3061 bd->props.brightness : 0);
3065 * ThinkPads can read brightness from two places: EC 0x31, or
3066 * CMOS NVRAM byte 0x5E, bits 0-3.
3068 static int brightness_get(struct backlight_device *bd)
3070 u8 lec = 0, lcmos = 0, level = 0;
3072 if (brightness_mode & 1) {
3073 if (!acpi_ec_read(brightness_offset, &lec))
3078 if (brightness_mode & 2) {
3079 lcmos = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS)
3080 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS)
3081 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS;
3085 if (brightness_mode == 3 && lec != lcmos) {
3087 "CMOS NVRAM (%u) and EC (%u) do not agree "
3088 "on display brightness level\n",
3089 (unsigned int) lcmos,
3090 (unsigned int) lec);
3097 static int brightness_set(int value)
3099 int cmos_cmd, inc, i, res;
3105 res = mutex_lock_interruptible(&brightness_mutex);
3109 current_value = brightness_get(NULL);
3110 if (current_value < 0) {
3111 res = current_value;
3115 cmos_cmd = value > current_value ?
3116 TP_CMOS_BRIGHTNESS_UP :
3117 TP_CMOS_BRIGHTNESS_DOWN;
3118 inc = value > current_value ? 1 : -1;
3121 for (i = current_value; i != value; i += inc) {
3122 if ((brightness_mode & 2) &&
3123 issue_thinkpad_cmos_command(cmos_cmd)) {
3127 if ((brightness_mode & 1) &&
3128 !acpi_ec_write(brightness_offset, i + inc)) {
3135 mutex_unlock(&brightness_mutex);
3139 static int brightness_read(char *p)
3144 if ((level = brightness_get(NULL)) < 0) {
3145 len += sprintf(p + len, "level:\t\tunreadable\n");
3147 len += sprintf(p + len, "level:\t\t%d\n", level & 0x7);
3148 len += sprintf(p + len, "commands:\tup, down\n");
3149 len += sprintf(p + len, "commands:\tlevel <level>"
3150 " (<level> is 0-7)\n");
3156 static int brightness_write(char *buf)
3162 while ((cmd = next_cmd(&buf))) {
3163 if ((level = brightness_get(NULL)) < 0)
3167 if (strlencmp(cmd, "up") == 0) {
3168 new_level = level == 7 ? 7 : level + 1;
3169 } else if (strlencmp(cmd, "down") == 0) {
3170 new_level = level == 0 ? 0 : level - 1;
3171 } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
3172 new_level >= 0 && new_level <= 7) {
3177 brightness_set(new_level);
3183 static struct ibm_struct brightness_driver_data = {
3184 .name = "brightness",
3185 .read = brightness_read,
3186 .write = brightness_write,
3187 .exit = brightness_exit,
3190 /*************************************************************************
3194 static int volume_read(char *p)
3199 if (!acpi_ec_read(volume_offset, &level)) {
3200 len += sprintf(p + len, "level:\t\tunreadable\n");
3202 len += sprintf(p + len, "level:\t\t%d\n", level & 0xf);
3203 len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6));
3204 len += sprintf(p + len, "commands:\tup, down, mute\n");
3205 len += sprintf(p + len, "commands:\tlevel <level>"
3206 " (<level> is 0-15)\n");
3212 static int volume_write(char *buf)
3214 int cmos_cmd, inc, i;
3216 int new_level, new_mute;
3219 while ((cmd = next_cmd(&buf))) {
3220 if (!acpi_ec_read(volume_offset, &level))
3222 new_mute = mute = level & 0x40;
3223 new_level = level = level & 0xf;
3225 if (strlencmp(cmd, "up") == 0) {
3229 new_level = level == 15 ? 15 : level + 1;
3230 } else if (strlencmp(cmd, "down") == 0) {
3234 new_level = level == 0 ? 0 : level - 1;
3235 } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
3236 new_level >= 0 && new_level <= 15) {
3238 } else if (strlencmp(cmd, "mute") == 0) {
3243 if (new_level != level) { /* mute doesn't change */
3244 cmos_cmd = new_level > level ? TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN;
3245 inc = new_level > level ? 1 : -1;
3247 if (mute && (issue_thinkpad_cmos_command(cmos_cmd) ||
3248 !acpi_ec_write(volume_offset, level)))
3251 for (i = level; i != new_level; i += inc)
3252 if (issue_thinkpad_cmos_command(cmos_cmd) ||
3253 !acpi_ec_write(volume_offset, i + inc))
3256 if (mute && (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE) ||
3257 !acpi_ec_write(volume_offset,
3262 if (new_mute != mute) { /* level doesn't change */
3263 cmos_cmd = new_mute ? TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP;
3265 if (issue_thinkpad_cmos_command(cmos_cmd) ||
3266 !acpi_ec_write(volume_offset, level + new_mute))
3274 static struct ibm_struct volume_driver_data = {
3276 .read = volume_read,
3277 .write = volume_write,
3280 /*************************************************************************
3287 * TPACPI_FAN_RD_ACPI_GFAN:
3288 * ACPI GFAN method: returns fan level
3290 * see TPACPI_FAN_WR_ACPI_SFAN
3291 * EC 0x2f (HFSP) not available if GFAN exists
3293 * TPACPI_FAN_WR_ACPI_SFAN:
3294 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
3296 * EC 0x2f (HFSP) might be available *for reading*, but do not use
3299 * TPACPI_FAN_WR_TPEC:
3300 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
3301 * Supported on almost all ThinkPads
3303 * Fan speed changes of any sort (including those caused by the
3304 * disengaged mode) are usually done slowly by the firmware as the
3305 * maximum ammount of fan duty cycle change per second seems to be
3308 * Reading is not available if GFAN exists.
3309 * Writing is not available if SFAN exists.
3312 * 7 automatic mode engaged;
3313 * (default operation mode of the ThinkPad)
3314 * fan level is ignored in this mode.
3315 * 6 full speed mode (takes precedence over bit 7);
3316 * not available on all thinkpads. May disable
3317 * the tachometer while the fan controller ramps up
3318 * the speed (which can take up to a few *minutes*).
3319 * Speeds up fan to 100% duty-cycle, which is far above
3320 * the standard RPM levels. It is not impossible that
3321 * it could cause hardware damage.
3322 * 5-3 unused in some models. Extra bits for fan level
3323 * in others, but still useless as all values above
3324 * 7 map to the same speed as level 7 in these models.
3325 * 2-0 fan level (0..7 usually)
3327 * 0x07 = max (set when temperatures critical)
3328 * Some ThinkPads may have other levels, see
3329 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
3331 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
3332 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
3333 * does so, its initial value is meaningless (0x07).
3335 * For firmware bugs, refer to:
3336 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3340 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
3341 * Main fan tachometer reading (in RPM)
3343 * This register is present on all ThinkPads with a new-style EC, and
3344 * it is known not to be present on the A21m/e, and T22, as there is
3345 * something else in offset 0x84 according to the ACPI DSDT. Other
3346 * ThinkPads from this same time period (and earlier) probably lack the
3347 * tachometer as well.
3349 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
3350 * was never fixed by IBM to report the EC firmware version string
3351 * probably support the tachometer (like the early X models), so
3352 * detecting it is quite hard. We need more data to know for sure.
3354 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
3357 * FIRMWARE BUG: may go stale while the EC is switching to full speed
3360 * For firmware bugs, refer to:
3361 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3363 * TPACPI_FAN_WR_ACPI_FANS:
3364 * ThinkPad X31, X40, X41. Not available in the X60.
3366 * FANS ACPI handle: takes three arguments: low speed, medium speed,
3367 * high speed. ACPI DSDT seems to map these three speeds to levels
3368 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
3369 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
3371 * The speeds are stored on handles
3372 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
3374 * There are three default speed sets, acessible as handles:
3375 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
3377 * ACPI DSDT switches which set is in use depending on various
3380 * TPACPI_FAN_WR_TPEC is also available and should be used to
3381 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
3382 * but the ACPI tables just mention level 7.
3385 static enum fan_status_access_mode fan_status_access_mode;
3386 static enum fan_control_access_mode fan_control_access_mode;
3387 static enum fan_control_commands fan_control_commands;
3389 static u8 fan_control_initial_status;
3390 static u8 fan_control_desired_level;
3392 static void fan_watchdog_fire(struct work_struct *ignored);
3393 static int fan_watchdog_maxinterval;
3394 static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire);
3396 IBM_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */
3397 IBM_HANDLE(gfan, ec, "GFAN", /* 570 */
3398 "\\FSPD", /* 600e/x, 770e, 770x */
3400 IBM_HANDLE(sfan, ec, "SFAN", /* 570 */
3401 "JFNS", /* 770x-JL */
3405 * SYSFS fan layout: hwmon compatible (device)
3408 * 0: "disengaged" mode
3410 * 2: native EC "auto" mode (recommended, hardware default)
3412 * pwm*: set speed in manual mode, ignored otherwise.
3413 * 0 is level 0; 255 is level 7. Intermediate points done with linear
3416 * fan*_input: tachometer reading, RPM
3419 * SYSFS fan layout: extensions
3421 * fan_watchdog (driver):
3422 * fan watchdog interval in seconds, 0 disables (default), max 120
3425 /* sysfs fan pwm1_enable ----------------------------------------------- */
3426 static ssize_t fan_pwm1_enable_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 /* Return most likely status. In fact, it
3442 * might be the only possible status */
3443 status = TP_EC_FAN_AUTO;
3447 if (status & TP_EC_FAN_FULLSPEED) {
3449 } else if (status & TP_EC_FAN_AUTO) {
3454 return snprintf(buf, PAGE_SIZE, "%d\n", mode);
3457 static ssize_t fan_pwm1_enable_store(struct device *dev,
3458 struct device_attribute *attr,
3459 const char *buf, size_t count)
3464 if (parse_strtoul(buf, 2, &t))
3469 level = TP_EC_FAN_FULLSPEED;
3472 level = TPACPI_FAN_LAST_LEVEL;
3475 level = TP_EC_FAN_AUTO;
3478 /* reserved for software-controlled auto mode */
3484 res = fan_set_level_safe(level);
3490 fan_watchdog_reset();
3495 static struct device_attribute dev_attr_fan_pwm1_enable =
3496 __ATTR(pwm1_enable, S_IWUSR | S_IRUGO,
3497 fan_pwm1_enable_show, fan_pwm1_enable_store);
3499 /* sysfs fan pwm1 ------------------------------------------------------ */
3500 static ssize_t fan_pwm1_show(struct device *dev,
3501 struct device_attribute *attr,
3507 res = fan_get_status_safe(&status);
3511 if (unlikely(tp_features.fan_ctrl_status_undef)) {
3512 if (status != fan_control_initial_status) {
3513 tp_features.fan_ctrl_status_undef = 0;
3515 status = TP_EC_FAN_AUTO;
3520 (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) != 0)
3521 status = fan_control_desired_level;
3526 return snprintf(buf, PAGE_SIZE, "%u\n", (status * 255) / 7);
3529 static ssize_t fan_pwm1_store(struct device *dev,
3530 struct device_attribute *attr,
3531 const char *buf, size_t count)
3535 u8 status, newlevel;
3537 if (parse_strtoul(buf, 255, &s))
3540 /* scale down from 0-255 to 0-7 */
3541 newlevel = (s >> 5) & 0x07;
3543 rc = mutex_lock_interruptible(&fan_mutex);
3547 rc = fan_get_status(&status);
3548 if (!rc && (status &
3549 (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) {
3550 rc = fan_set_level(newlevel);
3554 fan_update_desired_level(newlevel);
3555 fan_watchdog_reset();
3559 mutex_unlock(&fan_mutex);
3560 return (rc)? rc : count;
3563 static struct device_attribute dev_attr_fan_pwm1 =
3564 __ATTR(pwm1, S_IWUSR | S_IRUGO,
3565 fan_pwm1_show, fan_pwm1_store);
3567 /* sysfs fan fan1_input ------------------------------------------------ */
3568 static ssize_t fan_fan1_input_show(struct device *dev,
3569 struct device_attribute *attr,
3575 res = fan_get_speed(&speed);
3579 return snprintf(buf, PAGE_SIZE, "%u\n", speed);
3582 static struct device_attribute dev_attr_fan_fan1_input =
3583 __ATTR(fan1_input, S_IRUGO,
3584 fan_fan1_input_show, NULL);
3586 /* sysfs fan fan_watchdog (driver) ------------------------------------- */
3587 static ssize_t fan_fan_watchdog_show(struct device_driver *drv,
3590 return snprintf(buf, PAGE_SIZE, "%u\n", fan_watchdog_maxinterval);
3593 static ssize_t fan_fan_watchdog_store(struct device_driver *drv,
3594 const char *buf, size_t count)
3598 if (parse_strtoul(buf, 120, &t))
3601 if (!fan_control_allowed)
3604 fan_watchdog_maxinterval = t;
3605 fan_watchdog_reset();
3610 static DRIVER_ATTR(fan_watchdog, S_IWUSR | S_IRUGO,
3611 fan_fan_watchdog_show, fan_fan_watchdog_store);
3613 /* --------------------------------------------------------------------- */
3614 static struct attribute *fan_attributes[] = {
3615 &dev_attr_fan_pwm1_enable.attr, &dev_attr_fan_pwm1.attr,
3616 &dev_attr_fan_fan1_input.attr,
3620 static const struct attribute_group fan_attr_group = {
3621 .attrs = fan_attributes,
3624 static int __init fan_init(struct ibm_init_struct *iibm)
3628 vdbg_printk(TPACPI_DBG_INIT, "initializing fan subdriver\n");
3630 mutex_init(&fan_mutex);
3631 fan_status_access_mode = TPACPI_FAN_NONE;
3632 fan_control_access_mode = TPACPI_FAN_WR_NONE;
3633 fan_control_commands = 0;
3634 fan_watchdog_maxinterval = 0;
3635 tp_features.fan_ctrl_status_undef = 0;
3636 fan_control_desired_level = 7;
3638 IBM_ACPIHANDLE_INIT(fans);
3639 IBM_ACPIHANDLE_INIT(gfan);
3640 IBM_ACPIHANDLE_INIT(sfan);
3643 /* 570, 600e/x, 770e, 770x */
3644 fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN;
3646 /* all other ThinkPads: note that even old-style
3647 * ThinkPad ECs supports the fan control register */
3648 if (likely(acpi_ec_read(fan_status_offset,
3649 &fan_control_initial_status))) {
3650 fan_status_access_mode = TPACPI_FAN_RD_TPEC;
3652 /* In some ThinkPads, neither the EC nor the ACPI
3653 * DSDT initialize the fan status, and it ends up
3654 * being set to 0x07 when it *could* be either
3657 * Enable for TP-1Y (T43), TP-78 (R51e),
3658 * TP-76 (R52), TP-70 (T43, R52), which are known
3660 if (fan_control_initial_status == 0x07) {
3661 switch (thinkpad_id.ec_model) {
3662 case 0x5931: /* TP-1Y */
3663 case 0x3837: /* TP-78 */
3664 case 0x3637: /* TP-76 */
3665 case 0x3037: /* TP-70 */
3667 "fan_init: initial fan status is "
3668 "unknown, assuming it is in auto "
3670 tp_features.fan_ctrl_status_undef = 1;
3676 "ThinkPad ACPI EC access misbehaving, "
3677 "fan status and control unavailable\n");
3684 fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN;
3685 fan_control_commands |=
3686 TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE;
3689 /* gfan without sfan means no fan control */
3690 /* all other models implement TP EC 0x2f control */
3694 fan_control_access_mode =
3695 TPACPI_FAN_WR_ACPI_FANS;
3696 fan_control_commands |=
3697 TPACPI_FAN_CMD_SPEED |
3698 TPACPI_FAN_CMD_LEVEL |
3699 TPACPI_FAN_CMD_ENABLE;
3701 fan_control_access_mode = TPACPI_FAN_WR_TPEC;
3702 fan_control_commands |=
3703 TPACPI_FAN_CMD_LEVEL |
3704 TPACPI_FAN_CMD_ENABLE;
3709 vdbg_printk(TPACPI_DBG_INIT, "fan is %s, modes %d, %d\n",
3710 str_supported(fan_status_access_mode != TPACPI_FAN_NONE ||
3711 fan_control_access_mode != TPACPI_FAN_WR_NONE),
3712 fan_status_access_mode, fan_control_access_mode);
3714 /* fan control master switch */
3715 if (!fan_control_allowed) {
3716 fan_control_access_mode = TPACPI_FAN_WR_NONE;
3717 fan_control_commands = 0;
3718 dbg_printk(TPACPI_DBG_INIT,
3719 "fan control features disabled by parameter\n");
3722 /* update fan_control_desired_level */
3723 if (fan_status_access_mode != TPACPI_FAN_NONE)
3724 fan_get_status_safe(NULL);
3726 if (fan_status_access_mode != TPACPI_FAN_NONE ||
3727 fan_control_access_mode != TPACPI_FAN_WR_NONE) {
3728 rc = sysfs_create_group(&tpacpi_pdev->dev.kobj,
3731 rc = driver_create_file(&tpacpi_pdriver.driver,
3732 &driver_attr_fan_watchdog);
3741 * Call with fan_mutex held
3743 static void fan_update_desired_level(u8 status)
3746 (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) {
3748 fan_control_desired_level = 7;
3750 fan_control_desired_level = status;
3754 static int fan_get_status(u8 *status)
3759 * Add TPACPI_FAN_RD_ACPI_FANS ? */
3761 switch (fan_status_access_mode) {
3762 case TPACPI_FAN_RD_ACPI_GFAN:
3763 /* 570, 600e/x, 770e, 770x */
3765 if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d")))
3773 case TPACPI_FAN_RD_TPEC:
3774 /* all except 570, 600e/x, 770e, 770x */
3775 if (unlikely(!acpi_ec_read(fan_status_offset, &s)))
3790 static int fan_get_status_safe(u8 *status)
3795 rc = mutex_lock_interruptible(&fan_mutex);
3798 rc = fan_get_status(&s);
3800 fan_update_desired_level(s);
3801 mutex_unlock(&fan_mutex);
3809 static void fan_exit(void)
3811 vdbg_printk(TPACPI_DBG_EXIT, "cancelling any pending fan watchdog tasks\n");
3813 /* FIXME: can we really do this unconditionally? */
3814 sysfs_remove_group(&tpacpi_pdev->dev.kobj, &fan_attr_group);
3815 driver_remove_file(&tpacpi_pdriver.driver, &driver_attr_fan_watchdog);
3817 cancel_delayed_work(&fan_watchdog_task);
3818 flush_scheduled_work();
3821 static int fan_get_speed(unsigned int *speed)
3825 switch (fan_status_access_mode) {
3826 case TPACPI_FAN_RD_TPEC:
3827 /* all except 570, 600e/x, 770e, 770x */
3828 if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) ||
3829 !acpi_ec_read(fan_rpm_offset + 1, &hi)))
3833 *speed = (hi << 8) | lo;
3844 static void fan_watchdog_fire(struct work_struct *ignored)
3848 printk(IBM_NOTICE "fan watchdog: enabling fan\n");
3849 rc = fan_set_enable();
3851 printk(IBM_ERR "fan watchdog: error %d while enabling fan, "
3852 "will try again later...\n", -rc);
3853 /* reschedule for later */
3854 fan_watchdog_reset();
3858 static void fan_watchdog_reset(void)
3860 static int fan_watchdog_active;
3862 if (fan_control_access_mode == TPACPI_FAN_WR_NONE)
3865 if (fan_watchdog_active)
3866 cancel_delayed_work(&fan_watchdog_task);
3868 if (fan_watchdog_maxinterval > 0) {
3869 fan_watchdog_active = 1;
3870 if (!schedule_delayed_work(&fan_watchdog_task,
3871 msecs_to_jiffies(fan_watchdog_maxinterval
3873 printk(IBM_ERR "failed to schedule the fan watchdog, "
3874 "watchdog will not trigger\n");
3877 fan_watchdog_active = 0;
3880 static int fan_set_level(int level)
3882 if (!fan_control_allowed)
3885 switch (fan_control_access_mode) {
3886 case TPACPI_FAN_WR_ACPI_SFAN:
3887 if (level >= 0 && level <= 7) {
3888 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level))
3894 case TPACPI_FAN_WR_ACPI_FANS:
3895 case TPACPI_FAN_WR_TPEC:
3896 if ((level != TP_EC_FAN_AUTO) &&
3897 (level != TP_EC_FAN_FULLSPEED) &&
3898 ((level < 0) || (level > 7)))
3901 /* safety net should the EC not support AUTO
3902 * or FULLSPEED mode bits and just ignore them */
3903 if (level & TP_EC_FAN_FULLSPEED)
3904 level |= 7; /* safety min speed 7 */
3905 else if (level & TP_EC_FAN_FULLSPEED)
3906 level |= 4; /* safety min speed 4 */
3908 if (!acpi_ec_write(fan_status_offset, level))
3911 tp_features.fan_ctrl_status_undef = 0;
3920 static int fan_set_level_safe(int level)
3924 if (!fan_control_allowed)
3927 rc = mutex_lock_interruptible(&fan_mutex);
3931 if (level == TPACPI_FAN_LAST_LEVEL)
3932 level = fan_control_desired_level;
3934 rc = fan_set_level(level);
3936 fan_update_desired_level(level);
3938 mutex_unlock(&fan_mutex);
3942 static int fan_set_enable(void)
3947 if (!fan_control_allowed)
3950 rc = mutex_lock_interruptible(&fan_mutex);
3954 switch (fan_control_access_mode) {
3955 case TPACPI_FAN_WR_ACPI_FANS:
3956 case TPACPI_FAN_WR_TPEC:
3957 rc = fan_get_status(&s);
3961 /* Don't go out of emergency fan mode */
3964 s |= TP_EC_FAN_AUTO | 4; /* min fan speed 4 */
3967 if (!acpi_ec_write(fan_status_offset, s))
3970 tp_features.fan_ctrl_status_undef = 0;
3975 case TPACPI_FAN_WR_ACPI_SFAN:
3976 rc = fan_get_status(&s);
3982 /* Set fan to at least level 4 */
3985 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s))
3995 mutex_unlock(&fan_mutex);
3999 static int fan_set_disable(void)
4003 if (!fan_control_allowed)
4006 rc = mutex_lock_interruptible(&fan_mutex);
4011 switch (fan_control_access_mode) {
4012 case TPACPI_FAN_WR_ACPI_FANS:
4013 case TPACPI_FAN_WR_TPEC:
4014 if (!acpi_ec_write(fan_status_offset, 0x00))
4017 fan_control_desired_level = 0;
4018 tp_features.fan_ctrl_status_undef = 0;
4022 case TPACPI_FAN_WR_ACPI_SFAN:
4023 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00))
4026 fan_control_desired_level = 0;
4034 mutex_unlock(&fan_mutex);
4038 static int fan_set_speed(int speed)
4042 if (!fan_control_allowed)
4045 rc = mutex_lock_interruptible(&fan_mutex);
4050 switch (fan_control_access_mode) {
4051 case TPACPI_FAN_WR_ACPI_FANS:
4052 if (speed >= 0 && speed <= 65535) {
4053 if (!acpi_evalf(fans_handle, NULL, NULL, "vddd",
4054 speed, speed, speed))
4064 mutex_unlock(&fan_mutex);
4068 static int fan_read(char *p)
4073 unsigned int speed = 0;
4075 switch (fan_status_access_mode) {
4076 case TPACPI_FAN_RD_ACPI_GFAN:
4077 /* 570, 600e/x, 770e, 770x */
4078 if ((rc = fan_get_status_safe(&status)) < 0)
4081 len += sprintf(p + len, "status:\t\t%s\n"
4083 (status != 0) ? "enabled" : "disabled", status);
4086 case TPACPI_FAN_RD_TPEC:
4087 /* all except 570, 600e/x, 770e, 770x */
4088 if ((rc = fan_get_status_safe(&status)) < 0)
4091 if (unlikely(tp_features.fan_ctrl_status_undef)) {
4092 if (status != fan_control_initial_status)
4093 tp_features.fan_ctrl_status_undef = 0;
4095 /* Return most likely status. In fact, it
4096 * might be the only possible status */
4097 status = TP_EC_FAN_AUTO;
4100 len += sprintf(p + len, "status:\t\t%s\n",
4101 (status != 0) ? "enabled" : "disabled");
4103 if ((rc = fan_get_speed(&speed)) < 0)
4106 len += sprintf(p + len, "speed:\t\t%d\n", speed);
4108 if (status & TP_EC_FAN_FULLSPEED)
4109 /* Disengaged mode takes precedence */
4110 len += sprintf(p + len, "level:\t\tdisengaged\n");
4111 else if (status & TP_EC_FAN_AUTO)
4112 len += sprintf(p + len, "level:\t\tauto\n");
4114 len += sprintf(p + len, "level:\t\t%d\n", status);
4117 case TPACPI_FAN_NONE:
4119 len += sprintf(p + len, "status:\t\tnot supported\n");
4122 if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) {
4123 len += sprintf(p + len, "commands:\tlevel <level>");
4125 switch (fan_control_access_mode) {
4126 case TPACPI_FAN_WR_ACPI_SFAN:
4127 len += sprintf(p + len, " (<level> is 0-7)\n");
4131 len += sprintf(p + len, " (<level> is 0-7, "
4132 "auto, disengaged, full-speed)\n");
4137 if (fan_control_commands & TPACPI_FAN_CMD_ENABLE)
4138 len += sprintf(p + len, "commands:\tenable, disable\n"
4139 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
4140 "1-120 (seconds))\n");
4142 if (fan_control_commands & TPACPI_FAN_CMD_SPEED)
4143 len += sprintf(p + len, "commands:\tspeed <speed>"
4144 " (<speed> is 0-65535)\n");
4149 static int fan_write_cmd_level(const char *cmd, int *rc)
4153 if (strlencmp(cmd, "level auto") == 0)
4154 level = TP_EC_FAN_AUTO;
4155 else if ((strlencmp(cmd, "level disengaged") == 0) |
4156 (strlencmp(cmd, "level full-speed") == 0))
4157 level = TP_EC_FAN_FULLSPEED;
4158 else if (sscanf(cmd, "level %d", &level) != 1)
4161 if ((*rc = fan_set_level_safe(level)) == -ENXIO)
4162 printk(IBM_ERR "level command accepted for unsupported "
4163 "access mode %d", fan_control_access_mode);
4168 static int fan_write_cmd_enable(const char *cmd, int *rc)
4170 if (strlencmp(cmd, "enable") != 0)
4173 if ((*rc = fan_set_enable()) == -ENXIO)
4174 printk(IBM_ERR "enable command accepted for unsupported "
4175 "access mode %d", fan_control_access_mode);
4180 static int fan_write_cmd_disable(const char *cmd, int *rc)
4182 if (strlencmp(cmd, "disable") != 0)
4185 if ((*rc = fan_set_disable()) == -ENXIO)
4186 printk(IBM_ERR "disable command accepted for unsupported "
4187 "access mode %d", fan_control_access_mode);
4192 static int fan_write_cmd_speed(const char *cmd, int *rc)
4197 * Support speed <low> <medium> <high> ? */
4199 if (sscanf(cmd, "speed %d", &speed) != 1)
4202 if ((*rc = fan_set_speed(speed)) == -ENXIO)
4203 printk(IBM_ERR "speed command accepted for unsupported "
4204 "access mode %d", fan_control_access_mode);
4209 static int fan_write_cmd_watchdog(const char *cmd, int *rc)
4213 if (sscanf(cmd, "watchdog %d", &interval) != 1)
4216 if (interval < 0 || interval > 120)
4219 fan_watchdog_maxinterval = interval;
4224 static int fan_write(char *buf)
4229 while (!rc && (cmd = next_cmd(&buf))) {
4230 if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) &&
4231 fan_write_cmd_level(cmd, &rc)) &&
4232 !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) &&
4233 (fan_write_cmd_enable(cmd, &rc) ||
4234 fan_write_cmd_disable(cmd, &rc) ||
4235 fan_write_cmd_watchdog(cmd, &rc))) &&
4236 !((fan_control_commands & TPACPI_FAN_CMD_SPEED) &&
4237 fan_write_cmd_speed(cmd, &rc))
4241 fan_watchdog_reset();
4247 static struct ibm_struct fan_driver_data = {
4254 /****************************************************************************
4255 ****************************************************************************
4259 ****************************************************************************
4260 ****************************************************************************/
4263 static struct proc_dir_entry *proc_dir;
4265 /* Subdriver registry */
4266 static LIST_HEAD(tpacpi_all_drivers);
4270 * Module and infrastructure proble, init and exit handling
4273 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
4274 static const char * __init str_supported(int is_supported)
4276 static char text_unsupported[] __initdata = "not supported";
4278 return (is_supported)? &text_unsupported[4] : &text_unsupported[0];
4280 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
4282 static int __init ibm_init(struct ibm_init_struct *iibm)
4285 struct ibm_struct *ibm = iibm->data;
4286 struct proc_dir_entry *entry;
4288 BUG_ON(ibm == NULL);
4290 INIT_LIST_HEAD(&ibm->all_drivers);
4292 if (ibm->flags.experimental && !experimental)
4295 dbg_printk(TPACPI_DBG_INIT,
4296 "probing for %s\n", ibm->name);
4299 ret = iibm->init(iibm);
4301 return 0; /* probe failed */
4305 ibm->flags.init_called = 1;
4309 if (ibm->acpi->hid) {
4310 ret = register_tpacpi_subdriver(ibm);
4315 if (ibm->acpi->notify) {
4316 ret = setup_acpi_notify(ibm);
4317 if (ret == -ENODEV) {
4318 printk(IBM_NOTICE "disabling subdriver %s\n",
4328 dbg_printk(TPACPI_DBG_INIT,
4329 "%s installed\n", ibm->name);
4332 entry = create_proc_entry(ibm->name,
4333 S_IFREG | S_IRUGO | S_IWUSR,
4336 printk(IBM_ERR "unable to create proc entry %s\n",
4341 entry->owner = THIS_MODULE;
4343 entry->read_proc = &dispatch_procfs_read;
4345 entry->write_proc = &dispatch_procfs_write;
4346 ibm->flags.proc_created = 1;
4349 list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers);
4354 dbg_printk(TPACPI_DBG_INIT,
4355 "%s: at error exit path with result %d\n",
4359 return (ret < 0)? ret : 0;
4362 static void ibm_exit(struct ibm_struct *ibm)
4364 dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name);
4366 list_del_init(&ibm->all_drivers);
4368 if (ibm->flags.acpi_notify_installed) {
4369 dbg_printk(TPACPI_DBG_EXIT,
4370 "%s: acpi_remove_notify_handler\n", ibm->name);
4372 acpi_remove_notify_handler(*ibm->acpi->handle,
4374 dispatch_acpi_notify);
4375 ibm->flags.acpi_notify_installed = 0;
4376 ibm->flags.acpi_notify_installed = 0;
4379 if (ibm->flags.proc_created) {
4380 dbg_printk(TPACPI_DBG_EXIT,
4381 "%s: remove_proc_entry\n", ibm->name);
4382 remove_proc_entry(ibm->name, proc_dir);
4383 ibm->flags.proc_created = 0;
4386 if (ibm->flags.acpi_driver_registered) {
4387 dbg_printk(TPACPI_DBG_EXIT,
4388 "%s: acpi_bus_unregister_driver\n", ibm->name);
4390 acpi_bus_unregister_driver(ibm->acpi->driver);
4391 kfree(ibm->acpi->driver);
4392 ibm->acpi->driver = NULL;
4393 ibm->flags.acpi_driver_registered = 0;
4396 if (ibm->flags.init_called && ibm->exit) {
4398 ibm->flags.init_called = 0;
4401 dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name);
4406 static void __init get_thinkpad_model_data(struct thinkpad_id_data *tp)
4408 struct dmi_device *dev = NULL;
4409 char ec_fw_string[18];
4414 memset(tp, 0, sizeof(*tp));
4416 if (dmi_name_in_vendors("IBM"))
4417 tp->vendor = PCI_VENDOR_ID_IBM;
4418 else if (dmi_name_in_vendors("LENOVO"))
4419 tp->vendor = PCI_VENDOR_ID_LENOVO;
4423 tp->bios_version_str = kstrdup(dmi_get_system_info(DMI_BIOS_VERSION),
4425 if (!tp->bios_version_str)
4427 tp->bios_model = tp->bios_version_str[0]
4428 | (tp->bios_version_str[1] << 8);
4431 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
4432 * X32 or newer, all Z series; Some models must have an
4433 * up-to-date BIOS or they will not be detected.
4435 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
4437 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
4438 if (sscanf(dev->name,
4439 "IBM ThinkPad Embedded Controller -[%17c",
4440 ec_fw_string) == 1) {
4441 ec_fw_string[sizeof(ec_fw_string) - 1] = 0;
4442 ec_fw_string[strcspn(ec_fw_string, " ]")] = 0;
4444 tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL);
4445 tp->ec_model = ec_fw_string[0]
4446 | (ec_fw_string[1] << 8);
4451 tp->model_str = kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION),
4453 if (strnicmp(tp->model_str, "ThinkPad", 8) != 0) {
4454 kfree(tp->model_str);
4455 tp->model_str = NULL;
4459 static int __init probe_for_thinkpad(void)
4467 * Non-ancient models have better DMI tagging, but very old models
4470 is_thinkpad = (thinkpad_id.model_str != NULL);
4472 /* ec is required because many other handles are relative to it */
4473 IBM_ACPIHANDLE_INIT(ec);
4477 "Not yet supported ThinkPad detected!\n");
4482 * Risks a regression on very old machines, but reduces potential
4483 * false positives a damn great deal
4486 is_thinkpad = (thinkpad_id.vendor == PCI_VENDOR_ID_IBM);
4488 if (!is_thinkpad && !force_load)
4495 /* Module init, exit, parameters */
4497 static struct ibm_init_struct ibms_init[] __initdata = {
4499 .init = thinkpad_acpi_driver_init,
4500 .data = &thinkpad_acpi_driver_data,
4503 .init = hotkey_init,
4504 .data = &hotkey_driver_data,
4507 .init = bluetooth_init,
4508 .data = &bluetooth_driver_data,
4512 .data = &wan_driver_data,
4516 .data = &video_driver_data,
4520 .data = &light_driver_data,
4522 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4525 .data = &dock_driver_data[0],
4529 .data = &dock_driver_data[1],
4532 #ifdef CONFIG_THINKPAD_ACPI_BAY
4535 .data = &bay_driver_data,
4540 .data = &cmos_driver_data,
4544 .data = &led_driver_data,
4548 .data = &beep_driver_data,
4551 .init = thermal_init,
4552 .data = &thermal_driver_data,
4555 .data = &ecdump_driver_data,
4558 .init = brightness_init,
4559 .data = &brightness_driver_data,
4562 .data = &volume_driver_data,
4566 .data = &fan_driver_data,
4570 static int __init set_ibm_param(const char *val, struct kernel_param *kp)
4573 struct ibm_struct *ibm;
4575 for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
4576 ibm = ibms_init[i].data;
4577 BUG_ON(ibm == NULL);
4579 if (strcmp(ibm->name, kp->name) == 0 && ibm->write) {
4580 if (strlen(val) > sizeof(ibms_init[i].param) - 2)
4582 strcpy(ibms_init[i].param, val);
4583 strcat(ibms_init[i].param, ",");
4591 static int experimental;
4592 module_param(experimental, int, 0);
4594 static u32 dbg_level;
4595 module_param_named(debug, dbg_level, uint, 0);
4597 static int force_load;
4598 module_param(force_load, bool, 0);
4600 static int fan_control_allowed;
4601 module_param_named(fan_control, fan_control_allowed, bool, 0);
4603 static int brightness_mode;
4604 module_param_named(brightness_mode, brightness_mode, int, 0);
4606 #define IBM_PARAM(feature) \
4607 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
4610 IBM_PARAM(bluetooth);
4613 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4616 #ifdef CONFIG_THINKPAD_ACPI_BAY
4618 #endif /* CONFIG_THINKPAD_ACPI_BAY */
4623 IBM_PARAM(brightness);
4627 static int __init thinkpad_acpi_module_init(void)
4631 /* Driver-level probe */
4633 get_thinkpad_model_data(&thinkpad_id);
4634 ret = probe_for_thinkpad();
4636 thinkpad_acpi_module_exit();
4640 /* Driver initialization */
4642 IBM_ACPIHANDLE_INIT(ecrd);
4643 IBM_ACPIHANDLE_INIT(ecwr);
4645 proc_dir = proc_mkdir(IBM_PROC_DIR, acpi_root_dir);
4647 printk(IBM_ERR "unable to create proc dir " IBM_PROC_DIR);
4648 thinkpad_acpi_module_exit();
4651 proc_dir->owner = THIS_MODULE;
4653 ret = platform_driver_register(&tpacpi_pdriver);
4655 printk(IBM_ERR "unable to register platform driver\n");
4656 thinkpad_acpi_module_exit();
4659 ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver);
4661 printk(IBM_ERR "unable to create sysfs driver attributes\n");
4662 thinkpad_acpi_module_exit();
4667 /* Device initialization */
4668 tpacpi_pdev = platform_device_register_simple(IBM_DRVR_NAME, -1,
4670 if (IS_ERR(tpacpi_pdev)) {
4671 ret = PTR_ERR(tpacpi_pdev);
4673 printk(IBM_ERR "unable to register platform device\n");
4674 thinkpad_acpi_module_exit();
4677 tpacpi_hwmon = hwmon_device_register(&tpacpi_pdev->dev);
4678 if (IS_ERR(tpacpi_hwmon)) {
4679 ret = PTR_ERR(tpacpi_hwmon);
4680 tpacpi_hwmon = NULL;
4681 printk(IBM_ERR "unable to register hwmon device\n");
4682 thinkpad_acpi_module_exit();
4685 tpacpi_inputdev = input_allocate_device();
4686 if (!tpacpi_inputdev) {
4687 printk(IBM_ERR "unable to allocate input device\n");
4688 thinkpad_acpi_module_exit();
4691 /* Prepare input device, but don't register */
4692 tpacpi_inputdev->name = "ThinkPad Extra Buttons";
4693 tpacpi_inputdev->phys = IBM_DRVR_NAME "/input0";
4694 tpacpi_inputdev->id.bustype = BUS_HOST;
4695 tpacpi_inputdev->id.vendor = (thinkpad_id.vendor) ?
4696 thinkpad_id.vendor :
4698 tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT;
4699 tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION;
4701 for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
4702 ret = ibm_init(&ibms_init[i]);
4703 if (ret >= 0 && *ibms_init[i].param)
4704 ret = ibms_init[i].data->write(ibms_init[i].param);
4706 thinkpad_acpi_module_exit();
4710 ret = input_register_device(tpacpi_inputdev);
4712 printk(IBM_ERR "unable to register input device\n");
4713 thinkpad_acpi_module_exit();
4716 tp_features.input_device_registered = 1;
4722 static void thinkpad_acpi_module_exit(void)
4724 struct ibm_struct *ibm, *itmp;
4726 list_for_each_entry_safe_reverse(ibm, itmp,
4727 &tpacpi_all_drivers,
4732 dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n");
4734 if (tpacpi_inputdev) {
4735 if (tp_features.input_device_registered)
4736 input_unregister_device(tpacpi_inputdev);
4738 input_free_device(tpacpi_inputdev);
4742 hwmon_device_unregister(tpacpi_hwmon);
4745 platform_device_unregister(tpacpi_pdev);
4747 tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver);
4748 platform_driver_unregister(&tpacpi_pdriver);
4751 remove_proc_entry(IBM_PROC_DIR, acpi_root_dir);
4753 kfree(thinkpad_id.bios_version_str);
4754 kfree(thinkpad_id.ec_version_str);
4755 kfree(thinkpad_id.model_str);
4758 module_init(thinkpad_acpi_module_init);
4759 module_exit(thinkpad_acpi_module_exit);