2 * thinkpad_acpi.c - ThinkPad ACPI Extras
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006-2009 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.22"
25 #define TPACPI_SYSFS_VERSION 0x020300
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/sched.h>
58 #include <linux/kthread.h>
59 #include <linux/freezer.h>
60 #include <linux/delay.h>
62 #include <linux/nvram.h>
63 #include <linux/proc_fs.h>
64 #include <linux/sysfs.h>
65 #include <linux/backlight.h>
67 #include <linux/platform_device.h>
68 #include <linux/hwmon.h>
69 #include <linux/hwmon-sysfs.h>
70 #include <linux/input.h>
71 #include <linux/leds.h>
72 #include <linux/rfkill.h>
73 #include <asm/uaccess.h>
75 #include <linux/dmi.h>
76 #include <linux/jiffies.h>
77 #include <linux/workqueue.h>
79 #include <acpi/acpi_drivers.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
,
173 TPACPI_RFK_UWB_SW_ID
,
177 #define TPACPI_LOG TPACPI_FILE ": "
178 #define TPACPI_EMERG KERN_EMERG TPACPI_LOG
179 #define TPACPI_ALERT KERN_ALERT TPACPI_LOG
180 #define TPACPI_CRIT KERN_CRIT TPACPI_LOG
181 #define TPACPI_ERR KERN_ERR TPACPI_LOG
182 #define TPACPI_WARN KERN_WARNING TPACPI_LOG
183 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
184 #define TPACPI_INFO KERN_INFO TPACPI_LOG
185 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
187 /* Debugging printk groups */
188 #define TPACPI_DBG_ALL 0xffff
189 #define TPACPI_DBG_DISCLOSETASK 0x8000
190 #define TPACPI_DBG_INIT 0x0001
191 #define TPACPI_DBG_EXIT 0x0002
193 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
194 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
195 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
198 /****************************************************************************
199 * Driver-wide structs and misc. variables
204 struct tp_acpi_drv_struct
{
205 const struct acpi_device_id
*hid
;
206 struct acpi_driver
*driver
;
208 void (*notify
) (struct ibm_struct
*, u32
);
211 struct acpi_device
*device
;
217 int (*read
) (char *);
218 int (*write
) (char *);
220 void (*resume
) (void);
221 void (*suspend
) (pm_message_t state
);
222 void (*shutdown
) (void);
224 struct list_head all_drivers
;
226 struct tp_acpi_drv_struct
*acpi
;
229 u8 acpi_driver_registered
:1;
230 u8 acpi_notify_installed
:1;
237 struct ibm_init_struct
{
240 int (*init
) (struct ibm_init_struct
*);
241 struct ibm_struct
*data
;
245 #ifdef CONFIG_THINKPAD_ACPI_BAY
258 u32 bright_16levels
:1;
259 u32 bright_acpimode
:1;
262 u32 fan_ctrl_status_undef
:1;
263 u32 input_device_registered
:1;
264 u32 platform_drv_registered
:1;
265 u32 platform_drv_attrs_registered
:1;
266 u32 sensors_pdrv_registered
:1;
267 u32 sensors_pdrv_attrs_registered
:1;
268 u32 sensors_pdev_attrs_registered
:1;
269 u32 hotkey_poll_active
:1;
273 u16 hotkey_mask_ff
:1;
274 u16 bright_cmos_ec_unsync
:1;
277 struct thinkpad_id_data
{
278 unsigned int vendor
; /* ThinkPad vendor:
279 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
281 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
282 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
284 u16 bios_model
; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */
287 char *model_str
; /* ThinkPad T43 */
288 char *nummodel_str
; /* 9384A9C for a 9384-A9C model */
290 static struct thinkpad_id_data thinkpad_id
;
293 TPACPI_LIFE_INIT
= 0,
298 static int experimental
;
299 static u32 dbg_level
;
301 static struct workqueue_struct
*tpacpi_wq
;
309 /* Special LED class that can defer work */
310 struct tpacpi_led_classdev
{
311 struct led_classdev led_classdev
;
312 struct work_struct work
;
313 enum led_status_t new_state
;
317 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
318 static int dbg_wlswemul
;
319 static int tpacpi_wlsw_emulstate
;
320 static int dbg_bluetoothemul
;
321 static int tpacpi_bluetooth_emulstate
;
322 static int dbg_wwanemul
;
323 static int tpacpi_wwan_emulstate
;
324 static int dbg_uwbemul
;
325 static int tpacpi_uwb_emulstate
;
329 /*************************************************************************
333 #define dbg_printk(a_dbg_level, format, arg...) \
334 do { if (dbg_level & (a_dbg_level)) \
335 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
338 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
339 #define vdbg_printk dbg_printk
340 static const char *str_supported(int is_supported
);
342 #define vdbg_printk(a_dbg_level, format, arg...) \
346 static void tpacpi_log_usertask(const char * const what
)
348 printk(TPACPI_DEBUG
"%s: access by process with PID %d\n",
349 what
, task_tgid_vnr(current
));
352 #define tpacpi_disclose_usertask(what, format, arg...) \
355 (dbg_level & TPACPI_DBG_DISCLOSETASK) && \
356 (tpacpi_lifecycle == TPACPI_LIFE_RUNNING))) { \
357 printk(TPACPI_DEBUG "%s: PID %d: " format, \
358 what, task_tgid_vnr(current), ## arg); \
362 /****************************************************************************
363 ****************************************************************************
365 * ACPI Helpers and device model
367 ****************************************************************************
368 ****************************************************************************/
370 /*************************************************************************
374 static acpi_handle root_handle
;
376 #define TPACPI_HANDLE(object, parent, paths...) \
377 static acpi_handle object##_handle; \
378 static acpi_handle *object##_parent = &parent##_handle; \
379 static char *object##_path; \
380 static char *object##_paths[] = { paths }
382 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
383 "\\_SB.PCI.ISA.EC", /* 570 */
384 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
385 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
386 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
387 "\\_SB.PCI0.ICH3.EC0", /* R31 */
388 "\\_SB.PCI0.LPC.EC", /* all others */
391 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
392 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
394 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
396 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
397 "\\CMS", /* R40, R40e */
400 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
401 "^HKEY", /* R30, R31 */
402 "HKEY", /* all others */
405 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
406 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
407 "\\_SB.PCI0.VID0", /* 770e */
408 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
409 "\\_SB.PCI0.AGP.VID", /* all others */
413 /*************************************************************************
417 static int acpi_evalf(acpi_handle handle
,
418 void *res
, char *method
, char *fmt
, ...)
421 struct acpi_object_list params
;
422 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
423 struct acpi_buffer result
, *resultp
;
424 union acpi_object out_obj
;
432 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
445 params
.pointer
= &in_objs
[0];
452 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
453 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
455 /* add more types as needed */
457 printk(TPACPI_ERR
"acpi_evalf() called "
458 "with invalid format character '%c'\n", c
);
464 if (res_type
!= 'v') {
465 result
.length
= sizeof(out_obj
);
466 result
.pointer
= &out_obj
;
471 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
476 *(int *)res
= out_obj
.integer
.value
;
477 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
480 success
= status
== AE_OK
;
482 /* add more types as needed */
484 printk(TPACPI_ERR
"acpi_evalf() called "
485 "with invalid format character '%c'\n", res_type
);
489 if (!success
&& !quiet
)
490 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
491 method
, fmt0
, status
);
496 static int acpi_ec_read(int i
, u8
*p
)
501 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
505 if (ec_read(i
, p
) < 0)
512 static int acpi_ec_write(int i
, u8 v
)
515 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
518 if (ec_write(i
, v
) < 0)
525 #if defined(CONFIG_THINKPAD_ACPI_DOCK) || defined(CONFIG_THINKPAD_ACPI_BAY)
526 static int _sta(acpi_handle handle
)
530 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
537 static int issue_thinkpad_cmos_command(int cmos_cmd
)
542 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
548 /*************************************************************************
552 #define TPACPI_ACPIHANDLE_INIT(object) \
553 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
554 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
556 static void drv_acpi_handle_init(char *name
,
557 acpi_handle
*handle
, acpi_handle parent
,
558 char **paths
, int num_paths
, char **path
)
563 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
566 for (i
= 0; i
< num_paths
; i
++) {
567 status
= acpi_get_handle(parent
, paths
[i
], handle
);
568 if (ACPI_SUCCESS(status
)) {
570 dbg_printk(TPACPI_DBG_INIT
,
571 "Found ACPI handle %s for %s\n",
577 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
582 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
584 struct ibm_struct
*ibm
= data
;
586 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
589 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
592 ibm
->acpi
->notify(ibm
, event
);
595 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
602 if (!*ibm
->acpi
->handle
)
605 vdbg_printk(TPACPI_DBG_INIT
,
606 "setting up ACPI notify for %s\n", ibm
->name
);
608 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
610 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
615 ibm
->acpi
->device
->driver_data
= ibm
;
616 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
617 TPACPI_ACPI_EVENT_PREFIX
,
620 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
621 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
622 if (ACPI_FAILURE(status
)) {
623 if (status
== AE_ALREADY_EXISTS
) {
625 "another device driver is already "
626 "handling %s events\n", ibm
->name
);
629 "acpi_install_notify_handler(%s) failed: %d\n",
634 ibm
->flags
.acpi_notify_installed
= 1;
638 static int __init
tpacpi_device_add(struct acpi_device
*device
)
643 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
647 dbg_printk(TPACPI_DBG_INIT
,
648 "registering %s as an ACPI driver\n", ibm
->name
);
652 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
653 if (!ibm
->acpi
->driver
) {
655 "failed to allocate memory for ibm->acpi->driver\n");
659 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
660 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
662 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
664 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
666 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
668 kfree(ibm
->acpi
->driver
);
669 ibm
->acpi
->driver
= NULL
;
671 ibm
->flags
.acpi_driver_registered
= 1;
677 /****************************************************************************
678 ****************************************************************************
682 ****************************************************************************
683 ****************************************************************************/
685 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
686 int count
, int *eof
, void *data
)
688 struct ibm_struct
*ibm
= data
;
691 if (!ibm
|| !ibm
->read
)
694 len
= ibm
->read(page
);
698 if (len
<= off
+ count
)
710 static int dispatch_procfs_write(struct file
*file
,
711 const char __user
*userbuf
,
712 unsigned long count
, void *data
)
714 struct ibm_struct
*ibm
= data
;
718 if (!ibm
|| !ibm
->write
)
721 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
725 if (copy_from_user(kernbuf
, userbuf
, count
)) {
731 strcat(kernbuf
, ",");
732 ret
= ibm
->write(kernbuf
);
741 static char *next_cmd(char **cmds
)
746 while ((end
= strchr(start
, ',')) && end
== start
)
758 /****************************************************************************
759 ****************************************************************************
761 * Device model: input, hwmon and platform
763 ****************************************************************************
764 ****************************************************************************/
766 static struct platform_device
*tpacpi_pdev
;
767 static struct platform_device
*tpacpi_sensors_pdev
;
768 static struct device
*tpacpi_hwmon
;
769 static struct input_dev
*tpacpi_inputdev
;
770 static struct mutex tpacpi_inputdev_send_mutex
;
771 static LIST_HEAD(tpacpi_all_drivers
);
773 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
776 struct ibm_struct
*ibm
, *itmp
;
778 list_for_each_entry_safe(ibm
, itmp
,
782 (ibm
->suspend
)(state
);
788 static int tpacpi_resume_handler(struct platform_device
*pdev
)
790 struct ibm_struct
*ibm
, *itmp
;
792 list_for_each_entry_safe(ibm
, itmp
,
802 static void tpacpi_shutdown_handler(struct platform_device
*pdev
)
804 struct ibm_struct
*ibm
, *itmp
;
806 list_for_each_entry_safe(ibm
, itmp
,
814 static struct platform_driver tpacpi_pdriver
= {
816 .name
= TPACPI_DRVR_NAME
,
817 .owner
= THIS_MODULE
,
819 .suspend
= tpacpi_suspend_handler
,
820 .resume
= tpacpi_resume_handler
,
821 .shutdown
= tpacpi_shutdown_handler
,
824 static struct platform_driver tpacpi_hwmon_pdriver
= {
826 .name
= TPACPI_HWMON_DRVR_NAME
,
827 .owner
= THIS_MODULE
,
831 /*************************************************************************
832 * sysfs support helpers
835 struct attribute_set
{
836 unsigned int members
, max_members
;
837 struct attribute_group group
;
840 struct attribute_set_obj
{
841 struct attribute_set s
;
843 } __attribute__((packed
));
845 static struct attribute_set
*create_attr_set(unsigned int max_members
,
848 struct attribute_set_obj
*sobj
;
850 if (max_members
== 0)
853 /* Allocates space for implicit NULL at the end too */
854 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
855 max_members
* sizeof(struct attribute
*),
859 sobj
->s
.max_members
= max_members
;
860 sobj
->s
.group
.attrs
= &sobj
->a
;
861 sobj
->s
.group
.name
= name
;
866 #define destroy_attr_set(_set) \
869 /* not multi-threaded safe, use it in a single thread per set */
870 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
875 if (s
->members
>= s
->max_members
)
878 s
->group
.attrs
[s
->members
] = attr
;
884 static int add_many_to_attr_set(struct attribute_set
*s
,
885 struct attribute
**attr
,
890 for (i
= 0; i
< count
; i
++) {
891 res
= add_to_attr_set(s
, attr
[i
]);
899 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
901 sysfs_remove_group(kobj
, &s
->group
);
905 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
906 sysfs_create_group(_kobj, &_attr_set->group)
908 static int parse_strtoul(const char *buf
,
909 unsigned long max
, unsigned long *value
)
913 while (*buf
&& isspace(*buf
))
915 *value
= simple_strtoul(buf
, &endp
, 0);
916 while (*endp
&& isspace(*endp
))
918 if (*endp
|| *value
> max
)
924 static void tpacpi_disable_brightness_delay(void)
926 if (acpi_evalf(hkey_handle
, NULL
, "PWMS", "qvd", 0))
928 "ACPI backlight control delay disabled\n");
931 static int __init
tpacpi_query_bcl_levels(acpi_handle handle
)
933 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
934 union acpi_object
*obj
;
937 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
938 obj
= (union acpi_object
*)buffer
.pointer
;
939 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
940 printk(TPACPI_ERR
"Unknown _BCL data, "
941 "please report this to %s\n", TPACPI_MAIL
);
944 rc
= obj
->package
.count
;
950 kfree(buffer
.pointer
);
954 static acpi_status __init
tpacpi_acpi_walk_find_bcl(acpi_handle handle
,
955 u32 lvl
, void *context
, void **rv
)
957 char name
[ACPI_PATH_SEGMENT_LENGTH
];
958 struct acpi_buffer buffer
= { sizeof(name
), &name
};
960 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
961 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
963 **(int **)rv
= tpacpi_query_bcl_levels(handle
);
964 return AE_CTRL_TERMINATE
;
971 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
973 static int __init
tpacpi_check_std_acpi_brightness_support(void)
977 void *bcl_ptr
= &bcl_levels
;
980 TPACPI_ACPIHANDLE_INIT(vid
);
986 * Search for a _BCL method, and execute it. This is safe on all
987 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
988 * BIOS in ACPI backlight control mode. We do NOT have to care
989 * about calling the _BCL method in an enabled video device, any
990 * will do for our purposes.
993 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
994 tpacpi_acpi_walk_find_bcl
, NULL
,
997 if (ACPI_SUCCESS(status
) && bcl_levels
> 2) {
998 tp_features
.bright_acpimode
= 1;
999 return (bcl_levels
- 2);
1005 static int __init
tpacpi_new_rfkill(const unsigned int id
,
1006 struct rfkill
**rfk
,
1007 const enum rfkill_type rfktype
,
1009 const bool set_default
,
1010 int (*toggle_radio
)(void *, enum rfkill_state
),
1011 int (*get_state
)(void *, enum rfkill_state
*))
1014 enum rfkill_state initial_state
= RFKILL_STATE_SOFT_BLOCKED
;
1016 res
= get_state(NULL
, &initial_state
);
1019 "failed to read initial state for %s, error %d; "
1020 "will turn radio off\n", name
, res
);
1021 } else if (set_default
) {
1022 /* try to set the initial state as the default for the rfkill
1023 * type, since we ask the firmware to preserve it across S5 in
1025 rfkill_set_default(rfktype
,
1026 (initial_state
== RFKILL_STATE_UNBLOCKED
) ?
1027 RFKILL_STATE_UNBLOCKED
:
1028 RFKILL_STATE_SOFT_BLOCKED
);
1031 *rfk
= rfkill_allocate(&tpacpi_pdev
->dev
, rfktype
);
1034 "failed to allocate memory for rfkill class\n");
1038 (*rfk
)->name
= name
;
1039 (*rfk
)->get_state
= get_state
;
1040 (*rfk
)->toggle_radio
= toggle_radio
;
1041 (*rfk
)->state
= initial_state
;
1043 res
= rfkill_register(*rfk
);
1046 "failed to register %s rfkill switch: %d\n",
1056 static void printk_deprecated_attribute(const char * const what
,
1057 const char * const details
)
1059 tpacpi_log_usertask("deprecated sysfs attribute");
1060 printk(TPACPI_WARN
"WARNING: sysfs attribute %s is deprecated and "
1061 "will be removed. %s\n",
1065 static void printk_deprecated_rfkill_attribute(const char * const what
)
1067 printk_deprecated_attribute(what
,
1068 "Please switch to generic rfkill before year 2010");
1071 /*************************************************************************
1072 * thinkpad-acpi driver attributes
1075 /* interface_version --------------------------------------------------- */
1076 static ssize_t
tpacpi_driver_interface_version_show(
1077 struct device_driver
*drv
,
1080 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
1083 static DRIVER_ATTR(interface_version
, S_IRUGO
,
1084 tpacpi_driver_interface_version_show
, NULL
);
1086 /* debug_level --------------------------------------------------------- */
1087 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
1090 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
1093 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
1094 const char *buf
, size_t count
)
1098 if (parse_strtoul(buf
, 0xffff, &t
))
1106 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
1107 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
1109 /* version ------------------------------------------------------------- */
1110 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
1113 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
1114 TPACPI_DESC
, TPACPI_VERSION
);
1117 static DRIVER_ATTR(version
, S_IRUGO
,
1118 tpacpi_driver_version_show
, NULL
);
1120 /* --------------------------------------------------------------------- */
1122 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1124 static void tpacpi_send_radiosw_update(void);
1126 /* wlsw_emulstate ------------------------------------------------------ */
1127 static ssize_t
tpacpi_driver_wlsw_emulstate_show(struct device_driver
*drv
,
1130 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wlsw_emulstate
);
1133 static ssize_t
tpacpi_driver_wlsw_emulstate_store(struct device_driver
*drv
,
1134 const char *buf
, size_t count
)
1138 if (parse_strtoul(buf
, 1, &t
))
1141 if (tpacpi_wlsw_emulstate
!= t
) {
1142 tpacpi_wlsw_emulstate
= !!t
;
1143 tpacpi_send_radiosw_update();
1145 tpacpi_wlsw_emulstate
= !!t
;
1150 static DRIVER_ATTR(wlsw_emulstate
, S_IWUSR
| S_IRUGO
,
1151 tpacpi_driver_wlsw_emulstate_show
,
1152 tpacpi_driver_wlsw_emulstate_store
);
1154 /* bluetooth_emulstate ------------------------------------------------- */
1155 static ssize_t
tpacpi_driver_bluetooth_emulstate_show(
1156 struct device_driver
*drv
,
1159 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_bluetooth_emulstate
);
1162 static ssize_t
tpacpi_driver_bluetooth_emulstate_store(
1163 struct device_driver
*drv
,
1164 const char *buf
, size_t count
)
1168 if (parse_strtoul(buf
, 1, &t
))
1171 tpacpi_bluetooth_emulstate
= !!t
;
1176 static DRIVER_ATTR(bluetooth_emulstate
, S_IWUSR
| S_IRUGO
,
1177 tpacpi_driver_bluetooth_emulstate_show
,
1178 tpacpi_driver_bluetooth_emulstate_store
);
1180 /* wwan_emulstate ------------------------------------------------- */
1181 static ssize_t
tpacpi_driver_wwan_emulstate_show(
1182 struct device_driver
*drv
,
1185 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wwan_emulstate
);
1188 static ssize_t
tpacpi_driver_wwan_emulstate_store(
1189 struct device_driver
*drv
,
1190 const char *buf
, size_t count
)
1194 if (parse_strtoul(buf
, 1, &t
))
1197 tpacpi_wwan_emulstate
= !!t
;
1202 static DRIVER_ATTR(wwan_emulstate
, S_IWUSR
| S_IRUGO
,
1203 tpacpi_driver_wwan_emulstate_show
,
1204 tpacpi_driver_wwan_emulstate_store
);
1206 /* uwb_emulstate ------------------------------------------------- */
1207 static ssize_t
tpacpi_driver_uwb_emulstate_show(
1208 struct device_driver
*drv
,
1211 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_uwb_emulstate
);
1214 static ssize_t
tpacpi_driver_uwb_emulstate_store(
1215 struct device_driver
*drv
,
1216 const char *buf
, size_t count
)
1220 if (parse_strtoul(buf
, 1, &t
))
1223 tpacpi_uwb_emulstate
= !!t
;
1228 static DRIVER_ATTR(uwb_emulstate
, S_IWUSR
| S_IRUGO
,
1229 tpacpi_driver_uwb_emulstate_show
,
1230 tpacpi_driver_uwb_emulstate_store
);
1233 /* --------------------------------------------------------------------- */
1235 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
1236 &driver_attr_debug_level
, &driver_attr_version
,
1237 &driver_attr_interface_version
,
1240 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
1246 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
1247 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
1251 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1252 if (!res
&& dbg_wlswemul
)
1253 res
= driver_create_file(drv
, &driver_attr_wlsw_emulstate
);
1254 if (!res
&& dbg_bluetoothemul
)
1255 res
= driver_create_file(drv
, &driver_attr_bluetooth_emulstate
);
1256 if (!res
&& dbg_wwanemul
)
1257 res
= driver_create_file(drv
, &driver_attr_wwan_emulstate
);
1258 if (!res
&& dbg_uwbemul
)
1259 res
= driver_create_file(drv
, &driver_attr_uwb_emulstate
);
1265 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
1269 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
1270 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
1272 #ifdef THINKPAD_ACPI_DEBUGFACILITIES
1273 driver_remove_file(drv
, &driver_attr_wlsw_emulstate
);
1274 driver_remove_file(drv
, &driver_attr_bluetooth_emulstate
);
1275 driver_remove_file(drv
, &driver_attr_wwan_emulstate
);
1276 driver_remove_file(drv
, &driver_attr_uwb_emulstate
);
1280 /****************************************************************************
1281 ****************************************************************************
1285 ****************************************************************************
1286 ****************************************************************************/
1288 /*************************************************************************
1289 * thinkpad-acpi init subdriver
1292 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
1294 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
1295 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
1297 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
1298 (thinkpad_id
.bios_version_str
) ?
1299 thinkpad_id
.bios_version_str
: "unknown",
1300 (thinkpad_id
.ec_version_str
) ?
1301 thinkpad_id
.ec_version_str
: "unknown");
1303 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
1304 printk(TPACPI_INFO
"%s %s, model %s\n",
1305 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
1306 "IBM" : ((thinkpad_id
.vendor
==
1307 PCI_VENDOR_ID_LENOVO
) ?
1308 "Lenovo" : "Unknown vendor"),
1309 thinkpad_id
.model_str
,
1310 (thinkpad_id
.nummodel_str
) ?
1311 thinkpad_id
.nummodel_str
: "unknown");
1316 static int thinkpad_acpi_driver_read(char *p
)
1320 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", TPACPI_DESC
);
1321 len
+= sprintf(p
+ len
, "version:\t%s\n", TPACPI_VERSION
);
1326 static struct ibm_struct thinkpad_acpi_driver_data
= {
1328 .read
= thinkpad_acpi_driver_read
,
1331 /*************************************************************************
1335 enum { /* hot key scan codes (derived from ACPI DSDT) */
1336 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
1337 TP_ACPI_HOTKEYSCAN_FNF2
,
1338 TP_ACPI_HOTKEYSCAN_FNF3
,
1339 TP_ACPI_HOTKEYSCAN_FNF4
,
1340 TP_ACPI_HOTKEYSCAN_FNF5
,
1341 TP_ACPI_HOTKEYSCAN_FNF6
,
1342 TP_ACPI_HOTKEYSCAN_FNF7
,
1343 TP_ACPI_HOTKEYSCAN_FNF8
,
1344 TP_ACPI_HOTKEYSCAN_FNF9
,
1345 TP_ACPI_HOTKEYSCAN_FNF10
,
1346 TP_ACPI_HOTKEYSCAN_FNF11
,
1347 TP_ACPI_HOTKEYSCAN_FNF12
,
1348 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
1349 TP_ACPI_HOTKEYSCAN_FNINSERT
,
1350 TP_ACPI_HOTKEYSCAN_FNDELETE
,
1351 TP_ACPI_HOTKEYSCAN_FNHOME
,
1352 TP_ACPI_HOTKEYSCAN_FNEND
,
1353 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1354 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
1355 TP_ACPI_HOTKEYSCAN_FNSPACE
,
1356 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1357 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1358 TP_ACPI_HOTKEYSCAN_MUTE
,
1359 TP_ACPI_HOTKEYSCAN_THINKPAD
,
1362 enum { /* Keys available through NVRAM polling */
1363 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
1364 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
1367 enum { /* Positions of some of the keys in hotkey masks */
1368 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
1369 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
1370 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
1371 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
1372 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
1373 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1374 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
1375 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1376 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1377 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
1378 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
1381 enum { /* NVRAM to ACPI HKEY group map */
1382 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
1383 TP_ACPI_HKEY_ZOOM_MASK
|
1384 TP_ACPI_HKEY_DISPSWTCH_MASK
|
1385 TP_ACPI_HKEY_HIBERNATE_MASK
,
1386 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
1387 TP_ACPI_HKEY_BRGHTDWN_MASK
,
1388 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
1389 TP_ACPI_HKEY_VOLDWN_MASK
|
1390 TP_ACPI_HKEY_MUTE_MASK
,
1393 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1394 struct tp_nvram_state
{
1395 u16 thinkpad_toggle
:1;
1397 u16 display_toggle
:1;
1398 u16 thinklight_toggle
:1;
1399 u16 hibernate_toggle
:1;
1400 u16 displayexp_toggle
:1;
1401 u16 display_state
:1;
1402 u16 brightness_toggle
:1;
1403 u16 volume_toggle
:1;
1406 u8 brightness_level
;
1410 static struct task_struct
*tpacpi_hotkey_task
;
1411 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
1412 static int hotkey_poll_freq
= 10; /* Hz */
1413 static struct mutex hotkey_thread_mutex
;
1414 static struct mutex hotkey_thread_data_mutex
;
1415 static unsigned int hotkey_config_change
;
1417 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1419 #define hotkey_source_mask 0U
1421 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1423 static struct mutex hotkey_mutex
;
1425 static enum { /* Reasons for waking up */
1426 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
1427 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
1428 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
1429 } hotkey_wakeup_reason
;
1431 static int hotkey_autosleep_ack
;
1433 static u32 hotkey_orig_mask
;
1434 static u32 hotkey_all_mask
;
1435 static u32 hotkey_reserved_mask
;
1436 static u32 hotkey_mask
;
1438 static unsigned int hotkey_report_mode
;
1440 static u16
*hotkey_keycode_map
;
1442 static struct attribute_set
*hotkey_dev_attributes
;
1444 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1445 #define HOTKEY_CONFIG_CRITICAL_START \
1447 mutex_lock(&hotkey_thread_data_mutex); \
1448 hotkey_config_change++; \
1450 #define HOTKEY_CONFIG_CRITICAL_END \
1451 mutex_unlock(&hotkey_thread_data_mutex);
1453 #define HOTKEY_CONFIG_CRITICAL_START
1454 #define HOTKEY_CONFIG_CRITICAL_END
1455 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1457 /* HKEY.MHKG() return bits */
1458 #define TP_HOTKEY_TABLET_MASK (1 << 3)
1460 static int hotkey_get_wlsw(int *status
)
1462 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1464 *status
= !!tpacpi_wlsw_emulstate
;
1468 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
1473 static int hotkey_get_tablet_mode(int *status
)
1477 if (!acpi_evalf(hkey_handle
, &s
, "MHKG", "d"))
1480 *status
= ((s
& TP_HOTKEY_TABLET_MASK
) != 0);
1485 * Call with hotkey_mutex held
1487 static int hotkey_mask_get(void)
1491 if (tp_features
.hotkey_mask
) {
1492 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
1495 hotkey_mask
= m
| (hotkey_source_mask
& hotkey_mask
);
1501 * Call with hotkey_mutex held
1503 static int hotkey_mask_set(u32 mask
)
1508 if (tp_features
.hotkey_mask
) {
1509 if (!tp_warned
.hotkey_mask_ff
&&
1510 (mask
== 0xffff || mask
== 0xffffff ||
1511 mask
== 0xffffffff)) {
1512 tp_warned
.hotkey_mask_ff
= 1;
1513 printk(TPACPI_NOTICE
1514 "setting the hotkey mask to 0x%08x is likely "
1515 "not the best way to go about it\n", mask
);
1516 printk(TPACPI_NOTICE
1517 "please consider using the driver defaults, "
1518 "and refer to up-to-date thinkpad-acpi "
1522 HOTKEY_CONFIG_CRITICAL_START
1523 for (i
= 0; i
< 32; i
++) {
1525 /* enable in firmware mask only keys not in NVRAM
1526 * mode, but enable the key in the cached hotkey_mask
1527 * regardless of mode, or the key will end up
1528 * disabled by hotkey_mask_get() */
1529 if (!acpi_evalf(hkey_handle
,
1530 NULL
, "MHKM", "vdd", i
+ 1,
1531 !!((mask
& ~hotkey_source_mask
) & m
))) {
1535 hotkey_mask
= (hotkey_mask
& ~m
) | (mask
& m
);
1538 HOTKEY_CONFIG_CRITICAL_END
1540 /* hotkey_mask_get must be called unconditionally below */
1541 if (!hotkey_mask_get() && !rc
&&
1542 (hotkey_mask
& ~hotkey_source_mask
) !=
1543 (mask
& ~hotkey_source_mask
)) {
1544 printk(TPACPI_NOTICE
1545 "requested hot key mask 0x%08x, but "
1546 "firmware forced it to 0x%08x\n",
1550 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1551 HOTKEY_CONFIG_CRITICAL_START
1552 hotkey_mask
= mask
& hotkey_source_mask
;
1553 HOTKEY_CONFIG_CRITICAL_END
1555 if (hotkey_mask
!= mask
) {
1556 printk(TPACPI_NOTICE
1557 "requested hot key mask 0x%08x, "
1558 "forced to 0x%08x (NVRAM poll mask is "
1559 "0x%08x): no firmware mask support\n",
1560 mask
, hotkey_mask
, hotkey_source_mask
);
1565 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1571 static int hotkey_status_get(int *status
)
1573 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1579 static int hotkey_status_set(bool enable
)
1581 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", enable
? 1 : 0))
1587 static void tpacpi_input_send_tabletsw(void)
1591 if (tp_features
.hotkey_tablet
&&
1592 !hotkey_get_tablet_mode(&state
)) {
1593 mutex_lock(&tpacpi_inputdev_send_mutex
);
1595 input_report_switch(tpacpi_inputdev
,
1596 SW_TABLET_MODE
, !!state
);
1597 input_sync(tpacpi_inputdev
);
1599 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1603 static void tpacpi_input_send_key(unsigned int scancode
)
1605 unsigned int keycode
;
1607 keycode
= hotkey_keycode_map
[scancode
];
1609 if (keycode
!= KEY_RESERVED
) {
1610 mutex_lock(&tpacpi_inputdev_send_mutex
);
1612 input_report_key(tpacpi_inputdev
, keycode
, 1);
1613 if (keycode
== KEY_UNKNOWN
)
1614 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1616 input_sync(tpacpi_inputdev
);
1618 input_report_key(tpacpi_inputdev
, keycode
, 0);
1619 if (keycode
== KEY_UNKNOWN
)
1620 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1622 input_sync(tpacpi_inputdev
);
1624 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1628 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1629 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
1631 static void tpacpi_hotkey_send_key(unsigned int scancode
)
1633 tpacpi_input_send_key(scancode
);
1634 if (hotkey_report_mode
< 2) {
1635 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
1636 0x80, 0x1001 + scancode
);
1640 static void hotkey_read_nvram(struct tp_nvram_state
*n
, u32 m
)
1644 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
1645 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
1646 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
1647 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
1648 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
1649 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
1651 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
1652 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
1653 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
1655 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
1656 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
1657 n
->displayexp_toggle
=
1658 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
1660 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
1661 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
1662 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
1663 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
1664 n
->brightness_toggle
=
1665 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
1667 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
1668 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
1669 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
1670 >> TP_NVRAM_POS_LEVEL_VOLUME
;
1671 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
1672 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
1676 #define TPACPI_COMPARE_KEY(__scancode, __member) \
1678 if ((mask & (1 << __scancode)) && \
1679 oldn->__member != newn->__member) \
1680 tpacpi_hotkey_send_key(__scancode); \
1683 #define TPACPI_MAY_SEND_KEY(__scancode) \
1684 do { if (mask & (1 << __scancode)) \
1685 tpacpi_hotkey_send_key(__scancode); } while (0)
1687 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
1688 struct tp_nvram_state
*newn
,
1691 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
1692 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
1693 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
1694 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
1696 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
1698 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
1701 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
1702 if (oldn
->mute
!= newn
->mute
) {
1703 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1705 if (oldn
->volume_level
> newn
->volume_level
) {
1706 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1707 } else if (oldn
->volume_level
< newn
->volume_level
) {
1708 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1709 } else if (oldn
->mute
== newn
->mute
) {
1710 /* repeated key presses that didn't change state */
1712 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1713 } else if (newn
->volume_level
!= 0) {
1714 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1716 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1721 /* handle brightness */
1722 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
1723 if (oldn
->brightness_level
< newn
->brightness_level
) {
1724 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1725 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
1726 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1728 /* repeated key presses that didn't change state */
1729 if (newn
->brightness_level
!= 0) {
1730 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1732 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1738 #undef TPACPI_COMPARE_KEY
1739 #undef TPACPI_MAY_SEND_KEY
1741 static int hotkey_kthread(void *data
)
1743 struct tp_nvram_state s
[2];
1745 unsigned int si
, so
;
1747 unsigned int change_detector
, must_reset
;
1749 mutex_lock(&hotkey_thread_mutex
);
1751 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
1760 /* Initial state for compares */
1761 mutex_lock(&hotkey_thread_data_mutex
);
1762 change_detector
= hotkey_config_change
;
1763 mask
= hotkey_source_mask
& hotkey_mask
;
1764 mutex_unlock(&hotkey_thread_data_mutex
);
1765 hotkey_read_nvram(&s
[so
], mask
);
1767 while (!kthread_should_stop() && hotkey_poll_freq
) {
1769 t
= 1000/hotkey_poll_freq
;
1770 t
= msleep_interruptible(t
);
1771 if (unlikely(kthread_should_stop()))
1773 must_reset
= try_to_freeze();
1774 if (t
> 0 && !must_reset
)
1777 mutex_lock(&hotkey_thread_data_mutex
);
1778 if (must_reset
|| hotkey_config_change
!= change_detector
) {
1779 /* forget old state on thaw or config change */
1782 change_detector
= hotkey_config_change
;
1784 mask
= hotkey_source_mask
& hotkey_mask
;
1785 mutex_unlock(&hotkey_thread_data_mutex
);
1788 hotkey_read_nvram(&s
[si
], mask
);
1789 if (likely(si
!= so
)) {
1790 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
1800 mutex_unlock(&hotkey_thread_mutex
);
1804 static void hotkey_poll_stop_sync(void)
1806 if (tpacpi_hotkey_task
) {
1807 if (frozen(tpacpi_hotkey_task
) ||
1808 freezing(tpacpi_hotkey_task
))
1809 thaw_process(tpacpi_hotkey_task
);
1811 kthread_stop(tpacpi_hotkey_task
);
1812 tpacpi_hotkey_task
= NULL
;
1813 mutex_lock(&hotkey_thread_mutex
);
1814 /* at this point, the thread did exit */
1815 mutex_unlock(&hotkey_thread_mutex
);
1819 /* call with hotkey_mutex held */
1820 static void hotkey_poll_setup(int may_warn
)
1822 if ((hotkey_source_mask
& hotkey_mask
) != 0 &&
1823 hotkey_poll_freq
> 0 &&
1824 (tpacpi_inputdev
->users
> 0 || hotkey_report_mode
< 2)) {
1825 if (!tpacpi_hotkey_task
) {
1826 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
1827 NULL
, TPACPI_NVRAM_KTHREAD_NAME
);
1828 if (IS_ERR(tpacpi_hotkey_task
)) {
1829 tpacpi_hotkey_task
= NULL
;
1831 "could not create kernel thread "
1832 "for hotkey polling\n");
1836 hotkey_poll_stop_sync();
1838 hotkey_source_mask
!= 0 && hotkey_poll_freq
== 0) {
1839 printk(TPACPI_NOTICE
1840 "hot keys 0x%08x require polling, "
1841 "which is currently disabled\n",
1842 hotkey_source_mask
);
1847 static void hotkey_poll_setup_safe(int may_warn
)
1849 mutex_lock(&hotkey_mutex
);
1850 hotkey_poll_setup(may_warn
);
1851 mutex_unlock(&hotkey_mutex
);
1854 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1856 static void hotkey_poll_setup_safe(int __unused
)
1860 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1862 static int hotkey_inputdev_open(struct input_dev
*dev
)
1864 switch (tpacpi_lifecycle
) {
1865 case TPACPI_LIFE_INIT
:
1867 * hotkey_init will call hotkey_poll_setup_safe
1868 * at the appropriate moment
1871 case TPACPI_LIFE_EXITING
:
1873 case TPACPI_LIFE_RUNNING
:
1874 hotkey_poll_setup_safe(0);
1878 /* Should only happen if tpacpi_lifecycle is corrupt */
1883 static void hotkey_inputdev_close(struct input_dev
*dev
)
1885 /* disable hotkey polling when possible */
1886 if (tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
)
1887 hotkey_poll_setup_safe(0);
1890 /* sysfs hotkey enable ------------------------------------------------- */
1891 static ssize_t
hotkey_enable_show(struct device
*dev
,
1892 struct device_attribute
*attr
,
1897 printk_deprecated_attribute("hotkey_enable",
1898 "Hotkey reporting is always enabled");
1900 res
= hotkey_status_get(&status
);
1904 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
1907 static ssize_t
hotkey_enable_store(struct device
*dev
,
1908 struct device_attribute
*attr
,
1909 const char *buf
, size_t count
)
1913 printk_deprecated_attribute("hotkey_enable",
1914 "Hotkeys can be disabled through hotkey_mask");
1916 if (parse_strtoul(buf
, 1, &t
))
1925 static struct device_attribute dev_attr_hotkey_enable
=
1926 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
1927 hotkey_enable_show
, hotkey_enable_store
);
1929 /* sysfs hotkey mask --------------------------------------------------- */
1930 static ssize_t
hotkey_mask_show(struct device
*dev
,
1931 struct device_attribute
*attr
,
1936 if (mutex_lock_killable(&hotkey_mutex
))
1937 return -ERESTARTSYS
;
1938 res
= hotkey_mask_get();
1939 mutex_unlock(&hotkey_mutex
);
1942 res
: snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_mask
);
1945 static ssize_t
hotkey_mask_store(struct device
*dev
,
1946 struct device_attribute
*attr
,
1947 const char *buf
, size_t count
)
1952 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
1955 if (mutex_lock_killable(&hotkey_mutex
))
1956 return -ERESTARTSYS
;
1958 res
= hotkey_mask_set(t
);
1960 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1961 hotkey_poll_setup(1);
1964 mutex_unlock(&hotkey_mutex
);
1966 return (res
) ? res
: count
;
1969 static struct device_attribute dev_attr_hotkey_mask
=
1970 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
1971 hotkey_mask_show
, hotkey_mask_store
);
1973 /* sysfs hotkey bios_enabled ------------------------------------------- */
1974 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
1975 struct device_attribute
*attr
,
1978 return sprintf(buf
, "0\n");
1981 static struct device_attribute dev_attr_hotkey_bios_enabled
=
1982 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
1984 /* sysfs hotkey bios_mask ---------------------------------------------- */
1985 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
1986 struct device_attribute
*attr
,
1989 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
1992 static struct device_attribute dev_attr_hotkey_bios_mask
=
1993 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
1995 /* sysfs hotkey all_mask ----------------------------------------------- */
1996 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
1997 struct device_attribute
*attr
,
2000 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2001 hotkey_all_mask
| hotkey_source_mask
);
2004 static struct device_attribute dev_attr_hotkey_all_mask
=
2005 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
2007 /* sysfs hotkey recommended_mask --------------------------------------- */
2008 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
2009 struct device_attribute
*attr
,
2012 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2013 (hotkey_all_mask
| hotkey_source_mask
)
2014 & ~hotkey_reserved_mask
);
2017 static struct device_attribute dev_attr_hotkey_recommended_mask
=
2018 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
2019 hotkey_recommended_mask_show
, NULL
);
2021 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2023 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
2024 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
2025 struct device_attribute
*attr
,
2028 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
2031 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
2032 struct device_attribute
*attr
,
2033 const char *buf
, size_t count
)
2037 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
2038 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
2041 if (mutex_lock_killable(&hotkey_mutex
))
2042 return -ERESTARTSYS
;
2044 HOTKEY_CONFIG_CRITICAL_START
2045 hotkey_source_mask
= t
;
2046 HOTKEY_CONFIG_CRITICAL_END
2048 hotkey_poll_setup(1);
2050 mutex_unlock(&hotkey_mutex
);
2055 static struct device_attribute dev_attr_hotkey_source_mask
=
2056 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
2057 hotkey_source_mask_show
, hotkey_source_mask_store
);
2059 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
2060 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
2061 struct device_attribute
*attr
,
2064 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
2067 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
2068 struct device_attribute
*attr
,
2069 const char *buf
, size_t count
)
2073 if (parse_strtoul(buf
, 25, &t
))
2076 if (mutex_lock_killable(&hotkey_mutex
))
2077 return -ERESTARTSYS
;
2079 hotkey_poll_freq
= t
;
2081 hotkey_poll_setup(1);
2082 mutex_unlock(&hotkey_mutex
);
2087 static struct device_attribute dev_attr_hotkey_poll_freq
=
2088 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
2089 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
2091 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2093 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
2094 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
2095 struct device_attribute
*attr
,
2099 res
= hotkey_get_wlsw(&s
);
2103 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2106 static struct device_attribute dev_attr_hotkey_radio_sw
=
2107 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
2109 static void hotkey_radio_sw_notify_change(void)
2111 if (tp_features
.hotkey_wlsw
)
2112 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2116 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
2117 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
2118 struct device_attribute
*attr
,
2122 res
= hotkey_get_tablet_mode(&s
);
2126 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2129 static struct device_attribute dev_attr_hotkey_tablet_mode
=
2130 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
2132 static void hotkey_tablet_mode_notify_change(void)
2134 if (tp_features
.hotkey_tablet
)
2135 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2136 "hotkey_tablet_mode");
2139 /* sysfs hotkey report_mode -------------------------------------------- */
2140 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
2141 struct device_attribute
*attr
,
2144 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2145 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
2148 static struct device_attribute dev_attr_hotkey_report_mode
=
2149 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
2151 /* sysfs wakeup reason (pollable) -------------------------------------- */
2152 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
2153 struct device_attribute
*attr
,
2156 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
2159 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
2160 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
2162 static void hotkey_wakeup_reason_notify_change(void)
2164 if (tp_features
.hotkey_mask
)
2165 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2169 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2170 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
2171 struct device_attribute
*attr
,
2174 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
2177 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
2178 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
2179 hotkey_wakeup_hotunplug_complete_show
, NULL
);
2181 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2183 if (tp_features
.hotkey_mask
)
2184 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2185 "wakeup_hotunplug_complete");
2188 /* --------------------------------------------------------------------- */
2190 static struct attribute
*hotkey_attributes
[] __initdata
= {
2191 &dev_attr_hotkey_enable
.attr
,
2192 &dev_attr_hotkey_bios_enabled
.attr
,
2193 &dev_attr_hotkey_report_mode
.attr
,
2194 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2195 &dev_attr_hotkey_mask
.attr
,
2196 &dev_attr_hotkey_all_mask
.attr
,
2197 &dev_attr_hotkey_recommended_mask
.attr
,
2198 &dev_attr_hotkey_source_mask
.attr
,
2199 &dev_attr_hotkey_poll_freq
.attr
,
2203 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
2204 &dev_attr_hotkey_bios_mask
.attr
,
2205 #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2206 &dev_attr_hotkey_mask
.attr
,
2207 &dev_attr_hotkey_all_mask
.attr
,
2208 &dev_attr_hotkey_recommended_mask
.attr
,
2210 &dev_attr_hotkey_wakeup_reason
.attr
,
2211 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
2214 static void bluetooth_update_rfk(void);
2215 static void wan_update_rfk(void);
2216 static void uwb_update_rfk(void);
2217 static void tpacpi_send_radiosw_update(void)
2221 /* Sync these BEFORE sending any rfkill events */
2222 if (tp_features
.bluetooth
)
2223 bluetooth_update_rfk();
2224 if (tp_features
.wan
)
2226 if (tp_features
.uwb
)
2229 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
2230 mutex_lock(&tpacpi_inputdev_send_mutex
);
2232 input_report_switch(tpacpi_inputdev
,
2233 SW_RFKILL_ALL
, !!wlsw
);
2234 input_sync(tpacpi_inputdev
);
2236 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2238 hotkey_radio_sw_notify_change();
2241 static void hotkey_exit(void)
2243 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2244 hotkey_poll_stop_sync();
2247 if (hotkey_dev_attributes
)
2248 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2250 kfree(hotkey_keycode_map
);
2252 if (tp_features
.hotkey
) {
2253 dbg_printk(TPACPI_DBG_EXIT
,
2254 "restoring original hot key mask\n");
2255 /* no short-circuit boolean operator below! */
2256 if ((hotkey_mask_set(hotkey_orig_mask
) |
2257 hotkey_status_set(false)) != 0)
2259 "failed to restore hot key mask "
2260 "to BIOS defaults\n");
2264 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
2266 /* Requirements for changing the default keymaps:
2268 * 1. Many of the keys are mapped to KEY_RESERVED for very
2269 * good reasons. Do not change them unless you have deep
2270 * knowledge on the IBM and Lenovo ThinkPad firmware for
2271 * the various ThinkPad models. The driver behaves
2272 * differently for KEY_RESERVED: such keys have their
2273 * hot key mask *unset* in mask_recommended, and also
2274 * in the initial hot key mask programmed into the
2275 * firmware at driver load time, which means the firm-
2276 * ware may react very differently if you change them to
2279 * 2. You must be subscribed to the linux-thinkpad and
2280 * ibm-acpi-devel mailing lists, and you should read the
2281 * list archives since 2007 if you want to change the
2282 * keymaps. This requirement exists so that you will
2283 * know the past history of problems with the thinkpad-
2284 * acpi driver keymaps, and also that you will be
2285 * listening to any bug reports;
2287 * 3. Do not send thinkpad-acpi specific patches directly to
2288 * for merging, *ever*. Send them to the linux-acpi
2289 * mailinglist for comments. Merging is to be done only
2290 * through acpi-test and the ACPI maintainer.
2292 * If the above is too much to ask, don't change the keymap.
2293 * Ask the thinkpad-acpi maintainer to do it, instead.
2295 static u16 ibm_keycode_map
[] __initdata
= {
2296 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2297 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
2298 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2299 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2301 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2302 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2303 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2304 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2306 /* brightness: firmware always reacts to them, unless
2307 * X.org did some tricks in the radeon BIOS scratch
2308 * registers of *some* models */
2309 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
2310 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
2312 /* Thinklight: firmware always react to it */
2313 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2315 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2316 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2318 /* Volume: firmware always react to it and reprograms
2319 * the built-in *extra* mixer. Never map it to control
2320 * another mixer by default. */
2321 KEY_RESERVED
, /* 0x14: VOLUME UP */
2322 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2323 KEY_RESERVED
, /* 0x16: MUTE */
2325 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2327 /* (assignments unknown, please report if found) */
2328 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2329 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2331 static u16 lenovo_keycode_map
[] __initdata
= {
2332 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2333 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
2334 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2335 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2337 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2338 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2339 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2340 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2342 /* These either have to go through ACPI video, or
2343 * act like in the IBM ThinkPads, so don't ever
2344 * enable them by default */
2345 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
2346 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
2348 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2350 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2351 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2353 /* Volume: z60/z61, T60 (BIOS version?): firmware always
2354 * react to it and reprograms the built-in *extra* mixer.
2355 * Never map it to control another mixer by default.
2357 * T60?, T61, R60?, R61: firmware and EC tries to send
2358 * these over the regular keyboard, so these are no-ops,
2359 * but there are still weird bugs re. MUTE, so do not
2360 * change unless you get test reports from all Lenovo
2361 * models. May cause the BIOS to interfere with the
2364 KEY_RESERVED
, /* 0x14: VOLUME UP */
2365 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2366 KEY_RESERVED
, /* 0x16: MUTE */
2368 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2370 /* (assignments unknown, please report if found) */
2371 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2372 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2375 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
2376 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
2377 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
2383 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
2385 BUG_ON(!tpacpi_inputdev
);
2386 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
2387 tpacpi_inputdev
->close
!= NULL
);
2389 TPACPI_ACPIHANDLE_INIT(hkey
);
2390 mutex_init(&hotkey_mutex
);
2392 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2393 mutex_init(&hotkey_thread_mutex
);
2394 mutex_init(&hotkey_thread_data_mutex
);
2397 /* hotkey not supported on 570 */
2398 tp_features
.hotkey
= hkey_handle
!= NULL
;
2400 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
2401 str_supported(tp_features
.hotkey
));
2403 if (!tp_features
.hotkey
)
2406 tpacpi_disable_brightness_delay();
2408 hotkey_dev_attributes
= create_attr_set(13, NULL
);
2409 if (!hotkey_dev_attributes
)
2411 res
= add_many_to_attr_set(hotkey_dev_attributes
,
2413 ARRAY_SIZE(hotkey_attributes
));
2417 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2418 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
2419 for HKEY interface version 0x100 */
2420 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
2421 if ((hkeyv
>> 8) != 1) {
2422 printk(TPACPI_ERR
"unknown version of the "
2423 "HKEY interface: 0x%x\n", hkeyv
);
2424 printk(TPACPI_ERR
"please report this to %s\n",
2428 * MHKV 0x100 in A31, R40, R40e,
2429 * T4x, X31, and later
2431 tp_features
.hotkey_mask
= 1;
2435 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
2436 str_supported(tp_features
.hotkey_mask
));
2438 if (tp_features
.hotkey_mask
) {
2439 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
2442 "missing MHKA handler, "
2443 "please report this to %s\n",
2445 /* FN+F12, FN+F4, FN+F3 */
2446 hotkey_all_mask
= 0x080cU
;
2450 /* hotkey_source_mask *must* be zero for
2451 * the first hotkey_mask_get */
2452 if (tp_features
.hotkey_mask
) {
2453 res
= hotkey_mask_get();
2457 hotkey_orig_mask
= hotkey_mask
;
2458 res
= add_many_to_attr_set(
2459 hotkey_dev_attributes
,
2460 hotkey_mask_attributes
,
2461 ARRAY_SIZE(hotkey_mask_attributes
));
2466 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2467 if (tp_features
.hotkey_mask
) {
2468 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
2471 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
;
2474 vdbg_printk(TPACPI_DBG_INIT
,
2475 "hotkey source mask 0x%08x, polling freq %d\n",
2476 hotkey_source_mask
, hotkey_poll_freq
);
2479 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2481 tp_features
.hotkey_wlsw
= 1;
2483 "radio switch emulation enabled\n");
2486 /* Not all thinkpads have a hardware radio switch */
2487 if (acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
2488 tp_features
.hotkey_wlsw
= 1;
2490 "radio switch found; radios are %s\n",
2491 enabled(status
, 0));
2493 if (tp_features
.hotkey_wlsw
)
2494 res
= add_to_attr_set(hotkey_dev_attributes
,
2495 &dev_attr_hotkey_radio_sw
.attr
);
2497 /* For X41t, X60t, X61t Tablets... */
2498 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
2499 tp_features
.hotkey_tablet
= 1;
2501 "possible tablet mode switch found; "
2502 "ThinkPad in %s mode\n",
2503 (status
& TP_HOTKEY_TABLET_MASK
)?
2504 "tablet" : "laptop");
2505 res
= add_to_attr_set(hotkey_dev_attributes
,
2506 &dev_attr_hotkey_tablet_mode
.attr
);
2510 res
= register_attr_set_with_sysfs(
2511 hotkey_dev_attributes
,
2512 &tpacpi_pdev
->dev
.kobj
);
2516 /* Set up key map */
2518 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
2520 if (!hotkey_keycode_map
) {
2522 "failed to allocate memory for key map\n");
2527 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
2528 dbg_printk(TPACPI_DBG_INIT
,
2529 "using Lenovo default hot key map\n");
2530 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
2531 TPACPI_HOTKEY_MAP_SIZE
);
2533 dbg_printk(TPACPI_DBG_INIT
,
2534 "using IBM default hot key map\n");
2535 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
2536 TPACPI_HOTKEY_MAP_SIZE
);
2539 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
2540 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
2541 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
2542 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
2543 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
2544 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
2545 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
2546 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
2547 set_bit(hotkey_keycode_map
[i
],
2548 tpacpi_inputdev
->keybit
);
2550 if (i
< sizeof(hotkey_reserved_mask
)*8)
2551 hotkey_reserved_mask
|= 1 << i
;
2555 if (tp_features
.hotkey_wlsw
) {
2556 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
2557 set_bit(SW_RFKILL_ALL
, tpacpi_inputdev
->swbit
);
2559 if (tp_features
.hotkey_tablet
) {
2560 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
2561 set_bit(SW_TABLET_MODE
, tpacpi_inputdev
->swbit
);
2564 /* Do not issue duplicate brightness change events to
2566 if (!tp_features
.bright_acpimode
)
2567 /* update bright_acpimode... */
2568 tpacpi_check_std_acpi_brightness_support();
2570 if (tp_features
.bright_acpimode
) {
2572 "This ThinkPad has standard ACPI backlight "
2573 "brightness control, supported by the ACPI "
2575 printk(TPACPI_NOTICE
2576 "Disabling thinkpad-acpi brightness events "
2579 /* The hotkey_reserved_mask change below is not
2580 * necessary while the keys are at KEY_RESERVED in the
2581 * default map, but better safe than sorry, leave it
2582 * here as a marker of what we have to do, especially
2583 * when we finally become able to set this at runtime
2584 * on response to X.org requests */
2585 hotkey_reserved_mask
|=
2586 (1 << TP_ACPI_HOTKEYSCAN_FNHOME
)
2587 | (1 << TP_ACPI_HOTKEYSCAN_FNEND
);
2590 dbg_printk(TPACPI_DBG_INIT
, "enabling hot key handling\n");
2591 res
= hotkey_status_set(true);
2596 res
= hotkey_mask_set(((hotkey_all_mask
| hotkey_source_mask
)
2597 & ~hotkey_reserved_mask
)
2598 | hotkey_orig_mask
);
2599 if (res
< 0 && res
!= -ENXIO
) {
2604 dbg_printk(TPACPI_DBG_INIT
,
2605 "legacy hot key reporting over procfs %s\n",
2606 (hotkey_report_mode
< 2) ?
2607 "enabled" : "disabled");
2609 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
2610 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
2612 hotkey_poll_setup_safe(1);
2613 tpacpi_send_radiosw_update();
2614 tpacpi_input_send_tabletsw();
2619 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2620 hotkey_dev_attributes
= NULL
;
2622 return (res
< 0)? res
: 1;
2625 static bool hotkey_notify_hotkey(const u32 hkey
,
2627 bool *ignore_acpi_ev
)
2629 /* 0x1000-0x1FFF: key presses */
2630 unsigned int scancode
= hkey
& 0xfff;
2631 *send_acpi_ev
= true;
2632 *ignore_acpi_ev
= false;
2634 if (scancode
> 0 && scancode
< 0x21) {
2636 if (!(hotkey_source_mask
& (1 << scancode
))) {
2637 tpacpi_input_send_key(scancode
);
2638 *send_acpi_ev
= false;
2640 *ignore_acpi_ev
= true;
2647 static bool hotkey_notify_wakeup(const u32 hkey
,
2649 bool *ignore_acpi_ev
)
2651 /* 0x2000-0x2FFF: Wakeup reason */
2652 *send_acpi_ev
= true;
2653 *ignore_acpi_ev
= false;
2656 case 0x2304: /* suspend, undock */
2657 case 0x2404: /* hibernation, undock */
2658 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
2659 *ignore_acpi_ev
= true;
2662 case 0x2305: /* suspend, bay eject */
2663 case 0x2405: /* hibernation, bay eject */
2664 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
2665 *ignore_acpi_ev
= true;
2668 case 0x2313: /* Battery on critical low level (S3) */
2669 case 0x2413: /* Battery on critical low level (S4) */
2671 "EMERGENCY WAKEUP: battery almost empty\n");
2672 /* how to auto-heal: */
2673 /* 2313: woke up from S3, go to S4/S5 */
2674 /* 2413: woke up from S4, go to S5 */
2681 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
2683 "woke up due to a hot-unplug "
2685 hotkey_wakeup_reason_notify_change();
2690 static bool hotkey_notify_usrevent(const u32 hkey
,
2692 bool *ignore_acpi_ev
)
2694 /* 0x5000-0x5FFF: human interface helpers */
2695 *send_acpi_ev
= true;
2696 *ignore_acpi_ev
= false;
2699 case 0x5010: /* Lenovo new BIOS: brightness changed */
2700 case 0x500b: /* X61t: tablet pen inserted into bay */
2701 case 0x500c: /* X61t: tablet pen removed from bay */
2704 case 0x5009: /* X41t-X61t: swivel up (tablet mode) */
2705 case 0x500a: /* X41t-X61t: swivel down (normal mode) */
2706 tpacpi_input_send_tabletsw();
2707 hotkey_tablet_mode_notify_change();
2708 *send_acpi_ev
= false;
2713 /* LID switch events. Do not propagate */
2714 *ignore_acpi_ev
= true;
2722 static bool hotkey_notify_thermal(const u32 hkey
,
2724 bool *ignore_acpi_ev
)
2726 /* 0x6000-0x6FFF: thermal alarms */
2727 *send_acpi_ev
= true;
2728 *ignore_acpi_ev
= false;
2733 "THERMAL ALARM: battery is too hot!\n");
2734 /* recommended action: warn user through gui */
2738 "THERMAL EMERGENCY: battery is extremely hot!\n");
2739 /* recommended action: immediate sleep/hibernate */
2744 "a sensor reports something is too hot!\n");
2745 /* recommended action: warn user through gui, that */
2746 /* some internal component is too hot */
2750 "THERMAL EMERGENCY: "
2751 "a sensor reports something is extremely hot!\n");
2752 /* recommended action: immediate sleep/hibernate */
2756 "EC reports that Thermal Table has changed\n");
2757 /* recommended action: do nothing, we don't have
2758 * Lenovo ATM information */
2762 "THERMAL ALERT: unknown thermal alarm received\n");
2767 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
2771 bool ignore_acpi_ev
;
2774 if (event
!= 0x80) {
2776 "unknown HKEY notification event %d\n", event
);
2777 /* forward it to userspace, maybe it knows how to handle it */
2778 acpi_bus_generate_netlink_event(
2779 ibm
->acpi
->device
->pnp
.device_class
,
2780 dev_name(&ibm
->acpi
->device
->dev
),
2786 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
2787 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
2796 send_acpi_ev
= true;
2797 ignore_acpi_ev
= false;
2799 switch (hkey
>> 12) {
2801 /* 0x1000-0x1FFF: key presses */
2802 known_ev
= hotkey_notify_hotkey(hkey
, &send_acpi_ev
,
2806 /* 0x2000-0x2FFF: Wakeup reason */
2807 known_ev
= hotkey_notify_wakeup(hkey
, &send_acpi_ev
,
2811 /* 0x3000-0x3FFF: bay-related wakeups */
2812 if (hkey
== 0x3003) {
2813 hotkey_autosleep_ack
= 1;
2816 hotkey_wakeup_hotunplug_complete_notify_change();
2823 /* 0x4000-0x4FFF: dock-related wakeups */
2824 if (hkey
== 0x4003) {
2825 hotkey_autosleep_ack
= 1;
2828 hotkey_wakeup_hotunplug_complete_notify_change();
2835 /* 0x5000-0x5FFF: human interface helpers */
2836 known_ev
= hotkey_notify_usrevent(hkey
, &send_acpi_ev
,
2840 /* 0x6000-0x6FFF: thermal alarms */
2841 known_ev
= hotkey_notify_thermal(hkey
, &send_acpi_ev
,
2845 /* 0x7000-0x7FFF: misc */
2846 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
2847 tpacpi_send_radiosw_update();
2852 /* fallthrough to default */
2857 printk(TPACPI_NOTICE
2858 "unhandled HKEY event 0x%04x\n", hkey
);
2859 printk(TPACPI_NOTICE
2860 "please report the conditions when this "
2861 "event happened to %s\n", TPACPI_MAIL
);
2865 if (!ignore_acpi_ev
&&
2866 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
2867 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
2871 /* netlink events */
2872 if (!ignore_acpi_ev
&& send_acpi_ev
) {
2873 acpi_bus_generate_netlink_event(
2874 ibm
->acpi
->device
->pnp
.device_class
,
2875 dev_name(&ibm
->acpi
->device
->dev
),
2881 static void hotkey_suspend(pm_message_t state
)
2883 /* Do these on suspend, we get the events on early resume! */
2884 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
2885 hotkey_autosleep_ack
= 0;
2888 static void hotkey_resume(void)
2890 tpacpi_disable_brightness_delay();
2892 if (hotkey_mask_get())
2894 "error while trying to read hot key mask "
2896 tpacpi_send_radiosw_update();
2897 hotkey_tablet_mode_notify_change();
2898 hotkey_wakeup_reason_notify_change();
2899 hotkey_wakeup_hotunplug_complete_notify_change();
2900 hotkey_poll_setup_safe(0);
2903 /* procfs -------------------------------------------------------------- */
2904 static int hotkey_read(char *p
)
2909 if (!tp_features
.hotkey
) {
2910 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2914 if (mutex_lock_killable(&hotkey_mutex
))
2915 return -ERESTARTSYS
;
2916 res
= hotkey_status_get(&status
);
2918 res
= hotkey_mask_get();
2919 mutex_unlock(&hotkey_mutex
);
2923 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
2924 if (tp_features
.hotkey_mask
) {
2925 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", hotkey_mask
);
2926 len
+= sprintf(p
+ len
,
2927 "commands:\tenable, disable, reset, <mask>\n");
2929 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
2930 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
2936 static void hotkey_enabledisable_warn(void)
2938 tpacpi_log_usertask("procfs hotkey enable/disable");
2940 "hotkey enable/disable functionality has been "
2941 "removed from the driver. Hotkeys are always enabled.\n");
2944 static int hotkey_write(char *buf
)
2950 if (!tp_features
.hotkey
)
2953 if (mutex_lock_killable(&hotkey_mutex
))
2954 return -ERESTARTSYS
;
2959 while ((cmd
= next_cmd(&buf
))) {
2960 if (strlencmp(cmd
, "enable") == 0) {
2961 hotkey_enabledisable_warn();
2962 } else if (strlencmp(cmd
, "disable") == 0) {
2963 hotkey_enabledisable_warn();
2965 } else if (strlencmp(cmd
, "reset") == 0) {
2966 mask
= hotkey_orig_mask
;
2967 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
2969 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
2976 if (!res
&& mask
!= hotkey_mask
)
2977 res
= hotkey_mask_set(mask
);
2980 mutex_unlock(&hotkey_mutex
);
2984 static const struct acpi_device_id ibm_htk_device_ids
[] = {
2985 {TPACPI_ACPI_HKEY_HID
, 0},
2989 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
2990 .hid
= ibm_htk_device_ids
,
2991 .notify
= hotkey_notify
,
2992 .handle
= &hkey_handle
,
2993 .type
= ACPI_DEVICE_NOTIFY
,
2996 static struct ibm_struct hotkey_driver_data
= {
2998 .read
= hotkey_read
,
2999 .write
= hotkey_write
,
3000 .exit
= hotkey_exit
,
3001 .resume
= hotkey_resume
,
3002 .suspend
= hotkey_suspend
,
3003 .acpi
= &ibm_hotkey_acpidriver
,
3006 /*************************************************************************
3007 * Bluetooth subdriver
3011 /* ACPI GBDC/SBDC bits */
3012 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
3013 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
3014 TP_ACPI_BLUETOOTH_RESUMECTRL
= 0x04, /* Bluetooth state at resume:
3019 /* ACPI \BLTH commands */
3020 TP_ACPI_BLTH_GET_ULTRAPORT_ID
= 0x00, /* Get Ultraport BT ID */
3021 TP_ACPI_BLTH_GET_PWR_ON_RESUME
= 0x01, /* Get power-on-resume state */
3022 TP_ACPI_BLTH_PWR_ON_ON_RESUME
= 0x02, /* Resume powered on */
3023 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
= 0x03, /* Resume powered off */
3024 TP_ACPI_BLTH_SAVE_STATE
= 0x05, /* Save state for S4/S5 */
3027 static struct rfkill
*tpacpi_bluetooth_rfkill
;
3029 static void bluetooth_suspend(pm_message_t state
)
3031 /* Try to make sure radio will resume powered off */
3032 acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3033 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
);
3036 static int bluetooth_get_radiosw(void)
3040 if (!tp_features
.bluetooth
)
3043 /* WLSW overrides bluetooth in firmware/hardware, reflect that */
3044 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3045 return RFKILL_STATE_HARD_BLOCKED
;
3047 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3048 if (dbg_bluetoothemul
)
3049 return (tpacpi_bluetooth_emulstate
) ?
3050 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3053 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
3056 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0) ?
3057 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3060 static void bluetooth_update_rfk(void)
3064 if (!tpacpi_bluetooth_rfkill
)
3067 status
= bluetooth_get_radiosw();
3070 rfkill_force_state(tpacpi_bluetooth_rfkill
, status
);
3073 static int bluetooth_set_radiosw(int radio_on
, int update_rfk
)
3077 if (!tp_features
.bluetooth
)
3080 /* WLSW overrides bluetooth in firmware/hardware, but there is no
3081 * reason to risk weird behaviour. */
3082 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3086 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3087 if (dbg_bluetoothemul
) {
3088 tpacpi_bluetooth_emulstate
= !!radio_on
;
3090 bluetooth_update_rfk();
3095 /* We make sure to keep TP_ACPI_BLUETOOTH_RESUMECTRL off */
3097 status
= TP_ACPI_BLUETOOTH_RADIOSSW
;
3100 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
3104 bluetooth_update_rfk();
3109 /* sysfs bluetooth enable ---------------------------------------------- */
3110 static ssize_t
bluetooth_enable_show(struct device
*dev
,
3111 struct device_attribute
*attr
,
3116 printk_deprecated_rfkill_attribute("bluetooth_enable");
3118 status
= bluetooth_get_radiosw();
3122 return snprintf(buf
, PAGE_SIZE
, "%d\n",
3123 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
3126 static ssize_t
bluetooth_enable_store(struct device
*dev
,
3127 struct device_attribute
*attr
,
3128 const char *buf
, size_t count
)
3133 printk_deprecated_rfkill_attribute("bluetooth_enable");
3135 if (parse_strtoul(buf
, 1, &t
))
3138 res
= bluetooth_set_radiosw(t
, 1);
3140 return (res
) ? res
: count
;
3143 static struct device_attribute dev_attr_bluetooth_enable
=
3144 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
3145 bluetooth_enable_show
, bluetooth_enable_store
);
3147 /* --------------------------------------------------------------------- */
3149 static struct attribute
*bluetooth_attributes
[] = {
3150 &dev_attr_bluetooth_enable
.attr
,
3154 static const struct attribute_group bluetooth_attr_group
= {
3155 .attrs
= bluetooth_attributes
,
3158 static int tpacpi_bluetooth_rfk_get(void *data
, enum rfkill_state
*state
)
3160 int bts
= bluetooth_get_radiosw();
3169 static int tpacpi_bluetooth_rfk_set(void *data
, enum rfkill_state state
)
3171 return bluetooth_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
3174 static void bluetooth_shutdown(void)
3176 /* Order firmware to save current state to NVRAM */
3177 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3178 TP_ACPI_BLTH_SAVE_STATE
))
3179 printk(TPACPI_NOTICE
3180 "failed to save bluetooth state to NVRAM\n");
3183 static void bluetooth_exit(void)
3185 bluetooth_shutdown();
3187 if (tpacpi_bluetooth_rfkill
)
3188 rfkill_unregister(tpacpi_bluetooth_rfkill
);
3190 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3191 &bluetooth_attr_group
);
3194 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
3199 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
3201 TPACPI_ACPIHANDLE_INIT(hkey
);
3203 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
3204 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
3205 tp_features
.bluetooth
= hkey_handle
&&
3206 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
3208 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
3209 str_supported(tp_features
.bluetooth
),
3212 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3213 if (dbg_bluetoothemul
) {
3214 tp_features
.bluetooth
= 1;
3216 "bluetooth switch emulation enabled\n");
3219 if (tp_features
.bluetooth
&&
3220 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
3221 /* no bluetooth hardware present in system */
3222 tp_features
.bluetooth
= 0;
3223 dbg_printk(TPACPI_DBG_INIT
,
3224 "bluetooth hardware not installed\n");
3227 if (!tp_features
.bluetooth
)
3230 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3231 &bluetooth_attr_group
);
3235 res
= tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
,
3236 &tpacpi_bluetooth_rfkill
,
3237 RFKILL_TYPE_BLUETOOTH
,
3238 "tpacpi_bluetooth_sw",
3240 tpacpi_bluetooth_rfk_set
,
3241 tpacpi_bluetooth_rfk_get
);
3250 /* procfs -------------------------------------------------------------- */
3251 static int bluetooth_read(char *p
)
3254 int status
= bluetooth_get_radiosw();
3256 if (!tp_features
.bluetooth
)
3257 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3259 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3260 (status
== RFKILL_STATE_UNBLOCKED
) ?
3261 "enabled" : "disabled");
3262 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
3268 static int bluetooth_write(char *buf
)
3272 if (!tp_features
.bluetooth
)
3275 while ((cmd
= next_cmd(&buf
))) {
3276 if (strlencmp(cmd
, "enable") == 0) {
3277 bluetooth_set_radiosw(1, 1);
3278 } else if (strlencmp(cmd
, "disable") == 0) {
3279 bluetooth_set_radiosw(0, 1);
3287 static struct ibm_struct bluetooth_driver_data
= {
3288 .name
= "bluetooth",
3289 .read
= bluetooth_read
,
3290 .write
= bluetooth_write
,
3291 .exit
= bluetooth_exit
,
3292 .suspend
= bluetooth_suspend
,
3293 .shutdown
= bluetooth_shutdown
,
3296 /*************************************************************************
3301 /* ACPI GWAN/SWAN bits */
3302 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
3303 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
3304 TP_ACPI_WANCARD_RESUMECTRL
= 0x04, /* Wan state at resume:
3308 static struct rfkill
*tpacpi_wan_rfkill
;
3310 static void wan_suspend(pm_message_t state
)
3312 /* Try to make sure radio will resume powered off */
3313 acpi_evalf(NULL
, NULL
, "\\WGSV", "qvd",
3314 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
);
3317 static int wan_get_radiosw(void)
3321 if (!tp_features
.wan
)
3324 /* WLSW overrides WWAN in firmware/hardware, reflect that */
3325 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3326 return RFKILL_STATE_HARD_BLOCKED
;
3328 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3330 return (tpacpi_wwan_emulstate
) ?
3331 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3334 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
3337 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0) ?
3338 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3341 static void wan_update_rfk(void)
3345 if (!tpacpi_wan_rfkill
)
3348 status
= wan_get_radiosw();
3351 rfkill_force_state(tpacpi_wan_rfkill
, status
);
3354 static int wan_set_radiosw(int radio_on
, int update_rfk
)
3358 if (!tp_features
.wan
)
3361 /* WLSW overrides bluetooth in firmware/hardware, but there is no
3362 * reason to risk weird behaviour. */
3363 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3367 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3369 tpacpi_wwan_emulstate
= !!radio_on
;
3376 /* We make sure to keep TP_ACPI_WANCARD_RESUMECTRL off */
3378 status
= TP_ACPI_WANCARD_RADIOSSW
;
3381 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
3390 /* sysfs wan enable ---------------------------------------------------- */
3391 static ssize_t
wan_enable_show(struct device
*dev
,
3392 struct device_attribute
*attr
,
3397 printk_deprecated_rfkill_attribute("wwan_enable");
3399 status
= wan_get_radiosw();
3403 return snprintf(buf
, PAGE_SIZE
, "%d\n",
3404 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
3407 static ssize_t
wan_enable_store(struct device
*dev
,
3408 struct device_attribute
*attr
,
3409 const char *buf
, size_t count
)
3414 printk_deprecated_rfkill_attribute("wwan_enable");
3416 if (parse_strtoul(buf
, 1, &t
))
3419 res
= wan_set_radiosw(t
, 1);
3421 return (res
) ? res
: count
;
3424 static struct device_attribute dev_attr_wan_enable
=
3425 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
3426 wan_enable_show
, wan_enable_store
);
3428 /* --------------------------------------------------------------------- */
3430 static struct attribute
*wan_attributes
[] = {
3431 &dev_attr_wan_enable
.attr
,
3435 static const struct attribute_group wan_attr_group
= {
3436 .attrs
= wan_attributes
,
3439 static int tpacpi_wan_rfk_get(void *data
, enum rfkill_state
*state
)
3441 int wans
= wan_get_radiosw();
3450 static int tpacpi_wan_rfk_set(void *data
, enum rfkill_state state
)
3452 return wan_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
3455 static void wan_shutdown(void)
3457 /* Order firmware to save current state to NVRAM */
3458 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "vd",
3459 TP_ACPI_WGSV_SAVE_STATE
))
3460 printk(TPACPI_NOTICE
3461 "failed to save WWAN state to NVRAM\n");
3464 static void wan_exit(void)
3468 if (tpacpi_wan_rfkill
)
3469 rfkill_unregister(tpacpi_wan_rfkill
);
3471 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3475 static int __init
wan_init(struct ibm_init_struct
*iibm
)
3480 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
3482 TPACPI_ACPIHANDLE_INIT(hkey
);
3484 tp_features
.wan
= hkey_handle
&&
3485 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
3487 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
3488 str_supported(tp_features
.wan
),
3491 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3493 tp_features
.wan
= 1;
3495 "wwan switch emulation enabled\n");
3498 if (tp_features
.wan
&&
3499 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
3500 /* no wan hardware present in system */
3501 tp_features
.wan
= 0;
3502 dbg_printk(TPACPI_DBG_INIT
,
3503 "wan hardware not installed\n");
3506 if (!tp_features
.wan
)
3509 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3514 res
= tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID
,
3520 tpacpi_wan_rfk_get
);
3529 /* procfs -------------------------------------------------------------- */
3530 static int wan_read(char *p
)
3533 int status
= wan_get_radiosw();
3535 if (!tp_features
.wan
)
3536 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3538 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3539 (status
== RFKILL_STATE_UNBLOCKED
) ?
3540 "enabled" : "disabled");
3541 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
3547 static int wan_write(char *buf
)
3551 if (!tp_features
.wan
)
3554 while ((cmd
= next_cmd(&buf
))) {
3555 if (strlencmp(cmd
, "enable") == 0) {
3556 wan_set_radiosw(1, 1);
3557 } else if (strlencmp(cmd
, "disable") == 0) {
3558 wan_set_radiosw(0, 1);
3566 static struct ibm_struct wan_driver_data
= {
3571 .suspend
= wan_suspend
,
3572 .shutdown
= wan_shutdown
,
3575 /*************************************************************************
3580 /* ACPI GUWB/SUWB bits */
3581 TP_ACPI_UWB_HWPRESENT
= 0x01, /* UWB hw available */
3582 TP_ACPI_UWB_RADIOSSW
= 0x02, /* UWB radio enabled */
3585 static struct rfkill
*tpacpi_uwb_rfkill
;
3587 static int uwb_get_radiosw(void)
3591 if (!tp_features
.uwb
)
3594 /* WLSW overrides UWB in firmware/hardware, reflect that */
3595 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3596 return RFKILL_STATE_HARD_BLOCKED
;
3598 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3600 return (tpacpi_uwb_emulstate
) ?
3601 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3604 if (!acpi_evalf(hkey_handle
, &status
, "GUWB", "d"))
3607 return ((status
& TP_ACPI_UWB_RADIOSSW
) != 0) ?
3608 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3611 static void uwb_update_rfk(void)
3615 if (!tpacpi_uwb_rfkill
)
3618 status
= uwb_get_radiosw();
3621 rfkill_force_state(tpacpi_uwb_rfkill
, status
);
3624 static int uwb_set_radiosw(int radio_on
, int update_rfk
)
3628 if (!tp_features
.uwb
)
3631 /* WLSW overrides UWB in firmware/hardware, but there is no
3632 * reason to risk weird behaviour. */
3633 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3637 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3639 tpacpi_uwb_emulstate
= !!radio_on
;
3646 status
= (radio_on
) ? TP_ACPI_UWB_RADIOSSW
: 0;
3647 if (!acpi_evalf(hkey_handle
, NULL
, "SUWB", "vd", status
))
3656 /* --------------------------------------------------------------------- */
3658 static int tpacpi_uwb_rfk_get(void *data
, enum rfkill_state
*state
)
3660 int uwbs
= uwb_get_radiosw();
3669 static int tpacpi_uwb_rfk_set(void *data
, enum rfkill_state state
)
3671 return uwb_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
3674 static void uwb_exit(void)
3676 if (tpacpi_uwb_rfkill
)
3677 rfkill_unregister(tpacpi_uwb_rfkill
);
3680 static int __init
uwb_init(struct ibm_init_struct
*iibm
)
3685 vdbg_printk(TPACPI_DBG_INIT
, "initializing uwb subdriver\n");
3687 TPACPI_ACPIHANDLE_INIT(hkey
);
3689 tp_features
.uwb
= hkey_handle
&&
3690 acpi_evalf(hkey_handle
, &status
, "GUWB", "qd");
3692 vdbg_printk(TPACPI_DBG_INIT
, "uwb is %s, status 0x%02x\n",
3693 str_supported(tp_features
.uwb
),
3696 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3698 tp_features
.uwb
= 1;
3700 "uwb switch emulation enabled\n");
3703 if (tp_features
.uwb
&&
3704 !(status
& TP_ACPI_UWB_HWPRESENT
)) {
3705 /* no uwb hardware present in system */
3706 tp_features
.uwb
= 0;
3707 dbg_printk(TPACPI_DBG_INIT
,
3708 "uwb hardware not installed\n");
3711 if (!tp_features
.uwb
)
3714 res
= tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID
,
3720 tpacpi_uwb_rfk_get
);
3725 static struct ibm_struct uwb_driver_data
= {
3728 .flags
.experimental
= 1,
3731 /*************************************************************************
3735 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
3737 enum video_access_mode
{
3738 TPACPI_VIDEO_NONE
= 0,
3739 TPACPI_VIDEO_570
, /* 570 */
3740 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
3741 TPACPI_VIDEO_NEW
, /* all others */
3744 enum { /* video status flags, based on VIDEO_570 */
3745 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
3746 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
3747 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
3750 enum { /* TPACPI_VIDEO_570 constants */
3751 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
3752 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
3753 * video_status_flags */
3754 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
3755 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
3758 static enum video_access_mode video_supported
;
3759 static int video_orig_autosw
;
3761 static int video_autosw_get(void);
3762 static int video_autosw_set(int enable
);
3764 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
3766 static int __init
video_init(struct ibm_init_struct
*iibm
)
3770 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
3772 TPACPI_ACPIHANDLE_INIT(vid
);
3773 TPACPI_ACPIHANDLE_INIT(vid2
);
3775 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
3776 /* G41, assume IVGA doesn't change */
3777 vid_handle
= vid2_handle
;
3780 /* video switching not supported on R30, R31 */
3781 video_supported
= TPACPI_VIDEO_NONE
;
3782 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
3784 video_supported
= TPACPI_VIDEO_570
;
3785 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
3786 /* 600e/x, 770e, 770x */
3787 video_supported
= TPACPI_VIDEO_770
;
3790 video_supported
= TPACPI_VIDEO_NEW
;
3792 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
3793 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
3796 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
3799 static void video_exit(void)
3801 dbg_printk(TPACPI_DBG_EXIT
,
3802 "restoring original video autoswitch mode\n");
3803 if (video_autosw_set(video_orig_autosw
))
3804 printk(TPACPI_ERR
"error while trying to restore original "
3805 "video autoswitch mode\n");
3808 static int video_outputsw_get(void)
3813 switch (video_supported
) {
3814 case TPACPI_VIDEO_570
:
3815 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
3816 TP_ACPI_VIDEO_570_PHSCMD
))
3818 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
3820 case TPACPI_VIDEO_770
:
3821 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
3824 status
|= TP_ACPI_VIDEO_S_LCD
;
3825 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
3828 status
|= TP_ACPI_VIDEO_S_CRT
;
3830 case TPACPI_VIDEO_NEW
:
3831 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
3832 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
3835 status
|= TP_ACPI_VIDEO_S_CRT
;
3837 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
3838 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
3841 status
|= TP_ACPI_VIDEO_S_LCD
;
3842 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
3845 status
|= TP_ACPI_VIDEO_S_DVI
;
3854 static int video_outputsw_set(int status
)
3859 switch (video_supported
) {
3860 case TPACPI_VIDEO_570
:
3861 res
= acpi_evalf(NULL
, NULL
,
3862 "\\_SB.PHS2", "vdd",
3863 TP_ACPI_VIDEO_570_PHS2CMD
,
3864 status
| TP_ACPI_VIDEO_570_PHS2SET
);
3866 case TPACPI_VIDEO_770
:
3867 autosw
= video_autosw_get();
3871 res
= video_autosw_set(1);
3874 res
= acpi_evalf(vid_handle
, NULL
,
3875 "ASWT", "vdd", status
* 0x100, 0);
3876 if (!autosw
&& video_autosw_set(autosw
)) {
3878 "video auto-switch left enabled due to error\n");
3882 case TPACPI_VIDEO_NEW
:
3883 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
3884 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
3890 return (res
)? 0 : -EIO
;
3893 static int video_autosw_get(void)
3897 switch (video_supported
) {
3898 case TPACPI_VIDEO_570
:
3899 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
3902 case TPACPI_VIDEO_770
:
3903 case TPACPI_VIDEO_NEW
:
3904 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
3914 static int video_autosw_set(int enable
)
3916 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
3921 static int video_outputsw_cycle(void)
3923 int autosw
= video_autosw_get();
3929 switch (video_supported
) {
3930 case TPACPI_VIDEO_570
:
3931 res
= video_autosw_set(1);
3934 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
3936 case TPACPI_VIDEO_770
:
3937 case TPACPI_VIDEO_NEW
:
3938 res
= video_autosw_set(1);
3941 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
3946 if (!autosw
&& video_autosw_set(autosw
)) {
3948 "video auto-switch left enabled due to error\n");
3952 return (res
)? 0 : -EIO
;
3955 static int video_expand_toggle(void)
3957 switch (video_supported
) {
3958 case TPACPI_VIDEO_570
:
3959 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
3961 case TPACPI_VIDEO_770
:
3962 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
3964 case TPACPI_VIDEO_NEW
:
3965 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
3973 static int video_read(char *p
)
3978 if (video_supported
== TPACPI_VIDEO_NONE
) {
3979 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3983 status
= video_outputsw_get();
3987 autosw
= video_autosw_get();
3991 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3992 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
3993 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
3994 if (video_supported
== TPACPI_VIDEO_NEW
)
3995 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
3996 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
3997 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
3998 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
3999 if (video_supported
== TPACPI_VIDEO_NEW
)
4000 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
4001 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
4002 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
4007 static int video_write(char *buf
)
4010 int enable
, disable
, status
;
4013 if (video_supported
== TPACPI_VIDEO_NONE
)
4019 while ((cmd
= next_cmd(&buf
))) {
4020 if (strlencmp(cmd
, "lcd_enable") == 0) {
4021 enable
|= TP_ACPI_VIDEO_S_LCD
;
4022 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
4023 disable
|= TP_ACPI_VIDEO_S_LCD
;
4024 } else if (strlencmp(cmd
, "crt_enable") == 0) {
4025 enable
|= TP_ACPI_VIDEO_S_CRT
;
4026 } else if (strlencmp(cmd
, "crt_disable") == 0) {
4027 disable
|= TP_ACPI_VIDEO_S_CRT
;
4028 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4029 strlencmp(cmd
, "dvi_enable") == 0) {
4030 enable
|= TP_ACPI_VIDEO_S_DVI
;
4031 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4032 strlencmp(cmd
, "dvi_disable") == 0) {
4033 disable
|= TP_ACPI_VIDEO_S_DVI
;
4034 } else if (strlencmp(cmd
, "auto_enable") == 0) {
4035 res
= video_autosw_set(1);
4038 } else if (strlencmp(cmd
, "auto_disable") == 0) {
4039 res
= video_autosw_set(0);
4042 } else if (strlencmp(cmd
, "video_switch") == 0) {
4043 res
= video_outputsw_cycle();
4046 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
4047 res
= video_expand_toggle();
4054 if (enable
|| disable
) {
4055 status
= video_outputsw_get();
4058 res
= video_outputsw_set((status
& ~disable
) | enable
);
4066 static struct ibm_struct video_driver_data
= {
4069 .write
= video_write
,
4073 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
4075 /*************************************************************************
4076 * Light (thinklight) subdriver
4079 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
4080 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
4082 static int light_get_status(void)
4086 if (tp_features
.light_status
) {
4087 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
4095 static int light_set_status(int status
)
4099 if (tp_features
.light
) {
4101 rc
= acpi_evalf(cmos_handle
, NULL
, NULL
, "vd",
4103 TP_CMOS_THINKLIGHT_ON
:
4104 TP_CMOS_THINKLIGHT_OFF
);
4106 rc
= acpi_evalf(lght_handle
, NULL
, NULL
, "vd",
4109 return (rc
)? 0 : -EIO
;
4115 static void light_set_status_worker(struct work_struct
*work
)
4117 struct tpacpi_led_classdev
*data
=
4118 container_of(work
, struct tpacpi_led_classdev
, work
);
4120 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4121 light_set_status((data
->new_state
!= TPACPI_LED_OFF
));
4124 static void light_sysfs_set(struct led_classdev
*led_cdev
,
4125 enum led_brightness brightness
)
4127 struct tpacpi_led_classdev
*data
=
4128 container_of(led_cdev
,
4129 struct tpacpi_led_classdev
,
4131 data
->new_state
= (brightness
!= LED_OFF
) ?
4132 TPACPI_LED_ON
: TPACPI_LED_OFF
;
4133 queue_work(tpacpi_wq
, &data
->work
);
4136 static enum led_brightness
light_sysfs_get(struct led_classdev
*led_cdev
)
4138 return (light_get_status() == 1)? LED_FULL
: LED_OFF
;
4141 static struct tpacpi_led_classdev tpacpi_led_thinklight
= {
4143 .name
= "tpacpi::thinklight",
4144 .brightness_set
= &light_sysfs_set
,
4145 .brightness_get
= &light_sysfs_get
,
4149 static int __init
light_init(struct ibm_init_struct
*iibm
)
4153 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
4155 TPACPI_ACPIHANDLE_INIT(ledb
);
4156 TPACPI_ACPIHANDLE_INIT(lght
);
4157 TPACPI_ACPIHANDLE_INIT(cmos
);
4158 INIT_WORK(&tpacpi_led_thinklight
.work
, light_set_status_worker
);
4160 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
4161 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
4163 if (tp_features
.light
)
4164 /* light status not supported on
4165 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
4166 tp_features
.light_status
=
4167 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
4169 vdbg_printk(TPACPI_DBG_INIT
, "light is %s, light status is %s\n",
4170 str_supported(tp_features
.light
),
4171 str_supported(tp_features
.light_status
));
4173 if (!tp_features
.light
)
4176 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4177 &tpacpi_led_thinklight
.led_classdev
);
4180 tp_features
.light
= 0;
4181 tp_features
.light_status
= 0;
4189 static void light_exit(void)
4191 led_classdev_unregister(&tpacpi_led_thinklight
.led_classdev
);
4192 if (work_pending(&tpacpi_led_thinklight
.work
))
4193 flush_workqueue(tpacpi_wq
);
4196 static int light_read(char *p
)
4201 if (!tp_features
.light
) {
4202 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4203 } else if (!tp_features
.light_status
) {
4204 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
4205 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
4207 status
= light_get_status();
4210 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
4211 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
4217 static int light_write(char *buf
)
4222 if (!tp_features
.light
)
4225 while ((cmd
= next_cmd(&buf
))) {
4226 if (strlencmp(cmd
, "on") == 0) {
4228 } else if (strlencmp(cmd
, "off") == 0) {
4234 return light_set_status(newstatus
);
4237 static struct ibm_struct light_driver_data
= {
4240 .write
= light_write
,
4244 /*************************************************************************
4248 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4250 static void dock_notify(struct ibm_struct
*ibm
, u32 event
);
4251 static int dock_read(char *p
);
4252 static int dock_write(char *buf
);
4254 TPACPI_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
4255 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
4256 "\\_SB.PCI0.PCI1.DOCK", /* all others */
4257 "\\_SB.PCI.ISA.SLCE", /* 570 */
4258 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
4260 /* don't list other alternatives as we install a notify handler on the 570 */
4261 TPACPI_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
4263 static const struct acpi_device_id ibm_pci_device_ids
[] = {
4264 {PCI_ROOT_HID_STRING
, 0},
4268 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
4270 .notify
= dock_notify
,
4271 .handle
= &dock_handle
,
4272 .type
= ACPI_SYSTEM_NOTIFY
,
4275 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
4276 * We just use it to get notifications of dock hotplug
4277 * in very old thinkpads */
4278 .hid
= ibm_pci_device_ids
,
4279 .notify
= dock_notify
,
4280 .handle
= &pci_handle
,
4281 .type
= ACPI_SYSTEM_NOTIFY
,
4285 static struct ibm_struct dock_driver_data
[2] = {
4289 .write
= dock_write
,
4290 .acpi
= &ibm_dock_acpidriver
[0],
4294 .acpi
= &ibm_dock_acpidriver
[1],
4298 #define dock_docked() (_sta(dock_handle) & 1)
4300 static int __init
dock_init(struct ibm_init_struct
*iibm
)
4302 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
4304 TPACPI_ACPIHANDLE_INIT(dock
);
4306 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
4307 str_supported(dock_handle
!= NULL
));
4309 return (dock_handle
)? 0 : 1;
4312 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
4316 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
4318 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
4319 dock_driver_data
[0].flags
.acpi_notify_installed
) {
4320 TPACPI_ACPIHANDLE_INIT(pci
);
4321 dock2_needed
= (pci_handle
!= NULL
);
4322 vdbg_printk(TPACPI_DBG_INIT
,
4323 "dock PCI handler for the TP 570 is %s\n",
4324 str_supported(dock2_needed
));
4326 vdbg_printk(TPACPI_DBG_INIT
,
4327 "dock subdriver part 2 not required\n");
4331 return (dock2_needed
)? 0 : 1;
4334 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
4336 int docked
= dock_docked();
4337 int pci
= ibm
->acpi
->hid
&& ibm
->acpi
->device
&&
4338 acpi_match_device_ids(ibm
->acpi
->device
, ibm_pci_device_ids
);
4341 if (event
== 1 && !pci
) /* 570 */
4342 data
= 1; /* button */
4343 else if (event
== 1 && pci
) /* 570 */
4344 data
= 3; /* dock */
4345 else if (event
== 3 && docked
)
4346 data
= 1; /* button */
4347 else if (event
== 3 && !docked
)
4348 data
= 2; /* undock */
4349 else if (event
== 0 && docked
)
4350 data
= 3; /* dock */
4352 printk(TPACPI_ERR
"unknown dock event %d, status %d\n",
4353 event
, _sta(dock_handle
));
4354 data
= 0; /* unknown */
4356 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, data
);
4357 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
4358 dev_name(&ibm
->acpi
->device
->dev
),
4362 static int dock_read(char *p
)
4365 int docked
= dock_docked();
4368 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4370 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
4372 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
4373 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
4379 static int dock_write(char *buf
)
4386 while ((cmd
= next_cmd(&buf
))) {
4387 if (strlencmp(cmd
, "undock") == 0) {
4388 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
4389 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
4391 } else if (strlencmp(cmd
, "dock") == 0) {
4392 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
4401 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
4403 /*************************************************************************
4407 #ifdef CONFIG_THINKPAD_ACPI_BAY
4409 TPACPI_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
4410 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
4411 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
4412 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
4413 ); /* A21e, R30, R31 */
4414 TPACPI_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
4415 "_EJ0", /* all others */
4416 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
4417 TPACPI_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
4418 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
4420 TPACPI_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
4424 static int __init
bay_init(struct ibm_init_struct
*iibm
)
4426 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
4428 TPACPI_ACPIHANDLE_INIT(bay
);
4430 TPACPI_ACPIHANDLE_INIT(bay_ej
);
4431 TPACPI_ACPIHANDLE_INIT(bay2
);
4433 TPACPI_ACPIHANDLE_INIT(bay2_ej
);
4435 tp_features
.bay_status
= bay_handle
&&
4436 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
4437 tp_features
.bay_status2
= bay2_handle
&&
4438 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
4440 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
4441 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
4442 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
4443 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
4445 vdbg_printk(TPACPI_DBG_INIT
,
4446 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
4447 str_supported(tp_features
.bay_status
),
4448 str_supported(tp_features
.bay_eject
),
4449 str_supported(tp_features
.bay_status2
),
4450 str_supported(tp_features
.bay_eject2
));
4452 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
4453 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
4456 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
4458 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, 0);
4459 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
4460 dev_name(&ibm
->acpi
->device
->dev
),
4464 #define bay_occupied(b) (_sta(b##_handle) & 1)
4466 static int bay_read(char *p
)
4469 int occupied
= bay_occupied(bay
);
4470 int occupied2
= bay_occupied(bay2
);
4473 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
4474 tp_features
.bay_status
?
4475 (occupied
? "occupied" : "unoccupied") :
4477 if (tp_features
.bay_status2
)
4478 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
4479 "occupied" : "unoccupied");
4481 eject
= tp_features
.bay_eject
&& occupied
;
4482 eject2
= tp_features
.bay_eject2
&& occupied2
;
4484 if (eject
&& eject2
)
4485 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
4487 len
+= sprintf(p
+ len
, "commands:\teject\n");
4489 len
+= sprintf(p
+ len
, "commands:\teject2\n");
4494 static int bay_write(char *buf
)
4498 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
4501 while ((cmd
= next_cmd(&buf
))) {
4502 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
4503 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
4505 } else if (tp_features
.bay_eject2
&&
4506 strlencmp(cmd
, "eject2") == 0) {
4507 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
4516 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
4517 .notify
= bay_notify
,
4518 .handle
= &bay_handle
,
4519 .type
= ACPI_SYSTEM_NOTIFY
,
4522 static struct ibm_struct bay_driver_data
= {
4526 .acpi
= &ibm_bay_acpidriver
,
4529 #endif /* CONFIG_THINKPAD_ACPI_BAY */
4531 /*************************************************************************
4535 /* sysfs cmos_command -------------------------------------------------- */
4536 static ssize_t
cmos_command_store(struct device
*dev
,
4537 struct device_attribute
*attr
,
4538 const char *buf
, size_t count
)
4540 unsigned long cmos_cmd
;
4543 if (parse_strtoul(buf
, 21, &cmos_cmd
))
4546 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4547 return (res
)? res
: count
;
4550 static struct device_attribute dev_attr_cmos_command
=
4551 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
4553 /* --------------------------------------------------------------------- */
4555 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
4559 vdbg_printk(TPACPI_DBG_INIT
,
4560 "initializing cmos commands subdriver\n");
4562 TPACPI_ACPIHANDLE_INIT(cmos
);
4564 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
4565 str_supported(cmos_handle
!= NULL
));
4567 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4571 return (cmos_handle
)? 0 : 1;
4574 static void cmos_exit(void)
4576 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4579 static int cmos_read(char *p
)
4583 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4584 R30, R31, T20-22, X20-21 */
4586 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4588 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4589 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
4595 static int cmos_write(char *buf
)
4600 while ((cmd
= next_cmd(&buf
))) {
4601 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
4602 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
4607 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4615 static struct ibm_struct cmos_driver_data
= {
4618 .write
= cmos_write
,
4622 /*************************************************************************
4626 enum led_access_mode
{
4627 TPACPI_LED_NONE
= 0,
4628 TPACPI_LED_570
, /* 570 */
4629 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4630 TPACPI_LED_NEW
, /* all others */
4633 enum { /* For TPACPI_LED_OLD */
4634 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
4635 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
4636 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
4639 static enum led_access_mode led_supported
;
4641 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
4642 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
4643 /* T20-22, X20-21 */
4644 "LED", /* all others */
4647 #define TPACPI_LED_NUMLEDS 8
4648 static struct tpacpi_led_classdev
*tpacpi_leds
;
4649 static enum led_status_t tpacpi_led_state_cache
[TPACPI_LED_NUMLEDS
];
4650 static const char * const tpacpi_led_names
[TPACPI_LED_NUMLEDS
] = {
4651 /* there's a limit of 19 chars + NULL before 2.6.26 */
4653 "tpacpi:orange:batt",
4654 "tpacpi:green:batt",
4655 "tpacpi::dock_active",
4656 "tpacpi::bay_active",
4657 "tpacpi::dock_batt",
4658 "tpacpi::unknown_led",
4662 static int led_get_status(const unsigned int led
)
4665 enum led_status_t led_s
;
4667 switch (led_supported
) {
4668 case TPACPI_LED_570
:
4669 if (!acpi_evalf(ec_handle
,
4670 &status
, "GLED", "dd", 1 << led
))
4672 led_s
= (status
== 0)?
4677 tpacpi_led_state_cache
[led
] = led_s
;
4686 static int led_set_status(const unsigned int led
,
4687 const enum led_status_t ledstatus
)
4689 /* off, on, blink. Index is led_status_t */
4690 static const unsigned int led_sled_arg1
[] = { 0, 1, 3 };
4691 static const unsigned int led_led_arg1
[] = { 0, 0x80, 0xc0 };
4695 switch (led_supported
) {
4696 case TPACPI_LED_570
:
4700 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
4701 (1 << led
), led_sled_arg1
[ledstatus
]))
4704 case TPACPI_LED_OLD
:
4705 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
4708 rc
= ec_write(TPACPI_LED_EC_HLMS
, (1 << led
));
4710 rc
= ec_write(TPACPI_LED_EC_HLBL
,
4711 (ledstatus
== TPACPI_LED_BLINK
) << led
);
4713 rc
= ec_write(TPACPI_LED_EC_HLCL
,
4714 (ledstatus
!= TPACPI_LED_OFF
) << led
);
4716 case TPACPI_LED_NEW
:
4718 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
4719 led
, led_led_arg1
[ledstatus
]))
4727 tpacpi_led_state_cache
[led
] = ledstatus
;
4732 static void led_set_status_worker(struct work_struct
*work
)
4734 struct tpacpi_led_classdev
*data
=
4735 container_of(work
, struct tpacpi_led_classdev
, work
);
4737 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4738 led_set_status(data
->led
, data
->new_state
);
4741 static void led_sysfs_set(struct led_classdev
*led_cdev
,
4742 enum led_brightness brightness
)
4744 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4745 struct tpacpi_led_classdev
, led_classdev
);
4747 if (brightness
== LED_OFF
)
4748 data
->new_state
= TPACPI_LED_OFF
;
4749 else if (tpacpi_led_state_cache
[data
->led
] != TPACPI_LED_BLINK
)
4750 data
->new_state
= TPACPI_LED_ON
;
4752 data
->new_state
= TPACPI_LED_BLINK
;
4754 queue_work(tpacpi_wq
, &data
->work
);
4757 static int led_sysfs_blink_set(struct led_classdev
*led_cdev
,
4758 unsigned long *delay_on
, unsigned long *delay_off
)
4760 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4761 struct tpacpi_led_classdev
, led_classdev
);
4763 /* Can we choose the flash rate? */
4764 if (*delay_on
== 0 && *delay_off
== 0) {
4765 /* yes. set them to the hardware blink rate (1 Hz) */
4766 *delay_on
= 500; /* ms */
4767 *delay_off
= 500; /* ms */
4768 } else if ((*delay_on
!= 500) || (*delay_off
!= 500))
4771 data
->new_state
= TPACPI_LED_BLINK
;
4772 queue_work(tpacpi_wq
, &data
->work
);
4777 static enum led_brightness
led_sysfs_get(struct led_classdev
*led_cdev
)
4781 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4782 struct tpacpi_led_classdev
, led_classdev
);
4784 rc
= led_get_status(data
->led
);
4786 if (rc
== TPACPI_LED_OFF
|| rc
< 0)
4787 rc
= LED_OFF
; /* no error handling in led class :( */
4794 static void led_exit(void)
4798 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
4799 if (tpacpi_leds
[i
].led_classdev
.name
)
4800 led_classdev_unregister(&tpacpi_leds
[i
].led_classdev
);
4806 static int __init
led_init(struct ibm_init_struct
*iibm
)
4811 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
4813 TPACPI_ACPIHANDLE_INIT(led
);
4816 /* led not supported on R30, R31 */
4817 led_supported
= TPACPI_LED_NONE
;
4818 else if (strlencmp(led_path
, "SLED") == 0)
4820 led_supported
= TPACPI_LED_570
;
4821 else if (strlencmp(led_path
, "SYSL") == 0)
4822 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4823 led_supported
= TPACPI_LED_OLD
;
4826 led_supported
= TPACPI_LED_NEW
;
4828 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
4829 str_supported(led_supported
), led_supported
);
4831 tpacpi_leds
= kzalloc(sizeof(*tpacpi_leds
) * TPACPI_LED_NUMLEDS
,
4834 printk(TPACPI_ERR
"Out of memory for LED data\n");
4838 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
4839 tpacpi_leds
[i
].led
= i
;
4841 tpacpi_leds
[i
].led_classdev
.brightness_set
= &led_sysfs_set
;
4842 tpacpi_leds
[i
].led_classdev
.blink_set
= &led_sysfs_blink_set
;
4843 if (led_supported
== TPACPI_LED_570
)
4844 tpacpi_leds
[i
].led_classdev
.brightness_get
=
4847 tpacpi_leds
[i
].led_classdev
.name
= tpacpi_led_names
[i
];
4849 INIT_WORK(&tpacpi_leds
[i
].work
, led_set_status_worker
);
4851 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4852 &tpacpi_leds
[i
].led_classdev
);
4854 tpacpi_leds
[i
].led_classdev
.name
= NULL
;
4860 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
4863 #define str_led_status(s) \
4864 ((s) == TPACPI_LED_OFF ? "off" : \
4865 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
4867 static int led_read(char *p
)
4871 if (!led_supported
) {
4872 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4875 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4877 if (led_supported
== TPACPI_LED_570
) {
4880 for (i
= 0; i
< 8; i
++) {
4881 status
= led_get_status(i
);
4884 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
4885 i
, str_led_status(status
));
4889 len
+= sprintf(p
+ len
, "commands:\t"
4890 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
4895 static int led_write(char *buf
)
4899 enum led_status_t s
;
4904 while ((cmd
= next_cmd(&buf
))) {
4905 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
4908 if (strstr(cmd
, "off")) {
4910 } else if (strstr(cmd
, "on")) {
4912 } else if (strstr(cmd
, "blink")) {
4913 s
= TPACPI_LED_BLINK
;
4918 rc
= led_set_status(led
, s
);
4926 static struct ibm_struct led_driver_data
= {
4933 /*************************************************************************
4937 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
4939 static int __init
beep_init(struct ibm_init_struct
*iibm
)
4941 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
4943 TPACPI_ACPIHANDLE_INIT(beep
);
4945 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
4946 str_supported(beep_handle
!= NULL
));
4948 return (beep_handle
)? 0 : 1;
4951 static int beep_read(char *p
)
4956 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4958 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4959 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
4965 static int beep_write(char *buf
)
4973 while ((cmd
= next_cmd(&buf
))) {
4974 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
4975 beep_cmd
>= 0 && beep_cmd
<= 17) {
4979 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
4986 static struct ibm_struct beep_driver_data
= {
4989 .write
= beep_write
,
4992 /*************************************************************************
4996 enum thermal_access_mode
{
4997 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
4998 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
4999 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
5000 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
5001 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
5004 enum { /* TPACPI_THERMAL_TPEC_* */
5005 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
5006 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
5007 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
5010 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
5011 struct ibm_thermal_sensors_struct
{
5012 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
5015 static enum thermal_access_mode thermal_read_mode
;
5017 /* idx is zero-based */
5018 static int thermal_get_sensor(int idx
, s32
*value
)
5024 t
= TP_EC_THERMAL_TMP0
;
5026 switch (thermal_read_mode
) {
5027 #if TPACPI_MAX_THERMAL_SENSORS >= 16
5028 case TPACPI_THERMAL_TPEC_16
:
5029 if (idx
>= 8 && idx
<= 15) {
5030 t
= TP_EC_THERMAL_TMP8
;
5035 case TPACPI_THERMAL_TPEC_8
:
5037 if (!acpi_ec_read(t
+ idx
, &tmp
))
5039 *value
= tmp
* 1000;
5044 case TPACPI_THERMAL_ACPI_UPDT
:
5046 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5047 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
5049 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5051 *value
= (t
- 2732) * 100;
5056 case TPACPI_THERMAL_ACPI_TMP07
:
5058 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5059 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5061 if (t
> 127 || t
< -127)
5062 t
= TP_EC_THERMAL_TMP_NA
;
5068 case TPACPI_THERMAL_NONE
:
5076 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
5087 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
5090 for (i
= 0 ; i
< n
; i
++) {
5091 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
5099 /* sysfs temp##_input -------------------------------------------------- */
5101 static ssize_t
thermal_temp_input_show(struct device
*dev
,
5102 struct device_attribute
*attr
,
5105 struct sensor_device_attribute
*sensor_attr
=
5106 to_sensor_dev_attr(attr
);
5107 int idx
= sensor_attr
->index
;
5111 res
= thermal_get_sensor(idx
, &value
);
5114 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
5117 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
5120 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
5121 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
5122 thermal_temp_input_show, NULL, _idxB)
5124 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
5125 THERMAL_SENSOR_ATTR_TEMP(1, 0),
5126 THERMAL_SENSOR_ATTR_TEMP(2, 1),
5127 THERMAL_SENSOR_ATTR_TEMP(3, 2),
5128 THERMAL_SENSOR_ATTR_TEMP(4, 3),
5129 THERMAL_SENSOR_ATTR_TEMP(5, 4),
5130 THERMAL_SENSOR_ATTR_TEMP(6, 5),
5131 THERMAL_SENSOR_ATTR_TEMP(7, 6),
5132 THERMAL_SENSOR_ATTR_TEMP(8, 7),
5133 THERMAL_SENSOR_ATTR_TEMP(9, 8),
5134 THERMAL_SENSOR_ATTR_TEMP(10, 9),
5135 THERMAL_SENSOR_ATTR_TEMP(11, 10),
5136 THERMAL_SENSOR_ATTR_TEMP(12, 11),
5137 THERMAL_SENSOR_ATTR_TEMP(13, 12),
5138 THERMAL_SENSOR_ATTR_TEMP(14, 13),
5139 THERMAL_SENSOR_ATTR_TEMP(15, 14),
5140 THERMAL_SENSOR_ATTR_TEMP(16, 15),
5143 #define THERMAL_ATTRS(X) \
5144 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
5146 static struct attribute
*thermal_temp_input_attr
[] = {
5166 static const struct attribute_group thermal_temp_input16_group
= {
5167 .attrs
= thermal_temp_input_attr
5170 static const struct attribute_group thermal_temp_input8_group
= {
5171 .attrs
= &thermal_temp_input_attr
[8]
5174 #undef THERMAL_SENSOR_ATTR_TEMP
5175 #undef THERMAL_ATTRS
5177 /* --------------------------------------------------------------------- */
5179 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
5186 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
5188 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
5190 if (thinkpad_id
.ec_model
) {
5192 * Direct EC access mode: sensors at registers
5193 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
5194 * non-implemented, thermal sensors return 0x80 when
5199 for (i
= 0; i
< 8; i
++) {
5200 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
5206 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
5214 /* This is sheer paranoia, but we handle it anyway */
5217 "ThinkPad ACPI EC access misbehaving, "
5218 "falling back to ACPI TMPx access "
5220 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5223 "ThinkPad ACPI EC access misbehaving, "
5224 "disabling thermal sensors access\n");
5225 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5230 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
5232 } else if (acpi_tmp7
) {
5233 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
5234 /* 600e/x, 770e, 770x */
5235 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
5237 /* Standard ACPI TMPx access, max 8 sensors */
5238 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5241 /* temperatures not supported on 570, G4x, R30, R31, R32 */
5242 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5245 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
5246 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
5249 switch (thermal_read_mode
) {
5250 case TPACPI_THERMAL_TPEC_16
:
5251 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5252 &thermal_temp_input16_group
);
5256 case TPACPI_THERMAL_TPEC_8
:
5257 case TPACPI_THERMAL_ACPI_TMP07
:
5258 case TPACPI_THERMAL_ACPI_UPDT
:
5259 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5260 &thermal_temp_input8_group
);
5264 case TPACPI_THERMAL_NONE
:
5272 static void thermal_exit(void)
5274 switch (thermal_read_mode
) {
5275 case TPACPI_THERMAL_TPEC_16
:
5276 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5277 &thermal_temp_input16_group
);
5279 case TPACPI_THERMAL_TPEC_8
:
5280 case TPACPI_THERMAL_ACPI_TMP07
:
5281 case TPACPI_THERMAL_ACPI_UPDT
:
5282 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5283 &thermal_temp_input16_group
);
5285 case TPACPI_THERMAL_NONE
:
5291 static int thermal_read(char *p
)
5295 struct ibm_thermal_sensors_struct t
;
5297 n
= thermal_get_sensors(&t
);
5298 if (unlikely(n
< 0))
5301 len
+= sprintf(p
+ len
, "temperatures:\t");
5304 for (i
= 0; i
< (n
- 1); i
++)
5305 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
5306 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
5308 len
+= sprintf(p
+ len
, "not supported\n");
5313 static struct ibm_struct thermal_driver_data
= {
5315 .read
= thermal_read
,
5316 .exit
= thermal_exit
,
5319 /*************************************************************************
5323 static u8 ecdump_regs
[256];
5325 static int ecdump_read(char *p
)
5331 len
+= sprintf(p
+ len
, "EC "
5332 " +00 +01 +02 +03 +04 +05 +06 +07"
5333 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
5334 for (i
= 0; i
< 256; i
+= 16) {
5335 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
5336 for (j
= 0; j
< 16; j
++) {
5337 if (!acpi_ec_read(i
+ j
, &v
))
5339 if (v
!= ecdump_regs
[i
+ j
])
5340 len
+= sprintf(p
+ len
, " *%02x", v
);
5342 len
+= sprintf(p
+ len
, " %02x", v
);
5343 ecdump_regs
[i
+ j
] = v
;
5345 len
+= sprintf(p
+ len
, "\n");
5350 /* These are way too dangerous to advertise openly... */
5352 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
5353 " (<offset> is 00-ff, <value> is 00-ff)\n");
5354 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
5355 " (<offset> is 00-ff, <value> is 0-255)\n");
5360 static int ecdump_write(char *buf
)
5365 while ((cmd
= next_cmd(&buf
))) {
5366 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
5368 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
5372 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
5373 if (!acpi_ec_write(i
, v
))
5382 static struct ibm_struct ecdump_driver_data
= {
5384 .read
= ecdump_read
,
5385 .write
= ecdump_write
,
5386 .flags
.experimental
= 1,
5389 /*************************************************************************
5390 * Backlight/brightness subdriver
5393 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
5396 TP_EC_BACKLIGHT
= 0x31,
5398 /* TP_EC_BACKLIGHT bitmasks */
5399 TP_EC_BACKLIGHT_LVLMSK
= 0x1F,
5400 TP_EC_BACKLIGHT_CMDMSK
= 0xE0,
5401 TP_EC_BACKLIGHT_MAPSW
= 0x20,
5404 static struct backlight_device
*ibm_backlight_device
;
5405 static int brightness_mode
;
5406 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
5408 static struct mutex brightness_mutex
;
5411 * ThinkPads can read brightness from two places: EC 0x31, or
5412 * CMOS NVRAM byte 0x5E, bits 0-3.
5414 * EC 0x31 has the following layout
5415 * Bit 7: unknown function
5416 * Bit 6: unknown function
5417 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
5418 * Bit 4: must be set to zero to avoid problems
5419 * Bit 3-0: backlight brightness level
5421 * brightness_get_raw returns status data in the EC 0x31 layout
5423 static int brightness_get_raw(int *status
)
5425 u8 lec
= 0, lcmos
= 0, level
= 0;
5427 if (brightness_mode
& 1) {
5428 if (!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
))
5430 level
= lec
& TP_EC_BACKLIGHT_LVLMSK
;
5432 if (brightness_mode
& 2) {
5433 lcmos
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
5434 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5435 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
5436 lcmos
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
5440 if (brightness_mode
== 3) {
5441 *status
= lec
; /* Prefer EC, CMOS is just a backing store */
5442 lec
&= TP_EC_BACKLIGHT_LVLMSK
;
5444 tp_warned
.bright_cmos_ec_unsync
= 0;
5446 if (!tp_warned
.bright_cmos_ec_unsync
) {
5448 "CMOS NVRAM (%u) and EC (%u) do not "
5449 "agree on display brightness level\n",
5450 (unsigned int) lcmos
,
5451 (unsigned int) lec
);
5452 tp_warned
.bright_cmos_ec_unsync
= 1;
5463 /* May return EINTR which can always be mapped to ERESTARTSYS */
5464 static int brightness_set(int value
)
5466 int cmos_cmd
, inc
, i
, res
;
5470 if (value
> ((tp_features
.bright_16levels
)? 15 : 7) ||
5474 res
= mutex_lock_killable(&brightness_mutex
);
5478 res
= brightness_get_raw(¤t_value
);
5482 command_bits
= current_value
& TP_EC_BACKLIGHT_CMDMSK
;
5483 current_value
&= TP_EC_BACKLIGHT_LVLMSK
;
5485 cmos_cmd
= value
> current_value
?
5486 TP_CMOS_BRIGHTNESS_UP
:
5487 TP_CMOS_BRIGHTNESS_DOWN
;
5488 inc
= (value
> current_value
)? 1 : -1;
5491 for (i
= current_value
; i
!= value
; i
+= inc
) {
5492 if ((brightness_mode
& 2) &&
5493 issue_thinkpad_cmos_command(cmos_cmd
)) {
5497 if ((brightness_mode
& 1) &&
5498 !acpi_ec_write(TP_EC_BACKLIGHT
,
5499 (i
+ inc
) | command_bits
)) {
5506 mutex_unlock(&brightness_mutex
);
5510 /* sysfs backlight class ----------------------------------------------- */
5512 static int brightness_update_status(struct backlight_device
*bd
)
5514 /* it is the backlight class's job (caller) to handle
5515 * EINTR and other errors properly */
5516 return brightness_set(
5517 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
5518 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
5519 bd
->props
.brightness
: 0);
5522 static int brightness_get(struct backlight_device
*bd
)
5526 res
= brightness_get_raw(&status
);
5528 return 0; /* FIXME: teach backlight about error handling */
5530 return status
& TP_EC_BACKLIGHT_LVLMSK
;
5533 static struct backlight_ops ibm_backlight_data
= {
5534 .get_brightness
= brightness_get
,
5535 .update_status
= brightness_update_status
,
5538 /* --------------------------------------------------------------------- */
5540 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
5544 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
5546 mutex_init(&brightness_mutex
);
5549 * We always attempt to detect acpi support, so as to switch
5550 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
5551 * going to publish a backlight interface
5553 b
= tpacpi_check_std_acpi_brightness_support();
5556 if (acpi_video_backlight_support()) {
5557 if (brightness_enable
> 1) {
5558 printk(TPACPI_NOTICE
5559 "Standard ACPI backlight interface "
5560 "available, not loading native one.\n");
5562 } else if (brightness_enable
== 1) {
5563 printk(TPACPI_NOTICE
5564 "Backlight control force enabled, even if standard "
5565 "ACPI backlight interface is available\n");
5568 if (brightness_enable
> 1) {
5569 printk(TPACPI_NOTICE
5570 "Standard ACPI backlight interface not "
5571 "available, thinkpad_acpi native "
5572 "brightness control enabled\n");
5577 if (!brightness_enable
) {
5578 dbg_printk(TPACPI_DBG_INIT
,
5579 "brightness support disabled by "
5580 "module parameter\n");
5586 "Unsupported brightness interface, "
5587 "please contact %s\n", TPACPI_MAIL
);
5591 tp_features
.bright_16levels
= 1;
5593 if (!brightness_mode
) {
5594 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
)
5595 brightness_mode
= 2;
5597 brightness_mode
= 3;
5599 dbg_printk(TPACPI_DBG_INIT
, "selected brightness_mode=%d\n",
5603 if (brightness_mode
> 3)
5606 if (brightness_get_raw(&b
) < 0)
5609 if (tp_features
.bright_16levels
)
5611 "detected a 16-level brightness capable ThinkPad\n");
5613 ibm_backlight_device
= backlight_device_register(
5614 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
5615 &ibm_backlight_data
);
5616 if (IS_ERR(ibm_backlight_device
)) {
5617 printk(TPACPI_ERR
"Could not register backlight device\n");
5618 return PTR_ERR(ibm_backlight_device
);
5620 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
5622 ibm_backlight_device
->props
.max_brightness
=
5623 (tp_features
.bright_16levels
)? 15 : 7;
5624 ibm_backlight_device
->props
.brightness
= b
& TP_EC_BACKLIGHT_LVLMSK
;
5625 backlight_update_status(ibm_backlight_device
);
5630 static void brightness_exit(void)
5632 if (ibm_backlight_device
) {
5633 vdbg_printk(TPACPI_DBG_EXIT
,
5634 "calling backlight_device_unregister()\n");
5635 backlight_device_unregister(ibm_backlight_device
);
5639 static int brightness_read(char *p
)
5644 level
= brightness_get(NULL
);
5646 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
5648 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
5649 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
5650 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
5651 " (<level> is 0-%d)\n",
5652 (tp_features
.bright_16levels
) ? 15 : 7);
5658 static int brightness_write(char *buf
)
5663 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
5665 level
= brightness_get(NULL
);
5669 while ((cmd
= next_cmd(&buf
))) {
5670 if (strlencmp(cmd
, "up") == 0) {
5671 if (level
< max_level
)
5673 } else if (strlencmp(cmd
, "down") == 0) {
5676 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
5677 level
>= 0 && level
<= max_level
) {
5684 * Now we know what the final level should be, so we try to set it.
5685 * Doing it this way makes the syscall restartable in case of EINTR
5687 rc
= brightness_set(level
);
5688 return (rc
== -EINTR
)? ERESTARTSYS
: rc
;
5691 static struct ibm_struct brightness_driver_data
= {
5692 .name
= "brightness",
5693 .read
= brightness_read
,
5694 .write
= brightness_write
,
5695 .exit
= brightness_exit
,
5698 /*************************************************************************
5702 static int volume_offset
= 0x30;
5704 static int volume_read(char *p
)
5709 if (!acpi_ec_read(volume_offset
, &level
)) {
5710 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
5712 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
5713 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
5714 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
5715 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
5716 " (<level> is 0-15)\n");
5722 static int volume_write(char *buf
)
5724 int cmos_cmd
, inc
, i
;
5726 int new_level
, new_mute
;
5729 while ((cmd
= next_cmd(&buf
))) {
5730 if (!acpi_ec_read(volume_offset
, &level
))
5732 new_mute
= mute
= level
& 0x40;
5733 new_level
= level
= level
& 0xf;
5735 if (strlencmp(cmd
, "up") == 0) {
5739 new_level
= level
== 15 ? 15 : level
+ 1;
5740 } else if (strlencmp(cmd
, "down") == 0) {
5744 new_level
= level
== 0 ? 0 : level
- 1;
5745 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
5746 new_level
>= 0 && new_level
<= 15) {
5748 } else if (strlencmp(cmd
, "mute") == 0) {
5753 if (new_level
!= level
) {
5754 /* mute doesn't change */
5756 cmos_cmd
= (new_level
> level
) ?
5757 TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
5758 inc
= new_level
> level
? 1 : -1;
5760 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
5761 !acpi_ec_write(volume_offset
, level
)))
5764 for (i
= level
; i
!= new_level
; i
+= inc
)
5765 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
5766 !acpi_ec_write(volume_offset
, i
+ inc
))
5770 (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
5771 !acpi_ec_write(volume_offset
, new_level
+ mute
))) {
5776 if (new_mute
!= mute
) {
5777 /* level doesn't change */
5779 cmos_cmd
= (new_mute
) ?
5780 TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
5782 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
5783 !acpi_ec_write(volume_offset
, level
+ new_mute
))
5791 static struct ibm_struct volume_driver_data
= {
5793 .read
= volume_read
,
5794 .write
= volume_write
,
5797 /*************************************************************************
5804 * TPACPI_FAN_RD_ACPI_GFAN:
5805 * ACPI GFAN method: returns fan level
5807 * see TPACPI_FAN_WR_ACPI_SFAN
5808 * EC 0x2f (HFSP) not available if GFAN exists
5810 * TPACPI_FAN_WR_ACPI_SFAN:
5811 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
5813 * EC 0x2f (HFSP) might be available *for reading*, but do not use
5816 * TPACPI_FAN_WR_TPEC:
5817 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
5818 * Supported on almost all ThinkPads
5820 * Fan speed changes of any sort (including those caused by the
5821 * disengaged mode) are usually done slowly by the firmware as the
5822 * maximum ammount of fan duty cycle change per second seems to be
5825 * Reading is not available if GFAN exists.
5826 * Writing is not available if SFAN exists.
5829 * 7 automatic mode engaged;
5830 * (default operation mode of the ThinkPad)
5831 * fan level is ignored in this mode.
5832 * 6 full speed mode (takes precedence over bit 7);
5833 * not available on all thinkpads. May disable
5834 * the tachometer while the fan controller ramps up
5835 * the speed (which can take up to a few *minutes*).
5836 * Speeds up fan to 100% duty-cycle, which is far above
5837 * the standard RPM levels. It is not impossible that
5838 * it could cause hardware damage.
5839 * 5-3 unused in some models. Extra bits for fan level
5840 * in others, but still useless as all values above
5841 * 7 map to the same speed as level 7 in these models.
5842 * 2-0 fan level (0..7 usually)
5844 * 0x07 = max (set when temperatures critical)
5845 * Some ThinkPads may have other levels, see
5846 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
5848 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
5849 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
5850 * does so, its initial value is meaningless (0x07).
5852 * For firmware bugs, refer to:
5853 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
5857 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
5858 * Main fan tachometer reading (in RPM)
5860 * This register is present on all ThinkPads with a new-style EC, and
5861 * it is known not to be present on the A21m/e, and T22, as there is
5862 * something else in offset 0x84 according to the ACPI DSDT. Other
5863 * ThinkPads from this same time period (and earlier) probably lack the
5864 * tachometer as well.
5866 * Unfortunately a lot of ThinkPads with new-style ECs but whose firmware
5867 * was never fixed by IBM to report the EC firmware version string
5868 * probably support the tachometer (like the early X models), so
5869 * detecting it is quite hard. We need more data to know for sure.
5871 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
5874 * FIRMWARE BUG: may go stale while the EC is switching to full speed
5877 * For firmware bugs, refer to:
5878 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
5880 * TPACPI_FAN_WR_ACPI_FANS:
5881 * ThinkPad X31, X40, X41. Not available in the X60.
5883 * FANS ACPI handle: takes three arguments: low speed, medium speed,
5884 * high speed. ACPI DSDT seems to map these three speeds to levels
5885 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
5886 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
5888 * The speeds are stored on handles
5889 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
5891 * There are three default speed sets, acessible as handles:
5892 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
5894 * ACPI DSDT switches which set is in use depending on various
5897 * TPACPI_FAN_WR_TPEC is also available and should be used to
5898 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
5899 * but the ACPI tables just mention level 7.
5902 enum { /* Fan control constants */
5903 fan_status_offset
= 0x2f, /* EC register 0x2f */
5904 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
5905 * 0x84 must be read before 0x85 */
5907 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
5908 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
5910 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
5913 enum fan_status_access_mode
{
5914 TPACPI_FAN_NONE
= 0, /* No fan status or control */
5915 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
5916 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
5919 enum fan_control_access_mode
{
5920 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
5921 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
5922 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
5923 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
5926 enum fan_control_commands
{
5927 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
5928 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
5929 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
5930 * and also watchdog cmd */
5933 static int fan_control_allowed
;
5935 static enum fan_status_access_mode fan_status_access_mode
;
5936 static enum fan_control_access_mode fan_control_access_mode
;
5937 static enum fan_control_commands fan_control_commands
;
5939 static u8 fan_control_initial_status
;
5940 static u8 fan_control_desired_level
;
5941 static u8 fan_control_resume_level
;
5942 static int fan_watchdog_maxinterval
;
5944 static struct mutex fan_mutex
;
5946 static void fan_watchdog_fire(struct work_struct
*ignored
);
5947 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
5949 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
5950 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
5951 "\\FSPD", /* 600e/x, 770e, 770x */
5953 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
5954 "JFNS", /* 770x-JL */
5958 * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the
5959 * HFSP register at boot, so it contains 0x07 but the Thinkpad could
5960 * be in auto mode (0x80).
5962 * This is corrected by any write to HFSP either by the driver, or
5965 * We assume 0x07 really means auto mode while this quirk is active,
5966 * as this is far more likely than the ThinkPad being in level 7,
5967 * which is only used by the firmware during thermal emergencies.
5970 static void fan_quirk1_detect(void)
5972 /* In some ThinkPads, neither the EC nor the ACPI
5973 * DSDT initialize the HFSP register, and it ends up
5974 * being initially set to 0x07 when it *could* be
5975 * either 0x07 or 0x80.
5977 * Enable for TP-1Y (T43), TP-78 (R51e),
5978 * TP-76 (R52), TP-70 (T43, R52), which are known
5980 if (fan_control_initial_status
== 0x07) {
5981 switch (thinkpad_id
.ec_model
) {
5982 case 0x5931: /* TP-1Y */
5983 case 0x3837: /* TP-78 */
5984 case 0x3637: /* TP-76 */
5985 case 0x3037: /* TP-70 */
5986 printk(TPACPI_NOTICE
5987 "fan_init: initial fan status is unknown, "
5988 "assuming it is in auto mode\n");
5989 tp_features
.fan_ctrl_status_undef
= 1;
5995 static void fan_quirk1_handle(u8
*fan_status
)
5997 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
5998 if (*fan_status
!= fan_control_initial_status
) {
5999 /* something changed the HFSP regisnter since
6000 * driver init time, so it is not undefined
6002 tp_features
.fan_ctrl_status_undef
= 0;
6004 /* Return most likely status. In fact, it
6005 * might be the only possible status */
6006 *fan_status
= TP_EC_FAN_AUTO
;
6012 * Call with fan_mutex held
6014 static void fan_update_desired_level(u8 status
)
6017 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
6019 fan_control_desired_level
= 7;
6021 fan_control_desired_level
= status
;
6025 static int fan_get_status(u8
*status
)
6030 * Add TPACPI_FAN_RD_ACPI_FANS ? */
6032 switch (fan_status_access_mode
) {
6033 case TPACPI_FAN_RD_ACPI_GFAN
:
6034 /* 570, 600e/x, 770e, 770x */
6036 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
6044 case TPACPI_FAN_RD_TPEC
:
6045 /* all except 570, 600e/x, 770e, 770x */
6046 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
6049 if (likely(status
)) {
6051 fan_quirk1_handle(status
);
6063 static int fan_get_status_safe(u8
*status
)
6068 if (mutex_lock_killable(&fan_mutex
))
6069 return -ERESTARTSYS
;
6070 rc
= fan_get_status(&s
);
6072 fan_update_desired_level(s
);
6073 mutex_unlock(&fan_mutex
);
6081 static int fan_get_speed(unsigned int *speed
)
6085 switch (fan_status_access_mode
) {
6086 case TPACPI_FAN_RD_TPEC
:
6087 /* all except 570, 600e/x, 770e, 770x */
6088 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
6089 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
6093 *speed
= (hi
<< 8) | lo
;
6104 static int fan_set_level(int level
)
6106 if (!fan_control_allowed
)
6109 switch (fan_control_access_mode
) {
6110 case TPACPI_FAN_WR_ACPI_SFAN
:
6111 if (level
>= 0 && level
<= 7) {
6112 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
6118 case TPACPI_FAN_WR_ACPI_FANS
:
6119 case TPACPI_FAN_WR_TPEC
:
6120 if (!(level
& TP_EC_FAN_AUTO
) &&
6121 !(level
& TP_EC_FAN_FULLSPEED
) &&
6122 ((level
< 0) || (level
> 7)))
6125 /* safety net should the EC not support AUTO
6126 * or FULLSPEED mode bits and just ignore them */
6127 if (level
& TP_EC_FAN_FULLSPEED
)
6128 level
|= 7; /* safety min speed 7 */
6129 else if (level
& TP_EC_FAN_AUTO
)
6130 level
|= 4; /* safety min speed 4 */
6132 if (!acpi_ec_write(fan_status_offset
, level
))
6135 tp_features
.fan_ctrl_status_undef
= 0;
6144 static int fan_set_level_safe(int level
)
6148 if (!fan_control_allowed
)
6151 if (mutex_lock_killable(&fan_mutex
))
6152 return -ERESTARTSYS
;
6154 if (level
== TPACPI_FAN_LAST_LEVEL
)
6155 level
= fan_control_desired_level
;
6157 rc
= fan_set_level(level
);
6159 fan_update_desired_level(level
);
6161 mutex_unlock(&fan_mutex
);
6165 static int fan_set_enable(void)
6170 if (!fan_control_allowed
)
6173 if (mutex_lock_killable(&fan_mutex
))
6174 return -ERESTARTSYS
;
6176 switch (fan_control_access_mode
) {
6177 case TPACPI_FAN_WR_ACPI_FANS
:
6178 case TPACPI_FAN_WR_TPEC
:
6179 rc
= fan_get_status(&s
);
6183 /* Don't go out of emergency fan mode */
6186 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
6189 if (!acpi_ec_write(fan_status_offset
, s
))
6192 tp_features
.fan_ctrl_status_undef
= 0;
6197 case TPACPI_FAN_WR_ACPI_SFAN
:
6198 rc
= fan_get_status(&s
);
6204 /* Set fan to at least level 4 */
6207 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
6217 mutex_unlock(&fan_mutex
);
6221 static int fan_set_disable(void)
6225 if (!fan_control_allowed
)
6228 if (mutex_lock_killable(&fan_mutex
))
6229 return -ERESTARTSYS
;
6232 switch (fan_control_access_mode
) {
6233 case TPACPI_FAN_WR_ACPI_FANS
:
6234 case TPACPI_FAN_WR_TPEC
:
6235 if (!acpi_ec_write(fan_status_offset
, 0x00))
6238 fan_control_desired_level
= 0;
6239 tp_features
.fan_ctrl_status_undef
= 0;
6243 case TPACPI_FAN_WR_ACPI_SFAN
:
6244 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
6247 fan_control_desired_level
= 0;
6255 mutex_unlock(&fan_mutex
);
6259 static int fan_set_speed(int speed
)
6263 if (!fan_control_allowed
)
6266 if (mutex_lock_killable(&fan_mutex
))
6267 return -ERESTARTSYS
;
6270 switch (fan_control_access_mode
) {
6271 case TPACPI_FAN_WR_ACPI_FANS
:
6272 if (speed
>= 0 && speed
<= 65535) {
6273 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
6274 speed
, speed
, speed
))
6284 mutex_unlock(&fan_mutex
);
6288 static void fan_watchdog_reset(void)
6290 static int fan_watchdog_active
;
6292 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
6295 if (fan_watchdog_active
)
6296 cancel_delayed_work(&fan_watchdog_task
);
6298 if (fan_watchdog_maxinterval
> 0 &&
6299 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
6300 fan_watchdog_active
= 1;
6301 if (!queue_delayed_work(tpacpi_wq
, &fan_watchdog_task
,
6302 msecs_to_jiffies(fan_watchdog_maxinterval
6305 "failed to queue the fan watchdog, "
6306 "watchdog will not trigger\n");
6309 fan_watchdog_active
= 0;
6312 static void fan_watchdog_fire(struct work_struct
*ignored
)
6316 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
6319 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
6320 rc
= fan_set_enable();
6322 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
6323 "will try again later...\n", -rc
);
6324 /* reschedule for later */
6325 fan_watchdog_reset();
6330 * SYSFS fan layout: hwmon compatible (device)
6333 * 0: "disengaged" mode
6335 * 2: native EC "auto" mode (recommended, hardware default)
6337 * pwm*: set speed in manual mode, ignored otherwise.
6338 * 0 is level 0; 255 is level 7. Intermediate points done with linear
6341 * fan*_input: tachometer reading, RPM
6344 * SYSFS fan layout: extensions
6346 * fan_watchdog (driver):
6347 * fan watchdog interval in seconds, 0 disables (default), max 120
6350 /* sysfs fan pwm1_enable ----------------------------------------------- */
6351 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
6352 struct device_attribute
*attr
,
6358 res
= fan_get_status_safe(&status
);
6362 if (status
& TP_EC_FAN_FULLSPEED
) {
6364 } else if (status
& TP_EC_FAN_AUTO
) {
6369 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
6372 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
6373 struct device_attribute
*attr
,
6374 const char *buf
, size_t count
)
6379 if (parse_strtoul(buf
, 2, &t
))
6384 level
= TP_EC_FAN_FULLSPEED
;
6387 level
= TPACPI_FAN_LAST_LEVEL
;
6390 level
= TP_EC_FAN_AUTO
;
6393 /* reserved for software-controlled auto mode */
6399 res
= fan_set_level_safe(level
);
6405 fan_watchdog_reset();
6410 static struct device_attribute dev_attr_fan_pwm1_enable
=
6411 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
6412 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
6414 /* sysfs fan pwm1 ------------------------------------------------------ */
6415 static ssize_t
fan_pwm1_show(struct device
*dev
,
6416 struct device_attribute
*attr
,
6422 res
= fan_get_status_safe(&status
);
6427 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
6428 status
= fan_control_desired_level
;
6433 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
6436 static ssize_t
fan_pwm1_store(struct device
*dev
,
6437 struct device_attribute
*attr
,
6438 const char *buf
, size_t count
)
6442 u8 status
, newlevel
;
6444 if (parse_strtoul(buf
, 255, &s
))
6447 /* scale down from 0-255 to 0-7 */
6448 newlevel
= (s
>> 5) & 0x07;
6450 if (mutex_lock_killable(&fan_mutex
))
6451 return -ERESTARTSYS
;
6453 rc
= fan_get_status(&status
);
6454 if (!rc
&& (status
&
6455 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
6456 rc
= fan_set_level(newlevel
);
6460 fan_update_desired_level(newlevel
);
6461 fan_watchdog_reset();
6465 mutex_unlock(&fan_mutex
);
6466 return (rc
)? rc
: count
;
6469 static struct device_attribute dev_attr_fan_pwm1
=
6470 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
6471 fan_pwm1_show
, fan_pwm1_store
);
6473 /* sysfs fan fan1_input ------------------------------------------------ */
6474 static ssize_t
fan_fan1_input_show(struct device
*dev
,
6475 struct device_attribute
*attr
,
6481 res
= fan_get_speed(&speed
);
6485 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
6488 static struct device_attribute dev_attr_fan_fan1_input
=
6489 __ATTR(fan1_input
, S_IRUGO
,
6490 fan_fan1_input_show
, NULL
);
6492 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
6493 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
6496 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
6499 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
6500 const char *buf
, size_t count
)
6504 if (parse_strtoul(buf
, 120, &t
))
6507 if (!fan_control_allowed
)
6510 fan_watchdog_maxinterval
= t
;
6511 fan_watchdog_reset();
6516 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
6517 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
6519 /* --------------------------------------------------------------------- */
6520 static struct attribute
*fan_attributes
[] = {
6521 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
6522 &dev_attr_fan_fan1_input
.attr
,
6526 static const struct attribute_group fan_attr_group
= {
6527 .attrs
= fan_attributes
,
6530 static int __init
fan_init(struct ibm_init_struct
*iibm
)
6534 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
6536 mutex_init(&fan_mutex
);
6537 fan_status_access_mode
= TPACPI_FAN_NONE
;
6538 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
6539 fan_control_commands
= 0;
6540 fan_watchdog_maxinterval
= 0;
6541 tp_features
.fan_ctrl_status_undef
= 0;
6542 fan_control_desired_level
= 7;
6544 TPACPI_ACPIHANDLE_INIT(fans
);
6545 TPACPI_ACPIHANDLE_INIT(gfan
);
6546 TPACPI_ACPIHANDLE_INIT(sfan
);
6549 /* 570, 600e/x, 770e, 770x */
6550 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
6552 /* all other ThinkPads: note that even old-style
6553 * ThinkPad ECs supports the fan control register */
6554 if (likely(acpi_ec_read(fan_status_offset
,
6555 &fan_control_initial_status
))) {
6556 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
6557 fan_quirk1_detect();
6560 "ThinkPad ACPI EC access misbehaving, "
6561 "fan status and control unavailable\n");
6568 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
6569 fan_control_commands
|=
6570 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
6573 /* gfan without sfan means no fan control */
6574 /* all other models implement TP EC 0x2f control */
6578 fan_control_access_mode
=
6579 TPACPI_FAN_WR_ACPI_FANS
;
6580 fan_control_commands
|=
6581 TPACPI_FAN_CMD_SPEED
|
6582 TPACPI_FAN_CMD_LEVEL
|
6583 TPACPI_FAN_CMD_ENABLE
;
6585 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
6586 fan_control_commands
|=
6587 TPACPI_FAN_CMD_LEVEL
|
6588 TPACPI_FAN_CMD_ENABLE
;
6593 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
6594 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
6595 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
6596 fan_status_access_mode
, fan_control_access_mode
);
6598 /* fan control master switch */
6599 if (!fan_control_allowed
) {
6600 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
6601 fan_control_commands
= 0;
6602 dbg_printk(TPACPI_DBG_INIT
,
6603 "fan control features disabled by parameter\n");
6606 /* update fan_control_desired_level */
6607 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
6608 fan_get_status_safe(NULL
);
6610 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
6611 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
6612 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
6617 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
6618 &driver_attr_fan_watchdog
);
6620 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
6629 static void fan_exit(void)
6631 vdbg_printk(TPACPI_DBG_EXIT
,
6632 "cancelling any pending fan watchdog tasks\n");
6634 /* FIXME: can we really do this unconditionally? */
6635 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
6636 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
6637 &driver_attr_fan_watchdog
);
6639 cancel_delayed_work(&fan_watchdog_task
);
6640 flush_workqueue(tpacpi_wq
);
6643 static void fan_suspend(pm_message_t state
)
6647 if (!fan_control_allowed
)
6650 /* Store fan status in cache */
6651 fan_control_resume_level
= 0;
6652 rc
= fan_get_status_safe(&fan_control_resume_level
);
6654 printk(TPACPI_NOTICE
6655 "failed to read fan level for later "
6656 "restore during resume: %d\n", rc
);
6658 /* if it is undefined, don't attempt to restore it.
6660 if (tp_features
.fan_ctrl_status_undef
)
6661 fan_control_resume_level
= 0;
6664 static void fan_resume(void)
6666 u8 current_level
= 7;
6667 bool do_set
= false;
6670 /* DSDT *always* updates status on resume */
6671 tp_features
.fan_ctrl_status_undef
= 0;
6673 if (!fan_control_allowed
||
6674 !fan_control_resume_level
||
6675 (fan_get_status_safe(¤t_level
) < 0))
6678 switch (fan_control_access_mode
) {
6679 case TPACPI_FAN_WR_ACPI_SFAN
:
6680 /* never decrease fan level */
6681 do_set
= (fan_control_resume_level
> current_level
);
6683 case TPACPI_FAN_WR_ACPI_FANS
:
6684 case TPACPI_FAN_WR_TPEC
:
6685 /* never decrease fan level, scale is:
6686 * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO
6688 * We expect the firmware to set either 7 or AUTO, but we
6689 * handle FULLSPEED out of paranoia.
6691 * So, we can safely only restore FULLSPEED or 7, anything
6692 * else could slow the fan. Restoring AUTO is useless, at
6693 * best that's exactly what the DSDT already set (it is the
6696 * Always keep in mind that the DSDT *will* have set the
6697 * fans to what the vendor supposes is the best level. We
6698 * muck with it only to speed the fan up.
6700 if (fan_control_resume_level
!= 7 &&
6701 !(fan_control_resume_level
& TP_EC_FAN_FULLSPEED
))
6704 do_set
= !(current_level
& TP_EC_FAN_FULLSPEED
) &&
6705 (current_level
!= fan_control_resume_level
);
6711 printk(TPACPI_NOTICE
6712 "restoring fan level to 0x%02x\n",
6713 fan_control_resume_level
);
6714 rc
= fan_set_level_safe(fan_control_resume_level
);
6716 printk(TPACPI_NOTICE
6717 "failed to restore fan level: %d\n", rc
);
6721 static int fan_read(char *p
)
6726 unsigned int speed
= 0;
6728 switch (fan_status_access_mode
) {
6729 case TPACPI_FAN_RD_ACPI_GFAN
:
6730 /* 570, 600e/x, 770e, 770x */
6731 rc
= fan_get_status_safe(&status
);
6735 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
6737 (status
!= 0) ? "enabled" : "disabled", status
);
6740 case TPACPI_FAN_RD_TPEC
:
6741 /* all except 570, 600e/x, 770e, 770x */
6742 rc
= fan_get_status_safe(&status
);
6746 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
6747 (status
!= 0) ? "enabled" : "disabled");
6749 rc
= fan_get_speed(&speed
);
6753 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
6755 if (status
& TP_EC_FAN_FULLSPEED
)
6756 /* Disengaged mode takes precedence */
6757 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
6758 else if (status
& TP_EC_FAN_AUTO
)
6759 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
6761 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
6764 case TPACPI_FAN_NONE
:
6766 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
6769 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
6770 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
6772 switch (fan_control_access_mode
) {
6773 case TPACPI_FAN_WR_ACPI_SFAN
:
6774 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
6778 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
6779 "auto, disengaged, full-speed)\n");
6784 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
6785 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
6786 "commands:\twatchdog <timeout> (<timeout> "
6787 "is 0 (off), 1-120 (seconds))\n");
6789 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
6790 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
6791 " (<speed> is 0-65535)\n");
6796 static int fan_write_cmd_level(const char *cmd
, int *rc
)
6800 if (strlencmp(cmd
, "level auto") == 0)
6801 level
= TP_EC_FAN_AUTO
;
6802 else if ((strlencmp(cmd
, "level disengaged") == 0) |
6803 (strlencmp(cmd
, "level full-speed") == 0))
6804 level
= TP_EC_FAN_FULLSPEED
;
6805 else if (sscanf(cmd
, "level %d", &level
) != 1)
6808 *rc
= fan_set_level_safe(level
);
6810 printk(TPACPI_ERR
"level command accepted for unsupported "
6811 "access mode %d", fan_control_access_mode
);
6816 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
6818 if (strlencmp(cmd
, "enable") != 0)
6821 *rc
= fan_set_enable();
6823 printk(TPACPI_ERR
"enable command accepted for unsupported "
6824 "access mode %d", fan_control_access_mode
);
6829 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
6831 if (strlencmp(cmd
, "disable") != 0)
6834 *rc
= fan_set_disable();
6836 printk(TPACPI_ERR
"disable command accepted for unsupported "
6837 "access mode %d", fan_control_access_mode
);
6842 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
6847 * Support speed <low> <medium> <high> ? */
6849 if (sscanf(cmd
, "speed %d", &speed
) != 1)
6852 *rc
= fan_set_speed(speed
);
6854 printk(TPACPI_ERR
"speed command accepted for unsupported "
6855 "access mode %d", fan_control_access_mode
);
6860 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
6864 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
6867 if (interval
< 0 || interval
> 120)
6870 fan_watchdog_maxinterval
= interval
;
6875 static int fan_write(char *buf
)
6880 while (!rc
&& (cmd
= next_cmd(&buf
))) {
6881 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
6882 fan_write_cmd_level(cmd
, &rc
)) &&
6883 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
6884 (fan_write_cmd_enable(cmd
, &rc
) ||
6885 fan_write_cmd_disable(cmd
, &rc
) ||
6886 fan_write_cmd_watchdog(cmd
, &rc
))) &&
6887 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
6888 fan_write_cmd_speed(cmd
, &rc
))
6892 fan_watchdog_reset();
6898 static struct ibm_struct fan_driver_data
= {
6903 .suspend
= fan_suspend
,
6904 .resume
= fan_resume
,
6907 /****************************************************************************
6908 ****************************************************************************
6912 ****************************************************************************
6913 ****************************************************************************/
6915 /* sysfs name ---------------------------------------------------------- */
6916 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
6917 struct device_attribute
*attr
,
6920 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
6923 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
6924 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
6926 /* --------------------------------------------------------------------- */
6929 static struct proc_dir_entry
*proc_dir
;
6932 * Module and infrastructure proble, init and exit handling
6935 static int force_load
;
6937 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
6938 static const char * __init
str_supported(int is_supported
)
6940 static char text_unsupported
[] __initdata
= "not supported";
6942 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
6944 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
6946 static void ibm_exit(struct ibm_struct
*ibm
)
6948 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
6950 list_del_init(&ibm
->all_drivers
);
6952 if (ibm
->flags
.acpi_notify_installed
) {
6953 dbg_printk(TPACPI_DBG_EXIT
,
6954 "%s: acpi_remove_notify_handler\n", ibm
->name
);
6956 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
6958 dispatch_acpi_notify
);
6959 ibm
->flags
.acpi_notify_installed
= 0;
6960 ibm
->flags
.acpi_notify_installed
= 0;
6963 if (ibm
->flags
.proc_created
) {
6964 dbg_printk(TPACPI_DBG_EXIT
,
6965 "%s: remove_proc_entry\n", ibm
->name
);
6966 remove_proc_entry(ibm
->name
, proc_dir
);
6967 ibm
->flags
.proc_created
= 0;
6970 if (ibm
->flags
.acpi_driver_registered
) {
6971 dbg_printk(TPACPI_DBG_EXIT
,
6972 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
6974 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
6975 kfree(ibm
->acpi
->driver
);
6976 ibm
->acpi
->driver
= NULL
;
6977 ibm
->flags
.acpi_driver_registered
= 0;
6980 if (ibm
->flags
.init_called
&& ibm
->exit
) {
6982 ibm
->flags
.init_called
= 0;
6985 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
6988 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
6991 struct ibm_struct
*ibm
= iibm
->data
;
6992 struct proc_dir_entry
*entry
;
6994 BUG_ON(ibm
== NULL
);
6996 INIT_LIST_HEAD(&ibm
->all_drivers
);
6998 if (ibm
->flags
.experimental
&& !experimental
)
7001 dbg_printk(TPACPI_DBG_INIT
,
7002 "probing for %s\n", ibm
->name
);
7005 ret
= iibm
->init(iibm
);
7007 return 0; /* probe failed */
7011 ibm
->flags
.init_called
= 1;
7015 if (ibm
->acpi
->hid
) {
7016 ret
= register_tpacpi_subdriver(ibm
);
7021 if (ibm
->acpi
->notify
) {
7022 ret
= setup_acpi_notify(ibm
);
7023 if (ret
== -ENODEV
) {
7024 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
7034 dbg_printk(TPACPI_DBG_INIT
,
7035 "%s installed\n", ibm
->name
);
7038 entry
= create_proc_entry(ibm
->name
,
7039 S_IFREG
| S_IRUGO
| S_IWUSR
,
7042 printk(TPACPI_ERR
"unable to create proc entry %s\n",
7047 entry
->owner
= THIS_MODULE
;
7049 entry
->read_proc
= &dispatch_procfs_read
;
7051 entry
->write_proc
= &dispatch_procfs_write
;
7052 ibm
->flags
.proc_created
= 1;
7055 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
7060 dbg_printk(TPACPI_DBG_INIT
,
7061 "%s: at error exit path with result %d\n",
7065 return (ret
< 0)? ret
: 0;
7070 /* returns 0 - probe ok, or < 0 - probe error.
7071 * Probe ok doesn't mean thinkpad found.
7072 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
7073 static int __must_check __init
get_thinkpad_model_data(
7074 struct thinkpad_id_data
*tp
)
7076 const struct dmi_device
*dev
= NULL
;
7077 char ec_fw_string
[18];
7083 memset(tp
, 0, sizeof(*tp
));
7085 if (dmi_name_in_vendors("IBM"))
7086 tp
->vendor
= PCI_VENDOR_ID_IBM
;
7087 else if (dmi_name_in_vendors("LENOVO"))
7088 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
7092 s
= dmi_get_system_info(DMI_BIOS_VERSION
);
7093 tp
->bios_version_str
= kstrdup(s
, GFP_KERNEL
);
7094 if (s
&& !tp
->bios_version_str
)
7096 if (!tp
->bios_version_str
)
7098 tp
->bios_model
= tp
->bios_version_str
[0]
7099 | (tp
->bios_version_str
[1] << 8);
7102 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
7103 * X32 or newer, all Z series; Some models must have an
7104 * up-to-date BIOS or they will not be detected.
7106 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
7108 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
7109 if (sscanf(dev
->name
,
7110 "IBM ThinkPad Embedded Controller -[%17c",
7111 ec_fw_string
) == 1) {
7112 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
7113 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
7115 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
7116 if (!tp
->ec_version_str
)
7118 tp
->ec_model
= ec_fw_string
[0]
7119 | (ec_fw_string
[1] << 8);
7124 s
= dmi_get_system_info(DMI_PRODUCT_VERSION
);
7125 if (s
&& !strnicmp(s
, "ThinkPad", 8)) {
7126 tp
->model_str
= kstrdup(s
, GFP_KERNEL
);
7131 s
= dmi_get_system_info(DMI_PRODUCT_NAME
);
7132 tp
->nummodel_str
= kstrdup(s
, GFP_KERNEL
);
7133 if (s
&& !tp
->nummodel_str
)
7139 static int __init
probe_for_thinkpad(void)
7147 * Non-ancient models have better DMI tagging, but very old models
7150 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
7152 /* ec is required because many other handles are relative to it */
7153 TPACPI_ACPIHANDLE_INIT(ec
);
7157 "Not yet supported ThinkPad detected!\n");
7162 * Risks a regression on very old machines, but reduces potential
7163 * false positives a damn great deal
7166 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
7168 if (!is_thinkpad
&& !force_load
)
7175 /* Module init, exit, parameters */
7177 static struct ibm_init_struct ibms_init
[] __initdata
= {
7179 .init
= thinkpad_acpi_driver_init
,
7180 .data
= &thinkpad_acpi_driver_data
,
7183 .init
= hotkey_init
,
7184 .data
= &hotkey_driver_data
,
7187 .init
= bluetooth_init
,
7188 .data
= &bluetooth_driver_data
,
7192 .data
= &wan_driver_data
,
7196 .data
= &uwb_driver_data
,
7198 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
7201 .data
= &video_driver_data
,
7206 .data
= &light_driver_data
,
7208 #ifdef CONFIG_THINKPAD_ACPI_DOCK
7211 .data
= &dock_driver_data
[0],
7215 .data
= &dock_driver_data
[1],
7218 #ifdef CONFIG_THINKPAD_ACPI_BAY
7221 .data
= &bay_driver_data
,
7226 .data
= &cmos_driver_data
,
7230 .data
= &led_driver_data
,
7234 .data
= &beep_driver_data
,
7237 .init
= thermal_init
,
7238 .data
= &thermal_driver_data
,
7241 .data
= &ecdump_driver_data
,
7244 .init
= brightness_init
,
7245 .data
= &brightness_driver_data
,
7248 .data
= &volume_driver_data
,
7252 .data
= &fan_driver_data
,
7256 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
7259 struct ibm_struct
*ibm
;
7261 if (!kp
|| !kp
->name
|| !val
)
7264 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
7265 ibm
= ibms_init
[i
].data
;
7266 WARN_ON(ibm
== NULL
);
7268 if (!ibm
|| !ibm
->name
)
7271 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
7272 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
7274 strcpy(ibms_init
[i
].param
, val
);
7275 strcat(ibms_init
[i
].param
, ",");
7283 module_param(experimental
, int, 0);
7284 MODULE_PARM_DESC(experimental
,
7285 "Enables experimental features when non-zero");
7287 module_param_named(debug
, dbg_level
, uint
, 0);
7288 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
7290 module_param(force_load
, bool, 0);
7291 MODULE_PARM_DESC(force_load
,
7292 "Attempts to load the driver even on a "
7293 "mis-identified ThinkPad when true");
7295 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
7296 MODULE_PARM_DESC(fan_control
,
7297 "Enables setting fan parameters features when true");
7299 module_param_named(brightness_mode
, brightness_mode
, int, 0);
7300 MODULE_PARM_DESC(brightness_mode
,
7301 "Selects brightness control strategy: "
7302 "0=auto, 1=EC, 2=CMOS, 3=both");
7304 module_param(brightness_enable
, uint
, 0);
7305 MODULE_PARM_DESC(brightness_enable
,
7306 "Enables backlight control when 1, disables when 0");
7308 module_param(hotkey_report_mode
, uint
, 0);
7309 MODULE_PARM_DESC(hotkey_report_mode
,
7310 "used for backwards compatibility with userspace, "
7311 "see documentation");
7313 #define TPACPI_PARAM(feature) \
7314 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
7315 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
7316 "at module load, see documentation")
7318 TPACPI_PARAM(hotkey
);
7319 TPACPI_PARAM(bluetooth
);
7320 TPACPI_PARAM(video
);
7321 TPACPI_PARAM(light
);
7322 #ifdef CONFIG_THINKPAD_ACPI_DOCK
7325 #ifdef CONFIG_THINKPAD_ACPI_BAY
7327 #endif /* CONFIG_THINKPAD_ACPI_BAY */
7331 TPACPI_PARAM(ecdump
);
7332 TPACPI_PARAM(brightness
);
7333 TPACPI_PARAM(volume
);
7336 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
7337 module_param(dbg_wlswemul
, uint
, 0);
7338 MODULE_PARM_DESC(dbg_wlswemul
, "Enables WLSW emulation");
7339 module_param_named(wlsw_state
, tpacpi_wlsw_emulstate
, bool, 0);
7340 MODULE_PARM_DESC(wlsw_state
,
7341 "Initial state of the emulated WLSW switch");
7343 module_param(dbg_bluetoothemul
, uint
, 0);
7344 MODULE_PARM_DESC(dbg_bluetoothemul
, "Enables bluetooth switch emulation");
7345 module_param_named(bluetooth_state
, tpacpi_bluetooth_emulstate
, bool, 0);
7346 MODULE_PARM_DESC(bluetooth_state
,
7347 "Initial state of the emulated bluetooth switch");
7349 module_param(dbg_wwanemul
, uint
, 0);
7350 MODULE_PARM_DESC(dbg_wwanemul
, "Enables WWAN switch emulation");
7351 module_param_named(wwan_state
, tpacpi_wwan_emulstate
, bool, 0);
7352 MODULE_PARM_DESC(wwan_state
,
7353 "Initial state of the emulated WWAN switch");
7355 module_param(dbg_uwbemul
, uint
, 0);
7356 MODULE_PARM_DESC(dbg_uwbemul
, "Enables UWB switch emulation");
7357 module_param_named(uwb_state
, tpacpi_uwb_emulstate
, bool, 0);
7358 MODULE_PARM_DESC(uwb_state
,
7359 "Initial state of the emulated UWB switch");
7362 static void thinkpad_acpi_module_exit(void)
7364 struct ibm_struct
*ibm
, *itmp
;
7366 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
7368 list_for_each_entry_safe_reverse(ibm
, itmp
,
7369 &tpacpi_all_drivers
,
7374 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
7376 if (tpacpi_inputdev
) {
7377 if (tp_features
.input_device_registered
)
7378 input_unregister_device(tpacpi_inputdev
);
7380 input_free_device(tpacpi_inputdev
);
7384 hwmon_device_unregister(tpacpi_hwmon
);
7386 if (tp_features
.sensors_pdev_attrs_registered
)
7387 device_remove_file(&tpacpi_sensors_pdev
->dev
,
7388 &dev_attr_thinkpad_acpi_pdev_name
);
7389 if (tpacpi_sensors_pdev
)
7390 platform_device_unregister(tpacpi_sensors_pdev
);
7392 platform_device_unregister(tpacpi_pdev
);
7394 if (tp_features
.sensors_pdrv_attrs_registered
)
7395 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
7396 if (tp_features
.platform_drv_attrs_registered
)
7397 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
7399 if (tp_features
.sensors_pdrv_registered
)
7400 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
7402 if (tp_features
.platform_drv_registered
)
7403 platform_driver_unregister(&tpacpi_pdriver
);
7406 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
7409 destroy_workqueue(tpacpi_wq
);
7411 kfree(thinkpad_id
.bios_version_str
);
7412 kfree(thinkpad_id
.ec_version_str
);
7413 kfree(thinkpad_id
.model_str
);
7417 static int __init
thinkpad_acpi_module_init(void)
7421 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
7423 /* Parameter checking */
7424 if (hotkey_report_mode
> 2)
7427 /* Driver-level probe */
7429 ret
= get_thinkpad_model_data(&thinkpad_id
);
7432 "unable to get DMI data: %d\n", ret
);
7433 thinkpad_acpi_module_exit();
7436 ret
= probe_for_thinkpad();
7438 thinkpad_acpi_module_exit();
7442 /* Driver initialization */
7444 TPACPI_ACPIHANDLE_INIT(ecrd
);
7445 TPACPI_ACPIHANDLE_INIT(ecwr
);
7447 tpacpi_wq
= create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME
);
7449 thinkpad_acpi_module_exit();
7453 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
7456 "unable to create proc dir " TPACPI_PROC_DIR
);
7457 thinkpad_acpi_module_exit();
7460 proc_dir
->owner
= THIS_MODULE
;
7462 ret
= platform_driver_register(&tpacpi_pdriver
);
7465 "unable to register main platform driver\n");
7466 thinkpad_acpi_module_exit();
7469 tp_features
.platform_drv_registered
= 1;
7471 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
7474 "unable to register hwmon platform driver\n");
7475 thinkpad_acpi_module_exit();
7478 tp_features
.sensors_pdrv_registered
= 1;
7480 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
7482 tp_features
.platform_drv_attrs_registered
= 1;
7483 ret
= tpacpi_create_driver_attributes(
7484 &tpacpi_hwmon_pdriver
.driver
);
7488 "unable to create sysfs driver attributes\n");
7489 thinkpad_acpi_module_exit();
7492 tp_features
.sensors_pdrv_attrs_registered
= 1;
7495 /* Device initialization */
7496 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
7498 if (IS_ERR(tpacpi_pdev
)) {
7499 ret
= PTR_ERR(tpacpi_pdev
);
7501 printk(TPACPI_ERR
"unable to register platform device\n");
7502 thinkpad_acpi_module_exit();
7505 tpacpi_sensors_pdev
= platform_device_register_simple(
7506 TPACPI_HWMON_DRVR_NAME
,
7508 if (IS_ERR(tpacpi_sensors_pdev
)) {
7509 ret
= PTR_ERR(tpacpi_sensors_pdev
);
7510 tpacpi_sensors_pdev
= NULL
;
7512 "unable to register hwmon platform device\n");
7513 thinkpad_acpi_module_exit();
7516 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
7517 &dev_attr_thinkpad_acpi_pdev_name
);
7520 "unable to create sysfs hwmon device attributes\n");
7521 thinkpad_acpi_module_exit();
7524 tp_features
.sensors_pdev_attrs_registered
= 1;
7525 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
7526 if (IS_ERR(tpacpi_hwmon
)) {
7527 ret
= PTR_ERR(tpacpi_hwmon
);
7528 tpacpi_hwmon
= NULL
;
7529 printk(TPACPI_ERR
"unable to register hwmon device\n");
7530 thinkpad_acpi_module_exit();
7533 mutex_init(&tpacpi_inputdev_send_mutex
);
7534 tpacpi_inputdev
= input_allocate_device();
7535 if (!tpacpi_inputdev
) {
7536 printk(TPACPI_ERR
"unable to allocate input device\n");
7537 thinkpad_acpi_module_exit();
7540 /* Prepare input device, but don't register */
7541 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
7542 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
7543 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
7544 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
7545 thinkpad_id
.vendor
:
7547 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
7548 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
7550 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
7551 ret
= ibm_init(&ibms_init
[i
]);
7552 if (ret
>= 0 && *ibms_init
[i
].param
)
7553 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
7555 thinkpad_acpi_module_exit();
7559 ret
= input_register_device(tpacpi_inputdev
);
7561 printk(TPACPI_ERR
"unable to register input device\n");
7562 thinkpad_acpi_module_exit();
7565 tp_features
.input_device_registered
= 1;
7568 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
7572 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME
);
7575 * DMI matching for module autoloading
7577 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
7578 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
7580 * Only models listed in thinkwiki will be supported, so add yours
7581 * if it is not there yet.
7583 #define IBM_BIOS_MODULE_ALIAS(__type) \
7584 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*")
7586 /* Non-ancient thinkpads */
7587 MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*");
7588 MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*");
7590 /* Ancient thinkpad BIOSes have to be identified by
7591 * BIOS type or model number, and there are far less
7592 * BIOS types than model numbers... */
7593 IBM_BIOS_MODULE_ALIAS("I[BDHIMNOTWVYZ]");
7594 IBM_BIOS_MODULE_ALIAS("1[0368A-GIKM-PST]");
7595 IBM_BIOS_MODULE_ALIAS("K[UX-Z]");
7597 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
7598 MODULE_DESCRIPTION(TPACPI_DESC
);
7599 MODULE_VERSION(TPACPI_VERSION
);
7600 MODULE_LICENSE("GPL");
7602 module_init(thinkpad_acpi_module_init
);
7603 module_exit(thinkpad_acpi_module_exit
);