2 * Wistron laptop button driver
3 * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz>
4 * Copyright (C) 2005 Bernhard Rosenkraenzer <bero@arklinux.org>
5 * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru>
7 * You can redistribute and/or modify this program under the terms of the
8 * GNU General Public License version 2 as published by the Free Software
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14 * Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 59 Temple Place Suite 330, Boston, MA 02111-1307, USA.
21 #include <linux/dmi.h>
22 #include <linux/init.h>
23 #include <linux/input.h>
24 #include <linux/interrupt.h>
25 #include <linux/kernel.h>
26 #include <linux/mc146818rtc.h>
27 #include <linux/module.h>
28 #include <linux/preempt.h>
29 #include <linux/string.h>
30 #include <linux/timer.h>
31 #include <linux/types.h>
32 #include <linux/platform_device.h>
35 * Number of attempts to read data from queue per poll;
36 * the queue can hold up to 31 entries
38 #define MAX_POLL_ITERATIONS 64
40 #define POLL_FREQUENCY 10 /* Number of polls per second */
42 #if POLL_FREQUENCY > HZ
43 #error "POLL_FREQUENCY too high"
46 /* BIOS subsystem IDs */
48 #define BLUETOOTH 0x34
50 MODULE_AUTHOR("Miloslav Trmac <mitr@volny.cz>");
51 MODULE_DESCRIPTION("Wistron laptop button driver");
52 MODULE_LICENSE("GPL v2");
53 MODULE_VERSION("0.2");
55 static int force; /* = 0; */
56 module_param(force, bool, 0);
57 MODULE_PARM_DESC(force, "Load even if computer is not in database");
59 static char *keymap_name; /* = NULL; */
60 module_param_named(keymap, keymap_name, charp, 0);
61 MODULE_PARM_DESC(keymap, "Keymap name, if it can't be autodetected [generic, 1557/MS2141]");
63 static struct platform_device *wistron_device;
65 /* BIOS interface implementation */
67 static void __iomem *bios_entry_point; /* BIOS routine entry point */
68 static void __iomem *bios_code_map_base;
69 static void __iomem *bios_data_map_base;
71 static u8 cmos_address;
77 static void call_bios(struct regs *regs)
82 local_irq_save(flags);
83 asm volatile ("pushl %%ebp;"
87 : "=a" (regs->eax), "=b" (regs->ebx), "=c" (regs->ecx)
88 : "0" (regs->eax), "1" (regs->ebx), "2" (regs->ecx),
89 "m" (bios_entry_point), "m" (bios_data_map_base)
90 : "edx", "edi", "esi", "memory");
91 local_irq_restore(flags);
95 static ssize_t __init locate_wistron_bios(void __iomem *base)
97 static unsigned char __initdata signature[] =
98 { 0x42, 0x21, 0x55, 0x30 };
101 for (offset = 0; offset < 0x10000; offset += 0x10) {
102 if (check_signature(base + offset, signature,
103 sizeof(signature)) != 0)
109 static int __init map_bios(void)
115 base = ioremap(0xF0000, 0x10000); /* Can't fail */
116 offset = locate_wistron_bios(base);
118 printk(KERN_ERR "wistron_btns: BIOS entry point not found\n");
123 entry_point = readl(base + offset + 5);
125 "wistron_btns: BIOS signature found at %p, entry point %08X\n",
126 base + offset, entry_point);
128 if (entry_point >= 0xF0000) {
129 bios_code_map_base = base;
130 bios_entry_point = bios_code_map_base + (entry_point & 0xFFFF);
133 bios_code_map_base = ioremap(entry_point & ~0x3FFF, 0x4000);
134 if (bios_code_map_base == NULL) {
136 "wistron_btns: Can't map BIOS code at %08X\n",
137 entry_point & ~0x3FFF);
140 bios_entry_point = bios_code_map_base + (entry_point & 0x3FFF);
142 /* The Windows driver maps 0x10000 bytes, we keep only one page... */
143 bios_data_map_base = ioremap(0x400, 0xc00);
144 if (bios_data_map_base == NULL) {
145 printk(KERN_ERR "wistron_btns: Can't map BIOS data\n");
151 iounmap(bios_code_map_base);
156 static inline void unmap_bios(void)
158 iounmap(bios_code_map_base);
159 iounmap(bios_data_map_base);
164 static u16 bios_pop_queue(void)
168 memset(®s, 0, sizeof (regs));
177 static void __devinit bios_attach(void)
181 memset(®s, 0, sizeof (regs));
187 static void bios_detach(void)
191 memset(®s, 0, sizeof (regs));
197 static u8 __devinit bios_get_cmos_address(void)
201 memset(®s, 0, sizeof (regs));
209 static u16 __devinit bios_get_default_setting(u8 subsys)
213 memset(®s, 0, sizeof (regs));
215 regs.ebx = 0x0200 | subsys;
221 static void bios_set_state(u8 subsys, int enable)
225 memset(®s, 0, sizeof (regs));
227 regs.ebx = (enable ? 0x0100 : 0x0000) | subsys;
231 /* Hardware database */
234 char type; /* See KE_* below */
237 u16 keycode; /* For KE_KEY */
238 struct { /* For KE_SW */
245 enum { KE_END, KE_KEY, KE_SW, KE_WIFI, KE_BLUETOOTH };
247 #define FE_MAIL_LED 0x01
248 #define FE_WIFI_LED 0x02
249 #define FE_UNTESTED 0x80
251 static const struct key_entry *keymap; /* = NULL; Current key map */
252 static int have_wifi;
253 static int have_bluetooth;
255 static int __init dmi_matched(struct dmi_system_id *dmi)
257 const struct key_entry *key;
259 keymap = dmi->driver_data;
260 for (key = keymap; key->type != KE_END; key++) {
261 if (key->type == KE_WIFI)
263 else if (key->type == KE_BLUETOOTH)
269 static struct key_entry keymap_empty[] __initdata = {
273 static struct key_entry keymap_fs_amilo_pro_v2000[] __initdata = {
274 { KE_KEY, 0x01, {KEY_HELP} },
275 { KE_KEY, 0x11, {KEY_PROG1} },
276 { KE_KEY, 0x12, {KEY_PROG2} },
278 { KE_KEY, 0x31, {KEY_MAIL} },
279 { KE_KEY, 0x36, {KEY_WWW} },
283 static struct key_entry keymap_fujitsu_n3510[] __initdata = {
284 { KE_KEY, 0x11, {KEY_PROG1} },
285 { KE_KEY, 0x12, {KEY_PROG2} },
286 { KE_KEY, 0x36, {KEY_WWW} },
287 { KE_KEY, 0x31, {KEY_MAIL} },
288 { KE_KEY, 0x71, {KEY_STOPCD} },
289 { KE_KEY, 0x72, {KEY_PLAYPAUSE} },
290 { KE_KEY, 0x74, {KEY_REWIND} },
291 { KE_KEY, 0x78, {KEY_FORWARD} },
295 static struct key_entry keymap_wistron_ms2111[] __initdata = {
296 { KE_KEY, 0x11, {KEY_PROG1} },
297 { KE_KEY, 0x12, {KEY_PROG2} },
298 { KE_KEY, 0x13, {KEY_PROG3} },
299 { KE_KEY, 0x31, {KEY_MAIL} },
300 { KE_KEY, 0x36, {KEY_WWW} },
301 { KE_END, FE_MAIL_LED }
304 static struct key_entry keymap_wistron_md40100[] __initdata = {
305 { KE_KEY, 0x01, {KEY_HELP} },
306 { KE_KEY, 0x02, {KEY_CONFIG} },
307 { KE_KEY, 0x31, {KEY_MAIL} },
308 { KE_KEY, 0x36, {KEY_WWW} },
309 { KE_KEY, 0x37, {KEY_DISPLAYTOGGLE} }, /* Display on/off */
310 { KE_END, FE_MAIL_LED | FE_WIFI_LED | FE_UNTESTED }
313 static struct key_entry keymap_wistron_ms2141[] __initdata = {
314 { KE_KEY, 0x11, {KEY_PROG1} },
315 { KE_KEY, 0x12, {KEY_PROG2} },
317 { KE_KEY, 0x22, {KEY_REWIND} },
318 { KE_KEY, 0x23, {KEY_FORWARD} },
319 { KE_KEY, 0x24, {KEY_PLAYPAUSE} },
320 { KE_KEY, 0x25, {KEY_STOPCD} },
321 { KE_KEY, 0x31, {KEY_MAIL} },
322 { KE_KEY, 0x36, {KEY_WWW} },
326 static struct key_entry keymap_acer_aspire_1500[] __initdata = {
327 { KE_KEY, 0x01, {KEY_HELP} },
328 { KE_KEY, 0x03, {KEY_POWER} },
329 { KE_KEY, 0x11, {KEY_PROG1} },
330 { KE_KEY, 0x12, {KEY_PROG2} },
332 { KE_KEY, 0x31, {KEY_MAIL} },
333 { KE_KEY, 0x36, {KEY_WWW} },
334 { KE_KEY, 0x49, {KEY_CONFIG} },
335 { KE_BLUETOOTH, 0x44 },
336 { KE_END, FE_UNTESTED }
339 static struct key_entry keymap_acer_aspire_1600[] __initdata = {
340 { KE_KEY, 0x01, {KEY_HELP} },
341 { KE_KEY, 0x03, {KEY_POWER} },
342 { KE_KEY, 0x08, {KEY_MUTE} },
343 { KE_KEY, 0x11, {KEY_PROG1} },
344 { KE_KEY, 0x12, {KEY_PROG2} },
345 { KE_KEY, 0x13, {KEY_PROG3} },
346 { KE_KEY, 0x31, {KEY_MAIL} },
347 { KE_KEY, 0x36, {KEY_WWW} },
348 { KE_KEY, 0x49, {KEY_CONFIG} },
350 { KE_BLUETOOTH, 0x44 },
351 { KE_END, FE_MAIL_LED | FE_UNTESTED }
354 /* 3020 has been tested */
355 static struct key_entry keymap_acer_aspire_5020[] __initdata = {
356 { KE_KEY, 0x01, {KEY_HELP} },
357 { KE_KEY, 0x03, {KEY_POWER} },
358 { KE_KEY, 0x05, {KEY_SWITCHVIDEOMODE} }, /* Display selection */
359 { KE_KEY, 0x11, {KEY_PROG1} },
360 { KE_KEY, 0x12, {KEY_PROG2} },
361 { KE_KEY, 0x31, {KEY_MAIL} },
362 { KE_KEY, 0x36, {KEY_WWW} },
363 { KE_KEY, 0x6a, {KEY_CONFIG} },
365 { KE_BLUETOOTH, 0x44 },
366 { KE_END, FE_MAIL_LED | FE_UNTESTED }
369 static struct key_entry keymap_acer_travelmate_2410[] __initdata = {
370 { KE_KEY, 0x01, {KEY_HELP} },
371 { KE_KEY, 0x6d, {KEY_POWER} },
372 { KE_KEY, 0x11, {KEY_PROG1} },
373 { KE_KEY, 0x12, {KEY_PROG2} },
374 { KE_KEY, 0x31, {KEY_MAIL} },
375 { KE_KEY, 0x36, {KEY_WWW} },
376 { KE_KEY, 0x6a, {KEY_CONFIG} },
378 { KE_BLUETOOTH, 0x44 },
379 { KE_END, FE_MAIL_LED | FE_UNTESTED }
382 static struct key_entry keymap_acer_travelmate_110[] __initdata = {
383 { KE_KEY, 0x01, {KEY_HELP} },
384 { KE_KEY, 0x02, {KEY_CONFIG} },
385 { KE_KEY, 0x03, {KEY_POWER} },
386 { KE_KEY, 0x08, {KEY_MUTE} },
387 { KE_KEY, 0x11, {KEY_PROG1} },
388 { KE_KEY, 0x12, {KEY_PROG2} },
389 { KE_KEY, 0x20, {KEY_VOLUMEUP} },
390 { KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
391 { KE_KEY, 0x31, {KEY_MAIL} },
392 { KE_KEY, 0x36, {KEY_WWW} },
393 { KE_SW, 0x4a, {.sw = {SW_LID, 1}} }, /* lid close */
394 { KE_SW, 0x4b, {.sw = {SW_LID, 0}} }, /* lid open */
396 { KE_END, FE_MAIL_LED | FE_UNTESTED }
399 static struct key_entry keymap_acer_travelmate_300[] __initdata = {
400 { KE_KEY, 0x01, {KEY_HELP} },
401 { KE_KEY, 0x02, {KEY_CONFIG} },
402 { KE_KEY, 0x03, {KEY_POWER} },
403 { KE_KEY, 0x08, {KEY_MUTE} },
404 { KE_KEY, 0x11, {KEY_PROG1} },
405 { KE_KEY, 0x12, {KEY_PROG2} },
406 { KE_KEY, 0x20, {KEY_VOLUMEUP} },
407 { KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
408 { KE_KEY, 0x31, {KEY_MAIL} },
409 { KE_KEY, 0x36, {KEY_WWW} },
411 { KE_BLUETOOTH, 0x44 },
412 { KE_END, FE_MAIL_LED | FE_UNTESTED }
415 static struct key_entry keymap_acer_travelmate_380[] __initdata = {
416 { KE_KEY, 0x01, {KEY_HELP} },
417 { KE_KEY, 0x02, {KEY_CONFIG} },
418 { KE_KEY, 0x03, {KEY_POWER} }, /* not 370 */
419 { KE_KEY, 0x11, {KEY_PROG1} },
420 { KE_KEY, 0x12, {KEY_PROG2} },
421 { KE_KEY, 0x13, {KEY_PROG3} },
422 { KE_KEY, 0x31, {KEY_MAIL} },
423 { KE_KEY, 0x36, {KEY_WWW} },
425 { KE_END, FE_MAIL_LED | FE_UNTESTED }
429 static struct key_entry keymap_acer_travelmate_220[] __initdata = {
430 { KE_KEY, 0x01, {KEY_HELP} },
431 { KE_KEY, 0x02, {KEY_CONFIG} },
432 { KE_KEY, 0x11, {KEY_MAIL} },
433 { KE_KEY, 0x12, {KEY_WWW} },
434 { KE_KEY, 0x13, {KEY_PROG2} },
435 { KE_KEY, 0x31, {KEY_PROG1} },
436 { KE_END, FE_WIFI_LED | FE_UNTESTED }
439 static struct key_entry keymap_acer_travelmate_230[] __initdata = {
440 { KE_KEY, 0x01, {KEY_HELP} },
441 { KE_KEY, 0x02, {KEY_CONFIG} },
442 { KE_KEY, 0x11, {KEY_PROG1} },
443 { KE_KEY, 0x12, {KEY_PROG2} },
444 { KE_KEY, 0x31, {KEY_MAIL} },
445 { KE_KEY, 0x36, {KEY_WWW} },
446 { KE_END, FE_WIFI_LED | FE_UNTESTED }
449 static struct key_entry keymap_acer_travelmate_240[] __initdata = {
450 { KE_KEY, 0x01, {KEY_HELP} },
451 { KE_KEY, 0x02, {KEY_CONFIG} },
452 { KE_KEY, 0x03, {KEY_POWER} },
453 { KE_KEY, 0x08, {KEY_MUTE} },
454 { KE_KEY, 0x31, {KEY_MAIL} },
455 { KE_KEY, 0x36, {KEY_WWW} },
456 { KE_KEY, 0x11, {KEY_PROG1} },
457 { KE_KEY, 0x12, {KEY_PROG2} },
458 { KE_BLUETOOTH, 0x44 },
460 { KE_END, FE_UNTESTED }
463 static struct key_entry keymap_acer_travelmate_350[] __initdata = {
464 { KE_KEY, 0x01, {KEY_HELP} },
465 { KE_KEY, 0x02, {KEY_CONFIG} },
466 { KE_KEY, 0x11, {KEY_PROG1} },
467 { KE_KEY, 0x12, {KEY_PROG2} },
468 { KE_KEY, 0x13, {KEY_MAIL} },
469 { KE_KEY, 0x14, {KEY_PROG3} },
470 { KE_KEY, 0x15, {KEY_WWW} },
471 { KE_END, FE_MAIL_LED | FE_WIFI_LED | FE_UNTESTED }
474 static struct key_entry keymap_acer_travelmate_360[] __initdata = {
475 { KE_KEY, 0x01, {KEY_HELP} },
476 { KE_KEY, 0x02, {KEY_CONFIG} },
477 { KE_KEY, 0x11, {KEY_PROG1} },
478 { KE_KEY, 0x12, {KEY_PROG2} },
479 { KE_KEY, 0x13, {KEY_MAIL} },
480 { KE_KEY, 0x14, {KEY_PROG3} },
481 { KE_KEY, 0x15, {KEY_WWW} },
482 { KE_KEY, 0x40, {KEY_WLAN} },
483 { KE_END, FE_WIFI_LED | FE_UNTESTED } /* no mail led */
486 /* Wifi subsystem only activates the led. Therefore we need to pass
487 * wifi event as a normal key, then userspace can really change the wifi state.
488 * TODO we need to export led state to userspace (wifi and mail) */
489 static struct key_entry keymap_acer_travelmate_610[] __initdata = {
490 { KE_KEY, 0x01, {KEY_HELP} },
491 { KE_KEY, 0x02, {KEY_CONFIG} },
492 { KE_KEY, 0x11, {KEY_PROG1} },
493 { KE_KEY, 0x12, {KEY_PROG2} },
494 { KE_KEY, 0x13, {KEY_PROG3} },
495 { KE_KEY, 0x14, {KEY_MAIL} },
496 { KE_KEY, 0x15, {KEY_WWW} },
497 { KE_KEY, 0x40, {KEY_WLAN} },
498 { KE_END, FE_MAIL_LED | FE_WIFI_LED }
501 static struct key_entry keymap_acer_travelmate_630[] __initdata = {
502 { KE_KEY, 0x01, {KEY_HELP} },
503 { KE_KEY, 0x02, {KEY_CONFIG} },
504 { KE_KEY, 0x03, {KEY_POWER} },
505 { KE_KEY, 0x08, {KEY_MUTE} }, /* not 620 */
506 { KE_KEY, 0x11, {KEY_PROG1} },
507 { KE_KEY, 0x12, {KEY_PROG2} },
508 { KE_KEY, 0x13, {KEY_PROG3} },
509 { KE_KEY, 0x20, {KEY_VOLUMEUP} },
510 { KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
511 { KE_KEY, 0x31, {KEY_MAIL} },
512 { KE_KEY, 0x36, {KEY_WWW} },
514 { KE_END, FE_MAIL_LED | FE_UNTESTED }
517 static struct key_entry keymap_aopen_1559as[] __initdata = {
518 { KE_KEY, 0x01, {KEY_HELP} },
519 { KE_KEY, 0x06, {KEY_PROG3} },
520 { KE_KEY, 0x11, {KEY_PROG1} },
521 { KE_KEY, 0x12, {KEY_PROG2} },
523 { KE_KEY, 0x31, {KEY_MAIL} },
524 { KE_KEY, 0x36, {KEY_WWW} },
528 static struct key_entry keymap_fs_amilo_d88x0[] __initdata = {
529 { KE_KEY, 0x01, {KEY_HELP} },
530 { KE_KEY, 0x08, {KEY_MUTE} },
531 { KE_KEY, 0x31, {KEY_MAIL} },
532 { KE_KEY, 0x36, {KEY_WWW} },
533 { KE_KEY, 0x11, {KEY_PROG1} },
534 { KE_KEY, 0x12, {KEY_PROG2} },
535 { KE_KEY, 0x13, {KEY_PROG3} },
536 { KE_END, FE_MAIL_LED | FE_WIFI_LED | FE_UNTESTED }
539 static struct key_entry keymap_wistron_md2900[] __initdata = {
540 { KE_KEY, 0x01, {KEY_HELP} },
541 { KE_KEY, 0x02, {KEY_CONFIG} },
542 { KE_KEY, 0x11, {KEY_PROG1} },
543 { KE_KEY, 0x12, {KEY_PROG2} },
544 { KE_KEY, 0x31, {KEY_MAIL} },
545 { KE_KEY, 0x36, {KEY_WWW} },
547 { KE_END, FE_MAIL_LED | FE_UNTESTED }
550 static struct key_entry keymap_wistron_md96500[] __initdata = {
551 { KE_KEY, 0x01, {KEY_HELP} },
552 { KE_KEY, 0x02, {KEY_CONFIG} },
553 { KE_KEY, 0x05, {KEY_SWITCHVIDEOMODE} }, /* Display selection */
554 { KE_KEY, 0x06, {KEY_DISPLAYTOGGLE} }, /* Display on/off */
555 { KE_KEY, 0x08, {KEY_MUTE} },
556 { KE_KEY, 0x11, {KEY_PROG1} },
557 { KE_KEY, 0x12, {KEY_PROG2} },
558 { KE_KEY, 0x20, {KEY_VOLUMEUP} },
559 { KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
560 { KE_KEY, 0x22, {KEY_REWIND} },
561 { KE_KEY, 0x23, {KEY_FORWARD} },
562 { KE_KEY, 0x24, {KEY_PLAYPAUSE} },
563 { KE_KEY, 0x25, {KEY_STOPCD} },
564 { KE_KEY, 0x31, {KEY_MAIL} },
565 { KE_KEY, 0x36, {KEY_WWW} },
567 { KE_BLUETOOTH, 0x44 },
568 { KE_END, FE_UNTESTED }
571 static struct key_entry keymap_wistron_generic[] __initdata = {
572 { KE_KEY, 0x01, {KEY_HELP} },
573 { KE_KEY, 0x02, {KEY_CONFIG} },
574 { KE_KEY, 0x03, {KEY_POWER} },
575 { KE_KEY, 0x05, {KEY_SWITCHVIDEOMODE} }, /* Display selection */
576 { KE_KEY, 0x06, {KEY_DISPLAYTOGGLE} }, /* Display on/off */
577 { KE_KEY, 0x08, {KEY_MUTE} },
578 { KE_KEY, 0x11, {KEY_PROG1} },
579 { KE_KEY, 0x12, {KEY_PROG2} },
580 { KE_KEY, 0x13, {KEY_PROG3} },
581 { KE_KEY, 0x14, {KEY_MAIL} },
582 { KE_KEY, 0x15, {KEY_WWW} },
583 { KE_KEY, 0x20, {KEY_VOLUMEUP} },
584 { KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
585 { KE_KEY, 0x22, {KEY_REWIND} },
586 { KE_KEY, 0x23, {KEY_FORWARD} },
587 { KE_KEY, 0x24, {KEY_PLAYPAUSE} },
588 { KE_KEY, 0x25, {KEY_STOPCD} },
589 { KE_KEY, 0x31, {KEY_MAIL} },
590 { KE_KEY, 0x36, {KEY_WWW} },
591 { KE_KEY, 0x37, {KEY_DISPLAYTOGGLE} }, /* Display on/off */
592 { KE_KEY, 0x40, {KEY_WLAN} },
593 { KE_KEY, 0x49, {KEY_CONFIG} },
594 { KE_SW, 0x4a, {.sw = {SW_LID, 1}} }, /* lid close */
595 { KE_SW, 0x4b, {.sw = {SW_LID, 0}} }, /* lid open */
596 { KE_KEY, 0x6a, {KEY_CONFIG} },
597 { KE_KEY, 0x6d, {KEY_POWER} },
598 { KE_KEY, 0x71, {KEY_STOPCD} },
599 { KE_KEY, 0x72, {KEY_PLAYPAUSE} },
600 { KE_KEY, 0x74, {KEY_REWIND} },
601 { KE_KEY, 0x78, {KEY_FORWARD} },
603 { KE_BLUETOOTH, 0x44 },
608 * If your machine is not here (which is currently rather likely), please send
609 * a list of buttons and their key codes (reported when loading this module
610 * with force=1) and the output of dmidecode to $MODULE_AUTHOR.
612 static struct dmi_system_id dmi_ids[] __initdata = {
614 .callback = dmi_matched,
615 .ident = "Fujitsu-Siemens Amilo Pro V2000",
617 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
618 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pro V2000"),
620 .driver_data = keymap_fs_amilo_pro_v2000
623 .callback = dmi_matched,
624 .ident = "Fujitsu-Siemens Amilo M7400",
626 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
627 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO M "),
629 .driver_data = keymap_fs_amilo_pro_v2000
632 .callback = dmi_matched,
633 .ident = "Fujitsu N3510",
635 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
636 DMI_MATCH(DMI_PRODUCT_NAME, "N3510"),
638 .driver_data = keymap_fujitsu_n3510
641 .callback = dmi_matched,
642 .ident = "Acer Aspire 1500",
644 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
645 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1500"),
647 .driver_data = keymap_acer_aspire_1500
650 .callback = dmi_matched,
651 .ident = "Acer Aspire 1600",
653 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
654 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1600"),
656 .driver_data = keymap_acer_aspire_1600
659 .callback = dmi_matched,
660 .ident = "Acer Aspire 3020",
662 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
663 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3020"),
665 .driver_data = keymap_acer_aspire_5020
668 .callback = dmi_matched,
669 .ident = "Acer Aspire 5020",
671 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
672 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5020"),
674 .driver_data = keymap_acer_aspire_5020
677 .callback = dmi_matched,
678 .ident = "Acer TravelMate 2100",
680 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
681 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2100"),
683 .driver_data = keymap_acer_aspire_5020
686 .callback = dmi_matched,
687 .ident = "Acer TravelMate 2410",
689 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
690 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2410"),
692 .driver_data = keymap_acer_travelmate_2410
695 .callback = dmi_matched,
696 .ident = "Acer TravelMate C300",
698 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
699 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate C300"),
701 .driver_data = keymap_acer_travelmate_300
704 .callback = dmi_matched,
705 .ident = "Acer TravelMate C100",
707 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
708 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate C100"),
710 .driver_data = keymap_acer_travelmate_300
713 .callback = dmi_matched,
714 .ident = "Acer TravelMate C110",
716 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
717 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate C110"),
719 .driver_data = keymap_acer_travelmate_110
722 .callback = dmi_matched,
723 .ident = "Acer TravelMate 380",
725 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
726 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 380"),
728 .driver_data = keymap_acer_travelmate_380
731 .callback = dmi_matched,
732 .ident = "Acer TravelMate 370",
734 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
735 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 370"),
737 .driver_data = keymap_acer_travelmate_380 /* keyboard minus 1 key */
740 .callback = dmi_matched,
741 .ident = "Acer TravelMate 220",
743 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
744 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 220"),
746 .driver_data = keymap_acer_travelmate_220
749 .callback = dmi_matched,
750 .ident = "Acer TravelMate 260",
752 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
753 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 260"),
755 .driver_data = keymap_acer_travelmate_220
758 .callback = dmi_matched,
759 .ident = "Acer TravelMate 230",
761 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
762 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 230"),
763 /* acerhk looks for "TravelMate F4..." ?! */
765 .driver_data = keymap_acer_travelmate_230
768 .callback = dmi_matched,
769 .ident = "Acer TravelMate 280",
771 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
772 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 280"),
774 .driver_data = keymap_acer_travelmate_230
777 .callback = dmi_matched,
778 .ident = "Acer TravelMate 240",
780 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
781 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 240"),
783 .driver_data = keymap_acer_travelmate_240
786 .callback = dmi_matched,
787 .ident = "Acer TravelMate 250",
789 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
790 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 250"),
792 .driver_data = keymap_acer_travelmate_240
795 .callback = dmi_matched,
796 .ident = "Acer TravelMate 2424NWXCi",
798 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
799 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2420"),
801 .driver_data = keymap_acer_travelmate_240
804 .callback = dmi_matched,
805 .ident = "Acer TravelMate 350",
807 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
808 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 350"),
810 .driver_data = keymap_acer_travelmate_350
813 .callback = dmi_matched,
814 .ident = "Acer TravelMate 360",
816 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
817 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
819 .driver_data = keymap_acer_travelmate_360
822 .callback = dmi_matched,
823 .ident = "Acer TravelMate 610",
825 DMI_MATCH(DMI_SYS_VENDOR, "ACER"),
826 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 610"),
828 .driver_data = keymap_acer_travelmate_610
831 .callback = dmi_matched,
832 .ident = "Acer TravelMate 620",
834 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
835 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 620"),
837 .driver_data = keymap_acer_travelmate_630
840 .callback = dmi_matched,
841 .ident = "Acer TravelMate 630",
843 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
844 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 630"),
846 .driver_data = keymap_acer_travelmate_630
849 .callback = dmi_matched,
850 .ident = "AOpen 1559AS",
852 DMI_MATCH(DMI_PRODUCT_NAME, "E2U"),
853 DMI_MATCH(DMI_BOARD_NAME, "E2U"),
855 .driver_data = keymap_aopen_1559as
858 .callback = dmi_matched,
859 .ident = "Medion MD 9783",
861 DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
862 DMI_MATCH(DMI_PRODUCT_NAME, "MD 9783"),
864 .driver_data = keymap_wistron_ms2111
867 .callback = dmi_matched,
868 .ident = "Medion MD 40100",
870 DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
871 DMI_MATCH(DMI_PRODUCT_NAME, "WID2000"),
873 .driver_data = keymap_wistron_md40100
876 .callback = dmi_matched,
877 .ident = "Medion MD 2900",
879 DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
880 DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2000"),
882 .driver_data = keymap_wistron_md2900
885 .callback = dmi_matched,
886 .ident = "Medion MD 96500",
888 DMI_MATCH(DMI_SYS_VENDOR, "MEDIONPC"),
889 DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2040"),
891 .driver_data = keymap_wistron_md96500
894 .callback = dmi_matched,
895 .ident = "Medion MD 95400",
897 DMI_MATCH(DMI_SYS_VENDOR, "MEDIONPC"),
898 DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2050"),
900 .driver_data = keymap_wistron_md96500
903 .callback = dmi_matched,
904 .ident = "Fujitsu Siemens Amilo D7820",
906 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"), /* not sure */
907 DMI_MATCH(DMI_PRODUCT_NAME, "Amilo D"),
909 .driver_data = keymap_fs_amilo_d88x0
912 .callback = dmi_matched,
913 .ident = "Fujitsu Siemens Amilo D88x0",
915 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
916 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO D"),
918 .driver_data = keymap_fs_amilo_d88x0
923 /* Copy the good keymap, as the original ones are free'd */
924 static int __init copy_keymap(void)
926 const struct key_entry *key;
927 struct key_entry *new_keymap;
928 unsigned int length = 1;
930 for (key = keymap; key->type != KE_END; key++)
933 new_keymap = kmalloc(length * sizeof(struct key_entry), GFP_KERNEL);
937 memcpy(new_keymap, keymap, length * sizeof(struct key_entry));
943 static int __init select_keymap(void)
945 dmi_check_system(dmi_ids);
946 if (keymap_name != NULL) {
947 if (strcmp (keymap_name, "1557/MS2141") == 0)
948 keymap = keymap_wistron_ms2141;
949 else if (strcmp (keymap_name, "generic") == 0)
950 keymap = keymap_wistron_generic;
952 printk(KERN_ERR "wistron_btns: Keymap unknown\n");
956 if (keymap == NULL) {
958 printk(KERN_ERR "wistron_btns: System unknown\n");
961 keymap = keymap_empty;
964 return copy_keymap();
967 /* Input layer interface */
969 static struct input_dev *input_dev;
971 static int __devinit setup_input_dev(void)
973 const struct key_entry *key;
976 input_dev = input_allocate_device();
980 input_dev->name = "Wistron laptop buttons";
981 input_dev->phys = "wistron/input0";
982 input_dev->id.bustype = BUS_HOST;
983 input_dev->cdev.dev = &wistron_device->dev;
985 for (key = keymap; key->type != KE_END; key++) {
988 set_bit(EV_KEY, input_dev->evbit);
989 set_bit(key->keycode, input_dev->keybit);
993 set_bit(EV_SW, input_dev->evbit);
994 set_bit(key->sw.code, input_dev->swbit);
1002 /* reads information flags on KE_END */
1003 if (key->code & FE_UNTESTED)
1004 printk(KERN_WARNING "Untested laptop multimedia keys, "
1005 "please report success or failure to eric.piel"
1006 "@tremplin-utc.net\n");
1008 error = input_register_device(input_dev);
1010 input_free_device(input_dev);
1017 static void report_key(unsigned keycode)
1019 input_report_key(input_dev, keycode, 1);
1020 input_sync(input_dev);
1021 input_report_key(input_dev, keycode, 0);
1022 input_sync(input_dev);
1025 static void report_switch(unsigned code, int value)
1027 input_report_switch(input_dev, code, value);
1028 input_sync(input_dev);
1033 static int wifi_enabled;
1034 static int bluetooth_enabled;
1036 static void poll_bios(unsigned long);
1038 static struct timer_list poll_timer = TIMER_INITIALIZER(poll_bios, 0, 0);
1040 static void handle_key(u8 code)
1042 const struct key_entry *key;
1044 for (key = keymap; key->type != KE_END; key++) {
1045 if (code == key->code) {
1046 switch (key->type) {
1048 report_key(key->keycode);
1052 report_switch(key->sw.code, key->sw.value);
1057 wifi_enabled = !wifi_enabled;
1058 bios_set_state(WIFI, wifi_enabled);
1063 if (have_bluetooth) {
1064 bluetooth_enabled = !bluetooth_enabled;
1065 bios_set_state(BLUETOOTH, bluetooth_enabled);
1077 printk(KERN_NOTICE "wistron_btns: Unknown key code %02X\n", code);
1080 static void poll_bios(unsigned long discard)
1086 qlen = CMOS_READ(cmos_address);
1089 val = bios_pop_queue();
1090 if (val != 0 && !discard)
1091 handle_key((u8)val);
1094 mod_timer(&poll_timer, jiffies + HZ / POLL_FREQUENCY);
1097 static int __devinit wistron_probe(struct platform_device *dev)
1099 int err = setup_input_dev();
1104 cmos_address = bios_get_cmos_address();
1107 u16 wifi = bios_get_default_setting(WIFI);
1109 wifi_enabled = (wifi & 2) ? 1 : 0;
1114 bios_set_state(WIFI, wifi_enabled);
1117 if (have_bluetooth) {
1118 u16 bt = bios_get_default_setting(BLUETOOTH);
1120 bluetooth_enabled = (bt & 2) ? 1 : 0;
1125 bios_set_state(BLUETOOTH, bluetooth_enabled);
1128 poll_bios(1); /* Flush stale event queue and arm timer */
1133 static int __devexit wistron_remove(struct platform_device *dev)
1135 del_timer_sync(&poll_timer);
1136 input_unregister_device(input_dev);
1143 static int wistron_suspend(struct platform_device *dev, pm_message_t state)
1145 del_timer_sync(&poll_timer);
1148 bios_set_state(WIFI, 0);
1151 bios_set_state(BLUETOOTH, 0);
1156 static int wistron_resume(struct platform_device *dev)
1159 bios_set_state(WIFI, wifi_enabled);
1162 bios_set_state(BLUETOOTH, bluetooth_enabled);
1169 #define wistron_suspend NULL
1170 #define wistron_resume NULL
1173 static struct platform_driver wistron_driver = {
1175 .name = "wistron-bios",
1176 .owner = THIS_MODULE,
1178 .probe = wistron_probe,
1179 .remove = __devexit_p(wistron_remove),
1180 .suspend = wistron_suspend,
1181 .resume = wistron_resume,
1184 static int __init wb_module_init(void)
1188 err = select_keymap();
1196 err = platform_driver_register(&wistron_driver);
1198 goto err_unmap_bios;
1200 wistron_device = platform_device_alloc("wistron-bios", -1);
1201 if (!wistron_device) {
1203 goto err_unregister_driver;
1206 err = platform_device_add(wistron_device);
1208 goto err_free_device;
1213 platform_device_put(wistron_device);
1214 err_unregister_driver:
1215 platform_driver_unregister(&wistron_driver);
1222 static void __exit wb_module_exit(void)
1224 platform_device_unregister(wistron_device);
1225 platform_driver_unregister(&wistron_driver);
1230 module_init(wb_module_init);
1231 module_exit(wb_module_exit);