blob: b6505454bcc4575f810b468d81c419a6f8ff611c [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>
Dmitry Torokhovc2554c92007-05-22 23:48:39 -040023#include <linux/input-polldev.h>
Dmitry Torokhove97af4c2009-12-04 10:22:24 -080024#include <linux/input/sparse-keymap.h>
Dmitry Torokhov5fc146802005-11-20 00:50:06 -050025#include <linux/interrupt.h>
Eric Piela4da16d2007-05-21 00:46:22 -040026#include <linux/jiffies.h>
Dmitry Torokhov5fc146802005-11-20 00:50:06 -050027#include <linux/kernel.h>
28#include <linux/mc146818rtc.h>
29#include <linux/module.h>
30#include <linux/preempt.h>
31#include <linux/string.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090032#include <linux/slab.h>
Dmitry Torokhov5fc146802005-11-20 00:50:06 -050033#include <linux/types.h>
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -050034#include <linux/platform_device.h>
Eric Piel389679d2007-05-21 00:46:31 -040035#include <linux/leds.h>
Dmitry Torokhov5fc146802005-11-20 00:50:06 -050036
Dmitry Torokhovc2554c92007-05-22 23:48:39 -040037/* How often we poll keys - msecs */
38#define POLL_INTERVAL_DEFAULT 500 /* when idle */
39#define POLL_INTERVAL_BURST 100 /* when a key was recently pressed */
Dmitry Torokhov5fc146802005-11-20 00:50:06 -050040
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -050041/* BIOS subsystem IDs */
42#define WIFI 0x35
43#define BLUETOOTH 0x34
Eric Piel389679d2007-05-21 00:46:31 -040044#define MAIL_LED 0x31
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -050045
Dmitry Torokhov5fc146802005-11-20 00:50:06 -050046MODULE_AUTHOR("Miloslav Trmac <mitr@volny.cz>");
47MODULE_DESCRIPTION("Wistron laptop button driver");
48MODULE_LICENSE("GPL v2");
Dmitry Torokhov5fc146802005-11-20 00:50:06 -050049
Rusty Russell90ab5ee2012-01-13 09:32:20 +103050static bool force; /* = 0; */
Dmitry Torokhov5fc146802005-11-20 00:50:06 -050051module_param(force, bool, 0);
52MODULE_PARM_DESC(force, "Load even if computer is not in database");
53
54static char *keymap_name; /* = NULL; */
55module_param_named(keymap, keymap_name, charp, 0);
Eric Piel7b0a4cd2007-04-12 01:32:41 -040056MODULE_PARM_DESC(keymap, "Keymap name, if it can't be autodetected [generic, 1557/MS2141]");
Dmitry Torokhov5fc146802005-11-20 00:50:06 -050057
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -050058static struct platform_device *wistron_device;
59
Dmitry Torokhov5fc146802005-11-20 00:50:06 -050060 /* BIOS interface implementation */
61
62static void __iomem *bios_entry_point; /* BIOS routine entry point */
63static void __iomem *bios_code_map_base;
64static void __iomem *bios_data_map_base;
65
66static u8 cmos_address;
67
68struct regs {
69 u32 eax, ebx, ecx;
70};
71
72static void call_bios(struct regs *regs)
73{
74 unsigned long flags;
75
76 preempt_disable();
77 local_irq_save(flags);
78 asm volatile ("pushl %%ebp;"
79 "movl %7, %%ebp;"
80 "call *%6;"
81 "popl %%ebp"
82 : "=a" (regs->eax), "=b" (regs->ebx), "=c" (regs->ecx)
83 : "0" (regs->eax), "1" (regs->ebx), "2" (regs->ecx),
84 "m" (bios_entry_point), "m" (bios_data_map_base)
85 : "edx", "edi", "esi", "memory");
86 local_irq_restore(flags);
87 preempt_enable();
88}
89
Miloslav Trmacc28c3582006-01-10 01:59:07 -050090static ssize_t __init locate_wistron_bios(void __iomem *base)
Dmitry Torokhov5fc146802005-11-20 00:50:06 -050091{
Andrew Mortonc7948982006-07-06 00:23:38 -040092 static unsigned char __initdata signature[] =
Dmitry Torokhov5fc146802005-11-20 00:50:06 -050093 { 0x42, 0x21, 0x55, 0x30 };
Miloslav Trmacc28c3582006-01-10 01:59:07 -050094 ssize_t offset;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -050095
96 for (offset = 0; offset < 0x10000; offset += 0x10) {
97 if (check_signature(base + offset, signature,
98 sizeof(signature)) != 0)
99 return offset;
100 }
101 return -1;
102}
103
104static int __init map_bios(void)
105{
106 void __iomem *base;
Miloslav Trmacc28c3582006-01-10 01:59:07 -0500107 ssize_t offset;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500108 u32 entry_point;
109
110 base = ioremap(0xF0000, 0x10000); /* Can't fail */
111 offset = locate_wistron_bios(base);
112 if (offset < 0) {
113 printk(KERN_ERR "wistron_btns: BIOS entry point not found\n");
114 iounmap(base);
115 return -ENODEV;
116 }
117
118 entry_point = readl(base + offset + 5);
119 printk(KERN_DEBUG
120 "wistron_btns: BIOS signature found at %p, entry point %08X\n",
121 base + offset, entry_point);
122
123 if (entry_point >= 0xF0000) {
124 bios_code_map_base = base;
125 bios_entry_point = bios_code_map_base + (entry_point & 0xFFFF);
126 } else {
127 iounmap(base);
128 bios_code_map_base = ioremap(entry_point & ~0x3FFF, 0x4000);
129 if (bios_code_map_base == NULL) {
130 printk(KERN_ERR
131 "wistron_btns: Can't map BIOS code at %08X\n",
132 entry_point & ~0x3FFF);
133 goto err;
134 }
135 bios_entry_point = bios_code_map_base + (entry_point & 0x3FFF);
136 }
137 /* The Windows driver maps 0x10000 bytes, we keep only one page... */
138 bios_data_map_base = ioremap(0x400, 0xc00);
139 if (bios_data_map_base == NULL) {
140 printk(KERN_ERR "wistron_btns: Can't map BIOS data\n");
141 goto err_code;
142 }
143 return 0;
144
145err_code:
146 iounmap(bios_code_map_base);
147err:
148 return -ENOMEM;
149}
150
Dmitry Torokhov22a397e2005-11-20 00:50:46 -0500151static inline void unmap_bios(void)
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500152{
153 iounmap(bios_code_map_base);
154 iounmap(bios_data_map_base);
155}
156
157 /* BIOS calls */
158
159static u16 bios_pop_queue(void)
160{
161 struct regs regs;
162
163 memset(&regs, 0, sizeof (regs));
164 regs.eax = 0x9610;
165 regs.ebx = 0x061C;
166 regs.ecx = 0x0000;
167 call_bios(&regs);
168
169 return regs.eax;
170}
171
Bill Pemberton5298cc42012-11-23 21:38:25 -0800172static void bios_attach(void)
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500173{
174 struct regs regs;
175
176 memset(&regs, 0, sizeof (regs));
177 regs.eax = 0x9610;
178 regs.ebx = 0x012E;
179 call_bios(&regs);
180}
181
Dmitry Torokhov22a397e2005-11-20 00:50:46 -0500182static void bios_detach(void)
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500183{
184 struct regs regs;
185
186 memset(&regs, 0, sizeof (regs));
187 regs.eax = 0x9610;
188 regs.ebx = 0x002E;
189 call_bios(&regs);
190}
191
Bill Pemberton5298cc42012-11-23 21:38:25 -0800192static u8 bios_get_cmos_address(void)
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500193{
194 struct regs regs;
195
196 memset(&regs, 0, sizeof (regs));
197 regs.eax = 0x9610;
198 regs.ebx = 0x051C;
199 call_bios(&regs);
200
201 return regs.ecx;
202}
203
Bill Pemberton5298cc42012-11-23 21:38:25 -0800204static u16 bios_get_default_setting(u8 subsys)
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500205{
206 struct regs regs;
207
208 memset(&regs, 0, sizeof (regs));
209 regs.eax = 0x9610;
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -0500210 regs.ebx = 0x0200 | subsys;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500211 call_bios(&regs);
212
213 return regs.eax;
214}
215
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -0500216static void bios_set_state(u8 subsys, int enable)
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500217{
218 struct regs regs;
219
220 memset(&regs, 0, sizeof (regs));
221 regs.eax = 0x9610;
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -0500222 regs.ebx = (enable ? 0x0100 : 0x0000) | subsys;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500223 call_bios(&regs);
224}
225
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -0500226/* Hardware database */
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500227
Dmitry Torokhove97af4c2009-12-04 10:22:24 -0800228#define KE_WIFI (KE_LAST + 1)
229#define KE_BLUETOOTH (KE_LAST + 2)
Eric Piel6480e2a2007-04-12 01:32:34 -0400230
231#define FE_MAIL_LED 0x01
232#define FE_WIFI_LED 0x02
233#define FE_UNTESTED 0x80
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500234
Dmitry Torokhovd63219a2007-06-14 23:31:45 -0400235static struct key_entry *keymap; /* = NULL; Current key map */
Dmitry Torokhov67dbe832009-08-07 23:17:39 -0700236static bool have_wifi;
237static bool have_bluetooth;
238static int leds_present; /* bitmask of leds present */
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500239
Jeff Garzik18552562007-10-03 15:15:40 -0400240static int __init dmi_matched(const struct dmi_system_id *dmi)
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500241{
242 const struct key_entry *key;
243
244 keymap = dmi->driver_data;
245 for (key = keymap; key->type != KE_END; key++) {
Reiner Herrmanncde45f12006-10-01 21:58:51 -0400246 if (key->type == KE_WIFI)
Dmitry Torokhov67dbe832009-08-07 23:17:39 -0700247 have_wifi = true;
Reiner Herrmanncde45f12006-10-01 21:58:51 -0400248 else if (key->type == KE_BLUETOOTH)
Dmitry Torokhov67dbe832009-08-07 23:17:39 -0700249 have_bluetooth = true;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500250 }
Dmitry Torokhov67dbe832009-08-07 23:17:39 -0700251 leds_present = key->code & (FE_MAIL_LED | FE_WIFI_LED);
Eric Piel389679d2007-05-21 00:46:31 -0400252
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500253 return 1;
254}
255
Eric Piel55d29c92007-04-12 01:32:49 -0400256static struct key_entry keymap_empty[] __initdata = {
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500257 { KE_END, 0 }
258};
259
Eric Piel55d29c92007-04-12 01:32:49 -0400260static struct key_entry keymap_fs_amilo_pro_v2000[] __initdata = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400261 { KE_KEY, 0x01, {KEY_HELP} },
262 { KE_KEY, 0x11, {KEY_PROG1} },
263 { KE_KEY, 0x12, {KEY_PROG2} },
264 { KE_WIFI, 0x30 },
265 { KE_KEY, 0x31, {KEY_MAIL} },
266 { KE_KEY, 0x36, {KEY_WWW} },
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500267 { KE_END, 0 }
268};
269
Remi Herilier34a7c482008-08-08 12:13:13 -0400270static struct key_entry keymap_fs_amilo_pro_v3505[] __initdata = {
271 { KE_KEY, 0x01, {KEY_HELP} }, /* Fn+F1 */
272 { KE_KEY, 0x06, {KEY_DISPLAYTOGGLE} }, /* Fn+F4 */
273 { KE_BLUETOOTH, 0x30 }, /* Fn+F10 */
274 { KE_KEY, 0x31, {KEY_MAIL} }, /* mail button */
275 { KE_KEY, 0x36, {KEY_WWW} }, /* www button */
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300276 { KE_WIFI, 0x78 }, /* satellite dish button */
Remi Herilier34a7c482008-08-08 12:13:13 -0400277 { KE_END, 0 }
278};
279
Eric Piel55d29c92007-04-12 01:32:49 -0400280static struct key_entry keymap_fujitsu_n3510[] __initdata = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400281 { KE_KEY, 0x11, {KEY_PROG1} },
282 { KE_KEY, 0x12, {KEY_PROG2} },
283 { KE_KEY, 0x36, {KEY_WWW} },
284 { KE_KEY, 0x31, {KEY_MAIL} },
285 { KE_KEY, 0x71, {KEY_STOPCD} },
286 { KE_KEY, 0x72, {KEY_PLAYPAUSE} },
287 { KE_KEY, 0x74, {KEY_REWIND} },
288 { KE_KEY, 0x78, {KEY_FORWARD} },
John Reed Rileye2aa5072006-04-05 00:40:01 -0400289 { KE_END, 0 }
290};
291
Eric Piel55d29c92007-04-12 01:32:49 -0400292static struct key_entry keymap_wistron_ms2111[] __initdata = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400293 { KE_KEY, 0x11, {KEY_PROG1} },
294 { KE_KEY, 0x12, {KEY_PROG2} },
295 { KE_KEY, 0x13, {KEY_PROG3} },
296 { KE_KEY, 0x31, {KEY_MAIL} },
297 { KE_KEY, 0x36, {KEY_WWW} },
298 { KE_END, FE_MAIL_LED }
299};
300
Eric Piel55d29c92007-04-12 01:32:49 -0400301static struct key_entry keymap_wistron_md40100[] __initdata = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400302 { KE_KEY, 0x01, {KEY_HELP} },
303 { KE_KEY, 0x02, {KEY_CONFIG} },
304 { KE_KEY, 0x31, {KEY_MAIL} },
305 { KE_KEY, 0x36, {KEY_WWW} },
306 { KE_KEY, 0x37, {KEY_DISPLAYTOGGLE} }, /* Display on/off */
307 { KE_END, FE_MAIL_LED | FE_WIFI_LED | FE_UNTESTED }
Frank de Lange90001952006-06-27 01:48:24 -0400308};
309
Eric Piel55d29c92007-04-12 01:32:49 -0400310static struct key_entry keymap_wistron_ms2141[] __initdata = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400311 { KE_KEY, 0x11, {KEY_PROG1} },
312 { KE_KEY, 0x12, {KEY_PROG2} },
313 { KE_WIFI, 0x30 },
314 { KE_KEY, 0x22, {KEY_REWIND} },
315 { KE_KEY, 0x23, {KEY_FORWARD} },
316 { KE_KEY, 0x24, {KEY_PLAYPAUSE} },
317 { KE_KEY, 0x25, {KEY_STOPCD} },
318 { KE_KEY, 0x31, {KEY_MAIL} },
319 { KE_KEY, 0x36, {KEY_WWW} },
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500320 { KE_END, 0 }
321};
322
Eric Piel55d29c92007-04-12 01:32:49 -0400323static struct key_entry keymap_acer_aspire_1500[] __initdata = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400324 { KE_KEY, 0x01, {KEY_HELP} },
325 { KE_KEY, 0x03, {KEY_POWER} },
326 { KE_KEY, 0x11, {KEY_PROG1} },
327 { KE_KEY, 0x12, {KEY_PROG2} },
328 { KE_WIFI, 0x30 },
329 { KE_KEY, 0x31, {KEY_MAIL} },
330 { KE_KEY, 0x36, {KEY_WWW} },
331 { KE_KEY, 0x49, {KEY_CONFIG} },
332 { KE_BLUETOOTH, 0x44 },
333 { KE_END, FE_UNTESTED }
334};
335
Eric Piel55d29c92007-04-12 01:32:49 -0400336static struct key_entry keymap_acer_aspire_1600[] __initdata = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400337 { KE_KEY, 0x01, {KEY_HELP} },
338 { KE_KEY, 0x03, {KEY_POWER} },
339 { KE_KEY, 0x08, {KEY_MUTE} },
340 { KE_KEY, 0x11, {KEY_PROG1} },
341 { KE_KEY, 0x12, {KEY_PROG2} },
342 { KE_KEY, 0x13, {KEY_PROG3} },
343 { KE_KEY, 0x31, {KEY_MAIL} },
344 { KE_KEY, 0x36, {KEY_WWW} },
345 { KE_KEY, 0x49, {KEY_CONFIG} },
346 { KE_WIFI, 0x30 },
347 { KE_BLUETOOTH, 0x44 },
348 { KE_END, FE_MAIL_LED | FE_UNTESTED }
349};
350
351/* 3020 has been tested */
Eric Piel55d29c92007-04-12 01:32:49 -0400352static struct key_entry keymap_acer_aspire_5020[] __initdata = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400353 { KE_KEY, 0x01, {KEY_HELP} },
354 { KE_KEY, 0x03, {KEY_POWER} },
355 { KE_KEY, 0x05, {KEY_SWITCHVIDEOMODE} }, /* Display selection */
356 { KE_KEY, 0x11, {KEY_PROG1} },
357 { KE_KEY, 0x12, {KEY_PROG2} },
358 { KE_KEY, 0x31, {KEY_MAIL} },
359 { KE_KEY, 0x36, {KEY_WWW} },
360 { KE_KEY, 0x6a, {KEY_CONFIG} },
361 { KE_WIFI, 0x30 },
362 { KE_BLUETOOTH, 0x44 },
363 { KE_END, FE_MAIL_LED | FE_UNTESTED }
364};
365
Eric Piel55d29c92007-04-12 01:32:49 -0400366static struct key_entry keymap_acer_travelmate_2410[] __initdata = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400367 { KE_KEY, 0x01, {KEY_HELP} },
368 { KE_KEY, 0x6d, {KEY_POWER} },
369 { KE_KEY, 0x11, {KEY_PROG1} },
370 { KE_KEY, 0x12, {KEY_PROG2} },
371 { KE_KEY, 0x31, {KEY_MAIL} },
372 { KE_KEY, 0x36, {KEY_WWW} },
373 { KE_KEY, 0x6a, {KEY_CONFIG} },
374 { KE_WIFI, 0x30 },
375 { KE_BLUETOOTH, 0x44 },
376 { KE_END, FE_MAIL_LED | FE_UNTESTED }
377};
378
Eric Piel55d29c92007-04-12 01:32:49 -0400379static struct key_entry keymap_acer_travelmate_110[] __initdata = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400380 { KE_KEY, 0x01, {KEY_HELP} },
381 { KE_KEY, 0x02, {KEY_CONFIG} },
382 { KE_KEY, 0x03, {KEY_POWER} },
383 { KE_KEY, 0x08, {KEY_MUTE} },
384 { KE_KEY, 0x11, {KEY_PROG1} },
385 { KE_KEY, 0x12, {KEY_PROG2} },
386 { KE_KEY, 0x20, {KEY_VOLUMEUP} },
387 { KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
388 { KE_KEY, 0x31, {KEY_MAIL} },
389 { KE_KEY, 0x36, {KEY_WWW} },
390 { KE_SW, 0x4a, {.sw = {SW_LID, 1}} }, /* lid close */
391 { KE_SW, 0x4b, {.sw = {SW_LID, 0}} }, /* lid open */
392 { KE_WIFI, 0x30 },
393 { KE_END, FE_MAIL_LED | FE_UNTESTED }
394};
395
Eric Piel55d29c92007-04-12 01:32:49 -0400396static struct key_entry keymap_acer_travelmate_300[] __initdata = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400397 { KE_KEY, 0x01, {KEY_HELP} },
398 { KE_KEY, 0x02, {KEY_CONFIG} },
399 { KE_KEY, 0x03, {KEY_POWER} },
400 { KE_KEY, 0x08, {KEY_MUTE} },
401 { KE_KEY, 0x11, {KEY_PROG1} },
402 { KE_KEY, 0x12, {KEY_PROG2} },
403 { KE_KEY, 0x20, {KEY_VOLUMEUP} },
404 { KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
405 { KE_KEY, 0x31, {KEY_MAIL} },
406 { KE_KEY, 0x36, {KEY_WWW} },
407 { KE_WIFI, 0x30 },
408 { KE_BLUETOOTH, 0x44 },
409 { KE_END, FE_MAIL_LED | FE_UNTESTED }
410};
411
Eric Piel55d29c92007-04-12 01:32:49 -0400412static struct key_entry keymap_acer_travelmate_380[] __initdata = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400413 { KE_KEY, 0x01, {KEY_HELP} },
414 { KE_KEY, 0x02, {KEY_CONFIG} },
415 { KE_KEY, 0x03, {KEY_POWER} }, /* not 370 */
416 { KE_KEY, 0x11, {KEY_PROG1} },
417 { KE_KEY, 0x12, {KEY_PROG2} },
418 { KE_KEY, 0x13, {KEY_PROG3} },
419 { KE_KEY, 0x31, {KEY_MAIL} },
420 { KE_KEY, 0x36, {KEY_WWW} },
421 { KE_WIFI, 0x30 },
422 { KE_END, FE_MAIL_LED | FE_UNTESTED }
423};
424
425/* unusual map */
Eric Piel55d29c92007-04-12 01:32:49 -0400426static struct key_entry keymap_acer_travelmate_220[] __initdata = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400427 { KE_KEY, 0x01, {KEY_HELP} },
428 { KE_KEY, 0x02, {KEY_CONFIG} },
429 { KE_KEY, 0x11, {KEY_MAIL} },
430 { KE_KEY, 0x12, {KEY_WWW} },
431 { KE_KEY, 0x13, {KEY_PROG2} },
432 { KE_KEY, 0x31, {KEY_PROG1} },
433 { KE_END, FE_WIFI_LED | FE_UNTESTED }
434};
435
Eric Piel55d29c92007-04-12 01:32:49 -0400436static struct key_entry keymap_acer_travelmate_230[] __initdata = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400437 { KE_KEY, 0x01, {KEY_HELP} },
438 { KE_KEY, 0x02, {KEY_CONFIG} },
439 { KE_KEY, 0x11, {KEY_PROG1} },
440 { KE_KEY, 0x12, {KEY_PROG2} },
441 { KE_KEY, 0x31, {KEY_MAIL} },
442 { KE_KEY, 0x36, {KEY_WWW} },
443 { KE_END, FE_WIFI_LED | FE_UNTESTED }
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -0500444};
445
Eric Piel55d29c92007-04-12 01:32:49 -0400446static struct key_entry keymap_acer_travelmate_240[] __initdata = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400447 { KE_KEY, 0x01, {KEY_HELP} },
448 { KE_KEY, 0x02, {KEY_CONFIG} },
449 { KE_KEY, 0x03, {KEY_POWER} },
450 { KE_KEY, 0x08, {KEY_MUTE} },
451 { KE_KEY, 0x31, {KEY_MAIL} },
452 { KE_KEY, 0x36, {KEY_WWW} },
453 { KE_KEY, 0x11, {KEY_PROG1} },
454 { KE_KEY, 0x12, {KEY_PROG2} },
455 { KE_BLUETOOTH, 0x44 },
456 { KE_WIFI, 0x30 },
457 { KE_END, FE_UNTESTED }
458};
459
Eric Piel55d29c92007-04-12 01:32:49 -0400460static struct key_entry keymap_acer_travelmate_350[] __initdata = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400461 { KE_KEY, 0x01, {KEY_HELP} },
462 { KE_KEY, 0x02, {KEY_CONFIG} },
463 { KE_KEY, 0x11, {KEY_PROG1} },
464 { KE_KEY, 0x12, {KEY_PROG2} },
465 { KE_KEY, 0x13, {KEY_MAIL} },
466 { KE_KEY, 0x14, {KEY_PROG3} },
467 { KE_KEY, 0x15, {KEY_WWW} },
468 { KE_END, FE_MAIL_LED | FE_WIFI_LED | FE_UNTESTED }
469};
470
Eric Piel55d29c92007-04-12 01:32:49 -0400471static struct key_entry keymap_acer_travelmate_360[] __initdata = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400472 { KE_KEY, 0x01, {KEY_HELP} },
473 { KE_KEY, 0x02, {KEY_CONFIG} },
474 { KE_KEY, 0x11, {KEY_PROG1} },
475 { KE_KEY, 0x12, {KEY_PROG2} },
476 { KE_KEY, 0x13, {KEY_MAIL} },
477 { KE_KEY, 0x14, {KEY_PROG3} },
478 { KE_KEY, 0x15, {KEY_WWW} },
479 { KE_KEY, 0x40, {KEY_WLAN} },
480 { KE_END, FE_WIFI_LED | FE_UNTESTED } /* no mail led */
Ashutosh Naik74a89c92005-12-11 12:41:32 -0500481};
482
Eric Pielbc413c92007-03-07 01:45:16 -0500483/* Wifi subsystem only activates the led. Therefore we need to pass
484 * wifi event as a normal key, then userspace can really change the wifi state.
485 * TODO we need to export led state to userspace (wifi and mail) */
Eric Piel55d29c92007-04-12 01:32:49 -0400486static struct key_entry keymap_acer_travelmate_610[] __initdata = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400487 { KE_KEY, 0x01, {KEY_HELP} },
488 { KE_KEY, 0x02, {KEY_CONFIG} },
489 { KE_KEY, 0x11, {KEY_PROG1} },
Eric Pielfd013ce2007-04-29 23:41:53 -0400490 { KE_KEY, 0x12, {KEY_PROG2} },
Eric Piel6480e2a2007-04-12 01:32:34 -0400491 { KE_KEY, 0x13, {KEY_PROG3} },
492 { KE_KEY, 0x14, {KEY_MAIL} },
493 { KE_KEY, 0x15, {KEY_WWW} },
494 { KE_KEY, 0x40, {KEY_WLAN} },
495 { KE_END, FE_MAIL_LED | FE_WIFI_LED }
496};
497
Eric Piel55d29c92007-04-12 01:32:49 -0400498static struct key_entry keymap_acer_travelmate_630[] __initdata = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400499 { KE_KEY, 0x01, {KEY_HELP} },
500 { KE_KEY, 0x02, {KEY_CONFIG} },
501 { KE_KEY, 0x03, {KEY_POWER} },
502 { KE_KEY, 0x08, {KEY_MUTE} }, /* not 620 */
503 { KE_KEY, 0x11, {KEY_PROG1} },
504 { KE_KEY, 0x12, {KEY_PROG2} },
505 { KE_KEY, 0x13, {KEY_PROG3} },
506 { KE_KEY, 0x20, {KEY_VOLUMEUP} },
507 { KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
508 { KE_KEY, 0x31, {KEY_MAIL} },
509 { KE_KEY, 0x36, {KEY_WWW} },
510 { KE_WIFI, 0x30 },
511 { KE_END, FE_MAIL_LED | FE_UNTESTED }
Eric Pielbc413c92007-03-07 01:45:16 -0500512};
513
Eric Piel55d29c92007-04-12 01:32:49 -0400514static struct key_entry keymap_aopen_1559as[] __initdata = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400515 { KE_KEY, 0x01, {KEY_HELP} },
516 { KE_KEY, 0x06, {KEY_PROG3} },
517 { KE_KEY, 0x11, {KEY_PROG1} },
518 { KE_KEY, 0x12, {KEY_PROG2} },
519 { KE_WIFI, 0x30 },
520 { KE_KEY, 0x31, {KEY_MAIL} },
521 { KE_KEY, 0x36, {KEY_WWW} },
Frank de Lange90001952006-06-27 01:48:24 -0400522 { KE_END, 0 },
masc@theaterzentrum.ate107b8e2006-05-29 23:29:36 -0400523};
524
Eric Piel55d29c92007-04-12 01:32:49 -0400525static struct key_entry keymap_fs_amilo_d88x0[] __initdata = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400526 { KE_KEY, 0x01, {KEY_HELP} },
527 { KE_KEY, 0x08, {KEY_MUTE} },
528 { KE_KEY, 0x31, {KEY_MAIL} },
529 { KE_KEY, 0x36, {KEY_WWW} },
530 { KE_KEY, 0x11, {KEY_PROG1} },
531 { KE_KEY, 0x12, {KEY_PROG2} },
532 { KE_KEY, 0x13, {KEY_PROG3} },
533 { KE_END, FE_MAIL_LED | FE_WIFI_LED | FE_UNTESTED }
534};
535
Eric Piel55d29c92007-04-12 01:32:49 -0400536static struct key_entry keymap_wistron_md2900[] __initdata = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400537 { KE_KEY, 0x01, {KEY_HELP} },
538 { KE_KEY, 0x02, {KEY_CONFIG} },
539 { KE_KEY, 0x11, {KEY_PROG1} },
540 { KE_KEY, 0x12, {KEY_PROG2} },
541 { KE_KEY, 0x31, {KEY_MAIL} },
542 { KE_KEY, 0x36, {KEY_WWW} },
543 { KE_WIFI, 0x30 },
544 { KE_END, FE_MAIL_LED | FE_UNTESTED }
545};
546
Eric Piel55d29c92007-04-12 01:32:49 -0400547static struct key_entry keymap_wistron_md96500[] __initdata = {
Eric Piel6480e2a2007-04-12 01:32:34 -0400548 { KE_KEY, 0x01, {KEY_HELP} },
549 { KE_KEY, 0x02, {KEY_CONFIG} },
550 { KE_KEY, 0x05, {KEY_SWITCHVIDEOMODE} }, /* Display selection */
551 { KE_KEY, 0x06, {KEY_DISPLAYTOGGLE} }, /* Display on/off */
552 { KE_KEY, 0x08, {KEY_MUTE} },
553 { KE_KEY, 0x11, {KEY_PROG1} },
554 { KE_KEY, 0x12, {KEY_PROG2} },
555 { KE_KEY, 0x20, {KEY_VOLUMEUP} },
556 { KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
557 { KE_KEY, 0x22, {KEY_REWIND} },
558 { KE_KEY, 0x23, {KEY_FORWARD} },
559 { KE_KEY, 0x24, {KEY_PLAYPAUSE} },
560 { KE_KEY, 0x25, {KEY_STOPCD} },
561 { KE_KEY, 0x31, {KEY_MAIL} },
562 { KE_KEY, 0x36, {KEY_WWW} },
563 { KE_WIFI, 0x30 },
564 { KE_BLUETOOTH, 0x44 },
Stefan Lippers-Hollmann53e88752013-08-12 22:45:38 -0700565 { KE_END, 0 }
Michael Leun5809d532007-02-10 01:29:42 -0500566};
567
Eric Piel55d29c92007-04-12 01:32:49 -0400568static struct key_entry keymap_wistron_generic[] __initdata = {
Eric Piel7b0a4cd2007-04-12 01:32:41 -0400569 { KE_KEY, 0x01, {KEY_HELP} },
570 { KE_KEY, 0x02, {KEY_CONFIG} },
571 { KE_KEY, 0x03, {KEY_POWER} },
572 { KE_KEY, 0x05, {KEY_SWITCHVIDEOMODE} }, /* Display selection */
573 { KE_KEY, 0x06, {KEY_DISPLAYTOGGLE} }, /* Display on/off */
574 { KE_KEY, 0x08, {KEY_MUTE} },
575 { KE_KEY, 0x11, {KEY_PROG1} },
576 { KE_KEY, 0x12, {KEY_PROG2} },
577 { KE_KEY, 0x13, {KEY_PROG3} },
578 { KE_KEY, 0x14, {KEY_MAIL} },
579 { KE_KEY, 0x15, {KEY_WWW} },
580 { KE_KEY, 0x20, {KEY_VOLUMEUP} },
581 { KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
582 { KE_KEY, 0x22, {KEY_REWIND} },
583 { KE_KEY, 0x23, {KEY_FORWARD} },
584 { KE_KEY, 0x24, {KEY_PLAYPAUSE} },
585 { KE_KEY, 0x25, {KEY_STOPCD} },
586 { KE_KEY, 0x31, {KEY_MAIL} },
587 { KE_KEY, 0x36, {KEY_WWW} },
588 { KE_KEY, 0x37, {KEY_DISPLAYTOGGLE} }, /* Display on/off */
589 { KE_KEY, 0x40, {KEY_WLAN} },
590 { KE_KEY, 0x49, {KEY_CONFIG} },
591 { KE_SW, 0x4a, {.sw = {SW_LID, 1}} }, /* lid close */
592 { KE_SW, 0x4b, {.sw = {SW_LID, 0}} }, /* lid open */
593 { KE_KEY, 0x6a, {KEY_CONFIG} },
594 { KE_KEY, 0x6d, {KEY_POWER} },
595 { KE_KEY, 0x71, {KEY_STOPCD} },
596 { KE_KEY, 0x72, {KEY_PLAYPAUSE} },
597 { KE_KEY, 0x74, {KEY_REWIND} },
598 { KE_KEY, 0x78, {KEY_FORWARD} },
599 { KE_WIFI, 0x30 },
600 { KE_BLUETOOTH, 0x44 },
601 { KE_END, 0 }
602};
603
Dmitry Torokhov85927b02009-09-09 19:17:24 -0700604static struct key_entry keymap_aopen_1557[] __initdata = {
605 { KE_KEY, 0x01, {KEY_HELP} },
606 { KE_KEY, 0x11, {KEY_PROG1} },
607 { KE_KEY, 0x12, {KEY_PROG2} },
608 { KE_WIFI, 0x30 },
609 { KE_KEY, 0x22, {KEY_REWIND} },
610 { KE_KEY, 0x23, {KEY_FORWARD} },
611 { KE_KEY, 0x24, {KEY_PLAYPAUSE} },
612 { KE_KEY, 0x25, {KEY_STOPCD} },
613 { KE_KEY, 0x31, {KEY_MAIL} },
614 { KE_KEY, 0x36, {KEY_WWW} },
615 { KE_END, 0 }
616};
617
TJ194934782009-08-03 13:39:09 -0700618static struct key_entry keymap_prestigio[] __initdata = {
619 { KE_KEY, 0x11, {KEY_PROG1} },
620 { KE_KEY, 0x12, {KEY_PROG2} },
Dmitry Torokhov85927b02009-09-09 19:17:24 -0700621 { KE_WIFI, 0x30 },
TJ194934782009-08-03 13:39:09 -0700622 { KE_KEY, 0x22, {KEY_REWIND} },
623 { KE_KEY, 0x23, {KEY_FORWARD} },
624 { KE_KEY, 0x24, {KEY_PLAYPAUSE} },
625 { KE_KEY, 0x25, {KEY_STOPCD} },
626 { KE_KEY, 0x31, {KEY_MAIL} },
627 { KE_KEY, 0x36, {KEY_WWW} },
628 { KE_END, 0 }
629};
630
631
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500632/*
633 * If your machine is not here (which is currently rather likely), please send
634 * a list of buttons and their key codes (reported when loading this module
635 * with force=1) and the output of dmidecode to $MODULE_AUTHOR.
636 */
Sachin Kamat98f6e5d2013-08-12 11:05:18 -0700637static const struct dmi_system_id dmi_ids[] __initconst = {
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500638 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800639 /* Fujitsu-Siemens Amilo Pro V2000 */
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500640 .callback = dmi_matched,
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500641 .matches = {
642 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
643 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pro V2000"),
644 },
645 .driver_data = keymap_fs_amilo_pro_v2000
646 },
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -0500647 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800648 /* Fujitsu-Siemens Amilo Pro Edition V3505 */
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -0500649 .callback = dmi_matched,
Remi Herilier34a7c482008-08-08 12:13:13 -0400650 .matches = {
651 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
652 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pro Edition V3505"),
653 },
654 .driver_data = keymap_fs_amilo_pro_v3505
655 },
656 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800657 /* Fujitsu-Siemens Amilo M7400 */
Remi Herilier34a7c482008-08-08 12:13:13 -0400658 .callback = dmi_matched,
Stefan Rompf8a1b1702006-04-05 00:39:20 -0400659 .matches = {
660 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
661 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO M "),
662 },
663 .driver_data = keymap_fs_amilo_pro_v2000
664 },
665 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800666 /* Maxdata Pro 7000 DX */
Stefan Rompf8a1b1702006-04-05 00:39:20 -0400667 .callback = dmi_matched,
Giuseppe Mazzottae705cee42009-07-12 21:02:27 -0700668 .matches = {
669 DMI_MATCH(DMI_SYS_VENDOR, "MAXDATA"),
670 DMI_MATCH(DMI_PRODUCT_NAME, "Pro 7000"),
671 },
672 .driver_data = keymap_fs_amilo_pro_v2000
673 },
674 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800675 /* Fujitsu N3510 */
Giuseppe Mazzottae705cee42009-07-12 21:02:27 -0700676 .callback = dmi_matched,
John Reed Rileye2aa5072006-04-05 00:40:01 -0400677 .matches = {
678 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
679 DMI_MATCH(DMI_PRODUCT_NAME, "N3510"),
680 },
681 .driver_data = keymap_fujitsu_n3510
682 },
683 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800684 /* Acer Aspire 1500 */
John Reed Rileye2aa5072006-04-05 00:40:01 -0400685 .callback = dmi_matched,
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -0500686 .matches = {
687 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
688 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1500"),
689 },
690 .driver_data = keymap_acer_aspire_1500
691 },
Ashutosh Naik74a89c92005-12-11 12:41:32 -0500692 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800693 /* Acer Aspire 1600 */
Ashutosh Naik74a89c92005-12-11 12:41:32 -0500694 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400695 .matches = {
696 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
697 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1600"),
698 },
699 .driver_data = keymap_acer_aspire_1600
700 },
701 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800702 /* Acer Aspire 3020 */
Eric Piel6480e2a2007-04-12 01:32:34 -0400703 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400704 .matches = {
705 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
706 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3020"),
707 },
708 .driver_data = keymap_acer_aspire_5020
709 },
710 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800711 /* Acer Aspire 5020 */
Eric Piel6480e2a2007-04-12 01:32:34 -0400712 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400713 .matches = {
714 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
715 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5020"),
716 },
717 .driver_data = keymap_acer_aspire_5020
718 },
719 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800720 /* Acer TravelMate 2100 */
Eric Piel6480e2a2007-04-12 01:32:34 -0400721 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400722 .matches = {
723 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
724 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2100"),
725 },
726 .driver_data = keymap_acer_aspire_5020
727 },
728 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800729 /* Acer TravelMate 2410 */
Eric Piel6480e2a2007-04-12 01:32:34 -0400730 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400731 .matches = {
732 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
733 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2410"),
734 },
735 .driver_data = keymap_acer_travelmate_2410
736 },
737 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800738 /* Acer TravelMate C300 */
Eric Piel6480e2a2007-04-12 01:32:34 -0400739 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400740 .matches = {
741 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
742 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate C300"),
743 },
744 .driver_data = keymap_acer_travelmate_300
745 },
746 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800747 /* Acer TravelMate C100 */
Eric Piel6480e2a2007-04-12 01:32:34 -0400748 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400749 .matches = {
750 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
751 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate C100"),
752 },
753 .driver_data = keymap_acer_travelmate_300
754 },
755 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800756 /* Acer TravelMate C110 */
Eric Piel6480e2a2007-04-12 01:32:34 -0400757 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400758 .matches = {
759 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
760 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate C110"),
761 },
762 .driver_data = keymap_acer_travelmate_110
763 },
764 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800765 /* Acer TravelMate 380 */
Eric Piel6480e2a2007-04-12 01:32:34 -0400766 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400767 .matches = {
768 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
769 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 380"),
770 },
771 .driver_data = keymap_acer_travelmate_380
772 },
773 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800774 /* Acer TravelMate 370 */
Eric Piel6480e2a2007-04-12 01:32:34 -0400775 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400776 .matches = {
777 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
778 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 370"),
779 },
780 .driver_data = keymap_acer_travelmate_380 /* keyboard minus 1 key */
781 },
782 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800783 /* Acer TravelMate 220 */
Eric Piel6480e2a2007-04-12 01:32:34 -0400784 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400785 .matches = {
786 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
787 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 220"),
788 },
789 .driver_data = keymap_acer_travelmate_220
790 },
791 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800792 /* Acer TravelMate 260 */
Eric Piel6480e2a2007-04-12 01:32:34 -0400793 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400794 .matches = {
795 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
796 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 260"),
797 },
798 .driver_data = keymap_acer_travelmate_220
799 },
800 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800801 /* Acer TravelMate 230 */
Eric Piel6480e2a2007-04-12 01:32:34 -0400802 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400803 .matches = {
804 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
805 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 230"),
806 /* acerhk looks for "TravelMate F4..." ?! */
807 },
808 .driver_data = keymap_acer_travelmate_230
809 },
810 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800811 /* Acer TravelMate 280 */
Eric Piel6480e2a2007-04-12 01:32:34 -0400812 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400813 .matches = {
814 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
815 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 280"),
816 },
817 .driver_data = keymap_acer_travelmate_230
818 },
819 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800820 /* Acer TravelMate 240 */
Eric Piel6480e2a2007-04-12 01:32:34 -0400821 .callback = dmi_matched,
Ashutosh Naik74a89c92005-12-11 12:41:32 -0500822 .matches = {
823 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
824 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 240"),
825 },
826 .driver_data = keymap_acer_travelmate_240
827 },
Ashutosh Naikbb088592006-10-01 22:07:14 -0400828 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800829 /* Acer TravelMate 250 */
Ashutosh Naikbb088592006-10-01 22:07:14 -0400830 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400831 .matches = {
832 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
833 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 250"),
834 },
835 .driver_data = keymap_acer_travelmate_240
836 },
837 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800838 /* Acer TravelMate 2424NWXCi */
Eric Piel6480e2a2007-04-12 01:32:34 -0400839 .callback = dmi_matched,
Ashutosh Naikbb088592006-10-01 22:07:14 -0400840 .matches = {
841 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
842 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2420"),
843 },
844 .driver_data = keymap_acer_travelmate_240
845 },
846 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800847 /* Acer TravelMate 350 */
masc@theaterzentrum.ate107b8e2006-05-29 23:29:36 -0400848 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400849 .matches = {
850 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
851 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 350"),
852 },
853 .driver_data = keymap_acer_travelmate_350
854 },
855 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800856 /* Acer TravelMate 360 */
Eric Piel6480e2a2007-04-12 01:32:34 -0400857 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400858 .matches = {
859 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
860 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
861 },
862 .driver_data = keymap_acer_travelmate_360
863 },
864 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800865 /* Acer TravelMate 610 */
Eric Piel6480e2a2007-04-12 01:32:34 -0400866 .callback = dmi_matched,
Eric Pielbc413c92007-03-07 01:45:16 -0500867 .matches = {
868 DMI_MATCH(DMI_SYS_VENDOR, "ACER"),
869 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 610"),
870 },
871 .driver_data = keymap_acer_travelmate_610
872 },
873 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800874 /* Acer TravelMate 620 */
Eric Pielbc413c92007-03-07 01:45:16 -0500875 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400876 .matches = {
877 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
878 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 620"),
879 },
880 .driver_data = keymap_acer_travelmate_630
881 },
882 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800883 /* Acer TravelMate 630 */
Eric Piel6480e2a2007-04-12 01:32:34 -0400884 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400885 .matches = {
886 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
887 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 630"),
888 },
889 .driver_data = keymap_acer_travelmate_630
890 },
891 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800892 /* AOpen 1559AS */
Eric Piel6480e2a2007-04-12 01:32:34 -0400893 .callback = dmi_matched,
masc@theaterzentrum.ate107b8e2006-05-29 23:29:36 -0400894 .matches = {
895 DMI_MATCH(DMI_PRODUCT_NAME, "E2U"),
896 DMI_MATCH(DMI_BOARD_NAME, "E2U"),
897 },
898 .driver_data = keymap_aopen_1559as
899 },
Frank de Lange90001952006-06-27 01:48:24 -0400900 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800901 /* Medion MD 9783 */
Frank de Lange90001952006-06-27 01:48:24 -0400902 .callback = dmi_matched,
Frank de Lange90001952006-06-27 01:48:24 -0400903 .matches = {
904 DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
905 DMI_MATCH(DMI_PRODUCT_NAME, "MD 9783"),
906 },
907 .driver_data = keymap_wistron_ms2111
908 },
Michael Leun5809d532007-02-10 01:29:42 -0500909 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800910 /* Medion MD 40100 */
Michael Leun5809d532007-02-10 01:29:42 -0500911 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400912 .matches = {
913 DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
914 DMI_MATCH(DMI_PRODUCT_NAME, "WID2000"),
915 },
916 .driver_data = keymap_wistron_md40100
917 },
918 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800919 /* Medion MD 2900 */
Eric Piel6480e2a2007-04-12 01:32:34 -0400920 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400921 .matches = {
922 DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
923 DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2000"),
924 },
925 .driver_data = keymap_wistron_md2900
926 },
927 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800928 /* Medion MD 42200 */
Eric Piel6480e2a2007-04-12 01:32:34 -0400929 .callback = dmi_matched,
Sebastian Frei3bfb0a72009-10-05 21:43:39 -0700930 .matches = {
931 DMI_MATCH(DMI_SYS_VENDOR, "Medion"),
932 DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2030"),
933 },
934 .driver_data = keymap_fs_amilo_pro_v2000
935 },
936 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800937 /* Medion MD 96500 */
Sebastian Frei3bfb0a72009-10-05 21:43:39 -0700938 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400939 .matches = {
940 DMI_MATCH(DMI_SYS_VENDOR, "MEDIONPC"),
941 DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2040"),
942 },
943 .driver_data = keymap_wistron_md96500
944 },
945 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800946 /* Medion MD 95400 */
Eric Piel6480e2a2007-04-12 01:32:34 -0400947 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400948 .matches = {
949 DMI_MATCH(DMI_SYS_VENDOR, "MEDIONPC"),
950 DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2050"),
951 },
952 .driver_data = keymap_wistron_md96500
953 },
954 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800955 /* Fujitsu Siemens Amilo D7820 */
Eric Piel6480e2a2007-04-12 01:32:34 -0400956 .callback = dmi_matched,
Eric Piel6480e2a2007-04-12 01:32:34 -0400957 .matches = {
958 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"), /* not sure */
959 DMI_MATCH(DMI_PRODUCT_NAME, "Amilo D"),
960 },
961 .driver_data = keymap_fs_amilo_d88x0
962 },
963 {
Dmitry Torokhova9b0d0e2009-12-04 10:24:19 -0800964 /* Fujitsu Siemens Amilo D88x0 */
Eric Piel6480e2a2007-04-12 01:32:34 -0400965 .callback = dmi_matched,
Michael Leun5809d532007-02-10 01:29:42 -0500966 .matches = {
967 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
968 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO D"),
969 },
970 .driver_data = keymap_fs_amilo_d88x0
971 },
Al Viro81f0a912005-12-15 09:19:05 +0000972 { NULL, }
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500973};
Stefan Lippers-Hollmannac67be92013-08-12 22:45:58 -0700974MODULE_DEVICE_TABLE(dmi, dmi_ids);
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500975
Eric Piel55d29c92007-04-12 01:32:49 -0400976/* Copy the good keymap, as the original ones are free'd */
977static int __init copy_keymap(void)
978{
979 const struct key_entry *key;
980 struct key_entry *new_keymap;
981 unsigned int length = 1;
982
983 for (key = keymap; key->type != KE_END; key++)
984 length++;
985
Julia Lawallf8300ab2010-05-19 10:11:14 -0700986 new_keymap = kmemdup(keymap, length * sizeof(struct key_entry),
987 GFP_KERNEL);
Eric Piel55d29c92007-04-12 01:32:49 -0400988 if (!new_keymap)
989 return -ENOMEM;
990
Eric Piel55d29c92007-04-12 01:32:49 -0400991 keymap = new_keymap;
992
993 return 0;
994}
995
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500996static int __init select_keymap(void)
997{
Eric Piel7b0a4cd2007-04-12 01:32:41 -0400998 dmi_check_system(dmi_ids);
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500999 if (keymap_name != NULL) {
1000 if (strcmp (keymap_name, "1557/MS2141") == 0)
1001 keymap = keymap_wistron_ms2141;
Dmitry Torokhov85927b02009-09-09 19:17:24 -07001002 else if (strcmp (keymap_name, "aopen1557") == 0)
1003 keymap = keymap_aopen_1557;
TJ194934782009-08-03 13:39:09 -07001004 else if (strcmp (keymap_name, "prestigio") == 0)
1005 keymap = keymap_prestigio;
Eric Piel7b0a4cd2007-04-12 01:32:41 -04001006 else if (strcmp (keymap_name, "generic") == 0)
1007 keymap = keymap_wistron_generic;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001008 else {
1009 printk(KERN_ERR "wistron_btns: Keymap unknown\n");
1010 return -EINVAL;
1011 }
1012 }
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001013 if (keymap == NULL) {
1014 if (!force) {
1015 printk(KERN_ERR "wistron_btns: System unknown\n");
1016 return -ENODEV;
1017 }
1018 keymap = keymap_empty;
1019 }
Eric Piel55d29c92007-04-12 01:32:49 -04001020
1021 return copy_keymap();
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001022}
1023
1024 /* Input layer interface */
1025
Dmitry Torokhovc2554c92007-05-22 23:48:39 -04001026static struct input_polled_dev *wistron_idev;
1027static unsigned long jiffies_last_press;
Dmitry Torokhov67dbe832009-08-07 23:17:39 -07001028static bool wifi_enabled;
1029static bool bluetooth_enabled;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001030
Eric Piel389679d2007-05-21 00:46:31 -04001031 /* led management */
1032static void wistron_mail_led_set(struct led_classdev *led_cdev,
1033 enum led_brightness value)
1034{
1035 bios_set_state(MAIL_LED, (value != LED_OFF) ? 1 : 0);
1036}
1037
1038/* same as setting up wifi card, but for laptops on which the led is managed */
1039static void wistron_wifi_led_set(struct led_classdev *led_cdev,
1040 enum led_brightness value)
1041{
1042 bios_set_state(WIFI, (value != LED_OFF) ? 1 : 0);
1043}
1044
1045static struct led_classdev wistron_mail_led = {
Richard Purdie6c152be2007-10-31 15:00:07 +01001046 .name = "wistron:green:mail",
Eric Piel389679d2007-05-21 00:46:31 -04001047 .brightness_set = wistron_mail_led_set,
1048};
1049
1050static struct led_classdev wistron_wifi_led = {
Richard Purdie6c152be2007-10-31 15:00:07 +01001051 .name = "wistron:red:wifi",
Eric Piel389679d2007-05-21 00:46:31 -04001052 .brightness_set = wistron_wifi_led_set,
1053};
1054
Bill Pemberton5298cc42012-11-23 21:38:25 -08001055static void wistron_led_init(struct device *parent)
Eric Piel389679d2007-05-21 00:46:31 -04001056{
Dmitry Torokhov67dbe832009-08-07 23:17:39 -07001057 if (leds_present & FE_WIFI_LED) {
Eric Piel389679d2007-05-21 00:46:31 -04001058 u16 wifi = bios_get_default_setting(WIFI);
1059 if (wifi & 1) {
1060 wistron_wifi_led.brightness = (wifi & 2) ? LED_FULL : LED_OFF;
1061 if (led_classdev_register(parent, &wistron_wifi_led))
Dmitry Torokhov67dbe832009-08-07 23:17:39 -07001062 leds_present &= ~FE_WIFI_LED;
Eric Piel389679d2007-05-21 00:46:31 -04001063 else
1064 bios_set_state(WIFI, wistron_wifi_led.brightness);
1065
1066 } else
Dmitry Torokhov67dbe832009-08-07 23:17:39 -07001067 leds_present &= ~FE_WIFI_LED;
Eric Piel389679d2007-05-21 00:46:31 -04001068 }
1069
Dmitry Torokhov67dbe832009-08-07 23:17:39 -07001070 if (leds_present & FE_MAIL_LED) {
Eric Piel389679d2007-05-21 00:46:31 -04001071 /* bios_get_default_setting(MAIL) always retuns 0, so just turn the led off */
1072 wistron_mail_led.brightness = LED_OFF;
1073 if (led_classdev_register(parent, &wistron_mail_led))
Dmitry Torokhov67dbe832009-08-07 23:17:39 -07001074 leds_present &= ~FE_MAIL_LED;
Eric Piel389679d2007-05-21 00:46:31 -04001075 else
1076 bios_set_state(MAIL_LED, wistron_mail_led.brightness);
1077 }
1078}
1079
Bill Pembertone2619cf2012-11-23 21:50:47 -08001080static void wistron_led_remove(void)
Eric Piel389679d2007-05-21 00:46:31 -04001081{
Dmitry Torokhov67dbe832009-08-07 23:17:39 -07001082 if (leds_present & FE_MAIL_LED)
Eric Piel389679d2007-05-21 00:46:31 -04001083 led_classdev_unregister(&wistron_mail_led);
1084
Dmitry Torokhov67dbe832009-08-07 23:17:39 -07001085 if (leds_present & FE_WIFI_LED)
Eric Piel389679d2007-05-21 00:46:31 -04001086 led_classdev_unregister(&wistron_wifi_led);
1087}
1088
1089static inline void wistron_led_suspend(void)
1090{
Dmitry Torokhov67dbe832009-08-07 23:17:39 -07001091 if (leds_present & FE_MAIL_LED)
Eric Piel389679d2007-05-21 00:46:31 -04001092 led_classdev_suspend(&wistron_mail_led);
1093
Dmitry Torokhov67dbe832009-08-07 23:17:39 -07001094 if (leds_present & FE_WIFI_LED)
Eric Piel389679d2007-05-21 00:46:31 -04001095 led_classdev_suspend(&wistron_wifi_led);
1096}
1097
1098static inline void wistron_led_resume(void)
1099{
Dmitry Torokhov67dbe832009-08-07 23:17:39 -07001100 if (leds_present & FE_MAIL_LED)
Eric Piel389679d2007-05-21 00:46:31 -04001101 led_classdev_resume(&wistron_mail_led);
1102
Dmitry Torokhov67dbe832009-08-07 23:17:39 -07001103 if (leds_present & FE_WIFI_LED)
Eric Piel389679d2007-05-21 00:46:31 -04001104 led_classdev_resume(&wistron_wifi_led);
1105}
1106
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001107static void handle_key(u8 code)
1108{
Dmitry Torokhove97af4c2009-12-04 10:22:24 -08001109 const struct key_entry *key =
1110 sparse_keymap_entry_from_scancode(wistron_idev->input, code);
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001111
Dmitry Torokhovd63219a2007-06-14 23:31:45 -04001112 if (key) {
1113 switch (key->type) {
Dmitry Torokhovd63219a2007-06-14 23:31:45 -04001114 case KE_WIFI:
1115 if (have_wifi) {
1116 wifi_enabled = !wifi_enabled;
1117 bios_set_state(WIFI, wifi_enabled);
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001118 }
Dmitry Torokhovd63219a2007-06-14 23:31:45 -04001119 break;
1120
1121 case KE_BLUETOOTH:
1122 if (have_bluetooth) {
1123 bluetooth_enabled = !bluetooth_enabled;
1124 bios_set_state(BLUETOOTH, bluetooth_enabled);
1125 }
1126 break;
1127
1128 default:
Dmitry Torokhove97af4c2009-12-04 10:22:24 -08001129 sparse_keymap_report_entry(wistron_idev->input,
1130 key, 1, true);
1131 break;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001132 }
Dmitry Torokhovd63219a2007-06-14 23:31:45 -04001133 jiffies_last_press = jiffies;
1134 } else
1135 printk(KERN_NOTICE
1136 "wistron_btns: Unknown key code %02X\n", code);
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001137}
1138
Dmitry Torokhovc2554c92007-05-22 23:48:39 -04001139static void poll_bios(bool discard)
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001140{
1141 u8 qlen;
1142 u16 val;
1143
1144 for (;;) {
1145 qlen = CMOS_READ(cmos_address);
1146 if (qlen == 0)
1147 break;
1148 val = bios_pop_queue();
Dmitry Torokhovc2554c92007-05-22 23:48:39 -04001149 if (val != 0 && !discard)
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001150 handle_key((u8)val);
Dmitry Torokhovc2554c92007-05-22 23:48:39 -04001151 }
1152}
1153
1154static void wistron_flush(struct input_polled_dev *dev)
1155{
1156 /* Flush stale event queue */
1157 poll_bios(true);
1158}
1159
1160static void wistron_poll(struct input_polled_dev *dev)
1161{
1162 poll_bios(false);
1163
1164 /* Increase poll frequency if user is currently pressing keys (< 2s ago) */
1165 if (time_before(jiffies, jiffies_last_press + 2 * HZ))
1166 dev->poll_interval = POLL_INTERVAL_BURST;
1167 else
1168 dev->poll_interval = POLL_INTERVAL_DEFAULT;
1169}
1170
Bill Pemberton5298cc42012-11-23 21:38:25 -08001171static int wistron_setup_keymap(struct input_dev *dev,
Dmitry Torokhove97af4c2009-12-04 10:22:24 -08001172 struct key_entry *entry)
Dmitry Torokhovd63219a2007-06-14 23:31:45 -04001173{
Dmitry Torokhove97af4c2009-12-04 10:22:24 -08001174 switch (entry->type) {
Dmitry Torokhovd63219a2007-06-14 23:31:45 -04001175
Dmitry Torokhove97af4c2009-12-04 10:22:24 -08001176 /* if wifi or bluetooth are not available, create normal keys */
1177 case KE_WIFI:
1178 if (!have_wifi) {
1179 entry->type = KE_KEY;
1180 entry->keycode = KEY_WLAN;
1181 }
1182 break;
1183
1184 case KE_BLUETOOTH:
1185 if (!have_bluetooth) {
1186 entry->type = KE_KEY;
1187 entry->keycode = KEY_BLUETOOTH;
1188 }
1189 break;
1190
1191 case KE_END:
1192 if (entry->code & FE_UNTESTED)
1193 printk(KERN_WARNING "Untested laptop multimedia keys, "
1194 "please report success or failure to "
1195 "eric.piel@tremplin-utc.net\n");
1196 break;
Dmitry Torokhovd63219a2007-06-14 23:31:45 -04001197 }
1198
Dmitry Torokhove97af4c2009-12-04 10:22:24 -08001199 return 0;
Dmitry Torokhovd63219a2007-06-14 23:31:45 -04001200}
1201
Bill Pemberton5298cc42012-11-23 21:38:25 -08001202static int setup_input_dev(void)
Dmitry Torokhovc2554c92007-05-22 23:48:39 -04001203{
Dmitry Torokhovc2554c92007-05-22 23:48:39 -04001204 struct input_dev *input_dev;
1205 int error;
1206
1207 wistron_idev = input_allocate_polled_device();
1208 if (!wistron_idev)
1209 return -ENOMEM;
1210
Samu Onkalob0aba1e2009-10-18 00:38:57 -07001211 wistron_idev->open = wistron_flush;
Dmitry Torokhovc2554c92007-05-22 23:48:39 -04001212 wistron_idev->poll = wistron_poll;
1213 wistron_idev->poll_interval = POLL_INTERVAL_DEFAULT;
1214
1215 input_dev = wistron_idev->input;
1216 input_dev->name = "Wistron laptop buttons";
1217 input_dev->phys = "wistron/input0";
1218 input_dev->id.bustype = BUS_HOST;
Dmitry Torokhovd63219a2007-06-14 23:31:45 -04001219 input_dev->dev.parent = &wistron_device->dev;
1220
Dmitry Torokhove97af4c2009-12-04 10:22:24 -08001221 error = sparse_keymap_setup(input_dev, keymap, wistron_setup_keymap);
1222 if (error)
1223 goto err_free_dev;
Dmitry Torokhovc2554c92007-05-22 23:48:39 -04001224
1225 error = input_register_polled_device(wistron_idev);
Dmitry Torokhove97af4c2009-12-04 10:22:24 -08001226 if (error)
1227 goto err_free_keymap;
Dmitry Torokhovc2554c92007-05-22 23:48:39 -04001228
1229 return 0;
Dmitry Torokhove97af4c2009-12-04 10:22:24 -08001230
1231 err_free_keymap:
1232 sparse_keymap_free(input_dev);
1233 err_free_dev:
1234 input_free_polled_device(wistron_idev);
1235 return error;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001236}
1237
Dmitry Torokhovc2554c92007-05-22 23:48:39 -04001238/* Driver core */
1239
Bill Pemberton5298cc42012-11-23 21:38:25 -08001240static int wistron_probe(struct platform_device *dev)
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001241{
Dmitry Torokhovc2554c92007-05-22 23:48:39 -04001242 int err;
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001243
1244 bios_attach();
1245 cmos_address = bios_get_cmos_address();
1246
1247 if (have_wifi) {
1248 u16 wifi = bios_get_default_setting(WIFI);
1249 if (wifi & 1)
Dmitry Torokhov67dbe832009-08-07 23:17:39 -07001250 wifi_enabled = wifi & 2;
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001251 else
1252 have_wifi = 0;
1253
1254 if (have_wifi)
1255 bios_set_state(WIFI, wifi_enabled);
1256 }
1257
1258 if (have_bluetooth) {
1259 u16 bt = bios_get_default_setting(BLUETOOTH);
1260 if (bt & 1)
Dmitry Torokhov67dbe832009-08-07 23:17:39 -07001261 bluetooth_enabled = bt & 2;
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001262 else
Dmitry Torokhov67dbe832009-08-07 23:17:39 -07001263 have_bluetooth = false;
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001264
1265 if (have_bluetooth)
1266 bios_set_state(BLUETOOTH, bluetooth_enabled);
1267 }
1268
Eric Piel389679d2007-05-21 00:46:31 -04001269 wistron_led_init(&dev->dev);
Dmitry Torokhov67dbe832009-08-07 23:17:39 -07001270
Dmitry Torokhovc2554c92007-05-22 23:48:39 -04001271 err = setup_input_dev();
1272 if (err) {
1273 bios_detach();
1274 return err;
1275 }
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001276
1277 return 0;
1278}
1279
Bill Pembertone2619cf2012-11-23 21:50:47 -08001280static int wistron_remove(struct platform_device *dev)
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001281{
Eric Piel389679d2007-05-21 00:46:31 -04001282 wistron_led_remove();
Dmitry Torokhovc2554c92007-05-22 23:48:39 -04001283 input_unregister_polled_device(wistron_idev);
Dmitry Torokhove97af4c2009-12-04 10:22:24 -08001284 sparse_keymap_free(wistron_idev->input);
Dmitry Torokhovc2554c92007-05-22 23:48:39 -04001285 input_free_polled_device(wistron_idev);
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001286 bios_detach();
1287
1288 return 0;
1289}
1290
1291#ifdef CONFIG_PM
Dmitry Torokhov67dbe832009-08-07 23:17:39 -07001292static int wistron_suspend(struct device *dev)
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001293{
Miloslav Trmace753b652005-11-20 00:51:05 -05001294 if (have_wifi)
1295 bios_set_state(WIFI, 0);
1296
1297 if (have_bluetooth)
1298 bios_set_state(BLUETOOTH, 0);
1299
Eric Piel389679d2007-05-21 00:46:31 -04001300 wistron_led_suspend();
Dmitry Torokhov67dbe832009-08-07 23:17:39 -07001301
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001302 return 0;
1303}
1304
Dmitry Torokhov67dbe832009-08-07 23:17:39 -07001305static int wistron_resume(struct device *dev)
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001306{
1307 if (have_wifi)
1308 bios_set_state(WIFI, wifi_enabled);
1309
1310 if (have_bluetooth)
1311 bios_set_state(BLUETOOTH, bluetooth_enabled);
1312
Eric Piel389679d2007-05-21 00:46:31 -04001313 wistron_led_resume();
Dmitry Torokhov67dbe832009-08-07 23:17:39 -07001314
Dmitry Torokhovc2554c92007-05-22 23:48:39 -04001315 poll_bios(true);
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001316
1317 return 0;
1318}
Dmitry Torokhov67dbe832009-08-07 23:17:39 -07001319
1320static const struct dev_pm_ops wistron_pm_ops = {
1321 .suspend = wistron_suspend,
1322 .resume = wistron_resume,
1323 .poweroff = wistron_suspend,
1324 .restore = wistron_resume,
1325};
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001326#endif
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001327
1328static struct platform_driver wistron_driver = {
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001329 .driver = {
1330 .name = "wistron-bios",
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001331 .owner = THIS_MODULE,
Rakib Mullicke97006a2009-12-29 23:19:31 -08001332#ifdef CONFIG_PM
Dmitry Torokhov67dbe832009-08-07 23:17:39 -07001333 .pm = &wistron_pm_ops,
1334#endif
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001335 },
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001336 .probe = wistron_probe,
Bill Pemberton1cb0aa82012-11-23 21:27:39 -08001337 .remove = wistron_remove,
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001338};
1339
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001340static int __init wb_module_init(void)
1341{
1342 int err;
1343
1344 err = select_keymap();
1345 if (err)
1346 return err;
Dmitry Torokhov22a397e2005-11-20 00:50:46 -05001347
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001348 err = map_bios();
1349 if (err)
Axel Lin1fcb8bb2010-06-28 01:10:01 -07001350 goto err_free_keymap;
Dmitry Torokhov22a397e2005-11-20 00:50:46 -05001351
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001352 err = platform_driver_register(&wistron_driver);
1353 if (err)
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001354 goto err_unmap_bios;
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001355
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001356 wistron_device = platform_device_alloc("wistron-bios", -1);
1357 if (!wistron_device) {
1358 err = -ENOMEM;
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001359 goto err_unregister_driver;
1360 }
1361
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001362 err = platform_device_add(wistron_device);
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001363 if (err)
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001364 goto err_free_device;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001365
1366 return 0;
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001367
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001368 err_free_device:
1369 platform_device_put(wistron_device);
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001370 err_unregister_driver:
1371 platform_driver_unregister(&wistron_driver);
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -05001372 err_unmap_bios:
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001373 unmap_bios();
Axel Lin1fcb8bb2010-06-28 01:10:01 -07001374 err_free_keymap:
1375 kfree(keymap);
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001376
1377 return err;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001378}
1379
1380static void __exit wb_module_exit(void)
1381{
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -05001382 platform_device_unregister(wistron_device);
1383 platform_driver_unregister(&wistron_driver);
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001384 unmap_bios();
Eric Piel55d29c92007-04-12 01:32:49 -04001385 kfree(keymap);
Dmitry Torokhov5fc146802005-11-20 00:50:06 -05001386}
1387
1388module_init(wb_module_init);
1389module_exit(wb_module_exit);