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 0x020200
29 * 2007-10-20 changelog trimmed down
31 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
34 * 2006-11-22 0.13 new maintainer
35 * changelog now lives in git commit history, and will
36 * not be updated further in-file.
38 * 2005-03-17 0.11 support for 600e, 770x
39 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
41 * 2005-01-16 0.9 use MODULE_VERSION
42 * thanks to Henrik Brix Andersen <brix@gentoo.org>
43 * fix parameter passing on module loading
44 * thanks to Rusty Russell <rusty@rustcorp.com.au>
45 * thanks to Jim Radford <radford@blackbean.org>
46 * 2004-11-08 0.8 fix init error case, don't return from a macro
47 * thanks to Chris Wright <chrisw@osdl.org>
50 #include <linux/kernel.h>
51 #include <linux/module.h>
52 #include <linux/init.h>
53 #include <linux/types.h>
54 #include <linux/string.h>
55 #include <linux/list.h>
56 #include <linux/mutex.h>
57 #include <linux/kthread.h>
58 #include <linux/freezer.h>
59 #include <linux/delay.h>
61 #include <linux/nvram.h>
62 #include <linux/proc_fs.h>
63 #include <linux/sysfs.h>
64 #include <linux/backlight.h>
66 #include <linux/platform_device.h>
67 #include <linux/hwmon.h>
68 #include <linux/hwmon-sysfs.h>
69 #include <linux/input.h>
70 #include <linux/leds.h>
71 #include <linux/rfkill.h>
72 #include <asm/uaccess.h>
74 #include <linux/dmi.h>
75 #include <linux/jiffies.h>
76 #include <linux/workqueue.h>
78 #include <acpi/acpi_drivers.h>
80 #include <linux/pci_ids.h>
83 /* ThinkPad CMOS commands */
84 #define TP_CMOS_VOLUME_DOWN 0
85 #define TP_CMOS_VOLUME_UP 1
86 #define TP_CMOS_VOLUME_MUTE 2
87 #define TP_CMOS_BRIGHTNESS_UP 4
88 #define TP_CMOS_BRIGHTNESS_DOWN 5
89 #define TP_CMOS_THINKLIGHT_ON 12
90 #define TP_CMOS_THINKLIGHT_OFF 13
94 TP_NVRAM_ADDR_HK2
= 0x57,
95 TP_NVRAM_ADDR_THINKLIGHT
= 0x58,
96 TP_NVRAM_ADDR_VIDEO
= 0x59,
97 TP_NVRAM_ADDR_BRIGHTNESS
= 0x5e,
98 TP_NVRAM_ADDR_MIXER
= 0x60,
101 /* NVRAM bit masks */
103 TP_NVRAM_MASK_HKT_THINKPAD
= 0x08,
104 TP_NVRAM_MASK_HKT_ZOOM
= 0x20,
105 TP_NVRAM_MASK_HKT_DISPLAY
= 0x40,
106 TP_NVRAM_MASK_HKT_HIBERNATE
= 0x80,
107 TP_NVRAM_MASK_THINKLIGHT
= 0x10,
108 TP_NVRAM_MASK_HKT_DISPEXPND
= 0x30,
109 TP_NVRAM_MASK_HKT_BRIGHTNESS
= 0x20,
110 TP_NVRAM_MASK_LEVEL_BRIGHTNESS
= 0x0f,
111 TP_NVRAM_POS_LEVEL_BRIGHTNESS
= 0,
112 TP_NVRAM_MASK_MUTE
= 0x40,
113 TP_NVRAM_MASK_HKT_VOLUME
= 0x80,
114 TP_NVRAM_MASK_LEVEL_VOLUME
= 0x0f,
115 TP_NVRAM_POS_LEVEL_VOLUME
= 0,
119 #define TPACPI_ACPI_HKEY_HID "IBM0068"
122 #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */
123 #define TPACPI_HKEY_INPUT_VERSION 0x4101
125 /* ACPI \WGSV commands */
127 TP_ACPI_WGSV_GET_STATE
= 0x01, /* Get state information */
128 TP_ACPI_WGSV_PWR_ON_ON_RESUME
= 0x02, /* Resume WWAN powered on */
129 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
= 0x03, /* Resume WWAN powered off */
130 TP_ACPI_WGSV_SAVE_STATE
= 0x04, /* Save state for S4/S5 */
133 /* TP_ACPI_WGSV_GET_STATE bits */
135 TP_ACPI_WGSV_STATE_WWANEXIST
= 0x0001, /* WWAN hw available */
136 TP_ACPI_WGSV_STATE_WWANPWR
= 0x0002, /* WWAN radio enabled */
137 TP_ACPI_WGSV_STATE_WWANPWRRES
= 0x0004, /* WWAN state at resume */
138 TP_ACPI_WGSV_STATE_WWANBIOSOFF
= 0x0008, /* WWAN disabled in BIOS */
139 TP_ACPI_WGSV_STATE_BLTHEXIST
= 0x0001, /* BLTH hw available */
140 TP_ACPI_WGSV_STATE_BLTHPWR
= 0x0002, /* BLTH radio enabled */
141 TP_ACPI_WGSV_STATE_BLTHPWRRES
= 0x0004, /* BLTH state at resume */
142 TP_ACPI_WGSV_STATE_BLTHBIOSOFF
= 0x0008, /* BLTH disabled in BIOS */
143 TP_ACPI_WGSV_STATE_UWBEXIST
= 0x0010, /* UWB hw available */
144 TP_ACPI_WGSV_STATE_UWBPWR
= 0x0020, /* UWB radio enabled */
147 /****************************************************************************
151 #define TPACPI_NAME "thinkpad"
152 #define TPACPI_DESC "ThinkPad ACPI Extras"
153 #define TPACPI_FILE TPACPI_NAME "_acpi"
154 #define TPACPI_URL "http://ibm-acpi.sf.net/"
155 #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net"
157 #define TPACPI_PROC_DIR "ibm"
158 #define TPACPI_ACPI_EVENT_PREFIX "ibm"
159 #define TPACPI_DRVR_NAME TPACPI_FILE
160 #define TPACPI_DRVR_SHORTNAME "tpacpi"
161 #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon"
163 #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd"
164 #define TPACPI_WORKQUEUE_NAME "ktpacpid"
166 #define TPACPI_MAX_ACPI_ARGS 3
168 /* rfkill switches */
170 TPACPI_RFK_BLUETOOTH_SW_ID
= 0,
171 TPACPI_RFK_WWAN_SW_ID
,
172 TPACPI_RFK_UWB_SW_ID
,
176 #define TPACPI_LOG TPACPI_FILE ": "
177 #define TPACPI_ALERT KERN_ALERT TPACPI_LOG
178 #define TPACPI_CRIT KERN_CRIT TPACPI_LOG
179 #define TPACPI_ERR KERN_ERR TPACPI_LOG
180 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
181 #define TPACPI_INFO KERN_INFO TPACPI_LOG
182 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
184 #define TPACPI_DBG_ALL 0xffff
185 #define TPACPI_DBG_INIT 0x0001
186 #define TPACPI_DBG_EXIT 0x0002
188 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
189 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
190 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
193 /****************************************************************************
194 * Driver-wide structs and misc. variables
199 struct tp_acpi_drv_struct
{
200 const struct acpi_device_id
*hid
;
201 struct acpi_driver
*driver
;
203 void (*notify
) (struct ibm_struct
*, u32
);
206 struct acpi_device
*device
;
212 int (*read
) (char *);
213 int (*write
) (char *);
215 void (*resume
) (void);
216 void (*suspend
) (pm_message_t state
);
217 void (*shutdown
) (void);
219 struct list_head all_drivers
;
221 struct tp_acpi_drv_struct
*acpi
;
224 u8 acpi_driver_registered
:1;
225 u8 acpi_notify_installed
:1;
232 struct ibm_init_struct
{
235 int (*init
) (struct ibm_init_struct
*);
236 struct ibm_struct
*data
;
240 #ifdef CONFIG_THINKPAD_ACPI_BAY
253 u32 bright_16levels
:1;
254 u32 bright_acpimode
:1;
257 u32 fan_ctrl_status_undef
:1;
258 u32 input_device_registered
:1;
259 u32 platform_drv_registered
:1;
260 u32 platform_drv_attrs_registered
:1;
261 u32 sensors_pdrv_registered
:1;
262 u32 sensors_pdrv_attrs_registered
:1;
263 u32 sensors_pdev_attrs_registered
:1;
264 u32 hotkey_poll_active
:1;
268 u16 hotkey_mask_ff
:1;
269 u16 bright_cmos_ec_unsync
:1;
272 struct thinkpad_id_data
{
273 unsigned int vendor
; /* ThinkPad vendor:
274 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
276 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
277 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
279 u16 bios_model
; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */
282 char *model_str
; /* ThinkPad T43 */
283 char *nummodel_str
; /* 9384A9C for a 9384-A9C model */
285 static struct thinkpad_id_data thinkpad_id
;
288 TPACPI_LIFE_INIT
= 0,
293 static int experimental
;
294 static u32 dbg_level
;
296 static struct workqueue_struct
*tpacpi_wq
;
304 /* Special LED class that can defer work */
305 struct tpacpi_led_classdev
{
306 struct led_classdev led_classdev
;
307 struct work_struct work
;
308 enum led_status_t new_state
;
312 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
313 static int dbg_wlswemul
;
314 static int tpacpi_wlsw_emulstate
;
315 static int dbg_bluetoothemul
;
316 static int tpacpi_bluetooth_emulstate
;
317 static int dbg_wwanemul
;
318 static int tpacpi_wwan_emulstate
;
319 static int dbg_uwbemul
;
320 static int tpacpi_uwb_emulstate
;
324 /*************************************************************************
328 #define dbg_printk(a_dbg_level, format, arg...) \
329 do { if (dbg_level & (a_dbg_level)) \
330 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
333 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
334 #define vdbg_printk dbg_printk
335 static const char *str_supported(int is_supported
);
337 #define vdbg_printk(a_dbg_level, format, arg...) \
342 /****************************************************************************
343 ****************************************************************************
345 * ACPI Helpers and device model
347 ****************************************************************************
348 ****************************************************************************/
350 /*************************************************************************
354 static acpi_handle root_handle
;
356 #define TPACPI_HANDLE(object, parent, paths...) \
357 static acpi_handle object##_handle; \
358 static acpi_handle *object##_parent = &parent##_handle; \
359 static char *object##_path; \
360 static char *object##_paths[] = { paths }
362 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
363 "\\_SB.PCI.ISA.EC", /* 570 */
364 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
365 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
366 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
367 "\\_SB.PCI0.ICH3.EC0", /* R31 */
368 "\\_SB.PCI0.LPC.EC", /* all others */
371 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
372 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
374 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
376 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
377 "\\CMS", /* R40, R40e */
380 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
381 "^HKEY", /* R30, R31 */
382 "HKEY", /* all others */
385 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
386 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
387 "\\_SB.PCI0.VID0", /* 770e */
388 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
389 "\\_SB.PCI0.AGP.VID", /* all others */
393 /*************************************************************************
397 static int acpi_evalf(acpi_handle handle
,
398 void *res
, char *method
, char *fmt
, ...)
401 struct acpi_object_list params
;
402 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
403 struct acpi_buffer result
, *resultp
;
404 union acpi_object out_obj
;
412 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
425 params
.pointer
= &in_objs
[0];
432 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
433 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
435 /* add more types as needed */
437 printk(TPACPI_ERR
"acpi_evalf() called "
438 "with invalid format character '%c'\n", c
);
444 if (res_type
!= 'v') {
445 result
.length
= sizeof(out_obj
);
446 result
.pointer
= &out_obj
;
451 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
456 *(int *)res
= out_obj
.integer
.value
;
457 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
460 success
= status
== AE_OK
;
462 /* add more types as needed */
464 printk(TPACPI_ERR
"acpi_evalf() called "
465 "with invalid format character '%c'\n", res_type
);
469 if (!success
&& !quiet
)
470 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
471 method
, fmt0
, status
);
476 static int acpi_ec_read(int i
, u8
*p
)
481 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
485 if (ec_read(i
, p
) < 0)
492 static int acpi_ec_write(int i
, u8 v
)
495 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
498 if (ec_write(i
, v
) < 0)
505 #if defined(CONFIG_THINKPAD_ACPI_DOCK) || defined(CONFIG_THINKPAD_ACPI_BAY)
506 static int _sta(acpi_handle handle
)
510 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
517 static int issue_thinkpad_cmos_command(int cmos_cmd
)
522 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
528 /*************************************************************************
532 #define TPACPI_ACPIHANDLE_INIT(object) \
533 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
534 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
536 static void drv_acpi_handle_init(char *name
,
537 acpi_handle
*handle
, acpi_handle parent
,
538 char **paths
, int num_paths
, char **path
)
543 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
546 for (i
= 0; i
< num_paths
; i
++) {
547 status
= acpi_get_handle(parent
, paths
[i
], handle
);
548 if (ACPI_SUCCESS(status
)) {
550 dbg_printk(TPACPI_DBG_INIT
,
551 "Found ACPI handle %s for %s\n",
557 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
562 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
564 struct ibm_struct
*ibm
= data
;
566 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
569 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
572 ibm
->acpi
->notify(ibm
, event
);
575 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
582 if (!*ibm
->acpi
->handle
)
585 vdbg_printk(TPACPI_DBG_INIT
,
586 "setting up ACPI notify for %s\n", ibm
->name
);
588 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
590 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
595 ibm
->acpi
->device
->driver_data
= ibm
;
596 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
597 TPACPI_ACPI_EVENT_PREFIX
,
600 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
601 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
602 if (ACPI_FAILURE(status
)) {
603 if (status
== AE_ALREADY_EXISTS
) {
605 "another device driver is already "
606 "handling %s events\n", ibm
->name
);
609 "acpi_install_notify_handler(%s) failed: %d\n",
614 ibm
->flags
.acpi_notify_installed
= 1;
618 static int __init
tpacpi_device_add(struct acpi_device
*device
)
623 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
627 dbg_printk(TPACPI_DBG_INIT
,
628 "registering %s as an ACPI driver\n", ibm
->name
);
632 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
633 if (!ibm
->acpi
->driver
) {
635 "failed to allocate memory for ibm->acpi->driver\n");
639 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
640 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
642 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
644 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
646 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
648 kfree(ibm
->acpi
->driver
);
649 ibm
->acpi
->driver
= NULL
;
651 ibm
->flags
.acpi_driver_registered
= 1;
657 /****************************************************************************
658 ****************************************************************************
662 ****************************************************************************
663 ****************************************************************************/
665 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
666 int count
, int *eof
, void *data
)
668 struct ibm_struct
*ibm
= data
;
671 if (!ibm
|| !ibm
->read
)
674 len
= ibm
->read(page
);
678 if (len
<= off
+ count
)
690 static int dispatch_procfs_write(struct file
*file
,
691 const char __user
*userbuf
,
692 unsigned long count
, void *data
)
694 struct ibm_struct
*ibm
= data
;
698 if (!ibm
|| !ibm
->write
)
701 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
705 if (copy_from_user(kernbuf
, userbuf
, count
)) {
711 strcat(kernbuf
, ",");
712 ret
= ibm
->write(kernbuf
);
721 static char *next_cmd(char **cmds
)
726 while ((end
= strchr(start
, ',')) && end
== start
)
738 /****************************************************************************
739 ****************************************************************************
741 * Device model: input, hwmon and platform
743 ****************************************************************************
744 ****************************************************************************/
746 static struct platform_device
*tpacpi_pdev
;
747 static struct platform_device
*tpacpi_sensors_pdev
;
748 static struct device
*tpacpi_hwmon
;
749 static struct input_dev
*tpacpi_inputdev
;
750 static struct mutex tpacpi_inputdev_send_mutex
;
751 static LIST_HEAD(tpacpi_all_drivers
);
753 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
756 struct ibm_struct
*ibm
, *itmp
;
758 list_for_each_entry_safe(ibm
, itmp
,
762 (ibm
->suspend
)(state
);
768 static int tpacpi_resume_handler(struct platform_device
*pdev
)
770 struct ibm_struct
*ibm
, *itmp
;
772 list_for_each_entry_safe(ibm
, itmp
,
782 static void tpacpi_shutdown_handler(struct platform_device
*pdev
)
784 struct ibm_struct
*ibm
, *itmp
;
786 list_for_each_entry_safe(ibm
, itmp
,
794 static struct platform_driver tpacpi_pdriver
= {
796 .name
= TPACPI_DRVR_NAME
,
797 .owner
= THIS_MODULE
,
799 .suspend
= tpacpi_suspend_handler
,
800 .resume
= tpacpi_resume_handler
,
801 .shutdown
= tpacpi_shutdown_handler
,
804 static struct platform_driver tpacpi_hwmon_pdriver
= {
806 .name
= TPACPI_HWMON_DRVR_NAME
,
807 .owner
= THIS_MODULE
,
811 /*************************************************************************
812 * sysfs support helpers
815 struct attribute_set
{
816 unsigned int members
, max_members
;
817 struct attribute_group group
;
820 struct attribute_set_obj
{
821 struct attribute_set s
;
823 } __attribute__((packed
));
825 static struct attribute_set
*create_attr_set(unsigned int max_members
,
828 struct attribute_set_obj
*sobj
;
830 if (max_members
== 0)
833 /* Allocates space for implicit NULL at the end too */
834 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
835 max_members
* sizeof(struct attribute
*),
839 sobj
->s
.max_members
= max_members
;
840 sobj
->s
.group
.attrs
= &sobj
->a
;
841 sobj
->s
.group
.name
= name
;
846 #define destroy_attr_set(_set) \
849 /* not multi-threaded safe, use it in a single thread per set */
850 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
855 if (s
->members
>= s
->max_members
)
858 s
->group
.attrs
[s
->members
] = attr
;
864 static int add_many_to_attr_set(struct attribute_set
*s
,
865 struct attribute
**attr
,
870 for (i
= 0; i
< count
; i
++) {
871 res
= add_to_attr_set(s
, attr
[i
]);
879 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
881 sysfs_remove_group(kobj
, &s
->group
);
885 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
886 sysfs_create_group(_kobj, &_attr_set->group)
888 static int parse_strtoul(const char *buf
,
889 unsigned long max
, unsigned long *value
)
893 while (*buf
&& isspace(*buf
))
895 *value
= simple_strtoul(buf
, &endp
, 0);
896 while (*endp
&& isspace(*endp
))
898 if (*endp
|| *value
> max
)
904 static void tpacpi_disable_brightness_delay(void)
906 if (acpi_evalf(hkey_handle
, NULL
, "PWMS", "qvd", 0))
908 "ACPI backlight control delay disabled\n");
911 static int __init
tpacpi_query_bcl_levels(acpi_handle handle
)
913 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
914 union acpi_object
*obj
;
917 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
918 obj
= (union acpi_object
*)buffer
.pointer
;
919 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
920 printk(TPACPI_ERR
"Unknown _BCL data, "
921 "please report this to %s\n", TPACPI_MAIL
);
924 rc
= obj
->package
.count
;
930 kfree(buffer
.pointer
);
934 static acpi_status __init
tpacpi_acpi_walk_find_bcl(acpi_handle handle
,
935 u32 lvl
, void *context
, void **rv
)
937 char name
[ACPI_PATH_SEGMENT_LENGTH
];
938 struct acpi_buffer buffer
= { sizeof(name
), &name
};
940 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
941 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
943 **(int **)rv
= tpacpi_query_bcl_levels(handle
);
944 return AE_CTRL_TERMINATE
;
951 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
953 static int __init
tpacpi_check_std_acpi_brightness_support(void)
957 void *bcl_ptr
= &bcl_levels
;
960 TPACPI_ACPIHANDLE_INIT(vid
);
966 * Search for a _BCL method, and execute it. This is safe on all
967 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
968 * BIOS in ACPI backlight control mode. We do NOT have to care
969 * about calling the _BCL method in an enabled video device, any
970 * will do for our purposes.
973 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
974 tpacpi_acpi_walk_find_bcl
, NULL
,
977 if (ACPI_SUCCESS(status
) && bcl_levels
> 2) {
978 tp_features
.bright_acpimode
= 1;
979 return (bcl_levels
- 2);
985 static int __init
tpacpi_new_rfkill(const unsigned int id
,
987 const enum rfkill_type rfktype
,
989 const bool set_default
,
990 int (*toggle_radio
)(void *, enum rfkill_state
),
991 int (*get_state
)(void *, enum rfkill_state
*))
994 enum rfkill_state initial_state
= RFKILL_STATE_SOFT_BLOCKED
;
996 res
= get_state(NULL
, &initial_state
);
999 "failed to read initial state for %s, error %d; "
1000 "will turn radio off\n", name
, res
);
1001 } else if (set_default
) {
1002 /* try to set the initial state as the default for the rfkill
1003 * type, since we ask the firmware to preserve it across S5 in
1005 rfkill_set_default(rfktype
,
1006 (initial_state
== RFKILL_STATE_UNBLOCKED
) ?
1007 RFKILL_STATE_UNBLOCKED
:
1008 RFKILL_STATE_SOFT_BLOCKED
);
1011 *rfk
= rfkill_allocate(&tpacpi_pdev
->dev
, rfktype
);
1014 "failed to allocate memory for rfkill class\n");
1018 (*rfk
)->name
= name
;
1019 (*rfk
)->get_state
= get_state
;
1020 (*rfk
)->toggle_radio
= toggle_radio
;
1021 (*rfk
)->state
= initial_state
;
1023 res
= rfkill_register(*rfk
);
1026 "failed to register %s rfkill switch: %d\n",
1036 /*************************************************************************
1037 * thinkpad-acpi driver attributes
1040 /* interface_version --------------------------------------------------- */
1041 static ssize_t
tpacpi_driver_interface_version_show(
1042 struct device_driver
*drv
,
1045 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
1048 static DRIVER_ATTR(interface_version
, S_IRUGO
,
1049 tpacpi_driver_interface_version_show
, NULL
);
1051 /* debug_level --------------------------------------------------------- */
1052 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
1055 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
1058 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
1059 const char *buf
, size_t count
)
1063 if (parse_strtoul(buf
, 0xffff, &t
))
1071 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
1072 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
1074 /* version ------------------------------------------------------------- */
1075 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
1078 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
1079 TPACPI_DESC
, TPACPI_VERSION
);
1082 static DRIVER_ATTR(version
, S_IRUGO
,
1083 tpacpi_driver_version_show
, NULL
);
1085 /* --------------------------------------------------------------------- */
1087 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1089 static void tpacpi_send_radiosw_update(void);
1091 /* wlsw_emulstate ------------------------------------------------------ */
1092 static ssize_t
tpacpi_driver_wlsw_emulstate_show(struct device_driver
*drv
,
1095 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wlsw_emulstate
);
1098 static ssize_t
tpacpi_driver_wlsw_emulstate_store(struct device_driver
*drv
,
1099 const char *buf
, size_t count
)
1103 if (parse_strtoul(buf
, 1, &t
))
1106 if (tpacpi_wlsw_emulstate
!= t
) {
1107 tpacpi_wlsw_emulstate
= !!t
;
1108 tpacpi_send_radiosw_update();
1110 tpacpi_wlsw_emulstate
= !!t
;
1115 static DRIVER_ATTR(wlsw_emulstate
, S_IWUSR
| S_IRUGO
,
1116 tpacpi_driver_wlsw_emulstate_show
,
1117 tpacpi_driver_wlsw_emulstate_store
);
1119 /* bluetooth_emulstate ------------------------------------------------- */
1120 static ssize_t
tpacpi_driver_bluetooth_emulstate_show(
1121 struct device_driver
*drv
,
1124 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_bluetooth_emulstate
);
1127 static ssize_t
tpacpi_driver_bluetooth_emulstate_store(
1128 struct device_driver
*drv
,
1129 const char *buf
, size_t count
)
1133 if (parse_strtoul(buf
, 1, &t
))
1136 tpacpi_bluetooth_emulstate
= !!t
;
1141 static DRIVER_ATTR(bluetooth_emulstate
, S_IWUSR
| S_IRUGO
,
1142 tpacpi_driver_bluetooth_emulstate_show
,
1143 tpacpi_driver_bluetooth_emulstate_store
);
1145 /* wwan_emulstate ------------------------------------------------- */
1146 static ssize_t
tpacpi_driver_wwan_emulstate_show(
1147 struct device_driver
*drv
,
1150 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wwan_emulstate
);
1153 static ssize_t
tpacpi_driver_wwan_emulstate_store(
1154 struct device_driver
*drv
,
1155 const char *buf
, size_t count
)
1159 if (parse_strtoul(buf
, 1, &t
))
1162 tpacpi_wwan_emulstate
= !!t
;
1167 static DRIVER_ATTR(wwan_emulstate
, S_IWUSR
| S_IRUGO
,
1168 tpacpi_driver_wwan_emulstate_show
,
1169 tpacpi_driver_wwan_emulstate_store
);
1171 /* uwb_emulstate ------------------------------------------------- */
1172 static ssize_t
tpacpi_driver_uwb_emulstate_show(
1173 struct device_driver
*drv
,
1176 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_uwb_emulstate
);
1179 static ssize_t
tpacpi_driver_uwb_emulstate_store(
1180 struct device_driver
*drv
,
1181 const char *buf
, size_t count
)
1185 if (parse_strtoul(buf
, 1, &t
))
1188 tpacpi_uwb_emulstate
= !!t
;
1193 static DRIVER_ATTR(uwb_emulstate
, S_IWUSR
| S_IRUGO
,
1194 tpacpi_driver_uwb_emulstate_show
,
1195 tpacpi_driver_uwb_emulstate_store
);
1198 /* --------------------------------------------------------------------- */
1200 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
1201 &driver_attr_debug_level
, &driver_attr_version
,
1202 &driver_attr_interface_version
,
1205 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
1211 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
1212 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
1216 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1217 if (!res
&& dbg_wlswemul
)
1218 res
= driver_create_file(drv
, &driver_attr_wlsw_emulstate
);
1219 if (!res
&& dbg_bluetoothemul
)
1220 res
= driver_create_file(drv
, &driver_attr_bluetooth_emulstate
);
1221 if (!res
&& dbg_wwanemul
)
1222 res
= driver_create_file(drv
, &driver_attr_wwan_emulstate
);
1223 if (!res
&& dbg_uwbemul
)
1224 res
= driver_create_file(drv
, &driver_attr_uwb_emulstate
);
1230 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
1234 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
1235 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
1237 #ifdef THINKPAD_ACPI_DEBUGFACILITIES
1238 driver_remove_file(drv
, &driver_attr_wlsw_emulstate
);
1239 driver_remove_file(drv
, &driver_attr_bluetooth_emulstate
);
1240 driver_remove_file(drv
, &driver_attr_wwan_emulstate
);
1241 driver_remove_file(drv
, &driver_attr_uwb_emulstate
);
1245 /****************************************************************************
1246 ****************************************************************************
1250 ****************************************************************************
1251 ****************************************************************************/
1253 /*************************************************************************
1254 * thinkpad-acpi init subdriver
1257 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
1259 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
1260 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
1262 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
1263 (thinkpad_id
.bios_version_str
) ?
1264 thinkpad_id
.bios_version_str
: "unknown",
1265 (thinkpad_id
.ec_version_str
) ?
1266 thinkpad_id
.ec_version_str
: "unknown");
1268 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
1269 printk(TPACPI_INFO
"%s %s, model %s\n",
1270 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
1271 "IBM" : ((thinkpad_id
.vendor
==
1272 PCI_VENDOR_ID_LENOVO
) ?
1273 "Lenovo" : "Unknown vendor"),
1274 thinkpad_id
.model_str
,
1275 (thinkpad_id
.nummodel_str
) ?
1276 thinkpad_id
.nummodel_str
: "unknown");
1281 static int thinkpad_acpi_driver_read(char *p
)
1285 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", TPACPI_DESC
);
1286 len
+= sprintf(p
+ len
, "version:\t%s\n", TPACPI_VERSION
);
1291 static struct ibm_struct thinkpad_acpi_driver_data
= {
1293 .read
= thinkpad_acpi_driver_read
,
1296 /*************************************************************************
1300 enum { /* hot key scan codes (derived from ACPI DSDT) */
1301 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
1302 TP_ACPI_HOTKEYSCAN_FNF2
,
1303 TP_ACPI_HOTKEYSCAN_FNF3
,
1304 TP_ACPI_HOTKEYSCAN_FNF4
,
1305 TP_ACPI_HOTKEYSCAN_FNF5
,
1306 TP_ACPI_HOTKEYSCAN_FNF6
,
1307 TP_ACPI_HOTKEYSCAN_FNF7
,
1308 TP_ACPI_HOTKEYSCAN_FNF8
,
1309 TP_ACPI_HOTKEYSCAN_FNF9
,
1310 TP_ACPI_HOTKEYSCAN_FNF10
,
1311 TP_ACPI_HOTKEYSCAN_FNF11
,
1312 TP_ACPI_HOTKEYSCAN_FNF12
,
1313 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
1314 TP_ACPI_HOTKEYSCAN_FNINSERT
,
1315 TP_ACPI_HOTKEYSCAN_FNDELETE
,
1316 TP_ACPI_HOTKEYSCAN_FNHOME
,
1317 TP_ACPI_HOTKEYSCAN_FNEND
,
1318 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1319 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
1320 TP_ACPI_HOTKEYSCAN_FNSPACE
,
1321 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1322 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1323 TP_ACPI_HOTKEYSCAN_MUTE
,
1324 TP_ACPI_HOTKEYSCAN_THINKPAD
,
1327 enum { /* Keys available through NVRAM polling */
1328 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
1329 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
1332 enum { /* Positions of some of the keys in hotkey masks */
1333 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
1334 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
1335 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
1336 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
1337 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
1338 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1339 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
1340 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1341 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1342 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
1343 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
1346 enum { /* NVRAM to ACPI HKEY group map */
1347 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
1348 TP_ACPI_HKEY_ZOOM_MASK
|
1349 TP_ACPI_HKEY_DISPSWTCH_MASK
|
1350 TP_ACPI_HKEY_HIBERNATE_MASK
,
1351 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
1352 TP_ACPI_HKEY_BRGHTDWN_MASK
,
1353 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
1354 TP_ACPI_HKEY_VOLDWN_MASK
|
1355 TP_ACPI_HKEY_MUTE_MASK
,
1358 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1359 struct tp_nvram_state
{
1360 u16 thinkpad_toggle
:1;
1362 u16 display_toggle
:1;
1363 u16 thinklight_toggle
:1;
1364 u16 hibernate_toggle
:1;
1365 u16 displayexp_toggle
:1;
1366 u16 display_state
:1;
1367 u16 brightness_toggle
:1;
1368 u16 volume_toggle
:1;
1371 u8 brightness_level
;
1375 static struct task_struct
*tpacpi_hotkey_task
;
1376 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
1377 static int hotkey_poll_freq
= 10; /* Hz */
1378 static struct mutex hotkey_thread_mutex
;
1379 static struct mutex hotkey_thread_data_mutex
;
1380 static unsigned int hotkey_config_change
;
1382 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1384 #define hotkey_source_mask 0U
1386 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1388 static struct mutex hotkey_mutex
;
1390 static enum { /* Reasons for waking up */
1391 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
1392 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
1393 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
1394 } hotkey_wakeup_reason
;
1396 static int hotkey_autosleep_ack
;
1398 static int hotkey_orig_status
;
1399 static u32 hotkey_orig_mask
;
1400 static u32 hotkey_all_mask
;
1401 static u32 hotkey_reserved_mask
;
1402 static u32 hotkey_mask
;
1404 static unsigned int hotkey_report_mode
;
1406 static u16
*hotkey_keycode_map
;
1408 static struct attribute_set
*hotkey_dev_attributes
;
1410 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1411 #define HOTKEY_CONFIG_CRITICAL_START \
1413 mutex_lock(&hotkey_thread_data_mutex); \
1414 hotkey_config_change++; \
1416 #define HOTKEY_CONFIG_CRITICAL_END \
1417 mutex_unlock(&hotkey_thread_data_mutex);
1419 #define HOTKEY_CONFIG_CRITICAL_START
1420 #define HOTKEY_CONFIG_CRITICAL_END
1421 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1423 /* HKEY.MHKG() return bits */
1424 #define TP_HOTKEY_TABLET_MASK (1 << 3)
1426 static int hotkey_get_wlsw(int *status
)
1428 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1430 *status
= !!tpacpi_wlsw_emulstate
;
1434 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
1439 static int hotkey_get_tablet_mode(int *status
)
1443 if (!acpi_evalf(hkey_handle
, &s
, "MHKG", "d"))
1446 *status
= ((s
& TP_HOTKEY_TABLET_MASK
) != 0);
1451 * Call with hotkey_mutex held
1453 static int hotkey_mask_get(void)
1457 if (tp_features
.hotkey_mask
) {
1458 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
1461 hotkey_mask
= m
| (hotkey_source_mask
& hotkey_mask
);
1467 * Call with hotkey_mutex held
1469 static int hotkey_mask_set(u32 mask
)
1474 if (tp_features
.hotkey_mask
) {
1475 if (!tp_warned
.hotkey_mask_ff
&&
1476 (mask
== 0xffff || mask
== 0xffffff ||
1477 mask
== 0xffffffff)) {
1478 tp_warned
.hotkey_mask_ff
= 1;
1479 printk(TPACPI_NOTICE
1480 "setting the hotkey mask to 0x%08x is likely "
1481 "not the best way to go about it\n", mask
);
1482 printk(TPACPI_NOTICE
1483 "please consider using the driver defaults, "
1484 "and refer to up-to-date thinkpad-acpi "
1488 HOTKEY_CONFIG_CRITICAL_START
1489 for (i
= 0; i
< 32; i
++) {
1491 /* enable in firmware mask only keys not in NVRAM
1492 * mode, but enable the key in the cached hotkey_mask
1493 * regardless of mode, or the key will end up
1494 * disabled by hotkey_mask_get() */
1495 if (!acpi_evalf(hkey_handle
,
1496 NULL
, "MHKM", "vdd", i
+ 1,
1497 !!((mask
& ~hotkey_source_mask
) & m
))) {
1501 hotkey_mask
= (hotkey_mask
& ~m
) | (mask
& m
);
1504 HOTKEY_CONFIG_CRITICAL_END
1506 /* hotkey_mask_get must be called unconditionally below */
1507 if (!hotkey_mask_get() && !rc
&&
1508 (hotkey_mask
& ~hotkey_source_mask
) !=
1509 (mask
& ~hotkey_source_mask
)) {
1510 printk(TPACPI_NOTICE
1511 "requested hot key mask 0x%08x, but "
1512 "firmware forced it to 0x%08x\n",
1516 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1517 HOTKEY_CONFIG_CRITICAL_START
1518 hotkey_mask
= mask
& hotkey_source_mask
;
1519 HOTKEY_CONFIG_CRITICAL_END
1521 if (hotkey_mask
!= mask
) {
1522 printk(TPACPI_NOTICE
1523 "requested hot key mask 0x%08x, "
1524 "forced to 0x%08x (NVRAM poll mask is "
1525 "0x%08x): no firmware mask support\n",
1526 mask
, hotkey_mask
, hotkey_source_mask
);
1531 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1537 static int hotkey_status_get(int *status
)
1539 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1545 static int hotkey_status_set(int status
)
1547 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
1553 static void tpacpi_input_send_tabletsw(void)
1557 if (tp_features
.hotkey_tablet
&&
1558 !hotkey_get_tablet_mode(&state
)) {
1559 mutex_lock(&tpacpi_inputdev_send_mutex
);
1561 input_report_switch(tpacpi_inputdev
,
1562 SW_TABLET_MODE
, !!state
);
1563 input_sync(tpacpi_inputdev
);
1565 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1569 static void tpacpi_input_send_key(unsigned int scancode
)
1571 unsigned int keycode
;
1573 keycode
= hotkey_keycode_map
[scancode
];
1575 if (keycode
!= KEY_RESERVED
) {
1576 mutex_lock(&tpacpi_inputdev_send_mutex
);
1578 input_report_key(tpacpi_inputdev
, keycode
, 1);
1579 if (keycode
== KEY_UNKNOWN
)
1580 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1582 input_sync(tpacpi_inputdev
);
1584 input_report_key(tpacpi_inputdev
, keycode
, 0);
1585 if (keycode
== KEY_UNKNOWN
)
1586 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1588 input_sync(tpacpi_inputdev
);
1590 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1594 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1595 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
1597 static void tpacpi_hotkey_send_key(unsigned int scancode
)
1599 tpacpi_input_send_key(scancode
);
1600 if (hotkey_report_mode
< 2) {
1601 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
1602 0x80, 0x1001 + scancode
);
1606 static void hotkey_read_nvram(struct tp_nvram_state
*n
, u32 m
)
1610 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
1611 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
1612 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
1613 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
1614 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
1615 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
1617 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
1618 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
1619 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
1621 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
1622 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
1623 n
->displayexp_toggle
=
1624 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
1626 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
1627 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
1628 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
1629 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
1630 n
->brightness_toggle
=
1631 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
1633 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
1634 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
1635 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
1636 >> TP_NVRAM_POS_LEVEL_VOLUME
;
1637 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
1638 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
1642 #define TPACPI_COMPARE_KEY(__scancode, __member) \
1644 if ((mask & (1 << __scancode)) && \
1645 oldn->__member != newn->__member) \
1646 tpacpi_hotkey_send_key(__scancode); \
1649 #define TPACPI_MAY_SEND_KEY(__scancode) \
1650 do { if (mask & (1 << __scancode)) \
1651 tpacpi_hotkey_send_key(__scancode); } while (0)
1653 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
1654 struct tp_nvram_state
*newn
,
1657 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
1658 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
1659 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
1660 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
1662 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
1664 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
1667 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
1668 if (oldn
->mute
!= newn
->mute
) {
1669 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1671 if (oldn
->volume_level
> newn
->volume_level
) {
1672 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1673 } else if (oldn
->volume_level
< newn
->volume_level
) {
1674 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1675 } else if (oldn
->mute
== newn
->mute
) {
1676 /* repeated key presses that didn't change state */
1678 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1679 } else if (newn
->volume_level
!= 0) {
1680 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1682 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1687 /* handle brightness */
1688 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
1689 if (oldn
->brightness_level
< newn
->brightness_level
) {
1690 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1691 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
1692 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1694 /* repeated key presses that didn't change state */
1695 if (newn
->brightness_level
!= 0) {
1696 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1698 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1704 #undef TPACPI_COMPARE_KEY
1705 #undef TPACPI_MAY_SEND_KEY
1707 static int hotkey_kthread(void *data
)
1709 struct tp_nvram_state s
[2];
1711 unsigned int si
, so
;
1713 unsigned int change_detector
, must_reset
;
1715 mutex_lock(&hotkey_thread_mutex
);
1717 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
1726 /* Initial state for compares */
1727 mutex_lock(&hotkey_thread_data_mutex
);
1728 change_detector
= hotkey_config_change
;
1729 mask
= hotkey_source_mask
& hotkey_mask
;
1730 mutex_unlock(&hotkey_thread_data_mutex
);
1731 hotkey_read_nvram(&s
[so
], mask
);
1733 while (!kthread_should_stop() && hotkey_poll_freq
) {
1735 t
= 1000/hotkey_poll_freq
;
1736 t
= msleep_interruptible(t
);
1737 if (unlikely(kthread_should_stop()))
1739 must_reset
= try_to_freeze();
1740 if (t
> 0 && !must_reset
)
1743 mutex_lock(&hotkey_thread_data_mutex
);
1744 if (must_reset
|| hotkey_config_change
!= change_detector
) {
1745 /* forget old state on thaw or config change */
1748 change_detector
= hotkey_config_change
;
1750 mask
= hotkey_source_mask
& hotkey_mask
;
1751 mutex_unlock(&hotkey_thread_data_mutex
);
1754 hotkey_read_nvram(&s
[si
], mask
);
1755 if (likely(si
!= so
)) {
1756 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
1766 mutex_unlock(&hotkey_thread_mutex
);
1770 static void hotkey_poll_stop_sync(void)
1772 if (tpacpi_hotkey_task
) {
1773 if (frozen(tpacpi_hotkey_task
) ||
1774 freezing(tpacpi_hotkey_task
))
1775 thaw_process(tpacpi_hotkey_task
);
1777 kthread_stop(tpacpi_hotkey_task
);
1778 tpacpi_hotkey_task
= NULL
;
1779 mutex_lock(&hotkey_thread_mutex
);
1780 /* at this point, the thread did exit */
1781 mutex_unlock(&hotkey_thread_mutex
);
1785 /* call with hotkey_mutex held */
1786 static void hotkey_poll_setup(int may_warn
)
1788 if ((hotkey_source_mask
& hotkey_mask
) != 0 &&
1789 hotkey_poll_freq
> 0 &&
1790 (tpacpi_inputdev
->users
> 0 || hotkey_report_mode
< 2)) {
1791 if (!tpacpi_hotkey_task
) {
1792 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
1793 NULL
, TPACPI_NVRAM_KTHREAD_NAME
);
1794 if (IS_ERR(tpacpi_hotkey_task
)) {
1795 tpacpi_hotkey_task
= NULL
;
1797 "could not create kernel thread "
1798 "for hotkey polling\n");
1802 hotkey_poll_stop_sync();
1804 hotkey_source_mask
!= 0 && hotkey_poll_freq
== 0) {
1805 printk(TPACPI_NOTICE
1806 "hot keys 0x%08x require polling, "
1807 "which is currently disabled\n",
1808 hotkey_source_mask
);
1813 static void hotkey_poll_setup_safe(int may_warn
)
1815 mutex_lock(&hotkey_mutex
);
1816 hotkey_poll_setup(may_warn
);
1817 mutex_unlock(&hotkey_mutex
);
1820 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1822 static void hotkey_poll_setup_safe(int __unused
)
1826 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1828 static int hotkey_inputdev_open(struct input_dev
*dev
)
1830 switch (tpacpi_lifecycle
) {
1831 case TPACPI_LIFE_INIT
:
1833 * hotkey_init will call hotkey_poll_setup_safe
1834 * at the appropriate moment
1837 case TPACPI_LIFE_EXITING
:
1839 case TPACPI_LIFE_RUNNING
:
1840 hotkey_poll_setup_safe(0);
1844 /* Should only happen if tpacpi_lifecycle is corrupt */
1849 static void hotkey_inputdev_close(struct input_dev
*dev
)
1851 /* disable hotkey polling when possible */
1852 if (tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
)
1853 hotkey_poll_setup_safe(0);
1856 /* sysfs hotkey enable ------------------------------------------------- */
1857 static ssize_t
hotkey_enable_show(struct device
*dev
,
1858 struct device_attribute
*attr
,
1863 res
= hotkey_status_get(&status
);
1867 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
1870 static ssize_t
hotkey_enable_store(struct device
*dev
,
1871 struct device_attribute
*attr
,
1872 const char *buf
, size_t count
)
1877 if (parse_strtoul(buf
, 1, &t
))
1880 res
= hotkey_status_set(t
);
1882 return (res
) ? res
: count
;
1885 static struct device_attribute dev_attr_hotkey_enable
=
1886 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
1887 hotkey_enable_show
, hotkey_enable_store
);
1889 /* sysfs hotkey mask --------------------------------------------------- */
1890 static ssize_t
hotkey_mask_show(struct device
*dev
,
1891 struct device_attribute
*attr
,
1896 if (mutex_lock_killable(&hotkey_mutex
))
1897 return -ERESTARTSYS
;
1898 res
= hotkey_mask_get();
1899 mutex_unlock(&hotkey_mutex
);
1902 res
: snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_mask
);
1905 static ssize_t
hotkey_mask_store(struct device
*dev
,
1906 struct device_attribute
*attr
,
1907 const char *buf
, size_t count
)
1912 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
1915 if (mutex_lock_killable(&hotkey_mutex
))
1916 return -ERESTARTSYS
;
1918 res
= hotkey_mask_set(t
);
1920 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1921 hotkey_poll_setup(1);
1924 mutex_unlock(&hotkey_mutex
);
1926 return (res
) ? res
: count
;
1929 static struct device_attribute dev_attr_hotkey_mask
=
1930 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
1931 hotkey_mask_show
, hotkey_mask_store
);
1933 /* sysfs hotkey bios_enabled ------------------------------------------- */
1934 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
1935 struct device_attribute
*attr
,
1938 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
1941 static struct device_attribute dev_attr_hotkey_bios_enabled
=
1942 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
1944 /* sysfs hotkey bios_mask ---------------------------------------------- */
1945 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
1946 struct device_attribute
*attr
,
1949 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
1952 static struct device_attribute dev_attr_hotkey_bios_mask
=
1953 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
1955 /* sysfs hotkey all_mask ----------------------------------------------- */
1956 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
1957 struct device_attribute
*attr
,
1960 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1961 hotkey_all_mask
| hotkey_source_mask
);
1964 static struct device_attribute dev_attr_hotkey_all_mask
=
1965 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
1967 /* sysfs hotkey recommended_mask --------------------------------------- */
1968 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
1969 struct device_attribute
*attr
,
1972 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1973 (hotkey_all_mask
| hotkey_source_mask
)
1974 & ~hotkey_reserved_mask
);
1977 static struct device_attribute dev_attr_hotkey_recommended_mask
=
1978 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
1979 hotkey_recommended_mask_show
, NULL
);
1981 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1983 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
1984 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
1985 struct device_attribute
*attr
,
1988 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
1991 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
1992 struct device_attribute
*attr
,
1993 const char *buf
, size_t count
)
1997 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
1998 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
2001 if (mutex_lock_killable(&hotkey_mutex
))
2002 return -ERESTARTSYS
;
2004 HOTKEY_CONFIG_CRITICAL_START
2005 hotkey_source_mask
= t
;
2006 HOTKEY_CONFIG_CRITICAL_END
2008 hotkey_poll_setup(1);
2010 mutex_unlock(&hotkey_mutex
);
2015 static struct device_attribute dev_attr_hotkey_source_mask
=
2016 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
2017 hotkey_source_mask_show
, hotkey_source_mask_store
);
2019 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
2020 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
2021 struct device_attribute
*attr
,
2024 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
2027 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
2028 struct device_attribute
*attr
,
2029 const char *buf
, size_t count
)
2033 if (parse_strtoul(buf
, 25, &t
))
2036 if (mutex_lock_killable(&hotkey_mutex
))
2037 return -ERESTARTSYS
;
2039 hotkey_poll_freq
= t
;
2041 hotkey_poll_setup(1);
2042 mutex_unlock(&hotkey_mutex
);
2047 static struct device_attribute dev_attr_hotkey_poll_freq
=
2048 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
2049 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
2051 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2053 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
2054 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
2055 struct device_attribute
*attr
,
2059 res
= hotkey_get_wlsw(&s
);
2063 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2066 static struct device_attribute dev_attr_hotkey_radio_sw
=
2067 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
2069 static void hotkey_radio_sw_notify_change(void)
2071 if (tp_features
.hotkey_wlsw
)
2072 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2076 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
2077 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
2078 struct device_attribute
*attr
,
2082 res
= hotkey_get_tablet_mode(&s
);
2086 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2089 static struct device_attribute dev_attr_hotkey_tablet_mode
=
2090 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
2092 static void hotkey_tablet_mode_notify_change(void)
2094 if (tp_features
.hotkey_tablet
)
2095 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2096 "hotkey_tablet_mode");
2099 /* sysfs hotkey report_mode -------------------------------------------- */
2100 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
2101 struct device_attribute
*attr
,
2104 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2105 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
2108 static struct device_attribute dev_attr_hotkey_report_mode
=
2109 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
2111 /* sysfs wakeup reason (pollable) -------------------------------------- */
2112 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
2113 struct device_attribute
*attr
,
2116 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
2119 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
2120 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
2122 static void hotkey_wakeup_reason_notify_change(void)
2124 if (tp_features
.hotkey_mask
)
2125 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2129 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2130 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
2131 struct device_attribute
*attr
,
2134 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
2137 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
2138 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
2139 hotkey_wakeup_hotunplug_complete_show
, NULL
);
2141 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2143 if (tp_features
.hotkey_mask
)
2144 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2145 "wakeup_hotunplug_complete");
2148 /* --------------------------------------------------------------------- */
2150 static struct attribute
*hotkey_attributes
[] __initdata
= {
2151 &dev_attr_hotkey_enable
.attr
,
2152 &dev_attr_hotkey_bios_enabled
.attr
,
2153 &dev_attr_hotkey_report_mode
.attr
,
2154 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2155 &dev_attr_hotkey_mask
.attr
,
2156 &dev_attr_hotkey_all_mask
.attr
,
2157 &dev_attr_hotkey_recommended_mask
.attr
,
2158 &dev_attr_hotkey_source_mask
.attr
,
2159 &dev_attr_hotkey_poll_freq
.attr
,
2163 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
2164 &dev_attr_hotkey_bios_mask
.attr
,
2165 #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2166 &dev_attr_hotkey_mask
.attr
,
2167 &dev_attr_hotkey_all_mask
.attr
,
2168 &dev_attr_hotkey_recommended_mask
.attr
,
2170 &dev_attr_hotkey_wakeup_reason
.attr
,
2171 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
2174 static void bluetooth_update_rfk(void);
2175 static void wan_update_rfk(void);
2176 static void uwb_update_rfk(void);
2177 static void tpacpi_send_radiosw_update(void)
2181 /* Sync these BEFORE sending any rfkill events */
2182 if (tp_features
.bluetooth
)
2183 bluetooth_update_rfk();
2184 if (tp_features
.wan
)
2186 if (tp_features
.uwb
)
2189 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
2190 mutex_lock(&tpacpi_inputdev_send_mutex
);
2192 input_report_switch(tpacpi_inputdev
,
2193 SW_RFKILL_ALL
, !!wlsw
);
2194 input_sync(tpacpi_inputdev
);
2196 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2198 hotkey_radio_sw_notify_change();
2201 static void hotkey_exit(void)
2203 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2204 hotkey_poll_stop_sync();
2207 if (hotkey_dev_attributes
)
2208 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2210 kfree(hotkey_keycode_map
);
2212 if (tp_features
.hotkey
) {
2213 dbg_printk(TPACPI_DBG_EXIT
,
2214 "restoring original hot key mask\n");
2215 /* no short-circuit boolean operator below! */
2216 if ((hotkey_mask_set(hotkey_orig_mask
) |
2217 hotkey_status_set(hotkey_orig_status
)) != 0)
2219 "failed to restore hot key mask "
2220 "to BIOS defaults\n");
2224 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
2226 /* Requirements for changing the default keymaps:
2228 * 1. Many of the keys are mapped to KEY_RESERVED for very
2229 * good reasons. Do not change them unless you have deep
2230 * knowledge on the IBM and Lenovo ThinkPad firmware for
2231 * the various ThinkPad models. The driver behaves
2232 * differently for KEY_RESERVED: such keys have their
2233 * hot key mask *unset* in mask_recommended, and also
2234 * in the initial hot key mask programmed into the
2235 * firmware at driver load time, which means the firm-
2236 * ware may react very differently if you change them to
2239 * 2. You must be subscribed to the linux-thinkpad and
2240 * ibm-acpi-devel mailing lists, and you should read the
2241 * list archives since 2007 if you want to change the
2242 * keymaps. This requirement exists so that you will
2243 * know the past history of problems with the thinkpad-
2244 * acpi driver keymaps, and also that you will be
2245 * listening to any bug reports;
2247 * 3. Do not send thinkpad-acpi specific patches directly to
2248 * for merging, *ever*. Send them to the linux-acpi
2249 * mailinglist for comments. Merging is to be done only
2250 * through acpi-test and the ACPI maintainer.
2252 * If the above is too much to ask, don't change the keymap.
2253 * Ask the thinkpad-acpi maintainer to do it, instead.
2255 static u16 ibm_keycode_map
[] __initdata
= {
2256 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2257 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
2258 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2259 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2261 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2262 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2263 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2264 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2266 /* brightness: firmware always reacts to them, unless
2267 * X.org did some tricks in the radeon BIOS scratch
2268 * registers of *some* models */
2269 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
2270 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
2272 /* Thinklight: firmware always react to it */
2273 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2275 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2276 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2278 /* Volume: firmware always react to it and reprograms
2279 * the built-in *extra* mixer. Never map it to control
2280 * another mixer by default. */
2281 KEY_RESERVED
, /* 0x14: VOLUME UP */
2282 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2283 KEY_RESERVED
, /* 0x16: MUTE */
2285 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2287 /* (assignments unknown, please report if found) */
2288 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2289 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2291 static u16 lenovo_keycode_map
[] __initdata
= {
2292 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2293 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
2294 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2295 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2297 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2298 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2299 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2300 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2302 /* These either have to go through ACPI video, or
2303 * act like in the IBM ThinkPads, so don't ever
2304 * enable them by default */
2305 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
2306 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
2308 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2310 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2311 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2313 /* Volume: z60/z61, T60 (BIOS version?): firmware always
2314 * react to it and reprograms the built-in *extra* mixer.
2315 * Never map it to control another mixer by default.
2317 * T60?, T61, R60?, R61: firmware and EC tries to send
2318 * these over the regular keyboard, so these are no-ops,
2319 * but there are still weird bugs re. MUTE, so do not
2320 * change unless you get test reports from all Lenovo
2321 * models. May cause the BIOS to interfere with the
2324 KEY_RESERVED
, /* 0x14: VOLUME UP */
2325 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2326 KEY_RESERVED
, /* 0x16: MUTE */
2328 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2330 /* (assignments unknown, please report if found) */
2331 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2332 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2335 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
2336 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
2337 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
2343 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
2345 BUG_ON(!tpacpi_inputdev
);
2346 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
2347 tpacpi_inputdev
->close
!= NULL
);
2349 TPACPI_ACPIHANDLE_INIT(hkey
);
2350 mutex_init(&hotkey_mutex
);
2352 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2353 mutex_init(&hotkey_thread_mutex
);
2354 mutex_init(&hotkey_thread_data_mutex
);
2357 /* hotkey not supported on 570 */
2358 tp_features
.hotkey
= hkey_handle
!= NULL
;
2360 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
2361 str_supported(tp_features
.hotkey
));
2363 if (!tp_features
.hotkey
)
2366 tpacpi_disable_brightness_delay();
2368 hotkey_dev_attributes
= create_attr_set(13, NULL
);
2369 if (!hotkey_dev_attributes
)
2371 res
= add_many_to_attr_set(hotkey_dev_attributes
,
2373 ARRAY_SIZE(hotkey_attributes
));
2377 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2378 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
2379 for HKEY interface version 0x100 */
2380 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
2381 if ((hkeyv
>> 8) != 1) {
2382 printk(TPACPI_ERR
"unknown version of the "
2383 "HKEY interface: 0x%x\n", hkeyv
);
2384 printk(TPACPI_ERR
"please report this to %s\n",
2388 * MHKV 0x100 in A31, R40, R40e,
2389 * T4x, X31, and later
2391 tp_features
.hotkey_mask
= 1;
2395 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
2396 str_supported(tp_features
.hotkey_mask
));
2398 if (tp_features
.hotkey_mask
) {
2399 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
2402 "missing MHKA handler, "
2403 "please report this to %s\n",
2405 /* FN+F12, FN+F4, FN+F3 */
2406 hotkey_all_mask
= 0x080cU
;
2410 /* hotkey_source_mask *must* be zero for
2411 * the first hotkey_mask_get */
2412 res
= hotkey_status_get(&hotkey_orig_status
);
2416 if (tp_features
.hotkey_mask
) {
2417 res
= hotkey_mask_get();
2421 hotkey_orig_mask
= hotkey_mask
;
2422 res
= add_many_to_attr_set(
2423 hotkey_dev_attributes
,
2424 hotkey_mask_attributes
,
2425 ARRAY_SIZE(hotkey_mask_attributes
));
2430 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2431 if (tp_features
.hotkey_mask
) {
2432 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
2435 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
;
2438 vdbg_printk(TPACPI_DBG_INIT
,
2439 "hotkey source mask 0x%08x, polling freq %d\n",
2440 hotkey_source_mask
, hotkey_poll_freq
);
2443 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2445 tp_features
.hotkey_wlsw
= 1;
2447 "radio switch emulation enabled\n");
2450 /* Not all thinkpads have a hardware radio switch */
2451 if (acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
2452 tp_features
.hotkey_wlsw
= 1;
2454 "radio switch found; radios are %s\n",
2455 enabled(status
, 0));
2457 if (tp_features
.hotkey_wlsw
)
2458 res
= add_to_attr_set(hotkey_dev_attributes
,
2459 &dev_attr_hotkey_radio_sw
.attr
);
2461 /* For X41t, X60t, X61t Tablets... */
2462 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
2463 tp_features
.hotkey_tablet
= 1;
2465 "possible tablet mode switch found; "
2466 "ThinkPad in %s mode\n",
2467 (status
& TP_HOTKEY_TABLET_MASK
)?
2468 "tablet" : "laptop");
2469 res
= add_to_attr_set(hotkey_dev_attributes
,
2470 &dev_attr_hotkey_tablet_mode
.attr
);
2474 res
= register_attr_set_with_sysfs(
2475 hotkey_dev_attributes
,
2476 &tpacpi_pdev
->dev
.kobj
);
2480 /* Set up key map */
2482 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
2484 if (!hotkey_keycode_map
) {
2486 "failed to allocate memory for key map\n");
2491 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
2492 dbg_printk(TPACPI_DBG_INIT
,
2493 "using Lenovo default hot key map\n");
2494 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
2495 TPACPI_HOTKEY_MAP_SIZE
);
2497 dbg_printk(TPACPI_DBG_INIT
,
2498 "using IBM default hot key map\n");
2499 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
2500 TPACPI_HOTKEY_MAP_SIZE
);
2503 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
2504 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
2505 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
2506 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
2507 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
2508 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
2509 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
2510 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
2511 set_bit(hotkey_keycode_map
[i
],
2512 tpacpi_inputdev
->keybit
);
2514 if (i
< sizeof(hotkey_reserved_mask
)*8)
2515 hotkey_reserved_mask
|= 1 << i
;
2519 if (tp_features
.hotkey_wlsw
) {
2520 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
2521 set_bit(SW_RFKILL_ALL
, tpacpi_inputdev
->swbit
);
2523 if (tp_features
.hotkey_tablet
) {
2524 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
2525 set_bit(SW_TABLET_MODE
, tpacpi_inputdev
->swbit
);
2528 /* Do not issue duplicate brightness change events to
2530 if (!tp_features
.bright_acpimode
)
2531 /* update bright_acpimode... */
2532 tpacpi_check_std_acpi_brightness_support();
2534 if (tp_features
.bright_acpimode
) {
2536 "This ThinkPad has standard ACPI backlight "
2537 "brightness control, supported by the ACPI "
2539 printk(TPACPI_NOTICE
2540 "Disabling thinkpad-acpi brightness events "
2543 /* The hotkey_reserved_mask change below is not
2544 * necessary while the keys are at KEY_RESERVED in the
2545 * default map, but better safe than sorry, leave it
2546 * here as a marker of what we have to do, especially
2547 * when we finally become able to set this at runtime
2548 * on response to X.org requests */
2549 hotkey_reserved_mask
|=
2550 (1 << TP_ACPI_HOTKEYSCAN_FNHOME
)
2551 | (1 << TP_ACPI_HOTKEYSCAN_FNEND
);
2554 dbg_printk(TPACPI_DBG_INIT
, "enabling hot key handling\n");
2555 res
= hotkey_status_set(1);
2560 res
= hotkey_mask_set(((hotkey_all_mask
| hotkey_source_mask
)
2561 & ~hotkey_reserved_mask
)
2562 | hotkey_orig_mask
);
2563 if (res
< 0 && res
!= -ENXIO
) {
2568 dbg_printk(TPACPI_DBG_INIT
,
2569 "legacy hot key reporting over procfs %s\n",
2570 (hotkey_report_mode
< 2) ?
2571 "enabled" : "disabled");
2573 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
2574 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
2576 hotkey_poll_setup_safe(1);
2577 tpacpi_send_radiosw_update();
2578 tpacpi_input_send_tabletsw();
2583 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2584 hotkey_dev_attributes
= NULL
;
2586 return (res
< 0)? res
: 1;
2589 static bool hotkey_notify_hotkey(const u32 hkey
,
2591 bool *ignore_acpi_ev
)
2593 /* 0x1000-0x1FFF: key presses */
2594 unsigned int scancode
= hkey
& 0xfff;
2595 *send_acpi_ev
= true;
2596 *ignore_acpi_ev
= false;
2598 if (scancode
> 0 && scancode
< 0x21) {
2600 if (!(hotkey_source_mask
& (1 << scancode
))) {
2601 tpacpi_input_send_key(scancode
);
2602 *send_acpi_ev
= false;
2604 *ignore_acpi_ev
= true;
2611 static bool hotkey_notify_wakeup(const u32 hkey
,
2613 bool *ignore_acpi_ev
)
2615 /* 0x2000-0x2FFF: Wakeup reason */
2616 *send_acpi_ev
= true;
2617 *ignore_acpi_ev
= false;
2620 case 0x2304: /* suspend, undock */
2621 case 0x2404: /* hibernation, undock */
2622 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
2623 *ignore_acpi_ev
= true;
2626 case 0x2305: /* suspend, bay eject */
2627 case 0x2405: /* hibernation, bay eject */
2628 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
2629 *ignore_acpi_ev
= true;
2632 case 0x2313: /* Battery on critical low level (S3) */
2633 case 0x2413: /* Battery on critical low level (S4) */
2635 "EMERGENCY WAKEUP: battery almost empty\n");
2636 /* how to auto-heal: */
2637 /* 2313: woke up from S3, go to S4/S5 */
2638 /* 2413: woke up from S4, go to S5 */
2645 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
2647 "woke up due to a hot-unplug "
2649 hotkey_wakeup_reason_notify_change();
2654 static bool hotkey_notify_usrevent(const u32 hkey
,
2656 bool *ignore_acpi_ev
)
2658 /* 0x5000-0x5FFF: human interface helpers */
2659 *send_acpi_ev
= true;
2660 *ignore_acpi_ev
= false;
2663 case 0x5010: /* Lenovo new BIOS: brightness changed */
2664 case 0x500b: /* X61t: tablet pen inserted into bay */
2665 case 0x500c: /* X61t: tablet pen removed from bay */
2668 case 0x5009: /* X41t-X61t: swivel up (tablet mode) */
2669 case 0x500a: /* X41t-X61t: swivel down (normal mode) */
2670 tpacpi_input_send_tabletsw();
2671 hotkey_tablet_mode_notify_change();
2672 *send_acpi_ev
= false;
2677 /* LID switch events. Do not propagate */
2678 *ignore_acpi_ev
= true;
2686 static bool hotkey_notify_thermal(const u32 hkey
,
2688 bool *ignore_acpi_ev
)
2690 /* 0x6000-0x6FFF: thermal alarms */
2691 *send_acpi_ev
= true;
2692 *ignore_acpi_ev
= false;
2697 "THERMAL ALARM: battery is too hot!\n");
2698 /* recommended action: warn user through gui */
2702 "THERMAL EMERGENCY: battery is extremely hot!\n");
2703 /* recommended action: immediate sleep/hibernate */
2708 "a sensor reports something is too hot!\n");
2709 /* recommended action: warn user through gui, that */
2710 /* some internal component is too hot */
2714 "THERMAL EMERGENCY: "
2715 "a sensor reports something is extremely hot!\n");
2716 /* recommended action: immediate sleep/hibernate */
2720 "EC reports that Thermal Table has changed\n");
2721 /* recommended action: do nothing, we don't have
2722 * Lenovo ATM information */
2726 "THERMAL ALERT: unknown thermal alarm received\n");
2731 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
2735 bool ignore_acpi_ev
;
2738 if (event
!= 0x80) {
2740 "unknown HKEY notification event %d\n", event
);
2741 /* forward it to userspace, maybe it knows how to handle it */
2742 acpi_bus_generate_netlink_event(
2743 ibm
->acpi
->device
->pnp
.device_class
,
2744 dev_name(&ibm
->acpi
->device
->dev
),
2750 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
2751 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
2760 send_acpi_ev
= true;
2761 ignore_acpi_ev
= false;
2763 switch (hkey
>> 12) {
2765 /* 0x1000-0x1FFF: key presses */
2766 known_ev
= hotkey_notify_hotkey(hkey
, &send_acpi_ev
,
2770 /* 0x2000-0x2FFF: Wakeup reason */
2771 known_ev
= hotkey_notify_wakeup(hkey
, &send_acpi_ev
,
2775 /* 0x3000-0x3FFF: bay-related wakeups */
2776 if (hkey
== 0x3003) {
2777 hotkey_autosleep_ack
= 1;
2780 hotkey_wakeup_hotunplug_complete_notify_change();
2787 /* 0x4000-0x4FFF: dock-related wakeups */
2788 if (hkey
== 0x4003) {
2789 hotkey_autosleep_ack
= 1;
2792 hotkey_wakeup_hotunplug_complete_notify_change();
2799 /* 0x5000-0x5FFF: human interface helpers */
2800 known_ev
= hotkey_notify_usrevent(hkey
, &send_acpi_ev
,
2804 /* 0x6000-0x6FFF: thermal alarms */
2805 known_ev
= hotkey_notify_thermal(hkey
, &send_acpi_ev
,
2809 /* 0x7000-0x7FFF: misc */
2810 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
2811 tpacpi_send_radiosw_update();
2816 /* fallthrough to default */
2821 printk(TPACPI_NOTICE
2822 "unhandled HKEY event 0x%04x\n", hkey
);
2823 printk(TPACPI_NOTICE
2824 "please report the conditions when this "
2825 "event happened to %s\n", TPACPI_MAIL
);
2829 if (!ignore_acpi_ev
&&
2830 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
2831 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
2835 /* netlink events */
2836 if (!ignore_acpi_ev
&& send_acpi_ev
) {
2837 acpi_bus_generate_netlink_event(
2838 ibm
->acpi
->device
->pnp
.device_class
,
2839 dev_name(&ibm
->acpi
->device
->dev
),
2845 static void hotkey_suspend(pm_message_t state
)
2847 /* Do these on suspend, we get the events on early resume! */
2848 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
2849 hotkey_autosleep_ack
= 0;
2852 static void hotkey_resume(void)
2854 tpacpi_disable_brightness_delay();
2856 if (hotkey_mask_get())
2858 "error while trying to read hot key mask "
2860 tpacpi_send_radiosw_update();
2861 hotkey_tablet_mode_notify_change();
2862 hotkey_wakeup_reason_notify_change();
2863 hotkey_wakeup_hotunplug_complete_notify_change();
2864 hotkey_poll_setup_safe(0);
2867 /* procfs -------------------------------------------------------------- */
2868 static int hotkey_read(char *p
)
2873 if (!tp_features
.hotkey
) {
2874 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2878 if (mutex_lock_killable(&hotkey_mutex
))
2879 return -ERESTARTSYS
;
2880 res
= hotkey_status_get(&status
);
2882 res
= hotkey_mask_get();
2883 mutex_unlock(&hotkey_mutex
);
2887 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
2888 if (tp_features
.hotkey_mask
) {
2889 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", hotkey_mask
);
2890 len
+= sprintf(p
+ len
,
2891 "commands:\tenable, disable, reset, <mask>\n");
2893 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
2894 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
2900 static int hotkey_write(char *buf
)
2906 if (!tp_features
.hotkey
)
2909 if (mutex_lock_killable(&hotkey_mutex
))
2910 return -ERESTARTSYS
;
2916 while ((cmd
= next_cmd(&buf
))) {
2917 if (strlencmp(cmd
, "enable") == 0) {
2919 } else if (strlencmp(cmd
, "disable") == 0) {
2921 } else if (strlencmp(cmd
, "reset") == 0) {
2922 status
= hotkey_orig_status
;
2923 mask
= hotkey_orig_mask
;
2924 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
2926 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
2934 res
= hotkey_status_set(status
);
2936 if (!res
&& mask
!= hotkey_mask
)
2937 res
= hotkey_mask_set(mask
);
2940 mutex_unlock(&hotkey_mutex
);
2944 static const struct acpi_device_id ibm_htk_device_ids
[] = {
2945 {TPACPI_ACPI_HKEY_HID
, 0},
2949 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
2950 .hid
= ibm_htk_device_ids
,
2951 .notify
= hotkey_notify
,
2952 .handle
= &hkey_handle
,
2953 .type
= ACPI_DEVICE_NOTIFY
,
2956 static struct ibm_struct hotkey_driver_data
= {
2958 .read
= hotkey_read
,
2959 .write
= hotkey_write
,
2960 .exit
= hotkey_exit
,
2961 .resume
= hotkey_resume
,
2962 .suspend
= hotkey_suspend
,
2963 .acpi
= &ibm_hotkey_acpidriver
,
2966 /*************************************************************************
2967 * Bluetooth subdriver
2971 /* ACPI GBDC/SBDC bits */
2972 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
2973 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
2974 TP_ACPI_BLUETOOTH_RESUMECTRL
= 0x04, /* Bluetooth state at resume:
2979 /* ACPI \BLTH commands */
2980 TP_ACPI_BLTH_GET_ULTRAPORT_ID
= 0x00, /* Get Ultraport BT ID */
2981 TP_ACPI_BLTH_GET_PWR_ON_RESUME
= 0x01, /* Get power-on-resume state */
2982 TP_ACPI_BLTH_PWR_ON_ON_RESUME
= 0x02, /* Resume powered on */
2983 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
= 0x03, /* Resume powered off */
2984 TP_ACPI_BLTH_SAVE_STATE
= 0x05, /* Save state for S4/S5 */
2987 static struct rfkill
*tpacpi_bluetooth_rfkill
;
2989 static void bluetooth_suspend(pm_message_t state
)
2991 /* Try to make sure radio will resume powered off */
2992 acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
2993 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
);
2996 static int bluetooth_get_radiosw(void)
3000 if (!tp_features
.bluetooth
)
3003 /* WLSW overrides bluetooth in firmware/hardware, reflect that */
3004 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3005 return RFKILL_STATE_HARD_BLOCKED
;
3007 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3008 if (dbg_bluetoothemul
)
3009 return (tpacpi_bluetooth_emulstate
) ?
3010 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3013 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
3016 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0) ?
3017 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3020 static void bluetooth_update_rfk(void)
3024 if (!tpacpi_bluetooth_rfkill
)
3027 status
= bluetooth_get_radiosw();
3030 rfkill_force_state(tpacpi_bluetooth_rfkill
, status
);
3033 static int bluetooth_set_radiosw(int radio_on
, int update_rfk
)
3037 if (!tp_features
.bluetooth
)
3040 /* WLSW overrides bluetooth in firmware/hardware, but there is no
3041 * reason to risk weird behaviour. */
3042 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3046 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3047 if (dbg_bluetoothemul
) {
3048 tpacpi_bluetooth_emulstate
= !!radio_on
;
3050 bluetooth_update_rfk();
3055 /* We make sure to keep TP_ACPI_BLUETOOTH_RESUMECTRL off */
3057 status
= TP_ACPI_BLUETOOTH_RADIOSSW
;
3060 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
3064 bluetooth_update_rfk();
3069 /* sysfs bluetooth enable ---------------------------------------------- */
3070 static ssize_t
bluetooth_enable_show(struct device
*dev
,
3071 struct device_attribute
*attr
,
3076 status
= bluetooth_get_radiosw();
3080 return snprintf(buf
, PAGE_SIZE
, "%d\n",
3081 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
3084 static ssize_t
bluetooth_enable_store(struct device
*dev
,
3085 struct device_attribute
*attr
,
3086 const char *buf
, size_t count
)
3091 if (parse_strtoul(buf
, 1, &t
))
3094 res
= bluetooth_set_radiosw(t
, 1);
3096 return (res
) ? res
: count
;
3099 static struct device_attribute dev_attr_bluetooth_enable
=
3100 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
3101 bluetooth_enable_show
, bluetooth_enable_store
);
3103 /* --------------------------------------------------------------------- */
3105 static struct attribute
*bluetooth_attributes
[] = {
3106 &dev_attr_bluetooth_enable
.attr
,
3110 static const struct attribute_group bluetooth_attr_group
= {
3111 .attrs
= bluetooth_attributes
,
3114 static int tpacpi_bluetooth_rfk_get(void *data
, enum rfkill_state
*state
)
3116 int bts
= bluetooth_get_radiosw();
3125 static int tpacpi_bluetooth_rfk_set(void *data
, enum rfkill_state state
)
3127 return bluetooth_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
3130 static void bluetooth_shutdown(void)
3132 /* Order firmware to save current state to NVRAM */
3133 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3134 TP_ACPI_BLTH_SAVE_STATE
))
3135 printk(TPACPI_NOTICE
3136 "failed to save bluetooth state to NVRAM\n");
3139 static void bluetooth_exit(void)
3141 bluetooth_shutdown();
3143 if (tpacpi_bluetooth_rfkill
)
3144 rfkill_unregister(tpacpi_bluetooth_rfkill
);
3146 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3147 &bluetooth_attr_group
);
3150 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
3155 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
3157 TPACPI_ACPIHANDLE_INIT(hkey
);
3159 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
3160 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
3161 tp_features
.bluetooth
= hkey_handle
&&
3162 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
3164 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
3165 str_supported(tp_features
.bluetooth
),
3168 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3169 if (dbg_bluetoothemul
) {
3170 tp_features
.bluetooth
= 1;
3172 "bluetooth switch emulation enabled\n");
3175 if (tp_features
.bluetooth
&&
3176 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
3177 /* no bluetooth hardware present in system */
3178 tp_features
.bluetooth
= 0;
3179 dbg_printk(TPACPI_DBG_INIT
,
3180 "bluetooth hardware not installed\n");
3183 if (!tp_features
.bluetooth
)
3186 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3187 &bluetooth_attr_group
);
3191 res
= tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
,
3192 &tpacpi_bluetooth_rfkill
,
3193 RFKILL_TYPE_BLUETOOTH
,
3194 "tpacpi_bluetooth_sw",
3196 tpacpi_bluetooth_rfk_set
,
3197 tpacpi_bluetooth_rfk_get
);
3206 /* procfs -------------------------------------------------------------- */
3207 static int bluetooth_read(char *p
)
3210 int status
= bluetooth_get_radiosw();
3212 if (!tp_features
.bluetooth
)
3213 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3215 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3216 (status
== RFKILL_STATE_UNBLOCKED
) ?
3217 "enabled" : "disabled");
3218 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
3224 static int bluetooth_write(char *buf
)
3228 if (!tp_features
.bluetooth
)
3231 while ((cmd
= next_cmd(&buf
))) {
3232 if (strlencmp(cmd
, "enable") == 0) {
3233 bluetooth_set_radiosw(1, 1);
3234 } else if (strlencmp(cmd
, "disable") == 0) {
3235 bluetooth_set_radiosw(0, 1);
3243 static struct ibm_struct bluetooth_driver_data
= {
3244 .name
= "bluetooth",
3245 .read
= bluetooth_read
,
3246 .write
= bluetooth_write
,
3247 .exit
= bluetooth_exit
,
3248 .suspend
= bluetooth_suspend
,
3249 .shutdown
= bluetooth_shutdown
,
3252 /*************************************************************************
3257 /* ACPI GWAN/SWAN bits */
3258 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
3259 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
3260 TP_ACPI_WANCARD_RESUMECTRL
= 0x04, /* Wan state at resume:
3264 static struct rfkill
*tpacpi_wan_rfkill
;
3266 static void wan_suspend(pm_message_t state
)
3268 /* Try to make sure radio will resume powered off */
3269 acpi_evalf(NULL
, NULL
, "\\WGSV", "qvd",
3270 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
);
3273 static int wan_get_radiosw(void)
3277 if (!tp_features
.wan
)
3280 /* WLSW overrides WWAN in firmware/hardware, reflect that */
3281 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3282 return RFKILL_STATE_HARD_BLOCKED
;
3284 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3286 return (tpacpi_wwan_emulstate
) ?
3287 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3290 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
3293 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0) ?
3294 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3297 static void wan_update_rfk(void)
3301 if (!tpacpi_wan_rfkill
)
3304 status
= wan_get_radiosw();
3307 rfkill_force_state(tpacpi_wan_rfkill
, status
);
3310 static int wan_set_radiosw(int radio_on
, int update_rfk
)
3314 if (!tp_features
.wan
)
3317 /* WLSW overrides bluetooth in firmware/hardware, but there is no
3318 * reason to risk weird behaviour. */
3319 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3323 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3325 tpacpi_wwan_emulstate
= !!radio_on
;
3332 /* We make sure to keep TP_ACPI_WANCARD_RESUMECTRL off */
3334 status
= TP_ACPI_WANCARD_RADIOSSW
;
3337 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
3346 /* sysfs wan enable ---------------------------------------------------- */
3347 static ssize_t
wan_enable_show(struct device
*dev
,
3348 struct device_attribute
*attr
,
3353 status
= wan_get_radiosw();
3357 return snprintf(buf
, PAGE_SIZE
, "%d\n",
3358 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
3361 static ssize_t
wan_enable_store(struct device
*dev
,
3362 struct device_attribute
*attr
,
3363 const char *buf
, size_t count
)
3368 if (parse_strtoul(buf
, 1, &t
))
3371 res
= wan_set_radiosw(t
, 1);
3373 return (res
) ? res
: count
;
3376 static struct device_attribute dev_attr_wan_enable
=
3377 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
3378 wan_enable_show
, wan_enable_store
);
3380 /* --------------------------------------------------------------------- */
3382 static struct attribute
*wan_attributes
[] = {
3383 &dev_attr_wan_enable
.attr
,
3387 static const struct attribute_group wan_attr_group
= {
3388 .attrs
= wan_attributes
,
3391 static int tpacpi_wan_rfk_get(void *data
, enum rfkill_state
*state
)
3393 int wans
= wan_get_radiosw();
3402 static int tpacpi_wan_rfk_set(void *data
, enum rfkill_state state
)
3404 return wan_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
3407 static void wan_shutdown(void)
3409 /* Order firmware to save current state to NVRAM */
3410 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "vd",
3411 TP_ACPI_WGSV_SAVE_STATE
))
3412 printk(TPACPI_NOTICE
3413 "failed to save WWAN state to NVRAM\n");
3416 static void wan_exit(void)
3420 if (tpacpi_wan_rfkill
)
3421 rfkill_unregister(tpacpi_wan_rfkill
);
3423 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3427 static int __init
wan_init(struct ibm_init_struct
*iibm
)
3432 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
3434 TPACPI_ACPIHANDLE_INIT(hkey
);
3436 tp_features
.wan
= hkey_handle
&&
3437 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
3439 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
3440 str_supported(tp_features
.wan
),
3443 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3445 tp_features
.wan
= 1;
3447 "wwan switch emulation enabled\n");
3450 if (tp_features
.wan
&&
3451 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
3452 /* no wan hardware present in system */
3453 tp_features
.wan
= 0;
3454 dbg_printk(TPACPI_DBG_INIT
,
3455 "wan hardware not installed\n");
3458 if (!tp_features
.wan
)
3461 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3466 res
= tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID
,
3472 tpacpi_wan_rfk_get
);
3481 /* procfs -------------------------------------------------------------- */
3482 static int wan_read(char *p
)
3485 int status
= wan_get_radiosw();
3487 if (!tp_features
.wan
)
3488 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3490 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3491 (status
== RFKILL_STATE_UNBLOCKED
) ?
3492 "enabled" : "disabled");
3493 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
3499 static int wan_write(char *buf
)
3503 if (!tp_features
.wan
)
3506 while ((cmd
= next_cmd(&buf
))) {
3507 if (strlencmp(cmd
, "enable") == 0) {
3508 wan_set_radiosw(1, 1);
3509 } else if (strlencmp(cmd
, "disable") == 0) {
3510 wan_set_radiosw(0, 1);
3518 static struct ibm_struct wan_driver_data
= {
3523 .suspend
= wan_suspend
,
3524 .shutdown
= wan_shutdown
,
3527 /*************************************************************************
3532 /* ACPI GUWB/SUWB bits */
3533 TP_ACPI_UWB_HWPRESENT
= 0x01, /* UWB hw available */
3534 TP_ACPI_UWB_RADIOSSW
= 0x02, /* UWB radio enabled */
3537 static struct rfkill
*tpacpi_uwb_rfkill
;
3539 static int uwb_get_radiosw(void)
3543 if (!tp_features
.uwb
)
3546 /* WLSW overrides UWB in firmware/hardware, reflect that */
3547 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3548 return RFKILL_STATE_HARD_BLOCKED
;
3550 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3552 return (tpacpi_uwb_emulstate
) ?
3553 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3556 if (!acpi_evalf(hkey_handle
, &status
, "GUWB", "d"))
3559 return ((status
& TP_ACPI_UWB_RADIOSSW
) != 0) ?
3560 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3563 static void uwb_update_rfk(void)
3567 if (!tpacpi_uwb_rfkill
)
3570 status
= uwb_get_radiosw();
3573 rfkill_force_state(tpacpi_uwb_rfkill
, status
);
3576 static int uwb_set_radiosw(int radio_on
, int update_rfk
)
3580 if (!tp_features
.uwb
)
3583 /* WLSW overrides UWB in firmware/hardware, but there is no
3584 * reason to risk weird behaviour. */
3585 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3589 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3591 tpacpi_uwb_emulstate
= !!radio_on
;
3598 status
= (radio_on
) ? TP_ACPI_UWB_RADIOSSW
: 0;
3599 if (!acpi_evalf(hkey_handle
, NULL
, "SUWB", "vd", status
))
3608 /* --------------------------------------------------------------------- */
3610 static int tpacpi_uwb_rfk_get(void *data
, enum rfkill_state
*state
)
3612 int uwbs
= uwb_get_radiosw();
3621 static int tpacpi_uwb_rfk_set(void *data
, enum rfkill_state state
)
3623 return uwb_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
3626 static void uwb_exit(void)
3628 if (tpacpi_uwb_rfkill
)
3629 rfkill_unregister(tpacpi_uwb_rfkill
);
3632 static int __init
uwb_init(struct ibm_init_struct
*iibm
)
3637 vdbg_printk(TPACPI_DBG_INIT
, "initializing uwb subdriver\n");
3639 TPACPI_ACPIHANDLE_INIT(hkey
);
3641 tp_features
.uwb
= hkey_handle
&&
3642 acpi_evalf(hkey_handle
, &status
, "GUWB", "qd");
3644 vdbg_printk(TPACPI_DBG_INIT
, "uwb is %s, status 0x%02x\n",
3645 str_supported(tp_features
.uwb
),
3648 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3650 tp_features
.uwb
= 1;
3652 "uwb switch emulation enabled\n");
3655 if (tp_features
.uwb
&&
3656 !(status
& TP_ACPI_UWB_HWPRESENT
)) {
3657 /* no uwb hardware present in system */
3658 tp_features
.uwb
= 0;
3659 dbg_printk(TPACPI_DBG_INIT
,
3660 "uwb hardware not installed\n");
3663 if (!tp_features
.uwb
)
3666 res
= tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID
,
3672 tpacpi_uwb_rfk_get
);
3677 static struct ibm_struct uwb_driver_data
= {
3680 .flags
.experimental
= 1,
3683 /*************************************************************************
3687 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
3689 enum video_access_mode
{
3690 TPACPI_VIDEO_NONE
= 0,
3691 TPACPI_VIDEO_570
, /* 570 */
3692 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
3693 TPACPI_VIDEO_NEW
, /* all others */
3696 enum { /* video status flags, based on VIDEO_570 */
3697 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
3698 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
3699 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
3702 enum { /* TPACPI_VIDEO_570 constants */
3703 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
3704 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
3705 * video_status_flags */
3706 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
3707 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
3710 static enum video_access_mode video_supported
;
3711 static int video_orig_autosw
;
3713 static int video_autosw_get(void);
3714 static int video_autosw_set(int enable
);
3716 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
3718 static int __init
video_init(struct ibm_init_struct
*iibm
)
3722 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
3724 TPACPI_ACPIHANDLE_INIT(vid
);
3725 TPACPI_ACPIHANDLE_INIT(vid2
);
3727 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
3728 /* G41, assume IVGA doesn't change */
3729 vid_handle
= vid2_handle
;
3732 /* video switching not supported on R30, R31 */
3733 video_supported
= TPACPI_VIDEO_NONE
;
3734 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
3736 video_supported
= TPACPI_VIDEO_570
;
3737 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
3738 /* 600e/x, 770e, 770x */
3739 video_supported
= TPACPI_VIDEO_770
;
3742 video_supported
= TPACPI_VIDEO_NEW
;
3744 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
3745 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
3748 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
3751 static void video_exit(void)
3753 dbg_printk(TPACPI_DBG_EXIT
,
3754 "restoring original video autoswitch mode\n");
3755 if (video_autosw_set(video_orig_autosw
))
3756 printk(TPACPI_ERR
"error while trying to restore original "
3757 "video autoswitch mode\n");
3760 static int video_outputsw_get(void)
3765 switch (video_supported
) {
3766 case TPACPI_VIDEO_570
:
3767 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
3768 TP_ACPI_VIDEO_570_PHSCMD
))
3770 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
3772 case TPACPI_VIDEO_770
:
3773 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
3776 status
|= TP_ACPI_VIDEO_S_LCD
;
3777 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
3780 status
|= TP_ACPI_VIDEO_S_CRT
;
3782 case TPACPI_VIDEO_NEW
:
3783 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
3784 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
3787 status
|= TP_ACPI_VIDEO_S_CRT
;
3789 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
3790 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
3793 status
|= TP_ACPI_VIDEO_S_LCD
;
3794 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
3797 status
|= TP_ACPI_VIDEO_S_DVI
;
3806 static int video_outputsw_set(int status
)
3811 switch (video_supported
) {
3812 case TPACPI_VIDEO_570
:
3813 res
= acpi_evalf(NULL
, NULL
,
3814 "\\_SB.PHS2", "vdd",
3815 TP_ACPI_VIDEO_570_PHS2CMD
,
3816 status
| TP_ACPI_VIDEO_570_PHS2SET
);
3818 case TPACPI_VIDEO_770
:
3819 autosw
= video_autosw_get();
3823 res
= video_autosw_set(1);
3826 res
= acpi_evalf(vid_handle
, NULL
,
3827 "ASWT", "vdd", status
* 0x100, 0);
3828 if (!autosw
&& video_autosw_set(autosw
)) {
3830 "video auto-switch left enabled due to error\n");
3834 case TPACPI_VIDEO_NEW
:
3835 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
3836 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
3842 return (res
)? 0 : -EIO
;
3845 static int video_autosw_get(void)
3849 switch (video_supported
) {
3850 case TPACPI_VIDEO_570
:
3851 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
3854 case TPACPI_VIDEO_770
:
3855 case TPACPI_VIDEO_NEW
:
3856 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
3866 static int video_autosw_set(int enable
)
3868 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
3873 static int video_outputsw_cycle(void)
3875 int autosw
= video_autosw_get();
3881 switch (video_supported
) {
3882 case TPACPI_VIDEO_570
:
3883 res
= video_autosw_set(1);
3886 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
3888 case TPACPI_VIDEO_770
:
3889 case TPACPI_VIDEO_NEW
:
3890 res
= video_autosw_set(1);
3893 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
3898 if (!autosw
&& video_autosw_set(autosw
)) {
3900 "video auto-switch left enabled due to error\n");
3904 return (res
)? 0 : -EIO
;
3907 static int video_expand_toggle(void)
3909 switch (video_supported
) {
3910 case TPACPI_VIDEO_570
:
3911 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
3913 case TPACPI_VIDEO_770
:
3914 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
3916 case TPACPI_VIDEO_NEW
:
3917 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
3925 static int video_read(char *p
)
3930 if (video_supported
== TPACPI_VIDEO_NONE
) {
3931 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3935 status
= video_outputsw_get();
3939 autosw
= video_autosw_get();
3943 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3944 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
3945 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
3946 if (video_supported
== TPACPI_VIDEO_NEW
)
3947 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
3948 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
3949 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
3950 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
3951 if (video_supported
== TPACPI_VIDEO_NEW
)
3952 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
3953 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
3954 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
3959 static int video_write(char *buf
)
3962 int enable
, disable
, status
;
3965 if (video_supported
== TPACPI_VIDEO_NONE
)
3971 while ((cmd
= next_cmd(&buf
))) {
3972 if (strlencmp(cmd
, "lcd_enable") == 0) {
3973 enable
|= TP_ACPI_VIDEO_S_LCD
;
3974 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
3975 disable
|= TP_ACPI_VIDEO_S_LCD
;
3976 } else if (strlencmp(cmd
, "crt_enable") == 0) {
3977 enable
|= TP_ACPI_VIDEO_S_CRT
;
3978 } else if (strlencmp(cmd
, "crt_disable") == 0) {
3979 disable
|= TP_ACPI_VIDEO_S_CRT
;
3980 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
3981 strlencmp(cmd
, "dvi_enable") == 0) {
3982 enable
|= TP_ACPI_VIDEO_S_DVI
;
3983 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
3984 strlencmp(cmd
, "dvi_disable") == 0) {
3985 disable
|= TP_ACPI_VIDEO_S_DVI
;
3986 } else if (strlencmp(cmd
, "auto_enable") == 0) {
3987 res
= video_autosw_set(1);
3990 } else if (strlencmp(cmd
, "auto_disable") == 0) {
3991 res
= video_autosw_set(0);
3994 } else if (strlencmp(cmd
, "video_switch") == 0) {
3995 res
= video_outputsw_cycle();
3998 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
3999 res
= video_expand_toggle();
4006 if (enable
|| disable
) {
4007 status
= video_outputsw_get();
4010 res
= video_outputsw_set((status
& ~disable
) | enable
);
4018 static struct ibm_struct video_driver_data
= {
4021 .write
= video_write
,
4025 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
4027 /*************************************************************************
4028 * Light (thinklight) subdriver
4031 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
4032 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
4034 static int light_get_status(void)
4038 if (tp_features
.light_status
) {
4039 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
4047 static int light_set_status(int status
)
4051 if (tp_features
.light
) {
4053 rc
= acpi_evalf(cmos_handle
, NULL
, NULL
, "vd",
4055 TP_CMOS_THINKLIGHT_ON
:
4056 TP_CMOS_THINKLIGHT_OFF
);
4058 rc
= acpi_evalf(lght_handle
, NULL
, NULL
, "vd",
4061 return (rc
)? 0 : -EIO
;
4067 static void light_set_status_worker(struct work_struct
*work
)
4069 struct tpacpi_led_classdev
*data
=
4070 container_of(work
, struct tpacpi_led_classdev
, work
);
4072 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4073 light_set_status((data
->new_state
!= TPACPI_LED_OFF
));
4076 static void light_sysfs_set(struct led_classdev
*led_cdev
,
4077 enum led_brightness brightness
)
4079 struct tpacpi_led_classdev
*data
=
4080 container_of(led_cdev
,
4081 struct tpacpi_led_classdev
,
4083 data
->new_state
= (brightness
!= LED_OFF
) ?
4084 TPACPI_LED_ON
: TPACPI_LED_OFF
;
4085 queue_work(tpacpi_wq
, &data
->work
);
4088 static enum led_brightness
light_sysfs_get(struct led_classdev
*led_cdev
)
4090 return (light_get_status() == 1)? LED_FULL
: LED_OFF
;
4093 static struct tpacpi_led_classdev tpacpi_led_thinklight
= {
4095 .name
= "tpacpi::thinklight",
4096 .brightness_set
= &light_sysfs_set
,
4097 .brightness_get
= &light_sysfs_get
,
4101 static int __init
light_init(struct ibm_init_struct
*iibm
)
4105 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
4107 TPACPI_ACPIHANDLE_INIT(ledb
);
4108 TPACPI_ACPIHANDLE_INIT(lght
);
4109 TPACPI_ACPIHANDLE_INIT(cmos
);
4110 INIT_WORK(&tpacpi_led_thinklight
.work
, light_set_status_worker
);
4112 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
4113 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
4115 if (tp_features
.light
)
4116 /* light status not supported on
4117 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
4118 tp_features
.light_status
=
4119 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
4121 vdbg_printk(TPACPI_DBG_INIT
, "light is %s, light status is %s\n",
4122 str_supported(tp_features
.light
),
4123 str_supported(tp_features
.light_status
));
4125 if (!tp_features
.light
)
4128 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4129 &tpacpi_led_thinklight
.led_classdev
);
4132 tp_features
.light
= 0;
4133 tp_features
.light_status
= 0;
4141 static void light_exit(void)
4143 led_classdev_unregister(&tpacpi_led_thinklight
.led_classdev
);
4144 if (work_pending(&tpacpi_led_thinklight
.work
))
4145 flush_workqueue(tpacpi_wq
);
4148 static int light_read(char *p
)
4153 if (!tp_features
.light
) {
4154 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4155 } else if (!tp_features
.light_status
) {
4156 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
4157 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
4159 status
= light_get_status();
4162 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
4163 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
4169 static int light_write(char *buf
)
4174 if (!tp_features
.light
)
4177 while ((cmd
= next_cmd(&buf
))) {
4178 if (strlencmp(cmd
, "on") == 0) {
4180 } else if (strlencmp(cmd
, "off") == 0) {
4186 return light_set_status(newstatus
);
4189 static struct ibm_struct light_driver_data
= {
4192 .write
= light_write
,
4196 /*************************************************************************
4200 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4202 static void dock_notify(struct ibm_struct
*ibm
, u32 event
);
4203 static int dock_read(char *p
);
4204 static int dock_write(char *buf
);
4206 TPACPI_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
4207 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
4208 "\\_SB.PCI0.PCI1.DOCK", /* all others */
4209 "\\_SB.PCI.ISA.SLCE", /* 570 */
4210 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
4212 /* don't list other alternatives as we install a notify handler on the 570 */
4213 TPACPI_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
4215 static const struct acpi_device_id ibm_pci_device_ids
[] = {
4216 {PCI_ROOT_HID_STRING
, 0},
4220 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
4222 .notify
= dock_notify
,
4223 .handle
= &dock_handle
,
4224 .type
= ACPI_SYSTEM_NOTIFY
,
4227 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
4228 * We just use it to get notifications of dock hotplug
4229 * in very old thinkpads */
4230 .hid
= ibm_pci_device_ids
,
4231 .notify
= dock_notify
,
4232 .handle
= &pci_handle
,
4233 .type
= ACPI_SYSTEM_NOTIFY
,
4237 static struct ibm_struct dock_driver_data
[2] = {
4241 .write
= dock_write
,
4242 .acpi
= &ibm_dock_acpidriver
[0],
4246 .acpi
= &ibm_dock_acpidriver
[1],
4250 #define dock_docked() (_sta(dock_handle) & 1)
4252 static int __init
dock_init(struct ibm_init_struct
*iibm
)
4254 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
4256 TPACPI_ACPIHANDLE_INIT(dock
);
4258 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
4259 str_supported(dock_handle
!= NULL
));
4261 return (dock_handle
)? 0 : 1;
4264 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
4268 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
4270 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
4271 dock_driver_data
[0].flags
.acpi_notify_installed
) {
4272 TPACPI_ACPIHANDLE_INIT(pci
);
4273 dock2_needed
= (pci_handle
!= NULL
);
4274 vdbg_printk(TPACPI_DBG_INIT
,
4275 "dock PCI handler for the TP 570 is %s\n",
4276 str_supported(dock2_needed
));
4278 vdbg_printk(TPACPI_DBG_INIT
,
4279 "dock subdriver part 2 not required\n");
4283 return (dock2_needed
)? 0 : 1;
4286 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
4288 int docked
= dock_docked();
4289 int pci
= ibm
->acpi
->hid
&& ibm
->acpi
->device
&&
4290 acpi_match_device_ids(ibm
->acpi
->device
, ibm_pci_device_ids
);
4293 if (event
== 1 && !pci
) /* 570 */
4294 data
= 1; /* button */
4295 else if (event
== 1 && pci
) /* 570 */
4296 data
= 3; /* dock */
4297 else if (event
== 3 && docked
)
4298 data
= 1; /* button */
4299 else if (event
== 3 && !docked
)
4300 data
= 2; /* undock */
4301 else if (event
== 0 && docked
)
4302 data
= 3; /* dock */
4304 printk(TPACPI_ERR
"unknown dock event %d, status %d\n",
4305 event
, _sta(dock_handle
));
4306 data
= 0; /* unknown */
4308 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, data
);
4309 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
4310 dev_name(&ibm
->acpi
->device
->dev
),
4314 static int dock_read(char *p
)
4317 int docked
= dock_docked();
4320 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4322 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
4324 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
4325 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
4331 static int dock_write(char *buf
)
4338 while ((cmd
= next_cmd(&buf
))) {
4339 if (strlencmp(cmd
, "undock") == 0) {
4340 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
4341 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
4343 } else if (strlencmp(cmd
, "dock") == 0) {
4344 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
4353 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
4355 /*************************************************************************
4359 #ifdef CONFIG_THINKPAD_ACPI_BAY
4361 TPACPI_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
4362 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
4363 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
4364 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
4365 ); /* A21e, R30, R31 */
4366 TPACPI_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
4367 "_EJ0", /* all others */
4368 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
4369 TPACPI_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
4370 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
4372 TPACPI_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
4376 static int __init
bay_init(struct ibm_init_struct
*iibm
)
4378 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
4380 TPACPI_ACPIHANDLE_INIT(bay
);
4382 TPACPI_ACPIHANDLE_INIT(bay_ej
);
4383 TPACPI_ACPIHANDLE_INIT(bay2
);
4385 TPACPI_ACPIHANDLE_INIT(bay2_ej
);
4387 tp_features
.bay_status
= bay_handle
&&
4388 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
4389 tp_features
.bay_status2
= bay2_handle
&&
4390 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
4392 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
4393 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
4394 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
4395 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
4397 vdbg_printk(TPACPI_DBG_INIT
,
4398 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
4399 str_supported(tp_features
.bay_status
),
4400 str_supported(tp_features
.bay_eject
),
4401 str_supported(tp_features
.bay_status2
),
4402 str_supported(tp_features
.bay_eject2
));
4404 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
4405 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
4408 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
4410 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, 0);
4411 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
4412 dev_name(&ibm
->acpi
->device
->dev
),
4416 #define bay_occupied(b) (_sta(b##_handle) & 1)
4418 static int bay_read(char *p
)
4421 int occupied
= bay_occupied(bay
);
4422 int occupied2
= bay_occupied(bay2
);
4425 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
4426 tp_features
.bay_status
?
4427 (occupied
? "occupied" : "unoccupied") :
4429 if (tp_features
.bay_status2
)
4430 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
4431 "occupied" : "unoccupied");
4433 eject
= tp_features
.bay_eject
&& occupied
;
4434 eject2
= tp_features
.bay_eject2
&& occupied2
;
4436 if (eject
&& eject2
)
4437 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
4439 len
+= sprintf(p
+ len
, "commands:\teject\n");
4441 len
+= sprintf(p
+ len
, "commands:\teject2\n");
4446 static int bay_write(char *buf
)
4450 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
4453 while ((cmd
= next_cmd(&buf
))) {
4454 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
4455 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
4457 } else if (tp_features
.bay_eject2
&&
4458 strlencmp(cmd
, "eject2") == 0) {
4459 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
4468 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
4469 .notify
= bay_notify
,
4470 .handle
= &bay_handle
,
4471 .type
= ACPI_SYSTEM_NOTIFY
,
4474 static struct ibm_struct bay_driver_data
= {
4478 .acpi
= &ibm_bay_acpidriver
,
4481 #endif /* CONFIG_THINKPAD_ACPI_BAY */
4483 /*************************************************************************
4487 /* sysfs cmos_command -------------------------------------------------- */
4488 static ssize_t
cmos_command_store(struct device
*dev
,
4489 struct device_attribute
*attr
,
4490 const char *buf
, size_t count
)
4492 unsigned long cmos_cmd
;
4495 if (parse_strtoul(buf
, 21, &cmos_cmd
))
4498 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4499 return (res
)? res
: count
;
4502 static struct device_attribute dev_attr_cmos_command
=
4503 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
4505 /* --------------------------------------------------------------------- */
4507 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
4511 vdbg_printk(TPACPI_DBG_INIT
,
4512 "initializing cmos commands subdriver\n");
4514 TPACPI_ACPIHANDLE_INIT(cmos
);
4516 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
4517 str_supported(cmos_handle
!= NULL
));
4519 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4523 return (cmos_handle
)? 0 : 1;
4526 static void cmos_exit(void)
4528 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4531 static int cmos_read(char *p
)
4535 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4536 R30, R31, T20-22, X20-21 */
4538 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4540 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4541 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
4547 static int cmos_write(char *buf
)
4552 while ((cmd
= next_cmd(&buf
))) {
4553 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
4554 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
4559 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4567 static struct ibm_struct cmos_driver_data
= {
4570 .write
= cmos_write
,
4574 /*************************************************************************
4578 enum led_access_mode
{
4579 TPACPI_LED_NONE
= 0,
4580 TPACPI_LED_570
, /* 570 */
4581 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4582 TPACPI_LED_NEW
, /* all others */
4585 enum { /* For TPACPI_LED_OLD */
4586 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
4587 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
4588 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
4591 static enum led_access_mode led_supported
;
4593 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
4594 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
4595 /* T20-22, X20-21 */
4596 "LED", /* all others */
4599 #define TPACPI_LED_NUMLEDS 8
4600 static struct tpacpi_led_classdev
*tpacpi_leds
;
4601 static enum led_status_t tpacpi_led_state_cache
[TPACPI_LED_NUMLEDS
];
4602 static const char * const tpacpi_led_names
[TPACPI_LED_NUMLEDS
] = {
4603 /* there's a limit of 19 chars + NULL before 2.6.26 */
4605 "tpacpi:orange:batt",
4606 "tpacpi:green:batt",
4607 "tpacpi::dock_active",
4608 "tpacpi::bay_active",
4609 "tpacpi::dock_batt",
4610 "tpacpi::unknown_led",
4614 static int led_get_status(const unsigned int led
)
4617 enum led_status_t led_s
;
4619 switch (led_supported
) {
4620 case TPACPI_LED_570
:
4621 if (!acpi_evalf(ec_handle
,
4622 &status
, "GLED", "dd", 1 << led
))
4624 led_s
= (status
== 0)?
4629 tpacpi_led_state_cache
[led
] = led_s
;
4638 static int led_set_status(const unsigned int led
,
4639 const enum led_status_t ledstatus
)
4641 /* off, on, blink. Index is led_status_t */
4642 static const unsigned int led_sled_arg1
[] = { 0, 1, 3 };
4643 static const unsigned int led_led_arg1
[] = { 0, 0x80, 0xc0 };
4647 switch (led_supported
) {
4648 case TPACPI_LED_570
:
4652 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
4653 (1 << led
), led_sled_arg1
[ledstatus
]))
4656 case TPACPI_LED_OLD
:
4657 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
4660 rc
= ec_write(TPACPI_LED_EC_HLMS
, (1 << led
));
4662 rc
= ec_write(TPACPI_LED_EC_HLBL
,
4663 (ledstatus
== TPACPI_LED_BLINK
) << led
);
4665 rc
= ec_write(TPACPI_LED_EC_HLCL
,
4666 (ledstatus
!= TPACPI_LED_OFF
) << led
);
4668 case TPACPI_LED_NEW
:
4670 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
4671 led
, led_led_arg1
[ledstatus
]))
4679 tpacpi_led_state_cache
[led
] = ledstatus
;
4684 static void led_set_status_worker(struct work_struct
*work
)
4686 struct tpacpi_led_classdev
*data
=
4687 container_of(work
, struct tpacpi_led_classdev
, work
);
4689 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4690 led_set_status(data
->led
, data
->new_state
);
4693 static void led_sysfs_set(struct led_classdev
*led_cdev
,
4694 enum led_brightness brightness
)
4696 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4697 struct tpacpi_led_classdev
, led_classdev
);
4699 if (brightness
== LED_OFF
)
4700 data
->new_state
= TPACPI_LED_OFF
;
4701 else if (tpacpi_led_state_cache
[data
->led
] != TPACPI_LED_BLINK
)
4702 data
->new_state
= TPACPI_LED_ON
;
4704 data
->new_state
= TPACPI_LED_BLINK
;
4706 queue_work(tpacpi_wq
, &data
->work
);
4709 static int led_sysfs_blink_set(struct led_classdev
*led_cdev
,
4710 unsigned long *delay_on
, unsigned long *delay_off
)
4712 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4713 struct tpacpi_led_classdev
, led_classdev
);
4715 /* Can we choose the flash rate? */
4716 if (*delay_on
== 0 && *delay_off
== 0) {
4717 /* yes. set them to the hardware blink rate (1 Hz) */
4718 *delay_on
= 500; /* ms */
4719 *delay_off
= 500; /* ms */
4720 } else if ((*delay_on
!= 500) || (*delay_off
!= 500))
4723 data
->new_state
= TPACPI_LED_BLINK
;
4724 queue_work(tpacpi_wq
, &data
->work
);
4729 static enum led_brightness
led_sysfs_get(struct led_classdev
*led_cdev
)
4733 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4734 struct tpacpi_led_classdev
, led_classdev
);
4736 rc
= led_get_status(data
->led
);
4738 if (rc
== TPACPI_LED_OFF
|| rc
< 0)
4739 rc
= LED_OFF
; /* no error handling in led class :( */
4746 static void led_exit(void)
4750 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
4751 if (tpacpi_leds
[i
].led_classdev
.name
)
4752 led_classdev_unregister(&tpacpi_leds
[i
].led_classdev
);
4758 static int __init
led_init(struct ibm_init_struct
*iibm
)
4763 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
4765 TPACPI_ACPIHANDLE_INIT(led
);
4768 /* led not supported on R30, R31 */
4769 led_supported
= TPACPI_LED_NONE
;
4770 else if (strlencmp(led_path
, "SLED") == 0)
4772 led_supported
= TPACPI_LED_570
;
4773 else if (strlencmp(led_path
, "SYSL") == 0)
4774 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4775 led_supported
= TPACPI_LED_OLD
;
4778 led_supported
= TPACPI_LED_NEW
;
4780 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
4781 str_supported(led_supported
), led_supported
);
4783 tpacpi_leds
= kzalloc(sizeof(*tpacpi_leds
) * TPACPI_LED_NUMLEDS
,
4786 printk(TPACPI_ERR
"Out of memory for LED data\n");
4790 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
4791 tpacpi_leds
[i
].led
= i
;
4793 tpacpi_leds
[i
].led_classdev
.brightness_set
= &led_sysfs_set
;
4794 tpacpi_leds
[i
].led_classdev
.blink_set
= &led_sysfs_blink_set
;
4795 if (led_supported
== TPACPI_LED_570
)
4796 tpacpi_leds
[i
].led_classdev
.brightness_get
=
4799 tpacpi_leds
[i
].led_classdev
.name
= tpacpi_led_names
[i
];
4801 INIT_WORK(&tpacpi_leds
[i
].work
, led_set_status_worker
);
4803 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4804 &tpacpi_leds
[i
].led_classdev
);
4806 tpacpi_leds
[i
].led_classdev
.name
= NULL
;
4812 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
4815 #define str_led_status(s) \
4816 ((s) == TPACPI_LED_OFF ? "off" : \
4817 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
4819 static int led_read(char *p
)
4823 if (!led_supported
) {
4824 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4827 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4829 if (led_supported
== TPACPI_LED_570
) {
4832 for (i
= 0; i
< 8; i
++) {
4833 status
= led_get_status(i
);
4836 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
4837 i
, str_led_status(status
));
4841 len
+= sprintf(p
+ len
, "commands:\t"
4842 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
4847 static int led_write(char *buf
)
4851 enum led_status_t s
;
4856 while ((cmd
= next_cmd(&buf
))) {
4857 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
4860 if (strstr(cmd
, "off")) {
4862 } else if (strstr(cmd
, "on")) {
4864 } else if (strstr(cmd
, "blink")) {
4865 s
= TPACPI_LED_BLINK
;
4870 rc
= led_set_status(led
, s
);
4878 static struct ibm_struct led_driver_data
= {
4885 /*************************************************************************
4889 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
4891 static int __init
beep_init(struct ibm_init_struct
*iibm
)
4893 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
4895 TPACPI_ACPIHANDLE_INIT(beep
);
4897 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
4898 str_supported(beep_handle
!= NULL
));
4900 return (beep_handle
)? 0 : 1;
4903 static int beep_read(char *p
)
4908 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4910 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4911 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
4917 static int beep_write(char *buf
)
4925 while ((cmd
= next_cmd(&buf
))) {
4926 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
4927 beep_cmd
>= 0 && beep_cmd
<= 17) {
4931 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
4938 static struct ibm_struct beep_driver_data
= {
4941 .write
= beep_write
,
4944 /*************************************************************************
4948 enum thermal_access_mode
{
4949 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
4950 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
4951 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
4952 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
4953 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
4956 enum { /* TPACPI_THERMAL_TPEC_* */
4957 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
4958 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
4959 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
4962 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
4963 struct ibm_thermal_sensors_struct
{
4964 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
4967 static enum thermal_access_mode thermal_read_mode
;
4969 /* idx is zero-based */
4970 static int thermal_get_sensor(int idx
, s32
*value
)
4976 t
= TP_EC_THERMAL_TMP0
;
4978 switch (thermal_read_mode
) {
4979 #if TPACPI_MAX_THERMAL_SENSORS >= 16
4980 case TPACPI_THERMAL_TPEC_16
:
4981 if (idx
>= 8 && idx
<= 15) {
4982 t
= TP_EC_THERMAL_TMP8
;
4987 case TPACPI_THERMAL_TPEC_8
:
4989 if (!acpi_ec_read(t
+ idx
, &tmp
))
4991 *value
= tmp
* 1000;
4996 case TPACPI_THERMAL_ACPI_UPDT
:
4998 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
4999 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
5001 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5003 *value
= (t
- 2732) * 100;
5008 case TPACPI_THERMAL_ACPI_TMP07
:
5010 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5011 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5013 if (t
> 127 || t
< -127)
5014 t
= TP_EC_THERMAL_TMP_NA
;
5020 case TPACPI_THERMAL_NONE
:
5028 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
5039 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
5042 for (i
= 0 ; i
< n
; i
++) {
5043 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
5051 /* sysfs temp##_input -------------------------------------------------- */
5053 static ssize_t
thermal_temp_input_show(struct device
*dev
,
5054 struct device_attribute
*attr
,
5057 struct sensor_device_attribute
*sensor_attr
=
5058 to_sensor_dev_attr(attr
);
5059 int idx
= sensor_attr
->index
;
5063 res
= thermal_get_sensor(idx
, &value
);
5066 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
5069 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
5072 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
5073 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
5074 thermal_temp_input_show, NULL, _idxB)
5076 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
5077 THERMAL_SENSOR_ATTR_TEMP(1, 0),
5078 THERMAL_SENSOR_ATTR_TEMP(2, 1),
5079 THERMAL_SENSOR_ATTR_TEMP(3, 2),
5080 THERMAL_SENSOR_ATTR_TEMP(4, 3),
5081 THERMAL_SENSOR_ATTR_TEMP(5, 4),
5082 THERMAL_SENSOR_ATTR_TEMP(6, 5),
5083 THERMAL_SENSOR_ATTR_TEMP(7, 6),
5084 THERMAL_SENSOR_ATTR_TEMP(8, 7),
5085 THERMAL_SENSOR_ATTR_TEMP(9, 8),
5086 THERMAL_SENSOR_ATTR_TEMP(10, 9),
5087 THERMAL_SENSOR_ATTR_TEMP(11, 10),
5088 THERMAL_SENSOR_ATTR_TEMP(12, 11),
5089 THERMAL_SENSOR_ATTR_TEMP(13, 12),
5090 THERMAL_SENSOR_ATTR_TEMP(14, 13),
5091 THERMAL_SENSOR_ATTR_TEMP(15, 14),
5092 THERMAL_SENSOR_ATTR_TEMP(16, 15),
5095 #define THERMAL_ATTRS(X) \
5096 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
5098 static struct attribute
*thermal_temp_input_attr
[] = {
5118 static const struct attribute_group thermal_temp_input16_group
= {
5119 .attrs
= thermal_temp_input_attr
5122 static const struct attribute_group thermal_temp_input8_group
= {
5123 .attrs
= &thermal_temp_input_attr
[8]
5126 #undef THERMAL_SENSOR_ATTR_TEMP
5127 #undef THERMAL_ATTRS
5129 /* --------------------------------------------------------------------- */
5131 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
5138 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
5140 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
5142 if (thinkpad_id
.ec_model
) {
5144 * Direct EC access mode: sensors at registers
5145 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
5146 * non-implemented, thermal sensors return 0x80 when
5151 for (i
= 0; i
< 8; i
++) {
5152 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
5158 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
5166 /* This is sheer paranoia, but we handle it anyway */
5169 "ThinkPad ACPI EC access misbehaving, "
5170 "falling back to ACPI TMPx access "
5172 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5175 "ThinkPad ACPI EC access misbehaving, "
5176 "disabling thermal sensors access\n");
5177 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5182 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
5184 } else if (acpi_tmp7
) {
5185 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
5186 /* 600e/x, 770e, 770x */
5187 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
5189 /* Standard ACPI TMPx access, max 8 sensors */
5190 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5193 /* temperatures not supported on 570, G4x, R30, R31, R32 */
5194 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5197 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
5198 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
5201 switch (thermal_read_mode
) {
5202 case TPACPI_THERMAL_TPEC_16
:
5203 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5204 &thermal_temp_input16_group
);
5208 case TPACPI_THERMAL_TPEC_8
:
5209 case TPACPI_THERMAL_ACPI_TMP07
:
5210 case TPACPI_THERMAL_ACPI_UPDT
:
5211 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5212 &thermal_temp_input8_group
);
5216 case TPACPI_THERMAL_NONE
:
5224 static void thermal_exit(void)
5226 switch (thermal_read_mode
) {
5227 case TPACPI_THERMAL_TPEC_16
:
5228 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5229 &thermal_temp_input16_group
);
5231 case TPACPI_THERMAL_TPEC_8
:
5232 case TPACPI_THERMAL_ACPI_TMP07
:
5233 case TPACPI_THERMAL_ACPI_UPDT
:
5234 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5235 &thermal_temp_input16_group
);
5237 case TPACPI_THERMAL_NONE
:
5243 static int thermal_read(char *p
)
5247 struct ibm_thermal_sensors_struct t
;
5249 n
= thermal_get_sensors(&t
);
5250 if (unlikely(n
< 0))
5253 len
+= sprintf(p
+ len
, "temperatures:\t");
5256 for (i
= 0; i
< (n
- 1); i
++)
5257 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
5258 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
5260 len
+= sprintf(p
+ len
, "not supported\n");
5265 static struct ibm_struct thermal_driver_data
= {
5267 .read
= thermal_read
,
5268 .exit
= thermal_exit
,
5271 /*************************************************************************
5275 static u8 ecdump_regs
[256];
5277 static int ecdump_read(char *p
)
5283 len
+= sprintf(p
+ len
, "EC "
5284 " +00 +01 +02 +03 +04 +05 +06 +07"
5285 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
5286 for (i
= 0; i
< 256; i
+= 16) {
5287 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
5288 for (j
= 0; j
< 16; j
++) {
5289 if (!acpi_ec_read(i
+ j
, &v
))
5291 if (v
!= ecdump_regs
[i
+ j
])
5292 len
+= sprintf(p
+ len
, " *%02x", v
);
5294 len
+= sprintf(p
+ len
, " %02x", v
);
5295 ecdump_regs
[i
+ j
] = v
;
5297 len
+= sprintf(p
+ len
, "\n");
5302 /* These are way too dangerous to advertise openly... */
5304 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
5305 " (<offset> is 00-ff, <value> is 00-ff)\n");
5306 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
5307 " (<offset> is 00-ff, <value> is 0-255)\n");
5312 static int ecdump_write(char *buf
)
5317 while ((cmd
= next_cmd(&buf
))) {
5318 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
5320 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
5324 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
5325 if (!acpi_ec_write(i
, v
))
5334 static struct ibm_struct ecdump_driver_data
= {
5336 .read
= ecdump_read
,
5337 .write
= ecdump_write
,
5338 .flags
.experimental
= 1,
5341 /*************************************************************************
5342 * Backlight/brightness subdriver
5345 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
5348 TP_EC_BACKLIGHT
= 0x31,
5350 /* TP_EC_BACKLIGHT bitmasks */
5351 TP_EC_BACKLIGHT_LVLMSK
= 0x1F,
5352 TP_EC_BACKLIGHT_CMDMSK
= 0xE0,
5353 TP_EC_BACKLIGHT_MAPSW
= 0x20,
5356 static struct backlight_device
*ibm_backlight_device
;
5357 static int brightness_mode
;
5358 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
5360 static struct mutex brightness_mutex
;
5363 * ThinkPads can read brightness from two places: EC 0x31, or
5364 * CMOS NVRAM byte 0x5E, bits 0-3.
5366 * EC 0x31 has the following layout
5367 * Bit 7: unknown function
5368 * Bit 6: unknown function
5369 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
5370 * Bit 4: must be set to zero to avoid problems
5371 * Bit 3-0: backlight brightness level
5373 * brightness_get_raw returns status data in the EC 0x31 layout
5375 static int brightness_get_raw(int *status
)
5377 u8 lec
= 0, lcmos
= 0, level
= 0;
5379 if (brightness_mode
& 1) {
5380 if (!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
))
5382 level
= lec
& TP_EC_BACKLIGHT_LVLMSK
;
5384 if (brightness_mode
& 2) {
5385 lcmos
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
5386 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5387 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
5388 lcmos
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
5392 if (brightness_mode
== 3) {
5393 *status
= lec
; /* Prefer EC, CMOS is just a backing store */
5394 lec
&= TP_EC_BACKLIGHT_LVLMSK
;
5396 tp_warned
.bright_cmos_ec_unsync
= 0;
5398 if (!tp_warned
.bright_cmos_ec_unsync
) {
5400 "CMOS NVRAM (%u) and EC (%u) do not "
5401 "agree on display brightness level\n",
5402 (unsigned int) lcmos
,
5403 (unsigned int) lec
);
5404 tp_warned
.bright_cmos_ec_unsync
= 1;
5415 /* May return EINTR which can always be mapped to ERESTARTSYS */
5416 static int brightness_set(int value
)
5418 int cmos_cmd
, inc
, i
, res
;
5422 if (value
> ((tp_features
.bright_16levels
)? 15 : 7) ||
5426 res
= mutex_lock_killable(&brightness_mutex
);
5430 res
= brightness_get_raw(¤t_value
);
5434 command_bits
= current_value
& TP_EC_BACKLIGHT_CMDMSK
;
5435 current_value
&= TP_EC_BACKLIGHT_LVLMSK
;
5437 cmos_cmd
= value
> current_value
?
5438 TP_CMOS_BRIGHTNESS_UP
:
5439 TP_CMOS_BRIGHTNESS_DOWN
;
5440 inc
= (value
> current_value
)? 1 : -1;
5443 for (i
= current_value
; i
!= value
; i
+= inc
) {
5444 if ((brightness_mode
& 2) &&
5445 issue_thinkpad_cmos_command(cmos_cmd
)) {
5449 if ((brightness_mode
& 1) &&
5450 !acpi_ec_write(TP_EC_BACKLIGHT
,
5451 (i
+ inc
) | command_bits
)) {
5458 mutex_unlock(&brightness_mutex
);
5462 /* sysfs backlight class ----------------------------------------------- */
5464 static int brightness_update_status(struct backlight_device
*bd
)
5466 /* it is the backlight class's job (caller) to handle
5467 * EINTR and other errors properly */
5468 return brightness_set(
5469 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
5470 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
5471 bd
->props
.brightness
: 0);
5474 static int brightness_get(struct backlight_device
*bd
)
5478 res
= brightness_get_raw(&status
);
5480 return 0; /* FIXME: teach backlight about error handling */
5482 return status
& TP_EC_BACKLIGHT_LVLMSK
;
5485 static struct backlight_ops ibm_backlight_data
= {
5486 .get_brightness
= brightness_get
,
5487 .update_status
= brightness_update_status
,
5490 /* --------------------------------------------------------------------- */
5492 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
5496 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
5498 mutex_init(&brightness_mutex
);
5501 * We always attempt to detect acpi support, so as to switch
5502 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
5503 * going to publish a backlight interface
5505 b
= tpacpi_check_std_acpi_brightness_support();
5508 if (acpi_video_backlight_support()) {
5509 if (brightness_enable
> 1) {
5510 printk(TPACPI_NOTICE
5511 "Standard ACPI backlight interface "
5512 "available, not loading native one.\n");
5514 } else if (brightness_enable
== 1) {
5515 printk(TPACPI_NOTICE
5516 "Backlight control force enabled, even if standard "
5517 "ACPI backlight interface is available\n");
5520 if (brightness_enable
> 1) {
5521 printk(TPACPI_NOTICE
5522 "Standard ACPI backlight interface not "
5523 "available, thinkpad_acpi native "
5524 "brightness control enabled\n");
5529 if (!brightness_enable
) {
5530 dbg_printk(TPACPI_DBG_INIT
,
5531 "brightness support disabled by "
5532 "module parameter\n");
5538 "Unsupported brightness interface, "
5539 "please contact %s\n", TPACPI_MAIL
);
5543 tp_features
.bright_16levels
= 1;
5545 if (!brightness_mode
) {
5546 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
)
5547 brightness_mode
= 2;
5549 brightness_mode
= 3;
5551 dbg_printk(TPACPI_DBG_INIT
, "selected brightness_mode=%d\n",
5555 if (brightness_mode
> 3)
5558 if (brightness_get_raw(&b
) < 0)
5561 if (tp_features
.bright_16levels
)
5563 "detected a 16-level brightness capable ThinkPad\n");
5565 ibm_backlight_device
= backlight_device_register(
5566 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
5567 &ibm_backlight_data
);
5568 if (IS_ERR(ibm_backlight_device
)) {
5569 printk(TPACPI_ERR
"Could not register backlight device\n");
5570 return PTR_ERR(ibm_backlight_device
);
5572 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
5574 ibm_backlight_device
->props
.max_brightness
=
5575 (tp_features
.bright_16levels
)? 15 : 7;
5576 ibm_backlight_device
->props
.brightness
= b
& TP_EC_BACKLIGHT_LVLMSK
;
5577 backlight_update_status(ibm_backlight_device
);
5582 static void brightness_exit(void)
5584 if (ibm_backlight_device
) {
5585 vdbg_printk(TPACPI_DBG_EXIT
,
5586 "calling backlight_device_unregister()\n");
5587 backlight_device_unregister(ibm_backlight_device
);
5591 static int brightness_read(char *p
)
5596 level
= brightness_get(NULL
);
5598 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
5600 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
5601 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
5602 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
5603 " (<level> is 0-%d)\n",
5604 (tp_features
.bright_16levels
) ? 15 : 7);
5610 static int brightness_write(char *buf
)
5615 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
5617 level
= brightness_get(NULL
);
5621 while ((cmd
= next_cmd(&buf
))) {
5622 if (strlencmp(cmd
, "up") == 0) {
5623 if (level
< max_level
)
5625 } else if (strlencmp(cmd
, "down") == 0) {
5628 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
5629 level
>= 0 && level
<= max_level
) {
5636 * Now we know what the final level should be, so we try to set it.
5637 * Doing it this way makes the syscall restartable in case of EINTR
5639 rc
= brightness_set(level
);
5640 return (rc
== -EINTR
)? ERESTARTSYS
: rc
;
5643 static struct ibm_struct brightness_driver_data
= {
5644 .name
= "brightness",
5645 .read
= brightness_read
,
5646 .write
= brightness_write
,
5647 .exit
= brightness_exit
,
5650 /*************************************************************************
5654 static int volume_offset
= 0x30;
5656 static int volume_read(char *p
)
5661 if (!acpi_ec_read(volume_offset
, &level
)) {
5662 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
5664 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
5665 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
5666 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
5667 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
5668 " (<level> is 0-15)\n");
5674 static int volume_write(char *buf
)
5676 int cmos_cmd
, inc
, i
;
5678 int new_level
, new_mute
;
5681 while ((cmd
= next_cmd(&buf
))) {
5682 if (!acpi_ec_read(volume_offset
, &level
))
5684 new_mute
= mute
= level
& 0x40;
5685 new_level
= level
= level
& 0xf;
5687 if (strlencmp(cmd
, "up") == 0) {
5691 new_level
= level
== 15 ? 15 : level
+ 1;
5692 } else if (strlencmp(cmd
, "down") == 0) {
5696 new_level
= level
== 0 ? 0 : level
- 1;
5697 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
5698 new_level
>= 0 && new_level
<= 15) {
5700 } else if (strlencmp(cmd
, "mute") == 0) {
5705 if (new_level
!= level
) {
5706 /* mute doesn't change */
5708 cmos_cmd
= (new_level
> level
) ?
5709 TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
5710 inc
= new_level
> level
? 1 : -1;
5712 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
5713 !acpi_ec_write(volume_offset
, level
)))
5716 for (i
= level
; i
!= new_level
; i
+= inc
)
5717 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
5718 !acpi_ec_write(volume_offset
, i
+ inc
))
5722 (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
5723 !acpi_ec_write(volume_offset
, new_level
+ mute
))) {
5728 if (new_mute
!= mute
) {
5729 /* level doesn't change */
5731 cmos_cmd
= (new_mute
) ?
5732 TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
5734 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
5735 !acpi_ec_write(volume_offset
, level
+ new_mute
))
5743 static struct ibm_struct volume_driver_data
= {
5745 .read
= volume_read
,
5746 .write
= volume_write
,
5749 /*************************************************************************
5756 * TPACPI_FAN_RD_ACPI_GFAN:
5757 * ACPI GFAN method: returns fan level
5759 * see TPACPI_FAN_WR_ACPI_SFAN
5760 * EC 0x2f (HFSP) not available if GFAN exists
5762 * TPACPI_FAN_WR_ACPI_SFAN:
5763 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
5765 * EC 0x2f (HFSP) might be available *for reading*, but do not use
5768 * TPACPI_FAN_WR_TPEC:
5769 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
5770 * Supported on almost all ThinkPads
5772 * Fan speed changes of any sort (including those caused by the
5773 * disengaged mode) are usually done slowly by the firmware as the
5774 * maximum ammount of fan duty cycle change per second seems to be
5777 * Reading is not available if GFAN exists.
5778 * Writing is not available if SFAN exists.
5781 * 7 automatic mode engaged;
5782 * (default operation mode of the ThinkPad)
5783 * fan level is ignored in this mode.
5784 * 6 full speed mode (takes precedence over bit 7);
5785 * not available on all thinkpads. May disable
5786 * the tachometer while the fan controller ramps up
5787 * the speed (which can take up to a few *minutes*).
5788 * Speeds up fan to 100% duty-cycle, which is far above
5789 * the standard RPM levels. It is not impossible that
5790 * it could cause hardware damage.
5791 * 5-3 unused in some models. Extra bits for fan level
5792 * in others, but still useless as all values above
5793 * 7 map to the same speed as level 7 in these models.
5794 * 2-0 fan level (0..7 usually)
5796 * 0x07 = max (set when temperatures critical)
5797 * Some ThinkPads may have other levels, see
5798 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
5800 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
5801 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
5802 * does so, its initial value is meaningless (0x07).
5804 * For firmware bugs, refer to:
5805 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
5809 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
5810 * Main fan tachometer reading (in RPM)
5812 * This register is present on all ThinkPads with a new-style EC, and
5813 * it is known not to be present on the A21m/e, and T22, as there is
5814 * something else in offset 0x84 according to the ACPI DSDT. Other
5815 * ThinkPads from this same time period (and earlier) probably lack the
5816 * tachometer as well.
5818 * Unfortunately a lot of ThinkPads with new-style ECs but whose firmware
5819 * was never fixed by IBM to report the EC firmware version string
5820 * probably support the tachometer (like the early X models), so
5821 * detecting it is quite hard. We need more data to know for sure.
5823 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
5826 * FIRMWARE BUG: may go stale while the EC is switching to full speed
5829 * For firmware bugs, refer to:
5830 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
5832 * TPACPI_FAN_WR_ACPI_FANS:
5833 * ThinkPad X31, X40, X41. Not available in the X60.
5835 * FANS ACPI handle: takes three arguments: low speed, medium speed,
5836 * high speed. ACPI DSDT seems to map these three speeds to levels
5837 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
5838 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
5840 * The speeds are stored on handles
5841 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
5843 * There are three default speed sets, acessible as handles:
5844 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
5846 * ACPI DSDT switches which set is in use depending on various
5849 * TPACPI_FAN_WR_TPEC is also available and should be used to
5850 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
5851 * but the ACPI tables just mention level 7.
5854 enum { /* Fan control constants */
5855 fan_status_offset
= 0x2f, /* EC register 0x2f */
5856 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
5857 * 0x84 must be read before 0x85 */
5859 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
5860 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
5862 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
5865 enum fan_status_access_mode
{
5866 TPACPI_FAN_NONE
= 0, /* No fan status or control */
5867 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
5868 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
5871 enum fan_control_access_mode
{
5872 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
5873 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
5874 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
5875 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
5878 enum fan_control_commands
{
5879 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
5880 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
5881 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
5882 * and also watchdog cmd */
5885 static int fan_control_allowed
;
5887 static enum fan_status_access_mode fan_status_access_mode
;
5888 static enum fan_control_access_mode fan_control_access_mode
;
5889 static enum fan_control_commands fan_control_commands
;
5891 static u8 fan_control_initial_status
;
5892 static u8 fan_control_desired_level
;
5893 static u8 fan_control_resume_level
;
5894 static int fan_watchdog_maxinterval
;
5896 static struct mutex fan_mutex
;
5898 static void fan_watchdog_fire(struct work_struct
*ignored
);
5899 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
5901 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
5902 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
5903 "\\FSPD", /* 600e/x, 770e, 770x */
5905 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
5906 "JFNS", /* 770x-JL */
5910 * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the
5911 * HFSP register at boot, so it contains 0x07 but the Thinkpad could
5912 * be in auto mode (0x80).
5914 * This is corrected by any write to HFSP either by the driver, or
5917 * We assume 0x07 really means auto mode while this quirk is active,
5918 * as this is far more likely than the ThinkPad being in level 7,
5919 * which is only used by the firmware during thermal emergencies.
5922 static void fan_quirk1_detect(void)
5924 /* In some ThinkPads, neither the EC nor the ACPI
5925 * DSDT initialize the HFSP register, and it ends up
5926 * being initially set to 0x07 when it *could* be
5927 * either 0x07 or 0x80.
5929 * Enable for TP-1Y (T43), TP-78 (R51e),
5930 * TP-76 (R52), TP-70 (T43, R52), which are known
5932 if (fan_control_initial_status
== 0x07) {
5933 switch (thinkpad_id
.ec_model
) {
5934 case 0x5931: /* TP-1Y */
5935 case 0x3837: /* TP-78 */
5936 case 0x3637: /* TP-76 */
5937 case 0x3037: /* TP-70 */
5938 printk(TPACPI_NOTICE
5939 "fan_init: initial fan status is unknown, "
5940 "assuming it is in auto mode\n");
5941 tp_features
.fan_ctrl_status_undef
= 1;
5947 static void fan_quirk1_handle(u8
*fan_status
)
5949 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
5950 if (*fan_status
!= fan_control_initial_status
) {
5951 /* something changed the HFSP regisnter since
5952 * driver init time, so it is not undefined
5954 tp_features
.fan_ctrl_status_undef
= 0;
5956 /* Return most likely status. In fact, it
5957 * might be the only possible status */
5958 *fan_status
= TP_EC_FAN_AUTO
;
5964 * Call with fan_mutex held
5966 static void fan_update_desired_level(u8 status
)
5969 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
5971 fan_control_desired_level
= 7;
5973 fan_control_desired_level
= status
;
5977 static int fan_get_status(u8
*status
)
5982 * Add TPACPI_FAN_RD_ACPI_FANS ? */
5984 switch (fan_status_access_mode
) {
5985 case TPACPI_FAN_RD_ACPI_GFAN
:
5986 /* 570, 600e/x, 770e, 770x */
5988 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
5996 case TPACPI_FAN_RD_TPEC
:
5997 /* all except 570, 600e/x, 770e, 770x */
5998 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
6001 if (likely(status
)) {
6003 fan_quirk1_handle(status
);
6015 static int fan_get_status_safe(u8
*status
)
6020 if (mutex_lock_killable(&fan_mutex
))
6021 return -ERESTARTSYS
;
6022 rc
= fan_get_status(&s
);
6024 fan_update_desired_level(s
);
6025 mutex_unlock(&fan_mutex
);
6033 static int fan_get_speed(unsigned int *speed
)
6037 switch (fan_status_access_mode
) {
6038 case TPACPI_FAN_RD_TPEC
:
6039 /* all except 570, 600e/x, 770e, 770x */
6040 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
6041 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
6045 *speed
= (hi
<< 8) | lo
;
6056 static int fan_set_level(int level
)
6058 if (!fan_control_allowed
)
6061 switch (fan_control_access_mode
) {
6062 case TPACPI_FAN_WR_ACPI_SFAN
:
6063 if (level
>= 0 && level
<= 7) {
6064 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
6070 case TPACPI_FAN_WR_ACPI_FANS
:
6071 case TPACPI_FAN_WR_TPEC
:
6072 if (!(level
& TP_EC_FAN_AUTO
) &&
6073 !(level
& TP_EC_FAN_FULLSPEED
) &&
6074 ((level
< 0) || (level
> 7)))
6077 /* safety net should the EC not support AUTO
6078 * or FULLSPEED mode bits and just ignore them */
6079 if (level
& TP_EC_FAN_FULLSPEED
)
6080 level
|= 7; /* safety min speed 7 */
6081 else if (level
& TP_EC_FAN_AUTO
)
6082 level
|= 4; /* safety min speed 4 */
6084 if (!acpi_ec_write(fan_status_offset
, level
))
6087 tp_features
.fan_ctrl_status_undef
= 0;
6096 static int fan_set_level_safe(int level
)
6100 if (!fan_control_allowed
)
6103 if (mutex_lock_killable(&fan_mutex
))
6104 return -ERESTARTSYS
;
6106 if (level
== TPACPI_FAN_LAST_LEVEL
)
6107 level
= fan_control_desired_level
;
6109 rc
= fan_set_level(level
);
6111 fan_update_desired_level(level
);
6113 mutex_unlock(&fan_mutex
);
6117 static int fan_set_enable(void)
6122 if (!fan_control_allowed
)
6125 if (mutex_lock_killable(&fan_mutex
))
6126 return -ERESTARTSYS
;
6128 switch (fan_control_access_mode
) {
6129 case TPACPI_FAN_WR_ACPI_FANS
:
6130 case TPACPI_FAN_WR_TPEC
:
6131 rc
= fan_get_status(&s
);
6135 /* Don't go out of emergency fan mode */
6138 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
6141 if (!acpi_ec_write(fan_status_offset
, s
))
6144 tp_features
.fan_ctrl_status_undef
= 0;
6149 case TPACPI_FAN_WR_ACPI_SFAN
:
6150 rc
= fan_get_status(&s
);
6156 /* Set fan to at least level 4 */
6159 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
6169 mutex_unlock(&fan_mutex
);
6173 static int fan_set_disable(void)
6177 if (!fan_control_allowed
)
6180 if (mutex_lock_killable(&fan_mutex
))
6181 return -ERESTARTSYS
;
6184 switch (fan_control_access_mode
) {
6185 case TPACPI_FAN_WR_ACPI_FANS
:
6186 case TPACPI_FAN_WR_TPEC
:
6187 if (!acpi_ec_write(fan_status_offset
, 0x00))
6190 fan_control_desired_level
= 0;
6191 tp_features
.fan_ctrl_status_undef
= 0;
6195 case TPACPI_FAN_WR_ACPI_SFAN
:
6196 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
6199 fan_control_desired_level
= 0;
6207 mutex_unlock(&fan_mutex
);
6211 static int fan_set_speed(int speed
)
6215 if (!fan_control_allowed
)
6218 if (mutex_lock_killable(&fan_mutex
))
6219 return -ERESTARTSYS
;
6222 switch (fan_control_access_mode
) {
6223 case TPACPI_FAN_WR_ACPI_FANS
:
6224 if (speed
>= 0 && speed
<= 65535) {
6225 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
6226 speed
, speed
, speed
))
6236 mutex_unlock(&fan_mutex
);
6240 static void fan_watchdog_reset(void)
6242 static int fan_watchdog_active
;
6244 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
6247 if (fan_watchdog_active
)
6248 cancel_delayed_work(&fan_watchdog_task
);
6250 if (fan_watchdog_maxinterval
> 0 &&
6251 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
6252 fan_watchdog_active
= 1;
6253 if (!queue_delayed_work(tpacpi_wq
, &fan_watchdog_task
,
6254 msecs_to_jiffies(fan_watchdog_maxinterval
6257 "failed to queue the fan watchdog, "
6258 "watchdog will not trigger\n");
6261 fan_watchdog_active
= 0;
6264 static void fan_watchdog_fire(struct work_struct
*ignored
)
6268 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
6271 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
6272 rc
= fan_set_enable();
6274 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
6275 "will try again later...\n", -rc
);
6276 /* reschedule for later */
6277 fan_watchdog_reset();
6282 * SYSFS fan layout: hwmon compatible (device)
6285 * 0: "disengaged" mode
6287 * 2: native EC "auto" mode (recommended, hardware default)
6289 * pwm*: set speed in manual mode, ignored otherwise.
6290 * 0 is level 0; 255 is level 7. Intermediate points done with linear
6293 * fan*_input: tachometer reading, RPM
6296 * SYSFS fan layout: extensions
6298 * fan_watchdog (driver):
6299 * fan watchdog interval in seconds, 0 disables (default), max 120
6302 /* sysfs fan pwm1_enable ----------------------------------------------- */
6303 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
6304 struct device_attribute
*attr
,
6310 res
= fan_get_status_safe(&status
);
6314 if (status
& TP_EC_FAN_FULLSPEED
) {
6316 } else if (status
& TP_EC_FAN_AUTO
) {
6321 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
6324 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
6325 struct device_attribute
*attr
,
6326 const char *buf
, size_t count
)
6331 if (parse_strtoul(buf
, 2, &t
))
6336 level
= TP_EC_FAN_FULLSPEED
;
6339 level
= TPACPI_FAN_LAST_LEVEL
;
6342 level
= TP_EC_FAN_AUTO
;
6345 /* reserved for software-controlled auto mode */
6351 res
= fan_set_level_safe(level
);
6357 fan_watchdog_reset();
6362 static struct device_attribute dev_attr_fan_pwm1_enable
=
6363 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
6364 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
6366 /* sysfs fan pwm1 ------------------------------------------------------ */
6367 static ssize_t
fan_pwm1_show(struct device
*dev
,
6368 struct device_attribute
*attr
,
6374 res
= fan_get_status_safe(&status
);
6379 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
6380 status
= fan_control_desired_level
;
6385 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
6388 static ssize_t
fan_pwm1_store(struct device
*dev
,
6389 struct device_attribute
*attr
,
6390 const char *buf
, size_t count
)
6394 u8 status
, newlevel
;
6396 if (parse_strtoul(buf
, 255, &s
))
6399 /* scale down from 0-255 to 0-7 */
6400 newlevel
= (s
>> 5) & 0x07;
6402 if (mutex_lock_killable(&fan_mutex
))
6403 return -ERESTARTSYS
;
6405 rc
= fan_get_status(&status
);
6406 if (!rc
&& (status
&
6407 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
6408 rc
= fan_set_level(newlevel
);
6412 fan_update_desired_level(newlevel
);
6413 fan_watchdog_reset();
6417 mutex_unlock(&fan_mutex
);
6418 return (rc
)? rc
: count
;
6421 static struct device_attribute dev_attr_fan_pwm1
=
6422 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
6423 fan_pwm1_show
, fan_pwm1_store
);
6425 /* sysfs fan fan1_input ------------------------------------------------ */
6426 static ssize_t
fan_fan1_input_show(struct device
*dev
,
6427 struct device_attribute
*attr
,
6433 res
= fan_get_speed(&speed
);
6437 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
6440 static struct device_attribute dev_attr_fan_fan1_input
=
6441 __ATTR(fan1_input
, S_IRUGO
,
6442 fan_fan1_input_show
, NULL
);
6444 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
6445 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
6448 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
6451 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
6452 const char *buf
, size_t count
)
6456 if (parse_strtoul(buf
, 120, &t
))
6459 if (!fan_control_allowed
)
6462 fan_watchdog_maxinterval
= t
;
6463 fan_watchdog_reset();
6468 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
6469 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
6471 /* --------------------------------------------------------------------- */
6472 static struct attribute
*fan_attributes
[] = {
6473 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
6474 &dev_attr_fan_fan1_input
.attr
,
6478 static const struct attribute_group fan_attr_group
= {
6479 .attrs
= fan_attributes
,
6482 static int __init
fan_init(struct ibm_init_struct
*iibm
)
6486 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
6488 mutex_init(&fan_mutex
);
6489 fan_status_access_mode
= TPACPI_FAN_NONE
;
6490 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
6491 fan_control_commands
= 0;
6492 fan_watchdog_maxinterval
= 0;
6493 tp_features
.fan_ctrl_status_undef
= 0;
6494 fan_control_desired_level
= 7;
6496 TPACPI_ACPIHANDLE_INIT(fans
);
6497 TPACPI_ACPIHANDLE_INIT(gfan
);
6498 TPACPI_ACPIHANDLE_INIT(sfan
);
6501 /* 570, 600e/x, 770e, 770x */
6502 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
6504 /* all other ThinkPads: note that even old-style
6505 * ThinkPad ECs supports the fan control register */
6506 if (likely(acpi_ec_read(fan_status_offset
,
6507 &fan_control_initial_status
))) {
6508 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
6509 fan_quirk1_detect();
6512 "ThinkPad ACPI EC access misbehaving, "
6513 "fan status and control unavailable\n");
6520 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
6521 fan_control_commands
|=
6522 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
6525 /* gfan without sfan means no fan control */
6526 /* all other models implement TP EC 0x2f control */
6530 fan_control_access_mode
=
6531 TPACPI_FAN_WR_ACPI_FANS
;
6532 fan_control_commands
|=
6533 TPACPI_FAN_CMD_SPEED
|
6534 TPACPI_FAN_CMD_LEVEL
|
6535 TPACPI_FAN_CMD_ENABLE
;
6537 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
6538 fan_control_commands
|=
6539 TPACPI_FAN_CMD_LEVEL
|
6540 TPACPI_FAN_CMD_ENABLE
;
6545 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
6546 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
6547 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
6548 fan_status_access_mode
, fan_control_access_mode
);
6550 /* fan control master switch */
6551 if (!fan_control_allowed
) {
6552 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
6553 fan_control_commands
= 0;
6554 dbg_printk(TPACPI_DBG_INIT
,
6555 "fan control features disabled by parameter\n");
6558 /* update fan_control_desired_level */
6559 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
6560 fan_get_status_safe(NULL
);
6562 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
6563 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
6564 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
6569 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
6570 &driver_attr_fan_watchdog
);
6572 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
6581 static void fan_exit(void)
6583 vdbg_printk(TPACPI_DBG_EXIT
,
6584 "cancelling any pending fan watchdog tasks\n");
6586 /* FIXME: can we really do this unconditionally? */
6587 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
6588 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
6589 &driver_attr_fan_watchdog
);
6591 cancel_delayed_work(&fan_watchdog_task
);
6592 flush_workqueue(tpacpi_wq
);
6595 static void fan_suspend(pm_message_t state
)
6599 if (!fan_control_allowed
)
6602 /* Store fan status in cache */
6603 fan_control_resume_level
= 0;
6604 rc
= fan_get_status_safe(&fan_control_resume_level
);
6606 printk(TPACPI_NOTICE
6607 "failed to read fan level for later "
6608 "restore during resume: %d\n", rc
);
6610 /* if it is undefined, don't attempt to restore it.
6612 if (tp_features
.fan_ctrl_status_undef
)
6613 fan_control_resume_level
= 0;
6616 static void fan_resume(void)
6618 u8 current_level
= 7;
6619 bool do_set
= false;
6622 /* DSDT *always* updates status on resume */
6623 tp_features
.fan_ctrl_status_undef
= 0;
6625 if (!fan_control_allowed
||
6626 !fan_control_resume_level
||
6627 (fan_get_status_safe(¤t_level
) < 0))
6630 switch (fan_control_access_mode
) {
6631 case TPACPI_FAN_WR_ACPI_SFAN
:
6632 /* never decrease fan level */
6633 do_set
= (fan_control_resume_level
> current_level
);
6635 case TPACPI_FAN_WR_ACPI_FANS
:
6636 case TPACPI_FAN_WR_TPEC
:
6637 /* never decrease fan level, scale is:
6638 * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO
6640 * We expect the firmware to set either 7 or AUTO, but we
6641 * handle FULLSPEED out of paranoia.
6643 * So, we can safely only restore FULLSPEED or 7, anything
6644 * else could slow the fan. Restoring AUTO is useless, at
6645 * best that's exactly what the DSDT already set (it is the
6648 * Always keep in mind that the DSDT *will* have set the
6649 * fans to what the vendor supposes is the best level. We
6650 * muck with it only to speed the fan up.
6652 if (fan_control_resume_level
!= 7 &&
6653 !(fan_control_resume_level
& TP_EC_FAN_FULLSPEED
))
6656 do_set
= !(current_level
& TP_EC_FAN_FULLSPEED
) &&
6657 (current_level
!= fan_control_resume_level
);
6663 printk(TPACPI_NOTICE
6664 "restoring fan level to 0x%02x\n",
6665 fan_control_resume_level
);
6666 rc
= fan_set_level_safe(fan_control_resume_level
);
6668 printk(TPACPI_NOTICE
6669 "failed to restore fan level: %d\n", rc
);
6673 static int fan_read(char *p
)
6678 unsigned int speed
= 0;
6680 switch (fan_status_access_mode
) {
6681 case TPACPI_FAN_RD_ACPI_GFAN
:
6682 /* 570, 600e/x, 770e, 770x */
6683 rc
= fan_get_status_safe(&status
);
6687 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
6689 (status
!= 0) ? "enabled" : "disabled", status
);
6692 case TPACPI_FAN_RD_TPEC
:
6693 /* all except 570, 600e/x, 770e, 770x */
6694 rc
= fan_get_status_safe(&status
);
6698 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
6699 (status
!= 0) ? "enabled" : "disabled");
6701 rc
= fan_get_speed(&speed
);
6705 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
6707 if (status
& TP_EC_FAN_FULLSPEED
)
6708 /* Disengaged mode takes precedence */
6709 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
6710 else if (status
& TP_EC_FAN_AUTO
)
6711 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
6713 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
6716 case TPACPI_FAN_NONE
:
6718 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
6721 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
6722 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
6724 switch (fan_control_access_mode
) {
6725 case TPACPI_FAN_WR_ACPI_SFAN
:
6726 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
6730 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
6731 "auto, disengaged, full-speed)\n");
6736 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
6737 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
6738 "commands:\twatchdog <timeout> (<timeout> "
6739 "is 0 (off), 1-120 (seconds))\n");
6741 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
6742 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
6743 " (<speed> is 0-65535)\n");
6748 static int fan_write_cmd_level(const char *cmd
, int *rc
)
6752 if (strlencmp(cmd
, "level auto") == 0)
6753 level
= TP_EC_FAN_AUTO
;
6754 else if ((strlencmp(cmd
, "level disengaged") == 0) |
6755 (strlencmp(cmd
, "level full-speed") == 0))
6756 level
= TP_EC_FAN_FULLSPEED
;
6757 else if (sscanf(cmd
, "level %d", &level
) != 1)
6760 *rc
= fan_set_level_safe(level
);
6762 printk(TPACPI_ERR
"level command accepted for unsupported "
6763 "access mode %d", fan_control_access_mode
);
6768 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
6770 if (strlencmp(cmd
, "enable") != 0)
6773 *rc
= fan_set_enable();
6775 printk(TPACPI_ERR
"enable command accepted for unsupported "
6776 "access mode %d", fan_control_access_mode
);
6781 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
6783 if (strlencmp(cmd
, "disable") != 0)
6786 *rc
= fan_set_disable();
6788 printk(TPACPI_ERR
"disable command accepted for unsupported "
6789 "access mode %d", fan_control_access_mode
);
6794 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
6799 * Support speed <low> <medium> <high> ? */
6801 if (sscanf(cmd
, "speed %d", &speed
) != 1)
6804 *rc
= fan_set_speed(speed
);
6806 printk(TPACPI_ERR
"speed command accepted for unsupported "
6807 "access mode %d", fan_control_access_mode
);
6812 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
6816 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
6819 if (interval
< 0 || interval
> 120)
6822 fan_watchdog_maxinterval
= interval
;
6827 static int fan_write(char *buf
)
6832 while (!rc
&& (cmd
= next_cmd(&buf
))) {
6833 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
6834 fan_write_cmd_level(cmd
, &rc
)) &&
6835 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
6836 (fan_write_cmd_enable(cmd
, &rc
) ||
6837 fan_write_cmd_disable(cmd
, &rc
) ||
6838 fan_write_cmd_watchdog(cmd
, &rc
))) &&
6839 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
6840 fan_write_cmd_speed(cmd
, &rc
))
6844 fan_watchdog_reset();
6850 static struct ibm_struct fan_driver_data
= {
6855 .suspend
= fan_suspend
,
6856 .resume
= fan_resume
,
6859 /****************************************************************************
6860 ****************************************************************************
6864 ****************************************************************************
6865 ****************************************************************************/
6867 /* sysfs name ---------------------------------------------------------- */
6868 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
6869 struct device_attribute
*attr
,
6872 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
6875 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
6876 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
6878 /* --------------------------------------------------------------------- */
6881 static struct proc_dir_entry
*proc_dir
;
6884 * Module and infrastructure proble, init and exit handling
6887 static int force_load
;
6889 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
6890 static const char * __init
str_supported(int is_supported
)
6892 static char text_unsupported
[] __initdata
= "not supported";
6894 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
6896 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
6898 static void ibm_exit(struct ibm_struct
*ibm
)
6900 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
6902 list_del_init(&ibm
->all_drivers
);
6904 if (ibm
->flags
.acpi_notify_installed
) {
6905 dbg_printk(TPACPI_DBG_EXIT
,
6906 "%s: acpi_remove_notify_handler\n", ibm
->name
);
6908 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
6910 dispatch_acpi_notify
);
6911 ibm
->flags
.acpi_notify_installed
= 0;
6912 ibm
->flags
.acpi_notify_installed
= 0;
6915 if (ibm
->flags
.proc_created
) {
6916 dbg_printk(TPACPI_DBG_EXIT
,
6917 "%s: remove_proc_entry\n", ibm
->name
);
6918 remove_proc_entry(ibm
->name
, proc_dir
);
6919 ibm
->flags
.proc_created
= 0;
6922 if (ibm
->flags
.acpi_driver_registered
) {
6923 dbg_printk(TPACPI_DBG_EXIT
,
6924 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
6926 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
6927 kfree(ibm
->acpi
->driver
);
6928 ibm
->acpi
->driver
= NULL
;
6929 ibm
->flags
.acpi_driver_registered
= 0;
6932 if (ibm
->flags
.init_called
&& ibm
->exit
) {
6934 ibm
->flags
.init_called
= 0;
6937 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
6940 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
6943 struct ibm_struct
*ibm
= iibm
->data
;
6944 struct proc_dir_entry
*entry
;
6946 BUG_ON(ibm
== NULL
);
6948 INIT_LIST_HEAD(&ibm
->all_drivers
);
6950 if (ibm
->flags
.experimental
&& !experimental
)
6953 dbg_printk(TPACPI_DBG_INIT
,
6954 "probing for %s\n", ibm
->name
);
6957 ret
= iibm
->init(iibm
);
6959 return 0; /* probe failed */
6963 ibm
->flags
.init_called
= 1;
6967 if (ibm
->acpi
->hid
) {
6968 ret
= register_tpacpi_subdriver(ibm
);
6973 if (ibm
->acpi
->notify
) {
6974 ret
= setup_acpi_notify(ibm
);
6975 if (ret
== -ENODEV
) {
6976 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
6986 dbg_printk(TPACPI_DBG_INIT
,
6987 "%s installed\n", ibm
->name
);
6990 entry
= create_proc_entry(ibm
->name
,
6991 S_IFREG
| S_IRUGO
| S_IWUSR
,
6994 printk(TPACPI_ERR
"unable to create proc entry %s\n",
6999 entry
->owner
= THIS_MODULE
;
7001 entry
->read_proc
= &dispatch_procfs_read
;
7003 entry
->write_proc
= &dispatch_procfs_write
;
7004 ibm
->flags
.proc_created
= 1;
7007 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
7012 dbg_printk(TPACPI_DBG_INIT
,
7013 "%s: at error exit path with result %d\n",
7017 return (ret
< 0)? ret
: 0;
7022 /* returns 0 - probe ok, or < 0 - probe error.
7023 * Probe ok doesn't mean thinkpad found.
7024 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
7025 static int __must_check __init
get_thinkpad_model_data(
7026 struct thinkpad_id_data
*tp
)
7028 const struct dmi_device
*dev
= NULL
;
7029 char ec_fw_string
[18];
7035 memset(tp
, 0, sizeof(*tp
));
7037 if (dmi_name_in_vendors("IBM"))
7038 tp
->vendor
= PCI_VENDOR_ID_IBM
;
7039 else if (dmi_name_in_vendors("LENOVO"))
7040 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
7044 s
= dmi_get_system_info(DMI_BIOS_VERSION
);
7045 tp
->bios_version_str
= kstrdup(s
, GFP_KERNEL
);
7046 if (s
&& !tp
->bios_version_str
)
7048 if (!tp
->bios_version_str
)
7050 tp
->bios_model
= tp
->bios_version_str
[0]
7051 | (tp
->bios_version_str
[1] << 8);
7054 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
7055 * X32 or newer, all Z series; Some models must have an
7056 * up-to-date BIOS or they will not be detected.
7058 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
7060 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
7061 if (sscanf(dev
->name
,
7062 "IBM ThinkPad Embedded Controller -[%17c",
7063 ec_fw_string
) == 1) {
7064 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
7065 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
7067 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
7068 if (!tp
->ec_version_str
)
7070 tp
->ec_model
= ec_fw_string
[0]
7071 | (ec_fw_string
[1] << 8);
7076 s
= dmi_get_system_info(DMI_PRODUCT_VERSION
);
7077 if (s
&& !strnicmp(s
, "ThinkPad", 8)) {
7078 tp
->model_str
= kstrdup(s
, GFP_KERNEL
);
7083 s
= dmi_get_system_info(DMI_PRODUCT_NAME
);
7084 tp
->nummodel_str
= kstrdup(s
, GFP_KERNEL
);
7085 if (s
&& !tp
->nummodel_str
)
7091 static int __init
probe_for_thinkpad(void)
7099 * Non-ancient models have better DMI tagging, but very old models
7102 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
7104 /* ec is required because many other handles are relative to it */
7105 TPACPI_ACPIHANDLE_INIT(ec
);
7109 "Not yet supported ThinkPad detected!\n");
7114 * Risks a regression on very old machines, but reduces potential
7115 * false positives a damn great deal
7118 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
7120 if (!is_thinkpad
&& !force_load
)
7127 /* Module init, exit, parameters */
7129 static struct ibm_init_struct ibms_init
[] __initdata
= {
7131 .init
= thinkpad_acpi_driver_init
,
7132 .data
= &thinkpad_acpi_driver_data
,
7135 .init
= hotkey_init
,
7136 .data
= &hotkey_driver_data
,
7139 .init
= bluetooth_init
,
7140 .data
= &bluetooth_driver_data
,
7144 .data
= &wan_driver_data
,
7148 .data
= &uwb_driver_data
,
7150 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
7153 .data
= &video_driver_data
,
7158 .data
= &light_driver_data
,
7160 #ifdef CONFIG_THINKPAD_ACPI_DOCK
7163 .data
= &dock_driver_data
[0],
7167 .data
= &dock_driver_data
[1],
7170 #ifdef CONFIG_THINKPAD_ACPI_BAY
7173 .data
= &bay_driver_data
,
7178 .data
= &cmos_driver_data
,
7182 .data
= &led_driver_data
,
7186 .data
= &beep_driver_data
,
7189 .init
= thermal_init
,
7190 .data
= &thermal_driver_data
,
7193 .data
= &ecdump_driver_data
,
7196 .init
= brightness_init
,
7197 .data
= &brightness_driver_data
,
7200 .data
= &volume_driver_data
,
7204 .data
= &fan_driver_data
,
7208 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
7211 struct ibm_struct
*ibm
;
7213 if (!kp
|| !kp
->name
|| !val
)
7216 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
7217 ibm
= ibms_init
[i
].data
;
7218 WARN_ON(ibm
== NULL
);
7220 if (!ibm
|| !ibm
->name
)
7223 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
7224 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
7226 strcpy(ibms_init
[i
].param
, val
);
7227 strcat(ibms_init
[i
].param
, ",");
7235 module_param(experimental
, int, 0);
7236 MODULE_PARM_DESC(experimental
,
7237 "Enables experimental features when non-zero");
7239 module_param_named(debug
, dbg_level
, uint
, 0);
7240 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
7242 module_param(force_load
, bool, 0);
7243 MODULE_PARM_DESC(force_load
,
7244 "Attempts to load the driver even on a "
7245 "mis-identified ThinkPad when true");
7247 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
7248 MODULE_PARM_DESC(fan_control
,
7249 "Enables setting fan parameters features when true");
7251 module_param_named(brightness_mode
, brightness_mode
, int, 0);
7252 MODULE_PARM_DESC(brightness_mode
,
7253 "Selects brightness control strategy: "
7254 "0=auto, 1=EC, 2=CMOS, 3=both");
7256 module_param(brightness_enable
, uint
, 0);
7257 MODULE_PARM_DESC(brightness_enable
,
7258 "Enables backlight control when 1, disables when 0");
7260 module_param(hotkey_report_mode
, uint
, 0);
7261 MODULE_PARM_DESC(hotkey_report_mode
,
7262 "used for backwards compatibility with userspace, "
7263 "see documentation");
7265 #define TPACPI_PARAM(feature) \
7266 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
7267 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
7268 "at module load, see documentation")
7270 TPACPI_PARAM(hotkey
);
7271 TPACPI_PARAM(bluetooth
);
7272 TPACPI_PARAM(video
);
7273 TPACPI_PARAM(light
);
7274 #ifdef CONFIG_THINKPAD_ACPI_DOCK
7277 #ifdef CONFIG_THINKPAD_ACPI_BAY
7279 #endif /* CONFIG_THINKPAD_ACPI_BAY */
7283 TPACPI_PARAM(ecdump
);
7284 TPACPI_PARAM(brightness
);
7285 TPACPI_PARAM(volume
);
7288 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
7289 module_param(dbg_wlswemul
, uint
, 0);
7290 MODULE_PARM_DESC(dbg_wlswemul
, "Enables WLSW emulation");
7291 module_param_named(wlsw_state
, tpacpi_wlsw_emulstate
, bool, 0);
7292 MODULE_PARM_DESC(wlsw_state
,
7293 "Initial state of the emulated WLSW switch");
7295 module_param(dbg_bluetoothemul
, uint
, 0);
7296 MODULE_PARM_DESC(dbg_bluetoothemul
, "Enables bluetooth switch emulation");
7297 module_param_named(bluetooth_state
, tpacpi_bluetooth_emulstate
, bool, 0);
7298 MODULE_PARM_DESC(bluetooth_state
,
7299 "Initial state of the emulated bluetooth switch");
7301 module_param(dbg_wwanemul
, uint
, 0);
7302 MODULE_PARM_DESC(dbg_wwanemul
, "Enables WWAN switch emulation");
7303 module_param_named(wwan_state
, tpacpi_wwan_emulstate
, bool, 0);
7304 MODULE_PARM_DESC(wwan_state
,
7305 "Initial state of the emulated WWAN switch");
7307 module_param(dbg_uwbemul
, uint
, 0);
7308 MODULE_PARM_DESC(dbg_uwbemul
, "Enables UWB switch emulation");
7309 module_param_named(uwb_state
, tpacpi_uwb_emulstate
, bool, 0);
7310 MODULE_PARM_DESC(uwb_state
,
7311 "Initial state of the emulated UWB switch");
7314 static void thinkpad_acpi_module_exit(void)
7316 struct ibm_struct
*ibm
, *itmp
;
7318 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
7320 list_for_each_entry_safe_reverse(ibm
, itmp
,
7321 &tpacpi_all_drivers
,
7326 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
7328 if (tpacpi_inputdev
) {
7329 if (tp_features
.input_device_registered
)
7330 input_unregister_device(tpacpi_inputdev
);
7332 input_free_device(tpacpi_inputdev
);
7336 hwmon_device_unregister(tpacpi_hwmon
);
7338 if (tp_features
.sensors_pdev_attrs_registered
)
7339 device_remove_file(&tpacpi_sensors_pdev
->dev
,
7340 &dev_attr_thinkpad_acpi_pdev_name
);
7341 if (tpacpi_sensors_pdev
)
7342 platform_device_unregister(tpacpi_sensors_pdev
);
7344 platform_device_unregister(tpacpi_pdev
);
7346 if (tp_features
.sensors_pdrv_attrs_registered
)
7347 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
7348 if (tp_features
.platform_drv_attrs_registered
)
7349 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
7351 if (tp_features
.sensors_pdrv_registered
)
7352 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
7354 if (tp_features
.platform_drv_registered
)
7355 platform_driver_unregister(&tpacpi_pdriver
);
7358 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
7361 destroy_workqueue(tpacpi_wq
);
7363 kfree(thinkpad_id
.bios_version_str
);
7364 kfree(thinkpad_id
.ec_version_str
);
7365 kfree(thinkpad_id
.model_str
);
7369 static int __init
thinkpad_acpi_module_init(void)
7373 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
7375 /* Parameter checking */
7376 if (hotkey_report_mode
> 2)
7379 /* Driver-level probe */
7381 ret
= get_thinkpad_model_data(&thinkpad_id
);
7384 "unable to get DMI data: %d\n", ret
);
7385 thinkpad_acpi_module_exit();
7388 ret
= probe_for_thinkpad();
7390 thinkpad_acpi_module_exit();
7394 /* Driver initialization */
7396 TPACPI_ACPIHANDLE_INIT(ecrd
);
7397 TPACPI_ACPIHANDLE_INIT(ecwr
);
7399 tpacpi_wq
= create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME
);
7401 thinkpad_acpi_module_exit();
7405 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
7408 "unable to create proc dir " TPACPI_PROC_DIR
);
7409 thinkpad_acpi_module_exit();
7412 proc_dir
->owner
= THIS_MODULE
;
7414 ret
= platform_driver_register(&tpacpi_pdriver
);
7417 "unable to register main platform driver\n");
7418 thinkpad_acpi_module_exit();
7421 tp_features
.platform_drv_registered
= 1;
7423 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
7426 "unable to register hwmon platform driver\n");
7427 thinkpad_acpi_module_exit();
7430 tp_features
.sensors_pdrv_registered
= 1;
7432 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
7434 tp_features
.platform_drv_attrs_registered
= 1;
7435 ret
= tpacpi_create_driver_attributes(
7436 &tpacpi_hwmon_pdriver
.driver
);
7440 "unable to create sysfs driver attributes\n");
7441 thinkpad_acpi_module_exit();
7444 tp_features
.sensors_pdrv_attrs_registered
= 1;
7447 /* Device initialization */
7448 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
7450 if (IS_ERR(tpacpi_pdev
)) {
7451 ret
= PTR_ERR(tpacpi_pdev
);
7453 printk(TPACPI_ERR
"unable to register platform device\n");
7454 thinkpad_acpi_module_exit();
7457 tpacpi_sensors_pdev
= platform_device_register_simple(
7458 TPACPI_HWMON_DRVR_NAME
,
7460 if (IS_ERR(tpacpi_sensors_pdev
)) {
7461 ret
= PTR_ERR(tpacpi_sensors_pdev
);
7462 tpacpi_sensors_pdev
= NULL
;
7464 "unable to register hwmon platform device\n");
7465 thinkpad_acpi_module_exit();
7468 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
7469 &dev_attr_thinkpad_acpi_pdev_name
);
7472 "unable to create sysfs hwmon device attributes\n");
7473 thinkpad_acpi_module_exit();
7476 tp_features
.sensors_pdev_attrs_registered
= 1;
7477 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
7478 if (IS_ERR(tpacpi_hwmon
)) {
7479 ret
= PTR_ERR(tpacpi_hwmon
);
7480 tpacpi_hwmon
= NULL
;
7481 printk(TPACPI_ERR
"unable to register hwmon device\n");
7482 thinkpad_acpi_module_exit();
7485 mutex_init(&tpacpi_inputdev_send_mutex
);
7486 tpacpi_inputdev
= input_allocate_device();
7487 if (!tpacpi_inputdev
) {
7488 printk(TPACPI_ERR
"unable to allocate input device\n");
7489 thinkpad_acpi_module_exit();
7492 /* Prepare input device, but don't register */
7493 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
7494 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
7495 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
7496 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
7497 thinkpad_id
.vendor
:
7499 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
7500 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
7502 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
7503 ret
= ibm_init(&ibms_init
[i
]);
7504 if (ret
>= 0 && *ibms_init
[i
].param
)
7505 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
7507 thinkpad_acpi_module_exit();
7511 ret
= input_register_device(tpacpi_inputdev
);
7513 printk(TPACPI_ERR
"unable to register input device\n");
7514 thinkpad_acpi_module_exit();
7517 tp_features
.input_device_registered
= 1;
7520 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
7524 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME
);
7527 * DMI matching for module autoloading
7529 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
7530 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
7532 * Only models listed in thinkwiki will be supported, so add yours
7533 * if it is not there yet.
7535 #define IBM_BIOS_MODULE_ALIAS(__type) \
7536 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*")
7538 /* Non-ancient thinkpads */
7539 MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*");
7540 MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*");
7542 /* Ancient thinkpad BIOSes have to be identified by
7543 * BIOS type or model number, and there are far less
7544 * BIOS types than model numbers... */
7545 IBM_BIOS_MODULE_ALIAS("I[BDHIMNOTWVYZ]");
7546 IBM_BIOS_MODULE_ALIAS("1[0368A-GIKM-PST]");
7547 IBM_BIOS_MODULE_ALIAS("K[UX-Z]");
7549 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
7550 MODULE_DESCRIPTION(TPACPI_DESC
);
7551 MODULE_VERSION(TPACPI_VERSION
);
7552 MODULE_LICENSE("GPL");
7554 module_init(thinkpad_acpi_module_init
);
7555 module_exit(thinkpad_acpi_module_exit
);