2 * (C) Copyright 2002 ELTEC Elektronik AG
3 * Frank Gottschling <fgottschling@eltec.de>
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
24 /* i8042.c - Intel 8042 keyboard driver routines */
30 #ifdef CONFIG_I8042_KBD
36 #ifdef CONFIG_CONSOLE_CURSOR
37 extern void console_cursor (int state);
38 static int blinkCount = CFG_CONSOLE_BLINK_COUNT;
39 static int cursor_state = 0;
44 static int kbd_input = -1; /* no input yet */
45 static int kbd_mapping = KBD_US; /* default US keyboard */
46 static int kbd_flags = NORMAL; /* after reset */
47 static int kbd_state = 0; /* unshift code */
49 static void kbd_conv_char (unsigned char scan_code);
50 static void kbd_led_set (void);
51 static void kbd_normal (unsigned char scan_code);
52 static void kbd_shift (unsigned char scan_code);
53 static void kbd_ctrl (unsigned char scan_code);
54 static void kbd_num (unsigned char scan_code);
55 static void kbd_caps (unsigned char scan_code);
56 static void kbd_scroll (unsigned char scan_code);
57 static void kbd_alt (unsigned char scan_code);
58 static int kbd_input_empty (void);
59 static int kbd_reset (void);
61 static unsigned char kbd_fct_map [144] =
62 { /* kbd_fct_map table for scan code */
63 0, AS, AS, AS, AS, AS, AS, AS, /* scan 0- 7 */
64 AS, AS, AS, AS, AS, AS, AS, AS, /* scan 8- F */
65 AS, AS, AS, AS, AS, AS, AS, AS, /* scan 10-17 */
66 AS, AS, AS, AS, AS, CN, AS, AS, /* scan 18-1F */
67 AS, AS, AS, AS, AS, AS, AS, AS, /* scan 20-27 */
68 AS, AS, SH, AS, AS, AS, AS, AS, /* scan 28-2F */
69 AS, AS, AS, AS, AS, AS, SH, AS, /* scan 30-37 */
70 AS, AS, CP, 0, 0, 0, 0, 0, /* scan 38-3F */
71 0, 0, 0, 0, 0, NM, ST, ES, /* scan 40-47 */
72 ES, ES, ES, ES, ES, ES, ES, ES, /* scan 48-4F */
73 ES, ES, ES, ES, 0, 0, AS, 0, /* scan 50-57 */
74 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */
75 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */
76 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */
77 AS, 0, 0, AS, 0, 0, AS, 0, /* scan 70-77 */
78 0, AS, 0, 0, 0, AS, 0, 0, /* scan 78-7F */
79 AS, CN, AS, AS, AK, ST, EX, EX, /* enhanced */
80 AS, EX, EX, AS, EX, AS, EX, EX /* enhanced */
83 static unsigned char kbd_key_map [2][5][144] =
87 0, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 0- 7 */
88 '7', '8', '9', '0', '-', '=', 0x08, '\t', /* scan 8- F */
89 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', /* scan 10-17 */
90 'o', 'p', '[', ']', '\r', CN, 'a', 's', /* scan 18-1F */
91 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* scan 20-27 */
92 '\'', '`', SH, '\\', 'z', 'x', 'c', 'v', /* scan 28-2F */
93 'b', 'n', 'm', ',', '.', '/', SH, '*', /* scan 30-37 */
94 ' ', ' ', CP, 0, 0, 0, 0, 0, /* scan 38-3F */
95 0, 0, 0, 0, 0, NM, ST, '7', /* scan 40-47 */
96 '8', '9', '-', '4', '5', '6', '+', '1', /* scan 48-4F */
97 '2', '3', '0', '.', 0, 0, 0, 0, /* scan 50-57 */
98 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */
99 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */
100 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */
101 0, 0, 0, 0, 0, 0, 0, 0, /* scan 70-77 */
102 0, 0, 0, 0, 0, 0, 0, 0, /* scan 78-7F */
103 '\r', CN, '/', '*', ' ', ST, 'F', 'A', /* extended */
104 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */
107 0, 0x1b, '!', '@', '#', '$', '%', '^', /* scan 0- 7 */
108 '&', '*', '(', ')', '_', '+', 0x08, '\t', /* scan 8- F */
109 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', /* scan 10-17 */
110 'O', 'P', '{', '}', '\r', CN, 'A', 'S', /* scan 18-1F */
111 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', /* scan 20-27 */
112 '"', '~', SH, '|', 'Z', 'X', 'C', 'V', /* scan 28-2F */
113 'B', 'N', 'M', '<', '>', '?', SH, '*', /* scan 30-37 */
114 ' ', ' ', CP, 0, 0, 0, 0, 0, /* scan 38-3F */
115 0, 0, 0, 0, 0, NM, ST, '7', /* scan 40-47 */
116 '8', '9', '-', '4', '5', '6', '+', '1', /* scan 48-4F */
117 '2', '3', '0', '.', 0, 0, 0, 0, /* scan 50-57 */
118 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */
119 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */
120 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */
121 0, 0, 0, 0, 0, 0, 0, 0, /* scan 70-77 */
122 0, 0, 0, 0, 0, 0, 0, 0, /* scan 78-7F */
123 '\r', CN, '/', '*', ' ', ST, 'F', 'A', /* extended */
124 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */
127 0xff, 0x1b, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, /* scan 0- 7 */
128 0x1e, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, '\t', /* scan 8- F */
129 0x11, 0x17, 0x05, 0x12, 0x14, 0x19, 0x15, 0x09, /* scan 10-17 */
130 0x0f, 0x10, 0x1b, 0x1d, '\r', CN, 0x01, 0x13, /* scan 18-1F */
131 0x04, 0x06, 0x07, 0x08, 0x0a, 0x0b, 0x0c, 0xff, /* scan 20-27 */
132 0xff, 0x1c, SH, 0xff, 0x1a, 0x18, 0x03, 0x16, /* scan 28-2F */
133 0x02, 0x0e, 0x0d, 0xff, 0xff, 0xff, SH, 0xff, /* scan 30-37 */
134 0xff, 0xff, CP, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */
135 0xff, 0xff, 0xff, 0xff, 0xff, NM, ST, 0xff, /* scan 40-47 */
136 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48-4F */
137 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 50-57 */
138 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58-5F */
139 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60-67 */
140 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68-6F */
141 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70-77 */
142 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78-7F */
143 '\r', CN, '/', '*', ' ', ST, 0xff, 0xff, /* extended */
144 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff /* extended */
146 { /* non numeric code */
147 0, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 0- 7 */
148 '7', '8', '9', '0', '-', '=', 0x08, '\t', /* scan 8- F */
149 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', /* scan 10-17 */
150 'o', 'p', '[', ']', '\r', CN, 'a', 's', /* scan 18-1F */
151 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* scan 20-27 */
152 '\'', '`', SH, '\\', 'z', 'x', 'c', 'v', /* scan 28-2F */
153 'b', 'n', 'm', ',', '.', '/', SH, '*', /* scan 30-37 */
154 ' ', ' ', CP, 0, 0, 0, 0, 0, /* scan 38-3F */
155 0, 0, 0, 0, 0, NM, ST, 'w', /* scan 40-47 */
156 'x', 'y', 'l', 't', 'u', 'v', 'm', 'q', /* scan 48-4F */
157 'r', 's', 'p', 'n', 0, 0, 0, 0, /* scan 50-57 */
158 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */
159 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */
160 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */
161 0, 0, 0, 0, 0, 0, 0, 0, /* scan 70-77 */
162 0, 0, 0, 0, 0, 0, 0, 0, /* scan 78-7F */
163 '\r', CN, '/', '*', ' ', ST, 'F', 'A', /* extended */
164 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */
166 { /* right alt mode - not used in US keyboard */
167 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 0 - 7 */
168 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 8 - F */
169 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 10 -17 */
170 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 18 -1F */
171 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 20 -27 */
172 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 28 -2F */
173 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 30 -37 */
174 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38 -3F */
175 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 40 -47 */
176 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48 -4F */
177 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 50 -57 */
178 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58 -5F */
179 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60 -67 */
180 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68 -6F */
181 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70 -77 */
182 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78 -7F */
183 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* extended */
184 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff /* extended */
187 { /* german keyboard */
189 0, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 0- 7 */
190 '7', '8', '9', '0', 0xe1, '\'', 0x08, '\t', /* scan 8- F */
191 'q', 'w', 'e', 'r', 't', 'z', 'u', 'i', /* scan 10-17 */
192 'o', 'p', 0x81, '+', '\r', CN, 'a', 's', /* scan 18-1F */
193 'd', 'f', 'g', 'h', 'j', 'k', 'l', 0x94, /* scan 20-27 */
194 0x84, '^', SH, '#', 'y', 'x', 'c', 'v', /* scan 28-2F */
195 'b', 'n', 'm', ',', '.', '-', SH, '*', /* scan 30-37 */
196 ' ', ' ', CP, 0, 0, 0, 0, 0, /* scan 38-3F */
197 0, 0, 0, 0, 0, NM, ST, '7', /* scan 40-47 */
198 '8', '9', '-', '4', '5', '6', '+', '1', /* scan 48-4F */
199 '2', '3', '0', ',', 0, 0, '<', 0, /* scan 50-57 */
200 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */
201 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */
202 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */
203 0, 0, 0, 0, 0, 0, 0, 0, /* scan 70-77 */
204 0, 0, 0, 0, 0, 0, 0, 0, /* scan 78-7F */
205 '\r', CN, '/', '*', ' ', ST, 'F', 'A', /* extended */
206 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */
209 0, 0x1b, '!', '"', 0x15, '$', '%', '&', /* scan 0- 7 */
210 '/', '(', ')', '=', '?', '`', 0x08, '\t', /* scan 8- F */
211 'Q', 'W', 'E', 'R', 'T', 'Z', 'U', 'I', /* scan 10-17 */
212 'O', 'P', 0x9a, '*', '\r', CN, 'A', 'S', /* scan 18-1F */
213 'D', 'F', 'G', 'H', 'J', 'K', 'L', 0x99, /* scan 20-27 */
214 0x8e, 0xf8, SH, '\'', 'Y', 'X', 'C', 'V', /* scan 28-2F */
215 'B', 'N', 'M', ';', ':', '_', SH, '*', /* scan 30-37 */
216 ' ', ' ', CP, 0, 0, 0, 0, 0, /* scan 38-3F */
217 0, 0, 0, 0, 0, NM, ST, '7', /* scan 40-47 */
218 '8', '9', '-', '4', '5', '6', '+', '1', /* scan 48-4F */
219 '2', '3', '0', ',', 0, 0, '>', 0, /* scan 50-57 */
220 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */
221 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */
222 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */
223 0, 0, 0, 0, 0, 0, 0, 0, /* scan 70-77 */
224 0, 0, 0, 0, 0, 0, 0, 0, /* scan 78-7F */
225 '\r', CN, '/', '*', ' ', ST, 'F', 'A', /* extended */
226 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */
229 0xff, 0x1b, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, /* scan 0- 7 */
230 0x1e, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, '\t', /* scan 8- F */
231 0x11, 0x17, 0x05, 0x12, 0x14, 0x19, 0x15, 0x09, /* scan 10-17 */
232 0x0f, 0x10, 0x1b, 0x1d, '\r', CN, 0x01, 0x13, /* scan 18-1F */
233 0x04, 0x06, 0x07, 0x08, 0x0a, 0x0b, 0x0c, 0xff, /* scan 20-27 */
234 0xff, 0x1c, SH, 0xff, 0x1a, 0x18, 0x03, 0x16, /* scan 28-2F */
235 0x02, 0x0e, 0x0d, 0xff, 0xff, 0xff, SH, 0xff, /* scan 30-37 */
236 0xff, 0xff, CP, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */
237 0xff, 0xff, 0xff, 0xff, 0xff, NM, ST, 0xff, /* scan 40-47 */
238 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48-4F */
239 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 50-57 */
240 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58-5F */
241 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60-67 */
242 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68-6F */
243 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70-77 */
244 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78-7F */
245 '\r', CN, '/', '*', ' ', ST, 0xff, 0xff, /* extended */
246 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff /* extended */
248 { /* non numeric code */
249 0, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 0- 7 */
250 '7', '8', '9', '0', 0xe1, '\'', 0x08, '\t', /* scan 8- F */
251 'q', 'w', 'e', 'r', 't', 'z', 'u', 'i', /* scan 10-17 */
252 'o', 'p', 0x81, '+', '\r', CN, 'a', 's', /* scan 18-1F */
253 'd', 'f', 'g', 'h', 'j', 'k', 'l', 0x94, /* scan 20-27 */
254 0x84, '^', SH, 0, 'y', 'x', 'c', 'v', /* scan 28-2F */
255 'b', 'n', 'm', ',', '.', '-', SH, '*', /* scan 30-37 */
256 ' ', ' ', CP, 0, 0, 0, 0, 0, /* scan 38-3F */
257 0, 0, 0, 0, 0, NM, ST, 'w', /* scan 40-47 */
258 'x', 'y', 'l', 't', 'u', 'v', 'm', 'q', /* scan 48-4F */
259 'r', 's', 'p', 'n', 0, 0, '<', 0, /* scan 50-57 */
260 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */
261 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */
262 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */
263 0, 0, 0, 0, 0, 0, 0, 0, /* scan 70-77 */
264 0, 0, 0, 0, 0, 0, 0, 0, /* scan 78-7F */
265 '\r', CN, '/', '*', ' ', ST, 'F', 'A', /* extended */
266 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */
268 { /* Right alt mode - is used in German keyboard */
269 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 0 - 7 */
270 '{', '[', ']', '}', '\\', 0xff, 0xff, 0xff, /* scan 8 - F */
271 '@', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 10 -17 */
272 0xff, 0xff, 0xff, '~', 0xff, 0xff, 0xff, 0xff, /* scan 18 -1F */
273 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 20 -27 */
274 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 28 -2F */
275 0xff, 0xff, 0xe6, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 30 -37 */
276 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38 -3F */
277 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 40 -47 */
278 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48 -4F */
279 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, '|', 0xff, /* scan 50 -57 */
280 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58 -5F */
281 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60 -67 */
282 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68 -6F */
283 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70 -77 */
284 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78 -7F */
285 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* extended */
286 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff /* extended */
291 static unsigned char ext_key_map [] =
293 0x1c, /* keypad enter */
294 0x1d, /* right control */
295 0x35, /* keypad slash */
296 0x37, /* print screen */
297 0x38, /* right alt */
299 0x47, /* editpad home */
300 0x48, /* editpad up */
301 0x49, /* editpad pgup */
302 0x4b, /* editpad left */
303 0x4d, /* editpad right */
304 0x4f, /* editpad end */
305 0x50, /* editpad dn */
306 0x51, /* editpad pgdn */
307 0x52, /* editpad ins */
308 0x53, /* editpad del */
312 /*******************************************************************************
314 * i8042_kbd_init - reset keyboard and init state flags
316 int i8042_kbd_init (void)
321 /* Init keyboard device (default US layout) */
323 if ((penv = getenv ("keymap")) != NULL)
325 if (strncmp (penv, "de", 3) == 0)
329 for (try = 0; try < KBD_RESET_TRIES; try++)
331 if (kbd_reset() == 0)
333 kbd_mapping = keymap;
344 /*******************************************************************************
346 * i8042_tstc - test if keyboard input is available
347 * option: cursor blinking if called in a loop
349 int i8042_tstc (void)
351 unsigned char scan_code = 0;
353 #ifdef CONFIG_CONSOLE_CURSOR
354 if (--blinkCount == 0)
357 console_cursor (cursor_state);
358 blinkCount = CFG_CONSOLE_BLINK_COUNT;
363 if ((in8 (I8042_STATUS_REG) & 0x01) == 0)
367 scan_code = in8 (I8042_DATA_REG);
368 if (scan_code == 0xfa)
371 kbd_conv_char(scan_code);
380 /*******************************************************************************
382 * i8042_getc - wait till keyboard input is available
383 * option: turn on/off cursor while waiting
385 int i8042_getc (void)
388 unsigned char scan_code;
390 while (kbd_input == -1)
392 while ((in8 (I8042_STATUS_REG) & 0x01) == 0)
394 #ifdef CONFIG_CONSOLE_CURSOR
398 console_cursor (cursor_state);
399 blinkCount = CFG_CONSOLE_BLINK_COUNT;
405 scan_code = in8 (I8042_DATA_REG);
407 if (scan_code != 0xfa)
408 kbd_conv_char (scan_code);
416 /******************************************************************************/
418 static void kbd_conv_char (unsigned char scan_code)
420 if (scan_code == 0xe0)
426 /* if high bit of scan_code, set break flag */
427 if (scan_code & 0x80)
432 if ((scan_code == 0xe1) || (kbd_flags & E1))
434 if (scan_code == 0xe1)
436 kbd_flags ^= BRK; /* reset the break flag */
437 kbd_flags ^= E1; /* bitwise EXOR with E1 flag */
449 for (i=0; ext_key_map[i]; i++)
451 if (ext_key_map[i] == scan_code)
453 scan_code = 0x80 + i;
462 switch (kbd_fct_map [scan_code])
464 case AS: kbd_normal (scan_code);
466 case SH: kbd_shift (scan_code);
468 case CN: kbd_ctrl (scan_code);
470 case NM: kbd_num (scan_code);
472 case CP: kbd_caps (scan_code);
474 case ST: kbd_scroll (scan_code);
476 case AK: kbd_alt (scan_code);
483 /******************************************************************************/
485 static void kbd_normal (unsigned char scan_code)
489 if ((kbd_flags & BRK) == NORMAL)
491 chr = kbd_key_map [kbd_mapping][kbd_state][scan_code];
492 if ((chr == 0xff) || (chr == 0x00))
497 /* if caps lock convert upper to lower */
498 if (((kbd_flags & CAPS) == CAPS) && (chr >= 'a' && chr <= 'z'))
507 /******************************************************************************/
509 static void kbd_shift (unsigned char scan_code)
511 if ((kbd_flags & BRK) == BRK)
514 kbd_flags &= (~SHIFT);
524 /******************************************************************************/
526 static void kbd_ctrl (unsigned char scan_code)
528 if ((kbd_flags & BRK) == BRK)
531 kbd_flags &= (~CTRL);
541 /******************************************************************************/
543 static void kbd_caps (unsigned char scan_code)
545 if ((kbd_flags & BRK) == NORMAL)
548 kbd_led_set (); /* update keyboard LED */
553 /******************************************************************************/
555 static void kbd_num (unsigned char scan_code)
557 if ((kbd_flags & BRK) == NORMAL)
560 kbd_state = (kbd_flags & NUM) ? AS : NM;
561 kbd_led_set (); /* update keyboard LED */
566 /******************************************************************************/
568 static void kbd_scroll (unsigned char scan_code)
570 if ((kbd_flags & BRK) == NORMAL)
573 kbd_led_set (); /* update keyboard LED */
581 /******************************************************************************/
583 static void kbd_alt (unsigned char scan_code)
585 if ((kbd_flags & BRK) == BRK)
598 /******************************************************************************/
600 static void kbd_led_set (void)
603 out8 (I8042_DATA_REG, 0xed); /* SET LED command */
605 out8 (I8042_DATA_REG, (kbd_flags & 0x7)); /* LED bits only */
609 /******************************************************************************/
611 static int kbd_input_empty (void)
613 int kbdTimeout = KBD_TIMEOUT;
615 /* wait for input buf empty */
616 while ((in8 (I8042_STATUS_REG) & 0x02) && kbdTimeout--)
622 /******************************************************************************/
624 static int kbd_reset (void)
626 if (kbd_input_empty() == 0)
629 out8 (I8042_DATA_REG, 0xff);
633 if (kbd_input_empty() == 0)
636 out8 (I8042_DATA_REG, 0x60);
638 if (kbd_input_empty() == 0)
641 out8 (I8042_DATA_REG, 0x45);
644 if (kbd_input_empty() == 0)
647 out8 (I8042_COMMAND_REG, 0xae);
649 if (kbd_input_empty() == 0)
655 #endif /* CONFIG_I8042_KBD */