wistron_btns.c 29 KB

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