Input: wriston - reduce polling frequency
[pandora-kernel.git] / drivers / input / misc / wistron_btns.c
1 /*
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>
6  *
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
9  * Foundation.
10  *
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.
15  *
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.
19  */
20 #include <linux/io.h>
21 #include <linux/dmi.h>
22 #include <linux/init.h>
23 #include <linux/input.h>
24 #include <linux/interrupt.h>
25 #include <linux/jiffies.h>
26 #include <linux/kernel.h>
27 #include <linux/mc146818rtc.h>
28 #include <linux/module.h>
29 #include <linux/preempt.h>
30 #include <linux/string.h>
31 #include <linux/timer.h>
32 #include <linux/types.h>
33 #include <linux/platform_device.h>
34
35 /*
36  * Number of attempts to read data from queue per poll;
37  * the queue can hold up to 31 entries
38  */
39 #define MAX_POLL_ITERATIONS 64
40
41 #define POLL_FREQUENCY 2 /* Number of polls per second when idle */
42 #define POLL_FREQUENCY_BURST 10 /* Polls per second when a key was recently pressed */
43
44 #if POLL_FREQUENCY_BURST > HZ
45 #error "POLL_FREQUENCY too high"
46 #endif
47
48 /* BIOS subsystem IDs */
49 #define WIFI            0x35
50 #define BLUETOOTH       0x34
51
52 MODULE_AUTHOR("Miloslav Trmac <mitr@volny.cz>");
53 MODULE_DESCRIPTION("Wistron laptop button driver");
54 MODULE_LICENSE("GPL v2");
55 MODULE_VERSION("0.2");
56
57 static int force; /* = 0; */
58 module_param(force, bool, 0);
59 MODULE_PARM_DESC(force, "Load even if computer is not in database");
60
61 static char *keymap_name; /* = NULL; */
62 module_param_named(keymap, keymap_name, charp, 0);
63 MODULE_PARM_DESC(keymap, "Keymap name, if it can't be autodetected [generic, 1557/MS2141]");
64
65 static struct platform_device *wistron_device;
66
67  /* BIOS interface implementation */
68
69 static void __iomem *bios_entry_point; /* BIOS routine entry point */
70 static void __iomem *bios_code_map_base;
71 static void __iomem *bios_data_map_base;
72
73 static u8 cmos_address;
74
75 struct regs {
76         u32 eax, ebx, ecx;
77 };
78
79 static void call_bios(struct regs *regs)
80 {
81         unsigned long flags;
82
83         preempt_disable();
84         local_irq_save(flags);
85         asm volatile ("pushl %%ebp;"
86                       "movl %7, %%ebp;"
87                       "call *%6;"
88                       "popl %%ebp"
89                       : "=a" (regs->eax), "=b" (regs->ebx), "=c" (regs->ecx)
90                       : "0" (regs->eax), "1" (regs->ebx), "2" (regs->ecx),
91                         "m" (bios_entry_point), "m" (bios_data_map_base)
92                       : "edx", "edi", "esi", "memory");
93         local_irq_restore(flags);
94         preempt_enable();
95 }
96
97 static ssize_t __init locate_wistron_bios(void __iomem *base)
98 {
99         static unsigned char __initdata signature[] =
100                 { 0x42, 0x21, 0x55, 0x30 };
101         ssize_t offset;
102
103         for (offset = 0; offset < 0x10000; offset += 0x10) {
104                 if (check_signature(base + offset, signature,
105                                     sizeof(signature)) != 0)
106                         return offset;
107         }
108         return -1;
109 }
110
111 static int __init map_bios(void)
112 {
113         void __iomem *base;
114         ssize_t offset;
115         u32 entry_point;
116
117         base = ioremap(0xF0000, 0x10000); /* Can't fail */
118         offset = locate_wistron_bios(base);
119         if (offset < 0) {
120                 printk(KERN_ERR "wistron_btns: BIOS entry point not found\n");
121                 iounmap(base);
122                 return -ENODEV;
123         }
124
125         entry_point = readl(base + offset + 5);
126         printk(KERN_DEBUG
127                 "wistron_btns: BIOS signature found at %p, entry point %08X\n",
128                 base + offset, entry_point);
129
130         if (entry_point >= 0xF0000) {
131                 bios_code_map_base = base;
132                 bios_entry_point = bios_code_map_base + (entry_point & 0xFFFF);
133         } else {
134                 iounmap(base);
135                 bios_code_map_base = ioremap(entry_point & ~0x3FFF, 0x4000);
136                 if (bios_code_map_base == NULL) {
137                         printk(KERN_ERR
138                                 "wistron_btns: Can't map BIOS code at %08X\n",
139                                 entry_point & ~0x3FFF);
140                         goto err;
141                 }
142                 bios_entry_point = bios_code_map_base + (entry_point & 0x3FFF);
143         }
144         /* The Windows driver maps 0x10000 bytes, we keep only one page... */
145         bios_data_map_base = ioremap(0x400, 0xc00);
146         if (bios_data_map_base == NULL) {
147                 printk(KERN_ERR "wistron_btns: Can't map BIOS data\n");
148                 goto err_code;
149         }
150         return 0;
151
152 err_code:
153         iounmap(bios_code_map_base);
154 err:
155         return -ENOMEM;
156 }
157
158 static inline void unmap_bios(void)
159 {
160         iounmap(bios_code_map_base);
161         iounmap(bios_data_map_base);
162 }
163
164  /* BIOS calls */
165
166 static u16 bios_pop_queue(void)
167 {
168         struct regs regs;
169
170         memset(&regs, 0, sizeof (regs));
171         regs.eax = 0x9610;
172         regs.ebx = 0x061C;
173         regs.ecx = 0x0000;
174         call_bios(&regs);
175
176         return regs.eax;
177 }
178
179 static void __devinit bios_attach(void)
180 {
181         struct regs regs;
182
183         memset(&regs, 0, sizeof (regs));
184         regs.eax = 0x9610;
185         regs.ebx = 0x012E;
186         call_bios(&regs);
187 }
188
189 static void bios_detach(void)
190 {
191         struct regs regs;
192
193         memset(&regs, 0, sizeof (regs));
194         regs.eax = 0x9610;
195         regs.ebx = 0x002E;
196         call_bios(&regs);
197 }
198
199 static u8 __devinit bios_get_cmos_address(void)
200 {
201         struct regs regs;
202
203         memset(&regs, 0, sizeof (regs));
204         regs.eax = 0x9610;
205         regs.ebx = 0x051C;
206         call_bios(&regs);
207
208         return regs.ecx;
209 }
210
211 static u16 __devinit bios_get_default_setting(u8 subsys)
212 {
213         struct regs regs;
214
215         memset(&regs, 0, sizeof (regs));
216         regs.eax = 0x9610;
217         regs.ebx = 0x0200 | subsys;
218         call_bios(&regs);
219
220         return regs.eax;
221 }
222
223 static void bios_set_state(u8 subsys, int enable)
224 {
225         struct regs regs;
226
227         memset(&regs, 0, sizeof (regs));
228         regs.eax = 0x9610;
229         regs.ebx = (enable ? 0x0100 : 0x0000) | subsys;
230         call_bios(&regs);
231 }
232
233 /* Hardware database */
234
235 struct key_entry {
236         char type;              /* See KE_* below */
237         u8 code;
238         union {
239                 u16 keycode;            /* For KE_KEY */
240                 struct {                /* For KE_SW */
241                         u8 code;
242                         u8 value;
243                 } sw;
244         };
245 };
246
247 enum { KE_END, KE_KEY, KE_SW, KE_WIFI, KE_BLUETOOTH };
248
249 #define FE_MAIL_LED 0x01
250 #define FE_WIFI_LED 0x02
251 #define FE_UNTESTED 0x80
252
253 static const struct key_entry *keymap; /* = NULL; Current key map */
254 static int have_wifi;
255 static int have_bluetooth;
256
257 static int __init dmi_matched(struct dmi_system_id *dmi)
258 {
259         const struct key_entry *key;
260
261         keymap = dmi->driver_data;
262         for (key = keymap; key->type != KE_END; key++) {
263                 if (key->type == KE_WIFI)
264                         have_wifi = 1;
265                 else if (key->type == KE_BLUETOOTH)
266                         have_bluetooth = 1;
267         }
268         return 1;
269 }
270
271 static struct key_entry keymap_empty[] __initdata = {
272         { KE_END, 0 }
273 };
274
275 static struct key_entry keymap_fs_amilo_pro_v2000[] __initdata = {
276         { KE_KEY,  0x01, {KEY_HELP} },
277         { KE_KEY,  0x11, {KEY_PROG1} },
278         { KE_KEY,  0x12, {KEY_PROG2} },
279         { KE_WIFI, 0x30 },
280         { KE_KEY,  0x31, {KEY_MAIL} },
281         { KE_KEY,  0x36, {KEY_WWW} },
282         { KE_END,  0 }
283 };
284
285 static struct key_entry keymap_fujitsu_n3510[] __initdata = {
286         { KE_KEY, 0x11, {KEY_PROG1} },
287         { KE_KEY, 0x12, {KEY_PROG2} },
288         { KE_KEY, 0x36, {KEY_WWW} },
289         { KE_KEY, 0x31, {KEY_MAIL} },
290         { KE_KEY, 0x71, {KEY_STOPCD} },
291         { KE_KEY, 0x72, {KEY_PLAYPAUSE} },
292         { KE_KEY, 0x74, {KEY_REWIND} },
293         { KE_KEY, 0x78, {KEY_FORWARD} },
294         { KE_END, 0 }
295 };
296
297 static struct key_entry keymap_wistron_ms2111[] __initdata = {
298         { KE_KEY,  0x11, {KEY_PROG1} },
299         { KE_KEY,  0x12, {KEY_PROG2} },
300         { KE_KEY,  0x13, {KEY_PROG3} },
301         { KE_KEY,  0x31, {KEY_MAIL} },
302         { KE_KEY,  0x36, {KEY_WWW} },
303         { KE_END, FE_MAIL_LED }
304 };
305
306 static struct key_entry keymap_wistron_md40100[] __initdata = {
307         { KE_KEY, 0x01, {KEY_HELP} },
308         { KE_KEY, 0x02, {KEY_CONFIG} },
309         { KE_KEY, 0x31, {KEY_MAIL} },
310         { KE_KEY, 0x36, {KEY_WWW} },
311         { KE_KEY, 0x37, {KEY_DISPLAYTOGGLE} }, /* Display on/off */
312         { KE_END, FE_MAIL_LED | FE_WIFI_LED | FE_UNTESTED }
313 };
314
315 static struct key_entry keymap_wistron_ms2141[] __initdata = {
316         { KE_KEY,  0x11, {KEY_PROG1} },
317         { KE_KEY,  0x12, {KEY_PROG2} },
318         { KE_WIFI, 0x30 },
319         { KE_KEY,  0x22, {KEY_REWIND} },
320         { KE_KEY,  0x23, {KEY_FORWARD} },
321         { KE_KEY,  0x24, {KEY_PLAYPAUSE} },
322         { KE_KEY,  0x25, {KEY_STOPCD} },
323         { KE_KEY,  0x31, {KEY_MAIL} },
324         { KE_KEY,  0x36, {KEY_WWW} },
325         { KE_END,  0 }
326 };
327
328 static struct key_entry keymap_acer_aspire_1500[] __initdata = {
329         { KE_KEY, 0x01, {KEY_HELP} },
330         { KE_KEY, 0x03, {KEY_POWER} },
331         { KE_KEY, 0x11, {KEY_PROG1} },
332         { KE_KEY, 0x12, {KEY_PROG2} },
333         { KE_WIFI, 0x30 },
334         { KE_KEY, 0x31, {KEY_MAIL} },
335         { KE_KEY, 0x36, {KEY_WWW} },
336         { KE_KEY, 0x49, {KEY_CONFIG} },
337         { KE_BLUETOOTH, 0x44 },
338         { KE_END, FE_UNTESTED }
339 };
340
341 static struct key_entry keymap_acer_aspire_1600[] __initdata = {
342         { KE_KEY, 0x01, {KEY_HELP} },
343         { KE_KEY, 0x03, {KEY_POWER} },
344         { KE_KEY, 0x08, {KEY_MUTE} },
345         { KE_KEY, 0x11, {KEY_PROG1} },
346         { KE_KEY, 0x12, {KEY_PROG2} },
347         { KE_KEY, 0x13, {KEY_PROG3} },
348         { KE_KEY, 0x31, {KEY_MAIL} },
349         { KE_KEY, 0x36, {KEY_WWW} },
350         { KE_KEY, 0x49, {KEY_CONFIG} },
351         { KE_WIFI, 0x30 },
352         { KE_BLUETOOTH, 0x44 },
353         { KE_END, FE_MAIL_LED | FE_UNTESTED }
354 };
355
356 /* 3020 has been tested */
357 static struct key_entry keymap_acer_aspire_5020[] __initdata = {
358         { KE_KEY, 0x01, {KEY_HELP} },
359         { KE_KEY, 0x03, {KEY_POWER} },
360         { KE_KEY, 0x05, {KEY_SWITCHVIDEOMODE} }, /* Display selection */
361         { KE_KEY, 0x11, {KEY_PROG1} },
362         { KE_KEY, 0x12, {KEY_PROG2} },
363         { KE_KEY, 0x31, {KEY_MAIL} },
364         { KE_KEY, 0x36, {KEY_WWW} },
365         { KE_KEY, 0x6a, {KEY_CONFIG} },
366         { KE_WIFI, 0x30 },
367         { KE_BLUETOOTH, 0x44 },
368         { KE_END, FE_MAIL_LED | FE_UNTESTED }
369 };
370
371 static struct key_entry keymap_acer_travelmate_2410[] __initdata = {
372         { KE_KEY, 0x01, {KEY_HELP} },
373         { KE_KEY, 0x6d, {KEY_POWER} },
374         { KE_KEY, 0x11, {KEY_PROG1} },
375         { KE_KEY, 0x12, {KEY_PROG2} },
376         { KE_KEY, 0x31, {KEY_MAIL} },
377         { KE_KEY, 0x36, {KEY_WWW} },
378         { KE_KEY, 0x6a, {KEY_CONFIG} },
379         { KE_WIFI, 0x30 },
380         { KE_BLUETOOTH, 0x44 },
381         { KE_END, FE_MAIL_LED | FE_UNTESTED }
382 };
383
384 static struct key_entry keymap_acer_travelmate_110[] __initdata = {
385         { KE_KEY, 0x01, {KEY_HELP} },
386         { KE_KEY, 0x02, {KEY_CONFIG} },
387         { KE_KEY, 0x03, {KEY_POWER} },
388         { KE_KEY, 0x08, {KEY_MUTE} },
389         { KE_KEY, 0x11, {KEY_PROG1} },
390         { KE_KEY, 0x12, {KEY_PROG2} },
391         { KE_KEY, 0x20, {KEY_VOLUMEUP} },
392         { KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
393         { KE_KEY, 0x31, {KEY_MAIL} },
394         { KE_KEY, 0x36, {KEY_WWW} },
395         { KE_SW, 0x4a, {.sw = {SW_LID, 1}} }, /* lid close */
396         { KE_SW, 0x4b, {.sw = {SW_LID, 0}} }, /* lid open */
397         { KE_WIFI, 0x30 },
398         { KE_END, FE_MAIL_LED | FE_UNTESTED }
399 };
400
401 static struct key_entry keymap_acer_travelmate_300[] __initdata = {
402         { KE_KEY, 0x01, {KEY_HELP} },
403         { KE_KEY, 0x02, {KEY_CONFIG} },
404         { KE_KEY, 0x03, {KEY_POWER} },
405         { KE_KEY, 0x08, {KEY_MUTE} },
406         { KE_KEY, 0x11, {KEY_PROG1} },
407         { KE_KEY, 0x12, {KEY_PROG2} },
408         { KE_KEY, 0x20, {KEY_VOLUMEUP} },
409         { KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
410         { KE_KEY, 0x31, {KEY_MAIL} },
411         { KE_KEY, 0x36, {KEY_WWW} },
412         { KE_WIFI, 0x30 },
413         { KE_BLUETOOTH, 0x44 },
414         { KE_END, FE_MAIL_LED | FE_UNTESTED }
415 };
416
417 static struct key_entry keymap_acer_travelmate_380[] __initdata = {
418         { KE_KEY, 0x01, {KEY_HELP} },
419         { KE_KEY, 0x02, {KEY_CONFIG} },
420         { KE_KEY, 0x03, {KEY_POWER} }, /* not 370 */
421         { KE_KEY, 0x11, {KEY_PROG1} },
422         { KE_KEY, 0x12, {KEY_PROG2} },
423         { KE_KEY, 0x13, {KEY_PROG3} },
424         { KE_KEY, 0x31, {KEY_MAIL} },
425         { KE_KEY, 0x36, {KEY_WWW} },
426         { KE_WIFI, 0x30 },
427         { KE_END, FE_MAIL_LED | FE_UNTESTED }
428 };
429
430 /* unusual map */
431 static struct key_entry keymap_acer_travelmate_220[] __initdata = {
432         { KE_KEY, 0x01, {KEY_HELP} },
433         { KE_KEY, 0x02, {KEY_CONFIG} },
434         { KE_KEY, 0x11, {KEY_MAIL} },
435         { KE_KEY, 0x12, {KEY_WWW} },
436         { KE_KEY, 0x13, {KEY_PROG2} },
437         { KE_KEY, 0x31, {KEY_PROG1} },
438         { KE_END, FE_WIFI_LED | FE_UNTESTED }
439 };
440
441 static struct key_entry keymap_acer_travelmate_230[] __initdata = {
442         { KE_KEY, 0x01, {KEY_HELP} },
443         { KE_KEY, 0x02, {KEY_CONFIG} },
444         { KE_KEY, 0x11, {KEY_PROG1} },
445         { KE_KEY, 0x12, {KEY_PROG2} },
446         { KE_KEY, 0x31, {KEY_MAIL} },
447         { KE_KEY, 0x36, {KEY_WWW} },
448         { KE_END, FE_WIFI_LED | FE_UNTESTED }
449 };
450
451 static struct key_entry keymap_acer_travelmate_240[] __initdata = {
452         { KE_KEY, 0x01, {KEY_HELP} },
453         { KE_KEY, 0x02, {KEY_CONFIG} },
454         { KE_KEY, 0x03, {KEY_POWER} },
455         { KE_KEY, 0x08, {KEY_MUTE} },
456         { KE_KEY, 0x31, {KEY_MAIL} },
457         { KE_KEY, 0x36, {KEY_WWW} },
458         { KE_KEY, 0x11, {KEY_PROG1} },
459         { KE_KEY, 0x12, {KEY_PROG2} },
460         { KE_BLUETOOTH, 0x44 },
461         { KE_WIFI, 0x30 },
462         { KE_END, FE_UNTESTED }
463 };
464
465 static struct key_entry keymap_acer_travelmate_350[] __initdata = {
466         { KE_KEY, 0x01, {KEY_HELP} },
467         { KE_KEY, 0x02, {KEY_CONFIG} },
468         { KE_KEY, 0x11, {KEY_PROG1} },
469         { KE_KEY, 0x12, {KEY_PROG2} },
470         { KE_KEY, 0x13, {KEY_MAIL} },
471         { KE_KEY, 0x14, {KEY_PROG3} },
472         { KE_KEY, 0x15, {KEY_WWW} },
473         { KE_END, FE_MAIL_LED | FE_WIFI_LED | FE_UNTESTED }
474 };
475
476 static struct key_entry keymap_acer_travelmate_360[] __initdata = {
477         { KE_KEY, 0x01, {KEY_HELP} },
478         { KE_KEY, 0x02, {KEY_CONFIG} },
479         { KE_KEY, 0x11, {KEY_PROG1} },
480         { KE_KEY, 0x12, {KEY_PROG2} },
481         { KE_KEY, 0x13, {KEY_MAIL} },
482         { KE_KEY, 0x14, {KEY_PROG3} },
483         { KE_KEY, 0x15, {KEY_WWW} },
484         { KE_KEY, 0x40, {KEY_WLAN} },
485         { KE_END, FE_WIFI_LED | FE_UNTESTED } /* no mail led */
486 };
487
488 /* Wifi subsystem only activates the led. Therefore we need to pass
489  * wifi event as a normal key, then userspace can really change the wifi state.
490  * TODO we need to export led state to userspace (wifi and mail) */
491 static struct key_entry keymap_acer_travelmate_610[] __initdata = {
492         { KE_KEY, 0x01, {KEY_HELP} },
493         { KE_KEY, 0x02, {KEY_CONFIG} },
494         { KE_KEY, 0x11, {KEY_PROG1} },
495         { KE_KEY, 0x12, {KEY_PROG2} },
496         { KE_KEY, 0x13, {KEY_PROG3} },
497         { KE_KEY, 0x14, {KEY_MAIL} },
498         { KE_KEY, 0x15, {KEY_WWW} },
499         { KE_KEY, 0x40, {KEY_WLAN} },
500         { KE_END, FE_MAIL_LED | FE_WIFI_LED }
501 };
502
503 static struct key_entry keymap_acer_travelmate_630[] __initdata = {
504         { KE_KEY, 0x01, {KEY_HELP} },
505         { KE_KEY, 0x02, {KEY_CONFIG} },
506         { KE_KEY, 0x03, {KEY_POWER} },
507         { KE_KEY, 0x08, {KEY_MUTE} }, /* not 620 */
508         { KE_KEY, 0x11, {KEY_PROG1} },
509         { KE_KEY, 0x12, {KEY_PROG2} },
510         { KE_KEY, 0x13, {KEY_PROG3} },
511         { KE_KEY, 0x20, {KEY_VOLUMEUP} },
512         { KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
513         { KE_KEY, 0x31, {KEY_MAIL} },
514         { KE_KEY, 0x36, {KEY_WWW} },
515         { KE_WIFI, 0x30 },
516         { KE_END, FE_MAIL_LED | FE_UNTESTED }
517 };
518
519 static struct key_entry keymap_aopen_1559as[] __initdata = {
520         { KE_KEY,  0x01, {KEY_HELP} },
521         { KE_KEY,  0x06, {KEY_PROG3} },
522         { KE_KEY,  0x11, {KEY_PROG1} },
523         { KE_KEY,  0x12, {KEY_PROG2} },
524         { KE_WIFI, 0x30 },
525         { KE_KEY,  0x31, {KEY_MAIL} },
526         { KE_KEY,  0x36, {KEY_WWW} },
527         { KE_END,  0 },
528 };
529
530 static struct key_entry keymap_fs_amilo_d88x0[] __initdata = {
531         { KE_KEY, 0x01, {KEY_HELP} },
532         { KE_KEY, 0x08, {KEY_MUTE} },
533         { KE_KEY, 0x31, {KEY_MAIL} },
534         { KE_KEY, 0x36, {KEY_WWW} },
535         { KE_KEY, 0x11, {KEY_PROG1} },
536         { KE_KEY, 0x12, {KEY_PROG2} },
537         { KE_KEY, 0x13, {KEY_PROG3} },
538         { KE_END, FE_MAIL_LED | FE_WIFI_LED | FE_UNTESTED }
539 };
540
541 static struct key_entry keymap_wistron_md2900[] __initdata = {
542         { KE_KEY, 0x01, {KEY_HELP} },
543         { KE_KEY, 0x02, {KEY_CONFIG} },
544         { KE_KEY, 0x11, {KEY_PROG1} },
545         { KE_KEY, 0x12, {KEY_PROG2} },
546         { KE_KEY, 0x31, {KEY_MAIL} },
547         { KE_KEY, 0x36, {KEY_WWW} },
548         { KE_WIFI, 0x30 },
549         { KE_END, FE_MAIL_LED | FE_UNTESTED }
550 };
551
552 static struct key_entry keymap_wistron_md96500[] __initdata = {
553         { KE_KEY, 0x01, {KEY_HELP} },
554         { KE_KEY, 0x02, {KEY_CONFIG} },
555         { KE_KEY, 0x05, {KEY_SWITCHVIDEOMODE} }, /* Display selection */
556         { KE_KEY, 0x06, {KEY_DISPLAYTOGGLE} }, /* Display on/off */
557         { KE_KEY, 0x08, {KEY_MUTE} },
558         { KE_KEY, 0x11, {KEY_PROG1} },
559         { KE_KEY, 0x12, {KEY_PROG2} },
560         { KE_KEY, 0x20, {KEY_VOLUMEUP} },
561         { KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
562         { KE_KEY, 0x22, {KEY_REWIND} },
563         { KE_KEY, 0x23, {KEY_FORWARD} },
564         { KE_KEY, 0x24, {KEY_PLAYPAUSE} },
565         { KE_KEY, 0x25, {KEY_STOPCD} },
566         { KE_KEY, 0x31, {KEY_MAIL} },
567         { KE_KEY, 0x36, {KEY_WWW} },
568         { KE_WIFI, 0x30 },
569         { KE_BLUETOOTH, 0x44 },
570         { KE_END, FE_UNTESTED }
571 };
572
573 static struct key_entry keymap_wistron_generic[] __initdata = {
574         { KE_KEY, 0x01, {KEY_HELP} },
575         { KE_KEY, 0x02, {KEY_CONFIG} },
576         { KE_KEY, 0x03, {KEY_POWER} },
577         { KE_KEY, 0x05, {KEY_SWITCHVIDEOMODE} }, /* Display selection */
578         { KE_KEY, 0x06, {KEY_DISPLAYTOGGLE} }, /* Display on/off */
579         { KE_KEY, 0x08, {KEY_MUTE} },
580         { KE_KEY, 0x11, {KEY_PROG1} },
581         { KE_KEY, 0x12, {KEY_PROG2} },
582         { KE_KEY, 0x13, {KEY_PROG3} },
583         { KE_KEY, 0x14, {KEY_MAIL} },
584         { KE_KEY, 0x15, {KEY_WWW} },
585         { KE_KEY, 0x20, {KEY_VOLUMEUP} },
586         { KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
587         { KE_KEY, 0x22, {KEY_REWIND} },
588         { KE_KEY, 0x23, {KEY_FORWARD} },
589         { KE_KEY, 0x24, {KEY_PLAYPAUSE} },
590         { KE_KEY, 0x25, {KEY_STOPCD} },
591         { KE_KEY, 0x31, {KEY_MAIL} },
592         { KE_KEY, 0x36, {KEY_WWW} },
593         { KE_KEY, 0x37, {KEY_DISPLAYTOGGLE} }, /* Display on/off */
594         { KE_KEY, 0x40, {KEY_WLAN} },
595         { KE_KEY, 0x49, {KEY_CONFIG} },
596         { KE_SW, 0x4a, {.sw = {SW_LID, 1}} }, /* lid close */
597         { KE_SW, 0x4b, {.sw = {SW_LID, 0}} }, /* lid open */
598         { KE_KEY, 0x6a, {KEY_CONFIG} },
599         { KE_KEY, 0x6d, {KEY_POWER} },
600         { KE_KEY, 0x71, {KEY_STOPCD} },
601         { KE_KEY, 0x72, {KEY_PLAYPAUSE} },
602         { KE_KEY, 0x74, {KEY_REWIND} },
603         { KE_KEY, 0x78, {KEY_FORWARD} },
604         { KE_WIFI, 0x30 },
605         { KE_BLUETOOTH, 0x44 },
606         { KE_END, 0 }
607 };
608
609 /*
610  * If your machine is not here (which is currently rather likely), please send
611  * a list of buttons and their key codes (reported when loading this module
612  * with force=1) and the output of dmidecode to $MODULE_AUTHOR.
613  */
614 static struct dmi_system_id dmi_ids[] __initdata = {
615         {
616                 .callback = dmi_matched,
617                 .ident = "Fujitsu-Siemens Amilo Pro V2000",
618                 .matches = {
619                         DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
620                         DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pro V2000"),
621                 },
622                 .driver_data = keymap_fs_amilo_pro_v2000
623         },
624         {
625                 .callback = dmi_matched,
626                 .ident = "Fujitsu-Siemens Amilo M7400",
627                 .matches = {
628                         DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
629                         DMI_MATCH(DMI_PRODUCT_NAME, "AMILO M        "),
630                 },
631                 .driver_data = keymap_fs_amilo_pro_v2000
632         },
633         {
634                 .callback = dmi_matched,
635                 .ident = "Fujitsu N3510",
636                 .matches = {
637                         DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
638                         DMI_MATCH(DMI_PRODUCT_NAME, "N3510"),
639                 },
640                 .driver_data = keymap_fujitsu_n3510
641         },
642         {
643                 .callback = dmi_matched,
644                 .ident = "Acer Aspire 1500",
645                 .matches = {
646                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
647                         DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1500"),
648                 },
649                 .driver_data = keymap_acer_aspire_1500
650         },
651         {
652                 .callback = dmi_matched,
653                 .ident = "Acer Aspire 1600",
654                 .matches = {
655                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
656                         DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1600"),
657                 },
658                 .driver_data = keymap_acer_aspire_1600
659         },
660         {
661                 .callback = dmi_matched,
662                 .ident = "Acer Aspire 3020",
663                 .matches = {
664                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
665                         DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3020"),
666                 },
667                 .driver_data = keymap_acer_aspire_5020
668         },
669         {
670                 .callback = dmi_matched,
671                 .ident = "Acer Aspire 5020",
672                 .matches = {
673                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
674                         DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5020"),
675                 },
676                 .driver_data = keymap_acer_aspire_5020
677         },
678         {
679                 .callback = dmi_matched,
680                 .ident = "Acer TravelMate 2100",
681                 .matches = {
682                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
683                         DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2100"),
684                 },
685                 .driver_data = keymap_acer_aspire_5020
686         },
687         {
688                 .callback = dmi_matched,
689                 .ident = "Acer TravelMate 2410",
690                 .matches = {
691                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
692                         DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2410"),
693                 },
694                 .driver_data = keymap_acer_travelmate_2410
695         },
696         {
697                 .callback = dmi_matched,
698                 .ident = "Acer TravelMate C300",
699                 .matches = {
700                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
701                         DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate C300"),
702                 },
703                 .driver_data = keymap_acer_travelmate_300
704         },
705         {
706                 .callback = dmi_matched,
707                 .ident = "Acer TravelMate C100",
708                 .matches = {
709                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
710                         DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate C100"),
711                 },
712                 .driver_data = keymap_acer_travelmate_300
713         },
714         {
715                 .callback = dmi_matched,
716                 .ident = "Acer TravelMate C110",
717                 .matches = {
718                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
719                         DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate C110"),
720                 },
721                 .driver_data = keymap_acer_travelmate_110
722         },
723         {
724                 .callback = dmi_matched,
725                 .ident = "Acer TravelMate 380",
726                 .matches = {
727                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
728                         DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 380"),
729                 },
730                 .driver_data = keymap_acer_travelmate_380
731         },
732         {
733                 .callback = dmi_matched,
734                 .ident = "Acer TravelMate 370",
735                 .matches = {
736                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
737                         DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 370"),
738                 },
739                 .driver_data = keymap_acer_travelmate_380 /* keyboard minus 1 key */
740         },
741         {
742                 .callback = dmi_matched,
743                 .ident = "Acer TravelMate 220",
744                 .matches = {
745                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
746                         DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 220"),
747                 },
748                 .driver_data = keymap_acer_travelmate_220
749         },
750         {
751                 .callback = dmi_matched,
752                 .ident = "Acer TravelMate 260",
753                 .matches = {
754                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
755                         DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 260"),
756                 },
757                 .driver_data = keymap_acer_travelmate_220
758         },
759         {
760                 .callback = dmi_matched,
761                 .ident = "Acer TravelMate 230",
762                 .matches = {
763                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
764                         DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 230"),
765                         /* acerhk looks for "TravelMate F4..." ?! */
766                 },
767                 .driver_data = keymap_acer_travelmate_230
768         },
769         {
770                 .callback = dmi_matched,
771                 .ident = "Acer TravelMate 280",
772                 .matches = {
773                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
774                         DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 280"),
775                 },
776                 .driver_data = keymap_acer_travelmate_230
777         },
778         {
779                 .callback = dmi_matched,
780                 .ident = "Acer TravelMate 240",
781                 .matches = {
782                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
783                         DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 240"),
784                 },
785                 .driver_data = keymap_acer_travelmate_240
786         },
787         {
788                 .callback = dmi_matched,
789                 .ident = "Acer TravelMate 250",
790                 .matches = {
791                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
792                         DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 250"),
793                 },
794                 .driver_data = keymap_acer_travelmate_240
795         },
796         {
797                 .callback = dmi_matched,
798                 .ident = "Acer TravelMate 2424NWXCi",
799                 .matches = {
800                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
801                         DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2420"),
802                 },
803                 .driver_data = keymap_acer_travelmate_240
804         },
805         {
806                 .callback = dmi_matched,
807                 .ident = "Acer TravelMate 350",
808                 .matches = {
809                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
810                         DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 350"),
811                 },
812                 .driver_data = keymap_acer_travelmate_350
813         },
814         {
815                 .callback = dmi_matched,
816                 .ident = "Acer TravelMate 360",
817                 .matches = {
818                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
819                         DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
820                 },
821                 .driver_data = keymap_acer_travelmate_360
822         },
823         {
824                 .callback = dmi_matched,
825                 .ident = "Acer TravelMate 610",
826                 .matches = {
827                         DMI_MATCH(DMI_SYS_VENDOR, "ACER"),
828                         DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 610"),
829                 },
830                 .driver_data = keymap_acer_travelmate_610
831         },
832         {
833                 .callback = dmi_matched,
834                 .ident = "Acer TravelMate 620",
835                 .matches = {
836                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
837                         DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 620"),
838                 },
839                 .driver_data = keymap_acer_travelmate_630
840         },
841         {
842                 .callback = dmi_matched,
843                 .ident = "Acer TravelMate 630",
844                 .matches = {
845                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
846                         DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 630"),
847                 },
848                 .driver_data = keymap_acer_travelmate_630
849         },
850         {
851                 .callback = dmi_matched,
852                 .ident = "AOpen 1559AS",
853                 .matches = {
854                         DMI_MATCH(DMI_PRODUCT_NAME, "E2U"),
855                         DMI_MATCH(DMI_BOARD_NAME, "E2U"),
856                 },
857                 .driver_data = keymap_aopen_1559as
858         },
859         {
860                 .callback = dmi_matched,
861                 .ident = "Medion MD 9783",
862                 .matches = {
863                         DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
864                         DMI_MATCH(DMI_PRODUCT_NAME, "MD 9783"),
865                 },
866                 .driver_data = keymap_wistron_ms2111
867         },
868         {
869                 .callback = dmi_matched,
870                 .ident = "Medion MD 40100",
871                 .matches = {
872                         DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
873                         DMI_MATCH(DMI_PRODUCT_NAME, "WID2000"),
874                 },
875                 .driver_data = keymap_wistron_md40100
876         },
877         {
878                 .callback = dmi_matched,
879                 .ident = "Medion MD 2900",
880                 .matches = {
881                         DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
882                         DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2000"),
883                 },
884                 .driver_data = keymap_wistron_md2900
885         },
886         {
887                 .callback = dmi_matched,
888                 .ident = "Medion MD 96500",
889                 .matches = {
890                         DMI_MATCH(DMI_SYS_VENDOR, "MEDIONPC"),
891                         DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2040"),
892                 },
893                 .driver_data = keymap_wistron_md96500
894         },
895         {
896                 .callback = dmi_matched,
897                 .ident = "Medion MD 95400",
898                 .matches = {
899                         DMI_MATCH(DMI_SYS_VENDOR, "MEDIONPC"),
900                         DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2050"),
901                 },
902                 .driver_data = keymap_wistron_md96500
903         },
904         {
905                 .callback = dmi_matched,
906                 .ident = "Fujitsu Siemens Amilo D7820",
907                 .matches = {
908                         DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"), /* not sure */
909                         DMI_MATCH(DMI_PRODUCT_NAME, "Amilo D"),
910                 },
911                 .driver_data = keymap_fs_amilo_d88x0
912         },
913         {
914                 .callback = dmi_matched,
915                 .ident = "Fujitsu Siemens Amilo D88x0",
916                 .matches = {
917                         DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
918                         DMI_MATCH(DMI_PRODUCT_NAME, "AMILO D"),
919                 },
920                 .driver_data = keymap_fs_amilo_d88x0
921         },
922         { NULL, }
923 };
924
925 /* Copy the good keymap, as the original ones are free'd */
926 static int __init copy_keymap(void)
927 {
928         const struct key_entry *key;
929         struct key_entry *new_keymap;
930         unsigned int length = 1;
931
932         for (key = keymap; key->type != KE_END; key++)
933                 length++;
934
935         new_keymap = kmalloc(length * sizeof(struct key_entry), GFP_KERNEL);
936         if (!new_keymap)
937                 return -ENOMEM;
938
939         memcpy(new_keymap, keymap, length * sizeof(struct key_entry));
940         keymap = new_keymap;
941
942         return 0;
943 }
944
945 static int __init select_keymap(void)
946 {
947         dmi_check_system(dmi_ids);
948         if (keymap_name != NULL) {
949                 if (strcmp (keymap_name, "1557/MS2141") == 0)
950                         keymap = keymap_wistron_ms2141;
951                 else if (strcmp (keymap_name, "generic") == 0)
952                         keymap = keymap_wistron_generic;
953                 else {
954                         printk(KERN_ERR "wistron_btns: Keymap unknown\n");
955                         return -EINVAL;
956                 }
957         }
958         if (keymap == NULL) {
959                 if (!force) {
960                         printk(KERN_ERR "wistron_btns: System unknown\n");
961                         return -ENODEV;
962                 }
963                 keymap = keymap_empty;
964         }
965
966         return copy_keymap();
967 }
968
969  /* Input layer interface */
970
971 static struct input_dev *input_dev;
972
973 static int __devinit setup_input_dev(void)
974 {
975         const struct key_entry *key;
976         int error;
977
978         input_dev = input_allocate_device();
979         if (!input_dev)
980                 return -ENOMEM;
981
982         input_dev->name = "Wistron laptop buttons";
983         input_dev->phys = "wistron/input0";
984         input_dev->id.bustype = BUS_HOST;
985         input_dev->cdev.dev = &wistron_device->dev;
986
987         for (key = keymap; key->type != KE_END; key++) {
988                 switch (key->type) {
989                         case KE_KEY:
990                                 set_bit(EV_KEY, input_dev->evbit);
991                                 set_bit(key->keycode, input_dev->keybit);
992                                 break;
993
994                         case KE_SW:
995                                 set_bit(EV_SW, input_dev->evbit);
996                                 set_bit(key->sw.code, input_dev->swbit);
997                                 break;
998
999                         default:
1000                                 ;
1001                 }
1002         }
1003
1004         /* reads information flags on KE_END */
1005         if (key->code & FE_UNTESTED)
1006                 printk(KERN_WARNING "Untested laptop multimedia keys, "
1007                         "please report success or failure to eric.piel"
1008                         "@tremplin-utc.net\n");
1009
1010         error = input_register_device(input_dev);
1011         if (error) {
1012                 input_free_device(input_dev);
1013                 return error;
1014         }
1015
1016         return 0;
1017 }
1018
1019 static void report_key(unsigned keycode)
1020 {
1021         input_report_key(input_dev, keycode, 1);
1022         input_sync(input_dev);
1023         input_report_key(input_dev, keycode, 0);
1024         input_sync(input_dev);
1025 }
1026
1027 static void report_switch(unsigned code, int value)
1028 {
1029         input_report_switch(input_dev, code, value);
1030         input_sync(input_dev);
1031 }
1032
1033  /* Driver core */
1034
1035 static int wifi_enabled;
1036 static int bluetooth_enabled;
1037
1038 static void poll_bios(unsigned long);
1039
1040 static struct timer_list poll_timer = TIMER_INITIALIZER(poll_bios, 0, 0);
1041
1042 static void handle_key(u8 code)
1043 {
1044         const struct key_entry *key;
1045
1046         for (key = keymap; key->type != KE_END; key++) {
1047                 if (code == key->code) {
1048                         switch (key->type) {
1049                         case KE_KEY:
1050                                 report_key(key->keycode);
1051                                 break;
1052
1053                         case KE_SW:
1054                                 report_switch(key->sw.code, key->sw.value);
1055                                 break;
1056
1057                         case KE_WIFI:
1058                                 if (have_wifi) {
1059                                         wifi_enabled = !wifi_enabled;
1060                                         bios_set_state(WIFI, wifi_enabled);
1061                                 }
1062                                 break;
1063
1064                         case KE_BLUETOOTH:
1065                                 if (have_bluetooth) {
1066                                         bluetooth_enabled = !bluetooth_enabled;
1067                                         bios_set_state(BLUETOOTH, bluetooth_enabled);
1068                                 }
1069                                 break;
1070
1071                         case KE_END:
1072                                 break;
1073                         default:
1074                                 BUG();
1075                         }
1076                         return;
1077                 }
1078         }
1079         printk(KERN_NOTICE "wistron_btns: Unknown key code %02X\n", code);
1080 }
1081
1082 static void poll_bios(unsigned long discard)
1083 {
1084         static unsigned long jiffies_last_press;
1085         unsigned long jiffies_now = jiffies;
1086         u8 qlen;
1087         u16 val;
1088
1089         for (;;) {
1090                 qlen = CMOS_READ(cmos_address);
1091                 if (qlen == 0)
1092                         break;
1093                 val = bios_pop_queue();
1094                 if (val != 0 && !discard) {
1095                         handle_key((u8)val);
1096                         jiffies_last_press = jiffies_now;
1097                 }
1098         }
1099
1100         /* Increase precision if user is currently pressing keys (< 2s ago) */
1101         if (time_after(jiffies_last_press, jiffies_now - (HZ * 2)))
1102                 mod_timer(&poll_timer, jiffies_now + HZ / POLL_FREQUENCY_BURST);
1103         else
1104                 mod_timer(&poll_timer, jiffies_now + HZ / POLL_FREQUENCY);
1105 }
1106
1107 static int __devinit wistron_probe(struct platform_device *dev)
1108 {
1109         int err = setup_input_dev();
1110         if (err)
1111                 return err;
1112
1113         bios_attach();
1114         cmos_address = bios_get_cmos_address();
1115
1116         if (have_wifi) {
1117                 u16 wifi = bios_get_default_setting(WIFI);
1118                 if (wifi & 1)
1119                         wifi_enabled = (wifi & 2) ? 1 : 0;
1120                 else
1121                         have_wifi = 0;
1122
1123                 if (have_wifi)
1124                         bios_set_state(WIFI, wifi_enabled);
1125         }
1126
1127         if (have_bluetooth) {
1128                 u16 bt = bios_get_default_setting(BLUETOOTH);
1129                 if (bt & 1)
1130                         bluetooth_enabled = (bt & 2) ? 1 : 0;
1131                 else
1132                         have_bluetooth = 0;
1133
1134                 if (have_bluetooth)
1135                         bios_set_state(BLUETOOTH, bluetooth_enabled);
1136         }
1137
1138         poll_bios(1); /* Flush stale event queue and arm timer */
1139
1140         return 0;
1141 }
1142
1143 static int __devexit wistron_remove(struct platform_device *dev)
1144 {
1145         del_timer_sync(&poll_timer);
1146         input_unregister_device(input_dev);
1147         bios_detach();
1148
1149         return 0;
1150 }
1151
1152 #ifdef CONFIG_PM
1153 static int wistron_suspend(struct platform_device *dev, pm_message_t state)
1154 {
1155         del_timer_sync(&poll_timer);
1156
1157         if (have_wifi)
1158                 bios_set_state(WIFI, 0);
1159
1160         if (have_bluetooth)
1161                 bios_set_state(BLUETOOTH, 0);
1162
1163         return 0;
1164 }
1165
1166 static int wistron_resume(struct platform_device *dev)
1167 {
1168         if (have_wifi)
1169                 bios_set_state(WIFI, wifi_enabled);
1170
1171         if (have_bluetooth)
1172                 bios_set_state(BLUETOOTH, bluetooth_enabled);
1173
1174         poll_bios(1);
1175
1176         return 0;
1177 }
1178 #else
1179 #define wistron_suspend         NULL
1180 #define wistron_resume          NULL
1181 #endif
1182
1183 static struct platform_driver wistron_driver = {
1184         .driver         = {
1185                 .name   = "wistron-bios",
1186                 .owner  = THIS_MODULE,
1187         },
1188         .probe          = wistron_probe,
1189         .remove         = __devexit_p(wistron_remove),
1190         .suspend        = wistron_suspend,
1191         .resume         = wistron_resume,
1192 };
1193
1194 static int __init wb_module_init(void)
1195 {
1196         int err;
1197
1198         err = select_keymap();
1199         if (err)
1200                 return err;
1201
1202         err = map_bios();
1203         if (err)
1204                 return err;
1205
1206         err = platform_driver_register(&wistron_driver);
1207         if (err)
1208                 goto err_unmap_bios;
1209
1210         wistron_device = platform_device_alloc("wistron-bios", -1);
1211         if (!wistron_device) {
1212                 err = -ENOMEM;
1213                 goto err_unregister_driver;
1214         }
1215
1216         err = platform_device_add(wistron_device);
1217         if (err)
1218                 goto err_free_device;
1219
1220         return 0;
1221
1222  err_free_device:
1223         platform_device_put(wistron_device);
1224  err_unregister_driver:
1225         platform_driver_unregister(&wistron_driver);
1226  err_unmap_bios:
1227         unmap_bios();
1228
1229         return err;
1230 }
1231
1232 static void __exit wb_module_exit(void)
1233 {
1234         platform_device_unregister(wistron_device);
1235         platform_driver_unregister(&wistron_driver);
1236         unmap_bios();
1237         kfree(keymap);
1238 }
1239
1240 module_init(wb_module_init);
1241 module_exit(wb_module_exit);