aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/platform/x86/eeepc-wmi.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/platform/x86/eeepc-wmi.c')
-rw-r--r--drivers/platform/x86/eeepc-wmi.c158
1 files changed, 158 insertions, 0 deletions
diff --git a/drivers/platform/x86/eeepc-wmi.c b/drivers/platform/x86/eeepc-wmi.c
new file mode 100644
index 000000000000..9f8822658fd7
--- /dev/null
+++ b/drivers/platform/x86/eeepc-wmi.c
@@ -0,0 +1,158 @@
1/*
2 * Eee PC WMI hotkey driver
3 *
4 * Copyright(C) 2010 Intel Corporation.
5 *
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>
10 *
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.
15 *
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.
20 *
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
24 */
25
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/init.h>
29#include <linux/types.h>
30#include <linux/slab.h>
31#include <linux/input.h>
32#include <linux/input/sparse-keymap.h>
33#include <acpi/acpi_bus.h>
34#include <acpi/acpi_drivers.h>
35
36MODULE_AUTHOR("Yong Wang <yong.y.wang@intel.com>");
37MODULE_DESCRIPTION("Eee PC WMI Hotkey Driver");
38MODULE_LICENSE("GPL");
39
40#define EEEPC_WMI_EVENT_GUID "ABBC0F72-8EA1-11D1-00A0-C90629100000"
41
42MODULE_ALIAS("wmi:"EEEPC_WMI_EVENT_GUID);
43
44#define NOTIFY_BRNUP_MIN 0x11
45#define NOTIFY_BRNUP_MAX 0x1f
46#define NOTIFY_BRNDOWN_MIN 0x20
47#define NOTIFY_BRNDOWN_MAX 0x2e
48
49static const struct key_entry eeepc_wmi_keymap[] = {
50 /* Sleep already handled via generic ACPI code */
51 { KE_KEY, 0x5d, { KEY_WLAN } },
52 { KE_KEY, 0x32, { KEY_MUTE } },
53 { KE_KEY, 0x31, { KEY_VOLUMEDOWN } },
54 { KE_KEY, 0x30, { KEY_VOLUMEUP } },
55 { KE_IGNORE, NOTIFY_BRNDOWN_MIN, { KEY_BRIGHTNESSDOWN } },
56 { KE_IGNORE, NOTIFY_BRNUP_MIN, { KEY_BRIGHTNESSUP } },
57 { KE_KEY, 0xcc, { KEY_SWITCHVIDEOMODE } },
58 { KE_END, 0},
59};
60
61static struct input_dev *eeepc_wmi_input_dev;
62
63static void eeepc_wmi_notify(u32 value, void *context)
64{
65 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
66 union acpi_object *obj;
67 acpi_status status;
68 int code;
69
70 status = wmi_get_event_data(value, &response);
71 if (status != AE_OK) {
72 pr_err("EEEPC WMI: bad event status 0x%x\n", status);
73 return;
74 }
75
76 obj = (union acpi_object *)response.pointer;
77
78 if (obj && obj->type == ACPI_TYPE_INTEGER) {
79 code = obj->integer.value;
80
81 if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX)
82 code = NOTIFY_BRNUP_MIN;
83 else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX)
84 code = NOTIFY_BRNDOWN_MIN;
85
86 if (!sparse_keymap_report_event(eeepc_wmi_input_dev,
87 code, 1, true))
88 pr_info("EEEPC WMI: Unknown key %x pressed\n", code);
89 }
90
91 kfree(obj);
92}
93
94static int eeepc_wmi_input_setup(void)
95{
96 int err;
97
98 eeepc_wmi_input_dev = input_allocate_device();
99 if (!eeepc_wmi_input_dev)
100 return -ENOMEM;
101
102 eeepc_wmi_input_dev->name = "Eee PC WMI hotkeys";
103 eeepc_wmi_input_dev->phys = "wmi/input0";
104 eeepc_wmi_input_dev->id.bustype = BUS_HOST;
105
106 err = sparse_keymap_setup(eeepc_wmi_input_dev, eeepc_wmi_keymap, NULL);
107 if (err)
108 goto err_free_dev;
109
110 err = input_register_device(eeepc_wmi_input_dev);
111 if (err)
112 goto err_free_keymap;
113
114 return 0;
115
116err_free_keymap:
117 sparse_keymap_free(eeepc_wmi_input_dev);
118err_free_dev:
119 input_free_device(eeepc_wmi_input_dev);
120 return err;
121}
122
123static int __init eeepc_wmi_init(void)
124{
125 int err;
126 acpi_status status;
127
128 if (!wmi_has_guid(EEEPC_WMI_EVENT_GUID)) {
129 pr_warning("EEEPC WMI: No known WMI GUID found\n");
130 return -ENODEV;
131 }
132
133 err = eeepc_wmi_input_setup();
134 if (err)
135 return err;
136
137 status = wmi_install_notify_handler(EEEPC_WMI_EVENT_GUID,
138 eeepc_wmi_notify, NULL);
139 if (ACPI_FAILURE(status)) {
140 sparse_keymap_free(eeepc_wmi_input_dev);
141 input_unregister_device(eeepc_wmi_input_dev);
142 pr_err("EEEPC WMI: Unable to register notify handler - %d\n",
143 status);
144 return -ENODEV;
145 }
146
147 return 0;
148}
149
150static void __exit eeepc_wmi_exit(void)
151{
152 wmi_remove_notify_handler(EEEPC_WMI_EVENT_GUID);
153 sparse_keymap_free(eeepc_wmi_input_dev);
154 input_unregister_device(eeepc_wmi_input_dev);
155}
156
157module_init(eeepc_wmi_init);
158module_exit(eeepc_wmi_exit);