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
127 /****************************************************************************
131 #define TPACPI_NAME "thinkpad"
132 #define TPACPI_DESC "ThinkPad ACPI Extras"
133 #define TPACPI_FILE TPACPI_NAME "_acpi"
134 #define TPACPI_URL "http://ibm-acpi.sf.net/"
135 #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net"
137 #define TPACPI_PROC_DIR "ibm"
138 #define TPACPI_ACPI_EVENT_PREFIX "ibm"
139 #define TPACPI_DRVR_NAME TPACPI_FILE
140 #define TPACPI_DRVR_SHORTNAME "tpacpi"
141 #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon"
143 #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd"
144 #define TPACPI_WORKQUEUE_NAME "ktpacpid"
146 #define TPACPI_MAX_ACPI_ARGS 3
148 /* rfkill switches */
150 TPACPI_RFK_BLUETOOTH_SW_ID
= 0,
151 TPACPI_RFK_WWAN_SW_ID
,
155 #define TPACPI_LOG TPACPI_FILE ": "
156 #define TPACPI_ERR KERN_ERR TPACPI_LOG
157 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
158 #define TPACPI_INFO KERN_INFO TPACPI_LOG
159 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
161 #define TPACPI_DBG_ALL 0xffff
162 #define TPACPI_DBG_ALL 0xffff
163 #define TPACPI_DBG_INIT 0x0001
164 #define TPACPI_DBG_EXIT 0x0002
165 #define dbg_printk(a_dbg_level, format, arg...) \
166 do { if (dbg_level & a_dbg_level) \
167 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
169 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
170 #define vdbg_printk(a_dbg_level, format, arg...) \
171 dbg_printk(a_dbg_level, format, ## arg)
172 static const char *str_supported(int is_supported
);
174 #define vdbg_printk(a_dbg_level, format, arg...)
177 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
178 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
179 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
182 /****************************************************************************
183 * Driver-wide structs and misc. variables
188 struct tp_acpi_drv_struct
{
189 const struct acpi_device_id
*hid
;
190 struct acpi_driver
*driver
;
192 void (*notify
) (struct ibm_struct
*, u32
);
195 struct acpi_device
*device
;
201 int (*read
) (char *);
202 int (*write
) (char *);
204 void (*resume
) (void);
205 void (*suspend
) (pm_message_t state
);
207 struct list_head all_drivers
;
209 struct tp_acpi_drv_struct
*acpi
;
212 u8 acpi_driver_registered
:1;
213 u8 acpi_notify_installed
:1;
220 struct ibm_init_struct
{
223 int (*init
) (struct ibm_init_struct
*);
224 struct ibm_struct
*data
;
228 #ifdef CONFIG_THINKPAD_ACPI_BAY
241 u32 bright_16levels
:1;
242 u32 bright_acpimode
:1;
244 u32 fan_ctrl_status_undef
:1;
245 u32 input_device_registered
:1;
246 u32 platform_drv_registered
:1;
247 u32 platform_drv_attrs_registered
:1;
248 u32 sensors_pdrv_registered
:1;
249 u32 sensors_pdrv_attrs_registered
:1;
250 u32 sensors_pdev_attrs_registered
:1;
251 u32 hotkey_poll_active
:1;
255 u16 hotkey_mask_ff
:1;
256 u16 bright_cmos_ec_unsync
:1;
259 struct thinkpad_id_data
{
260 unsigned int vendor
; /* ThinkPad vendor:
261 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
263 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
264 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
266 u16 bios_model
; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */
269 char *model_str
; /* ThinkPad T43 */
270 char *nummodel_str
; /* 9384A9C for a 9384-A9C model */
272 static struct thinkpad_id_data thinkpad_id
;
275 TPACPI_LIFE_INIT
= 0,
280 static int experimental
;
281 static u32 dbg_level
;
283 static struct workqueue_struct
*tpacpi_wq
;
291 /* Special LED class that can defer work */
292 struct tpacpi_led_classdev
{
293 struct led_classdev led_classdev
;
294 struct work_struct work
;
295 enum led_status_t new_state
;
299 /****************************************************************************
300 ****************************************************************************
302 * ACPI Helpers and device model
304 ****************************************************************************
305 ****************************************************************************/
307 /*************************************************************************
311 static acpi_handle root_handle
;
313 #define TPACPI_HANDLE(object, parent, paths...) \
314 static acpi_handle object##_handle; \
315 static acpi_handle *object##_parent = &parent##_handle; \
316 static char *object##_path; \
317 static char *object##_paths[] = { paths }
319 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
320 "\\_SB.PCI.ISA.EC", /* 570 */
321 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
322 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
323 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
324 "\\_SB.PCI0.ICH3.EC0", /* R31 */
325 "\\_SB.PCI0.LPC.EC", /* all others */
328 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
329 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
331 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
333 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
334 "\\CMS", /* R40, R40e */
337 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
338 "^HKEY", /* R30, R31 */
339 "HKEY", /* all others */
342 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
343 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
344 "\\_SB.PCI0.VID0", /* 770e */
345 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
346 "\\_SB.PCI0.AGP.VID", /* all others */
350 /*************************************************************************
354 static int acpi_evalf(acpi_handle handle
,
355 void *res
, char *method
, char *fmt
, ...)
358 struct acpi_object_list params
;
359 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
360 struct acpi_buffer result
, *resultp
;
361 union acpi_object out_obj
;
369 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
382 params
.pointer
= &in_objs
[0];
389 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
390 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
392 /* add more types as needed */
394 printk(TPACPI_ERR
"acpi_evalf() called "
395 "with invalid format character '%c'\n", c
);
401 if (res_type
!= 'v') {
402 result
.length
= sizeof(out_obj
);
403 result
.pointer
= &out_obj
;
408 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
413 *(int *)res
= out_obj
.integer
.value
;
414 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
417 success
= status
== AE_OK
;
419 /* add more types as needed */
421 printk(TPACPI_ERR
"acpi_evalf() called "
422 "with invalid format character '%c'\n", res_type
);
426 if (!success
&& !quiet
)
427 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
428 method
, fmt0
, status
);
433 static int acpi_ec_read(int i
, u8
*p
)
438 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
442 if (ec_read(i
, p
) < 0)
449 static int acpi_ec_write(int i
, u8 v
)
452 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
455 if (ec_write(i
, v
) < 0)
462 #if defined(CONFIG_THINKPAD_ACPI_DOCK) || defined(CONFIG_THINKPAD_ACPI_BAY)
463 static int _sta(acpi_handle handle
)
467 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
474 static int issue_thinkpad_cmos_command(int cmos_cmd
)
479 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
485 /*************************************************************************
489 #define TPACPI_ACPIHANDLE_INIT(object) \
490 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
491 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
493 static void drv_acpi_handle_init(char *name
,
494 acpi_handle
*handle
, acpi_handle parent
,
495 char **paths
, int num_paths
, char **path
)
500 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
503 for (i
= 0; i
< num_paths
; i
++) {
504 status
= acpi_get_handle(parent
, paths
[i
], handle
);
505 if (ACPI_SUCCESS(status
)) {
507 dbg_printk(TPACPI_DBG_INIT
,
508 "Found ACPI handle %s for %s\n",
514 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
519 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
521 struct ibm_struct
*ibm
= data
;
523 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
526 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
529 ibm
->acpi
->notify(ibm
, event
);
532 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
539 if (!*ibm
->acpi
->handle
)
542 vdbg_printk(TPACPI_DBG_INIT
,
543 "setting up ACPI notify for %s\n", ibm
->name
);
545 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
547 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
552 acpi_driver_data(ibm
->acpi
->device
) = ibm
;
553 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
554 TPACPI_ACPI_EVENT_PREFIX
,
557 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
558 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
559 if (ACPI_FAILURE(status
)) {
560 if (status
== AE_ALREADY_EXISTS
) {
562 "another device driver is already "
563 "handling %s events\n", ibm
->name
);
566 "acpi_install_notify_handler(%s) failed: %d\n",
571 ibm
->flags
.acpi_notify_installed
= 1;
575 static int __init
tpacpi_device_add(struct acpi_device
*device
)
580 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
584 dbg_printk(TPACPI_DBG_INIT
,
585 "registering %s as an ACPI driver\n", ibm
->name
);
589 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
590 if (!ibm
->acpi
->driver
) {
591 printk(TPACPI_ERR
"kzalloc(ibm->driver) failed\n");
595 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
596 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
598 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
600 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
602 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
604 kfree(ibm
->acpi
->driver
);
605 ibm
->acpi
->driver
= NULL
;
607 ibm
->flags
.acpi_driver_registered
= 1;
613 /****************************************************************************
614 ****************************************************************************
618 ****************************************************************************
619 ****************************************************************************/
621 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
622 int count
, int *eof
, void *data
)
624 struct ibm_struct
*ibm
= data
;
627 if (!ibm
|| !ibm
->read
)
630 len
= ibm
->read(page
);
634 if (len
<= off
+ count
)
646 static int dispatch_procfs_write(struct file
*file
,
647 const char __user
*userbuf
,
648 unsigned long count
, void *data
)
650 struct ibm_struct
*ibm
= data
;
654 if (!ibm
|| !ibm
->write
)
657 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
661 if (copy_from_user(kernbuf
, userbuf
, count
)) {
667 strcat(kernbuf
, ",");
668 ret
= ibm
->write(kernbuf
);
677 static char *next_cmd(char **cmds
)
682 while ((end
= strchr(start
, ',')) && end
== start
)
694 /****************************************************************************
695 ****************************************************************************
697 * Device model: input, hwmon and platform
699 ****************************************************************************
700 ****************************************************************************/
702 static struct platform_device
*tpacpi_pdev
;
703 static struct platform_device
*tpacpi_sensors_pdev
;
704 static struct device
*tpacpi_hwmon
;
705 static struct input_dev
*tpacpi_inputdev
;
706 static struct mutex tpacpi_inputdev_send_mutex
;
707 static LIST_HEAD(tpacpi_all_drivers
);
709 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
712 struct ibm_struct
*ibm
, *itmp
;
714 list_for_each_entry_safe(ibm
, itmp
,
718 (ibm
->suspend
)(state
);
724 static int tpacpi_resume_handler(struct platform_device
*pdev
)
726 struct ibm_struct
*ibm
, *itmp
;
728 list_for_each_entry_safe(ibm
, itmp
,
738 static struct platform_driver tpacpi_pdriver
= {
740 .name
= TPACPI_DRVR_NAME
,
741 .owner
= THIS_MODULE
,
743 .suspend
= tpacpi_suspend_handler
,
744 .resume
= tpacpi_resume_handler
,
747 static struct platform_driver tpacpi_hwmon_pdriver
= {
749 .name
= TPACPI_HWMON_DRVR_NAME
,
750 .owner
= THIS_MODULE
,
754 /*************************************************************************
755 * sysfs support helpers
758 struct attribute_set
{
759 unsigned int members
, max_members
;
760 struct attribute_group group
;
763 struct attribute_set_obj
{
764 struct attribute_set s
;
766 } __attribute__((packed
));
768 static struct attribute_set
*create_attr_set(unsigned int max_members
,
771 struct attribute_set_obj
*sobj
;
773 if (max_members
== 0)
776 /* Allocates space for implicit NULL at the end too */
777 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
778 max_members
* sizeof(struct attribute
*),
782 sobj
->s
.max_members
= max_members
;
783 sobj
->s
.group
.attrs
= &sobj
->a
;
784 sobj
->s
.group
.name
= name
;
789 #define destroy_attr_set(_set) \
792 /* not multi-threaded safe, use it in a single thread per set */
793 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
798 if (s
->members
>= s
->max_members
)
801 s
->group
.attrs
[s
->members
] = attr
;
807 static int add_many_to_attr_set(struct attribute_set
*s
,
808 struct attribute
**attr
,
813 for (i
= 0; i
< count
; i
++) {
814 res
= add_to_attr_set(s
, attr
[i
]);
822 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
824 sysfs_remove_group(kobj
, &s
->group
);
828 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
829 sysfs_create_group(_kobj, &_attr_set->group)
831 static int parse_strtoul(const char *buf
,
832 unsigned long max
, unsigned long *value
)
836 while (*buf
&& isspace(*buf
))
838 *value
= simple_strtoul(buf
, &endp
, 0);
839 while (*endp
&& isspace(*endp
))
841 if (*endp
|| *value
> max
)
847 static int __init
tpacpi_query_bcl_levels(acpi_handle handle
)
849 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
850 union acpi_object
*obj
;
853 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
854 obj
= (union acpi_object
*)buffer
.pointer
;
855 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
856 printk(TPACPI_ERR
"Unknown _BCL data, "
857 "please report this to %s\n", TPACPI_MAIL
);
860 rc
= obj
->package
.count
;
866 kfree(buffer
.pointer
);
870 static acpi_status __init
tpacpi_acpi_walk_find_bcl(acpi_handle handle
,
871 u32 lvl
, void *context
, void **rv
)
873 char name
[ACPI_PATH_SEGMENT_LENGTH
];
874 struct acpi_buffer buffer
= { sizeof(name
), &name
};
876 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
877 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
879 **(int **)rv
= tpacpi_query_bcl_levels(handle
);
880 return AE_CTRL_TERMINATE
;
887 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
889 static int __init
tpacpi_check_std_acpi_brightness_support(void)
893 void *bcl_ptr
= &bcl_levels
;
896 TPACPI_ACPIHANDLE_INIT(vid
);
902 * Search for a _BCL method, and execute it. This is safe on all
903 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
904 * BIOS in ACPI backlight control mode. We do NOT have to care
905 * about calling the _BCL method in an enabled video device, any
906 * will do for our purposes.
909 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
910 tpacpi_acpi_walk_find_bcl
, NULL
,
913 if (ACPI_SUCCESS(status
) && bcl_levels
> 2) {
914 tp_features
.bright_acpimode
= 1;
915 return (bcl_levels
- 2);
921 static int __init
tpacpi_new_rfkill(const unsigned int id
,
923 const enum rfkill_type rfktype
,
925 int (*toggle_radio
)(void *, enum rfkill_state
),
926 int (*get_state
)(void *, enum rfkill_state
*))
929 enum rfkill_state initial_state
;
931 *rfk
= rfkill_allocate(&tpacpi_pdev
->dev
, rfktype
);
934 "failed to allocate memory for rfkill class\n");
939 (*rfk
)->get_state
= get_state
;
940 (*rfk
)->toggle_radio
= toggle_radio
;
942 if (!get_state(NULL
, &initial_state
))
943 (*rfk
)->state
= initial_state
;
945 res
= rfkill_register(*rfk
);
948 "failed to register %s rfkill switch: %d\n",
958 /*************************************************************************
959 * thinkpad-acpi driver attributes
962 /* interface_version --------------------------------------------------- */
963 static ssize_t
tpacpi_driver_interface_version_show(
964 struct device_driver
*drv
,
967 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
970 static DRIVER_ATTR(interface_version
, S_IRUGO
,
971 tpacpi_driver_interface_version_show
, NULL
);
973 /* debug_level --------------------------------------------------------- */
974 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
977 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
980 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
981 const char *buf
, size_t count
)
985 if (parse_strtoul(buf
, 0xffff, &t
))
993 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
994 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
996 /* version ------------------------------------------------------------- */
997 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
1000 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
1001 TPACPI_DESC
, TPACPI_VERSION
);
1004 static DRIVER_ATTR(version
, S_IRUGO
,
1005 tpacpi_driver_version_show
, NULL
);
1007 /* --------------------------------------------------------------------- */
1009 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
1010 &driver_attr_debug_level
, &driver_attr_version
,
1011 &driver_attr_interface_version
,
1014 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
1020 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
1021 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
1028 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
1032 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
1033 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
1036 /****************************************************************************
1037 ****************************************************************************
1041 ****************************************************************************
1042 ****************************************************************************/
1044 /*************************************************************************
1045 * thinkpad-acpi init subdriver
1048 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
1050 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
1051 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
1053 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
1054 (thinkpad_id
.bios_version_str
) ?
1055 thinkpad_id
.bios_version_str
: "unknown",
1056 (thinkpad_id
.ec_version_str
) ?
1057 thinkpad_id
.ec_version_str
: "unknown");
1059 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
1060 printk(TPACPI_INFO
"%s %s, model %s\n",
1061 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
1062 "IBM" : ((thinkpad_id
.vendor
==
1063 PCI_VENDOR_ID_LENOVO
) ?
1064 "Lenovo" : "Unknown vendor"),
1065 thinkpad_id
.model_str
,
1066 (thinkpad_id
.nummodel_str
) ?
1067 thinkpad_id
.nummodel_str
: "unknown");
1072 static int thinkpad_acpi_driver_read(char *p
)
1076 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", TPACPI_DESC
);
1077 len
+= sprintf(p
+ len
, "version:\t%s\n", TPACPI_VERSION
);
1082 static struct ibm_struct thinkpad_acpi_driver_data
= {
1084 .read
= thinkpad_acpi_driver_read
,
1087 /*************************************************************************
1091 enum { /* hot key scan codes (derived from ACPI DSDT) */
1092 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
1093 TP_ACPI_HOTKEYSCAN_FNF2
,
1094 TP_ACPI_HOTKEYSCAN_FNF3
,
1095 TP_ACPI_HOTKEYSCAN_FNF4
,
1096 TP_ACPI_HOTKEYSCAN_FNF5
,
1097 TP_ACPI_HOTKEYSCAN_FNF6
,
1098 TP_ACPI_HOTKEYSCAN_FNF7
,
1099 TP_ACPI_HOTKEYSCAN_FNF8
,
1100 TP_ACPI_HOTKEYSCAN_FNF9
,
1101 TP_ACPI_HOTKEYSCAN_FNF10
,
1102 TP_ACPI_HOTKEYSCAN_FNF11
,
1103 TP_ACPI_HOTKEYSCAN_FNF12
,
1104 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
1105 TP_ACPI_HOTKEYSCAN_FNINSERT
,
1106 TP_ACPI_HOTKEYSCAN_FNDELETE
,
1107 TP_ACPI_HOTKEYSCAN_FNHOME
,
1108 TP_ACPI_HOTKEYSCAN_FNEND
,
1109 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1110 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
1111 TP_ACPI_HOTKEYSCAN_FNSPACE
,
1112 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1113 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1114 TP_ACPI_HOTKEYSCAN_MUTE
,
1115 TP_ACPI_HOTKEYSCAN_THINKPAD
,
1118 enum { /* Keys available through NVRAM polling */
1119 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
1120 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
1123 enum { /* Positions of some of the keys in hotkey masks */
1124 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
1125 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
1126 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
1127 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
1128 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
1129 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1130 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
1131 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1132 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1133 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
1134 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
1137 enum { /* NVRAM to ACPI HKEY group map */
1138 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
1139 TP_ACPI_HKEY_ZOOM_MASK
|
1140 TP_ACPI_HKEY_DISPSWTCH_MASK
|
1141 TP_ACPI_HKEY_HIBERNATE_MASK
,
1142 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
1143 TP_ACPI_HKEY_BRGHTDWN_MASK
,
1144 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
1145 TP_ACPI_HKEY_VOLDWN_MASK
|
1146 TP_ACPI_HKEY_MUTE_MASK
,
1149 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1150 struct tp_nvram_state
{
1151 u16 thinkpad_toggle
:1;
1153 u16 display_toggle
:1;
1154 u16 thinklight_toggle
:1;
1155 u16 hibernate_toggle
:1;
1156 u16 displayexp_toggle
:1;
1157 u16 display_state
:1;
1158 u16 brightness_toggle
:1;
1159 u16 volume_toggle
:1;
1162 u8 brightness_level
;
1166 static struct task_struct
*tpacpi_hotkey_task
;
1167 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
1168 static int hotkey_poll_freq
= 10; /* Hz */
1169 static struct mutex hotkey_thread_mutex
;
1170 static struct mutex hotkey_thread_data_mutex
;
1171 static unsigned int hotkey_config_change
;
1173 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1175 #define hotkey_source_mask 0U
1177 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1179 static struct mutex hotkey_mutex
;
1181 static enum { /* Reasons for waking up */
1182 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
1183 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
1184 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
1185 } hotkey_wakeup_reason
;
1187 static int hotkey_autosleep_ack
;
1189 static int hotkey_orig_status
;
1190 static u32 hotkey_orig_mask
;
1191 static u32 hotkey_all_mask
;
1192 static u32 hotkey_reserved_mask
;
1193 static u32 hotkey_mask
;
1195 static unsigned int hotkey_report_mode
;
1197 static u16
*hotkey_keycode_map
;
1199 static struct attribute_set
*hotkey_dev_attributes
;
1201 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1202 #define HOTKEY_CONFIG_CRITICAL_START \
1204 mutex_lock(&hotkey_thread_data_mutex); \
1205 hotkey_config_change++; \
1207 #define HOTKEY_CONFIG_CRITICAL_END \
1208 mutex_unlock(&hotkey_thread_data_mutex);
1210 #define HOTKEY_CONFIG_CRITICAL_START
1211 #define HOTKEY_CONFIG_CRITICAL_END
1212 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1214 /* HKEY.MHKG() return bits */
1215 #define TP_HOTKEY_TABLET_MASK (1 << 3)
1217 static int hotkey_get_wlsw(int *status
)
1219 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
1224 static int hotkey_get_tablet_mode(int *status
)
1228 if (!acpi_evalf(hkey_handle
, &s
, "MHKG", "d"))
1231 *status
= ((s
& TP_HOTKEY_TABLET_MASK
) != 0);
1236 * Call with hotkey_mutex held
1238 static int hotkey_mask_get(void)
1242 if (tp_features
.hotkey_mask
) {
1243 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
1246 hotkey_mask
= m
| (hotkey_source_mask
& hotkey_mask
);
1252 * Call with hotkey_mutex held
1254 static int hotkey_mask_set(u32 mask
)
1259 if (tp_features
.hotkey_mask
) {
1260 if (!tp_warned
.hotkey_mask_ff
&&
1261 (mask
== 0xffff || mask
== 0xffffff ||
1262 mask
== 0xffffffff)) {
1263 tp_warned
.hotkey_mask_ff
= 1;
1264 printk(TPACPI_NOTICE
1265 "setting the hotkey mask to 0x%08x is likely "
1266 "not the best way to go about it\n", mask
);
1267 printk(TPACPI_NOTICE
1268 "please consider using the driver defaults, "
1269 "and refer to up-to-date thinkpad-acpi "
1273 HOTKEY_CONFIG_CRITICAL_START
1274 for (i
= 0; i
< 32; i
++) {
1276 /* enable in firmware mask only keys not in NVRAM
1277 * mode, but enable the key in the cached hotkey_mask
1278 * regardless of mode, or the key will end up
1279 * disabled by hotkey_mask_get() */
1280 if (!acpi_evalf(hkey_handle
,
1281 NULL
, "MHKM", "vdd", i
+ 1,
1282 !!((mask
& ~hotkey_source_mask
) & m
))) {
1286 hotkey_mask
= (hotkey_mask
& ~m
) | (mask
& m
);
1289 HOTKEY_CONFIG_CRITICAL_END
1291 /* hotkey_mask_get must be called unconditionally below */
1292 if (!hotkey_mask_get() && !rc
&&
1293 (hotkey_mask
& ~hotkey_source_mask
) !=
1294 (mask
& ~hotkey_source_mask
)) {
1295 printk(TPACPI_NOTICE
1296 "requested hot key mask 0x%08x, but "
1297 "firmware forced it to 0x%08x\n",
1301 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1302 HOTKEY_CONFIG_CRITICAL_START
1303 hotkey_mask
= mask
& hotkey_source_mask
;
1304 HOTKEY_CONFIG_CRITICAL_END
1306 if (hotkey_mask
!= mask
) {
1307 printk(TPACPI_NOTICE
1308 "requested hot key mask 0x%08x, "
1309 "forced to 0x%08x (NVRAM poll mask is "
1310 "0x%08x): no firmware mask support\n",
1311 mask
, hotkey_mask
, hotkey_source_mask
);
1316 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1322 static int hotkey_status_get(int *status
)
1324 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1330 static int hotkey_status_set(int status
)
1332 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
1338 static void tpacpi_input_send_tabletsw(void)
1342 if (tp_features
.hotkey_tablet
&&
1343 !hotkey_get_tablet_mode(&state
)) {
1344 mutex_lock(&tpacpi_inputdev_send_mutex
);
1346 input_report_switch(tpacpi_inputdev
,
1347 SW_TABLET_MODE
, !!state
);
1348 input_sync(tpacpi_inputdev
);
1350 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1354 static void tpacpi_input_send_key(unsigned int scancode
)
1356 unsigned int keycode
;
1358 keycode
= hotkey_keycode_map
[scancode
];
1360 if (keycode
!= KEY_RESERVED
) {
1361 mutex_lock(&tpacpi_inputdev_send_mutex
);
1363 input_report_key(tpacpi_inputdev
, keycode
, 1);
1364 if (keycode
== KEY_UNKNOWN
)
1365 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1367 input_sync(tpacpi_inputdev
);
1369 input_report_key(tpacpi_inputdev
, keycode
, 0);
1370 if (keycode
== KEY_UNKNOWN
)
1371 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1373 input_sync(tpacpi_inputdev
);
1375 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1379 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1380 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
1382 static void tpacpi_hotkey_send_key(unsigned int scancode
)
1384 tpacpi_input_send_key(scancode
);
1385 if (hotkey_report_mode
< 2) {
1386 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
1387 0x80, 0x1001 + scancode
);
1391 static void hotkey_read_nvram(struct tp_nvram_state
*n
, u32 m
)
1395 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
1396 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
1397 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
1398 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
1399 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
1400 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
1402 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
1403 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
1404 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
1406 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
1407 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
1408 n
->displayexp_toggle
=
1409 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
1411 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
1412 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
1413 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
1414 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
1415 n
->brightness_toggle
=
1416 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
1418 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
1419 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
1420 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
1421 >> TP_NVRAM_POS_LEVEL_VOLUME
;
1422 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
1423 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
1427 #define TPACPI_COMPARE_KEY(__scancode, __member) \
1429 if ((mask & (1 << __scancode)) && \
1430 oldn->__member != newn->__member) \
1431 tpacpi_hotkey_send_key(__scancode); \
1434 #define TPACPI_MAY_SEND_KEY(__scancode) \
1435 do { if (mask & (1 << __scancode)) \
1436 tpacpi_hotkey_send_key(__scancode); } while (0)
1438 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
1439 struct tp_nvram_state
*newn
,
1442 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
1443 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
1444 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
1445 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
1447 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
1449 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
1452 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
1453 if (oldn
->mute
!= newn
->mute
) {
1454 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1456 if (oldn
->volume_level
> newn
->volume_level
) {
1457 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1458 } else if (oldn
->volume_level
< newn
->volume_level
) {
1459 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1460 } else if (oldn
->mute
== newn
->mute
) {
1461 /* repeated key presses that didn't change state */
1463 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1464 } else if (newn
->volume_level
!= 0) {
1465 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1467 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1472 /* handle brightness */
1473 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
1474 if (oldn
->brightness_level
< newn
->brightness_level
) {
1475 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1476 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
1477 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1479 /* repeated key presses that didn't change state */
1480 if (newn
->brightness_level
!= 0) {
1481 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1483 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1489 #undef TPACPI_COMPARE_KEY
1490 #undef TPACPI_MAY_SEND_KEY
1492 static int hotkey_kthread(void *data
)
1494 struct tp_nvram_state s
[2];
1496 unsigned int si
, so
;
1498 unsigned int change_detector
, must_reset
;
1500 mutex_lock(&hotkey_thread_mutex
);
1502 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
1511 /* Initial state for compares */
1512 mutex_lock(&hotkey_thread_data_mutex
);
1513 change_detector
= hotkey_config_change
;
1514 mask
= hotkey_source_mask
& hotkey_mask
;
1515 mutex_unlock(&hotkey_thread_data_mutex
);
1516 hotkey_read_nvram(&s
[so
], mask
);
1518 while (!kthread_should_stop() && hotkey_poll_freq
) {
1520 t
= 1000/hotkey_poll_freq
;
1521 t
= msleep_interruptible(t
);
1522 if (unlikely(kthread_should_stop()))
1524 must_reset
= try_to_freeze();
1525 if (t
> 0 && !must_reset
)
1528 mutex_lock(&hotkey_thread_data_mutex
);
1529 if (must_reset
|| hotkey_config_change
!= change_detector
) {
1530 /* forget old state on thaw or config change */
1533 change_detector
= hotkey_config_change
;
1535 mask
= hotkey_source_mask
& hotkey_mask
;
1536 mutex_unlock(&hotkey_thread_data_mutex
);
1539 hotkey_read_nvram(&s
[si
], mask
);
1540 if (likely(si
!= so
)) {
1541 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
1551 mutex_unlock(&hotkey_thread_mutex
);
1555 static void hotkey_poll_stop_sync(void)
1557 if (tpacpi_hotkey_task
) {
1558 if (frozen(tpacpi_hotkey_task
) ||
1559 freezing(tpacpi_hotkey_task
))
1560 thaw_process(tpacpi_hotkey_task
);
1562 kthread_stop(tpacpi_hotkey_task
);
1563 tpacpi_hotkey_task
= NULL
;
1564 mutex_lock(&hotkey_thread_mutex
);
1565 /* at this point, the thread did exit */
1566 mutex_unlock(&hotkey_thread_mutex
);
1570 /* call with hotkey_mutex held */
1571 static void hotkey_poll_setup(int may_warn
)
1573 if ((hotkey_source_mask
& hotkey_mask
) != 0 &&
1574 hotkey_poll_freq
> 0 &&
1575 (tpacpi_inputdev
->users
> 0 || hotkey_report_mode
< 2)) {
1576 if (!tpacpi_hotkey_task
) {
1577 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
1578 NULL
, TPACPI_NVRAM_KTHREAD_NAME
);
1579 if (IS_ERR(tpacpi_hotkey_task
)) {
1580 tpacpi_hotkey_task
= NULL
;
1582 "could not create kernel thread "
1583 "for hotkey polling\n");
1587 hotkey_poll_stop_sync();
1589 hotkey_source_mask
!= 0 && hotkey_poll_freq
== 0) {
1590 printk(TPACPI_NOTICE
1591 "hot keys 0x%08x require polling, "
1592 "which is currently disabled\n",
1593 hotkey_source_mask
);
1598 static void hotkey_poll_setup_safe(int may_warn
)
1600 mutex_lock(&hotkey_mutex
);
1601 hotkey_poll_setup(may_warn
);
1602 mutex_unlock(&hotkey_mutex
);
1605 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1607 static void hotkey_poll_setup_safe(int __unused
)
1611 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1613 static int hotkey_inputdev_open(struct input_dev
*dev
)
1615 switch (tpacpi_lifecycle
) {
1616 case TPACPI_LIFE_INIT
:
1618 * hotkey_init will call hotkey_poll_setup_safe
1619 * at the appropriate moment
1622 case TPACPI_LIFE_EXITING
:
1624 case TPACPI_LIFE_RUNNING
:
1625 hotkey_poll_setup_safe(0);
1629 /* Should only happen if tpacpi_lifecycle is corrupt */
1634 static void hotkey_inputdev_close(struct input_dev
*dev
)
1636 /* disable hotkey polling when possible */
1637 if (tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
)
1638 hotkey_poll_setup_safe(0);
1641 /* sysfs hotkey enable ------------------------------------------------- */
1642 static ssize_t
hotkey_enable_show(struct device
*dev
,
1643 struct device_attribute
*attr
,
1648 res
= hotkey_status_get(&status
);
1652 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
1655 static ssize_t
hotkey_enable_store(struct device
*dev
,
1656 struct device_attribute
*attr
,
1657 const char *buf
, size_t count
)
1662 if (parse_strtoul(buf
, 1, &t
))
1665 res
= hotkey_status_set(t
);
1667 return (res
) ? res
: count
;
1670 static struct device_attribute dev_attr_hotkey_enable
=
1671 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
1672 hotkey_enable_show
, hotkey_enable_store
);
1674 /* sysfs hotkey mask --------------------------------------------------- */
1675 static ssize_t
hotkey_mask_show(struct device
*dev
,
1676 struct device_attribute
*attr
,
1681 if (mutex_lock_interruptible(&hotkey_mutex
))
1682 return -ERESTARTSYS
;
1683 res
= hotkey_mask_get();
1684 mutex_unlock(&hotkey_mutex
);
1687 res
: snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_mask
);
1690 static ssize_t
hotkey_mask_store(struct device
*dev
,
1691 struct device_attribute
*attr
,
1692 const char *buf
, size_t count
)
1697 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
1700 if (mutex_lock_interruptible(&hotkey_mutex
))
1701 return -ERESTARTSYS
;
1703 res
= hotkey_mask_set(t
);
1705 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1706 hotkey_poll_setup(1);
1709 mutex_unlock(&hotkey_mutex
);
1711 return (res
) ? res
: count
;
1714 static struct device_attribute dev_attr_hotkey_mask
=
1715 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
1716 hotkey_mask_show
, hotkey_mask_store
);
1718 /* sysfs hotkey bios_enabled ------------------------------------------- */
1719 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
1720 struct device_attribute
*attr
,
1723 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
1726 static struct device_attribute dev_attr_hotkey_bios_enabled
=
1727 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
1729 /* sysfs hotkey bios_mask ---------------------------------------------- */
1730 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
1731 struct device_attribute
*attr
,
1734 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
1737 static struct device_attribute dev_attr_hotkey_bios_mask
=
1738 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
1740 /* sysfs hotkey all_mask ----------------------------------------------- */
1741 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
1742 struct device_attribute
*attr
,
1745 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1746 hotkey_all_mask
| hotkey_source_mask
);
1749 static struct device_attribute dev_attr_hotkey_all_mask
=
1750 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
1752 /* sysfs hotkey recommended_mask --------------------------------------- */
1753 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
1754 struct device_attribute
*attr
,
1757 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1758 (hotkey_all_mask
| hotkey_source_mask
)
1759 & ~hotkey_reserved_mask
);
1762 static struct device_attribute dev_attr_hotkey_recommended_mask
=
1763 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
1764 hotkey_recommended_mask_show
, NULL
);
1766 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1768 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
1769 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
1770 struct device_attribute
*attr
,
1773 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
1776 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
1777 struct device_attribute
*attr
,
1778 const char *buf
, size_t count
)
1782 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
1783 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
1786 if (mutex_lock_interruptible(&hotkey_mutex
))
1787 return -ERESTARTSYS
;
1789 HOTKEY_CONFIG_CRITICAL_START
1790 hotkey_source_mask
= t
;
1791 HOTKEY_CONFIG_CRITICAL_END
1793 hotkey_poll_setup(1);
1795 mutex_unlock(&hotkey_mutex
);
1800 static struct device_attribute dev_attr_hotkey_source_mask
=
1801 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
1802 hotkey_source_mask_show
, hotkey_source_mask_store
);
1804 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
1805 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
1806 struct device_attribute
*attr
,
1809 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
1812 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
1813 struct device_attribute
*attr
,
1814 const char *buf
, size_t count
)
1818 if (parse_strtoul(buf
, 25, &t
))
1821 if (mutex_lock_interruptible(&hotkey_mutex
))
1822 return -ERESTARTSYS
;
1824 hotkey_poll_freq
= t
;
1826 hotkey_poll_setup(1);
1827 mutex_unlock(&hotkey_mutex
);
1832 static struct device_attribute dev_attr_hotkey_poll_freq
=
1833 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
1834 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
1836 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1838 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
1839 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
1840 struct device_attribute
*attr
,
1844 res
= hotkey_get_wlsw(&s
);
1848 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
1851 static struct device_attribute dev_attr_hotkey_radio_sw
=
1852 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
1854 static void hotkey_radio_sw_notify_change(void)
1856 if (tp_features
.hotkey_wlsw
)
1857 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
1861 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
1862 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
1863 struct device_attribute
*attr
,
1867 res
= hotkey_get_tablet_mode(&s
);
1871 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
1874 static struct device_attribute dev_attr_hotkey_tablet_mode
=
1875 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
1877 static void hotkey_tablet_mode_notify_change(void)
1879 if (tp_features
.hotkey_tablet
)
1880 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
1881 "hotkey_tablet_mode");
1884 /* sysfs hotkey report_mode -------------------------------------------- */
1885 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
1886 struct device_attribute
*attr
,
1889 return snprintf(buf
, PAGE_SIZE
, "%d\n",
1890 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
1893 static struct device_attribute dev_attr_hotkey_report_mode
=
1894 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
1896 /* sysfs wakeup reason (pollable) -------------------------------------- */
1897 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
1898 struct device_attribute
*attr
,
1901 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
1904 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
1905 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
1907 static void hotkey_wakeup_reason_notify_change(void)
1909 if (tp_features
.hotkey_mask
)
1910 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
1914 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
1915 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
1916 struct device_attribute
*attr
,
1919 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
1922 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
1923 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
1924 hotkey_wakeup_hotunplug_complete_show
, NULL
);
1926 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
1928 if (tp_features
.hotkey_mask
)
1929 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
1930 "wakeup_hotunplug_complete");
1933 /* --------------------------------------------------------------------- */
1935 static struct attribute
*hotkey_attributes
[] __initdata
= {
1936 &dev_attr_hotkey_enable
.attr
,
1937 &dev_attr_hotkey_bios_enabled
.attr
,
1938 &dev_attr_hotkey_report_mode
.attr
,
1939 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1940 &dev_attr_hotkey_mask
.attr
,
1941 &dev_attr_hotkey_all_mask
.attr
,
1942 &dev_attr_hotkey_recommended_mask
.attr
,
1943 &dev_attr_hotkey_source_mask
.attr
,
1944 &dev_attr_hotkey_poll_freq
.attr
,
1948 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
1949 &dev_attr_hotkey_bios_mask
.attr
,
1950 #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1951 &dev_attr_hotkey_mask
.attr
,
1952 &dev_attr_hotkey_all_mask
.attr
,
1953 &dev_attr_hotkey_recommended_mask
.attr
,
1955 &dev_attr_hotkey_wakeup_reason
.attr
,
1956 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
1959 static void bluetooth_update_rfk(void);
1960 static void wan_update_rfk(void);
1961 static void tpacpi_send_radiosw_update(void)
1965 /* Sync these BEFORE sending any rfkill events */
1966 if (tp_features
.bluetooth
)
1967 bluetooth_update_rfk();
1968 if (tp_features
.wan
)
1971 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
1972 mutex_lock(&tpacpi_inputdev_send_mutex
);
1974 input_report_switch(tpacpi_inputdev
,
1975 SW_RFKILL_ALL
, !!wlsw
);
1976 input_sync(tpacpi_inputdev
);
1978 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1980 hotkey_radio_sw_notify_change();
1983 static void hotkey_exit(void)
1985 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1986 hotkey_poll_stop_sync();
1989 if (hotkey_dev_attributes
)
1990 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
1992 kfree(hotkey_keycode_map
);
1994 if (tp_features
.hotkey
) {
1995 dbg_printk(TPACPI_DBG_EXIT
,
1996 "restoring original hot key mask\n");
1997 /* no short-circuit boolean operator below! */
1998 if ((hotkey_mask_set(hotkey_orig_mask
) |
1999 hotkey_status_set(hotkey_orig_status
)) != 0)
2001 "failed to restore hot key mask "
2002 "to BIOS defaults\n");
2006 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
2008 /* Requirements for changing the default keymaps:
2010 * 1. Many of the keys are mapped to KEY_RESERVED for very
2011 * good reasons. Do not change them unless you have deep
2012 * knowledge on the IBM and Lenovo ThinkPad firmware for
2013 * the various ThinkPad models. The driver behaves
2014 * differently for KEY_RESERVED: such keys have their
2015 * hot key mask *unset* in mask_recommended, and also
2016 * in the initial hot key mask programmed into the
2017 * firmware at driver load time, which means the firm-
2018 * ware may react very differently if you change them to
2021 * 2. You must be subscribed to the linux-thinkpad and
2022 * ibm-acpi-devel mailing lists, and you should read the
2023 * list archives since 2007 if you want to change the
2024 * keymaps. This requirement exists so that you will
2025 * know the past history of problems with the thinkpad-
2026 * acpi driver keymaps, and also that you will be
2027 * listening to any bug reports;
2029 * 3. Do not send thinkpad-acpi specific patches directly to
2030 * for merging, *ever*. Send them to the linux-acpi
2031 * mailinglist for comments. Merging is to be done only
2032 * through acpi-test and the ACPI maintainer.
2034 * If the above is too much to ask, don't change the keymap.
2035 * Ask the thinkpad-acpi maintainer to do it, instead.
2037 static u16 ibm_keycode_map
[] __initdata
= {
2038 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2039 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
2040 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2041 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2043 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2044 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2045 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2046 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2048 /* brightness: firmware always reacts to them, unless
2049 * X.org did some tricks in the radeon BIOS scratch
2050 * registers of *some* models */
2051 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
2052 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
2054 /* Thinklight: firmware always react to it */
2055 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2057 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2058 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2060 /* Volume: firmware always react to it and reprograms
2061 * the built-in *extra* mixer. Never map it to control
2062 * another mixer by default. */
2063 KEY_RESERVED
, /* 0x14: VOLUME UP */
2064 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2065 KEY_RESERVED
, /* 0x16: MUTE */
2067 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2069 /* (assignments unknown, please report if found) */
2070 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2071 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2073 static u16 lenovo_keycode_map
[] __initdata
= {
2074 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2075 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
2076 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2077 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2079 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2080 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2081 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2082 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2084 /* These either have to go through ACPI video, or
2085 * act like in the IBM ThinkPads, so don't ever
2086 * enable them by default */
2087 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
2088 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
2090 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2092 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2093 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2095 /* Volume: z60/z61, T60 (BIOS version?): firmware always
2096 * react to it and reprograms the built-in *extra* mixer.
2097 * Never map it to control another mixer by default.
2099 * T60?, T61, R60?, R61: firmware and EC tries to send
2100 * these over the regular keyboard, so these are no-ops,
2101 * but there are still weird bugs re. MUTE, so do not
2102 * change unless you get test reports from all Lenovo
2103 * models. May cause the BIOS to interfere with the
2106 KEY_RESERVED
, /* 0x14: VOLUME UP */
2107 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2108 KEY_RESERVED
, /* 0x16: MUTE */
2110 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2112 /* (assignments unknown, please report if found) */
2113 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2114 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2117 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
2118 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
2119 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
2125 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
2127 BUG_ON(!tpacpi_inputdev
);
2128 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
2129 tpacpi_inputdev
->close
!= NULL
);
2131 TPACPI_ACPIHANDLE_INIT(hkey
);
2132 mutex_init(&hotkey_mutex
);
2134 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2135 mutex_init(&hotkey_thread_mutex
);
2136 mutex_init(&hotkey_thread_data_mutex
);
2139 /* hotkey not supported on 570 */
2140 tp_features
.hotkey
= hkey_handle
!= NULL
;
2142 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
2143 str_supported(tp_features
.hotkey
));
2145 if (!tp_features
.hotkey
)
2148 hotkey_dev_attributes
= create_attr_set(13, NULL
);
2149 if (!hotkey_dev_attributes
)
2151 res
= add_many_to_attr_set(hotkey_dev_attributes
,
2153 ARRAY_SIZE(hotkey_attributes
));
2157 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2158 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
2159 for HKEY interface version 0x100 */
2160 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
2161 if ((hkeyv
>> 8) != 1) {
2162 printk(TPACPI_ERR
"unknown version of the "
2163 "HKEY interface: 0x%x\n", hkeyv
);
2164 printk(TPACPI_ERR
"please report this to %s\n",
2168 * MHKV 0x100 in A31, R40, R40e,
2169 * T4x, X31, and later
2171 tp_features
.hotkey_mask
= 1;
2175 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
2176 str_supported(tp_features
.hotkey_mask
));
2178 if (tp_features
.hotkey_mask
) {
2179 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
2182 "missing MHKA handler, "
2183 "please report this to %s\n",
2185 /* FN+F12, FN+F4, FN+F3 */
2186 hotkey_all_mask
= 0x080cU
;
2190 /* hotkey_source_mask *must* be zero for
2191 * the first hotkey_mask_get */
2192 res
= hotkey_status_get(&hotkey_orig_status
);
2196 if (tp_features
.hotkey_mask
) {
2197 res
= hotkey_mask_get();
2201 hotkey_orig_mask
= hotkey_mask
;
2202 res
= add_many_to_attr_set(
2203 hotkey_dev_attributes
,
2204 hotkey_mask_attributes
,
2205 ARRAY_SIZE(hotkey_mask_attributes
));
2210 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2211 if (tp_features
.hotkey_mask
) {
2212 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
2215 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
;
2218 vdbg_printk(TPACPI_DBG_INIT
,
2219 "hotkey source mask 0x%08x, polling freq %d\n",
2220 hotkey_source_mask
, hotkey_poll_freq
);
2223 /* Not all thinkpads have a hardware radio switch */
2224 if (acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
2225 tp_features
.hotkey_wlsw
= 1;
2227 "radio switch found; radios are %s\n",
2228 enabled(status
, 0));
2230 if (tp_features
.hotkey_wlsw
)
2231 res
= add_to_attr_set(hotkey_dev_attributes
,
2232 &dev_attr_hotkey_radio_sw
.attr
);
2234 /* For X41t, X60t, X61t Tablets... */
2235 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
2236 tp_features
.hotkey_tablet
= 1;
2238 "possible tablet mode switch found; "
2239 "ThinkPad in %s mode\n",
2240 (status
& TP_HOTKEY_TABLET_MASK
)?
2241 "tablet" : "laptop");
2242 res
= add_to_attr_set(hotkey_dev_attributes
,
2243 &dev_attr_hotkey_tablet_mode
.attr
);
2247 res
= register_attr_set_with_sysfs(
2248 hotkey_dev_attributes
,
2249 &tpacpi_pdev
->dev
.kobj
);
2253 /* Set up key map */
2255 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
2257 if (!hotkey_keycode_map
) {
2259 "failed to allocate memory for key map\n");
2264 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
2265 dbg_printk(TPACPI_DBG_INIT
,
2266 "using Lenovo default hot key map\n");
2267 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
2268 TPACPI_HOTKEY_MAP_SIZE
);
2270 dbg_printk(TPACPI_DBG_INIT
,
2271 "using IBM default hot key map\n");
2272 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
2273 TPACPI_HOTKEY_MAP_SIZE
);
2276 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
2277 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
2278 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
2279 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
2280 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
2281 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
2282 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
2283 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
2284 set_bit(hotkey_keycode_map
[i
],
2285 tpacpi_inputdev
->keybit
);
2287 if (i
< sizeof(hotkey_reserved_mask
)*8)
2288 hotkey_reserved_mask
|= 1 << i
;
2292 if (tp_features
.hotkey_wlsw
) {
2293 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
2294 set_bit(SW_RFKILL_ALL
, tpacpi_inputdev
->swbit
);
2296 if (tp_features
.hotkey_tablet
) {
2297 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
2298 set_bit(SW_TABLET_MODE
, tpacpi_inputdev
->swbit
);
2301 /* Do not issue duplicate brightness change events to
2303 if (!tp_features
.bright_acpimode
)
2304 /* update bright_acpimode... */
2305 tpacpi_check_std_acpi_brightness_support();
2307 if (tp_features
.bright_acpimode
) {
2309 "This ThinkPad has standard ACPI backlight "
2310 "brightness control, supported by the ACPI "
2312 printk(TPACPI_NOTICE
2313 "Disabling thinkpad-acpi brightness events "
2316 /* The hotkey_reserved_mask change below is not
2317 * necessary while the keys are at KEY_RESERVED in the
2318 * default map, but better safe than sorry, leave it
2319 * here as a marker of what we have to do, especially
2320 * when we finally become able to set this at runtime
2321 * on response to X.org requests */
2322 hotkey_reserved_mask
|=
2323 (1 << TP_ACPI_HOTKEYSCAN_FNHOME
)
2324 | (1 << TP_ACPI_HOTKEYSCAN_FNEND
);
2327 dbg_printk(TPACPI_DBG_INIT
, "enabling hot key handling\n");
2328 res
= hotkey_status_set(1);
2333 res
= hotkey_mask_set(((hotkey_all_mask
| hotkey_source_mask
)
2334 & ~hotkey_reserved_mask
)
2335 | hotkey_orig_mask
);
2336 if (res
< 0 && res
!= -ENXIO
) {
2341 dbg_printk(TPACPI_DBG_INIT
,
2342 "legacy hot key reporting over procfs %s\n",
2343 (hotkey_report_mode
< 2) ?
2344 "enabled" : "disabled");
2346 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
2347 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
2349 hotkey_poll_setup_safe(1);
2350 tpacpi_send_radiosw_update();
2351 tpacpi_input_send_tabletsw();
2356 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2357 hotkey_dev_attributes
= NULL
;
2359 return (res
< 0)? res
: 1;
2362 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
2365 unsigned int scancode
;
2370 if (event
!= 0x80) {
2372 "unknown HKEY notification event %d\n", event
);
2373 /* forward it to userspace, maybe it knows how to handle it */
2374 acpi_bus_generate_netlink_event(
2375 ibm
->acpi
->device
->pnp
.device_class
,
2376 ibm
->acpi
->device
->dev
.bus_id
,
2382 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
2383 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
2396 switch (hkey
>> 12) {
2398 /* 0x1000-0x1FFF: key presses */
2399 scancode
= hkey
& 0xfff;
2400 if (scancode
> 0 && scancode
< 0x21) {
2402 if (!(hotkey_source_mask
& (1 << scancode
))) {
2403 tpacpi_input_send_key(scancode
);
2415 case 0x2304: /* suspend, undock */
2416 case 0x2404: /* hibernation, undock */
2417 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
2420 case 0x2305: /* suspend, bay eject */
2421 case 0x2405: /* hibernation, bay eject */
2422 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
2428 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
2430 "woke up due to a hot-unplug "
2432 hotkey_wakeup_reason_notify_change();
2436 /* bay-related wakeups */
2437 if (hkey
== 0x3003) {
2438 hotkey_autosleep_ack
= 1;
2441 hotkey_wakeup_hotunplug_complete_notify_change();
2447 /* dock-related wakeups */
2448 if (hkey
== 0x4003) {
2449 hotkey_autosleep_ack
= 1;
2452 hotkey_wakeup_hotunplug_complete_notify_change();
2458 /* 0x5000-0x5FFF: human interface helpers */
2460 case 0x5010: /* Lenovo new BIOS: brightness changed */
2461 case 0x500b: /* X61t: tablet pen inserted into bay */
2462 case 0x500c: /* X61t: tablet pen removed from bay */
2464 case 0x5009: /* X41t-X61t: swivel up (tablet mode) */
2465 case 0x500a: /* X41t-X61t: swivel down (normal mode) */
2466 tpacpi_input_send_tabletsw();
2467 hotkey_tablet_mode_notify_change();
2472 /* LID switch events. Do not propagate */
2480 /* 0x7000-0x7FFF: misc */
2481 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
2482 tpacpi_send_radiosw_update();
2486 /* fallthrough to default */
2491 printk(TPACPI_NOTICE
2492 "unhandled HKEY event 0x%04x\n", hkey
);
2496 if (!ignore_acpi_ev
&&
2497 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
2498 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
2502 /* netlink events */
2503 if (!ignore_acpi_ev
&& send_acpi_ev
) {
2504 acpi_bus_generate_netlink_event(
2505 ibm
->acpi
->device
->pnp
.device_class
,
2506 ibm
->acpi
->device
->dev
.bus_id
,
2512 static void hotkey_suspend(pm_message_t state
)
2514 /* Do these on suspend, we get the events on early resume! */
2515 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
2516 hotkey_autosleep_ack
= 0;
2519 static void hotkey_resume(void)
2521 if (hotkey_mask_get())
2523 "error while trying to read hot key mask "
2525 tpacpi_send_radiosw_update();
2526 hotkey_tablet_mode_notify_change();
2527 hotkey_wakeup_reason_notify_change();
2528 hotkey_wakeup_hotunplug_complete_notify_change();
2529 hotkey_poll_setup_safe(0);
2532 /* procfs -------------------------------------------------------------- */
2533 static int hotkey_read(char *p
)
2538 if (!tp_features
.hotkey
) {
2539 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2543 if (mutex_lock_interruptible(&hotkey_mutex
))
2544 return -ERESTARTSYS
;
2545 res
= hotkey_status_get(&status
);
2547 res
= hotkey_mask_get();
2548 mutex_unlock(&hotkey_mutex
);
2552 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
2553 if (tp_features
.hotkey_mask
) {
2554 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", hotkey_mask
);
2555 len
+= sprintf(p
+ len
,
2556 "commands:\tenable, disable, reset, <mask>\n");
2558 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
2559 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
2565 static int hotkey_write(char *buf
)
2571 if (!tp_features
.hotkey
)
2574 if (mutex_lock_interruptible(&hotkey_mutex
))
2575 return -ERESTARTSYS
;
2581 while ((cmd
= next_cmd(&buf
))) {
2582 if (strlencmp(cmd
, "enable") == 0) {
2584 } else if (strlencmp(cmd
, "disable") == 0) {
2586 } else if (strlencmp(cmd
, "reset") == 0) {
2587 status
= hotkey_orig_status
;
2588 mask
= hotkey_orig_mask
;
2589 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
2591 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
2599 res
= hotkey_status_set(status
);
2601 if (!res
&& mask
!= hotkey_mask
)
2602 res
= hotkey_mask_set(mask
);
2605 mutex_unlock(&hotkey_mutex
);
2609 static const struct acpi_device_id ibm_htk_device_ids
[] = {
2610 {TPACPI_ACPI_HKEY_HID
, 0},
2614 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
2615 .hid
= ibm_htk_device_ids
,
2616 .notify
= hotkey_notify
,
2617 .handle
= &hkey_handle
,
2618 .type
= ACPI_DEVICE_NOTIFY
,
2621 static struct ibm_struct hotkey_driver_data
= {
2623 .read
= hotkey_read
,
2624 .write
= hotkey_write
,
2625 .exit
= hotkey_exit
,
2626 .resume
= hotkey_resume
,
2627 .suspend
= hotkey_suspend
,
2628 .acpi
= &ibm_hotkey_acpidriver
,
2631 /*************************************************************************
2632 * Bluetooth subdriver
2636 /* ACPI GBDC/SBDC bits */
2637 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
2638 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
2639 TP_ACPI_BLUETOOTH_UNK
= 0x04, /* unknown function */
2642 static struct rfkill
*tpacpi_bluetooth_rfkill
;
2644 static int bluetooth_get_radiosw(void)
2648 if (!tp_features
.bluetooth
)
2651 /* WLSW overrides bluetooth in firmware/hardware, reflect that */
2652 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
2653 return RFKILL_STATE_HARD_BLOCKED
;
2655 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
2658 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0) ?
2659 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
2662 static void bluetooth_update_rfk(void)
2666 if (!tpacpi_bluetooth_rfkill
)
2669 status
= bluetooth_get_radiosw();
2672 rfkill_force_state(tpacpi_bluetooth_rfkill
, status
);
2675 static int bluetooth_set_radiosw(int radio_on
, int update_rfk
)
2679 if (!tp_features
.bluetooth
)
2682 /* WLSW overrides bluetooth in firmware/hardware, but there is no
2683 * reason to risk weird behaviour. */
2684 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
2688 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
2691 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
2693 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
2694 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
2698 bluetooth_update_rfk();
2703 /* sysfs bluetooth enable ---------------------------------------------- */
2704 static ssize_t
bluetooth_enable_show(struct device
*dev
,
2705 struct device_attribute
*attr
,
2710 status
= bluetooth_get_radiosw();
2714 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2715 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
2718 static ssize_t
bluetooth_enable_store(struct device
*dev
,
2719 struct device_attribute
*attr
,
2720 const char *buf
, size_t count
)
2725 if (parse_strtoul(buf
, 1, &t
))
2728 res
= bluetooth_set_radiosw(t
, 1);
2730 return (res
) ? res
: count
;
2733 static struct device_attribute dev_attr_bluetooth_enable
=
2734 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
2735 bluetooth_enable_show
, bluetooth_enable_store
);
2737 /* --------------------------------------------------------------------- */
2739 static struct attribute
*bluetooth_attributes
[] = {
2740 &dev_attr_bluetooth_enable
.attr
,
2744 static const struct attribute_group bluetooth_attr_group
= {
2745 .attrs
= bluetooth_attributes
,
2748 static int tpacpi_bluetooth_rfk_get(void *data
, enum rfkill_state
*state
)
2750 int bts
= bluetooth_get_radiosw();
2759 static int tpacpi_bluetooth_rfk_set(void *data
, enum rfkill_state state
)
2761 return bluetooth_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
2764 static void bluetooth_exit(void)
2766 if (tpacpi_bluetooth_rfkill
)
2767 rfkill_unregister(tpacpi_bluetooth_rfkill
);
2769 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2770 &bluetooth_attr_group
);
2773 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
2778 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
2780 TPACPI_ACPIHANDLE_INIT(hkey
);
2782 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2783 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
2784 tp_features
.bluetooth
= hkey_handle
&&
2785 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
2787 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
2788 str_supported(tp_features
.bluetooth
),
2791 if (tp_features
.bluetooth
&&
2792 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
2793 /* no bluetooth hardware present in system */
2794 tp_features
.bluetooth
= 0;
2795 dbg_printk(TPACPI_DBG_INIT
,
2796 "bluetooth hardware not installed\n");
2799 if (!tp_features
.bluetooth
)
2802 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2803 &bluetooth_attr_group
);
2807 res
= tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
,
2808 &tpacpi_bluetooth_rfkill
,
2809 RFKILL_TYPE_BLUETOOTH
,
2810 "tpacpi_bluetooth_sw",
2811 tpacpi_bluetooth_rfk_set
,
2812 tpacpi_bluetooth_rfk_get
);
2821 /* procfs -------------------------------------------------------------- */
2822 static int bluetooth_read(char *p
)
2825 int status
= bluetooth_get_radiosw();
2827 if (!tp_features
.bluetooth
)
2828 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2830 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2831 (status
== RFKILL_STATE_UNBLOCKED
) ?
2832 "enabled" : "disabled");
2833 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
2839 static int bluetooth_write(char *buf
)
2843 if (!tp_features
.bluetooth
)
2846 while ((cmd
= next_cmd(&buf
))) {
2847 if (strlencmp(cmd
, "enable") == 0) {
2848 bluetooth_set_radiosw(1, 1);
2849 } else if (strlencmp(cmd
, "disable") == 0) {
2850 bluetooth_set_radiosw(0, 1);
2858 static struct ibm_struct bluetooth_driver_data
= {
2859 .name
= "bluetooth",
2860 .read
= bluetooth_read
,
2861 .write
= bluetooth_write
,
2862 .exit
= bluetooth_exit
,
2865 /*************************************************************************
2870 /* ACPI GWAN/SWAN bits */
2871 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
2872 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
2873 TP_ACPI_WANCARD_UNK
= 0x04, /* unknown function */
2876 static struct rfkill
*tpacpi_wan_rfkill
;
2878 static int wan_get_radiosw(void)
2882 if (!tp_features
.wan
)
2885 /* WLSW overrides WWAN in firmware/hardware, reflect that */
2886 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
2887 return RFKILL_STATE_HARD_BLOCKED
;
2889 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
2892 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0) ?
2893 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
2896 static void wan_update_rfk(void)
2900 if (!tpacpi_wan_rfkill
)
2903 status
= wan_get_radiosw();
2906 rfkill_force_state(tpacpi_wan_rfkill
, status
);
2909 static int wan_set_radiosw(int radio_on
, int update_rfk
)
2913 if (!tp_features
.wan
)
2916 /* WLSW overrides bluetooth in firmware/hardware, but there is no
2917 * reason to risk weird behaviour. */
2918 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
2922 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
2925 status
|= TP_ACPI_WANCARD_RADIOSSW
;
2927 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
2928 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
2937 /* sysfs wan enable ---------------------------------------------------- */
2938 static ssize_t
wan_enable_show(struct device
*dev
,
2939 struct device_attribute
*attr
,
2944 status
= wan_get_radiosw();
2948 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2949 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
2952 static ssize_t
wan_enable_store(struct device
*dev
,
2953 struct device_attribute
*attr
,
2954 const char *buf
, size_t count
)
2959 if (parse_strtoul(buf
, 1, &t
))
2962 res
= wan_set_radiosw(t
, 1);
2964 return (res
) ? res
: count
;
2967 static struct device_attribute dev_attr_wan_enable
=
2968 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
2969 wan_enable_show
, wan_enable_store
);
2971 /* --------------------------------------------------------------------- */
2973 static struct attribute
*wan_attributes
[] = {
2974 &dev_attr_wan_enable
.attr
,
2978 static const struct attribute_group wan_attr_group
= {
2979 .attrs
= wan_attributes
,
2982 static int tpacpi_wan_rfk_get(void *data
, enum rfkill_state
*state
)
2984 int wans
= wan_get_radiosw();
2993 static int tpacpi_wan_rfk_set(void *data
, enum rfkill_state state
)
2995 return wan_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
2998 static void wan_exit(void)
3000 if (tpacpi_wan_rfkill
)
3001 rfkill_unregister(tpacpi_wan_rfkill
);
3003 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3007 static int __init
wan_init(struct ibm_init_struct
*iibm
)
3012 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
3014 TPACPI_ACPIHANDLE_INIT(hkey
);
3016 tp_features
.wan
= hkey_handle
&&
3017 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
3019 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
3020 str_supported(tp_features
.wan
),
3023 if (tp_features
.wan
&&
3024 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
3025 /* no wan hardware present in system */
3026 tp_features
.wan
= 0;
3027 dbg_printk(TPACPI_DBG_INIT
,
3028 "wan hardware not installed\n");
3031 if (!tp_features
.wan
)
3034 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3039 res
= tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID
,
3044 tpacpi_wan_rfk_get
);
3053 /* procfs -------------------------------------------------------------- */
3054 static int wan_read(char *p
)
3057 int status
= wan_get_radiosw();
3059 if (!tp_features
.wan
)
3060 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3062 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3063 (status
== RFKILL_STATE_UNBLOCKED
) ?
3064 "enabled" : "disabled");
3065 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
3071 static int wan_write(char *buf
)
3075 if (!tp_features
.wan
)
3078 while ((cmd
= next_cmd(&buf
))) {
3079 if (strlencmp(cmd
, "enable") == 0) {
3080 wan_set_radiosw(1, 1);
3081 } else if (strlencmp(cmd
, "disable") == 0) {
3082 wan_set_radiosw(0, 1);
3090 static struct ibm_struct wan_driver_data
= {
3097 /*************************************************************************
3101 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
3103 enum video_access_mode
{
3104 TPACPI_VIDEO_NONE
= 0,
3105 TPACPI_VIDEO_570
, /* 570 */
3106 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
3107 TPACPI_VIDEO_NEW
, /* all others */
3110 enum { /* video status flags, based on VIDEO_570 */
3111 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
3112 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
3113 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
3116 enum { /* TPACPI_VIDEO_570 constants */
3117 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
3118 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
3119 * video_status_flags */
3120 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
3121 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
3124 static enum video_access_mode video_supported
;
3125 static int video_orig_autosw
;
3127 static int video_autosw_get(void);
3128 static int video_autosw_set(int enable
);
3130 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
3132 static int __init
video_init(struct ibm_init_struct
*iibm
)
3136 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
3138 TPACPI_ACPIHANDLE_INIT(vid
);
3139 TPACPI_ACPIHANDLE_INIT(vid2
);
3141 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
3142 /* G41, assume IVGA doesn't change */
3143 vid_handle
= vid2_handle
;
3146 /* video switching not supported on R30, R31 */
3147 video_supported
= TPACPI_VIDEO_NONE
;
3148 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
3150 video_supported
= TPACPI_VIDEO_570
;
3151 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
3152 /* 600e/x, 770e, 770x */
3153 video_supported
= TPACPI_VIDEO_770
;
3156 video_supported
= TPACPI_VIDEO_NEW
;
3158 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
3159 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
3162 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
3165 static void video_exit(void)
3167 dbg_printk(TPACPI_DBG_EXIT
,
3168 "restoring original video autoswitch mode\n");
3169 if (video_autosw_set(video_orig_autosw
))
3170 printk(TPACPI_ERR
"error while trying to restore original "
3171 "video autoswitch mode\n");
3174 static int video_outputsw_get(void)
3179 switch (video_supported
) {
3180 case TPACPI_VIDEO_570
:
3181 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
3182 TP_ACPI_VIDEO_570_PHSCMD
))
3184 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
3186 case TPACPI_VIDEO_770
:
3187 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
3190 status
|= TP_ACPI_VIDEO_S_LCD
;
3191 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
3194 status
|= TP_ACPI_VIDEO_S_CRT
;
3196 case TPACPI_VIDEO_NEW
:
3197 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
3198 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
3201 status
|= TP_ACPI_VIDEO_S_CRT
;
3203 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
3204 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
3207 status
|= TP_ACPI_VIDEO_S_LCD
;
3208 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
3211 status
|= TP_ACPI_VIDEO_S_DVI
;
3220 static int video_outputsw_set(int status
)
3225 switch (video_supported
) {
3226 case TPACPI_VIDEO_570
:
3227 res
= acpi_evalf(NULL
, NULL
,
3228 "\\_SB.PHS2", "vdd",
3229 TP_ACPI_VIDEO_570_PHS2CMD
,
3230 status
| TP_ACPI_VIDEO_570_PHS2SET
);
3232 case TPACPI_VIDEO_770
:
3233 autosw
= video_autosw_get();
3237 res
= video_autosw_set(1);
3240 res
= acpi_evalf(vid_handle
, NULL
,
3241 "ASWT", "vdd", status
* 0x100, 0);
3242 if (!autosw
&& video_autosw_set(autosw
)) {
3244 "video auto-switch left enabled due to error\n");
3248 case TPACPI_VIDEO_NEW
:
3249 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
3250 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
3256 return (res
)? 0 : -EIO
;
3259 static int video_autosw_get(void)
3263 switch (video_supported
) {
3264 case TPACPI_VIDEO_570
:
3265 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
3268 case TPACPI_VIDEO_770
:
3269 case TPACPI_VIDEO_NEW
:
3270 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
3280 static int video_autosw_set(int enable
)
3282 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
3287 static int video_outputsw_cycle(void)
3289 int autosw
= video_autosw_get();
3295 switch (video_supported
) {
3296 case TPACPI_VIDEO_570
:
3297 res
= video_autosw_set(1);
3300 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
3302 case TPACPI_VIDEO_770
:
3303 case TPACPI_VIDEO_NEW
:
3304 res
= video_autosw_set(1);
3307 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
3312 if (!autosw
&& video_autosw_set(autosw
)) {
3314 "video auto-switch left enabled due to error\n");
3318 return (res
)? 0 : -EIO
;
3321 static int video_expand_toggle(void)
3323 switch (video_supported
) {
3324 case TPACPI_VIDEO_570
:
3325 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
3327 case TPACPI_VIDEO_770
:
3328 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
3330 case TPACPI_VIDEO_NEW
:
3331 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
3339 static int video_read(char *p
)
3344 if (video_supported
== TPACPI_VIDEO_NONE
) {
3345 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3349 status
= video_outputsw_get();
3353 autosw
= video_autosw_get();
3357 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3358 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
3359 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
3360 if (video_supported
== TPACPI_VIDEO_NEW
)
3361 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
3362 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
3363 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
3364 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
3365 if (video_supported
== TPACPI_VIDEO_NEW
)
3366 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
3367 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
3368 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
3373 static int video_write(char *buf
)
3376 int enable
, disable
, status
;
3379 if (video_supported
== TPACPI_VIDEO_NONE
)
3385 while ((cmd
= next_cmd(&buf
))) {
3386 if (strlencmp(cmd
, "lcd_enable") == 0) {
3387 enable
|= TP_ACPI_VIDEO_S_LCD
;
3388 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
3389 disable
|= TP_ACPI_VIDEO_S_LCD
;
3390 } else if (strlencmp(cmd
, "crt_enable") == 0) {
3391 enable
|= TP_ACPI_VIDEO_S_CRT
;
3392 } else if (strlencmp(cmd
, "crt_disable") == 0) {
3393 disable
|= TP_ACPI_VIDEO_S_CRT
;
3394 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
3395 strlencmp(cmd
, "dvi_enable") == 0) {
3396 enable
|= TP_ACPI_VIDEO_S_DVI
;
3397 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
3398 strlencmp(cmd
, "dvi_disable") == 0) {
3399 disable
|= TP_ACPI_VIDEO_S_DVI
;
3400 } else if (strlencmp(cmd
, "auto_enable") == 0) {
3401 res
= video_autosw_set(1);
3404 } else if (strlencmp(cmd
, "auto_disable") == 0) {
3405 res
= video_autosw_set(0);
3408 } else if (strlencmp(cmd
, "video_switch") == 0) {
3409 res
= video_outputsw_cycle();
3412 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
3413 res
= video_expand_toggle();
3420 if (enable
|| disable
) {
3421 status
= video_outputsw_get();
3424 res
= video_outputsw_set((status
& ~disable
) | enable
);
3432 static struct ibm_struct video_driver_data
= {
3435 .write
= video_write
,
3439 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
3441 /*************************************************************************
3442 * Light (thinklight) subdriver
3445 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
3446 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
3448 static int light_get_status(void)
3452 if (tp_features
.light_status
) {
3453 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
3461 static int light_set_status(int status
)
3465 if (tp_features
.light
) {
3467 rc
= acpi_evalf(cmos_handle
, NULL
, NULL
, "vd",
3469 TP_CMOS_THINKLIGHT_ON
:
3470 TP_CMOS_THINKLIGHT_OFF
);
3472 rc
= acpi_evalf(lght_handle
, NULL
, NULL
, "vd",
3475 return (rc
)? 0 : -EIO
;
3481 static void light_set_status_worker(struct work_struct
*work
)
3483 struct tpacpi_led_classdev
*data
=
3484 container_of(work
, struct tpacpi_led_classdev
, work
);
3486 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
3487 light_set_status((data
->new_state
!= TPACPI_LED_OFF
));
3490 static void light_sysfs_set(struct led_classdev
*led_cdev
,
3491 enum led_brightness brightness
)
3493 struct tpacpi_led_classdev
*data
=
3494 container_of(led_cdev
,
3495 struct tpacpi_led_classdev
,
3497 data
->new_state
= (brightness
!= LED_OFF
) ?
3498 TPACPI_LED_ON
: TPACPI_LED_OFF
;
3499 queue_work(tpacpi_wq
, &data
->work
);
3502 static enum led_brightness
light_sysfs_get(struct led_classdev
*led_cdev
)
3504 return (light_get_status() == 1)? LED_FULL
: LED_OFF
;
3507 static struct tpacpi_led_classdev tpacpi_led_thinklight
= {
3509 .name
= "tpacpi::thinklight",
3510 .brightness_set
= &light_sysfs_set
,
3511 .brightness_get
= &light_sysfs_get
,
3515 static int __init
light_init(struct ibm_init_struct
*iibm
)
3519 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
3521 TPACPI_ACPIHANDLE_INIT(ledb
);
3522 TPACPI_ACPIHANDLE_INIT(lght
);
3523 TPACPI_ACPIHANDLE_INIT(cmos
);
3524 INIT_WORK(&tpacpi_led_thinklight
.work
, light_set_status_worker
);
3526 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
3527 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
3529 if (tp_features
.light
)
3530 /* light status not supported on
3531 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
3532 tp_features
.light_status
=
3533 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
3535 vdbg_printk(TPACPI_DBG_INIT
, "light is %s, light status is %s\n",
3536 str_supported(tp_features
.light
),
3537 str_supported(tp_features
.light_status
));
3539 if (!tp_features
.light
)
3542 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
3543 &tpacpi_led_thinklight
.led_classdev
);
3546 tp_features
.light
= 0;
3547 tp_features
.light_status
= 0;
3555 static void light_exit(void)
3557 led_classdev_unregister(&tpacpi_led_thinklight
.led_classdev
);
3558 if (work_pending(&tpacpi_led_thinklight
.work
))
3559 flush_workqueue(tpacpi_wq
);
3562 static int light_read(char *p
)
3567 if (!tp_features
.light
) {
3568 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3569 } else if (!tp_features
.light_status
) {
3570 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
3571 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
3573 status
= light_get_status();
3576 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
3577 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
3583 static int light_write(char *buf
)
3588 if (!tp_features
.light
)
3591 while ((cmd
= next_cmd(&buf
))) {
3592 if (strlencmp(cmd
, "on") == 0) {
3594 } else if (strlencmp(cmd
, "off") == 0) {
3600 return light_set_status(newstatus
);
3603 static struct ibm_struct light_driver_data
= {
3606 .write
= light_write
,
3610 /*************************************************************************
3614 #ifdef CONFIG_THINKPAD_ACPI_DOCK
3616 static void dock_notify(struct ibm_struct
*ibm
, u32 event
);
3617 static int dock_read(char *p
);
3618 static int dock_write(char *buf
);
3620 TPACPI_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
3621 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
3622 "\\_SB.PCI0.PCI1.DOCK", /* all others */
3623 "\\_SB.PCI.ISA.SLCE", /* 570 */
3624 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
3626 /* don't list other alternatives as we install a notify handler on the 570 */
3627 TPACPI_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
3629 static const struct acpi_device_id ibm_pci_device_ids
[] = {
3630 {PCI_ROOT_HID_STRING
, 0},
3634 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
3636 .notify
= dock_notify
,
3637 .handle
= &dock_handle
,
3638 .type
= ACPI_SYSTEM_NOTIFY
,
3641 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
3642 * We just use it to get notifications of dock hotplug
3643 * in very old thinkpads */
3644 .hid
= ibm_pci_device_ids
,
3645 .notify
= dock_notify
,
3646 .handle
= &pci_handle
,
3647 .type
= ACPI_SYSTEM_NOTIFY
,
3651 static struct ibm_struct dock_driver_data
[2] = {
3655 .write
= dock_write
,
3656 .acpi
= &ibm_dock_acpidriver
[0],
3660 .acpi
= &ibm_dock_acpidriver
[1],
3664 #define dock_docked() (_sta(dock_handle) & 1)
3666 static int __init
dock_init(struct ibm_init_struct
*iibm
)
3668 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
3670 TPACPI_ACPIHANDLE_INIT(dock
);
3672 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
3673 str_supported(dock_handle
!= NULL
));
3675 return (dock_handle
)? 0 : 1;
3678 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
3682 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
3684 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
3685 dock_driver_data
[0].flags
.acpi_notify_installed
) {
3686 TPACPI_ACPIHANDLE_INIT(pci
);
3687 dock2_needed
= (pci_handle
!= NULL
);
3688 vdbg_printk(TPACPI_DBG_INIT
,
3689 "dock PCI handler for the TP 570 is %s\n",
3690 str_supported(dock2_needed
));
3692 vdbg_printk(TPACPI_DBG_INIT
,
3693 "dock subdriver part 2 not required\n");
3697 return (dock2_needed
)? 0 : 1;
3700 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
3702 int docked
= dock_docked();
3703 int pci
= ibm
->acpi
->hid
&& ibm
->acpi
->device
&&
3704 acpi_match_device_ids(ibm
->acpi
->device
, ibm_pci_device_ids
);
3707 if (event
== 1 && !pci
) /* 570 */
3708 data
= 1; /* button */
3709 else if (event
== 1 && pci
) /* 570 */
3710 data
= 3; /* dock */
3711 else if (event
== 3 && docked
)
3712 data
= 1; /* button */
3713 else if (event
== 3 && !docked
)
3714 data
= 2; /* undock */
3715 else if (event
== 0 && docked
)
3716 data
= 3; /* dock */
3718 printk(TPACPI_ERR
"unknown dock event %d, status %d\n",
3719 event
, _sta(dock_handle
));
3720 data
= 0; /* unknown */
3722 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, data
);
3723 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
3724 ibm
->acpi
->device
->dev
.bus_id
,
3728 static int dock_read(char *p
)
3731 int docked
= dock_docked();
3734 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3736 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
3738 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
3739 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
3745 static int dock_write(char *buf
)
3752 while ((cmd
= next_cmd(&buf
))) {
3753 if (strlencmp(cmd
, "undock") == 0) {
3754 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
3755 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
3757 } else if (strlencmp(cmd
, "dock") == 0) {
3758 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
3767 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
3769 /*************************************************************************
3773 #ifdef CONFIG_THINKPAD_ACPI_BAY
3775 TPACPI_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
3776 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
3777 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
3778 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
3779 ); /* A21e, R30, R31 */
3780 TPACPI_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
3781 "_EJ0", /* all others */
3782 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
3783 TPACPI_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
3784 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
3786 TPACPI_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
3790 static int __init
bay_init(struct ibm_init_struct
*iibm
)
3792 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
3794 TPACPI_ACPIHANDLE_INIT(bay
);
3796 TPACPI_ACPIHANDLE_INIT(bay_ej
);
3797 TPACPI_ACPIHANDLE_INIT(bay2
);
3799 TPACPI_ACPIHANDLE_INIT(bay2_ej
);
3801 tp_features
.bay_status
= bay_handle
&&
3802 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
3803 tp_features
.bay_status2
= bay2_handle
&&
3804 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
3806 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
3807 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
3808 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
3809 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
3811 vdbg_printk(TPACPI_DBG_INIT
,
3812 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
3813 str_supported(tp_features
.bay_status
),
3814 str_supported(tp_features
.bay_eject
),
3815 str_supported(tp_features
.bay_status2
),
3816 str_supported(tp_features
.bay_eject2
));
3818 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
3819 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
3822 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
3824 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, 0);
3825 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
3826 ibm
->acpi
->device
->dev
.bus_id
,
3830 #define bay_occupied(b) (_sta(b##_handle) & 1)
3832 static int bay_read(char *p
)
3835 int occupied
= bay_occupied(bay
);
3836 int occupied2
= bay_occupied(bay2
);
3839 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3840 tp_features
.bay_status
?
3841 (occupied
? "occupied" : "unoccupied") :
3843 if (tp_features
.bay_status2
)
3844 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
3845 "occupied" : "unoccupied");
3847 eject
= tp_features
.bay_eject
&& occupied
;
3848 eject2
= tp_features
.bay_eject2
&& occupied2
;
3850 if (eject
&& eject2
)
3851 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
3853 len
+= sprintf(p
+ len
, "commands:\teject\n");
3855 len
+= sprintf(p
+ len
, "commands:\teject2\n");
3860 static int bay_write(char *buf
)
3864 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
3867 while ((cmd
= next_cmd(&buf
))) {
3868 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
3869 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
3871 } else if (tp_features
.bay_eject2
&&
3872 strlencmp(cmd
, "eject2") == 0) {
3873 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
3882 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
3883 .notify
= bay_notify
,
3884 .handle
= &bay_handle
,
3885 .type
= ACPI_SYSTEM_NOTIFY
,
3888 static struct ibm_struct bay_driver_data
= {
3892 .acpi
= &ibm_bay_acpidriver
,
3895 #endif /* CONFIG_THINKPAD_ACPI_BAY */
3897 /*************************************************************************
3901 /* sysfs cmos_command -------------------------------------------------- */
3902 static ssize_t
cmos_command_store(struct device
*dev
,
3903 struct device_attribute
*attr
,
3904 const char *buf
, size_t count
)
3906 unsigned long cmos_cmd
;
3909 if (parse_strtoul(buf
, 21, &cmos_cmd
))
3912 res
= issue_thinkpad_cmos_command(cmos_cmd
);
3913 return (res
)? res
: count
;
3916 static struct device_attribute dev_attr_cmos_command
=
3917 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
3919 /* --------------------------------------------------------------------- */
3921 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
3925 vdbg_printk(TPACPI_DBG_INIT
,
3926 "initializing cmos commands subdriver\n");
3928 TPACPI_ACPIHANDLE_INIT(cmos
);
3930 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
3931 str_supported(cmos_handle
!= NULL
));
3933 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
3937 return (cmos_handle
)? 0 : 1;
3940 static void cmos_exit(void)
3942 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
3945 static int cmos_read(char *p
)
3949 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
3950 R30, R31, T20-22, X20-21 */
3952 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3954 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3955 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
3961 static int cmos_write(char *buf
)
3966 while ((cmd
= next_cmd(&buf
))) {
3967 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
3968 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
3973 res
= issue_thinkpad_cmos_command(cmos_cmd
);
3981 static struct ibm_struct cmos_driver_data
= {
3984 .write
= cmos_write
,
3988 /*************************************************************************
3992 enum led_access_mode
{
3993 TPACPI_LED_NONE
= 0,
3994 TPACPI_LED_570
, /* 570 */
3995 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
3996 TPACPI_LED_NEW
, /* all others */
3999 enum { /* For TPACPI_LED_OLD */
4000 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
4001 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
4002 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
4005 static enum led_access_mode led_supported
;
4007 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
4008 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
4009 /* T20-22, X20-21 */
4010 "LED", /* all others */
4013 #define TPACPI_LED_NUMLEDS 8
4014 static struct tpacpi_led_classdev
*tpacpi_leds
;
4015 static enum led_status_t tpacpi_led_state_cache
[TPACPI_LED_NUMLEDS
];
4016 static const char * const tpacpi_led_names
[TPACPI_LED_NUMLEDS
] = {
4017 /* there's a limit of 19 chars + NULL before 2.6.26 */
4019 "tpacpi:orange:batt",
4020 "tpacpi:green:batt",
4021 "tpacpi::dock_active",
4022 "tpacpi::bay_active",
4023 "tpacpi::dock_batt",
4024 "tpacpi::unknown_led",
4028 static int led_get_status(const unsigned int led
)
4031 enum led_status_t led_s
;
4033 switch (led_supported
) {
4034 case TPACPI_LED_570
:
4035 if (!acpi_evalf(ec_handle
,
4036 &status
, "GLED", "dd", 1 << led
))
4038 led_s
= (status
== 0)?
4043 tpacpi_led_state_cache
[led
] = led_s
;
4052 static int led_set_status(const unsigned int led
,
4053 const enum led_status_t ledstatus
)
4055 /* off, on, blink. Index is led_status_t */
4056 static const unsigned int led_sled_arg1
[] = { 0, 1, 3 };
4057 static const unsigned int led_led_arg1
[] = { 0, 0x80, 0xc0 };
4061 switch (led_supported
) {
4062 case TPACPI_LED_570
:
4066 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
4067 (1 << led
), led_sled_arg1
[ledstatus
]))
4070 case TPACPI_LED_OLD
:
4071 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
4074 rc
= ec_write(TPACPI_LED_EC_HLMS
, (1 << led
));
4076 rc
= ec_write(TPACPI_LED_EC_HLBL
,
4077 (ledstatus
== TPACPI_LED_BLINK
) << led
);
4079 rc
= ec_write(TPACPI_LED_EC_HLCL
,
4080 (ledstatus
!= TPACPI_LED_OFF
) << led
);
4082 case TPACPI_LED_NEW
:
4084 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
4085 led
, led_led_arg1
[ledstatus
]))
4093 tpacpi_led_state_cache
[led
] = ledstatus
;
4098 static void led_set_status_worker(struct work_struct
*work
)
4100 struct tpacpi_led_classdev
*data
=
4101 container_of(work
, struct tpacpi_led_classdev
, work
);
4103 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4104 led_set_status(data
->led
, data
->new_state
);
4107 static void led_sysfs_set(struct led_classdev
*led_cdev
,
4108 enum led_brightness brightness
)
4110 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4111 struct tpacpi_led_classdev
, led_classdev
);
4113 if (brightness
== LED_OFF
)
4114 data
->new_state
= TPACPI_LED_OFF
;
4115 else if (tpacpi_led_state_cache
[data
->led
] != TPACPI_LED_BLINK
)
4116 data
->new_state
= TPACPI_LED_ON
;
4118 data
->new_state
= TPACPI_LED_BLINK
;
4120 queue_work(tpacpi_wq
, &data
->work
);
4123 static int led_sysfs_blink_set(struct led_classdev
*led_cdev
,
4124 unsigned long *delay_on
, unsigned long *delay_off
)
4126 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4127 struct tpacpi_led_classdev
, led_classdev
);
4129 /* Can we choose the flash rate? */
4130 if (*delay_on
== 0 && *delay_off
== 0) {
4131 /* yes. set them to the hardware blink rate (1 Hz) */
4132 *delay_on
= 500; /* ms */
4133 *delay_off
= 500; /* ms */
4134 } else if ((*delay_on
!= 500) || (*delay_off
!= 500))
4137 data
->new_state
= TPACPI_LED_BLINK
;
4138 queue_work(tpacpi_wq
, &data
->work
);
4143 static enum led_brightness
led_sysfs_get(struct led_classdev
*led_cdev
)
4147 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4148 struct tpacpi_led_classdev
, led_classdev
);
4150 rc
= led_get_status(data
->led
);
4152 if (rc
== TPACPI_LED_OFF
|| rc
< 0)
4153 rc
= LED_OFF
; /* no error handling in led class :( */
4160 static void led_exit(void)
4164 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
4165 if (tpacpi_leds
[i
].led_classdev
.name
)
4166 led_classdev_unregister(&tpacpi_leds
[i
].led_classdev
);
4172 static int __init
led_init(struct ibm_init_struct
*iibm
)
4177 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
4179 TPACPI_ACPIHANDLE_INIT(led
);
4182 /* led not supported on R30, R31 */
4183 led_supported
= TPACPI_LED_NONE
;
4184 else if (strlencmp(led_path
, "SLED") == 0)
4186 led_supported
= TPACPI_LED_570
;
4187 else if (strlencmp(led_path
, "SYSL") == 0)
4188 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4189 led_supported
= TPACPI_LED_OLD
;
4192 led_supported
= TPACPI_LED_NEW
;
4194 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
4195 str_supported(led_supported
), led_supported
);
4197 tpacpi_leds
= kzalloc(sizeof(*tpacpi_leds
) * TPACPI_LED_NUMLEDS
,
4200 printk(TPACPI_ERR
"Out of memory for LED data\n");
4204 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
4205 tpacpi_leds
[i
].led
= i
;
4207 tpacpi_leds
[i
].led_classdev
.brightness_set
= &led_sysfs_set
;
4208 tpacpi_leds
[i
].led_classdev
.blink_set
= &led_sysfs_blink_set
;
4209 if (led_supported
== TPACPI_LED_570
)
4210 tpacpi_leds
[i
].led_classdev
.brightness_get
=
4213 tpacpi_leds
[i
].led_classdev
.name
= tpacpi_led_names
[i
];
4215 INIT_WORK(&tpacpi_leds
[i
].work
, led_set_status_worker
);
4217 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4218 &tpacpi_leds
[i
].led_classdev
);
4220 tpacpi_leds
[i
].led_classdev
.name
= NULL
;
4226 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
4229 #define str_led_status(s) \
4230 ((s) == TPACPI_LED_OFF ? "off" : \
4231 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
4233 static int led_read(char *p
)
4237 if (!led_supported
) {
4238 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4241 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4243 if (led_supported
== TPACPI_LED_570
) {
4246 for (i
= 0; i
< 8; i
++) {
4247 status
= led_get_status(i
);
4250 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
4251 i
, str_led_status(status
));
4255 len
+= sprintf(p
+ len
, "commands:\t"
4256 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
4261 static int led_write(char *buf
)
4265 enum led_status_t s
;
4270 while ((cmd
= next_cmd(&buf
))) {
4271 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
4274 if (strstr(cmd
, "off")) {
4276 } else if (strstr(cmd
, "on")) {
4278 } else if (strstr(cmd
, "blink")) {
4279 s
= TPACPI_LED_BLINK
;
4284 rc
= led_set_status(led
, s
);
4292 static struct ibm_struct led_driver_data
= {
4299 /*************************************************************************
4303 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
4305 static int __init
beep_init(struct ibm_init_struct
*iibm
)
4307 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
4309 TPACPI_ACPIHANDLE_INIT(beep
);
4311 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
4312 str_supported(beep_handle
!= NULL
));
4314 return (beep_handle
)? 0 : 1;
4317 static int beep_read(char *p
)
4322 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4324 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4325 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
4331 static int beep_write(char *buf
)
4339 while ((cmd
= next_cmd(&buf
))) {
4340 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
4341 beep_cmd
>= 0 && beep_cmd
<= 17) {
4345 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
4352 static struct ibm_struct beep_driver_data
= {
4355 .write
= beep_write
,
4358 /*************************************************************************
4362 enum thermal_access_mode
{
4363 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
4364 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
4365 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
4366 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
4367 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
4370 enum { /* TPACPI_THERMAL_TPEC_* */
4371 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
4372 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
4373 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
4376 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
4377 struct ibm_thermal_sensors_struct
{
4378 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
4381 static enum thermal_access_mode thermal_read_mode
;
4383 /* idx is zero-based */
4384 static int thermal_get_sensor(int idx
, s32
*value
)
4390 t
= TP_EC_THERMAL_TMP0
;
4392 switch (thermal_read_mode
) {
4393 #if TPACPI_MAX_THERMAL_SENSORS >= 16
4394 case TPACPI_THERMAL_TPEC_16
:
4395 if (idx
>= 8 && idx
<= 15) {
4396 t
= TP_EC_THERMAL_TMP8
;
4401 case TPACPI_THERMAL_TPEC_8
:
4403 if (!acpi_ec_read(t
+ idx
, &tmp
))
4405 *value
= tmp
* 1000;
4410 case TPACPI_THERMAL_ACPI_UPDT
:
4412 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
4413 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
4415 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
4417 *value
= (t
- 2732) * 100;
4422 case TPACPI_THERMAL_ACPI_TMP07
:
4424 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
4425 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
4427 if (t
> 127 || t
< -127)
4428 t
= TP_EC_THERMAL_TMP_NA
;
4434 case TPACPI_THERMAL_NONE
:
4442 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
4453 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
4456 for (i
= 0 ; i
< n
; i
++) {
4457 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
4465 /* sysfs temp##_input -------------------------------------------------- */
4467 static ssize_t
thermal_temp_input_show(struct device
*dev
,
4468 struct device_attribute
*attr
,
4471 struct sensor_device_attribute
*sensor_attr
=
4472 to_sensor_dev_attr(attr
);
4473 int idx
= sensor_attr
->index
;
4477 res
= thermal_get_sensor(idx
, &value
);
4480 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
4483 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
4486 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
4487 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
4488 thermal_temp_input_show, NULL, _idxB)
4490 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
4491 THERMAL_SENSOR_ATTR_TEMP(1, 0),
4492 THERMAL_SENSOR_ATTR_TEMP(2, 1),
4493 THERMAL_SENSOR_ATTR_TEMP(3, 2),
4494 THERMAL_SENSOR_ATTR_TEMP(4, 3),
4495 THERMAL_SENSOR_ATTR_TEMP(5, 4),
4496 THERMAL_SENSOR_ATTR_TEMP(6, 5),
4497 THERMAL_SENSOR_ATTR_TEMP(7, 6),
4498 THERMAL_SENSOR_ATTR_TEMP(8, 7),
4499 THERMAL_SENSOR_ATTR_TEMP(9, 8),
4500 THERMAL_SENSOR_ATTR_TEMP(10, 9),
4501 THERMAL_SENSOR_ATTR_TEMP(11, 10),
4502 THERMAL_SENSOR_ATTR_TEMP(12, 11),
4503 THERMAL_SENSOR_ATTR_TEMP(13, 12),
4504 THERMAL_SENSOR_ATTR_TEMP(14, 13),
4505 THERMAL_SENSOR_ATTR_TEMP(15, 14),
4506 THERMAL_SENSOR_ATTR_TEMP(16, 15),
4509 #define THERMAL_ATTRS(X) \
4510 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
4512 static struct attribute
*thermal_temp_input_attr
[] = {
4532 static const struct attribute_group thermal_temp_input16_group
= {
4533 .attrs
= thermal_temp_input_attr
4536 static const struct attribute_group thermal_temp_input8_group
= {
4537 .attrs
= &thermal_temp_input_attr
[8]
4540 #undef THERMAL_SENSOR_ATTR_TEMP
4541 #undef THERMAL_ATTRS
4543 /* --------------------------------------------------------------------- */
4545 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
4552 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
4554 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
4556 if (thinkpad_id
.ec_model
) {
4558 * Direct EC access mode: sensors at registers
4559 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
4560 * non-implemented, thermal sensors return 0x80 when
4565 for (i
= 0; i
< 8; i
++) {
4566 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
4572 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
4580 /* This is sheer paranoia, but we handle it anyway */
4583 "ThinkPad ACPI EC access misbehaving, "
4584 "falling back to ACPI TMPx access "
4586 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
4589 "ThinkPad ACPI EC access misbehaving, "
4590 "disabling thermal sensors access\n");
4591 thermal_read_mode
= TPACPI_THERMAL_NONE
;
4596 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
4598 } else if (acpi_tmp7
) {
4599 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
4600 /* 600e/x, 770e, 770x */
4601 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
4603 /* Standard ACPI TMPx access, max 8 sensors */
4604 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
4607 /* temperatures not supported on 570, G4x, R30, R31, R32 */
4608 thermal_read_mode
= TPACPI_THERMAL_NONE
;
4611 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
4612 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
4615 switch (thermal_read_mode
) {
4616 case TPACPI_THERMAL_TPEC_16
:
4617 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4618 &thermal_temp_input16_group
);
4622 case TPACPI_THERMAL_TPEC_8
:
4623 case TPACPI_THERMAL_ACPI_TMP07
:
4624 case TPACPI_THERMAL_ACPI_UPDT
:
4625 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4626 &thermal_temp_input8_group
);
4630 case TPACPI_THERMAL_NONE
:
4638 static void thermal_exit(void)
4640 switch (thermal_read_mode
) {
4641 case TPACPI_THERMAL_TPEC_16
:
4642 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4643 &thermal_temp_input16_group
);
4645 case TPACPI_THERMAL_TPEC_8
:
4646 case TPACPI_THERMAL_ACPI_TMP07
:
4647 case TPACPI_THERMAL_ACPI_UPDT
:
4648 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4649 &thermal_temp_input16_group
);
4651 case TPACPI_THERMAL_NONE
:
4657 static int thermal_read(char *p
)
4661 struct ibm_thermal_sensors_struct t
;
4663 n
= thermal_get_sensors(&t
);
4664 if (unlikely(n
< 0))
4667 len
+= sprintf(p
+ len
, "temperatures:\t");
4670 for (i
= 0; i
< (n
- 1); i
++)
4671 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
4672 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
4674 len
+= sprintf(p
+ len
, "not supported\n");
4679 static struct ibm_struct thermal_driver_data
= {
4681 .read
= thermal_read
,
4682 .exit
= thermal_exit
,
4685 /*************************************************************************
4689 static u8 ecdump_regs
[256];
4691 static int ecdump_read(char *p
)
4697 len
+= sprintf(p
+ len
, "EC "
4698 " +00 +01 +02 +03 +04 +05 +06 +07"
4699 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
4700 for (i
= 0; i
< 256; i
+= 16) {
4701 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
4702 for (j
= 0; j
< 16; j
++) {
4703 if (!acpi_ec_read(i
+ j
, &v
))
4705 if (v
!= ecdump_regs
[i
+ j
])
4706 len
+= sprintf(p
+ len
, " *%02x", v
);
4708 len
+= sprintf(p
+ len
, " %02x", v
);
4709 ecdump_regs
[i
+ j
] = v
;
4711 len
+= sprintf(p
+ len
, "\n");
4716 /* These are way too dangerous to advertise openly... */
4718 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
4719 " (<offset> is 00-ff, <value> is 00-ff)\n");
4720 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
4721 " (<offset> is 00-ff, <value> is 0-255)\n");
4726 static int ecdump_write(char *buf
)
4731 while ((cmd
= next_cmd(&buf
))) {
4732 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
4734 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
4738 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
4739 if (!acpi_ec_write(i
, v
))
4748 static struct ibm_struct ecdump_driver_data
= {
4750 .read
= ecdump_read
,
4751 .write
= ecdump_write
,
4752 .flags
.experimental
= 1,
4755 /*************************************************************************
4756 * Backlight/brightness subdriver
4759 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
4762 TP_EC_BACKLIGHT
= 0x31,
4764 /* TP_EC_BACKLIGHT bitmasks */
4765 TP_EC_BACKLIGHT_LVLMSK
= 0x1F,
4766 TP_EC_BACKLIGHT_CMDMSK
= 0xE0,
4767 TP_EC_BACKLIGHT_MAPSW
= 0x20,
4770 static struct backlight_device
*ibm_backlight_device
;
4771 static int brightness_mode
;
4772 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
4774 static struct mutex brightness_mutex
;
4777 * ThinkPads can read brightness from two places: EC 0x31, or
4778 * CMOS NVRAM byte 0x5E, bits 0-3.
4780 * EC 0x31 has the following layout
4781 * Bit 7: unknown function
4782 * Bit 6: unknown function
4783 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
4784 * Bit 4: must be set to zero to avoid problems
4785 * Bit 3-0: backlight brightness level
4787 * brightness_get_raw returns status data in the EC 0x31 layout
4789 static int brightness_get_raw(int *status
)
4791 u8 lec
= 0, lcmos
= 0, level
= 0;
4793 if (brightness_mode
& 1) {
4794 if (!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
))
4796 level
= lec
& TP_EC_BACKLIGHT_LVLMSK
;
4798 if (brightness_mode
& 2) {
4799 lcmos
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
4800 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
4801 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
4802 lcmos
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
4806 if (brightness_mode
== 3) {
4807 *status
= lec
; /* Prefer EC, CMOS is just a backing store */
4808 lec
&= TP_EC_BACKLIGHT_LVLMSK
;
4810 tp_warned
.bright_cmos_ec_unsync
= 0;
4812 if (!tp_warned
.bright_cmos_ec_unsync
) {
4814 "CMOS NVRAM (%u) and EC (%u) do not "
4815 "agree on display brightness level\n",
4816 (unsigned int) lcmos
,
4817 (unsigned int) lec
);
4818 tp_warned
.bright_cmos_ec_unsync
= 1;
4829 /* May return EINTR which can always be mapped to ERESTARTSYS */
4830 static int brightness_set(int value
)
4832 int cmos_cmd
, inc
, i
, res
;
4836 if (value
> ((tp_features
.bright_16levels
)? 15 : 7) ||
4840 res
= mutex_lock_interruptible(&brightness_mutex
);
4844 res
= brightness_get_raw(¤t_value
);
4848 command_bits
= current_value
& TP_EC_BACKLIGHT_CMDMSK
;
4849 current_value
&= TP_EC_BACKLIGHT_LVLMSK
;
4851 cmos_cmd
= value
> current_value
?
4852 TP_CMOS_BRIGHTNESS_UP
:
4853 TP_CMOS_BRIGHTNESS_DOWN
;
4854 inc
= (value
> current_value
)? 1 : -1;
4857 for (i
= current_value
; i
!= value
; i
+= inc
) {
4858 if ((brightness_mode
& 2) &&
4859 issue_thinkpad_cmos_command(cmos_cmd
)) {
4863 if ((brightness_mode
& 1) &&
4864 !acpi_ec_write(TP_EC_BACKLIGHT
,
4865 (i
+ inc
) | command_bits
)) {
4872 mutex_unlock(&brightness_mutex
);
4876 /* sysfs backlight class ----------------------------------------------- */
4878 static int brightness_update_status(struct backlight_device
*bd
)
4880 /* it is the backlight class's job (caller) to handle
4881 * EINTR and other errors properly */
4882 return brightness_set(
4883 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
4884 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
4885 bd
->props
.brightness
: 0);
4888 static int brightness_get(struct backlight_device
*bd
)
4892 res
= brightness_get_raw(&status
);
4894 return 0; /* FIXME: teach backlight about error handling */
4896 return status
& TP_EC_BACKLIGHT_LVLMSK
;
4899 static struct backlight_ops ibm_backlight_data
= {
4900 .get_brightness
= brightness_get
,
4901 .update_status
= brightness_update_status
,
4904 /* --------------------------------------------------------------------- */
4906 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
4910 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
4912 mutex_init(&brightness_mutex
);
4915 * We always attempt to detect acpi support, so as to switch
4916 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
4917 * going to publish a backlight interface
4919 b
= tpacpi_check_std_acpi_brightness_support();
4921 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
4922 printk(TPACPI_NOTICE
4923 "Lenovo BIOS switched to ACPI backlight "
4926 if (brightness_enable
> 1) {
4927 printk(TPACPI_NOTICE
4928 "standard ACPI backlight interface "
4929 "available, not loading native one...\n");
4934 if (!brightness_enable
) {
4935 dbg_printk(TPACPI_DBG_INIT
,
4936 "brightness support disabled by "
4937 "module parameter\n");
4943 "Unsupported brightness interface, "
4944 "please contact %s\n", TPACPI_MAIL
);
4948 tp_features
.bright_16levels
= 1;
4950 if (!brightness_mode
) {
4951 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
)
4952 brightness_mode
= 2;
4954 brightness_mode
= 3;
4956 dbg_printk(TPACPI_DBG_INIT
, "selected brightness_mode=%d\n",
4960 if (brightness_mode
> 3)
4963 if (brightness_get_raw(&b
) < 0)
4966 if (tp_features
.bright_16levels
)
4968 "detected a 16-level brightness capable ThinkPad\n");
4970 ibm_backlight_device
= backlight_device_register(
4971 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
4972 &ibm_backlight_data
);
4973 if (IS_ERR(ibm_backlight_device
)) {
4974 printk(TPACPI_ERR
"Could not register backlight device\n");
4975 return PTR_ERR(ibm_backlight_device
);
4977 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
4979 ibm_backlight_device
->props
.max_brightness
=
4980 (tp_features
.bright_16levels
)? 15 : 7;
4981 ibm_backlight_device
->props
.brightness
= b
& TP_EC_BACKLIGHT_LVLMSK
;
4982 backlight_update_status(ibm_backlight_device
);
4987 static void brightness_exit(void)
4989 if (ibm_backlight_device
) {
4990 vdbg_printk(TPACPI_DBG_EXIT
,
4991 "calling backlight_device_unregister()\n");
4992 backlight_device_unregister(ibm_backlight_device
);
4996 static int brightness_read(char *p
)
5001 level
= brightness_get(NULL
);
5003 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
5005 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
5006 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
5007 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
5008 " (<level> is 0-%d)\n",
5009 (tp_features
.bright_16levels
) ? 15 : 7);
5015 static int brightness_write(char *buf
)
5020 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
5022 level
= brightness_get(NULL
);
5026 while ((cmd
= next_cmd(&buf
))) {
5027 if (strlencmp(cmd
, "up") == 0) {
5028 if (level
< max_level
)
5030 } else if (strlencmp(cmd
, "down") == 0) {
5033 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
5034 level
>= 0 && level
<= max_level
) {
5041 * Now we know what the final level should be, so we try to set it.
5042 * Doing it this way makes the syscall restartable in case of EINTR
5044 rc
= brightness_set(level
);
5045 return (rc
== -EINTR
)? -ERESTARTSYS
: rc
;
5048 static struct ibm_struct brightness_driver_data
= {
5049 .name
= "brightness",
5050 .read
= brightness_read
,
5051 .write
= brightness_write
,
5052 .exit
= brightness_exit
,
5055 /*************************************************************************
5059 static int volume_offset
= 0x30;
5061 static int volume_read(char *p
)
5066 if (!acpi_ec_read(volume_offset
, &level
)) {
5067 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
5069 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
5070 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
5071 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
5072 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
5073 " (<level> is 0-15)\n");
5079 static int volume_write(char *buf
)
5081 int cmos_cmd
, inc
, i
;
5083 int new_level
, new_mute
;
5086 while ((cmd
= next_cmd(&buf
))) {
5087 if (!acpi_ec_read(volume_offset
, &level
))
5089 new_mute
= mute
= level
& 0x40;
5090 new_level
= level
= level
& 0xf;
5092 if (strlencmp(cmd
, "up") == 0) {
5096 new_level
= level
== 15 ? 15 : level
+ 1;
5097 } else if (strlencmp(cmd
, "down") == 0) {
5101 new_level
= level
== 0 ? 0 : level
- 1;
5102 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
5103 new_level
>= 0 && new_level
<= 15) {
5105 } else if (strlencmp(cmd
, "mute") == 0) {
5110 if (new_level
!= level
) {
5111 /* mute doesn't change */
5113 cmos_cmd
= (new_level
> level
) ?
5114 TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
5115 inc
= new_level
> level
? 1 : -1;
5117 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
5118 !acpi_ec_write(volume_offset
, level
)))
5121 for (i
= level
; i
!= new_level
; i
+= inc
)
5122 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
5123 !acpi_ec_write(volume_offset
, i
+ inc
))
5127 (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
5128 !acpi_ec_write(volume_offset
, new_level
+ mute
))) {
5133 if (new_mute
!= mute
) {
5134 /* level doesn't change */
5136 cmos_cmd
= (new_mute
) ?
5137 TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
5139 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
5140 !acpi_ec_write(volume_offset
, level
+ new_mute
))
5148 static struct ibm_struct volume_driver_data
= {
5150 .read
= volume_read
,
5151 .write
= volume_write
,
5154 /*************************************************************************
5161 * TPACPI_FAN_RD_ACPI_GFAN:
5162 * ACPI GFAN method: returns fan level
5164 * see TPACPI_FAN_WR_ACPI_SFAN
5165 * EC 0x2f (HFSP) not available if GFAN exists
5167 * TPACPI_FAN_WR_ACPI_SFAN:
5168 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
5170 * EC 0x2f (HFSP) might be available *for reading*, but do not use
5173 * TPACPI_FAN_WR_TPEC:
5174 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
5175 * Supported on almost all ThinkPads
5177 * Fan speed changes of any sort (including those caused by the
5178 * disengaged mode) are usually done slowly by the firmware as the
5179 * maximum ammount of fan duty cycle change per second seems to be
5182 * Reading is not available if GFAN exists.
5183 * Writing is not available if SFAN exists.
5186 * 7 automatic mode engaged;
5187 * (default operation mode of the ThinkPad)
5188 * fan level is ignored in this mode.
5189 * 6 full speed mode (takes precedence over bit 7);
5190 * not available on all thinkpads. May disable
5191 * the tachometer while the fan controller ramps up
5192 * the speed (which can take up to a few *minutes*).
5193 * Speeds up fan to 100% duty-cycle, which is far above
5194 * the standard RPM levels. It is not impossible that
5195 * it could cause hardware damage.
5196 * 5-3 unused in some models. Extra bits for fan level
5197 * in others, but still useless as all values above
5198 * 7 map to the same speed as level 7 in these models.
5199 * 2-0 fan level (0..7 usually)
5201 * 0x07 = max (set when temperatures critical)
5202 * Some ThinkPads may have other levels, see
5203 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
5205 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
5206 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
5207 * does so, its initial value is meaningless (0x07).
5209 * For firmware bugs, refer to:
5210 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
5214 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
5215 * Main fan tachometer reading (in RPM)
5217 * This register is present on all ThinkPads with a new-style EC, and
5218 * it is known not to be present on the A21m/e, and T22, as there is
5219 * something else in offset 0x84 according to the ACPI DSDT. Other
5220 * ThinkPads from this same time period (and earlier) probably lack the
5221 * tachometer as well.
5223 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
5224 * was never fixed by IBM to report the EC firmware version string
5225 * probably support the tachometer (like the early X models), so
5226 * detecting it is quite hard. We need more data to know for sure.
5228 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
5231 * FIRMWARE BUG: may go stale while the EC is switching to full speed
5234 * For firmware bugs, refer to:
5235 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
5237 * TPACPI_FAN_WR_ACPI_FANS:
5238 * ThinkPad X31, X40, X41. Not available in the X60.
5240 * FANS ACPI handle: takes three arguments: low speed, medium speed,
5241 * high speed. ACPI DSDT seems to map these three speeds to levels
5242 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
5243 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
5245 * The speeds are stored on handles
5246 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
5248 * There are three default speed sets, acessible as handles:
5249 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
5251 * ACPI DSDT switches which set is in use depending on various
5254 * TPACPI_FAN_WR_TPEC is also available and should be used to
5255 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
5256 * but the ACPI tables just mention level 7.
5259 enum { /* Fan control constants */
5260 fan_status_offset
= 0x2f, /* EC register 0x2f */
5261 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
5262 * 0x84 must be read before 0x85 */
5264 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
5265 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
5267 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
5270 enum fan_status_access_mode
{
5271 TPACPI_FAN_NONE
= 0, /* No fan status or control */
5272 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
5273 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
5276 enum fan_control_access_mode
{
5277 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
5278 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
5279 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
5280 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
5283 enum fan_control_commands
{
5284 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
5285 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
5286 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
5287 * and also watchdog cmd */
5290 static int fan_control_allowed
;
5292 static enum fan_status_access_mode fan_status_access_mode
;
5293 static enum fan_control_access_mode fan_control_access_mode
;
5294 static enum fan_control_commands fan_control_commands
;
5296 static u8 fan_control_initial_status
;
5297 static u8 fan_control_desired_level
;
5298 static int fan_watchdog_maxinterval
;
5300 static struct mutex fan_mutex
;
5302 static void fan_watchdog_fire(struct work_struct
*ignored
);
5303 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
5305 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
5306 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
5307 "\\FSPD", /* 600e/x, 770e, 770x */
5309 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
5310 "JFNS", /* 770x-JL */
5314 * Call with fan_mutex held
5316 static void fan_update_desired_level(u8 status
)
5319 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
5321 fan_control_desired_level
= 7;
5323 fan_control_desired_level
= status
;
5327 static int fan_get_status(u8
*status
)
5332 * Add TPACPI_FAN_RD_ACPI_FANS ? */
5334 switch (fan_status_access_mode
) {
5335 case TPACPI_FAN_RD_ACPI_GFAN
:
5336 /* 570, 600e/x, 770e, 770x */
5338 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
5346 case TPACPI_FAN_RD_TPEC
:
5347 /* all except 570, 600e/x, 770e, 770x */
5348 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
5363 static int fan_get_status_safe(u8
*status
)
5368 if (mutex_lock_interruptible(&fan_mutex
))
5369 return -ERESTARTSYS
;
5370 rc
= fan_get_status(&s
);
5372 fan_update_desired_level(s
);
5373 mutex_unlock(&fan_mutex
);
5381 static int fan_get_speed(unsigned int *speed
)
5385 switch (fan_status_access_mode
) {
5386 case TPACPI_FAN_RD_TPEC
:
5387 /* all except 570, 600e/x, 770e, 770x */
5388 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
5389 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
5393 *speed
= (hi
<< 8) | lo
;
5404 static int fan_set_level(int level
)
5406 if (!fan_control_allowed
)
5409 switch (fan_control_access_mode
) {
5410 case TPACPI_FAN_WR_ACPI_SFAN
:
5411 if (level
>= 0 && level
<= 7) {
5412 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
5418 case TPACPI_FAN_WR_ACPI_FANS
:
5419 case TPACPI_FAN_WR_TPEC
:
5420 if ((level
!= TP_EC_FAN_AUTO
) &&
5421 (level
!= TP_EC_FAN_FULLSPEED
) &&
5422 ((level
< 0) || (level
> 7)))
5425 /* safety net should the EC not support AUTO
5426 * or FULLSPEED mode bits and just ignore them */
5427 if (level
& TP_EC_FAN_FULLSPEED
)
5428 level
|= 7; /* safety min speed 7 */
5429 else if (level
& TP_EC_FAN_AUTO
)
5430 level
|= 4; /* safety min speed 4 */
5432 if (!acpi_ec_write(fan_status_offset
, level
))
5435 tp_features
.fan_ctrl_status_undef
= 0;
5444 static int fan_set_level_safe(int level
)
5448 if (!fan_control_allowed
)
5451 if (mutex_lock_interruptible(&fan_mutex
))
5452 return -ERESTARTSYS
;
5454 if (level
== TPACPI_FAN_LAST_LEVEL
)
5455 level
= fan_control_desired_level
;
5457 rc
= fan_set_level(level
);
5459 fan_update_desired_level(level
);
5461 mutex_unlock(&fan_mutex
);
5465 static int fan_set_enable(void)
5470 if (!fan_control_allowed
)
5473 if (mutex_lock_interruptible(&fan_mutex
))
5474 return -ERESTARTSYS
;
5476 switch (fan_control_access_mode
) {
5477 case TPACPI_FAN_WR_ACPI_FANS
:
5478 case TPACPI_FAN_WR_TPEC
:
5479 rc
= fan_get_status(&s
);
5483 /* Don't go out of emergency fan mode */
5486 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
5489 if (!acpi_ec_write(fan_status_offset
, s
))
5492 tp_features
.fan_ctrl_status_undef
= 0;
5497 case TPACPI_FAN_WR_ACPI_SFAN
:
5498 rc
= fan_get_status(&s
);
5504 /* Set fan to at least level 4 */
5507 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
5517 mutex_unlock(&fan_mutex
);
5521 static int fan_set_disable(void)
5525 if (!fan_control_allowed
)
5528 if (mutex_lock_interruptible(&fan_mutex
))
5529 return -ERESTARTSYS
;
5532 switch (fan_control_access_mode
) {
5533 case TPACPI_FAN_WR_ACPI_FANS
:
5534 case TPACPI_FAN_WR_TPEC
:
5535 if (!acpi_ec_write(fan_status_offset
, 0x00))
5538 fan_control_desired_level
= 0;
5539 tp_features
.fan_ctrl_status_undef
= 0;
5543 case TPACPI_FAN_WR_ACPI_SFAN
:
5544 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
5547 fan_control_desired_level
= 0;
5555 mutex_unlock(&fan_mutex
);
5559 static int fan_set_speed(int speed
)
5563 if (!fan_control_allowed
)
5566 if (mutex_lock_interruptible(&fan_mutex
))
5567 return -ERESTARTSYS
;
5570 switch (fan_control_access_mode
) {
5571 case TPACPI_FAN_WR_ACPI_FANS
:
5572 if (speed
>= 0 && speed
<= 65535) {
5573 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
5574 speed
, speed
, speed
))
5584 mutex_unlock(&fan_mutex
);
5588 static void fan_watchdog_reset(void)
5590 static int fan_watchdog_active
;
5592 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
5595 if (fan_watchdog_active
)
5596 cancel_delayed_work(&fan_watchdog_task
);
5598 if (fan_watchdog_maxinterval
> 0 &&
5599 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
5600 fan_watchdog_active
= 1;
5601 if (!queue_delayed_work(tpacpi_wq
, &fan_watchdog_task
,
5602 msecs_to_jiffies(fan_watchdog_maxinterval
5605 "failed to queue the fan watchdog, "
5606 "watchdog will not trigger\n");
5609 fan_watchdog_active
= 0;
5612 static void fan_watchdog_fire(struct work_struct
*ignored
)
5616 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
5619 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
5620 rc
= fan_set_enable();
5622 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
5623 "will try again later...\n", -rc
);
5624 /* reschedule for later */
5625 fan_watchdog_reset();
5630 * SYSFS fan layout: hwmon compatible (device)
5633 * 0: "disengaged" mode
5635 * 2: native EC "auto" mode (recommended, hardware default)
5637 * pwm*: set speed in manual mode, ignored otherwise.
5638 * 0 is level 0; 255 is level 7. Intermediate points done with linear
5641 * fan*_input: tachometer reading, RPM
5644 * SYSFS fan layout: extensions
5646 * fan_watchdog (driver):
5647 * fan watchdog interval in seconds, 0 disables (default), max 120
5650 /* sysfs fan pwm1_enable ----------------------------------------------- */
5651 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
5652 struct device_attribute
*attr
,
5658 res
= fan_get_status_safe(&status
);
5662 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
5663 if (status
!= fan_control_initial_status
) {
5664 tp_features
.fan_ctrl_status_undef
= 0;
5666 /* Return most likely status. In fact, it
5667 * might be the only possible status */
5668 status
= TP_EC_FAN_AUTO
;
5672 if (status
& TP_EC_FAN_FULLSPEED
) {
5674 } else if (status
& TP_EC_FAN_AUTO
) {
5679 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
5682 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
5683 struct device_attribute
*attr
,
5684 const char *buf
, size_t count
)
5689 if (parse_strtoul(buf
, 2, &t
))
5694 level
= TP_EC_FAN_FULLSPEED
;
5697 level
= TPACPI_FAN_LAST_LEVEL
;
5700 level
= TP_EC_FAN_AUTO
;
5703 /* reserved for software-controlled auto mode */
5709 res
= fan_set_level_safe(level
);
5715 fan_watchdog_reset();
5720 static struct device_attribute dev_attr_fan_pwm1_enable
=
5721 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
5722 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
5724 /* sysfs fan pwm1 ------------------------------------------------------ */
5725 static ssize_t
fan_pwm1_show(struct device
*dev
,
5726 struct device_attribute
*attr
,
5732 res
= fan_get_status_safe(&status
);
5736 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
5737 if (status
!= fan_control_initial_status
) {
5738 tp_features
.fan_ctrl_status_undef
= 0;
5740 status
= TP_EC_FAN_AUTO
;
5745 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
5746 status
= fan_control_desired_level
;
5751 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
5754 static ssize_t
fan_pwm1_store(struct device
*dev
,
5755 struct device_attribute
*attr
,
5756 const char *buf
, size_t count
)
5760 u8 status
, newlevel
;
5762 if (parse_strtoul(buf
, 255, &s
))
5765 /* scale down from 0-255 to 0-7 */
5766 newlevel
= (s
>> 5) & 0x07;
5768 if (mutex_lock_interruptible(&fan_mutex
))
5769 return -ERESTARTSYS
;
5771 rc
= fan_get_status(&status
);
5772 if (!rc
&& (status
&
5773 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
5774 rc
= fan_set_level(newlevel
);
5778 fan_update_desired_level(newlevel
);
5779 fan_watchdog_reset();
5783 mutex_unlock(&fan_mutex
);
5784 return (rc
)? rc
: count
;
5787 static struct device_attribute dev_attr_fan_pwm1
=
5788 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
5789 fan_pwm1_show
, fan_pwm1_store
);
5791 /* sysfs fan fan1_input ------------------------------------------------ */
5792 static ssize_t
fan_fan1_input_show(struct device
*dev
,
5793 struct device_attribute
*attr
,
5799 res
= fan_get_speed(&speed
);
5803 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
5806 static struct device_attribute dev_attr_fan_fan1_input
=
5807 __ATTR(fan1_input
, S_IRUGO
,
5808 fan_fan1_input_show
, NULL
);
5810 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
5811 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
5814 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
5817 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
5818 const char *buf
, size_t count
)
5822 if (parse_strtoul(buf
, 120, &t
))
5825 if (!fan_control_allowed
)
5828 fan_watchdog_maxinterval
= t
;
5829 fan_watchdog_reset();
5834 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
5835 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
5837 /* --------------------------------------------------------------------- */
5838 static struct attribute
*fan_attributes
[] = {
5839 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
5840 &dev_attr_fan_fan1_input
.attr
,
5844 static const struct attribute_group fan_attr_group
= {
5845 .attrs
= fan_attributes
,
5848 static int __init
fan_init(struct ibm_init_struct
*iibm
)
5852 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
5854 mutex_init(&fan_mutex
);
5855 fan_status_access_mode
= TPACPI_FAN_NONE
;
5856 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
5857 fan_control_commands
= 0;
5858 fan_watchdog_maxinterval
= 0;
5859 tp_features
.fan_ctrl_status_undef
= 0;
5860 fan_control_desired_level
= 7;
5862 TPACPI_ACPIHANDLE_INIT(fans
);
5863 TPACPI_ACPIHANDLE_INIT(gfan
);
5864 TPACPI_ACPIHANDLE_INIT(sfan
);
5867 /* 570, 600e/x, 770e, 770x */
5868 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
5870 /* all other ThinkPads: note that even old-style
5871 * ThinkPad ECs supports the fan control register */
5872 if (likely(acpi_ec_read(fan_status_offset
,
5873 &fan_control_initial_status
))) {
5874 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
5876 /* In some ThinkPads, neither the EC nor the ACPI
5877 * DSDT initialize the fan status, and it ends up
5878 * being set to 0x07 when it *could* be either
5881 * Enable for TP-1Y (T43), TP-78 (R51e),
5882 * TP-76 (R52), TP-70 (T43, R52), which are known
5884 if (fan_control_initial_status
== 0x07) {
5885 switch (thinkpad_id
.ec_model
) {
5886 case 0x5931: /* TP-1Y */
5887 case 0x3837: /* TP-78 */
5888 case 0x3637: /* TP-76 */
5889 case 0x3037: /* TP-70 */
5890 printk(TPACPI_NOTICE
5891 "fan_init: initial fan status "
5892 "is unknown, assuming it is "
5894 tp_features
.fan_ctrl_status_undef
= 1;
5900 "ThinkPad ACPI EC access misbehaving, "
5901 "fan status and control unavailable\n");
5908 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
5909 fan_control_commands
|=
5910 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
5913 /* gfan without sfan means no fan control */
5914 /* all other models implement TP EC 0x2f control */
5918 fan_control_access_mode
=
5919 TPACPI_FAN_WR_ACPI_FANS
;
5920 fan_control_commands
|=
5921 TPACPI_FAN_CMD_SPEED
|
5922 TPACPI_FAN_CMD_LEVEL
|
5923 TPACPI_FAN_CMD_ENABLE
;
5925 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
5926 fan_control_commands
|=
5927 TPACPI_FAN_CMD_LEVEL
|
5928 TPACPI_FAN_CMD_ENABLE
;
5933 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
5934 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
5935 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
5936 fan_status_access_mode
, fan_control_access_mode
);
5938 /* fan control master switch */
5939 if (!fan_control_allowed
) {
5940 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
5941 fan_control_commands
= 0;
5942 dbg_printk(TPACPI_DBG_INIT
,
5943 "fan control features disabled by parameter\n");
5946 /* update fan_control_desired_level */
5947 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
5948 fan_get_status_safe(NULL
);
5950 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
5951 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
5952 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5957 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
5958 &driver_attr_fan_watchdog
);
5960 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5969 static void fan_exit(void)
5971 vdbg_printk(TPACPI_DBG_EXIT
,
5972 "cancelling any pending fan watchdog tasks\n");
5974 /* FIXME: can we really do this unconditionally? */
5975 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
5976 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
5977 &driver_attr_fan_watchdog
);
5979 cancel_delayed_work(&fan_watchdog_task
);
5980 flush_workqueue(tpacpi_wq
);
5983 static int fan_read(char *p
)
5988 unsigned int speed
= 0;
5990 switch (fan_status_access_mode
) {
5991 case TPACPI_FAN_RD_ACPI_GFAN
:
5992 /* 570, 600e/x, 770e, 770x */
5993 rc
= fan_get_status_safe(&status
);
5997 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
5999 (status
!= 0) ? "enabled" : "disabled", status
);
6002 case TPACPI_FAN_RD_TPEC
:
6003 /* all except 570, 600e/x, 770e, 770x */
6004 rc
= fan_get_status_safe(&status
);
6008 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
6009 if (status
!= fan_control_initial_status
)
6010 tp_features
.fan_ctrl_status_undef
= 0;
6012 /* Return most likely status. In fact, it
6013 * might be the only possible status */
6014 status
= TP_EC_FAN_AUTO
;
6017 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
6018 (status
!= 0) ? "enabled" : "disabled");
6020 rc
= fan_get_speed(&speed
);
6024 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
6026 if (status
& TP_EC_FAN_FULLSPEED
)
6027 /* Disengaged mode takes precedence */
6028 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
6029 else if (status
& TP_EC_FAN_AUTO
)
6030 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
6032 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
6035 case TPACPI_FAN_NONE
:
6037 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
6040 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
6041 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
6043 switch (fan_control_access_mode
) {
6044 case TPACPI_FAN_WR_ACPI_SFAN
:
6045 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
6049 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
6050 "auto, disengaged, full-speed)\n");
6055 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
6056 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
6057 "commands:\twatchdog <timeout> (<timeout> "
6058 "is 0 (off), 1-120 (seconds))\n");
6060 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
6061 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
6062 " (<speed> is 0-65535)\n");
6067 static int fan_write_cmd_level(const char *cmd
, int *rc
)
6071 if (strlencmp(cmd
, "level auto") == 0)
6072 level
= TP_EC_FAN_AUTO
;
6073 else if ((strlencmp(cmd
, "level disengaged") == 0) |
6074 (strlencmp(cmd
, "level full-speed") == 0))
6075 level
= TP_EC_FAN_FULLSPEED
;
6076 else if (sscanf(cmd
, "level %d", &level
) != 1)
6079 *rc
= fan_set_level_safe(level
);
6081 printk(TPACPI_ERR
"level command accepted for unsupported "
6082 "access mode %d", fan_control_access_mode
);
6087 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
6089 if (strlencmp(cmd
, "enable") != 0)
6092 *rc
= fan_set_enable();
6094 printk(TPACPI_ERR
"enable command accepted for unsupported "
6095 "access mode %d", fan_control_access_mode
);
6100 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
6102 if (strlencmp(cmd
, "disable") != 0)
6105 *rc
= fan_set_disable();
6107 printk(TPACPI_ERR
"disable command accepted for unsupported "
6108 "access mode %d", fan_control_access_mode
);
6113 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
6118 * Support speed <low> <medium> <high> ? */
6120 if (sscanf(cmd
, "speed %d", &speed
) != 1)
6123 *rc
= fan_set_speed(speed
);
6125 printk(TPACPI_ERR
"speed command accepted for unsupported "
6126 "access mode %d", fan_control_access_mode
);
6131 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
6135 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
6138 if (interval
< 0 || interval
> 120)
6141 fan_watchdog_maxinterval
= interval
;
6146 static int fan_write(char *buf
)
6151 while (!rc
&& (cmd
= next_cmd(&buf
))) {
6152 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
6153 fan_write_cmd_level(cmd
, &rc
)) &&
6154 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
6155 (fan_write_cmd_enable(cmd
, &rc
) ||
6156 fan_write_cmd_disable(cmd
, &rc
) ||
6157 fan_write_cmd_watchdog(cmd
, &rc
))) &&
6158 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
6159 fan_write_cmd_speed(cmd
, &rc
))
6163 fan_watchdog_reset();
6169 static struct ibm_struct fan_driver_data
= {
6176 /****************************************************************************
6177 ****************************************************************************
6181 ****************************************************************************
6182 ****************************************************************************/
6184 /* sysfs name ---------------------------------------------------------- */
6185 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
6186 struct device_attribute
*attr
,
6189 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
6192 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
6193 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
6195 /* --------------------------------------------------------------------- */
6198 static struct proc_dir_entry
*proc_dir
;
6201 * Module and infrastructure proble, init and exit handling
6204 static int force_load
;
6206 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
6207 static const char * __init
str_supported(int is_supported
)
6209 static char text_unsupported
[] __initdata
= "not supported";
6211 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
6213 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
6215 static void ibm_exit(struct ibm_struct
*ibm
)
6217 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
6219 list_del_init(&ibm
->all_drivers
);
6221 if (ibm
->flags
.acpi_notify_installed
) {
6222 dbg_printk(TPACPI_DBG_EXIT
,
6223 "%s: acpi_remove_notify_handler\n", ibm
->name
);
6225 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
6227 dispatch_acpi_notify
);
6228 ibm
->flags
.acpi_notify_installed
= 0;
6229 ibm
->flags
.acpi_notify_installed
= 0;
6232 if (ibm
->flags
.proc_created
) {
6233 dbg_printk(TPACPI_DBG_EXIT
,
6234 "%s: remove_proc_entry\n", ibm
->name
);
6235 remove_proc_entry(ibm
->name
, proc_dir
);
6236 ibm
->flags
.proc_created
= 0;
6239 if (ibm
->flags
.acpi_driver_registered
) {
6240 dbg_printk(TPACPI_DBG_EXIT
,
6241 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
6243 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
6244 kfree(ibm
->acpi
->driver
);
6245 ibm
->acpi
->driver
= NULL
;
6246 ibm
->flags
.acpi_driver_registered
= 0;
6249 if (ibm
->flags
.init_called
&& ibm
->exit
) {
6251 ibm
->flags
.init_called
= 0;
6254 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
6257 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
6260 struct ibm_struct
*ibm
= iibm
->data
;
6261 struct proc_dir_entry
*entry
;
6263 BUG_ON(ibm
== NULL
);
6265 INIT_LIST_HEAD(&ibm
->all_drivers
);
6267 if (ibm
->flags
.experimental
&& !experimental
)
6270 dbg_printk(TPACPI_DBG_INIT
,
6271 "probing for %s\n", ibm
->name
);
6274 ret
= iibm
->init(iibm
);
6276 return 0; /* probe failed */
6280 ibm
->flags
.init_called
= 1;
6284 if (ibm
->acpi
->hid
) {
6285 ret
= register_tpacpi_subdriver(ibm
);
6290 if (ibm
->acpi
->notify
) {
6291 ret
= setup_acpi_notify(ibm
);
6292 if (ret
== -ENODEV
) {
6293 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
6303 dbg_printk(TPACPI_DBG_INIT
,
6304 "%s installed\n", ibm
->name
);
6307 entry
= create_proc_entry(ibm
->name
,
6308 S_IFREG
| S_IRUGO
| S_IWUSR
,
6311 printk(TPACPI_ERR
"unable to create proc entry %s\n",
6316 entry
->owner
= THIS_MODULE
;
6318 entry
->read_proc
= &dispatch_procfs_read
;
6320 entry
->write_proc
= &dispatch_procfs_write
;
6321 ibm
->flags
.proc_created
= 1;
6324 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
6329 dbg_printk(TPACPI_DBG_INIT
,
6330 "%s: at error exit path with result %d\n",
6334 return (ret
< 0)? ret
: 0;
6339 /* returns 0 - probe ok, or < 0 - probe error.
6340 * Probe ok doesn't mean thinkpad found.
6341 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
6342 static int __must_check __init
get_thinkpad_model_data(
6343 struct thinkpad_id_data
*tp
)
6345 const struct dmi_device
*dev
= NULL
;
6346 char ec_fw_string
[18];
6352 memset(tp
, 0, sizeof(*tp
));
6354 if (dmi_name_in_vendors("IBM"))
6355 tp
->vendor
= PCI_VENDOR_ID_IBM
;
6356 else if (dmi_name_in_vendors("LENOVO"))
6357 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
6361 s
= dmi_get_system_info(DMI_BIOS_VERSION
);
6362 tp
->bios_version_str
= kstrdup(s
, GFP_KERNEL
);
6363 if (s
&& !tp
->bios_version_str
)
6365 if (!tp
->bios_version_str
)
6367 tp
->bios_model
= tp
->bios_version_str
[0]
6368 | (tp
->bios_version_str
[1] << 8);
6371 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
6372 * X32 or newer, all Z series; Some models must have an
6373 * up-to-date BIOS or they will not be detected.
6375 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
6377 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
6378 if (sscanf(dev
->name
,
6379 "IBM ThinkPad Embedded Controller -[%17c",
6380 ec_fw_string
) == 1) {
6381 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
6382 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
6384 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
6385 if (!tp
->ec_version_str
)
6387 tp
->ec_model
= ec_fw_string
[0]
6388 | (ec_fw_string
[1] << 8);
6393 s
= dmi_get_system_info(DMI_PRODUCT_VERSION
);
6394 if (s
&& !strnicmp(s
, "ThinkPad", 8)) {
6395 tp
->model_str
= kstrdup(s
, GFP_KERNEL
);
6400 s
= dmi_get_system_info(DMI_PRODUCT_NAME
);
6401 tp
->nummodel_str
= kstrdup(s
, GFP_KERNEL
);
6402 if (s
&& !tp
->nummodel_str
)
6408 static int __init
probe_for_thinkpad(void)
6416 * Non-ancient models have better DMI tagging, but very old models
6419 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
6421 /* ec is required because many other handles are relative to it */
6422 TPACPI_ACPIHANDLE_INIT(ec
);
6426 "Not yet supported ThinkPad detected!\n");
6431 * Risks a regression on very old machines, but reduces potential
6432 * false positives a damn great deal
6435 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
6437 if (!is_thinkpad
&& !force_load
)
6444 /* Module init, exit, parameters */
6446 static struct ibm_init_struct ibms_init
[] __initdata
= {
6448 .init
= thinkpad_acpi_driver_init
,
6449 .data
= &thinkpad_acpi_driver_data
,
6452 .init
= hotkey_init
,
6453 .data
= &hotkey_driver_data
,
6456 .init
= bluetooth_init
,
6457 .data
= &bluetooth_driver_data
,
6461 .data
= &wan_driver_data
,
6463 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
6466 .data
= &video_driver_data
,
6471 .data
= &light_driver_data
,
6473 #ifdef CONFIG_THINKPAD_ACPI_DOCK
6476 .data
= &dock_driver_data
[0],
6480 .data
= &dock_driver_data
[1],
6483 #ifdef CONFIG_THINKPAD_ACPI_BAY
6486 .data
= &bay_driver_data
,
6491 .data
= &cmos_driver_data
,
6495 .data
= &led_driver_data
,
6499 .data
= &beep_driver_data
,
6502 .init
= thermal_init
,
6503 .data
= &thermal_driver_data
,
6506 .data
= &ecdump_driver_data
,
6509 .init
= brightness_init
,
6510 .data
= &brightness_driver_data
,
6513 .data
= &volume_driver_data
,
6517 .data
= &fan_driver_data
,
6521 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
6524 struct ibm_struct
*ibm
;
6526 if (!kp
|| !kp
->name
|| !val
)
6529 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
6530 ibm
= ibms_init
[i
].data
;
6531 WARN_ON(ibm
== NULL
);
6533 if (!ibm
|| !ibm
->name
)
6536 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
6537 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
6539 strcpy(ibms_init
[i
].param
, val
);
6540 strcat(ibms_init
[i
].param
, ",");
6548 module_param(experimental
, int, 0);
6549 MODULE_PARM_DESC(experimental
,
6550 "Enables experimental features when non-zero");
6552 module_param_named(debug
, dbg_level
, uint
, 0);
6553 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
6555 module_param(force_load
, bool, 0);
6556 MODULE_PARM_DESC(force_load
,
6557 "Attempts to load the driver even on a "
6558 "mis-identified ThinkPad when true");
6560 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
6561 MODULE_PARM_DESC(fan_control
,
6562 "Enables setting fan parameters features when true");
6564 module_param_named(brightness_mode
, brightness_mode
, int, 0);
6565 MODULE_PARM_DESC(brightness_mode
,
6566 "Selects brightness control strategy: "
6567 "0=auto, 1=EC, 2=CMOS, 3=both");
6569 module_param(brightness_enable
, uint
, 0);
6570 MODULE_PARM_DESC(brightness_enable
,
6571 "Enables backlight control when 1, disables when 0");
6573 module_param(hotkey_report_mode
, uint
, 0);
6574 MODULE_PARM_DESC(hotkey_report_mode
,
6575 "used for backwards compatibility with userspace, "
6576 "see documentation");
6578 #define TPACPI_PARAM(feature) \
6579 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
6580 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
6581 "at module load, see documentation")
6583 TPACPI_PARAM(hotkey
);
6584 TPACPI_PARAM(bluetooth
);
6585 TPACPI_PARAM(video
);
6586 TPACPI_PARAM(light
);
6587 #ifdef CONFIG_THINKPAD_ACPI_DOCK
6590 #ifdef CONFIG_THINKPAD_ACPI_BAY
6592 #endif /* CONFIG_THINKPAD_ACPI_BAY */
6596 TPACPI_PARAM(ecdump
);
6597 TPACPI_PARAM(brightness
);
6598 TPACPI_PARAM(volume
);
6601 static void thinkpad_acpi_module_exit(void)
6603 struct ibm_struct
*ibm
, *itmp
;
6605 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
6607 list_for_each_entry_safe_reverse(ibm
, itmp
,
6608 &tpacpi_all_drivers
,
6613 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
6615 if (tpacpi_inputdev
) {
6616 if (tp_features
.input_device_registered
)
6617 input_unregister_device(tpacpi_inputdev
);
6619 input_free_device(tpacpi_inputdev
);
6623 hwmon_device_unregister(tpacpi_hwmon
);
6625 if (tp_features
.sensors_pdev_attrs_registered
)
6626 device_remove_file(&tpacpi_sensors_pdev
->dev
,
6627 &dev_attr_thinkpad_acpi_pdev_name
);
6628 if (tpacpi_sensors_pdev
)
6629 platform_device_unregister(tpacpi_sensors_pdev
);
6631 platform_device_unregister(tpacpi_pdev
);
6633 if (tp_features
.sensors_pdrv_attrs_registered
)
6634 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
6635 if (tp_features
.platform_drv_attrs_registered
)
6636 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
6638 if (tp_features
.sensors_pdrv_registered
)
6639 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
6641 if (tp_features
.platform_drv_registered
)
6642 platform_driver_unregister(&tpacpi_pdriver
);
6645 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
6648 destroy_workqueue(tpacpi_wq
);
6650 kfree(thinkpad_id
.bios_version_str
);
6651 kfree(thinkpad_id
.ec_version_str
);
6652 kfree(thinkpad_id
.model_str
);
6656 static int __init
thinkpad_acpi_module_init(void)
6660 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
6662 /* Parameter checking */
6663 if (hotkey_report_mode
> 2)
6666 /* Driver-level probe */
6668 ret
= get_thinkpad_model_data(&thinkpad_id
);
6671 "unable to get DMI data: %d\n", ret
);
6672 thinkpad_acpi_module_exit();
6675 ret
= probe_for_thinkpad();
6677 thinkpad_acpi_module_exit();
6681 /* Driver initialization */
6683 TPACPI_ACPIHANDLE_INIT(ecrd
);
6684 TPACPI_ACPIHANDLE_INIT(ecwr
);
6686 tpacpi_wq
= create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME
);
6688 thinkpad_acpi_module_exit();
6692 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
6695 "unable to create proc dir " TPACPI_PROC_DIR
);
6696 thinkpad_acpi_module_exit();
6699 proc_dir
->owner
= THIS_MODULE
;
6701 ret
= platform_driver_register(&tpacpi_pdriver
);
6704 "unable to register main platform driver\n");
6705 thinkpad_acpi_module_exit();
6708 tp_features
.platform_drv_registered
= 1;
6710 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
6713 "unable to register hwmon platform driver\n");
6714 thinkpad_acpi_module_exit();
6717 tp_features
.sensors_pdrv_registered
= 1;
6719 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
6721 tp_features
.platform_drv_attrs_registered
= 1;
6722 ret
= tpacpi_create_driver_attributes(
6723 &tpacpi_hwmon_pdriver
.driver
);
6727 "unable to create sysfs driver attributes\n");
6728 thinkpad_acpi_module_exit();
6731 tp_features
.sensors_pdrv_attrs_registered
= 1;
6734 /* Device initialization */
6735 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
6737 if (IS_ERR(tpacpi_pdev
)) {
6738 ret
= PTR_ERR(tpacpi_pdev
);
6740 printk(TPACPI_ERR
"unable to register platform device\n");
6741 thinkpad_acpi_module_exit();
6744 tpacpi_sensors_pdev
= platform_device_register_simple(
6745 TPACPI_HWMON_DRVR_NAME
,
6747 if (IS_ERR(tpacpi_sensors_pdev
)) {
6748 ret
= PTR_ERR(tpacpi_sensors_pdev
);
6749 tpacpi_sensors_pdev
= NULL
;
6751 "unable to register hwmon platform device\n");
6752 thinkpad_acpi_module_exit();
6755 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
6756 &dev_attr_thinkpad_acpi_pdev_name
);
6759 "unable to create sysfs hwmon device attributes\n");
6760 thinkpad_acpi_module_exit();
6763 tp_features
.sensors_pdev_attrs_registered
= 1;
6764 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
6765 if (IS_ERR(tpacpi_hwmon
)) {
6766 ret
= PTR_ERR(tpacpi_hwmon
);
6767 tpacpi_hwmon
= NULL
;
6768 printk(TPACPI_ERR
"unable to register hwmon device\n");
6769 thinkpad_acpi_module_exit();
6772 mutex_init(&tpacpi_inputdev_send_mutex
);
6773 tpacpi_inputdev
= input_allocate_device();
6774 if (!tpacpi_inputdev
) {
6775 printk(TPACPI_ERR
"unable to allocate input device\n");
6776 thinkpad_acpi_module_exit();
6779 /* Prepare input device, but don't register */
6780 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
6781 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
6782 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
6783 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
6784 thinkpad_id
.vendor
:
6786 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
6787 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
6789 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
6790 ret
= ibm_init(&ibms_init
[i
]);
6791 if (ret
>= 0 && *ibms_init
[i
].param
)
6792 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
6794 thinkpad_acpi_module_exit();
6798 ret
= input_register_device(tpacpi_inputdev
);
6800 printk(TPACPI_ERR
"unable to register input device\n");
6801 thinkpad_acpi_module_exit();
6804 tp_features
.input_device_registered
= 1;
6807 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
6811 /* Please remove this in year 2009 */
6812 MODULE_ALIAS("ibm_acpi");
6814 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME
);
6817 * DMI matching for module autoloading
6819 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
6820 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
6822 * Only models listed in thinkwiki will be supported, so add yours
6823 * if it is not there yet.
6825 #define IBM_BIOS_MODULE_ALIAS(__type) \
6826 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*")
6828 /* Non-ancient thinkpads */
6829 MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*");
6830 MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*");
6832 /* Ancient thinkpad BIOSes have to be identified by
6833 * BIOS type or model number, and there are far less
6834 * BIOS types than model numbers... */
6835 IBM_BIOS_MODULE_ALIAS("I[BDHIMNOTWVYZ]");
6836 IBM_BIOS_MODULE_ALIAS("1[0368A-GIKM-PST]");
6837 IBM_BIOS_MODULE_ALIAS("K[UX-Z]");
6839 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
6840 MODULE_DESCRIPTION(TPACPI_DESC
);
6841 MODULE_VERSION(TPACPI_VERSION
);
6842 MODULE_LICENSE("GPL");
6844 module_init(thinkpad_acpi_module_init
);
6845 module_exit(thinkpad_acpi_module_exit
);