diff options
Diffstat (limited to 'drivers/platform/x86/dell-wmi.c')
-rw-r--r-- | drivers/platform/x86/dell-wmi.c | 256 |
1 files changed, 96 insertions, 160 deletions
diff --git a/drivers/platform/x86/dell-wmi.c b/drivers/platform/x86/dell-wmi.c index 08fb70f6d9bf..77f1d55414c6 100644 --- a/drivers/platform/x86/dell-wmi.c +++ b/drivers/platform/x86/dell-wmi.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <linux/slab.h> | 29 | #include <linux/slab.h> |
30 | #include <linux/types.h> | 30 | #include <linux/types.h> |
31 | #include <linux/input.h> | 31 | #include <linux/input.h> |
32 | #include <linux/input/sparse-keymap.h> | ||
32 | #include <acpi/acpi_drivers.h> | 33 | #include <acpi/acpi_drivers.h> |
33 | #include <linux/acpi.h> | 34 | #include <linux/acpi.h> |
34 | #include <linux/string.h> | 35 | #include <linux/string.h> |
@@ -44,78 +45,70 @@ static int acpi_video; | |||
44 | 45 | ||
45 | MODULE_ALIAS("wmi:"DELL_EVENT_GUID); | 46 | MODULE_ALIAS("wmi:"DELL_EVENT_GUID); |
46 | 47 | ||
47 | struct key_entry { | ||
48 | char type; /* See KE_* below */ | ||
49 | u16 code; | ||
50 | u16 keycode; | ||
51 | }; | ||
52 | |||
53 | enum { KE_KEY, KE_SW, KE_IGNORE, KE_END }; | ||
54 | |||
55 | /* | 48 | /* |
56 | * Certain keys are flagged as KE_IGNORE. All of these are either | 49 | * Certain keys are flagged as KE_IGNORE. All of these are either |
57 | * notifications (rather than requests for change) or are also sent | 50 | * notifications (rather than requests for change) or are also sent |
58 | * via the keyboard controller so should not be sent again. | 51 | * via the keyboard controller so should not be sent again. |
59 | */ | 52 | */ |
60 | 53 | ||
61 | static struct key_entry dell_legacy_wmi_keymap[] = { | 54 | static const struct key_entry dell_wmi_legacy_keymap[] __initconst = { |
62 | {KE_KEY, 0xe045, KEY_PROG1}, | 55 | { KE_KEY, 0xe045, { KEY_PROG1 } }, |
63 | {KE_KEY, 0xe009, KEY_EJECTCD}, | 56 | { KE_KEY, 0xe009, { KEY_EJECTCD } }, |
64 | 57 | ||
65 | /* These also contain the brightness level at offset 6 */ | 58 | /* These also contain the brightness level at offset 6 */ |
66 | {KE_KEY, 0xe006, KEY_BRIGHTNESSUP}, | 59 | { KE_KEY, 0xe006, { KEY_BRIGHTNESSUP } }, |
67 | {KE_KEY, 0xe005, KEY_BRIGHTNESSDOWN}, | 60 | { KE_KEY, 0xe005, { KEY_BRIGHTNESSDOWN } }, |
68 | 61 | ||
69 | /* Battery health status button */ | 62 | /* Battery health status button */ |
70 | {KE_KEY, 0xe007, KEY_BATTERY}, | 63 | { KE_KEY, 0xe007, { KEY_BATTERY } }, |
71 | 64 | ||
72 | /* This is actually for all radios. Although physically a | 65 | /* This is actually for all radios. Although physically a |
73 | * switch, the notification does not provide an indication of | 66 | * switch, the notification does not provide an indication of |
74 | * state and so it should be reported as a key */ | 67 | * state and so it should be reported as a key */ |
75 | {KE_KEY, 0xe008, KEY_WLAN}, | 68 | { KE_KEY, 0xe008, { KEY_WLAN } }, |
76 | 69 | ||
77 | /* The next device is at offset 6, the active devices are at | 70 | /* The next device is at offset 6, the active devices are at |
78 | offset 8 and the attached devices at offset 10 */ | 71 | offset 8 and the attached devices at offset 10 */ |
79 | {KE_KEY, 0xe00b, KEY_SWITCHVIDEOMODE}, | 72 | { KE_KEY, 0xe00b, { KEY_SWITCHVIDEOMODE } }, |
80 | 73 | ||
81 | {KE_IGNORE, 0xe00c, KEY_KBDILLUMTOGGLE}, | 74 | { KE_IGNORE, 0xe00c, { KEY_KBDILLUMTOGGLE } }, |
82 | 75 | ||
83 | /* BIOS error detected */ | 76 | /* BIOS error detected */ |
84 | {KE_IGNORE, 0xe00d, KEY_RESERVED}, | 77 | { KE_IGNORE, 0xe00d, { KEY_RESERVED } }, |
85 | 78 | ||
86 | /* Wifi Catcher */ | 79 | /* Wifi Catcher */ |
87 | {KE_KEY, 0xe011, KEY_PROG2}, | 80 | { KE_KEY, 0xe011, {KEY_PROG2 } }, |
88 | 81 | ||
89 | /* Ambient light sensor toggle */ | 82 | /* Ambient light sensor toggle */ |
90 | {KE_IGNORE, 0xe013, KEY_RESERVED}, | 83 | { KE_IGNORE, 0xe013, { KEY_RESERVED } }, |
91 | 84 | ||
92 | {KE_IGNORE, 0xe020, KEY_MUTE}, | 85 | { KE_IGNORE, 0xe020, { KEY_MUTE } }, |
93 | {KE_IGNORE, 0xe02e, KEY_VOLUMEDOWN}, | 86 | { KE_IGNORE, 0xe02e, { KEY_VOLUMEDOWN } }, |
94 | {KE_IGNORE, 0xe030, KEY_VOLUMEUP}, | 87 | { KE_IGNORE, 0xe030, { KEY_VOLUMEUP } }, |
95 | {KE_IGNORE, 0xe033, KEY_KBDILLUMUP}, | 88 | { KE_IGNORE, 0xe033, { KEY_KBDILLUMUP } }, |
96 | {KE_IGNORE, 0xe034, KEY_KBDILLUMDOWN}, | 89 | { KE_IGNORE, 0xe034, { KEY_KBDILLUMDOWN } }, |
97 | {KE_IGNORE, 0xe03a, KEY_CAPSLOCK}, | 90 | { KE_IGNORE, 0xe03a, { KEY_CAPSLOCK } }, |
98 | {KE_IGNORE, 0xe045, KEY_NUMLOCK}, | 91 | { KE_IGNORE, 0xe045, { KEY_NUMLOCK } }, |
99 | {KE_IGNORE, 0xe046, KEY_SCROLLLOCK}, | 92 | { KE_IGNORE, 0xe046, { KEY_SCROLLLOCK } }, |
100 | {KE_END, 0} | 93 | { KE_END, 0 } |
101 | }; | 94 | }; |
102 | 95 | ||
103 | static bool dell_new_hk_type; | 96 | static bool dell_new_hk_type; |
104 | 97 | ||
105 | struct dell_new_keymap_entry { | 98 | struct dell_bios_keymap_entry { |
106 | u16 scancode; | 99 | u16 scancode; |
107 | u16 keycode; | 100 | u16 keycode; |
108 | }; | 101 | }; |
109 | 102 | ||
110 | struct dell_hotkey_table { | 103 | struct dell_bios_hotkey_table { |
111 | struct dmi_header header; | 104 | struct dmi_header header; |
112 | struct dell_new_keymap_entry keymap[]; | 105 | struct dell_bios_keymap_entry keymap[]; |
113 | 106 | ||
114 | }; | 107 | }; |
115 | 108 | ||
116 | static struct key_entry *dell_new_wmi_keymap; | 109 | static const struct dell_bios_hotkey_table *dell_bios_hotkey_table; |
117 | 110 | ||
118 | static u16 bios_to_linux_keycode[256] = { | 111 | static const u16 bios_to_linux_keycode[256] __initconst = { |
119 | 112 | ||
120 | KEY_MEDIA, KEY_NEXTSONG, KEY_PLAYPAUSE, KEY_PREVIOUSSONG, | 113 | KEY_MEDIA, KEY_NEXTSONG, KEY_PLAYPAUSE, KEY_PREVIOUSSONG, |
121 | KEY_STOPCD, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, | 114 | KEY_STOPCD, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
@@ -138,68 +131,11 @@ static u16 bios_to_linux_keycode[256] = { | |||
138 | KEY_PROG3 | 131 | KEY_PROG3 |
139 | }; | 132 | }; |
140 | 133 | ||
141 | |||
142 | static struct key_entry *dell_wmi_keymap = dell_legacy_wmi_keymap; | ||
143 | |||
144 | static struct input_dev *dell_wmi_input_dev; | 134 | static struct input_dev *dell_wmi_input_dev; |
145 | 135 | ||
146 | static struct key_entry *dell_wmi_get_entry_by_scancode(unsigned int code) | ||
147 | { | ||
148 | struct key_entry *key; | ||
149 | |||
150 | for (key = dell_wmi_keymap; key->type != KE_END; key++) | ||
151 | if (code == key->code) | ||
152 | return key; | ||
153 | |||
154 | return NULL; | ||
155 | } | ||
156 | |||
157 | static struct key_entry *dell_wmi_get_entry_by_keycode(unsigned int keycode) | ||
158 | { | ||
159 | struct key_entry *key; | ||
160 | |||
161 | for (key = dell_wmi_keymap; key->type != KE_END; key++) | ||
162 | if (key->type == KE_KEY && keycode == key->keycode) | ||
163 | return key; | ||
164 | |||
165 | return NULL; | ||
166 | } | ||
167 | |||
168 | static int dell_wmi_getkeycode(struct input_dev *dev, | ||
169 | unsigned int scancode, unsigned int *keycode) | ||
170 | { | ||
171 | struct key_entry *key = dell_wmi_get_entry_by_scancode(scancode); | ||
172 | |||
173 | if (key && key->type == KE_KEY) { | ||
174 | *keycode = key->keycode; | ||
175 | return 0; | ||
176 | } | ||
177 | |||
178 | return -EINVAL; | ||
179 | } | ||
180 | |||
181 | static int dell_wmi_setkeycode(struct input_dev *dev, | ||
182 | unsigned int scancode, unsigned int keycode) | ||
183 | { | ||
184 | struct key_entry *key; | ||
185 | unsigned int old_keycode; | ||
186 | |||
187 | key = dell_wmi_get_entry_by_scancode(scancode); | ||
188 | if (key && key->type == KE_KEY) { | ||
189 | old_keycode = key->keycode; | ||
190 | key->keycode = keycode; | ||
191 | set_bit(keycode, dev->keybit); | ||
192 | if (!dell_wmi_get_entry_by_keycode(old_keycode)) | ||
193 | clear_bit(old_keycode, dev->keybit); | ||
194 | return 0; | ||
195 | } | ||
196 | return -EINVAL; | ||
197 | } | ||
198 | |||
199 | static void dell_wmi_notify(u32 value, void *context) | 136 | static void dell_wmi_notify(u32 value, void *context) |
200 | { | 137 | { |
201 | struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; | 138 | struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; |
202 | static struct key_entry *key; | ||
203 | union acpi_object *obj; | 139 | union acpi_object *obj; |
204 | acpi_status status; | 140 | acpi_status status; |
205 | 141 | ||
@@ -212,8 +148,10 @@ static void dell_wmi_notify(u32 value, void *context) | |||
212 | obj = (union acpi_object *)response.pointer; | 148 | obj = (union acpi_object *)response.pointer; |
213 | 149 | ||
214 | if (obj && obj->type == ACPI_TYPE_BUFFER) { | 150 | if (obj && obj->type == ACPI_TYPE_BUFFER) { |
151 | const struct key_entry *key; | ||
215 | int reported_key; | 152 | int reported_key; |
216 | u16 *buffer_entry = (u16 *)obj->buffer.pointer; | 153 | u16 *buffer_entry = (u16 *)obj->buffer.pointer; |
154 | |||
217 | if (dell_new_hk_type && (buffer_entry[1] != 0x10)) { | 155 | if (dell_new_hk_type && (buffer_entry[1] != 0x10)) { |
218 | printk(KERN_INFO "dell-wmi: Received unknown WMI event" | 156 | printk(KERN_INFO "dell-wmi: Received unknown WMI event" |
219 | " (0x%x)\n", buffer_entry[1]); | 157 | " (0x%x)\n", buffer_entry[1]); |
@@ -226,8 +164,8 @@ static void dell_wmi_notify(u32 value, void *context) | |||
226 | else | 164 | else |
227 | reported_key = (int)buffer_entry[1] & 0xffff; | 165 | reported_key = (int)buffer_entry[1] & 0xffff; |
228 | 166 | ||
229 | key = dell_wmi_get_entry_by_scancode(reported_key); | 167 | key = sparse_keymap_entry_from_scancode(dell_wmi_input_dev, |
230 | 168 | reported_key); | |
231 | if (!key) { | 169 | if (!key) { |
232 | printk(KERN_INFO "dell-wmi: Unknown key %x pressed\n", | 170 | printk(KERN_INFO "dell-wmi: Unknown key %x pressed\n", |
233 | reported_key); | 171 | reported_key); |
@@ -237,92 +175,98 @@ static void dell_wmi_notify(u32 value, void *context) | |||
237 | * come via ACPI */ | 175 | * come via ACPI */ |
238 | ; | 176 | ; |
239 | } else { | 177 | } else { |
240 | input_report_key(dell_wmi_input_dev, key->keycode, 1); | 178 | sparse_keymap_report_entry(dell_wmi_input_dev, key, |
241 | input_sync(dell_wmi_input_dev); | 179 | 1, true); |
242 | input_report_key(dell_wmi_input_dev, key->keycode, 0); | ||
243 | input_sync(dell_wmi_input_dev); | ||
244 | } | 180 | } |
245 | } | 181 | } |
246 | kfree(obj); | 182 | kfree(obj); |
247 | } | 183 | } |
248 | 184 | ||
249 | 185 | static const struct key_entry * __init dell_wmi_prepare_new_keymap(void) | |
250 | static void setup_new_hk_map(const struct dmi_header *dm) | ||
251 | { | 186 | { |
252 | 187 | int hotkey_num = (dell_bios_hotkey_table->header.length - 4) / | |
188 | sizeof(struct dell_bios_keymap_entry); | ||
189 | struct key_entry *keymap; | ||
253 | int i; | 190 | int i; |
254 | int hotkey_num = (dm->length-4)/sizeof(struct dell_new_keymap_entry); | ||
255 | struct dell_hotkey_table *table = | ||
256 | container_of(dm, struct dell_hotkey_table, header); | ||
257 | 191 | ||
258 | dell_new_wmi_keymap = kzalloc((hotkey_num+1) * | 192 | keymap = kcalloc(hotkey_num + 1, sizeof(struct key_entry), GFP_KERNEL); |
259 | sizeof(struct key_entry), GFP_KERNEL); | 193 | if (!keymap) |
194 | return NULL; | ||
260 | 195 | ||
261 | for (i = 0; i < hotkey_num; i++) { | 196 | for (i = 0; i < hotkey_num; i++) { |
262 | dell_new_wmi_keymap[i].type = KE_KEY; | 197 | const struct dell_bios_keymap_entry *bios_entry = |
263 | dell_new_wmi_keymap[i].code = table->keymap[i].scancode; | 198 | &dell_bios_hotkey_table->keymap[i]; |
264 | dell_new_wmi_keymap[i].keycode = | 199 | keymap[i].type = KE_KEY; |
265 | (table->keymap[i].keycode > 255) ? 0 : | 200 | keymap[i].code = bios_entry->scancode; |
266 | bios_to_linux_keycode[table->keymap[i].keycode]; | 201 | keymap[i].keycode = bios_entry->keycode < 256 ? |
202 | bios_to_linux_keycode[bios_entry->keycode] : | ||
203 | KEY_RESERVED; | ||
267 | } | 204 | } |
268 | 205 | ||
269 | dell_new_wmi_keymap[i].type = KE_END; | 206 | keymap[hotkey_num].type = KE_END; |
270 | dell_new_wmi_keymap[i].code = 0; | ||
271 | dell_new_wmi_keymap[i].keycode = 0; | ||
272 | |||
273 | dell_wmi_keymap = dell_new_wmi_keymap; | ||
274 | 207 | ||
208 | return keymap; | ||
275 | } | 209 | } |
276 | 210 | ||
277 | |||
278 | static void find_hk_type(const struct dmi_header *dm, void *dummy) | ||
279 | { | ||
280 | |||
281 | if ((dm->type == 0xb2) && (dm->length > 6)) { | ||
282 | dell_new_hk_type = true; | ||
283 | setup_new_hk_map(dm); | ||
284 | } | ||
285 | |||
286 | } | ||
287 | |||
288 | |||
289 | static int __init dell_wmi_input_setup(void) | 211 | static int __init dell_wmi_input_setup(void) |
290 | { | 212 | { |
291 | struct key_entry *key; | ||
292 | int err; | 213 | int err; |
293 | 214 | ||
294 | dell_wmi_input_dev = input_allocate_device(); | 215 | dell_wmi_input_dev = input_allocate_device(); |
295 | |||
296 | if (!dell_wmi_input_dev) | 216 | if (!dell_wmi_input_dev) |
297 | return -ENOMEM; | 217 | return -ENOMEM; |
298 | 218 | ||
299 | dell_wmi_input_dev->name = "Dell WMI hotkeys"; | 219 | dell_wmi_input_dev->name = "Dell WMI hotkeys"; |
300 | dell_wmi_input_dev->phys = "wmi/input0"; | 220 | dell_wmi_input_dev->phys = "wmi/input0"; |
301 | dell_wmi_input_dev->id.bustype = BUS_HOST; | 221 | dell_wmi_input_dev->id.bustype = BUS_HOST; |
302 | dell_wmi_input_dev->getkeycode = dell_wmi_getkeycode; | 222 | |
303 | dell_wmi_input_dev->setkeycode = dell_wmi_setkeycode; | 223 | if (dell_new_hk_type) { |
304 | 224 | const struct key_entry *keymap = dell_wmi_prepare_new_keymap(); | |
305 | for (key = dell_wmi_keymap; key->type != KE_END; key++) { | 225 | if (!keymap) { |
306 | switch (key->type) { | 226 | err = -ENOMEM; |
307 | case KE_KEY: | 227 | goto err_free_dev; |
308 | set_bit(EV_KEY, dell_wmi_input_dev->evbit); | ||
309 | set_bit(key->keycode, dell_wmi_input_dev->keybit); | ||
310 | break; | ||
311 | case KE_SW: | ||
312 | set_bit(EV_SW, dell_wmi_input_dev->evbit); | ||
313 | set_bit(key->keycode, dell_wmi_input_dev->swbit); | ||
314 | break; | ||
315 | } | 228 | } |
316 | } | ||
317 | 229 | ||
318 | err = input_register_device(dell_wmi_input_dev); | 230 | err = sparse_keymap_setup(dell_wmi_input_dev, keymap, NULL); |
319 | 231 | ||
320 | if (err) { | 232 | /* |
321 | input_free_device(dell_wmi_input_dev); | 233 | * Sparse keymap library makes a copy of keymap so we |
322 | return err; | 234 | * don't need the original one that was allocated. |
235 | */ | ||
236 | kfree(keymap); | ||
237 | } else { | ||
238 | err = sparse_keymap_setup(dell_wmi_input_dev, | ||
239 | dell_wmi_legacy_keymap, NULL); | ||
323 | } | 240 | } |
241 | if (err) | ||
242 | goto err_free_dev; | ||
243 | |||
244 | err = input_register_device(dell_wmi_input_dev); | ||
245 | if (err) | ||
246 | goto err_free_keymap; | ||
324 | 247 | ||
325 | return 0; | 248 | return 0; |
249 | |||
250 | err_free_keymap: | ||
251 | sparse_keymap_free(dell_wmi_input_dev); | ||
252 | err_free_dev: | ||
253 | input_free_device(dell_wmi_input_dev); | ||
254 | return err; | ||
255 | } | ||
256 | |||
257 | static void dell_wmi_input_destroy(void) | ||
258 | { | ||
259 | sparse_keymap_free(dell_wmi_input_dev); | ||
260 | input_unregister_device(dell_wmi_input_dev); | ||
261 | } | ||
262 | |||
263 | static void __init find_hk_type(const struct dmi_header *dm, void *dummy) | ||
264 | { | ||
265 | if (dm->type == 0xb2 && dm->length > 6) { | ||
266 | dell_new_hk_type = true; | ||
267 | dell_bios_hotkey_table = | ||
268 | container_of(dm, struct dell_bios_hotkey_table, header); | ||
269 | } | ||
326 | } | 270 | } |
327 | 271 | ||
328 | static int __init dell_wmi_init(void) | 272 | static int __init dell_wmi_init(void) |
@@ -339,18 +283,13 @@ static int __init dell_wmi_init(void) | |||
339 | acpi_video = acpi_video_backlight_support(); | 283 | acpi_video = acpi_video_backlight_support(); |
340 | 284 | ||
341 | err = dell_wmi_input_setup(); | 285 | err = dell_wmi_input_setup(); |
342 | if (err) { | 286 | if (err) |
343 | if (dell_new_hk_type) | ||
344 | kfree(dell_wmi_keymap); | ||
345 | return err; | 287 | return err; |
346 | } | ||
347 | 288 | ||
348 | status = wmi_install_notify_handler(DELL_EVENT_GUID, | 289 | status = wmi_install_notify_handler(DELL_EVENT_GUID, |
349 | dell_wmi_notify, NULL); | 290 | dell_wmi_notify, NULL); |
350 | if (ACPI_FAILURE(status)) { | 291 | if (ACPI_FAILURE(status)) { |
351 | input_unregister_device(dell_wmi_input_dev); | 292 | dell_wmi_input_destroy(); |
352 | if (dell_new_hk_type) | ||
353 | kfree(dell_wmi_keymap); | ||
354 | printk(KERN_ERR | 293 | printk(KERN_ERR |
355 | "dell-wmi: Unable to register notify handler - %d\n", | 294 | "dell-wmi: Unable to register notify handler - %d\n", |
356 | status); | 295 | status); |
@@ -359,14 +298,11 @@ static int __init dell_wmi_init(void) | |||
359 | 298 | ||
360 | return 0; | 299 | return 0; |
361 | } | 300 | } |
301 | module_init(dell_wmi_init); | ||
362 | 302 | ||
363 | static void __exit dell_wmi_exit(void) | 303 | static void __exit dell_wmi_exit(void) |
364 | { | 304 | { |
365 | wmi_remove_notify_handler(DELL_EVENT_GUID); | 305 | wmi_remove_notify_handler(DELL_EVENT_GUID); |
366 | input_unregister_device(dell_wmi_input_dev); | 306 | dell_wmi_input_destroy(); |
367 | if (dell_new_hk_type) | ||
368 | kfree(dell_wmi_keymap); | ||
369 | } | 307 | } |
370 | |||
371 | module_init(dell_wmi_init); | ||
372 | module_exit(dell_wmi_exit); | 308 | module_exit(dell_wmi_exit); |