wistron_btns.c 34 KB

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