wistron_btns.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  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.2");
  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[] __initdata = {
  224. { KE_END, 0 }
  225. };
  226. static struct key_entry keymap_fs_amilo_pro_v2000[] __initdata = {
  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[] __initdata = {
  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[] __initdata = {
  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[] __initdata = {
  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[] __initdata = {
  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[] __initdata = {
  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[] __initdata = {
  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[] __initdata = {
  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[] __initdata = {
  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[] __initdata = {
  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[] __initdata = {
  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[] __initdata = {
  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[] __initdata = {
  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[] __initdata = {
  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[] __initdata = {
  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[] __initdata = {
  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[] __initdata = {
  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[] __initdata = {
  426. { KE_KEY, 0x01, {KEY_HELP} },
  427. { KE_KEY, 0x02, {KEY_CONFIG} },
  428. { KE_KEY, 0x11, {KEY_PROG1} },
  429. { KE_KEY, 0x12, {KEY_PROG2} },
  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[] __initdata = {
  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[] __initdata = {
  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[] __initdata = {
  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[] __initdata = {
  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[] __initdata = {
  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[] __initdata = {
  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. /* Copy the good keymap, as the original ones are free'd */
  852. static int __init copy_keymap(void)
  853. {
  854. const struct key_entry *key;
  855. struct key_entry *new_keymap;
  856. unsigned int length = 1;
  857. for (key = keymap; key->type != KE_END; key++)
  858. length++;
  859. new_keymap = kmalloc(length * sizeof(struct key_entry), GFP_KERNEL);
  860. if (!new_keymap)
  861. return -ENOMEM;
  862. memcpy(new_keymap, keymap, length * sizeof(struct key_entry));
  863. keymap = new_keymap;
  864. return 0;
  865. }
  866. static int __init select_keymap(void)
  867. {
  868. dmi_check_system(dmi_ids);
  869. if (keymap_name != NULL) {
  870. if (strcmp (keymap_name, "1557/MS2141") == 0)
  871. keymap = keymap_wistron_ms2141;
  872. else if (strcmp (keymap_name, "generic") == 0)
  873. keymap = keymap_wistron_generic;
  874. else {
  875. printk(KERN_ERR "wistron_btns: Keymap unknown\n");
  876. return -EINVAL;
  877. }
  878. }
  879. if (keymap == NULL) {
  880. if (!force) {
  881. printk(KERN_ERR "wistron_btns: System unknown\n");
  882. return -ENODEV;
  883. }
  884. keymap = keymap_empty;
  885. }
  886. return copy_keymap();
  887. }
  888. /* Input layer interface */
  889. static struct input_dev *input_dev;
  890. static int __devinit setup_input_dev(void)
  891. {
  892. const struct key_entry *key;
  893. int error;
  894. input_dev = input_allocate_device();
  895. if (!input_dev)
  896. return -ENOMEM;
  897. input_dev->name = "Wistron laptop buttons";
  898. input_dev->phys = "wistron/input0";
  899. input_dev->id.bustype = BUS_HOST;
  900. input_dev->cdev.dev = &wistron_device->dev;
  901. for (key = keymap; key->type != KE_END; key++) {
  902. switch (key->type) {
  903. case KE_KEY:
  904. set_bit(EV_KEY, input_dev->evbit);
  905. set_bit(key->keycode, input_dev->keybit);
  906. break;
  907. case KE_SW:
  908. set_bit(EV_SW, input_dev->evbit);
  909. set_bit(key->sw.code, input_dev->swbit);
  910. break;
  911. default:
  912. ;
  913. }
  914. }
  915. /* reads information flags on KE_END */
  916. if (key->code & FE_UNTESTED)
  917. printk(KERN_WARNING "Untested laptop multimedia keys, "
  918. "please report success or failure to eric.piel"
  919. "@tremplin-utc.net\n");
  920. error = input_register_device(input_dev);
  921. if (error) {
  922. input_free_device(input_dev);
  923. return error;
  924. }
  925. return 0;
  926. }
  927. static void report_key(unsigned keycode)
  928. {
  929. input_report_key(input_dev, keycode, 1);
  930. input_sync(input_dev);
  931. input_report_key(input_dev, keycode, 0);
  932. input_sync(input_dev);
  933. }
  934. static void report_switch(unsigned code, int value)
  935. {
  936. input_report_switch(input_dev, code, value);
  937. input_sync(input_dev);
  938. }
  939. /* Driver core */
  940. static int wifi_enabled;
  941. static int bluetooth_enabled;
  942. static void poll_bios(unsigned long);
  943. static struct timer_list poll_timer = TIMER_INITIALIZER(poll_bios, 0, 0);
  944. static void handle_key(u8 code)
  945. {
  946. const struct key_entry *key;
  947. for (key = keymap; key->type != KE_END; key++) {
  948. if (code == key->code) {
  949. switch (key->type) {
  950. case KE_KEY:
  951. report_key(key->keycode);
  952. break;
  953. case KE_SW:
  954. report_switch(key->sw.code, key->sw.value);
  955. break;
  956. case KE_WIFI:
  957. if (have_wifi) {
  958. wifi_enabled = !wifi_enabled;
  959. bios_set_state(WIFI, wifi_enabled);
  960. }
  961. break;
  962. case KE_BLUETOOTH:
  963. if (have_bluetooth) {
  964. bluetooth_enabled = !bluetooth_enabled;
  965. bios_set_state(BLUETOOTH, bluetooth_enabled);
  966. }
  967. break;
  968. case KE_END:
  969. break;
  970. default:
  971. BUG();
  972. }
  973. return;
  974. }
  975. }
  976. printk(KERN_NOTICE "wistron_btns: Unknown key code %02X\n", code);
  977. }
  978. static void poll_bios(unsigned long discard)
  979. {
  980. u8 qlen;
  981. u16 val;
  982. for (;;) {
  983. qlen = CMOS_READ(cmos_address);
  984. if (qlen == 0)
  985. break;
  986. val = bios_pop_queue();
  987. if (val != 0 && !discard)
  988. handle_key((u8)val);
  989. }
  990. mod_timer(&poll_timer, jiffies + HZ / POLL_FREQUENCY);
  991. }
  992. static int __devinit wistron_probe(struct platform_device *dev)
  993. {
  994. int err = setup_input_dev();
  995. if (err)
  996. return err;
  997. bios_attach();
  998. cmos_address = bios_get_cmos_address();
  999. if (have_wifi) {
  1000. u16 wifi = bios_get_default_setting(WIFI);
  1001. if (wifi & 1)
  1002. wifi_enabled = (wifi & 2) ? 1 : 0;
  1003. else
  1004. have_wifi = 0;
  1005. if (have_wifi)
  1006. bios_set_state(WIFI, wifi_enabled);
  1007. }
  1008. if (have_bluetooth) {
  1009. u16 bt = bios_get_default_setting(BLUETOOTH);
  1010. if (bt & 1)
  1011. bluetooth_enabled = (bt & 2) ? 1 : 0;
  1012. else
  1013. have_bluetooth = 0;
  1014. if (have_bluetooth)
  1015. bios_set_state(BLUETOOTH, bluetooth_enabled);
  1016. }
  1017. poll_bios(1); /* Flush stale event queue and arm timer */
  1018. return 0;
  1019. }
  1020. static int __devexit wistron_remove(struct platform_device *dev)
  1021. {
  1022. del_timer_sync(&poll_timer);
  1023. input_unregister_device(input_dev);
  1024. bios_detach();
  1025. return 0;
  1026. }
  1027. #ifdef CONFIG_PM
  1028. static int wistron_suspend(struct platform_device *dev, pm_message_t state)
  1029. {
  1030. del_timer_sync(&poll_timer);
  1031. if (have_wifi)
  1032. bios_set_state(WIFI, 0);
  1033. if (have_bluetooth)
  1034. bios_set_state(BLUETOOTH, 0);
  1035. return 0;
  1036. }
  1037. static int wistron_resume(struct platform_device *dev)
  1038. {
  1039. if (have_wifi)
  1040. bios_set_state(WIFI, wifi_enabled);
  1041. if (have_bluetooth)
  1042. bios_set_state(BLUETOOTH, bluetooth_enabled);
  1043. poll_bios(1);
  1044. return 0;
  1045. }
  1046. #else
  1047. #define wistron_suspend NULL
  1048. #define wistron_resume NULL
  1049. #endif
  1050. static struct platform_driver wistron_driver = {
  1051. .driver = {
  1052. .name = "wistron-bios",
  1053. .owner = THIS_MODULE,
  1054. },
  1055. .probe = wistron_probe,
  1056. .remove = __devexit_p(wistron_remove),
  1057. .suspend = wistron_suspend,
  1058. .resume = wistron_resume,
  1059. };
  1060. static int __init wb_module_init(void)
  1061. {
  1062. int err;
  1063. err = select_keymap();
  1064. if (err)
  1065. return err;
  1066. err = map_bios();
  1067. if (err)
  1068. return err;
  1069. err = platform_driver_register(&wistron_driver);
  1070. if (err)
  1071. goto err_unmap_bios;
  1072. wistron_device = platform_device_alloc("wistron-bios", -1);
  1073. if (!wistron_device) {
  1074. err = -ENOMEM;
  1075. goto err_unregister_driver;
  1076. }
  1077. err = platform_device_add(wistron_device);
  1078. if (err)
  1079. goto err_free_device;
  1080. return 0;
  1081. err_free_device:
  1082. platform_device_put(wistron_device);
  1083. err_unregister_driver:
  1084. platform_driver_unregister(&wistron_driver);
  1085. err_unmap_bios:
  1086. unmap_bios();
  1087. return err;
  1088. }
  1089. static void __exit wb_module_exit(void)
  1090. {
  1091. platform_device_unregister(wistron_device);
  1092. platform_driver_unregister(&wistron_driver);
  1093. unmap_bios();
  1094. kfree(keymap);
  1095. }
  1096. module_init(wb_module_init);
  1097. module_exit(wb_module_exit);