2 * thinkpad_acpi.c - ThinkPad ACPI Extras
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006-2008 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 TPACPI_VERSION "0.21"
25 #define TPACPI_SYSFS_VERSION 0x020200
29 * 2007-10-20 changelog trimmed down
31 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
34 * 2006-11-22 0.13 new maintainer
35 * changelog now lives in git commit history, and will
36 * not be updated further in-file.
38 * 2005-03-17 0.11 support for 600e, 770x
39 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
41 * 2005-01-16 0.9 use MODULE_VERSION
42 * thanks to Henrik Brix Andersen <brix@gentoo.org>
43 * fix parameter passing on module loading
44 * thanks to Rusty Russell <rusty@rustcorp.com.au>
45 * thanks to Jim Radford <radford@blackbean.org>
46 * 2004-11-08 0.8 fix init error case, don't return from a macro
47 * thanks to Chris Wright <chrisw@osdl.org>
50 #include <linux/kernel.h>
51 #include <linux/module.h>
52 #include <linux/init.h>
53 #include <linux/types.h>
54 #include <linux/string.h>
55 #include <linux/list.h>
56 #include <linux/mutex.h>
57 #include <linux/kthread.h>
58 #include <linux/freezer.h>
59 #include <linux/delay.h>
61 #include <linux/nvram.h>
62 #include <linux/proc_fs.h>
63 #include <linux/sysfs.h>
64 #include <linux/backlight.h>
66 #include <linux/platform_device.h>
67 #include <linux/hwmon.h>
68 #include <linux/hwmon-sysfs.h>
69 #include <linux/input.h>
70 #include <linux/leds.h>
71 #include <linux/rfkill.h>
72 #include <asm/uaccess.h>
74 #include <linux/dmi.h>
75 #include <linux/jiffies.h>
76 #include <linux/workqueue.h>
78 #include <acpi/acpi_drivers.h>
79 #include <acpi/acnamesp.h>
81 #include <linux/pci_ids.h>
84 /* ThinkPad CMOS commands */
85 #define TP_CMOS_VOLUME_DOWN 0
86 #define TP_CMOS_VOLUME_UP 1
87 #define TP_CMOS_VOLUME_MUTE 2
88 #define TP_CMOS_BRIGHTNESS_UP 4
89 #define TP_CMOS_BRIGHTNESS_DOWN 5
90 #define TP_CMOS_THINKLIGHT_ON 12
91 #define TP_CMOS_THINKLIGHT_OFF 13
95 TP_NVRAM_ADDR_HK2
= 0x57,
96 TP_NVRAM_ADDR_THINKLIGHT
= 0x58,
97 TP_NVRAM_ADDR_VIDEO
= 0x59,
98 TP_NVRAM_ADDR_BRIGHTNESS
= 0x5e,
99 TP_NVRAM_ADDR_MIXER
= 0x60,
102 /* NVRAM bit masks */
104 TP_NVRAM_MASK_HKT_THINKPAD
= 0x08,
105 TP_NVRAM_MASK_HKT_ZOOM
= 0x20,
106 TP_NVRAM_MASK_HKT_DISPLAY
= 0x40,
107 TP_NVRAM_MASK_HKT_HIBERNATE
= 0x80,
108 TP_NVRAM_MASK_THINKLIGHT
= 0x10,
109 TP_NVRAM_MASK_HKT_DISPEXPND
= 0x30,
110 TP_NVRAM_MASK_HKT_BRIGHTNESS
= 0x20,
111 TP_NVRAM_MASK_LEVEL_BRIGHTNESS
= 0x0f,
112 TP_NVRAM_POS_LEVEL_BRIGHTNESS
= 0,
113 TP_NVRAM_MASK_MUTE
= 0x40,
114 TP_NVRAM_MASK_HKT_VOLUME
= 0x80,
115 TP_NVRAM_MASK_LEVEL_VOLUME
= 0x0f,
116 TP_NVRAM_POS_LEVEL_VOLUME
= 0,
120 #define TPACPI_ACPI_HKEY_HID "IBM0068"
123 #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */
124 #define TPACPI_HKEY_INPUT_VERSION 0x4101
126 /* ACPI \WGSV commands */
128 TP_ACPI_WGSV_GET_STATE
= 0x01, /* Get state information */
129 TP_ACPI_WGSV_PWR_ON_ON_RESUME
= 0x02, /* Resume WWAN powered on */
130 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
= 0x03, /* Resume WWAN powered off */
131 TP_ACPI_WGSV_SAVE_STATE
= 0x04, /* Save state for S4/S5 */
134 /* TP_ACPI_WGSV_GET_STATE bits */
136 TP_ACPI_WGSV_STATE_WWANEXIST
= 0x0001, /* WWAN hw available */
137 TP_ACPI_WGSV_STATE_WWANPWR
= 0x0002, /* WWAN radio enabled */
138 TP_ACPI_WGSV_STATE_WWANPWRRES
= 0x0004, /* WWAN state at resume */
139 TP_ACPI_WGSV_STATE_WWANBIOSOFF
= 0x0008, /* WWAN disabled in BIOS */
140 TP_ACPI_WGSV_STATE_BLTHEXIST
= 0x0001, /* BLTH hw available */
141 TP_ACPI_WGSV_STATE_BLTHPWR
= 0x0002, /* BLTH radio enabled */
142 TP_ACPI_WGSV_STATE_BLTHPWRRES
= 0x0004, /* BLTH state at resume */
143 TP_ACPI_WGSV_STATE_BLTHBIOSOFF
= 0x0008, /* BLTH disabled in BIOS */
144 TP_ACPI_WGSV_STATE_UWBEXIST
= 0x0010, /* UWB hw available */
145 TP_ACPI_WGSV_STATE_UWBPWR
= 0x0020, /* UWB radio enabled */
148 /****************************************************************************
152 #define TPACPI_NAME "thinkpad"
153 #define TPACPI_DESC "ThinkPad ACPI Extras"
154 #define TPACPI_FILE TPACPI_NAME "_acpi"
155 #define TPACPI_URL "http://ibm-acpi.sf.net/"
156 #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net"
158 #define TPACPI_PROC_DIR "ibm"
159 #define TPACPI_ACPI_EVENT_PREFIX "ibm"
160 #define TPACPI_DRVR_NAME TPACPI_FILE
161 #define TPACPI_DRVR_SHORTNAME "tpacpi"
162 #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon"
164 #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd"
165 #define TPACPI_WORKQUEUE_NAME "ktpacpid"
167 #define TPACPI_MAX_ACPI_ARGS 3
169 /* rfkill switches */
171 TPACPI_RFK_BLUETOOTH_SW_ID
= 0,
172 TPACPI_RFK_WWAN_SW_ID
,
176 #define TPACPI_LOG TPACPI_FILE ": "
177 #define TPACPI_ERR KERN_ERR TPACPI_LOG
178 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
179 #define TPACPI_INFO KERN_INFO TPACPI_LOG
180 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
182 #define TPACPI_DBG_ALL 0xffff
183 #define TPACPI_DBG_INIT 0x0001
184 #define TPACPI_DBG_EXIT 0x0002
185 #define dbg_printk(a_dbg_level, format, arg...) \
186 do { if (dbg_level & a_dbg_level) \
187 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
189 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
190 #define vdbg_printk(a_dbg_level, format, arg...) \
191 dbg_printk(a_dbg_level, format, ## arg)
192 static const char *str_supported(int is_supported
);
194 #define vdbg_printk(a_dbg_level, format, arg...)
197 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
198 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
199 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
202 /****************************************************************************
203 * Driver-wide structs and misc. variables
208 struct tp_acpi_drv_struct
{
209 const struct acpi_device_id
*hid
;
210 struct acpi_driver
*driver
;
212 void (*notify
) (struct ibm_struct
*, u32
);
215 struct acpi_device
*device
;
221 int (*read
) (char *);
222 int (*write
) (char *);
224 void (*resume
) (void);
225 void (*suspend
) (pm_message_t state
);
227 struct list_head all_drivers
;
229 struct tp_acpi_drv_struct
*acpi
;
232 u8 acpi_driver_registered
:1;
233 u8 acpi_notify_installed
:1;
240 struct ibm_init_struct
{
243 int (*init
) (struct ibm_init_struct
*);
244 struct ibm_struct
*data
;
248 #ifdef CONFIG_THINKPAD_ACPI_BAY
261 u32 bright_16levels
:1;
262 u32 bright_acpimode
:1;
264 u32 fan_ctrl_status_undef
:1;
265 u32 input_device_registered
:1;
266 u32 platform_drv_registered
:1;
267 u32 platform_drv_attrs_registered
:1;
268 u32 sensors_pdrv_registered
:1;
269 u32 sensors_pdrv_attrs_registered
:1;
270 u32 sensors_pdev_attrs_registered
:1;
271 u32 hotkey_poll_active
:1;
275 u16 hotkey_mask_ff
:1;
276 u16 bright_cmos_ec_unsync
:1;
279 struct thinkpad_id_data
{
280 unsigned int vendor
; /* ThinkPad vendor:
281 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
283 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
284 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
286 u16 bios_model
; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */
289 char *model_str
; /* ThinkPad T43 */
290 char *nummodel_str
; /* 9384A9C for a 9384-A9C model */
292 static struct thinkpad_id_data thinkpad_id
;
295 TPACPI_LIFE_INIT
= 0,
300 static int experimental
;
301 static u32 dbg_level
;
303 static struct workqueue_struct
*tpacpi_wq
;
311 /* Special LED class that can defer work */
312 struct tpacpi_led_classdev
{
313 struct led_classdev led_classdev
;
314 struct work_struct work
;
315 enum led_status_t new_state
;
319 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
320 static int dbg_wlswemul
;
321 static int tpacpi_wlsw_emulstate
;
322 static int dbg_bluetoothemul
;
323 static int tpacpi_bluetooth_emulstate
;
324 static int dbg_wwanemul
;
325 static int tpacpi_wwan_emulstate
;
329 /****************************************************************************
330 ****************************************************************************
332 * ACPI Helpers and device model
334 ****************************************************************************
335 ****************************************************************************/
337 /*************************************************************************
341 static acpi_handle root_handle
;
343 #define TPACPI_HANDLE(object, parent, paths...) \
344 static acpi_handle object##_handle; \
345 static acpi_handle *object##_parent = &parent##_handle; \
346 static char *object##_path; \
347 static char *object##_paths[] = { paths }
349 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
350 "\\_SB.PCI.ISA.EC", /* 570 */
351 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
352 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
353 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
354 "\\_SB.PCI0.ICH3.EC0", /* R31 */
355 "\\_SB.PCI0.LPC.EC", /* all others */
358 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
359 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
361 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
363 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
364 "\\CMS", /* R40, R40e */
367 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
368 "^HKEY", /* R30, R31 */
369 "HKEY", /* all others */
372 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
373 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
374 "\\_SB.PCI0.VID0", /* 770e */
375 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
376 "\\_SB.PCI0.AGP.VID", /* all others */
380 /*************************************************************************
384 static int acpi_evalf(acpi_handle handle
,
385 void *res
, char *method
, char *fmt
, ...)
388 struct acpi_object_list params
;
389 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
390 struct acpi_buffer result
, *resultp
;
391 union acpi_object out_obj
;
399 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
412 params
.pointer
= &in_objs
[0];
419 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
420 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
422 /* add more types as needed */
424 printk(TPACPI_ERR
"acpi_evalf() called "
425 "with invalid format character '%c'\n", c
);
431 if (res_type
!= 'v') {
432 result
.length
= sizeof(out_obj
);
433 result
.pointer
= &out_obj
;
438 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
443 *(int *)res
= out_obj
.integer
.value
;
444 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
447 success
= status
== AE_OK
;
449 /* add more types as needed */
451 printk(TPACPI_ERR
"acpi_evalf() called "
452 "with invalid format character '%c'\n", res_type
);
456 if (!success
&& !quiet
)
457 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
458 method
, fmt0
, status
);
463 static int acpi_ec_read(int i
, u8
*p
)
468 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
472 if (ec_read(i
, p
) < 0)
479 static int acpi_ec_write(int i
, u8 v
)
482 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
485 if (ec_write(i
, v
) < 0)
492 #if defined(CONFIG_THINKPAD_ACPI_DOCK) || defined(CONFIG_THINKPAD_ACPI_BAY)
493 static int _sta(acpi_handle handle
)
497 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
504 static int issue_thinkpad_cmos_command(int cmos_cmd
)
509 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
515 /*************************************************************************
519 #define TPACPI_ACPIHANDLE_INIT(object) \
520 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
521 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
523 static void drv_acpi_handle_init(char *name
,
524 acpi_handle
*handle
, acpi_handle parent
,
525 char **paths
, int num_paths
, char **path
)
530 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
533 for (i
= 0; i
< num_paths
; i
++) {
534 status
= acpi_get_handle(parent
, paths
[i
], handle
);
535 if (ACPI_SUCCESS(status
)) {
537 dbg_printk(TPACPI_DBG_INIT
,
538 "Found ACPI handle %s for %s\n",
544 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
549 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
551 struct ibm_struct
*ibm
= data
;
553 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
556 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
559 ibm
->acpi
->notify(ibm
, event
);
562 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
569 if (!*ibm
->acpi
->handle
)
572 vdbg_printk(TPACPI_DBG_INIT
,
573 "setting up ACPI notify for %s\n", ibm
->name
);
575 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
577 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
582 ibm
->acpi
->device
->driver_data
= ibm
;
583 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
584 TPACPI_ACPI_EVENT_PREFIX
,
587 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
588 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
589 if (ACPI_FAILURE(status
)) {
590 if (status
== AE_ALREADY_EXISTS
) {
592 "another device driver is already "
593 "handling %s events\n", ibm
->name
);
596 "acpi_install_notify_handler(%s) failed: %d\n",
601 ibm
->flags
.acpi_notify_installed
= 1;
605 static int __init
tpacpi_device_add(struct acpi_device
*device
)
610 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
614 dbg_printk(TPACPI_DBG_INIT
,
615 "registering %s as an ACPI driver\n", ibm
->name
);
619 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
620 if (!ibm
->acpi
->driver
) {
622 "failed to allocate memory for ibm->acpi->driver\n");
626 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
627 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
629 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
631 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
633 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
635 kfree(ibm
->acpi
->driver
);
636 ibm
->acpi
->driver
= NULL
;
638 ibm
->flags
.acpi_driver_registered
= 1;
644 /****************************************************************************
645 ****************************************************************************
649 ****************************************************************************
650 ****************************************************************************/
652 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
653 int count
, int *eof
, void *data
)
655 struct ibm_struct
*ibm
= data
;
658 if (!ibm
|| !ibm
->read
)
661 len
= ibm
->read(page
);
665 if (len
<= off
+ count
)
677 static int dispatch_procfs_write(struct file
*file
,
678 const char __user
*userbuf
,
679 unsigned long count
, void *data
)
681 struct ibm_struct
*ibm
= data
;
685 if (!ibm
|| !ibm
->write
)
688 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
692 if (copy_from_user(kernbuf
, userbuf
, count
)) {
698 strcat(kernbuf
, ",");
699 ret
= ibm
->write(kernbuf
);
708 static char *next_cmd(char **cmds
)
713 while ((end
= strchr(start
, ',')) && end
== start
)
725 /****************************************************************************
726 ****************************************************************************
728 * Device model: input, hwmon and platform
730 ****************************************************************************
731 ****************************************************************************/
733 static struct platform_device
*tpacpi_pdev
;
734 static struct platform_device
*tpacpi_sensors_pdev
;
735 static struct device
*tpacpi_hwmon
;
736 static struct input_dev
*tpacpi_inputdev
;
737 static struct mutex tpacpi_inputdev_send_mutex
;
738 static LIST_HEAD(tpacpi_all_drivers
);
740 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
743 struct ibm_struct
*ibm
, *itmp
;
745 list_for_each_entry_safe(ibm
, itmp
,
749 (ibm
->suspend
)(state
);
755 static int tpacpi_resume_handler(struct platform_device
*pdev
)
757 struct ibm_struct
*ibm
, *itmp
;
759 list_for_each_entry_safe(ibm
, itmp
,
769 static struct platform_driver tpacpi_pdriver
= {
771 .name
= TPACPI_DRVR_NAME
,
772 .owner
= THIS_MODULE
,
774 .suspend
= tpacpi_suspend_handler
,
775 .resume
= tpacpi_resume_handler
,
778 static struct platform_driver tpacpi_hwmon_pdriver
= {
780 .name
= TPACPI_HWMON_DRVR_NAME
,
781 .owner
= THIS_MODULE
,
785 /*************************************************************************
786 * sysfs support helpers
789 struct attribute_set
{
790 unsigned int members
, max_members
;
791 struct attribute_group group
;
794 struct attribute_set_obj
{
795 struct attribute_set s
;
797 } __attribute__((packed
));
799 static struct attribute_set
*create_attr_set(unsigned int max_members
,
802 struct attribute_set_obj
*sobj
;
804 if (max_members
== 0)
807 /* Allocates space for implicit NULL at the end too */
808 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
809 max_members
* sizeof(struct attribute
*),
813 sobj
->s
.max_members
= max_members
;
814 sobj
->s
.group
.attrs
= &sobj
->a
;
815 sobj
->s
.group
.name
= name
;
820 #define destroy_attr_set(_set) \
823 /* not multi-threaded safe, use it in a single thread per set */
824 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
829 if (s
->members
>= s
->max_members
)
832 s
->group
.attrs
[s
->members
] = attr
;
838 static int add_many_to_attr_set(struct attribute_set
*s
,
839 struct attribute
**attr
,
844 for (i
= 0; i
< count
; i
++) {
845 res
= add_to_attr_set(s
, attr
[i
]);
853 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
855 sysfs_remove_group(kobj
, &s
->group
);
859 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
860 sysfs_create_group(_kobj, &_attr_set->group)
862 static int parse_strtoul(const char *buf
,
863 unsigned long max
, unsigned long *value
)
867 while (*buf
&& isspace(*buf
))
869 *value
= simple_strtoul(buf
, &endp
, 0);
870 while (*endp
&& isspace(*endp
))
872 if (*endp
|| *value
> max
)
878 static void tpacpi_disable_brightness_delay(void)
880 if (acpi_evalf(hkey_handle
, NULL
, "PWMS", "qvd", 0))
882 "ACPI backlight control delay disabled\n");
885 static int __init
tpacpi_query_bcl_levels(acpi_handle handle
)
887 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
888 union acpi_object
*obj
;
891 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
892 obj
= (union acpi_object
*)buffer
.pointer
;
893 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
894 printk(TPACPI_ERR
"Unknown _BCL data, "
895 "please report this to %s\n", TPACPI_MAIL
);
898 rc
= obj
->package
.count
;
904 kfree(buffer
.pointer
);
908 static acpi_status __init
tpacpi_acpi_walk_find_bcl(acpi_handle handle
,
909 u32 lvl
, void *context
, void **rv
)
911 char name
[ACPI_PATH_SEGMENT_LENGTH
];
912 struct acpi_buffer buffer
= { sizeof(name
), &name
};
914 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
915 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
917 **(int **)rv
= tpacpi_query_bcl_levels(handle
);
918 return AE_CTRL_TERMINATE
;
925 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
927 static int __init
tpacpi_check_std_acpi_brightness_support(void)
931 void *bcl_ptr
= &bcl_levels
;
934 TPACPI_ACPIHANDLE_INIT(vid
);
940 * Search for a _BCL method, and execute it. This is safe on all
941 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
942 * BIOS in ACPI backlight control mode. We do NOT have to care
943 * about calling the _BCL method in an enabled video device, any
944 * will do for our purposes.
947 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
948 tpacpi_acpi_walk_find_bcl
, NULL
,
951 if (ACPI_SUCCESS(status
) && bcl_levels
> 2) {
952 tp_features
.bright_acpimode
= 1;
953 return (bcl_levels
- 2);
959 static int __init
tpacpi_new_rfkill(const unsigned int id
,
961 const enum rfkill_type rfktype
,
963 int (*toggle_radio
)(void *, enum rfkill_state
),
964 int (*get_state
)(void *, enum rfkill_state
*))
967 enum rfkill_state initial_state
;
969 *rfk
= rfkill_allocate(&tpacpi_pdev
->dev
, rfktype
);
972 "failed to allocate memory for rfkill class\n");
977 (*rfk
)->get_state
= get_state
;
978 (*rfk
)->toggle_radio
= toggle_radio
;
980 if (!get_state(NULL
, &initial_state
))
981 (*rfk
)->state
= initial_state
;
983 res
= rfkill_register(*rfk
);
986 "failed to register %s rfkill switch: %d\n",
996 /*************************************************************************
997 * thinkpad-acpi driver attributes
1000 /* interface_version --------------------------------------------------- */
1001 static ssize_t
tpacpi_driver_interface_version_show(
1002 struct device_driver
*drv
,
1005 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
1008 static DRIVER_ATTR(interface_version
, S_IRUGO
,
1009 tpacpi_driver_interface_version_show
, NULL
);
1011 /* debug_level --------------------------------------------------------- */
1012 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
1015 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
1018 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
1019 const char *buf
, size_t count
)
1023 if (parse_strtoul(buf
, 0xffff, &t
))
1031 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
1032 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
1034 /* version ------------------------------------------------------------- */
1035 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
1038 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
1039 TPACPI_DESC
, TPACPI_VERSION
);
1042 static DRIVER_ATTR(version
, S_IRUGO
,
1043 tpacpi_driver_version_show
, NULL
);
1045 /* --------------------------------------------------------------------- */
1047 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1049 static void tpacpi_send_radiosw_update(void);
1051 /* wlsw_emulstate ------------------------------------------------------ */
1052 static ssize_t
tpacpi_driver_wlsw_emulstate_show(struct device_driver
*drv
,
1055 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wlsw_emulstate
);
1058 static ssize_t
tpacpi_driver_wlsw_emulstate_store(struct device_driver
*drv
,
1059 const char *buf
, size_t count
)
1063 if (parse_strtoul(buf
, 1, &t
))
1066 if (tpacpi_wlsw_emulstate
!= t
) {
1067 tpacpi_wlsw_emulstate
= !!t
;
1068 tpacpi_send_radiosw_update();
1070 tpacpi_wlsw_emulstate
= !!t
;
1075 static DRIVER_ATTR(wlsw_emulstate
, S_IWUSR
| S_IRUGO
,
1076 tpacpi_driver_wlsw_emulstate_show
,
1077 tpacpi_driver_wlsw_emulstate_store
);
1079 /* bluetooth_emulstate ------------------------------------------------- */
1080 static ssize_t
tpacpi_driver_bluetooth_emulstate_show(
1081 struct device_driver
*drv
,
1084 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_bluetooth_emulstate
);
1087 static ssize_t
tpacpi_driver_bluetooth_emulstate_store(
1088 struct device_driver
*drv
,
1089 const char *buf
, size_t count
)
1093 if (parse_strtoul(buf
, 1, &t
))
1096 tpacpi_bluetooth_emulstate
= !!t
;
1101 static DRIVER_ATTR(bluetooth_emulstate
, S_IWUSR
| S_IRUGO
,
1102 tpacpi_driver_bluetooth_emulstate_show
,
1103 tpacpi_driver_bluetooth_emulstate_store
);
1105 /* wwan_emulstate ------------------------------------------------- */
1106 static ssize_t
tpacpi_driver_wwan_emulstate_show(
1107 struct device_driver
*drv
,
1110 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wwan_emulstate
);
1113 static ssize_t
tpacpi_driver_wwan_emulstate_store(
1114 struct device_driver
*drv
,
1115 const char *buf
, size_t count
)
1119 if (parse_strtoul(buf
, 1, &t
))
1122 tpacpi_wwan_emulstate
= !!t
;
1127 static DRIVER_ATTR(wwan_emulstate
, S_IWUSR
| S_IRUGO
,
1128 tpacpi_driver_wwan_emulstate_show
,
1129 tpacpi_driver_wwan_emulstate_store
);
1133 /* --------------------------------------------------------------------- */
1135 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
1136 &driver_attr_debug_level
, &driver_attr_version
,
1137 &driver_attr_interface_version
,
1140 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
1146 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
1147 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
1151 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1152 if (!res
&& dbg_wlswemul
)
1153 res
= driver_create_file(drv
, &driver_attr_wlsw_emulstate
);
1154 if (!res
&& dbg_bluetoothemul
)
1155 res
= driver_create_file(drv
, &driver_attr_bluetooth_emulstate
);
1156 if (!res
&& dbg_wwanemul
)
1157 res
= driver_create_file(drv
, &driver_attr_wwan_emulstate
);
1163 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
1167 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
1168 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
1170 #ifdef THINKPAD_ACPI_DEBUGFACILITIES
1171 driver_remove_file(drv
, &driver_attr_wlsw_emulstate
);
1172 driver_remove_file(drv
, &driver_attr_bluetooth_emulstate
);
1173 driver_remove_file(drv
, &driver_attr_wwan_emulstate
);
1177 /****************************************************************************
1178 ****************************************************************************
1182 ****************************************************************************
1183 ****************************************************************************/
1185 /*************************************************************************
1186 * thinkpad-acpi init subdriver
1189 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
1191 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
1192 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
1194 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
1195 (thinkpad_id
.bios_version_str
) ?
1196 thinkpad_id
.bios_version_str
: "unknown",
1197 (thinkpad_id
.ec_version_str
) ?
1198 thinkpad_id
.ec_version_str
: "unknown");
1200 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
1201 printk(TPACPI_INFO
"%s %s, model %s\n",
1202 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
1203 "IBM" : ((thinkpad_id
.vendor
==
1204 PCI_VENDOR_ID_LENOVO
) ?
1205 "Lenovo" : "Unknown vendor"),
1206 thinkpad_id
.model_str
,
1207 (thinkpad_id
.nummodel_str
) ?
1208 thinkpad_id
.nummodel_str
: "unknown");
1213 static int thinkpad_acpi_driver_read(char *p
)
1217 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", TPACPI_DESC
);
1218 len
+= sprintf(p
+ len
, "version:\t%s\n", TPACPI_VERSION
);
1223 static struct ibm_struct thinkpad_acpi_driver_data
= {
1225 .read
= thinkpad_acpi_driver_read
,
1228 /*************************************************************************
1232 enum { /* hot key scan codes (derived from ACPI DSDT) */
1233 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
1234 TP_ACPI_HOTKEYSCAN_FNF2
,
1235 TP_ACPI_HOTKEYSCAN_FNF3
,
1236 TP_ACPI_HOTKEYSCAN_FNF4
,
1237 TP_ACPI_HOTKEYSCAN_FNF5
,
1238 TP_ACPI_HOTKEYSCAN_FNF6
,
1239 TP_ACPI_HOTKEYSCAN_FNF7
,
1240 TP_ACPI_HOTKEYSCAN_FNF8
,
1241 TP_ACPI_HOTKEYSCAN_FNF9
,
1242 TP_ACPI_HOTKEYSCAN_FNF10
,
1243 TP_ACPI_HOTKEYSCAN_FNF11
,
1244 TP_ACPI_HOTKEYSCAN_FNF12
,
1245 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
1246 TP_ACPI_HOTKEYSCAN_FNINSERT
,
1247 TP_ACPI_HOTKEYSCAN_FNDELETE
,
1248 TP_ACPI_HOTKEYSCAN_FNHOME
,
1249 TP_ACPI_HOTKEYSCAN_FNEND
,
1250 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1251 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
1252 TP_ACPI_HOTKEYSCAN_FNSPACE
,
1253 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1254 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1255 TP_ACPI_HOTKEYSCAN_MUTE
,
1256 TP_ACPI_HOTKEYSCAN_THINKPAD
,
1259 enum { /* Keys available through NVRAM polling */
1260 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
1261 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
1264 enum { /* Positions of some of the keys in hotkey masks */
1265 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
1266 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
1267 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
1268 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
1269 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
1270 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1271 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
1272 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1273 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1274 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
1275 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
1278 enum { /* NVRAM to ACPI HKEY group map */
1279 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
1280 TP_ACPI_HKEY_ZOOM_MASK
|
1281 TP_ACPI_HKEY_DISPSWTCH_MASK
|
1282 TP_ACPI_HKEY_HIBERNATE_MASK
,
1283 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
1284 TP_ACPI_HKEY_BRGHTDWN_MASK
,
1285 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
1286 TP_ACPI_HKEY_VOLDWN_MASK
|
1287 TP_ACPI_HKEY_MUTE_MASK
,
1290 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1291 struct tp_nvram_state
{
1292 u16 thinkpad_toggle
:1;
1294 u16 display_toggle
:1;
1295 u16 thinklight_toggle
:1;
1296 u16 hibernate_toggle
:1;
1297 u16 displayexp_toggle
:1;
1298 u16 display_state
:1;
1299 u16 brightness_toggle
:1;
1300 u16 volume_toggle
:1;
1303 u8 brightness_level
;
1307 static struct task_struct
*tpacpi_hotkey_task
;
1308 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
1309 static int hotkey_poll_freq
= 10; /* Hz */
1310 static struct mutex hotkey_thread_mutex
;
1311 static struct mutex hotkey_thread_data_mutex
;
1312 static unsigned int hotkey_config_change
;
1314 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1316 #define hotkey_source_mask 0U
1318 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1320 static struct mutex hotkey_mutex
;
1322 static enum { /* Reasons for waking up */
1323 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
1324 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
1325 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
1326 } hotkey_wakeup_reason
;
1328 static int hotkey_autosleep_ack
;
1330 static int hotkey_orig_status
;
1331 static u32 hotkey_orig_mask
;
1332 static u32 hotkey_all_mask
;
1333 static u32 hotkey_reserved_mask
;
1334 static u32 hotkey_mask
;
1336 static unsigned int hotkey_report_mode
;
1338 static u16
*hotkey_keycode_map
;
1340 static struct attribute_set
*hotkey_dev_attributes
;
1342 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1343 #define HOTKEY_CONFIG_CRITICAL_START \
1345 mutex_lock(&hotkey_thread_data_mutex); \
1346 hotkey_config_change++; \
1348 #define HOTKEY_CONFIG_CRITICAL_END \
1349 mutex_unlock(&hotkey_thread_data_mutex);
1351 #define HOTKEY_CONFIG_CRITICAL_START
1352 #define HOTKEY_CONFIG_CRITICAL_END
1353 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1355 /* HKEY.MHKG() return bits */
1356 #define TP_HOTKEY_TABLET_MASK (1 << 3)
1358 static int hotkey_get_wlsw(int *status
)
1360 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1362 *status
= !!tpacpi_wlsw_emulstate
;
1366 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
1371 static int hotkey_get_tablet_mode(int *status
)
1375 if (!acpi_evalf(hkey_handle
, &s
, "MHKG", "d"))
1378 *status
= ((s
& TP_HOTKEY_TABLET_MASK
) != 0);
1383 * Call with hotkey_mutex held
1385 static int hotkey_mask_get(void)
1389 if (tp_features
.hotkey_mask
) {
1390 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
1393 hotkey_mask
= m
| (hotkey_source_mask
& hotkey_mask
);
1399 * Call with hotkey_mutex held
1401 static int hotkey_mask_set(u32 mask
)
1406 if (tp_features
.hotkey_mask
) {
1407 if (!tp_warned
.hotkey_mask_ff
&&
1408 (mask
== 0xffff || mask
== 0xffffff ||
1409 mask
== 0xffffffff)) {
1410 tp_warned
.hotkey_mask_ff
= 1;
1411 printk(TPACPI_NOTICE
1412 "setting the hotkey mask to 0x%08x is likely "
1413 "not the best way to go about it\n", mask
);
1414 printk(TPACPI_NOTICE
1415 "please consider using the driver defaults, "
1416 "and refer to up-to-date thinkpad-acpi "
1420 HOTKEY_CONFIG_CRITICAL_START
1421 for (i
= 0; i
< 32; i
++) {
1423 /* enable in firmware mask only keys not in NVRAM
1424 * mode, but enable the key in the cached hotkey_mask
1425 * regardless of mode, or the key will end up
1426 * disabled by hotkey_mask_get() */
1427 if (!acpi_evalf(hkey_handle
,
1428 NULL
, "MHKM", "vdd", i
+ 1,
1429 !!((mask
& ~hotkey_source_mask
) & m
))) {
1433 hotkey_mask
= (hotkey_mask
& ~m
) | (mask
& m
);
1436 HOTKEY_CONFIG_CRITICAL_END
1438 /* hotkey_mask_get must be called unconditionally below */
1439 if (!hotkey_mask_get() && !rc
&&
1440 (hotkey_mask
& ~hotkey_source_mask
) !=
1441 (mask
& ~hotkey_source_mask
)) {
1442 printk(TPACPI_NOTICE
1443 "requested hot key mask 0x%08x, but "
1444 "firmware forced it to 0x%08x\n",
1448 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1449 HOTKEY_CONFIG_CRITICAL_START
1450 hotkey_mask
= mask
& hotkey_source_mask
;
1451 HOTKEY_CONFIG_CRITICAL_END
1453 if (hotkey_mask
!= mask
) {
1454 printk(TPACPI_NOTICE
1455 "requested hot key mask 0x%08x, "
1456 "forced to 0x%08x (NVRAM poll mask is "
1457 "0x%08x): no firmware mask support\n",
1458 mask
, hotkey_mask
, hotkey_source_mask
);
1463 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1469 static int hotkey_status_get(int *status
)
1471 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1477 static int hotkey_status_set(int status
)
1479 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
1485 static void tpacpi_input_send_tabletsw(void)
1489 if (tp_features
.hotkey_tablet
&&
1490 !hotkey_get_tablet_mode(&state
)) {
1491 mutex_lock(&tpacpi_inputdev_send_mutex
);
1493 input_report_switch(tpacpi_inputdev
,
1494 SW_TABLET_MODE
, !!state
);
1495 input_sync(tpacpi_inputdev
);
1497 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1501 static void tpacpi_input_send_key(unsigned int scancode
)
1503 unsigned int keycode
;
1505 keycode
= hotkey_keycode_map
[scancode
];
1507 if (keycode
!= KEY_RESERVED
) {
1508 mutex_lock(&tpacpi_inputdev_send_mutex
);
1510 input_report_key(tpacpi_inputdev
, keycode
, 1);
1511 if (keycode
== KEY_UNKNOWN
)
1512 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1514 input_sync(tpacpi_inputdev
);
1516 input_report_key(tpacpi_inputdev
, keycode
, 0);
1517 if (keycode
== KEY_UNKNOWN
)
1518 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1520 input_sync(tpacpi_inputdev
);
1522 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1526 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1527 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
1529 static void tpacpi_hotkey_send_key(unsigned int scancode
)
1531 tpacpi_input_send_key(scancode
);
1532 if (hotkey_report_mode
< 2) {
1533 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
1534 0x80, 0x1001 + scancode
);
1538 static void hotkey_read_nvram(struct tp_nvram_state
*n
, u32 m
)
1542 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
1543 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
1544 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
1545 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
1546 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
1547 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
1549 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
1550 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
1551 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
1553 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
1554 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
1555 n
->displayexp_toggle
=
1556 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
1558 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
1559 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
1560 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
1561 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
1562 n
->brightness_toggle
=
1563 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
1565 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
1566 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
1567 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
1568 >> TP_NVRAM_POS_LEVEL_VOLUME
;
1569 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
1570 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
1574 #define TPACPI_COMPARE_KEY(__scancode, __member) \
1576 if ((mask & (1 << __scancode)) && \
1577 oldn->__member != newn->__member) \
1578 tpacpi_hotkey_send_key(__scancode); \
1581 #define TPACPI_MAY_SEND_KEY(__scancode) \
1582 do { if (mask & (1 << __scancode)) \
1583 tpacpi_hotkey_send_key(__scancode); } while (0)
1585 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
1586 struct tp_nvram_state
*newn
,
1589 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
1590 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
1591 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
1592 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
1594 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
1596 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
1599 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
1600 if (oldn
->mute
!= newn
->mute
) {
1601 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1603 if (oldn
->volume_level
> newn
->volume_level
) {
1604 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1605 } else if (oldn
->volume_level
< newn
->volume_level
) {
1606 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1607 } else if (oldn
->mute
== newn
->mute
) {
1608 /* repeated key presses that didn't change state */
1610 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1611 } else if (newn
->volume_level
!= 0) {
1612 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1614 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1619 /* handle brightness */
1620 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
1621 if (oldn
->brightness_level
< newn
->brightness_level
) {
1622 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1623 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
1624 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1626 /* repeated key presses that didn't change state */
1627 if (newn
->brightness_level
!= 0) {
1628 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1630 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1636 #undef TPACPI_COMPARE_KEY
1637 #undef TPACPI_MAY_SEND_KEY
1639 static int hotkey_kthread(void *data
)
1641 struct tp_nvram_state s
[2];
1643 unsigned int si
, so
;
1645 unsigned int change_detector
, must_reset
;
1647 mutex_lock(&hotkey_thread_mutex
);
1649 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
1658 /* Initial state for compares */
1659 mutex_lock(&hotkey_thread_data_mutex
);
1660 change_detector
= hotkey_config_change
;
1661 mask
= hotkey_source_mask
& hotkey_mask
;
1662 mutex_unlock(&hotkey_thread_data_mutex
);
1663 hotkey_read_nvram(&s
[so
], mask
);
1665 while (!kthread_should_stop() && hotkey_poll_freq
) {
1667 t
= 1000/hotkey_poll_freq
;
1668 t
= msleep_interruptible(t
);
1669 if (unlikely(kthread_should_stop()))
1671 must_reset
= try_to_freeze();
1672 if (t
> 0 && !must_reset
)
1675 mutex_lock(&hotkey_thread_data_mutex
);
1676 if (must_reset
|| hotkey_config_change
!= change_detector
) {
1677 /* forget old state on thaw or config change */
1680 change_detector
= hotkey_config_change
;
1682 mask
= hotkey_source_mask
& hotkey_mask
;
1683 mutex_unlock(&hotkey_thread_data_mutex
);
1686 hotkey_read_nvram(&s
[si
], mask
);
1687 if (likely(si
!= so
)) {
1688 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
1698 mutex_unlock(&hotkey_thread_mutex
);
1702 static void hotkey_poll_stop_sync(void)
1704 if (tpacpi_hotkey_task
) {
1705 if (frozen(tpacpi_hotkey_task
) ||
1706 freezing(tpacpi_hotkey_task
))
1707 thaw_process(tpacpi_hotkey_task
);
1709 kthread_stop(tpacpi_hotkey_task
);
1710 tpacpi_hotkey_task
= NULL
;
1711 mutex_lock(&hotkey_thread_mutex
);
1712 /* at this point, the thread did exit */
1713 mutex_unlock(&hotkey_thread_mutex
);
1717 /* call with hotkey_mutex held */
1718 static void hotkey_poll_setup(int may_warn
)
1720 if ((hotkey_source_mask
& hotkey_mask
) != 0 &&
1721 hotkey_poll_freq
> 0 &&
1722 (tpacpi_inputdev
->users
> 0 || hotkey_report_mode
< 2)) {
1723 if (!tpacpi_hotkey_task
) {
1724 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
1725 NULL
, TPACPI_NVRAM_KTHREAD_NAME
);
1726 if (IS_ERR(tpacpi_hotkey_task
)) {
1727 tpacpi_hotkey_task
= NULL
;
1729 "could not create kernel thread "
1730 "for hotkey polling\n");
1734 hotkey_poll_stop_sync();
1736 hotkey_source_mask
!= 0 && hotkey_poll_freq
== 0) {
1737 printk(TPACPI_NOTICE
1738 "hot keys 0x%08x require polling, "
1739 "which is currently disabled\n",
1740 hotkey_source_mask
);
1745 static void hotkey_poll_setup_safe(int may_warn
)
1747 mutex_lock(&hotkey_mutex
);
1748 hotkey_poll_setup(may_warn
);
1749 mutex_unlock(&hotkey_mutex
);
1752 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1754 static void hotkey_poll_setup_safe(int __unused
)
1758 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1760 static int hotkey_inputdev_open(struct input_dev
*dev
)
1762 switch (tpacpi_lifecycle
) {
1763 case TPACPI_LIFE_INIT
:
1765 * hotkey_init will call hotkey_poll_setup_safe
1766 * at the appropriate moment
1769 case TPACPI_LIFE_EXITING
:
1771 case TPACPI_LIFE_RUNNING
:
1772 hotkey_poll_setup_safe(0);
1776 /* Should only happen if tpacpi_lifecycle is corrupt */
1781 static void hotkey_inputdev_close(struct input_dev
*dev
)
1783 /* disable hotkey polling when possible */
1784 if (tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
)
1785 hotkey_poll_setup_safe(0);
1788 /* sysfs hotkey enable ------------------------------------------------- */
1789 static ssize_t
hotkey_enable_show(struct device
*dev
,
1790 struct device_attribute
*attr
,
1795 res
= hotkey_status_get(&status
);
1799 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
1802 static ssize_t
hotkey_enable_store(struct device
*dev
,
1803 struct device_attribute
*attr
,
1804 const char *buf
, size_t count
)
1809 if (parse_strtoul(buf
, 1, &t
))
1812 res
= hotkey_status_set(t
);
1814 return (res
) ? res
: count
;
1817 static struct device_attribute dev_attr_hotkey_enable
=
1818 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
1819 hotkey_enable_show
, hotkey_enable_store
);
1821 /* sysfs hotkey mask --------------------------------------------------- */
1822 static ssize_t
hotkey_mask_show(struct device
*dev
,
1823 struct device_attribute
*attr
,
1828 if (mutex_lock_interruptible(&hotkey_mutex
))
1829 return -ERESTARTSYS
;
1830 res
= hotkey_mask_get();
1831 mutex_unlock(&hotkey_mutex
);
1834 res
: snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_mask
);
1837 static ssize_t
hotkey_mask_store(struct device
*dev
,
1838 struct device_attribute
*attr
,
1839 const char *buf
, size_t count
)
1844 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
1847 if (mutex_lock_interruptible(&hotkey_mutex
))
1848 return -ERESTARTSYS
;
1850 res
= hotkey_mask_set(t
);
1852 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1853 hotkey_poll_setup(1);
1856 mutex_unlock(&hotkey_mutex
);
1858 return (res
) ? res
: count
;
1861 static struct device_attribute dev_attr_hotkey_mask
=
1862 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
1863 hotkey_mask_show
, hotkey_mask_store
);
1865 /* sysfs hotkey bios_enabled ------------------------------------------- */
1866 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
1867 struct device_attribute
*attr
,
1870 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
1873 static struct device_attribute dev_attr_hotkey_bios_enabled
=
1874 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
1876 /* sysfs hotkey bios_mask ---------------------------------------------- */
1877 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
1878 struct device_attribute
*attr
,
1881 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
1884 static struct device_attribute dev_attr_hotkey_bios_mask
=
1885 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
1887 /* sysfs hotkey all_mask ----------------------------------------------- */
1888 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
1889 struct device_attribute
*attr
,
1892 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1893 hotkey_all_mask
| hotkey_source_mask
);
1896 static struct device_attribute dev_attr_hotkey_all_mask
=
1897 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
1899 /* sysfs hotkey recommended_mask --------------------------------------- */
1900 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
1901 struct device_attribute
*attr
,
1904 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1905 (hotkey_all_mask
| hotkey_source_mask
)
1906 & ~hotkey_reserved_mask
);
1909 static struct device_attribute dev_attr_hotkey_recommended_mask
=
1910 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
1911 hotkey_recommended_mask_show
, NULL
);
1913 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1915 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
1916 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
1917 struct device_attribute
*attr
,
1920 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
1923 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
1924 struct device_attribute
*attr
,
1925 const char *buf
, size_t count
)
1929 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
1930 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
1933 if (mutex_lock_interruptible(&hotkey_mutex
))
1934 return -ERESTARTSYS
;
1936 HOTKEY_CONFIG_CRITICAL_START
1937 hotkey_source_mask
= t
;
1938 HOTKEY_CONFIG_CRITICAL_END
1940 hotkey_poll_setup(1);
1942 mutex_unlock(&hotkey_mutex
);
1947 static struct device_attribute dev_attr_hotkey_source_mask
=
1948 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
1949 hotkey_source_mask_show
, hotkey_source_mask_store
);
1951 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
1952 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
1953 struct device_attribute
*attr
,
1956 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
1959 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
1960 struct device_attribute
*attr
,
1961 const char *buf
, size_t count
)
1965 if (parse_strtoul(buf
, 25, &t
))
1968 if (mutex_lock_interruptible(&hotkey_mutex
))
1969 return -ERESTARTSYS
;
1971 hotkey_poll_freq
= t
;
1973 hotkey_poll_setup(1);
1974 mutex_unlock(&hotkey_mutex
);
1979 static struct device_attribute dev_attr_hotkey_poll_freq
=
1980 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
1981 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
1983 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1985 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
1986 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
1987 struct device_attribute
*attr
,
1991 res
= hotkey_get_wlsw(&s
);
1995 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
1998 static struct device_attribute dev_attr_hotkey_radio_sw
=
1999 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
2001 static void hotkey_radio_sw_notify_change(void)
2003 if (tp_features
.hotkey_wlsw
)
2004 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2008 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
2009 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
2010 struct device_attribute
*attr
,
2014 res
= hotkey_get_tablet_mode(&s
);
2018 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2021 static struct device_attribute dev_attr_hotkey_tablet_mode
=
2022 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
2024 static void hotkey_tablet_mode_notify_change(void)
2026 if (tp_features
.hotkey_tablet
)
2027 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2028 "hotkey_tablet_mode");
2031 /* sysfs hotkey report_mode -------------------------------------------- */
2032 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
2033 struct device_attribute
*attr
,
2036 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2037 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
2040 static struct device_attribute dev_attr_hotkey_report_mode
=
2041 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
2043 /* sysfs wakeup reason (pollable) -------------------------------------- */
2044 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
2045 struct device_attribute
*attr
,
2048 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
2051 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
2052 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
2054 static void hotkey_wakeup_reason_notify_change(void)
2056 if (tp_features
.hotkey_mask
)
2057 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2061 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2062 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
2063 struct device_attribute
*attr
,
2066 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
2069 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
2070 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
2071 hotkey_wakeup_hotunplug_complete_show
, NULL
);
2073 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2075 if (tp_features
.hotkey_mask
)
2076 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2077 "wakeup_hotunplug_complete");
2080 /* --------------------------------------------------------------------- */
2082 static struct attribute
*hotkey_attributes
[] __initdata
= {
2083 &dev_attr_hotkey_enable
.attr
,
2084 &dev_attr_hotkey_bios_enabled
.attr
,
2085 &dev_attr_hotkey_report_mode
.attr
,
2086 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2087 &dev_attr_hotkey_mask
.attr
,
2088 &dev_attr_hotkey_all_mask
.attr
,
2089 &dev_attr_hotkey_recommended_mask
.attr
,
2090 &dev_attr_hotkey_source_mask
.attr
,
2091 &dev_attr_hotkey_poll_freq
.attr
,
2095 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
2096 &dev_attr_hotkey_bios_mask
.attr
,
2097 #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2098 &dev_attr_hotkey_mask
.attr
,
2099 &dev_attr_hotkey_all_mask
.attr
,
2100 &dev_attr_hotkey_recommended_mask
.attr
,
2102 &dev_attr_hotkey_wakeup_reason
.attr
,
2103 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
2106 static void bluetooth_update_rfk(void);
2107 static void wan_update_rfk(void);
2108 static void tpacpi_send_radiosw_update(void)
2112 /* Sync these BEFORE sending any rfkill events */
2113 if (tp_features
.bluetooth
)
2114 bluetooth_update_rfk();
2115 if (tp_features
.wan
)
2118 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
2119 mutex_lock(&tpacpi_inputdev_send_mutex
);
2121 input_report_switch(tpacpi_inputdev
,
2122 SW_RFKILL_ALL
, !!wlsw
);
2123 input_sync(tpacpi_inputdev
);
2125 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2127 hotkey_radio_sw_notify_change();
2130 static void hotkey_exit(void)
2132 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2133 hotkey_poll_stop_sync();
2136 if (hotkey_dev_attributes
)
2137 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2139 kfree(hotkey_keycode_map
);
2141 if (tp_features
.hotkey
) {
2142 dbg_printk(TPACPI_DBG_EXIT
,
2143 "restoring original hot key mask\n");
2144 /* no short-circuit boolean operator below! */
2145 if ((hotkey_mask_set(hotkey_orig_mask
) |
2146 hotkey_status_set(hotkey_orig_status
)) != 0)
2148 "failed to restore hot key mask "
2149 "to BIOS defaults\n");
2153 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
2155 /* Requirements for changing the default keymaps:
2157 * 1. Many of the keys are mapped to KEY_RESERVED for very
2158 * good reasons. Do not change them unless you have deep
2159 * knowledge on the IBM and Lenovo ThinkPad firmware for
2160 * the various ThinkPad models. The driver behaves
2161 * differently for KEY_RESERVED: such keys have their
2162 * hot key mask *unset* in mask_recommended, and also
2163 * in the initial hot key mask programmed into the
2164 * firmware at driver load time, which means the firm-
2165 * ware may react very differently if you change them to
2168 * 2. You must be subscribed to the linux-thinkpad and
2169 * ibm-acpi-devel mailing lists, and you should read the
2170 * list archives since 2007 if you want to change the
2171 * keymaps. This requirement exists so that you will
2172 * know the past history of problems with the thinkpad-
2173 * acpi driver keymaps, and also that you will be
2174 * listening to any bug reports;
2176 * 3. Do not send thinkpad-acpi specific patches directly to
2177 * for merging, *ever*. Send them to the linux-acpi
2178 * mailinglist for comments. Merging is to be done only
2179 * through acpi-test and the ACPI maintainer.
2181 * If the above is too much to ask, don't change the keymap.
2182 * Ask the thinkpad-acpi maintainer to do it, instead.
2184 static u16 ibm_keycode_map
[] __initdata
= {
2185 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2186 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
2187 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2188 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2190 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2191 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2192 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2193 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2195 /* brightness: firmware always reacts to them, unless
2196 * X.org did some tricks in the radeon BIOS scratch
2197 * registers of *some* models */
2198 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
2199 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
2201 /* Thinklight: firmware always react to it */
2202 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2204 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2205 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2207 /* Volume: firmware always react to it and reprograms
2208 * the built-in *extra* mixer. Never map it to control
2209 * another mixer by default. */
2210 KEY_RESERVED
, /* 0x14: VOLUME UP */
2211 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2212 KEY_RESERVED
, /* 0x16: MUTE */
2214 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2216 /* (assignments unknown, please report if found) */
2217 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2218 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2220 static u16 lenovo_keycode_map
[] __initdata
= {
2221 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2222 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
2223 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2224 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2226 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2227 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2228 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2229 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2231 /* These either have to go through ACPI video, or
2232 * act like in the IBM ThinkPads, so don't ever
2233 * enable them by default */
2234 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
2235 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
2237 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2239 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2240 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2242 /* Volume: z60/z61, T60 (BIOS version?): firmware always
2243 * react to it and reprograms the built-in *extra* mixer.
2244 * Never map it to control another mixer by default.
2246 * T60?, T61, R60?, R61: firmware and EC tries to send
2247 * these over the regular keyboard, so these are no-ops,
2248 * but there are still weird bugs re. MUTE, so do not
2249 * change unless you get test reports from all Lenovo
2250 * models. May cause the BIOS to interfere with the
2253 KEY_RESERVED
, /* 0x14: VOLUME UP */
2254 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2255 KEY_RESERVED
, /* 0x16: MUTE */
2257 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2259 /* (assignments unknown, please report if found) */
2260 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2261 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2264 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
2265 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
2266 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
2272 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
2274 BUG_ON(!tpacpi_inputdev
);
2275 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
2276 tpacpi_inputdev
->close
!= NULL
);
2278 TPACPI_ACPIHANDLE_INIT(hkey
);
2279 mutex_init(&hotkey_mutex
);
2281 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2282 mutex_init(&hotkey_thread_mutex
);
2283 mutex_init(&hotkey_thread_data_mutex
);
2286 /* hotkey not supported on 570 */
2287 tp_features
.hotkey
= hkey_handle
!= NULL
;
2289 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
2290 str_supported(tp_features
.hotkey
));
2292 if (!tp_features
.hotkey
)
2295 tpacpi_disable_brightness_delay();
2297 hotkey_dev_attributes
= create_attr_set(13, NULL
);
2298 if (!hotkey_dev_attributes
)
2300 res
= add_many_to_attr_set(hotkey_dev_attributes
,
2302 ARRAY_SIZE(hotkey_attributes
));
2306 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2307 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
2308 for HKEY interface version 0x100 */
2309 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
2310 if ((hkeyv
>> 8) != 1) {
2311 printk(TPACPI_ERR
"unknown version of the "
2312 "HKEY interface: 0x%x\n", hkeyv
);
2313 printk(TPACPI_ERR
"please report this to %s\n",
2317 * MHKV 0x100 in A31, R40, R40e,
2318 * T4x, X31, and later
2320 tp_features
.hotkey_mask
= 1;
2324 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
2325 str_supported(tp_features
.hotkey_mask
));
2327 if (tp_features
.hotkey_mask
) {
2328 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
2331 "missing MHKA handler, "
2332 "please report this to %s\n",
2334 /* FN+F12, FN+F4, FN+F3 */
2335 hotkey_all_mask
= 0x080cU
;
2339 /* hotkey_source_mask *must* be zero for
2340 * the first hotkey_mask_get */
2341 res
= hotkey_status_get(&hotkey_orig_status
);
2345 if (tp_features
.hotkey_mask
) {
2346 res
= hotkey_mask_get();
2350 hotkey_orig_mask
= hotkey_mask
;
2351 res
= add_many_to_attr_set(
2352 hotkey_dev_attributes
,
2353 hotkey_mask_attributes
,
2354 ARRAY_SIZE(hotkey_mask_attributes
));
2359 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2360 if (tp_features
.hotkey_mask
) {
2361 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
2364 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
;
2367 vdbg_printk(TPACPI_DBG_INIT
,
2368 "hotkey source mask 0x%08x, polling freq %d\n",
2369 hotkey_source_mask
, hotkey_poll_freq
);
2372 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2374 tp_features
.hotkey_wlsw
= 1;
2376 "radio switch emulation enabled\n");
2379 /* Not all thinkpads have a hardware radio switch */
2380 if (acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
2381 tp_features
.hotkey_wlsw
= 1;
2383 "radio switch found; radios are %s\n",
2384 enabled(status
, 0));
2386 if (tp_features
.hotkey_wlsw
)
2387 res
= add_to_attr_set(hotkey_dev_attributes
,
2388 &dev_attr_hotkey_radio_sw
.attr
);
2390 /* For X41t, X60t, X61t Tablets... */
2391 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
2392 tp_features
.hotkey_tablet
= 1;
2394 "possible tablet mode switch found; "
2395 "ThinkPad in %s mode\n",
2396 (status
& TP_HOTKEY_TABLET_MASK
)?
2397 "tablet" : "laptop");
2398 res
= add_to_attr_set(hotkey_dev_attributes
,
2399 &dev_attr_hotkey_tablet_mode
.attr
);
2403 res
= register_attr_set_with_sysfs(
2404 hotkey_dev_attributes
,
2405 &tpacpi_pdev
->dev
.kobj
);
2409 /* Set up key map */
2411 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
2413 if (!hotkey_keycode_map
) {
2415 "failed to allocate memory for key map\n");
2420 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
2421 dbg_printk(TPACPI_DBG_INIT
,
2422 "using Lenovo default hot key map\n");
2423 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
2424 TPACPI_HOTKEY_MAP_SIZE
);
2426 dbg_printk(TPACPI_DBG_INIT
,
2427 "using IBM default hot key map\n");
2428 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
2429 TPACPI_HOTKEY_MAP_SIZE
);
2432 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
2433 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
2434 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
2435 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
2436 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
2437 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
2438 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
2439 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
2440 set_bit(hotkey_keycode_map
[i
],
2441 tpacpi_inputdev
->keybit
);
2443 if (i
< sizeof(hotkey_reserved_mask
)*8)
2444 hotkey_reserved_mask
|= 1 << i
;
2448 if (tp_features
.hotkey_wlsw
) {
2449 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
2450 set_bit(SW_RFKILL_ALL
, tpacpi_inputdev
->swbit
);
2452 if (tp_features
.hotkey_tablet
) {
2453 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
2454 set_bit(SW_TABLET_MODE
, tpacpi_inputdev
->swbit
);
2457 /* Do not issue duplicate brightness change events to
2459 if (!tp_features
.bright_acpimode
)
2460 /* update bright_acpimode... */
2461 tpacpi_check_std_acpi_brightness_support();
2463 if (tp_features
.bright_acpimode
) {
2465 "This ThinkPad has standard ACPI backlight "
2466 "brightness control, supported by the ACPI "
2468 printk(TPACPI_NOTICE
2469 "Disabling thinkpad-acpi brightness events "
2472 /* The hotkey_reserved_mask change below is not
2473 * necessary while the keys are at KEY_RESERVED in the
2474 * default map, but better safe than sorry, leave it
2475 * here as a marker of what we have to do, especially
2476 * when we finally become able to set this at runtime
2477 * on response to X.org requests */
2478 hotkey_reserved_mask
|=
2479 (1 << TP_ACPI_HOTKEYSCAN_FNHOME
)
2480 | (1 << TP_ACPI_HOTKEYSCAN_FNEND
);
2483 dbg_printk(TPACPI_DBG_INIT
, "enabling hot key handling\n");
2484 res
= hotkey_status_set(1);
2489 res
= hotkey_mask_set(((hotkey_all_mask
| hotkey_source_mask
)
2490 & ~hotkey_reserved_mask
)
2491 | hotkey_orig_mask
);
2492 if (res
< 0 && res
!= -ENXIO
) {
2497 dbg_printk(TPACPI_DBG_INIT
,
2498 "legacy hot key reporting over procfs %s\n",
2499 (hotkey_report_mode
< 2) ?
2500 "enabled" : "disabled");
2502 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
2503 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
2505 hotkey_poll_setup_safe(1);
2506 tpacpi_send_radiosw_update();
2507 tpacpi_input_send_tabletsw();
2512 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2513 hotkey_dev_attributes
= NULL
;
2515 return (res
< 0)? res
: 1;
2518 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
2521 unsigned int scancode
;
2526 if (event
!= 0x80) {
2528 "unknown HKEY notification event %d\n", event
);
2529 /* forward it to userspace, maybe it knows how to handle it */
2530 acpi_bus_generate_netlink_event(
2531 ibm
->acpi
->device
->pnp
.device_class
,
2532 dev_name(&ibm
->acpi
->device
->dev
),
2538 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
2539 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
2552 switch (hkey
>> 12) {
2554 /* 0x1000-0x1FFF: key presses */
2555 scancode
= hkey
& 0xfff;
2556 if (scancode
> 0 && scancode
< 0x21) {
2558 if (!(hotkey_source_mask
& (1 << scancode
))) {
2559 tpacpi_input_send_key(scancode
);
2571 case 0x2304: /* suspend, undock */
2572 case 0x2404: /* hibernation, undock */
2573 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
2576 case 0x2305: /* suspend, bay eject */
2577 case 0x2405: /* hibernation, bay eject */
2578 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
2584 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
2586 "woke up due to a hot-unplug "
2588 hotkey_wakeup_reason_notify_change();
2592 /* bay-related wakeups */
2593 if (hkey
== 0x3003) {
2594 hotkey_autosleep_ack
= 1;
2597 hotkey_wakeup_hotunplug_complete_notify_change();
2603 /* dock-related wakeups */
2604 if (hkey
== 0x4003) {
2605 hotkey_autosleep_ack
= 1;
2608 hotkey_wakeup_hotunplug_complete_notify_change();
2614 /* 0x5000-0x5FFF: human interface helpers */
2616 case 0x5010: /* Lenovo new BIOS: brightness changed */
2617 case 0x500b: /* X61t: tablet pen inserted into bay */
2618 case 0x500c: /* X61t: tablet pen removed from bay */
2620 case 0x5009: /* X41t-X61t: swivel up (tablet mode) */
2621 case 0x500a: /* X41t-X61t: swivel down (normal mode) */
2622 tpacpi_input_send_tabletsw();
2623 hotkey_tablet_mode_notify_change();
2628 /* LID switch events. Do not propagate */
2636 /* 0x7000-0x7FFF: misc */
2637 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
2638 tpacpi_send_radiosw_update();
2642 /* fallthrough to default */
2647 printk(TPACPI_NOTICE
2648 "unhandled HKEY event 0x%04x\n", hkey
);
2652 if (!ignore_acpi_ev
&&
2653 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
2654 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
2658 /* netlink events */
2659 if (!ignore_acpi_ev
&& send_acpi_ev
) {
2660 acpi_bus_generate_netlink_event(
2661 ibm
->acpi
->device
->pnp
.device_class
,
2662 dev_name(&ibm
->acpi
->device
->dev
),
2668 static void hotkey_suspend(pm_message_t state
)
2670 /* Do these on suspend, we get the events on early resume! */
2671 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
2672 hotkey_autosleep_ack
= 0;
2675 static void hotkey_resume(void)
2677 tpacpi_disable_brightness_delay();
2679 if (hotkey_mask_get())
2681 "error while trying to read hot key mask "
2683 tpacpi_send_radiosw_update();
2684 hotkey_tablet_mode_notify_change();
2685 hotkey_wakeup_reason_notify_change();
2686 hotkey_wakeup_hotunplug_complete_notify_change();
2687 hotkey_poll_setup_safe(0);
2690 /* procfs -------------------------------------------------------------- */
2691 static int hotkey_read(char *p
)
2696 if (!tp_features
.hotkey
) {
2697 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2701 if (mutex_lock_interruptible(&hotkey_mutex
))
2702 return -ERESTARTSYS
;
2703 res
= hotkey_status_get(&status
);
2705 res
= hotkey_mask_get();
2706 mutex_unlock(&hotkey_mutex
);
2710 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
2711 if (tp_features
.hotkey_mask
) {
2712 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", hotkey_mask
);
2713 len
+= sprintf(p
+ len
,
2714 "commands:\tenable, disable, reset, <mask>\n");
2716 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
2717 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
2723 static int hotkey_write(char *buf
)
2729 if (!tp_features
.hotkey
)
2732 if (mutex_lock_interruptible(&hotkey_mutex
))
2733 return -ERESTARTSYS
;
2739 while ((cmd
= next_cmd(&buf
))) {
2740 if (strlencmp(cmd
, "enable") == 0) {
2742 } else if (strlencmp(cmd
, "disable") == 0) {
2744 } else if (strlencmp(cmd
, "reset") == 0) {
2745 status
= hotkey_orig_status
;
2746 mask
= hotkey_orig_mask
;
2747 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
2749 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
2757 res
= hotkey_status_set(status
);
2759 if (!res
&& mask
!= hotkey_mask
)
2760 res
= hotkey_mask_set(mask
);
2763 mutex_unlock(&hotkey_mutex
);
2767 static const struct acpi_device_id ibm_htk_device_ids
[] = {
2768 {TPACPI_ACPI_HKEY_HID
, 0},
2772 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
2773 .hid
= ibm_htk_device_ids
,
2774 .notify
= hotkey_notify
,
2775 .handle
= &hkey_handle
,
2776 .type
= ACPI_DEVICE_NOTIFY
,
2779 static struct ibm_struct hotkey_driver_data
= {
2781 .read
= hotkey_read
,
2782 .write
= hotkey_write
,
2783 .exit
= hotkey_exit
,
2784 .resume
= hotkey_resume
,
2785 .suspend
= hotkey_suspend
,
2786 .acpi
= &ibm_hotkey_acpidriver
,
2789 /*************************************************************************
2790 * Bluetooth subdriver
2794 /* ACPI GBDC/SBDC bits */
2795 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
2796 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
2797 TP_ACPI_BLUETOOTH_RESUMECTRL
= 0x04, /* Bluetooth state at resume:
2802 /* ACPI \BLTH commands */
2803 TP_ACPI_BLTH_GET_ULTRAPORT_ID
= 0x00, /* Get Ultraport BT ID */
2804 TP_ACPI_BLTH_GET_PWR_ON_RESUME
= 0x01, /* Get power-on-resume state */
2805 TP_ACPI_BLTH_PWR_ON_ON_RESUME
= 0x02, /* Resume powered on */
2806 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
= 0x03, /* Resume powered off */
2807 TP_ACPI_BLTH_SAVE_STATE
= 0x05, /* Save state for S4/S5 */
2810 static struct rfkill
*tpacpi_bluetooth_rfkill
;
2812 static void bluetooth_suspend(pm_message_t state
)
2814 /* Try to make sure radio will resume powered off */
2815 acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
2816 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
);
2819 static int bluetooth_get_radiosw(void)
2823 if (!tp_features
.bluetooth
)
2826 /* WLSW overrides bluetooth in firmware/hardware, reflect that */
2827 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
2828 return RFKILL_STATE_HARD_BLOCKED
;
2830 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2831 if (dbg_bluetoothemul
)
2832 return (tpacpi_bluetooth_emulstate
) ?
2833 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
2836 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
2839 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0) ?
2840 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
2843 static void bluetooth_update_rfk(void)
2847 if (!tpacpi_bluetooth_rfkill
)
2850 status
= bluetooth_get_radiosw();
2853 rfkill_force_state(tpacpi_bluetooth_rfkill
, status
);
2856 static int bluetooth_set_radiosw(int radio_on
, int update_rfk
)
2860 if (!tp_features
.bluetooth
)
2863 /* WLSW overrides bluetooth in firmware/hardware, but there is no
2864 * reason to risk weird behaviour. */
2865 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
2869 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2870 if (dbg_bluetoothemul
) {
2871 tpacpi_bluetooth_emulstate
= !!radio_on
;
2873 bluetooth_update_rfk();
2878 /* We make sure to keep TP_ACPI_BLUETOOTH_RESUMECTRL off */
2880 status
= TP_ACPI_BLUETOOTH_RADIOSSW
;
2883 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
2887 bluetooth_update_rfk();
2892 /* sysfs bluetooth enable ---------------------------------------------- */
2893 static ssize_t
bluetooth_enable_show(struct device
*dev
,
2894 struct device_attribute
*attr
,
2899 status
= bluetooth_get_radiosw();
2903 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2904 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
2907 static ssize_t
bluetooth_enable_store(struct device
*dev
,
2908 struct device_attribute
*attr
,
2909 const char *buf
, size_t count
)
2914 if (parse_strtoul(buf
, 1, &t
))
2917 res
= bluetooth_set_radiosw(t
, 1);
2919 return (res
) ? res
: count
;
2922 static struct device_attribute dev_attr_bluetooth_enable
=
2923 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
2924 bluetooth_enable_show
, bluetooth_enable_store
);
2926 /* --------------------------------------------------------------------- */
2928 static struct attribute
*bluetooth_attributes
[] = {
2929 &dev_attr_bluetooth_enable
.attr
,
2933 static const struct attribute_group bluetooth_attr_group
= {
2934 .attrs
= bluetooth_attributes
,
2937 static int tpacpi_bluetooth_rfk_get(void *data
, enum rfkill_state
*state
)
2939 int bts
= bluetooth_get_radiosw();
2948 static int tpacpi_bluetooth_rfk_set(void *data
, enum rfkill_state state
)
2950 return bluetooth_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
2953 static void bluetooth_exit(void)
2955 if (tpacpi_bluetooth_rfkill
)
2956 rfkill_unregister(tpacpi_bluetooth_rfkill
);
2958 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2959 &bluetooth_attr_group
);
2962 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
2967 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
2969 TPACPI_ACPIHANDLE_INIT(hkey
);
2971 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2972 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
2973 tp_features
.bluetooth
= hkey_handle
&&
2974 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
2976 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
2977 str_supported(tp_features
.bluetooth
),
2980 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2981 if (dbg_bluetoothemul
) {
2982 tp_features
.bluetooth
= 1;
2984 "bluetooth switch emulation enabled\n");
2987 if (tp_features
.bluetooth
&&
2988 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
2989 /* no bluetooth hardware present in system */
2990 tp_features
.bluetooth
= 0;
2991 dbg_printk(TPACPI_DBG_INIT
,
2992 "bluetooth hardware not installed\n");
2995 if (!tp_features
.bluetooth
)
2998 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2999 &bluetooth_attr_group
);
3003 res
= tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
,
3004 &tpacpi_bluetooth_rfkill
,
3005 RFKILL_TYPE_BLUETOOTH
,
3006 "tpacpi_bluetooth_sw",
3007 tpacpi_bluetooth_rfk_set
,
3008 tpacpi_bluetooth_rfk_get
);
3017 /* procfs -------------------------------------------------------------- */
3018 static int bluetooth_read(char *p
)
3021 int status
= bluetooth_get_radiosw();
3023 if (!tp_features
.bluetooth
)
3024 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3026 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3027 (status
== RFKILL_STATE_UNBLOCKED
) ?
3028 "enabled" : "disabled");
3029 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
3035 static int bluetooth_write(char *buf
)
3039 if (!tp_features
.bluetooth
)
3042 while ((cmd
= next_cmd(&buf
))) {
3043 if (strlencmp(cmd
, "enable") == 0) {
3044 bluetooth_set_radiosw(1, 1);
3045 } else if (strlencmp(cmd
, "disable") == 0) {
3046 bluetooth_set_radiosw(0, 1);
3054 static struct ibm_struct bluetooth_driver_data
= {
3055 .name
= "bluetooth",
3056 .read
= bluetooth_read
,
3057 .write
= bluetooth_write
,
3058 .exit
= bluetooth_exit
,
3059 .suspend
= bluetooth_suspend
,
3062 /*************************************************************************
3067 /* ACPI GWAN/SWAN bits */
3068 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
3069 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
3070 TP_ACPI_WANCARD_RESUMECTRL
= 0x04, /* Wan state at resume:
3074 static struct rfkill
*tpacpi_wan_rfkill
;
3076 static void wan_suspend(pm_message_t state
)
3078 /* Try to make sure radio will resume powered off */
3079 acpi_evalf(NULL
, NULL
, "\\WGSV", "qvd",
3080 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
);
3083 static int wan_get_radiosw(void)
3087 if (!tp_features
.wan
)
3090 /* WLSW overrides WWAN in firmware/hardware, reflect that */
3091 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3092 return RFKILL_STATE_HARD_BLOCKED
;
3094 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3096 return (tpacpi_wwan_emulstate
) ?
3097 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3100 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
3103 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0) ?
3104 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3107 static void wan_update_rfk(void)
3111 if (!tpacpi_wan_rfkill
)
3114 status
= wan_get_radiosw();
3117 rfkill_force_state(tpacpi_wan_rfkill
, status
);
3120 static int wan_set_radiosw(int radio_on
, int update_rfk
)
3124 if (!tp_features
.wan
)
3127 /* WLSW overrides bluetooth in firmware/hardware, but there is no
3128 * reason to risk weird behaviour. */
3129 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3133 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3135 tpacpi_wwan_emulstate
= !!radio_on
;
3142 /* We make sure to keep TP_ACPI_WANCARD_RESUMECTRL off */
3144 status
= TP_ACPI_WANCARD_RADIOSSW
;
3147 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
3156 /* sysfs wan enable ---------------------------------------------------- */
3157 static ssize_t
wan_enable_show(struct device
*dev
,
3158 struct device_attribute
*attr
,
3163 status
= wan_get_radiosw();
3167 return snprintf(buf
, PAGE_SIZE
, "%d\n",
3168 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
3171 static ssize_t
wan_enable_store(struct device
*dev
,
3172 struct device_attribute
*attr
,
3173 const char *buf
, size_t count
)
3178 if (parse_strtoul(buf
, 1, &t
))
3181 res
= wan_set_radiosw(t
, 1);
3183 return (res
) ? res
: count
;
3186 static struct device_attribute dev_attr_wan_enable
=
3187 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
3188 wan_enable_show
, wan_enable_store
);
3190 /* --------------------------------------------------------------------- */
3192 static struct attribute
*wan_attributes
[] = {
3193 &dev_attr_wan_enable
.attr
,
3197 static const struct attribute_group wan_attr_group
= {
3198 .attrs
= wan_attributes
,
3201 static int tpacpi_wan_rfk_get(void *data
, enum rfkill_state
*state
)
3203 int wans
= wan_get_radiosw();
3212 static int tpacpi_wan_rfk_set(void *data
, enum rfkill_state state
)
3214 return wan_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
3217 static void wan_exit(void)
3219 if (tpacpi_wan_rfkill
)
3220 rfkill_unregister(tpacpi_wan_rfkill
);
3222 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3226 static int __init
wan_init(struct ibm_init_struct
*iibm
)
3231 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
3233 TPACPI_ACPIHANDLE_INIT(hkey
);
3235 tp_features
.wan
= hkey_handle
&&
3236 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
3238 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
3239 str_supported(tp_features
.wan
),
3242 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3244 tp_features
.wan
= 1;
3246 "wwan switch emulation enabled\n");
3249 if (tp_features
.wan
&&
3250 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
3251 /* no wan hardware present in system */
3252 tp_features
.wan
= 0;
3253 dbg_printk(TPACPI_DBG_INIT
,
3254 "wan hardware not installed\n");
3257 if (!tp_features
.wan
)
3260 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3265 res
= tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID
,
3270 tpacpi_wan_rfk_get
);
3279 /* procfs -------------------------------------------------------------- */
3280 static int wan_read(char *p
)
3283 int status
= wan_get_radiosw();
3285 if (!tp_features
.wan
)
3286 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3288 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3289 (status
== RFKILL_STATE_UNBLOCKED
) ?
3290 "enabled" : "disabled");
3291 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
3297 static int wan_write(char *buf
)
3301 if (!tp_features
.wan
)
3304 while ((cmd
= next_cmd(&buf
))) {
3305 if (strlencmp(cmd
, "enable") == 0) {
3306 wan_set_radiosw(1, 1);
3307 } else if (strlencmp(cmd
, "disable") == 0) {
3308 wan_set_radiosw(0, 1);
3316 static struct ibm_struct wan_driver_data
= {
3321 .suspend
= wan_suspend
,
3324 /*************************************************************************
3328 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
3330 enum video_access_mode
{
3331 TPACPI_VIDEO_NONE
= 0,
3332 TPACPI_VIDEO_570
, /* 570 */
3333 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
3334 TPACPI_VIDEO_NEW
, /* all others */
3337 enum { /* video status flags, based on VIDEO_570 */
3338 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
3339 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
3340 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
3343 enum { /* TPACPI_VIDEO_570 constants */
3344 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
3345 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
3346 * video_status_flags */
3347 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
3348 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
3351 static enum video_access_mode video_supported
;
3352 static int video_orig_autosw
;
3354 static int video_autosw_get(void);
3355 static int video_autosw_set(int enable
);
3357 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
3359 static int __init
video_init(struct ibm_init_struct
*iibm
)
3363 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
3365 TPACPI_ACPIHANDLE_INIT(vid
);
3366 TPACPI_ACPIHANDLE_INIT(vid2
);
3368 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
3369 /* G41, assume IVGA doesn't change */
3370 vid_handle
= vid2_handle
;
3373 /* video switching not supported on R30, R31 */
3374 video_supported
= TPACPI_VIDEO_NONE
;
3375 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
3377 video_supported
= TPACPI_VIDEO_570
;
3378 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
3379 /* 600e/x, 770e, 770x */
3380 video_supported
= TPACPI_VIDEO_770
;
3383 video_supported
= TPACPI_VIDEO_NEW
;
3385 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
3386 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
3389 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
3392 static void video_exit(void)
3394 dbg_printk(TPACPI_DBG_EXIT
,
3395 "restoring original video autoswitch mode\n");
3396 if (video_autosw_set(video_orig_autosw
))
3397 printk(TPACPI_ERR
"error while trying to restore original "
3398 "video autoswitch mode\n");
3401 static int video_outputsw_get(void)
3406 switch (video_supported
) {
3407 case TPACPI_VIDEO_570
:
3408 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
3409 TP_ACPI_VIDEO_570_PHSCMD
))
3411 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
3413 case TPACPI_VIDEO_770
:
3414 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
3417 status
|= TP_ACPI_VIDEO_S_LCD
;
3418 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
3421 status
|= TP_ACPI_VIDEO_S_CRT
;
3423 case TPACPI_VIDEO_NEW
:
3424 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
3425 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
3428 status
|= TP_ACPI_VIDEO_S_CRT
;
3430 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
3431 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
3434 status
|= TP_ACPI_VIDEO_S_LCD
;
3435 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
3438 status
|= TP_ACPI_VIDEO_S_DVI
;
3447 static int video_outputsw_set(int status
)
3452 switch (video_supported
) {
3453 case TPACPI_VIDEO_570
:
3454 res
= acpi_evalf(NULL
, NULL
,
3455 "\\_SB.PHS2", "vdd",
3456 TP_ACPI_VIDEO_570_PHS2CMD
,
3457 status
| TP_ACPI_VIDEO_570_PHS2SET
);
3459 case TPACPI_VIDEO_770
:
3460 autosw
= video_autosw_get();
3464 res
= video_autosw_set(1);
3467 res
= acpi_evalf(vid_handle
, NULL
,
3468 "ASWT", "vdd", status
* 0x100, 0);
3469 if (!autosw
&& video_autosw_set(autosw
)) {
3471 "video auto-switch left enabled due to error\n");
3475 case TPACPI_VIDEO_NEW
:
3476 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
3477 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
3483 return (res
)? 0 : -EIO
;
3486 static int video_autosw_get(void)
3490 switch (video_supported
) {
3491 case TPACPI_VIDEO_570
:
3492 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
3495 case TPACPI_VIDEO_770
:
3496 case TPACPI_VIDEO_NEW
:
3497 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
3507 static int video_autosw_set(int enable
)
3509 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
3514 static int video_outputsw_cycle(void)
3516 int autosw
= video_autosw_get();
3522 switch (video_supported
) {
3523 case TPACPI_VIDEO_570
:
3524 res
= video_autosw_set(1);
3527 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
3529 case TPACPI_VIDEO_770
:
3530 case TPACPI_VIDEO_NEW
:
3531 res
= video_autosw_set(1);
3534 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
3539 if (!autosw
&& video_autosw_set(autosw
)) {
3541 "video auto-switch left enabled due to error\n");
3545 return (res
)? 0 : -EIO
;
3548 static int video_expand_toggle(void)
3550 switch (video_supported
) {
3551 case TPACPI_VIDEO_570
:
3552 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
3554 case TPACPI_VIDEO_770
:
3555 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
3557 case TPACPI_VIDEO_NEW
:
3558 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
3566 static int video_read(char *p
)
3571 if (video_supported
== TPACPI_VIDEO_NONE
) {
3572 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3576 status
= video_outputsw_get();
3580 autosw
= video_autosw_get();
3584 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3585 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
3586 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
3587 if (video_supported
== TPACPI_VIDEO_NEW
)
3588 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
3589 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
3590 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
3591 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
3592 if (video_supported
== TPACPI_VIDEO_NEW
)
3593 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
3594 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
3595 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
3600 static int video_write(char *buf
)
3603 int enable
, disable
, status
;
3606 if (video_supported
== TPACPI_VIDEO_NONE
)
3612 while ((cmd
= next_cmd(&buf
))) {
3613 if (strlencmp(cmd
, "lcd_enable") == 0) {
3614 enable
|= TP_ACPI_VIDEO_S_LCD
;
3615 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
3616 disable
|= TP_ACPI_VIDEO_S_LCD
;
3617 } else if (strlencmp(cmd
, "crt_enable") == 0) {
3618 enable
|= TP_ACPI_VIDEO_S_CRT
;
3619 } else if (strlencmp(cmd
, "crt_disable") == 0) {
3620 disable
|= TP_ACPI_VIDEO_S_CRT
;
3621 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
3622 strlencmp(cmd
, "dvi_enable") == 0) {
3623 enable
|= TP_ACPI_VIDEO_S_DVI
;
3624 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
3625 strlencmp(cmd
, "dvi_disable") == 0) {
3626 disable
|= TP_ACPI_VIDEO_S_DVI
;
3627 } else if (strlencmp(cmd
, "auto_enable") == 0) {
3628 res
= video_autosw_set(1);
3631 } else if (strlencmp(cmd
, "auto_disable") == 0) {
3632 res
= video_autosw_set(0);
3635 } else if (strlencmp(cmd
, "video_switch") == 0) {
3636 res
= video_outputsw_cycle();
3639 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
3640 res
= video_expand_toggle();
3647 if (enable
|| disable
) {
3648 status
= video_outputsw_get();
3651 res
= video_outputsw_set((status
& ~disable
) | enable
);
3659 static struct ibm_struct video_driver_data
= {
3662 .write
= video_write
,
3666 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
3668 /*************************************************************************
3669 * Light (thinklight) subdriver
3672 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
3673 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
3675 static int light_get_status(void)
3679 if (tp_features
.light_status
) {
3680 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
3688 static int light_set_status(int status
)
3692 if (tp_features
.light
) {
3694 rc
= acpi_evalf(cmos_handle
, NULL
, NULL
, "vd",
3696 TP_CMOS_THINKLIGHT_ON
:
3697 TP_CMOS_THINKLIGHT_OFF
);
3699 rc
= acpi_evalf(lght_handle
, NULL
, NULL
, "vd",
3702 return (rc
)? 0 : -EIO
;
3708 static void light_set_status_worker(struct work_struct
*work
)
3710 struct tpacpi_led_classdev
*data
=
3711 container_of(work
, struct tpacpi_led_classdev
, work
);
3713 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
3714 light_set_status((data
->new_state
!= TPACPI_LED_OFF
));
3717 static void light_sysfs_set(struct led_classdev
*led_cdev
,
3718 enum led_brightness brightness
)
3720 struct tpacpi_led_classdev
*data
=
3721 container_of(led_cdev
,
3722 struct tpacpi_led_classdev
,
3724 data
->new_state
= (brightness
!= LED_OFF
) ?
3725 TPACPI_LED_ON
: TPACPI_LED_OFF
;
3726 queue_work(tpacpi_wq
, &data
->work
);
3729 static enum led_brightness
light_sysfs_get(struct led_classdev
*led_cdev
)
3731 return (light_get_status() == 1)? LED_FULL
: LED_OFF
;
3734 static struct tpacpi_led_classdev tpacpi_led_thinklight
= {
3736 .name
= "tpacpi::thinklight",
3737 .brightness_set
= &light_sysfs_set
,
3738 .brightness_get
= &light_sysfs_get
,
3742 static int __init
light_init(struct ibm_init_struct
*iibm
)
3746 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
3748 TPACPI_ACPIHANDLE_INIT(ledb
);
3749 TPACPI_ACPIHANDLE_INIT(lght
);
3750 TPACPI_ACPIHANDLE_INIT(cmos
);
3751 INIT_WORK(&tpacpi_led_thinklight
.work
, light_set_status_worker
);
3753 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
3754 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
3756 if (tp_features
.light
)
3757 /* light status not supported on
3758 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
3759 tp_features
.light_status
=
3760 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
3762 vdbg_printk(TPACPI_DBG_INIT
, "light is %s, light status is %s\n",
3763 str_supported(tp_features
.light
),
3764 str_supported(tp_features
.light_status
));
3766 if (!tp_features
.light
)
3769 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
3770 &tpacpi_led_thinklight
.led_classdev
);
3773 tp_features
.light
= 0;
3774 tp_features
.light_status
= 0;
3782 static void light_exit(void)
3784 led_classdev_unregister(&tpacpi_led_thinklight
.led_classdev
);
3785 if (work_pending(&tpacpi_led_thinklight
.work
))
3786 flush_workqueue(tpacpi_wq
);
3789 static int light_read(char *p
)
3794 if (!tp_features
.light
) {
3795 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3796 } else if (!tp_features
.light_status
) {
3797 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
3798 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
3800 status
= light_get_status();
3803 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
3804 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
3810 static int light_write(char *buf
)
3815 if (!tp_features
.light
)
3818 while ((cmd
= next_cmd(&buf
))) {
3819 if (strlencmp(cmd
, "on") == 0) {
3821 } else if (strlencmp(cmd
, "off") == 0) {
3827 return light_set_status(newstatus
);
3830 static struct ibm_struct light_driver_data
= {
3833 .write
= light_write
,
3837 /*************************************************************************
3841 #ifdef CONFIG_THINKPAD_ACPI_DOCK
3843 static void dock_notify(struct ibm_struct
*ibm
, u32 event
);
3844 static int dock_read(char *p
);
3845 static int dock_write(char *buf
);
3847 TPACPI_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
3848 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
3849 "\\_SB.PCI0.PCI1.DOCK", /* all others */
3850 "\\_SB.PCI.ISA.SLCE", /* 570 */
3851 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
3853 /* don't list other alternatives as we install a notify handler on the 570 */
3854 TPACPI_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
3856 static const struct acpi_device_id ibm_pci_device_ids
[] = {
3857 {PCI_ROOT_HID_STRING
, 0},
3861 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
3863 .notify
= dock_notify
,
3864 .handle
= &dock_handle
,
3865 .type
= ACPI_SYSTEM_NOTIFY
,
3868 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
3869 * We just use it to get notifications of dock hotplug
3870 * in very old thinkpads */
3871 .hid
= ibm_pci_device_ids
,
3872 .notify
= dock_notify
,
3873 .handle
= &pci_handle
,
3874 .type
= ACPI_SYSTEM_NOTIFY
,
3878 static struct ibm_struct dock_driver_data
[2] = {
3882 .write
= dock_write
,
3883 .acpi
= &ibm_dock_acpidriver
[0],
3887 .acpi
= &ibm_dock_acpidriver
[1],
3891 #define dock_docked() (_sta(dock_handle) & 1)
3893 static int __init
dock_init(struct ibm_init_struct
*iibm
)
3895 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
3897 TPACPI_ACPIHANDLE_INIT(dock
);
3899 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
3900 str_supported(dock_handle
!= NULL
));
3902 return (dock_handle
)? 0 : 1;
3905 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
3909 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
3911 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
3912 dock_driver_data
[0].flags
.acpi_notify_installed
) {
3913 TPACPI_ACPIHANDLE_INIT(pci
);
3914 dock2_needed
= (pci_handle
!= NULL
);
3915 vdbg_printk(TPACPI_DBG_INIT
,
3916 "dock PCI handler for the TP 570 is %s\n",
3917 str_supported(dock2_needed
));
3919 vdbg_printk(TPACPI_DBG_INIT
,
3920 "dock subdriver part 2 not required\n");
3924 return (dock2_needed
)? 0 : 1;
3927 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
3929 int docked
= dock_docked();
3930 int pci
= ibm
->acpi
->hid
&& ibm
->acpi
->device
&&
3931 acpi_match_device_ids(ibm
->acpi
->device
, ibm_pci_device_ids
);
3934 if (event
== 1 && !pci
) /* 570 */
3935 data
= 1; /* button */
3936 else if (event
== 1 && pci
) /* 570 */
3937 data
= 3; /* dock */
3938 else if (event
== 3 && docked
)
3939 data
= 1; /* button */
3940 else if (event
== 3 && !docked
)
3941 data
= 2; /* undock */
3942 else if (event
== 0 && docked
)
3943 data
= 3; /* dock */
3945 printk(TPACPI_ERR
"unknown dock event %d, status %d\n",
3946 event
, _sta(dock_handle
));
3947 data
= 0; /* unknown */
3949 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, data
);
3950 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
3951 dev_name(&ibm
->acpi
->device
->dev
),
3955 static int dock_read(char *p
)
3958 int docked
= dock_docked();
3961 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3963 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
3965 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
3966 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
3972 static int dock_write(char *buf
)
3979 while ((cmd
= next_cmd(&buf
))) {
3980 if (strlencmp(cmd
, "undock") == 0) {
3981 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
3982 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
3984 } else if (strlencmp(cmd
, "dock") == 0) {
3985 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
3994 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
3996 /*************************************************************************
4000 #ifdef CONFIG_THINKPAD_ACPI_BAY
4002 TPACPI_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
4003 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
4004 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
4005 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
4006 ); /* A21e, R30, R31 */
4007 TPACPI_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
4008 "_EJ0", /* all others */
4009 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
4010 TPACPI_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
4011 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
4013 TPACPI_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
4017 static int __init
bay_init(struct ibm_init_struct
*iibm
)
4019 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
4021 TPACPI_ACPIHANDLE_INIT(bay
);
4023 TPACPI_ACPIHANDLE_INIT(bay_ej
);
4024 TPACPI_ACPIHANDLE_INIT(bay2
);
4026 TPACPI_ACPIHANDLE_INIT(bay2_ej
);
4028 tp_features
.bay_status
= bay_handle
&&
4029 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
4030 tp_features
.bay_status2
= bay2_handle
&&
4031 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
4033 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
4034 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
4035 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
4036 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
4038 vdbg_printk(TPACPI_DBG_INIT
,
4039 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
4040 str_supported(tp_features
.bay_status
),
4041 str_supported(tp_features
.bay_eject
),
4042 str_supported(tp_features
.bay_status2
),
4043 str_supported(tp_features
.bay_eject2
));
4045 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
4046 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
4049 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
4051 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, 0);
4052 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
4053 dev_name(&ibm
->acpi
->device
->dev
),
4057 #define bay_occupied(b) (_sta(b##_handle) & 1)
4059 static int bay_read(char *p
)
4062 int occupied
= bay_occupied(bay
);
4063 int occupied2
= bay_occupied(bay2
);
4066 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
4067 tp_features
.bay_status
?
4068 (occupied
? "occupied" : "unoccupied") :
4070 if (tp_features
.bay_status2
)
4071 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
4072 "occupied" : "unoccupied");
4074 eject
= tp_features
.bay_eject
&& occupied
;
4075 eject2
= tp_features
.bay_eject2
&& occupied2
;
4077 if (eject
&& eject2
)
4078 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
4080 len
+= sprintf(p
+ len
, "commands:\teject\n");
4082 len
+= sprintf(p
+ len
, "commands:\teject2\n");
4087 static int bay_write(char *buf
)
4091 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
4094 while ((cmd
= next_cmd(&buf
))) {
4095 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
4096 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
4098 } else if (tp_features
.bay_eject2
&&
4099 strlencmp(cmd
, "eject2") == 0) {
4100 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
4109 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
4110 .notify
= bay_notify
,
4111 .handle
= &bay_handle
,
4112 .type
= ACPI_SYSTEM_NOTIFY
,
4115 static struct ibm_struct bay_driver_data
= {
4119 .acpi
= &ibm_bay_acpidriver
,
4122 #endif /* CONFIG_THINKPAD_ACPI_BAY */
4124 /*************************************************************************
4128 /* sysfs cmos_command -------------------------------------------------- */
4129 static ssize_t
cmos_command_store(struct device
*dev
,
4130 struct device_attribute
*attr
,
4131 const char *buf
, size_t count
)
4133 unsigned long cmos_cmd
;
4136 if (parse_strtoul(buf
, 21, &cmos_cmd
))
4139 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4140 return (res
)? res
: count
;
4143 static struct device_attribute dev_attr_cmos_command
=
4144 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
4146 /* --------------------------------------------------------------------- */
4148 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
4152 vdbg_printk(TPACPI_DBG_INIT
,
4153 "initializing cmos commands subdriver\n");
4155 TPACPI_ACPIHANDLE_INIT(cmos
);
4157 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
4158 str_supported(cmos_handle
!= NULL
));
4160 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4164 return (cmos_handle
)? 0 : 1;
4167 static void cmos_exit(void)
4169 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4172 static int cmos_read(char *p
)
4176 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4177 R30, R31, T20-22, X20-21 */
4179 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4181 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4182 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
4188 static int cmos_write(char *buf
)
4193 while ((cmd
= next_cmd(&buf
))) {
4194 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
4195 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
4200 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4208 static struct ibm_struct cmos_driver_data
= {
4211 .write
= cmos_write
,
4215 /*************************************************************************
4219 enum led_access_mode
{
4220 TPACPI_LED_NONE
= 0,
4221 TPACPI_LED_570
, /* 570 */
4222 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4223 TPACPI_LED_NEW
, /* all others */
4226 enum { /* For TPACPI_LED_OLD */
4227 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
4228 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
4229 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
4232 static enum led_access_mode led_supported
;
4234 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
4235 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
4236 /* T20-22, X20-21 */
4237 "LED", /* all others */
4240 #define TPACPI_LED_NUMLEDS 8
4241 static struct tpacpi_led_classdev
*tpacpi_leds
;
4242 static enum led_status_t tpacpi_led_state_cache
[TPACPI_LED_NUMLEDS
];
4243 static const char * const tpacpi_led_names
[TPACPI_LED_NUMLEDS
] = {
4244 /* there's a limit of 19 chars + NULL before 2.6.26 */
4246 "tpacpi:orange:batt",
4247 "tpacpi:green:batt",
4248 "tpacpi::dock_active",
4249 "tpacpi::bay_active",
4250 "tpacpi::dock_batt",
4251 "tpacpi::unknown_led",
4255 static int led_get_status(const unsigned int led
)
4258 enum led_status_t led_s
;
4260 switch (led_supported
) {
4261 case TPACPI_LED_570
:
4262 if (!acpi_evalf(ec_handle
,
4263 &status
, "GLED", "dd", 1 << led
))
4265 led_s
= (status
== 0)?
4270 tpacpi_led_state_cache
[led
] = led_s
;
4279 static int led_set_status(const unsigned int led
,
4280 const enum led_status_t ledstatus
)
4282 /* off, on, blink. Index is led_status_t */
4283 static const unsigned int led_sled_arg1
[] = { 0, 1, 3 };
4284 static const unsigned int led_led_arg1
[] = { 0, 0x80, 0xc0 };
4288 switch (led_supported
) {
4289 case TPACPI_LED_570
:
4293 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
4294 (1 << led
), led_sled_arg1
[ledstatus
]))
4297 case TPACPI_LED_OLD
:
4298 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
4301 rc
= ec_write(TPACPI_LED_EC_HLMS
, (1 << led
));
4303 rc
= ec_write(TPACPI_LED_EC_HLBL
,
4304 (ledstatus
== TPACPI_LED_BLINK
) << led
);
4306 rc
= ec_write(TPACPI_LED_EC_HLCL
,
4307 (ledstatus
!= TPACPI_LED_OFF
) << led
);
4309 case TPACPI_LED_NEW
:
4311 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
4312 led
, led_led_arg1
[ledstatus
]))
4320 tpacpi_led_state_cache
[led
] = ledstatus
;
4325 static void led_set_status_worker(struct work_struct
*work
)
4327 struct tpacpi_led_classdev
*data
=
4328 container_of(work
, struct tpacpi_led_classdev
, work
);
4330 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4331 led_set_status(data
->led
, data
->new_state
);
4334 static void led_sysfs_set(struct led_classdev
*led_cdev
,
4335 enum led_brightness brightness
)
4337 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4338 struct tpacpi_led_classdev
, led_classdev
);
4340 if (brightness
== LED_OFF
)
4341 data
->new_state
= TPACPI_LED_OFF
;
4342 else if (tpacpi_led_state_cache
[data
->led
] != TPACPI_LED_BLINK
)
4343 data
->new_state
= TPACPI_LED_ON
;
4345 data
->new_state
= TPACPI_LED_BLINK
;
4347 queue_work(tpacpi_wq
, &data
->work
);
4350 static int led_sysfs_blink_set(struct led_classdev
*led_cdev
,
4351 unsigned long *delay_on
, unsigned long *delay_off
)
4353 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4354 struct tpacpi_led_classdev
, led_classdev
);
4356 /* Can we choose the flash rate? */
4357 if (*delay_on
== 0 && *delay_off
== 0) {
4358 /* yes. set them to the hardware blink rate (1 Hz) */
4359 *delay_on
= 500; /* ms */
4360 *delay_off
= 500; /* ms */
4361 } else if ((*delay_on
!= 500) || (*delay_off
!= 500))
4364 data
->new_state
= TPACPI_LED_BLINK
;
4365 queue_work(tpacpi_wq
, &data
->work
);
4370 static enum led_brightness
led_sysfs_get(struct led_classdev
*led_cdev
)
4374 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4375 struct tpacpi_led_classdev
, led_classdev
);
4377 rc
= led_get_status(data
->led
);
4379 if (rc
== TPACPI_LED_OFF
|| rc
< 0)
4380 rc
= LED_OFF
; /* no error handling in led class :( */
4387 static void led_exit(void)
4391 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
4392 if (tpacpi_leds
[i
].led_classdev
.name
)
4393 led_classdev_unregister(&tpacpi_leds
[i
].led_classdev
);
4399 static int __init
led_init(struct ibm_init_struct
*iibm
)
4404 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
4406 TPACPI_ACPIHANDLE_INIT(led
);
4409 /* led not supported on R30, R31 */
4410 led_supported
= TPACPI_LED_NONE
;
4411 else if (strlencmp(led_path
, "SLED") == 0)
4413 led_supported
= TPACPI_LED_570
;
4414 else if (strlencmp(led_path
, "SYSL") == 0)
4415 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4416 led_supported
= TPACPI_LED_OLD
;
4419 led_supported
= TPACPI_LED_NEW
;
4421 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
4422 str_supported(led_supported
), led_supported
);
4424 tpacpi_leds
= kzalloc(sizeof(*tpacpi_leds
) * TPACPI_LED_NUMLEDS
,
4427 printk(TPACPI_ERR
"Out of memory for LED data\n");
4431 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
4432 tpacpi_leds
[i
].led
= i
;
4434 tpacpi_leds
[i
].led_classdev
.brightness_set
= &led_sysfs_set
;
4435 tpacpi_leds
[i
].led_classdev
.blink_set
= &led_sysfs_blink_set
;
4436 if (led_supported
== TPACPI_LED_570
)
4437 tpacpi_leds
[i
].led_classdev
.brightness_get
=
4440 tpacpi_leds
[i
].led_classdev
.name
= tpacpi_led_names
[i
];
4442 INIT_WORK(&tpacpi_leds
[i
].work
, led_set_status_worker
);
4444 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4445 &tpacpi_leds
[i
].led_classdev
);
4447 tpacpi_leds
[i
].led_classdev
.name
= NULL
;
4453 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
4456 #define str_led_status(s) \
4457 ((s) == TPACPI_LED_OFF ? "off" : \
4458 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
4460 static int led_read(char *p
)
4464 if (!led_supported
) {
4465 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4468 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4470 if (led_supported
== TPACPI_LED_570
) {
4473 for (i
= 0; i
< 8; i
++) {
4474 status
= led_get_status(i
);
4477 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
4478 i
, str_led_status(status
));
4482 len
+= sprintf(p
+ len
, "commands:\t"
4483 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
4488 static int led_write(char *buf
)
4492 enum led_status_t s
;
4497 while ((cmd
= next_cmd(&buf
))) {
4498 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
4501 if (strstr(cmd
, "off")) {
4503 } else if (strstr(cmd
, "on")) {
4505 } else if (strstr(cmd
, "blink")) {
4506 s
= TPACPI_LED_BLINK
;
4511 rc
= led_set_status(led
, s
);
4519 static struct ibm_struct led_driver_data
= {
4526 /*************************************************************************
4530 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
4532 static int __init
beep_init(struct ibm_init_struct
*iibm
)
4534 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
4536 TPACPI_ACPIHANDLE_INIT(beep
);
4538 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
4539 str_supported(beep_handle
!= NULL
));
4541 return (beep_handle
)? 0 : 1;
4544 static int beep_read(char *p
)
4549 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4551 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4552 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
4558 static int beep_write(char *buf
)
4566 while ((cmd
= next_cmd(&buf
))) {
4567 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
4568 beep_cmd
>= 0 && beep_cmd
<= 17) {
4572 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
4579 static struct ibm_struct beep_driver_data
= {
4582 .write
= beep_write
,
4585 /*************************************************************************
4589 enum thermal_access_mode
{
4590 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
4591 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
4592 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
4593 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
4594 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
4597 enum { /* TPACPI_THERMAL_TPEC_* */
4598 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
4599 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
4600 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
4603 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
4604 struct ibm_thermal_sensors_struct
{
4605 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
4608 static enum thermal_access_mode thermal_read_mode
;
4610 /* idx is zero-based */
4611 static int thermal_get_sensor(int idx
, s32
*value
)
4617 t
= TP_EC_THERMAL_TMP0
;
4619 switch (thermal_read_mode
) {
4620 #if TPACPI_MAX_THERMAL_SENSORS >= 16
4621 case TPACPI_THERMAL_TPEC_16
:
4622 if (idx
>= 8 && idx
<= 15) {
4623 t
= TP_EC_THERMAL_TMP8
;
4628 case TPACPI_THERMAL_TPEC_8
:
4630 if (!acpi_ec_read(t
+ idx
, &tmp
))
4632 *value
= tmp
* 1000;
4637 case TPACPI_THERMAL_ACPI_UPDT
:
4639 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
4640 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
4642 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
4644 *value
= (t
- 2732) * 100;
4649 case TPACPI_THERMAL_ACPI_TMP07
:
4651 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
4652 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
4654 if (t
> 127 || t
< -127)
4655 t
= TP_EC_THERMAL_TMP_NA
;
4661 case TPACPI_THERMAL_NONE
:
4669 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
4680 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
4683 for (i
= 0 ; i
< n
; i
++) {
4684 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
4692 /* sysfs temp##_input -------------------------------------------------- */
4694 static ssize_t
thermal_temp_input_show(struct device
*dev
,
4695 struct device_attribute
*attr
,
4698 struct sensor_device_attribute
*sensor_attr
=
4699 to_sensor_dev_attr(attr
);
4700 int idx
= sensor_attr
->index
;
4704 res
= thermal_get_sensor(idx
, &value
);
4707 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
4710 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
4713 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
4714 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
4715 thermal_temp_input_show, NULL, _idxB)
4717 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
4718 THERMAL_SENSOR_ATTR_TEMP(1, 0),
4719 THERMAL_SENSOR_ATTR_TEMP(2, 1),
4720 THERMAL_SENSOR_ATTR_TEMP(3, 2),
4721 THERMAL_SENSOR_ATTR_TEMP(4, 3),
4722 THERMAL_SENSOR_ATTR_TEMP(5, 4),
4723 THERMAL_SENSOR_ATTR_TEMP(6, 5),
4724 THERMAL_SENSOR_ATTR_TEMP(7, 6),
4725 THERMAL_SENSOR_ATTR_TEMP(8, 7),
4726 THERMAL_SENSOR_ATTR_TEMP(9, 8),
4727 THERMAL_SENSOR_ATTR_TEMP(10, 9),
4728 THERMAL_SENSOR_ATTR_TEMP(11, 10),
4729 THERMAL_SENSOR_ATTR_TEMP(12, 11),
4730 THERMAL_SENSOR_ATTR_TEMP(13, 12),
4731 THERMAL_SENSOR_ATTR_TEMP(14, 13),
4732 THERMAL_SENSOR_ATTR_TEMP(15, 14),
4733 THERMAL_SENSOR_ATTR_TEMP(16, 15),
4736 #define THERMAL_ATTRS(X) \
4737 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
4739 static struct attribute
*thermal_temp_input_attr
[] = {
4759 static const struct attribute_group thermal_temp_input16_group
= {
4760 .attrs
= thermal_temp_input_attr
4763 static const struct attribute_group thermal_temp_input8_group
= {
4764 .attrs
= &thermal_temp_input_attr
[8]
4767 #undef THERMAL_SENSOR_ATTR_TEMP
4768 #undef THERMAL_ATTRS
4770 /* --------------------------------------------------------------------- */
4772 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
4779 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
4781 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
4783 if (thinkpad_id
.ec_model
) {
4785 * Direct EC access mode: sensors at registers
4786 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
4787 * non-implemented, thermal sensors return 0x80 when
4792 for (i
= 0; i
< 8; i
++) {
4793 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
4799 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
4807 /* This is sheer paranoia, but we handle it anyway */
4810 "ThinkPad ACPI EC access misbehaving, "
4811 "falling back to ACPI TMPx access "
4813 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
4816 "ThinkPad ACPI EC access misbehaving, "
4817 "disabling thermal sensors access\n");
4818 thermal_read_mode
= TPACPI_THERMAL_NONE
;
4823 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
4825 } else if (acpi_tmp7
) {
4826 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
4827 /* 600e/x, 770e, 770x */
4828 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
4830 /* Standard ACPI TMPx access, max 8 sensors */
4831 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
4834 /* temperatures not supported on 570, G4x, R30, R31, R32 */
4835 thermal_read_mode
= TPACPI_THERMAL_NONE
;
4838 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
4839 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
4842 switch (thermal_read_mode
) {
4843 case TPACPI_THERMAL_TPEC_16
:
4844 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4845 &thermal_temp_input16_group
);
4849 case TPACPI_THERMAL_TPEC_8
:
4850 case TPACPI_THERMAL_ACPI_TMP07
:
4851 case TPACPI_THERMAL_ACPI_UPDT
:
4852 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4853 &thermal_temp_input8_group
);
4857 case TPACPI_THERMAL_NONE
:
4865 static void thermal_exit(void)
4867 switch (thermal_read_mode
) {
4868 case TPACPI_THERMAL_TPEC_16
:
4869 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4870 &thermal_temp_input16_group
);
4872 case TPACPI_THERMAL_TPEC_8
:
4873 case TPACPI_THERMAL_ACPI_TMP07
:
4874 case TPACPI_THERMAL_ACPI_UPDT
:
4875 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4876 &thermal_temp_input16_group
);
4878 case TPACPI_THERMAL_NONE
:
4884 static int thermal_read(char *p
)
4888 struct ibm_thermal_sensors_struct t
;
4890 n
= thermal_get_sensors(&t
);
4891 if (unlikely(n
< 0))
4894 len
+= sprintf(p
+ len
, "temperatures:\t");
4897 for (i
= 0; i
< (n
- 1); i
++)
4898 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
4899 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
4901 len
+= sprintf(p
+ len
, "not supported\n");
4906 static struct ibm_struct thermal_driver_data
= {
4908 .read
= thermal_read
,
4909 .exit
= thermal_exit
,
4912 /*************************************************************************
4916 static u8 ecdump_regs
[256];
4918 static int ecdump_read(char *p
)
4924 len
+= sprintf(p
+ len
, "EC "
4925 " +00 +01 +02 +03 +04 +05 +06 +07"
4926 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
4927 for (i
= 0; i
< 256; i
+= 16) {
4928 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
4929 for (j
= 0; j
< 16; j
++) {
4930 if (!acpi_ec_read(i
+ j
, &v
))
4932 if (v
!= ecdump_regs
[i
+ j
])
4933 len
+= sprintf(p
+ len
, " *%02x", v
);
4935 len
+= sprintf(p
+ len
, " %02x", v
);
4936 ecdump_regs
[i
+ j
] = v
;
4938 len
+= sprintf(p
+ len
, "\n");
4943 /* These are way too dangerous to advertise openly... */
4945 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
4946 " (<offset> is 00-ff, <value> is 00-ff)\n");
4947 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
4948 " (<offset> is 00-ff, <value> is 0-255)\n");
4953 static int ecdump_write(char *buf
)
4958 while ((cmd
= next_cmd(&buf
))) {
4959 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
4961 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
4965 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
4966 if (!acpi_ec_write(i
, v
))
4975 static struct ibm_struct ecdump_driver_data
= {
4977 .read
= ecdump_read
,
4978 .write
= ecdump_write
,
4979 .flags
.experimental
= 1,
4982 /*************************************************************************
4983 * Backlight/brightness subdriver
4986 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
4989 TP_EC_BACKLIGHT
= 0x31,
4991 /* TP_EC_BACKLIGHT bitmasks */
4992 TP_EC_BACKLIGHT_LVLMSK
= 0x1F,
4993 TP_EC_BACKLIGHT_CMDMSK
= 0xE0,
4994 TP_EC_BACKLIGHT_MAPSW
= 0x20,
4997 static struct backlight_device
*ibm_backlight_device
;
4998 static int brightness_mode
;
4999 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
5001 static struct mutex brightness_mutex
;
5004 * ThinkPads can read brightness from two places: EC 0x31, or
5005 * CMOS NVRAM byte 0x5E, bits 0-3.
5007 * EC 0x31 has the following layout
5008 * Bit 7: unknown function
5009 * Bit 6: unknown function
5010 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
5011 * Bit 4: must be set to zero to avoid problems
5012 * Bit 3-0: backlight brightness level
5014 * brightness_get_raw returns status data in the EC 0x31 layout
5016 static int brightness_get_raw(int *status
)
5018 u8 lec
= 0, lcmos
= 0, level
= 0;
5020 if (brightness_mode
& 1) {
5021 if (!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
))
5023 level
= lec
& TP_EC_BACKLIGHT_LVLMSK
;
5025 if (brightness_mode
& 2) {
5026 lcmos
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
5027 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5028 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
5029 lcmos
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
5033 if (brightness_mode
== 3) {
5034 *status
= lec
; /* Prefer EC, CMOS is just a backing store */
5035 lec
&= TP_EC_BACKLIGHT_LVLMSK
;
5037 tp_warned
.bright_cmos_ec_unsync
= 0;
5039 if (!tp_warned
.bright_cmos_ec_unsync
) {
5041 "CMOS NVRAM (%u) and EC (%u) do not "
5042 "agree on display brightness level\n",
5043 (unsigned int) lcmos
,
5044 (unsigned int) lec
);
5045 tp_warned
.bright_cmos_ec_unsync
= 1;
5056 /* May return EINTR which can always be mapped to ERESTARTSYS */
5057 static int brightness_set(int value
)
5059 int cmos_cmd
, inc
, i
, res
;
5063 if (value
> ((tp_features
.bright_16levels
)? 15 : 7) ||
5067 res
= mutex_lock_interruptible(&brightness_mutex
);
5071 res
= brightness_get_raw(¤t_value
);
5075 command_bits
= current_value
& TP_EC_BACKLIGHT_CMDMSK
;
5076 current_value
&= TP_EC_BACKLIGHT_LVLMSK
;
5078 cmos_cmd
= value
> current_value
?
5079 TP_CMOS_BRIGHTNESS_UP
:
5080 TP_CMOS_BRIGHTNESS_DOWN
;
5081 inc
= (value
> current_value
)? 1 : -1;
5084 for (i
= current_value
; i
!= value
; i
+= inc
) {
5085 if ((brightness_mode
& 2) &&
5086 issue_thinkpad_cmos_command(cmos_cmd
)) {
5090 if ((brightness_mode
& 1) &&
5091 !acpi_ec_write(TP_EC_BACKLIGHT
,
5092 (i
+ inc
) | command_bits
)) {
5099 mutex_unlock(&brightness_mutex
);
5103 /* sysfs backlight class ----------------------------------------------- */
5105 static int brightness_update_status(struct backlight_device
*bd
)
5107 /* it is the backlight class's job (caller) to handle
5108 * EINTR and other errors properly */
5109 return brightness_set(
5110 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
5111 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
5112 bd
->props
.brightness
: 0);
5115 static int brightness_get(struct backlight_device
*bd
)
5119 res
= brightness_get_raw(&status
);
5121 return 0; /* FIXME: teach backlight about error handling */
5123 return status
& TP_EC_BACKLIGHT_LVLMSK
;
5126 static struct backlight_ops ibm_backlight_data
= {
5127 .get_brightness
= brightness_get
,
5128 .update_status
= brightness_update_status
,
5131 /* --------------------------------------------------------------------- */
5133 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
5137 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
5139 mutex_init(&brightness_mutex
);
5142 * We always attempt to detect acpi support, so as to switch
5143 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
5144 * going to publish a backlight interface
5146 b
= tpacpi_check_std_acpi_brightness_support();
5149 if (acpi_video_backlight_support()) {
5150 if (brightness_enable
> 1) {
5151 printk(TPACPI_NOTICE
5152 "Standard ACPI backlight interface "
5153 "available, not loading native one.\n");
5155 } else if (brightness_enable
== 1) {
5156 printk(TPACPI_NOTICE
5157 "Backlight control force enabled, even if standard "
5158 "ACPI backlight interface is available\n");
5161 if (brightness_enable
> 1) {
5162 printk(TPACPI_NOTICE
5163 "Standard ACPI backlight interface not "
5164 "available, thinkpad_acpi native "
5165 "brightness control enabled\n");
5170 if (!brightness_enable
) {
5171 dbg_printk(TPACPI_DBG_INIT
,
5172 "brightness support disabled by "
5173 "module parameter\n");
5179 "Unsupported brightness interface, "
5180 "please contact %s\n", TPACPI_MAIL
);
5184 tp_features
.bright_16levels
= 1;
5186 if (!brightness_mode
) {
5187 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
)
5188 brightness_mode
= 2;
5190 brightness_mode
= 3;
5192 dbg_printk(TPACPI_DBG_INIT
, "selected brightness_mode=%d\n",
5196 if (brightness_mode
> 3)
5199 if (brightness_get_raw(&b
) < 0)
5202 if (tp_features
.bright_16levels
)
5204 "detected a 16-level brightness capable ThinkPad\n");
5206 ibm_backlight_device
= backlight_device_register(
5207 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
5208 &ibm_backlight_data
);
5209 if (IS_ERR(ibm_backlight_device
)) {
5210 printk(TPACPI_ERR
"Could not register backlight device\n");
5211 return PTR_ERR(ibm_backlight_device
);
5213 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
5215 ibm_backlight_device
->props
.max_brightness
=
5216 (tp_features
.bright_16levels
)? 15 : 7;
5217 ibm_backlight_device
->props
.brightness
= b
& TP_EC_BACKLIGHT_LVLMSK
;
5218 backlight_update_status(ibm_backlight_device
);
5223 static void brightness_exit(void)
5225 if (ibm_backlight_device
) {
5226 vdbg_printk(TPACPI_DBG_EXIT
,
5227 "calling backlight_device_unregister()\n");
5228 backlight_device_unregister(ibm_backlight_device
);
5232 static int brightness_read(char *p
)
5237 level
= brightness_get(NULL
);
5239 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
5241 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
5242 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
5243 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
5244 " (<level> is 0-%d)\n",
5245 (tp_features
.bright_16levels
) ? 15 : 7);
5251 static int brightness_write(char *buf
)
5256 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
5258 level
= brightness_get(NULL
);
5262 while ((cmd
= next_cmd(&buf
))) {
5263 if (strlencmp(cmd
, "up") == 0) {
5264 if (level
< max_level
)
5266 } else if (strlencmp(cmd
, "down") == 0) {
5269 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
5270 level
>= 0 && level
<= max_level
) {
5277 * Now we know what the final level should be, so we try to set it.
5278 * Doing it this way makes the syscall restartable in case of EINTR
5280 rc
= brightness_set(level
);
5281 return (rc
== -EINTR
)? ERESTARTSYS
: rc
;
5284 static struct ibm_struct brightness_driver_data
= {
5285 .name
= "brightness",
5286 .read
= brightness_read
,
5287 .write
= brightness_write
,
5288 .exit
= brightness_exit
,
5291 /*************************************************************************
5295 static int volume_offset
= 0x30;
5297 static int volume_read(char *p
)
5302 if (!acpi_ec_read(volume_offset
, &level
)) {
5303 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
5305 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
5306 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
5307 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
5308 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
5309 " (<level> is 0-15)\n");
5315 static int volume_write(char *buf
)
5317 int cmos_cmd
, inc
, i
;
5319 int new_level
, new_mute
;
5322 while ((cmd
= next_cmd(&buf
))) {
5323 if (!acpi_ec_read(volume_offset
, &level
))
5325 new_mute
= mute
= level
& 0x40;
5326 new_level
= level
= level
& 0xf;
5328 if (strlencmp(cmd
, "up") == 0) {
5332 new_level
= level
== 15 ? 15 : level
+ 1;
5333 } else if (strlencmp(cmd
, "down") == 0) {
5337 new_level
= level
== 0 ? 0 : level
- 1;
5338 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
5339 new_level
>= 0 && new_level
<= 15) {
5341 } else if (strlencmp(cmd
, "mute") == 0) {
5346 if (new_level
!= level
) {
5347 /* mute doesn't change */
5349 cmos_cmd
= (new_level
> level
) ?
5350 TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
5351 inc
= new_level
> level
? 1 : -1;
5353 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
5354 !acpi_ec_write(volume_offset
, level
)))
5357 for (i
= level
; i
!= new_level
; i
+= inc
)
5358 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
5359 !acpi_ec_write(volume_offset
, i
+ inc
))
5363 (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
5364 !acpi_ec_write(volume_offset
, new_level
+ mute
))) {
5369 if (new_mute
!= mute
) {
5370 /* level doesn't change */
5372 cmos_cmd
= (new_mute
) ?
5373 TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
5375 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
5376 !acpi_ec_write(volume_offset
, level
+ new_mute
))
5384 static struct ibm_struct volume_driver_data
= {
5386 .read
= volume_read
,
5387 .write
= volume_write
,
5390 /*************************************************************************
5397 * TPACPI_FAN_RD_ACPI_GFAN:
5398 * ACPI GFAN method: returns fan level
5400 * see TPACPI_FAN_WR_ACPI_SFAN
5401 * EC 0x2f (HFSP) not available if GFAN exists
5403 * TPACPI_FAN_WR_ACPI_SFAN:
5404 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
5406 * EC 0x2f (HFSP) might be available *for reading*, but do not use
5409 * TPACPI_FAN_WR_TPEC:
5410 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
5411 * Supported on almost all ThinkPads
5413 * Fan speed changes of any sort (including those caused by the
5414 * disengaged mode) are usually done slowly by the firmware as the
5415 * maximum ammount of fan duty cycle change per second seems to be
5418 * Reading is not available if GFAN exists.
5419 * Writing is not available if SFAN exists.
5422 * 7 automatic mode engaged;
5423 * (default operation mode of the ThinkPad)
5424 * fan level is ignored in this mode.
5425 * 6 full speed mode (takes precedence over bit 7);
5426 * not available on all thinkpads. May disable
5427 * the tachometer while the fan controller ramps up
5428 * the speed (which can take up to a few *minutes*).
5429 * Speeds up fan to 100% duty-cycle, which is far above
5430 * the standard RPM levels. It is not impossible that
5431 * it could cause hardware damage.
5432 * 5-3 unused in some models. Extra bits for fan level
5433 * in others, but still useless as all values above
5434 * 7 map to the same speed as level 7 in these models.
5435 * 2-0 fan level (0..7 usually)
5437 * 0x07 = max (set when temperatures critical)
5438 * Some ThinkPads may have other levels, see
5439 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
5441 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
5442 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
5443 * does so, its initial value is meaningless (0x07).
5445 * For firmware bugs, refer to:
5446 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
5450 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
5451 * Main fan tachometer reading (in RPM)
5453 * This register is present on all ThinkPads with a new-style EC, and
5454 * it is known not to be present on the A21m/e, and T22, as there is
5455 * something else in offset 0x84 according to the ACPI DSDT. Other
5456 * ThinkPads from this same time period (and earlier) probably lack the
5457 * tachometer as well.
5459 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
5460 * was never fixed by IBM to report the EC firmware version string
5461 * probably support the tachometer (like the early X models), so
5462 * detecting it is quite hard. We need more data to know for sure.
5464 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
5467 * FIRMWARE BUG: may go stale while the EC is switching to full speed
5470 * For firmware bugs, refer to:
5471 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
5473 * TPACPI_FAN_WR_ACPI_FANS:
5474 * ThinkPad X31, X40, X41. Not available in the X60.
5476 * FANS ACPI handle: takes three arguments: low speed, medium speed,
5477 * high speed. ACPI DSDT seems to map these three speeds to levels
5478 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
5479 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
5481 * The speeds are stored on handles
5482 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
5484 * There are three default speed sets, acessible as handles:
5485 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
5487 * ACPI DSDT switches which set is in use depending on various
5490 * TPACPI_FAN_WR_TPEC is also available and should be used to
5491 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
5492 * but the ACPI tables just mention level 7.
5495 enum { /* Fan control constants */
5496 fan_status_offset
= 0x2f, /* EC register 0x2f */
5497 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
5498 * 0x84 must be read before 0x85 */
5500 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
5501 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
5503 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
5506 enum fan_status_access_mode
{
5507 TPACPI_FAN_NONE
= 0, /* No fan status or control */
5508 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
5509 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
5512 enum fan_control_access_mode
{
5513 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
5514 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
5515 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
5516 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
5519 enum fan_control_commands
{
5520 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
5521 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
5522 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
5523 * and also watchdog cmd */
5526 static int fan_control_allowed
;
5528 static enum fan_status_access_mode fan_status_access_mode
;
5529 static enum fan_control_access_mode fan_control_access_mode
;
5530 static enum fan_control_commands fan_control_commands
;
5532 static u8 fan_control_initial_status
;
5533 static u8 fan_control_desired_level
;
5534 static u8 fan_control_resume_level
;
5535 static int fan_watchdog_maxinterval
;
5537 static struct mutex fan_mutex
;
5539 static void fan_watchdog_fire(struct work_struct
*ignored
);
5540 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
5542 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
5543 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
5544 "\\FSPD", /* 600e/x, 770e, 770x */
5546 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
5547 "JFNS", /* 770x-JL */
5551 * Call with fan_mutex held
5553 static void fan_update_desired_level(u8 status
)
5556 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
5558 fan_control_desired_level
= 7;
5560 fan_control_desired_level
= status
;
5564 static int fan_get_status(u8
*status
)
5569 * Add TPACPI_FAN_RD_ACPI_FANS ? */
5571 switch (fan_status_access_mode
) {
5572 case TPACPI_FAN_RD_ACPI_GFAN
:
5573 /* 570, 600e/x, 770e, 770x */
5575 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
5583 case TPACPI_FAN_RD_TPEC
:
5584 /* all except 570, 600e/x, 770e, 770x */
5585 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
5600 static int fan_get_status_safe(u8
*status
)
5605 if (mutex_lock_interruptible(&fan_mutex
))
5606 return -ERESTARTSYS
;
5607 rc
= fan_get_status(&s
);
5609 fan_update_desired_level(s
);
5610 mutex_unlock(&fan_mutex
);
5618 static int fan_get_speed(unsigned int *speed
)
5622 switch (fan_status_access_mode
) {
5623 case TPACPI_FAN_RD_TPEC
:
5624 /* all except 570, 600e/x, 770e, 770x */
5625 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
5626 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
5630 *speed
= (hi
<< 8) | lo
;
5641 static int fan_set_level(int level
)
5643 if (!fan_control_allowed
)
5646 switch (fan_control_access_mode
) {
5647 case TPACPI_FAN_WR_ACPI_SFAN
:
5648 if (level
>= 0 && level
<= 7) {
5649 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
5655 case TPACPI_FAN_WR_ACPI_FANS
:
5656 case TPACPI_FAN_WR_TPEC
:
5657 if (!(level
& TP_EC_FAN_AUTO
) &&
5658 !(level
& TP_EC_FAN_FULLSPEED
) &&
5659 ((level
< 0) || (level
> 7)))
5662 /* safety net should the EC not support AUTO
5663 * or FULLSPEED mode bits and just ignore them */
5664 if (level
& TP_EC_FAN_FULLSPEED
)
5665 level
|= 7; /* safety min speed 7 */
5666 else if (level
& TP_EC_FAN_AUTO
)
5667 level
|= 4; /* safety min speed 4 */
5669 if (!acpi_ec_write(fan_status_offset
, level
))
5672 tp_features
.fan_ctrl_status_undef
= 0;
5681 static int fan_set_level_safe(int level
)
5685 if (!fan_control_allowed
)
5688 if (mutex_lock_interruptible(&fan_mutex
))
5689 return -ERESTARTSYS
;
5691 if (level
== TPACPI_FAN_LAST_LEVEL
)
5692 level
= fan_control_desired_level
;
5694 rc
= fan_set_level(level
);
5696 fan_update_desired_level(level
);
5698 mutex_unlock(&fan_mutex
);
5702 static int fan_set_enable(void)
5707 if (!fan_control_allowed
)
5710 if (mutex_lock_interruptible(&fan_mutex
))
5711 return -ERESTARTSYS
;
5713 switch (fan_control_access_mode
) {
5714 case TPACPI_FAN_WR_ACPI_FANS
:
5715 case TPACPI_FAN_WR_TPEC
:
5716 rc
= fan_get_status(&s
);
5720 /* Don't go out of emergency fan mode */
5723 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
5726 if (!acpi_ec_write(fan_status_offset
, s
))
5729 tp_features
.fan_ctrl_status_undef
= 0;
5734 case TPACPI_FAN_WR_ACPI_SFAN
:
5735 rc
= fan_get_status(&s
);
5741 /* Set fan to at least level 4 */
5744 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
5754 mutex_unlock(&fan_mutex
);
5758 static int fan_set_disable(void)
5762 if (!fan_control_allowed
)
5765 if (mutex_lock_interruptible(&fan_mutex
))
5766 return -ERESTARTSYS
;
5769 switch (fan_control_access_mode
) {
5770 case TPACPI_FAN_WR_ACPI_FANS
:
5771 case TPACPI_FAN_WR_TPEC
:
5772 if (!acpi_ec_write(fan_status_offset
, 0x00))
5775 fan_control_desired_level
= 0;
5776 tp_features
.fan_ctrl_status_undef
= 0;
5780 case TPACPI_FAN_WR_ACPI_SFAN
:
5781 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
5784 fan_control_desired_level
= 0;
5792 mutex_unlock(&fan_mutex
);
5796 static int fan_set_speed(int speed
)
5800 if (!fan_control_allowed
)
5803 if (mutex_lock_interruptible(&fan_mutex
))
5804 return -ERESTARTSYS
;
5807 switch (fan_control_access_mode
) {
5808 case TPACPI_FAN_WR_ACPI_FANS
:
5809 if (speed
>= 0 && speed
<= 65535) {
5810 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
5811 speed
, speed
, speed
))
5821 mutex_unlock(&fan_mutex
);
5825 static void fan_watchdog_reset(void)
5827 static int fan_watchdog_active
;
5829 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
5832 if (fan_watchdog_active
)
5833 cancel_delayed_work(&fan_watchdog_task
);
5835 if (fan_watchdog_maxinterval
> 0 &&
5836 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
5837 fan_watchdog_active
= 1;
5838 if (!queue_delayed_work(tpacpi_wq
, &fan_watchdog_task
,
5839 msecs_to_jiffies(fan_watchdog_maxinterval
5842 "failed to queue the fan watchdog, "
5843 "watchdog will not trigger\n");
5846 fan_watchdog_active
= 0;
5849 static void fan_watchdog_fire(struct work_struct
*ignored
)
5853 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
5856 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
5857 rc
= fan_set_enable();
5859 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
5860 "will try again later...\n", -rc
);
5861 /* reschedule for later */
5862 fan_watchdog_reset();
5867 * SYSFS fan layout: hwmon compatible (device)
5870 * 0: "disengaged" mode
5872 * 2: native EC "auto" mode (recommended, hardware default)
5874 * pwm*: set speed in manual mode, ignored otherwise.
5875 * 0 is level 0; 255 is level 7. Intermediate points done with linear
5878 * fan*_input: tachometer reading, RPM
5881 * SYSFS fan layout: extensions
5883 * fan_watchdog (driver):
5884 * fan watchdog interval in seconds, 0 disables (default), max 120
5887 /* sysfs fan pwm1_enable ----------------------------------------------- */
5888 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
5889 struct device_attribute
*attr
,
5895 res
= fan_get_status_safe(&status
);
5899 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
5900 if (status
!= fan_control_initial_status
) {
5901 tp_features
.fan_ctrl_status_undef
= 0;
5903 /* Return most likely status. In fact, it
5904 * might be the only possible status */
5905 status
= TP_EC_FAN_AUTO
;
5909 if (status
& TP_EC_FAN_FULLSPEED
) {
5911 } else if (status
& TP_EC_FAN_AUTO
) {
5916 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
5919 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
5920 struct device_attribute
*attr
,
5921 const char *buf
, size_t count
)
5926 if (parse_strtoul(buf
, 2, &t
))
5931 level
= TP_EC_FAN_FULLSPEED
;
5934 level
= TPACPI_FAN_LAST_LEVEL
;
5937 level
= TP_EC_FAN_AUTO
;
5940 /* reserved for software-controlled auto mode */
5946 res
= fan_set_level_safe(level
);
5952 fan_watchdog_reset();
5957 static struct device_attribute dev_attr_fan_pwm1_enable
=
5958 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
5959 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
5961 /* sysfs fan pwm1 ------------------------------------------------------ */
5962 static ssize_t
fan_pwm1_show(struct device
*dev
,
5963 struct device_attribute
*attr
,
5969 res
= fan_get_status_safe(&status
);
5973 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
5974 if (status
!= fan_control_initial_status
) {
5975 tp_features
.fan_ctrl_status_undef
= 0;
5977 status
= TP_EC_FAN_AUTO
;
5982 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
5983 status
= fan_control_desired_level
;
5988 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
5991 static ssize_t
fan_pwm1_store(struct device
*dev
,
5992 struct device_attribute
*attr
,
5993 const char *buf
, size_t count
)
5997 u8 status
, newlevel
;
5999 if (parse_strtoul(buf
, 255, &s
))
6002 /* scale down from 0-255 to 0-7 */
6003 newlevel
= (s
>> 5) & 0x07;
6005 if (mutex_lock_interruptible(&fan_mutex
))
6006 return -ERESTARTSYS
;
6008 rc
= fan_get_status(&status
);
6009 if (!rc
&& (status
&
6010 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
6011 rc
= fan_set_level(newlevel
);
6015 fan_update_desired_level(newlevel
);
6016 fan_watchdog_reset();
6020 mutex_unlock(&fan_mutex
);
6021 return (rc
)? rc
: count
;
6024 static struct device_attribute dev_attr_fan_pwm1
=
6025 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
6026 fan_pwm1_show
, fan_pwm1_store
);
6028 /* sysfs fan fan1_input ------------------------------------------------ */
6029 static ssize_t
fan_fan1_input_show(struct device
*dev
,
6030 struct device_attribute
*attr
,
6036 res
= fan_get_speed(&speed
);
6040 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
6043 static struct device_attribute dev_attr_fan_fan1_input
=
6044 __ATTR(fan1_input
, S_IRUGO
,
6045 fan_fan1_input_show
, NULL
);
6047 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
6048 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
6051 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
6054 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
6055 const char *buf
, size_t count
)
6059 if (parse_strtoul(buf
, 120, &t
))
6062 if (!fan_control_allowed
)
6065 fan_watchdog_maxinterval
= t
;
6066 fan_watchdog_reset();
6071 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
6072 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
6074 /* --------------------------------------------------------------------- */
6075 static struct attribute
*fan_attributes
[] = {
6076 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
6077 &dev_attr_fan_fan1_input
.attr
,
6081 static const struct attribute_group fan_attr_group
= {
6082 .attrs
= fan_attributes
,
6085 static int __init
fan_init(struct ibm_init_struct
*iibm
)
6089 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
6091 mutex_init(&fan_mutex
);
6092 fan_status_access_mode
= TPACPI_FAN_NONE
;
6093 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
6094 fan_control_commands
= 0;
6095 fan_watchdog_maxinterval
= 0;
6096 tp_features
.fan_ctrl_status_undef
= 0;
6097 fan_control_desired_level
= 7;
6099 TPACPI_ACPIHANDLE_INIT(fans
);
6100 TPACPI_ACPIHANDLE_INIT(gfan
);
6101 TPACPI_ACPIHANDLE_INIT(sfan
);
6104 /* 570, 600e/x, 770e, 770x */
6105 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
6107 /* all other ThinkPads: note that even old-style
6108 * ThinkPad ECs supports the fan control register */
6109 if (likely(acpi_ec_read(fan_status_offset
,
6110 &fan_control_initial_status
))) {
6111 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
6113 /* In some ThinkPads, neither the EC nor the ACPI
6114 * DSDT initialize the fan status, and it ends up
6115 * being set to 0x07 when it *could* be either
6118 * Enable for TP-1Y (T43), TP-78 (R51e),
6119 * TP-76 (R52), TP-70 (T43, R52), which are known
6121 if (fan_control_initial_status
== 0x07) {
6122 switch (thinkpad_id
.ec_model
) {
6123 case 0x5931: /* TP-1Y */
6124 case 0x3837: /* TP-78 */
6125 case 0x3637: /* TP-76 */
6126 case 0x3037: /* TP-70 */
6127 printk(TPACPI_NOTICE
6128 "fan_init: initial fan status "
6129 "is unknown, assuming it is "
6131 tp_features
.fan_ctrl_status_undef
= 1;
6137 "ThinkPad ACPI EC access misbehaving, "
6138 "fan status and control unavailable\n");
6145 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
6146 fan_control_commands
|=
6147 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
6150 /* gfan without sfan means no fan control */
6151 /* all other models implement TP EC 0x2f control */
6155 fan_control_access_mode
=
6156 TPACPI_FAN_WR_ACPI_FANS
;
6157 fan_control_commands
|=
6158 TPACPI_FAN_CMD_SPEED
|
6159 TPACPI_FAN_CMD_LEVEL
|
6160 TPACPI_FAN_CMD_ENABLE
;
6162 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
6163 fan_control_commands
|=
6164 TPACPI_FAN_CMD_LEVEL
|
6165 TPACPI_FAN_CMD_ENABLE
;
6170 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
6171 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
6172 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
6173 fan_status_access_mode
, fan_control_access_mode
);
6175 /* fan control master switch */
6176 if (!fan_control_allowed
) {
6177 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
6178 fan_control_commands
= 0;
6179 dbg_printk(TPACPI_DBG_INIT
,
6180 "fan control features disabled by parameter\n");
6183 /* update fan_control_desired_level */
6184 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
6185 fan_get_status_safe(NULL
);
6187 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
6188 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
6189 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
6194 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
6195 &driver_attr_fan_watchdog
);
6197 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
6206 static void fan_exit(void)
6208 vdbg_printk(TPACPI_DBG_EXIT
,
6209 "cancelling any pending fan watchdog tasks\n");
6211 /* FIXME: can we really do this unconditionally? */
6212 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
6213 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
6214 &driver_attr_fan_watchdog
);
6216 cancel_delayed_work(&fan_watchdog_task
);
6217 flush_workqueue(tpacpi_wq
);
6220 static void fan_suspend(pm_message_t state
)
6224 if (!fan_control_allowed
)
6227 /* Store fan status in cache */
6228 fan_control_resume_level
= 0;
6229 rc
= fan_get_status_safe(&fan_control_resume_level
);
6231 printk(TPACPI_NOTICE
6232 "failed to read fan level for later "
6233 "restore during resume: %d\n", rc
);
6235 /* if it is undefined, don't attempt to restore it.
6237 if (tp_features
.fan_ctrl_status_undef
)
6238 fan_control_resume_level
= 0;
6241 static void fan_resume(void)
6243 u8 current_level
= 7;
6244 bool do_set
= false;
6247 /* DSDT *always* updates status on resume */
6248 tp_features
.fan_ctrl_status_undef
= 0;
6250 if (!fan_control_allowed
||
6251 !fan_control_resume_level
||
6252 (fan_get_status_safe(¤t_level
) < 0))
6255 switch (fan_control_access_mode
) {
6256 case TPACPI_FAN_WR_ACPI_SFAN
:
6257 /* never decrease fan level */
6258 do_set
= (fan_control_resume_level
> current_level
);
6260 case TPACPI_FAN_WR_ACPI_FANS
:
6261 case TPACPI_FAN_WR_TPEC
:
6262 /* never decrease fan level, scale is:
6263 * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO
6265 * We expect the firmware to set either 7 or AUTO, but we
6266 * handle FULLSPEED out of paranoia.
6268 * So, we can safely only restore FULLSPEED or 7, anything
6269 * else could slow the fan. Restoring AUTO is useless, at
6270 * best that's exactly what the DSDT already set (it is the
6273 * Always keep in mind that the DSDT *will* have set the
6274 * fans to what the vendor supposes is the best level. We
6275 * muck with it only to speed the fan up.
6277 if (fan_control_resume_level
!= 7 &&
6278 !(fan_control_resume_level
& TP_EC_FAN_FULLSPEED
))
6281 do_set
= !(current_level
& TP_EC_FAN_FULLSPEED
) &&
6282 (current_level
!= fan_control_resume_level
);
6288 printk(TPACPI_NOTICE
6289 "restoring fan level to 0x%02x\n",
6290 fan_control_resume_level
);
6291 rc
= fan_set_level_safe(fan_control_resume_level
);
6293 printk(TPACPI_NOTICE
6294 "failed to restore fan level: %d\n", rc
);
6298 static int fan_read(char *p
)
6303 unsigned int speed
= 0;
6305 switch (fan_status_access_mode
) {
6306 case TPACPI_FAN_RD_ACPI_GFAN
:
6307 /* 570, 600e/x, 770e, 770x */
6308 rc
= fan_get_status_safe(&status
);
6312 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
6314 (status
!= 0) ? "enabled" : "disabled", status
);
6317 case TPACPI_FAN_RD_TPEC
:
6318 /* all except 570, 600e/x, 770e, 770x */
6319 rc
= fan_get_status_safe(&status
);
6323 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
6324 if (status
!= fan_control_initial_status
)
6325 tp_features
.fan_ctrl_status_undef
= 0;
6327 /* Return most likely status. In fact, it
6328 * might be the only possible status */
6329 status
= TP_EC_FAN_AUTO
;
6332 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
6333 (status
!= 0) ? "enabled" : "disabled");
6335 rc
= fan_get_speed(&speed
);
6339 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
6341 if (status
& TP_EC_FAN_FULLSPEED
)
6342 /* Disengaged mode takes precedence */
6343 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
6344 else if (status
& TP_EC_FAN_AUTO
)
6345 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
6347 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
6350 case TPACPI_FAN_NONE
:
6352 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
6355 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
6356 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
6358 switch (fan_control_access_mode
) {
6359 case TPACPI_FAN_WR_ACPI_SFAN
:
6360 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
6364 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
6365 "auto, disengaged, full-speed)\n");
6370 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
6371 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
6372 "commands:\twatchdog <timeout> (<timeout> "
6373 "is 0 (off), 1-120 (seconds))\n");
6375 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
6376 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
6377 " (<speed> is 0-65535)\n");
6382 static int fan_write_cmd_level(const char *cmd
, int *rc
)
6386 if (strlencmp(cmd
, "level auto") == 0)
6387 level
= TP_EC_FAN_AUTO
;
6388 else if ((strlencmp(cmd
, "level disengaged") == 0) |
6389 (strlencmp(cmd
, "level full-speed") == 0))
6390 level
= TP_EC_FAN_FULLSPEED
;
6391 else if (sscanf(cmd
, "level %d", &level
) != 1)
6394 *rc
= fan_set_level_safe(level
);
6396 printk(TPACPI_ERR
"level command accepted for unsupported "
6397 "access mode %d", fan_control_access_mode
);
6402 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
6404 if (strlencmp(cmd
, "enable") != 0)
6407 *rc
= fan_set_enable();
6409 printk(TPACPI_ERR
"enable command accepted for unsupported "
6410 "access mode %d", fan_control_access_mode
);
6415 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
6417 if (strlencmp(cmd
, "disable") != 0)
6420 *rc
= fan_set_disable();
6422 printk(TPACPI_ERR
"disable command accepted for unsupported "
6423 "access mode %d", fan_control_access_mode
);
6428 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
6433 * Support speed <low> <medium> <high> ? */
6435 if (sscanf(cmd
, "speed %d", &speed
) != 1)
6438 *rc
= fan_set_speed(speed
);
6440 printk(TPACPI_ERR
"speed command accepted for unsupported "
6441 "access mode %d", fan_control_access_mode
);
6446 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
6450 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
6453 if (interval
< 0 || interval
> 120)
6456 fan_watchdog_maxinterval
= interval
;
6461 static int fan_write(char *buf
)
6466 while (!rc
&& (cmd
= next_cmd(&buf
))) {
6467 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
6468 fan_write_cmd_level(cmd
, &rc
)) &&
6469 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
6470 (fan_write_cmd_enable(cmd
, &rc
) ||
6471 fan_write_cmd_disable(cmd
, &rc
) ||
6472 fan_write_cmd_watchdog(cmd
, &rc
))) &&
6473 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
6474 fan_write_cmd_speed(cmd
, &rc
))
6478 fan_watchdog_reset();
6484 static struct ibm_struct fan_driver_data
= {
6489 .suspend
= fan_suspend
,
6490 .resume
= fan_resume
,
6493 /****************************************************************************
6494 ****************************************************************************
6498 ****************************************************************************
6499 ****************************************************************************/
6501 /* sysfs name ---------------------------------------------------------- */
6502 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
6503 struct device_attribute
*attr
,
6506 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
6509 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
6510 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
6512 /* --------------------------------------------------------------------- */
6515 static struct proc_dir_entry
*proc_dir
;
6518 * Module and infrastructure proble, init and exit handling
6521 static int force_load
;
6523 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
6524 static const char * __init
str_supported(int is_supported
)
6526 static char text_unsupported
[] __initdata
= "not supported";
6528 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
6530 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
6532 static void ibm_exit(struct ibm_struct
*ibm
)
6534 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
6536 list_del_init(&ibm
->all_drivers
);
6538 if (ibm
->flags
.acpi_notify_installed
) {
6539 dbg_printk(TPACPI_DBG_EXIT
,
6540 "%s: acpi_remove_notify_handler\n", ibm
->name
);
6542 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
6544 dispatch_acpi_notify
);
6545 ibm
->flags
.acpi_notify_installed
= 0;
6546 ibm
->flags
.acpi_notify_installed
= 0;
6549 if (ibm
->flags
.proc_created
) {
6550 dbg_printk(TPACPI_DBG_EXIT
,
6551 "%s: remove_proc_entry\n", ibm
->name
);
6552 remove_proc_entry(ibm
->name
, proc_dir
);
6553 ibm
->flags
.proc_created
= 0;
6556 if (ibm
->flags
.acpi_driver_registered
) {
6557 dbg_printk(TPACPI_DBG_EXIT
,
6558 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
6560 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
6561 kfree(ibm
->acpi
->driver
);
6562 ibm
->acpi
->driver
= NULL
;
6563 ibm
->flags
.acpi_driver_registered
= 0;
6566 if (ibm
->flags
.init_called
&& ibm
->exit
) {
6568 ibm
->flags
.init_called
= 0;
6571 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
6574 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
6577 struct ibm_struct
*ibm
= iibm
->data
;
6578 struct proc_dir_entry
*entry
;
6580 BUG_ON(ibm
== NULL
);
6582 INIT_LIST_HEAD(&ibm
->all_drivers
);
6584 if (ibm
->flags
.experimental
&& !experimental
)
6587 dbg_printk(TPACPI_DBG_INIT
,
6588 "probing for %s\n", ibm
->name
);
6591 ret
= iibm
->init(iibm
);
6593 return 0; /* probe failed */
6597 ibm
->flags
.init_called
= 1;
6601 if (ibm
->acpi
->hid
) {
6602 ret
= register_tpacpi_subdriver(ibm
);
6607 if (ibm
->acpi
->notify
) {
6608 ret
= setup_acpi_notify(ibm
);
6609 if (ret
== -ENODEV
) {
6610 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
6620 dbg_printk(TPACPI_DBG_INIT
,
6621 "%s installed\n", ibm
->name
);
6624 entry
= create_proc_entry(ibm
->name
,
6625 S_IFREG
| S_IRUGO
| S_IWUSR
,
6628 printk(TPACPI_ERR
"unable to create proc entry %s\n",
6633 entry
->owner
= THIS_MODULE
;
6635 entry
->read_proc
= &dispatch_procfs_read
;
6637 entry
->write_proc
= &dispatch_procfs_write
;
6638 ibm
->flags
.proc_created
= 1;
6641 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
6646 dbg_printk(TPACPI_DBG_INIT
,
6647 "%s: at error exit path with result %d\n",
6651 return (ret
< 0)? ret
: 0;
6656 /* returns 0 - probe ok, or < 0 - probe error.
6657 * Probe ok doesn't mean thinkpad found.
6658 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
6659 static int __must_check __init
get_thinkpad_model_data(
6660 struct thinkpad_id_data
*tp
)
6662 const struct dmi_device
*dev
= NULL
;
6663 char ec_fw_string
[18];
6669 memset(tp
, 0, sizeof(*tp
));
6671 if (dmi_name_in_vendors("IBM"))
6672 tp
->vendor
= PCI_VENDOR_ID_IBM
;
6673 else if (dmi_name_in_vendors("LENOVO"))
6674 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
6678 s
= dmi_get_system_info(DMI_BIOS_VERSION
);
6679 tp
->bios_version_str
= kstrdup(s
, GFP_KERNEL
);
6680 if (s
&& !tp
->bios_version_str
)
6682 if (!tp
->bios_version_str
)
6684 tp
->bios_model
= tp
->bios_version_str
[0]
6685 | (tp
->bios_version_str
[1] << 8);
6688 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
6689 * X32 or newer, all Z series; Some models must have an
6690 * up-to-date BIOS or they will not be detected.
6692 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
6694 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
6695 if (sscanf(dev
->name
,
6696 "IBM ThinkPad Embedded Controller -[%17c",
6697 ec_fw_string
) == 1) {
6698 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
6699 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
6701 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
6702 if (!tp
->ec_version_str
)
6704 tp
->ec_model
= ec_fw_string
[0]
6705 | (ec_fw_string
[1] << 8);
6710 s
= dmi_get_system_info(DMI_PRODUCT_VERSION
);
6711 if (s
&& !strnicmp(s
, "ThinkPad", 8)) {
6712 tp
->model_str
= kstrdup(s
, GFP_KERNEL
);
6717 s
= dmi_get_system_info(DMI_PRODUCT_NAME
);
6718 tp
->nummodel_str
= kstrdup(s
, GFP_KERNEL
);
6719 if (s
&& !tp
->nummodel_str
)
6725 static int __init
probe_for_thinkpad(void)
6733 * Non-ancient models have better DMI tagging, but very old models
6736 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
6738 /* ec is required because many other handles are relative to it */
6739 TPACPI_ACPIHANDLE_INIT(ec
);
6743 "Not yet supported ThinkPad detected!\n");
6748 * Risks a regression on very old machines, but reduces potential
6749 * false positives a damn great deal
6752 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
6754 if (!is_thinkpad
&& !force_load
)
6761 /* Module init, exit, parameters */
6763 static struct ibm_init_struct ibms_init
[] __initdata
= {
6765 .init
= thinkpad_acpi_driver_init
,
6766 .data
= &thinkpad_acpi_driver_data
,
6769 .init
= hotkey_init
,
6770 .data
= &hotkey_driver_data
,
6773 .init
= bluetooth_init
,
6774 .data
= &bluetooth_driver_data
,
6778 .data
= &wan_driver_data
,
6780 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
6783 .data
= &video_driver_data
,
6788 .data
= &light_driver_data
,
6790 #ifdef CONFIG_THINKPAD_ACPI_DOCK
6793 .data
= &dock_driver_data
[0],
6797 .data
= &dock_driver_data
[1],
6800 #ifdef CONFIG_THINKPAD_ACPI_BAY
6803 .data
= &bay_driver_data
,
6808 .data
= &cmos_driver_data
,
6812 .data
= &led_driver_data
,
6816 .data
= &beep_driver_data
,
6819 .init
= thermal_init
,
6820 .data
= &thermal_driver_data
,
6823 .data
= &ecdump_driver_data
,
6826 .init
= brightness_init
,
6827 .data
= &brightness_driver_data
,
6830 .data
= &volume_driver_data
,
6834 .data
= &fan_driver_data
,
6838 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
6841 struct ibm_struct
*ibm
;
6843 if (!kp
|| !kp
->name
|| !val
)
6846 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
6847 ibm
= ibms_init
[i
].data
;
6848 WARN_ON(ibm
== NULL
);
6850 if (!ibm
|| !ibm
->name
)
6853 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
6854 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
6856 strcpy(ibms_init
[i
].param
, val
);
6857 strcat(ibms_init
[i
].param
, ",");
6865 module_param(experimental
, int, 0);
6866 MODULE_PARM_DESC(experimental
,
6867 "Enables experimental features when non-zero");
6869 module_param_named(debug
, dbg_level
, uint
, 0);
6870 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
6872 module_param(force_load
, bool, 0);
6873 MODULE_PARM_DESC(force_load
,
6874 "Attempts to load the driver even on a "
6875 "mis-identified ThinkPad when true");
6877 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
6878 MODULE_PARM_DESC(fan_control
,
6879 "Enables setting fan parameters features when true");
6881 module_param_named(brightness_mode
, brightness_mode
, int, 0);
6882 MODULE_PARM_DESC(brightness_mode
,
6883 "Selects brightness control strategy: "
6884 "0=auto, 1=EC, 2=CMOS, 3=both");
6886 module_param(brightness_enable
, uint
, 0);
6887 MODULE_PARM_DESC(brightness_enable
,
6888 "Enables backlight control when 1, disables when 0");
6890 module_param(hotkey_report_mode
, uint
, 0);
6891 MODULE_PARM_DESC(hotkey_report_mode
,
6892 "used for backwards compatibility with userspace, "
6893 "see documentation");
6895 #define TPACPI_PARAM(feature) \
6896 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
6897 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
6898 "at module load, see documentation")
6900 TPACPI_PARAM(hotkey
);
6901 TPACPI_PARAM(bluetooth
);
6902 TPACPI_PARAM(video
);
6903 TPACPI_PARAM(light
);
6904 #ifdef CONFIG_THINKPAD_ACPI_DOCK
6907 #ifdef CONFIG_THINKPAD_ACPI_BAY
6909 #endif /* CONFIG_THINKPAD_ACPI_BAY */
6913 TPACPI_PARAM(ecdump
);
6914 TPACPI_PARAM(brightness
);
6915 TPACPI_PARAM(volume
);
6918 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
6919 module_param(dbg_wlswemul
, uint
, 0);
6920 MODULE_PARM_DESC(dbg_wlswemul
, "Enables WLSW emulation");
6921 module_param_named(wlsw_state
, tpacpi_wlsw_emulstate
, bool, 0);
6922 MODULE_PARM_DESC(wlsw_state
,
6923 "Initial state of the emulated WLSW switch");
6925 module_param(dbg_bluetoothemul
, uint
, 0);
6926 MODULE_PARM_DESC(dbg_bluetoothemul
, "Enables bluetooth switch emulation");
6927 module_param_named(bluetooth_state
, tpacpi_bluetooth_emulstate
, bool, 0);
6928 MODULE_PARM_DESC(bluetooth_state
,
6929 "Initial state of the emulated bluetooth switch");
6931 module_param(dbg_wwanemul
, uint
, 0);
6932 MODULE_PARM_DESC(dbg_wwanemul
, "Enables WWAN switch emulation");
6933 module_param_named(wwan_state
, tpacpi_wwan_emulstate
, bool, 0);
6934 MODULE_PARM_DESC(wwan_state
,
6935 "Initial state of the emulated WWAN switch");
6938 static void thinkpad_acpi_module_exit(void)
6940 struct ibm_struct
*ibm
, *itmp
;
6942 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
6944 list_for_each_entry_safe_reverse(ibm
, itmp
,
6945 &tpacpi_all_drivers
,
6950 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
6952 if (tpacpi_inputdev
) {
6953 if (tp_features
.input_device_registered
)
6954 input_unregister_device(tpacpi_inputdev
);
6956 input_free_device(tpacpi_inputdev
);
6960 hwmon_device_unregister(tpacpi_hwmon
);
6962 if (tp_features
.sensors_pdev_attrs_registered
)
6963 device_remove_file(&tpacpi_sensors_pdev
->dev
,
6964 &dev_attr_thinkpad_acpi_pdev_name
);
6965 if (tpacpi_sensors_pdev
)
6966 platform_device_unregister(tpacpi_sensors_pdev
);
6968 platform_device_unregister(tpacpi_pdev
);
6970 if (tp_features
.sensors_pdrv_attrs_registered
)
6971 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
6972 if (tp_features
.platform_drv_attrs_registered
)
6973 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
6975 if (tp_features
.sensors_pdrv_registered
)
6976 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
6978 if (tp_features
.platform_drv_registered
)
6979 platform_driver_unregister(&tpacpi_pdriver
);
6982 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
6985 destroy_workqueue(tpacpi_wq
);
6987 kfree(thinkpad_id
.bios_version_str
);
6988 kfree(thinkpad_id
.ec_version_str
);
6989 kfree(thinkpad_id
.model_str
);
6993 static int __init
thinkpad_acpi_module_init(void)
6997 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
6999 /* Parameter checking */
7000 if (hotkey_report_mode
> 2)
7003 /* Driver-level probe */
7005 ret
= get_thinkpad_model_data(&thinkpad_id
);
7008 "unable to get DMI data: %d\n", ret
);
7009 thinkpad_acpi_module_exit();
7012 ret
= probe_for_thinkpad();
7014 thinkpad_acpi_module_exit();
7018 /* Driver initialization */
7020 TPACPI_ACPIHANDLE_INIT(ecrd
);
7021 TPACPI_ACPIHANDLE_INIT(ecwr
);
7023 tpacpi_wq
= create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME
);
7025 thinkpad_acpi_module_exit();
7029 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
7032 "unable to create proc dir " TPACPI_PROC_DIR
);
7033 thinkpad_acpi_module_exit();
7036 proc_dir
->owner
= THIS_MODULE
;
7038 ret
= platform_driver_register(&tpacpi_pdriver
);
7041 "unable to register main platform driver\n");
7042 thinkpad_acpi_module_exit();
7045 tp_features
.platform_drv_registered
= 1;
7047 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
7050 "unable to register hwmon platform driver\n");
7051 thinkpad_acpi_module_exit();
7054 tp_features
.sensors_pdrv_registered
= 1;
7056 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
7058 tp_features
.platform_drv_attrs_registered
= 1;
7059 ret
= tpacpi_create_driver_attributes(
7060 &tpacpi_hwmon_pdriver
.driver
);
7064 "unable to create sysfs driver attributes\n");
7065 thinkpad_acpi_module_exit();
7068 tp_features
.sensors_pdrv_attrs_registered
= 1;
7071 /* Device initialization */
7072 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
7074 if (IS_ERR(tpacpi_pdev
)) {
7075 ret
= PTR_ERR(tpacpi_pdev
);
7077 printk(TPACPI_ERR
"unable to register platform device\n");
7078 thinkpad_acpi_module_exit();
7081 tpacpi_sensors_pdev
= platform_device_register_simple(
7082 TPACPI_HWMON_DRVR_NAME
,
7084 if (IS_ERR(tpacpi_sensors_pdev
)) {
7085 ret
= PTR_ERR(tpacpi_sensors_pdev
);
7086 tpacpi_sensors_pdev
= NULL
;
7088 "unable to register hwmon platform device\n");
7089 thinkpad_acpi_module_exit();
7092 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
7093 &dev_attr_thinkpad_acpi_pdev_name
);
7096 "unable to create sysfs hwmon device attributes\n");
7097 thinkpad_acpi_module_exit();
7100 tp_features
.sensors_pdev_attrs_registered
= 1;
7101 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
7102 if (IS_ERR(tpacpi_hwmon
)) {
7103 ret
= PTR_ERR(tpacpi_hwmon
);
7104 tpacpi_hwmon
= NULL
;
7105 printk(TPACPI_ERR
"unable to register hwmon device\n");
7106 thinkpad_acpi_module_exit();
7109 mutex_init(&tpacpi_inputdev_send_mutex
);
7110 tpacpi_inputdev
= input_allocate_device();
7111 if (!tpacpi_inputdev
) {
7112 printk(TPACPI_ERR
"unable to allocate input device\n");
7113 thinkpad_acpi_module_exit();
7116 /* Prepare input device, but don't register */
7117 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
7118 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
7119 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
7120 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
7121 thinkpad_id
.vendor
:
7123 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
7124 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
7126 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
7127 ret
= ibm_init(&ibms_init
[i
]);
7128 if (ret
>= 0 && *ibms_init
[i
].param
)
7129 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
7131 thinkpad_acpi_module_exit();
7135 ret
= input_register_device(tpacpi_inputdev
);
7137 printk(TPACPI_ERR
"unable to register input device\n");
7138 thinkpad_acpi_module_exit();
7141 tp_features
.input_device_registered
= 1;
7144 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
7148 /* Please remove this in year 2009 */
7149 MODULE_ALIAS("ibm_acpi");
7151 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME
);
7154 * DMI matching for module autoloading
7156 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
7157 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
7159 * Only models listed in thinkwiki will be supported, so add yours
7160 * if it is not there yet.
7162 #define IBM_BIOS_MODULE_ALIAS(__type) \
7163 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*")
7165 /* Non-ancient thinkpads */
7166 MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*");
7167 MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*");
7169 /* Ancient thinkpad BIOSes have to be identified by
7170 * BIOS type or model number, and there are far less
7171 * BIOS types than model numbers... */
7172 IBM_BIOS_MODULE_ALIAS("I[BDHIMNOTWVYZ]");
7173 IBM_BIOS_MODULE_ALIAS("1[0368A-GIKM-PST]");
7174 IBM_BIOS_MODULE_ALIAS("K[UX-Z]");
7176 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
7177 MODULE_DESCRIPTION(TPACPI_DESC
);
7178 MODULE_VERSION(TPACPI_VERSION
);
7179 MODULE_LICENSE("GPL");
7181 module_init(thinkpad_acpi_module_init
);
7182 module_exit(thinkpad_acpi_module_exit
);