wistron_btns.c 34 KB

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