wistron_btns.c 34 KB

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