1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28#include <common.h>
29
30#ifdef CONFIG_USE_CPCIDVI
31extern u8 gt_cpcidvi_in8(u32 offset);
32extern void gt_cpcidvi_out8(u32 offset, u8 data);
33
34#define in8(a) gt_cpcidvi_in8(a)
35#define out8(a, b) gt_cpcidvi_out8(a,b)
36#endif
37
38#include <i8042.h>
39
40
41
42#ifdef CONFIG_CONSOLE_CURSOR
43extern void console_cursor (int state);
44static int blinkCount = CONFIG_SYS_CONSOLE_BLINK_COUNT;
45static int cursor_state = 0;
46#endif
47
48
49
50static int kbd_input = -1;
51static int kbd_mapping = KBD_US;
52static int kbd_flags = NORMAL;
53static int kbd_state = 0;
54
55static void kbd_conv_char (unsigned char scan_code);
56static void kbd_led_set (void);
57static void kbd_normal (unsigned char scan_code);
58static void kbd_shift (unsigned char scan_code);
59static void kbd_ctrl (unsigned char scan_code);
60static void kbd_num (unsigned char scan_code);
61static void kbd_caps (unsigned char scan_code);
62static void kbd_scroll (unsigned char scan_code);
63static void kbd_alt (unsigned char scan_code);
64static int kbd_input_empty (void);
65static int kbd_reset (void);
66
67static unsigned char kbd_fct_map [144] =
68 {
69 0, AS, AS, AS, AS, AS, AS, AS,
70 AS, AS, AS, AS, AS, AS, AS, AS,
71 AS, AS, AS, AS, AS, AS, AS, AS,
72 AS, AS, AS, AS, AS, CN, AS, AS,
73 AS, AS, AS, AS, AS, AS, AS, AS,
74 AS, AS, SH, AS, AS, AS, AS, AS,
75 AS, AS, AS, AS, AS, AS, SH, AS,
76 AS, AS, CP, 0, 0, 0, 0, 0,
77 0, 0, 0, 0, 0, NM, ST, ES,
78 ES, ES, ES, ES, ES, ES, ES, ES,
79 ES, ES, ES, ES, 0, 0, AS, 0,
80 0, 0, 0, 0, 0, 0, 0, 0,
81 0, 0, 0, 0, 0, 0, 0, 0,
82 0, 0, 0, 0, 0, 0, 0, 0,
83 AS, 0, 0, AS, 0, 0, AS, 0,
84 0, AS, 0, 0, 0, AS, 0, 0,
85 AS, CN, AS, AS, AK, ST, EX, EX,
86 AS, EX, EX, AS, EX, AS, EX, EX
87 };
88
89static unsigned char kbd_key_map [2][5][144] =
90 {
91 {
92 {
93 0, 0x1b, '1', '2', '3', '4', '5', '6',
94 '7', '8', '9', '0', '-', '=', 0x08, '\t',
95 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i',
96 'o', 'p', '[', ']', '\r', CN, 'a', 's',
97 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',
98 '\'', '`', SH, '\\', 'z', 'x', 'c', 'v',
99 'b', 'n', 'm', ',', '.', '/', SH, '*',
100 ' ', ' ', CP, 0, 0, 0, 0, 0,
101 0, 0, 0, 0, 0, NM, ST, '7',
102 '8', '9', '-', '4', '5', '6', '+', '1',
103 '2', '3', '0', '.', 0, 0, 0, 0,
104 0, 0, 0, 0, 0, 0, 0, 0,
105 0, 0, 0, 0, 0, 0, 0, 0,
106 0, 0, 0, 0, 0, 0, 0, 0,
107 0, 0, 0, 0, 0, 0, 0, 0,
108 0, 0, 0, 0, 0, 0, 0, 0,
109 '\r', CN, '/', '*', ' ', ST, 'F', 'A',
110 0, 'D', 'C', 0, 'B', 0, '@', 'P'
111 },
112 {
113 0, 0x1b, '!', '@', '#', '$', '%', '^',
114 '&', '*', '(', ')', '_', '+', 0x08, '\t',
115 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I',
116 'O', 'P', '{', '}', '\r', CN, 'A', 'S',
117 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':',
118 '"', '~', SH, '|', 'Z', 'X', 'C', 'V',
119 'B', 'N', 'M', '<', '>', '?', SH, '*',
120 ' ', ' ', CP, 0, 0, 0, 0, 0,
121 0, 0, 0, 0, 0, NM, ST, '7',
122 '8', '9', '-', '4', '5', '6', '+', '1',
123 '2', '3', '0', '.', 0, 0, 0, 0,
124 0, 0, 0, 0, 0, 0, 0, 0,
125 0, 0, 0, 0, 0, 0, 0, 0,
126 0, 0, 0, 0, 0, 0, 0, 0,
127 0, 0, 0, 0, 0, 0, 0, 0,
128 0, 0, 0, 0, 0, 0, 0, 0,
129 '\r', CN, '/', '*', ' ', ST, 'F', 'A',
130 0, 'D', 'C', 0, 'B', 0, '@', 'P'
131 },
132 {
133 0xff, 0x1b, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff,
134 0x1e, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, '\t',
135 0x11, 0x17, 0x05, 0x12, 0x14, 0x19, 0x15, 0x09,
136 0x0f, 0x10, 0x1b, 0x1d, '\r', CN, 0x01, 0x13,
137 0x04, 0x06, 0x07, 0x08, 0x0a, 0x0b, 0x0c, 0xff,
138 0xff, 0x1c, SH, 0xff, 0x1a, 0x18, 0x03, 0x16,
139 0x02, 0x0e, 0x0d, 0xff, 0xff, 0xff, SH, 0xff,
140 0xff, 0xff, CP, 0xff, 0xff, 0xff, 0xff, 0xff,
141 0xff, 0xff, 0xff, 0xff, 0xff, NM, ST, 0xff,
142 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
143 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
144 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
145 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
146 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
147 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
148 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
149 '\r', CN, '/', '*', ' ', ST, 0xff, 0xff,
150 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
151 },
152 {
153 0, 0x1b, '1', '2', '3', '4', '5', '6',
154 '7', '8', '9', '0', '-', '=', 0x08, '\t',
155 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i',
156 'o', 'p', '[', ']', '\r', CN, 'a', 's',
157 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',
158 '\'', '`', SH, '\\', 'z', 'x', 'c', 'v',
159 'b', 'n', 'm', ',', '.', '/', SH, '*',
160 ' ', ' ', CP, 0, 0, 0, 0, 0,
161 0, 0, 0, 0, 0, NM, ST, 'w',
162 'x', 'y', 'l', 't', 'u', 'v', 'm', 'q',
163 'r', 's', 'p', 'n', 0, 0, 0, 0,
164 0, 0, 0, 0, 0, 0, 0, 0,
165 0, 0, 0, 0, 0, 0, 0, 0,
166 0, 0, 0, 0, 0, 0, 0, 0,
167 0, 0, 0, 0, 0, 0, 0, 0,
168 0, 0, 0, 0, 0, 0, 0, 0,
169 '\r', CN, '/', '*', ' ', ST, 'F', 'A',
170 0, 'D', 'C', 0, 'B', 0, '@', 'P'
171 },
172 {
173 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
174 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
175 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
176 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
177 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
178 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
179 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
180 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
181 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
182 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
183 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
184 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
185 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
186 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
187 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
188 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
189 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
190 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
191 }
192 },
193 {
194 {
195 0, 0x1b, '1', '2', '3', '4', '5', '6',
196 '7', '8', '9', '0', 0xe1, '\'', 0x08, '\t',
197 'q', 'w', 'e', 'r', 't', 'z', 'u', 'i',
198 'o', 'p', 0x81, '+', '\r', CN, 'a', 's',
199 'd', 'f', 'g', 'h', 'j', 'k', 'l', 0x94,
200 0x84, '^', SH, '#', 'y', 'x', 'c', 'v',
201 'b', 'n', 'm', ',', '.', '-', SH, '*',
202 ' ', ' ', CP, 0, 0, 0, 0, 0,
203 0, 0, 0, 0, 0, NM, ST, '7',
204 '8', '9', '-', '4', '5', '6', '+', '1',
205 '2', '3', '0', ',', 0, 0, '<', 0,
206 0, 0, 0, 0, 0, 0, 0, 0,
207 0, 0, 0, 0, 0, 0, 0, 0,
208 0, 0, 0, 0, 0, 0, 0, 0,
209 0, 0, 0, 0, 0, 0, 0, 0,
210 0, 0, 0, 0, 0, 0, 0, 0,
211 '\r', CN, '/', '*', ' ', ST, 'F', 'A',
212 0, 'D', 'C', 0, 'B', 0, '@', 'P'
213 },
214 {
215 0, 0x1b, '!', '"', 0x15, '$', '%', '&',
216 '/', '(', ')', '=', '?', '`', 0x08, '\t',
217 'Q', 'W', 'E', 'R', 'T', 'Z', 'U', 'I',
218 'O', 'P', 0x9a, '*', '\r', CN, 'A', 'S',
219 'D', 'F', 'G', 'H', 'J', 'K', 'L', 0x99,
220 0x8e, 0xf8, SH, '\'', 'Y', 'X', 'C', 'V',
221 'B', 'N', 'M', ';', ':', '_', SH, '*',
222 ' ', ' ', CP, 0, 0, 0, 0, 0,
223 0, 0, 0, 0, 0, NM, ST, '7',
224 '8', '9', '-', '4', '5', '6', '+', '1',
225 '2', '3', '0', ',', 0, 0, '>', 0,
226 0, 0, 0, 0, 0, 0, 0, 0,
227 0, 0, 0, 0, 0, 0, 0, 0,
228 0, 0, 0, 0, 0, 0, 0, 0,
229 0, 0, 0, 0, 0, 0, 0, 0,
230 0, 0, 0, 0, 0, 0, 0, 0,
231 '\r', CN, '/', '*', ' ', ST, 'F', 'A',
232 0, 'D', 'C', 0, 'B', 0, '@', 'P'
233 },
234 {
235 0xff, 0x1b, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff,
236 0x1e, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, '\t',
237 0x11, 0x17, 0x05, 0x12, 0x14, 0x19, 0x15, 0x09,
238 0x0f, 0x10, 0x1b, 0x1d, '\r', CN, 0x01, 0x13,
239 0x04, 0x06, 0x07, 0x08, 0x0a, 0x0b, 0x0c, 0xff,
240 0xff, 0x1c, SH, 0xff, 0x1a, 0x18, 0x03, 0x16,
241 0x02, 0x0e, 0x0d, 0xff, 0xff, 0xff, SH, 0xff,
242 0xff, 0xff, CP, 0xff, 0xff, 0xff, 0xff, 0xff,
243 0xff, 0xff, 0xff, 0xff, 0xff, NM, ST, 0xff,
244 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
245 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
246 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
247 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
248 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
249 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
250 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
251 '\r', CN, '/', '*', ' ', ST, 0xff, 0xff,
252 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
253 },
254 {
255 0, 0x1b, '1', '2', '3', '4', '5', '6',
256 '7', '8', '9', '0', 0xe1, '\'', 0x08, '\t',
257 'q', 'w', 'e', 'r', 't', 'z', 'u', 'i',
258 'o', 'p', 0x81, '+', '\r', CN, 'a', 's',
259 'd', 'f', 'g', 'h', 'j', 'k', 'l', 0x94,
260 0x84, '^', SH, 0, 'y', 'x', 'c', 'v',
261 'b', 'n', 'm', ',', '.', '-', SH, '*',
262 ' ', ' ', CP, 0, 0, 0, 0, 0,
263 0, 0, 0, 0, 0, NM, ST, 'w',
264 'x', 'y', 'l', 't', 'u', 'v', 'm', 'q',
265 'r', 's', 'p', 'n', 0, 0, '<', 0,
266 0, 0, 0, 0, 0, 0, 0, 0,
267 0, 0, 0, 0, 0, 0, 0, 0,
268 0, 0, 0, 0, 0, 0, 0, 0,
269 0, 0, 0, 0, 0, 0, 0, 0,
270 0, 0, 0, 0, 0, 0, 0, 0,
271 '\r', CN, '/', '*', ' ', ST, 'F', 'A',
272 0, 'D', 'C', 0, 'B', 0, '@', 'P'
273 },
274 {
275 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
276 '{', '[', ']', '}', '\\', 0xff, 0xff, 0xff,
277 '@', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
278 0xff, 0xff, 0xff, '~', 0xff, 0xff, 0xff, 0xff,
279 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
280 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
281 0xff, 0xff, 0xe6, 0xff, 0xff, 0xff, 0xff, 0xff,
282 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
283 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
284 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
285 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, '|', 0xff,
286 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
287 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
288 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
289 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
290 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
291 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
292 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
293 }
294 }
295 };
296
297static unsigned char ext_key_map [] =
298 {
299 0x1c,
300 0x1d,
301 0x35,
302 0x37,
303 0x38,
304 0x46,
305 0x47,
306 0x48,
307 0x49,
308 0x4b,
309 0x4d,
310 0x4f,
311 0x50,
312 0x51,
313 0x52,
314 0x53,
315 0x00
316 };
317
318
319
320
321
322int i8042_kbd_init (void)
323{
324 int keymap, try;
325 char *penv;
326
327#ifdef CONFIG_USE_CPCIDVI
328 if ((penv = getenv ("console")) != NULL) {
329 if (strncmp (penv, "serial", 7) == 0) {
330 return -1;
331 }
332 }
333#endif
334
335 keymap = KBD_US;
336 if ((penv = getenv ("keymap")) != NULL)
337 {
338 if (strncmp (penv, "de", 3) == 0)
339 keymap = KBD_GER;
340 }
341
342 for (try = 0; try < KBD_RESET_TRIES; try++)
343 {
344 if (kbd_reset() == 0)
345 {
346 kbd_mapping = keymap;
347 kbd_flags = NORMAL;
348 kbd_state = 0;
349 kbd_led_set();
350 return 0;
351 }
352 }
353 return -1;
354}
355
356
357
358
359
360
361
362int i8042_tstc (void)
363{
364 unsigned char scan_code = 0;
365
366#ifdef CONFIG_CONSOLE_CURSOR
367 if (--blinkCount == 0)
368 {
369 cursor_state ^= 1;
370 console_cursor (cursor_state);
371 blinkCount = CONFIG_SYS_CONSOLE_BLINK_COUNT;
372 udelay (10);
373 }
374#endif
375
376 if ((in8 (I8042_STATUS_REG) & 0x01) == 0)
377 return 0;
378 else
379 {
380 scan_code = in8 (I8042_DATA_REG);
381 if (scan_code == 0xfa)
382 return 0;
383
384 kbd_conv_char(scan_code);
385
386 if (kbd_input != -1)
387 return 1;
388 }
389 return 0;
390}
391
392
393
394
395
396
397
398int i8042_getc (void)
399{
400 int ret_chr;
401 unsigned char scan_code;
402
403 while (kbd_input == -1)
404 {
405 while ((in8 (I8042_STATUS_REG) & 0x01) == 0)
406 {
407#ifdef CONFIG_CONSOLE_CURSOR
408 if (--blinkCount==0)
409 {
410 cursor_state ^= 1;
411 console_cursor (cursor_state);
412 blinkCount = CONFIG_SYS_CONSOLE_BLINK_COUNT;
413 }
414 udelay (10);
415#endif
416 }
417
418 scan_code = in8 (I8042_DATA_REG);
419
420 if (scan_code != 0xfa)
421 kbd_conv_char (scan_code);
422 }
423 ret_chr = kbd_input;
424 kbd_input = -1;
425 return ret_chr;
426}
427
428
429
430
431static void kbd_conv_char (unsigned char scan_code)
432{
433 if (scan_code == 0xe0)
434 {
435 kbd_flags |= EXT;
436 return;
437 }
438
439
440 if (scan_code & 0x80)
441 kbd_flags |= BRK;
442 else
443 kbd_flags &= ~BRK;
444
445 if ((scan_code == 0xe1) || (kbd_flags & E1))
446 {
447 if (scan_code == 0xe1)
448 {
449 kbd_flags ^= BRK;
450 kbd_flags ^= E1;
451 }
452 return;
453 }
454
455 scan_code &= 0x7f;
456
457 if (kbd_flags & EXT)
458 {
459 int i;
460
461 kbd_flags ^= EXT;
462 for (i=0; ext_key_map[i]; i++)
463 {
464 if (ext_key_map[i] == scan_code)
465 {
466 scan_code = 0x80 + i;
467 break;
468 }
469 }
470
471 if (!ext_key_map[i])
472 return;
473 }
474
475 switch (kbd_fct_map [scan_code])
476 {
477 case AS: kbd_normal (scan_code);
478 break;
479 case SH: kbd_shift (scan_code);
480 break;
481 case CN: kbd_ctrl (scan_code);
482 break;
483 case NM: kbd_num (scan_code);
484 break;
485 case CP: kbd_caps (scan_code);
486 break;
487 case ST: kbd_scroll (scan_code);
488 break;
489 case AK: kbd_alt (scan_code);
490 break;
491 }
492 return;
493}
494
495
496
497
498static void kbd_normal (unsigned char scan_code)
499{
500 unsigned char chr;
501
502 if ((kbd_flags & BRK) == NORMAL)
503 {
504 chr = kbd_key_map [kbd_mapping][kbd_state][scan_code];
505 if ((chr == 0xff) || (chr == 0x00))
506 {
507 return;
508 }
509
510
511 if (((kbd_flags & CAPS) == CAPS) && (chr >= 'a' && chr <= 'z'))
512 {
513 chr -= 'a' - 'A';
514 }
515 kbd_input = chr;
516 }
517}
518
519
520
521
522static void kbd_shift (unsigned char scan_code)
523{
524 if ((kbd_flags & BRK) == BRK)
525 {
526 kbd_state = AS;
527 kbd_flags &= (~SHIFT);
528 }
529 else
530 {
531 kbd_state = SH;
532 kbd_flags |= SHIFT;
533 }
534}
535
536
537
538
539static void kbd_ctrl (unsigned char scan_code)
540{
541 if ((kbd_flags & BRK) == BRK)
542 {
543 kbd_state = AS;
544 kbd_flags &= (~CTRL);
545 }
546 else
547 {
548 kbd_state = CN;
549 kbd_flags |= CTRL;
550 }
551}
552
553
554
555
556static void kbd_caps (unsigned char scan_code)
557{
558 if ((kbd_flags & BRK) == NORMAL)
559 {
560 kbd_flags ^= CAPS;
561 kbd_led_set ();
562 }
563}
564
565
566
567
568static void kbd_num (unsigned char scan_code)
569{
570 if ((kbd_flags & BRK) == NORMAL)
571 {
572 kbd_flags ^= NUM;
573 kbd_state = (kbd_flags & NUM) ? AS : NM;
574 kbd_led_set ();
575 }
576}
577
578
579
580
581static void kbd_scroll (unsigned char scan_code)
582{
583 if ((kbd_flags & BRK) == NORMAL)
584 {
585 kbd_flags ^= STP;
586 kbd_led_set ();
587 if (kbd_flags & STP)
588 kbd_input = 0x13;
589 else
590 kbd_input = 0x11;
591 }
592}
593
594
595
596static void kbd_alt (unsigned char scan_code)
597{
598 if ((kbd_flags & BRK) == BRK)
599 {
600 kbd_state = AS;
601 kbd_flags &= (~ALT);
602 }
603 else
604 {
605 kbd_state = AK;
606 kbd_flags &= ALT;
607 }
608}
609
610
611
612
613static void kbd_led_set (void)
614{
615 kbd_input_empty();
616 out8 (I8042_DATA_REG, 0xed);
617 kbd_input_empty();
618 out8 (I8042_DATA_REG, (kbd_flags & 0x7));
619}
620
621
622
623
624static int kbd_input_empty (void)
625{
626 int kbdTimeout = KBD_TIMEOUT;
627
628
629 while ((in8 (I8042_STATUS_REG) & 0x02) && kbdTimeout--)
630 udelay(1000);
631
632 return kbdTimeout;
633}
634
635
636
637static int kbd_reset (void)
638{
639 if (kbd_input_empty() == 0)
640 return -1;
641
642 out8 (I8042_DATA_REG, 0xff);
643
644 udelay(250000);
645
646 if (kbd_input_empty() == 0)
647 return -1;
648
649#ifdef CONFIG_USE_CPCIDVI
650 out8 (I8042_COMMAND_REG, 0x60);
651#else
652 out8 (I8042_DATA_REG, 0x60);
653#endif
654
655 if (kbd_input_empty() == 0)
656 return -1;
657
658 out8 (I8042_DATA_REG, 0x45);
659
660
661 if (kbd_input_empty() == 0)
662 return -1;
663
664 out8 (I8042_COMMAND_REG, 0xae);
665
666 if (kbd_input_empty() == 0)
667 return -1;
668
669 return 0;
670}
671