wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 ELTEC Elektronik AG |
| 3 | * Frank Gottschling <fgottschling@eltec.de> |
| 4 | * |
Wolfgang Denk | 3765b3e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* i8042.c - Intel 8042 keyboard driver routines */ |
| 9 | |
| 10 | /* includes */ |
| 11 | |
| 12 | #include <common.h> |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 13 | #include <asm/io.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 14 | #include <i8042.h> |
| 15 | |
| 16 | /* defines */ |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 17 | #define in8(p) inb(p) |
| 18 | #define out8(p, v) outb(v, p) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 19 | |
| 20 | #ifdef CONFIG_CONSOLE_CURSOR |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 21 | extern void console_cursor(int state); |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 22 | static int blink_count = CONFIG_SYS_CONSOLE_BLINK_COUNT; |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 23 | static int cursor_state; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 24 | #endif |
| 25 | |
| 26 | /* locals */ |
| 27 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 28 | static int kbd_input = -1; /* no input yet */ |
| 29 | static int kbd_mapping = KBD_US; /* default US keyboard */ |
| 30 | static int kbd_flags = NORMAL; /* after reset */ |
| 31 | static int kbd_state; /* unshift code */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 32 | |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 33 | static unsigned char kbd_fct_map[144] = { |
| 34 | /* kbd_fct_map table for scan code */ |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 35 | 0, AS, AS, AS, AS, AS, AS, AS, /* scan 00-07 */ |
| 36 | AS, AS, AS, AS, AS, AS, AS, AS, /* scan 08-0F */ |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 37 | AS, AS, AS, AS, AS, AS, AS, AS, /* scan 10-17 */ |
| 38 | AS, AS, AS, AS, AS, CN, AS, AS, /* scan 18-1F */ |
| 39 | AS, AS, AS, AS, AS, AS, AS, AS, /* scan 20-27 */ |
| 40 | AS, AS, SH, AS, AS, AS, AS, AS, /* scan 28-2F */ |
| 41 | AS, AS, AS, AS, AS, AS, SH, AS, /* scan 30-37 */ |
| 42 | AS, AS, CP, 0, 0, 0, 0, 0, /* scan 38-3F */ |
| 43 | 0, 0, 0, 0, 0, NM, ST, ES, /* scan 40-47 */ |
| 44 | ES, ES, ES, ES, ES, ES, ES, ES, /* scan 48-4F */ |
| 45 | ES, ES, ES, ES, 0, 0, AS, 0, /* scan 50-57 */ |
| 46 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */ |
| 47 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */ |
| 48 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */ |
| 49 | AS, 0, 0, AS, 0, 0, AS, 0, /* scan 70-77 */ |
| 50 | 0, AS, 0, 0, 0, AS, 0, 0, /* scan 78-7F */ |
| 51 | AS, CN, AS, AS, AK, ST, EX, EX, /* enhanced */ |
| 52 | AS, EX, EX, AS, EX, AS, EX, EX /* enhanced */ |
| 53 | }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 54 | |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 55 | static unsigned char kbd_key_map[2][5][144] = { |
| 56 | { /* US keyboard */ |
| 57 | { /* unshift code */ |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 58 | 0, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 00-07 */ |
| 59 | '7', '8', '9', '0', '-', '=', 0x08, '\t', /* scan 08-0F */ |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 60 | 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', /* scan 10-17 */ |
| 61 | 'o', 'p', '[', ']', '\r', CN, 'a', 's', /* scan 18-1F */ |
| 62 | 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* scan 20-27 */ |
| 63 | '\'', '`', SH, '\\', 'z', 'x', 'c', 'v', /* scan 28-2F */ |
| 64 | 'b', 'n', 'm', ',', '.', '/', SH, '*', /* scan 30-37 */ |
| 65 | ' ', ' ', CP, 0, 0, 0, 0, 0, /* scan 38-3F */ |
| 66 | 0, 0, 0, 0, 0, NM, ST, '7', /* scan 40-47 */ |
| 67 | '8', '9', '-', '4', '5', '6', '+', '1', /* scan 48-4F */ |
| 68 | '2', '3', '0', '.', 0, 0, 0, 0, /* scan 50-57 */ |
| 69 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */ |
| 70 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */ |
| 71 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */ |
| 72 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 70-77 */ |
| 73 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 78-7F */ |
| 74 | '\r', CN, '/', '*', ' ', ST, 'F', 'A', /* extended */ |
| 75 | 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */ |
| 76 | }, |
| 77 | { /* shift code */ |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 78 | 0, 0x1b, '!', '@', '#', '$', '%', '^', /* scan 00-07 */ |
| 79 | '&', '*', '(', ')', '_', '+', 0x08, '\t', /* scan 08-0F */ |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 80 | 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', /* scan 10-17 */ |
| 81 | 'O', 'P', '{', '}', '\r', CN, 'A', 'S', /* scan 18-1F */ |
| 82 | 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', /* scan 20-27 */ |
| 83 | '"', '~', SH, '|', 'Z', 'X', 'C', 'V', /* scan 28-2F */ |
| 84 | 'B', 'N', 'M', '<', '>', '?', SH, '*', /* scan 30-37 */ |
| 85 | ' ', ' ', CP, 0, 0, 0, 0, 0, /* scan 38-3F */ |
| 86 | 0, 0, 0, 0, 0, NM, ST, '7', /* scan 40-47 */ |
| 87 | '8', '9', '-', '4', '5', '6', '+', '1', /* scan 48-4F */ |
| 88 | '2', '3', '0', '.', 0, 0, 0, 0, /* scan 50-57 */ |
| 89 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */ |
| 90 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */ |
| 91 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */ |
| 92 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 70-77 */ |
| 93 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 78-7F */ |
| 94 | '\r', CN, '/', '*', ' ', ST, 'F', 'A', /* extended */ |
| 95 | 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */ |
| 96 | }, |
| 97 | { /* control code */ |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 98 | 0xff, 0x1b, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, /* scan 00-07 */ |
| 99 | 0x1e, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, '\t', /* scan 08-0F */ |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 100 | 0x11, 0x17, 0x05, 0x12, 0x14, 0x19, 0x15, 0x09, /* scan 10-17 */ |
| 101 | 0x0f, 0x10, 0x1b, 0x1d, '\r', CN, 0x01, 0x13, /* scan 18-1F */ |
| 102 | 0x04, 0x06, 0x07, 0x08, 0x0a, 0x0b, 0x0c, 0xff, /* scan 20-27 */ |
| 103 | 0xff, 0x1c, SH, 0xff, 0x1a, 0x18, 0x03, 0x16, /* scan 28-2F */ |
| 104 | 0x02, 0x0e, 0x0d, 0xff, 0xff, 0xff, SH, 0xff, /* scan 30-37 */ |
| 105 | 0xff, 0xff, CP, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */ |
| 106 | 0xff, 0xff, 0xff, 0xff, 0xff, NM, ST, 0xff, /* scan 40-47 */ |
| 107 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48-4F */ |
| 108 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 50-57 */ |
| 109 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58-5F */ |
| 110 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60-67 */ |
| 111 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68-6F */ |
| 112 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70-77 */ |
| 113 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78-7F */ |
| 114 | '\r', CN, '/', '*', ' ', ST, 0xff, 0xff, /* extended */ |
| 115 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff /* extended */ |
| 116 | }, |
| 117 | { /* non numeric code */ |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 118 | 0, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 00-07 */ |
| 119 | '7', '8', '9', '0', '-', '=', 0x08, '\t', /* scan 08-0F */ |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 120 | 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', /* scan 10-17 */ |
| 121 | 'o', 'p', '[', ']', '\r', CN, 'a', 's', /* scan 18-1F */ |
| 122 | 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* scan 20-27 */ |
| 123 | '\'', '`', SH, '\\', 'z', 'x', 'c', 'v', /* scan 28-2F */ |
| 124 | 'b', 'n', 'm', ',', '.', '/', SH, '*', /* scan 30-37 */ |
| 125 | ' ', ' ', CP, 0, 0, 0, 0, 0, /* scan 38-3F */ |
| 126 | 0, 0, 0, 0, 0, NM, ST, 'w', /* scan 40-47 */ |
| 127 | 'x', 'y', 'l', 't', 'u', 'v', 'm', 'q', /* scan 48-4F */ |
| 128 | 'r', 's', 'p', 'n', 0, 0, 0, 0, /* scan 50-57 */ |
| 129 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */ |
| 130 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */ |
| 131 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */ |
| 132 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 70-77 */ |
| 133 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 78-7F */ |
| 134 | '\r', CN, '/', '*', ' ', ST, 'F', 'A', /* extended */ |
| 135 | 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */ |
| 136 | }, |
| 137 | { /* right alt mode - not used in US keyboard */ |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 138 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 00-07 */ |
| 139 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 08-0F */ |
| 140 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 10-17 */ |
| 141 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 18-1F */ |
| 142 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 20-27 */ |
| 143 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 28-2F */ |
| 144 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 30-37 */ |
| 145 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */ |
| 146 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 40-47 */ |
| 147 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48-4F */ |
| 148 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 50-57 */ |
| 149 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58-5F */ |
| 150 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60-67 */ |
| 151 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68-6F */ |
| 152 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70-77 */ |
| 153 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78-7F */ |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 154 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* extended */ |
| 155 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff /* extended */ |
| 156 | } |
| 157 | }, |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 158 | { /* German keyboard */ |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 159 | { /* unshift code */ |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 160 | 0, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 00-07 */ |
| 161 | '7', '8', '9', '0', 0xe1, '\'', 0x08, '\t', /* scan 08-0F */ |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 162 | 'q', 'w', 'e', 'r', 't', 'z', 'u', 'i', /* scan 10-17 */ |
| 163 | 'o', 'p', 0x81, '+', '\r', CN, 'a', 's', /* scan 18-1F */ |
| 164 | 'd', 'f', 'g', 'h', 'j', 'k', 'l', 0x94, /* scan 20-27 */ |
| 165 | 0x84, '^', SH, '#', 'y', 'x', 'c', 'v', /* scan 28-2F */ |
| 166 | 'b', 'n', 'm', ',', '.', '-', SH, '*', /* scan 30-37 */ |
| 167 | ' ', ' ', CP, 0, 0, 0, 0, 0, /* scan 38-3F */ |
| 168 | 0, 0, 0, 0, 0, NM, ST, '7', /* scan 40-47 */ |
| 169 | '8', '9', '-', '4', '5', '6', '+', '1', /* scan 48-4F */ |
| 170 | '2', '3', '0', ',', 0, 0, '<', 0, /* scan 50-57 */ |
| 171 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */ |
| 172 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */ |
| 173 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */ |
| 174 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 70-77 */ |
| 175 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 78-7F */ |
| 176 | '\r', CN, '/', '*', ' ', ST, 'F', 'A', /* extended */ |
| 177 | 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */ |
| 178 | }, |
| 179 | { /* shift code */ |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 180 | 0, 0x1b, '!', '"', 0x15, '$', '%', '&', /* scan 00-07 */ |
| 181 | '/', '(', ')', '=', '?', '`', 0x08, '\t', /* scan 08-0F */ |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 182 | 'Q', 'W', 'E', 'R', 'T', 'Z', 'U', 'I', /* scan 10-17 */ |
| 183 | 'O', 'P', 0x9a, '*', '\r', CN, 'A', 'S', /* scan 18-1F */ |
| 184 | 'D', 'F', 'G', 'H', 'J', 'K', 'L', 0x99, /* scan 20-27 */ |
| 185 | 0x8e, 0xf8, SH, '\'', 'Y', 'X', 'C', 'V', /* scan 28-2F */ |
| 186 | 'B', 'N', 'M', ';', ':', '_', SH, '*', /* scan 30-37 */ |
| 187 | ' ', ' ', CP, 0, 0, 0, 0, 0, /* scan 38-3F */ |
| 188 | 0, 0, 0, 0, 0, NM, ST, '7', /* scan 40-47 */ |
| 189 | '8', '9', '-', '4', '5', '6', '+', '1', /* scan 48-4F */ |
| 190 | '2', '3', '0', ',', 0, 0, '>', 0, /* scan 50-57 */ |
| 191 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */ |
| 192 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */ |
| 193 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */ |
| 194 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 70-77 */ |
| 195 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 78-7F */ |
| 196 | '\r', CN, '/', '*', ' ', ST, 'F', 'A', /* extended */ |
| 197 | 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */ |
| 198 | }, |
| 199 | { /* control code */ |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 200 | 0xff, 0x1b, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, /* scan 00-07 */ |
| 201 | 0x1e, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, '\t', /* scan 08-0F */ |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 202 | 0x11, 0x17, 0x05, 0x12, 0x14, 0x19, 0x15, 0x09, /* scan 10-17 */ |
| 203 | 0x0f, 0x10, 0x1b, 0x1d, '\r', CN, 0x01, 0x13, /* scan 18-1F */ |
| 204 | 0x04, 0x06, 0x07, 0x08, 0x0a, 0x0b, 0x0c, 0xff, /* scan 20-27 */ |
| 205 | 0xff, 0x1c, SH, 0xff, 0x1a, 0x18, 0x03, 0x16, /* scan 28-2F */ |
| 206 | 0x02, 0x0e, 0x0d, 0xff, 0xff, 0xff, SH, 0xff, /* scan 30-37 */ |
| 207 | 0xff, 0xff, CP, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */ |
| 208 | 0xff, 0xff, 0xff, 0xff, 0xff, NM, ST, 0xff, /* scan 40-47 */ |
| 209 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48-4F */ |
| 210 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 50-57 */ |
| 211 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58-5F */ |
| 212 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60-67 */ |
| 213 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68-6F */ |
| 214 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70-77 */ |
| 215 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78-7F */ |
| 216 | '\r', CN, '/', '*', ' ', ST, 0xff, 0xff, /* extended */ |
| 217 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff /* extended */ |
| 218 | }, |
| 219 | { /* non numeric code */ |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 220 | 0, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 00-07 */ |
| 221 | '7', '8', '9', '0', 0xe1, '\'', 0x08, '\t', /* scan 08-0F */ |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 222 | 'q', 'w', 'e', 'r', 't', 'z', 'u', 'i', /* scan 10-17 */ |
| 223 | 'o', 'p', 0x81, '+', '\r', CN, 'a', 's', /* scan 18-1F */ |
| 224 | 'd', 'f', 'g', 'h', 'j', 'k', 'l', 0x94, /* scan 20-27 */ |
| 225 | 0x84, '^', SH, 0, 'y', 'x', 'c', 'v', /* scan 28-2F */ |
| 226 | 'b', 'n', 'm', ',', '.', '-', SH, '*', /* scan 30-37 */ |
| 227 | ' ', ' ', CP, 0, 0, 0, 0, 0, /* scan 38-3F */ |
| 228 | 0, 0, 0, 0, 0, NM, ST, 'w', /* scan 40-47 */ |
| 229 | 'x', 'y', 'l', 't', 'u', 'v', 'm', 'q', /* scan 48-4F */ |
| 230 | 'r', 's', 'p', 'n', 0, 0, '<', 0, /* scan 50-57 */ |
| 231 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */ |
| 232 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */ |
| 233 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */ |
| 234 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 70-77 */ |
| 235 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 78-7F */ |
| 236 | '\r', CN, '/', '*', ' ', ST, 'F', 'A', /* extended */ |
| 237 | 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */ |
| 238 | }, |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 239 | { /* right alt mode - is used in German keyboard */ |
| 240 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 00-07 */ |
| 241 | '{', '[', ']', '}', '\\', 0xff, 0xff, 0xff, /* scan 08-0F */ |
| 242 | '@', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 10-17 */ |
| 243 | 0xff, 0xff, 0xff, '~', 0xff, 0xff, 0xff, 0xff, /* scan 18-1F */ |
| 244 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 20-27 */ |
| 245 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 28-2F */ |
| 246 | 0xff, 0xff, 0xe6, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 30-37 */ |
| 247 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */ |
| 248 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 40-47 */ |
| 249 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48-4F */ |
| 250 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, '|', 0xff, /* scan 50-57 */ |
| 251 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58-5F */ |
| 252 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60-67 */ |
| 253 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68-6F */ |
| 254 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70-77 */ |
| 255 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78-7F */ |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 256 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* extended */ |
| 257 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff /* extended */ |
| 258 | } |
| 259 | } |
| 260 | }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 261 | |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 262 | static unsigned char ext_key_map[] = { |
| 263 | 0x1c, /* keypad enter */ |
| 264 | 0x1d, /* right control */ |
| 265 | 0x35, /* keypad slash */ |
| 266 | 0x37, /* print screen */ |
| 267 | 0x38, /* right alt */ |
| 268 | 0x46, /* break */ |
| 269 | 0x47, /* editpad home */ |
| 270 | 0x48, /* editpad up */ |
| 271 | 0x49, /* editpad pgup */ |
| 272 | 0x4b, /* editpad left */ |
| 273 | 0x4d, /* editpad right */ |
| 274 | 0x4f, /* editpad end */ |
| 275 | 0x50, /* editpad dn */ |
| 276 | 0x51, /* editpad pgdn */ |
| 277 | 0x52, /* editpad ins */ |
| 278 | 0x53, /* editpad del */ |
| 279 | 0x00 /* map end */ |
| 280 | }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 281 | |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 282 | static int kbd_input_empty(void) |
| 283 | { |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 284 | int kbd_timeout = KBD_TIMEOUT * 1000; |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 285 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 286 | while ((in8(I8042_STS_REG) & STATUS_IBF) && kbd_timeout--) |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 287 | udelay(1); |
| 288 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 289 | return kbd_timeout != -1; |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 292 | static int kbd_output_full(void) |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 293 | { |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 294 | int kbd_timeout = KBD_TIMEOUT * 1000; |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 295 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 296 | while (((in8(I8042_STS_REG) & STATUS_OBF) == 0) && kbd_timeout--) |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 297 | udelay(1); |
| 298 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 299 | return kbd_timeout != -1; |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | static void kbd_led_set(void) |
| 303 | { |
| 304 | kbd_input_empty(); |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 305 | out8(I8042_DATA_REG, CMD_SET_KBD_LED); |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 306 | kbd_input_empty(); |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 307 | out8(I8042_DATA_REG, (kbd_flags & 0x7)); |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | static void kbd_normal(unsigned char scan_code) |
| 311 | { |
| 312 | unsigned char chr; |
| 313 | |
| 314 | if ((kbd_flags & BRK) == NORMAL) { |
| 315 | chr = kbd_key_map[kbd_mapping][kbd_state][scan_code]; |
| 316 | if ((chr == 0xff) || (chr == 0x00)) |
| 317 | return; |
| 318 | |
| 319 | /* if caps lock convert upper to lower */ |
| 320 | if (((kbd_flags & CAPS) == CAPS) && |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 321 | (chr >= 'a' && chr <= 'z')) { |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 322 | chr -= 'a' - 'A'; |
| 323 | } |
| 324 | kbd_input = chr; |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | static void kbd_shift(unsigned char scan_code) |
| 329 | { |
| 330 | if ((kbd_flags & BRK) == BRK) { |
| 331 | kbd_state = AS; |
| 332 | kbd_flags &= (~SHIFT); |
| 333 | } else { |
| 334 | kbd_state = SH; |
| 335 | kbd_flags |= SHIFT; |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | static void kbd_ctrl(unsigned char scan_code) |
| 340 | { |
| 341 | if ((kbd_flags & BRK) == BRK) { |
| 342 | kbd_state = AS; |
| 343 | kbd_flags &= (~CTRL); |
| 344 | } else { |
| 345 | kbd_state = CN; |
| 346 | kbd_flags |= CTRL; |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | static void kbd_num(unsigned char scan_code) |
| 351 | { |
| 352 | if ((kbd_flags & BRK) == NORMAL) { |
| 353 | kbd_flags ^= NUM; |
| 354 | kbd_state = (kbd_flags & NUM) ? AS : NM; |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 355 | kbd_led_set(); |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 356 | } |
| 357 | } |
| 358 | |
| 359 | static void kbd_alt(unsigned char scan_code) |
| 360 | { |
| 361 | if ((kbd_flags & BRK) == BRK) { |
| 362 | kbd_state = AS; |
| 363 | kbd_flags &= (~ALT); |
| 364 | } else { |
| 365 | kbd_state = AK; |
| 366 | kbd_flags &= ALT; |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | static void kbd_caps(unsigned char scan_code) |
| 371 | { |
| 372 | if ((kbd_flags & BRK) == NORMAL) { |
| 373 | kbd_flags ^= CAPS; |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 374 | kbd_led_set(); |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 375 | } |
| 376 | } |
| 377 | |
| 378 | static void kbd_scroll(unsigned char scan_code) |
| 379 | { |
| 380 | if ((kbd_flags & BRK) == NORMAL) { |
| 381 | kbd_flags ^= STP; |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 382 | kbd_led_set(); |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 383 | if (kbd_flags & STP) |
| 384 | kbd_input = 0x13; |
| 385 | else |
| 386 | kbd_input = 0x11; |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | static void kbd_conv_char(unsigned char scan_code) |
| 391 | { |
| 392 | if (scan_code == 0xe0) { |
| 393 | kbd_flags |= EXT; |
| 394 | return; |
| 395 | } |
| 396 | |
| 397 | /* if high bit of scan_code, set break flag */ |
| 398 | if (scan_code & 0x80) |
| 399 | kbd_flags |= BRK; |
| 400 | else |
| 401 | kbd_flags &= ~BRK; |
| 402 | |
| 403 | if ((scan_code == 0xe1) || (kbd_flags & E1)) { |
| 404 | if (scan_code == 0xe1) { |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 405 | kbd_flags ^= BRK; /* reset the break flag */ |
| 406 | kbd_flags ^= E1; /* bitwise EXOR with E1 flag */ |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 407 | } |
| 408 | return; |
| 409 | } |
| 410 | |
| 411 | scan_code &= 0x7f; |
| 412 | |
| 413 | if (kbd_flags & EXT) { |
| 414 | int i; |
| 415 | |
| 416 | kbd_flags ^= EXT; |
| 417 | for (i = 0; ext_key_map[i]; i++) { |
| 418 | if (ext_key_map[i] == scan_code) { |
| 419 | scan_code = 0x80 + i; |
| 420 | break; |
| 421 | } |
| 422 | } |
| 423 | /* not found ? */ |
| 424 | if (!ext_key_map[i]) |
| 425 | return; |
| 426 | } |
| 427 | |
| 428 | switch (kbd_fct_map[scan_code]) { |
| 429 | case AS: |
| 430 | kbd_normal(scan_code); |
| 431 | break; |
| 432 | case SH: |
| 433 | kbd_shift(scan_code); |
| 434 | break; |
| 435 | case CN: |
| 436 | kbd_ctrl(scan_code); |
| 437 | break; |
| 438 | case NM: |
| 439 | kbd_num(scan_code); |
| 440 | break; |
| 441 | case AK: |
| 442 | kbd_alt(scan_code); |
| 443 | break; |
| 444 | case CP: |
| 445 | kbd_caps(scan_code); |
| 446 | break; |
| 447 | case ST: |
| 448 | kbd_scroll(scan_code); |
| 449 | break; |
| 450 | } |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 451 | |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 452 | return; |
| 453 | } |
| 454 | |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 455 | static int kbd_reset(void) |
| 456 | { |
| 457 | /* KB Reset */ |
| 458 | if (kbd_input_empty() == 0) |
| 459 | return -1; |
| 460 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 461 | out8(I8042_DATA_REG, CMD_RESET_KBD); |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 462 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 463 | if (kbd_output_full() == 0) |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 464 | return -1; |
| 465 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 466 | if (in8(I8042_DATA_REG) != KBD_ACK) |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 467 | return -1; |
| 468 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 469 | if (kbd_output_full() == 0) |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 470 | return -1; |
| 471 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 472 | if (in8(I8042_DATA_REG) != KBD_POR) |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 473 | return -1; |
| 474 | |
| 475 | if (kbd_input_empty() == 0) |
| 476 | return -1; |
| 477 | |
| 478 | /* Set KBC mode */ |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 479 | out8(I8042_CMD_REG, CMD_WR_CONFIG); |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 480 | |
| 481 | if (kbd_input_empty() == 0) |
| 482 | return -1; |
| 483 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 484 | out8(I8042_DATA_REG, |
| 485 | CONFIG_AT_TRANS | CONFIG_SET_BIST | CONFIG_KIRQ_EN); |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 486 | |
| 487 | if (kbd_input_empty() == 0) |
| 488 | return -1; |
| 489 | |
| 490 | /* Enable Keyboard */ |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 491 | out8(I8042_CMD_REG, CMD_KBD_EN); |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 492 | if (kbd_input_empty() == 0) |
| 493 | return -1; |
| 494 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 495 | out8(I8042_CMD_REG, CMD_WR_CONFIG); |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 496 | if (kbd_input_empty() == 0) |
| 497 | return -1; |
| 498 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 499 | out8(I8042_DATA_REG, |
| 500 | CONFIG_AT_TRANS | CONFIG_MCLK_DIS | |
| 501 | CONFIG_KCLK_DIS | CONFIG_SET_BIST); |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 502 | if (kbd_input_empty() == 0) |
| 503 | return -1; |
| 504 | |
| 505 | return 0; |
| 506 | } |
| 507 | |
Gabe Black | 22e0f5a | 2011-11-14 20:18:12 +0000 | [diff] [blame] | 508 | static int kbd_controller_present(void) |
| 509 | { |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 510 | return in8(I8042_STS_REG) != 0xff; |
Gabe Black | 22e0f5a | 2011-11-14 20:18:12 +0000 | [diff] [blame] | 511 | } |
| 512 | |
Gabe Black | 48edb30 | 2012-10-12 14:02:02 +0000 | [diff] [blame] | 513 | /* |
| 514 | * Implement a weak default function for boards that optionally |
| 515 | * need to skip the i8042 initialization. |
| 516 | */ |
| 517 | int __weak board_i8042_skip(void) |
| 518 | { |
| 519 | /* As default, don't skip */ |
| 520 | return 0; |
| 521 | } |
| 522 | |
Louis Yung-Chieh Lo | 45fe668 | 2012-10-11 15:15:51 +0000 | [diff] [blame] | 523 | void i8042_flush(void) |
| 524 | { |
| 525 | int timeout; |
| 526 | |
| 527 | /* |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 528 | * The delay is to give the keyboard controller some time |
| 529 | * to fill the next byte. |
Louis Yung-Chieh Lo | 45fe668 | 2012-10-11 15:15:51 +0000 | [diff] [blame] | 530 | */ |
| 531 | while (1) { |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 532 | timeout = 100; /* wait for no longer than 100us */ |
| 533 | while (timeout > 0 && !(in8(I8042_STS_REG) & STATUS_OBF)) { |
Louis Yung-Chieh Lo | 45fe668 | 2012-10-11 15:15:51 +0000 | [diff] [blame] | 534 | udelay(1); |
| 535 | timeout--; |
| 536 | } |
| 537 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 538 | /* Try to pull next byte if not timeout */ |
| 539 | if (in8(I8042_STS_REG) & STATUS_OBF) |
Louis Yung-Chieh Lo | 45fe668 | 2012-10-11 15:15:51 +0000 | [diff] [blame] | 540 | in8(I8042_DATA_REG); |
| 541 | else |
| 542 | break; |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | int i8042_disable(void) |
| 547 | { |
| 548 | if (kbd_input_empty() == 0) |
| 549 | return -1; |
| 550 | |
| 551 | /* Disable keyboard */ |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 552 | out8(I8042_CMD_REG, CMD_KBD_DIS); |
Louis Yung-Chieh Lo | 45fe668 | 2012-10-11 15:15:51 +0000 | [diff] [blame] | 553 | |
| 554 | if (kbd_input_empty() == 0) |
| 555 | return -1; |
| 556 | |
| 557 | return 0; |
| 558 | } |
| 559 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 560 | /* i8042_kbd_init - reset keyboard and init state flags */ |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 561 | int i8042_kbd_init(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 562 | { |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 563 | int keymap, try; |
| 564 | char *penv; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 565 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 566 | if (!kbd_controller_present() || board_i8042_skip()) { |
| 567 | debug("i8042 keyboard controller is not present\n"); |
Gabe Black | 22e0f5a | 2011-11-14 20:18:12 +0000 | [diff] [blame] | 568 | return -1; |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 569 | } |
Gabe Black | 22e0f5a | 2011-11-14 20:18:12 +0000 | [diff] [blame] | 570 | |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 571 | /* Init keyboard device (default US layout) */ |
| 572 | keymap = KBD_US; |
| 573 | penv = getenv("keymap"); |
| 574 | if (penv != NULL) { |
| 575 | if (strncmp(penv, "de", 3) == 0) |
| 576 | keymap = KBD_GER; |
| 577 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 578 | |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 579 | for (try = 0; try < KBD_RESET_TRIES; try++) { |
| 580 | if (kbd_reset() == 0) { |
| 581 | kbd_mapping = keymap; |
| 582 | kbd_flags = NORMAL; |
| 583 | kbd_state = 0; |
| 584 | kbd_led_set(); |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 585 | |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 586 | return 0; |
| 587 | } |
| 588 | } |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 589 | |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 590 | return -1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 591 | } |
| 592 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 593 | /* |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 594 | * i8042_tstc - test if keyboard input is available |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 595 | * |
| 596 | * option: cursor blinking if called in a loop |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 597 | */ |
Simon Glass | 709ea54 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 598 | int i8042_tstc(struct stdio_dev *dev) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 599 | { |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 600 | unsigned char scan_code = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 601 | |
| 602 | #ifdef CONFIG_CONSOLE_CURSOR |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 603 | if (--blink_count == 0) { |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 604 | cursor_state ^= 1; |
| 605 | console_cursor(cursor_state); |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 606 | blink_count = CONFIG_SYS_CONSOLE_BLINK_COUNT; |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 607 | udelay(10); |
| 608 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 609 | #endif |
| 610 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 611 | if ((in8(I8042_STS_REG) & STATUS_OBF) == 0) { |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 612 | return 0; |
| 613 | } else { |
| 614 | scan_code = in8(I8042_DATA_REG); |
| 615 | if (scan_code == 0xfa) |
| 616 | return 0; |
| 617 | |
| 618 | kbd_conv_char(scan_code); |
| 619 | |
| 620 | if (kbd_input != -1) |
| 621 | return 1; |
| 622 | } |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 623 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 624 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 625 | } |
| 626 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 627 | /* |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 628 | * i8042_getc - wait till keyboard input is available |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 629 | * |
| 630 | * option: turn on/off cursor while waiting |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 631 | */ |
Simon Glass | 709ea54 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 632 | int i8042_getc(struct stdio_dev *dev) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 633 | { |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 634 | int ret_chr; |
| 635 | unsigned char scan_code; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 636 | |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 637 | while (kbd_input == -1) { |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 638 | while ((in8(I8042_STS_REG) & STATUS_OBF) == 0) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 639 | #ifdef CONFIG_CONSOLE_CURSOR |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 640 | if (--blink_count == 0) { |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 641 | cursor_state ^= 1; |
| 642 | console_cursor(cursor_state); |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 643 | blink_count = CONFIG_SYS_CONSOLE_BLINK_COUNT; |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 644 | } |
| 645 | udelay(10); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 646 | #endif |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 647 | } |
| 648 | scan_code = in8(I8042_DATA_REG); |
| 649 | if (scan_code != 0xfa) |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 650 | kbd_conv_char(scan_code); |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 651 | } |
| 652 | ret_chr = kbd_input; |
| 653 | kbd_input = -1; |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame^] | 654 | |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 655 | return ret_chr; |
| 656 | } |