wistron_btns.c 36.0 KB
Newer Older
D
Dmitry Torokhov 已提交
1 2 3
/*
 * Wistron laptop button driver
 * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz>
4
 * Copyright (C) 2005 Bernhard Rosenkraenzer <bero@arklinux.org>
D
Dmitry Torokhov 已提交
5
 * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru>
D
Dmitry Torokhov 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * You can redistribute and/or modify this program under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
 * Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place Suite 330, Boston, MA 02111-1307, USA.
 */
20
#include <linux/io.h>
D
Dmitry Torokhov 已提交
21 22
#include <linux/dmi.h>
#include <linux/init.h>
23
#include <linux/input-polldev.h>
D
Dmitry Torokhov 已提交
24
#include <linux/interrupt.h>
25
#include <linux/jiffies.h>
D
Dmitry Torokhov 已提交
26 27 28 29 30 31
#include <linux/kernel.h>
#include <linux/mc146818rtc.h>
#include <linux/module.h>
#include <linux/preempt.h>
#include <linux/string.h>
#include <linux/types.h>
D
Dmitry Torokhov 已提交
32
#include <linux/platform_device.h>
E
Eric Piel 已提交
33
#include <linux/leds.h>
D
Dmitry Torokhov 已提交
34

35 36 37
/* How often we poll keys - msecs */
#define POLL_INTERVAL_DEFAULT	500 /* when idle */
#define POLL_INTERVAL_BURST	100 /* when a key was recently pressed */
D
Dmitry Torokhov 已提交
38

39 40 41
/* BIOS subsystem IDs */
#define WIFI		0x35
#define BLUETOOTH	0x34
E
Eric Piel 已提交
42
#define MAIL_LED	0x31
43

D
Dmitry Torokhov 已提交
44 45 46
MODULE_AUTHOR("Miloslav Trmac <mitr@volny.cz>");
MODULE_DESCRIPTION("Wistron laptop button driver");
MODULE_LICENSE("GPL v2");
E
Eric Piel 已提交
47
MODULE_VERSION("0.3");
D
Dmitry Torokhov 已提交
48 49 50 51 52 53 54

static int force; /* = 0; */
module_param(force, bool, 0);
MODULE_PARM_DESC(force, "Load even if computer is not in database");

static char *keymap_name; /* = NULL; */
module_param_named(keymap, keymap_name, charp, 0);
55
MODULE_PARM_DESC(keymap, "Keymap name, if it can't be autodetected [generic, 1557/MS2141]");
D
Dmitry Torokhov 已提交
56

D
Dmitry Torokhov 已提交
57 58
static struct platform_device *wistron_device;

D
Dmitry Torokhov 已提交
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
 /* BIOS interface implementation */

static void __iomem *bios_entry_point; /* BIOS routine entry point */
static void __iomem *bios_code_map_base;
static void __iomem *bios_data_map_base;

static u8 cmos_address;

struct regs {
	u32 eax, ebx, ecx;
};

static void call_bios(struct regs *regs)
{
	unsigned long flags;

	preempt_disable();
	local_irq_save(flags);
	asm volatile ("pushl %%ebp;"
		      "movl %7, %%ebp;"
		      "call *%6;"
		      "popl %%ebp"
		      : "=a" (regs->eax), "=b" (regs->ebx), "=c" (regs->ecx)
		      : "0" (regs->eax), "1" (regs->ebx), "2" (regs->ecx),
			"m" (bios_entry_point), "m" (bios_data_map_base)
		      : "edx", "edi", "esi", "memory");
	local_irq_restore(flags);
	preempt_enable();
}

89
static ssize_t __init locate_wistron_bios(void __iomem *base)
D
Dmitry Torokhov 已提交
90
{
91
	static unsigned char __initdata signature[] =
D
Dmitry Torokhov 已提交
92
		{ 0x42, 0x21, 0x55, 0x30 };
93
	ssize_t offset;
D
Dmitry Torokhov 已提交
94 95 96 97 98 99 100 101 102 103 104 105

	for (offset = 0; offset < 0x10000; offset += 0x10) {
		if (check_signature(base + offset, signature,
				    sizeof(signature)) != 0)
			return offset;
	}
	return -1;
}

static int __init map_bios(void)
{
	void __iomem *base;
106
	ssize_t offset;
D
Dmitry Torokhov 已提交
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
	u32 entry_point;

	base = ioremap(0xF0000, 0x10000); /* Can't fail */
	offset = locate_wistron_bios(base);
	if (offset < 0) {
		printk(KERN_ERR "wistron_btns: BIOS entry point not found\n");
		iounmap(base);
		return -ENODEV;
	}

	entry_point = readl(base + offset + 5);
	printk(KERN_DEBUG
		"wistron_btns: BIOS signature found at %p, entry point %08X\n",
		base + offset, entry_point);

	if (entry_point >= 0xF0000) {
		bios_code_map_base = base;
		bios_entry_point = bios_code_map_base + (entry_point & 0xFFFF);
	} else {
		iounmap(base);
		bios_code_map_base = ioremap(entry_point & ~0x3FFF, 0x4000);
		if (bios_code_map_base == NULL) {
			printk(KERN_ERR
				"wistron_btns: Can't map BIOS code at %08X\n",
				entry_point & ~0x3FFF);
			goto err;
		}
		bios_entry_point = bios_code_map_base + (entry_point & 0x3FFF);
	}
	/* The Windows driver maps 0x10000 bytes, we keep only one page... */
	bios_data_map_base = ioremap(0x400, 0xc00);
	if (bios_data_map_base == NULL) {
		printk(KERN_ERR "wistron_btns: Can't map BIOS data\n");
		goto err_code;
	}
	return 0;

err_code:
	iounmap(bios_code_map_base);
err:
	return -ENOMEM;
}

150
static inline void unmap_bios(void)
D
Dmitry Torokhov 已提交
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
{
	iounmap(bios_code_map_base);
	iounmap(bios_data_map_base);
}

 /* BIOS calls */

static u16 bios_pop_queue(void)
{
	struct regs regs;

	memset(&regs, 0, sizeof (regs));
	regs.eax = 0x9610;
	regs.ebx = 0x061C;
	regs.ecx = 0x0000;
	call_bios(&regs);

	return regs.eax;
}

171
static void __devinit bios_attach(void)
D
Dmitry Torokhov 已提交
172 173 174 175 176 177 178 179 180
{
	struct regs regs;

	memset(&regs, 0, sizeof (regs));
	regs.eax = 0x9610;
	regs.ebx = 0x012E;
	call_bios(&regs);
}

181
static void bios_detach(void)
D
Dmitry Torokhov 已提交
182 183 184 185 186 187 188 189 190
{
	struct regs regs;

	memset(&regs, 0, sizeof (regs));
	regs.eax = 0x9610;
	regs.ebx = 0x002E;
	call_bios(&regs);
}

191
static u8 __devinit bios_get_cmos_address(void)
D
Dmitry Torokhov 已提交
192 193 194 195 196 197 198 199 200 201 202
{
	struct regs regs;

	memset(&regs, 0, sizeof (regs));
	regs.eax = 0x9610;
	regs.ebx = 0x051C;
	call_bios(&regs);

	return regs.ecx;
}

203
static u16 __devinit bios_get_default_setting(u8 subsys)
D
Dmitry Torokhov 已提交
204 205 206 207 208
{
	struct regs regs;

	memset(&regs, 0, sizeof (regs));
	regs.eax = 0x9610;
209
	regs.ebx = 0x0200 | subsys;
D
Dmitry Torokhov 已提交
210 211 212 213 214
	call_bios(&regs);

	return regs.eax;
}

215
static void bios_set_state(u8 subsys, int enable)
D
Dmitry Torokhov 已提交
216 217 218 219 220
{
	struct regs regs;

	memset(&regs, 0, sizeof (regs));
	regs.eax = 0x9610;
221
	regs.ebx = (enable ? 0x0100 : 0x0000) | subsys;
D
Dmitry Torokhov 已提交
222 223 224
	call_bios(&regs);
}

225
/* Hardware database */
D
Dmitry Torokhov 已提交
226 227 228 229

struct key_entry {
	char type;		/* See KE_* below */
	u8 code;
230 231 232 233 234 235 236
	union {
		u16 keycode;		/* For KE_KEY */
		struct {		/* For KE_SW */
			u8 code;
			u8 value;
		} sw;
	};
D
Dmitry Torokhov 已提交
237 238
};

239 240 241 242 243
enum { KE_END, KE_KEY, KE_SW, KE_WIFI, KE_BLUETOOTH };

#define FE_MAIL_LED 0x01
#define FE_WIFI_LED 0x02
#define FE_UNTESTED 0x80
D
Dmitry Torokhov 已提交
244

245
static struct key_entry *keymap; /* = NULL; Current key map */
246 247 248
static bool have_wifi;
static bool have_bluetooth;
static int leds_present;	/* bitmask of leds present */
D
Dmitry Torokhov 已提交
249

250
static int __init dmi_matched(const struct dmi_system_id *dmi)
D
Dmitry Torokhov 已提交
251 252 253 254 255
{
	const struct key_entry *key;

	keymap = dmi->driver_data;
	for (key = keymap; key->type != KE_END; key++) {
256
		if (key->type == KE_WIFI)
257
			have_wifi = true;
258
		else if (key->type == KE_BLUETOOTH)
259
			have_bluetooth = true;
D
Dmitry Torokhov 已提交
260
	}
261
	leds_present = key->code & (FE_MAIL_LED | FE_WIFI_LED);
E
Eric Piel 已提交
262

D
Dmitry Torokhov 已提交
263 264 265
	return 1;
}

266
static struct key_entry keymap_empty[] __initdata = {
D
Dmitry Torokhov 已提交
267 268 269
	{ KE_END, 0 }
};

270
static struct key_entry keymap_fs_amilo_pro_v2000[] __initdata = {
271 272 273 274 275 276
	{ KE_KEY,  0x01, {KEY_HELP} },
	{ KE_KEY,  0x11, {KEY_PROG1} },
	{ KE_KEY,  0x12, {KEY_PROG2} },
	{ KE_WIFI, 0x30 },
	{ KE_KEY,  0x31, {KEY_MAIL} },
	{ KE_KEY,  0x36, {KEY_WWW} },
D
Dmitry Torokhov 已提交
277 278 279
	{ KE_END,  0 }
};

280 281 282 283 284 285 286 287 288 289
static struct key_entry keymap_fs_amilo_pro_v3505[] __initdata = {
	{ KE_KEY,       0x01, {KEY_HELP} },          /* Fn+F1 */
	{ KE_KEY,       0x06, {KEY_DISPLAYTOGGLE} }, /* Fn+F4 */
	{ KE_BLUETOOTH, 0x30 },                      /* Fn+F10 */
	{ KE_KEY,       0x31, {KEY_MAIL} },          /* mail button */
	{ KE_KEY,       0x36, {KEY_WWW} },           /* www button */
	{ KE_WIFI,      0x78 },                      /* satelite dish button */
	{ KE_END,       0 }
};

290
static struct key_entry keymap_fujitsu_n3510[] __initdata = {
291 292 293 294 295 296 297 298
	{ KE_KEY, 0x11, {KEY_PROG1} },
	{ KE_KEY, 0x12, {KEY_PROG2} },
	{ KE_KEY, 0x36, {KEY_WWW} },
	{ KE_KEY, 0x31, {KEY_MAIL} },
	{ KE_KEY, 0x71, {KEY_STOPCD} },
	{ KE_KEY, 0x72, {KEY_PLAYPAUSE} },
	{ KE_KEY, 0x74, {KEY_REWIND} },
	{ KE_KEY, 0x78, {KEY_FORWARD} },
299 300 301
	{ KE_END, 0 }
};

302
static struct key_entry keymap_wistron_ms2111[] __initdata = {
303 304 305 306 307 308 309 310
	{ KE_KEY,  0x11, {KEY_PROG1} },
	{ KE_KEY,  0x12, {KEY_PROG2} },
	{ KE_KEY,  0x13, {KEY_PROG3} },
	{ KE_KEY,  0x31, {KEY_MAIL} },
	{ KE_KEY,  0x36, {KEY_WWW} },
	{ KE_END, FE_MAIL_LED }
};

311
static struct key_entry keymap_wistron_md40100[] __initdata = {
312 313 314 315 316 317
	{ KE_KEY, 0x01, {KEY_HELP} },
	{ KE_KEY, 0x02, {KEY_CONFIG} },
	{ KE_KEY, 0x31, {KEY_MAIL} },
	{ KE_KEY, 0x36, {KEY_WWW} },
	{ KE_KEY, 0x37, {KEY_DISPLAYTOGGLE} }, /* Display on/off */
	{ KE_END, FE_MAIL_LED | FE_WIFI_LED | FE_UNTESTED }
318 319
};

320
static struct key_entry keymap_wistron_ms2141[] __initdata = {
321 322 323 324 325 326 327 328 329
	{ KE_KEY,  0x11, {KEY_PROG1} },
	{ KE_KEY,  0x12, {KEY_PROG2} },
	{ KE_WIFI, 0x30 },
	{ KE_KEY,  0x22, {KEY_REWIND} },
	{ KE_KEY,  0x23, {KEY_FORWARD} },
	{ KE_KEY,  0x24, {KEY_PLAYPAUSE} },
	{ KE_KEY,  0x25, {KEY_STOPCD} },
	{ KE_KEY,  0x31, {KEY_MAIL} },
	{ KE_KEY,  0x36, {KEY_WWW} },
D
Dmitry Torokhov 已提交
330 331 332
	{ KE_END,  0 }
};

333
static struct key_entry keymap_acer_aspire_1500[] __initdata = {
334 335 336 337 338 339 340 341 342 343 344 345
	{ KE_KEY, 0x01, {KEY_HELP} },
	{ KE_KEY, 0x03, {KEY_POWER} },
	{ KE_KEY, 0x11, {KEY_PROG1} },
	{ KE_KEY, 0x12, {KEY_PROG2} },
	{ KE_WIFI, 0x30 },
	{ KE_KEY, 0x31, {KEY_MAIL} },
	{ KE_KEY, 0x36, {KEY_WWW} },
	{ KE_KEY, 0x49, {KEY_CONFIG} },
	{ KE_BLUETOOTH, 0x44 },
	{ KE_END, FE_UNTESTED }
};

346
static struct key_entry keymap_acer_aspire_1600[] __initdata = {
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
	{ KE_KEY, 0x01, {KEY_HELP} },
	{ KE_KEY, 0x03, {KEY_POWER} },
	{ KE_KEY, 0x08, {KEY_MUTE} },
	{ KE_KEY, 0x11, {KEY_PROG1} },
	{ KE_KEY, 0x12, {KEY_PROG2} },
	{ KE_KEY, 0x13, {KEY_PROG3} },
	{ KE_KEY, 0x31, {KEY_MAIL} },
	{ KE_KEY, 0x36, {KEY_WWW} },
	{ KE_KEY, 0x49, {KEY_CONFIG} },
	{ KE_WIFI, 0x30 },
	{ KE_BLUETOOTH, 0x44 },
	{ KE_END, FE_MAIL_LED | FE_UNTESTED }
};

/* 3020 has been tested */
362
static struct key_entry keymap_acer_aspire_5020[] __initdata = {
363 364 365 366 367 368 369 370 371 372 373 374 375
	{ KE_KEY, 0x01, {KEY_HELP} },
	{ KE_KEY, 0x03, {KEY_POWER} },
	{ KE_KEY, 0x05, {KEY_SWITCHVIDEOMODE} }, /* Display selection */
	{ KE_KEY, 0x11, {KEY_PROG1} },
	{ KE_KEY, 0x12, {KEY_PROG2} },
	{ KE_KEY, 0x31, {KEY_MAIL} },
	{ KE_KEY, 0x36, {KEY_WWW} },
	{ KE_KEY, 0x6a, {KEY_CONFIG} },
	{ KE_WIFI, 0x30 },
	{ KE_BLUETOOTH, 0x44 },
	{ KE_END, FE_MAIL_LED | FE_UNTESTED }
};

376
static struct key_entry keymap_acer_travelmate_2410[] __initdata = {
377 378 379 380 381 382 383 384 385 386 387 388
	{ KE_KEY, 0x01, {KEY_HELP} },
	{ KE_KEY, 0x6d, {KEY_POWER} },
	{ KE_KEY, 0x11, {KEY_PROG1} },
	{ KE_KEY, 0x12, {KEY_PROG2} },
	{ KE_KEY, 0x31, {KEY_MAIL} },
	{ KE_KEY, 0x36, {KEY_WWW} },
	{ KE_KEY, 0x6a, {KEY_CONFIG} },
	{ KE_WIFI, 0x30 },
	{ KE_BLUETOOTH, 0x44 },
	{ KE_END, FE_MAIL_LED | FE_UNTESTED }
};

389
static struct key_entry keymap_acer_travelmate_110[] __initdata = {
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
	{ KE_KEY, 0x01, {KEY_HELP} },
	{ KE_KEY, 0x02, {KEY_CONFIG} },
	{ KE_KEY, 0x03, {KEY_POWER} },
	{ KE_KEY, 0x08, {KEY_MUTE} },
	{ KE_KEY, 0x11, {KEY_PROG1} },
	{ KE_KEY, 0x12, {KEY_PROG2} },
	{ KE_KEY, 0x20, {KEY_VOLUMEUP} },
	{ KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
	{ KE_KEY, 0x31, {KEY_MAIL} },
	{ KE_KEY, 0x36, {KEY_WWW} },
	{ KE_SW, 0x4a, {.sw = {SW_LID, 1}} }, /* lid close */
	{ KE_SW, 0x4b, {.sw = {SW_LID, 0}} }, /* lid open */
	{ KE_WIFI, 0x30 },
	{ KE_END, FE_MAIL_LED | FE_UNTESTED }
};

406
static struct key_entry keymap_acer_travelmate_300[] __initdata = {
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
	{ KE_KEY, 0x01, {KEY_HELP} },
	{ KE_KEY, 0x02, {KEY_CONFIG} },
	{ KE_KEY, 0x03, {KEY_POWER} },
	{ KE_KEY, 0x08, {KEY_MUTE} },
	{ KE_KEY, 0x11, {KEY_PROG1} },
	{ KE_KEY, 0x12, {KEY_PROG2} },
	{ KE_KEY, 0x20, {KEY_VOLUMEUP} },
	{ KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
	{ KE_KEY, 0x31, {KEY_MAIL} },
	{ KE_KEY, 0x36, {KEY_WWW} },
	{ KE_WIFI, 0x30 },
	{ KE_BLUETOOTH, 0x44 },
	{ KE_END, FE_MAIL_LED | FE_UNTESTED }
};

422
static struct key_entry keymap_acer_travelmate_380[] __initdata = {
423 424 425 426 427 428 429 430 431 432 433 434 435
	{ KE_KEY, 0x01, {KEY_HELP} },
	{ KE_KEY, 0x02, {KEY_CONFIG} },
	{ KE_KEY, 0x03, {KEY_POWER} }, /* not 370 */
	{ KE_KEY, 0x11, {KEY_PROG1} },
	{ KE_KEY, 0x12, {KEY_PROG2} },
	{ KE_KEY, 0x13, {KEY_PROG3} },
	{ KE_KEY, 0x31, {KEY_MAIL} },
	{ KE_KEY, 0x36, {KEY_WWW} },
	{ KE_WIFI, 0x30 },
	{ KE_END, FE_MAIL_LED | FE_UNTESTED }
};

/* unusual map */
436
static struct key_entry keymap_acer_travelmate_220[] __initdata = {
437 438 439 440 441 442 443 444 445
	{ KE_KEY, 0x01, {KEY_HELP} },
	{ KE_KEY, 0x02, {KEY_CONFIG} },
	{ KE_KEY, 0x11, {KEY_MAIL} },
	{ KE_KEY, 0x12, {KEY_WWW} },
	{ KE_KEY, 0x13, {KEY_PROG2} },
	{ KE_KEY, 0x31, {KEY_PROG1} },
	{ KE_END, FE_WIFI_LED | FE_UNTESTED }
};

446
static struct key_entry keymap_acer_travelmate_230[] __initdata = {
447 448 449 450 451 452 453
	{ KE_KEY, 0x01, {KEY_HELP} },
	{ KE_KEY, 0x02, {KEY_CONFIG} },
	{ KE_KEY, 0x11, {KEY_PROG1} },
	{ KE_KEY, 0x12, {KEY_PROG2} },
	{ KE_KEY, 0x31, {KEY_MAIL} },
	{ KE_KEY, 0x36, {KEY_WWW} },
	{ KE_END, FE_WIFI_LED | FE_UNTESTED }
454 455
};

456
static struct key_entry keymap_acer_travelmate_240[] __initdata = {
457 458 459 460 461 462 463 464 465 466 467 468 469
	{ KE_KEY, 0x01, {KEY_HELP} },
	{ KE_KEY, 0x02, {KEY_CONFIG} },
	{ KE_KEY, 0x03, {KEY_POWER} },
	{ KE_KEY, 0x08, {KEY_MUTE} },
	{ KE_KEY, 0x31, {KEY_MAIL} },
	{ KE_KEY, 0x36, {KEY_WWW} },
	{ KE_KEY, 0x11, {KEY_PROG1} },
	{ KE_KEY, 0x12, {KEY_PROG2} },
	{ KE_BLUETOOTH, 0x44 },
	{ KE_WIFI, 0x30 },
	{ KE_END, FE_UNTESTED }
};

470
static struct key_entry keymap_acer_travelmate_350[] __initdata = {
471 472 473 474 475 476 477 478 479 480
	{ KE_KEY, 0x01, {KEY_HELP} },
	{ KE_KEY, 0x02, {KEY_CONFIG} },
	{ KE_KEY, 0x11, {KEY_PROG1} },
	{ KE_KEY, 0x12, {KEY_PROG2} },
	{ KE_KEY, 0x13, {KEY_MAIL} },
	{ KE_KEY, 0x14, {KEY_PROG3} },
	{ KE_KEY, 0x15, {KEY_WWW} },
	{ KE_END, FE_MAIL_LED | FE_WIFI_LED | FE_UNTESTED }
};

481
static struct key_entry keymap_acer_travelmate_360[] __initdata = {
482 483 484 485 486 487 488 489 490
	{ KE_KEY, 0x01, {KEY_HELP} },
	{ KE_KEY, 0x02, {KEY_CONFIG} },
	{ KE_KEY, 0x11, {KEY_PROG1} },
	{ KE_KEY, 0x12, {KEY_PROG2} },
	{ KE_KEY, 0x13, {KEY_MAIL} },
	{ KE_KEY, 0x14, {KEY_PROG3} },
	{ KE_KEY, 0x15, {KEY_WWW} },
	{ KE_KEY, 0x40, {KEY_WLAN} },
	{ KE_END, FE_WIFI_LED | FE_UNTESTED } /* no mail led */
491 492
};

493 494 495
/* Wifi subsystem only activates the led. Therefore we need to pass
 * wifi event as a normal key, then userspace can really change the wifi state.
 * TODO we need to export led state to userspace (wifi and mail) */
496
static struct key_entry keymap_acer_travelmate_610[] __initdata = {
497 498 499
	{ KE_KEY, 0x01, {KEY_HELP} },
	{ KE_KEY, 0x02, {KEY_CONFIG} },
	{ KE_KEY, 0x11, {KEY_PROG1} },
500
	{ KE_KEY, 0x12, {KEY_PROG2} },
501 502 503 504 505 506 507
	{ KE_KEY, 0x13, {KEY_PROG3} },
	{ KE_KEY, 0x14, {KEY_MAIL} },
	{ KE_KEY, 0x15, {KEY_WWW} },
	{ KE_KEY, 0x40, {KEY_WLAN} },
	{ KE_END, FE_MAIL_LED | FE_WIFI_LED }
};

508
static struct key_entry keymap_acer_travelmate_630[] __initdata = {
509 510 511 512 513 514 515 516 517 518 519 520 521
	{ KE_KEY, 0x01, {KEY_HELP} },
	{ KE_KEY, 0x02, {KEY_CONFIG} },
	{ KE_KEY, 0x03, {KEY_POWER} },
	{ KE_KEY, 0x08, {KEY_MUTE} }, /* not 620 */
	{ KE_KEY, 0x11, {KEY_PROG1} },
	{ KE_KEY, 0x12, {KEY_PROG2} },
	{ KE_KEY, 0x13, {KEY_PROG3} },
	{ KE_KEY, 0x20, {KEY_VOLUMEUP} },
	{ KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
	{ KE_KEY, 0x31, {KEY_MAIL} },
	{ KE_KEY, 0x36, {KEY_WWW} },
	{ KE_WIFI, 0x30 },
	{ KE_END, FE_MAIL_LED | FE_UNTESTED }
522 523
};

524
static struct key_entry keymap_aopen_1559as[] __initdata = {
525 526 527 528 529 530 531
	{ KE_KEY,  0x01, {KEY_HELP} },
	{ KE_KEY,  0x06, {KEY_PROG3} },
	{ KE_KEY,  0x11, {KEY_PROG1} },
	{ KE_KEY,  0x12, {KEY_PROG2} },
	{ KE_WIFI, 0x30 },
	{ KE_KEY,  0x31, {KEY_MAIL} },
	{ KE_KEY,  0x36, {KEY_WWW} },
532
	{ KE_END,  0 },
533 534
};

535
static struct key_entry keymap_fs_amilo_d88x0[] __initdata = {
536 537 538 539 540 541 542 543 544 545
	{ KE_KEY, 0x01, {KEY_HELP} },
	{ KE_KEY, 0x08, {KEY_MUTE} },
	{ KE_KEY, 0x31, {KEY_MAIL} },
	{ KE_KEY, 0x36, {KEY_WWW} },
	{ KE_KEY, 0x11, {KEY_PROG1} },
	{ KE_KEY, 0x12, {KEY_PROG2} },
	{ KE_KEY, 0x13, {KEY_PROG3} },
	{ KE_END, FE_MAIL_LED | FE_WIFI_LED | FE_UNTESTED }
};

546
static struct key_entry keymap_wistron_md2900[] __initdata = {
547 548 549 550 551 552 553 554 555 556
	{ KE_KEY, 0x01, {KEY_HELP} },
	{ KE_KEY, 0x02, {KEY_CONFIG} },
	{ KE_KEY, 0x11, {KEY_PROG1} },
	{ KE_KEY, 0x12, {KEY_PROG2} },
	{ KE_KEY, 0x31, {KEY_MAIL} },
	{ KE_KEY, 0x36, {KEY_WWW} },
	{ KE_WIFI, 0x30 },
	{ KE_END, FE_MAIL_LED | FE_UNTESTED }
};

557
static struct key_entry keymap_wistron_md96500[] __initdata = {
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
	{ KE_KEY, 0x01, {KEY_HELP} },
	{ KE_KEY, 0x02, {KEY_CONFIG} },
	{ KE_KEY, 0x05, {KEY_SWITCHVIDEOMODE} }, /* Display selection */
	{ KE_KEY, 0x06, {KEY_DISPLAYTOGGLE} }, /* Display on/off */
	{ KE_KEY, 0x08, {KEY_MUTE} },
	{ KE_KEY, 0x11, {KEY_PROG1} },
	{ KE_KEY, 0x12, {KEY_PROG2} },
	{ KE_KEY, 0x20, {KEY_VOLUMEUP} },
	{ KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
	{ KE_KEY, 0x22, {KEY_REWIND} },
	{ KE_KEY, 0x23, {KEY_FORWARD} },
	{ KE_KEY, 0x24, {KEY_PLAYPAUSE} },
	{ KE_KEY, 0x25, {KEY_STOPCD} },
	{ KE_KEY, 0x31, {KEY_MAIL} },
	{ KE_KEY, 0x36, {KEY_WWW} },
	{ KE_WIFI, 0x30 },
	{ KE_BLUETOOTH, 0x44 },
	{ KE_END, FE_UNTESTED }
576 577
};

578
static struct key_entry keymap_wistron_generic[] __initdata = {
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
	{ KE_KEY, 0x01, {KEY_HELP} },
	{ KE_KEY, 0x02, {KEY_CONFIG} },
	{ KE_KEY, 0x03, {KEY_POWER} },
	{ KE_KEY, 0x05, {KEY_SWITCHVIDEOMODE} }, /* Display selection */
	{ KE_KEY, 0x06, {KEY_DISPLAYTOGGLE} }, /* Display on/off */
	{ KE_KEY, 0x08, {KEY_MUTE} },
	{ KE_KEY, 0x11, {KEY_PROG1} },
	{ KE_KEY, 0x12, {KEY_PROG2} },
	{ KE_KEY, 0x13, {KEY_PROG3} },
	{ KE_KEY, 0x14, {KEY_MAIL} },
	{ KE_KEY, 0x15, {KEY_WWW} },
	{ KE_KEY, 0x20, {KEY_VOLUMEUP} },
	{ KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
	{ KE_KEY, 0x22, {KEY_REWIND} },
	{ KE_KEY, 0x23, {KEY_FORWARD} },
	{ KE_KEY, 0x24, {KEY_PLAYPAUSE} },
	{ KE_KEY, 0x25, {KEY_STOPCD} },
	{ KE_KEY, 0x31, {KEY_MAIL} },
	{ KE_KEY, 0x36, {KEY_WWW} },
	{ KE_KEY, 0x37, {KEY_DISPLAYTOGGLE} }, /* Display on/off */
	{ KE_KEY, 0x40, {KEY_WLAN} },
	{ KE_KEY, 0x49, {KEY_CONFIG} },
	{ KE_SW, 0x4a, {.sw = {SW_LID, 1}} }, /* lid close */
	{ KE_SW, 0x4b, {.sw = {SW_LID, 0}} }, /* lid open */
	{ KE_KEY, 0x6a, {KEY_CONFIG} },
	{ KE_KEY, 0x6d, {KEY_POWER} },
	{ KE_KEY, 0x71, {KEY_STOPCD} },
	{ KE_KEY, 0x72, {KEY_PLAYPAUSE} },
	{ KE_KEY, 0x74, {KEY_REWIND} },
	{ KE_KEY, 0x78, {KEY_FORWARD} },
	{ KE_WIFI, 0x30 },
	{ KE_BLUETOOTH, 0x44 },
	{ KE_END, 0 }
};

614 615 616 617 618 619 620 621 622 623 624 625 626 627
static struct key_entry keymap_aopen_1557[] __initdata = {
	{ KE_KEY,  0x01, {KEY_HELP} },
	{ KE_KEY,  0x11, {KEY_PROG1} },
	{ KE_KEY,  0x12, {KEY_PROG2} },
	{ KE_WIFI, 0x30 },
	{ KE_KEY,  0x22, {KEY_REWIND} },
	{ KE_KEY,  0x23, {KEY_FORWARD} },
	{ KE_KEY,  0x24, {KEY_PLAYPAUSE} },
	{ KE_KEY,  0x25, {KEY_STOPCD} },
	{ KE_KEY,  0x31, {KEY_MAIL} },
	{ KE_KEY,  0x36, {KEY_WWW} },
	{ KE_END,  0 }
};

628 629 630
static struct key_entry keymap_prestigio[] __initdata = {
	{ KE_KEY,  0x11, {KEY_PROG1} },
	{ KE_KEY,  0x12, {KEY_PROG2} },
631
	{ KE_WIFI, 0x30 },
632 633 634 635 636 637 638 639 640 641
	{ KE_KEY,  0x22, {KEY_REWIND} },
	{ KE_KEY,  0x23, {KEY_FORWARD} },
	{ KE_KEY,  0x24, {KEY_PLAYPAUSE} },
	{ KE_KEY,  0x25, {KEY_STOPCD} },
	{ KE_KEY,  0x31, {KEY_MAIL} },
	{ KE_KEY,  0x36, {KEY_WWW} },
	{ KE_END,  0 }
};


D
Dmitry Torokhov 已提交
642 643 644 645 646
/*
 * If your machine is not here (which is currently rather likely), please send
 * a list of buttons and their key codes (reported when loading this module
 * with force=1) and the output of dmidecode to $MODULE_AUTHOR.
 */
647
static struct dmi_system_id dmi_ids[] __initdata = {
D
Dmitry Torokhov 已提交
648 649 650 651 652 653 654 655 656
	{
		.callback = dmi_matched,
		.ident = "Fujitsu-Siemens Amilo Pro V2000",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
			DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pro V2000"),
		},
		.driver_data = keymap_fs_amilo_pro_v2000
	},
657 658 659 660 661 662 663 664 665
	{
		.callback = dmi_matched,
		.ident = "Fujitsu-Siemens Amilo Pro Edition V3505",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
			DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pro Edition V3505"),
		},
		.driver_data = keymap_fs_amilo_pro_v3505
	},
666 667 668 669 670 671 672 673 674
	{
		.callback = dmi_matched,
		.ident = "Fujitsu-Siemens Amilo M7400",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
			DMI_MATCH(DMI_PRODUCT_NAME, "AMILO M        "),
		},
		.driver_data = keymap_fs_amilo_pro_v2000
	},
675 676 677 678 679 680 681 682 683
	{
		.callback = dmi_matched,
		.ident = "Maxdata Pro 7000 DX",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "MAXDATA"),
			DMI_MATCH(DMI_PRODUCT_NAME, "Pro 7000"),
		},
		.driver_data = keymap_fs_amilo_pro_v2000
	},
684 685 686 687 688 689 690 691 692
	{
		.callback = dmi_matched,
		.ident = "Fujitsu N3510",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
			DMI_MATCH(DMI_PRODUCT_NAME, "N3510"),
		},
		.driver_data = keymap_fujitsu_n3510
	},
693 694 695 696 697 698 699 700 701
	{
		.callback = dmi_matched,
		.ident = "Acer Aspire 1500",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1500"),
		},
		.driver_data = keymap_acer_aspire_1500
	},
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828
	{
		.callback = dmi_matched,
		.ident = "Acer Aspire 1600",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1600"),
		},
		.driver_data = keymap_acer_aspire_1600
	},
	{
		.callback = dmi_matched,
		.ident = "Acer Aspire 3020",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3020"),
		},
		.driver_data = keymap_acer_aspire_5020
	},
	{
		.callback = dmi_matched,
		.ident = "Acer Aspire 5020",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5020"),
		},
		.driver_data = keymap_acer_aspire_5020
	},
	{
		.callback = dmi_matched,
		.ident = "Acer TravelMate 2100",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
			DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2100"),
		},
		.driver_data = keymap_acer_aspire_5020
	},
	{
		.callback = dmi_matched,
		.ident = "Acer TravelMate 2410",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
			DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2410"),
		},
		.driver_data = keymap_acer_travelmate_2410
	},
	{
		.callback = dmi_matched,
		.ident = "Acer TravelMate C300",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
			DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate C300"),
		},
		.driver_data = keymap_acer_travelmate_300
	},
	{
		.callback = dmi_matched,
		.ident = "Acer TravelMate C100",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
			DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate C100"),
		},
		.driver_data = keymap_acer_travelmate_300
	},
	{
		.callback = dmi_matched,
		.ident = "Acer TravelMate C110",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
			DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate C110"),
		},
		.driver_data = keymap_acer_travelmate_110
	},
	{
		.callback = dmi_matched,
		.ident = "Acer TravelMate 380",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
			DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 380"),
		},
		.driver_data = keymap_acer_travelmate_380
	},
	{
		.callback = dmi_matched,
		.ident = "Acer TravelMate 370",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
			DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 370"),
		},
		.driver_data = keymap_acer_travelmate_380 /* keyboard minus 1 key */
	},
	{
		.callback = dmi_matched,
		.ident = "Acer TravelMate 220",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
			DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 220"),
		},
		.driver_data = keymap_acer_travelmate_220
	},
	{
		.callback = dmi_matched,
		.ident = "Acer TravelMate 260",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
			DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 260"),
		},
		.driver_data = keymap_acer_travelmate_220
	},
	{
		.callback = dmi_matched,
		.ident = "Acer TravelMate 230",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
			DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 230"),
			/* acerhk looks for "TravelMate F4..." ?! */
		},
		.driver_data = keymap_acer_travelmate_230
	},
	{
		.callback = dmi_matched,
		.ident = "Acer TravelMate 280",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
			DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 280"),
		},
		.driver_data = keymap_acer_travelmate_230
	},
829 830 831 832 833 834 835 836 837
	{
		.callback = dmi_matched,
		.ident = "Acer TravelMate 240",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
			DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 240"),
		},
		.driver_data = keymap_acer_travelmate_240
	},
838 839 840 841 842 843 844 845 846
	{
		.callback = dmi_matched,
		.ident = "Acer TravelMate 250",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
			DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 250"),
		},
		.driver_data = keymap_acer_travelmate_240
	},
847 848 849 850 851 852 853 854 855
	{
		.callback = dmi_matched,
		.ident = "Acer TravelMate 2424NWXCi",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
			DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2420"),
		},
		.driver_data = keymap_acer_travelmate_240
	},
856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873
	{
		.callback = dmi_matched,
		.ident = "Acer TravelMate 350",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
			DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 350"),
		},
		.driver_data = keymap_acer_travelmate_350
	},
	{
		.callback = dmi_matched,
		.ident = "Acer TravelMate 360",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
			DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
		},
		.driver_data = keymap_acer_travelmate_360
	},
874 875 876 877 878 879 880 881 882
	{
		.callback = dmi_matched,
		.ident = "Acer TravelMate 610",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "ACER"),
			DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 610"),
		},
		.driver_data = keymap_acer_travelmate_610
	},
883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900
	{
		.callback = dmi_matched,
		.ident = "Acer TravelMate 620",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
			DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 620"),
		},
		.driver_data = keymap_acer_travelmate_630
	},
	{
		.callback = dmi_matched,
		.ident = "Acer TravelMate 630",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
			DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 630"),
		},
		.driver_data = keymap_acer_travelmate_630
	},
901
	{
902 903 904 905 906 907 908 909
		.callback = dmi_matched,
		.ident = "AOpen 1559AS",
		.matches = {
			DMI_MATCH(DMI_PRODUCT_NAME, "E2U"),
			DMI_MATCH(DMI_BOARD_NAME, "E2U"),
		},
		.driver_data = keymap_aopen_1559as
	},
910 911 912 913 914 915 916 917 918
	{
		.callback = dmi_matched,
		.ident = "Medion MD 9783",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
			DMI_MATCH(DMI_PRODUCT_NAME, "MD 9783"),
		},
		.driver_data = keymap_wistron_ms2111
	},
919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936
	{
		.callback = dmi_matched,
		.ident = "Medion MD 40100",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
			DMI_MATCH(DMI_PRODUCT_NAME, "WID2000"),
		},
		.driver_data = keymap_wistron_md40100
	},
	{
		.callback = dmi_matched,
		.ident = "Medion MD 2900",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
			DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2000"),
		},
		.driver_data = keymap_wistron_md2900
	},
937 938 939 940 941 942 943 944 945
	{
		.callback = dmi_matched,
		.ident = "Medion MD 42200",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "Medion"),
			DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2030"),
		},
		.driver_data = keymap_fs_amilo_pro_v2000
	},
946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972
	{
		.callback = dmi_matched,
		.ident = "Medion MD 96500",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "MEDIONPC"),
			DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2040"),
		},
		.driver_data = keymap_wistron_md96500
	},
	{
		.callback = dmi_matched,
		.ident = "Medion MD 95400",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "MEDIONPC"),
			DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2050"),
		},
		.driver_data = keymap_wistron_md96500
	},
	{
		.callback = dmi_matched,
		.ident = "Fujitsu Siemens Amilo D7820",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"), /* not sure */
			DMI_MATCH(DMI_PRODUCT_NAME, "Amilo D"),
		},
		.driver_data = keymap_fs_amilo_d88x0
	},
973 974 975 976 977 978 979 980 981
	{
		.callback = dmi_matched,
		.ident = "Fujitsu Siemens Amilo D88x0",
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
			DMI_MATCH(DMI_PRODUCT_NAME, "AMILO D"),
		},
		.driver_data = keymap_fs_amilo_d88x0
	},
982
	{ NULL, }
D
Dmitry Torokhov 已提交
983 984
};

985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004
/* Copy the good keymap, as the original ones are free'd */
static int __init copy_keymap(void)
{
	const struct key_entry *key;
	struct key_entry *new_keymap;
	unsigned int length = 1;

	for (key = keymap; key->type != KE_END; key++)
		length++;

	new_keymap = kmalloc(length * sizeof(struct key_entry), GFP_KERNEL);
	if (!new_keymap)
		return -ENOMEM;

	memcpy(new_keymap, keymap, length * sizeof(struct key_entry));
	keymap = new_keymap;

	return 0;
}

D
Dmitry Torokhov 已提交
1005 1006
static int __init select_keymap(void)
{
1007
	dmi_check_system(dmi_ids);
D
Dmitry Torokhov 已提交
1008 1009 1010
	if (keymap_name != NULL) {
		if (strcmp (keymap_name, "1557/MS2141") == 0)
			keymap = keymap_wistron_ms2141;
1011 1012
		else if (strcmp (keymap_name, "aopen1557") == 0)
			keymap = keymap_aopen_1557;
1013 1014
		else if (strcmp (keymap_name, "prestigio") == 0)
			keymap = keymap_prestigio;
1015 1016
		else if (strcmp (keymap_name, "generic") == 0)
			keymap = keymap_wistron_generic;
D
Dmitry Torokhov 已提交
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028
		else {
			printk(KERN_ERR "wistron_btns: Keymap unknown\n");
			return -EINVAL;
		}
	}
	if (keymap == NULL) {
		if (!force) {
			printk(KERN_ERR "wistron_btns: System unknown\n");
			return -ENODEV;
		}
		keymap = keymap_empty;
	}
1029 1030

	return copy_keymap();
D
Dmitry Torokhov 已提交
1031 1032 1033 1034
}

 /* Input layer interface */

1035 1036
static struct input_polled_dev *wistron_idev;
static unsigned long jiffies_last_press;
1037 1038
static bool wifi_enabled;
static bool bluetooth_enabled;
D
Dmitry Torokhov 已提交
1039

1040
static void report_key(struct input_dev *dev, unsigned int keycode)
D
Dmitry Torokhov 已提交
1041
{
1042 1043 1044 1045
	input_report_key(dev, keycode, 1);
	input_sync(dev);
	input_report_key(dev, keycode, 0);
	input_sync(dev);
D
Dmitry Torokhov 已提交
1046 1047
}

1048
static void report_switch(struct input_dev *dev, unsigned int code, int value)
1049
{
1050 1051
	input_report_switch(dev, code, value);
	input_sync(dev);
1052 1053
}

E
Eric Piel 已提交
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069

 /* led management */
static void wistron_mail_led_set(struct led_classdev *led_cdev,
				enum led_brightness value)
{
	bios_set_state(MAIL_LED, (value != LED_OFF) ? 1 : 0);
}

/* same as setting up wifi card, but for laptops on which the led is managed */
static void wistron_wifi_led_set(struct led_classdev *led_cdev,
				enum led_brightness value)
{
	bios_set_state(WIFI, (value != LED_OFF) ? 1 : 0);
}

static struct led_classdev wistron_mail_led = {
1070
	.name			= "wistron:green:mail",
E
Eric Piel 已提交
1071 1072 1073 1074
	.brightness_set		= wistron_mail_led_set,
};

static struct led_classdev wistron_wifi_led = {
1075
	.name			= "wistron:red:wifi",
E
Eric Piel 已提交
1076 1077 1078 1079 1080
	.brightness_set		= wistron_wifi_led_set,
};

static void __devinit wistron_led_init(struct device *parent)
{
1081
	if (leds_present & FE_WIFI_LED) {
E
Eric Piel 已提交
1082 1083 1084 1085
		u16 wifi = bios_get_default_setting(WIFI);
		if (wifi & 1) {
			wistron_wifi_led.brightness = (wifi & 2) ? LED_FULL : LED_OFF;
			if (led_classdev_register(parent, &wistron_wifi_led))
1086
				leds_present &= ~FE_WIFI_LED;
E
Eric Piel 已提交
1087 1088 1089 1090
			else
				bios_set_state(WIFI, wistron_wifi_led.brightness);

		} else
1091
			leds_present &= ~FE_WIFI_LED;
E
Eric Piel 已提交
1092 1093
	}

1094
	if (leds_present & FE_MAIL_LED) {
E
Eric Piel 已提交
1095 1096 1097
		/* bios_get_default_setting(MAIL) always retuns 0, so just turn the led off */
		wistron_mail_led.brightness = LED_OFF;
		if (led_classdev_register(parent, &wistron_mail_led))
1098
			leds_present &= ~FE_MAIL_LED;
E
Eric Piel 已提交
1099 1100 1101 1102 1103 1104 1105
		else
			bios_set_state(MAIL_LED, wistron_mail_led.brightness);
	}
}

static void __devexit wistron_led_remove(void)
{
1106
	if (leds_present & FE_MAIL_LED)
E
Eric Piel 已提交
1107 1108
		led_classdev_unregister(&wistron_mail_led);

1109
	if (leds_present & FE_WIFI_LED)
E
Eric Piel 已提交
1110 1111 1112 1113 1114
		led_classdev_unregister(&wistron_wifi_led);
}

static inline void wistron_led_suspend(void)
{
1115
	if (leds_present & FE_MAIL_LED)
E
Eric Piel 已提交
1116 1117
		led_classdev_suspend(&wistron_mail_led);

1118
	if (leds_present & FE_WIFI_LED)
E
Eric Piel 已提交
1119 1120 1121 1122 1123
		led_classdev_suspend(&wistron_wifi_led);
}

static inline void wistron_led_resume(void)
{
1124
	if (leds_present & FE_MAIL_LED)
E
Eric Piel 已提交
1125 1126
		led_classdev_resume(&wistron_mail_led);

1127
	if (leds_present & FE_WIFI_LED)
E
Eric Piel 已提交
1128 1129 1130
		led_classdev_resume(&wistron_wifi_led);
}

1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152
static struct key_entry *wistron_get_entry_by_scancode(int code)
{
	struct key_entry *key;

	for (key = keymap; key->type != KE_END; key++)
		if (code == key->code)
			return key;

	return NULL;
}

static struct key_entry *wistron_get_entry_by_keycode(int keycode)
{
	struct key_entry *key;

	for (key = keymap; key->type != KE_END; key++)
		if (key->type == KE_KEY && keycode == key->keycode)
			return key;

	return NULL;
}

D
Dmitry Torokhov 已提交
1153 1154
static void handle_key(u8 code)
{
1155
	const struct key_entry *key = wistron_get_entry_by_scancode(code);
D
Dmitry Torokhov 已提交
1156

1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171
	if (key) {
		switch (key->type) {
		case KE_KEY:
			report_key(wistron_idev->input, key->keycode);
			break;

		case KE_SW:
			report_switch(wistron_idev->input,
				      key->sw.code, key->sw.value);
			break;

		case KE_WIFI:
			if (have_wifi) {
				wifi_enabled = !wifi_enabled;
				bios_set_state(WIFI, wifi_enabled);
D
Dmitry Torokhov 已提交
1172
			}
1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183
			break;

		case KE_BLUETOOTH:
			if (have_bluetooth) {
				bluetooth_enabled = !bluetooth_enabled;
				bios_set_state(BLUETOOTH, bluetooth_enabled);
			}
			break;

		default:
			BUG();
D
Dmitry Torokhov 已提交
1184
		}
1185 1186 1187 1188
		jiffies_last_press = jiffies;
	} else
		printk(KERN_NOTICE
			"wistron_btns: Unknown key code %02X\n", code);
D
Dmitry Torokhov 已提交
1189 1190
}

1191
static void poll_bios(bool discard)
D
Dmitry Torokhov 已提交
1192 1193 1194 1195 1196 1197 1198 1199 1200
{
	u8 qlen;
	u16 val;

	for (;;) {
		qlen = CMOS_READ(cmos_address);
		if (qlen == 0)
			break;
		val = bios_pop_queue();
1201
		if (val != 0 && !discard)
D
Dmitry Torokhov 已提交
1202 1203
			handle_key((u8)val);
	}
1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214
}

static void wistron_flush(struct input_polled_dev *dev)
{
	/* Flush stale event queue */
	poll_bios(true);
}

static void wistron_poll(struct input_polled_dev *dev)
{
	poll_bios(false);
D
Dmitry Torokhov 已提交
1215

1216 1217 1218
	/* Increase poll frequency if user is currently pressing keys (< 2s ago) */
	if (time_before(jiffies, jiffies_last_press + 2 * HZ))
		dev->poll_interval = POLL_INTERVAL_BURST;
1219
	else
1220
		dev->poll_interval = POLL_INTERVAL_DEFAULT;
D
Dmitry Torokhov 已提交
1221 1222
}

1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255
static int wistron_getkeycode(struct input_dev *dev, int scancode, int *keycode)
{
	const struct key_entry *key = wistron_get_entry_by_scancode(scancode);

	if (key && key->type == KE_KEY) {
		*keycode = key->keycode;
		return 0;
	}

	return -EINVAL;
}

static int wistron_setkeycode(struct input_dev *dev, int scancode, int keycode)
{
	struct key_entry *key;
	int old_keycode;

	if (keycode < 0 || keycode > KEY_MAX)
		return -EINVAL;

	key = wistron_get_entry_by_scancode(scancode);
	if (key && key->type == KE_KEY) {
		old_keycode = key->keycode;
		key->keycode = keycode;
		set_bit(keycode, dev->keybit);
		if (!wistron_get_entry_by_keycode(old_keycode))
			clear_bit(old_keycode, dev->keybit);
		return 0;
	}

	return -EINVAL;
}

1256 1257
static int __devinit setup_input_dev(void)
{
1258
	struct key_entry *key;
1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273
	struct input_dev *input_dev;
	int error;

	wistron_idev = input_allocate_polled_device();
	if (!wistron_idev)
		return -ENOMEM;

	wistron_idev->flush = wistron_flush;
	wistron_idev->poll = wistron_poll;
	wistron_idev->poll_interval = POLL_INTERVAL_DEFAULT;

	input_dev = wistron_idev->input;
	input_dev->name = "Wistron laptop buttons";
	input_dev->phys = "wistron/input0";
	input_dev->id.bustype = BUS_HOST;
1274 1275 1276 1277
	input_dev->dev.parent = &wistron_device->dev;

	input_dev->getkeycode = wistron_getkeycode;
	input_dev->setkeycode = wistron_setkeycode;
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290

	for (key = keymap; key->type != KE_END; key++) {
		switch (key->type) {
			case KE_KEY:
				set_bit(EV_KEY, input_dev->evbit);
				set_bit(key->keycode, input_dev->keybit);
				break;

			case KE_SW:
				set_bit(EV_SW, input_dev->evbit);
				set_bit(key->sw.code, input_dev->swbit);
				break;

1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307
			/* if wifi or bluetooth are not available, create normal keys */
			case KE_WIFI:
				if (!have_wifi) {
					key->type = KE_KEY;
					key->keycode = KEY_WLAN;
					key--;
				}
				break;

			case KE_BLUETOOTH:
				if (!have_bluetooth) {
					key->type = KE_KEY;
					key->keycode = KEY_BLUETOOTH;
					key--;
				}
				break;

1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329
			default:
				break;
		}
	}

	/* reads information flags on KE_END */
	if (key->code & FE_UNTESTED)
		printk(KERN_WARNING "Untested laptop multimedia keys, "
			"please report success or failure to eric.piel"
			"@tremplin-utc.net\n");

	error = input_register_polled_device(wistron_idev);
	if (error) {
		input_free_polled_device(wistron_idev);
		return error;
	}

	return 0;
}

/* Driver core */

1330 1331
static int __devinit wistron_probe(struct platform_device *dev)
{
1332
	int err;
1333 1334 1335 1336 1337 1338 1339

	bios_attach();
	cmos_address = bios_get_cmos_address();

	if (have_wifi) {
		u16 wifi = bios_get_default_setting(WIFI);
		if (wifi & 1)
1340
			wifi_enabled = wifi & 2;
1341 1342 1343 1344 1345 1346 1347 1348 1349 1350
		else
			have_wifi = 0;

		if (have_wifi)
			bios_set_state(WIFI, wifi_enabled);
	}

	if (have_bluetooth) {
		u16 bt = bios_get_default_setting(BLUETOOTH);
		if (bt & 1)
1351
			bluetooth_enabled = bt & 2;
1352
		else
1353
			have_bluetooth = false;
1354 1355 1356 1357 1358

		if (have_bluetooth)
			bios_set_state(BLUETOOTH, bluetooth_enabled);
	}

E
Eric Piel 已提交
1359
	wistron_led_init(&dev->dev);
1360

1361 1362 1363 1364 1365
	err = setup_input_dev();
	if (err) {
		bios_detach();
		return err;
	}
1366 1367 1368 1369 1370 1371

	return 0;
}

static int __devexit wistron_remove(struct platform_device *dev)
{
E
Eric Piel 已提交
1372
	wistron_led_remove();
1373 1374
	input_unregister_polled_device(wistron_idev);
	input_free_polled_device(wistron_idev);
1375 1376 1377 1378 1379 1380
	bios_detach();

	return 0;
}

#ifdef CONFIG_PM
1381
static int wistron_suspend(struct device *dev)
D
Dmitry Torokhov 已提交
1382
{
1383 1384 1385 1386 1387 1388
	if (have_wifi)
		bios_set_state(WIFI, 0);

	if (have_bluetooth)
		bios_set_state(BLUETOOTH, 0);

E
Eric Piel 已提交
1389
	wistron_led_suspend();
1390

D
Dmitry Torokhov 已提交
1391 1392 1393
	return 0;
}

1394
static int wistron_resume(struct device *dev)
D
Dmitry Torokhov 已提交
1395 1396 1397 1398 1399 1400 1401
{
	if (have_wifi)
		bios_set_state(WIFI, wifi_enabled);

	if (have_bluetooth)
		bios_set_state(BLUETOOTH, bluetooth_enabled);

E
Eric Piel 已提交
1402
	wistron_led_resume();
1403

1404
	poll_bios(true);
D
Dmitry Torokhov 已提交
1405 1406 1407

	return 0;
}
1408 1409 1410 1411 1412 1413 1414

static const struct dev_pm_ops wistron_pm_ops = {
	.suspend	= wistron_suspend,
	.resume		= wistron_resume,
	.poweroff	= wistron_suspend,
	.restore	= wistron_resume,
};
1415
#endif
D
Dmitry Torokhov 已提交
1416 1417 1418 1419

static struct platform_driver wistron_driver = {
	.driver		= {
		.name	= "wistron-bios",
1420
		.owner	= THIS_MODULE,
1421 1422 1423
#if CONFIG_PM
		.pm	= &wistron_pm_ops,
#endif
D
Dmitry Torokhov 已提交
1424
	},
1425 1426
	.probe		= wistron_probe,
	.remove		= __devexit_p(wistron_remove),
D
Dmitry Torokhov 已提交
1427 1428
};

D
Dmitry Torokhov 已提交
1429 1430 1431 1432 1433 1434 1435
static int __init wb_module_init(void)
{
	int err;

	err = select_keymap();
	if (err)
		return err;
1436

D
Dmitry Torokhov 已提交
1437 1438 1439
	err = map_bios();
	if (err)
		return err;
1440

D
Dmitry Torokhov 已提交
1441 1442
	err = platform_driver_register(&wistron_driver);
	if (err)
1443
		goto err_unmap_bios;
D
Dmitry Torokhov 已提交
1444

1445 1446 1447
	wistron_device = platform_device_alloc("wistron-bios", -1);
	if (!wistron_device) {
		err = -ENOMEM;
D
Dmitry Torokhov 已提交
1448 1449 1450
		goto err_unregister_driver;
	}

1451
	err = platform_device_add(wistron_device);
D
Dmitry Torokhov 已提交
1452
	if (err)
1453
		goto err_free_device;
D
Dmitry Torokhov 已提交
1454 1455

	return 0;
D
Dmitry Torokhov 已提交
1456

1457 1458
 err_free_device:
	platform_device_put(wistron_device);
D
Dmitry Torokhov 已提交
1459 1460
 err_unregister_driver:
	platform_driver_unregister(&wistron_driver);
1461
 err_unmap_bios:
D
Dmitry Torokhov 已提交
1462 1463 1464
	unmap_bios();

	return err;
D
Dmitry Torokhov 已提交
1465 1466 1467 1468
}

static void __exit wb_module_exit(void)
{
D
Dmitry Torokhov 已提交
1469 1470
	platform_device_unregister(wistron_device);
	platform_driver_unregister(&wistron_driver);
D
Dmitry Torokhov 已提交
1471
	unmap_bios();
1472
	kfree(keymap);
D
Dmitry Torokhov 已提交
1473 1474 1475 1476
}

module_init(wb_module_init);
module_exit(wb_module_exit);