Commit 835dd000503591d8eb59a191f7220768898737b3
Committed by
Simon Glass
1 parent
3928d66a5e
Exists in
v2017.01-smarct4x
and in
30 other branches
x86: i8042: Clean up the driver per coding convention
- Rename CamelCase variables to conform U-Boot coding convention - Rename wait_until_kbd_output_full() to kbd_output_full() - Change to use macros for i8042 command and control register bits Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Acked-by: Simon Glass <sjg@chromium.org>
Showing 2 changed files with 177 additions and 156 deletions Side-by-side Diff
drivers/input/i8042.c
... | ... | @@ -10,27 +10,30 @@ |
10 | 10 | /* includes */ |
11 | 11 | |
12 | 12 | #include <common.h> |
13 | +#include <asm/io.h> | |
13 | 14 | #include <i8042.h> |
14 | 15 | |
15 | 16 | /* defines */ |
17 | +#define in8(p) inb(p) | |
18 | +#define out8(p, v) outb(v, p) | |
16 | 19 | |
17 | 20 | #ifdef CONFIG_CONSOLE_CURSOR |
18 | 21 | extern void console_cursor(int state); |
19 | -static int blinkCount = CONFIG_SYS_CONSOLE_BLINK_COUNT; | |
22 | +static int blink_count = CONFIG_SYS_CONSOLE_BLINK_COUNT; | |
20 | 23 | static int cursor_state; |
21 | 24 | #endif |
22 | 25 | |
23 | 26 | /* locals */ |
24 | 27 | |
25 | -static int kbd_input = -1; /* no input yet */ | |
26 | -static int kbd_mapping = KBD_US; /* default US keyboard */ | |
27 | -static int kbd_flags = NORMAL; /* after reset */ | |
28 | -static int kbd_state; /* unshift code */ | |
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 */ | |
29 | 32 | |
30 | 33 | static unsigned char kbd_fct_map[144] = { |
31 | 34 | /* kbd_fct_map table for scan code */ |
32 | - 0, AS, AS, AS, AS, AS, AS, AS, /* scan 0- 7 */ | |
33 | - AS, AS, AS, AS, AS, AS, AS, AS, /* scan 8- F */ | |
35 | + 0, AS, AS, AS, AS, AS, AS, AS, /* scan 00-07 */ | |
36 | + AS, AS, AS, AS, AS, AS, AS, AS, /* scan 08-0F */ | |
34 | 37 | AS, AS, AS, AS, AS, AS, AS, AS, /* scan 10-17 */ |
35 | 38 | AS, AS, AS, AS, AS, CN, AS, AS, /* scan 18-1F */ |
36 | 39 | AS, AS, AS, AS, AS, AS, AS, AS, /* scan 20-27 */ |
... | ... | @@ -52,8 +55,8 @@ |
52 | 55 | static unsigned char kbd_key_map[2][5][144] = { |
53 | 56 | { /* US keyboard */ |
54 | 57 | { /* unshift code */ |
55 | - 0, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 0- 7 */ | |
56 | - '7', '8', '9', '0', '-', '=', 0x08, '\t', /* scan 8- F */ | |
58 | + 0, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 00-07 */ | |
59 | + '7', '8', '9', '0', '-', '=', 0x08, '\t', /* scan 08-0F */ | |
57 | 60 | 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', /* scan 10-17 */ |
58 | 61 | 'o', 'p', '[', ']', '\r', CN, 'a', 's', /* scan 18-1F */ |
59 | 62 | 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* scan 20-27 */ |
... | ... | @@ -72,8 +75,8 @@ |
72 | 75 | 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */ |
73 | 76 | }, |
74 | 77 | { /* shift code */ |
75 | - 0, 0x1b, '!', '@', '#', '$', '%', '^', /* scan 0- 7 */ | |
76 | - '&', '*', '(', ')', '_', '+', 0x08, '\t', /* scan 8- F */ | |
78 | + 0, 0x1b, '!', '@', '#', '$', '%', '^', /* scan 00-07 */ | |
79 | + '&', '*', '(', ')', '_', '+', 0x08, '\t', /* scan 08-0F */ | |
77 | 80 | 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', /* scan 10-17 */ |
78 | 81 | 'O', 'P', '{', '}', '\r', CN, 'A', 'S', /* scan 18-1F */ |
79 | 82 | 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', /* scan 20-27 */ |
... | ... | @@ -92,8 +95,8 @@ |
92 | 95 | 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */ |
93 | 96 | }, |
94 | 97 | { /* control code */ |
95 | - 0xff, 0x1b, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, /* scan 0- 7 */ | |
96 | - 0x1e, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, '\t', /* scan 8- F */ | |
98 | + 0xff, 0x1b, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, /* scan 00-07 */ | |
99 | + 0x1e, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, '\t', /* scan 08-0F */ | |
97 | 100 | 0x11, 0x17, 0x05, 0x12, 0x14, 0x19, 0x15, 0x09, /* scan 10-17 */ |
98 | 101 | 0x0f, 0x10, 0x1b, 0x1d, '\r', CN, 0x01, 0x13, /* scan 18-1F */ |
99 | 102 | 0x04, 0x06, 0x07, 0x08, 0x0a, 0x0b, 0x0c, 0xff, /* scan 20-27 */ |
... | ... | @@ -112,8 +115,8 @@ |
112 | 115 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff /* extended */ |
113 | 116 | }, |
114 | 117 | { /* non numeric code */ |
115 | - 0, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 0- 7 */ | |
116 | - '7', '8', '9', '0', '-', '=', 0x08, '\t', /* scan 8- F */ | |
118 | + 0, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 00-07 */ | |
119 | + '7', '8', '9', '0', '-', '=', 0x08, '\t', /* scan 08-0F */ | |
117 | 120 | 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', /* scan 10-17 */ |
118 | 121 | 'o', 'p', '[', ']', '\r', CN, 'a', 's', /* scan 18-1F */ |
119 | 122 | 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* scan 20-27 */ |
120 | 123 | |
121 | 124 | |
... | ... | @@ -132,30 +135,30 @@ |
132 | 135 | 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */ |
133 | 136 | }, |
134 | 137 | { /* right alt mode - not used in US keyboard */ |
135 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 0 - 7 */ | |
136 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 8 - F */ | |
137 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 10 -17 */ | |
138 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 18 -1F */ | |
139 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 20 -27 */ | |
140 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 28 -2F */ | |
141 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 30 -37 */ | |
142 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38 -3F */ | |
143 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 40 -47 */ | |
144 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48 -4F */ | |
145 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 50 -57 */ | |
146 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58 -5F */ | |
147 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60 -67 */ | |
148 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68 -6F */ | |
149 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70 -77 */ | |
150 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78 -7F */ | |
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 */ | |
151 | 154 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* extended */ |
152 | 155 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff /* extended */ |
153 | 156 | } |
154 | 157 | }, |
155 | - { /* german keyboard */ | |
158 | + { /* German keyboard */ | |
156 | 159 | { /* unshift code */ |
157 | - 0, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 0- 7 */ | |
158 | - '7', '8', '9', '0', 0xe1, '\'', 0x08, '\t', /* scan 8- F */ | |
160 | + 0, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 00-07 */ | |
161 | + '7', '8', '9', '0', 0xe1, '\'', 0x08, '\t', /* scan 08-0F */ | |
159 | 162 | 'q', 'w', 'e', 'r', 't', 'z', 'u', 'i', /* scan 10-17 */ |
160 | 163 | 'o', 'p', 0x81, '+', '\r', CN, 'a', 's', /* scan 18-1F */ |
161 | 164 | 'd', 'f', 'g', 'h', 'j', 'k', 'l', 0x94, /* scan 20-27 */ |
... | ... | @@ -174,8 +177,8 @@ |
174 | 177 | 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */ |
175 | 178 | }, |
176 | 179 | { /* shift code */ |
177 | - 0, 0x1b, '!', '"', 0x15, '$', '%', '&', /* scan 0- 7 */ | |
178 | - '/', '(', ')', '=', '?', '`', 0x08, '\t', /* scan 8- F */ | |
180 | + 0, 0x1b, '!', '"', 0x15, '$', '%', '&', /* scan 00-07 */ | |
181 | + '/', '(', ')', '=', '?', '`', 0x08, '\t', /* scan 08-0F */ | |
179 | 182 | 'Q', 'W', 'E', 'R', 'T', 'Z', 'U', 'I', /* scan 10-17 */ |
180 | 183 | 'O', 'P', 0x9a, '*', '\r', CN, 'A', 'S', /* scan 18-1F */ |
181 | 184 | 'D', 'F', 'G', 'H', 'J', 'K', 'L', 0x99, /* scan 20-27 */ |
... | ... | @@ -194,8 +197,8 @@ |
194 | 197 | 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */ |
195 | 198 | }, |
196 | 199 | { /* control code */ |
197 | - 0xff, 0x1b, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, /* scan 0- 7 */ | |
198 | - 0x1e, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, '\t', /* scan 8- F */ | |
200 | + 0xff, 0x1b, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, /* scan 00-07 */ | |
201 | + 0x1e, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, '\t', /* scan 08-0F */ | |
199 | 202 | 0x11, 0x17, 0x05, 0x12, 0x14, 0x19, 0x15, 0x09, /* scan 10-17 */ |
200 | 203 | 0x0f, 0x10, 0x1b, 0x1d, '\r', CN, 0x01, 0x13, /* scan 18-1F */ |
201 | 204 | 0x04, 0x06, 0x07, 0x08, 0x0a, 0x0b, 0x0c, 0xff, /* scan 20-27 */ |
... | ... | @@ -214,8 +217,8 @@ |
214 | 217 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff /* extended */ |
215 | 218 | }, |
216 | 219 | { /* non numeric code */ |
217 | - 0, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 0- 7 */ | |
218 | - '7', '8', '9', '0', 0xe1, '\'', 0x08, '\t', /* scan 8- F */ | |
220 | + 0, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 00-07 */ | |
221 | + '7', '8', '9', '0', 0xe1, '\'', 0x08, '\t', /* scan 08-0F */ | |
219 | 222 | 'q', 'w', 'e', 'r', 't', 'z', 'u', 'i', /* scan 10-17 */ |
220 | 223 | 'o', 'p', 0x81, '+', '\r', CN, 'a', 's', /* scan 18-1F */ |
221 | 224 | 'd', 'f', 'g', 'h', 'j', 'k', 'l', 0x94, /* scan 20-27 */ |
... | ... | @@ -233,23 +236,23 @@ |
233 | 236 | '\r', CN, '/', '*', ' ', ST, 'F', 'A', /* extended */ |
234 | 237 | 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */ |
235 | 238 | }, |
236 | - { /* Right alt mode - is used in German keyboard */ | |
237 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 0 - 7 */ | |
238 | - '{', '[', ']', '}', '\\', 0xff, 0xff, 0xff, /* scan 8 - F */ | |
239 | - '@', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 10 -17 */ | |
240 | - 0xff, 0xff, 0xff, '~', 0xff, 0xff, 0xff, 0xff, /* scan 18 -1F */ | |
241 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 20 -27 */ | |
242 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 28 -2F */ | |
243 | - 0xff, 0xff, 0xe6, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 30 -37 */ | |
244 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38 -3F */ | |
245 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 40 -47 */ | |
246 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48 -4F */ | |
247 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, '|', 0xff, /* scan 50 -57 */ | |
248 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58 -5F */ | |
249 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60 -67 */ | |
250 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68 -6F */ | |
251 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70 -77 */ | |
252 | - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78 -7F */ | |
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 */ | |
253 | 256 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* extended */ |
254 | 257 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff /* extended */ |
255 | 258 | } |
256 | 259 | |
257 | 260 | |
258 | 261 | |
259 | 262 | |
260 | 263 | |
261 | 264 | |
262 | 265 | |
263 | 266 | |
... | ... | @@ -278,30 +281,30 @@ |
278 | 281 | |
279 | 282 | static int kbd_input_empty(void) |
280 | 283 | { |
281 | - int kbdTimeout = KBD_TIMEOUT * 1000; | |
284 | + int kbd_timeout = KBD_TIMEOUT * 1000; | |
282 | 285 | |
283 | - while ((in8(I8042_STATUS_REG) & I8042_STATUS_IN_DATA) && kbdTimeout--) | |
286 | + while ((in8(I8042_STS_REG) & STATUS_IBF) && kbd_timeout--) | |
284 | 287 | udelay(1); |
285 | 288 | |
286 | - return kbdTimeout != -1; | |
289 | + return kbd_timeout != -1; | |
287 | 290 | } |
288 | 291 | |
289 | -static int wait_until_kbd_output_full(void) | |
292 | +static int kbd_output_full(void) | |
290 | 293 | { |
291 | - int kbdTimeout = KBD_TIMEOUT * 1000; | |
294 | + int kbd_timeout = KBD_TIMEOUT * 1000; | |
292 | 295 | |
293 | - while (((in8(I8042_STATUS_REG) & 0x01) == 0) && kbdTimeout--) | |
296 | + while (((in8(I8042_STS_REG) & STATUS_OBF) == 0) && kbd_timeout--) | |
294 | 297 | udelay(1); |
295 | 298 | |
296 | - return kbdTimeout != -1; | |
299 | + return kbd_timeout != -1; | |
297 | 300 | } |
298 | 301 | |
299 | 302 | static void kbd_led_set(void) |
300 | 303 | { |
301 | 304 | kbd_input_empty(); |
302 | - out8(I8042_DATA_REG, 0xed); /* SET LED command */ | |
305 | + out8(I8042_DATA_REG, CMD_SET_KBD_LED); | |
303 | 306 | kbd_input_empty(); |
304 | - out8(I8042_DATA_REG, (kbd_flags & 0x7)); /* LED bits only */ | |
307 | + out8(I8042_DATA_REG, (kbd_flags & 0x7)); | |
305 | 308 | } |
306 | 309 | |
307 | 310 | static void kbd_normal(unsigned char scan_code) |
... | ... | @@ -315,7 +318,7 @@ |
315 | 318 | |
316 | 319 | /* if caps lock convert upper to lower */ |
317 | 320 | if (((kbd_flags & CAPS) == CAPS) && |
318 | - (chr >= 'a' && chr <= 'z')) { | |
321 | + (chr >= 'a' && chr <= 'z')) { | |
319 | 322 | chr -= 'a' - 'A'; |
320 | 323 | } |
321 | 324 | kbd_input = chr; |
... | ... | @@ -349,7 +352,7 @@ |
349 | 352 | if ((kbd_flags & BRK) == NORMAL) { |
350 | 353 | kbd_flags ^= NUM; |
351 | 354 | kbd_state = (kbd_flags & NUM) ? AS : NM; |
352 | - kbd_led_set(); /* update keyboard LED */ | |
355 | + kbd_led_set(); | |
353 | 356 | } |
354 | 357 | } |
355 | 358 | |
... | ... | @@ -368,7 +371,7 @@ |
368 | 371 | { |
369 | 372 | if ((kbd_flags & BRK) == NORMAL) { |
370 | 373 | kbd_flags ^= CAPS; |
371 | - kbd_led_set(); /* update keyboard LED */ | |
374 | + kbd_led_set(); | |
372 | 375 | } |
373 | 376 | } |
374 | 377 | |
... | ... | @@ -376,7 +379,7 @@ |
376 | 379 | { |
377 | 380 | if ((kbd_flags & BRK) == NORMAL) { |
378 | 381 | kbd_flags ^= STP; |
379 | - kbd_led_set(); /* update keyboard LED */ | |
382 | + kbd_led_set(); | |
380 | 383 | if (kbd_flags & STP) |
381 | 384 | kbd_input = 0x13; |
382 | 385 | else |
... | ... | @@ -399,8 +402,8 @@ |
399 | 402 | |
400 | 403 | if ((scan_code == 0xe1) || (kbd_flags & E1)) { |
401 | 404 | if (scan_code == 0xe1) { |
402 | - kbd_flags ^= BRK; /* reset the break flag */ | |
403 | - kbd_flags ^= E1; /* bitwise EXOR with E1 flag */ | |
405 | + kbd_flags ^= BRK; /* reset the break flag */ | |
406 | + kbd_flags ^= E1; /* bitwise EXOR with E1 flag */ | |
404 | 407 | } |
405 | 408 | return; |
406 | 409 | } |
407 | 410 | |
408 | 411 | |
409 | 412 | |
410 | 413 | |
411 | 414 | |
412 | 415 | |
413 | 416 | |
414 | 417 | |
415 | 418 | |
416 | 419 | |
417 | 420 | |
... | ... | @@ -445,55 +448,57 @@ |
445 | 448 | kbd_scroll(scan_code); |
446 | 449 | break; |
447 | 450 | } |
451 | + | |
448 | 452 | return; |
449 | 453 | } |
450 | 454 | |
451 | -/******************************************************************************/ | |
452 | - | |
453 | 455 | static int kbd_reset(void) |
454 | 456 | { |
455 | 457 | /* KB Reset */ |
456 | 458 | if (kbd_input_empty() == 0) |
457 | 459 | return -1; |
458 | 460 | |
459 | - out8(I8042_DATA_REG, 0xff); | |
461 | + out8(I8042_DATA_REG, CMD_RESET_KBD); | |
460 | 462 | |
461 | - if (wait_until_kbd_output_full() == 0) | |
463 | + if (kbd_output_full() == 0) | |
462 | 464 | return -1; |
463 | 465 | |
464 | - if (in8(I8042_DATA_REG) != 0xfa) /* ACK */ | |
466 | + if (in8(I8042_DATA_REG) != KBD_ACK) | |
465 | 467 | return -1; |
466 | 468 | |
467 | - if (wait_until_kbd_output_full() == 0) | |
469 | + if (kbd_output_full() == 0) | |
468 | 470 | return -1; |
469 | 471 | |
470 | - if (in8(I8042_DATA_REG) != 0xaa) /* Test Pass*/ | |
472 | + if (in8(I8042_DATA_REG) != KBD_POR) | |
471 | 473 | return -1; |
472 | 474 | |
473 | 475 | if (kbd_input_empty() == 0) |
474 | 476 | return -1; |
475 | 477 | |
476 | 478 | /* Set KBC mode */ |
477 | - out8(I8042_COMMAND_REG, 0x60); | |
479 | + out8(I8042_CMD_REG, CMD_WR_CONFIG); | |
478 | 480 | |
479 | 481 | if (kbd_input_empty() == 0) |
480 | 482 | return -1; |
481 | 483 | |
482 | - out8(I8042_DATA_REG, 0x45); | |
484 | + out8(I8042_DATA_REG, | |
485 | + CONFIG_AT_TRANS | CONFIG_SET_BIST | CONFIG_KIRQ_EN); | |
483 | 486 | |
484 | 487 | if (kbd_input_empty() == 0) |
485 | 488 | return -1; |
486 | 489 | |
487 | 490 | /* Enable Keyboard */ |
488 | - out8(I8042_COMMAND_REG, 0xae); | |
491 | + out8(I8042_CMD_REG, CMD_KBD_EN); | |
489 | 492 | if (kbd_input_empty() == 0) |
490 | 493 | return -1; |
491 | 494 | |
492 | - out8(I8042_COMMAND_REG, 0x60); | |
495 | + out8(I8042_CMD_REG, CMD_WR_CONFIG); | |
493 | 496 | if (kbd_input_empty() == 0) |
494 | 497 | return -1; |
495 | 498 | |
496 | - out8(I8042_DATA_REG, 0xf4); | |
499 | + out8(I8042_DATA_REG, | |
500 | + CONFIG_AT_TRANS | CONFIG_MCLK_DIS | | |
501 | + CONFIG_KCLK_DIS | CONFIG_SET_BIST); | |
497 | 502 | if (kbd_input_empty() == 0) |
498 | 503 | return -1; |
499 | 504 | |
... | ... | @@ -502,7 +507,7 @@ |
502 | 507 | |
503 | 508 | static int kbd_controller_present(void) |
504 | 509 | { |
505 | - return in8(I8042_STATUS_REG) != 0xff; | |
510 | + return in8(I8042_STS_REG) != 0xff; | |
506 | 511 | } |
507 | 512 | |
508 | 513 | /* |
509 | 514 | |
510 | 515 | |
... | ... | @@ -520,18 +525,18 @@ |
520 | 525 | int timeout; |
521 | 526 | |
522 | 527 | /* |
523 | - * The delay is to give the keyboard controller some time to fill the | |
524 | - * next byte. | |
528 | + * The delay is to give the keyboard controller some time | |
529 | + * to fill the next byte. | |
525 | 530 | */ |
526 | 531 | while (1) { |
527 | - timeout = 100; /* wait for no longer than 100us */ | |
528 | - while (timeout > 0 && !(in8(I8042_STATUS_REG) & 0x01)) { | |
532 | + timeout = 100; /* wait for no longer than 100us */ | |
533 | + while (timeout > 0 && !(in8(I8042_STS_REG) & STATUS_OBF)) { | |
529 | 534 | udelay(1); |
530 | 535 | timeout--; |
531 | 536 | } |
532 | 537 | |
533 | - /* Try to pull next byte if not timeout. */ | |
534 | - if (in8(I8042_STATUS_REG) & 0x01) | |
538 | + /* Try to pull next byte if not timeout */ | |
539 | + if (in8(I8042_STS_REG) & STATUS_OBF) | |
535 | 540 | in8(I8042_DATA_REG); |
536 | 541 | else |
537 | 542 | break; |
... | ... | @@ -544,7 +549,7 @@ |
544 | 549 | return -1; |
545 | 550 | |
546 | 551 | /* Disable keyboard */ |
547 | - out8(I8042_COMMAND_REG, 0xad); | |
552 | + out8(I8042_CMD_REG, CMD_KBD_DIS); | |
548 | 553 | |
549 | 554 | if (kbd_input_empty() == 0) |
550 | 555 | return -1; |
551 | 556 | |
552 | 557 | |
... | ... | @@ -552,17 +557,16 @@ |
552 | 557 | return 0; |
553 | 558 | } |
554 | 559 | |
555 | -/******************************************************************************* | |
556 | - * | |
557 | - * i8042_kbd_init - reset keyboard and init state flags | |
558 | - */ | |
560 | +/* i8042_kbd_init - reset keyboard and init state flags */ | |
559 | 561 | int i8042_kbd_init(void) |
560 | 562 | { |
561 | 563 | int keymap, try; |
562 | 564 | char *penv; |
563 | 565 | |
564 | - if (!kbd_controller_present() || board_i8042_skip()) | |
566 | + if (!kbd_controller_present() || board_i8042_skip()) { | |
567 | + debug("i8042 keyboard controller is not present\n"); | |
565 | 568 | return -1; |
569 | + } | |
566 | 570 | |
567 | 571 | /* Init keyboard device (default US layout) */ |
568 | 572 | keymap = KBD_US; |
569 | 573 | |
570 | 574 | |
571 | 575 | |
572 | 576 | |
573 | 577 | |
574 | 578 | |
... | ... | @@ -578,32 +582,33 @@ |
578 | 582 | kbd_flags = NORMAL; |
579 | 583 | kbd_state = 0; |
580 | 584 | kbd_led_set(); |
585 | + | |
581 | 586 | return 0; |
582 | 587 | } |
583 | 588 | } |
589 | + | |
584 | 590 | return -1; |
585 | 591 | } |
586 | 592 | |
587 | - | |
588 | -/******************************************************************************* | |
589 | - * | |
593 | +/* | |
590 | 594 | * i8042_tstc - test if keyboard input is available |
591 | - * option: cursor blinking if called in a loop | |
595 | + * | |
596 | + * option: cursor blinking if called in a loop | |
592 | 597 | */ |
593 | 598 | int i8042_tstc(struct stdio_dev *dev) |
594 | 599 | { |
595 | 600 | unsigned char scan_code = 0; |
596 | 601 | |
597 | 602 | #ifdef CONFIG_CONSOLE_CURSOR |
598 | - if (--blinkCount == 0) { | |
603 | + if (--blink_count == 0) { | |
599 | 604 | cursor_state ^= 1; |
600 | 605 | console_cursor(cursor_state); |
601 | - blinkCount = CONFIG_SYS_CONSOLE_BLINK_COUNT; | |
606 | + blink_count = CONFIG_SYS_CONSOLE_BLINK_COUNT; | |
602 | 607 | udelay(10); |
603 | 608 | } |
604 | 609 | #endif |
605 | 610 | |
606 | - if ((in8(I8042_STATUS_REG) & 0x01) == 0) { | |
611 | + if ((in8(I8042_STS_REG) & STATUS_OBF) == 0) { | |
607 | 612 | return 0; |
608 | 613 | } else { |
609 | 614 | scan_code = in8(I8042_DATA_REG); |
610 | 615 | |
611 | 616 | |
... | ... | @@ -615,14 +620,14 @@ |
615 | 620 | if (kbd_input != -1) |
616 | 621 | return 1; |
617 | 622 | } |
623 | + | |
618 | 624 | return 0; |
619 | 625 | } |
620 | 626 | |
621 | - | |
622 | -/******************************************************************************* | |
623 | - * | |
627 | +/* | |
624 | 628 | * i8042_getc - wait till keyboard input is available |
625 | - * option: turn on/off cursor while waiting | |
629 | + * | |
630 | + * option: turn on/off cursor while waiting | |
626 | 631 | */ |
627 | 632 | int i8042_getc(struct stdio_dev *dev) |
628 | 633 | { |
629 | 634 | |
630 | 635 | |
631 | 636 | |
632 | 637 | |
... | ... | @@ -630,22 +635,23 @@ |
630 | 635 | unsigned char scan_code; |
631 | 636 | |
632 | 637 | while (kbd_input == -1) { |
633 | - while ((in8(I8042_STATUS_REG) & 0x01) == 0) { | |
638 | + while ((in8(I8042_STS_REG) & STATUS_OBF) == 0) { | |
634 | 639 | #ifdef CONFIG_CONSOLE_CURSOR |
635 | - if (--blinkCount == 0) { | |
640 | + if (--blink_count == 0) { | |
636 | 641 | cursor_state ^= 1; |
637 | 642 | console_cursor(cursor_state); |
638 | - blinkCount = CONFIG_SYS_CONSOLE_BLINK_COUNT; | |
643 | + blink_count = CONFIG_SYS_CONSOLE_BLINK_COUNT; | |
639 | 644 | } |
640 | 645 | udelay(10); |
641 | 646 | #endif |
642 | 647 | } |
643 | 648 | scan_code = in8(I8042_DATA_REG); |
644 | 649 | if (scan_code != 0xfa) |
645 | - kbd_conv_char (scan_code); | |
650 | + kbd_conv_char(scan_code); | |
646 | 651 | } |
647 | 652 | ret_chr = kbd_input; |
648 | 653 | kbd_input = -1; |
654 | + | |
649 | 655 | return ret_chr; |
650 | 656 | } |
include/i8042.h
... | ... | @@ -10,52 +10,67 @@ |
10 | 10 | #ifndef _I8042_H_ |
11 | 11 | #define _I8042_H_ |
12 | 12 | |
13 | -#ifdef __I386__ | |
14 | -#include <common.h> | |
15 | -#include <asm/io.h> | |
16 | -#define in8(p) inb(p) | |
17 | -#define out8(p,v) outb(v,p) | |
18 | -#endif | |
19 | - | |
20 | 13 | /* defines */ |
21 | 14 | |
22 | -#define I8042_DATA_REG (CONFIG_SYS_ISA_IO + 0x0060) /* keyboard i/o buffer */ | |
23 | -#define I8042_STATUS_REG (CONFIG_SYS_ISA_IO + 0x0064) /* keyboard status read */ | |
24 | -#define I8042_COMMAND_REG (CONFIG_SYS_ISA_IO + 0x0064) /* keyboard ctrl write */ | |
15 | +#define I8042_DATA_REG 0x60 /* keyboard i/o buffer */ | |
16 | +#define I8042_STS_REG 0x64 /* keyboard status read */ | |
17 | +#define I8042_CMD_REG 0x64 /* keyboard ctrl write */ | |
25 | 18 | |
26 | -enum { | |
27 | - /* Output register (I8042_DATA_REG) has data for system */ | |
28 | - I8042_STATUS_OUT_DATA = 1 << 0, | |
29 | - I8042_STATUS_IN_DATA = 1 << 1, | |
30 | -}; | |
19 | +/* Status register bit defines */ | |
20 | +#define STATUS_OBF (1 << 0) | |
21 | +#define STATUS_IBF (1 << 1) | |
31 | 22 | |
32 | -#define KBD_US 0 /* default US layout */ | |
33 | -#define KBD_GER 1 /* german layout */ | |
23 | +/* Configuration byte bit defines */ | |
24 | +#define CONFIG_KIRQ_EN (1 << 0) | |
25 | +#define CONFIG_MIRQ_EN (1 << 1) | |
26 | +#define CONFIG_SET_BIST (1 << 2) | |
27 | +#define CONFIG_KCLK_DIS (1 << 4) | |
28 | +#define CONFIG_MCLK_DIS (1 << 5) | |
29 | +#define CONFIG_AT_TRANS (1 << 6) | |
34 | 30 | |
35 | -#define KBD_TIMEOUT 1000 /* 1 sec */ | |
36 | -#define KBD_RESET_TRIES 3 | |
31 | +/* i8042 commands */ | |
32 | +#define CMD_RD_CONFIG 0x20 /* read configuration byte */ | |
33 | +#define CMD_WR_CONFIG 0x60 /* write configuration byte */ | |
34 | +#define CMD_SELF_TEST 0xaa /* controller self-test */ | |
35 | +#define CMD_KBD_DIS 0xad /* keyboard disable */ | |
36 | +#define CMD_KBD_EN 0xae /* keyboard enable */ | |
37 | +#define CMD_SET_KBD_LED 0xed /* set keyboard led */ | |
38 | +#define CMD_RESET_KBD 0xff /* reset keyboard */ | |
37 | 39 | |
38 | -#define AS 0 /* normal character index */ | |
39 | -#define SH 1 /* shift index */ | |
40 | -#define CN 2 /* control index */ | |
41 | -#define NM 3 /* numeric lock index */ | |
42 | -#define AK 4 /* right alt key */ | |
43 | -#define CP 5 /* capslock index */ | |
44 | -#define ST 6 /* stop output index */ | |
45 | -#define EX 7 /* extended code index */ | |
46 | -#define ES 8 /* escape and extended code index */ | |
40 | +/* i8042 command result */ | |
41 | +#define KBC_TEST_OK 0x55 | |
42 | +#define KBD_ACK 0xfa | |
43 | +#define KBD_POR 0xaa | |
47 | 44 | |
48 | -#define NORMAL 0x0000 /* normal key */ | |
49 | -#define STP 0x0001 /* scroll lock stop output*/ | |
50 | -#define NUM 0x0002 /* numeric lock */ | |
51 | -#define CAPS 0x0004 /* capslock */ | |
52 | -#define SHIFT 0x0008 /* shift */ | |
53 | -#define CTRL 0x0010 /* control*/ | |
54 | -#define EXT 0x0020 /* extended scan code 0xe0 */ | |
55 | -#define ESC 0x0040 /* escape key press */ | |
56 | -#define E1 0x0080 /* extended scan code 0xe1 */ | |
57 | -#define BRK 0x0100 /* make break flag for keyboard */ | |
58 | -#define ALT 0x0200 /* right alt */ | |
45 | +/* keyboard scan codes */ | |
46 | + | |
47 | +#define KBD_US 0 /* default US layout */ | |
48 | +#define KBD_GER 1 /* german layout */ | |
49 | + | |
50 | +#define KBD_TIMEOUT 1000 /* 1 sec */ | |
51 | +#define KBD_RESET_TRIES 3 | |
52 | + | |
53 | +#define AS 0 /* normal character index */ | |
54 | +#define SH 1 /* shift index */ | |
55 | +#define CN 2 /* control index */ | |
56 | +#define NM 3 /* numeric lock index */ | |
57 | +#define AK 4 /* right alt key */ | |
58 | +#define CP 5 /* capslock index */ | |
59 | +#define ST 6 /* stop output index */ | |
60 | +#define EX 7 /* extended code index */ | |
61 | +#define ES 8 /* escape and extended code index */ | |
62 | + | |
63 | +#define NORMAL 0x0000 /* normal key */ | |
64 | +#define STP 0x0001 /* scroll lock stop output*/ | |
65 | +#define NUM 0x0002 /* numeric lock */ | |
66 | +#define CAPS 0x0004 /* capslock */ | |
67 | +#define SHIFT 0x0008 /* shift */ | |
68 | +#define CTRL 0x0010 /* control*/ | |
69 | +#define EXT 0x0020 /* extended scan code 0xe0 */ | |
70 | +#define ESC 0x0040 /* escape key press */ | |
71 | +#define E1 0x0080 /* extended scan code 0xe1 */ | |
72 | +#define BRK 0x0100 /* make break flag for keyboard */ | |
73 | +#define ALT 0x0200 /* right alt */ | |
59 | 74 | |
60 | 75 | /* exports */ |
61 | 76 |