2 * thinkpad_acpi.c - ThinkPad ACPI Extras
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006-2008 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #define TPACPI_VERSION "0.21"
25 #define TPACPI_SYSFS_VERSION 0x020200
29 * 2007-10-20 changelog trimmed down
31 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
34 * 2006-11-22 0.13 new maintainer
35 * changelog now lives in git commit history, and will
36 * not be updated further in-file.
38 * 2005-03-17 0.11 support for 600e, 770x
39 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
41 * 2005-01-16 0.9 use MODULE_VERSION
42 * thanks to Henrik Brix Andersen <brix@gentoo.org>
43 * fix parameter passing on module loading
44 * thanks to Rusty Russell <rusty@rustcorp.com.au>
45 * thanks to Jim Radford <radford@blackbean.org>
46 * 2004-11-08 0.8 fix init error case, don't return from a macro
47 * thanks to Chris Wright <chrisw@osdl.org>
50 #include <linux/kernel.h>
51 #include <linux/module.h>
52 #include <linux/init.h>
53 #include <linux/types.h>
54 #include <linux/string.h>
55 #include <linux/list.h>
56 #include <linux/mutex.h>
57 #include <linux/kthread.h>
58 #include <linux/freezer.h>
59 #include <linux/delay.h>
61 #include <linux/nvram.h>
62 #include <linux/proc_fs.h>
63 #include <linux/sysfs.h>
64 #include <linux/backlight.h>
66 #include <linux/platform_device.h>
67 #include <linux/hwmon.h>
68 #include <linux/hwmon-sysfs.h>
69 #include <linux/input.h>
70 #include <linux/leds.h>
71 #include <linux/rfkill.h>
72 #include <asm/uaccess.h>
74 #include <linux/dmi.h>
75 #include <linux/jiffies.h>
76 #include <linux/workqueue.h>
78 #include <acpi/acpi_drivers.h>
79 #include <acpi/acnamesp.h>
81 #include <linux/pci_ids.h>
84 /* ThinkPad CMOS commands */
85 #define TP_CMOS_VOLUME_DOWN 0
86 #define TP_CMOS_VOLUME_UP 1
87 #define TP_CMOS_VOLUME_MUTE 2
88 #define TP_CMOS_BRIGHTNESS_UP 4
89 #define TP_CMOS_BRIGHTNESS_DOWN 5
90 #define TP_CMOS_THINKLIGHT_ON 12
91 #define TP_CMOS_THINKLIGHT_OFF 13
95 TP_NVRAM_ADDR_HK2
= 0x57,
96 TP_NVRAM_ADDR_THINKLIGHT
= 0x58,
97 TP_NVRAM_ADDR_VIDEO
= 0x59,
98 TP_NVRAM_ADDR_BRIGHTNESS
= 0x5e,
99 TP_NVRAM_ADDR_MIXER
= 0x60,
102 /* NVRAM bit masks */
104 TP_NVRAM_MASK_HKT_THINKPAD
= 0x08,
105 TP_NVRAM_MASK_HKT_ZOOM
= 0x20,
106 TP_NVRAM_MASK_HKT_DISPLAY
= 0x40,
107 TP_NVRAM_MASK_HKT_HIBERNATE
= 0x80,
108 TP_NVRAM_MASK_THINKLIGHT
= 0x10,
109 TP_NVRAM_MASK_HKT_DISPEXPND
= 0x30,
110 TP_NVRAM_MASK_HKT_BRIGHTNESS
= 0x20,
111 TP_NVRAM_MASK_LEVEL_BRIGHTNESS
= 0x0f,
112 TP_NVRAM_POS_LEVEL_BRIGHTNESS
= 0,
113 TP_NVRAM_MASK_MUTE
= 0x40,
114 TP_NVRAM_MASK_HKT_VOLUME
= 0x80,
115 TP_NVRAM_MASK_LEVEL_VOLUME
= 0x0f,
116 TP_NVRAM_POS_LEVEL_VOLUME
= 0,
120 #define TPACPI_ACPI_HKEY_HID "IBM0068"
123 #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */
124 #define TPACPI_HKEY_INPUT_VERSION 0x4101
126 /* ACPI \WGSV commands */
128 TP_ACPI_WGSV_GET_STATE
= 0x01, /* Get state information */
129 TP_ACPI_WGSV_PWR_ON_ON_RESUME
= 0x02, /* Resume WWAN powered on */
130 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
= 0x03, /* Resume WWAN powered off */
131 TP_ACPI_WGSV_SAVE_STATE
= 0x04, /* Save state for S4/S5 */
134 /* TP_ACPI_WGSV_GET_STATE bits */
136 TP_ACPI_WGSV_STATE_WWANEXIST
= 0x0001, /* WWAN hw available */
137 TP_ACPI_WGSV_STATE_WWANPWR
= 0x0002, /* WWAN radio enabled */
138 TP_ACPI_WGSV_STATE_WWANPWRRES
= 0x0004, /* WWAN state at resume */
139 TP_ACPI_WGSV_STATE_WWANBIOSOFF
= 0x0008, /* WWAN disabled in BIOS */
140 TP_ACPI_WGSV_STATE_BLTHEXIST
= 0x0001, /* BLTH hw available */
141 TP_ACPI_WGSV_STATE_BLTHPWR
= 0x0002, /* BLTH radio enabled */
142 TP_ACPI_WGSV_STATE_BLTHPWRRES
= 0x0004, /* BLTH state at resume */
143 TP_ACPI_WGSV_STATE_BLTHBIOSOFF
= 0x0008, /* BLTH disabled in BIOS */
144 TP_ACPI_WGSV_STATE_UWBEXIST
= 0x0010, /* UWB hw available */
145 TP_ACPI_WGSV_STATE_UWBPWR
= 0x0020, /* UWB radio enabled */
148 /****************************************************************************
152 #define TPACPI_NAME "thinkpad"
153 #define TPACPI_DESC "ThinkPad ACPI Extras"
154 #define TPACPI_FILE TPACPI_NAME "_acpi"
155 #define TPACPI_URL "http://ibm-acpi.sf.net/"
156 #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net"
158 #define TPACPI_PROC_DIR "ibm"
159 #define TPACPI_ACPI_EVENT_PREFIX "ibm"
160 #define TPACPI_DRVR_NAME TPACPI_FILE
161 #define TPACPI_DRVR_SHORTNAME "tpacpi"
162 #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon"
164 #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd"
165 #define TPACPI_WORKQUEUE_NAME "ktpacpid"
167 #define TPACPI_MAX_ACPI_ARGS 3
169 /* rfkill switches */
171 TPACPI_RFK_BLUETOOTH_SW_ID
= 0,
172 TPACPI_RFK_WWAN_SW_ID
,
173 TPACPI_RFK_UWB_SW_ID
,
177 #define TPACPI_LOG TPACPI_FILE ": "
178 #define TPACPI_ERR KERN_ERR TPACPI_LOG
179 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
180 #define TPACPI_INFO KERN_INFO TPACPI_LOG
181 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
183 #define TPACPI_DBG_ALL 0xffff
184 #define TPACPI_DBG_INIT 0x0001
185 #define TPACPI_DBG_EXIT 0x0002
186 #define dbg_printk(a_dbg_level, format, arg...) \
187 do { if (dbg_level & a_dbg_level) \
188 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
190 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
191 #define vdbg_printk(a_dbg_level, format, arg...) \
192 dbg_printk(a_dbg_level, format, ## arg)
193 static const char *str_supported(int is_supported
);
195 #define vdbg_printk(a_dbg_level, format, arg...)
198 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
199 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
200 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
203 /****************************************************************************
204 * Driver-wide structs and misc. variables
209 struct tp_acpi_drv_struct
{
210 const struct acpi_device_id
*hid
;
211 struct acpi_driver
*driver
;
213 void (*notify
) (struct ibm_struct
*, u32
);
216 struct acpi_device
*device
;
222 int (*read
) (char *);
223 int (*write
) (char *);
225 void (*resume
) (void);
226 void (*suspend
) (pm_message_t state
);
227 void (*shutdown
) (void);
229 struct list_head all_drivers
;
231 struct tp_acpi_drv_struct
*acpi
;
234 u8 acpi_driver_registered
:1;
235 u8 acpi_notify_installed
:1;
242 struct ibm_init_struct
{
245 int (*init
) (struct ibm_init_struct
*);
246 struct ibm_struct
*data
;
250 #ifdef CONFIG_THINKPAD_ACPI_BAY
263 u32 bright_16levels
:1;
264 u32 bright_acpimode
:1;
267 u32 fan_ctrl_status_undef
:1;
268 u32 input_device_registered
:1;
269 u32 platform_drv_registered
:1;
270 u32 platform_drv_attrs_registered
:1;
271 u32 sensors_pdrv_registered
:1;
272 u32 sensors_pdrv_attrs_registered
:1;
273 u32 sensors_pdev_attrs_registered
:1;
274 u32 hotkey_poll_active
:1;
278 u16 hotkey_mask_ff
:1;
279 u16 bright_cmos_ec_unsync
:1;
282 struct thinkpad_id_data
{
283 unsigned int vendor
; /* ThinkPad vendor:
284 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
286 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
287 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
289 u16 bios_model
; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */
292 char *model_str
; /* ThinkPad T43 */
293 char *nummodel_str
; /* 9384A9C for a 9384-A9C model */
295 static struct thinkpad_id_data thinkpad_id
;
298 TPACPI_LIFE_INIT
= 0,
303 static int experimental
;
304 static u32 dbg_level
;
306 static struct workqueue_struct
*tpacpi_wq
;
308 /* Special LED class that can defer work */
309 struct tpacpi_led_classdev
{
310 struct led_classdev led_classdev
;
311 struct work_struct work
;
312 enum led_brightness new_brightness
;
316 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
317 static int dbg_wlswemul
;
318 static int tpacpi_wlsw_emulstate
;
319 static int dbg_bluetoothemul
;
320 static int tpacpi_bluetooth_emulstate
;
321 static int dbg_wwanemul
;
322 static int tpacpi_wwan_emulstate
;
323 static int dbg_uwbemul
;
324 static int tpacpi_uwb_emulstate
;
328 /****************************************************************************
329 ****************************************************************************
331 * ACPI Helpers and device model
333 ****************************************************************************
334 ****************************************************************************/
336 /*************************************************************************
340 static acpi_handle root_handle
;
342 #define TPACPI_HANDLE(object, parent, paths...) \
343 static acpi_handle object##_handle; \
344 static acpi_handle *object##_parent = &parent##_handle; \
345 static char *object##_path; \
346 static char *object##_paths[] = { paths }
348 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
349 "\\_SB.PCI.ISA.EC", /* 570 */
350 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
351 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
352 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
353 "\\_SB.PCI0.ICH3.EC0", /* R31 */
354 "\\_SB.PCI0.LPC.EC", /* all others */
357 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
358 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
360 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
362 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
363 "\\CMS", /* R40, R40e */
366 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
367 "^HKEY", /* R30, R31 */
368 "HKEY", /* all others */
371 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
372 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
373 "\\_SB.PCI0.VID0", /* 770e */
374 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
375 "\\_SB.PCI0.AGP.VID", /* all others */
379 /*************************************************************************
383 static int acpi_evalf(acpi_handle handle
,
384 void *res
, char *method
, char *fmt
, ...)
387 struct acpi_object_list params
;
388 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
389 struct acpi_buffer result
, *resultp
;
390 union acpi_object out_obj
;
398 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
411 params
.pointer
= &in_objs
[0];
418 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
419 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
421 /* add more types as needed */
423 printk(TPACPI_ERR
"acpi_evalf() called "
424 "with invalid format character '%c'\n", c
);
430 if (res_type
!= 'v') {
431 result
.length
= sizeof(out_obj
);
432 result
.pointer
= &out_obj
;
437 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
442 *(int *)res
= out_obj
.integer
.value
;
443 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
446 success
= status
== AE_OK
;
448 /* add more types as needed */
450 printk(TPACPI_ERR
"acpi_evalf() called "
451 "with invalid format character '%c'\n", res_type
);
455 if (!success
&& !quiet
)
456 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
457 method
, fmt0
, status
);
462 static int acpi_ec_read(int i
, u8
*p
)
467 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
471 if (ec_read(i
, p
) < 0)
478 static int acpi_ec_write(int i
, u8 v
)
481 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
484 if (ec_write(i
, v
) < 0)
491 #if defined(CONFIG_THINKPAD_ACPI_DOCK) || defined(CONFIG_THINKPAD_ACPI_BAY)
492 static int _sta(acpi_handle handle
)
496 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
503 static int issue_thinkpad_cmos_command(int cmos_cmd
)
508 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
514 /*************************************************************************
518 #define TPACPI_ACPIHANDLE_INIT(object) \
519 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
520 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
522 static void drv_acpi_handle_init(char *name
,
523 acpi_handle
*handle
, acpi_handle parent
,
524 char **paths
, int num_paths
, char **path
)
529 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
532 for (i
= 0; i
< num_paths
; i
++) {
533 status
= acpi_get_handle(parent
, paths
[i
], handle
);
534 if (ACPI_SUCCESS(status
)) {
536 dbg_printk(TPACPI_DBG_INIT
,
537 "Found ACPI handle %s for %s\n",
543 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
548 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
550 struct ibm_struct
*ibm
= data
;
552 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
555 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
558 ibm
->acpi
->notify(ibm
, event
);
561 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
568 if (!*ibm
->acpi
->handle
)
571 vdbg_printk(TPACPI_DBG_INIT
,
572 "setting up ACPI notify for %s\n", ibm
->name
);
574 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
576 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
581 ibm
->acpi
->device
->driver_data
= ibm
;
582 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
583 TPACPI_ACPI_EVENT_PREFIX
,
586 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
587 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
588 if (ACPI_FAILURE(status
)) {
589 if (status
== AE_ALREADY_EXISTS
) {
591 "another device driver is already "
592 "handling %s events\n", ibm
->name
);
595 "acpi_install_notify_handler(%s) failed: %d\n",
600 ibm
->flags
.acpi_notify_installed
= 1;
604 static int __init
tpacpi_device_add(struct acpi_device
*device
)
609 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
613 dbg_printk(TPACPI_DBG_INIT
,
614 "registering %s as an ACPI driver\n", ibm
->name
);
618 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
619 if (!ibm
->acpi
->driver
) {
621 "failed to allocate memory for ibm->acpi->driver\n");
625 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
626 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
628 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
630 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
632 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
634 kfree(ibm
->acpi
->driver
);
635 ibm
->acpi
->driver
= NULL
;
637 ibm
->flags
.acpi_driver_registered
= 1;
643 /****************************************************************************
644 ****************************************************************************
648 ****************************************************************************
649 ****************************************************************************/
651 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
652 int count
, int *eof
, void *data
)
654 struct ibm_struct
*ibm
= data
;
657 if (!ibm
|| !ibm
->read
)
660 len
= ibm
->read(page
);
664 if (len
<= off
+ count
)
676 static int dispatch_procfs_write(struct file
*file
,
677 const char __user
*userbuf
,
678 unsigned long count
, void *data
)
680 struct ibm_struct
*ibm
= data
;
684 if (!ibm
|| !ibm
->write
)
687 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
691 if (copy_from_user(kernbuf
, userbuf
, count
)) {
697 strcat(kernbuf
, ",");
698 ret
= ibm
->write(kernbuf
);
707 static char *next_cmd(char **cmds
)
712 while ((end
= strchr(start
, ',')) && end
== start
)
724 /****************************************************************************
725 ****************************************************************************
727 * Device model: input, hwmon and platform
729 ****************************************************************************
730 ****************************************************************************/
732 static struct platform_device
*tpacpi_pdev
;
733 static struct platform_device
*tpacpi_sensors_pdev
;
734 static struct device
*tpacpi_hwmon
;
735 static struct input_dev
*tpacpi_inputdev
;
736 static struct mutex tpacpi_inputdev_send_mutex
;
737 static LIST_HEAD(tpacpi_all_drivers
);
739 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
742 struct ibm_struct
*ibm
, *itmp
;
744 list_for_each_entry_safe(ibm
, itmp
,
748 (ibm
->suspend
)(state
);
754 static int tpacpi_resume_handler(struct platform_device
*pdev
)
756 struct ibm_struct
*ibm
, *itmp
;
758 list_for_each_entry_safe(ibm
, itmp
,
768 static void tpacpi_shutdown_handler(struct platform_device
*pdev
)
770 struct ibm_struct
*ibm
, *itmp
;
772 list_for_each_entry_safe(ibm
, itmp
,
780 static struct platform_driver tpacpi_pdriver
= {
782 .name
= TPACPI_DRVR_NAME
,
783 .owner
= THIS_MODULE
,
785 .suspend
= tpacpi_suspend_handler
,
786 .resume
= tpacpi_resume_handler
,
787 .shutdown
= tpacpi_shutdown_handler
,
790 static struct platform_driver tpacpi_hwmon_pdriver
= {
792 .name
= TPACPI_HWMON_DRVR_NAME
,
793 .owner
= THIS_MODULE
,
797 /*************************************************************************
798 * sysfs support helpers
801 struct attribute_set
{
802 unsigned int members
, max_members
;
803 struct attribute_group group
;
806 struct attribute_set_obj
{
807 struct attribute_set s
;
809 } __attribute__((packed
));
811 static struct attribute_set
*create_attr_set(unsigned int max_members
,
814 struct attribute_set_obj
*sobj
;
816 if (max_members
== 0)
819 /* Allocates space for implicit NULL at the end too */
820 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
821 max_members
* sizeof(struct attribute
*),
825 sobj
->s
.max_members
= max_members
;
826 sobj
->s
.group
.attrs
= &sobj
->a
;
827 sobj
->s
.group
.name
= name
;
832 #define destroy_attr_set(_set) \
835 /* not multi-threaded safe, use it in a single thread per set */
836 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
841 if (s
->members
>= s
->max_members
)
844 s
->group
.attrs
[s
->members
] = attr
;
850 static int add_many_to_attr_set(struct attribute_set
*s
,
851 struct attribute
**attr
,
856 for (i
= 0; i
< count
; i
++) {
857 res
= add_to_attr_set(s
, attr
[i
]);
865 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
867 sysfs_remove_group(kobj
, &s
->group
);
871 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
872 sysfs_create_group(_kobj, &_attr_set->group)
874 static int parse_strtoul(const char *buf
,
875 unsigned long max
, unsigned long *value
)
879 while (*buf
&& isspace(*buf
))
881 *value
= simple_strtoul(buf
, &endp
, 0);
882 while (*endp
&& isspace(*endp
))
884 if (*endp
|| *value
> max
)
890 static void tpacpi_disable_brightness_delay(void)
892 if (acpi_evalf(hkey_handle
, NULL
, "PWMS", "qvd", 0))
894 "ACPI backlight control delay disabled\n");
897 static int __init
tpacpi_query_bcl_levels(acpi_handle handle
)
899 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
900 union acpi_object
*obj
;
903 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
904 obj
= (union acpi_object
*)buffer
.pointer
;
905 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
906 printk(TPACPI_ERR
"Unknown _BCL data, "
907 "please report this to %s\n", TPACPI_MAIL
);
910 rc
= obj
->package
.count
;
916 kfree(buffer
.pointer
);
920 static acpi_status __init
tpacpi_acpi_walk_find_bcl(acpi_handle handle
,
921 u32 lvl
, void *context
, void **rv
)
923 char name
[ACPI_PATH_SEGMENT_LENGTH
];
924 struct acpi_buffer buffer
= { sizeof(name
), &name
};
926 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
927 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
929 **(int **)rv
= tpacpi_query_bcl_levels(handle
);
930 return AE_CTRL_TERMINATE
;
937 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
939 static int __init
tpacpi_check_std_acpi_brightness_support(void)
943 void *bcl_ptr
= &bcl_levels
;
946 TPACPI_ACPIHANDLE_INIT(vid
);
952 * Search for a _BCL method, and execute it. This is safe on all
953 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
954 * BIOS in ACPI backlight control mode. We do NOT have to care
955 * about calling the _BCL method in an enabled video device, any
956 * will do for our purposes.
959 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
960 tpacpi_acpi_walk_find_bcl
, NULL
,
963 if (ACPI_SUCCESS(status
) && bcl_levels
> 2) {
964 tp_features
.bright_acpimode
= 1;
965 return (bcl_levels
- 2);
971 static int __init
tpacpi_new_rfkill(const unsigned int id
,
973 const enum rfkill_type rfktype
,
975 const bool set_default
,
976 int (*toggle_radio
)(void *, enum rfkill_state
),
977 int (*get_state
)(void *, enum rfkill_state
*))
980 enum rfkill_state initial_state
= RFKILL_STATE_SOFT_BLOCKED
;
982 res
= get_state(NULL
, &initial_state
);
985 "failed to read initial state for %s, error %d; "
986 "will turn radio off\n", name
, res
);
987 } else if (set_default
) {
988 /* try to set the initial state as the default for the rfkill
989 * type, since we ask the firmware to preserve it across S5 in
991 rfkill_set_default(rfktype
,
992 (initial_state
== RFKILL_STATE_UNBLOCKED
) ?
993 RFKILL_STATE_UNBLOCKED
:
994 RFKILL_STATE_SOFT_BLOCKED
);
997 *rfk
= rfkill_allocate(&tpacpi_pdev
->dev
, rfktype
);
1000 "failed to allocate memory for rfkill class\n");
1004 (*rfk
)->name
= name
;
1005 (*rfk
)->get_state
= get_state
;
1006 (*rfk
)->toggle_radio
= toggle_radio
;
1007 (*rfk
)->state
= initial_state
;
1009 res
= rfkill_register(*rfk
);
1012 "failed to register %s rfkill switch: %d\n",
1022 /*************************************************************************
1023 * thinkpad-acpi driver attributes
1026 /* interface_version --------------------------------------------------- */
1027 static ssize_t
tpacpi_driver_interface_version_show(
1028 struct device_driver
*drv
,
1031 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
1034 static DRIVER_ATTR(interface_version
, S_IRUGO
,
1035 tpacpi_driver_interface_version_show
, NULL
);
1037 /* debug_level --------------------------------------------------------- */
1038 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
1041 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
1044 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
1045 const char *buf
, size_t count
)
1049 if (parse_strtoul(buf
, 0xffff, &t
))
1057 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
1058 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
1060 /* version ------------------------------------------------------------- */
1061 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
1064 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
1065 TPACPI_DESC
, TPACPI_VERSION
);
1068 static DRIVER_ATTR(version
, S_IRUGO
,
1069 tpacpi_driver_version_show
, NULL
);
1071 /* --------------------------------------------------------------------- */
1073 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1075 static void tpacpi_send_radiosw_update(void);
1077 /* wlsw_emulstate ------------------------------------------------------ */
1078 static ssize_t
tpacpi_driver_wlsw_emulstate_show(struct device_driver
*drv
,
1081 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wlsw_emulstate
);
1084 static ssize_t
tpacpi_driver_wlsw_emulstate_store(struct device_driver
*drv
,
1085 const char *buf
, size_t count
)
1089 if (parse_strtoul(buf
, 1, &t
))
1092 if (tpacpi_wlsw_emulstate
!= t
) {
1093 tpacpi_wlsw_emulstate
= !!t
;
1094 tpacpi_send_radiosw_update();
1096 tpacpi_wlsw_emulstate
= !!t
;
1101 static DRIVER_ATTR(wlsw_emulstate
, S_IWUSR
| S_IRUGO
,
1102 tpacpi_driver_wlsw_emulstate_show
,
1103 tpacpi_driver_wlsw_emulstate_store
);
1105 /* bluetooth_emulstate ------------------------------------------------- */
1106 static ssize_t
tpacpi_driver_bluetooth_emulstate_show(
1107 struct device_driver
*drv
,
1110 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_bluetooth_emulstate
);
1113 static ssize_t
tpacpi_driver_bluetooth_emulstate_store(
1114 struct device_driver
*drv
,
1115 const char *buf
, size_t count
)
1119 if (parse_strtoul(buf
, 1, &t
))
1122 tpacpi_bluetooth_emulstate
= !!t
;
1127 static DRIVER_ATTR(bluetooth_emulstate
, S_IWUSR
| S_IRUGO
,
1128 tpacpi_driver_bluetooth_emulstate_show
,
1129 tpacpi_driver_bluetooth_emulstate_store
);
1131 /* wwan_emulstate ------------------------------------------------- */
1132 static ssize_t
tpacpi_driver_wwan_emulstate_show(
1133 struct device_driver
*drv
,
1136 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wwan_emulstate
);
1139 static ssize_t
tpacpi_driver_wwan_emulstate_store(
1140 struct device_driver
*drv
,
1141 const char *buf
, size_t count
)
1145 if (parse_strtoul(buf
, 1, &t
))
1148 tpacpi_wwan_emulstate
= !!t
;
1153 static DRIVER_ATTR(wwan_emulstate
, S_IWUSR
| S_IRUGO
,
1154 tpacpi_driver_wwan_emulstate_show
,
1155 tpacpi_driver_wwan_emulstate_store
);
1157 /* uwb_emulstate ------------------------------------------------- */
1158 static ssize_t
tpacpi_driver_uwb_emulstate_show(
1159 struct device_driver
*drv
,
1162 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_uwb_emulstate
);
1165 static ssize_t
tpacpi_driver_uwb_emulstate_store(
1166 struct device_driver
*drv
,
1167 const char *buf
, size_t count
)
1171 if (parse_strtoul(buf
, 1, &t
))
1174 tpacpi_uwb_emulstate
= !!t
;
1179 static DRIVER_ATTR(uwb_emulstate
, S_IWUSR
| S_IRUGO
,
1180 tpacpi_driver_uwb_emulstate_show
,
1181 tpacpi_driver_uwb_emulstate_store
);
1184 /* --------------------------------------------------------------------- */
1186 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
1187 &driver_attr_debug_level
, &driver_attr_version
,
1188 &driver_attr_interface_version
,
1191 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
1197 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
1198 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
1202 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1203 if (!res
&& dbg_wlswemul
)
1204 res
= driver_create_file(drv
, &driver_attr_wlsw_emulstate
);
1205 if (!res
&& dbg_bluetoothemul
)
1206 res
= driver_create_file(drv
, &driver_attr_bluetooth_emulstate
);
1207 if (!res
&& dbg_wwanemul
)
1208 res
= driver_create_file(drv
, &driver_attr_wwan_emulstate
);
1209 if (!res
&& dbg_uwbemul
)
1210 res
= driver_create_file(drv
, &driver_attr_uwb_emulstate
);
1216 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
1220 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
1221 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
1223 #ifdef THINKPAD_ACPI_DEBUGFACILITIES
1224 driver_remove_file(drv
, &driver_attr_wlsw_emulstate
);
1225 driver_remove_file(drv
, &driver_attr_bluetooth_emulstate
);
1226 driver_remove_file(drv
, &driver_attr_wwan_emulstate
);
1227 driver_remove_file(drv
, &driver_attr_uwb_emulstate
);
1231 /****************************************************************************
1232 ****************************************************************************
1236 ****************************************************************************
1237 ****************************************************************************/
1239 /*************************************************************************
1240 * thinkpad-acpi init subdriver
1243 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
1245 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
1246 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
1248 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
1249 (thinkpad_id
.bios_version_str
) ?
1250 thinkpad_id
.bios_version_str
: "unknown",
1251 (thinkpad_id
.ec_version_str
) ?
1252 thinkpad_id
.ec_version_str
: "unknown");
1254 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
1255 printk(TPACPI_INFO
"%s %s, model %s\n",
1256 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
1257 "IBM" : ((thinkpad_id
.vendor
==
1258 PCI_VENDOR_ID_LENOVO
) ?
1259 "Lenovo" : "Unknown vendor"),
1260 thinkpad_id
.model_str
,
1261 (thinkpad_id
.nummodel_str
) ?
1262 thinkpad_id
.nummodel_str
: "unknown");
1267 static int thinkpad_acpi_driver_read(char *p
)
1271 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", TPACPI_DESC
);
1272 len
+= sprintf(p
+ len
, "version:\t%s\n", TPACPI_VERSION
);
1277 static struct ibm_struct thinkpad_acpi_driver_data
= {
1279 .read
= thinkpad_acpi_driver_read
,
1282 /*************************************************************************
1286 enum { /* hot key scan codes (derived from ACPI DSDT) */
1287 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
1288 TP_ACPI_HOTKEYSCAN_FNF2
,
1289 TP_ACPI_HOTKEYSCAN_FNF3
,
1290 TP_ACPI_HOTKEYSCAN_FNF4
,
1291 TP_ACPI_HOTKEYSCAN_FNF5
,
1292 TP_ACPI_HOTKEYSCAN_FNF6
,
1293 TP_ACPI_HOTKEYSCAN_FNF7
,
1294 TP_ACPI_HOTKEYSCAN_FNF8
,
1295 TP_ACPI_HOTKEYSCAN_FNF9
,
1296 TP_ACPI_HOTKEYSCAN_FNF10
,
1297 TP_ACPI_HOTKEYSCAN_FNF11
,
1298 TP_ACPI_HOTKEYSCAN_FNF12
,
1299 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
1300 TP_ACPI_HOTKEYSCAN_FNINSERT
,
1301 TP_ACPI_HOTKEYSCAN_FNDELETE
,
1302 TP_ACPI_HOTKEYSCAN_FNHOME
,
1303 TP_ACPI_HOTKEYSCAN_FNEND
,
1304 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1305 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
1306 TP_ACPI_HOTKEYSCAN_FNSPACE
,
1307 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1308 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1309 TP_ACPI_HOTKEYSCAN_MUTE
,
1310 TP_ACPI_HOTKEYSCAN_THINKPAD
,
1313 enum { /* Keys available through NVRAM polling */
1314 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
1315 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
1318 enum { /* Positions of some of the keys in hotkey masks */
1319 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
1320 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
1321 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
1322 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
1323 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
1324 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1325 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
1326 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1327 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1328 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
1329 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
1332 enum { /* NVRAM to ACPI HKEY group map */
1333 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
1334 TP_ACPI_HKEY_ZOOM_MASK
|
1335 TP_ACPI_HKEY_DISPSWTCH_MASK
|
1336 TP_ACPI_HKEY_HIBERNATE_MASK
,
1337 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
1338 TP_ACPI_HKEY_BRGHTDWN_MASK
,
1339 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
1340 TP_ACPI_HKEY_VOLDWN_MASK
|
1341 TP_ACPI_HKEY_MUTE_MASK
,
1344 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1345 struct tp_nvram_state
{
1346 u16 thinkpad_toggle
:1;
1348 u16 display_toggle
:1;
1349 u16 thinklight_toggle
:1;
1350 u16 hibernate_toggle
:1;
1351 u16 displayexp_toggle
:1;
1352 u16 display_state
:1;
1353 u16 brightness_toggle
:1;
1354 u16 volume_toggle
:1;
1357 u8 brightness_level
;
1361 static struct task_struct
*tpacpi_hotkey_task
;
1362 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
1363 static int hotkey_poll_freq
= 10; /* Hz */
1364 static struct mutex hotkey_thread_mutex
;
1365 static struct mutex hotkey_thread_data_mutex
;
1366 static unsigned int hotkey_config_change
;
1368 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1370 #define hotkey_source_mask 0U
1372 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1374 static struct mutex hotkey_mutex
;
1376 static enum { /* Reasons for waking up */
1377 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
1378 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
1379 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
1380 } hotkey_wakeup_reason
;
1382 static int hotkey_autosleep_ack
;
1384 static int hotkey_orig_status
;
1385 static u32 hotkey_orig_mask
;
1386 static u32 hotkey_all_mask
;
1387 static u32 hotkey_reserved_mask
;
1388 static u32 hotkey_mask
;
1390 static unsigned int hotkey_report_mode
;
1392 static u16
*hotkey_keycode_map
;
1394 static struct attribute_set
*hotkey_dev_attributes
;
1396 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1397 #define HOTKEY_CONFIG_CRITICAL_START \
1399 mutex_lock(&hotkey_thread_data_mutex); \
1400 hotkey_config_change++; \
1402 #define HOTKEY_CONFIG_CRITICAL_END \
1403 mutex_unlock(&hotkey_thread_data_mutex);
1405 #define HOTKEY_CONFIG_CRITICAL_START
1406 #define HOTKEY_CONFIG_CRITICAL_END
1407 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1409 /* HKEY.MHKG() return bits */
1410 #define TP_HOTKEY_TABLET_MASK (1 << 3)
1412 static int hotkey_get_wlsw(int *status
)
1414 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1416 *status
= !!tpacpi_wlsw_emulstate
;
1420 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
1425 static int hotkey_get_tablet_mode(int *status
)
1429 if (!acpi_evalf(hkey_handle
, &s
, "MHKG", "d"))
1432 *status
= ((s
& TP_HOTKEY_TABLET_MASK
) != 0);
1437 * Call with hotkey_mutex held
1439 static int hotkey_mask_get(void)
1443 if (tp_features
.hotkey_mask
) {
1444 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
1447 hotkey_mask
= m
| (hotkey_source_mask
& hotkey_mask
);
1453 * Call with hotkey_mutex held
1455 static int hotkey_mask_set(u32 mask
)
1460 if (tp_features
.hotkey_mask
) {
1461 if (!tp_warned
.hotkey_mask_ff
&&
1462 (mask
== 0xffff || mask
== 0xffffff ||
1463 mask
== 0xffffffff)) {
1464 tp_warned
.hotkey_mask_ff
= 1;
1465 printk(TPACPI_NOTICE
1466 "setting the hotkey mask to 0x%08x is likely "
1467 "not the best way to go about it\n", mask
);
1468 printk(TPACPI_NOTICE
1469 "please consider using the driver defaults, "
1470 "and refer to up-to-date thinkpad-acpi "
1474 HOTKEY_CONFIG_CRITICAL_START
1475 for (i
= 0; i
< 32; i
++) {
1477 /* enable in firmware mask only keys not in NVRAM
1478 * mode, but enable the key in the cached hotkey_mask
1479 * regardless of mode, or the key will end up
1480 * disabled by hotkey_mask_get() */
1481 if (!acpi_evalf(hkey_handle
,
1482 NULL
, "MHKM", "vdd", i
+ 1,
1483 !!((mask
& ~hotkey_source_mask
) & m
))) {
1487 hotkey_mask
= (hotkey_mask
& ~m
) | (mask
& m
);
1490 HOTKEY_CONFIG_CRITICAL_END
1492 /* hotkey_mask_get must be called unconditionally below */
1493 if (!hotkey_mask_get() && !rc
&&
1494 (hotkey_mask
& ~hotkey_source_mask
) !=
1495 (mask
& ~hotkey_source_mask
)) {
1496 printk(TPACPI_NOTICE
1497 "requested hot key mask 0x%08x, but "
1498 "firmware forced it to 0x%08x\n",
1502 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1503 HOTKEY_CONFIG_CRITICAL_START
1504 hotkey_mask
= mask
& hotkey_source_mask
;
1505 HOTKEY_CONFIG_CRITICAL_END
1507 if (hotkey_mask
!= mask
) {
1508 printk(TPACPI_NOTICE
1509 "requested hot key mask 0x%08x, "
1510 "forced to 0x%08x (NVRAM poll mask is "
1511 "0x%08x): no firmware mask support\n",
1512 mask
, hotkey_mask
, hotkey_source_mask
);
1517 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1523 static int hotkey_status_get(int *status
)
1525 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1531 static int hotkey_status_set(int status
)
1533 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
1539 static void tpacpi_input_send_tabletsw(void)
1543 if (tp_features
.hotkey_tablet
&&
1544 !hotkey_get_tablet_mode(&state
)) {
1545 mutex_lock(&tpacpi_inputdev_send_mutex
);
1547 input_report_switch(tpacpi_inputdev
,
1548 SW_TABLET_MODE
, !!state
);
1549 input_sync(tpacpi_inputdev
);
1551 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1555 static void tpacpi_input_send_key(unsigned int scancode
)
1557 unsigned int keycode
;
1559 keycode
= hotkey_keycode_map
[scancode
];
1561 if (keycode
!= KEY_RESERVED
) {
1562 mutex_lock(&tpacpi_inputdev_send_mutex
);
1564 input_report_key(tpacpi_inputdev
, keycode
, 1);
1565 if (keycode
== KEY_UNKNOWN
)
1566 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1568 input_sync(tpacpi_inputdev
);
1570 input_report_key(tpacpi_inputdev
, keycode
, 0);
1571 if (keycode
== KEY_UNKNOWN
)
1572 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1574 input_sync(tpacpi_inputdev
);
1576 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1580 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1581 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
1583 static void tpacpi_hotkey_send_key(unsigned int scancode
)
1585 tpacpi_input_send_key(scancode
);
1586 if (hotkey_report_mode
< 2) {
1587 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
1588 0x80, 0x1001 + scancode
);
1592 static void hotkey_read_nvram(struct tp_nvram_state
*n
, u32 m
)
1596 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
1597 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
1598 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
1599 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
1600 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
1601 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
1603 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
1604 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
1605 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
1607 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
1608 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
1609 n
->displayexp_toggle
=
1610 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
1612 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
1613 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
1614 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
1615 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
1616 n
->brightness_toggle
=
1617 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
1619 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
1620 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
1621 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
1622 >> TP_NVRAM_POS_LEVEL_VOLUME
;
1623 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
1624 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
1628 #define TPACPI_COMPARE_KEY(__scancode, __member) \
1630 if ((mask & (1 << __scancode)) && \
1631 oldn->__member != newn->__member) \
1632 tpacpi_hotkey_send_key(__scancode); \
1635 #define TPACPI_MAY_SEND_KEY(__scancode) \
1636 do { if (mask & (1 << __scancode)) \
1637 tpacpi_hotkey_send_key(__scancode); } while (0)
1639 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
1640 struct tp_nvram_state
*newn
,
1643 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
1644 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
1645 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
1646 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
1648 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
1650 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
1653 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
1654 if (oldn
->mute
!= newn
->mute
) {
1655 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1657 if (oldn
->volume_level
> newn
->volume_level
) {
1658 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1659 } else if (oldn
->volume_level
< newn
->volume_level
) {
1660 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1661 } else if (oldn
->mute
== newn
->mute
) {
1662 /* repeated key presses that didn't change state */
1664 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1665 } else if (newn
->volume_level
!= 0) {
1666 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1668 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1673 /* handle brightness */
1674 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
1675 if (oldn
->brightness_level
< newn
->brightness_level
) {
1676 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1677 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
1678 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1680 /* repeated key presses that didn't change state */
1681 if (newn
->brightness_level
!= 0) {
1682 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1684 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1690 #undef TPACPI_COMPARE_KEY
1691 #undef TPACPI_MAY_SEND_KEY
1693 static int hotkey_kthread(void *data
)
1695 struct tp_nvram_state s
[2];
1697 unsigned int si
, so
;
1699 unsigned int change_detector
, must_reset
;
1701 mutex_lock(&hotkey_thread_mutex
);
1703 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
1712 /* Initial state for compares */
1713 mutex_lock(&hotkey_thread_data_mutex
);
1714 change_detector
= hotkey_config_change
;
1715 mask
= hotkey_source_mask
& hotkey_mask
;
1716 mutex_unlock(&hotkey_thread_data_mutex
);
1717 hotkey_read_nvram(&s
[so
], mask
);
1719 while (!kthread_should_stop() && hotkey_poll_freq
) {
1721 t
= 1000/hotkey_poll_freq
;
1722 t
= msleep_interruptible(t
);
1723 if (unlikely(kthread_should_stop()))
1725 must_reset
= try_to_freeze();
1726 if (t
> 0 && !must_reset
)
1729 mutex_lock(&hotkey_thread_data_mutex
);
1730 if (must_reset
|| hotkey_config_change
!= change_detector
) {
1731 /* forget old state on thaw or config change */
1734 change_detector
= hotkey_config_change
;
1736 mask
= hotkey_source_mask
& hotkey_mask
;
1737 mutex_unlock(&hotkey_thread_data_mutex
);
1740 hotkey_read_nvram(&s
[si
], mask
);
1741 if (likely(si
!= so
)) {
1742 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
1752 mutex_unlock(&hotkey_thread_mutex
);
1756 static void hotkey_poll_stop_sync(void)
1758 if (tpacpi_hotkey_task
) {
1759 if (frozen(tpacpi_hotkey_task
) ||
1760 freezing(tpacpi_hotkey_task
))
1761 thaw_process(tpacpi_hotkey_task
);
1763 kthread_stop(tpacpi_hotkey_task
);
1764 tpacpi_hotkey_task
= NULL
;
1765 mutex_lock(&hotkey_thread_mutex
);
1766 /* at this point, the thread did exit */
1767 mutex_unlock(&hotkey_thread_mutex
);
1771 /* call with hotkey_mutex held */
1772 static void hotkey_poll_setup(int may_warn
)
1774 if ((hotkey_source_mask
& hotkey_mask
) != 0 &&
1775 hotkey_poll_freq
> 0 &&
1776 (tpacpi_inputdev
->users
> 0 || hotkey_report_mode
< 2)) {
1777 if (!tpacpi_hotkey_task
) {
1778 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
1779 NULL
, TPACPI_NVRAM_KTHREAD_NAME
);
1780 if (IS_ERR(tpacpi_hotkey_task
)) {
1781 tpacpi_hotkey_task
= NULL
;
1783 "could not create kernel thread "
1784 "for hotkey polling\n");
1788 hotkey_poll_stop_sync();
1790 hotkey_source_mask
!= 0 && hotkey_poll_freq
== 0) {
1791 printk(TPACPI_NOTICE
1792 "hot keys 0x%08x require polling, "
1793 "which is currently disabled\n",
1794 hotkey_source_mask
);
1799 static void hotkey_poll_setup_safe(int may_warn
)
1801 mutex_lock(&hotkey_mutex
);
1802 hotkey_poll_setup(may_warn
);
1803 mutex_unlock(&hotkey_mutex
);
1806 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1808 static void hotkey_poll_setup_safe(int __unused
)
1812 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1814 static int hotkey_inputdev_open(struct input_dev
*dev
)
1816 switch (tpacpi_lifecycle
) {
1817 case TPACPI_LIFE_INIT
:
1819 * hotkey_init will call hotkey_poll_setup_safe
1820 * at the appropriate moment
1823 case TPACPI_LIFE_EXITING
:
1825 case TPACPI_LIFE_RUNNING
:
1826 hotkey_poll_setup_safe(0);
1830 /* Should only happen if tpacpi_lifecycle is corrupt */
1835 static void hotkey_inputdev_close(struct input_dev
*dev
)
1837 /* disable hotkey polling when possible */
1838 if (tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
)
1839 hotkey_poll_setup_safe(0);
1842 /* sysfs hotkey enable ------------------------------------------------- */
1843 static ssize_t
hotkey_enable_show(struct device
*dev
,
1844 struct device_attribute
*attr
,
1849 res
= hotkey_status_get(&status
);
1853 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
1856 static ssize_t
hotkey_enable_store(struct device
*dev
,
1857 struct device_attribute
*attr
,
1858 const char *buf
, size_t count
)
1863 if (parse_strtoul(buf
, 1, &t
))
1866 res
= hotkey_status_set(t
);
1868 return (res
) ? res
: count
;
1871 static struct device_attribute dev_attr_hotkey_enable
=
1872 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
1873 hotkey_enable_show
, hotkey_enable_store
);
1875 /* sysfs hotkey mask --------------------------------------------------- */
1876 static ssize_t
hotkey_mask_show(struct device
*dev
,
1877 struct device_attribute
*attr
,
1882 if (mutex_lock_interruptible(&hotkey_mutex
))
1883 return -ERESTARTSYS
;
1884 res
= hotkey_mask_get();
1885 mutex_unlock(&hotkey_mutex
);
1888 res
: snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_mask
);
1891 static ssize_t
hotkey_mask_store(struct device
*dev
,
1892 struct device_attribute
*attr
,
1893 const char *buf
, size_t count
)
1898 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
1901 if (mutex_lock_interruptible(&hotkey_mutex
))
1902 return -ERESTARTSYS
;
1904 res
= hotkey_mask_set(t
);
1906 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1907 hotkey_poll_setup(1);
1910 mutex_unlock(&hotkey_mutex
);
1912 return (res
) ? res
: count
;
1915 static struct device_attribute dev_attr_hotkey_mask
=
1916 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
1917 hotkey_mask_show
, hotkey_mask_store
);
1919 /* sysfs hotkey bios_enabled ------------------------------------------- */
1920 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
1921 struct device_attribute
*attr
,
1924 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
1927 static struct device_attribute dev_attr_hotkey_bios_enabled
=
1928 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
1930 /* sysfs hotkey bios_mask ---------------------------------------------- */
1931 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
1932 struct device_attribute
*attr
,
1935 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
1938 static struct device_attribute dev_attr_hotkey_bios_mask
=
1939 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
1941 /* sysfs hotkey all_mask ----------------------------------------------- */
1942 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
1943 struct device_attribute
*attr
,
1946 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1947 hotkey_all_mask
| hotkey_source_mask
);
1950 static struct device_attribute dev_attr_hotkey_all_mask
=
1951 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
1953 /* sysfs hotkey recommended_mask --------------------------------------- */
1954 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
1955 struct device_attribute
*attr
,
1958 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1959 (hotkey_all_mask
| hotkey_source_mask
)
1960 & ~hotkey_reserved_mask
);
1963 static struct device_attribute dev_attr_hotkey_recommended_mask
=
1964 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
1965 hotkey_recommended_mask_show
, NULL
);
1967 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1969 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
1970 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
1971 struct device_attribute
*attr
,
1974 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
1977 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
1978 struct device_attribute
*attr
,
1979 const char *buf
, size_t count
)
1983 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
1984 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
1987 if (mutex_lock_interruptible(&hotkey_mutex
))
1988 return -ERESTARTSYS
;
1990 HOTKEY_CONFIG_CRITICAL_START
1991 hotkey_source_mask
= t
;
1992 HOTKEY_CONFIG_CRITICAL_END
1994 hotkey_poll_setup(1);
1996 mutex_unlock(&hotkey_mutex
);
2001 static struct device_attribute dev_attr_hotkey_source_mask
=
2002 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
2003 hotkey_source_mask_show
, hotkey_source_mask_store
);
2005 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
2006 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
2007 struct device_attribute
*attr
,
2010 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
2013 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
2014 struct device_attribute
*attr
,
2015 const char *buf
, size_t count
)
2019 if (parse_strtoul(buf
, 25, &t
))
2022 if (mutex_lock_interruptible(&hotkey_mutex
))
2023 return -ERESTARTSYS
;
2025 hotkey_poll_freq
= t
;
2027 hotkey_poll_setup(1);
2028 mutex_unlock(&hotkey_mutex
);
2033 static struct device_attribute dev_attr_hotkey_poll_freq
=
2034 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
2035 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
2037 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2039 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
2040 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
2041 struct device_attribute
*attr
,
2045 res
= hotkey_get_wlsw(&s
);
2049 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2052 static struct device_attribute dev_attr_hotkey_radio_sw
=
2053 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
2055 static void hotkey_radio_sw_notify_change(void)
2057 if (tp_features
.hotkey_wlsw
)
2058 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2062 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
2063 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
2064 struct device_attribute
*attr
,
2068 res
= hotkey_get_tablet_mode(&s
);
2072 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2075 static struct device_attribute dev_attr_hotkey_tablet_mode
=
2076 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
2078 static void hotkey_tablet_mode_notify_change(void)
2080 if (tp_features
.hotkey_tablet
)
2081 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2082 "hotkey_tablet_mode");
2085 /* sysfs hotkey report_mode -------------------------------------------- */
2086 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
2087 struct device_attribute
*attr
,
2090 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2091 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
2094 static struct device_attribute dev_attr_hotkey_report_mode
=
2095 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
2097 /* sysfs wakeup reason (pollable) -------------------------------------- */
2098 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
2099 struct device_attribute
*attr
,
2102 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
2105 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
2106 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
2108 static void hotkey_wakeup_reason_notify_change(void)
2110 if (tp_features
.hotkey_mask
)
2111 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2115 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2116 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
2117 struct device_attribute
*attr
,
2120 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
2123 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
2124 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
2125 hotkey_wakeup_hotunplug_complete_show
, NULL
);
2127 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2129 if (tp_features
.hotkey_mask
)
2130 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2131 "wakeup_hotunplug_complete");
2134 /* --------------------------------------------------------------------- */
2136 static struct attribute
*hotkey_attributes
[] __initdata
= {
2137 &dev_attr_hotkey_enable
.attr
,
2138 &dev_attr_hotkey_bios_enabled
.attr
,
2139 &dev_attr_hotkey_report_mode
.attr
,
2140 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2141 &dev_attr_hotkey_mask
.attr
,
2142 &dev_attr_hotkey_all_mask
.attr
,
2143 &dev_attr_hotkey_recommended_mask
.attr
,
2144 &dev_attr_hotkey_source_mask
.attr
,
2145 &dev_attr_hotkey_poll_freq
.attr
,
2149 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
2150 &dev_attr_hotkey_bios_mask
.attr
,
2151 #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2152 &dev_attr_hotkey_mask
.attr
,
2153 &dev_attr_hotkey_all_mask
.attr
,
2154 &dev_attr_hotkey_recommended_mask
.attr
,
2156 &dev_attr_hotkey_wakeup_reason
.attr
,
2157 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
2160 static void bluetooth_update_rfk(void);
2161 static void wan_update_rfk(void);
2162 static void uwb_update_rfk(void);
2163 static void tpacpi_send_radiosw_update(void)
2167 /* Sync these BEFORE sending any rfkill events */
2168 if (tp_features
.bluetooth
)
2169 bluetooth_update_rfk();
2170 if (tp_features
.wan
)
2172 if (tp_features
.uwb
)
2175 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
2176 mutex_lock(&tpacpi_inputdev_send_mutex
);
2178 input_report_switch(tpacpi_inputdev
,
2179 SW_RFKILL_ALL
, !!wlsw
);
2180 input_sync(tpacpi_inputdev
);
2182 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2184 hotkey_radio_sw_notify_change();
2187 static void hotkey_exit(void)
2189 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2190 hotkey_poll_stop_sync();
2193 if (hotkey_dev_attributes
)
2194 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2196 kfree(hotkey_keycode_map
);
2198 if (tp_features
.hotkey
) {
2199 dbg_printk(TPACPI_DBG_EXIT
,
2200 "restoring original hot key mask\n");
2201 /* no short-circuit boolean operator below! */
2202 if ((hotkey_mask_set(hotkey_orig_mask
) |
2203 hotkey_status_set(hotkey_orig_status
)) != 0)
2205 "failed to restore hot key mask "
2206 "to BIOS defaults\n");
2210 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
2212 /* Requirements for changing the default keymaps:
2214 * 1. Many of the keys are mapped to KEY_RESERVED for very
2215 * good reasons. Do not change them unless you have deep
2216 * knowledge on the IBM and Lenovo ThinkPad firmware for
2217 * the various ThinkPad models. The driver behaves
2218 * differently for KEY_RESERVED: such keys have their
2219 * hot key mask *unset* in mask_recommended, and also
2220 * in the initial hot key mask programmed into the
2221 * firmware at driver load time, which means the firm-
2222 * ware may react very differently if you change them to
2225 * 2. You must be subscribed to the linux-thinkpad and
2226 * ibm-acpi-devel mailing lists, and you should read the
2227 * list archives since 2007 if you want to change the
2228 * keymaps. This requirement exists so that you will
2229 * know the past history of problems with the thinkpad-
2230 * acpi driver keymaps, and also that you will be
2231 * listening to any bug reports;
2233 * 3. Do not send thinkpad-acpi specific patches directly to
2234 * for merging, *ever*. Send them to the linux-acpi
2235 * mailinglist for comments. Merging is to be done only
2236 * through acpi-test and the ACPI maintainer.
2238 * If the above is too much to ask, don't change the keymap.
2239 * Ask the thinkpad-acpi maintainer to do it, instead.
2241 static u16 ibm_keycode_map
[] __initdata
= {
2242 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2243 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
2244 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2245 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2247 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2248 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2249 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2250 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2252 /* brightness: firmware always reacts to them, unless
2253 * X.org did some tricks in the radeon BIOS scratch
2254 * registers of *some* models */
2255 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
2256 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
2258 /* Thinklight: firmware always react to it */
2259 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2261 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2262 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2264 /* Volume: firmware always react to it and reprograms
2265 * the built-in *extra* mixer. Never map it to control
2266 * another mixer by default. */
2267 KEY_RESERVED
, /* 0x14: VOLUME UP */
2268 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2269 KEY_RESERVED
, /* 0x16: MUTE */
2271 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2273 /* (assignments unknown, please report if found) */
2274 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2275 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2277 static u16 lenovo_keycode_map
[] __initdata
= {
2278 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2279 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
2280 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2281 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2283 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2284 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2285 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2286 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2288 /* These either have to go through ACPI video, or
2289 * act like in the IBM ThinkPads, so don't ever
2290 * enable them by default */
2291 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
2292 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
2294 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2296 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2297 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2299 /* Volume: z60/z61, T60 (BIOS version?): firmware always
2300 * react to it and reprograms the built-in *extra* mixer.
2301 * Never map it to control another mixer by default.
2303 * T60?, T61, R60?, R61: firmware and EC tries to send
2304 * these over the regular keyboard, so these are no-ops,
2305 * but there are still weird bugs re. MUTE, so do not
2306 * change unless you get test reports from all Lenovo
2307 * models. May cause the BIOS to interfere with the
2310 KEY_RESERVED
, /* 0x14: VOLUME UP */
2311 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2312 KEY_RESERVED
, /* 0x16: MUTE */
2314 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2316 /* (assignments unknown, please report if found) */
2317 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2318 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2321 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
2322 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
2323 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
2329 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
2331 BUG_ON(!tpacpi_inputdev
);
2332 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
2333 tpacpi_inputdev
->close
!= NULL
);
2335 TPACPI_ACPIHANDLE_INIT(hkey
);
2336 mutex_init(&hotkey_mutex
);
2338 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2339 mutex_init(&hotkey_thread_mutex
);
2340 mutex_init(&hotkey_thread_data_mutex
);
2343 /* hotkey not supported on 570 */
2344 tp_features
.hotkey
= hkey_handle
!= NULL
;
2346 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
2347 str_supported(tp_features
.hotkey
));
2349 if (!tp_features
.hotkey
)
2352 tpacpi_disable_brightness_delay();
2354 hotkey_dev_attributes
= create_attr_set(13, NULL
);
2355 if (!hotkey_dev_attributes
)
2357 res
= add_many_to_attr_set(hotkey_dev_attributes
,
2359 ARRAY_SIZE(hotkey_attributes
));
2363 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2364 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
2365 for HKEY interface version 0x100 */
2366 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
2367 if ((hkeyv
>> 8) != 1) {
2368 printk(TPACPI_ERR
"unknown version of the "
2369 "HKEY interface: 0x%x\n", hkeyv
);
2370 printk(TPACPI_ERR
"please report this to %s\n",
2374 * MHKV 0x100 in A31, R40, R40e,
2375 * T4x, X31, and later
2377 tp_features
.hotkey_mask
= 1;
2381 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
2382 str_supported(tp_features
.hotkey_mask
));
2384 if (tp_features
.hotkey_mask
) {
2385 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
2388 "missing MHKA handler, "
2389 "please report this to %s\n",
2391 /* FN+F12, FN+F4, FN+F3 */
2392 hotkey_all_mask
= 0x080cU
;
2396 /* hotkey_source_mask *must* be zero for
2397 * the first hotkey_mask_get */
2398 res
= hotkey_status_get(&hotkey_orig_status
);
2402 if (tp_features
.hotkey_mask
) {
2403 res
= hotkey_mask_get();
2407 hotkey_orig_mask
= hotkey_mask
;
2408 res
= add_many_to_attr_set(
2409 hotkey_dev_attributes
,
2410 hotkey_mask_attributes
,
2411 ARRAY_SIZE(hotkey_mask_attributes
));
2416 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2417 if (tp_features
.hotkey_mask
) {
2418 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
2421 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
;
2424 vdbg_printk(TPACPI_DBG_INIT
,
2425 "hotkey source mask 0x%08x, polling freq %d\n",
2426 hotkey_source_mask
, hotkey_poll_freq
);
2429 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2431 tp_features
.hotkey_wlsw
= 1;
2433 "radio switch emulation enabled\n");
2436 /* Not all thinkpads have a hardware radio switch */
2437 if (acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
2438 tp_features
.hotkey_wlsw
= 1;
2440 "radio switch found; radios are %s\n",
2441 enabled(status
, 0));
2443 if (tp_features
.hotkey_wlsw
)
2444 res
= add_to_attr_set(hotkey_dev_attributes
,
2445 &dev_attr_hotkey_radio_sw
.attr
);
2447 /* For X41t, X60t, X61t Tablets... */
2448 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
2449 tp_features
.hotkey_tablet
= 1;
2451 "possible tablet mode switch found; "
2452 "ThinkPad in %s mode\n",
2453 (status
& TP_HOTKEY_TABLET_MASK
)?
2454 "tablet" : "laptop");
2455 res
= add_to_attr_set(hotkey_dev_attributes
,
2456 &dev_attr_hotkey_tablet_mode
.attr
);
2460 res
= register_attr_set_with_sysfs(
2461 hotkey_dev_attributes
,
2462 &tpacpi_pdev
->dev
.kobj
);
2466 /* Set up key map */
2468 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
2470 if (!hotkey_keycode_map
) {
2472 "failed to allocate memory for key map\n");
2477 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
2478 dbg_printk(TPACPI_DBG_INIT
,
2479 "using Lenovo default hot key map\n");
2480 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
2481 TPACPI_HOTKEY_MAP_SIZE
);
2483 dbg_printk(TPACPI_DBG_INIT
,
2484 "using IBM default hot key map\n");
2485 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
2486 TPACPI_HOTKEY_MAP_SIZE
);
2489 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
2490 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
2491 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
2492 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
2493 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
2494 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
2495 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
2496 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
2497 set_bit(hotkey_keycode_map
[i
],
2498 tpacpi_inputdev
->keybit
);
2500 if (i
< sizeof(hotkey_reserved_mask
)*8)
2501 hotkey_reserved_mask
|= 1 << i
;
2505 if (tp_features
.hotkey_wlsw
) {
2506 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
2507 set_bit(SW_RFKILL_ALL
, tpacpi_inputdev
->swbit
);
2509 if (tp_features
.hotkey_tablet
) {
2510 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
2511 set_bit(SW_TABLET_MODE
, tpacpi_inputdev
->swbit
);
2514 /* Do not issue duplicate brightness change events to
2516 if (!tp_features
.bright_acpimode
)
2517 /* update bright_acpimode... */
2518 tpacpi_check_std_acpi_brightness_support();
2520 if (tp_features
.bright_acpimode
) {
2522 "This ThinkPad has standard ACPI backlight "
2523 "brightness control, supported by the ACPI "
2525 printk(TPACPI_NOTICE
2526 "Disabling thinkpad-acpi brightness events "
2529 /* The hotkey_reserved_mask change below is not
2530 * necessary while the keys are at KEY_RESERVED in the
2531 * default map, but better safe than sorry, leave it
2532 * here as a marker of what we have to do, especially
2533 * when we finally become able to set this at runtime
2534 * on response to X.org requests */
2535 hotkey_reserved_mask
|=
2536 (1 << TP_ACPI_HOTKEYSCAN_FNHOME
)
2537 | (1 << TP_ACPI_HOTKEYSCAN_FNEND
);
2540 dbg_printk(TPACPI_DBG_INIT
, "enabling hot key handling\n");
2541 res
= hotkey_status_set(1);
2546 res
= hotkey_mask_set(((hotkey_all_mask
| hotkey_source_mask
)
2547 & ~hotkey_reserved_mask
)
2548 | hotkey_orig_mask
);
2549 if (res
< 0 && res
!= -ENXIO
) {
2554 dbg_printk(TPACPI_DBG_INIT
,
2555 "legacy hot key reporting over procfs %s\n",
2556 (hotkey_report_mode
< 2) ?
2557 "enabled" : "disabled");
2559 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
2560 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
2562 hotkey_poll_setup_safe(1);
2563 tpacpi_send_radiosw_update();
2564 tpacpi_input_send_tabletsw();
2569 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2570 hotkey_dev_attributes
= NULL
;
2572 return (res
< 0)? res
: 1;
2575 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
2578 unsigned int scancode
;
2583 if (event
!= 0x80) {
2585 "unknown HKEY notification event %d\n", event
);
2586 /* forward it to userspace, maybe it knows how to handle it */
2587 acpi_bus_generate_netlink_event(
2588 ibm
->acpi
->device
->pnp
.device_class
,
2589 ibm
->acpi
->device
->dev
.bus_id
,
2595 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
2596 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
2609 switch (hkey
>> 12) {
2611 /* 0x1000-0x1FFF: key presses */
2612 scancode
= hkey
& 0xfff;
2613 if (scancode
> 0 && scancode
< 0x21) {
2615 if (!(hotkey_source_mask
& (1 << scancode
))) {
2616 tpacpi_input_send_key(scancode
);
2628 case 0x2304: /* suspend, undock */
2629 case 0x2404: /* hibernation, undock */
2630 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
2633 case 0x2305: /* suspend, bay eject */
2634 case 0x2405: /* hibernation, bay eject */
2635 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
2641 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
2643 "woke up due to a hot-unplug "
2645 hotkey_wakeup_reason_notify_change();
2649 /* bay-related wakeups */
2650 if (hkey
== 0x3003) {
2651 hotkey_autosleep_ack
= 1;
2654 hotkey_wakeup_hotunplug_complete_notify_change();
2660 /* dock-related wakeups */
2661 if (hkey
== 0x4003) {
2662 hotkey_autosleep_ack
= 1;
2665 hotkey_wakeup_hotunplug_complete_notify_change();
2671 /* 0x5000-0x5FFF: human interface helpers */
2673 case 0x5010: /* Lenovo new BIOS: brightness changed */
2674 case 0x500b: /* X61t: tablet pen inserted into bay */
2675 case 0x500c: /* X61t: tablet pen removed from bay */
2677 case 0x5009: /* X41t-X61t: swivel up (tablet mode) */
2678 case 0x500a: /* X41t-X61t: swivel down (normal mode) */
2679 tpacpi_input_send_tabletsw();
2680 hotkey_tablet_mode_notify_change();
2685 /* LID switch events. Do not propagate */
2693 /* 0x7000-0x7FFF: misc */
2694 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
2695 tpacpi_send_radiosw_update();
2699 /* fallthrough to default */
2704 printk(TPACPI_NOTICE
2705 "unhandled HKEY event 0x%04x\n", hkey
);
2709 if (!ignore_acpi_ev
&&
2710 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
2711 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
2715 /* netlink events */
2716 if (!ignore_acpi_ev
&& send_acpi_ev
) {
2717 acpi_bus_generate_netlink_event(
2718 ibm
->acpi
->device
->pnp
.device_class
,
2719 ibm
->acpi
->device
->dev
.bus_id
,
2725 static void hotkey_suspend(pm_message_t state
)
2727 /* Do these on suspend, we get the events on early resume! */
2728 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
2729 hotkey_autosleep_ack
= 0;
2732 static void hotkey_resume(void)
2734 tpacpi_disable_brightness_delay();
2736 if (hotkey_mask_get())
2738 "error while trying to read hot key mask "
2740 tpacpi_send_radiosw_update();
2741 hotkey_tablet_mode_notify_change();
2742 hotkey_wakeup_reason_notify_change();
2743 hotkey_wakeup_hotunplug_complete_notify_change();
2744 hotkey_poll_setup_safe(0);
2747 /* procfs -------------------------------------------------------------- */
2748 static int hotkey_read(char *p
)
2753 if (!tp_features
.hotkey
) {
2754 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2758 if (mutex_lock_interruptible(&hotkey_mutex
))
2759 return -ERESTARTSYS
;
2760 res
= hotkey_status_get(&status
);
2762 res
= hotkey_mask_get();
2763 mutex_unlock(&hotkey_mutex
);
2767 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
2768 if (tp_features
.hotkey_mask
) {
2769 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", hotkey_mask
);
2770 len
+= sprintf(p
+ len
,
2771 "commands:\tenable, disable, reset, <mask>\n");
2773 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
2774 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
2780 static int hotkey_write(char *buf
)
2786 if (!tp_features
.hotkey
)
2789 if (mutex_lock_interruptible(&hotkey_mutex
))
2790 return -ERESTARTSYS
;
2796 while ((cmd
= next_cmd(&buf
))) {
2797 if (strlencmp(cmd
, "enable") == 0) {
2799 } else if (strlencmp(cmd
, "disable") == 0) {
2801 } else if (strlencmp(cmd
, "reset") == 0) {
2802 status
= hotkey_orig_status
;
2803 mask
= hotkey_orig_mask
;
2804 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
2806 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
2814 res
= hotkey_status_set(status
);
2816 if (!res
&& mask
!= hotkey_mask
)
2817 res
= hotkey_mask_set(mask
);
2820 mutex_unlock(&hotkey_mutex
);
2824 static const struct acpi_device_id ibm_htk_device_ids
[] = {
2825 {TPACPI_ACPI_HKEY_HID
, 0},
2829 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
2830 .hid
= ibm_htk_device_ids
,
2831 .notify
= hotkey_notify
,
2832 .handle
= &hkey_handle
,
2833 .type
= ACPI_DEVICE_NOTIFY
,
2836 static struct ibm_struct hotkey_driver_data
= {
2838 .read
= hotkey_read
,
2839 .write
= hotkey_write
,
2840 .exit
= hotkey_exit
,
2841 .resume
= hotkey_resume
,
2842 .suspend
= hotkey_suspend
,
2843 .acpi
= &ibm_hotkey_acpidriver
,
2846 /*************************************************************************
2847 * Bluetooth subdriver
2851 /* ACPI GBDC/SBDC bits */
2852 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
2853 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
2854 TP_ACPI_BLUETOOTH_RESUMECTRL
= 0x04, /* Bluetooth state at resume:
2859 /* ACPI \BLTH commands */
2860 TP_ACPI_BLTH_GET_ULTRAPORT_ID
= 0x00, /* Get Ultraport BT ID */
2861 TP_ACPI_BLTH_GET_PWR_ON_RESUME
= 0x01, /* Get power-on-resume state */
2862 TP_ACPI_BLTH_PWR_ON_ON_RESUME
= 0x02, /* Resume powered on */
2863 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
= 0x03, /* Resume powered off */
2864 TP_ACPI_BLTH_SAVE_STATE
= 0x05, /* Save state for S4/S5 */
2867 static struct rfkill
*tpacpi_bluetooth_rfkill
;
2869 static void bluetooth_suspend(pm_message_t state
)
2871 /* Try to make sure radio will resume powered off */
2872 acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
2873 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
);
2876 static int bluetooth_get_radiosw(void)
2880 if (!tp_features
.bluetooth
)
2883 /* WLSW overrides bluetooth in firmware/hardware, reflect that */
2884 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
2885 return RFKILL_STATE_HARD_BLOCKED
;
2887 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2888 if (dbg_bluetoothemul
)
2889 return (tpacpi_bluetooth_emulstate
) ?
2890 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
2893 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
2896 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0) ?
2897 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
2900 static void bluetooth_update_rfk(void)
2904 if (!tpacpi_bluetooth_rfkill
)
2907 status
= bluetooth_get_radiosw();
2910 rfkill_force_state(tpacpi_bluetooth_rfkill
, status
);
2913 static int bluetooth_set_radiosw(int radio_on
, int update_rfk
)
2917 if (!tp_features
.bluetooth
)
2920 /* WLSW overrides bluetooth in firmware/hardware, but there is no
2921 * reason to risk weird behaviour. */
2922 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
2926 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2927 if (dbg_bluetoothemul
) {
2928 tpacpi_bluetooth_emulstate
= !!radio_on
;
2930 bluetooth_update_rfk();
2935 /* We make sure to keep TP_ACPI_BLUETOOTH_RESUMECTRL off */
2937 status
= TP_ACPI_BLUETOOTH_RADIOSSW
;
2940 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
2944 bluetooth_update_rfk();
2949 /* sysfs bluetooth enable ---------------------------------------------- */
2950 static ssize_t
bluetooth_enable_show(struct device
*dev
,
2951 struct device_attribute
*attr
,
2956 status
= bluetooth_get_radiosw();
2960 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2961 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
2964 static ssize_t
bluetooth_enable_store(struct device
*dev
,
2965 struct device_attribute
*attr
,
2966 const char *buf
, size_t count
)
2971 if (parse_strtoul(buf
, 1, &t
))
2974 res
= bluetooth_set_radiosw(t
, 1);
2976 return (res
) ? res
: count
;
2979 static struct device_attribute dev_attr_bluetooth_enable
=
2980 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
2981 bluetooth_enable_show
, bluetooth_enable_store
);
2983 /* --------------------------------------------------------------------- */
2985 static struct attribute
*bluetooth_attributes
[] = {
2986 &dev_attr_bluetooth_enable
.attr
,
2990 static const struct attribute_group bluetooth_attr_group
= {
2991 .attrs
= bluetooth_attributes
,
2994 static int tpacpi_bluetooth_rfk_get(void *data
, enum rfkill_state
*state
)
2996 int bts
= bluetooth_get_radiosw();
3005 static int tpacpi_bluetooth_rfk_set(void *data
, enum rfkill_state state
)
3007 return bluetooth_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
3010 static void bluetooth_shutdown(void)
3012 /* Order firmware to save current state to NVRAM */
3013 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3014 TP_ACPI_BLTH_SAVE_STATE
))
3015 printk(TPACPI_NOTICE
3016 "failed to save bluetooth state to NVRAM\n");
3019 static void bluetooth_exit(void)
3021 bluetooth_shutdown();
3023 if (tpacpi_bluetooth_rfkill
)
3024 rfkill_unregister(tpacpi_bluetooth_rfkill
);
3026 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3027 &bluetooth_attr_group
);
3030 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
3035 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
3037 TPACPI_ACPIHANDLE_INIT(hkey
);
3039 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
3040 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
3041 tp_features
.bluetooth
= hkey_handle
&&
3042 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
3044 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
3045 str_supported(tp_features
.bluetooth
),
3048 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3049 if (dbg_bluetoothemul
) {
3050 tp_features
.bluetooth
= 1;
3052 "bluetooth switch emulation enabled\n");
3055 if (tp_features
.bluetooth
&&
3056 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
3057 /* no bluetooth hardware present in system */
3058 tp_features
.bluetooth
= 0;
3059 dbg_printk(TPACPI_DBG_INIT
,
3060 "bluetooth hardware not installed\n");
3063 if (!tp_features
.bluetooth
)
3066 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3067 &bluetooth_attr_group
);
3071 res
= tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
,
3072 &tpacpi_bluetooth_rfkill
,
3073 RFKILL_TYPE_BLUETOOTH
,
3074 "tpacpi_bluetooth_sw",
3076 tpacpi_bluetooth_rfk_set
,
3077 tpacpi_bluetooth_rfk_get
);
3086 /* procfs -------------------------------------------------------------- */
3087 static int bluetooth_read(char *p
)
3090 int status
= bluetooth_get_radiosw();
3092 if (!tp_features
.bluetooth
)
3093 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3095 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3096 (status
== RFKILL_STATE_UNBLOCKED
) ?
3097 "enabled" : "disabled");
3098 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
3104 static int bluetooth_write(char *buf
)
3108 if (!tp_features
.bluetooth
)
3111 while ((cmd
= next_cmd(&buf
))) {
3112 if (strlencmp(cmd
, "enable") == 0) {
3113 bluetooth_set_radiosw(1, 1);
3114 } else if (strlencmp(cmd
, "disable") == 0) {
3115 bluetooth_set_radiosw(0, 1);
3123 static struct ibm_struct bluetooth_driver_data
= {
3124 .name
= "bluetooth",
3125 .read
= bluetooth_read
,
3126 .write
= bluetooth_write
,
3127 .exit
= bluetooth_exit
,
3128 .suspend
= bluetooth_suspend
,
3129 .shutdown
= bluetooth_shutdown
,
3132 /*************************************************************************
3137 /* ACPI GWAN/SWAN bits */
3138 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
3139 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
3140 TP_ACPI_WANCARD_RESUMECTRL
= 0x04, /* Wan state at resume:
3144 static struct rfkill
*tpacpi_wan_rfkill
;
3146 static void wan_suspend(pm_message_t state
)
3148 /* Try to make sure radio will resume powered off */
3149 acpi_evalf(NULL
, NULL
, "\\WGSV", "qvd",
3150 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
);
3153 static int wan_get_radiosw(void)
3157 if (!tp_features
.wan
)
3160 /* WLSW overrides WWAN in firmware/hardware, reflect that */
3161 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3162 return RFKILL_STATE_HARD_BLOCKED
;
3164 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3166 return (tpacpi_wwan_emulstate
) ?
3167 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3170 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
3173 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0) ?
3174 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3177 static void wan_update_rfk(void)
3181 if (!tpacpi_wan_rfkill
)
3184 status
= wan_get_radiosw();
3187 rfkill_force_state(tpacpi_wan_rfkill
, status
);
3190 static int wan_set_radiosw(int radio_on
, int update_rfk
)
3194 if (!tp_features
.wan
)
3197 /* WLSW overrides bluetooth in firmware/hardware, but there is no
3198 * reason to risk weird behaviour. */
3199 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3203 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3205 tpacpi_wwan_emulstate
= !!radio_on
;
3212 /* We make sure to keep TP_ACPI_WANCARD_RESUMECTRL off */
3214 status
= TP_ACPI_WANCARD_RADIOSSW
;
3217 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
3226 /* sysfs wan enable ---------------------------------------------------- */
3227 static ssize_t
wan_enable_show(struct device
*dev
,
3228 struct device_attribute
*attr
,
3233 status
= wan_get_radiosw();
3237 return snprintf(buf
, PAGE_SIZE
, "%d\n",
3238 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
3241 static ssize_t
wan_enable_store(struct device
*dev
,
3242 struct device_attribute
*attr
,
3243 const char *buf
, size_t count
)
3248 if (parse_strtoul(buf
, 1, &t
))
3251 res
= wan_set_radiosw(t
, 1);
3253 return (res
) ? res
: count
;
3256 static struct device_attribute dev_attr_wan_enable
=
3257 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
3258 wan_enable_show
, wan_enable_store
);
3260 /* --------------------------------------------------------------------- */
3262 static struct attribute
*wan_attributes
[] = {
3263 &dev_attr_wan_enable
.attr
,
3267 static const struct attribute_group wan_attr_group
= {
3268 .attrs
= wan_attributes
,
3271 static int tpacpi_wan_rfk_get(void *data
, enum rfkill_state
*state
)
3273 int wans
= wan_get_radiosw();
3282 static int tpacpi_wan_rfk_set(void *data
, enum rfkill_state state
)
3284 return wan_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
3287 static void wan_shutdown(void)
3289 /* Order firmware to save current state to NVRAM */
3290 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "vd",
3291 TP_ACPI_WGSV_SAVE_STATE
))
3292 printk(TPACPI_NOTICE
3293 "failed to save WWAN state to NVRAM\n");
3296 static void wan_exit(void)
3300 if (tpacpi_wan_rfkill
)
3301 rfkill_unregister(tpacpi_wan_rfkill
);
3303 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3307 static int __init
wan_init(struct ibm_init_struct
*iibm
)
3312 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
3314 TPACPI_ACPIHANDLE_INIT(hkey
);
3316 tp_features
.wan
= hkey_handle
&&
3317 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
3319 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
3320 str_supported(tp_features
.wan
),
3323 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3325 tp_features
.wan
= 1;
3327 "wwan switch emulation enabled\n");
3330 if (tp_features
.wan
&&
3331 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
3332 /* no wan hardware present in system */
3333 tp_features
.wan
= 0;
3334 dbg_printk(TPACPI_DBG_INIT
,
3335 "wan hardware not installed\n");
3338 if (!tp_features
.wan
)
3341 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3346 res
= tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID
,
3352 tpacpi_wan_rfk_get
);
3361 /* procfs -------------------------------------------------------------- */
3362 static int wan_read(char *p
)
3365 int status
= wan_get_radiosw();
3367 if (!tp_features
.wan
)
3368 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3370 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3371 (status
== RFKILL_STATE_UNBLOCKED
) ?
3372 "enabled" : "disabled");
3373 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
3379 static int wan_write(char *buf
)
3383 if (!tp_features
.wan
)
3386 while ((cmd
= next_cmd(&buf
))) {
3387 if (strlencmp(cmd
, "enable") == 0) {
3388 wan_set_radiosw(1, 1);
3389 } else if (strlencmp(cmd
, "disable") == 0) {
3390 wan_set_radiosw(0, 1);
3398 static struct ibm_struct wan_driver_data
= {
3403 .suspend
= wan_suspend
,
3404 .shutdown
= wan_shutdown
,
3407 /*************************************************************************
3412 /* ACPI GUWB/SUWB bits */
3413 TP_ACPI_UWB_HWPRESENT
= 0x01, /* UWB hw available */
3414 TP_ACPI_UWB_RADIOSSW
= 0x02, /* UWB radio enabled */
3417 static struct rfkill
*tpacpi_uwb_rfkill
;
3419 static int uwb_get_radiosw(void)
3423 if (!tp_features
.uwb
)
3426 /* WLSW overrides UWB in firmware/hardware, reflect that */
3427 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3428 return RFKILL_STATE_HARD_BLOCKED
;
3430 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3432 return (tpacpi_uwb_emulstate
) ?
3433 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3436 if (!acpi_evalf(hkey_handle
, &status
, "GUWB", "d"))
3439 return ((status
& TP_ACPI_UWB_RADIOSSW
) != 0) ?
3440 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3443 static void uwb_update_rfk(void)
3447 if (!tpacpi_uwb_rfkill
)
3450 status
= uwb_get_radiosw();
3453 rfkill_force_state(tpacpi_uwb_rfkill
, status
);
3456 static int uwb_set_radiosw(int radio_on
, int update_rfk
)
3460 if (!tp_features
.uwb
)
3463 /* WLSW overrides UWB in firmware/hardware, but there is no
3464 * reason to risk weird behaviour. */
3465 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3469 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3471 tpacpi_uwb_emulstate
= !!radio_on
;
3478 status
= (radio_on
) ? TP_ACPI_UWB_RADIOSSW
: 0;
3479 if (!acpi_evalf(hkey_handle
, NULL
, "SUWB", "vd", status
))
3488 /* --------------------------------------------------------------------- */
3490 static int tpacpi_uwb_rfk_get(void *data
, enum rfkill_state
*state
)
3492 int uwbs
= uwb_get_radiosw();
3501 static int tpacpi_uwb_rfk_set(void *data
, enum rfkill_state state
)
3503 return uwb_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
3506 static void uwb_exit(void)
3508 if (tpacpi_uwb_rfkill
)
3509 rfkill_unregister(tpacpi_uwb_rfkill
);
3512 static int __init
uwb_init(struct ibm_init_struct
*iibm
)
3517 vdbg_printk(TPACPI_DBG_INIT
, "initializing uwb subdriver\n");
3519 TPACPI_ACPIHANDLE_INIT(hkey
);
3521 tp_features
.uwb
= hkey_handle
&&
3522 acpi_evalf(hkey_handle
, &status
, "GUWB", "qd");
3524 vdbg_printk(TPACPI_DBG_INIT
, "uwb is %s, status 0x%02x\n",
3525 str_supported(tp_features
.uwb
),
3528 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3530 tp_features
.uwb
= 1;
3532 "uwb switch emulation enabled\n");
3535 if (tp_features
.uwb
&&
3536 !(status
& TP_ACPI_UWB_HWPRESENT
)) {
3537 /* no uwb hardware present in system */
3538 tp_features
.uwb
= 0;
3539 dbg_printk(TPACPI_DBG_INIT
,
3540 "uwb hardware not installed\n");
3543 if (!tp_features
.uwb
)
3546 res
= tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID
,
3552 tpacpi_uwb_rfk_get
);
3557 static struct ibm_struct uwb_driver_data
= {
3560 .flags
.experimental
= 1,
3563 /*************************************************************************
3567 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
3569 enum video_access_mode
{
3570 TPACPI_VIDEO_NONE
= 0,
3571 TPACPI_VIDEO_570
, /* 570 */
3572 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
3573 TPACPI_VIDEO_NEW
, /* all others */
3576 enum { /* video status flags, based on VIDEO_570 */
3577 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
3578 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
3579 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
3582 enum { /* TPACPI_VIDEO_570 constants */
3583 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
3584 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
3585 * video_status_flags */
3586 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
3587 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
3590 static enum video_access_mode video_supported
;
3591 static int video_orig_autosw
;
3593 static int video_autosw_get(void);
3594 static int video_autosw_set(int enable
);
3596 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
3598 static int __init
video_init(struct ibm_init_struct
*iibm
)
3602 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
3604 TPACPI_ACPIHANDLE_INIT(vid
);
3605 TPACPI_ACPIHANDLE_INIT(vid2
);
3607 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
3608 /* G41, assume IVGA doesn't change */
3609 vid_handle
= vid2_handle
;
3612 /* video switching not supported on R30, R31 */
3613 video_supported
= TPACPI_VIDEO_NONE
;
3614 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
3616 video_supported
= TPACPI_VIDEO_570
;
3617 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
3618 /* 600e/x, 770e, 770x */
3619 video_supported
= TPACPI_VIDEO_770
;
3622 video_supported
= TPACPI_VIDEO_NEW
;
3624 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
3625 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
3628 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
3631 static void video_exit(void)
3633 dbg_printk(TPACPI_DBG_EXIT
,
3634 "restoring original video autoswitch mode\n");
3635 if (video_autosw_set(video_orig_autosw
))
3636 printk(TPACPI_ERR
"error while trying to restore original "
3637 "video autoswitch mode\n");
3640 static int video_outputsw_get(void)
3645 switch (video_supported
) {
3646 case TPACPI_VIDEO_570
:
3647 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
3648 TP_ACPI_VIDEO_570_PHSCMD
))
3650 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
3652 case TPACPI_VIDEO_770
:
3653 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
3656 status
|= TP_ACPI_VIDEO_S_LCD
;
3657 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
3660 status
|= TP_ACPI_VIDEO_S_CRT
;
3662 case TPACPI_VIDEO_NEW
:
3663 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
3664 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
3667 status
|= TP_ACPI_VIDEO_S_CRT
;
3669 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
3670 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
3673 status
|= TP_ACPI_VIDEO_S_LCD
;
3674 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
3677 status
|= TP_ACPI_VIDEO_S_DVI
;
3686 static int video_outputsw_set(int status
)
3691 switch (video_supported
) {
3692 case TPACPI_VIDEO_570
:
3693 res
= acpi_evalf(NULL
, NULL
,
3694 "\\_SB.PHS2", "vdd",
3695 TP_ACPI_VIDEO_570_PHS2CMD
,
3696 status
| TP_ACPI_VIDEO_570_PHS2SET
);
3698 case TPACPI_VIDEO_770
:
3699 autosw
= video_autosw_get();
3703 res
= video_autosw_set(1);
3706 res
= acpi_evalf(vid_handle
, NULL
,
3707 "ASWT", "vdd", status
* 0x100, 0);
3708 if (!autosw
&& video_autosw_set(autosw
)) {
3710 "video auto-switch left enabled due to error\n");
3714 case TPACPI_VIDEO_NEW
:
3715 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
3716 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
3722 return (res
)? 0 : -EIO
;
3725 static int video_autosw_get(void)
3729 switch (video_supported
) {
3730 case TPACPI_VIDEO_570
:
3731 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
3734 case TPACPI_VIDEO_770
:
3735 case TPACPI_VIDEO_NEW
:
3736 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
3746 static int video_autosw_set(int enable
)
3748 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
3753 static int video_outputsw_cycle(void)
3755 int autosw
= video_autosw_get();
3761 switch (video_supported
) {
3762 case TPACPI_VIDEO_570
:
3763 res
= video_autosw_set(1);
3766 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
3768 case TPACPI_VIDEO_770
:
3769 case TPACPI_VIDEO_NEW
:
3770 res
= video_autosw_set(1);
3773 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
3778 if (!autosw
&& video_autosw_set(autosw
)) {
3780 "video auto-switch left enabled due to error\n");
3784 return (res
)? 0 : -EIO
;
3787 static int video_expand_toggle(void)
3789 switch (video_supported
) {
3790 case TPACPI_VIDEO_570
:
3791 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
3793 case TPACPI_VIDEO_770
:
3794 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
3796 case TPACPI_VIDEO_NEW
:
3797 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
3805 static int video_read(char *p
)
3810 if (video_supported
== TPACPI_VIDEO_NONE
) {
3811 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3815 status
= video_outputsw_get();
3819 autosw
= video_autosw_get();
3823 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3824 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
3825 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
3826 if (video_supported
== TPACPI_VIDEO_NEW
)
3827 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
3828 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
3829 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
3830 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
3831 if (video_supported
== TPACPI_VIDEO_NEW
)
3832 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
3833 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
3834 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
3839 static int video_write(char *buf
)
3842 int enable
, disable
, status
;
3845 if (video_supported
== TPACPI_VIDEO_NONE
)
3851 while ((cmd
= next_cmd(&buf
))) {
3852 if (strlencmp(cmd
, "lcd_enable") == 0) {
3853 enable
|= TP_ACPI_VIDEO_S_LCD
;
3854 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
3855 disable
|= TP_ACPI_VIDEO_S_LCD
;
3856 } else if (strlencmp(cmd
, "crt_enable") == 0) {
3857 enable
|= TP_ACPI_VIDEO_S_CRT
;
3858 } else if (strlencmp(cmd
, "crt_disable") == 0) {
3859 disable
|= TP_ACPI_VIDEO_S_CRT
;
3860 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
3861 strlencmp(cmd
, "dvi_enable") == 0) {
3862 enable
|= TP_ACPI_VIDEO_S_DVI
;
3863 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
3864 strlencmp(cmd
, "dvi_disable") == 0) {
3865 disable
|= TP_ACPI_VIDEO_S_DVI
;
3866 } else if (strlencmp(cmd
, "auto_enable") == 0) {
3867 res
= video_autosw_set(1);
3870 } else if (strlencmp(cmd
, "auto_disable") == 0) {
3871 res
= video_autosw_set(0);
3874 } else if (strlencmp(cmd
, "video_switch") == 0) {
3875 res
= video_outputsw_cycle();
3878 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
3879 res
= video_expand_toggle();
3886 if (enable
|| disable
) {
3887 status
= video_outputsw_get();
3890 res
= video_outputsw_set((status
& ~disable
) | enable
);
3898 static struct ibm_struct video_driver_data
= {
3901 .write
= video_write
,
3905 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
3907 /*************************************************************************
3908 * Light (thinklight) subdriver
3911 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
3912 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
3914 static int light_get_status(void)
3918 if (tp_features
.light_status
) {
3919 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
3927 static int light_set_status(int status
)
3931 if (tp_features
.light
) {
3933 rc
= acpi_evalf(cmos_handle
, NULL
, NULL
, "vd",
3935 TP_CMOS_THINKLIGHT_ON
:
3936 TP_CMOS_THINKLIGHT_OFF
);
3938 rc
= acpi_evalf(lght_handle
, NULL
, NULL
, "vd",
3941 return (rc
)? 0 : -EIO
;
3947 static void light_set_status_worker(struct work_struct
*work
)
3949 struct tpacpi_led_classdev
*data
=
3950 container_of(work
, struct tpacpi_led_classdev
, work
);
3952 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
3953 light_set_status((data
->new_brightness
!= LED_OFF
));
3956 static void light_sysfs_set(struct led_classdev
*led_cdev
,
3957 enum led_brightness brightness
)
3959 struct tpacpi_led_classdev
*data
=
3960 container_of(led_cdev
,
3961 struct tpacpi_led_classdev
,
3963 data
->new_brightness
= brightness
;
3964 queue_work(tpacpi_wq
, &data
->work
);
3967 static enum led_brightness
light_sysfs_get(struct led_classdev
*led_cdev
)
3969 return (light_get_status() == 1)? LED_FULL
: LED_OFF
;
3972 static struct tpacpi_led_classdev tpacpi_led_thinklight
= {
3974 .name
= "tpacpi::thinklight",
3975 .brightness_set
= &light_sysfs_set
,
3976 .brightness_get
= &light_sysfs_get
,
3980 static int __init
light_init(struct ibm_init_struct
*iibm
)
3984 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
3986 TPACPI_ACPIHANDLE_INIT(ledb
);
3987 TPACPI_ACPIHANDLE_INIT(lght
);
3988 TPACPI_ACPIHANDLE_INIT(cmos
);
3989 INIT_WORK(&tpacpi_led_thinklight
.work
, light_set_status_worker
);
3991 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
3992 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
3994 if (tp_features
.light
)
3995 /* light status not supported on
3996 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
3997 tp_features
.light_status
=
3998 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
4000 vdbg_printk(TPACPI_DBG_INIT
, "light is %s, light status is %s\n",
4001 str_supported(tp_features
.light
),
4002 str_supported(tp_features
.light_status
));
4004 if (!tp_features
.light
)
4007 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4008 &tpacpi_led_thinklight
.led_classdev
);
4011 tp_features
.light
= 0;
4012 tp_features
.light_status
= 0;
4020 static void light_exit(void)
4022 led_classdev_unregister(&tpacpi_led_thinklight
.led_classdev
);
4023 if (work_pending(&tpacpi_led_thinklight
.work
))
4024 flush_workqueue(tpacpi_wq
);
4027 static int light_read(char *p
)
4032 if (!tp_features
.light
) {
4033 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4034 } else if (!tp_features
.light_status
) {
4035 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
4036 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
4038 status
= light_get_status();
4041 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
4042 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
4048 static int light_write(char *buf
)
4053 if (!tp_features
.light
)
4056 while ((cmd
= next_cmd(&buf
))) {
4057 if (strlencmp(cmd
, "on") == 0) {
4059 } else if (strlencmp(cmd
, "off") == 0) {
4065 return light_set_status(newstatus
);
4068 static struct ibm_struct light_driver_data
= {
4071 .write
= light_write
,
4075 /*************************************************************************
4079 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4081 static void dock_notify(struct ibm_struct
*ibm
, u32 event
);
4082 static int dock_read(char *p
);
4083 static int dock_write(char *buf
);
4085 TPACPI_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
4086 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
4087 "\\_SB.PCI0.PCI1.DOCK", /* all others */
4088 "\\_SB.PCI.ISA.SLCE", /* 570 */
4089 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
4091 /* don't list other alternatives as we install a notify handler on the 570 */
4092 TPACPI_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
4094 static const struct acpi_device_id ibm_pci_device_ids
[] = {
4095 {PCI_ROOT_HID_STRING
, 0},
4099 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
4101 .notify
= dock_notify
,
4102 .handle
= &dock_handle
,
4103 .type
= ACPI_SYSTEM_NOTIFY
,
4106 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
4107 * We just use it to get notifications of dock hotplug
4108 * in very old thinkpads */
4109 .hid
= ibm_pci_device_ids
,
4110 .notify
= dock_notify
,
4111 .handle
= &pci_handle
,
4112 .type
= ACPI_SYSTEM_NOTIFY
,
4116 static struct ibm_struct dock_driver_data
[2] = {
4120 .write
= dock_write
,
4121 .acpi
= &ibm_dock_acpidriver
[0],
4125 .acpi
= &ibm_dock_acpidriver
[1],
4129 #define dock_docked() (_sta(dock_handle) & 1)
4131 static int __init
dock_init(struct ibm_init_struct
*iibm
)
4133 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
4135 TPACPI_ACPIHANDLE_INIT(dock
);
4137 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
4138 str_supported(dock_handle
!= NULL
));
4140 return (dock_handle
)? 0 : 1;
4143 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
4147 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
4149 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
4150 dock_driver_data
[0].flags
.acpi_notify_installed
) {
4151 TPACPI_ACPIHANDLE_INIT(pci
);
4152 dock2_needed
= (pci_handle
!= NULL
);
4153 vdbg_printk(TPACPI_DBG_INIT
,
4154 "dock PCI handler for the TP 570 is %s\n",
4155 str_supported(dock2_needed
));
4157 vdbg_printk(TPACPI_DBG_INIT
,
4158 "dock subdriver part 2 not required\n");
4162 return (dock2_needed
)? 0 : 1;
4165 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
4167 int docked
= dock_docked();
4168 int pci
= ibm
->acpi
->hid
&& ibm
->acpi
->device
&&
4169 acpi_match_device_ids(ibm
->acpi
->device
, ibm_pci_device_ids
);
4172 if (event
== 1 && !pci
) /* 570 */
4173 data
= 1; /* button */
4174 else if (event
== 1 && pci
) /* 570 */
4175 data
= 3; /* dock */
4176 else if (event
== 3 && docked
)
4177 data
= 1; /* button */
4178 else if (event
== 3 && !docked
)
4179 data
= 2; /* undock */
4180 else if (event
== 0 && docked
)
4181 data
= 3; /* dock */
4183 printk(TPACPI_ERR
"unknown dock event %d, status %d\n",
4184 event
, _sta(dock_handle
));
4185 data
= 0; /* unknown */
4187 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, data
);
4188 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
4189 ibm
->acpi
->device
->dev
.bus_id
,
4193 static int dock_read(char *p
)
4196 int docked
= dock_docked();
4199 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4201 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
4203 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
4204 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
4210 static int dock_write(char *buf
)
4217 while ((cmd
= next_cmd(&buf
))) {
4218 if (strlencmp(cmd
, "undock") == 0) {
4219 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
4220 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
4222 } else if (strlencmp(cmd
, "dock") == 0) {
4223 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
4232 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
4234 /*************************************************************************
4238 #ifdef CONFIG_THINKPAD_ACPI_BAY
4240 TPACPI_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
4241 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
4242 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
4243 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
4244 ); /* A21e, R30, R31 */
4245 TPACPI_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
4246 "_EJ0", /* all others */
4247 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
4248 TPACPI_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
4249 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
4251 TPACPI_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
4255 static int __init
bay_init(struct ibm_init_struct
*iibm
)
4257 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
4259 TPACPI_ACPIHANDLE_INIT(bay
);
4261 TPACPI_ACPIHANDLE_INIT(bay_ej
);
4262 TPACPI_ACPIHANDLE_INIT(bay2
);
4264 TPACPI_ACPIHANDLE_INIT(bay2_ej
);
4266 tp_features
.bay_status
= bay_handle
&&
4267 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
4268 tp_features
.bay_status2
= bay2_handle
&&
4269 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
4271 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
4272 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
4273 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
4274 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
4276 vdbg_printk(TPACPI_DBG_INIT
,
4277 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
4278 str_supported(tp_features
.bay_status
),
4279 str_supported(tp_features
.bay_eject
),
4280 str_supported(tp_features
.bay_status2
),
4281 str_supported(tp_features
.bay_eject2
));
4283 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
4284 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
4287 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
4289 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, 0);
4290 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
4291 ibm
->acpi
->device
->dev
.bus_id
,
4295 #define bay_occupied(b) (_sta(b##_handle) & 1)
4297 static int bay_read(char *p
)
4300 int occupied
= bay_occupied(bay
);
4301 int occupied2
= bay_occupied(bay2
);
4304 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
4305 tp_features
.bay_status
?
4306 (occupied
? "occupied" : "unoccupied") :
4308 if (tp_features
.bay_status2
)
4309 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
4310 "occupied" : "unoccupied");
4312 eject
= tp_features
.bay_eject
&& occupied
;
4313 eject2
= tp_features
.bay_eject2
&& occupied2
;
4315 if (eject
&& eject2
)
4316 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
4318 len
+= sprintf(p
+ len
, "commands:\teject\n");
4320 len
+= sprintf(p
+ len
, "commands:\teject2\n");
4325 static int bay_write(char *buf
)
4329 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
4332 while ((cmd
= next_cmd(&buf
))) {
4333 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
4334 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
4336 } else if (tp_features
.bay_eject2
&&
4337 strlencmp(cmd
, "eject2") == 0) {
4338 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
4347 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
4348 .notify
= bay_notify
,
4349 .handle
= &bay_handle
,
4350 .type
= ACPI_SYSTEM_NOTIFY
,
4353 static struct ibm_struct bay_driver_data
= {
4357 .acpi
= &ibm_bay_acpidriver
,
4360 #endif /* CONFIG_THINKPAD_ACPI_BAY */
4362 /*************************************************************************
4366 /* sysfs cmos_command -------------------------------------------------- */
4367 static ssize_t
cmos_command_store(struct device
*dev
,
4368 struct device_attribute
*attr
,
4369 const char *buf
, size_t count
)
4371 unsigned long cmos_cmd
;
4374 if (parse_strtoul(buf
, 21, &cmos_cmd
))
4377 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4378 return (res
)? res
: count
;
4381 static struct device_attribute dev_attr_cmos_command
=
4382 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
4384 /* --------------------------------------------------------------------- */
4386 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
4390 vdbg_printk(TPACPI_DBG_INIT
,
4391 "initializing cmos commands subdriver\n");
4393 TPACPI_ACPIHANDLE_INIT(cmos
);
4395 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
4396 str_supported(cmos_handle
!= NULL
));
4398 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4402 return (cmos_handle
)? 0 : 1;
4405 static void cmos_exit(void)
4407 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4410 static int cmos_read(char *p
)
4414 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4415 R30, R31, T20-22, X20-21 */
4417 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4419 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4420 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
4426 static int cmos_write(char *buf
)
4431 while ((cmd
= next_cmd(&buf
))) {
4432 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
4433 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
4438 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4446 static struct ibm_struct cmos_driver_data
= {
4449 .write
= cmos_write
,
4453 /*************************************************************************
4457 enum led_access_mode
{
4458 TPACPI_LED_NONE
= 0,
4459 TPACPI_LED_570
, /* 570 */
4460 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4461 TPACPI_LED_NEW
, /* all others */
4464 enum { /* For TPACPI_LED_OLD */
4465 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
4466 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
4467 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
4476 static enum led_access_mode led_supported
;
4478 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
4479 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
4480 /* T20-22, X20-21 */
4481 "LED", /* all others */
4484 #define TPACPI_LED_NUMLEDS 8
4485 static struct tpacpi_led_classdev
*tpacpi_leds
;
4486 static enum led_status_t tpacpi_led_state_cache
[TPACPI_LED_NUMLEDS
];
4487 static const char * const tpacpi_led_names
[TPACPI_LED_NUMLEDS
] = {
4488 /* there's a limit of 19 chars + NULL before 2.6.26 */
4490 "tpacpi:orange:batt",
4491 "tpacpi:green:batt",
4492 "tpacpi::dock_active",
4493 "tpacpi::bay_active",
4494 "tpacpi::dock_batt",
4495 "tpacpi::unknown_led",
4499 static int led_get_status(const unsigned int led
)
4502 enum led_status_t led_s
;
4504 switch (led_supported
) {
4505 case TPACPI_LED_570
:
4506 if (!acpi_evalf(ec_handle
,
4507 &status
, "GLED", "dd", 1 << led
))
4509 led_s
= (status
== 0)?
4514 tpacpi_led_state_cache
[led
] = led_s
;
4523 static int led_set_status(const unsigned int led
,
4524 const enum led_status_t ledstatus
)
4526 /* off, on, blink. Index is led_status_t */
4527 static const unsigned int led_sled_arg1
[] = { 0, 1, 3 };
4528 static const unsigned int led_led_arg1
[] = { 0, 0x80, 0xc0 };
4532 switch (led_supported
) {
4533 case TPACPI_LED_570
:
4537 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
4538 (1 << led
), led_sled_arg1
[ledstatus
]))
4541 case TPACPI_LED_OLD
:
4542 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
4545 rc
= ec_write(TPACPI_LED_EC_HLMS
, (1 << led
));
4547 rc
= ec_write(TPACPI_LED_EC_HLBL
,
4548 (ledstatus
== TPACPI_LED_BLINK
) << led
);
4550 rc
= ec_write(TPACPI_LED_EC_HLCL
,
4551 (ledstatus
!= TPACPI_LED_OFF
) << led
);
4553 case TPACPI_LED_NEW
:
4555 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
4556 led
, led_led_arg1
[ledstatus
]))
4564 tpacpi_led_state_cache
[led
] = ledstatus
;
4569 static void led_sysfs_set_status(unsigned int led
,
4570 enum led_brightness brightness
)
4573 (brightness
== LED_OFF
) ?
4575 (tpacpi_led_state_cache
[led
] == TPACPI_LED_BLINK
) ?
4576 TPACPI_LED_BLINK
: TPACPI_LED_ON
);
4579 static void led_set_status_worker(struct work_struct
*work
)
4581 struct tpacpi_led_classdev
*data
=
4582 container_of(work
, struct tpacpi_led_classdev
, work
);
4584 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4585 led_sysfs_set_status(data
->led
, data
->new_brightness
);
4588 static void led_sysfs_set(struct led_classdev
*led_cdev
,
4589 enum led_brightness brightness
)
4591 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4592 struct tpacpi_led_classdev
, led_classdev
);
4594 data
->new_brightness
= brightness
;
4595 queue_work(tpacpi_wq
, &data
->work
);
4598 static int led_sysfs_blink_set(struct led_classdev
*led_cdev
,
4599 unsigned long *delay_on
, unsigned long *delay_off
)
4601 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4602 struct tpacpi_led_classdev
, led_classdev
);
4604 /* Can we choose the flash rate? */
4605 if (*delay_on
== 0 && *delay_off
== 0) {
4606 /* yes. set them to the hardware blink rate (1 Hz) */
4607 *delay_on
= 500; /* ms */
4608 *delay_off
= 500; /* ms */
4609 } else if ((*delay_on
!= 500) || (*delay_off
!= 500))
4612 data
->new_brightness
= TPACPI_LED_BLINK
;
4613 queue_work(tpacpi_wq
, &data
->work
);
4618 static enum led_brightness
led_sysfs_get(struct led_classdev
*led_cdev
)
4622 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4623 struct tpacpi_led_classdev
, led_classdev
);
4625 rc
= led_get_status(data
->led
);
4627 if (rc
== TPACPI_LED_OFF
|| rc
< 0)
4628 rc
= LED_OFF
; /* no error handling in led class :( */
4635 static void led_exit(void)
4639 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
4640 if (tpacpi_leds
[i
].led_classdev
.name
)
4641 led_classdev_unregister(&tpacpi_leds
[i
].led_classdev
);
4647 static int __init
led_init(struct ibm_init_struct
*iibm
)
4652 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
4654 TPACPI_ACPIHANDLE_INIT(led
);
4657 /* led not supported on R30, R31 */
4658 led_supported
= TPACPI_LED_NONE
;
4659 else if (strlencmp(led_path
, "SLED") == 0)
4661 led_supported
= TPACPI_LED_570
;
4662 else if (strlencmp(led_path
, "SYSL") == 0)
4663 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4664 led_supported
= TPACPI_LED_OLD
;
4667 led_supported
= TPACPI_LED_NEW
;
4669 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
4670 str_supported(led_supported
), led_supported
);
4672 tpacpi_leds
= kzalloc(sizeof(*tpacpi_leds
) * TPACPI_LED_NUMLEDS
,
4675 printk(TPACPI_ERR
"Out of memory for LED data\n");
4679 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
4680 tpacpi_leds
[i
].led
= i
;
4682 tpacpi_leds
[i
].led_classdev
.brightness_set
= &led_sysfs_set
;
4683 tpacpi_leds
[i
].led_classdev
.blink_set
= &led_sysfs_blink_set
;
4684 if (led_supported
== TPACPI_LED_570
)
4685 tpacpi_leds
[i
].led_classdev
.brightness_get
=
4688 tpacpi_leds
[i
].led_classdev
.name
= tpacpi_led_names
[i
];
4690 INIT_WORK(&tpacpi_leds
[i
].work
, led_set_status_worker
);
4692 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4693 &tpacpi_leds
[i
].led_classdev
);
4695 tpacpi_leds
[i
].led_classdev
.name
= NULL
;
4701 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
4704 #define str_led_status(s) \
4705 ((s) == TPACPI_LED_OFF ? "off" : \
4706 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
4708 static int led_read(char *p
)
4712 if (!led_supported
) {
4713 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4716 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4718 if (led_supported
== TPACPI_LED_570
) {
4721 for (i
= 0; i
< 8; i
++) {
4722 status
= led_get_status(i
);
4725 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
4726 i
, str_led_status(status
));
4730 len
+= sprintf(p
+ len
, "commands:\t"
4731 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
4736 static int led_write(char *buf
)
4740 enum led_status_t s
;
4745 while ((cmd
= next_cmd(&buf
))) {
4746 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
4749 if (strstr(cmd
, "off")) {
4751 } else if (strstr(cmd
, "on")) {
4753 } else if (strstr(cmd
, "blink")) {
4754 s
= TPACPI_LED_BLINK
;
4759 rc
= led_set_status(led
, s
);
4767 static struct ibm_struct led_driver_data
= {
4774 /*************************************************************************
4778 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
4780 static int __init
beep_init(struct ibm_init_struct
*iibm
)
4782 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
4784 TPACPI_ACPIHANDLE_INIT(beep
);
4786 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
4787 str_supported(beep_handle
!= NULL
));
4789 return (beep_handle
)? 0 : 1;
4792 static int beep_read(char *p
)
4797 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4799 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4800 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
4806 static int beep_write(char *buf
)
4814 while ((cmd
= next_cmd(&buf
))) {
4815 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
4816 beep_cmd
>= 0 && beep_cmd
<= 17) {
4820 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
4827 static struct ibm_struct beep_driver_data
= {
4830 .write
= beep_write
,
4833 /*************************************************************************
4837 enum thermal_access_mode
{
4838 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
4839 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
4840 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
4841 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
4842 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
4845 enum { /* TPACPI_THERMAL_TPEC_* */
4846 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
4847 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
4848 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
4851 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
4852 struct ibm_thermal_sensors_struct
{
4853 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
4856 static enum thermal_access_mode thermal_read_mode
;
4858 /* idx is zero-based */
4859 static int thermal_get_sensor(int idx
, s32
*value
)
4865 t
= TP_EC_THERMAL_TMP0
;
4867 switch (thermal_read_mode
) {
4868 #if TPACPI_MAX_THERMAL_SENSORS >= 16
4869 case TPACPI_THERMAL_TPEC_16
:
4870 if (idx
>= 8 && idx
<= 15) {
4871 t
= TP_EC_THERMAL_TMP8
;
4876 case TPACPI_THERMAL_TPEC_8
:
4878 if (!acpi_ec_read(t
+ idx
, &tmp
))
4880 *value
= tmp
* 1000;
4885 case TPACPI_THERMAL_ACPI_UPDT
:
4887 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
4888 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
4890 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
4892 *value
= (t
- 2732) * 100;
4897 case TPACPI_THERMAL_ACPI_TMP07
:
4899 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
4900 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
4902 if (t
> 127 || t
< -127)
4903 t
= TP_EC_THERMAL_TMP_NA
;
4909 case TPACPI_THERMAL_NONE
:
4917 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
4928 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
4931 for (i
= 0 ; i
< n
; i
++) {
4932 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
4940 /* sysfs temp##_input -------------------------------------------------- */
4942 static ssize_t
thermal_temp_input_show(struct device
*dev
,
4943 struct device_attribute
*attr
,
4946 struct sensor_device_attribute
*sensor_attr
=
4947 to_sensor_dev_attr(attr
);
4948 int idx
= sensor_attr
->index
;
4952 res
= thermal_get_sensor(idx
, &value
);
4955 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
4958 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
4961 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
4962 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
4963 thermal_temp_input_show, NULL, _idxB)
4965 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
4966 THERMAL_SENSOR_ATTR_TEMP(1, 0),
4967 THERMAL_SENSOR_ATTR_TEMP(2, 1),
4968 THERMAL_SENSOR_ATTR_TEMP(3, 2),
4969 THERMAL_SENSOR_ATTR_TEMP(4, 3),
4970 THERMAL_SENSOR_ATTR_TEMP(5, 4),
4971 THERMAL_SENSOR_ATTR_TEMP(6, 5),
4972 THERMAL_SENSOR_ATTR_TEMP(7, 6),
4973 THERMAL_SENSOR_ATTR_TEMP(8, 7),
4974 THERMAL_SENSOR_ATTR_TEMP(9, 8),
4975 THERMAL_SENSOR_ATTR_TEMP(10, 9),
4976 THERMAL_SENSOR_ATTR_TEMP(11, 10),
4977 THERMAL_SENSOR_ATTR_TEMP(12, 11),
4978 THERMAL_SENSOR_ATTR_TEMP(13, 12),
4979 THERMAL_SENSOR_ATTR_TEMP(14, 13),
4980 THERMAL_SENSOR_ATTR_TEMP(15, 14),
4981 THERMAL_SENSOR_ATTR_TEMP(16, 15),
4984 #define THERMAL_ATTRS(X) \
4985 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
4987 static struct attribute
*thermal_temp_input_attr
[] = {
5007 static const struct attribute_group thermal_temp_input16_group
= {
5008 .attrs
= thermal_temp_input_attr
5011 static const struct attribute_group thermal_temp_input8_group
= {
5012 .attrs
= &thermal_temp_input_attr
[8]
5015 #undef THERMAL_SENSOR_ATTR_TEMP
5016 #undef THERMAL_ATTRS
5018 /* --------------------------------------------------------------------- */
5020 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
5027 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
5029 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
5031 if (thinkpad_id
.ec_model
) {
5033 * Direct EC access mode: sensors at registers
5034 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
5035 * non-implemented, thermal sensors return 0x80 when
5040 for (i
= 0; i
< 8; i
++) {
5041 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
5047 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
5055 /* This is sheer paranoia, but we handle it anyway */
5058 "ThinkPad ACPI EC access misbehaving, "
5059 "falling back to ACPI TMPx access "
5061 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5064 "ThinkPad ACPI EC access misbehaving, "
5065 "disabling thermal sensors access\n");
5066 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5071 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
5073 } else if (acpi_tmp7
) {
5074 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
5075 /* 600e/x, 770e, 770x */
5076 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
5078 /* Standard ACPI TMPx access, max 8 sensors */
5079 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5082 /* temperatures not supported on 570, G4x, R30, R31, R32 */
5083 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5086 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
5087 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
5090 switch (thermal_read_mode
) {
5091 case TPACPI_THERMAL_TPEC_16
:
5092 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5093 &thermal_temp_input16_group
);
5097 case TPACPI_THERMAL_TPEC_8
:
5098 case TPACPI_THERMAL_ACPI_TMP07
:
5099 case TPACPI_THERMAL_ACPI_UPDT
:
5100 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5101 &thermal_temp_input8_group
);
5105 case TPACPI_THERMAL_NONE
:
5113 static void thermal_exit(void)
5115 switch (thermal_read_mode
) {
5116 case TPACPI_THERMAL_TPEC_16
:
5117 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5118 &thermal_temp_input16_group
);
5120 case TPACPI_THERMAL_TPEC_8
:
5121 case TPACPI_THERMAL_ACPI_TMP07
:
5122 case TPACPI_THERMAL_ACPI_UPDT
:
5123 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5124 &thermal_temp_input16_group
);
5126 case TPACPI_THERMAL_NONE
:
5132 static int thermal_read(char *p
)
5136 struct ibm_thermal_sensors_struct t
;
5138 n
= thermal_get_sensors(&t
);
5139 if (unlikely(n
< 0))
5142 len
+= sprintf(p
+ len
, "temperatures:\t");
5145 for (i
= 0; i
< (n
- 1); i
++)
5146 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
5147 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
5149 len
+= sprintf(p
+ len
, "not supported\n");
5154 static struct ibm_struct thermal_driver_data
= {
5156 .read
= thermal_read
,
5157 .exit
= thermal_exit
,
5160 /*************************************************************************
5164 static u8 ecdump_regs
[256];
5166 static int ecdump_read(char *p
)
5172 len
+= sprintf(p
+ len
, "EC "
5173 " +00 +01 +02 +03 +04 +05 +06 +07"
5174 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
5175 for (i
= 0; i
< 256; i
+= 16) {
5176 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
5177 for (j
= 0; j
< 16; j
++) {
5178 if (!acpi_ec_read(i
+ j
, &v
))
5180 if (v
!= ecdump_regs
[i
+ j
])
5181 len
+= sprintf(p
+ len
, " *%02x", v
);
5183 len
+= sprintf(p
+ len
, " %02x", v
);
5184 ecdump_regs
[i
+ j
] = v
;
5186 len
+= sprintf(p
+ len
, "\n");
5191 /* These are way too dangerous to advertise openly... */
5193 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
5194 " (<offset> is 00-ff, <value> is 00-ff)\n");
5195 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
5196 " (<offset> is 00-ff, <value> is 0-255)\n");
5201 static int ecdump_write(char *buf
)
5206 while ((cmd
= next_cmd(&buf
))) {
5207 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
5209 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
5213 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
5214 if (!acpi_ec_write(i
, v
))
5223 static struct ibm_struct ecdump_driver_data
= {
5225 .read
= ecdump_read
,
5226 .write
= ecdump_write
,
5227 .flags
.experimental
= 1,
5230 /*************************************************************************
5231 * Backlight/brightness subdriver
5234 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
5237 TP_EC_BACKLIGHT
= 0x31,
5239 /* TP_EC_BACKLIGHT bitmasks */
5240 TP_EC_BACKLIGHT_LVLMSK
= 0x1F,
5241 TP_EC_BACKLIGHT_CMDMSK
= 0xE0,
5242 TP_EC_BACKLIGHT_MAPSW
= 0x20,
5245 static struct backlight_device
*ibm_backlight_device
;
5246 static int brightness_mode
;
5247 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
5249 static struct mutex brightness_mutex
;
5252 * ThinkPads can read brightness from two places: EC 0x31, or
5253 * CMOS NVRAM byte 0x5E, bits 0-3.
5255 * EC 0x31 has the following layout
5256 * Bit 7: unknown function
5257 * Bit 6: unknown function
5258 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
5259 * Bit 4: must be set to zero to avoid problems
5260 * Bit 3-0: backlight brightness level
5262 * brightness_get_raw returns status data in the EC 0x31 layout
5264 static int brightness_get_raw(int *status
)
5266 u8 lec
= 0, lcmos
= 0, level
= 0;
5268 if (brightness_mode
& 1) {
5269 if (!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
))
5271 level
= lec
& TP_EC_BACKLIGHT_LVLMSK
;
5273 if (brightness_mode
& 2) {
5274 lcmos
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
5275 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5276 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
5277 lcmos
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
5281 if (brightness_mode
== 3) {
5282 *status
= lec
; /* Prefer EC, CMOS is just a backing store */
5283 lec
&= TP_EC_BACKLIGHT_LVLMSK
;
5285 tp_warned
.bright_cmos_ec_unsync
= 0;
5287 if (!tp_warned
.bright_cmos_ec_unsync
) {
5289 "CMOS NVRAM (%u) and EC (%u) do not "
5290 "agree on display brightness level\n",
5291 (unsigned int) lcmos
,
5292 (unsigned int) lec
);
5293 tp_warned
.bright_cmos_ec_unsync
= 1;
5304 /* May return EINTR which can always be mapped to ERESTARTSYS */
5305 static int brightness_set(int value
)
5307 int cmos_cmd
, inc
, i
, res
;
5311 if (value
> ((tp_features
.bright_16levels
)? 15 : 7) ||
5315 res
= mutex_lock_interruptible(&brightness_mutex
);
5319 res
= brightness_get_raw(¤t_value
);
5323 command_bits
= current_value
& TP_EC_BACKLIGHT_CMDMSK
;
5324 current_value
&= TP_EC_BACKLIGHT_LVLMSK
;
5326 cmos_cmd
= value
> current_value
?
5327 TP_CMOS_BRIGHTNESS_UP
:
5328 TP_CMOS_BRIGHTNESS_DOWN
;
5329 inc
= (value
> current_value
)? 1 : -1;
5332 for (i
= current_value
; i
!= value
; i
+= inc
) {
5333 if ((brightness_mode
& 2) &&
5334 issue_thinkpad_cmos_command(cmos_cmd
)) {
5338 if ((brightness_mode
& 1) &&
5339 !acpi_ec_write(TP_EC_BACKLIGHT
,
5340 (i
+ inc
) | command_bits
)) {
5347 mutex_unlock(&brightness_mutex
);
5351 /* sysfs backlight class ----------------------------------------------- */
5353 static int brightness_update_status(struct backlight_device
*bd
)
5355 /* it is the backlight class's job (caller) to handle
5356 * EINTR and other errors properly */
5357 return brightness_set(
5358 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
5359 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
5360 bd
->props
.brightness
: 0);
5363 static int brightness_get(struct backlight_device
*bd
)
5367 res
= brightness_get_raw(&status
);
5369 return 0; /* FIXME: teach backlight about error handling */
5371 return status
& TP_EC_BACKLIGHT_LVLMSK
;
5374 static struct backlight_ops ibm_backlight_data
= {
5375 .get_brightness
= brightness_get
,
5376 .update_status
= brightness_update_status
,
5379 /* --------------------------------------------------------------------- */
5381 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
5385 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
5387 mutex_init(&brightness_mutex
);
5390 * We always attempt to detect acpi support, so as to switch
5391 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
5392 * going to publish a backlight interface
5394 b
= tpacpi_check_std_acpi_brightness_support();
5396 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
5397 printk(TPACPI_NOTICE
5398 "Lenovo BIOS switched to ACPI backlight "
5401 if (brightness_enable
> 1) {
5402 printk(TPACPI_NOTICE
5403 "standard ACPI backlight interface "
5404 "available, not loading native one...\n");
5409 if (!brightness_enable
) {
5410 dbg_printk(TPACPI_DBG_INIT
,
5411 "brightness support disabled by "
5412 "module parameter\n");
5418 "Unsupported brightness interface, "
5419 "please contact %s\n", TPACPI_MAIL
);
5423 tp_features
.bright_16levels
= 1;
5425 if (!brightness_mode
) {
5426 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
)
5427 brightness_mode
= 2;
5429 brightness_mode
= 3;
5431 dbg_printk(TPACPI_DBG_INIT
, "selected brightness_mode=%d\n",
5435 if (brightness_mode
> 3)
5438 if (brightness_get_raw(&b
) < 0)
5441 if (tp_features
.bright_16levels
)
5443 "detected a 16-level brightness capable ThinkPad\n");
5445 ibm_backlight_device
= backlight_device_register(
5446 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
5447 &ibm_backlight_data
);
5448 if (IS_ERR(ibm_backlight_device
)) {
5449 printk(TPACPI_ERR
"Could not register backlight device\n");
5450 return PTR_ERR(ibm_backlight_device
);
5452 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
5454 ibm_backlight_device
->props
.max_brightness
=
5455 (tp_features
.bright_16levels
)? 15 : 7;
5456 ibm_backlight_device
->props
.brightness
= b
& TP_EC_BACKLIGHT_LVLMSK
;
5457 backlight_update_status(ibm_backlight_device
);
5462 static void brightness_exit(void)
5464 if (ibm_backlight_device
) {
5465 vdbg_printk(TPACPI_DBG_EXIT
,
5466 "calling backlight_device_unregister()\n");
5467 backlight_device_unregister(ibm_backlight_device
);
5471 static int brightness_read(char *p
)
5476 level
= brightness_get(NULL
);
5478 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
5480 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
5481 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
5482 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
5483 " (<level> is 0-%d)\n",
5484 (tp_features
.bright_16levels
) ? 15 : 7);
5490 static int brightness_write(char *buf
)
5495 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
5497 level
= brightness_get(NULL
);
5501 while ((cmd
= next_cmd(&buf
))) {
5502 if (strlencmp(cmd
, "up") == 0) {
5503 if (level
< max_level
)
5505 } else if (strlencmp(cmd
, "down") == 0) {
5508 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
5509 level
>= 0 && level
<= max_level
) {
5516 * Now we know what the final level should be, so we try to set it.
5517 * Doing it this way makes the syscall restartable in case of EINTR
5519 rc
= brightness_set(level
);
5520 return (rc
== -EINTR
)? ERESTARTSYS
: rc
;
5523 static struct ibm_struct brightness_driver_data
= {
5524 .name
= "brightness",
5525 .read
= brightness_read
,
5526 .write
= brightness_write
,
5527 .exit
= brightness_exit
,
5530 /*************************************************************************
5534 static int volume_offset
= 0x30;
5536 static int volume_read(char *p
)
5541 if (!acpi_ec_read(volume_offset
, &level
)) {
5542 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
5544 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
5545 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
5546 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
5547 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
5548 " (<level> is 0-15)\n");
5554 static int volume_write(char *buf
)
5556 int cmos_cmd
, inc
, i
;
5558 int new_level
, new_mute
;
5561 while ((cmd
= next_cmd(&buf
))) {
5562 if (!acpi_ec_read(volume_offset
, &level
))
5564 new_mute
= mute
= level
& 0x40;
5565 new_level
= level
= level
& 0xf;
5567 if (strlencmp(cmd
, "up") == 0) {
5571 new_level
= level
== 15 ? 15 : level
+ 1;
5572 } else if (strlencmp(cmd
, "down") == 0) {
5576 new_level
= level
== 0 ? 0 : level
- 1;
5577 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
5578 new_level
>= 0 && new_level
<= 15) {
5580 } else if (strlencmp(cmd
, "mute") == 0) {
5585 if (new_level
!= level
) {
5586 /* mute doesn't change */
5588 cmos_cmd
= (new_level
> level
) ?
5589 TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
5590 inc
= new_level
> level
? 1 : -1;
5592 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
5593 !acpi_ec_write(volume_offset
, level
)))
5596 for (i
= level
; i
!= new_level
; i
+= inc
)
5597 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
5598 !acpi_ec_write(volume_offset
, i
+ inc
))
5602 (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
5603 !acpi_ec_write(volume_offset
, new_level
+ mute
))) {
5608 if (new_mute
!= mute
) {
5609 /* level doesn't change */
5611 cmos_cmd
= (new_mute
) ?
5612 TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
5614 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
5615 !acpi_ec_write(volume_offset
, level
+ new_mute
))
5623 static struct ibm_struct volume_driver_data
= {
5625 .read
= volume_read
,
5626 .write
= volume_write
,
5629 /*************************************************************************
5636 * TPACPI_FAN_RD_ACPI_GFAN:
5637 * ACPI GFAN method: returns fan level
5639 * see TPACPI_FAN_WR_ACPI_SFAN
5640 * EC 0x2f (HFSP) not available if GFAN exists
5642 * TPACPI_FAN_WR_ACPI_SFAN:
5643 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
5645 * EC 0x2f (HFSP) might be available *for reading*, but do not use
5648 * TPACPI_FAN_WR_TPEC:
5649 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
5650 * Supported on almost all ThinkPads
5652 * Fan speed changes of any sort (including those caused by the
5653 * disengaged mode) are usually done slowly by the firmware as the
5654 * maximum ammount of fan duty cycle change per second seems to be
5657 * Reading is not available if GFAN exists.
5658 * Writing is not available if SFAN exists.
5661 * 7 automatic mode engaged;
5662 * (default operation mode of the ThinkPad)
5663 * fan level is ignored in this mode.
5664 * 6 full speed mode (takes precedence over bit 7);
5665 * not available on all thinkpads. May disable
5666 * the tachometer while the fan controller ramps up
5667 * the speed (which can take up to a few *minutes*).
5668 * Speeds up fan to 100% duty-cycle, which is far above
5669 * the standard RPM levels. It is not impossible that
5670 * it could cause hardware damage.
5671 * 5-3 unused in some models. Extra bits for fan level
5672 * in others, but still useless as all values above
5673 * 7 map to the same speed as level 7 in these models.
5674 * 2-0 fan level (0..7 usually)
5676 * 0x07 = max (set when temperatures critical)
5677 * Some ThinkPads may have other levels, see
5678 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
5680 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
5681 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
5682 * does so, its initial value is meaningless (0x07).
5684 * For firmware bugs, refer to:
5685 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
5689 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
5690 * Main fan tachometer reading (in RPM)
5692 * This register is present on all ThinkPads with a new-style EC, and
5693 * it is known not to be present on the A21m/e, and T22, as there is
5694 * something else in offset 0x84 according to the ACPI DSDT. Other
5695 * ThinkPads from this same time period (and earlier) probably lack the
5696 * tachometer as well.
5698 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
5699 * was never fixed by IBM to report the EC firmware version string
5700 * probably support the tachometer (like the early X models), so
5701 * detecting it is quite hard. We need more data to know for sure.
5703 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
5706 * FIRMWARE BUG: may go stale while the EC is switching to full speed
5709 * For firmware bugs, refer to:
5710 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
5712 * TPACPI_FAN_WR_ACPI_FANS:
5713 * ThinkPad X31, X40, X41. Not available in the X60.
5715 * FANS ACPI handle: takes three arguments: low speed, medium speed,
5716 * high speed. ACPI DSDT seems to map these three speeds to levels
5717 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
5718 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
5720 * The speeds are stored on handles
5721 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
5723 * There are three default speed sets, acessible as handles:
5724 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
5726 * ACPI DSDT switches which set is in use depending on various
5729 * TPACPI_FAN_WR_TPEC is also available and should be used to
5730 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
5731 * but the ACPI tables just mention level 7.
5734 enum { /* Fan control constants */
5735 fan_status_offset
= 0x2f, /* EC register 0x2f */
5736 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
5737 * 0x84 must be read before 0x85 */
5739 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
5740 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
5742 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
5745 enum fan_status_access_mode
{
5746 TPACPI_FAN_NONE
= 0, /* No fan status or control */
5747 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
5748 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
5751 enum fan_control_access_mode
{
5752 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
5753 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
5754 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
5755 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
5758 enum fan_control_commands
{
5759 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
5760 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
5761 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
5762 * and also watchdog cmd */
5765 static int fan_control_allowed
;
5767 static enum fan_status_access_mode fan_status_access_mode
;
5768 static enum fan_control_access_mode fan_control_access_mode
;
5769 static enum fan_control_commands fan_control_commands
;
5771 static u8 fan_control_initial_status
;
5772 static u8 fan_control_desired_level
;
5773 static u8 fan_control_resume_level
;
5774 static int fan_watchdog_maxinterval
;
5776 static struct mutex fan_mutex
;
5778 static void fan_watchdog_fire(struct work_struct
*ignored
);
5779 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
5781 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
5782 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
5783 "\\FSPD", /* 600e/x, 770e, 770x */
5785 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
5786 "JFNS", /* 770x-JL */
5790 * Call with fan_mutex held
5792 static void fan_update_desired_level(u8 status
)
5795 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
5797 fan_control_desired_level
= 7;
5799 fan_control_desired_level
= status
;
5803 static int fan_get_status(u8
*status
)
5808 * Add TPACPI_FAN_RD_ACPI_FANS ? */
5810 switch (fan_status_access_mode
) {
5811 case TPACPI_FAN_RD_ACPI_GFAN
:
5812 /* 570, 600e/x, 770e, 770x */
5814 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
5822 case TPACPI_FAN_RD_TPEC
:
5823 /* all except 570, 600e/x, 770e, 770x */
5824 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
5839 static int fan_get_status_safe(u8
*status
)
5844 if (mutex_lock_interruptible(&fan_mutex
))
5845 return -ERESTARTSYS
;
5846 rc
= fan_get_status(&s
);
5848 fan_update_desired_level(s
);
5849 mutex_unlock(&fan_mutex
);
5857 static int fan_get_speed(unsigned int *speed
)
5861 switch (fan_status_access_mode
) {
5862 case TPACPI_FAN_RD_TPEC
:
5863 /* all except 570, 600e/x, 770e, 770x */
5864 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
5865 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
5869 *speed
= (hi
<< 8) | lo
;
5880 static int fan_set_level(int level
)
5882 if (!fan_control_allowed
)
5885 switch (fan_control_access_mode
) {
5886 case TPACPI_FAN_WR_ACPI_SFAN
:
5887 if (level
>= 0 && level
<= 7) {
5888 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
5894 case TPACPI_FAN_WR_ACPI_FANS
:
5895 case TPACPI_FAN_WR_TPEC
:
5896 if (!(level
& TP_EC_FAN_AUTO
) &&
5897 !(level
& TP_EC_FAN_FULLSPEED
) &&
5898 ((level
< 0) || (level
> 7)))
5901 /* safety net should the EC not support AUTO
5902 * or FULLSPEED mode bits and just ignore them */
5903 if (level
& TP_EC_FAN_FULLSPEED
)
5904 level
|= 7; /* safety min speed 7 */
5905 else if (level
& TP_EC_FAN_AUTO
)
5906 level
|= 4; /* safety min speed 4 */
5908 if (!acpi_ec_write(fan_status_offset
, level
))
5911 tp_features
.fan_ctrl_status_undef
= 0;
5920 static int fan_set_level_safe(int level
)
5924 if (!fan_control_allowed
)
5927 if (mutex_lock_interruptible(&fan_mutex
))
5928 return -ERESTARTSYS
;
5930 if (level
== TPACPI_FAN_LAST_LEVEL
)
5931 level
= fan_control_desired_level
;
5933 rc
= fan_set_level(level
);
5935 fan_update_desired_level(level
);
5937 mutex_unlock(&fan_mutex
);
5941 static int fan_set_enable(void)
5946 if (!fan_control_allowed
)
5949 if (mutex_lock_interruptible(&fan_mutex
))
5950 return -ERESTARTSYS
;
5952 switch (fan_control_access_mode
) {
5953 case TPACPI_FAN_WR_ACPI_FANS
:
5954 case TPACPI_FAN_WR_TPEC
:
5955 rc
= fan_get_status(&s
);
5959 /* Don't go out of emergency fan mode */
5962 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
5965 if (!acpi_ec_write(fan_status_offset
, s
))
5968 tp_features
.fan_ctrl_status_undef
= 0;
5973 case TPACPI_FAN_WR_ACPI_SFAN
:
5974 rc
= fan_get_status(&s
);
5980 /* Set fan to at least level 4 */
5983 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
5993 mutex_unlock(&fan_mutex
);
5997 static int fan_set_disable(void)
6001 if (!fan_control_allowed
)
6004 if (mutex_lock_interruptible(&fan_mutex
))
6005 return -ERESTARTSYS
;
6008 switch (fan_control_access_mode
) {
6009 case TPACPI_FAN_WR_ACPI_FANS
:
6010 case TPACPI_FAN_WR_TPEC
:
6011 if (!acpi_ec_write(fan_status_offset
, 0x00))
6014 fan_control_desired_level
= 0;
6015 tp_features
.fan_ctrl_status_undef
= 0;
6019 case TPACPI_FAN_WR_ACPI_SFAN
:
6020 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
6023 fan_control_desired_level
= 0;
6031 mutex_unlock(&fan_mutex
);
6035 static int fan_set_speed(int speed
)
6039 if (!fan_control_allowed
)
6042 if (mutex_lock_interruptible(&fan_mutex
))
6043 return -ERESTARTSYS
;
6046 switch (fan_control_access_mode
) {
6047 case TPACPI_FAN_WR_ACPI_FANS
:
6048 if (speed
>= 0 && speed
<= 65535) {
6049 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
6050 speed
, speed
, speed
))
6060 mutex_unlock(&fan_mutex
);
6064 static void fan_watchdog_reset(void)
6066 static int fan_watchdog_active
;
6068 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
6071 if (fan_watchdog_active
)
6072 cancel_delayed_work(&fan_watchdog_task
);
6074 if (fan_watchdog_maxinterval
> 0 &&
6075 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
6076 fan_watchdog_active
= 1;
6077 if (!queue_delayed_work(tpacpi_wq
, &fan_watchdog_task
,
6078 msecs_to_jiffies(fan_watchdog_maxinterval
6081 "failed to queue the fan watchdog, "
6082 "watchdog will not trigger\n");
6085 fan_watchdog_active
= 0;
6088 static void fan_watchdog_fire(struct work_struct
*ignored
)
6092 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
6095 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
6096 rc
= fan_set_enable();
6098 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
6099 "will try again later...\n", -rc
);
6100 /* reschedule for later */
6101 fan_watchdog_reset();
6106 * SYSFS fan layout: hwmon compatible (device)
6109 * 0: "disengaged" mode
6111 * 2: native EC "auto" mode (recommended, hardware default)
6113 * pwm*: set speed in manual mode, ignored otherwise.
6114 * 0 is level 0; 255 is level 7. Intermediate points done with linear
6117 * fan*_input: tachometer reading, RPM
6120 * SYSFS fan layout: extensions
6122 * fan_watchdog (driver):
6123 * fan watchdog interval in seconds, 0 disables (default), max 120
6126 /* sysfs fan pwm1_enable ----------------------------------------------- */
6127 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
6128 struct device_attribute
*attr
,
6134 res
= fan_get_status_safe(&status
);
6138 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
6139 if (status
!= fan_control_initial_status
) {
6140 tp_features
.fan_ctrl_status_undef
= 0;
6142 /* Return most likely status. In fact, it
6143 * might be the only possible status */
6144 status
= TP_EC_FAN_AUTO
;
6148 if (status
& TP_EC_FAN_FULLSPEED
) {
6150 } else if (status
& TP_EC_FAN_AUTO
) {
6155 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
6158 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
6159 struct device_attribute
*attr
,
6160 const char *buf
, size_t count
)
6165 if (parse_strtoul(buf
, 2, &t
))
6170 level
= TP_EC_FAN_FULLSPEED
;
6173 level
= TPACPI_FAN_LAST_LEVEL
;
6176 level
= TP_EC_FAN_AUTO
;
6179 /* reserved for software-controlled auto mode */
6185 res
= fan_set_level_safe(level
);
6191 fan_watchdog_reset();
6196 static struct device_attribute dev_attr_fan_pwm1_enable
=
6197 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
6198 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
6200 /* sysfs fan pwm1 ------------------------------------------------------ */
6201 static ssize_t
fan_pwm1_show(struct device
*dev
,
6202 struct device_attribute
*attr
,
6208 res
= fan_get_status_safe(&status
);
6212 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
6213 if (status
!= fan_control_initial_status
) {
6214 tp_features
.fan_ctrl_status_undef
= 0;
6216 status
= TP_EC_FAN_AUTO
;
6221 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
6222 status
= fan_control_desired_level
;
6227 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
6230 static ssize_t
fan_pwm1_store(struct device
*dev
,
6231 struct device_attribute
*attr
,
6232 const char *buf
, size_t count
)
6236 u8 status
, newlevel
;
6238 if (parse_strtoul(buf
, 255, &s
))
6241 /* scale down from 0-255 to 0-7 */
6242 newlevel
= (s
>> 5) & 0x07;
6244 if (mutex_lock_interruptible(&fan_mutex
))
6245 return -ERESTARTSYS
;
6247 rc
= fan_get_status(&status
);
6248 if (!rc
&& (status
&
6249 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
6250 rc
= fan_set_level(newlevel
);
6254 fan_update_desired_level(newlevel
);
6255 fan_watchdog_reset();
6259 mutex_unlock(&fan_mutex
);
6260 return (rc
)? rc
: count
;
6263 static struct device_attribute dev_attr_fan_pwm1
=
6264 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
6265 fan_pwm1_show
, fan_pwm1_store
);
6267 /* sysfs fan fan1_input ------------------------------------------------ */
6268 static ssize_t
fan_fan1_input_show(struct device
*dev
,
6269 struct device_attribute
*attr
,
6275 res
= fan_get_speed(&speed
);
6279 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
6282 static struct device_attribute dev_attr_fan_fan1_input
=
6283 __ATTR(fan1_input
, S_IRUGO
,
6284 fan_fan1_input_show
, NULL
);
6286 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
6287 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
6290 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
6293 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
6294 const char *buf
, size_t count
)
6298 if (parse_strtoul(buf
, 120, &t
))
6301 if (!fan_control_allowed
)
6304 fan_watchdog_maxinterval
= t
;
6305 fan_watchdog_reset();
6310 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
6311 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
6313 /* --------------------------------------------------------------------- */
6314 static struct attribute
*fan_attributes
[] = {
6315 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
6316 &dev_attr_fan_fan1_input
.attr
,
6320 static const struct attribute_group fan_attr_group
= {
6321 .attrs
= fan_attributes
,
6324 static int __init
fan_init(struct ibm_init_struct
*iibm
)
6328 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
6330 mutex_init(&fan_mutex
);
6331 fan_status_access_mode
= TPACPI_FAN_NONE
;
6332 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
6333 fan_control_commands
= 0;
6334 fan_watchdog_maxinterval
= 0;
6335 tp_features
.fan_ctrl_status_undef
= 0;
6336 fan_control_desired_level
= 7;
6338 TPACPI_ACPIHANDLE_INIT(fans
);
6339 TPACPI_ACPIHANDLE_INIT(gfan
);
6340 TPACPI_ACPIHANDLE_INIT(sfan
);
6343 /* 570, 600e/x, 770e, 770x */
6344 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
6346 /* all other ThinkPads: note that even old-style
6347 * ThinkPad ECs supports the fan control register */
6348 if (likely(acpi_ec_read(fan_status_offset
,
6349 &fan_control_initial_status
))) {
6350 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
6352 /* In some ThinkPads, neither the EC nor the ACPI
6353 * DSDT initialize the fan status, and it ends up
6354 * being set to 0x07 when it *could* be either
6357 * Enable for TP-1Y (T43), TP-78 (R51e),
6358 * TP-76 (R52), TP-70 (T43, R52), which are known
6360 if (fan_control_initial_status
== 0x07) {
6361 switch (thinkpad_id
.ec_model
) {
6362 case 0x5931: /* TP-1Y */
6363 case 0x3837: /* TP-78 */
6364 case 0x3637: /* TP-76 */
6365 case 0x3037: /* TP-70 */
6366 printk(TPACPI_NOTICE
6367 "fan_init: initial fan status "
6368 "is unknown, assuming it is "
6370 tp_features
.fan_ctrl_status_undef
= 1;
6376 "ThinkPad ACPI EC access misbehaving, "
6377 "fan status and control unavailable\n");
6384 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
6385 fan_control_commands
|=
6386 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
6389 /* gfan without sfan means no fan control */
6390 /* all other models implement TP EC 0x2f control */
6394 fan_control_access_mode
=
6395 TPACPI_FAN_WR_ACPI_FANS
;
6396 fan_control_commands
|=
6397 TPACPI_FAN_CMD_SPEED
|
6398 TPACPI_FAN_CMD_LEVEL
|
6399 TPACPI_FAN_CMD_ENABLE
;
6401 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
6402 fan_control_commands
|=
6403 TPACPI_FAN_CMD_LEVEL
|
6404 TPACPI_FAN_CMD_ENABLE
;
6409 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
6410 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
6411 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
6412 fan_status_access_mode
, fan_control_access_mode
);
6414 /* fan control master switch */
6415 if (!fan_control_allowed
) {
6416 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
6417 fan_control_commands
= 0;
6418 dbg_printk(TPACPI_DBG_INIT
,
6419 "fan control features disabled by parameter\n");
6422 /* update fan_control_desired_level */
6423 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
6424 fan_get_status_safe(NULL
);
6426 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
6427 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
6428 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
6433 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
6434 &driver_attr_fan_watchdog
);
6436 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
6445 static void fan_exit(void)
6447 vdbg_printk(TPACPI_DBG_EXIT
,
6448 "cancelling any pending fan watchdog tasks\n");
6450 /* FIXME: can we really do this unconditionally? */
6451 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
6452 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
6453 &driver_attr_fan_watchdog
);
6455 cancel_delayed_work(&fan_watchdog_task
);
6456 flush_workqueue(tpacpi_wq
);
6459 static void fan_suspend(pm_message_t state
)
6463 if (!fan_control_allowed
)
6466 /* Store fan status in cache */
6467 fan_control_resume_level
= 0;
6468 rc
= fan_get_status_safe(&fan_control_resume_level
);
6470 printk(TPACPI_NOTICE
6471 "failed to read fan level for later "
6472 "restore during resume: %d\n", rc
);
6474 /* if it is undefined, don't attempt to restore it.
6476 if (tp_features
.fan_ctrl_status_undef
)
6477 fan_control_resume_level
= 0;
6480 static void fan_resume(void)
6482 u8 current_level
= 7;
6483 bool do_set
= false;
6486 /* DSDT *always* updates status on resume */
6487 tp_features
.fan_ctrl_status_undef
= 0;
6489 if (!fan_control_allowed
||
6490 !fan_control_resume_level
||
6491 (fan_get_status_safe(¤t_level
) < 0))
6494 switch (fan_control_access_mode
) {
6495 case TPACPI_FAN_WR_ACPI_SFAN
:
6496 /* never decrease fan level */
6497 do_set
= (fan_control_resume_level
> current_level
);
6499 case TPACPI_FAN_WR_ACPI_FANS
:
6500 case TPACPI_FAN_WR_TPEC
:
6501 /* never decrease fan level, scale is:
6502 * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO
6504 * We expect the firmware to set either 7 or AUTO, but we
6505 * handle FULLSPEED out of paranoia.
6507 * So, we can safely only restore FULLSPEED or 7, anything
6508 * else could slow the fan. Restoring AUTO is useless, at
6509 * best that's exactly what the DSDT already set (it is the
6512 * Always keep in mind that the DSDT *will* have set the
6513 * fans to what the vendor supposes is the best level. We
6514 * muck with it only to speed the fan up.
6516 if (fan_control_resume_level
!= 7 &&
6517 !(fan_control_resume_level
& TP_EC_FAN_FULLSPEED
))
6520 do_set
= !(current_level
& TP_EC_FAN_FULLSPEED
) &&
6521 (current_level
!= fan_control_resume_level
);
6527 printk(TPACPI_NOTICE
6528 "restoring fan level to 0x%02x\n",
6529 fan_control_resume_level
);
6530 rc
= fan_set_level_safe(fan_control_resume_level
);
6532 printk(TPACPI_NOTICE
6533 "failed to restore fan level: %d\n", rc
);
6537 static int fan_read(char *p
)
6542 unsigned int speed
= 0;
6544 switch (fan_status_access_mode
) {
6545 case TPACPI_FAN_RD_ACPI_GFAN
:
6546 /* 570, 600e/x, 770e, 770x */
6547 rc
= fan_get_status_safe(&status
);
6551 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
6553 (status
!= 0) ? "enabled" : "disabled", status
);
6556 case TPACPI_FAN_RD_TPEC
:
6557 /* all except 570, 600e/x, 770e, 770x */
6558 rc
= fan_get_status_safe(&status
);
6562 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
6563 if (status
!= fan_control_initial_status
)
6564 tp_features
.fan_ctrl_status_undef
= 0;
6566 /* Return most likely status. In fact, it
6567 * might be the only possible status */
6568 status
= TP_EC_FAN_AUTO
;
6571 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
6572 (status
!= 0) ? "enabled" : "disabled");
6574 rc
= fan_get_speed(&speed
);
6578 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
6580 if (status
& TP_EC_FAN_FULLSPEED
)
6581 /* Disengaged mode takes precedence */
6582 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
6583 else if (status
& TP_EC_FAN_AUTO
)
6584 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
6586 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
6589 case TPACPI_FAN_NONE
:
6591 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
6594 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
6595 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
6597 switch (fan_control_access_mode
) {
6598 case TPACPI_FAN_WR_ACPI_SFAN
:
6599 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
6603 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
6604 "auto, disengaged, full-speed)\n");
6609 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
6610 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
6611 "commands:\twatchdog <timeout> (<timeout> "
6612 "is 0 (off), 1-120 (seconds))\n");
6614 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
6615 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
6616 " (<speed> is 0-65535)\n");
6621 static int fan_write_cmd_level(const char *cmd
, int *rc
)
6625 if (strlencmp(cmd
, "level auto") == 0)
6626 level
= TP_EC_FAN_AUTO
;
6627 else if ((strlencmp(cmd
, "level disengaged") == 0) |
6628 (strlencmp(cmd
, "level full-speed") == 0))
6629 level
= TP_EC_FAN_FULLSPEED
;
6630 else if (sscanf(cmd
, "level %d", &level
) != 1)
6633 *rc
= fan_set_level_safe(level
);
6635 printk(TPACPI_ERR
"level command accepted for unsupported "
6636 "access mode %d", fan_control_access_mode
);
6641 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
6643 if (strlencmp(cmd
, "enable") != 0)
6646 *rc
= fan_set_enable();
6648 printk(TPACPI_ERR
"enable command accepted for unsupported "
6649 "access mode %d", fan_control_access_mode
);
6654 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
6656 if (strlencmp(cmd
, "disable") != 0)
6659 *rc
= fan_set_disable();
6661 printk(TPACPI_ERR
"disable command accepted for unsupported "
6662 "access mode %d", fan_control_access_mode
);
6667 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
6672 * Support speed <low> <medium> <high> ? */
6674 if (sscanf(cmd
, "speed %d", &speed
) != 1)
6677 *rc
= fan_set_speed(speed
);
6679 printk(TPACPI_ERR
"speed command accepted for unsupported "
6680 "access mode %d", fan_control_access_mode
);
6685 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
6689 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
6692 if (interval
< 0 || interval
> 120)
6695 fan_watchdog_maxinterval
= interval
;
6700 static int fan_write(char *buf
)
6705 while (!rc
&& (cmd
= next_cmd(&buf
))) {
6706 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
6707 fan_write_cmd_level(cmd
, &rc
)) &&
6708 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
6709 (fan_write_cmd_enable(cmd
, &rc
) ||
6710 fan_write_cmd_disable(cmd
, &rc
) ||
6711 fan_write_cmd_watchdog(cmd
, &rc
))) &&
6712 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
6713 fan_write_cmd_speed(cmd
, &rc
))
6717 fan_watchdog_reset();
6723 static struct ibm_struct fan_driver_data
= {
6728 .suspend
= fan_suspend
,
6729 .resume
= fan_resume
,
6732 /****************************************************************************
6733 ****************************************************************************
6737 ****************************************************************************
6738 ****************************************************************************/
6740 /* sysfs name ---------------------------------------------------------- */
6741 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
6742 struct device_attribute
*attr
,
6745 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
6748 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
6749 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
6751 /* --------------------------------------------------------------------- */
6754 static struct proc_dir_entry
*proc_dir
;
6757 * Module and infrastructure proble, init and exit handling
6760 static int force_load
;
6762 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
6763 static const char * __init
str_supported(int is_supported
)
6765 static char text_unsupported
[] __initdata
= "not supported";
6767 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
6769 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
6771 static void ibm_exit(struct ibm_struct
*ibm
)
6773 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
6775 list_del_init(&ibm
->all_drivers
);
6777 if (ibm
->flags
.acpi_notify_installed
) {
6778 dbg_printk(TPACPI_DBG_EXIT
,
6779 "%s: acpi_remove_notify_handler\n", ibm
->name
);
6781 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
6783 dispatch_acpi_notify
);
6784 ibm
->flags
.acpi_notify_installed
= 0;
6785 ibm
->flags
.acpi_notify_installed
= 0;
6788 if (ibm
->flags
.proc_created
) {
6789 dbg_printk(TPACPI_DBG_EXIT
,
6790 "%s: remove_proc_entry\n", ibm
->name
);
6791 remove_proc_entry(ibm
->name
, proc_dir
);
6792 ibm
->flags
.proc_created
= 0;
6795 if (ibm
->flags
.acpi_driver_registered
) {
6796 dbg_printk(TPACPI_DBG_EXIT
,
6797 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
6799 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
6800 kfree(ibm
->acpi
->driver
);
6801 ibm
->acpi
->driver
= NULL
;
6802 ibm
->flags
.acpi_driver_registered
= 0;
6805 if (ibm
->flags
.init_called
&& ibm
->exit
) {
6807 ibm
->flags
.init_called
= 0;
6810 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
6813 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
6816 struct ibm_struct
*ibm
= iibm
->data
;
6817 struct proc_dir_entry
*entry
;
6819 BUG_ON(ibm
== NULL
);
6821 INIT_LIST_HEAD(&ibm
->all_drivers
);
6823 if (ibm
->flags
.experimental
&& !experimental
)
6826 dbg_printk(TPACPI_DBG_INIT
,
6827 "probing for %s\n", ibm
->name
);
6830 ret
= iibm
->init(iibm
);
6832 return 0; /* probe failed */
6836 ibm
->flags
.init_called
= 1;
6840 if (ibm
->acpi
->hid
) {
6841 ret
= register_tpacpi_subdriver(ibm
);
6846 if (ibm
->acpi
->notify
) {
6847 ret
= setup_acpi_notify(ibm
);
6848 if (ret
== -ENODEV
) {
6849 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
6859 dbg_printk(TPACPI_DBG_INIT
,
6860 "%s installed\n", ibm
->name
);
6863 entry
= create_proc_entry(ibm
->name
,
6864 S_IFREG
| S_IRUGO
| S_IWUSR
,
6867 printk(TPACPI_ERR
"unable to create proc entry %s\n",
6872 entry
->owner
= THIS_MODULE
;
6874 entry
->read_proc
= &dispatch_procfs_read
;
6876 entry
->write_proc
= &dispatch_procfs_write
;
6877 ibm
->flags
.proc_created
= 1;
6880 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
6885 dbg_printk(TPACPI_DBG_INIT
,
6886 "%s: at error exit path with result %d\n",
6890 return (ret
< 0)? ret
: 0;
6895 /* returns 0 - probe ok, or < 0 - probe error.
6896 * Probe ok doesn't mean thinkpad found.
6897 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
6898 static int __must_check __init
get_thinkpad_model_data(
6899 struct thinkpad_id_data
*tp
)
6901 const struct dmi_device
*dev
= NULL
;
6902 char ec_fw_string
[18];
6908 memset(tp
, 0, sizeof(*tp
));
6910 if (dmi_name_in_vendors("IBM"))
6911 tp
->vendor
= PCI_VENDOR_ID_IBM
;
6912 else if (dmi_name_in_vendors("LENOVO"))
6913 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
6917 s
= dmi_get_system_info(DMI_BIOS_VERSION
);
6918 tp
->bios_version_str
= kstrdup(s
, GFP_KERNEL
);
6919 if (s
&& !tp
->bios_version_str
)
6921 if (!tp
->bios_version_str
)
6923 tp
->bios_model
= tp
->bios_version_str
[0]
6924 | (tp
->bios_version_str
[1] << 8);
6927 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
6928 * X32 or newer, all Z series; Some models must have an
6929 * up-to-date BIOS or they will not be detected.
6931 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
6933 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
6934 if (sscanf(dev
->name
,
6935 "IBM ThinkPad Embedded Controller -[%17c",
6936 ec_fw_string
) == 1) {
6937 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
6938 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
6940 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
6941 if (!tp
->ec_version_str
)
6943 tp
->ec_model
= ec_fw_string
[0]
6944 | (ec_fw_string
[1] << 8);
6949 s
= dmi_get_system_info(DMI_PRODUCT_VERSION
);
6950 if (s
&& !strnicmp(s
, "ThinkPad", 8)) {
6951 tp
->model_str
= kstrdup(s
, GFP_KERNEL
);
6956 s
= dmi_get_system_info(DMI_PRODUCT_NAME
);
6957 tp
->nummodel_str
= kstrdup(s
, GFP_KERNEL
);
6958 if (s
&& !tp
->nummodel_str
)
6964 static int __init
probe_for_thinkpad(void)
6972 * Non-ancient models have better DMI tagging, but very old models
6975 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
6977 /* ec is required because many other handles are relative to it */
6978 TPACPI_ACPIHANDLE_INIT(ec
);
6982 "Not yet supported ThinkPad detected!\n");
6987 * Risks a regression on very old machines, but reduces potential
6988 * false positives a damn great deal
6991 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
6993 if (!is_thinkpad
&& !force_load
)
7000 /* Module init, exit, parameters */
7002 static struct ibm_init_struct ibms_init
[] __initdata
= {
7004 .init
= thinkpad_acpi_driver_init
,
7005 .data
= &thinkpad_acpi_driver_data
,
7008 .init
= hotkey_init
,
7009 .data
= &hotkey_driver_data
,
7012 .init
= bluetooth_init
,
7013 .data
= &bluetooth_driver_data
,
7017 .data
= &wan_driver_data
,
7021 .data
= &uwb_driver_data
,
7023 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
7026 .data
= &video_driver_data
,
7031 .data
= &light_driver_data
,
7033 #ifdef CONFIG_THINKPAD_ACPI_DOCK
7036 .data
= &dock_driver_data
[0],
7040 .data
= &dock_driver_data
[1],
7043 #ifdef CONFIG_THINKPAD_ACPI_BAY
7046 .data
= &bay_driver_data
,
7051 .data
= &cmos_driver_data
,
7055 .data
= &led_driver_data
,
7059 .data
= &beep_driver_data
,
7062 .init
= thermal_init
,
7063 .data
= &thermal_driver_data
,
7066 .data
= &ecdump_driver_data
,
7069 .init
= brightness_init
,
7070 .data
= &brightness_driver_data
,
7073 .data
= &volume_driver_data
,
7077 .data
= &fan_driver_data
,
7081 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
7084 struct ibm_struct
*ibm
;
7086 if (!kp
|| !kp
->name
|| !val
)
7089 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
7090 ibm
= ibms_init
[i
].data
;
7091 WARN_ON(ibm
== NULL
);
7093 if (!ibm
|| !ibm
->name
)
7096 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
7097 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
7099 strcpy(ibms_init
[i
].param
, val
);
7100 strcat(ibms_init
[i
].param
, ",");
7108 module_param(experimental
, int, 0);
7109 MODULE_PARM_DESC(experimental
,
7110 "Enables experimental features when non-zero");
7112 module_param_named(debug
, dbg_level
, uint
, 0);
7113 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
7115 module_param(force_load
, bool, 0);
7116 MODULE_PARM_DESC(force_load
,
7117 "Attempts to load the driver even on a "
7118 "mis-identified ThinkPad when true");
7120 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
7121 MODULE_PARM_DESC(fan_control
,
7122 "Enables setting fan parameters features when true");
7124 module_param_named(brightness_mode
, brightness_mode
, int, 0);
7125 MODULE_PARM_DESC(brightness_mode
,
7126 "Selects brightness control strategy: "
7127 "0=auto, 1=EC, 2=CMOS, 3=both");
7129 module_param(brightness_enable
, uint
, 0);
7130 MODULE_PARM_DESC(brightness_enable
,
7131 "Enables backlight control when 1, disables when 0");
7133 module_param(hotkey_report_mode
, uint
, 0);
7134 MODULE_PARM_DESC(hotkey_report_mode
,
7135 "used for backwards compatibility with userspace, "
7136 "see documentation");
7138 #define TPACPI_PARAM(feature) \
7139 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
7140 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
7141 "at module load, see documentation")
7143 TPACPI_PARAM(hotkey
);
7144 TPACPI_PARAM(bluetooth
);
7145 TPACPI_PARAM(video
);
7146 TPACPI_PARAM(light
);
7147 #ifdef CONFIG_THINKPAD_ACPI_DOCK
7150 #ifdef CONFIG_THINKPAD_ACPI_BAY
7152 #endif /* CONFIG_THINKPAD_ACPI_BAY */
7156 TPACPI_PARAM(ecdump
);
7157 TPACPI_PARAM(brightness
);
7158 TPACPI_PARAM(volume
);
7161 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
7162 module_param(dbg_wlswemul
, uint
, 0);
7163 MODULE_PARM_DESC(dbg_wlswemul
, "Enables WLSW emulation");
7164 module_param_named(wlsw_state
, tpacpi_wlsw_emulstate
, bool, 0);
7165 MODULE_PARM_DESC(wlsw_state
,
7166 "Initial state of the emulated WLSW switch");
7168 module_param(dbg_bluetoothemul
, uint
, 0);
7169 MODULE_PARM_DESC(dbg_bluetoothemul
, "Enables bluetooth switch emulation");
7170 module_param_named(bluetooth_state
, tpacpi_bluetooth_emulstate
, bool, 0);
7171 MODULE_PARM_DESC(bluetooth_state
,
7172 "Initial state of the emulated bluetooth switch");
7174 module_param(dbg_wwanemul
, uint
, 0);
7175 MODULE_PARM_DESC(dbg_wwanemul
, "Enables WWAN switch emulation");
7176 module_param_named(wwan_state
, tpacpi_wwan_emulstate
, bool, 0);
7177 MODULE_PARM_DESC(wwan_state
,
7178 "Initial state of the emulated WWAN switch");
7180 module_param(dbg_uwbemul
, uint
, 0);
7181 MODULE_PARM_DESC(dbg_uwbemul
, "Enables UWB switch emulation");
7182 module_param_named(uwb_state
, tpacpi_uwb_emulstate
, bool, 0);
7183 MODULE_PARM_DESC(uwb_state
,
7184 "Initial state of the emulated UWB switch");
7187 static void thinkpad_acpi_module_exit(void)
7189 struct ibm_struct
*ibm
, *itmp
;
7191 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
7193 list_for_each_entry_safe_reverse(ibm
, itmp
,
7194 &tpacpi_all_drivers
,
7199 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
7201 if (tpacpi_inputdev
) {
7202 if (tp_features
.input_device_registered
)
7203 input_unregister_device(tpacpi_inputdev
);
7205 input_free_device(tpacpi_inputdev
);
7209 hwmon_device_unregister(tpacpi_hwmon
);
7211 if (tp_features
.sensors_pdev_attrs_registered
)
7212 device_remove_file(&tpacpi_sensors_pdev
->dev
,
7213 &dev_attr_thinkpad_acpi_pdev_name
);
7214 if (tpacpi_sensors_pdev
)
7215 platform_device_unregister(tpacpi_sensors_pdev
);
7217 platform_device_unregister(tpacpi_pdev
);
7219 if (tp_features
.sensors_pdrv_attrs_registered
)
7220 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
7221 if (tp_features
.platform_drv_attrs_registered
)
7222 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
7224 if (tp_features
.sensors_pdrv_registered
)
7225 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
7227 if (tp_features
.platform_drv_registered
)
7228 platform_driver_unregister(&tpacpi_pdriver
);
7231 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
7234 destroy_workqueue(tpacpi_wq
);
7236 kfree(thinkpad_id
.bios_version_str
);
7237 kfree(thinkpad_id
.ec_version_str
);
7238 kfree(thinkpad_id
.model_str
);
7242 static int __init
thinkpad_acpi_module_init(void)
7246 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
7248 /* Parameter checking */
7249 if (hotkey_report_mode
> 2)
7252 /* Driver-level probe */
7254 ret
= get_thinkpad_model_data(&thinkpad_id
);
7257 "unable to get DMI data: %d\n", ret
);
7258 thinkpad_acpi_module_exit();
7261 ret
= probe_for_thinkpad();
7263 thinkpad_acpi_module_exit();
7267 /* Driver initialization */
7269 TPACPI_ACPIHANDLE_INIT(ecrd
);
7270 TPACPI_ACPIHANDLE_INIT(ecwr
);
7272 tpacpi_wq
= create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME
);
7274 thinkpad_acpi_module_exit();
7278 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
7281 "unable to create proc dir " TPACPI_PROC_DIR
);
7282 thinkpad_acpi_module_exit();
7285 proc_dir
->owner
= THIS_MODULE
;
7287 ret
= platform_driver_register(&tpacpi_pdriver
);
7290 "unable to register main platform driver\n");
7291 thinkpad_acpi_module_exit();
7294 tp_features
.platform_drv_registered
= 1;
7296 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
7299 "unable to register hwmon platform driver\n");
7300 thinkpad_acpi_module_exit();
7303 tp_features
.sensors_pdrv_registered
= 1;
7305 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
7307 tp_features
.platform_drv_attrs_registered
= 1;
7308 ret
= tpacpi_create_driver_attributes(
7309 &tpacpi_hwmon_pdriver
.driver
);
7313 "unable to create sysfs driver attributes\n");
7314 thinkpad_acpi_module_exit();
7317 tp_features
.sensors_pdrv_attrs_registered
= 1;
7320 /* Device initialization */
7321 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
7323 if (IS_ERR(tpacpi_pdev
)) {
7324 ret
= PTR_ERR(tpacpi_pdev
);
7326 printk(TPACPI_ERR
"unable to register platform device\n");
7327 thinkpad_acpi_module_exit();
7330 tpacpi_sensors_pdev
= platform_device_register_simple(
7331 TPACPI_HWMON_DRVR_NAME
,
7333 if (IS_ERR(tpacpi_sensors_pdev
)) {
7334 ret
= PTR_ERR(tpacpi_sensors_pdev
);
7335 tpacpi_sensors_pdev
= NULL
;
7337 "unable to register hwmon platform device\n");
7338 thinkpad_acpi_module_exit();
7341 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
7342 &dev_attr_thinkpad_acpi_pdev_name
);
7345 "unable to create sysfs hwmon device attributes\n");
7346 thinkpad_acpi_module_exit();
7349 tp_features
.sensors_pdev_attrs_registered
= 1;
7350 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
7351 if (IS_ERR(tpacpi_hwmon
)) {
7352 ret
= PTR_ERR(tpacpi_hwmon
);
7353 tpacpi_hwmon
= NULL
;
7354 printk(TPACPI_ERR
"unable to register hwmon device\n");
7355 thinkpad_acpi_module_exit();
7358 mutex_init(&tpacpi_inputdev_send_mutex
);
7359 tpacpi_inputdev
= input_allocate_device();
7360 if (!tpacpi_inputdev
) {
7361 printk(TPACPI_ERR
"unable to allocate input device\n");
7362 thinkpad_acpi_module_exit();
7365 /* Prepare input device, but don't register */
7366 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
7367 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
7368 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
7369 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
7370 thinkpad_id
.vendor
:
7372 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
7373 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
7375 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
7376 ret
= ibm_init(&ibms_init
[i
]);
7377 if (ret
>= 0 && *ibms_init
[i
].param
)
7378 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
7380 thinkpad_acpi_module_exit();
7384 ret
= input_register_device(tpacpi_inputdev
);
7386 printk(TPACPI_ERR
"unable to register input device\n");
7387 thinkpad_acpi_module_exit();
7390 tp_features
.input_device_registered
= 1;
7393 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
7397 /* Please remove this in year 2009 */
7398 MODULE_ALIAS("ibm_acpi");
7400 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME
);
7403 * DMI matching for module autoloading
7405 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
7406 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
7408 * Only models listed in thinkwiki will be supported, so add yours
7409 * if it is not there yet.
7411 #define IBM_BIOS_MODULE_ALIAS(__type) \
7412 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW")
7414 /* Non-ancient thinkpads */
7415 MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*");
7416 MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*");
7418 /* Ancient thinkpad BIOSes have to be identified by
7419 * BIOS type or model number, and there are far less
7420 * BIOS types than model numbers... */
7421 IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]");
7422 IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]");
7423 IBM_BIOS_MODULE_ALIAS("K[U,X-Z]");
7425 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
7426 MODULE_DESCRIPTION(TPACPI_DESC
);
7427 MODULE_VERSION(TPACPI_VERSION
);
7428 MODULE_LICENSE("GPL");
7430 module_init(thinkpad_acpi_module_init
);
7431 module_exit(thinkpad_acpi_module_exit
);