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.19"
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 <asm/uaccess.h>
73 #include <linux/dmi.h>
74 #include <linux/jiffies.h>
75 #include <linux/workqueue.h>
77 #include <acpi/acpi_drivers.h>
78 #include <acpi/acnamesp.h>
80 #include <linux/pci_ids.h>
83 /* ThinkPad CMOS commands */
84 #define TP_CMOS_VOLUME_DOWN 0
85 #define TP_CMOS_VOLUME_UP 1
86 #define TP_CMOS_VOLUME_MUTE 2
87 #define TP_CMOS_BRIGHTNESS_UP 4
88 #define TP_CMOS_BRIGHTNESS_DOWN 5
89 #define TP_CMOS_THINKLIGHT_ON 12
90 #define TP_CMOS_THINKLIGHT_OFF 13
94 TP_NVRAM_ADDR_HK2
= 0x57,
95 TP_NVRAM_ADDR_THINKLIGHT
= 0x58,
96 TP_NVRAM_ADDR_VIDEO
= 0x59,
97 TP_NVRAM_ADDR_BRIGHTNESS
= 0x5e,
98 TP_NVRAM_ADDR_MIXER
= 0x60,
101 /* NVRAM bit masks */
103 TP_NVRAM_MASK_HKT_THINKPAD
= 0x08,
104 TP_NVRAM_MASK_HKT_ZOOM
= 0x20,
105 TP_NVRAM_MASK_HKT_DISPLAY
= 0x40,
106 TP_NVRAM_MASK_HKT_HIBERNATE
= 0x80,
107 TP_NVRAM_MASK_THINKLIGHT
= 0x10,
108 TP_NVRAM_MASK_HKT_DISPEXPND
= 0x30,
109 TP_NVRAM_MASK_HKT_BRIGHTNESS
= 0x20,
110 TP_NVRAM_MASK_LEVEL_BRIGHTNESS
= 0x0f,
111 TP_NVRAM_POS_LEVEL_BRIGHTNESS
= 0,
112 TP_NVRAM_MASK_MUTE
= 0x40,
113 TP_NVRAM_MASK_HKT_VOLUME
= 0x80,
114 TP_NVRAM_MASK_LEVEL_VOLUME
= 0x0f,
115 TP_NVRAM_POS_LEVEL_VOLUME
= 0,
119 #define TPACPI_ACPI_HKEY_HID "IBM0068"
122 #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */
123 #define TPACPI_HKEY_INPUT_VERSION 0x4101
126 /****************************************************************************
130 #define TPACPI_NAME "thinkpad"
131 #define TPACPI_DESC "ThinkPad ACPI Extras"
132 #define TPACPI_FILE TPACPI_NAME "_acpi"
133 #define TPACPI_URL "http://ibm-acpi.sf.net/"
134 #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net"
136 #define TPACPI_PROC_DIR "ibm"
137 #define TPACPI_ACPI_EVENT_PREFIX "ibm"
138 #define TPACPI_DRVR_NAME TPACPI_FILE
139 #define TPACPI_DRVR_SHORTNAME "tpacpi"
140 #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon"
142 #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd"
144 #define TPACPI_MAX_ACPI_ARGS 3
147 #define TPACPI_LOG TPACPI_FILE ": "
148 #define TPACPI_ERR KERN_ERR TPACPI_LOG
149 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
150 #define TPACPI_INFO KERN_INFO TPACPI_LOG
151 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
153 #define TPACPI_DBG_ALL 0xffff
154 #define TPACPI_DBG_ALL 0xffff
155 #define TPACPI_DBG_INIT 0x0001
156 #define TPACPI_DBG_EXIT 0x0002
157 #define dbg_printk(a_dbg_level, format, arg...) \
158 do { if (dbg_level & a_dbg_level) \
159 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
161 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
162 #define vdbg_printk(a_dbg_level, format, arg...) \
163 dbg_printk(a_dbg_level, format, ## arg)
164 static const char *str_supported(int is_supported
);
166 #define vdbg_printk(a_dbg_level, format, arg...)
169 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
170 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
171 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
174 /****************************************************************************
175 * Driver-wide structs and misc. variables
180 struct tp_acpi_drv_struct
{
181 const struct acpi_device_id
*hid
;
182 struct acpi_driver
*driver
;
184 void (*notify
) (struct ibm_struct
*, u32
);
187 struct acpi_device
*device
;
193 int (*read
) (char *);
194 int (*write
) (char *);
196 void (*resume
) (void);
197 void (*suspend
) (pm_message_t state
);
199 struct list_head all_drivers
;
201 struct tp_acpi_drv_struct
*acpi
;
204 u8 acpi_driver_registered
:1;
205 u8 acpi_notify_installed
:1;
212 struct ibm_init_struct
{
215 int (*init
) (struct ibm_init_struct
*);
216 struct ibm_struct
*data
;
220 #ifdef CONFIG_THINKPAD_ACPI_BAY
233 u32 bright_16levels
:1;
234 u32 bright_acpimode
:1;
236 u32 fan_ctrl_status_undef
:1;
237 u32 input_device_registered
:1;
238 u32 platform_drv_registered
:1;
239 u32 platform_drv_attrs_registered
:1;
240 u32 sensors_pdrv_registered
:1;
241 u32 sensors_pdrv_attrs_registered
:1;
242 u32 sensors_pdev_attrs_registered
:1;
243 u32 hotkey_poll_active
:1;
247 u16 hotkey_mask_ff
:1;
248 u16 bright_cmos_ec_unsync
:1;
251 struct thinkpad_id_data
{
252 unsigned int vendor
; /* ThinkPad vendor:
253 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
255 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
256 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
258 u16 bios_model
; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */
261 char *model_str
; /* ThinkPad T43 */
262 char *nummodel_str
; /* 9384A9C for a 9384-A9C model */
264 static struct thinkpad_id_data thinkpad_id
;
267 TPACPI_LIFE_INIT
= 0,
272 static int experimental
;
273 static u32 dbg_level
;
275 /* Special LED class that can defer work */
276 struct tpacpi_led_classdev
{
277 struct led_classdev led_classdev
;
278 struct work_struct work
;
279 enum led_brightness new_brightness
;
283 /****************************************************************************
284 ****************************************************************************
286 * ACPI Helpers and device model
288 ****************************************************************************
289 ****************************************************************************/
291 /*************************************************************************
295 static acpi_handle root_handle
;
297 #define TPACPI_HANDLE(object, parent, paths...) \
298 static acpi_handle object##_handle; \
299 static acpi_handle *object##_parent = &parent##_handle; \
300 static char *object##_path; \
301 static char *object##_paths[] = { paths }
303 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
304 "\\_SB.PCI.ISA.EC", /* 570 */
305 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
306 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
307 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
308 "\\_SB.PCI0.ICH3.EC0", /* R31 */
309 "\\_SB.PCI0.LPC.EC", /* all others */
312 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
313 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
315 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
317 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
318 "\\CMS", /* R40, R40e */
321 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
322 "^HKEY", /* R30, R31 */
323 "HKEY", /* all others */
326 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
327 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
328 "\\_SB.PCI0.VID0", /* 770e */
329 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
330 "\\_SB.PCI0.AGP.VID", /* all others */
334 /*************************************************************************
338 static int acpi_evalf(acpi_handle handle
,
339 void *res
, char *method
, char *fmt
, ...)
342 struct acpi_object_list params
;
343 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
344 struct acpi_buffer result
, *resultp
;
345 union acpi_object out_obj
;
353 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
366 params
.pointer
= &in_objs
[0];
373 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
374 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
376 /* add more types as needed */
378 printk(TPACPI_ERR
"acpi_evalf() called "
379 "with invalid format character '%c'\n", c
);
385 if (res_type
!= 'v') {
386 result
.length
= sizeof(out_obj
);
387 result
.pointer
= &out_obj
;
392 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
397 *(int *)res
= out_obj
.integer
.value
;
398 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
401 success
= status
== AE_OK
;
403 /* add more types as needed */
405 printk(TPACPI_ERR
"acpi_evalf() called "
406 "with invalid format character '%c'\n", res_type
);
410 if (!success
&& !quiet
)
411 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
412 method
, fmt0
, status
);
417 static int acpi_ec_read(int i
, u8
*p
)
422 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
426 if (ec_read(i
, p
) < 0)
433 static int acpi_ec_write(int i
, u8 v
)
436 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
439 if (ec_write(i
, v
) < 0)
446 #if defined(CONFIG_THINKPAD_ACPI_DOCK) || defined(CONFIG_THINKPAD_ACPI_BAY)
447 static int _sta(acpi_handle handle
)
451 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
458 static int issue_thinkpad_cmos_command(int cmos_cmd
)
463 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
469 /*************************************************************************
473 #define TPACPI_ACPIHANDLE_INIT(object) \
474 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
475 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
477 static void drv_acpi_handle_init(char *name
,
478 acpi_handle
*handle
, acpi_handle parent
,
479 char **paths
, int num_paths
, char **path
)
484 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
487 for (i
= 0; i
< num_paths
; i
++) {
488 status
= acpi_get_handle(parent
, paths
[i
], handle
);
489 if (ACPI_SUCCESS(status
)) {
491 dbg_printk(TPACPI_DBG_INIT
,
492 "Found ACPI handle %s for %s\n",
498 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
503 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
505 struct ibm_struct
*ibm
= data
;
507 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
510 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
513 ibm
->acpi
->notify(ibm
, event
);
516 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
523 if (!*ibm
->acpi
->handle
)
526 vdbg_printk(TPACPI_DBG_INIT
,
527 "setting up ACPI notify for %s\n", ibm
->name
);
529 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
531 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
536 acpi_driver_data(ibm
->acpi
->device
) = ibm
;
537 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
538 TPACPI_ACPI_EVENT_PREFIX
,
541 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
542 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
543 if (ACPI_FAILURE(status
)) {
544 if (status
== AE_ALREADY_EXISTS
) {
546 "another device driver is already "
547 "handling %s events\n", ibm
->name
);
550 "acpi_install_notify_handler(%s) failed: %d\n",
555 ibm
->flags
.acpi_notify_installed
= 1;
559 static int __init
tpacpi_device_add(struct acpi_device
*device
)
564 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
568 dbg_printk(TPACPI_DBG_INIT
,
569 "registering %s as an ACPI driver\n", ibm
->name
);
573 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
574 if (!ibm
->acpi
->driver
) {
575 printk(TPACPI_ERR
"kzalloc(ibm->driver) failed\n");
579 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
580 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
582 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
584 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
586 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
588 kfree(ibm
->acpi
->driver
);
589 ibm
->acpi
->driver
= NULL
;
591 ibm
->flags
.acpi_driver_registered
= 1;
597 /****************************************************************************
598 ****************************************************************************
602 ****************************************************************************
603 ****************************************************************************/
605 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
606 int count
, int *eof
, void *data
)
608 struct ibm_struct
*ibm
= data
;
611 if (!ibm
|| !ibm
->read
)
614 len
= ibm
->read(page
);
618 if (len
<= off
+ count
)
630 static int dispatch_procfs_write(struct file
*file
,
631 const char __user
*userbuf
,
632 unsigned long count
, void *data
)
634 struct ibm_struct
*ibm
= data
;
638 if (!ibm
|| !ibm
->write
)
641 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
645 if (copy_from_user(kernbuf
, userbuf
, count
)) {
651 strcat(kernbuf
, ",");
652 ret
= ibm
->write(kernbuf
);
661 static char *next_cmd(char **cmds
)
666 while ((end
= strchr(start
, ',')) && end
== start
)
678 /****************************************************************************
679 ****************************************************************************
681 * Device model: input, hwmon and platform
683 ****************************************************************************
684 ****************************************************************************/
686 static struct platform_device
*tpacpi_pdev
;
687 static struct platform_device
*tpacpi_sensors_pdev
;
688 static struct device
*tpacpi_hwmon
;
689 static struct input_dev
*tpacpi_inputdev
;
690 static struct mutex tpacpi_inputdev_send_mutex
;
691 static LIST_HEAD(tpacpi_all_drivers
);
693 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
696 struct ibm_struct
*ibm
, *itmp
;
698 list_for_each_entry_safe(ibm
, itmp
,
702 (ibm
->suspend
)(state
);
708 static int tpacpi_resume_handler(struct platform_device
*pdev
)
710 struct ibm_struct
*ibm
, *itmp
;
712 list_for_each_entry_safe(ibm
, itmp
,
722 static struct platform_driver tpacpi_pdriver
= {
724 .name
= TPACPI_DRVR_NAME
,
725 .owner
= THIS_MODULE
,
727 .suspend
= tpacpi_suspend_handler
,
728 .resume
= tpacpi_resume_handler
,
731 static struct platform_driver tpacpi_hwmon_pdriver
= {
733 .name
= TPACPI_HWMON_DRVR_NAME
,
734 .owner
= THIS_MODULE
,
738 /*************************************************************************
739 * sysfs support helpers
742 struct attribute_set
{
743 unsigned int members
, max_members
;
744 struct attribute_group group
;
747 struct attribute_set_obj
{
748 struct attribute_set s
;
750 } __attribute__((packed
));
752 static struct attribute_set
*create_attr_set(unsigned int max_members
,
755 struct attribute_set_obj
*sobj
;
757 if (max_members
== 0)
760 /* Allocates space for implicit NULL at the end too */
761 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
762 max_members
* sizeof(struct attribute
*),
766 sobj
->s
.max_members
= max_members
;
767 sobj
->s
.group
.attrs
= &sobj
->a
;
768 sobj
->s
.group
.name
= name
;
773 #define destroy_attr_set(_set) \
776 /* not multi-threaded safe, use it in a single thread per set */
777 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
782 if (s
->members
>= s
->max_members
)
785 s
->group
.attrs
[s
->members
] = attr
;
791 static int add_many_to_attr_set(struct attribute_set
*s
,
792 struct attribute
**attr
,
797 for (i
= 0; i
< count
; i
++) {
798 res
= add_to_attr_set(s
, attr
[i
]);
806 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
808 sysfs_remove_group(kobj
, &s
->group
);
812 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
813 sysfs_create_group(_kobj, &_attr_set->group)
815 static int parse_strtoul(const char *buf
,
816 unsigned long max
, unsigned long *value
)
820 while (*buf
&& isspace(*buf
))
822 *value
= simple_strtoul(buf
, &endp
, 0);
823 while (*endp
&& isspace(*endp
))
825 if (*endp
|| *value
> max
)
831 static int __init
tpacpi_query_bcl_levels(acpi_handle handle
)
833 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
834 union acpi_object
*obj
;
837 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
838 obj
= (union acpi_object
*)buffer
.pointer
;
839 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
840 printk(TPACPI_ERR
"Unknown _BCL data, "
841 "please report this to %s\n", TPACPI_MAIL
);
844 rc
= obj
->package
.count
;
850 kfree(buffer
.pointer
);
854 static acpi_status __init
tpacpi_acpi_walk_find_bcl(acpi_handle handle
,
855 u32 lvl
, void *context
, void **rv
)
857 char name
[ACPI_PATH_SEGMENT_LENGTH
];
858 struct acpi_buffer buffer
= { sizeof(name
), &name
};
860 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
861 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
863 **(int **)rv
= tpacpi_query_bcl_levels(handle
);
864 return AE_CTRL_TERMINATE
;
871 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
873 static int __init
tpacpi_check_std_acpi_brightness_support(void)
877 void *bcl_ptr
= &bcl_levels
;
880 TPACPI_ACPIHANDLE_INIT(vid
);
886 * Search for a _BCL method, and execute it. This is safe on all
887 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
888 * BIOS in ACPI backlight control mode. We do NOT have to care
889 * about calling the _BCL method in an enabled video device, any
890 * will do for our purposes.
893 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
894 tpacpi_acpi_walk_find_bcl
, NULL
,
897 if (ACPI_SUCCESS(status
) && bcl_levels
> 2) {
898 tp_features
.bright_acpimode
= 1;
899 return (bcl_levels
- 2);
905 /*************************************************************************
906 * thinkpad-acpi driver attributes
909 /* interface_version --------------------------------------------------- */
910 static ssize_t
tpacpi_driver_interface_version_show(
911 struct device_driver
*drv
,
914 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
917 static DRIVER_ATTR(interface_version
, S_IRUGO
,
918 tpacpi_driver_interface_version_show
, NULL
);
920 /* debug_level --------------------------------------------------------- */
921 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
924 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
927 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
928 const char *buf
, size_t count
)
932 if (parse_strtoul(buf
, 0xffff, &t
))
940 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
941 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
943 /* version ------------------------------------------------------------- */
944 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
947 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
948 TPACPI_DESC
, TPACPI_VERSION
);
951 static DRIVER_ATTR(version
, S_IRUGO
,
952 tpacpi_driver_version_show
, NULL
);
954 /* --------------------------------------------------------------------- */
956 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
957 &driver_attr_debug_level
, &driver_attr_version
,
958 &driver_attr_interface_version
,
961 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
967 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
968 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
975 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
979 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
980 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
983 /****************************************************************************
984 ****************************************************************************
988 ****************************************************************************
989 ****************************************************************************/
991 /*************************************************************************
992 * thinkpad-acpi init subdriver
995 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
997 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
998 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
1000 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
1001 (thinkpad_id
.bios_version_str
) ?
1002 thinkpad_id
.bios_version_str
: "unknown",
1003 (thinkpad_id
.ec_version_str
) ?
1004 thinkpad_id
.ec_version_str
: "unknown");
1006 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
1007 printk(TPACPI_INFO
"%s %s, model %s\n",
1008 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
1009 "IBM" : ((thinkpad_id
.vendor
==
1010 PCI_VENDOR_ID_LENOVO
) ?
1011 "Lenovo" : "Unknown vendor"),
1012 thinkpad_id
.model_str
,
1013 (thinkpad_id
.nummodel_str
) ?
1014 thinkpad_id
.nummodel_str
: "unknown");
1019 static int thinkpad_acpi_driver_read(char *p
)
1023 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", TPACPI_DESC
);
1024 len
+= sprintf(p
+ len
, "version:\t%s\n", TPACPI_VERSION
);
1029 static struct ibm_struct thinkpad_acpi_driver_data
= {
1031 .read
= thinkpad_acpi_driver_read
,
1034 /*************************************************************************
1038 enum { /* hot key scan codes (derived from ACPI DSDT) */
1039 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
1040 TP_ACPI_HOTKEYSCAN_FNF2
,
1041 TP_ACPI_HOTKEYSCAN_FNF3
,
1042 TP_ACPI_HOTKEYSCAN_FNF4
,
1043 TP_ACPI_HOTKEYSCAN_FNF5
,
1044 TP_ACPI_HOTKEYSCAN_FNF6
,
1045 TP_ACPI_HOTKEYSCAN_FNF7
,
1046 TP_ACPI_HOTKEYSCAN_FNF8
,
1047 TP_ACPI_HOTKEYSCAN_FNF9
,
1048 TP_ACPI_HOTKEYSCAN_FNF10
,
1049 TP_ACPI_HOTKEYSCAN_FNF11
,
1050 TP_ACPI_HOTKEYSCAN_FNF12
,
1051 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
1052 TP_ACPI_HOTKEYSCAN_FNINSERT
,
1053 TP_ACPI_HOTKEYSCAN_FNDELETE
,
1054 TP_ACPI_HOTKEYSCAN_FNHOME
,
1055 TP_ACPI_HOTKEYSCAN_FNEND
,
1056 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1057 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
1058 TP_ACPI_HOTKEYSCAN_FNSPACE
,
1059 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1060 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1061 TP_ACPI_HOTKEYSCAN_MUTE
,
1062 TP_ACPI_HOTKEYSCAN_THINKPAD
,
1065 enum { /* Keys available through NVRAM polling */
1066 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
1067 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
1070 enum { /* Positions of some of the keys in hotkey masks */
1071 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
1072 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
1073 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
1074 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
1075 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
1076 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1077 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
1078 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1079 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1080 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
1081 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
1084 enum { /* NVRAM to ACPI HKEY group map */
1085 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
1086 TP_ACPI_HKEY_ZOOM_MASK
|
1087 TP_ACPI_HKEY_DISPSWTCH_MASK
|
1088 TP_ACPI_HKEY_HIBERNATE_MASK
,
1089 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
1090 TP_ACPI_HKEY_BRGHTDWN_MASK
,
1091 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
1092 TP_ACPI_HKEY_VOLDWN_MASK
|
1093 TP_ACPI_HKEY_MUTE_MASK
,
1096 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1097 struct tp_nvram_state
{
1098 u16 thinkpad_toggle
:1;
1100 u16 display_toggle
:1;
1101 u16 thinklight_toggle
:1;
1102 u16 hibernate_toggle
:1;
1103 u16 displayexp_toggle
:1;
1104 u16 display_state
:1;
1105 u16 brightness_toggle
:1;
1106 u16 volume_toggle
:1;
1109 u8 brightness_level
;
1113 static struct task_struct
*tpacpi_hotkey_task
;
1114 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
1115 static int hotkey_poll_freq
= 10; /* Hz */
1116 static struct mutex hotkey_thread_mutex
;
1117 static struct mutex hotkey_thread_data_mutex
;
1118 static unsigned int hotkey_config_change
;
1120 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1122 #define hotkey_source_mask 0U
1124 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1126 static struct mutex hotkey_mutex
;
1128 static enum { /* Reasons for waking up */
1129 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
1130 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
1131 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
1132 } hotkey_wakeup_reason
;
1134 static int hotkey_autosleep_ack
;
1136 static int hotkey_orig_status
;
1137 static u32 hotkey_orig_mask
;
1138 static u32 hotkey_all_mask
;
1139 static u32 hotkey_reserved_mask
;
1140 static u32 hotkey_mask
;
1142 static unsigned int hotkey_report_mode
;
1144 static u16
*hotkey_keycode_map
;
1146 static struct attribute_set
*hotkey_dev_attributes
;
1148 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1149 #define HOTKEY_CONFIG_CRITICAL_START \
1151 mutex_lock(&hotkey_thread_data_mutex); \
1152 hotkey_config_change++; \
1154 #define HOTKEY_CONFIG_CRITICAL_END \
1155 mutex_unlock(&hotkey_thread_data_mutex);
1157 #define HOTKEY_CONFIG_CRITICAL_START
1158 #define HOTKEY_CONFIG_CRITICAL_END
1159 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1161 /* HKEY.MHKG() return bits */
1162 #define TP_HOTKEY_TABLET_MASK (1 << 3)
1164 static int hotkey_get_wlsw(int *status
)
1166 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
1171 static int hotkey_get_tablet_mode(int *status
)
1175 if (!acpi_evalf(hkey_handle
, &s
, "MHKG", "d"))
1178 *status
= ((s
& TP_HOTKEY_TABLET_MASK
) != 0);
1183 * Call with hotkey_mutex held
1185 static int hotkey_mask_get(void)
1189 if (tp_features
.hotkey_mask
) {
1190 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
1193 hotkey_mask
= m
| (hotkey_source_mask
& hotkey_mask
);
1199 * Call with hotkey_mutex held
1201 static int hotkey_mask_set(u32 mask
)
1206 if (tp_features
.hotkey_mask
) {
1207 if (!tp_warned
.hotkey_mask_ff
&&
1208 (mask
== 0xffff || mask
== 0xffffff ||
1209 mask
== 0xffffffff)) {
1210 tp_warned
.hotkey_mask_ff
= 1;
1211 printk(TPACPI_NOTICE
1212 "setting the hotkey mask to 0x%08x is likely "
1213 "not the best way to go about it\n", mask
);
1214 printk(TPACPI_NOTICE
1215 "please consider using the driver defaults, "
1216 "and refer to up-to-date thinkpad-acpi "
1220 HOTKEY_CONFIG_CRITICAL_START
1221 for (i
= 0; i
< 32; i
++) {
1223 /* enable in firmware mask only keys not in NVRAM
1224 * mode, but enable the key in the cached hotkey_mask
1225 * regardless of mode, or the key will end up
1226 * disabled by hotkey_mask_get() */
1227 if (!acpi_evalf(hkey_handle
,
1228 NULL
, "MHKM", "vdd", i
+ 1,
1229 !!((mask
& ~hotkey_source_mask
) & m
))) {
1233 hotkey_mask
= (hotkey_mask
& ~m
) | (mask
& m
);
1236 HOTKEY_CONFIG_CRITICAL_END
1238 /* hotkey_mask_get must be called unconditionally below */
1239 if (!hotkey_mask_get() && !rc
&&
1240 (hotkey_mask
& ~hotkey_source_mask
) !=
1241 (mask
& ~hotkey_source_mask
)) {
1242 printk(TPACPI_NOTICE
1243 "requested hot key mask 0x%08x, but "
1244 "firmware forced it to 0x%08x\n",
1248 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1249 HOTKEY_CONFIG_CRITICAL_START
1250 hotkey_mask
= mask
& hotkey_source_mask
;
1251 HOTKEY_CONFIG_CRITICAL_END
1253 if (hotkey_mask
!= mask
) {
1254 printk(TPACPI_NOTICE
1255 "requested hot key mask 0x%08x, "
1256 "forced to 0x%08x (NVRAM poll mask is "
1257 "0x%08x): no firmware mask support\n",
1258 mask
, hotkey_mask
, hotkey_source_mask
);
1263 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1269 static int hotkey_status_get(int *status
)
1271 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1277 static int hotkey_status_set(int status
)
1279 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
1285 static void tpacpi_input_send_radiosw(void)
1289 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
1290 mutex_lock(&tpacpi_inputdev_send_mutex
);
1292 input_report_switch(tpacpi_inputdev
,
1294 input_sync(tpacpi_inputdev
);
1296 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1300 static void tpacpi_input_send_tabletsw(void)
1304 if (tp_features
.hotkey_tablet
&&
1305 !hotkey_get_tablet_mode(&state
)) {
1306 mutex_lock(&tpacpi_inputdev_send_mutex
);
1308 input_report_switch(tpacpi_inputdev
,
1309 SW_TABLET_MODE
, !!state
);
1310 input_sync(tpacpi_inputdev
);
1312 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1316 static void tpacpi_input_send_key(unsigned int scancode
)
1318 unsigned int keycode
;
1320 keycode
= hotkey_keycode_map
[scancode
];
1322 if (keycode
!= KEY_RESERVED
) {
1323 mutex_lock(&tpacpi_inputdev_send_mutex
);
1325 input_report_key(tpacpi_inputdev
, keycode
, 1);
1326 if (keycode
== KEY_UNKNOWN
)
1327 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1329 input_sync(tpacpi_inputdev
);
1331 input_report_key(tpacpi_inputdev
, keycode
, 0);
1332 if (keycode
== KEY_UNKNOWN
)
1333 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1335 input_sync(tpacpi_inputdev
);
1337 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1341 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1342 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
1344 static void tpacpi_hotkey_send_key(unsigned int scancode
)
1346 tpacpi_input_send_key(scancode
);
1347 if (hotkey_report_mode
< 2) {
1348 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
1349 0x80, 0x1001 + scancode
);
1353 static void hotkey_read_nvram(struct tp_nvram_state
*n
, u32 m
)
1357 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
1358 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
1359 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
1360 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
1361 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
1362 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
1364 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
1365 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
1366 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
1368 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
1369 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
1370 n
->displayexp_toggle
=
1371 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
1373 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
1374 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
1375 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
1376 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
1377 n
->brightness_toggle
=
1378 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
1380 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
1381 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
1382 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
1383 >> TP_NVRAM_POS_LEVEL_VOLUME
;
1384 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
1385 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
1389 #define TPACPI_COMPARE_KEY(__scancode, __member) \
1391 if ((mask & (1 << __scancode)) && \
1392 oldn->__member != newn->__member) \
1393 tpacpi_hotkey_send_key(__scancode); \
1396 #define TPACPI_MAY_SEND_KEY(__scancode) \
1397 do { if (mask & (1 << __scancode)) \
1398 tpacpi_hotkey_send_key(__scancode); } while (0)
1400 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
1401 struct tp_nvram_state
*newn
,
1404 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
1405 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
1406 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
1407 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
1409 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
1411 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
1414 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
1415 if (oldn
->mute
!= newn
->mute
) {
1416 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1418 if (oldn
->volume_level
> newn
->volume_level
) {
1419 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1420 } else if (oldn
->volume_level
< newn
->volume_level
) {
1421 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1422 } else if (oldn
->mute
== newn
->mute
) {
1423 /* repeated key presses that didn't change state */
1425 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1426 } else if (newn
->volume_level
!= 0) {
1427 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1429 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1434 /* handle brightness */
1435 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
1436 if (oldn
->brightness_level
< newn
->brightness_level
) {
1437 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1438 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
1439 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1441 /* repeated key presses that didn't change state */
1442 if (newn
->brightness_level
!= 0) {
1443 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1445 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1451 #undef TPACPI_COMPARE_KEY
1452 #undef TPACPI_MAY_SEND_KEY
1454 static int hotkey_kthread(void *data
)
1456 struct tp_nvram_state s
[2];
1458 unsigned int si
, so
;
1460 unsigned int change_detector
, must_reset
;
1462 mutex_lock(&hotkey_thread_mutex
);
1464 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
1473 /* Initial state for compares */
1474 mutex_lock(&hotkey_thread_data_mutex
);
1475 change_detector
= hotkey_config_change
;
1476 mask
= hotkey_source_mask
& hotkey_mask
;
1477 mutex_unlock(&hotkey_thread_data_mutex
);
1478 hotkey_read_nvram(&s
[so
], mask
);
1480 while (!kthread_should_stop() && hotkey_poll_freq
) {
1482 t
= 1000/hotkey_poll_freq
;
1483 t
= msleep_interruptible(t
);
1484 if (unlikely(kthread_should_stop()))
1486 must_reset
= try_to_freeze();
1487 if (t
> 0 && !must_reset
)
1490 mutex_lock(&hotkey_thread_data_mutex
);
1491 if (must_reset
|| hotkey_config_change
!= change_detector
) {
1492 /* forget old state on thaw or config change */
1495 change_detector
= hotkey_config_change
;
1497 mask
= hotkey_source_mask
& hotkey_mask
;
1498 mutex_unlock(&hotkey_thread_data_mutex
);
1501 hotkey_read_nvram(&s
[si
], mask
);
1502 if (likely(si
!= so
)) {
1503 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
1513 mutex_unlock(&hotkey_thread_mutex
);
1517 static void hotkey_poll_stop_sync(void)
1519 if (tpacpi_hotkey_task
) {
1520 if (frozen(tpacpi_hotkey_task
) ||
1521 freezing(tpacpi_hotkey_task
))
1522 thaw_process(tpacpi_hotkey_task
);
1524 kthread_stop(tpacpi_hotkey_task
);
1525 tpacpi_hotkey_task
= NULL
;
1526 mutex_lock(&hotkey_thread_mutex
);
1527 /* at this point, the thread did exit */
1528 mutex_unlock(&hotkey_thread_mutex
);
1532 /* call with hotkey_mutex held */
1533 static void hotkey_poll_setup(int may_warn
)
1535 if ((hotkey_source_mask
& hotkey_mask
) != 0 &&
1536 hotkey_poll_freq
> 0 &&
1537 (tpacpi_inputdev
->users
> 0 || hotkey_report_mode
< 2)) {
1538 if (!tpacpi_hotkey_task
) {
1539 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
1540 NULL
, TPACPI_NVRAM_KTHREAD_NAME
);
1541 if (IS_ERR(tpacpi_hotkey_task
)) {
1542 tpacpi_hotkey_task
= NULL
;
1544 "could not create kernel thread "
1545 "for hotkey polling\n");
1549 hotkey_poll_stop_sync();
1551 hotkey_source_mask
!= 0 && hotkey_poll_freq
== 0) {
1552 printk(TPACPI_NOTICE
1553 "hot keys 0x%08x require polling, "
1554 "which is currently disabled\n",
1555 hotkey_source_mask
);
1560 static void hotkey_poll_setup_safe(int may_warn
)
1562 mutex_lock(&hotkey_mutex
);
1563 hotkey_poll_setup(may_warn
);
1564 mutex_unlock(&hotkey_mutex
);
1567 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1569 static void hotkey_poll_setup_safe(int __unused
)
1573 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1575 static int hotkey_inputdev_open(struct input_dev
*dev
)
1577 switch (tpacpi_lifecycle
) {
1578 case TPACPI_LIFE_INIT
:
1580 * hotkey_init will call hotkey_poll_setup_safe
1581 * at the appropriate moment
1584 case TPACPI_LIFE_EXITING
:
1586 case TPACPI_LIFE_RUNNING
:
1587 hotkey_poll_setup_safe(0);
1591 /* Should only happen if tpacpi_lifecycle is corrupt */
1596 static void hotkey_inputdev_close(struct input_dev
*dev
)
1598 /* disable hotkey polling when possible */
1599 if (tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
)
1600 hotkey_poll_setup_safe(0);
1603 /* sysfs hotkey enable ------------------------------------------------- */
1604 static ssize_t
hotkey_enable_show(struct device
*dev
,
1605 struct device_attribute
*attr
,
1610 res
= hotkey_status_get(&status
);
1614 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
1617 static ssize_t
hotkey_enable_store(struct device
*dev
,
1618 struct device_attribute
*attr
,
1619 const char *buf
, size_t count
)
1624 if (parse_strtoul(buf
, 1, &t
))
1627 res
= hotkey_status_set(t
);
1629 return (res
) ? res
: count
;
1632 static struct device_attribute dev_attr_hotkey_enable
=
1633 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
1634 hotkey_enable_show
, hotkey_enable_store
);
1636 /* sysfs hotkey mask --------------------------------------------------- */
1637 static ssize_t
hotkey_mask_show(struct device
*dev
,
1638 struct device_attribute
*attr
,
1643 if (mutex_lock_interruptible(&hotkey_mutex
))
1644 return -ERESTARTSYS
;
1645 res
= hotkey_mask_get();
1646 mutex_unlock(&hotkey_mutex
);
1649 res
: snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_mask
);
1652 static ssize_t
hotkey_mask_store(struct device
*dev
,
1653 struct device_attribute
*attr
,
1654 const char *buf
, size_t count
)
1659 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
1662 if (mutex_lock_interruptible(&hotkey_mutex
))
1663 return -ERESTARTSYS
;
1665 res
= hotkey_mask_set(t
);
1667 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1668 hotkey_poll_setup(1);
1671 mutex_unlock(&hotkey_mutex
);
1673 return (res
) ? res
: count
;
1676 static struct device_attribute dev_attr_hotkey_mask
=
1677 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
1678 hotkey_mask_show
, hotkey_mask_store
);
1680 /* sysfs hotkey bios_enabled ------------------------------------------- */
1681 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
1682 struct device_attribute
*attr
,
1685 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
1688 static struct device_attribute dev_attr_hotkey_bios_enabled
=
1689 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
1691 /* sysfs hotkey bios_mask ---------------------------------------------- */
1692 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
1693 struct device_attribute
*attr
,
1696 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
1699 static struct device_attribute dev_attr_hotkey_bios_mask
=
1700 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
1702 /* sysfs hotkey all_mask ----------------------------------------------- */
1703 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
1704 struct device_attribute
*attr
,
1707 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1708 hotkey_all_mask
| hotkey_source_mask
);
1711 static struct device_attribute dev_attr_hotkey_all_mask
=
1712 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
1714 /* sysfs hotkey recommended_mask --------------------------------------- */
1715 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
1716 struct device_attribute
*attr
,
1719 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1720 (hotkey_all_mask
| hotkey_source_mask
)
1721 & ~hotkey_reserved_mask
);
1724 static struct device_attribute dev_attr_hotkey_recommended_mask
=
1725 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
1726 hotkey_recommended_mask_show
, NULL
);
1728 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1730 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
1731 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
1732 struct device_attribute
*attr
,
1735 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
1738 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
1739 struct device_attribute
*attr
,
1740 const char *buf
, size_t count
)
1744 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
1745 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
1748 if (mutex_lock_interruptible(&hotkey_mutex
))
1749 return -ERESTARTSYS
;
1751 HOTKEY_CONFIG_CRITICAL_START
1752 hotkey_source_mask
= t
;
1753 HOTKEY_CONFIG_CRITICAL_END
1755 hotkey_poll_setup(1);
1757 mutex_unlock(&hotkey_mutex
);
1762 static struct device_attribute dev_attr_hotkey_source_mask
=
1763 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
1764 hotkey_source_mask_show
, hotkey_source_mask_store
);
1766 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
1767 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
1768 struct device_attribute
*attr
,
1771 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
1774 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
1775 struct device_attribute
*attr
,
1776 const char *buf
, size_t count
)
1780 if (parse_strtoul(buf
, 25, &t
))
1783 if (mutex_lock_interruptible(&hotkey_mutex
))
1784 return -ERESTARTSYS
;
1786 hotkey_poll_freq
= t
;
1788 hotkey_poll_setup(1);
1789 mutex_unlock(&hotkey_mutex
);
1794 static struct device_attribute dev_attr_hotkey_poll_freq
=
1795 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
1796 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
1798 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1800 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
1801 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
1802 struct device_attribute
*attr
,
1806 res
= hotkey_get_wlsw(&s
);
1810 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
1813 static struct device_attribute dev_attr_hotkey_radio_sw
=
1814 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
1816 static void hotkey_radio_sw_notify_change(void)
1818 if (tp_features
.hotkey_wlsw
)
1819 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
1823 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
1824 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
1825 struct device_attribute
*attr
,
1829 res
= hotkey_get_tablet_mode(&s
);
1833 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
1836 static struct device_attribute dev_attr_hotkey_tablet_mode
=
1837 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
1839 static void hotkey_tablet_mode_notify_change(void)
1841 if (tp_features
.hotkey_tablet
)
1842 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
1843 "hotkey_tablet_mode");
1846 /* sysfs hotkey report_mode -------------------------------------------- */
1847 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
1848 struct device_attribute
*attr
,
1851 return snprintf(buf
, PAGE_SIZE
, "%d\n",
1852 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
1855 static struct device_attribute dev_attr_hotkey_report_mode
=
1856 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
1858 /* sysfs wakeup reason (pollable) -------------------------------------- */
1859 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
1860 struct device_attribute
*attr
,
1863 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
1866 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
1867 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
1869 static void hotkey_wakeup_reason_notify_change(void)
1871 if (tp_features
.hotkey_mask
)
1872 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
1876 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
1877 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
1878 struct device_attribute
*attr
,
1881 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
1884 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
1885 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
1886 hotkey_wakeup_hotunplug_complete_show
, NULL
);
1888 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
1890 if (tp_features
.hotkey_mask
)
1891 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
1892 "wakeup_hotunplug_complete");
1895 /* --------------------------------------------------------------------- */
1897 static struct attribute
*hotkey_attributes
[] __initdata
= {
1898 &dev_attr_hotkey_enable
.attr
,
1899 &dev_attr_hotkey_bios_enabled
.attr
,
1900 &dev_attr_hotkey_report_mode
.attr
,
1901 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1902 &dev_attr_hotkey_mask
.attr
,
1903 &dev_attr_hotkey_all_mask
.attr
,
1904 &dev_attr_hotkey_recommended_mask
.attr
,
1905 &dev_attr_hotkey_source_mask
.attr
,
1906 &dev_attr_hotkey_poll_freq
.attr
,
1910 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
1911 &dev_attr_hotkey_bios_mask
.attr
,
1912 #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1913 &dev_attr_hotkey_mask
.attr
,
1914 &dev_attr_hotkey_all_mask
.attr
,
1915 &dev_attr_hotkey_recommended_mask
.attr
,
1917 &dev_attr_hotkey_wakeup_reason
.attr
,
1918 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
1921 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
1923 /* Requirements for changing the default keymaps:
1925 * 1. Many of the keys are mapped to KEY_RESERVED for very
1926 * good reasons. Do not change them unless you have deep
1927 * knowledge on the IBM and Lenovo ThinkPad firmware for
1928 * the various ThinkPad models. The driver behaves
1929 * differently for KEY_RESERVED: such keys have their
1930 * hot key mask *unset* in mask_recommended, and also
1931 * in the initial hot key mask programmed into the
1932 * firmware at driver load time, which means the firm-
1933 * ware may react very differently if you change them to
1936 * 2. You must be subscribed to the linux-thinkpad and
1937 * ibm-acpi-devel mailing lists, and you should read the
1938 * list archives since 2007 if you want to change the
1939 * keymaps. This requirement exists so that you will
1940 * know the past history of problems with the thinkpad-
1941 * acpi driver keymaps, and also that you will be
1942 * listening to any bug reports;
1944 * 3. Do not send thinkpad-acpi specific patches directly to
1945 * for merging, *ever*. Send them to the linux-acpi
1946 * mailinglist for comments. Merging is to be done only
1947 * through acpi-test and the ACPI maintainer.
1949 * If the above is too much to ask, don't change the keymap.
1950 * Ask the thinkpad-acpi maintainer to do it, instead.
1952 static u16 ibm_keycode_map
[] __initdata
= {
1953 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
1954 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
1955 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
1956 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
1958 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
1959 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
1960 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
1961 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
1963 /* brightness: firmware always reacts to them, unless
1964 * X.org did some tricks in the radeon BIOS scratch
1965 * registers of *some* models */
1966 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
1967 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
1969 /* Thinklight: firmware always react to it */
1970 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
1972 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
1973 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
1975 /* Volume: firmware always react to it and reprograms
1976 * the built-in *extra* mixer. Never map it to control
1977 * another mixer by default. */
1978 KEY_RESERVED
, /* 0x14: VOLUME UP */
1979 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1980 KEY_RESERVED
, /* 0x16: MUTE */
1982 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1984 /* (assignments unknown, please report if found) */
1985 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1986 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1988 static u16 lenovo_keycode_map
[] __initdata
= {
1989 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
1990 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
1991 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
1992 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
1994 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
1995 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
1996 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
1997 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
1999 /* These either have to go through ACPI video, or
2000 * act like in the IBM ThinkPads, so don't ever
2001 * enable them by default */
2002 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
2003 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
2005 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2007 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2008 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2010 /* Volume: z60/z61, T60 (BIOS version?): firmware always
2011 * react to it and reprograms the built-in *extra* mixer.
2012 * Never map it to control another mixer by default.
2014 * T60?, T61, R60?, R61: firmware and EC tries to send
2015 * these over the regular keyboard, so these are no-ops,
2016 * but there are still weird bugs re. MUTE, so do not
2017 * change unless you get test reports from all Lenovo
2018 * models. May cause the BIOS to interfere with the
2021 KEY_RESERVED
, /* 0x14: VOLUME UP */
2022 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2023 KEY_RESERVED
, /* 0x16: MUTE */
2025 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2027 /* (assignments unknown, please report if found) */
2028 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2029 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2032 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
2033 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
2034 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
2040 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
2042 BUG_ON(!tpacpi_inputdev
);
2043 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
2044 tpacpi_inputdev
->close
!= NULL
);
2046 TPACPI_ACPIHANDLE_INIT(hkey
);
2047 mutex_init(&hotkey_mutex
);
2049 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2050 mutex_init(&hotkey_thread_mutex
);
2051 mutex_init(&hotkey_thread_data_mutex
);
2054 /* hotkey not supported on 570 */
2055 tp_features
.hotkey
= hkey_handle
!= NULL
;
2057 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
2058 str_supported(tp_features
.hotkey
));
2060 if (tp_features
.hotkey
) {
2061 hotkey_dev_attributes
= create_attr_set(13, NULL
);
2062 if (!hotkey_dev_attributes
)
2064 res
= add_many_to_attr_set(hotkey_dev_attributes
,
2066 ARRAY_SIZE(hotkey_attributes
));
2070 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2071 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
2072 for HKEY interface version 0x100 */
2073 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
2074 if ((hkeyv
>> 8) != 1) {
2075 printk(TPACPI_ERR
"unknown version of the "
2076 "HKEY interface: 0x%x\n", hkeyv
);
2077 printk(TPACPI_ERR
"please report this to %s\n",
2081 * MHKV 0x100 in A31, R40, R40e,
2082 * T4x, X31, and later
2084 tp_features
.hotkey_mask
= 1;
2088 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
2089 str_supported(tp_features
.hotkey_mask
));
2091 if (tp_features
.hotkey_mask
) {
2092 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
2095 "missing MHKA handler, "
2096 "please report this to %s\n",
2098 /* FN+F12, FN+F4, FN+F3 */
2099 hotkey_all_mask
= 0x080cU
;
2103 /* hotkey_source_mask *must* be zero for
2104 * the first hotkey_mask_get */
2105 res
= hotkey_status_get(&hotkey_orig_status
);
2106 if (!res
&& tp_features
.hotkey_mask
) {
2107 res
= hotkey_mask_get();
2108 hotkey_orig_mask
= hotkey_mask
;
2110 res
= add_many_to_attr_set(
2111 hotkey_dev_attributes
,
2112 hotkey_mask_attributes
,
2113 ARRAY_SIZE(hotkey_mask_attributes
));
2117 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2118 if (tp_features
.hotkey_mask
) {
2119 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
2122 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
;
2125 vdbg_printk(TPACPI_DBG_INIT
,
2126 "hotkey source mask 0x%08x, polling freq %d\n",
2127 hotkey_source_mask
, hotkey_poll_freq
);
2130 /* Not all thinkpads have a hardware radio switch */
2131 if (!res
&& acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
2132 tp_features
.hotkey_wlsw
= 1;
2134 "radio switch found; radios are %s\n",
2135 enabled(status
, 0));
2136 res
= add_to_attr_set(hotkey_dev_attributes
,
2137 &dev_attr_hotkey_radio_sw
.attr
);
2140 /* For X41t, X60t, X61t Tablets... */
2141 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
2142 tp_features
.hotkey_tablet
= 1;
2144 "possible tablet mode switch found; "
2145 "ThinkPad in %s mode\n",
2146 (status
& TP_HOTKEY_TABLET_MASK
)?
2147 "tablet" : "laptop");
2148 res
= add_to_attr_set(hotkey_dev_attributes
,
2149 &dev_attr_hotkey_tablet_mode
.attr
);
2153 res
= register_attr_set_with_sysfs(
2154 hotkey_dev_attributes
,
2155 &tpacpi_pdev
->dev
.kobj
);
2159 /* Set up key map */
2161 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
2163 if (!hotkey_keycode_map
) {
2165 "failed to allocate memory for key map\n");
2169 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
2170 dbg_printk(TPACPI_DBG_INIT
,
2171 "using Lenovo default hot key map\n");
2172 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
2173 TPACPI_HOTKEY_MAP_SIZE
);
2175 dbg_printk(TPACPI_DBG_INIT
,
2176 "using IBM default hot key map\n");
2177 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
2178 TPACPI_HOTKEY_MAP_SIZE
);
2181 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
2182 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
2183 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
2184 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
2185 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
2186 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
2187 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
2188 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
2189 set_bit(hotkey_keycode_map
[i
],
2190 tpacpi_inputdev
->keybit
);
2192 if (i
< sizeof(hotkey_reserved_mask
)*8)
2193 hotkey_reserved_mask
|= 1 << i
;
2197 if (tp_features
.hotkey_wlsw
) {
2198 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
2199 set_bit(SW_RADIO
, tpacpi_inputdev
->swbit
);
2201 if (tp_features
.hotkey_tablet
) {
2202 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
2203 set_bit(SW_TABLET_MODE
, tpacpi_inputdev
->swbit
);
2206 /* Do not issue duplicate brightness change events to
2208 if (!tp_features
.bright_acpimode
)
2209 /* update bright_acpimode... */
2210 tpacpi_check_std_acpi_brightness_support();
2212 if (tp_features
.bright_acpimode
) {
2214 "This ThinkPad has standard ACPI backlight "
2215 "brightness control, supported by the ACPI "
2217 printk(TPACPI_NOTICE
2218 "Disabling thinkpad-acpi brightness events "
2221 /* The hotkey_reserved_mask change below is not
2222 * necessary while the keys are at KEY_RESERVED in the
2223 * default map, but better safe than sorry, leave it
2224 * here as a marker of what we have to do, especially
2225 * when we finally become able to set this at runtime
2226 * on response to X.org requests */
2227 hotkey_reserved_mask
|=
2228 (1 << TP_ACPI_HOTKEYSCAN_FNHOME
)
2229 | (1 << TP_ACPI_HOTKEYSCAN_FNEND
);
2232 dbg_printk(TPACPI_DBG_INIT
,
2233 "enabling hot key handling\n");
2234 res
= hotkey_status_set(1);
2237 res
= hotkey_mask_set(((hotkey_all_mask
| hotkey_source_mask
)
2238 & ~hotkey_reserved_mask
)
2239 | hotkey_orig_mask
);
2240 if (res
< 0 && res
!= -ENXIO
)
2243 dbg_printk(TPACPI_DBG_INIT
,
2244 "legacy hot key reporting over procfs %s\n",
2245 (hotkey_report_mode
< 2) ?
2246 "enabled" : "disabled");
2248 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
2249 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
2251 hotkey_poll_setup_safe(1);
2252 tpacpi_input_send_radiosw();
2253 tpacpi_input_send_tabletsw();
2256 return (tp_features
.hotkey
)? 0 : 1;
2259 static void hotkey_exit(void)
2261 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2262 hotkey_poll_stop_sync();
2265 if (tp_features
.hotkey
) {
2266 dbg_printk(TPACPI_DBG_EXIT
,
2267 "restoring original hot key mask\n");
2268 /* no short-circuit boolean operator below! */
2269 if ((hotkey_mask_set(hotkey_orig_mask
) |
2270 hotkey_status_set(hotkey_orig_status
)) != 0)
2272 "failed to restore hot key mask "
2273 "to BIOS defaults\n");
2276 if (hotkey_dev_attributes
) {
2277 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2278 hotkey_dev_attributes
= NULL
;
2282 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
2285 unsigned int scancode
;
2290 if (event
!= 0x80) {
2292 "unknown HKEY notification event %d\n", event
);
2293 /* forward it to userspace, maybe it knows how to handle it */
2294 acpi_bus_generate_netlink_event(
2295 ibm
->acpi
->device
->pnp
.device_class
,
2296 ibm
->acpi
->device
->dev
.bus_id
,
2302 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
2303 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
2316 switch (hkey
>> 12) {
2318 /* 0x1000-0x1FFF: key presses */
2319 scancode
= hkey
& 0xfff;
2320 if (scancode
> 0 && scancode
< 0x21) {
2322 if (!(hotkey_source_mask
& (1 << scancode
))) {
2323 tpacpi_input_send_key(scancode
);
2335 case 0x2304: /* suspend, undock */
2336 case 0x2404: /* hibernation, undock */
2337 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
2340 case 0x2305: /* suspend, bay eject */
2341 case 0x2405: /* hibernation, bay eject */
2342 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
2348 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
2350 "woke up due to a hot-unplug "
2352 hotkey_wakeup_reason_notify_change();
2356 /* bay-related wakeups */
2357 if (hkey
== 0x3003) {
2358 hotkey_autosleep_ack
= 1;
2361 hotkey_wakeup_hotunplug_complete_notify_change();
2367 /* dock-related wakeups */
2368 if (hkey
== 0x4003) {
2369 hotkey_autosleep_ack
= 1;
2372 hotkey_wakeup_hotunplug_complete_notify_change();
2378 /* 0x5000-0x5FFF: human interface helpers */
2380 case 0x5010: /* Lenovo new BIOS: brightness changed */
2381 case 0x500b: /* X61t: tablet pen inserted into bay */
2382 case 0x500c: /* X61t: tablet pen removed from bay */
2384 case 0x5009: /* X41t-X61t: swivel up (tablet mode) */
2385 case 0x500a: /* X41t-X61t: swivel down (normal mode) */
2386 tpacpi_input_send_tabletsw();
2387 hotkey_tablet_mode_notify_change();
2392 /* LID switch events. Do not propagate */
2400 /* 0x7000-0x7FFF: misc */
2401 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
2402 tpacpi_input_send_radiosw();
2403 hotkey_radio_sw_notify_change();
2407 /* fallthrough to default */
2412 printk(TPACPI_NOTICE
2413 "unhandled HKEY event 0x%04x\n", hkey
);
2417 if (!ignore_acpi_ev
&&
2418 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
2419 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
2423 /* netlink events */
2424 if (!ignore_acpi_ev
&& send_acpi_ev
) {
2425 acpi_bus_generate_netlink_event(
2426 ibm
->acpi
->device
->pnp
.device_class
,
2427 ibm
->acpi
->device
->dev
.bus_id
,
2433 static void hotkey_suspend(pm_message_t state
)
2435 /* Do these on suspend, we get the events on early resume! */
2436 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
2437 hotkey_autosleep_ack
= 0;
2440 static void hotkey_resume(void)
2442 if (hotkey_mask_get())
2444 "error while trying to read hot key mask "
2446 tpacpi_input_send_radiosw();
2447 hotkey_radio_sw_notify_change();
2448 hotkey_tablet_mode_notify_change();
2449 hotkey_wakeup_reason_notify_change();
2450 hotkey_wakeup_hotunplug_complete_notify_change();
2451 hotkey_poll_setup_safe(0);
2454 /* procfs -------------------------------------------------------------- */
2455 static int hotkey_read(char *p
)
2460 if (!tp_features
.hotkey
) {
2461 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2465 if (mutex_lock_interruptible(&hotkey_mutex
))
2466 return -ERESTARTSYS
;
2467 res
= hotkey_status_get(&status
);
2469 res
= hotkey_mask_get();
2470 mutex_unlock(&hotkey_mutex
);
2474 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
2475 if (tp_features
.hotkey_mask
) {
2476 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", hotkey_mask
);
2477 len
+= sprintf(p
+ len
,
2478 "commands:\tenable, disable, reset, <mask>\n");
2480 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
2481 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
2487 static int hotkey_write(char *buf
)
2493 if (!tp_features
.hotkey
)
2496 if (mutex_lock_interruptible(&hotkey_mutex
))
2497 return -ERESTARTSYS
;
2503 while ((cmd
= next_cmd(&buf
))) {
2504 if (strlencmp(cmd
, "enable") == 0) {
2506 } else if (strlencmp(cmd
, "disable") == 0) {
2508 } else if (strlencmp(cmd
, "reset") == 0) {
2509 status
= hotkey_orig_status
;
2510 mask
= hotkey_orig_mask
;
2511 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
2513 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
2521 res
= hotkey_status_set(status
);
2523 if (!res
&& mask
!= hotkey_mask
)
2524 res
= hotkey_mask_set(mask
);
2527 mutex_unlock(&hotkey_mutex
);
2531 static const struct acpi_device_id ibm_htk_device_ids
[] = {
2532 {TPACPI_ACPI_HKEY_HID
, 0},
2536 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
2537 .hid
= ibm_htk_device_ids
,
2538 .notify
= hotkey_notify
,
2539 .handle
= &hkey_handle
,
2540 .type
= ACPI_DEVICE_NOTIFY
,
2543 static struct ibm_struct hotkey_driver_data
= {
2545 .read
= hotkey_read
,
2546 .write
= hotkey_write
,
2547 .exit
= hotkey_exit
,
2548 .resume
= hotkey_resume
,
2549 .suspend
= hotkey_suspend
,
2550 .acpi
= &ibm_hotkey_acpidriver
,
2553 /*************************************************************************
2554 * Bluetooth subdriver
2558 /* ACPI GBDC/SBDC bits */
2559 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
2560 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
2561 TP_ACPI_BLUETOOTH_UNK
= 0x04, /* unknown function */
2564 static int bluetooth_get_radiosw(void);
2565 static int bluetooth_set_radiosw(int radio_on
);
2567 /* sysfs bluetooth enable ---------------------------------------------- */
2568 static ssize_t
bluetooth_enable_show(struct device
*dev
,
2569 struct device_attribute
*attr
,
2574 status
= bluetooth_get_radiosw();
2578 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
2581 static ssize_t
bluetooth_enable_store(struct device
*dev
,
2582 struct device_attribute
*attr
,
2583 const char *buf
, size_t count
)
2588 if (parse_strtoul(buf
, 1, &t
))
2591 res
= bluetooth_set_radiosw(t
);
2593 return (res
) ? res
: count
;
2596 static struct device_attribute dev_attr_bluetooth_enable
=
2597 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
2598 bluetooth_enable_show
, bluetooth_enable_store
);
2600 /* --------------------------------------------------------------------- */
2602 static struct attribute
*bluetooth_attributes
[] = {
2603 &dev_attr_bluetooth_enable
.attr
,
2607 static const struct attribute_group bluetooth_attr_group
= {
2608 .attrs
= bluetooth_attributes
,
2611 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
2616 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
2618 TPACPI_ACPIHANDLE_INIT(hkey
);
2620 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2621 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
2622 tp_features
.bluetooth
= hkey_handle
&&
2623 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
2625 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
2626 str_supported(tp_features
.bluetooth
),
2629 if (tp_features
.bluetooth
) {
2630 if (!(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
2631 /* no bluetooth hardware present in system */
2632 tp_features
.bluetooth
= 0;
2633 dbg_printk(TPACPI_DBG_INIT
,
2634 "bluetooth hardware not installed\n");
2636 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2637 &bluetooth_attr_group
);
2643 return (tp_features
.bluetooth
)? 0 : 1;
2646 static void bluetooth_exit(void)
2648 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2649 &bluetooth_attr_group
);
2652 static int bluetooth_get_radiosw(void)
2656 if (!tp_features
.bluetooth
)
2659 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
2662 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
2665 static int bluetooth_set_radiosw(int radio_on
)
2669 if (!tp_features
.bluetooth
)
2672 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
2675 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
2677 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
2678 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
2684 /* procfs -------------------------------------------------------------- */
2685 static int bluetooth_read(char *p
)
2688 int status
= bluetooth_get_radiosw();
2690 if (!tp_features
.bluetooth
)
2691 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2693 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2694 (status
)? "enabled" : "disabled");
2695 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
2701 static int bluetooth_write(char *buf
)
2705 if (!tp_features
.bluetooth
)
2708 while ((cmd
= next_cmd(&buf
))) {
2709 if (strlencmp(cmd
, "enable") == 0) {
2710 bluetooth_set_radiosw(1);
2711 } else if (strlencmp(cmd
, "disable") == 0) {
2712 bluetooth_set_radiosw(0);
2720 static struct ibm_struct bluetooth_driver_data
= {
2721 .name
= "bluetooth",
2722 .read
= bluetooth_read
,
2723 .write
= bluetooth_write
,
2724 .exit
= bluetooth_exit
,
2727 /*************************************************************************
2732 /* ACPI GWAN/SWAN bits */
2733 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
2734 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
2735 TP_ACPI_WANCARD_UNK
= 0x04, /* unknown function */
2738 static int wan_get_radiosw(void);
2739 static int wan_set_radiosw(int radio_on
);
2741 /* sysfs wan enable ---------------------------------------------------- */
2742 static ssize_t
wan_enable_show(struct device
*dev
,
2743 struct device_attribute
*attr
,
2748 status
= wan_get_radiosw();
2752 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
2755 static ssize_t
wan_enable_store(struct device
*dev
,
2756 struct device_attribute
*attr
,
2757 const char *buf
, size_t count
)
2762 if (parse_strtoul(buf
, 1, &t
))
2765 res
= wan_set_radiosw(t
);
2767 return (res
) ? res
: count
;
2770 static struct device_attribute dev_attr_wan_enable
=
2771 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
2772 wan_enable_show
, wan_enable_store
);
2774 /* --------------------------------------------------------------------- */
2776 static struct attribute
*wan_attributes
[] = {
2777 &dev_attr_wan_enable
.attr
,
2781 static const struct attribute_group wan_attr_group
= {
2782 .attrs
= wan_attributes
,
2785 static int __init
wan_init(struct ibm_init_struct
*iibm
)
2790 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
2792 TPACPI_ACPIHANDLE_INIT(hkey
);
2794 tp_features
.wan
= hkey_handle
&&
2795 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
2797 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
2798 str_supported(tp_features
.wan
),
2801 if (tp_features
.wan
) {
2802 if (!(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
2803 /* no wan hardware present in system */
2804 tp_features
.wan
= 0;
2805 dbg_printk(TPACPI_DBG_INIT
,
2806 "wan hardware not installed\n");
2808 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2815 return (tp_features
.wan
)? 0 : 1;
2818 static void wan_exit(void)
2820 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2824 static int wan_get_radiosw(void)
2828 if (!tp_features
.wan
)
2831 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
2834 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
2837 static int wan_set_radiosw(int radio_on
)
2841 if (!tp_features
.wan
)
2844 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
2847 status
|= TP_ACPI_WANCARD_RADIOSSW
;
2849 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
2850 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
2856 /* procfs -------------------------------------------------------------- */
2857 static int wan_read(char *p
)
2860 int status
= wan_get_radiosw();
2862 if (!tp_features
.wan
)
2863 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2865 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2866 (status
)? "enabled" : "disabled");
2867 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
2873 static int wan_write(char *buf
)
2877 if (!tp_features
.wan
)
2880 while ((cmd
= next_cmd(&buf
))) {
2881 if (strlencmp(cmd
, "enable") == 0) {
2883 } else if (strlencmp(cmd
, "disable") == 0) {
2892 static struct ibm_struct wan_driver_data
= {
2897 .flags
.experimental
= 1,
2900 /*************************************************************************
2904 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
2906 enum video_access_mode
{
2907 TPACPI_VIDEO_NONE
= 0,
2908 TPACPI_VIDEO_570
, /* 570 */
2909 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
2910 TPACPI_VIDEO_NEW
, /* all others */
2913 enum { /* video status flags, based on VIDEO_570 */
2914 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
2915 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
2916 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
2919 enum { /* TPACPI_VIDEO_570 constants */
2920 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
2921 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
2922 * video_status_flags */
2923 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
2924 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
2927 static enum video_access_mode video_supported
;
2928 static int video_orig_autosw
;
2930 static int video_autosw_get(void);
2931 static int video_autosw_set(int enable
);
2933 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
2935 static int __init
video_init(struct ibm_init_struct
*iibm
)
2939 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
2941 TPACPI_ACPIHANDLE_INIT(vid
);
2942 TPACPI_ACPIHANDLE_INIT(vid2
);
2944 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
2945 /* G41, assume IVGA doesn't change */
2946 vid_handle
= vid2_handle
;
2949 /* video switching not supported on R30, R31 */
2950 video_supported
= TPACPI_VIDEO_NONE
;
2951 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
2953 video_supported
= TPACPI_VIDEO_570
;
2954 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
2955 /* 600e/x, 770e, 770x */
2956 video_supported
= TPACPI_VIDEO_770
;
2959 video_supported
= TPACPI_VIDEO_NEW
;
2961 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
2962 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
2965 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
2968 static void video_exit(void)
2970 dbg_printk(TPACPI_DBG_EXIT
,
2971 "restoring original video autoswitch mode\n");
2972 if (video_autosw_set(video_orig_autosw
))
2973 printk(TPACPI_ERR
"error while trying to restore original "
2974 "video autoswitch mode\n");
2977 static int video_outputsw_get(void)
2982 switch (video_supported
) {
2983 case TPACPI_VIDEO_570
:
2984 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
2985 TP_ACPI_VIDEO_570_PHSCMD
))
2987 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
2989 case TPACPI_VIDEO_770
:
2990 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
2993 status
|= TP_ACPI_VIDEO_S_LCD
;
2994 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
2997 status
|= TP_ACPI_VIDEO_S_CRT
;
2999 case TPACPI_VIDEO_NEW
:
3000 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
3001 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
3004 status
|= TP_ACPI_VIDEO_S_CRT
;
3006 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
3007 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
3010 status
|= TP_ACPI_VIDEO_S_LCD
;
3011 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
3014 status
|= TP_ACPI_VIDEO_S_DVI
;
3023 static int video_outputsw_set(int status
)
3028 switch (video_supported
) {
3029 case TPACPI_VIDEO_570
:
3030 res
= acpi_evalf(NULL
, NULL
,
3031 "\\_SB.PHS2", "vdd",
3032 TP_ACPI_VIDEO_570_PHS2CMD
,
3033 status
| TP_ACPI_VIDEO_570_PHS2SET
);
3035 case TPACPI_VIDEO_770
:
3036 autosw
= video_autosw_get();
3040 res
= video_autosw_set(1);
3043 res
= acpi_evalf(vid_handle
, NULL
,
3044 "ASWT", "vdd", status
* 0x100, 0);
3045 if (!autosw
&& video_autosw_set(autosw
)) {
3047 "video auto-switch left enabled due to error\n");
3051 case TPACPI_VIDEO_NEW
:
3052 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
3053 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
3059 return (res
)? 0 : -EIO
;
3062 static int video_autosw_get(void)
3066 switch (video_supported
) {
3067 case TPACPI_VIDEO_570
:
3068 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
3071 case TPACPI_VIDEO_770
:
3072 case TPACPI_VIDEO_NEW
:
3073 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
3083 static int video_autosw_set(int enable
)
3085 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
3090 static int video_outputsw_cycle(void)
3092 int autosw
= video_autosw_get();
3098 switch (video_supported
) {
3099 case TPACPI_VIDEO_570
:
3100 res
= video_autosw_set(1);
3103 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
3105 case TPACPI_VIDEO_770
:
3106 case TPACPI_VIDEO_NEW
:
3107 res
= video_autosw_set(1);
3110 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
3115 if (!autosw
&& video_autosw_set(autosw
)) {
3117 "video auto-switch left enabled due to error\n");
3121 return (res
)? 0 : -EIO
;
3124 static int video_expand_toggle(void)
3126 switch (video_supported
) {
3127 case TPACPI_VIDEO_570
:
3128 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
3130 case TPACPI_VIDEO_770
:
3131 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
3133 case TPACPI_VIDEO_NEW
:
3134 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
3142 static int video_read(char *p
)
3147 if (video_supported
== TPACPI_VIDEO_NONE
) {
3148 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3152 status
= video_outputsw_get();
3156 autosw
= video_autosw_get();
3160 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3161 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
3162 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
3163 if (video_supported
== TPACPI_VIDEO_NEW
)
3164 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
3165 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
3166 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
3167 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
3168 if (video_supported
== TPACPI_VIDEO_NEW
)
3169 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
3170 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
3171 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
3176 static int video_write(char *buf
)
3179 int enable
, disable
, status
;
3182 if (video_supported
== TPACPI_VIDEO_NONE
)
3188 while ((cmd
= next_cmd(&buf
))) {
3189 if (strlencmp(cmd
, "lcd_enable") == 0) {
3190 enable
|= TP_ACPI_VIDEO_S_LCD
;
3191 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
3192 disable
|= TP_ACPI_VIDEO_S_LCD
;
3193 } else if (strlencmp(cmd
, "crt_enable") == 0) {
3194 enable
|= TP_ACPI_VIDEO_S_CRT
;
3195 } else if (strlencmp(cmd
, "crt_disable") == 0) {
3196 disable
|= TP_ACPI_VIDEO_S_CRT
;
3197 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
3198 strlencmp(cmd
, "dvi_enable") == 0) {
3199 enable
|= TP_ACPI_VIDEO_S_DVI
;
3200 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
3201 strlencmp(cmd
, "dvi_disable") == 0) {
3202 disable
|= TP_ACPI_VIDEO_S_DVI
;
3203 } else if (strlencmp(cmd
, "auto_enable") == 0) {
3204 res
= video_autosw_set(1);
3207 } else if (strlencmp(cmd
, "auto_disable") == 0) {
3208 res
= video_autosw_set(0);
3211 } else if (strlencmp(cmd
, "video_switch") == 0) {
3212 res
= video_outputsw_cycle();
3215 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
3216 res
= video_expand_toggle();
3223 if (enable
|| disable
) {
3224 status
= video_outputsw_get();
3227 res
= video_outputsw_set((status
& ~disable
) | enable
);
3235 static struct ibm_struct video_driver_data
= {
3238 .write
= video_write
,
3242 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
3244 /*************************************************************************
3245 * Light (thinklight) subdriver
3248 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
3249 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
3251 static int light_get_status(void)
3255 if (tp_features
.light_status
) {
3256 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
3264 static int light_set_status(int status
)
3268 if (tp_features
.light
) {
3270 rc
= acpi_evalf(cmos_handle
, NULL
, NULL
, "vd",
3272 TP_CMOS_THINKLIGHT_ON
:
3273 TP_CMOS_THINKLIGHT_OFF
);
3275 rc
= acpi_evalf(lght_handle
, NULL
, NULL
, "vd",
3278 return (rc
)? 0 : -EIO
;
3284 static void light_set_status_worker(struct work_struct
*work
)
3286 struct tpacpi_led_classdev
*data
=
3287 container_of(work
, struct tpacpi_led_classdev
, work
);
3289 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
3290 light_set_status((data
->new_brightness
!= LED_OFF
));
3293 static void light_sysfs_set(struct led_classdev
*led_cdev
,
3294 enum led_brightness brightness
)
3296 struct tpacpi_led_classdev
*data
=
3297 container_of(led_cdev
,
3298 struct tpacpi_led_classdev
,
3300 data
->new_brightness
= brightness
;
3301 schedule_work(&data
->work
);
3304 static enum led_brightness
light_sysfs_get(struct led_classdev
*led_cdev
)
3306 return (light_get_status() == 1)? LED_FULL
: LED_OFF
;
3309 static struct tpacpi_led_classdev tpacpi_led_thinklight
= {
3311 .name
= "tpacpi::thinklight",
3312 .brightness_set
= &light_sysfs_set
,
3313 .brightness_get
= &light_sysfs_get
,
3317 static int __init
light_init(struct ibm_init_struct
*iibm
)
3321 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
3323 TPACPI_ACPIHANDLE_INIT(ledb
);
3324 TPACPI_ACPIHANDLE_INIT(lght
);
3325 TPACPI_ACPIHANDLE_INIT(cmos
);
3326 INIT_WORK(&tpacpi_led_thinklight
.work
, light_set_status_worker
);
3328 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
3329 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
3331 if (tp_features
.light
)
3332 /* light status not supported on
3333 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
3334 tp_features
.light_status
=
3335 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
3337 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
3338 str_supported(tp_features
.light
));
3340 if (tp_features
.light
) {
3341 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
3342 &tpacpi_led_thinklight
.led_classdev
);
3346 tp_features
.light
= 0;
3347 tp_features
.light_status
= 0;
3349 rc
= (tp_features
.light
)? 0 : 1;
3354 static void light_exit(void)
3356 led_classdev_unregister(&tpacpi_led_thinklight
.led_classdev
);
3357 if (work_pending(&tpacpi_led_thinklight
.work
))
3358 flush_scheduled_work();
3361 static int light_read(char *p
)
3366 if (!tp_features
.light
) {
3367 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3368 } else if (!tp_features
.light_status
) {
3369 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
3370 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
3372 status
= light_get_status();
3375 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
3376 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
3382 static int light_write(char *buf
)
3387 if (!tp_features
.light
)
3390 while ((cmd
= next_cmd(&buf
))) {
3391 if (strlencmp(cmd
, "on") == 0) {
3393 } else if (strlencmp(cmd
, "off") == 0) {
3399 return light_set_status(newstatus
);
3402 static struct ibm_struct light_driver_data
= {
3405 .write
= light_write
,
3409 /*************************************************************************
3413 #ifdef CONFIG_THINKPAD_ACPI_DOCK
3415 static void dock_notify(struct ibm_struct
*ibm
, u32 event
);
3416 static int dock_read(char *p
);
3417 static int dock_write(char *buf
);
3419 TPACPI_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
3420 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
3421 "\\_SB.PCI0.PCI1.DOCK", /* all others */
3422 "\\_SB.PCI.ISA.SLCE", /* 570 */
3423 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
3425 /* don't list other alternatives as we install a notify handler on the 570 */
3426 TPACPI_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
3428 static const struct acpi_device_id ibm_pci_device_ids
[] = {
3429 {PCI_ROOT_HID_STRING
, 0},
3433 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
3435 .notify
= dock_notify
,
3436 .handle
= &dock_handle
,
3437 .type
= ACPI_SYSTEM_NOTIFY
,
3440 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
3441 * We just use it to get notifications of dock hotplug
3442 * in very old thinkpads */
3443 .hid
= ibm_pci_device_ids
,
3444 .notify
= dock_notify
,
3445 .handle
= &pci_handle
,
3446 .type
= ACPI_SYSTEM_NOTIFY
,
3450 static struct ibm_struct dock_driver_data
[2] = {
3454 .write
= dock_write
,
3455 .acpi
= &ibm_dock_acpidriver
[0],
3459 .acpi
= &ibm_dock_acpidriver
[1],
3463 #define dock_docked() (_sta(dock_handle) & 1)
3465 static int __init
dock_init(struct ibm_init_struct
*iibm
)
3467 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
3469 TPACPI_ACPIHANDLE_INIT(dock
);
3471 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
3472 str_supported(dock_handle
!= NULL
));
3474 return (dock_handle
)? 0 : 1;
3477 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
3481 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
3483 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
3484 dock_driver_data
[0].flags
.acpi_notify_installed
) {
3485 TPACPI_ACPIHANDLE_INIT(pci
);
3486 dock2_needed
= (pci_handle
!= NULL
);
3487 vdbg_printk(TPACPI_DBG_INIT
,
3488 "dock PCI handler for the TP 570 is %s\n",
3489 str_supported(dock2_needed
));
3491 vdbg_printk(TPACPI_DBG_INIT
,
3492 "dock subdriver part 2 not required\n");
3496 return (dock2_needed
)? 0 : 1;
3499 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
3501 int docked
= dock_docked();
3502 int pci
= ibm
->acpi
->hid
&& ibm
->acpi
->device
&&
3503 acpi_match_device_ids(ibm
->acpi
->device
, ibm_pci_device_ids
);
3506 if (event
== 1 && !pci
) /* 570 */
3507 data
= 1; /* button */
3508 else if (event
== 1 && pci
) /* 570 */
3509 data
= 3; /* dock */
3510 else if (event
== 3 && docked
)
3511 data
= 1; /* button */
3512 else if (event
== 3 && !docked
)
3513 data
= 2; /* undock */
3514 else if (event
== 0 && docked
)
3515 data
= 3; /* dock */
3517 printk(TPACPI_ERR
"unknown dock event %d, status %d\n",
3518 event
, _sta(dock_handle
));
3519 data
= 0; /* unknown */
3521 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, data
);
3522 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
3523 ibm
->acpi
->device
->dev
.bus_id
,
3527 static int dock_read(char *p
)
3530 int docked
= dock_docked();
3533 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3535 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
3537 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
3538 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
3544 static int dock_write(char *buf
)
3551 while ((cmd
= next_cmd(&buf
))) {
3552 if (strlencmp(cmd
, "undock") == 0) {
3553 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
3554 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
3556 } else if (strlencmp(cmd
, "dock") == 0) {
3557 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
3566 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
3568 /*************************************************************************
3572 #ifdef CONFIG_THINKPAD_ACPI_BAY
3574 TPACPI_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
3575 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
3576 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
3577 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
3578 ); /* A21e, R30, R31 */
3579 TPACPI_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
3580 "_EJ0", /* all others */
3581 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
3582 TPACPI_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
3583 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
3585 TPACPI_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
3589 static int __init
bay_init(struct ibm_init_struct
*iibm
)
3591 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
3593 TPACPI_ACPIHANDLE_INIT(bay
);
3595 TPACPI_ACPIHANDLE_INIT(bay_ej
);
3596 TPACPI_ACPIHANDLE_INIT(bay2
);
3598 TPACPI_ACPIHANDLE_INIT(bay2_ej
);
3600 tp_features
.bay_status
= bay_handle
&&
3601 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
3602 tp_features
.bay_status2
= bay2_handle
&&
3603 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
3605 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
3606 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
3607 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
3608 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
3610 vdbg_printk(TPACPI_DBG_INIT
,
3611 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
3612 str_supported(tp_features
.bay_status
),
3613 str_supported(tp_features
.bay_eject
),
3614 str_supported(tp_features
.bay_status2
),
3615 str_supported(tp_features
.bay_eject2
));
3617 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
3618 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
3621 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
3623 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, 0);
3624 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
3625 ibm
->acpi
->device
->dev
.bus_id
,
3629 #define bay_occupied(b) (_sta(b##_handle) & 1)
3631 static int bay_read(char *p
)
3634 int occupied
= bay_occupied(bay
);
3635 int occupied2
= bay_occupied(bay2
);
3638 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3639 tp_features
.bay_status
?
3640 (occupied
? "occupied" : "unoccupied") :
3642 if (tp_features
.bay_status2
)
3643 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
3644 "occupied" : "unoccupied");
3646 eject
= tp_features
.bay_eject
&& occupied
;
3647 eject2
= tp_features
.bay_eject2
&& occupied2
;
3649 if (eject
&& eject2
)
3650 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
3652 len
+= sprintf(p
+ len
, "commands:\teject\n");
3654 len
+= sprintf(p
+ len
, "commands:\teject2\n");
3659 static int bay_write(char *buf
)
3663 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
3666 while ((cmd
= next_cmd(&buf
))) {
3667 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
3668 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
3670 } else if (tp_features
.bay_eject2
&&
3671 strlencmp(cmd
, "eject2") == 0) {
3672 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
3681 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
3682 .notify
= bay_notify
,
3683 .handle
= &bay_handle
,
3684 .type
= ACPI_SYSTEM_NOTIFY
,
3687 static struct ibm_struct bay_driver_data
= {
3691 .acpi
= &ibm_bay_acpidriver
,
3694 #endif /* CONFIG_THINKPAD_ACPI_BAY */
3696 /*************************************************************************
3700 /* sysfs cmos_command -------------------------------------------------- */
3701 static ssize_t
cmos_command_store(struct device
*dev
,
3702 struct device_attribute
*attr
,
3703 const char *buf
, size_t count
)
3705 unsigned long cmos_cmd
;
3708 if (parse_strtoul(buf
, 21, &cmos_cmd
))
3711 res
= issue_thinkpad_cmos_command(cmos_cmd
);
3712 return (res
)? res
: count
;
3715 static struct device_attribute dev_attr_cmos_command
=
3716 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
3718 /* --------------------------------------------------------------------- */
3720 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
3724 vdbg_printk(TPACPI_DBG_INIT
,
3725 "initializing cmos commands subdriver\n");
3727 TPACPI_ACPIHANDLE_INIT(cmos
);
3729 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
3730 str_supported(cmos_handle
!= NULL
));
3732 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
3736 return (cmos_handle
)? 0 : 1;
3739 static void cmos_exit(void)
3741 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
3744 static int cmos_read(char *p
)
3748 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
3749 R30, R31, T20-22, X20-21 */
3751 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3753 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3754 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
3760 static int cmos_write(char *buf
)
3765 while ((cmd
= next_cmd(&buf
))) {
3766 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
3767 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
3772 res
= issue_thinkpad_cmos_command(cmos_cmd
);
3780 static struct ibm_struct cmos_driver_data
= {
3783 .write
= cmos_write
,
3787 /*************************************************************************
3791 enum led_access_mode
{
3792 TPACPI_LED_NONE
= 0,
3793 TPACPI_LED_570
, /* 570 */
3794 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
3795 TPACPI_LED_NEW
, /* all others */
3798 enum { /* For TPACPI_LED_OLD */
3799 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
3800 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
3801 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
3810 static enum led_access_mode led_supported
;
3812 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
3813 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
3814 /* T20-22, X20-21 */
3815 "LED", /* all others */
3818 #define TPACPI_LED_NUMLEDS 8
3819 static struct tpacpi_led_classdev
*tpacpi_leds
;
3820 static enum led_status_t tpacpi_led_state_cache
[TPACPI_LED_NUMLEDS
];
3821 static const char const *tpacpi_led_names
[TPACPI_LED_NUMLEDS
] = {
3822 /* there's a limit of 19 chars + NULL before 2.6.26 */
3824 "tpacpi:orange:batt",
3825 "tpacpi:green:batt",
3826 "tpacpi::dock_active",
3827 "tpacpi::bay_active",
3828 "tpacpi::dock_batt",
3829 "tpacpi::unknown_led",
3833 static int led_get_status(unsigned int led
)
3836 enum led_status_t led_s
;
3838 switch (led_supported
) {
3839 case TPACPI_LED_570
:
3840 if (!acpi_evalf(ec_handle
,
3841 &status
, "GLED", "dd", 1 << led
))
3843 led_s
= (status
== 0)?
3848 tpacpi_led_state_cache
[led
] = led_s
;
3857 static int led_set_status(unsigned int led
, enum led_status_t ledstatus
)
3859 /* off, on, blink. Index is led_status_t */
3860 static const int const led_sled_arg1
[] = { 0, 1, 3 };
3861 static const int const led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
3862 static const int const led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
3863 static const int const led_led_arg1
[] = { 0, 0x80, 0xc0 };
3867 switch (led_supported
) {
3868 case TPACPI_LED_570
:
3871 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
3872 led
, led_sled_arg1
[ledstatus
]))
3875 case TPACPI_LED_OLD
:
3876 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
3878 rc
= ec_write(TPACPI_LED_EC_HLMS
, led
);
3880 rc
= ec_write(TPACPI_LED_EC_HLBL
,
3881 led
* led_exp_hlbl
[ledstatus
]);
3883 rc
= ec_write(TPACPI_LED_EC_HLCL
,
3884 led
* led_exp_hlcl
[ledstatus
]);
3886 case TPACPI_LED_NEW
:
3888 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
3889 led
, led_led_arg1
[ledstatus
]))
3897 tpacpi_led_state_cache
[led
] = ledstatus
;
3902 static void led_sysfs_set_status(unsigned int led
,
3903 enum led_brightness brightness
)
3906 (brightness
== LED_OFF
) ?
3908 (tpacpi_led_state_cache
[led
] == TPACPI_LED_BLINK
) ?
3909 TPACPI_LED_BLINK
: TPACPI_LED_ON
);
3912 static void led_set_status_worker(struct work_struct
*work
)
3914 struct tpacpi_led_classdev
*data
=
3915 container_of(work
, struct tpacpi_led_classdev
, work
);
3917 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
3918 led_sysfs_set_status(data
->led
, data
->new_brightness
);
3921 static void led_sysfs_set(struct led_classdev
*led_cdev
,
3922 enum led_brightness brightness
)
3924 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
3925 struct tpacpi_led_classdev
, led_classdev
);
3927 data
->new_brightness
= brightness
;
3928 schedule_work(&data
->work
);
3931 static int led_sysfs_blink_set(struct led_classdev
*led_cdev
,
3932 unsigned long *delay_on
, unsigned long *delay_off
)
3934 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
3935 struct tpacpi_led_classdev
, led_classdev
);
3937 /* Can we choose the flash rate? */
3938 if (*delay_on
== 0 && *delay_off
== 0) {
3939 /* yes. set them to the hardware blink rate (1 Hz) */
3940 *delay_on
= 500; /* ms */
3941 *delay_off
= 500; /* ms */
3942 } else if ((*delay_on
!= 500) || (*delay_off
!= 500))
3945 data
->new_brightness
= TPACPI_LED_BLINK
;
3946 schedule_work(&data
->work
);
3951 static enum led_brightness
led_sysfs_get(struct led_classdev
*led_cdev
)
3955 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
3956 struct tpacpi_led_classdev
, led_classdev
);
3958 rc
= led_get_status(data
->led
);
3960 if (rc
== TPACPI_LED_OFF
|| rc
< 0)
3961 rc
= LED_OFF
; /* no error handling in led class :( */
3968 static void led_exit(void)
3972 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
3973 if (tpacpi_leds
[i
].led_classdev
.name
)
3974 led_classdev_unregister(&tpacpi_leds
[i
].led_classdev
);
3981 static int __init
led_init(struct ibm_init_struct
*iibm
)
3986 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
3988 TPACPI_ACPIHANDLE_INIT(led
);
3991 /* led not supported on R30, R31 */
3992 led_supported
= TPACPI_LED_NONE
;
3993 else if (strlencmp(led_path
, "SLED") == 0)
3995 led_supported
= TPACPI_LED_570
;
3996 else if (strlencmp(led_path
, "SYSL") == 0)
3997 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
3998 led_supported
= TPACPI_LED_OLD
;
4001 led_supported
= TPACPI_LED_NEW
;
4003 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
4004 str_supported(led_supported
), led_supported
);
4006 tpacpi_leds
= kzalloc(sizeof(*tpacpi_leds
) * TPACPI_LED_NUMLEDS
,
4009 printk(TPACPI_ERR
"Out of memory for LED data\n");
4013 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
4014 tpacpi_leds
[i
].led
= i
;
4016 tpacpi_leds
[i
].led_classdev
.brightness_set
= &led_sysfs_set
;
4017 tpacpi_leds
[i
].led_classdev
.blink_set
= &led_sysfs_blink_set
;
4018 if (led_supported
== TPACPI_LED_570
)
4019 tpacpi_leds
[i
].led_classdev
.brightness_get
=
4022 tpacpi_leds
[i
].led_classdev
.name
= tpacpi_led_names
[i
];
4024 INIT_WORK(&tpacpi_leds
[i
].work
, led_set_status_worker
);
4026 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4027 &tpacpi_leds
[i
].led_classdev
);
4029 tpacpi_leds
[i
].led_classdev
.name
= NULL
;
4035 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
4038 #define str_led_status(s) \
4039 ((s) == TPACPI_LED_OFF ? "off" : \
4040 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
4042 static int led_read(char *p
)
4046 if (!led_supported
) {
4047 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4050 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4052 if (led_supported
== TPACPI_LED_570
) {
4055 for (i
= 0; i
< 8; i
++) {
4056 status
= led_get_status(i
);
4059 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
4060 i
, str_led_status(status
));
4064 len
+= sprintf(p
+ len
, "commands:\t"
4065 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
4070 static int led_write(char *buf
)
4074 enum led_status_t s
;
4079 while ((cmd
= next_cmd(&buf
))) {
4080 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
4083 if (strstr(cmd
, "off")) {
4085 } else if (strstr(cmd
, "on")) {
4087 } else if (strstr(cmd
, "blink")) {
4088 s
= TPACPI_LED_BLINK
;
4093 rc
= led_set_status(led
, s
);
4101 static struct ibm_struct led_driver_data
= {
4108 /*************************************************************************
4112 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
4114 static int __init
beep_init(struct ibm_init_struct
*iibm
)
4116 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
4118 TPACPI_ACPIHANDLE_INIT(beep
);
4120 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
4121 str_supported(beep_handle
!= NULL
));
4123 return (beep_handle
)? 0 : 1;
4126 static int beep_read(char *p
)
4131 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4133 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4134 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
4140 static int beep_write(char *buf
)
4148 while ((cmd
= next_cmd(&buf
))) {
4149 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
4150 beep_cmd
>= 0 && beep_cmd
<= 17) {
4154 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
4161 static struct ibm_struct beep_driver_data
= {
4164 .write
= beep_write
,
4167 /*************************************************************************
4171 enum thermal_access_mode
{
4172 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
4173 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
4174 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
4175 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
4176 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
4179 enum { /* TPACPI_THERMAL_TPEC_* */
4180 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
4181 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
4182 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
4185 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
4186 struct ibm_thermal_sensors_struct
{
4187 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
4190 static enum thermal_access_mode thermal_read_mode
;
4192 /* idx is zero-based */
4193 static int thermal_get_sensor(int idx
, s32
*value
)
4199 t
= TP_EC_THERMAL_TMP0
;
4201 switch (thermal_read_mode
) {
4202 #if TPACPI_MAX_THERMAL_SENSORS >= 16
4203 case TPACPI_THERMAL_TPEC_16
:
4204 if (idx
>= 8 && idx
<= 15) {
4205 t
= TP_EC_THERMAL_TMP8
;
4210 case TPACPI_THERMAL_TPEC_8
:
4212 if (!acpi_ec_read(t
+ idx
, &tmp
))
4214 *value
= tmp
* 1000;
4219 case TPACPI_THERMAL_ACPI_UPDT
:
4221 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
4222 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
4224 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
4226 *value
= (t
- 2732) * 100;
4231 case TPACPI_THERMAL_ACPI_TMP07
:
4233 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
4234 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
4236 if (t
> 127 || t
< -127)
4237 t
= TP_EC_THERMAL_TMP_NA
;
4243 case TPACPI_THERMAL_NONE
:
4251 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
4262 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
4265 for (i
= 0 ; i
< n
; i
++) {
4266 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
4274 /* sysfs temp##_input -------------------------------------------------- */
4276 static ssize_t
thermal_temp_input_show(struct device
*dev
,
4277 struct device_attribute
*attr
,
4280 struct sensor_device_attribute
*sensor_attr
=
4281 to_sensor_dev_attr(attr
);
4282 int idx
= sensor_attr
->index
;
4286 res
= thermal_get_sensor(idx
, &value
);
4289 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
4292 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
4295 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
4296 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
4297 thermal_temp_input_show, NULL, _idxB)
4299 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
4300 THERMAL_SENSOR_ATTR_TEMP(1, 0),
4301 THERMAL_SENSOR_ATTR_TEMP(2, 1),
4302 THERMAL_SENSOR_ATTR_TEMP(3, 2),
4303 THERMAL_SENSOR_ATTR_TEMP(4, 3),
4304 THERMAL_SENSOR_ATTR_TEMP(5, 4),
4305 THERMAL_SENSOR_ATTR_TEMP(6, 5),
4306 THERMAL_SENSOR_ATTR_TEMP(7, 6),
4307 THERMAL_SENSOR_ATTR_TEMP(8, 7),
4308 THERMAL_SENSOR_ATTR_TEMP(9, 8),
4309 THERMAL_SENSOR_ATTR_TEMP(10, 9),
4310 THERMAL_SENSOR_ATTR_TEMP(11, 10),
4311 THERMAL_SENSOR_ATTR_TEMP(12, 11),
4312 THERMAL_SENSOR_ATTR_TEMP(13, 12),
4313 THERMAL_SENSOR_ATTR_TEMP(14, 13),
4314 THERMAL_SENSOR_ATTR_TEMP(15, 14),
4315 THERMAL_SENSOR_ATTR_TEMP(16, 15),
4318 #define THERMAL_ATTRS(X) \
4319 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
4321 static struct attribute
*thermal_temp_input_attr
[] = {
4341 static const struct attribute_group thermal_temp_input16_group
= {
4342 .attrs
= thermal_temp_input_attr
4345 static const struct attribute_group thermal_temp_input8_group
= {
4346 .attrs
= &thermal_temp_input_attr
[8]
4349 #undef THERMAL_SENSOR_ATTR_TEMP
4350 #undef THERMAL_ATTRS
4352 /* --------------------------------------------------------------------- */
4354 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
4361 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
4363 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
4365 if (thinkpad_id
.ec_model
) {
4367 * Direct EC access mode: sensors at registers
4368 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
4369 * non-implemented, thermal sensors return 0x80 when
4374 for (i
= 0; i
< 8; i
++) {
4375 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
4381 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
4389 /* This is sheer paranoia, but we handle it anyway */
4392 "ThinkPad ACPI EC access misbehaving, "
4393 "falling back to ACPI TMPx access "
4395 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
4398 "ThinkPad ACPI EC access misbehaving, "
4399 "disabling thermal sensors access\n");
4400 thermal_read_mode
= TPACPI_THERMAL_NONE
;
4405 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
4407 } else if (acpi_tmp7
) {
4408 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
4409 /* 600e/x, 770e, 770x */
4410 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
4412 /* Standard ACPI TMPx access, max 8 sensors */
4413 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
4416 /* temperatures not supported on 570, G4x, R30, R31, R32 */
4417 thermal_read_mode
= TPACPI_THERMAL_NONE
;
4420 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
4421 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
4424 switch (thermal_read_mode
) {
4425 case TPACPI_THERMAL_TPEC_16
:
4426 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4427 &thermal_temp_input16_group
);
4431 case TPACPI_THERMAL_TPEC_8
:
4432 case TPACPI_THERMAL_ACPI_TMP07
:
4433 case TPACPI_THERMAL_ACPI_UPDT
:
4434 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4435 &thermal_temp_input8_group
);
4439 case TPACPI_THERMAL_NONE
:
4447 static void thermal_exit(void)
4449 switch (thermal_read_mode
) {
4450 case TPACPI_THERMAL_TPEC_16
:
4451 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4452 &thermal_temp_input16_group
);
4454 case TPACPI_THERMAL_TPEC_8
:
4455 case TPACPI_THERMAL_ACPI_TMP07
:
4456 case TPACPI_THERMAL_ACPI_UPDT
:
4457 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4458 &thermal_temp_input16_group
);
4460 case TPACPI_THERMAL_NONE
:
4466 static int thermal_read(char *p
)
4470 struct ibm_thermal_sensors_struct t
;
4472 n
= thermal_get_sensors(&t
);
4473 if (unlikely(n
< 0))
4476 len
+= sprintf(p
+ len
, "temperatures:\t");
4479 for (i
= 0; i
< (n
- 1); i
++)
4480 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
4481 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
4483 len
+= sprintf(p
+ len
, "not supported\n");
4488 static struct ibm_struct thermal_driver_data
= {
4490 .read
= thermal_read
,
4491 .exit
= thermal_exit
,
4494 /*************************************************************************
4498 static u8 ecdump_regs
[256];
4500 static int ecdump_read(char *p
)
4506 len
+= sprintf(p
+ len
, "EC "
4507 " +00 +01 +02 +03 +04 +05 +06 +07"
4508 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
4509 for (i
= 0; i
< 256; i
+= 16) {
4510 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
4511 for (j
= 0; j
< 16; j
++) {
4512 if (!acpi_ec_read(i
+ j
, &v
))
4514 if (v
!= ecdump_regs
[i
+ j
])
4515 len
+= sprintf(p
+ len
, " *%02x", v
);
4517 len
+= sprintf(p
+ len
, " %02x", v
);
4518 ecdump_regs
[i
+ j
] = v
;
4520 len
+= sprintf(p
+ len
, "\n");
4525 /* These are way too dangerous to advertise openly... */
4527 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
4528 " (<offset> is 00-ff, <value> is 00-ff)\n");
4529 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
4530 " (<offset> is 00-ff, <value> is 0-255)\n");
4535 static int ecdump_write(char *buf
)
4540 while ((cmd
= next_cmd(&buf
))) {
4541 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
4543 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
4547 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
4548 if (!acpi_ec_write(i
, v
))
4557 static struct ibm_struct ecdump_driver_data
= {
4559 .read
= ecdump_read
,
4560 .write
= ecdump_write
,
4561 .flags
.experimental
= 1,
4564 /*************************************************************************
4565 * Backlight/brightness subdriver
4568 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
4571 TP_EC_BACKLIGHT
= 0x31,
4573 /* TP_EC_BACKLIGHT bitmasks */
4574 TP_EC_BACKLIGHT_LVLMSK
= 0x1F,
4575 TP_EC_BACKLIGHT_CMDMSK
= 0xE0,
4576 TP_EC_BACKLIGHT_MAPSW
= 0x20,
4579 static struct backlight_device
*ibm_backlight_device
;
4580 static int brightness_mode
;
4581 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
4583 static struct mutex brightness_mutex
;
4586 * ThinkPads can read brightness from two places: EC 0x31, or
4587 * CMOS NVRAM byte 0x5E, bits 0-3.
4589 * EC 0x31 has the following layout
4590 * Bit 7: unknown function
4591 * Bit 6: unknown function
4592 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
4593 * Bit 4: must be set to zero to avoid problems
4594 * Bit 3-0: backlight brightness level
4596 * brightness_get_raw returns status data in the EC 0x31 layout
4598 static int brightness_get_raw(int *status
)
4600 u8 lec
= 0, lcmos
= 0, level
= 0;
4602 if (brightness_mode
& 1) {
4603 if (!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
))
4605 level
= lec
& TP_EC_BACKLIGHT_LVLMSK
;
4607 if (brightness_mode
& 2) {
4608 lcmos
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
4609 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
4610 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
4611 lcmos
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
4615 if (brightness_mode
== 3) {
4616 *status
= lec
; /* Prefer EC, CMOS is just a backing store */
4617 lec
&= TP_EC_BACKLIGHT_LVLMSK
;
4619 tp_warned
.bright_cmos_ec_unsync
= 0;
4621 if (!tp_warned
.bright_cmos_ec_unsync
) {
4623 "CMOS NVRAM (%u) and EC (%u) do not "
4624 "agree on display brightness level\n",
4625 (unsigned int) lcmos
,
4626 (unsigned int) lec
);
4627 tp_warned
.bright_cmos_ec_unsync
= 1;
4638 /* May return EINTR which can always be mapped to ERESTARTSYS */
4639 static int brightness_set(int value
)
4641 int cmos_cmd
, inc
, i
, res
;
4645 if (value
> ((tp_features
.bright_16levels
)? 15 : 7) ||
4649 res
= mutex_lock_interruptible(&brightness_mutex
);
4653 res
= brightness_get_raw(¤t_value
);
4657 command_bits
= current_value
& TP_EC_BACKLIGHT_CMDMSK
;
4658 current_value
&= TP_EC_BACKLIGHT_LVLMSK
;
4660 cmos_cmd
= value
> current_value
?
4661 TP_CMOS_BRIGHTNESS_UP
:
4662 TP_CMOS_BRIGHTNESS_DOWN
;
4663 inc
= (value
> current_value
)? 1 : -1;
4666 for (i
= current_value
; i
!= value
; i
+= inc
) {
4667 if ((brightness_mode
& 2) &&
4668 issue_thinkpad_cmos_command(cmos_cmd
)) {
4672 if ((brightness_mode
& 1) &&
4673 !acpi_ec_write(TP_EC_BACKLIGHT
,
4674 (i
+ inc
) | command_bits
)) {
4681 mutex_unlock(&brightness_mutex
);
4685 /* sysfs backlight class ----------------------------------------------- */
4687 static int brightness_update_status(struct backlight_device
*bd
)
4689 /* it is the backlight class's job (caller) to handle
4690 * EINTR and other errors properly */
4691 return brightness_set(
4692 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
4693 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
4694 bd
->props
.brightness
: 0);
4697 static int brightness_get(struct backlight_device
*bd
)
4701 res
= brightness_get_raw(&status
);
4703 return 0; /* FIXME: teach backlight about error handling */
4705 return status
& TP_EC_BACKLIGHT_LVLMSK
;
4708 static struct backlight_ops ibm_backlight_data
= {
4709 .get_brightness
= brightness_get
,
4710 .update_status
= brightness_update_status
,
4713 /* --------------------------------------------------------------------- */
4715 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
4719 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
4721 mutex_init(&brightness_mutex
);
4724 * We always attempt to detect acpi support, so as to switch
4725 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
4726 * going to publish a backlight interface
4728 b
= tpacpi_check_std_acpi_brightness_support();
4730 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
4731 printk(TPACPI_NOTICE
4732 "Lenovo BIOS switched to ACPI backlight "
4735 if (brightness_enable
> 1) {
4736 printk(TPACPI_NOTICE
4737 "standard ACPI backlight interface "
4738 "available, not loading native one...\n");
4743 if (!brightness_enable
) {
4744 dbg_printk(TPACPI_DBG_INIT
,
4745 "brightness support disabled by "
4746 "module parameter\n");
4752 "Unsupported brightness interface, "
4753 "please contact %s\n", TPACPI_MAIL
);
4757 tp_features
.bright_16levels
= 1;
4759 if (!brightness_mode
) {
4760 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
)
4761 brightness_mode
= 2;
4763 brightness_mode
= 3;
4765 dbg_printk(TPACPI_DBG_INIT
, "selected brightness_mode=%d\n",
4769 if (brightness_mode
> 3)
4772 if (brightness_get_raw(&b
) < 0)
4775 if (tp_features
.bright_16levels
)
4777 "detected a 16-level brightness capable ThinkPad\n");
4779 ibm_backlight_device
= backlight_device_register(
4780 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
4781 &ibm_backlight_data
);
4782 if (IS_ERR(ibm_backlight_device
)) {
4783 printk(TPACPI_ERR
"Could not register backlight device\n");
4784 return PTR_ERR(ibm_backlight_device
);
4786 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
4788 ibm_backlight_device
->props
.max_brightness
=
4789 (tp_features
.bright_16levels
)? 15 : 7;
4790 ibm_backlight_device
->props
.brightness
= b
& TP_EC_BACKLIGHT_LVLMSK
;
4791 backlight_update_status(ibm_backlight_device
);
4796 static void brightness_exit(void)
4798 if (ibm_backlight_device
) {
4799 vdbg_printk(TPACPI_DBG_EXIT
,
4800 "calling backlight_device_unregister()\n");
4801 backlight_device_unregister(ibm_backlight_device
);
4802 ibm_backlight_device
= NULL
;
4806 static int brightness_read(char *p
)
4811 level
= brightness_get(NULL
);
4813 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
4815 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
4816 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
4817 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
4818 " (<level> is 0-%d)\n",
4819 (tp_features
.bright_16levels
) ? 15 : 7);
4825 static int brightness_write(char *buf
)
4830 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
4832 level
= brightness_get(NULL
);
4836 while ((cmd
= next_cmd(&buf
))) {
4837 if (strlencmp(cmd
, "up") == 0) {
4838 if (level
< max_level
)
4840 } else if (strlencmp(cmd
, "down") == 0) {
4843 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
4844 level
>= 0 && level
<= max_level
) {
4851 * Now we know what the final level should be, so we try to set it.
4852 * Doing it this way makes the syscall restartable in case of EINTR
4854 rc
= brightness_set(level
);
4855 return (rc
== -EINTR
)? ERESTARTSYS
: rc
;
4858 static struct ibm_struct brightness_driver_data
= {
4859 .name
= "brightness",
4860 .read
= brightness_read
,
4861 .write
= brightness_write
,
4862 .exit
= brightness_exit
,
4865 /*************************************************************************
4869 static int volume_offset
= 0x30;
4871 static int volume_read(char *p
)
4876 if (!acpi_ec_read(volume_offset
, &level
)) {
4877 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
4879 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
4880 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
4881 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
4882 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
4883 " (<level> is 0-15)\n");
4889 static int volume_write(char *buf
)
4891 int cmos_cmd
, inc
, i
;
4893 int new_level
, new_mute
;
4896 while ((cmd
= next_cmd(&buf
))) {
4897 if (!acpi_ec_read(volume_offset
, &level
))
4899 new_mute
= mute
= level
& 0x40;
4900 new_level
= level
= level
& 0xf;
4902 if (strlencmp(cmd
, "up") == 0) {
4906 new_level
= level
== 15 ? 15 : level
+ 1;
4907 } else if (strlencmp(cmd
, "down") == 0) {
4911 new_level
= level
== 0 ? 0 : level
- 1;
4912 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
4913 new_level
>= 0 && new_level
<= 15) {
4915 } else if (strlencmp(cmd
, "mute") == 0) {
4920 if (new_level
!= level
) {
4921 /* mute doesn't change */
4923 cmos_cmd
= (new_level
> level
) ?
4924 TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
4925 inc
= new_level
> level
? 1 : -1;
4927 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
4928 !acpi_ec_write(volume_offset
, level
)))
4931 for (i
= level
; i
!= new_level
; i
+= inc
)
4932 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
4933 !acpi_ec_write(volume_offset
, i
+ inc
))
4937 (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
4938 !acpi_ec_write(volume_offset
, new_level
+ mute
))) {
4943 if (new_mute
!= mute
) {
4944 /* level doesn't change */
4946 cmos_cmd
= (new_mute
) ?
4947 TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
4949 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
4950 !acpi_ec_write(volume_offset
, level
+ new_mute
))
4958 static struct ibm_struct volume_driver_data
= {
4960 .read
= volume_read
,
4961 .write
= volume_write
,
4964 /*************************************************************************
4971 * TPACPI_FAN_RD_ACPI_GFAN:
4972 * ACPI GFAN method: returns fan level
4974 * see TPACPI_FAN_WR_ACPI_SFAN
4975 * EC 0x2f (HFSP) not available if GFAN exists
4977 * TPACPI_FAN_WR_ACPI_SFAN:
4978 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
4980 * EC 0x2f (HFSP) might be available *for reading*, but do not use
4983 * TPACPI_FAN_WR_TPEC:
4984 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
4985 * Supported on almost all ThinkPads
4987 * Fan speed changes of any sort (including those caused by the
4988 * disengaged mode) are usually done slowly by the firmware as the
4989 * maximum ammount of fan duty cycle change per second seems to be
4992 * Reading is not available if GFAN exists.
4993 * Writing is not available if SFAN exists.
4996 * 7 automatic mode engaged;
4997 * (default operation mode of the ThinkPad)
4998 * fan level is ignored in this mode.
4999 * 6 full speed mode (takes precedence over bit 7);
5000 * not available on all thinkpads. May disable
5001 * the tachometer while the fan controller ramps up
5002 * the speed (which can take up to a few *minutes*).
5003 * Speeds up fan to 100% duty-cycle, which is far above
5004 * the standard RPM levels. It is not impossible that
5005 * it could cause hardware damage.
5006 * 5-3 unused in some models. Extra bits for fan level
5007 * in others, but still useless as all values above
5008 * 7 map to the same speed as level 7 in these models.
5009 * 2-0 fan level (0..7 usually)
5011 * 0x07 = max (set when temperatures critical)
5012 * Some ThinkPads may have other levels, see
5013 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
5015 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
5016 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
5017 * does so, its initial value is meaningless (0x07).
5019 * For firmware bugs, refer to:
5020 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
5024 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
5025 * Main fan tachometer reading (in RPM)
5027 * This register is present on all ThinkPads with a new-style EC, and
5028 * it is known not to be present on the A21m/e, and T22, as there is
5029 * something else in offset 0x84 according to the ACPI DSDT. Other
5030 * ThinkPads from this same time period (and earlier) probably lack the
5031 * tachometer as well.
5033 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
5034 * was never fixed by IBM to report the EC firmware version string
5035 * probably support the tachometer (like the early X models), so
5036 * detecting it is quite hard. We need more data to know for sure.
5038 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
5041 * FIRMWARE BUG: may go stale while the EC is switching to full speed
5044 * For firmware bugs, refer to:
5045 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
5047 * TPACPI_FAN_WR_ACPI_FANS:
5048 * ThinkPad X31, X40, X41. Not available in the X60.
5050 * FANS ACPI handle: takes three arguments: low speed, medium speed,
5051 * high speed. ACPI DSDT seems to map these three speeds to levels
5052 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
5053 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
5055 * The speeds are stored on handles
5056 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
5058 * There are three default speed sets, acessible as handles:
5059 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
5061 * ACPI DSDT switches which set is in use depending on various
5064 * TPACPI_FAN_WR_TPEC is also available and should be used to
5065 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
5066 * but the ACPI tables just mention level 7.
5069 enum { /* Fan control constants */
5070 fan_status_offset
= 0x2f, /* EC register 0x2f */
5071 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
5072 * 0x84 must be read before 0x85 */
5074 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
5075 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
5077 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
5080 enum fan_status_access_mode
{
5081 TPACPI_FAN_NONE
= 0, /* No fan status or control */
5082 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
5083 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
5086 enum fan_control_access_mode
{
5087 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
5088 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
5089 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
5090 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
5093 enum fan_control_commands
{
5094 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
5095 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
5096 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
5097 * and also watchdog cmd */
5100 static int fan_control_allowed
;
5102 static enum fan_status_access_mode fan_status_access_mode
;
5103 static enum fan_control_access_mode fan_control_access_mode
;
5104 static enum fan_control_commands fan_control_commands
;
5106 static u8 fan_control_initial_status
;
5107 static u8 fan_control_desired_level
;
5108 static int fan_watchdog_maxinterval
;
5110 static struct mutex fan_mutex
;
5112 static void fan_watchdog_fire(struct work_struct
*ignored
);
5113 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
5115 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
5116 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
5117 "\\FSPD", /* 600e/x, 770e, 770x */
5119 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
5120 "JFNS", /* 770x-JL */
5124 * Call with fan_mutex held
5126 static void fan_update_desired_level(u8 status
)
5129 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
5131 fan_control_desired_level
= 7;
5133 fan_control_desired_level
= status
;
5137 static int fan_get_status(u8
*status
)
5142 * Add TPACPI_FAN_RD_ACPI_FANS ? */
5144 switch (fan_status_access_mode
) {
5145 case TPACPI_FAN_RD_ACPI_GFAN
:
5146 /* 570, 600e/x, 770e, 770x */
5148 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
5156 case TPACPI_FAN_RD_TPEC
:
5157 /* all except 570, 600e/x, 770e, 770x */
5158 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
5173 static int fan_get_status_safe(u8
*status
)
5178 if (mutex_lock_interruptible(&fan_mutex
))
5179 return -ERESTARTSYS
;
5180 rc
= fan_get_status(&s
);
5182 fan_update_desired_level(s
);
5183 mutex_unlock(&fan_mutex
);
5191 static int fan_get_speed(unsigned int *speed
)
5195 switch (fan_status_access_mode
) {
5196 case TPACPI_FAN_RD_TPEC
:
5197 /* all except 570, 600e/x, 770e, 770x */
5198 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
5199 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
5203 *speed
= (hi
<< 8) | lo
;
5214 static int fan_set_level(int level
)
5216 if (!fan_control_allowed
)
5219 switch (fan_control_access_mode
) {
5220 case TPACPI_FAN_WR_ACPI_SFAN
:
5221 if (level
>= 0 && level
<= 7) {
5222 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
5228 case TPACPI_FAN_WR_ACPI_FANS
:
5229 case TPACPI_FAN_WR_TPEC
:
5230 if ((level
!= TP_EC_FAN_AUTO
) &&
5231 (level
!= TP_EC_FAN_FULLSPEED
) &&
5232 ((level
< 0) || (level
> 7)))
5235 /* safety net should the EC not support AUTO
5236 * or FULLSPEED mode bits and just ignore them */
5237 if (level
& TP_EC_FAN_FULLSPEED
)
5238 level
|= 7; /* safety min speed 7 */
5239 else if (level
& TP_EC_FAN_AUTO
)
5240 level
|= 4; /* safety min speed 4 */
5242 if (!acpi_ec_write(fan_status_offset
, level
))
5245 tp_features
.fan_ctrl_status_undef
= 0;
5254 static int fan_set_level_safe(int level
)
5258 if (!fan_control_allowed
)
5261 if (mutex_lock_interruptible(&fan_mutex
))
5262 return -ERESTARTSYS
;
5264 if (level
== TPACPI_FAN_LAST_LEVEL
)
5265 level
= fan_control_desired_level
;
5267 rc
= fan_set_level(level
);
5269 fan_update_desired_level(level
);
5271 mutex_unlock(&fan_mutex
);
5275 static int fan_set_enable(void)
5280 if (!fan_control_allowed
)
5283 if (mutex_lock_interruptible(&fan_mutex
))
5284 return -ERESTARTSYS
;
5286 switch (fan_control_access_mode
) {
5287 case TPACPI_FAN_WR_ACPI_FANS
:
5288 case TPACPI_FAN_WR_TPEC
:
5289 rc
= fan_get_status(&s
);
5293 /* Don't go out of emergency fan mode */
5296 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
5299 if (!acpi_ec_write(fan_status_offset
, s
))
5302 tp_features
.fan_ctrl_status_undef
= 0;
5307 case TPACPI_FAN_WR_ACPI_SFAN
:
5308 rc
= fan_get_status(&s
);
5314 /* Set fan to at least level 4 */
5317 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
5327 mutex_unlock(&fan_mutex
);
5331 static int fan_set_disable(void)
5335 if (!fan_control_allowed
)
5338 if (mutex_lock_interruptible(&fan_mutex
))
5339 return -ERESTARTSYS
;
5342 switch (fan_control_access_mode
) {
5343 case TPACPI_FAN_WR_ACPI_FANS
:
5344 case TPACPI_FAN_WR_TPEC
:
5345 if (!acpi_ec_write(fan_status_offset
, 0x00))
5348 fan_control_desired_level
= 0;
5349 tp_features
.fan_ctrl_status_undef
= 0;
5353 case TPACPI_FAN_WR_ACPI_SFAN
:
5354 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
5357 fan_control_desired_level
= 0;
5365 mutex_unlock(&fan_mutex
);
5369 static int fan_set_speed(int speed
)
5373 if (!fan_control_allowed
)
5376 if (mutex_lock_interruptible(&fan_mutex
))
5377 return -ERESTARTSYS
;
5380 switch (fan_control_access_mode
) {
5381 case TPACPI_FAN_WR_ACPI_FANS
:
5382 if (speed
>= 0 && speed
<= 65535) {
5383 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
5384 speed
, speed
, speed
))
5394 mutex_unlock(&fan_mutex
);
5398 static void fan_watchdog_reset(void)
5400 static int fan_watchdog_active
;
5402 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
5405 if (fan_watchdog_active
)
5406 cancel_delayed_work(&fan_watchdog_task
);
5408 if (fan_watchdog_maxinterval
> 0 &&
5409 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
5410 fan_watchdog_active
= 1;
5411 if (!schedule_delayed_work(&fan_watchdog_task
,
5412 msecs_to_jiffies(fan_watchdog_maxinterval
5415 "failed to schedule the fan watchdog, "
5416 "watchdog will not trigger\n");
5419 fan_watchdog_active
= 0;
5422 static void fan_watchdog_fire(struct work_struct
*ignored
)
5426 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
5429 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
5430 rc
= fan_set_enable();
5432 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
5433 "will try again later...\n", -rc
);
5434 /* reschedule for later */
5435 fan_watchdog_reset();
5440 * SYSFS fan layout: hwmon compatible (device)
5443 * 0: "disengaged" mode
5445 * 2: native EC "auto" mode (recommended, hardware default)
5447 * pwm*: set speed in manual mode, ignored otherwise.
5448 * 0 is level 0; 255 is level 7. Intermediate points done with linear
5451 * fan*_input: tachometer reading, RPM
5454 * SYSFS fan layout: extensions
5456 * fan_watchdog (driver):
5457 * fan watchdog interval in seconds, 0 disables (default), max 120
5460 /* sysfs fan pwm1_enable ----------------------------------------------- */
5461 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
5462 struct device_attribute
*attr
,
5468 res
= fan_get_status_safe(&status
);
5472 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
5473 if (status
!= fan_control_initial_status
) {
5474 tp_features
.fan_ctrl_status_undef
= 0;
5476 /* Return most likely status. In fact, it
5477 * might be the only possible status */
5478 status
= TP_EC_FAN_AUTO
;
5482 if (status
& TP_EC_FAN_FULLSPEED
) {
5484 } else if (status
& TP_EC_FAN_AUTO
) {
5489 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
5492 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
5493 struct device_attribute
*attr
,
5494 const char *buf
, size_t count
)
5499 if (parse_strtoul(buf
, 2, &t
))
5504 level
= TP_EC_FAN_FULLSPEED
;
5507 level
= TPACPI_FAN_LAST_LEVEL
;
5510 level
= TP_EC_FAN_AUTO
;
5513 /* reserved for software-controlled auto mode */
5519 res
= fan_set_level_safe(level
);
5525 fan_watchdog_reset();
5530 static struct device_attribute dev_attr_fan_pwm1_enable
=
5531 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
5532 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
5534 /* sysfs fan pwm1 ------------------------------------------------------ */
5535 static ssize_t
fan_pwm1_show(struct device
*dev
,
5536 struct device_attribute
*attr
,
5542 res
= fan_get_status_safe(&status
);
5546 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
5547 if (status
!= fan_control_initial_status
) {
5548 tp_features
.fan_ctrl_status_undef
= 0;
5550 status
= TP_EC_FAN_AUTO
;
5555 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
5556 status
= fan_control_desired_level
;
5561 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
5564 static ssize_t
fan_pwm1_store(struct device
*dev
,
5565 struct device_attribute
*attr
,
5566 const char *buf
, size_t count
)
5570 u8 status
, newlevel
;
5572 if (parse_strtoul(buf
, 255, &s
))
5575 /* scale down from 0-255 to 0-7 */
5576 newlevel
= (s
>> 5) & 0x07;
5578 if (mutex_lock_interruptible(&fan_mutex
))
5579 return -ERESTARTSYS
;
5581 rc
= fan_get_status(&status
);
5582 if (!rc
&& (status
&
5583 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
5584 rc
= fan_set_level(newlevel
);
5588 fan_update_desired_level(newlevel
);
5589 fan_watchdog_reset();
5593 mutex_unlock(&fan_mutex
);
5594 return (rc
)? rc
: count
;
5597 static struct device_attribute dev_attr_fan_pwm1
=
5598 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
5599 fan_pwm1_show
, fan_pwm1_store
);
5601 /* sysfs fan fan1_input ------------------------------------------------ */
5602 static ssize_t
fan_fan1_input_show(struct device
*dev
,
5603 struct device_attribute
*attr
,
5609 res
= fan_get_speed(&speed
);
5613 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
5616 static struct device_attribute dev_attr_fan_fan1_input
=
5617 __ATTR(fan1_input
, S_IRUGO
,
5618 fan_fan1_input_show
, NULL
);
5620 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
5621 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
5624 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
5627 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
5628 const char *buf
, size_t count
)
5632 if (parse_strtoul(buf
, 120, &t
))
5635 if (!fan_control_allowed
)
5638 fan_watchdog_maxinterval
= t
;
5639 fan_watchdog_reset();
5644 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
5645 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
5647 /* --------------------------------------------------------------------- */
5648 static struct attribute
*fan_attributes
[] = {
5649 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
5650 &dev_attr_fan_fan1_input
.attr
,
5654 static const struct attribute_group fan_attr_group
= {
5655 .attrs
= fan_attributes
,
5658 static int __init
fan_init(struct ibm_init_struct
*iibm
)
5662 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
5664 mutex_init(&fan_mutex
);
5665 fan_status_access_mode
= TPACPI_FAN_NONE
;
5666 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
5667 fan_control_commands
= 0;
5668 fan_watchdog_maxinterval
= 0;
5669 tp_features
.fan_ctrl_status_undef
= 0;
5670 fan_control_desired_level
= 7;
5672 TPACPI_ACPIHANDLE_INIT(fans
);
5673 TPACPI_ACPIHANDLE_INIT(gfan
);
5674 TPACPI_ACPIHANDLE_INIT(sfan
);
5677 /* 570, 600e/x, 770e, 770x */
5678 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
5680 /* all other ThinkPads: note that even old-style
5681 * ThinkPad ECs supports the fan control register */
5682 if (likely(acpi_ec_read(fan_status_offset
,
5683 &fan_control_initial_status
))) {
5684 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
5686 /* In some ThinkPads, neither the EC nor the ACPI
5687 * DSDT initialize the fan status, and it ends up
5688 * being set to 0x07 when it *could* be either
5691 * Enable for TP-1Y (T43), TP-78 (R51e),
5692 * TP-76 (R52), TP-70 (T43, R52), which are known
5694 if (fan_control_initial_status
== 0x07) {
5695 switch (thinkpad_id
.ec_model
) {
5696 case 0x5931: /* TP-1Y */
5697 case 0x3837: /* TP-78 */
5698 case 0x3637: /* TP-76 */
5699 case 0x3037: /* TP-70 */
5700 printk(TPACPI_NOTICE
5701 "fan_init: initial fan status "
5702 "is unknown, assuming it is "
5704 tp_features
.fan_ctrl_status_undef
= 1;
5710 "ThinkPad ACPI EC access misbehaving, "
5711 "fan status and control unavailable\n");
5718 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
5719 fan_control_commands
|=
5720 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
5723 /* gfan without sfan means no fan control */
5724 /* all other models implement TP EC 0x2f control */
5728 fan_control_access_mode
=
5729 TPACPI_FAN_WR_ACPI_FANS
;
5730 fan_control_commands
|=
5731 TPACPI_FAN_CMD_SPEED
|
5732 TPACPI_FAN_CMD_LEVEL
|
5733 TPACPI_FAN_CMD_ENABLE
;
5735 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
5736 fan_control_commands
|=
5737 TPACPI_FAN_CMD_LEVEL
|
5738 TPACPI_FAN_CMD_ENABLE
;
5743 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
5744 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
5745 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
5746 fan_status_access_mode
, fan_control_access_mode
);
5748 /* fan control master switch */
5749 if (!fan_control_allowed
) {
5750 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
5751 fan_control_commands
= 0;
5752 dbg_printk(TPACPI_DBG_INIT
,
5753 "fan control features disabled by parameter\n");
5756 /* update fan_control_desired_level */
5757 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
5758 fan_get_status_safe(NULL
);
5760 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
5761 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
5762 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5765 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
5766 &driver_attr_fan_watchdog
);
5774 static void fan_exit(void)
5776 vdbg_printk(TPACPI_DBG_EXIT
,
5777 "cancelling any pending fan watchdog tasks\n");
5779 /* FIXME: can we really do this unconditionally? */
5780 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
5781 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
5782 &driver_attr_fan_watchdog
);
5784 cancel_delayed_work(&fan_watchdog_task
);
5785 flush_scheduled_work();
5788 static int fan_read(char *p
)
5793 unsigned int speed
= 0;
5795 switch (fan_status_access_mode
) {
5796 case TPACPI_FAN_RD_ACPI_GFAN
:
5797 /* 570, 600e/x, 770e, 770x */
5798 rc
= fan_get_status_safe(&status
);
5802 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
5804 (status
!= 0) ? "enabled" : "disabled", status
);
5807 case TPACPI_FAN_RD_TPEC
:
5808 /* all except 570, 600e/x, 770e, 770x */
5809 rc
= fan_get_status_safe(&status
);
5813 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
5814 if (status
!= fan_control_initial_status
)
5815 tp_features
.fan_ctrl_status_undef
= 0;
5817 /* Return most likely status. In fact, it
5818 * might be the only possible status */
5819 status
= TP_EC_FAN_AUTO
;
5822 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
5823 (status
!= 0) ? "enabled" : "disabled");
5825 rc
= fan_get_speed(&speed
);
5829 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
5831 if (status
& TP_EC_FAN_FULLSPEED
)
5832 /* Disengaged mode takes precedence */
5833 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
5834 else if (status
& TP_EC_FAN_AUTO
)
5835 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
5837 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
5840 case TPACPI_FAN_NONE
:
5842 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
5845 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
5846 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
5848 switch (fan_control_access_mode
) {
5849 case TPACPI_FAN_WR_ACPI_SFAN
:
5850 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
5854 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
5855 "auto, disengaged, full-speed)\n");
5860 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
5861 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
5862 "commands:\twatchdog <timeout> (<timeout> "
5863 "is 0 (off), 1-120 (seconds))\n");
5865 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
5866 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
5867 " (<speed> is 0-65535)\n");
5872 static int fan_write_cmd_level(const char *cmd
, int *rc
)
5876 if (strlencmp(cmd
, "level auto") == 0)
5877 level
= TP_EC_FAN_AUTO
;
5878 else if ((strlencmp(cmd
, "level disengaged") == 0) |
5879 (strlencmp(cmd
, "level full-speed") == 0))
5880 level
= TP_EC_FAN_FULLSPEED
;
5881 else if (sscanf(cmd
, "level %d", &level
) != 1)
5884 *rc
= fan_set_level_safe(level
);
5886 printk(TPACPI_ERR
"level command accepted for unsupported "
5887 "access mode %d", fan_control_access_mode
);
5892 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
5894 if (strlencmp(cmd
, "enable") != 0)
5897 *rc
= fan_set_enable();
5899 printk(TPACPI_ERR
"enable command accepted for unsupported "
5900 "access mode %d", fan_control_access_mode
);
5905 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
5907 if (strlencmp(cmd
, "disable") != 0)
5910 *rc
= fan_set_disable();
5912 printk(TPACPI_ERR
"disable command accepted for unsupported "
5913 "access mode %d", fan_control_access_mode
);
5918 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
5923 * Support speed <low> <medium> <high> ? */
5925 if (sscanf(cmd
, "speed %d", &speed
) != 1)
5928 *rc
= fan_set_speed(speed
);
5930 printk(TPACPI_ERR
"speed command accepted for unsupported "
5931 "access mode %d", fan_control_access_mode
);
5936 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
5940 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
5943 if (interval
< 0 || interval
> 120)
5946 fan_watchdog_maxinterval
= interval
;
5951 static int fan_write(char *buf
)
5956 while (!rc
&& (cmd
= next_cmd(&buf
))) {
5957 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
5958 fan_write_cmd_level(cmd
, &rc
)) &&
5959 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
5960 (fan_write_cmd_enable(cmd
, &rc
) ||
5961 fan_write_cmd_disable(cmd
, &rc
) ||
5962 fan_write_cmd_watchdog(cmd
, &rc
))) &&
5963 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
5964 fan_write_cmd_speed(cmd
, &rc
))
5968 fan_watchdog_reset();
5974 static struct ibm_struct fan_driver_data
= {
5981 /****************************************************************************
5982 ****************************************************************************
5986 ****************************************************************************
5987 ****************************************************************************/
5989 /* sysfs name ---------------------------------------------------------- */
5990 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
5991 struct device_attribute
*attr
,
5994 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
5997 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
5998 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
6000 /* --------------------------------------------------------------------- */
6003 static struct proc_dir_entry
*proc_dir
;
6006 * Module and infrastructure proble, init and exit handling
6009 static int force_load
;
6011 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
6012 static const char * __init
str_supported(int is_supported
)
6014 static char text_unsupported
[] __initdata
= "not supported";
6016 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
6018 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
6020 static void ibm_exit(struct ibm_struct
*ibm
)
6022 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
6024 list_del_init(&ibm
->all_drivers
);
6026 if (ibm
->flags
.acpi_notify_installed
) {
6027 dbg_printk(TPACPI_DBG_EXIT
,
6028 "%s: acpi_remove_notify_handler\n", ibm
->name
);
6030 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
6032 dispatch_acpi_notify
);
6033 ibm
->flags
.acpi_notify_installed
= 0;
6034 ibm
->flags
.acpi_notify_installed
= 0;
6037 if (ibm
->flags
.proc_created
) {
6038 dbg_printk(TPACPI_DBG_EXIT
,
6039 "%s: remove_proc_entry\n", ibm
->name
);
6040 remove_proc_entry(ibm
->name
, proc_dir
);
6041 ibm
->flags
.proc_created
= 0;
6044 if (ibm
->flags
.acpi_driver_registered
) {
6045 dbg_printk(TPACPI_DBG_EXIT
,
6046 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
6048 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
6049 kfree(ibm
->acpi
->driver
);
6050 ibm
->acpi
->driver
= NULL
;
6051 ibm
->flags
.acpi_driver_registered
= 0;
6054 if (ibm
->flags
.init_called
&& ibm
->exit
) {
6056 ibm
->flags
.init_called
= 0;
6059 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
6062 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
6065 struct ibm_struct
*ibm
= iibm
->data
;
6066 struct proc_dir_entry
*entry
;
6068 BUG_ON(ibm
== NULL
);
6070 INIT_LIST_HEAD(&ibm
->all_drivers
);
6072 if (ibm
->flags
.experimental
&& !experimental
)
6075 dbg_printk(TPACPI_DBG_INIT
,
6076 "probing for %s\n", ibm
->name
);
6079 ret
= iibm
->init(iibm
);
6081 return 0; /* probe failed */
6085 ibm
->flags
.init_called
= 1;
6089 if (ibm
->acpi
->hid
) {
6090 ret
= register_tpacpi_subdriver(ibm
);
6095 if (ibm
->acpi
->notify
) {
6096 ret
= setup_acpi_notify(ibm
);
6097 if (ret
== -ENODEV
) {
6098 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
6108 dbg_printk(TPACPI_DBG_INIT
,
6109 "%s installed\n", ibm
->name
);
6112 entry
= create_proc_entry(ibm
->name
,
6113 S_IFREG
| S_IRUGO
| S_IWUSR
,
6116 printk(TPACPI_ERR
"unable to create proc entry %s\n",
6121 entry
->owner
= THIS_MODULE
;
6123 entry
->read_proc
= &dispatch_procfs_read
;
6125 entry
->write_proc
= &dispatch_procfs_write
;
6126 ibm
->flags
.proc_created
= 1;
6129 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
6134 dbg_printk(TPACPI_DBG_INIT
,
6135 "%s: at error exit path with result %d\n",
6139 return (ret
< 0)? ret
: 0;
6144 static void __init
get_thinkpad_model_data(struct thinkpad_id_data
*tp
)
6146 const struct dmi_device
*dev
= NULL
;
6147 char ec_fw_string
[18];
6152 memset(tp
, 0, sizeof(*tp
));
6154 if (dmi_name_in_vendors("IBM"))
6155 tp
->vendor
= PCI_VENDOR_ID_IBM
;
6156 else if (dmi_name_in_vendors("LENOVO"))
6157 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
6161 tp
->bios_version_str
= kstrdup(dmi_get_system_info(DMI_BIOS_VERSION
),
6163 if (!tp
->bios_version_str
)
6165 tp
->bios_model
= tp
->bios_version_str
[0]
6166 | (tp
->bios_version_str
[1] << 8);
6169 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
6170 * X32 or newer, all Z series; Some models must have an
6171 * up-to-date BIOS or they will not be detected.
6173 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
6175 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
6176 if (sscanf(dev
->name
,
6177 "IBM ThinkPad Embedded Controller -[%17c",
6178 ec_fw_string
) == 1) {
6179 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
6180 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
6182 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
6183 tp
->ec_model
= ec_fw_string
[0]
6184 | (ec_fw_string
[1] << 8);
6189 tp
->model_str
= kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION
),
6191 if (strnicmp(tp
->model_str
, "ThinkPad", 8) != 0) {
6192 kfree(tp
->model_str
);
6193 tp
->model_str
= NULL
;
6196 tp
->nummodel_str
= kstrdup(dmi_get_system_info(DMI_PRODUCT_NAME
),
6200 static int __init
probe_for_thinkpad(void)
6208 * Non-ancient models have better DMI tagging, but very old models
6211 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
6213 /* ec is required because many other handles are relative to it */
6214 TPACPI_ACPIHANDLE_INIT(ec
);
6218 "Not yet supported ThinkPad detected!\n");
6223 * Risks a regression on very old machines, but reduces potential
6224 * false positives a damn great deal
6227 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
6229 if (!is_thinkpad
&& !force_load
)
6236 /* Module init, exit, parameters */
6238 static struct ibm_init_struct ibms_init
[] __initdata
= {
6240 .init
= thinkpad_acpi_driver_init
,
6241 .data
= &thinkpad_acpi_driver_data
,
6244 .init
= hotkey_init
,
6245 .data
= &hotkey_driver_data
,
6248 .init
= bluetooth_init
,
6249 .data
= &bluetooth_driver_data
,
6253 .data
= &wan_driver_data
,
6255 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
6258 .data
= &video_driver_data
,
6263 .data
= &light_driver_data
,
6265 #ifdef CONFIG_THINKPAD_ACPI_DOCK
6268 .data
= &dock_driver_data
[0],
6272 .data
= &dock_driver_data
[1],
6275 #ifdef CONFIG_THINKPAD_ACPI_BAY
6278 .data
= &bay_driver_data
,
6283 .data
= &cmos_driver_data
,
6287 .data
= &led_driver_data
,
6291 .data
= &beep_driver_data
,
6294 .init
= thermal_init
,
6295 .data
= &thermal_driver_data
,
6298 .data
= &ecdump_driver_data
,
6301 .init
= brightness_init
,
6302 .data
= &brightness_driver_data
,
6305 .data
= &volume_driver_data
,
6309 .data
= &fan_driver_data
,
6313 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
6316 struct ibm_struct
*ibm
;
6318 if (!kp
|| !kp
->name
|| !val
)
6321 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
6322 ibm
= ibms_init
[i
].data
;
6323 WARN_ON(ibm
== NULL
);
6325 if (!ibm
|| !ibm
->name
)
6328 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
6329 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
6331 strcpy(ibms_init
[i
].param
, val
);
6332 strcat(ibms_init
[i
].param
, ",");
6340 module_param(experimental
, int, 0);
6341 MODULE_PARM_DESC(experimental
,
6342 "Enables experimental features when non-zero");
6344 module_param_named(debug
, dbg_level
, uint
, 0);
6345 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
6347 module_param(force_load
, bool, 0);
6348 MODULE_PARM_DESC(force_load
,
6349 "Attempts to load the driver even on a "
6350 "mis-identified ThinkPad when true");
6352 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
6353 MODULE_PARM_DESC(fan_control
,
6354 "Enables setting fan parameters features when true");
6356 module_param_named(brightness_mode
, brightness_mode
, int, 0);
6357 MODULE_PARM_DESC(brightness_mode
,
6358 "Selects brightness control strategy: "
6359 "0=auto, 1=EC, 2=CMOS, 3=both");
6361 module_param(brightness_enable
, uint
, 0);
6362 MODULE_PARM_DESC(brightness_enable
,
6363 "Enables backlight control when 1, disables when 0");
6365 module_param(hotkey_report_mode
, uint
, 0);
6366 MODULE_PARM_DESC(hotkey_report_mode
,
6367 "used for backwards compatibility with userspace, "
6368 "see documentation");
6370 #define TPACPI_PARAM(feature) \
6371 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
6372 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
6373 "at module load, see documentation")
6375 TPACPI_PARAM(hotkey
);
6376 TPACPI_PARAM(bluetooth
);
6377 TPACPI_PARAM(video
);
6378 TPACPI_PARAM(light
);
6379 #ifdef CONFIG_THINKPAD_ACPI_DOCK
6382 #ifdef CONFIG_THINKPAD_ACPI_BAY
6384 #endif /* CONFIG_THINKPAD_ACPI_BAY */
6388 TPACPI_PARAM(ecdump
);
6389 TPACPI_PARAM(brightness
);
6390 TPACPI_PARAM(volume
);
6393 static void thinkpad_acpi_module_exit(void)
6395 struct ibm_struct
*ibm
, *itmp
;
6397 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
6399 list_for_each_entry_safe_reverse(ibm
, itmp
,
6400 &tpacpi_all_drivers
,
6405 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
6407 if (tpacpi_inputdev
) {
6408 if (tp_features
.input_device_registered
)
6409 input_unregister_device(tpacpi_inputdev
);
6411 input_free_device(tpacpi_inputdev
);
6415 hwmon_device_unregister(tpacpi_hwmon
);
6417 if (tp_features
.sensors_pdev_attrs_registered
)
6418 device_remove_file(&tpacpi_sensors_pdev
->dev
,
6419 &dev_attr_thinkpad_acpi_pdev_name
);
6420 if (tpacpi_sensors_pdev
)
6421 platform_device_unregister(tpacpi_sensors_pdev
);
6423 platform_device_unregister(tpacpi_pdev
);
6425 if (tp_features
.sensors_pdrv_attrs_registered
)
6426 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
6427 if (tp_features
.platform_drv_attrs_registered
)
6428 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
6430 if (tp_features
.sensors_pdrv_registered
)
6431 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
6433 if (tp_features
.platform_drv_registered
)
6434 platform_driver_unregister(&tpacpi_pdriver
);
6437 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
6439 kfree(thinkpad_id
.bios_version_str
);
6440 kfree(thinkpad_id
.ec_version_str
);
6441 kfree(thinkpad_id
.model_str
);
6445 static int __init
thinkpad_acpi_module_init(void)
6449 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
6451 /* Parameter checking */
6452 if (hotkey_report_mode
> 2)
6455 /* Driver-level probe */
6457 get_thinkpad_model_data(&thinkpad_id
);
6458 ret
= probe_for_thinkpad();
6460 thinkpad_acpi_module_exit();
6464 /* Driver initialization */
6466 TPACPI_ACPIHANDLE_INIT(ecrd
);
6467 TPACPI_ACPIHANDLE_INIT(ecwr
);
6469 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
6472 "unable to create proc dir " TPACPI_PROC_DIR
);
6473 thinkpad_acpi_module_exit();
6476 proc_dir
->owner
= THIS_MODULE
;
6478 ret
= platform_driver_register(&tpacpi_pdriver
);
6481 "unable to register main platform driver\n");
6482 thinkpad_acpi_module_exit();
6485 tp_features
.platform_drv_registered
= 1;
6487 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
6490 "unable to register hwmon platform driver\n");
6491 thinkpad_acpi_module_exit();
6494 tp_features
.sensors_pdrv_registered
= 1;
6496 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
6498 tp_features
.platform_drv_attrs_registered
= 1;
6499 ret
= tpacpi_create_driver_attributes(
6500 &tpacpi_hwmon_pdriver
.driver
);
6504 "unable to create sysfs driver attributes\n");
6505 thinkpad_acpi_module_exit();
6508 tp_features
.sensors_pdrv_attrs_registered
= 1;
6511 /* Device initialization */
6512 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
6514 if (IS_ERR(tpacpi_pdev
)) {
6515 ret
= PTR_ERR(tpacpi_pdev
);
6517 printk(TPACPI_ERR
"unable to register platform device\n");
6518 thinkpad_acpi_module_exit();
6521 tpacpi_sensors_pdev
= platform_device_register_simple(
6522 TPACPI_HWMON_DRVR_NAME
,
6524 if (IS_ERR(tpacpi_sensors_pdev
)) {
6525 ret
= PTR_ERR(tpacpi_sensors_pdev
);
6526 tpacpi_sensors_pdev
= NULL
;
6528 "unable to register hwmon platform device\n");
6529 thinkpad_acpi_module_exit();
6532 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
6533 &dev_attr_thinkpad_acpi_pdev_name
);
6536 "unable to create sysfs hwmon device attributes\n");
6537 thinkpad_acpi_module_exit();
6540 tp_features
.sensors_pdev_attrs_registered
= 1;
6541 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
6542 if (IS_ERR(tpacpi_hwmon
)) {
6543 ret
= PTR_ERR(tpacpi_hwmon
);
6544 tpacpi_hwmon
= NULL
;
6545 printk(TPACPI_ERR
"unable to register hwmon device\n");
6546 thinkpad_acpi_module_exit();
6549 mutex_init(&tpacpi_inputdev_send_mutex
);
6550 tpacpi_inputdev
= input_allocate_device();
6551 if (!tpacpi_inputdev
) {
6552 printk(TPACPI_ERR
"unable to allocate input device\n");
6553 thinkpad_acpi_module_exit();
6556 /* Prepare input device, but don't register */
6557 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
6558 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
6559 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
6560 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
6561 thinkpad_id
.vendor
:
6563 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
6564 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
6566 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
6567 ret
= ibm_init(&ibms_init
[i
]);
6568 if (ret
>= 0 && *ibms_init
[i
].param
)
6569 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
6571 thinkpad_acpi_module_exit();
6575 ret
= input_register_device(tpacpi_inputdev
);
6577 printk(TPACPI_ERR
"unable to register input device\n");
6578 thinkpad_acpi_module_exit();
6581 tp_features
.input_device_registered
= 1;
6584 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
6588 /* Please remove this in year 2009 */
6589 MODULE_ALIAS("ibm_acpi");
6591 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME
);
6594 * DMI matching for module autoloading
6596 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
6597 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
6599 * Only models listed in thinkwiki will be supported, so add yours
6600 * if it is not there yet.
6602 #define IBM_BIOS_MODULE_ALIAS(__type) \
6603 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW")
6605 /* Non-ancient thinkpads */
6606 MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*");
6607 MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*");
6609 /* Ancient thinkpad BIOSes have to be identified by
6610 * BIOS type or model number, and there are far less
6611 * BIOS types than model numbers... */
6612 IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]");
6613 IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]");
6614 IBM_BIOS_MODULE_ALIAS("K[U,X-Z]");
6616 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
6617 MODULE_DESCRIPTION(TPACPI_DESC
);
6618 MODULE_VERSION(TPACPI_VERSION
);
6619 MODULE_LICENSE("GPL");
6621 module_init(thinkpad_acpi_module_init
);
6622 module_exit(thinkpad_acpi_module_exit
);