wistron_btns.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443
  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 int have_wifi;
  206. static int have_bluetooth;
  207. static int have_leds;
  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 = 1;
  215. else if (key->type == KE_BLUETOOTH)
  216. have_bluetooth = 1;
  217. }
  218. have_leds = 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_prestigio[] __initdata = {
  544. { KE_KEY, 0x11, {KEY_PROG1} },
  545. { KE_KEY, 0x12, {KEY_PROG2} },
  546. { KE_WIFI, 0x30 },
  547. { KE_KEY, 0x22, {KEY_REWIND} },
  548. { KE_KEY, 0x23, {KEY_FORWARD} },
  549. { KE_KEY, 0x24, {KEY_PLAYPAUSE} },
  550. { KE_KEY, 0x25, {KEY_STOPCD} },
  551. { KE_KEY, 0x31, {KEY_MAIL} },
  552. { KE_KEY, 0x36, {KEY_WWW} },
  553. { KE_END, 0 }
  554. };
  555. /*
  556. * If your machine is not here (which is currently rather likely), please send
  557. * a list of buttons and their key codes (reported when loading this module
  558. * with force=1) and the output of dmidecode to $MODULE_AUTHOR.
  559. */
  560. static struct dmi_system_id dmi_ids[] __initdata = {
  561. {
  562. .callback = dmi_matched,
  563. .ident = "Fujitsu-Siemens Amilo Pro V2000",
  564. .matches = {
  565. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
  566. DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pro V2000"),
  567. },
  568. .driver_data = keymap_fs_amilo_pro_v2000
  569. },
  570. {
  571. .callback = dmi_matched,
  572. .ident = "Fujitsu-Siemens Amilo Pro Edition V3505",
  573. .matches = {
  574. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
  575. DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pro Edition V3505"),
  576. },
  577. .driver_data = keymap_fs_amilo_pro_v3505
  578. },
  579. {
  580. .callback = dmi_matched,
  581. .ident = "Fujitsu-Siemens Amilo M7400",
  582. .matches = {
  583. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
  584. DMI_MATCH(DMI_PRODUCT_NAME, "AMILO M "),
  585. },
  586. .driver_data = keymap_fs_amilo_pro_v2000
  587. },
  588. {
  589. .callback = dmi_matched,
  590. .ident = "Maxdata Pro 7000 DX",
  591. .matches = {
  592. DMI_MATCH(DMI_SYS_VENDOR, "MAXDATA"),
  593. DMI_MATCH(DMI_PRODUCT_NAME, "Pro 7000"),
  594. },
  595. .driver_data = keymap_fs_amilo_pro_v2000
  596. },
  597. {
  598. .callback = dmi_matched,
  599. .ident = "Fujitsu N3510",
  600. .matches = {
  601. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
  602. DMI_MATCH(DMI_PRODUCT_NAME, "N3510"),
  603. },
  604. .driver_data = keymap_fujitsu_n3510
  605. },
  606. {
  607. .callback = dmi_matched,
  608. .ident = "Acer Aspire 1500",
  609. .matches = {
  610. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  611. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1500"),
  612. },
  613. .driver_data = keymap_acer_aspire_1500
  614. },
  615. {
  616. .callback = dmi_matched,
  617. .ident = "Acer Aspire 1600",
  618. .matches = {
  619. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  620. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1600"),
  621. },
  622. .driver_data = keymap_acer_aspire_1600
  623. },
  624. {
  625. .callback = dmi_matched,
  626. .ident = "Acer Aspire 3020",
  627. .matches = {
  628. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  629. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3020"),
  630. },
  631. .driver_data = keymap_acer_aspire_5020
  632. },
  633. {
  634. .callback = dmi_matched,
  635. .ident = "Acer Aspire 5020",
  636. .matches = {
  637. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  638. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5020"),
  639. },
  640. .driver_data = keymap_acer_aspire_5020
  641. },
  642. {
  643. .callback = dmi_matched,
  644. .ident = "Acer TravelMate 2100",
  645. .matches = {
  646. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  647. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2100"),
  648. },
  649. .driver_data = keymap_acer_aspire_5020
  650. },
  651. {
  652. .callback = dmi_matched,
  653. .ident = "Acer TravelMate 2410",
  654. .matches = {
  655. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  656. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2410"),
  657. },
  658. .driver_data = keymap_acer_travelmate_2410
  659. },
  660. {
  661. .callback = dmi_matched,
  662. .ident = "Acer TravelMate C300",
  663. .matches = {
  664. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  665. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate C300"),
  666. },
  667. .driver_data = keymap_acer_travelmate_300
  668. },
  669. {
  670. .callback = dmi_matched,
  671. .ident = "Acer TravelMate C100",
  672. .matches = {
  673. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  674. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate C100"),
  675. },
  676. .driver_data = keymap_acer_travelmate_300
  677. },
  678. {
  679. .callback = dmi_matched,
  680. .ident = "Acer TravelMate C110",
  681. .matches = {
  682. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  683. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate C110"),
  684. },
  685. .driver_data = keymap_acer_travelmate_110
  686. },
  687. {
  688. .callback = dmi_matched,
  689. .ident = "Acer TravelMate 380",
  690. .matches = {
  691. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  692. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 380"),
  693. },
  694. .driver_data = keymap_acer_travelmate_380
  695. },
  696. {
  697. .callback = dmi_matched,
  698. .ident = "Acer TravelMate 370",
  699. .matches = {
  700. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  701. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 370"),
  702. },
  703. .driver_data = keymap_acer_travelmate_380 /* keyboard minus 1 key */
  704. },
  705. {
  706. .callback = dmi_matched,
  707. .ident = "Acer TravelMate 220",
  708. .matches = {
  709. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  710. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 220"),
  711. },
  712. .driver_data = keymap_acer_travelmate_220
  713. },
  714. {
  715. .callback = dmi_matched,
  716. .ident = "Acer TravelMate 260",
  717. .matches = {
  718. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  719. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 260"),
  720. },
  721. .driver_data = keymap_acer_travelmate_220
  722. },
  723. {
  724. .callback = dmi_matched,
  725. .ident = "Acer TravelMate 230",
  726. .matches = {
  727. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  728. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 230"),
  729. /* acerhk looks for "TravelMate F4..." ?! */
  730. },
  731. .driver_data = keymap_acer_travelmate_230
  732. },
  733. {
  734. .callback = dmi_matched,
  735. .ident = "Acer TravelMate 280",
  736. .matches = {
  737. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  738. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 280"),
  739. },
  740. .driver_data = keymap_acer_travelmate_230
  741. },
  742. {
  743. .callback = dmi_matched,
  744. .ident = "Acer TravelMate 240",
  745. .matches = {
  746. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  747. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 240"),
  748. },
  749. .driver_data = keymap_acer_travelmate_240
  750. },
  751. {
  752. .callback = dmi_matched,
  753. .ident = "Acer TravelMate 250",
  754. .matches = {
  755. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  756. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 250"),
  757. },
  758. .driver_data = keymap_acer_travelmate_240
  759. },
  760. {
  761. .callback = dmi_matched,
  762. .ident = "Acer TravelMate 2424NWXCi",
  763. .matches = {
  764. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  765. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2420"),
  766. },
  767. .driver_data = keymap_acer_travelmate_240
  768. },
  769. {
  770. .callback = dmi_matched,
  771. .ident = "Acer TravelMate 350",
  772. .matches = {
  773. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  774. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 350"),
  775. },
  776. .driver_data = keymap_acer_travelmate_350
  777. },
  778. {
  779. .callback = dmi_matched,
  780. .ident = "Acer TravelMate 360",
  781. .matches = {
  782. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  783. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
  784. },
  785. .driver_data = keymap_acer_travelmate_360
  786. },
  787. {
  788. .callback = dmi_matched,
  789. .ident = "Acer TravelMate 610",
  790. .matches = {
  791. DMI_MATCH(DMI_SYS_VENDOR, "ACER"),
  792. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 610"),
  793. },
  794. .driver_data = keymap_acer_travelmate_610
  795. },
  796. {
  797. .callback = dmi_matched,
  798. .ident = "Acer TravelMate 620",
  799. .matches = {
  800. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  801. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 620"),
  802. },
  803. .driver_data = keymap_acer_travelmate_630
  804. },
  805. {
  806. .callback = dmi_matched,
  807. .ident = "Acer TravelMate 630",
  808. .matches = {
  809. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  810. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 630"),
  811. },
  812. .driver_data = keymap_acer_travelmate_630
  813. },
  814. {
  815. .callback = dmi_matched,
  816. .ident = "AOpen 1559AS",
  817. .matches = {
  818. DMI_MATCH(DMI_PRODUCT_NAME, "E2U"),
  819. DMI_MATCH(DMI_BOARD_NAME, "E2U"),
  820. },
  821. .driver_data = keymap_aopen_1559as
  822. },
  823. {
  824. .callback = dmi_matched,
  825. .ident = "Medion MD 9783",
  826. .matches = {
  827. DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
  828. DMI_MATCH(DMI_PRODUCT_NAME, "MD 9783"),
  829. },
  830. .driver_data = keymap_wistron_ms2111
  831. },
  832. {
  833. .callback = dmi_matched,
  834. .ident = "Medion MD 40100",
  835. .matches = {
  836. DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
  837. DMI_MATCH(DMI_PRODUCT_NAME, "WID2000"),
  838. },
  839. .driver_data = keymap_wistron_md40100
  840. },
  841. {
  842. .callback = dmi_matched,
  843. .ident = "Medion MD 2900",
  844. .matches = {
  845. DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
  846. DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2000"),
  847. },
  848. .driver_data = keymap_wistron_md2900
  849. },
  850. {
  851. .callback = dmi_matched,
  852. .ident = "Medion MD 96500",
  853. .matches = {
  854. DMI_MATCH(DMI_SYS_VENDOR, "MEDIONPC"),
  855. DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2040"),
  856. },
  857. .driver_data = keymap_wistron_md96500
  858. },
  859. {
  860. .callback = dmi_matched,
  861. .ident = "Medion MD 95400",
  862. .matches = {
  863. DMI_MATCH(DMI_SYS_VENDOR, "MEDIONPC"),
  864. DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2050"),
  865. },
  866. .driver_data = keymap_wistron_md96500
  867. },
  868. {
  869. .callback = dmi_matched,
  870. .ident = "Fujitsu Siemens Amilo D7820",
  871. .matches = {
  872. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"), /* not sure */
  873. DMI_MATCH(DMI_PRODUCT_NAME, "Amilo D"),
  874. },
  875. .driver_data = keymap_fs_amilo_d88x0
  876. },
  877. {
  878. .callback = dmi_matched,
  879. .ident = "Fujitsu Siemens Amilo D88x0",
  880. .matches = {
  881. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
  882. DMI_MATCH(DMI_PRODUCT_NAME, "AMILO D"),
  883. },
  884. .driver_data = keymap_fs_amilo_d88x0
  885. },
  886. { NULL, }
  887. };
  888. /* Copy the good keymap, as the original ones are free'd */
  889. static int __init copy_keymap(void)
  890. {
  891. const struct key_entry *key;
  892. struct key_entry *new_keymap;
  893. unsigned int length = 1;
  894. for (key = keymap; key->type != KE_END; key++)
  895. length++;
  896. new_keymap = kmalloc(length * sizeof(struct key_entry), GFP_KERNEL);
  897. if (!new_keymap)
  898. return -ENOMEM;
  899. memcpy(new_keymap, keymap, length * sizeof(struct key_entry));
  900. keymap = new_keymap;
  901. return 0;
  902. }
  903. static int __init select_keymap(void)
  904. {
  905. dmi_check_system(dmi_ids);
  906. if (keymap_name != NULL) {
  907. if (strcmp (keymap_name, "1557/MS2141") == 0)
  908. keymap = keymap_wistron_ms2141;
  909. else if (strcmp (keymap_name, "prestigio") == 0)
  910. keymap = keymap_prestigio;
  911. else if (strcmp (keymap_name, "generic") == 0)
  912. keymap = keymap_wistron_generic;
  913. else {
  914. printk(KERN_ERR "wistron_btns: Keymap unknown\n");
  915. return -EINVAL;
  916. }
  917. }
  918. if (keymap == NULL) {
  919. if (!force) {
  920. printk(KERN_ERR "wistron_btns: System unknown\n");
  921. return -ENODEV;
  922. }
  923. keymap = keymap_empty;
  924. }
  925. return copy_keymap();
  926. }
  927. /* Input layer interface */
  928. static struct input_polled_dev *wistron_idev;
  929. static unsigned long jiffies_last_press;
  930. static int wifi_enabled;
  931. static int bluetooth_enabled;
  932. static void report_key(struct input_dev *dev, unsigned int keycode)
  933. {
  934. input_report_key(dev, keycode, 1);
  935. input_sync(dev);
  936. input_report_key(dev, keycode, 0);
  937. input_sync(dev);
  938. }
  939. static void report_switch(struct input_dev *dev, unsigned int code, int value)
  940. {
  941. input_report_switch(dev, code, value);
  942. input_sync(dev);
  943. }
  944. /* led management */
  945. static void wistron_mail_led_set(struct led_classdev *led_cdev,
  946. enum led_brightness value)
  947. {
  948. bios_set_state(MAIL_LED, (value != LED_OFF) ? 1 : 0);
  949. }
  950. /* same as setting up wifi card, but for laptops on which the led is managed */
  951. static void wistron_wifi_led_set(struct led_classdev *led_cdev,
  952. enum led_brightness value)
  953. {
  954. bios_set_state(WIFI, (value != LED_OFF) ? 1 : 0);
  955. }
  956. static struct led_classdev wistron_mail_led = {
  957. .name = "wistron:green:mail",
  958. .brightness_set = wistron_mail_led_set,
  959. };
  960. static struct led_classdev wistron_wifi_led = {
  961. .name = "wistron:red:wifi",
  962. .brightness_set = wistron_wifi_led_set,
  963. };
  964. static void __devinit wistron_led_init(struct device *parent)
  965. {
  966. if (have_leds & FE_WIFI_LED) {
  967. u16 wifi = bios_get_default_setting(WIFI);
  968. if (wifi & 1) {
  969. wistron_wifi_led.brightness = (wifi & 2) ? LED_FULL : LED_OFF;
  970. if (led_classdev_register(parent, &wistron_wifi_led))
  971. have_leds &= ~FE_WIFI_LED;
  972. else
  973. bios_set_state(WIFI, wistron_wifi_led.brightness);
  974. } else
  975. have_leds &= ~FE_WIFI_LED;
  976. }
  977. if (have_leds & FE_MAIL_LED) {
  978. /* bios_get_default_setting(MAIL) always retuns 0, so just turn the led off */
  979. wistron_mail_led.brightness = LED_OFF;
  980. if (led_classdev_register(parent, &wistron_mail_led))
  981. have_leds &= ~FE_MAIL_LED;
  982. else
  983. bios_set_state(MAIL_LED, wistron_mail_led.brightness);
  984. }
  985. }
  986. static void __devexit wistron_led_remove(void)
  987. {
  988. if (have_leds & FE_MAIL_LED)
  989. led_classdev_unregister(&wistron_mail_led);
  990. if (have_leds & FE_WIFI_LED)
  991. led_classdev_unregister(&wistron_wifi_led);
  992. }
  993. static inline void wistron_led_suspend(void)
  994. {
  995. if (have_leds & FE_MAIL_LED)
  996. led_classdev_suspend(&wistron_mail_led);
  997. if (have_leds & FE_WIFI_LED)
  998. led_classdev_suspend(&wistron_wifi_led);
  999. }
  1000. static inline void wistron_led_resume(void)
  1001. {
  1002. if (have_leds & FE_MAIL_LED)
  1003. led_classdev_resume(&wistron_mail_led);
  1004. if (have_leds & FE_WIFI_LED)
  1005. led_classdev_resume(&wistron_wifi_led);
  1006. }
  1007. static struct key_entry *wistron_get_entry_by_scancode(int code)
  1008. {
  1009. struct key_entry *key;
  1010. for (key = keymap; key->type != KE_END; key++)
  1011. if (code == key->code)
  1012. return key;
  1013. return NULL;
  1014. }
  1015. static struct key_entry *wistron_get_entry_by_keycode(int keycode)
  1016. {
  1017. struct key_entry *key;
  1018. for (key = keymap; key->type != KE_END; key++)
  1019. if (key->type == KE_KEY && keycode == key->keycode)
  1020. return key;
  1021. return NULL;
  1022. }
  1023. static void handle_key(u8 code)
  1024. {
  1025. const struct key_entry *key = wistron_get_entry_by_scancode(code);
  1026. if (key) {
  1027. switch (key->type) {
  1028. case KE_KEY:
  1029. report_key(wistron_idev->input, key->keycode);
  1030. break;
  1031. case KE_SW:
  1032. report_switch(wistron_idev->input,
  1033. key->sw.code, key->sw.value);
  1034. break;
  1035. case KE_WIFI:
  1036. if (have_wifi) {
  1037. wifi_enabled = !wifi_enabled;
  1038. bios_set_state(WIFI, wifi_enabled);
  1039. }
  1040. break;
  1041. case KE_BLUETOOTH:
  1042. if (have_bluetooth) {
  1043. bluetooth_enabled = !bluetooth_enabled;
  1044. bios_set_state(BLUETOOTH, bluetooth_enabled);
  1045. }
  1046. break;
  1047. default:
  1048. BUG();
  1049. }
  1050. jiffies_last_press = jiffies;
  1051. } else
  1052. printk(KERN_NOTICE
  1053. "wistron_btns: Unknown key code %02X\n", code);
  1054. }
  1055. static void poll_bios(bool discard)
  1056. {
  1057. u8 qlen;
  1058. u16 val;
  1059. for (;;) {
  1060. qlen = CMOS_READ(cmos_address);
  1061. if (qlen == 0)
  1062. break;
  1063. val = bios_pop_queue();
  1064. if (val != 0 && !discard)
  1065. handle_key((u8)val);
  1066. }
  1067. }
  1068. static void wistron_flush(struct input_polled_dev *dev)
  1069. {
  1070. /* Flush stale event queue */
  1071. poll_bios(true);
  1072. }
  1073. static void wistron_poll(struct input_polled_dev *dev)
  1074. {
  1075. poll_bios(false);
  1076. /* Increase poll frequency if user is currently pressing keys (< 2s ago) */
  1077. if (time_before(jiffies, jiffies_last_press + 2 * HZ))
  1078. dev->poll_interval = POLL_INTERVAL_BURST;
  1079. else
  1080. dev->poll_interval = POLL_INTERVAL_DEFAULT;
  1081. }
  1082. static int wistron_getkeycode(struct input_dev *dev, int scancode, int *keycode)
  1083. {
  1084. const struct key_entry *key = wistron_get_entry_by_scancode(scancode);
  1085. if (key && key->type == KE_KEY) {
  1086. *keycode = key->keycode;
  1087. return 0;
  1088. }
  1089. return -EINVAL;
  1090. }
  1091. static int wistron_setkeycode(struct input_dev *dev, int scancode, int keycode)
  1092. {
  1093. struct key_entry *key;
  1094. int old_keycode;
  1095. if (keycode < 0 || keycode > KEY_MAX)
  1096. return -EINVAL;
  1097. key = wistron_get_entry_by_scancode(scancode);
  1098. if (key && key->type == KE_KEY) {
  1099. old_keycode = key->keycode;
  1100. key->keycode = keycode;
  1101. set_bit(keycode, dev->keybit);
  1102. if (!wistron_get_entry_by_keycode(old_keycode))
  1103. clear_bit(old_keycode, dev->keybit);
  1104. return 0;
  1105. }
  1106. return -EINVAL;
  1107. }
  1108. static int __devinit setup_input_dev(void)
  1109. {
  1110. struct key_entry *key;
  1111. struct input_dev *input_dev;
  1112. int error;
  1113. wistron_idev = input_allocate_polled_device();
  1114. if (!wistron_idev)
  1115. return -ENOMEM;
  1116. wistron_idev->flush = wistron_flush;
  1117. wistron_idev->poll = wistron_poll;
  1118. wistron_idev->poll_interval = POLL_INTERVAL_DEFAULT;
  1119. input_dev = wistron_idev->input;
  1120. input_dev->name = "Wistron laptop buttons";
  1121. input_dev->phys = "wistron/input0";
  1122. input_dev->id.bustype = BUS_HOST;
  1123. input_dev->dev.parent = &wistron_device->dev;
  1124. input_dev->getkeycode = wistron_getkeycode;
  1125. input_dev->setkeycode = wistron_setkeycode;
  1126. for (key = keymap; key->type != KE_END; key++) {
  1127. switch (key->type) {
  1128. case KE_KEY:
  1129. set_bit(EV_KEY, input_dev->evbit);
  1130. set_bit(key->keycode, input_dev->keybit);
  1131. break;
  1132. case KE_SW:
  1133. set_bit(EV_SW, input_dev->evbit);
  1134. set_bit(key->sw.code, input_dev->swbit);
  1135. break;
  1136. /* if wifi or bluetooth are not available, create normal keys */
  1137. case KE_WIFI:
  1138. if (!have_wifi) {
  1139. key->type = KE_KEY;
  1140. key->keycode = KEY_WLAN;
  1141. key--;
  1142. }
  1143. break;
  1144. case KE_BLUETOOTH:
  1145. if (!have_bluetooth) {
  1146. key->type = KE_KEY;
  1147. key->keycode = KEY_BLUETOOTH;
  1148. key--;
  1149. }
  1150. break;
  1151. default:
  1152. break;
  1153. }
  1154. }
  1155. /* reads information flags on KE_END */
  1156. if (key->code & FE_UNTESTED)
  1157. printk(KERN_WARNING "Untested laptop multimedia keys, "
  1158. "please report success or failure to eric.piel"
  1159. "@tremplin-utc.net\n");
  1160. error = input_register_polled_device(wistron_idev);
  1161. if (error) {
  1162. input_free_polled_device(wistron_idev);
  1163. return error;
  1164. }
  1165. return 0;
  1166. }
  1167. /* Driver core */
  1168. static int __devinit wistron_probe(struct platform_device *dev)
  1169. {
  1170. int err;
  1171. bios_attach();
  1172. cmos_address = bios_get_cmos_address();
  1173. if (have_wifi) {
  1174. u16 wifi = bios_get_default_setting(WIFI);
  1175. if (wifi & 1)
  1176. wifi_enabled = (wifi & 2) ? 1 : 0;
  1177. else
  1178. have_wifi = 0;
  1179. if (have_wifi)
  1180. bios_set_state(WIFI, wifi_enabled);
  1181. }
  1182. if (have_bluetooth) {
  1183. u16 bt = bios_get_default_setting(BLUETOOTH);
  1184. if (bt & 1)
  1185. bluetooth_enabled = (bt & 2) ? 1 : 0;
  1186. else
  1187. have_bluetooth = 0;
  1188. if (have_bluetooth)
  1189. bios_set_state(BLUETOOTH, bluetooth_enabled);
  1190. }
  1191. wistron_led_init(&dev->dev);
  1192. err = setup_input_dev();
  1193. if (err) {
  1194. bios_detach();
  1195. return err;
  1196. }
  1197. return 0;
  1198. }
  1199. static int __devexit wistron_remove(struct platform_device *dev)
  1200. {
  1201. wistron_led_remove();
  1202. input_unregister_polled_device(wistron_idev);
  1203. input_free_polled_device(wistron_idev);
  1204. bios_detach();
  1205. return 0;
  1206. }
  1207. #ifdef CONFIG_PM
  1208. static int wistron_suspend(struct platform_device *dev, pm_message_t state)
  1209. {
  1210. if (have_wifi)
  1211. bios_set_state(WIFI, 0);
  1212. if (have_bluetooth)
  1213. bios_set_state(BLUETOOTH, 0);
  1214. wistron_led_suspend();
  1215. return 0;
  1216. }
  1217. static int wistron_resume(struct platform_device *dev)
  1218. {
  1219. if (have_wifi)
  1220. bios_set_state(WIFI, wifi_enabled);
  1221. if (have_bluetooth)
  1222. bios_set_state(BLUETOOTH, bluetooth_enabled);
  1223. wistron_led_resume();
  1224. poll_bios(true);
  1225. return 0;
  1226. }
  1227. #else
  1228. #define wistron_suspend NULL
  1229. #define wistron_resume NULL
  1230. #endif
  1231. static struct platform_driver wistron_driver = {
  1232. .driver = {
  1233. .name = "wistron-bios",
  1234. .owner = THIS_MODULE,
  1235. },
  1236. .probe = wistron_probe,
  1237. .remove = __devexit_p(wistron_remove),
  1238. .suspend = wistron_suspend,
  1239. .resume = wistron_resume,
  1240. };
  1241. static int __init wb_module_init(void)
  1242. {
  1243. int err;
  1244. err = select_keymap();
  1245. if (err)
  1246. return err;
  1247. err = map_bios();
  1248. if (err)
  1249. return err;
  1250. err = platform_driver_register(&wistron_driver);
  1251. if (err)
  1252. goto err_unmap_bios;
  1253. wistron_device = platform_device_alloc("wistron-bios", -1);
  1254. if (!wistron_device) {
  1255. err = -ENOMEM;
  1256. goto err_unregister_driver;
  1257. }
  1258. err = platform_device_add(wistron_device);
  1259. if (err)
  1260. goto err_free_device;
  1261. return 0;
  1262. err_free_device:
  1263. platform_device_put(wistron_device);
  1264. err_unregister_driver:
  1265. platform_driver_unregister(&wistron_driver);
  1266. err_unmap_bios:
  1267. unmap_bios();
  1268. return err;
  1269. }
  1270. static void __exit wb_module_exit(void)
  1271. {
  1272. platform_device_unregister(wistron_device);
  1273. platform_driver_unregister(&wistron_driver);
  1274. unmap_bios();
  1275. kfree(keymap);
  1276. }
  1277. module_init(wb_module_init);
  1278. module_exit(wb_module_exit);