wistron_btns.c 30 KB

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