4 * Copyright (C) 2008 Red Hat <mjg@redhat.com>
6 * Portions based on wistron_btns.c:
7 * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz>
8 * Copyright (C) 2005 Bernhard Rosenkraenzer <bero@arklinux.org>
9 * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/kernel.h>
27 #include <linux/module.h>
28 #include <linux/init.h>
29 #include <linux/types.h>
30 #include <linux/input.h>
31 #include <acpi/acpi_drivers.h>
32 #include <linux/acpi.h>
33 #include <linux/string.h>
35 MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
36 MODULE_DESCRIPTION("Dell laptop WMI hotkeys driver");
37 MODULE_LICENSE("GPL");
39 #define DELL_EVENT_GUID "9DBB5994-A997-11DA-B012-B622A1EF5492"
41 MODULE_ALIAS("wmi:"DELL_EVENT_GUID
);
44 char type
; /* See KE_* below */
49 enum { KE_KEY
, KE_SW
, KE_IGNORE
, KE_END
};
52 * Certain keys are flagged as KE_IGNORE. All of these are either
53 * notifications (rather than requests for change) or are also sent
54 * via the keyboard controller so should not be sent again.
57 static struct key_entry dell_wmi_keymap
[] = {
58 {KE_KEY
, 0xe045, KEY_PROG1
},
59 {KE_KEY
, 0xe009, KEY_EJECTCD
},
61 /* These also contain the brightness level at offset 6 */
62 {KE_KEY
, 0xe006, KEY_BRIGHTNESSUP
},
63 {KE_KEY
, 0xe005, KEY_BRIGHTNESSDOWN
},
65 /* Battery health status button */
66 {KE_KEY
, 0xe007, KEY_BATTERY
},
68 /* This is actually for all radios. Although physically a
69 * switch, the notification does not provide an indication of
70 * state and so it should be reported as a key */
71 {KE_KEY
, 0xe008, KEY_WLAN
},
73 /* The next device is at offset 6, the active devices are at
74 offset 8 and the attached devices at offset 10 */
75 {KE_KEY
, 0xe00b, KEY_DISPLAYTOGGLE
},
77 {KE_IGNORE
, 0xe00c, KEY_KBDILLUMTOGGLE
},
79 /* BIOS error detected */
80 {KE_IGNORE
, 0xe00d, KEY_RESERVED
},
83 {KE_KEY
, 0xe011, KEY_PROG2
},
85 /* Ambient light sensor toggle */
86 {KE_IGNORE
, 0xe013, KEY_RESERVED
},
88 {KE_IGNORE
, 0xe020, KEY_MUTE
},
89 {KE_IGNORE
, 0xe02e, KEY_VOLUMEDOWN
},
90 {KE_IGNORE
, 0xe030, KEY_VOLUMEUP
},
91 {KE_IGNORE
, 0xe033, KEY_KBDILLUMUP
},
92 {KE_IGNORE
, 0xe034, KEY_KBDILLUMDOWN
},
93 {KE_IGNORE
, 0xe03a, KEY_CAPSLOCK
},
94 {KE_IGNORE
, 0xe045, KEY_NUMLOCK
},
95 {KE_IGNORE
, 0xe046, KEY_SCROLLLOCK
},
99 static struct input_dev
*dell_wmi_input_dev
;
101 static struct key_entry
*dell_wmi_get_entry_by_scancode(int code
)
103 struct key_entry
*key
;
105 for (key
= dell_wmi_keymap
; key
->type
!= KE_END
; key
++)
106 if (code
== key
->code
)
112 static struct key_entry
*dell_wmi_get_entry_by_keycode(int keycode
)
114 struct key_entry
*key
;
116 for (key
= dell_wmi_keymap
; key
->type
!= KE_END
; key
++)
117 if (key
->type
== KE_KEY
&& keycode
== key
->keycode
)
123 static int dell_wmi_getkeycode(struct input_dev
*dev
, int scancode
,
126 struct key_entry
*key
= dell_wmi_get_entry_by_scancode(scancode
);
128 if (key
&& key
->type
== KE_KEY
) {
129 *keycode
= key
->keycode
;
136 static int dell_wmi_setkeycode(struct input_dev
*dev
, int scancode
, int keycode
)
138 struct key_entry
*key
;
141 if (keycode
< 0 || keycode
> KEY_MAX
)
144 key
= dell_wmi_get_entry_by_scancode(scancode
);
145 if (key
&& key
->type
== KE_KEY
) {
146 old_keycode
= key
->keycode
;
147 key
->keycode
= keycode
;
148 set_bit(keycode
, dev
->keybit
);
149 if (!dell_wmi_get_entry_by_keycode(old_keycode
))
150 clear_bit(old_keycode
, dev
->keybit
);
156 static void dell_wmi_notify(u32 value
, void *context
)
158 struct acpi_buffer response
= { ACPI_ALLOCATE_BUFFER
, NULL
};
159 static struct key_entry
*key
;
160 union acpi_object
*obj
;
162 wmi_get_event_data(value
, &response
);
164 obj
= (union acpi_object
*)response
.pointer
;
166 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
) {
167 int *buffer
= (int *)obj
->buffer
.pointer
;
169 * The upper bytes of the event may contain
170 * additional information, so mask them off for the
173 key
= dell_wmi_get_entry_by_scancode(buffer
[1] & 0xFFFF);
175 input_report_key(dell_wmi_input_dev
, key
->keycode
, 1);
176 input_sync(dell_wmi_input_dev
);
177 input_report_key(dell_wmi_input_dev
, key
->keycode
, 0);
178 input_sync(dell_wmi_input_dev
);
180 printk(KERN_INFO
"dell-wmi: Unknown key %x pressed\n",
185 static int __init
dell_wmi_input_setup(void)
187 struct key_entry
*key
;
190 dell_wmi_input_dev
= input_allocate_device();
192 if (!dell_wmi_input_dev
)
195 dell_wmi_input_dev
->name
= "Dell WMI hotkeys";
196 dell_wmi_input_dev
->phys
= "wmi/input0";
197 dell_wmi_input_dev
->id
.bustype
= BUS_HOST
;
198 dell_wmi_input_dev
->getkeycode
= dell_wmi_getkeycode
;
199 dell_wmi_input_dev
->setkeycode
= dell_wmi_setkeycode
;
201 for (key
= dell_wmi_keymap
; key
->type
!= KE_END
; key
++) {
204 set_bit(EV_KEY
, dell_wmi_input_dev
->evbit
);
205 set_bit(key
->keycode
, dell_wmi_input_dev
->keybit
);
208 set_bit(EV_SW
, dell_wmi_input_dev
->evbit
);
209 set_bit(key
->keycode
, dell_wmi_input_dev
->swbit
);
214 err
= input_register_device(dell_wmi_input_dev
);
217 input_free_device(dell_wmi_input_dev
);
224 static int __init
dell_wmi_init(void)
228 if (wmi_has_guid(DELL_EVENT_GUID
)) {
229 err
= dell_wmi_input_setup();
234 err
= wmi_install_notify_handler(DELL_EVENT_GUID
,
235 dell_wmi_notify
, NULL
);
237 input_unregister_device(dell_wmi_input_dev
);
238 printk(KERN_ERR
"dell-wmi: Unable to register"
239 " notify handler - %d\n", err
);
244 printk(KERN_WARNING
"dell-wmi: No known WMI GUID found\n");
249 static void __exit
dell_wmi_exit(void)
251 if (wmi_has_guid(DELL_EVENT_GUID
)) {
252 wmi_remove_notify_handler(DELL_EVENT_GUID
);
253 input_unregister_device(dell_wmi_input_dev
);
257 module_init(dell_wmi_init
);
258 module_exit(dell_wmi_exit
);