wistron_btns.c 32 KB

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