blob: b9ef1dfc9a071c700239b803c989d429cb529d7a [file] [log] [blame]
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001/*
2 * Wistron laptop button driver
3 * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz>
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -05004 * Copyright (C) 2005 Bernhard Rosenkraenzer <bero@arklinux.org>
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05005 * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru>
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05006 *
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 */
Matthew Wilcox53d5ed62006-10-11 01:22:01 -070020#include <linux/io.h>
Dmitry Torokhov5fc146802005-11-20 00:50:06 -050021#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>
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -050032#include <linux/platform_device.h>
Dmitry Torokhov5fc146802005-11-20 00:50:06 -050033
34/*
35 * Number of attempts to read data from queue per poll;
36 * the queue can hold up to 31 entries
37 */
38#define MAX_POLL_ITERATIONS 64
39
40#define POLL_FREQUENCY 10 /* Number of polls per second */
41
42#if POLL_FREQUENCY > HZ
43#error "POLL_FREQUENCY too high"
44#endif
45
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -050046/* BIOS subsystem IDs */
47#define WIFI 0x35
48#define BLUETOOTH 0x34
49
Dmitry Torokhov5fc146802005-11-20 00:50:06 -050050MODULE_AUTHOR("Miloslav Trmac <mitr@volny.cz>");
51MODULE_DESCRIPTION("Wistron laptop button driver");
52MODULE_LICENSE("GPL v2");
53MODULE_VERSION("0.1");
54
55static int force; /* = 0; */
56module_param(force, bool, 0);
57MODULE_PARM_DESC(force, "Load even if computer is not in database");
58
59static char *keymap_name; /* = NULL; */
60module_param_named(keymap, keymap_name, charp, 0);
Eric Piel7b0a4cd2007-04-12 01:32:41 -040061MODULE_PARM_DESC(keymap, "Keymap name, if it can't be autodetected [generic, 1557/MS2141]");
Dmitry Torokhov5fc146802005-11-20 00:50:06 -050062
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -050063static struct platform_device *wistron_device;
64
Dmitry Torokhov5fc146802005-11-20 00:50:06 -050065 /* BIOS interface implementation */
66
67static void __iomem *bios_entry_point; /* BIOS routine entry point */
68static void __iomem *bios_code_map_base;
69static void __iomem *bios_data_map_base;
70
71static u8 cmos_address;
72
73struct regs {
74 u32 eax, ebx, ecx;
75};
76
77static void call_bios(struct regs *regs)
78{
79 unsigned long flags;
80
81 preempt_disable();
82 local_irq_save(flags);
83 asm volatile ("pushl %%ebp;"
84 "movl %7, %%ebp;"
85 "call *%6;"
86 "popl %%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);
92 preempt_enable();
93}
94
Miloslav Trmacc28c3582006-01-10 01:59:07 -050095static ssize_t __init locate_wistron_bios(void __iomem *base)
Dmitry Torokhov5fc146802005-11-20 00:50:06 -050096{
Andrew Mortonc7948982006-07-06 00:23:38 -040097 static unsigned char __initdata signature[] =
Dmitry Torokhov5fc146802005-11-20 00:50:06 -050098 { 0x42, 0x21, 0x55, 0x30 };
Miloslav Trmacc28c3582006-01-10 01:59:07 -050099 ssize_t offset;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500100
101 for (offset = 0; offset < 0x10000; offset += 0x10) {
102 if (check_signature(base + offset, signature,
103 sizeof(signature)) != 0)
104 return offset;
105 }
106 return -1;
107}
108
109static int __init map_bios(void)
110{
111 void __iomem *base;
Miloslav Trmacc28c3582006-01-10 01:59:07 -0500112 ssize_t offset;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500113 u32 entry_point;
114
115 base = ioremap(0xF0000, 0x10000); /* Can't fail */
116 offset = locate_wistron_bios(base);
117 if (offset < 0) {
118 printk(KERN_ERR "wistron_btns: BIOS entry point not found\n");
119 iounmap(base);
120 return -ENODEV;
121 }
122
123 entry_point = readl(base + offset + 5);
124 printk(KERN_DEBUG
125 "wistron_btns: BIOS signature found at %p, entry point %08X\n",
126 base + offset, entry_point);
127
128 if (entry_point >= 0xF0000) {
129 bios_code_map_base = base;
130 bios_entry_point = bios_code_map_base + (entry_point & 0xFFFF);
131 } else {
132 iounmap(base);
133 bios_code_map_base = ioremap(entry_point & ~0x3FFF, 0x4000);
134 if (bios_code_map_base == NULL) {
135 printk(KERN_ERR
136 "wistron_btns: Can't map BIOS code at %08X\n",
137 entry_point & ~0x3FFF);
138 goto err;
139 }
140 bios_entry_point = bios_code_map_base + (entry_point & 0x3FFF);
141 }
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");
146 goto err_code;
147 }
148 return 0;
149
150err_code:
151 iounmap(bios_code_map_base);
152err:
153 return -ENOMEM;
154}
155
Dmitry Torokhov22a397e2005-11-20 00:50:46 -0500156static inline void unmap_bios(void)
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500157{
158 iounmap(bios_code_map_base);
159 iounmap(bios_data_map_base);
160}
161
162 /* BIOS calls */
163
164static u16 bios_pop_queue(void)
165{
166 struct regs regs;
167
168 memset(&regs, 0, sizeof (regs));
169 regs.eax = 0x9610;
170 regs.ebx = 0x061C;
171 regs.ecx = 0x0000;
172 call_bios(&regs);
173
174 return regs.eax;
175}
176
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -0500177static void __devinit bios_attach(void)
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500178{
179 struct regs regs;
180
181 memset(&regs, 0, sizeof (regs));
182 regs.eax = 0x9610;
183 regs.ebx = 0x012E;
184 call_bios(&regs);
185}
186
Dmitry Torokhov22a397e2005-11-20 00:50:46 -0500187static void bios_detach(void)
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500188{
189 struct regs regs;
190
191 memset(&regs, 0, sizeof (regs));
192 regs.eax = 0x9610;
193 regs.ebx = 0x002E;
194 call_bios(&regs);
195}
196
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -0500197static u8 __devinit bios_get_cmos_address(void)
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500198{
199 struct regs regs;
200
201 memset(&regs, 0, sizeof (regs));
202 regs.eax = 0x9610;
203 regs.ebx = 0x051C;
204 call_bios(&regs);
205
206 return regs.ecx;
207}
208
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -0500209static u16 __devinit bios_get_default_setting(u8 subsys)
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500210{
211 struct regs regs;
212
213 memset(&regs, 0, sizeof (regs));
214 regs.eax = 0x9610;
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -0500215 regs.ebx = 0x0200 | subsys;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500216 call_bios(&regs);
217
218 return regs.eax;
219}
220
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -0500221static void bios_set_state(u8 subsys, int enable)
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500222{
223 struct regs regs;
224
225 memset(&regs, 0, sizeof (regs));
226 regs.eax = 0x9610;
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -0500227 regs.ebx = (enable ? 0x0100 : 0x0000) | subsys;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500228 call_bios(&regs);
229}
230
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -0500231/* Hardware database */
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500232
233struct key_entry {
234 char type; /* See KE_* below */
235 u8 code;
Eric Piel6480e2a2007-04-12 01:32:34 -0400236 union {
237 u16 keycode; /* For KE_KEY */
238 struct { /* For KE_SW */
239 u8 code;
240 u8 value;
241 } sw;
242 };
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500243};
244
Eric Piel6480e2a2007-04-12 01:32:34 -0400245enum { KE_END, KE_KEY, KE_SW, KE_WIFI, KE_BLUETOOTH };
246
247#define FE_MAIL_LED 0x01
248#define FE_WIFI_LED 0x02
249#define FE_UNTESTED 0x80
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500250
251static const struct key_entry *keymap; /* = NULL; Current key map */
252static int have_wifi;
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -0500253static int have_bluetooth;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500254
255static int __init dmi_matched(struct dmi_system_id *dmi)
256{
257 const struct key_entry *key;
258
259 keymap = dmi->driver_data;
260 for (key = keymap; key->type != KE_END; key++) {
Reiner Herrmanncde45f12006-10-01 21:58:51 -0400261 if (key->type == KE_WIFI)
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500262 have_wifi = 1;
Reiner Herrmanncde45f12006-10-01 21:58:51 -0400263 else if (key->type == KE_BLUETOOTH)
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -0500264 have_bluetooth = 1;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500265 }
266 return 1;
267}
268
Dmitry Torokhov72a623b2006-08-23 00:47:39 -0400269static struct key_entry keymap_empty[] = {
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500270 { KE_END, 0 }
271};
272
Dmitry Torokhov72a623b2006-08-23 00:47:39 -0400273static struct key_entry keymap_fs_amilo_pro_v2000[] = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400274 { KE_KEY, 0x01, {KEY_HELP} },
275 { KE_KEY, 0x11, {KEY_PROG1} },
276 { KE_KEY, 0x12, {KEY_PROG2} },
277 { KE_WIFI, 0x30 },
278 { KE_KEY, 0x31, {KEY_MAIL} },
279 { KE_KEY, 0x36, {KEY_WWW} },
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500280 { KE_END, 0 }
281};
282
Dmitry Torokhov72a623b2006-08-23 00:47:39 -0400283static struct key_entry keymap_fujitsu_n3510[] = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400284 { 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} },
John Reed Rileye2aa5072006-04-05 00:40:01 -0400292 { KE_END, 0 }
293};
294
Dmitry Torokhov72a623b2006-08-23 00:47:39 -0400295static struct key_entry keymap_wistron_ms2111[] = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400296 { 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 }
302};
303
304static struct key_entry keymap_wistron_md40100[] = {
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 }
Frank de Lange90001952006-06-27 01:48:24 -0400311};
312
Dmitry Torokhov72a623b2006-08-23 00:47:39 -0400313static struct key_entry keymap_wistron_ms2141[] = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400314 { KE_KEY, 0x11, {KEY_PROG1} },
315 { KE_KEY, 0x12, {KEY_PROG2} },
316 { KE_WIFI, 0x30 },
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} },
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500323 { KE_END, 0 }
324};
325
Dmitry Torokhov72a623b2006-08-23 00:47:39 -0400326static struct key_entry keymap_acer_aspire_1500[] = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400327 { KE_KEY, 0x01, {KEY_HELP} },
328 { KE_KEY, 0x03, {KEY_POWER} },
329 { KE_KEY, 0x11, {KEY_PROG1} },
330 { KE_KEY, 0x12, {KEY_PROG2} },
331 { KE_WIFI, 0x30 },
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 }
337};
338
339static struct key_entry keymap_acer_aspire_1600[] = {
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} },
349 { KE_WIFI, 0x30 },
350 { KE_BLUETOOTH, 0x44 },
351 { KE_END, FE_MAIL_LED | FE_UNTESTED }
352};
353
354/* 3020 has been tested */
355static struct key_entry keymap_acer_aspire_5020[] = {
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} },
364 { KE_WIFI, 0x30 },
365 { KE_BLUETOOTH, 0x44 },
366 { KE_END, FE_MAIL_LED | FE_UNTESTED }
367};
368
369static struct key_entry keymap_acer_travelmate_2410[] = {
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} },
377 { KE_WIFI, 0x30 },
378 { KE_BLUETOOTH, 0x44 },
379 { KE_END, FE_MAIL_LED | FE_UNTESTED }
380};
381
382static struct key_entry keymap_acer_travelmate_110[] = {
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 */
395 { KE_WIFI, 0x30 },
396 { KE_END, FE_MAIL_LED | FE_UNTESTED }
397};
398
399static struct key_entry keymap_acer_travelmate_300[] = {
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} },
410 { KE_WIFI, 0x30 },
411 { KE_BLUETOOTH, 0x44 },
412 { KE_END, FE_MAIL_LED | FE_UNTESTED }
413};
414
415static struct key_entry keymap_acer_travelmate_380[] = {
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} },
424 { KE_WIFI, 0x30 },
425 { KE_END, FE_MAIL_LED | FE_UNTESTED }
426};
427
428/* unusual map */
429static struct key_entry keymap_acer_travelmate_220[] = {
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 }
437};
438
439static struct key_entry keymap_acer_travelmate_230[] = {
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 }
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -0500447};
448
Dmitry Torokhov72a623b2006-08-23 00:47:39 -0400449static struct key_entry keymap_acer_travelmate_240[] = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400450 { 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 },
459 { KE_WIFI, 0x30 },
460 { KE_END, FE_UNTESTED }
461};
462
463static struct key_entry keymap_acer_travelmate_350[] = {
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 }
472};
473
474static struct key_entry keymap_acer_travelmate_360[] = {
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 */
Ashutosh Naik74a89c92005-12-11 12:41:32 -0500484};
485
Eric Pielbc413c92007-03-07 01:45:16 -0500486/* 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) */
489static struct key_entry keymap_acer_travelmate_610[] = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400490 { KE_KEY, 0x01, {KEY_HELP} },
491 { KE_KEY, 0x02, {KEY_CONFIG} },
492 { KE_KEY, 0x11, {KEY_PROG1} },
493 { KE_KEY, 0x12, {KEY_PROG3} },
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 }
499};
500
501static struct key_entry keymap_acer_travelmate_630[] = {
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} },
513 { KE_WIFI, 0x30 },
514 { KE_END, FE_MAIL_LED | FE_UNTESTED }
Eric Pielbc413c92007-03-07 01:45:16 -0500515};
516
Dmitry Torokhov72a623b2006-08-23 00:47:39 -0400517static struct key_entry keymap_aopen_1559as[] = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400518 { KE_KEY, 0x01, {KEY_HELP} },
519 { KE_KEY, 0x06, {KEY_PROG3} },
520 { KE_KEY, 0x11, {KEY_PROG1} },
521 { KE_KEY, 0x12, {KEY_PROG2} },
522 { KE_WIFI, 0x30 },
523 { KE_KEY, 0x31, {KEY_MAIL} },
524 { KE_KEY, 0x36, {KEY_WWW} },
Frank de Lange90001952006-06-27 01:48:24 -0400525 { KE_END, 0 },
masc@theaterzentrum.ate107b8e2006-05-29 23:29:36 -0400526};
527
Michael Leun5809d5372007-02-10 01:29:42 -0500528static struct key_entry keymap_fs_amilo_d88x0[] = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400529 { 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 }
537};
538
539static struct key_entry keymap_wistron_md2900[] = {
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} },
546 { KE_WIFI, 0x30 },
547 { KE_END, FE_MAIL_LED | FE_UNTESTED }
548};
549
550static struct key_entry keymap_wistron_md96500[] = {
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} },
566 { KE_WIFI, 0x30 },
567 { KE_BLUETOOTH, 0x44 },
568 { KE_END, FE_UNTESTED }
Michael Leun5809d5372007-02-10 01:29:42 -0500569};
570
Eric Piel7b0a4cd2007-04-12 01:32:41 -0400571static struct key_entry keymap_wistron_generic[] = {
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} },
602 { KE_WIFI, 0x30 },
603 { KE_BLUETOOTH, 0x44 },
604 { KE_END, 0 }
605};
606
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500607/*
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.
611 */
Andrew Mortonc7948982006-07-06 00:23:38 -0400612static struct dmi_system_id dmi_ids[] __initdata = {
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500613 {
614 .callback = dmi_matched,
615 .ident = "Fujitsu-Siemens Amilo Pro V2000",
616 .matches = {
617 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
618 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pro V2000"),
619 },
620 .driver_data = keymap_fs_amilo_pro_v2000
621 },
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -0500622 {
623 .callback = dmi_matched,
Stefan Rompf8a1b1702006-04-05 00:39:20 -0400624 .ident = "Fujitsu-Siemens Amilo M7400",
625 .matches = {
626 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
627 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO M "),
628 },
629 .driver_data = keymap_fs_amilo_pro_v2000
630 },
631 {
632 .callback = dmi_matched,
John Reed Rileye2aa5072006-04-05 00:40:01 -0400633 .ident = "Fujitsu N3510",
634 .matches = {
635 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
636 DMI_MATCH(DMI_PRODUCT_NAME, "N3510"),
637 },
638 .driver_data = keymap_fujitsu_n3510
639 },
640 {
641 .callback = dmi_matched,
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -0500642 .ident = "Acer Aspire 1500",
643 .matches = {
644 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
645 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1500"),
646 },
647 .driver_data = keymap_acer_aspire_1500
648 },
Ashutosh Naik74a89c92005-12-11 12:41:32 -0500649 {
650 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400651 .ident = "Acer Aspire 1600",
652 .matches = {
653 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
654 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1600"),
655 },
656 .driver_data = keymap_acer_aspire_1600
657 },
658 {
659 .callback = dmi_matched,
660 .ident = "Acer Aspire 3020",
661 .matches = {
662 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
663 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3020"),
664 },
665 .driver_data = keymap_acer_aspire_5020
666 },
667 {
668 .callback = dmi_matched,
669 .ident = "Acer Aspire 5020",
670 .matches = {
671 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
672 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5020"),
673 },
674 .driver_data = keymap_acer_aspire_5020
675 },
676 {
677 .callback = dmi_matched,
678 .ident = "Acer TravelMate 2100",
679 .matches = {
680 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
681 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2100"),
682 },
683 .driver_data = keymap_acer_aspire_5020
684 },
685 {
686 .callback = dmi_matched,
687 .ident = "Acer TravelMate 2410",
688 .matches = {
689 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
690 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2410"),
691 },
692 .driver_data = keymap_acer_travelmate_2410
693 },
694 {
695 .callback = dmi_matched,
696 .ident = "Acer TravelMate C300",
697 .matches = {
698 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
699 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate C300"),
700 },
701 .driver_data = keymap_acer_travelmate_300
702 },
703 {
704 .callback = dmi_matched,
705 .ident = "Acer TravelMate C100",
706 .matches = {
707 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
708 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate C100"),
709 },
710 .driver_data = keymap_acer_travelmate_300
711 },
712 {
713 .callback = dmi_matched,
714 .ident = "Acer TravelMate C110",
715 .matches = {
716 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
717 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate C110"),
718 },
719 .driver_data = keymap_acer_travelmate_110
720 },
721 {
722 .callback = dmi_matched,
723 .ident = "Acer TravelMate 380",
724 .matches = {
725 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
726 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 380"),
727 },
728 .driver_data = keymap_acer_travelmate_380
729 },
730 {
731 .callback = dmi_matched,
732 .ident = "Acer TravelMate 370",
733 .matches = {
734 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
735 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 370"),
736 },
737 .driver_data = keymap_acer_travelmate_380 /* keyboard minus 1 key */
738 },
739 {
740 .callback = dmi_matched,
741 .ident = "Acer TravelMate 220",
742 .matches = {
743 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
744 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 220"),
745 },
746 .driver_data = keymap_acer_travelmate_220
747 },
748 {
749 .callback = dmi_matched,
750 .ident = "Acer TravelMate 260",
751 .matches = {
752 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
753 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 260"),
754 },
755 .driver_data = keymap_acer_travelmate_220
756 },
757 {
758 .callback = dmi_matched,
759 .ident = "Acer TravelMate 230",
760 .matches = {
761 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
762 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 230"),
763 /* acerhk looks for "TravelMate F4..." ?! */
764 },
765 .driver_data = keymap_acer_travelmate_230
766 },
767 {
768 .callback = dmi_matched,
769 .ident = "Acer TravelMate 280",
770 .matches = {
771 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
772 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 280"),
773 },
774 .driver_data = keymap_acer_travelmate_230
775 },
776 {
777 .callback = dmi_matched,
Ashutosh Naik74a89c92005-12-11 12:41:32 -0500778 .ident = "Acer TravelMate 240",
779 .matches = {
780 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
781 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 240"),
782 },
783 .driver_data = keymap_acer_travelmate_240
784 },
Ashutosh Naikbb088592006-10-01 22:07:14 -0400785 {
786 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400787 .ident = "Acer TravelMate 250",
788 .matches = {
789 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
790 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 250"),
791 },
792 .driver_data = keymap_acer_travelmate_240
793 },
794 {
795 .callback = dmi_matched,
Ashutosh Naikbb088592006-10-01 22:07:14 -0400796 .ident = "Acer TravelMate 2424NWXCi",
797 .matches = {
798 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
799 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2420"),
800 },
801 .driver_data = keymap_acer_travelmate_240
802 },
803 {
masc@theaterzentrum.ate107b8e2006-05-29 23:29:36 -0400804 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400805 .ident = "Acer TravelMate 350",
806 .matches = {
807 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
808 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 350"),
809 },
810 .driver_data = keymap_acer_travelmate_350
811 },
812 {
813 .callback = dmi_matched,
814 .ident = "Acer TravelMate 360",
815 .matches = {
816 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
817 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
818 },
819 .driver_data = keymap_acer_travelmate_360
820 },
821 {
822 .callback = dmi_matched,
Eric Pielbc413c92007-03-07 01:45:16 -0500823 .ident = "Acer TravelMate 610",
824 .matches = {
825 DMI_MATCH(DMI_SYS_VENDOR, "ACER"),
826 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 610"),
827 },
828 .driver_data = keymap_acer_travelmate_610
829 },
830 {
831 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400832 .ident = "Acer TravelMate 620",
833 .matches = {
834 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
835 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 620"),
836 },
837 .driver_data = keymap_acer_travelmate_630
838 },
839 {
840 .callback = dmi_matched,
841 .ident = "Acer TravelMate 630",
842 .matches = {
843 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
844 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 630"),
845 },
846 .driver_data = keymap_acer_travelmate_630
847 },
848 {
849 .callback = dmi_matched,
masc@theaterzentrum.ate107b8e2006-05-29 23:29:36 -0400850 .ident = "AOpen 1559AS",
851 .matches = {
852 DMI_MATCH(DMI_PRODUCT_NAME, "E2U"),
853 DMI_MATCH(DMI_BOARD_NAME, "E2U"),
854 },
855 .driver_data = keymap_aopen_1559as
856 },
Frank de Lange90001952006-06-27 01:48:24 -0400857 {
858 .callback = dmi_matched,
859 .ident = "Medion MD 9783",
860 .matches = {
861 DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
862 DMI_MATCH(DMI_PRODUCT_NAME, "MD 9783"),
863 },
864 .driver_data = keymap_wistron_ms2111
865 },
Michael Leun5809d5372007-02-10 01:29:42 -0500866 {
867 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400868 .ident = "Medion MD 40100",
869 .matches = {
870 DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
871 DMI_MATCH(DMI_PRODUCT_NAME, "WID2000"),
872 },
873 .driver_data = keymap_wistron_md40100
874 },
875 {
876 .callback = dmi_matched,
877 .ident = "Medion MD 2900",
878 .matches = {
879 DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
880 DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2000"),
881 },
882 .driver_data = keymap_wistron_md2900
883 },
884 {
885 .callback = dmi_matched,
886 .ident = "Medion MD 96500",
887 .matches = {
888 DMI_MATCH(DMI_SYS_VENDOR, "MEDIONPC"),
889 DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2040"),
890 },
891 .driver_data = keymap_wistron_md96500
892 },
893 {
894 .callback = dmi_matched,
895 .ident = "Medion MD 95400",
896 .matches = {
897 DMI_MATCH(DMI_SYS_VENDOR, "MEDIONPC"),
898 DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2050"),
899 },
900 .driver_data = keymap_wistron_md96500
901 },
902 {
903 .callback = dmi_matched,
904 .ident = "Fujitsu Siemens Amilo D7820",
905 .matches = {
906 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"), /* not sure */
907 DMI_MATCH(DMI_PRODUCT_NAME, "Amilo D"),
908 },
909 .driver_data = keymap_fs_amilo_d88x0
910 },
911 {
912 .callback = dmi_matched,
Michael Leun5809d5372007-02-10 01:29:42 -0500913 .ident = "Fujitsu Siemens Amilo D88x0",
914 .matches = {
915 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
916 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO D"),
917 },
918 .driver_data = keymap_fs_amilo_d88x0
919 },
Al Viro81f0a912005-12-15 09:19:05 +0000920 { NULL, }
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500921};
922
923static int __init select_keymap(void)
924{
Eric Piel7b0a4cd2007-04-12 01:32:41 -0400925 dmi_check_system(dmi_ids);
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500926 if (keymap_name != NULL) {
927 if (strcmp (keymap_name, "1557/MS2141") == 0)
928 keymap = keymap_wistron_ms2141;
Eric Piel7b0a4cd2007-04-12 01:32:41 -0400929 else if (strcmp (keymap_name, "generic") == 0)
930 keymap = keymap_wistron_generic;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500931 else {
932 printk(KERN_ERR "wistron_btns: Keymap unknown\n");
933 return -EINVAL;
934 }
935 }
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500936 if (keymap == NULL) {
937 if (!force) {
938 printk(KERN_ERR "wistron_btns: System unknown\n");
939 return -ENODEV;
940 }
941 keymap = keymap_empty;
942 }
943 return 0;
944}
945
946 /* Input layer interface */
947
Dmitry Torokhov22a397e2005-11-20 00:50:46 -0500948static struct input_dev *input_dev;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500949
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -0500950static int __devinit setup_input_dev(void)
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500951{
952 const struct key_entry *key;
Dmitry Torokhov22a397e2005-11-20 00:50:46 -0500953 int error;
954
955 input_dev = input_allocate_device();
956 if (!input_dev)
957 return -ENOMEM;
958
959 input_dev->name = "Wistron laptop buttons";
960 input_dev->phys = "wistron/input0";
961 input_dev->id.bustype = BUS_HOST;
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -0500962 input_dev->cdev.dev = &wistron_device->dev;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500963
964 for (key = keymap; key->type != KE_END; key++) {
Eric Piel6480e2a2007-04-12 01:32:34 -0400965 switch (key->type) {
966 case KE_KEY:
967 set_bit(EV_KEY, input_dev->evbit);
968 set_bit(key->keycode, input_dev->keybit);
969 break;
970
971 case KE_SW:
972 set_bit(EV_SW, input_dev->evbit);
973 set_bit(key->sw.code, input_dev->swbit);
974 break;
975
976 default:
977 ;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500978 }
979 }
980
Eric Piel6480e2a2007-04-12 01:32:34 -0400981 /* reads information flags on KE_END */
982 if (key->code & FE_UNTESTED)
983 printk(KERN_WARNING "Untested laptop multimedia keys, "
984 "please report success or failure to eric.piel"
985 "@tremplin-utc.net\n");
986
Dmitry Torokhov22a397e2005-11-20 00:50:46 -0500987 error = input_register_device(input_dev);
988 if (error) {
989 input_free_device(input_dev);
990 return error;
991 }
992
993 return 0;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500994}
995
996static void report_key(unsigned keycode)
997{
Dmitry Torokhov22a397e2005-11-20 00:50:46 -0500998 input_report_key(input_dev, keycode, 1);
999 input_sync(input_dev);
1000 input_report_key(input_dev, keycode, 0);
1001 input_sync(input_dev);
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001002}
1003
Eric Piel6480e2a2007-04-12 01:32:34 -04001004static void report_switch(unsigned code, int value)
1005{
1006 input_report_switch(input_dev, code, value);
1007 input_sync(input_dev);
1008}
1009
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001010 /* Driver core */
1011
1012static int wifi_enabled;
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -05001013static int bluetooth_enabled;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001014
1015static void poll_bios(unsigned long);
1016
1017static struct timer_list poll_timer = TIMER_INITIALIZER(poll_bios, 0, 0);
1018
1019static void handle_key(u8 code)
1020{
1021 const struct key_entry *key;
1022
1023 for (key = keymap; key->type != KE_END; key++) {
1024 if (code == key->code) {
1025 switch (key->type) {
1026 case KE_KEY:
1027 report_key(key->keycode);
1028 break;
1029
Eric Piel6480e2a2007-04-12 01:32:34 -04001030 case KE_SW:
1031 report_switch(key->sw.code, key->sw.value);
1032 break;
1033
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001034 case KE_WIFI:
1035 if (have_wifi) {
1036 wifi_enabled = !wifi_enabled;
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -05001037 bios_set_state(WIFI, wifi_enabled);
1038 }
1039 break;
1040
1041 case KE_BLUETOOTH:
1042 if (have_bluetooth) {
1043 bluetooth_enabled = !bluetooth_enabled;
1044 bios_set_state(BLUETOOTH, bluetooth_enabled);
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001045 }
1046 break;
1047
1048 case KE_END:
Eric Piel6480e2a2007-04-12 01:32:34 -04001049 break;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001050 default:
1051 BUG();
1052 }
1053 return;
1054 }
1055 }
1056 printk(KERN_NOTICE "wistron_btns: Unknown key code %02X\n", code);
1057}
1058
1059static void poll_bios(unsigned long discard)
1060{
1061 u8 qlen;
1062 u16 val;
1063
1064 for (;;) {
1065 qlen = CMOS_READ(cmos_address);
1066 if (qlen == 0)
1067 break;
1068 val = bios_pop_queue();
1069 if (val != 0 && !discard)
1070 handle_key((u8)val);
1071 }
1072
1073 mod_timer(&poll_timer, jiffies + HZ / POLL_FREQUENCY);
1074}
1075
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001076static int __devinit wistron_probe(struct platform_device *dev)
1077{
1078 int err = setup_input_dev();
1079 if (err)
1080 return err;
1081
1082 bios_attach();
1083 cmos_address = bios_get_cmos_address();
1084
1085 if (have_wifi) {
1086 u16 wifi = bios_get_default_setting(WIFI);
1087 if (wifi & 1)
1088 wifi_enabled = (wifi & 2) ? 1 : 0;
1089 else
1090 have_wifi = 0;
1091
1092 if (have_wifi)
1093 bios_set_state(WIFI, wifi_enabled);
1094 }
1095
1096 if (have_bluetooth) {
1097 u16 bt = bios_get_default_setting(BLUETOOTH);
1098 if (bt & 1)
1099 bluetooth_enabled = (bt & 2) ? 1 : 0;
1100 else
1101 have_bluetooth = 0;
1102
1103 if (have_bluetooth)
1104 bios_set_state(BLUETOOTH, bluetooth_enabled);
1105 }
1106
1107 poll_bios(1); /* Flush stale event queue and arm timer */
1108
1109 return 0;
1110}
1111
1112static int __devexit wistron_remove(struct platform_device *dev)
1113{
1114 del_timer_sync(&poll_timer);
1115 input_unregister_device(input_dev);
1116 bios_detach();
1117
1118 return 0;
1119}
1120
1121#ifdef CONFIG_PM
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001122static int wistron_suspend(struct platform_device *dev, pm_message_t state)
1123{
1124 del_timer_sync(&poll_timer);
1125
Miloslav Trmace753b652005-11-20 00:51:05 -05001126 if (have_wifi)
1127 bios_set_state(WIFI, 0);
1128
1129 if (have_bluetooth)
1130 bios_set_state(BLUETOOTH, 0);
1131
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001132 return 0;
1133}
1134
1135static int wistron_resume(struct platform_device *dev)
1136{
1137 if (have_wifi)
1138 bios_set_state(WIFI, wifi_enabled);
1139
1140 if (have_bluetooth)
1141 bios_set_state(BLUETOOTH, bluetooth_enabled);
1142
1143 poll_bios(1);
1144
1145 return 0;
1146}
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001147#else
1148#define wistron_suspend NULL
1149#define wistron_resume NULL
1150#endif
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001151
1152static struct platform_driver wistron_driver = {
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001153 .driver = {
1154 .name = "wistron-bios",
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001155 .owner = THIS_MODULE,
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001156 },
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001157 .probe = wistron_probe,
1158 .remove = __devexit_p(wistron_remove),
1159 .suspend = wistron_suspend,
1160 .resume = wistron_resume,
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001161};
1162
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001163static int __init wb_module_init(void)
1164{
1165 int err;
1166
1167 err = select_keymap();
1168 if (err)
1169 return err;
Dmitry Torokhov22a397e2005-11-20 00:50:46 -05001170
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001171 err = map_bios();
1172 if (err)
1173 return err;
Dmitry Torokhov22a397e2005-11-20 00:50:46 -05001174
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001175 err = platform_driver_register(&wistron_driver);
1176 if (err)
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001177 goto err_unmap_bios;
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001178
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001179 wistron_device = platform_device_alloc("wistron-bios", -1);
1180 if (!wistron_device) {
1181 err = -ENOMEM;
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001182 goto err_unregister_driver;
1183 }
1184
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001185 err = platform_device_add(wistron_device);
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001186 if (err)
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001187 goto err_free_device;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001188
1189 return 0;
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001190
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001191 err_free_device:
1192 platform_device_put(wistron_device);
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001193 err_unregister_driver:
1194 platform_driver_unregister(&wistron_driver);
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001195 err_unmap_bios:
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001196 unmap_bios();
1197
1198 return err;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001199}
1200
1201static void __exit wb_module_exit(void)
1202{
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001203 platform_device_unregister(wistron_device);
1204 platform_driver_unregister(&wistron_driver);
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001205 unmap_bios();
1206}
1207
1208module_init(wb_module_init);
1209module_exit(wb_module_exit);