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