i8042.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. /*
  2. * (C) Copyright 2002 ELTEC Elektronik AG
  3. * Frank Gottschling <fgottschling@eltec.de>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /* i8042.c - Intel 8042 keyboard driver routines */
  24. /* includes */
  25. #include <common.h>
  26. #ifdef CONFIG_I8042_KBD
  27. #include <i8042.h>
  28. /* defines */
  29. #ifdef CONFIG_CONSOLE_CURSOR
  30. extern void console_cursor (int state);
  31. static int blinkCount = CFG_CONSOLE_BLINK_COUNT;
  32. static int cursor_state = 0;
  33. #endif
  34. /* locals */
  35. static int kbd_input = -1; /* no input yet */
  36. static int kbd_mapping = KBD_US; /* default US keyboard */
  37. static int kbd_flags = NORMAL; /* after reset */
  38. static int kbd_state = 0; /* unshift code */
  39. static void kbd_conv_char (unsigned char scan_code);
  40. static void kbd_led_set (void);
  41. static void kbd_normal (unsigned char scan_code);
  42. static void kbd_shift (unsigned char scan_code);
  43. static void kbd_ctrl (unsigned char scan_code);
  44. static void kbd_num (unsigned char scan_code);
  45. static void kbd_caps (unsigned char scan_code);
  46. static void kbd_scroll (unsigned char scan_code);
  47. static void kbd_alt (unsigned char scan_code);
  48. static int kbd_input_empty (void);
  49. static int kbd_reset (void);
  50. static unsigned char kbd_fct_map [144] =
  51. { /* kbd_fct_map table for scan code */
  52. 0, AS, AS, AS, AS, AS, AS, AS, /* scan 0- 7 */
  53. AS, AS, AS, AS, AS, AS, AS, AS, /* scan 8- F */
  54. AS, AS, AS, AS, AS, AS, AS, AS, /* scan 10-17 */
  55. AS, AS, AS, AS, AS, CN, AS, AS, /* scan 18-1F */
  56. AS, AS, AS, AS, AS, AS, AS, AS, /* scan 20-27 */
  57. AS, AS, SH, AS, AS, AS, AS, AS, /* scan 28-2F */
  58. AS, AS, AS, AS, AS, AS, SH, AS, /* scan 30-37 */
  59. AS, AS, CP, 0, 0, 0, 0, 0, /* scan 38-3F */
  60. 0, 0, 0, 0, 0, NM, ST, ES, /* scan 40-47 */
  61. ES, ES, ES, ES, ES, ES, ES, ES, /* scan 48-4F */
  62. ES, ES, ES, ES, 0, 0, AS, 0, /* scan 50-57 */
  63. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */
  64. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */
  65. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */
  66. AS, 0, 0, AS, 0, 0, AS, 0, /* scan 70-77 */
  67. 0, AS, 0, 0, 0, AS, 0, 0, /* scan 78-7F */
  68. AS, CN, AS, AS, AK, ST, EX, EX, /* enhanced */
  69. AS, EX, EX, AS, EX, AS, EX, EX /* enhanced */
  70. };
  71. static unsigned char kbd_key_map [2][5][144] =
  72. {
  73. { /* US keyboard */
  74. { /* unshift code */
  75. 0, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 0- 7 */
  76. '7', '8', '9', '0', '-', '=', 0x08, '\t', /* scan 8- F */
  77. 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', /* scan 10-17 */
  78. 'o', 'p', '[', ']', '\r', CN, 'a', 's', /* scan 18-1F */
  79. 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* scan 20-27 */
  80. '\'', '`', SH, '\\', 'z', 'x', 'c', 'v', /* scan 28-2F */
  81. 'b', 'n', 'm', ',', '.', '/', SH, '*', /* scan 30-37 */
  82. ' ', ' ', CP, 0, 0, 0, 0, 0, /* scan 38-3F */
  83. 0, 0, 0, 0, 0, NM, ST, '7', /* scan 40-47 */
  84. '8', '9', '-', '4', '5', '6', '+', '1', /* scan 48-4F */
  85. '2', '3', '0', '.', 0, 0, 0, 0, /* scan 50-57 */
  86. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */
  87. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */
  88. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */
  89. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 70-77 */
  90. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 78-7F */
  91. '\r', CN, '/', '*', ' ', ST, 'F', 'A', /* extended */
  92. 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */
  93. },
  94. { /* shift code */
  95. 0, 0x1b, '!', '@', '#', '$', '%', '^', /* scan 0- 7 */
  96. '&', '*', '(', ')', '_', '+', 0x08, '\t', /* scan 8- F */
  97. 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', /* scan 10-17 */
  98. 'O', 'P', '{', '}', '\r', CN, 'A', 'S', /* scan 18-1F */
  99. 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', /* scan 20-27 */
  100. '"', '~', SH, '|', 'Z', 'X', 'C', 'V', /* scan 28-2F */
  101. 'B', 'N', 'M', '<', '>', '?', SH, '*', /* scan 30-37 */
  102. ' ', ' ', CP, 0, 0, 0, 0, 0, /* scan 38-3F */
  103. 0, 0, 0, 0, 0, NM, ST, '7', /* scan 40-47 */
  104. '8', '9', '-', '4', '5', '6', '+', '1', /* scan 48-4F */
  105. '2', '3', '0', '.', 0, 0, 0, 0, /* scan 50-57 */
  106. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */
  107. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */
  108. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */
  109. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 70-77 */
  110. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 78-7F */
  111. '\r', CN, '/', '*', ' ', ST, 'F', 'A', /* extended */
  112. 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */
  113. },
  114. { /* control code */
  115. 0xff, 0x1b, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, /* scan 0- 7 */
  116. 0x1e, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, '\t', /* scan 8- F */
  117. 0x11, 0x17, 0x05, 0x12, 0x14, 0x19, 0x15, 0x09, /* scan 10-17 */
  118. 0x0f, 0x10, 0x1b, 0x1d, '\r', CN, 0x01, 0x13, /* scan 18-1F */
  119. 0x04, 0x06, 0x07, 0x08, 0x0a, 0x0b, 0x0c, 0xff, /* scan 20-27 */
  120. 0xff, 0x1c, SH, 0xff, 0x1a, 0x18, 0x03, 0x16, /* scan 28-2F */
  121. 0x02, 0x0e, 0x0d, 0xff, 0xff, 0xff, SH, 0xff, /* scan 30-37 */
  122. 0xff, 0xff, CP, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */
  123. 0xff, 0xff, 0xff, 0xff, 0xff, NM, ST, 0xff, /* scan 40-47 */
  124. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48-4F */
  125. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 50-57 */
  126. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58-5F */
  127. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60-67 */
  128. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68-6F */
  129. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70-77 */
  130. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78-7F */
  131. '\r', CN, '/', '*', ' ', ST, 0xff, 0xff, /* extended */
  132. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff /* extended */
  133. },
  134. { /* non numeric code */
  135. 0, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 0- 7 */
  136. '7', '8', '9', '0', '-', '=', 0x08, '\t', /* scan 8- F */
  137. 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', /* scan 10-17 */
  138. 'o', 'p', '[', ']', '\r', CN, 'a', 's', /* scan 18-1F */
  139. 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* scan 20-27 */
  140. '\'', '`', SH, '\\', 'z', 'x', 'c', 'v', /* scan 28-2F */
  141. 'b', 'n', 'm', ',', '.', '/', SH, '*', /* scan 30-37 */
  142. ' ', ' ', CP, 0, 0, 0, 0, 0, /* scan 38-3F */
  143. 0, 0, 0, 0, 0, NM, ST, 'w', /* scan 40-47 */
  144. 'x', 'y', 'l', 't', 'u', 'v', 'm', 'q', /* scan 48-4F */
  145. 'r', 's', 'p', 'n', 0, 0, 0, 0, /* scan 50-57 */
  146. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */
  147. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */
  148. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */
  149. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 70-77 */
  150. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 78-7F */
  151. '\r', CN, '/', '*', ' ', ST, 'F', 'A', /* extended */
  152. 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */
  153. },
  154. { /* right alt mode - not used in US keyboard */
  155. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 0 - 7 */
  156. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 8 - F */
  157. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 10 -17 */
  158. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 18 -1F */
  159. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 20 -27 */
  160. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 28 -2F */
  161. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 30 -37 */
  162. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38 -3F */
  163. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 40 -47 */
  164. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48 -4F */
  165. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 50 -57 */
  166. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58 -5F */
  167. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60 -67 */
  168. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68 -6F */
  169. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70 -77 */
  170. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78 -7F */
  171. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* extended */
  172. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff /* extended */
  173. }
  174. },
  175. { /* german keyboard */
  176. { /* unshift code */
  177. 0, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 0- 7 */
  178. '7', '8', '9', '0', 0xe1, '\'', 0x08, '\t', /* scan 8- F */
  179. 'q', 'w', 'e', 'r', 't', 'z', 'u', 'i', /* scan 10-17 */
  180. 'o', 'p', 0x81, '+', '\r', CN, 'a', 's', /* scan 18-1F */
  181. 'd', 'f', 'g', 'h', 'j', 'k', 'l', 0x94, /* scan 20-27 */
  182. 0x84, '^', SH, '#', 'y', 'x', 'c', 'v', /* scan 28-2F */
  183. 'b', 'n', 'm', ',', '.', '-', SH, '*', /* scan 30-37 */
  184. ' ', ' ', CP, 0, 0, 0, 0, 0, /* scan 38-3F */
  185. 0, 0, 0, 0, 0, NM, ST, '7', /* scan 40-47 */
  186. '8', '9', '-', '4', '5', '6', '+', '1', /* scan 48-4F */
  187. '2', '3', '0', ',', 0, 0, '<', 0, /* scan 50-57 */
  188. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */
  189. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */
  190. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */
  191. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 70-77 */
  192. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 78-7F */
  193. '\r', CN, '/', '*', ' ', ST, 'F', 'A', /* extended */
  194. 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */
  195. },
  196. { /* shift code */
  197. 0, 0x1b, '!', '"', 0x15, '$', '%', '&', /* scan 0- 7 */
  198. '/', '(', ')', '=', '?', '`', 0x08, '\t', /* scan 8- F */
  199. 'Q', 'W', 'E', 'R', 'T', 'Z', 'U', 'I', /* scan 10-17 */
  200. 'O', 'P', 0x9a, '*', '\r', CN, 'A', 'S', /* scan 18-1F */
  201. 'D', 'F', 'G', 'H', 'J', 'K', 'L', 0x99, /* scan 20-27 */
  202. 0x8e, 0xf8, SH, '\'', 'Y', 'X', 'C', 'V', /* scan 28-2F */
  203. 'B', 'N', 'M', ';', ':', '_', SH, '*', /* scan 30-37 */
  204. ' ', ' ', CP, 0, 0, 0, 0, 0, /* scan 38-3F */
  205. 0, 0, 0, 0, 0, NM, ST, '7', /* scan 40-47 */
  206. '8', '9', '-', '4', '5', '6', '+', '1', /* scan 48-4F */
  207. '2', '3', '0', ',', 0, 0, '>', 0, /* scan 50-57 */
  208. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */
  209. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */
  210. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */
  211. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 70-77 */
  212. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 78-7F */
  213. '\r', CN, '/', '*', ' ', ST, 'F', 'A', /* extended */
  214. 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */
  215. },
  216. { /* control code */
  217. 0xff, 0x1b, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, /* scan 0- 7 */
  218. 0x1e, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, '\t', /* scan 8- F */
  219. 0x11, 0x17, 0x05, 0x12, 0x14, 0x19, 0x15, 0x09, /* scan 10-17 */
  220. 0x0f, 0x10, 0x1b, 0x1d, '\r', CN, 0x01, 0x13, /* scan 18-1F */
  221. 0x04, 0x06, 0x07, 0x08, 0x0a, 0x0b, 0x0c, 0xff, /* scan 20-27 */
  222. 0xff, 0x1c, SH, 0xff, 0x1a, 0x18, 0x03, 0x16, /* scan 28-2F */
  223. 0x02, 0x0e, 0x0d, 0xff, 0xff, 0xff, SH, 0xff, /* scan 30-37 */
  224. 0xff, 0xff, CP, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */
  225. 0xff, 0xff, 0xff, 0xff, 0xff, NM, ST, 0xff, /* scan 40-47 */
  226. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48-4F */
  227. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 50-57 */
  228. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58-5F */
  229. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60-67 */
  230. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68-6F */
  231. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70-77 */
  232. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78-7F */
  233. '\r', CN, '/', '*', ' ', ST, 0xff, 0xff, /* extended */
  234. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff /* extended */
  235. },
  236. { /* non numeric code */
  237. 0, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 0- 7 */
  238. '7', '8', '9', '0', 0xe1, '\'', 0x08, '\t', /* scan 8- F */
  239. 'q', 'w', 'e', 'r', 't', 'z', 'u', 'i', /* scan 10-17 */
  240. 'o', 'p', 0x81, '+', '\r', CN, 'a', 's', /* scan 18-1F */
  241. 'd', 'f', 'g', 'h', 'j', 'k', 'l', 0x94, /* scan 20-27 */
  242. 0x84, '^', SH, 0, 'y', 'x', 'c', 'v', /* scan 28-2F */
  243. 'b', 'n', 'm', ',', '.', '-', SH, '*', /* scan 30-37 */
  244. ' ', ' ', CP, 0, 0, 0, 0, 0, /* scan 38-3F */
  245. 0, 0, 0, 0, 0, NM, ST, 'w', /* scan 40-47 */
  246. 'x', 'y', 'l', 't', 'u', 'v', 'm', 'q', /* scan 48-4F */
  247. 'r', 's', 'p', 'n', 0, 0, '<', 0, /* scan 50-57 */
  248. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */
  249. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */
  250. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */
  251. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 70-77 */
  252. 0, 0, 0, 0, 0, 0, 0, 0, /* scan 78-7F */
  253. '\r', CN, '/', '*', ' ', ST, 'F', 'A', /* extended */
  254. 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */
  255. },
  256. { /* Right alt mode - is used in German keyboard */
  257. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 0 - 7 */
  258. '{', '[', ']', '}', '\\', 0xff, 0xff, 0xff, /* scan 8 - F */
  259. '@', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 10 -17 */
  260. 0xff, 0xff, 0xff, '~', 0xff, 0xff, 0xff, 0xff, /* scan 18 -1F */
  261. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 20 -27 */
  262. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 28 -2F */
  263. 0xff, 0xff, 0xe6, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 30 -37 */
  264. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38 -3F */
  265. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 40 -47 */
  266. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48 -4F */
  267. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, '|', 0xff, /* scan 50 -57 */
  268. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58 -5F */
  269. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60 -67 */
  270. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68 -6F */
  271. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70 -77 */
  272. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78 -7F */
  273. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* extended */
  274. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff /* extended */
  275. }
  276. }
  277. };
  278. static unsigned char ext_key_map [] =
  279. {
  280. 0x1c, /* keypad enter */
  281. 0x1d, /* right control */
  282. 0x35, /* keypad slash */
  283. 0x37, /* print screen */
  284. 0x38, /* right alt */
  285. 0x46, /* break */
  286. 0x47, /* editpad home */
  287. 0x48, /* editpad up */
  288. 0x49, /* editpad pgup */
  289. 0x4b, /* editpad left */
  290. 0x4d, /* editpad right */
  291. 0x4f, /* editpad end */
  292. 0x50, /* editpad dn */
  293. 0x51, /* editpad pgdn */
  294. 0x52, /* editpad ins */
  295. 0x53, /* editpad del */
  296. 0x00 /* map end */
  297. };
  298. /*******************************************************************************
  299. *
  300. * i8042_kbd_init - reset keyboard and init state flags
  301. */
  302. int i8042_kbd_init (void)
  303. {
  304. int keymap, try;
  305. char *penv;
  306. /* Init keyboard device (default US layout) */
  307. keymap = KBD_US;
  308. if ((penv = getenv ("keymap")) != NULL)
  309. {
  310. if (strncmp (penv, "de", 3) == 0)
  311. keymap = KBD_GER;
  312. }
  313. for (try = 0; try < KBD_RESET_TRIES; try++)
  314. {
  315. if (kbd_reset() == 0)
  316. {
  317. kbd_mapping = keymap;
  318. kbd_flags = NORMAL;
  319. kbd_state = 0;
  320. kbd_led_set();
  321. return 0;
  322. }
  323. }
  324. return -1;
  325. }
  326. /*******************************************************************************
  327. *
  328. * i8042_tstc - test if keyboard input is available
  329. * option: cursor blinking if called in a loop
  330. */
  331. int i8042_tstc (void)
  332. {
  333. unsigned char scan_code = 0;
  334. #ifdef CONFIG_CONSOLE_CURSOR
  335. if (--blinkCount == 0)
  336. {
  337. cursor_state ^= 1;
  338. console_cursor (cursor_state);
  339. blinkCount = CFG_CONSOLE_BLINK_COUNT;
  340. udelay (10);
  341. }
  342. #endif
  343. if ((in8 (I8042_STATUS_REG) & 0x01) == 0)
  344. return 0;
  345. else
  346. {
  347. scan_code = in8 (I8042_DATA_REG);
  348. if (scan_code == 0xfa)
  349. return 0;
  350. kbd_conv_char(scan_code);
  351. if (kbd_input != -1)
  352. return 1;
  353. }
  354. return 0;
  355. }
  356. /*******************************************************************************
  357. *
  358. * i8042_getc - wait till keyboard input is available
  359. * option: turn on/off cursor while waiting
  360. */
  361. int i8042_getc (void)
  362. {
  363. int ret_chr;
  364. unsigned char scan_code;
  365. while (kbd_input == -1)
  366. {
  367. while ((in8 (I8042_STATUS_REG) & 0x01) == 0)
  368. {
  369. #ifdef CONFIG_CONSOLE_CURSOR
  370. if (--blinkCount==0)
  371. {
  372. cursor_state ^= 1;
  373. console_cursor (cursor_state);
  374. blinkCount = CFG_CONSOLE_BLINK_COUNT;
  375. }
  376. udelay (10);
  377. #endif
  378. }
  379. scan_code = in8 (I8042_DATA_REG);
  380. if (scan_code != 0xfa)
  381. kbd_conv_char (scan_code);
  382. }
  383. ret_chr = kbd_input;
  384. kbd_input = -1;
  385. return ret_chr;
  386. }
  387. /******************************************************************************/
  388. static void kbd_conv_char (unsigned char scan_code)
  389. {
  390. if (scan_code == 0xe0)
  391. {
  392. kbd_flags |= EXT;
  393. return;
  394. }
  395. /* if high bit of scan_code, set break flag */
  396. if (scan_code & 0x80)
  397. kbd_flags |= BRK;
  398. else
  399. kbd_flags &= ~BRK;
  400. if ((scan_code == 0xe1) || (kbd_flags & E1))
  401. {
  402. if (scan_code == 0xe1)
  403. {
  404. kbd_flags ^= BRK; /* reset the break flag */
  405. kbd_flags ^= E1; /* bitwise EXOR with E1 flag */
  406. }
  407. return;
  408. }
  409. scan_code &= 0x7f;
  410. if (kbd_flags & EXT)
  411. {
  412. int i;
  413. kbd_flags ^= EXT;
  414. for (i=0; ext_key_map[i]; i++)
  415. {
  416. if (ext_key_map[i] == scan_code)
  417. {
  418. scan_code = 0x80 + i;
  419. break;
  420. }
  421. }
  422. /* not found ? */
  423. if (!ext_key_map[i])
  424. return;
  425. }
  426. switch (kbd_fct_map [scan_code])
  427. {
  428. case AS: kbd_normal (scan_code);
  429. break;
  430. case SH: kbd_shift (scan_code);
  431. break;
  432. case CN: kbd_ctrl (scan_code);
  433. break;
  434. case NM: kbd_num (scan_code);
  435. break;
  436. case CP: kbd_caps (scan_code);
  437. break;
  438. case ST: kbd_scroll (scan_code);
  439. break;
  440. case AK: kbd_alt (scan_code);
  441. break;
  442. }
  443. return;
  444. }
  445. /******************************************************************************/
  446. static void kbd_normal (unsigned char scan_code)
  447. {
  448. unsigned char chr;
  449. if ((kbd_flags & BRK) == NORMAL)
  450. {
  451. chr = kbd_key_map [kbd_mapping][kbd_state][scan_code];
  452. if ((chr == 0xff) || (chr == 0x00))
  453. {
  454. return;
  455. }
  456. /* if caps lock convert upper to lower */
  457. if (((kbd_flags & CAPS) == CAPS) && (chr >= 'a' && chr <= 'z'))
  458. {
  459. chr -= 'a' - 'A';
  460. }
  461. kbd_input = chr;
  462. }
  463. }
  464. /******************************************************************************/
  465. static void kbd_shift (unsigned char scan_code)
  466. {
  467. if ((kbd_flags & BRK) == BRK)
  468. {
  469. kbd_state = AS;
  470. kbd_flags &= (~SHIFT);
  471. }
  472. else
  473. {
  474. kbd_state = SH;
  475. kbd_flags |= SHIFT;
  476. }
  477. }
  478. /******************************************************************************/
  479. static void kbd_ctrl (unsigned char scan_code)
  480. {
  481. if ((kbd_flags & BRK) == BRK)
  482. {
  483. kbd_state = AS;
  484. kbd_flags &= (~CTRL);
  485. }
  486. else
  487. {
  488. kbd_state = CN;
  489. kbd_flags |= CTRL;
  490. }
  491. }
  492. /******************************************************************************/
  493. static void kbd_caps (unsigned char scan_code)
  494. {
  495. if ((kbd_flags & BRK) == NORMAL)
  496. {
  497. kbd_flags ^= CAPS;
  498. kbd_led_set (); /* update keyboard LED */
  499. }
  500. }
  501. /******************************************************************************/
  502. static void kbd_num (unsigned char scan_code)
  503. {
  504. if ((kbd_flags & BRK) == NORMAL)
  505. {
  506. kbd_flags ^= NUM;
  507. kbd_state = (kbd_flags & NUM) ? AS : NM;
  508. kbd_led_set (); /* update keyboard LED */
  509. }
  510. }
  511. /******************************************************************************/
  512. static void kbd_scroll (unsigned char scan_code)
  513. {
  514. if ((kbd_flags & BRK) == NORMAL)
  515. {
  516. kbd_flags ^= STP;
  517. kbd_led_set (); /* update keyboard LED */
  518. if (kbd_flags & STP)
  519. kbd_input = 0x13;
  520. else
  521. kbd_input = 0x11;
  522. }
  523. }
  524. /******************************************************************************/
  525. static void kbd_alt (unsigned char scan_code)
  526. {
  527. if ((kbd_flags & BRK) == BRK)
  528. {
  529. kbd_state = AS;
  530. kbd_flags &= (~ALT);
  531. }
  532. else
  533. {
  534. kbd_state = AK;
  535. kbd_flags &= ALT;
  536. }
  537. }
  538. /******************************************************************************/
  539. static void kbd_led_set (void)
  540. {
  541. kbd_input_empty();
  542. out8 (I8042_DATA_REG, 0xed); /* SET LED command */
  543. kbd_input_empty();
  544. out8 (I8042_DATA_REG, (kbd_flags & 0x7)); /* LED bits only */
  545. }
  546. /******************************************************************************/
  547. static int kbd_input_empty (void)
  548. {
  549. int kbdTimeout = KBD_TIMEOUT;
  550. /* wait for input buf empty */
  551. while ((in8 (I8042_STATUS_REG) & 0x02) && kbdTimeout--)
  552. udelay(1000);
  553. return kbdTimeout;
  554. }
  555. /******************************************************************************/
  556. static int kbd_reset (void)
  557. {
  558. if (kbd_input_empty() == 0)
  559. return -1;
  560. out8 (I8042_DATA_REG, 0xff);
  561. udelay(250000);
  562. if (kbd_input_empty() == 0)
  563. return -1;
  564. out8 (I8042_DATA_REG, 0x60);
  565. if (kbd_input_empty() == 0)
  566. return -1;
  567. out8 (I8042_DATA_REG, 0x45);
  568. if (kbd_input_empty() == 0)
  569. return -1;
  570. out8 (I8042_COMMAND_REG, 0xae);
  571. if (kbd_input_empty() == 0)
  572. return -1;
  573. return 0;
  574. }
  575. #endif /* CONFIG_I8042_KBD */