blob: a172ea1dc97be775c85f1250a7821acc39eb4485 [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 */
20#include <asm/io.h>
21#include <linux/dmi.h>
22#include <linux/init.h>
23#include <linux/input.h>
24#include <linux/interrupt.h>
25#include <linux/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);
61MODULE_PARM_DESC(keymap, "Keymap name, if it can't be autodetected");
62
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;
236 unsigned keycode; /* For KE_KEY */
237};
238
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -0500239enum { KE_END, KE_KEY, KE_WIFI, KE_BLUETOOTH };
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500240
241static const struct key_entry *keymap; /* = NULL; Current key map */
242static int have_wifi;
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -0500243static int have_bluetooth;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500244
245static int __init dmi_matched(struct dmi_system_id *dmi)
246{
247 const struct key_entry *key;
248
249 keymap = dmi->driver_data;
250 for (key = keymap; key->type != KE_END; key++) {
Reiner Herrmanncde45f12006-10-01 21:58:51 -0400251 if (key->type == KE_WIFI)
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500252 have_wifi = 1;
Reiner Herrmanncde45f12006-10-01 21:58:51 -0400253 else if (key->type == KE_BLUETOOTH)
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -0500254 have_bluetooth = 1;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500255 }
256 return 1;
257}
258
Dmitry Torokhov72a623b2006-08-23 00:47:39 -0400259static struct key_entry keymap_empty[] = {
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500260 { KE_END, 0 }
261};
262
Dmitry Torokhov72a623b2006-08-23 00:47:39 -0400263static struct key_entry keymap_fs_amilo_pro_v2000[] = {
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500264 { KE_KEY, 0x01, KEY_HELP },
265 { KE_KEY, 0x11, KEY_PROG1 },
266 { KE_KEY, 0x12, KEY_PROG2 },
267 { KE_WIFI, 0x30, 0 },
268 { KE_KEY, 0x31, KEY_MAIL },
269 { KE_KEY, 0x36, KEY_WWW },
270 { KE_END, 0 }
271};
272
Dmitry Torokhov72a623b2006-08-23 00:47:39 -0400273static struct key_entry keymap_fujitsu_n3510[] = {
John Reed Rileye2aa5072006-04-05 00:40:01 -0400274 { KE_KEY, 0x11, KEY_PROG1 },
275 { KE_KEY, 0x12, KEY_PROG2 },
276 { KE_KEY, 0x36, KEY_WWW },
277 { KE_KEY, 0x31, KEY_MAIL },
278 { KE_KEY, 0x71, KEY_STOPCD },
279 { KE_KEY, 0x72, KEY_PLAYPAUSE },
280 { KE_KEY, 0x74, KEY_REWIND },
281 { KE_KEY, 0x78, KEY_FORWARD },
282 { KE_END, 0 }
283};
284
Dmitry Torokhov72a623b2006-08-23 00:47:39 -0400285static struct key_entry keymap_wistron_ms2111[] = {
Frank de Lange90001952006-06-27 01:48:24 -0400286 { KE_KEY, 0x11, KEY_PROG1 },
287 { KE_KEY, 0x12, KEY_PROG2 },
288 { KE_KEY, 0x13, KEY_PROG3 },
289 { KE_KEY, 0x31, KEY_MAIL },
290 { KE_KEY, 0x36, KEY_WWW },
291 { KE_END, 0 }
292};
293
Dmitry Torokhov72a623b2006-08-23 00:47:39 -0400294static struct key_entry keymap_wistron_ms2141[] = {
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500295 { KE_KEY, 0x11, KEY_PROG1 },
296 { KE_KEY, 0x12, KEY_PROG2 },
297 { KE_WIFI, 0x30, 0 },
298 { KE_KEY, 0x22, KEY_REWIND },
299 { KE_KEY, 0x23, KEY_FORWARD },
300 { KE_KEY, 0x24, KEY_PLAYPAUSE },
301 { KE_KEY, 0x25, KEY_STOPCD },
302 { KE_KEY, 0x31, KEY_MAIL },
303 { KE_KEY, 0x36, KEY_WWW },
304 { KE_END, 0 }
305};
306
Dmitry Torokhov72a623b2006-08-23 00:47:39 -0400307static struct key_entry keymap_acer_aspire_1500[] = {
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -0500308 { KE_KEY, 0x11, KEY_PROG1 },
309 { KE_KEY, 0x12, KEY_PROG2 },
310 { KE_WIFI, 0x30, 0 },
311 { KE_KEY, 0x31, KEY_MAIL },
312 { KE_KEY, 0x36, KEY_WWW },
313 { KE_BLUETOOTH, 0x44, 0 },
314 { KE_END, 0 }
315};
316
Dmitry Torokhov72a623b2006-08-23 00:47:39 -0400317static struct key_entry keymap_acer_travelmate_240[] = {
Ashutosh Naik74a89c92005-12-11 12:41:32 -0500318 { KE_KEY, 0x31, KEY_MAIL },
319 { KE_KEY, 0x36, KEY_WWW },
320 { KE_KEY, 0x11, KEY_PROG1 },
321 { KE_KEY, 0x12, KEY_PROG2 },
322 { KE_BLUETOOTH, 0x44, 0 },
323 { KE_WIFI, 0x30, 0 },
324 { KE_END, 0 }
325};
326
Dmitry Torokhov72a623b2006-08-23 00:47:39 -0400327static struct key_entry keymap_aopen_1559as[] = {
masc@theaterzentrum.ate107b8e2006-05-29 23:29:36 -0400328 { KE_KEY, 0x01, KEY_HELP },
329 { KE_KEY, 0x06, KEY_PROG3 },
330 { KE_KEY, 0x11, KEY_PROG1 },
331 { KE_KEY, 0x12, KEY_PROG2 },
332 { KE_WIFI, 0x30, 0 },
333 { KE_KEY, 0x31, KEY_MAIL },
334 { KE_KEY, 0x36, KEY_WWW },
Frank de Lange90001952006-06-27 01:48:24 -0400335 { KE_END, 0 },
masc@theaterzentrum.ate107b8e2006-05-29 23:29:36 -0400336};
337
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500338/*
339 * If your machine is not here (which is currently rather likely), please send
340 * a list of buttons and their key codes (reported when loading this module
341 * with force=1) and the output of dmidecode to $MODULE_AUTHOR.
342 */
Andrew Mortonc7948982006-07-06 00:23:38 -0400343static struct dmi_system_id dmi_ids[] __initdata = {
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500344 {
345 .callback = dmi_matched,
346 .ident = "Fujitsu-Siemens Amilo Pro V2000",
347 .matches = {
348 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
349 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pro V2000"),
350 },
351 .driver_data = keymap_fs_amilo_pro_v2000
352 },
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -0500353 {
354 .callback = dmi_matched,
Stefan Rompf8a1b1702006-04-05 00:39:20 -0400355 .ident = "Fujitsu-Siemens Amilo M7400",
356 .matches = {
357 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
358 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO M "),
359 },
360 .driver_data = keymap_fs_amilo_pro_v2000
361 },
362 {
363 .callback = dmi_matched,
John Reed Rileye2aa5072006-04-05 00:40:01 -0400364 .ident = "Fujitsu N3510",
365 .matches = {
366 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
367 DMI_MATCH(DMI_PRODUCT_NAME, "N3510"),
368 },
369 .driver_data = keymap_fujitsu_n3510
370 },
371 {
372 .callback = dmi_matched,
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -0500373 .ident = "Acer Aspire 1500",
374 .matches = {
375 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
376 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1500"),
377 },
378 .driver_data = keymap_acer_aspire_1500
379 },
Ashutosh Naik74a89c92005-12-11 12:41:32 -0500380 {
381 .callback = dmi_matched,
382 .ident = "Acer TravelMate 240",
383 .matches = {
384 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
385 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 240"),
386 },
387 .driver_data = keymap_acer_travelmate_240
388 },
masc@theaterzentrum.ate107b8e2006-05-29 23:29:36 -0400389 {
390 .callback = dmi_matched,
391 .ident = "AOpen 1559AS",
392 .matches = {
393 DMI_MATCH(DMI_PRODUCT_NAME, "E2U"),
394 DMI_MATCH(DMI_BOARD_NAME, "E2U"),
395 },
396 .driver_data = keymap_aopen_1559as
397 },
Frank de Lange90001952006-06-27 01:48:24 -0400398 {
399 .callback = dmi_matched,
400 .ident = "Medion MD 9783",
401 .matches = {
402 DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
403 DMI_MATCH(DMI_PRODUCT_NAME, "MD 9783"),
404 },
405 .driver_data = keymap_wistron_ms2111
406 },
Al Viro81f0a912005-12-15 09:19:05 +0000407 { NULL, }
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500408};
409
410static int __init select_keymap(void)
411{
412 if (keymap_name != NULL) {
413 if (strcmp (keymap_name, "1557/MS2141") == 0)
414 keymap = keymap_wistron_ms2141;
415 else {
416 printk(KERN_ERR "wistron_btns: Keymap unknown\n");
417 return -EINVAL;
418 }
419 }
420 dmi_check_system(dmi_ids);
421 if (keymap == NULL) {
422 if (!force) {
423 printk(KERN_ERR "wistron_btns: System unknown\n");
424 return -ENODEV;
425 }
426 keymap = keymap_empty;
427 }
428 return 0;
429}
430
431 /* Input layer interface */
432
Dmitry Torokhov22a397e2005-11-20 00:50:46 -0500433static struct input_dev *input_dev;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500434
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -0500435static int __devinit setup_input_dev(void)
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500436{
437 const struct key_entry *key;
Dmitry Torokhov22a397e2005-11-20 00:50:46 -0500438 int error;
439
440 input_dev = input_allocate_device();
441 if (!input_dev)
442 return -ENOMEM;
443
444 input_dev->name = "Wistron laptop buttons";
445 input_dev->phys = "wistron/input0";
446 input_dev->id.bustype = BUS_HOST;
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -0500447 input_dev->cdev.dev = &wistron_device->dev;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500448
449 for (key = keymap; key->type != KE_END; key++) {
450 if (key->type == KE_KEY) {
Dmitry Torokhov22a397e2005-11-20 00:50:46 -0500451 input_dev->evbit[LONG(EV_KEY)] = BIT(EV_KEY);
452 set_bit(key->keycode, input_dev->keybit);
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500453 }
454 }
455
Dmitry Torokhov22a397e2005-11-20 00:50:46 -0500456 error = input_register_device(input_dev);
457 if (error) {
458 input_free_device(input_dev);
459 return error;
460 }
461
462 return 0;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500463}
464
465static void report_key(unsigned keycode)
466{
Dmitry Torokhov22a397e2005-11-20 00:50:46 -0500467 input_report_key(input_dev, keycode, 1);
468 input_sync(input_dev);
469 input_report_key(input_dev, keycode, 0);
470 input_sync(input_dev);
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500471}
472
473 /* Driver core */
474
475static int wifi_enabled;
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -0500476static int bluetooth_enabled;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500477
478static void poll_bios(unsigned long);
479
480static struct timer_list poll_timer = TIMER_INITIALIZER(poll_bios, 0, 0);
481
482static void handle_key(u8 code)
483{
484 const struct key_entry *key;
485
486 for (key = keymap; key->type != KE_END; key++) {
487 if (code == key->code) {
488 switch (key->type) {
489 case KE_KEY:
490 report_key(key->keycode);
491 break;
492
493 case KE_WIFI:
494 if (have_wifi) {
495 wifi_enabled = !wifi_enabled;
Bernhard Rosenkraenzer84b256a2005-11-20 00:50:37 -0500496 bios_set_state(WIFI, wifi_enabled);
497 }
498 break;
499
500 case KE_BLUETOOTH:
501 if (have_bluetooth) {
502 bluetooth_enabled = !bluetooth_enabled;
503 bios_set_state(BLUETOOTH, bluetooth_enabled);
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500504 }
505 break;
506
507 case KE_END:
508 default:
509 BUG();
510 }
511 return;
512 }
513 }
514 printk(KERN_NOTICE "wistron_btns: Unknown key code %02X\n", code);
515}
516
517static void poll_bios(unsigned long discard)
518{
519 u8 qlen;
520 u16 val;
521
522 for (;;) {
523 qlen = CMOS_READ(cmos_address);
524 if (qlen == 0)
525 break;
526 val = bios_pop_queue();
527 if (val != 0 && !discard)
528 handle_key((u8)val);
529 }
530
531 mod_timer(&poll_timer, jiffies + HZ / POLL_FREQUENCY);
532}
533
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -0500534static int __devinit wistron_probe(struct platform_device *dev)
535{
536 int err = setup_input_dev();
537 if (err)
538 return err;
539
540 bios_attach();
541 cmos_address = bios_get_cmos_address();
542
543 if (have_wifi) {
544 u16 wifi = bios_get_default_setting(WIFI);
545 if (wifi & 1)
546 wifi_enabled = (wifi & 2) ? 1 : 0;
547 else
548 have_wifi = 0;
549
550 if (have_wifi)
551 bios_set_state(WIFI, wifi_enabled);
552 }
553
554 if (have_bluetooth) {
555 u16 bt = bios_get_default_setting(BLUETOOTH);
556 if (bt & 1)
557 bluetooth_enabled = (bt & 2) ? 1 : 0;
558 else
559 have_bluetooth = 0;
560
561 if (have_bluetooth)
562 bios_set_state(BLUETOOTH, bluetooth_enabled);
563 }
564
565 poll_bios(1); /* Flush stale event queue and arm timer */
566
567 return 0;
568}
569
570static int __devexit wistron_remove(struct platform_device *dev)
571{
572 del_timer_sync(&poll_timer);
573 input_unregister_device(input_dev);
574 bios_detach();
575
576 return 0;
577}
578
579#ifdef CONFIG_PM
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -0500580static int wistron_suspend(struct platform_device *dev, pm_message_t state)
581{
582 del_timer_sync(&poll_timer);
583
Miloslav Trmace753b652005-11-20 00:51:05 -0500584 if (have_wifi)
585 bios_set_state(WIFI, 0);
586
587 if (have_bluetooth)
588 bios_set_state(BLUETOOTH, 0);
589
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -0500590 return 0;
591}
592
593static int wistron_resume(struct platform_device *dev)
594{
595 if (have_wifi)
596 bios_set_state(WIFI, wifi_enabled);
597
598 if (have_bluetooth)
599 bios_set_state(BLUETOOTH, bluetooth_enabled);
600
601 poll_bios(1);
602
603 return 0;
604}
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -0500605#else
606#define wistron_suspend NULL
607#define wistron_resume NULL
608#endif
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -0500609
610static struct platform_driver wistron_driver = {
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -0500611 .driver = {
612 .name = "wistron-bios",
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -0500613 .owner = THIS_MODULE,
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -0500614 },
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -0500615 .probe = wistron_probe,
616 .remove = __devexit_p(wistron_remove),
617 .suspend = wistron_suspend,
618 .resume = wistron_resume,
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -0500619};
620
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500621static int __init wb_module_init(void)
622{
623 int err;
624
625 err = select_keymap();
626 if (err)
627 return err;
Dmitry Torokhov22a397e2005-11-20 00:50:46 -0500628
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500629 err = map_bios();
630 if (err)
631 return err;
Dmitry Torokhov22a397e2005-11-20 00:50:46 -0500632
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -0500633 err = platform_driver_register(&wistron_driver);
634 if (err)
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -0500635 goto err_unmap_bios;
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -0500636
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -0500637 wistron_device = platform_device_alloc("wistron-bios", -1);
638 if (!wistron_device) {
639 err = -ENOMEM;
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -0500640 goto err_unregister_driver;
641 }
642
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -0500643 err = platform_device_add(wistron_device);
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -0500644 if (err)
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -0500645 goto err_free_device;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500646
647 return 0;
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -0500648
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -0500649 err_free_device:
650 platform_device_put(wistron_device);
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -0500651 err_unregister_driver:
652 platform_driver_unregister(&wistron_driver);
Dmitry Torokhove7c3aad2005-12-28 01:26:24 -0500653 err_unmap_bios:
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -0500654 unmap_bios();
655
656 return err;
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500657}
658
659static void __exit wb_module_exit(void)
660{
Dmitry Torokhova5b0cc802005-11-20 00:50:58 -0500661 platform_device_unregister(wistron_device);
662 platform_driver_unregister(&wistron_driver);
Dmitry Torokhov5fc146802005-11-20 00:50:06 -0500663 unmap_bios();
664}
665
666module_init(wb_module_init);
667module_exit(wb_module_exit);