1 // SPDX-License-Identifier: GPL-2.0-only
3 * Wistron laptop button driver
4 * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz>
5 * Copyright (C) 2005 Bernhard Rosenkraenzer <bero@arklinux.org>
6 * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru>
10 #include <linux/init.h>
11 #include <linux/input.h>
12 #include <linux/input/sparse-keymap.h>
13 #include <linux/interrupt.h>
14 #include <linux/jiffies.h>
15 #include <linux/kernel.h>
16 #include <linux/mc146818rtc.h>
17 #include <linux/module.h>
18 #include <linux/preempt.h>
19 #include <linux/string.h>
20 #include <linux/slab.h>
21 #include <linux/types.h>
22 #include <linux/platform_device.h>
23 #include <linux/leds.h>
25 /* How often we poll keys - msecs */
26 #define POLL_INTERVAL_DEFAULT 500 /* when idle */
27 #define POLL_INTERVAL_BURST 100 /* when a key was recently pressed */
29 /* BIOS subsystem IDs */
31 #define BLUETOOTH 0x34
34 MODULE_AUTHOR("Miloslav Trmac <mitr@volny.cz>");
35 MODULE_DESCRIPTION("Wistron laptop button driver");
36 MODULE_LICENSE("GPL v2");
38 static bool force; /* = 0; */
39 module_param(force, bool, 0);
40 MODULE_PARM_DESC(force, "Load even if computer is not in database");
42 static char *keymap_name; /* = NULL; */
43 module_param_named(keymap, keymap_name, charp, 0);
44 MODULE_PARM_DESC(keymap, "Keymap name, if it can't be autodetected [generic, 1557/MS2141]");
46 static struct platform_device *wistron_device;
48 /* BIOS interface implementation */
50 static void __iomem *bios_entry_point; /* BIOS routine entry point */
51 static void __iomem *bios_code_map_base;
52 static void __iomem *bios_data_map_base;
54 static u8 cmos_address;
60 static void call_bios(struct regs *regs)
65 local_irq_save(flags);
66 asm volatile ("pushl %%ebp;"
70 : "=a" (regs->eax), "=b" (regs->ebx), "=c" (regs->ecx)
71 : "0" (regs->eax), "1" (regs->ebx), "2" (regs->ecx),
72 "m" (bios_entry_point), "m" (bios_data_map_base)
73 : "edx", "edi", "esi", "memory");
74 local_irq_restore(flags);
78 static ssize_t __init locate_wistron_bios(void __iomem *base)
80 static unsigned char __initdata signature[] =
81 { 0x42, 0x21, 0x55, 0x30 };
84 for (offset = 0; offset < 0x10000; offset += 0x10) {
85 if (check_signature(base + offset, signature,
86 sizeof(signature)) != 0)
92 static int __init map_bios(void)
98 base = ioremap(0xF0000, 0x10000); /* Can't fail */
99 offset = locate_wistron_bios(base);
101 printk(KERN_ERR "wistron_btns: BIOS entry point not found\n");
106 entry_point = readl(base + offset + 5);
108 "wistron_btns: BIOS signature found at %p, entry point %08X\n",
109 base + offset, entry_point);
111 if (entry_point >= 0xF0000) {
112 bios_code_map_base = base;
113 bios_entry_point = bios_code_map_base + (entry_point & 0xFFFF);
116 bios_code_map_base = ioremap(entry_point & ~0x3FFF, 0x4000);
117 if (bios_code_map_base == NULL) {
119 "wistron_btns: Can't map BIOS code at %08X\n",
120 entry_point & ~0x3FFF);
123 bios_entry_point = bios_code_map_base + (entry_point & 0x3FFF);
125 /* The Windows driver maps 0x10000 bytes, we keep only one page... */
126 bios_data_map_base = ioremap(0x400, 0xc00);
127 if (bios_data_map_base == NULL) {
128 printk(KERN_ERR "wistron_btns: Can't map BIOS data\n");
134 iounmap(bios_code_map_base);
139 static inline void unmap_bios(void)
141 iounmap(bios_code_map_base);
142 iounmap(bios_data_map_base);
147 static u16 bios_pop_queue(void)
151 memset(®s, 0, sizeof (regs));
160 static void bios_attach(void)
164 memset(®s, 0, sizeof (regs));
170 static void bios_detach(void)
174 memset(®s, 0, sizeof (regs));
180 static u8 bios_get_cmos_address(void)
184 memset(®s, 0, sizeof (regs));
192 static u16 bios_get_default_setting(u8 subsys)
196 memset(®s, 0, sizeof (regs));
198 regs.ebx = 0x0200 | subsys;
204 static void bios_set_state(u8 subsys, int enable)
208 memset(®s, 0, sizeof (regs));
210 regs.ebx = (enable ? 0x0100 : 0x0000) | subsys;
214 /* Hardware database */
216 #define KE_WIFI (KE_LAST + 1)
217 #define KE_BLUETOOTH (KE_LAST + 2)
219 #define FE_MAIL_LED 0x01
220 #define FE_WIFI_LED 0x02
221 #define FE_UNTESTED 0x80
223 static struct key_entry *keymap; /* = NULL; Current key map */
224 static bool have_wifi;
225 static bool have_bluetooth;
226 static int leds_present; /* bitmask of leds present */
228 static int __init dmi_matched(const struct dmi_system_id *dmi)
230 const struct key_entry *key;
232 keymap = dmi->driver_data;
233 for (key = keymap; key->type != KE_END; key++) {
234 if (key->type == KE_WIFI)
236 else if (key->type == KE_BLUETOOTH)
237 have_bluetooth = true;
239 leds_present = key->code & (FE_MAIL_LED | FE_WIFI_LED);
244 static struct key_entry keymap_empty[] __initdata = {
248 static struct key_entry keymap_fs_amilo_pro_v2000[] __initdata = {
249 { KE_KEY, 0x01, {KEY_HELP} },
250 { KE_KEY, 0x11, {KEY_PROG1} },
251 { KE_KEY, 0x12, {KEY_PROG2} },
253 { KE_KEY, 0x31, {KEY_MAIL} },
254 { KE_KEY, 0x36, {KEY_WWW} },
258 static struct key_entry keymap_fs_amilo_pro_v3505[] __initdata = {
259 { KE_KEY, 0x01, {KEY_HELP} }, /* Fn+F1 */
260 { KE_KEY, 0x06, {KEY_DISPLAYTOGGLE} }, /* Fn+F4 */
261 { KE_BLUETOOTH, 0x30 }, /* Fn+F10 */
262 { KE_KEY, 0x31, {KEY_MAIL} }, /* mail button */
263 { KE_KEY, 0x36, {KEY_WWW} }, /* www button */
264 { KE_WIFI, 0x78 }, /* satellite dish button */
268 static struct key_entry keymap_fs_amilo_pro_v8210[] __initdata = {
269 { KE_KEY, 0x01, {KEY_HELP} }, /* Fn+F1 */
270 { KE_KEY, 0x06, {KEY_DISPLAYTOGGLE} }, /* Fn+F4 */
271 { KE_BLUETOOTH, 0x30 }, /* Fn+F10 */
272 { KE_KEY, 0x31, {KEY_MAIL} }, /* mail button */
273 { KE_KEY, 0x36, {KEY_WWW} }, /* www button */
274 { KE_WIFI, 0x78 }, /* satelite dish button */
275 { KE_END, FE_WIFI_LED }
278 static struct key_entry keymap_fujitsu_n3510[] __initdata = {
279 { KE_KEY, 0x11, {KEY_PROG1} },
280 { KE_KEY, 0x12, {KEY_PROG2} },
281 { KE_KEY, 0x36, {KEY_WWW} },
282 { KE_KEY, 0x31, {KEY_MAIL} },
283 { KE_KEY, 0x71, {KEY_STOPCD} },
284 { KE_KEY, 0x72, {KEY_PLAYPAUSE} },
285 { KE_KEY, 0x74, {KEY_REWIND} },
286 { KE_KEY, 0x78, {KEY_FORWARD} },
290 static struct key_entry keymap_wistron_ms2111[] __initdata = {
291 { KE_KEY, 0x11, {KEY_PROG1} },
292 { KE_KEY, 0x12, {KEY_PROG2} },
293 { KE_KEY, 0x13, {KEY_PROG3} },
294 { KE_KEY, 0x31, {KEY_MAIL} },
295 { KE_KEY, 0x36, {KEY_WWW} },
296 { KE_END, FE_MAIL_LED }
299 static struct key_entry keymap_wistron_md40100[] __initdata = {
300 { KE_KEY, 0x01, {KEY_HELP} },
301 { KE_KEY, 0x02, {KEY_CONFIG} },
302 { KE_KEY, 0x31, {KEY_MAIL} },
303 { KE_KEY, 0x36, {KEY_WWW} },
304 { KE_KEY, 0x37, {KEY_DISPLAYTOGGLE} }, /* Display on/off */
305 { KE_END, FE_MAIL_LED | FE_WIFI_LED | FE_UNTESTED }
308 static struct key_entry keymap_wistron_ms2141[] __initdata = {
309 { KE_KEY, 0x11, {KEY_PROG1} },
310 { KE_KEY, 0x12, {KEY_PROG2} },
312 { KE_KEY, 0x22, {KEY_REWIND} },
313 { KE_KEY, 0x23, {KEY_FORWARD} },
314 { KE_KEY, 0x24, {KEY_PLAYPAUSE} },
315 { KE_KEY, 0x25, {KEY_STOPCD} },
316 { KE_KEY, 0x31, {KEY_MAIL} },
317 { KE_KEY, 0x36, {KEY_WWW} },
321 static struct key_entry keymap_acer_aspire_1500[] __initdata = {
322 { KE_KEY, 0x01, {KEY_HELP} },
323 { KE_KEY, 0x03, {KEY_POWER} },
324 { KE_KEY, 0x11, {KEY_PROG1} },
325 { KE_KEY, 0x12, {KEY_PROG2} },
327 { KE_KEY, 0x31, {KEY_MAIL} },
328 { KE_KEY, 0x36, {KEY_WWW} },
329 { KE_KEY, 0x49, {KEY_CONFIG} },
330 { KE_BLUETOOTH, 0x44 },
331 { KE_END, FE_UNTESTED }
334 static struct key_entry keymap_acer_aspire_1600[] __initdata = {
335 { KE_KEY, 0x01, {KEY_HELP} },
336 { KE_KEY, 0x03, {KEY_POWER} },
337 { KE_KEY, 0x08, {KEY_MUTE} },
338 { KE_KEY, 0x11, {KEY_PROG1} },
339 { KE_KEY, 0x12, {KEY_PROG2} },
340 { KE_KEY, 0x13, {KEY_PROG3} },
341 { KE_KEY, 0x31, {KEY_MAIL} },
342 { KE_KEY, 0x36, {KEY_WWW} },
343 { KE_KEY, 0x49, {KEY_CONFIG} },
345 { KE_BLUETOOTH, 0x44 },
346 { KE_END, FE_MAIL_LED | FE_UNTESTED }
349 /* 3020 has been tested */
350 static struct key_entry keymap_acer_aspire_5020[] __initdata = {
351 { KE_KEY, 0x01, {KEY_HELP} },
352 { KE_KEY, 0x03, {KEY_POWER} },
353 { KE_KEY, 0x05, {KEY_SWITCHVIDEOMODE} }, /* Display selection */
354 { KE_KEY, 0x11, {KEY_PROG1} },
355 { KE_KEY, 0x12, {KEY_PROG2} },
356 { KE_KEY, 0x31, {KEY_MAIL} },
357 { KE_KEY, 0x36, {KEY_WWW} },
358 { KE_KEY, 0x6a, {KEY_CONFIG} },
360 { KE_BLUETOOTH, 0x44 },
361 { KE_END, FE_MAIL_LED | FE_UNTESTED }
364 static struct key_entry keymap_acer_travelmate_2410[] __initdata = {
365 { KE_KEY, 0x01, {KEY_HELP} },
366 { KE_KEY, 0x6d, {KEY_POWER} },
367 { KE_KEY, 0x11, {KEY_PROG1} },
368 { KE_KEY, 0x12, {KEY_PROG2} },
369 { KE_KEY, 0x31, {KEY_MAIL} },
370 { KE_KEY, 0x36, {KEY_WWW} },
371 { KE_KEY, 0x6a, {KEY_CONFIG} },
373 { KE_BLUETOOTH, 0x44 },
374 { KE_END, FE_MAIL_LED | FE_UNTESTED }
377 static struct key_entry keymap_acer_travelmate_110[] __initdata = {
378 { KE_KEY, 0x01, {KEY_HELP} },
379 { KE_KEY, 0x02, {KEY_CONFIG} },
380 { KE_KEY, 0x03, {KEY_POWER} },
381 { KE_KEY, 0x08, {KEY_MUTE} },
382 { KE_KEY, 0x11, {KEY_PROG1} },
383 { KE_KEY, 0x12, {KEY_PROG2} },
384 { KE_KEY, 0x20, {KEY_VOLUMEUP} },
385 { KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
386 { KE_KEY, 0x31, {KEY_MAIL} },
387 { KE_KEY, 0x36, {KEY_WWW} },
388 { KE_SW, 0x4a, {.sw = {SW_LID, 1}} }, /* lid close */
389 { KE_SW, 0x4b, {.sw = {SW_LID, 0}} }, /* lid open */
391 { KE_END, FE_MAIL_LED | FE_UNTESTED }
394 static struct key_entry keymap_acer_travelmate_300[] __initdata = {
395 { KE_KEY, 0x01, {KEY_HELP} },
396 { KE_KEY, 0x02, {KEY_CONFIG} },
397 { KE_KEY, 0x03, {KEY_POWER} },
398 { KE_KEY, 0x08, {KEY_MUTE} },
399 { KE_KEY, 0x11, {KEY_PROG1} },
400 { KE_KEY, 0x12, {KEY_PROG2} },
401 { KE_KEY, 0x20, {KEY_VOLUMEUP} },
402 { KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
403 { KE_KEY, 0x31, {KEY_MAIL} },
404 { KE_KEY, 0x36, {KEY_WWW} },
406 { KE_BLUETOOTH, 0x44 },
407 { KE_END, FE_MAIL_LED | FE_UNTESTED }
410 static struct key_entry keymap_acer_travelmate_380[] __initdata = {
411 { KE_KEY, 0x01, {KEY_HELP} },
412 { KE_KEY, 0x02, {KEY_CONFIG} },
413 { KE_KEY, 0x03, {KEY_POWER} }, /* not 370 */
414 { KE_KEY, 0x11, {KEY_PROG1} },
415 { KE_KEY, 0x12, {KEY_PROG2} },
416 { KE_KEY, 0x13, {KEY_PROG3} },
417 { KE_KEY, 0x31, {KEY_MAIL} },
418 { KE_KEY, 0x36, {KEY_WWW} },
420 { KE_END, FE_MAIL_LED | FE_UNTESTED }
424 static struct key_entry keymap_acer_travelmate_220[] __initdata = {
425 { KE_KEY, 0x01, {KEY_HELP} },
426 { KE_KEY, 0x02, {KEY_CONFIG} },
427 { KE_KEY, 0x11, {KEY_MAIL} },
428 { KE_KEY, 0x12, {KEY_WWW} },
429 { KE_KEY, 0x13, {KEY_PROG2} },
430 { KE_KEY, 0x31, {KEY_PROG1} },
431 { KE_END, FE_WIFI_LED | FE_UNTESTED }
434 static struct key_entry keymap_acer_travelmate_230[] __initdata = {
435 { KE_KEY, 0x01, {KEY_HELP} },
436 { KE_KEY, 0x02, {KEY_CONFIG} },
437 { KE_KEY, 0x11, {KEY_PROG1} },
438 { KE_KEY, 0x12, {KEY_PROG2} },
439 { KE_KEY, 0x31, {KEY_MAIL} },
440 { KE_KEY, 0x36, {KEY_WWW} },
441 { KE_END, FE_WIFI_LED | FE_UNTESTED }
444 static struct key_entry keymap_acer_travelmate_240[] __initdata = {
445 { KE_KEY, 0x01, {KEY_HELP} },
446 { KE_KEY, 0x02, {KEY_CONFIG} },
447 { KE_KEY, 0x03, {KEY_POWER} },
448 { KE_KEY, 0x08, {KEY_MUTE} },
449 { KE_KEY, 0x31, {KEY_MAIL} },
450 { KE_KEY, 0x36, {KEY_WWW} },
451 { KE_KEY, 0x11, {KEY_PROG1} },
452 { KE_KEY, 0x12, {KEY_PROG2} },
453 { KE_BLUETOOTH, 0x44 },
455 { KE_END, FE_UNTESTED }
458 static struct key_entry keymap_acer_travelmate_350[] __initdata = {
459 { KE_KEY, 0x01, {KEY_HELP} },
460 { KE_KEY, 0x02, {KEY_CONFIG} },
461 { KE_KEY, 0x11, {KEY_PROG1} },
462 { KE_KEY, 0x12, {KEY_PROG2} },
463 { KE_KEY, 0x13, {KEY_MAIL} },
464 { KE_KEY, 0x14, {KEY_PROG3} },
465 { KE_KEY, 0x15, {KEY_WWW} },
466 { KE_END, FE_MAIL_LED | FE_WIFI_LED | FE_UNTESTED }
469 static struct key_entry keymap_acer_travelmate_360[] __initdata = {
470 { KE_KEY, 0x01, {KEY_HELP} },
471 { KE_KEY, 0x02, {KEY_CONFIG} },
472 { KE_KEY, 0x11, {KEY_PROG1} },
473 { KE_KEY, 0x12, {KEY_PROG2} },
474 { KE_KEY, 0x13, {KEY_MAIL} },
475 { KE_KEY, 0x14, {KEY_PROG3} },
476 { KE_KEY, 0x15, {KEY_WWW} },
477 { KE_KEY, 0x40, {KEY_WLAN} },
478 { KE_END, FE_WIFI_LED | FE_UNTESTED } /* no mail led */
481 /* Wifi subsystem only activates the led. Therefore we need to pass
482 * wifi event as a normal key, then userspace can really change the wifi state.
483 * TODO we need to export led state to userspace (wifi and mail) */
484 static struct key_entry keymap_acer_travelmate_610[] __initdata = {
485 { KE_KEY, 0x01, {KEY_HELP} },
486 { KE_KEY, 0x02, {KEY_CONFIG} },
487 { KE_KEY, 0x11, {KEY_PROG1} },
488 { KE_KEY, 0x12, {KEY_PROG2} },
489 { KE_KEY, 0x13, {KEY_PROG3} },
490 { KE_KEY, 0x14, {KEY_MAIL} },
491 { KE_KEY, 0x15, {KEY_WWW} },
492 { KE_KEY, 0x40, {KEY_WLAN} },
493 { KE_END, FE_MAIL_LED | FE_WIFI_LED }
496 static struct key_entry keymap_acer_travelmate_630[] __initdata = {
497 { KE_KEY, 0x01, {KEY_HELP} },
498 { KE_KEY, 0x02, {KEY_CONFIG} },
499 { KE_KEY, 0x03, {KEY_POWER} },
500 { KE_KEY, 0x08, {KEY_MUTE} }, /* not 620 */
501 { KE_KEY, 0x11, {KEY_PROG1} },
502 { KE_KEY, 0x12, {KEY_PROG2} },
503 { KE_KEY, 0x13, {KEY_PROG3} },
504 { KE_KEY, 0x20, {KEY_VOLUMEUP} },
505 { KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
506 { KE_KEY, 0x31, {KEY_MAIL} },
507 { KE_KEY, 0x36, {KEY_WWW} },
509 { KE_END, FE_MAIL_LED | FE_UNTESTED }
512 static struct key_entry keymap_aopen_1559as[] __initdata = {
513 { KE_KEY, 0x01, {KEY_HELP} },
514 { KE_KEY, 0x06, {KEY_PROG3} },
515 { KE_KEY, 0x11, {KEY_PROG1} },
516 { KE_KEY, 0x12, {KEY_PROG2} },
518 { KE_KEY, 0x31, {KEY_MAIL} },
519 { KE_KEY, 0x36, {KEY_WWW} },
523 static struct key_entry keymap_fs_amilo_d88x0[] __initdata = {
524 { KE_KEY, 0x01, {KEY_HELP} },
525 { KE_KEY, 0x08, {KEY_MUTE} },
526 { KE_KEY, 0x31, {KEY_MAIL} },
527 { KE_KEY, 0x36, {KEY_WWW} },
528 { KE_KEY, 0x11, {KEY_PROG1} },
529 { KE_KEY, 0x12, {KEY_PROG2} },
530 { KE_KEY, 0x13, {KEY_PROG3} },
531 { KE_END, FE_MAIL_LED | FE_WIFI_LED | FE_UNTESTED }
534 static struct key_entry keymap_wistron_md2900[] __initdata = {
535 { KE_KEY, 0x01, {KEY_HELP} },
536 { KE_KEY, 0x02, {KEY_CONFIG} },
537 { KE_KEY, 0x11, {KEY_PROG1} },
538 { KE_KEY, 0x12, {KEY_PROG2} },
539 { KE_KEY, 0x31, {KEY_MAIL} },
540 { KE_KEY, 0x36, {KEY_WWW} },
542 { KE_END, FE_MAIL_LED | FE_UNTESTED }
545 static struct key_entry keymap_wistron_md96500[] __initdata = {
546 { KE_KEY, 0x01, {KEY_HELP} },
547 { KE_KEY, 0x02, {KEY_CONFIG} },
548 { KE_KEY, 0x05, {KEY_SWITCHVIDEOMODE} }, /* Display selection */
549 { KE_KEY, 0x06, {KEY_DISPLAYTOGGLE} }, /* Display on/off */
550 { KE_KEY, 0x08, {KEY_MUTE} },
551 { KE_KEY, 0x11, {KEY_PROG1} },
552 { KE_KEY, 0x12, {KEY_PROG2} },
553 { KE_KEY, 0x20, {KEY_VOLUMEUP} },
554 { KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
555 { KE_KEY, 0x22, {KEY_REWIND} },
556 { KE_KEY, 0x23, {KEY_FORWARD} },
557 { KE_KEY, 0x24, {KEY_PLAYPAUSE} },
558 { KE_KEY, 0x25, {KEY_STOPCD} },
559 { KE_KEY, 0x31, {KEY_MAIL} },
560 { KE_KEY, 0x36, {KEY_WWW} },
562 { KE_BLUETOOTH, 0x44 },
566 static struct key_entry keymap_wistron_generic[] __initdata = {
567 { KE_KEY, 0x01, {KEY_HELP} },
568 { KE_KEY, 0x02, {KEY_CONFIG} },
569 { KE_KEY, 0x03, {KEY_POWER} },
570 { KE_KEY, 0x05, {KEY_SWITCHVIDEOMODE} }, /* Display selection */
571 { KE_KEY, 0x06, {KEY_DISPLAYTOGGLE} }, /* Display on/off */
572 { KE_KEY, 0x08, {KEY_MUTE} },
573 { KE_KEY, 0x11, {KEY_PROG1} },
574 { KE_KEY, 0x12, {KEY_PROG2} },
575 { KE_KEY, 0x13, {KEY_PROG3} },
576 { KE_KEY, 0x14, {KEY_MAIL} },
577 { KE_KEY, 0x15, {KEY_WWW} },
578 { KE_KEY, 0x20, {KEY_VOLUMEUP} },
579 { KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
580 { KE_KEY, 0x22, {KEY_REWIND} },
581 { KE_KEY, 0x23, {KEY_FORWARD} },
582 { KE_KEY, 0x24, {KEY_PLAYPAUSE} },
583 { KE_KEY, 0x25, {KEY_STOPCD} },
584 { KE_KEY, 0x31, {KEY_MAIL} },
585 { KE_KEY, 0x36, {KEY_WWW} },
586 { KE_KEY, 0x37, {KEY_DISPLAYTOGGLE} }, /* Display on/off */
587 { KE_KEY, 0x40, {KEY_WLAN} },
588 { KE_KEY, 0x49, {KEY_CONFIG} },
589 { KE_SW, 0x4a, {.sw = {SW_LID, 1}} }, /* lid close */
590 { KE_SW, 0x4b, {.sw = {SW_LID, 0}} }, /* lid open */
591 { KE_KEY, 0x6a, {KEY_CONFIG} },
592 { KE_KEY, 0x6d, {KEY_POWER} },
593 { KE_KEY, 0x71, {KEY_STOPCD} },
594 { KE_KEY, 0x72, {KEY_PLAYPAUSE} },
595 { KE_KEY, 0x74, {KEY_REWIND} },
596 { KE_KEY, 0x78, {KEY_FORWARD} },
598 { KE_BLUETOOTH, 0x44 },
602 static struct key_entry keymap_aopen_1557[] __initdata = {
603 { KE_KEY, 0x01, {KEY_HELP} },
604 { KE_KEY, 0x11, {KEY_PROG1} },
605 { KE_KEY, 0x12, {KEY_PROG2} },
607 { KE_KEY, 0x22, {KEY_REWIND} },
608 { KE_KEY, 0x23, {KEY_FORWARD} },
609 { KE_KEY, 0x24, {KEY_PLAYPAUSE} },
610 { KE_KEY, 0x25, {KEY_STOPCD} },
611 { KE_KEY, 0x31, {KEY_MAIL} },
612 { KE_KEY, 0x36, {KEY_WWW} },
616 static struct key_entry keymap_prestigio[] __initdata = {
617 { KE_KEY, 0x11, {KEY_PROG1} },
618 { KE_KEY, 0x12, {KEY_PROG2} },
620 { KE_KEY, 0x22, {KEY_REWIND} },
621 { KE_KEY, 0x23, {KEY_FORWARD} },
622 { KE_KEY, 0x24, {KEY_PLAYPAUSE} },
623 { KE_KEY, 0x25, {KEY_STOPCD} },
624 { KE_KEY, 0x31, {KEY_MAIL} },
625 { KE_KEY, 0x36, {KEY_WWW} },
631 * If your machine is not here (which is currently rather likely), please send
632 * a list of buttons and their key codes (reported when loading this module
633 * with force=1) and the output of dmidecode to $MODULE_AUTHOR.
635 static const struct dmi_system_id dmi_ids[] __initconst = {
637 /* Fujitsu-Siemens Amilo Pro V2000 */
638 .callback = dmi_matched,
640 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
641 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pro V2000"),
643 .driver_data = keymap_fs_amilo_pro_v2000
646 /* Fujitsu-Siemens Amilo Pro Edition V3505 */
647 .callback = dmi_matched,
649 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
650 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pro Edition V3505"),
652 .driver_data = keymap_fs_amilo_pro_v3505
655 /* Fujitsu-Siemens Amilo Pro Edition V8210 */
656 .callback = dmi_matched,
658 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
659 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pro Series V8210"),
661 .driver_data = keymap_fs_amilo_pro_v8210
664 /* Fujitsu-Siemens Amilo M7400 */
665 .callback = dmi_matched,
667 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
668 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO M "),
670 .driver_data = keymap_fs_amilo_pro_v2000
673 /* Maxdata Pro 7000 DX */
674 .callback = dmi_matched,
676 DMI_MATCH(DMI_SYS_VENDOR, "MAXDATA"),
677 DMI_MATCH(DMI_PRODUCT_NAME, "Pro 7000"),
679 .driver_data = keymap_fs_amilo_pro_v2000
683 .callback = dmi_matched,
685 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
686 DMI_MATCH(DMI_PRODUCT_NAME, "N3510"),
688 .driver_data = keymap_fujitsu_n3510
691 /* Acer Aspire 1500 */
692 .callback = dmi_matched,
694 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
695 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1500"),
697 .driver_data = keymap_acer_aspire_1500
700 /* Acer Aspire 1600 */
701 .callback = dmi_matched,
703 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
704 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1600"),
706 .driver_data = keymap_acer_aspire_1600
709 /* Acer Aspire 3020 */
710 .callback = dmi_matched,
712 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
713 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3020"),
715 .driver_data = keymap_acer_aspire_5020
718 /* Acer Aspire 5020 */
719 .callback = dmi_matched,
721 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
722 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5020"),
724 .driver_data = keymap_acer_aspire_5020
727 /* Acer TravelMate 2100 */
728 .callback = dmi_matched,
730 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
731 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2100"),
733 .driver_data = keymap_acer_aspire_5020
736 /* Acer TravelMate 2410 */
737 .callback = dmi_matched,
739 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
740 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2410"),
742 .driver_data = keymap_acer_travelmate_2410
745 /* Acer TravelMate C300 */
746 .callback = dmi_matched,
748 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
749 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate C300"),
751 .driver_data = keymap_acer_travelmate_300
754 /* Acer TravelMate C100 */
755 .callback = dmi_matched,
757 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
758 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate C100"),
760 .driver_data = keymap_acer_travelmate_300
763 /* Acer TravelMate C110 */
764 .callback = dmi_matched,
766 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
767 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate C110"),
769 .driver_data = keymap_acer_travelmate_110
772 /* Acer TravelMate 380 */
773 .callback = dmi_matched,
775 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
776 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 380"),
778 .driver_data = keymap_acer_travelmate_380
781 /* Acer TravelMate 370 */
782 .callback = dmi_matched,
784 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
785 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 370"),
787 .driver_data = keymap_acer_travelmate_380 /* keyboard minus 1 key */
790 /* Acer TravelMate 220 */
791 .callback = dmi_matched,
793 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
794 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 220"),
796 .driver_data = keymap_acer_travelmate_220
799 /* Acer TravelMate 260 */
800 .callback = dmi_matched,
802 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
803 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 260"),
805 .driver_data = keymap_acer_travelmate_220
808 /* Acer TravelMate 230 */
809 .callback = dmi_matched,
811 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
812 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 230"),
813 /* acerhk looks for "TravelMate F4..." ?! */
815 .driver_data = keymap_acer_travelmate_230
818 /* Acer TravelMate 280 */
819 .callback = dmi_matched,
821 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
822 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 280"),
824 .driver_data = keymap_acer_travelmate_230
827 /* Acer TravelMate 240 */
828 .callback = dmi_matched,
830 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
831 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 240"),
833 .driver_data = keymap_acer_travelmate_240
836 /* Acer TravelMate 250 */
837 .callback = dmi_matched,
839 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
840 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 250"),
842 .driver_data = keymap_acer_travelmate_240
845 /* Acer TravelMate 2424NWXCi */
846 .callback = dmi_matched,
848 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
849 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2420"),
851 .driver_data = keymap_acer_travelmate_240
854 /* Acer TravelMate 350 */
855 .callback = dmi_matched,
857 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
858 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 350"),
860 .driver_data = keymap_acer_travelmate_350
863 /* Acer TravelMate 360 */
864 .callback = dmi_matched,
866 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
867 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
869 .driver_data = keymap_acer_travelmate_360
872 /* Acer TravelMate 610 */
873 .callback = dmi_matched,
875 DMI_MATCH(DMI_SYS_VENDOR, "ACER"),
876 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 610"),
878 .driver_data = keymap_acer_travelmate_610
881 /* Acer TravelMate 620 */
882 .callback = dmi_matched,
884 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
885 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 620"),
887 .driver_data = keymap_acer_travelmate_630
890 /* Acer TravelMate 630 */
891 .callback = dmi_matched,
893 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
894 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 630"),
896 .driver_data = keymap_acer_travelmate_630
900 .callback = dmi_matched,
902 DMI_MATCH(DMI_PRODUCT_NAME, "E2U"),
903 DMI_MATCH(DMI_BOARD_NAME, "E2U"),
905 .driver_data = keymap_aopen_1559as
909 .callback = dmi_matched,
911 DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
912 DMI_MATCH(DMI_PRODUCT_NAME, "MD 9783"),
914 .driver_data = keymap_wistron_ms2111
917 /* Medion MD 40100 */
918 .callback = dmi_matched,
920 DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
921 DMI_MATCH(DMI_PRODUCT_NAME, "WID2000"),
923 .driver_data = keymap_wistron_md40100
927 .callback = dmi_matched,
929 DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
930 DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2000"),
932 .driver_data = keymap_wistron_md2900
935 /* Medion MD 42200 */
936 .callback = dmi_matched,
938 DMI_MATCH(DMI_SYS_VENDOR, "Medion"),
939 DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2030"),
941 .driver_data = keymap_fs_amilo_pro_v2000
944 /* Medion MD 96500 */
945 .callback = dmi_matched,
947 DMI_MATCH(DMI_SYS_VENDOR, "MEDIONPC"),
948 DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2040"),
950 .driver_data = keymap_wistron_md96500
953 /* Medion MD 95400 */
954 .callback = dmi_matched,
956 DMI_MATCH(DMI_SYS_VENDOR, "MEDIONPC"),
957 DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2050"),
959 .driver_data = keymap_wistron_md96500
962 /* Fujitsu Siemens Amilo D7820 */
963 .callback = dmi_matched,
965 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"), /* not sure */
966 DMI_MATCH(DMI_PRODUCT_NAME, "Amilo D"),
968 .driver_data = keymap_fs_amilo_d88x0
971 /* Fujitsu Siemens Amilo D88x0 */
972 .callback = dmi_matched,
974 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
975 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO D"),
977 .driver_data = keymap_fs_amilo_d88x0
981 MODULE_DEVICE_TABLE(dmi, dmi_ids);
983 /* Copy the good keymap, as the original ones are free'd */
984 static int __init copy_keymap(void)
986 const struct key_entry *key;
987 struct key_entry *new_keymap;
988 unsigned int length = 1;
990 for (key = keymap; key->type != KE_END; key++)
993 new_keymap = kmemdup(keymap, length * sizeof(struct key_entry),
1003 static int __init select_keymap(void)
1005 dmi_check_system(dmi_ids);
1006 if (keymap_name != NULL) {
1007 if (strcmp (keymap_name, "1557/MS2141") == 0)
1008 keymap = keymap_wistron_ms2141;
1009 else if (strcmp (keymap_name, "aopen1557") == 0)
1010 keymap = keymap_aopen_1557;
1011 else if (strcmp (keymap_name, "prestigio") == 0)
1012 keymap = keymap_prestigio;
1013 else if (strcmp (keymap_name, "generic") == 0)
1014 keymap = keymap_wistron_generic;
1016 printk(KERN_ERR "wistron_btns: Keymap unknown\n");
1020 if (keymap == NULL) {
1022 printk(KERN_ERR "wistron_btns: System unknown\n");
1025 keymap = keymap_empty;
1028 return copy_keymap();
1031 /* Input layer interface */
1033 static struct input_dev *wistron_idev;
1034 static unsigned long jiffies_last_press;
1035 static bool wifi_enabled;
1036 static bool bluetooth_enabled;
1038 /* led management */
1039 static void wistron_mail_led_set(struct led_classdev *led_cdev,
1040 enum led_brightness value)
1042 bios_set_state(MAIL_LED, (value != LED_OFF) ? 1 : 0);
1045 /* same as setting up wifi card, but for laptops on which the led is managed */
1046 static void wistron_wifi_led_set(struct led_classdev *led_cdev,
1047 enum led_brightness value)
1049 bios_set_state(WIFI, (value != LED_OFF) ? 1 : 0);
1052 static struct led_classdev wistron_mail_led = {
1053 .name = "wistron:green:mail",
1054 .brightness_set = wistron_mail_led_set,
1057 static struct led_classdev wistron_wifi_led = {
1058 .name = "wistron:red:wifi",
1059 .brightness_set = wistron_wifi_led_set,
1062 static void wistron_led_init(struct device *parent)
1064 if (leds_present & FE_WIFI_LED) {
1065 u16 wifi = bios_get_default_setting(WIFI);
1067 wistron_wifi_led.brightness = (wifi & 2) ? LED_FULL : LED_OFF;
1068 if (led_classdev_register(parent, &wistron_wifi_led))
1069 leds_present &= ~FE_WIFI_LED;
1071 bios_set_state(WIFI, wistron_wifi_led.brightness);
1074 leds_present &= ~FE_WIFI_LED;
1077 if (leds_present & FE_MAIL_LED) {
1078 /* bios_get_default_setting(MAIL) always retuns 0, so just turn the led off */
1079 wistron_mail_led.brightness = LED_OFF;
1080 if (led_classdev_register(parent, &wistron_mail_led))
1081 leds_present &= ~FE_MAIL_LED;
1083 bios_set_state(MAIL_LED, wistron_mail_led.brightness);
1087 static void wistron_led_remove(void)
1089 if (leds_present & FE_MAIL_LED)
1090 led_classdev_unregister(&wistron_mail_led);
1092 if (leds_present & FE_WIFI_LED)
1093 led_classdev_unregister(&wistron_wifi_led);
1096 static inline void wistron_led_suspend(void)
1098 if (leds_present & FE_MAIL_LED)
1099 led_classdev_suspend(&wistron_mail_led);
1101 if (leds_present & FE_WIFI_LED)
1102 led_classdev_suspend(&wistron_wifi_led);
1105 static inline void wistron_led_resume(void)
1107 if (leds_present & FE_MAIL_LED)
1108 led_classdev_resume(&wistron_mail_led);
1110 if (leds_present & FE_WIFI_LED)
1111 led_classdev_resume(&wistron_wifi_led);
1114 static void handle_key(u8 code)
1116 const struct key_entry *key =
1117 sparse_keymap_entry_from_scancode(wistron_idev, code);
1120 switch (key->type) {
1123 wifi_enabled = !wifi_enabled;
1124 bios_set_state(WIFI, wifi_enabled);
1129 if (have_bluetooth) {
1130 bluetooth_enabled = !bluetooth_enabled;
1131 bios_set_state(BLUETOOTH, bluetooth_enabled);
1136 sparse_keymap_report_entry(wistron_idev, key, 1, true);
1139 jiffies_last_press = jiffies;
1142 "wistron_btns: Unknown key code %02X\n", code);
1146 static void poll_bios(bool discard)
1152 qlen = CMOS_READ(cmos_address);
1155 val = bios_pop_queue();
1156 if (val != 0 && !discard)
1157 handle_key((u8)val);
1161 static int wistron_flush(struct input_dev *dev)
1163 /* Flush stale event queue */
1169 static void wistron_poll(struct input_dev *dev)
1173 /* Increase poll frequency if user is currently pressing keys (< 2s ago) */
1174 if (time_before(jiffies, jiffies_last_press + 2 * HZ))
1175 input_set_poll_interval(dev, POLL_INTERVAL_BURST);
1177 input_set_poll_interval(dev, POLL_INTERVAL_DEFAULT);
1180 static int wistron_setup_keymap(struct input_dev *dev,
1181 struct key_entry *entry)
1183 switch (entry->type) {
1185 /* if wifi or bluetooth are not available, create normal keys */
1188 entry->type = KE_KEY;
1189 entry->keycode = KEY_WLAN;
1194 if (!have_bluetooth) {
1195 entry->type = KE_KEY;
1196 entry->keycode = KEY_BLUETOOTH;
1201 if (entry->code & FE_UNTESTED)
1202 printk(KERN_WARNING "Untested laptop multimedia keys, "
1203 "please report success or failure to "
1204 "eric.piel@tremplin-utc.net\n");
1211 static int setup_input_dev(void)
1215 wistron_idev = input_allocate_device();
1219 wistron_idev->name = "Wistron laptop buttons";
1220 wistron_idev->phys = "wistron/input0";
1221 wistron_idev->id.bustype = BUS_HOST;
1222 wistron_idev->dev.parent = &wistron_device->dev;
1224 wistron_idev->open = wistron_flush;
1226 error = sparse_keymap_setup(wistron_idev, keymap, wistron_setup_keymap);
1230 error = input_setup_polling(wistron_idev, wistron_poll);
1234 input_set_poll_interval(wistron_idev, POLL_INTERVAL_DEFAULT);
1236 error = input_register_device(wistron_idev);
1243 input_free_device(wistron_idev);
1249 static int wistron_probe(struct platform_device *dev)
1254 cmos_address = bios_get_cmos_address();
1257 u16 wifi = bios_get_default_setting(WIFI);
1259 wifi_enabled = wifi & 2;
1264 bios_set_state(WIFI, wifi_enabled);
1267 if (have_bluetooth) {
1268 u16 bt = bios_get_default_setting(BLUETOOTH);
1270 bluetooth_enabled = bt & 2;
1272 have_bluetooth = false;
1275 bios_set_state(BLUETOOTH, bluetooth_enabled);
1278 wistron_led_init(&dev->dev);
1280 err = setup_input_dev();
1289 static int wistron_remove(struct platform_device *dev)
1291 wistron_led_remove();
1292 input_unregister_device(wistron_idev);
1298 static int wistron_suspend(struct device *dev)
1301 bios_set_state(WIFI, 0);
1304 bios_set_state(BLUETOOTH, 0);
1306 wistron_led_suspend();
1311 static int wistron_resume(struct device *dev)
1314 bios_set_state(WIFI, wifi_enabled);
1317 bios_set_state(BLUETOOTH, bluetooth_enabled);
1319 wistron_led_resume();
1326 static const struct dev_pm_ops wistron_pm_ops = {
1327 .suspend = wistron_suspend,
1328 .resume = wistron_resume,
1329 .poweroff = wistron_suspend,
1330 .restore = wistron_resume,
1333 static struct platform_driver wistron_driver = {
1335 .name = "wistron-bios",
1336 .pm = pm_sleep_ptr(&wistron_pm_ops),
1338 .probe = wistron_probe,
1339 .remove = wistron_remove,
1342 static int __init wb_module_init(void)
1346 err = select_keymap();
1352 goto err_free_keymap;
1354 err = platform_driver_register(&wistron_driver);
1356 goto err_unmap_bios;
1358 wistron_device = platform_device_alloc("wistron-bios", -1);
1359 if (!wistron_device) {
1361 goto err_unregister_driver;
1364 err = platform_device_add(wistron_device);
1366 goto err_free_device;
1371 platform_device_put(wistron_device);
1372 err_unregister_driver:
1373 platform_driver_unregister(&wistron_driver);
1382 static void __exit wb_module_exit(void)
1384 platform_device_unregister(wistron_device);
1385 platform_driver_unregister(&wistron_driver);
1390 module_init(wb_module_init);
1391 module_exit(wb_module_exit);