2 * Eee PC WMI hotkey driver
4 * Copyright(C) 2010 Intel Corporation.
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 <linux/input/sparse-keymap.h>
32 #include <acpi/acpi_bus.h>
33 #include <acpi/acpi_drivers.h>
35 MODULE_AUTHOR("Yong Wang <yong.y.wang@intel.com>");
36 MODULE_DESCRIPTION("Eee PC WMI Hotkey Driver");
37 MODULE_LICENSE("GPL");
39 #define EEEPC_WMI_EVENT_GUID "ABBC0F72-8EA1-11D1-00A0-C90629100000"
41 MODULE_ALIAS("wmi:"EEEPC_WMI_EVENT_GUID);
43 #define NOTIFY_BRNUP_MIN 0x11
44 #define NOTIFY_BRNUP_MAX 0x1f
45 #define NOTIFY_BRNDOWN_MIN 0x20
46 #define NOTIFY_BRNDOWN_MAX 0x2e
48 static const struct key_entry eeepc_wmi_keymap[] = {
49 /* Sleep already handled via generic ACPI code */
50 { KE_KEY, 0x5d, { KEY_WLAN } },
51 { KE_KEY, 0x32, { KEY_MUTE } },
52 { KE_KEY, 0x31, { KEY_VOLUMEDOWN } },
53 { KE_KEY, 0x30, { KEY_VOLUMEUP } },
54 { KE_IGNORE, NOTIFY_BRNDOWN_MIN, { KEY_BRIGHTNESSDOWN } },
55 { KE_IGNORE, NOTIFY_BRNUP_MIN, { KEY_BRIGHTNESSUP } },
56 { KE_KEY, 0xcc, { KEY_SWITCHVIDEOMODE } },
60 static struct input_dev *eeepc_wmi_input_dev;
62 static void eeepc_wmi_notify(u32 value, void *context)
64 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
65 union acpi_object *obj;
69 status = wmi_get_event_data(value, &response);
70 if (status != AE_OK) {
71 pr_err("EEEPC WMI: bad event status 0x%x\n", status);
75 obj = (union acpi_object *)response.pointer;
77 if (obj && obj->type == ACPI_TYPE_INTEGER) {
78 code = obj->integer.value;
80 if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX)
81 code = NOTIFY_BRNUP_MIN;
82 else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX)
83 code = NOTIFY_BRNDOWN_MIN;
85 if (!sparse_keymap_report_event(eeepc_wmi_input_dev,
87 pr_info("EEEPC WMI: Unknown key %x pressed\n", code);
93 static int eeepc_wmi_input_setup(void)
97 eeepc_wmi_input_dev = input_allocate_device();
98 if (!eeepc_wmi_input_dev)
101 eeepc_wmi_input_dev->name = "Eee PC WMI hotkeys";
102 eeepc_wmi_input_dev->phys = "wmi/input0";
103 eeepc_wmi_input_dev->id.bustype = BUS_HOST;
105 err = sparse_keymap_setup(eeepc_wmi_input_dev, eeepc_wmi_keymap, NULL);
109 err = input_register_device(eeepc_wmi_input_dev);
111 goto err_free_keymap;
116 sparse_keymap_free(eeepc_wmi_input_dev);
118 input_free_device(eeepc_wmi_input_dev);
122 static int __init eeepc_wmi_init(void)
127 if (!wmi_has_guid(EEEPC_WMI_EVENT_GUID)) {
128 pr_warning("EEEPC WMI: No known WMI GUID found\n");
132 err = eeepc_wmi_input_setup();
136 status = wmi_install_notify_handler(EEEPC_WMI_EVENT_GUID,
137 eeepc_wmi_notify, NULL);
138 if (ACPI_FAILURE(status)) {
139 sparse_keymap_free(eeepc_wmi_input_dev);
140 input_unregister_device(eeepc_wmi_input_dev);
141 pr_err("EEEPC WMI: Unable to register notify handler - %d\n",
149 static void __exit eeepc_wmi_exit(void)
151 wmi_remove_notify_handler(EEEPC_WMI_EVENT_GUID);
152 sparse_keymap_free(eeepc_wmi_input_dev);
153 input_unregister_device(eeepc_wmi_input_dev);
156 module_init(eeepc_wmi_init);
157 module_exit(eeepc_wmi_exit);