Linux Audio

Check our new training course

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