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_END };
51 static struct key_entry dell_wmi_keymap[] = {
52 {KE_KEY, 0xe045, KEY_PROG1},
56 static struct input_dev *dell_wmi_input_dev;
58 static struct key_entry *dell_wmi_get_entry_by_scancode(int code)
60 struct key_entry *key;
62 for (key = dell_wmi_keymap; key->type != KE_END; key++)
63 if (code == key->code)
69 static struct key_entry *dell_wmi_get_entry_by_keycode(int keycode)
71 struct key_entry *key;
73 for (key = dell_wmi_keymap; key->type != KE_END; key++)
74 if (key->type == KE_KEY && keycode == key->keycode)
80 static int dell_wmi_getkeycode(struct input_dev *dev, int scancode,
83 struct key_entry *key = dell_wmi_get_entry_by_scancode(scancode);
85 if (key && key->type == KE_KEY) {
86 *keycode = key->keycode;
93 static int dell_wmi_setkeycode(struct input_dev *dev, int scancode, int keycode)
95 struct key_entry *key;
98 if (keycode < 0 || keycode > KEY_MAX)
101 key = dell_wmi_get_entry_by_scancode(scancode);
102 if (key && key->type == KE_KEY) {
103 old_keycode = key->keycode;
104 key->keycode = keycode;
105 set_bit(keycode, dev->keybit);
106 if (!dell_wmi_get_entry_by_keycode(old_keycode))
107 clear_bit(old_keycode, dev->keybit);
113 static void dell_wmi_notify(u32 value, void *context)
115 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
116 static struct key_entry *key;
117 union acpi_object *obj;
119 wmi_get_event_data(value, &response);
121 obj = (union acpi_object *)response.pointer;
123 if (obj && obj->type == ACPI_TYPE_BUFFER) {
124 int *buffer = (int *)obj->buffer.pointer;
125 key = dell_wmi_get_entry_by_scancode(buffer[1]);
127 input_report_key(dell_wmi_input_dev, key->keycode, 1);
128 input_sync(dell_wmi_input_dev);
129 input_report_key(dell_wmi_input_dev, key->keycode, 0);
130 input_sync(dell_wmi_input_dev);
132 printk(KERN_INFO "dell-wmi: Unknown key %x pressed\n",
137 static int __init dell_wmi_input_setup(void)
139 struct key_entry *key;
142 dell_wmi_input_dev = input_allocate_device();
144 if (!dell_wmi_input_dev)
147 dell_wmi_input_dev->name = "Dell WMI hotkeys";
148 dell_wmi_input_dev->phys = "wmi/input0";
149 dell_wmi_input_dev->id.bustype = BUS_HOST;
150 dell_wmi_input_dev->getkeycode = dell_wmi_getkeycode;
151 dell_wmi_input_dev->setkeycode = dell_wmi_setkeycode;
153 for (key = dell_wmi_keymap; key->type != KE_END; key++) {
156 set_bit(EV_KEY, dell_wmi_input_dev->evbit);
157 set_bit(key->keycode, dell_wmi_input_dev->keybit);
160 set_bit(EV_SW, dell_wmi_input_dev->evbit);
161 set_bit(key->keycode, dell_wmi_input_dev->swbit);
166 err = input_register_device(dell_wmi_input_dev);
169 input_free_device(dell_wmi_input_dev);
176 static int __init dell_wmi_init(void)
180 if (wmi_has_guid(DELL_EVENT_GUID)) {
181 err = dell_wmi_input_setup();
186 err = wmi_install_notify_handler(DELL_EVENT_GUID,
187 dell_wmi_notify, NULL);
189 input_unregister_device(dell_wmi_input_dev);
190 printk(KERN_ERR "dell-wmi: Unable to register"
191 " notify handler - %d\n", err);
196 printk(KERN_WARNING "dell-wmi: No known WMI GUID found\n");
201 static void __exit dell_wmi_exit(void)
203 if (wmi_has_guid(DELL_EVENT_GUID)) {
204 wmi_remove_notify_handler(DELL_EVENT_GUID);
205 input_unregister_device(dell_wmi_input_dev);
209 module_init(dell_wmi_init);
210 module_exit(dell_wmi_exit);