wistron_btns.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418
  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_fs_amilo_pro_v3505[] __initdata = {
  234. { KE_KEY, 0x01, {KEY_HELP} }, /* Fn+F1 */
  235. { KE_KEY, 0x06, {KEY_DISPLAYTOGGLE} }, /* Fn+F4 */
  236. { KE_BLUETOOTH, 0x30 }, /* Fn+F10 */
  237. { KE_KEY, 0x31, {KEY_MAIL} }, /* mail button */
  238. { KE_KEY, 0x36, {KEY_WWW} }, /* www button */
  239. { KE_WIFI, 0x78 }, /* satelite dish button */
  240. { KE_END, 0 }
  241. };
  242. static struct key_entry keymap_fujitsu_n3510[] __initdata = {
  243. { KE_KEY, 0x11, {KEY_PROG1} },
  244. { KE_KEY, 0x12, {KEY_PROG2} },
  245. { KE_KEY, 0x36, {KEY_WWW} },
  246. { KE_KEY, 0x31, {KEY_MAIL} },
  247. { KE_KEY, 0x71, {KEY_STOPCD} },
  248. { KE_KEY, 0x72, {KEY_PLAYPAUSE} },
  249. { KE_KEY, 0x74, {KEY_REWIND} },
  250. { KE_KEY, 0x78, {KEY_FORWARD} },
  251. { KE_END, 0 }
  252. };
  253. static struct key_entry keymap_wistron_ms2111[] __initdata = {
  254. { KE_KEY, 0x11, {KEY_PROG1} },
  255. { KE_KEY, 0x12, {KEY_PROG2} },
  256. { KE_KEY, 0x13, {KEY_PROG3} },
  257. { KE_KEY, 0x31, {KEY_MAIL} },
  258. { KE_KEY, 0x36, {KEY_WWW} },
  259. { KE_END, FE_MAIL_LED }
  260. };
  261. static struct key_entry keymap_wistron_md40100[] __initdata = {
  262. { KE_KEY, 0x01, {KEY_HELP} },
  263. { KE_KEY, 0x02, {KEY_CONFIG} },
  264. { KE_KEY, 0x31, {KEY_MAIL} },
  265. { KE_KEY, 0x36, {KEY_WWW} },
  266. { KE_KEY, 0x37, {KEY_DISPLAYTOGGLE} }, /* Display on/off */
  267. { KE_END, FE_MAIL_LED | FE_WIFI_LED | FE_UNTESTED }
  268. };
  269. static struct key_entry keymap_wistron_ms2141[] __initdata = {
  270. { KE_KEY, 0x11, {KEY_PROG1} },
  271. { KE_KEY, 0x12, {KEY_PROG2} },
  272. { KE_WIFI, 0x30 },
  273. { KE_KEY, 0x22, {KEY_REWIND} },
  274. { KE_KEY, 0x23, {KEY_FORWARD} },
  275. { KE_KEY, 0x24, {KEY_PLAYPAUSE} },
  276. { KE_KEY, 0x25, {KEY_STOPCD} },
  277. { KE_KEY, 0x31, {KEY_MAIL} },
  278. { KE_KEY, 0x36, {KEY_WWW} },
  279. { KE_END, 0 }
  280. };
  281. static struct key_entry keymap_acer_aspire_1500[] __initdata = {
  282. { KE_KEY, 0x01, {KEY_HELP} },
  283. { KE_KEY, 0x03, {KEY_POWER} },
  284. { KE_KEY, 0x11, {KEY_PROG1} },
  285. { KE_KEY, 0x12, {KEY_PROG2} },
  286. { KE_WIFI, 0x30 },
  287. { KE_KEY, 0x31, {KEY_MAIL} },
  288. { KE_KEY, 0x36, {KEY_WWW} },
  289. { KE_KEY, 0x49, {KEY_CONFIG} },
  290. { KE_BLUETOOTH, 0x44 },
  291. { KE_END, FE_UNTESTED }
  292. };
  293. static struct key_entry keymap_acer_aspire_1600[] __initdata = {
  294. { KE_KEY, 0x01, {KEY_HELP} },
  295. { KE_KEY, 0x03, {KEY_POWER} },
  296. { KE_KEY, 0x08, {KEY_MUTE} },
  297. { KE_KEY, 0x11, {KEY_PROG1} },
  298. { KE_KEY, 0x12, {KEY_PROG2} },
  299. { KE_KEY, 0x13, {KEY_PROG3} },
  300. { KE_KEY, 0x31, {KEY_MAIL} },
  301. { KE_KEY, 0x36, {KEY_WWW} },
  302. { KE_KEY, 0x49, {KEY_CONFIG} },
  303. { KE_WIFI, 0x30 },
  304. { KE_BLUETOOTH, 0x44 },
  305. { KE_END, FE_MAIL_LED | FE_UNTESTED }
  306. };
  307. /* 3020 has been tested */
  308. static struct key_entry keymap_acer_aspire_5020[] __initdata = {
  309. { KE_KEY, 0x01, {KEY_HELP} },
  310. { KE_KEY, 0x03, {KEY_POWER} },
  311. { KE_KEY, 0x05, {KEY_SWITCHVIDEOMODE} }, /* Display selection */
  312. { KE_KEY, 0x11, {KEY_PROG1} },
  313. { KE_KEY, 0x12, {KEY_PROG2} },
  314. { KE_KEY, 0x31, {KEY_MAIL} },
  315. { KE_KEY, 0x36, {KEY_WWW} },
  316. { KE_KEY, 0x6a, {KEY_CONFIG} },
  317. { KE_WIFI, 0x30 },
  318. { KE_BLUETOOTH, 0x44 },
  319. { KE_END, FE_MAIL_LED | FE_UNTESTED }
  320. };
  321. static struct key_entry keymap_acer_travelmate_2410[] __initdata = {
  322. { KE_KEY, 0x01, {KEY_HELP} },
  323. { KE_KEY, 0x6d, {KEY_POWER} },
  324. { KE_KEY, 0x11, {KEY_PROG1} },
  325. { KE_KEY, 0x12, {KEY_PROG2} },
  326. { KE_KEY, 0x31, {KEY_MAIL} },
  327. { KE_KEY, 0x36, {KEY_WWW} },
  328. { KE_KEY, 0x6a, {KEY_CONFIG} },
  329. { KE_WIFI, 0x30 },
  330. { KE_BLUETOOTH, 0x44 },
  331. { KE_END, FE_MAIL_LED | FE_UNTESTED }
  332. };
  333. static struct key_entry keymap_acer_travelmate_110[] __initdata = {
  334. { KE_KEY, 0x01, {KEY_HELP} },
  335. { KE_KEY, 0x02, {KEY_CONFIG} },
  336. { KE_KEY, 0x03, {KEY_POWER} },
  337. { KE_KEY, 0x08, {KEY_MUTE} },
  338. { KE_KEY, 0x11, {KEY_PROG1} },
  339. { KE_KEY, 0x12, {KEY_PROG2} },
  340. { KE_KEY, 0x20, {KEY_VOLUMEUP} },
  341. { KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
  342. { KE_KEY, 0x31, {KEY_MAIL} },
  343. { KE_KEY, 0x36, {KEY_WWW} },
  344. { KE_SW, 0x4a, {.sw = {SW_LID, 1}} }, /* lid close */
  345. { KE_SW, 0x4b, {.sw = {SW_LID, 0}} }, /* lid open */
  346. { KE_WIFI, 0x30 },
  347. { KE_END, FE_MAIL_LED | FE_UNTESTED }
  348. };
  349. static struct key_entry keymap_acer_travelmate_300[] __initdata = {
  350. { KE_KEY, 0x01, {KEY_HELP} },
  351. { KE_KEY, 0x02, {KEY_CONFIG} },
  352. { KE_KEY, 0x03, {KEY_POWER} },
  353. { KE_KEY, 0x08, {KEY_MUTE} },
  354. { KE_KEY, 0x11, {KEY_PROG1} },
  355. { KE_KEY, 0x12, {KEY_PROG2} },
  356. { KE_KEY, 0x20, {KEY_VOLUMEUP} },
  357. { KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
  358. { KE_KEY, 0x31, {KEY_MAIL} },
  359. { KE_KEY, 0x36, {KEY_WWW} },
  360. { KE_WIFI, 0x30 },
  361. { KE_BLUETOOTH, 0x44 },
  362. { KE_END, FE_MAIL_LED | FE_UNTESTED }
  363. };
  364. static struct key_entry keymap_acer_travelmate_380[] __initdata = {
  365. { KE_KEY, 0x01, {KEY_HELP} },
  366. { KE_KEY, 0x02, {KEY_CONFIG} },
  367. { KE_KEY, 0x03, {KEY_POWER} }, /* not 370 */
  368. { KE_KEY, 0x11, {KEY_PROG1} },
  369. { KE_KEY, 0x12, {KEY_PROG2} },
  370. { KE_KEY, 0x13, {KEY_PROG3} },
  371. { KE_KEY, 0x31, {KEY_MAIL} },
  372. { KE_KEY, 0x36, {KEY_WWW} },
  373. { KE_WIFI, 0x30 },
  374. { KE_END, FE_MAIL_LED | FE_UNTESTED }
  375. };
  376. /* unusual map */
  377. static struct key_entry keymap_acer_travelmate_220[] __initdata = {
  378. { KE_KEY, 0x01, {KEY_HELP} },
  379. { KE_KEY, 0x02, {KEY_CONFIG} },
  380. { KE_KEY, 0x11, {KEY_MAIL} },
  381. { KE_KEY, 0x12, {KEY_WWW} },
  382. { KE_KEY, 0x13, {KEY_PROG2} },
  383. { KE_KEY, 0x31, {KEY_PROG1} },
  384. { KE_END, FE_WIFI_LED | FE_UNTESTED }
  385. };
  386. static struct key_entry keymap_acer_travelmate_230[] __initdata = {
  387. { KE_KEY, 0x01, {KEY_HELP} },
  388. { KE_KEY, 0x02, {KEY_CONFIG} },
  389. { KE_KEY, 0x11, {KEY_PROG1} },
  390. { KE_KEY, 0x12, {KEY_PROG2} },
  391. { KE_KEY, 0x31, {KEY_MAIL} },
  392. { KE_KEY, 0x36, {KEY_WWW} },
  393. { KE_END, FE_WIFI_LED | FE_UNTESTED }
  394. };
  395. static struct key_entry keymap_acer_travelmate_240[] __initdata = {
  396. { KE_KEY, 0x01, {KEY_HELP} },
  397. { KE_KEY, 0x02, {KEY_CONFIG} },
  398. { KE_KEY, 0x03, {KEY_POWER} },
  399. { KE_KEY, 0x08, {KEY_MUTE} },
  400. { KE_KEY, 0x31, {KEY_MAIL} },
  401. { KE_KEY, 0x36, {KEY_WWW} },
  402. { KE_KEY, 0x11, {KEY_PROG1} },
  403. { KE_KEY, 0x12, {KEY_PROG2} },
  404. { KE_BLUETOOTH, 0x44 },
  405. { KE_WIFI, 0x30 },
  406. { KE_END, FE_UNTESTED }
  407. };
  408. static struct key_entry keymap_acer_travelmate_350[] __initdata = {
  409. { KE_KEY, 0x01, {KEY_HELP} },
  410. { KE_KEY, 0x02, {KEY_CONFIG} },
  411. { KE_KEY, 0x11, {KEY_PROG1} },
  412. { KE_KEY, 0x12, {KEY_PROG2} },
  413. { KE_KEY, 0x13, {KEY_MAIL} },
  414. { KE_KEY, 0x14, {KEY_PROG3} },
  415. { KE_KEY, 0x15, {KEY_WWW} },
  416. { KE_END, FE_MAIL_LED | FE_WIFI_LED | FE_UNTESTED }
  417. };
  418. static struct key_entry keymap_acer_travelmate_360[] __initdata = {
  419. { KE_KEY, 0x01, {KEY_HELP} },
  420. { KE_KEY, 0x02, {KEY_CONFIG} },
  421. { KE_KEY, 0x11, {KEY_PROG1} },
  422. { KE_KEY, 0x12, {KEY_PROG2} },
  423. { KE_KEY, 0x13, {KEY_MAIL} },
  424. { KE_KEY, 0x14, {KEY_PROG3} },
  425. { KE_KEY, 0x15, {KEY_WWW} },
  426. { KE_KEY, 0x40, {KEY_WLAN} },
  427. { KE_END, FE_WIFI_LED | FE_UNTESTED } /* no mail led */
  428. };
  429. /* Wifi subsystem only activates the led. Therefore we need to pass
  430. * wifi event as a normal key, then userspace can really change the wifi state.
  431. * TODO we need to export led state to userspace (wifi and mail) */
  432. static struct key_entry keymap_acer_travelmate_610[] __initdata = {
  433. { KE_KEY, 0x01, {KEY_HELP} },
  434. { KE_KEY, 0x02, {KEY_CONFIG} },
  435. { KE_KEY, 0x11, {KEY_PROG1} },
  436. { KE_KEY, 0x12, {KEY_PROG2} },
  437. { KE_KEY, 0x13, {KEY_PROG3} },
  438. { KE_KEY, 0x14, {KEY_MAIL} },
  439. { KE_KEY, 0x15, {KEY_WWW} },
  440. { KE_KEY, 0x40, {KEY_WLAN} },
  441. { KE_END, FE_MAIL_LED | FE_WIFI_LED }
  442. };
  443. static struct key_entry keymap_acer_travelmate_630[] __initdata = {
  444. { KE_KEY, 0x01, {KEY_HELP} },
  445. { KE_KEY, 0x02, {KEY_CONFIG} },
  446. { KE_KEY, 0x03, {KEY_POWER} },
  447. { KE_KEY, 0x08, {KEY_MUTE} }, /* not 620 */
  448. { KE_KEY, 0x11, {KEY_PROG1} },
  449. { KE_KEY, 0x12, {KEY_PROG2} },
  450. { KE_KEY, 0x13, {KEY_PROG3} },
  451. { KE_KEY, 0x20, {KEY_VOLUMEUP} },
  452. { KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
  453. { KE_KEY, 0x31, {KEY_MAIL} },
  454. { KE_KEY, 0x36, {KEY_WWW} },
  455. { KE_WIFI, 0x30 },
  456. { KE_END, FE_MAIL_LED | FE_UNTESTED }
  457. };
  458. static struct key_entry keymap_aopen_1559as[] __initdata = {
  459. { KE_KEY, 0x01, {KEY_HELP} },
  460. { KE_KEY, 0x06, {KEY_PROG3} },
  461. { KE_KEY, 0x11, {KEY_PROG1} },
  462. { KE_KEY, 0x12, {KEY_PROG2} },
  463. { KE_WIFI, 0x30 },
  464. { KE_KEY, 0x31, {KEY_MAIL} },
  465. { KE_KEY, 0x36, {KEY_WWW} },
  466. { KE_END, 0 },
  467. };
  468. static struct key_entry keymap_fs_amilo_d88x0[] __initdata = {
  469. { KE_KEY, 0x01, {KEY_HELP} },
  470. { KE_KEY, 0x08, {KEY_MUTE} },
  471. { KE_KEY, 0x31, {KEY_MAIL} },
  472. { KE_KEY, 0x36, {KEY_WWW} },
  473. { KE_KEY, 0x11, {KEY_PROG1} },
  474. { KE_KEY, 0x12, {KEY_PROG2} },
  475. { KE_KEY, 0x13, {KEY_PROG3} },
  476. { KE_END, FE_MAIL_LED | FE_WIFI_LED | FE_UNTESTED }
  477. };
  478. static struct key_entry keymap_wistron_md2900[] __initdata = {
  479. { KE_KEY, 0x01, {KEY_HELP} },
  480. { KE_KEY, 0x02, {KEY_CONFIG} },
  481. { KE_KEY, 0x11, {KEY_PROG1} },
  482. { KE_KEY, 0x12, {KEY_PROG2} },
  483. { KE_KEY, 0x31, {KEY_MAIL} },
  484. { KE_KEY, 0x36, {KEY_WWW} },
  485. { KE_WIFI, 0x30 },
  486. { KE_END, FE_MAIL_LED | FE_UNTESTED }
  487. };
  488. static struct key_entry keymap_wistron_md96500[] __initdata = {
  489. { KE_KEY, 0x01, {KEY_HELP} },
  490. { KE_KEY, 0x02, {KEY_CONFIG} },
  491. { KE_KEY, 0x05, {KEY_SWITCHVIDEOMODE} }, /* Display selection */
  492. { KE_KEY, 0x06, {KEY_DISPLAYTOGGLE} }, /* Display on/off */
  493. { KE_KEY, 0x08, {KEY_MUTE} },
  494. { KE_KEY, 0x11, {KEY_PROG1} },
  495. { KE_KEY, 0x12, {KEY_PROG2} },
  496. { KE_KEY, 0x20, {KEY_VOLUMEUP} },
  497. { KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
  498. { KE_KEY, 0x22, {KEY_REWIND} },
  499. { KE_KEY, 0x23, {KEY_FORWARD} },
  500. { KE_KEY, 0x24, {KEY_PLAYPAUSE} },
  501. { KE_KEY, 0x25, {KEY_STOPCD} },
  502. { KE_KEY, 0x31, {KEY_MAIL} },
  503. { KE_KEY, 0x36, {KEY_WWW} },
  504. { KE_WIFI, 0x30 },
  505. { KE_BLUETOOTH, 0x44 },
  506. { KE_END, FE_UNTESTED }
  507. };
  508. static struct key_entry keymap_wistron_generic[] __initdata = {
  509. { KE_KEY, 0x01, {KEY_HELP} },
  510. { KE_KEY, 0x02, {KEY_CONFIG} },
  511. { KE_KEY, 0x03, {KEY_POWER} },
  512. { KE_KEY, 0x05, {KEY_SWITCHVIDEOMODE} }, /* Display selection */
  513. { KE_KEY, 0x06, {KEY_DISPLAYTOGGLE} }, /* Display on/off */
  514. { KE_KEY, 0x08, {KEY_MUTE} },
  515. { KE_KEY, 0x11, {KEY_PROG1} },
  516. { KE_KEY, 0x12, {KEY_PROG2} },
  517. { KE_KEY, 0x13, {KEY_PROG3} },
  518. { KE_KEY, 0x14, {KEY_MAIL} },
  519. { KE_KEY, 0x15, {KEY_WWW} },
  520. { KE_KEY, 0x20, {KEY_VOLUMEUP} },
  521. { KE_KEY, 0x21, {KEY_VOLUMEDOWN} },
  522. { KE_KEY, 0x22, {KEY_REWIND} },
  523. { KE_KEY, 0x23, {KEY_FORWARD} },
  524. { KE_KEY, 0x24, {KEY_PLAYPAUSE} },
  525. { KE_KEY, 0x25, {KEY_STOPCD} },
  526. { KE_KEY, 0x31, {KEY_MAIL} },
  527. { KE_KEY, 0x36, {KEY_WWW} },
  528. { KE_KEY, 0x37, {KEY_DISPLAYTOGGLE} }, /* Display on/off */
  529. { KE_KEY, 0x40, {KEY_WLAN} },
  530. { KE_KEY, 0x49, {KEY_CONFIG} },
  531. { KE_SW, 0x4a, {.sw = {SW_LID, 1}} }, /* lid close */
  532. { KE_SW, 0x4b, {.sw = {SW_LID, 0}} }, /* lid open */
  533. { KE_KEY, 0x6a, {KEY_CONFIG} },
  534. { KE_KEY, 0x6d, {KEY_POWER} },
  535. { KE_KEY, 0x71, {KEY_STOPCD} },
  536. { KE_KEY, 0x72, {KEY_PLAYPAUSE} },
  537. { KE_KEY, 0x74, {KEY_REWIND} },
  538. { KE_KEY, 0x78, {KEY_FORWARD} },
  539. { KE_WIFI, 0x30 },
  540. { KE_BLUETOOTH, 0x44 },
  541. { KE_END, 0 }
  542. };
  543. /*
  544. * If your machine is not here (which is currently rather likely), please send
  545. * a list of buttons and their key codes (reported when loading this module
  546. * with force=1) and the output of dmidecode to $MODULE_AUTHOR.
  547. */
  548. static struct dmi_system_id dmi_ids[] __initdata = {
  549. {
  550. .callback = dmi_matched,
  551. .ident = "Fujitsu-Siemens Amilo Pro V2000",
  552. .matches = {
  553. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
  554. DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pro V2000"),
  555. },
  556. .driver_data = keymap_fs_amilo_pro_v2000
  557. },
  558. {
  559. .callback = dmi_matched,
  560. .ident = "Fujitsu-Siemens Amilo Pro Edition V3505",
  561. .matches = {
  562. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
  563. DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pro Edition V3505"),
  564. },
  565. .driver_data = keymap_fs_amilo_pro_v3505
  566. },
  567. {
  568. .callback = dmi_matched,
  569. .ident = "Fujitsu-Siemens Amilo M7400",
  570. .matches = {
  571. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
  572. DMI_MATCH(DMI_PRODUCT_NAME, "AMILO M "),
  573. },
  574. .driver_data = keymap_fs_amilo_pro_v2000
  575. },
  576. {
  577. .callback = dmi_matched,
  578. .ident = "Fujitsu N3510",
  579. .matches = {
  580. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
  581. DMI_MATCH(DMI_PRODUCT_NAME, "N3510"),
  582. },
  583. .driver_data = keymap_fujitsu_n3510
  584. },
  585. {
  586. .callback = dmi_matched,
  587. .ident = "Acer Aspire 1500",
  588. .matches = {
  589. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  590. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1500"),
  591. },
  592. .driver_data = keymap_acer_aspire_1500
  593. },
  594. {
  595. .callback = dmi_matched,
  596. .ident = "Acer Aspire 1600",
  597. .matches = {
  598. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  599. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1600"),
  600. },
  601. .driver_data = keymap_acer_aspire_1600
  602. },
  603. {
  604. .callback = dmi_matched,
  605. .ident = "Acer Aspire 3020",
  606. .matches = {
  607. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  608. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3020"),
  609. },
  610. .driver_data = keymap_acer_aspire_5020
  611. },
  612. {
  613. .callback = dmi_matched,
  614. .ident = "Acer Aspire 5020",
  615. .matches = {
  616. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  617. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5020"),
  618. },
  619. .driver_data = keymap_acer_aspire_5020
  620. },
  621. {
  622. .callback = dmi_matched,
  623. .ident = "Acer TravelMate 2100",
  624. .matches = {
  625. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  626. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2100"),
  627. },
  628. .driver_data = keymap_acer_aspire_5020
  629. },
  630. {
  631. .callback = dmi_matched,
  632. .ident = "Acer TravelMate 2410",
  633. .matches = {
  634. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  635. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2410"),
  636. },
  637. .driver_data = keymap_acer_travelmate_2410
  638. },
  639. {
  640. .callback = dmi_matched,
  641. .ident = "Acer TravelMate C300",
  642. .matches = {
  643. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  644. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate C300"),
  645. },
  646. .driver_data = keymap_acer_travelmate_300
  647. },
  648. {
  649. .callback = dmi_matched,
  650. .ident = "Acer TravelMate C100",
  651. .matches = {
  652. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  653. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate C100"),
  654. },
  655. .driver_data = keymap_acer_travelmate_300
  656. },
  657. {
  658. .callback = dmi_matched,
  659. .ident = "Acer TravelMate C110",
  660. .matches = {
  661. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  662. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate C110"),
  663. },
  664. .driver_data = keymap_acer_travelmate_110
  665. },
  666. {
  667. .callback = dmi_matched,
  668. .ident = "Acer TravelMate 380",
  669. .matches = {
  670. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  671. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 380"),
  672. },
  673. .driver_data = keymap_acer_travelmate_380
  674. },
  675. {
  676. .callback = dmi_matched,
  677. .ident = "Acer TravelMate 370",
  678. .matches = {
  679. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  680. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 370"),
  681. },
  682. .driver_data = keymap_acer_travelmate_380 /* keyboard minus 1 key */
  683. },
  684. {
  685. .callback = dmi_matched,
  686. .ident = "Acer TravelMate 220",
  687. .matches = {
  688. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  689. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 220"),
  690. },
  691. .driver_data = keymap_acer_travelmate_220
  692. },
  693. {
  694. .callback = dmi_matched,
  695. .ident = "Acer TravelMate 260",
  696. .matches = {
  697. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  698. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 260"),
  699. },
  700. .driver_data = keymap_acer_travelmate_220
  701. },
  702. {
  703. .callback = dmi_matched,
  704. .ident = "Acer TravelMate 230",
  705. .matches = {
  706. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  707. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 230"),
  708. /* acerhk looks for "TravelMate F4..." ?! */
  709. },
  710. .driver_data = keymap_acer_travelmate_230
  711. },
  712. {
  713. .callback = dmi_matched,
  714. .ident = "Acer TravelMate 280",
  715. .matches = {
  716. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  717. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 280"),
  718. },
  719. .driver_data = keymap_acer_travelmate_230
  720. },
  721. {
  722. .callback = dmi_matched,
  723. .ident = "Acer TravelMate 240",
  724. .matches = {
  725. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  726. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 240"),
  727. },
  728. .driver_data = keymap_acer_travelmate_240
  729. },
  730. {
  731. .callback = dmi_matched,
  732. .ident = "Acer TravelMate 250",
  733. .matches = {
  734. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  735. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 250"),
  736. },
  737. .driver_data = keymap_acer_travelmate_240
  738. },
  739. {
  740. .callback = dmi_matched,
  741. .ident = "Acer TravelMate 2424NWXCi",
  742. .matches = {
  743. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  744. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2420"),
  745. },
  746. .driver_data = keymap_acer_travelmate_240
  747. },
  748. {
  749. .callback = dmi_matched,
  750. .ident = "Acer TravelMate 350",
  751. .matches = {
  752. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  753. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 350"),
  754. },
  755. .driver_data = keymap_acer_travelmate_350
  756. },
  757. {
  758. .callback = dmi_matched,
  759. .ident = "Acer TravelMate 360",
  760. .matches = {
  761. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  762. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
  763. },
  764. .driver_data = keymap_acer_travelmate_360
  765. },
  766. {
  767. .callback = dmi_matched,
  768. .ident = "Acer TravelMate 610",
  769. .matches = {
  770. DMI_MATCH(DMI_SYS_VENDOR, "ACER"),
  771. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 610"),
  772. },
  773. .driver_data = keymap_acer_travelmate_610
  774. },
  775. {
  776. .callback = dmi_matched,
  777. .ident = "Acer TravelMate 620",
  778. .matches = {
  779. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  780. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 620"),
  781. },
  782. .driver_data = keymap_acer_travelmate_630
  783. },
  784. {
  785. .callback = dmi_matched,
  786. .ident = "Acer TravelMate 630",
  787. .matches = {
  788. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  789. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 630"),
  790. },
  791. .driver_data = keymap_acer_travelmate_630
  792. },
  793. {
  794. .callback = dmi_matched,
  795. .ident = "AOpen 1559AS",
  796. .matches = {
  797. DMI_MATCH(DMI_PRODUCT_NAME, "E2U"),
  798. DMI_MATCH(DMI_BOARD_NAME, "E2U"),
  799. },
  800. .driver_data = keymap_aopen_1559as
  801. },
  802. {
  803. .callback = dmi_matched,
  804. .ident = "Medion MD 9783",
  805. .matches = {
  806. DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
  807. DMI_MATCH(DMI_PRODUCT_NAME, "MD 9783"),
  808. },
  809. .driver_data = keymap_wistron_ms2111
  810. },
  811. {
  812. .callback = dmi_matched,
  813. .ident = "Medion MD 40100",
  814. .matches = {
  815. DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
  816. DMI_MATCH(DMI_PRODUCT_NAME, "WID2000"),
  817. },
  818. .driver_data = keymap_wistron_md40100
  819. },
  820. {
  821. .callback = dmi_matched,
  822. .ident = "Medion MD 2900",
  823. .matches = {
  824. DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
  825. DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2000"),
  826. },
  827. .driver_data = keymap_wistron_md2900
  828. },
  829. {
  830. .callback = dmi_matched,
  831. .ident = "Medion MD 96500",
  832. .matches = {
  833. DMI_MATCH(DMI_SYS_VENDOR, "MEDIONPC"),
  834. DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2040"),
  835. },
  836. .driver_data = keymap_wistron_md96500
  837. },
  838. {
  839. .callback = dmi_matched,
  840. .ident = "Medion MD 95400",
  841. .matches = {
  842. DMI_MATCH(DMI_SYS_VENDOR, "MEDIONPC"),
  843. DMI_MATCH(DMI_PRODUCT_NAME, "WIM 2050"),
  844. },
  845. .driver_data = keymap_wistron_md96500
  846. },
  847. {
  848. .callback = dmi_matched,
  849. .ident = "Fujitsu Siemens Amilo D7820",
  850. .matches = {
  851. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"), /* not sure */
  852. DMI_MATCH(DMI_PRODUCT_NAME, "Amilo D"),
  853. },
  854. .driver_data = keymap_fs_amilo_d88x0
  855. },
  856. {
  857. .callback = dmi_matched,
  858. .ident = "Fujitsu Siemens Amilo D88x0",
  859. .matches = {
  860. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
  861. DMI_MATCH(DMI_PRODUCT_NAME, "AMILO D"),
  862. },
  863. .driver_data = keymap_fs_amilo_d88x0
  864. },
  865. { NULL, }
  866. };
  867. /* Copy the good keymap, as the original ones are free'd */
  868. static int __init copy_keymap(void)
  869. {
  870. const struct key_entry *key;
  871. struct key_entry *new_keymap;
  872. unsigned int length = 1;
  873. for (key = keymap; key->type != KE_END; key++)
  874. length++;
  875. new_keymap = kmalloc(length * sizeof(struct key_entry), GFP_KERNEL);
  876. if (!new_keymap)
  877. return -ENOMEM;
  878. memcpy(new_keymap, keymap, length * sizeof(struct key_entry));
  879. keymap = new_keymap;
  880. return 0;
  881. }
  882. static int __init select_keymap(void)
  883. {
  884. dmi_check_system(dmi_ids);
  885. if (keymap_name != NULL) {
  886. if (strcmp (keymap_name, "1557/MS2141") == 0)
  887. keymap = keymap_wistron_ms2141;
  888. else if (strcmp (keymap_name, "generic") == 0)
  889. keymap = keymap_wistron_generic;
  890. else {
  891. printk(KERN_ERR "wistron_btns: Keymap unknown\n");
  892. return -EINVAL;
  893. }
  894. }
  895. if (keymap == NULL) {
  896. if (!force) {
  897. printk(KERN_ERR "wistron_btns: System unknown\n");
  898. return -ENODEV;
  899. }
  900. keymap = keymap_empty;
  901. }
  902. return copy_keymap();
  903. }
  904. /* Input layer interface */
  905. static struct input_polled_dev *wistron_idev;
  906. static unsigned long jiffies_last_press;
  907. static int wifi_enabled;
  908. static int bluetooth_enabled;
  909. static void report_key(struct input_dev *dev, unsigned int keycode)
  910. {
  911. input_report_key(dev, keycode, 1);
  912. input_sync(dev);
  913. input_report_key(dev, keycode, 0);
  914. input_sync(dev);
  915. }
  916. static void report_switch(struct input_dev *dev, unsigned int code, int value)
  917. {
  918. input_report_switch(dev, code, value);
  919. input_sync(dev);
  920. }
  921. /* led management */
  922. static void wistron_mail_led_set(struct led_classdev *led_cdev,
  923. enum led_brightness value)
  924. {
  925. bios_set_state(MAIL_LED, (value != LED_OFF) ? 1 : 0);
  926. }
  927. /* same as setting up wifi card, but for laptops on which the led is managed */
  928. static void wistron_wifi_led_set(struct led_classdev *led_cdev,
  929. enum led_brightness value)
  930. {
  931. bios_set_state(WIFI, (value != LED_OFF) ? 1 : 0);
  932. }
  933. static struct led_classdev wistron_mail_led = {
  934. .name = "wistron:green:mail",
  935. .brightness_set = wistron_mail_led_set,
  936. };
  937. static struct led_classdev wistron_wifi_led = {
  938. .name = "wistron:red:wifi",
  939. .brightness_set = wistron_wifi_led_set,
  940. };
  941. static void __devinit wistron_led_init(struct device *parent)
  942. {
  943. if (have_leds & FE_WIFI_LED) {
  944. u16 wifi = bios_get_default_setting(WIFI);
  945. if (wifi & 1) {
  946. wistron_wifi_led.brightness = (wifi & 2) ? LED_FULL : LED_OFF;
  947. if (led_classdev_register(parent, &wistron_wifi_led))
  948. have_leds &= ~FE_WIFI_LED;
  949. else
  950. bios_set_state(WIFI, wistron_wifi_led.brightness);
  951. } else
  952. have_leds &= ~FE_WIFI_LED;
  953. }
  954. if (have_leds & FE_MAIL_LED) {
  955. /* bios_get_default_setting(MAIL) always retuns 0, so just turn the led off */
  956. wistron_mail_led.brightness = LED_OFF;
  957. if (led_classdev_register(parent, &wistron_mail_led))
  958. have_leds &= ~FE_MAIL_LED;
  959. else
  960. bios_set_state(MAIL_LED, wistron_mail_led.brightness);
  961. }
  962. }
  963. static void __devexit wistron_led_remove(void)
  964. {
  965. if (have_leds & FE_MAIL_LED)
  966. led_classdev_unregister(&wistron_mail_led);
  967. if (have_leds & FE_WIFI_LED)
  968. led_classdev_unregister(&wistron_wifi_led);
  969. }
  970. static inline void wistron_led_suspend(void)
  971. {
  972. if (have_leds & FE_MAIL_LED)
  973. led_classdev_suspend(&wistron_mail_led);
  974. if (have_leds & FE_WIFI_LED)
  975. led_classdev_suspend(&wistron_wifi_led);
  976. }
  977. static inline void wistron_led_resume(void)
  978. {
  979. if (have_leds & FE_MAIL_LED)
  980. led_classdev_resume(&wistron_mail_led);
  981. if (have_leds & FE_WIFI_LED)
  982. led_classdev_resume(&wistron_wifi_led);
  983. }
  984. static struct key_entry *wistron_get_entry_by_scancode(int code)
  985. {
  986. struct key_entry *key;
  987. for (key = keymap; key->type != KE_END; key++)
  988. if (code == key->code)
  989. return key;
  990. return NULL;
  991. }
  992. static struct key_entry *wistron_get_entry_by_keycode(int keycode)
  993. {
  994. struct key_entry *key;
  995. for (key = keymap; key->type != KE_END; key++)
  996. if (key->type == KE_KEY && keycode == key->keycode)
  997. return key;
  998. return NULL;
  999. }
  1000. static void handle_key(u8 code)
  1001. {
  1002. const struct key_entry *key = wistron_get_entry_by_scancode(code);
  1003. if (key) {
  1004. switch (key->type) {
  1005. case KE_KEY:
  1006. report_key(wistron_idev->input, key->keycode);
  1007. break;
  1008. case KE_SW:
  1009. report_switch(wistron_idev->input,
  1010. key->sw.code, key->sw.value);
  1011. break;
  1012. case KE_WIFI:
  1013. if (have_wifi) {
  1014. wifi_enabled = !wifi_enabled;
  1015. bios_set_state(WIFI, wifi_enabled);
  1016. }
  1017. break;
  1018. case KE_BLUETOOTH:
  1019. if (have_bluetooth) {
  1020. bluetooth_enabled = !bluetooth_enabled;
  1021. bios_set_state(BLUETOOTH, bluetooth_enabled);
  1022. }
  1023. break;
  1024. default:
  1025. BUG();
  1026. }
  1027. jiffies_last_press = jiffies;
  1028. } else
  1029. printk(KERN_NOTICE
  1030. "wistron_btns: Unknown key code %02X\n", code);
  1031. }
  1032. static void poll_bios(bool discard)
  1033. {
  1034. u8 qlen;
  1035. u16 val;
  1036. for (;;) {
  1037. qlen = CMOS_READ(cmos_address);
  1038. if (qlen == 0)
  1039. break;
  1040. val = bios_pop_queue();
  1041. if (val != 0 && !discard)
  1042. handle_key((u8)val);
  1043. }
  1044. }
  1045. static void wistron_flush(struct input_polled_dev *dev)
  1046. {
  1047. /* Flush stale event queue */
  1048. poll_bios(true);
  1049. }
  1050. static void wistron_poll(struct input_polled_dev *dev)
  1051. {
  1052. poll_bios(false);
  1053. /* Increase poll frequency if user is currently pressing keys (< 2s ago) */
  1054. if (time_before(jiffies, jiffies_last_press + 2 * HZ))
  1055. dev->poll_interval = POLL_INTERVAL_BURST;
  1056. else
  1057. dev->poll_interval = POLL_INTERVAL_DEFAULT;
  1058. }
  1059. static int wistron_getkeycode(struct input_dev *dev, int scancode, int *keycode)
  1060. {
  1061. const struct key_entry *key = wistron_get_entry_by_scancode(scancode);
  1062. if (key && key->type == KE_KEY) {
  1063. *keycode = key->keycode;
  1064. return 0;
  1065. }
  1066. return -EINVAL;
  1067. }
  1068. static int wistron_setkeycode(struct input_dev *dev, int scancode, int keycode)
  1069. {
  1070. struct key_entry *key;
  1071. int old_keycode;
  1072. if (keycode < 0 || keycode > KEY_MAX)
  1073. return -EINVAL;
  1074. key = wistron_get_entry_by_scancode(scancode);
  1075. if (key && key->type == KE_KEY) {
  1076. old_keycode = key->keycode;
  1077. key->keycode = keycode;
  1078. set_bit(keycode, dev->keybit);
  1079. if (!wistron_get_entry_by_keycode(old_keycode))
  1080. clear_bit(old_keycode, dev->keybit);
  1081. return 0;
  1082. }
  1083. return -EINVAL;
  1084. }
  1085. static int __devinit setup_input_dev(void)
  1086. {
  1087. struct key_entry *key;
  1088. struct input_dev *input_dev;
  1089. int error;
  1090. wistron_idev = input_allocate_polled_device();
  1091. if (!wistron_idev)
  1092. return -ENOMEM;
  1093. wistron_idev->flush = wistron_flush;
  1094. wistron_idev->poll = wistron_poll;
  1095. wistron_idev->poll_interval = POLL_INTERVAL_DEFAULT;
  1096. input_dev = wistron_idev->input;
  1097. input_dev->name = "Wistron laptop buttons";
  1098. input_dev->phys = "wistron/input0";
  1099. input_dev->id.bustype = BUS_HOST;
  1100. input_dev->dev.parent = &wistron_device->dev;
  1101. input_dev->getkeycode = wistron_getkeycode;
  1102. input_dev->setkeycode = wistron_setkeycode;
  1103. for (key = keymap; key->type != KE_END; key++) {
  1104. switch (key->type) {
  1105. case KE_KEY:
  1106. set_bit(EV_KEY, input_dev->evbit);
  1107. set_bit(key->keycode, input_dev->keybit);
  1108. break;
  1109. case KE_SW:
  1110. set_bit(EV_SW, input_dev->evbit);
  1111. set_bit(key->sw.code, input_dev->swbit);
  1112. break;
  1113. /* if wifi or bluetooth are not available, create normal keys */
  1114. case KE_WIFI:
  1115. if (!have_wifi) {
  1116. key->type = KE_KEY;
  1117. key->keycode = KEY_WLAN;
  1118. key--;
  1119. }
  1120. break;
  1121. case KE_BLUETOOTH:
  1122. if (!have_bluetooth) {
  1123. key->type = KE_KEY;
  1124. key->keycode = KEY_BLUETOOTH;
  1125. key--;
  1126. }
  1127. break;
  1128. default:
  1129. break;
  1130. }
  1131. }
  1132. /* reads information flags on KE_END */
  1133. if (key->code & FE_UNTESTED)
  1134. printk(KERN_WARNING "Untested laptop multimedia keys, "
  1135. "please report success or failure to eric.piel"
  1136. "@tremplin-utc.net\n");
  1137. error = input_register_polled_device(wistron_idev);
  1138. if (error) {
  1139. input_free_polled_device(wistron_idev);
  1140. return error;
  1141. }
  1142. return 0;
  1143. }
  1144. /* Driver core */
  1145. static int __devinit wistron_probe(struct platform_device *dev)
  1146. {
  1147. int err;
  1148. bios_attach();
  1149. cmos_address = bios_get_cmos_address();
  1150. if (have_wifi) {
  1151. u16 wifi = bios_get_default_setting(WIFI);
  1152. if (wifi & 1)
  1153. wifi_enabled = (wifi & 2) ? 1 : 0;
  1154. else
  1155. have_wifi = 0;
  1156. if (have_wifi)
  1157. bios_set_state(WIFI, wifi_enabled);
  1158. }
  1159. if (have_bluetooth) {
  1160. u16 bt = bios_get_default_setting(BLUETOOTH);
  1161. if (bt & 1)
  1162. bluetooth_enabled = (bt & 2) ? 1 : 0;
  1163. else
  1164. have_bluetooth = 0;
  1165. if (have_bluetooth)
  1166. bios_set_state(BLUETOOTH, bluetooth_enabled);
  1167. }
  1168. wistron_led_init(&dev->dev);
  1169. err = setup_input_dev();
  1170. if (err) {
  1171. bios_detach();
  1172. return err;
  1173. }
  1174. return 0;
  1175. }
  1176. static int __devexit wistron_remove(struct platform_device *dev)
  1177. {
  1178. wistron_led_remove();
  1179. input_unregister_polled_device(wistron_idev);
  1180. input_free_polled_device(wistron_idev);
  1181. bios_detach();
  1182. return 0;
  1183. }
  1184. #ifdef CONFIG_PM
  1185. static int wistron_suspend(struct platform_device *dev, pm_message_t state)
  1186. {
  1187. if (have_wifi)
  1188. bios_set_state(WIFI, 0);
  1189. if (have_bluetooth)
  1190. bios_set_state(BLUETOOTH, 0);
  1191. wistron_led_suspend();
  1192. return 0;
  1193. }
  1194. static int wistron_resume(struct platform_device *dev)
  1195. {
  1196. if (have_wifi)
  1197. bios_set_state(WIFI, wifi_enabled);
  1198. if (have_bluetooth)
  1199. bios_set_state(BLUETOOTH, bluetooth_enabled);
  1200. wistron_led_resume();
  1201. poll_bios(true);
  1202. return 0;
  1203. }
  1204. #else
  1205. #define wistron_suspend NULL
  1206. #define wistron_resume NULL
  1207. #endif
  1208. static struct platform_driver wistron_driver = {
  1209. .driver = {
  1210. .name = "wistron-bios",
  1211. .owner = THIS_MODULE,
  1212. },
  1213. .probe = wistron_probe,
  1214. .remove = __devexit_p(wistron_remove),
  1215. .suspend = wistron_suspend,
  1216. .resume = wistron_resume,
  1217. };
  1218. static int __init wb_module_init(void)
  1219. {
  1220. int err;
  1221. err = select_keymap();
  1222. if (err)
  1223. return err;
  1224. err = map_bios();
  1225. if (err)
  1226. return err;
  1227. err = platform_driver_register(&wistron_driver);
  1228. if (err)
  1229. goto err_unmap_bios;
  1230. wistron_device = platform_device_alloc("wistron-bios", -1);
  1231. if (!wistron_device) {
  1232. err = -ENOMEM;
  1233. goto err_unregister_driver;
  1234. }
  1235. err = platform_device_add(wistron_device);
  1236. if (err)
  1237. goto err_free_device;
  1238. return 0;
  1239. err_free_device:
  1240. platform_device_put(wistron_device);
  1241. err_unregister_driver:
  1242. platform_driver_unregister(&wistron_driver);
  1243. err_unmap_bios:
  1244. unmap_bios();
  1245. return err;
  1246. }
  1247. static void __exit wb_module_exit(void)
  1248. {
  1249. platform_device_unregister(wistron_device);
  1250. platform_driver_unregister(&wistron_driver);
  1251. unmap_bios();
  1252. kfree(keymap);
  1253. }
  1254. module_init(wb_module_init);
  1255. module_exit(wb_module_exit);