wistron_btns.c 36 KB

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