wistron_btns.c 34 KB

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