]>
Commit | Line | Data |
---|---|---|
affae2bf WD |
1 | /* |
2 | * (C) Copyright 2001 | |
3 | * Denis Peter, MPL AG Switzerland | |
4 | * | |
5 | * Part of this source has been derived from the Linux USB | |
6 | * project. | |
7 | * | |
8 | * See file CREDITS for list of people who contributed to this | |
9 | * project. | |
10 | * | |
11 | * This program is free software; you can redistribute it and/or | |
12 | * modify it under the terms of the GNU General Public License as | |
13 | * published by the Free Software Foundation; either version 2 of | |
14 | * the License, or (at your option) any later version. | |
15 | * | |
16 | * This program is distributed in the hope that it will be useful, | |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | * GNU General Public License for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License | |
22 | * along with this program; if not, write to the Free Software | |
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, | |
24 | * MA 02111-1307 USA | |
25 | * | |
26 | */ | |
27 | #include <common.h> | |
9a8c72a6 | 28 | #include <malloc.h> |
52cb4d4f | 29 | #include <stdio_dev.h> |
c918261c | 30 | #include <asm/byteorder.h> |
affae2bf | 31 | |
affae2bf WD |
32 | #include <usb.h> |
33 | ||
9a8c72a6 MV |
34 | #ifdef USB_KBD_DEBUG |
35 | #define USB_KBD_PRINTF(fmt, args...) printf(fmt, ##args) | |
36 | #else | |
37 | #define USB_KBD_PRINTF(fmt, args...) | |
38 | #endif | |
39 | ||
affae2bf | 40 | /* |
00b7d6ec | 41 | * If overwrite_console returns 1, the stdin, stderr and stdout |
affae2bf WD |
42 | * are switched to the serial port, else the settings in the |
43 | * environment are used | |
44 | */ | |
6d0f6bcf | 45 | #ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE |
00b7d6ec | 46 | extern int overwrite_console(void); |
affae2bf | 47 | #else |
00b7d6ec | 48 | int overwrite_console(void) |
affae2bf | 49 | { |
00b7d6ec | 50 | return 0; |
affae2bf WD |
51 | } |
52 | #endif | |
53 | ||
9a8c72a6 MV |
54 | /* Keyboard sampling rate */ |
55 | #define REPEAT_RATE (40 / 4) /* 40msec -> 25cps */ | |
56 | #define REPEAT_DELAY 10 /* 10 x REPEAT_RATE = 400msec */ | |
affae2bf WD |
57 | |
58 | #define NUM_LOCK 0x53 | |
00b7d6ec MV |
59 | #define CAPS_LOCK 0x39 |
60 | #define SCROLL_LOCK 0x47 | |
affae2bf | 61 | |
affae2bf | 62 | /* Modifier bits */ |
9a8c72a6 MV |
63 | #define LEFT_CNTR (1 << 0) |
64 | #define LEFT_SHIFT (1 << 1) | |
65 | #define LEFT_ALT (1 << 2) | |
66 | #define LEFT_GUI (1 << 3) | |
67 | #define RIGHT_CNTR (1 << 4) | |
68 | #define RIGHT_SHIFT (1 << 5) | |
69 | #define RIGHT_ALT (1 << 6) | |
70 | #define RIGHT_GUI (1 << 7) | |
71 | ||
72 | /* Size of the keyboard buffer */ | |
73 | #define USB_KBD_BUFFER_LEN 0x20 | |
74 | ||
75 | /* Device name */ | |
00b7d6ec | 76 | #define DEVNAME "usbkbd" |
affae2bf | 77 | |
9a8c72a6 MV |
78 | /* Keyboard maps */ |
79 | static const unsigned char usb_kbd_numkey[] = { | |
00b7d6ec MV |
80 | '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', |
81 | '\r', 0x1b, '\b', '\t', ' ', '-', '=', '[', ']', | |
82 | '\\', '#', ';', '\'', '`', ',', '.', '/' | |
affae2bf | 83 | }; |
9a8c72a6 | 84 | static const unsigned char usb_kbd_numkey_shifted[] = { |
00b7d6ec MV |
85 | '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', |
86 | '\r', 0x1b, '\b', '\t', ' ', '_', '+', '{', '}', | |
87 | '|', '~', ':', '"', '~', '<', '>', '?' | |
affae2bf WD |
88 | }; |
89 | ||
d53da847 VP |
90 | static const unsigned char usb_kbd_num_keypad[] = { |
91 | '/', '*', '-', '+', '\r', | |
92 | '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', | |
93 | '.', 0, 0, 0, '=' | |
94 | }; | |
95 | ||
9a8c72a6 MV |
96 | /* |
97 | * NOTE: It's important for the NUM, CAPS, SCROLL-lock bits to be in this | |
98 | * order. See usb_kbd_setled() function! | |
99 | */ | |
100 | #define USB_KBD_NUMLOCK (1 << 0) | |
101 | #define USB_KBD_CAPSLOCK (1 << 1) | |
102 | #define USB_KBD_SCROLLLOCK (1 << 2) | |
103 | #define USB_KBD_CTRL (1 << 3) | |
48c8073e | 104 | |
9a8c72a6 MV |
105 | #define USB_KBD_LEDMASK \ |
106 | (USB_KBD_NUMLOCK | USB_KBD_CAPSLOCK | USB_KBD_SCROLLLOCK) | |
48c8073e | 107 | |
9a8c72a6 MV |
108 | struct usb_kbd_pdata { |
109 | uint32_t repeat_delay; | |
affae2bf | 110 | |
9a8c72a6 MV |
111 | uint32_t usb_in_pointer; |
112 | uint32_t usb_out_pointer; | |
113 | uint8_t usb_kbd_buffer[USB_KBD_BUFFER_LEN]; | |
48c8073e | 114 | |
9a8c72a6 MV |
115 | uint8_t new[8]; |
116 | uint8_t old[8]; | |
48c8073e | 117 | |
9a8c72a6 MV |
118 | uint8_t flags; |
119 | }; | |
48c8073e | 120 | |
9a8c72a6 MV |
121 | /* Generic keyboard event polling. */ |
122 | void usb_kbd_generic_poll(void) | |
affae2bf | 123 | { |
48c8073e MV |
124 | struct stdio_dev *dev; |
125 | struct usb_device *usb_kbd_dev; | |
9a8c72a6 MV |
126 | struct usb_kbd_pdata *data; |
127 | struct usb_interface *iface; | |
128 | struct usb_endpoint_descriptor *ep; | |
129 | int pipe; | |
130 | int maxp; | |
48c8073e | 131 | |
9a8c72a6 MV |
132 | /* Get the pointer to USB Keyboard device pointer */ |
133 | dev = stdio_get_by_name(DEVNAME); | |
48c8073e | 134 | usb_kbd_dev = (struct usb_device *)dev->priv; |
9a8c72a6 MV |
135 | data = usb_kbd_dev->privptr; |
136 | iface = &usb_kbd_dev->config.if_desc[0]; | |
137 | ep = &iface->ep_desc[0]; | |
138 | pipe = usb_rcvintpipe(usb_kbd_dev, ep->bEndpointAddress); | |
48c8073e | 139 | |
9a8c72a6 MV |
140 | /* Submit a interrupt transfer request */ |
141 | maxp = usb_maxpacket(usb_kbd_dev, pipe); | |
142 | usb_submit_int_msg(usb_kbd_dev, pipe, data->new, | |
143 | maxp > 8 ? 8 : maxp, ep->bInterval); | |
affae2bf WD |
144 | } |
145 | ||
9a8c72a6 MV |
146 | /* Puts character in the queue and sets up the in and out pointer. */ |
147 | static void usb_kbd_put_queue(struct usb_kbd_pdata *data, char c) | |
affae2bf | 148 | { |
9a8c72a6 MV |
149 | if (data->usb_in_pointer == USB_KBD_BUFFER_LEN - 1) { |
150 | /* Check for buffer full. */ | |
151 | if (data->usb_out_pointer == 0) | |
152 | return; | |
affae2bf | 153 | |
9a8c72a6 MV |
154 | data->usb_in_pointer = 0; |
155 | } else { | |
156 | /* Check for buffer full. */ | |
157 | if (data->usb_in_pointer == data->usb_out_pointer - 1) | |
158 | return; | |
affae2bf | 159 | |
9a8c72a6 MV |
160 | data->usb_in_pointer++; |
161 | } | |
affae2bf | 162 | |
9a8c72a6 | 163 | data->usb_kbd_buffer[data->usb_in_pointer] = c; |
affae2bf WD |
164 | } |
165 | ||
9a8c72a6 MV |
166 | /* |
167 | * Set the LEDs. Since this is used in the irq routine, the control job is | |
168 | * issued with a timeout of 0. This means, that the job is queued without | |
169 | * waiting for job completion. | |
affae2bf | 170 | */ |
affae2bf WD |
171 | static void usb_kbd_setled(struct usb_device *dev) |
172 | { | |
9a8c72a6 MV |
173 | struct usb_interface *iface = &dev->config.if_desc[0]; |
174 | struct usb_kbd_pdata *data = dev->privptr; | |
175 | uint32_t leds = data->flags & USB_KBD_LEDMASK; | |
176 | ||
affae2bf WD |
177 | usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
178 | USB_REQ_SET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE, | |
8f8bd565 | 179 | 0x200, iface->desc.bInterfaceNumber, (void *)&leds, 1, 0); |
affae2bf WD |
180 | } |
181 | ||
9a8c72a6 | 182 | #define CAPITAL_MASK 0x20 |
affae2bf | 183 | /* Translate the scancode in ASCII */ |
9a8c72a6 MV |
184 | static int usb_kbd_translate(struct usb_kbd_pdata *data, unsigned char scancode, |
185 | unsigned char modifier, int pressed) | |
affae2bf | 186 | { |
9a8c72a6 | 187 | uint8_t keycode = 0; |
affae2bf | 188 | |
9a8c72a6 | 189 | /* Key released */ |
00b7d6ec | 190 | if (pressed == 0) { |
9a8c72a6 | 191 | data->repeat_delay = 0; |
affae2bf WD |
192 | return 0; |
193 | } | |
9a8c72a6 | 194 | |
00b7d6ec | 195 | if (pressed == 2) { |
9a8c72a6 MV |
196 | data->repeat_delay++; |
197 | if (data->repeat_delay < REPEAT_DELAY) | |
affae2bf | 198 | return 0; |
9a8c72a6 MV |
199 | |
200 | data->repeat_delay = REPEAT_DELAY; | |
affae2bf | 201 | } |
9a8c72a6 MV |
202 | |
203 | /* Alphanumeric values */ | |
204 | if ((scancode > 3) && (scancode <= 0x1d)) { | |
205 | keycode = scancode - 4 + 'a'; | |
206 | ||
207 | if (data->flags & USB_KBD_CAPSLOCK) | |
00b7d6ec | 208 | keycode &= ~CAPITAL_MASK; |
9a8c72a6 MV |
209 | |
210 | if (modifier & (LEFT_SHIFT | RIGHT_SHIFT)) { | |
211 | /* Handle CAPSLock + Shift pressed simultaneously */ | |
00b7d6ec | 212 | if (keycode & CAPITAL_MASK) |
00b7d6ec | 213 | keycode &= ~CAPITAL_MASK; |
affae2bf | 214 | else |
00b7d6ec | 215 | keycode |= CAPITAL_MASK; |
affae2bf WD |
216 | } |
217 | } | |
9a8c72a6 MV |
218 | |
219 | if ((scancode > 0x1d) && (scancode < 0x3a)) { | |
220 | /* Shift pressed */ | |
221 | if (modifier & (LEFT_SHIFT | RIGHT_SHIFT)) | |
222 | keycode = usb_kbd_numkey_shifted[scancode - 0x1e]; | |
223 | else | |
224 | keycode = usb_kbd_numkey[scancode - 0x1e]; | |
affae2bf | 225 | } |
4785a694 | 226 | |
d53da847 VP |
227 | /* Numeric keypad */ |
228 | if ((scancode >= 0x54) && (scancode <= 0x67)) | |
229 | keycode = usb_kbd_num_keypad[scancode - 0x54]; | |
230 | ||
9a8c72a6 | 231 | if (data->flags & USB_KBD_CTRL) |
4785a694 ZW |
232 | keycode = scancode - 0x3; |
233 | ||
00b7d6ec MV |
234 | if (pressed == 1) { |
235 | if (scancode == NUM_LOCK) { | |
9a8c72a6 | 236 | data->flags ^= USB_KBD_NUMLOCK; |
affae2bf WD |
237 | return 1; |
238 | } | |
9a8c72a6 | 239 | |
00b7d6ec | 240 | if (scancode == CAPS_LOCK) { |
9a8c72a6 | 241 | data->flags ^= USB_KBD_CAPSLOCK; |
affae2bf WD |
242 | return 1; |
243 | } | |
00b7d6ec | 244 | if (scancode == SCROLL_LOCK) { |
9a8c72a6 | 245 | data->flags ^= USB_KBD_SCROLLLOCK; |
affae2bf WD |
246 | return 1; |
247 | } | |
248 | } | |
9a8c72a6 MV |
249 | |
250 | /* Report keycode if any */ | |
251 | if (keycode) { | |
00b7d6ec | 252 | USB_KBD_PRINTF("%c", keycode); |
9a8c72a6 | 253 | usb_kbd_put_queue(data, keycode); |
affae2bf | 254 | } |
9a8c72a6 | 255 | |
affae2bf WD |
256 | return 0; |
257 | } | |
258 | ||
9a8c72a6 MV |
259 | static uint32_t usb_kbd_service_key(struct usb_device *dev, int i, int up) |
260 | { | |
261 | uint32_t res = 0; | |
262 | struct usb_kbd_pdata *data = dev->privptr; | |
263 | uint8_t *new; | |
264 | uint8_t *old; | |
265 | ||
266 | if (up) { | |
267 | new = data->old; | |
268 | old = data->new; | |
269 | } else { | |
270 | new = data->new; | |
271 | old = data->old; | |
272 | } | |
273 | ||
274 | if ((old[i] > 3) && (memscan(new + 2, old[i], 6) == new + 8)) | |
275 | res |= usb_kbd_translate(data, old[i], data->new[0], up); | |
276 | ||
277 | return res; | |
278 | } | |
279 | ||
affae2bf | 280 | /* Interrupt service routine */ |
48c8073e | 281 | static int usb_kbd_irq_worker(struct usb_device *dev) |
affae2bf | 282 | { |
9a8c72a6 MV |
283 | struct usb_kbd_pdata *data = dev->privptr; |
284 | int i, res = 0; | |
4785a694 | 285 | |
9a8c72a6 MV |
286 | /* No combo key pressed */ |
287 | if (data->new[0] == 0x00) | |
288 | data->flags &= ~USB_KBD_CTRL; | |
289 | /* Left or Right Ctrl pressed */ | |
290 | else if ((data->new[0] == LEFT_CNTR) || (data->new[0] == RIGHT_CNTR)) | |
291 | data->flags |= USB_KBD_CTRL; | |
00b7d6ec | 292 | |
9a8c72a6 MV |
293 | for (i = 2; i < 8; i++) { |
294 | res |= usb_kbd_service_key(dev, i, 0); | |
295 | res |= usb_kbd_service_key(dev, i, 1); | |
affae2bf | 296 | } |
00b7d6ec | 297 | |
9a8c72a6 MV |
298 | /* Key is still pressed */ |
299 | if ((data->new[2] > 3) && (data->old[2] == data->new[2])) | |
300 | res |= usb_kbd_translate(data, data->new[2], data->new[0], 2); | |
301 | ||
00b7d6ec | 302 | if (res == 1) |
affae2bf | 303 | usb_kbd_setled(dev); |
00b7d6ec | 304 | |
9a8c72a6 | 305 | memcpy(data->old, data->new, 8); |
00b7d6ec | 306 | |
9a8c72a6 | 307 | return 1; |
affae2bf WD |
308 | } |
309 | ||
9a8c72a6 | 310 | /* Keyboard interrupt handler */ |
48c8073e MV |
311 | static int usb_kbd_irq(struct usb_device *dev) |
312 | { | |
313 | if ((dev->irq_status != 0) || (dev->irq_act_len != 8)) { | |
9a8c72a6 | 314 | USB_KBD_PRINTF("USB KBD: Error %lX, len %d\n", |
48c8073e MV |
315 | dev->irq_status, dev->irq_act_len); |
316 | return 1; | |
317 | } | |
318 | ||
319 | return usb_kbd_irq_worker(dev); | |
320 | } | |
321 | ||
9a8c72a6 MV |
322 | /* Interrupt polling */ |
323 | static inline void usb_kbd_poll_for_event(struct usb_device *dev) | |
324 | { | |
325 | #if defined(CONFIG_SYS_USB_EVENT_POLL) | |
326 | usb_event_poll(); | |
327 | usb_kbd_irq_worker(dev); | |
328 | #elif defined(CONFIG_SYS_USB_EVENT_POLL_VIA_CONTROL_EP) | |
329 | struct usb_interface *iface; | |
330 | struct usb_kbd_pdata *data = dev->privptr; | |
331 | iface = &dev->config.if_desc[0]; | |
332 | usb_get_report(dev, iface->desc.bInterfaceNumber, | |
3d17308e | 333 | 1, 0, data->new, sizeof(data->new)); |
9a8c72a6 MV |
334 | if (memcmp(data->old, data->new, sizeof(data->new))) |
335 | usb_kbd_irq_worker(dev); | |
336 | #endif | |
337 | } | |
338 | ||
339 | /* test if a character is in the queue */ | |
340 | static int usb_kbd_testc(void) | |
341 | { | |
342 | struct stdio_dev *dev; | |
343 | struct usb_device *usb_kbd_dev; | |
344 | struct usb_kbd_pdata *data; | |
345 | ||
346 | dev = stdio_get_by_name(DEVNAME); | |
347 | usb_kbd_dev = (struct usb_device *)dev->priv; | |
348 | data = usb_kbd_dev->privptr; | |
349 | ||
350 | usb_kbd_poll_for_event(usb_kbd_dev); | |
351 | ||
352 | return !(data->usb_in_pointer == data->usb_out_pointer); | |
353 | } | |
354 | ||
355 | /* gets the character from the queue */ | |
356 | static int usb_kbd_getc(void) | |
357 | { | |
358 | struct stdio_dev *dev; | |
359 | struct usb_device *usb_kbd_dev; | |
360 | struct usb_kbd_pdata *data; | |
361 | ||
362 | dev = stdio_get_by_name(DEVNAME); | |
363 | usb_kbd_dev = (struct usb_device *)dev->priv; | |
364 | data = usb_kbd_dev->privptr; | |
365 | ||
366 | while (data->usb_in_pointer == data->usb_out_pointer) | |
367 | usb_kbd_poll_for_event(usb_kbd_dev); | |
368 | ||
369 | if (data->usb_out_pointer == USB_KBD_BUFFER_LEN - 1) | |
370 | data->usb_out_pointer = 0; | |
371 | else | |
372 | data->usb_out_pointer++; | |
373 | ||
374 | return data->usb_kbd_buffer[data->usb_out_pointer]; | |
375 | } | |
376 | ||
377 | /* probes the USB device dev for keyboard type. */ | |
affae2bf WD |
378 | static int usb_kbd_probe(struct usb_device *dev, unsigned int ifnum) |
379 | { | |
8f8bd565 | 380 | struct usb_interface *iface; |
affae2bf | 381 | struct usb_endpoint_descriptor *ep; |
9a8c72a6 | 382 | struct usb_kbd_pdata *data; |
00b7d6ec | 383 | int pipe, maxp; |
affae2bf | 384 | |
00b7d6ec MV |
385 | if (dev->descriptor.bNumConfigurations != 1) |
386 | return 0; | |
9a8c72a6 | 387 | |
affae2bf WD |
388 | iface = &dev->config.if_desc[ifnum]; |
389 | ||
8f8bd565 TR |
390 | if (iface->desc.bInterfaceClass != 3) |
391 | return 0; | |
9a8c72a6 | 392 | |
8f8bd565 TR |
393 | if (iface->desc.bInterfaceSubClass != 1) |
394 | return 0; | |
9a8c72a6 | 395 | |
8f8bd565 TR |
396 | if (iface->desc.bInterfaceProtocol != 1) |
397 | return 0; | |
9a8c72a6 | 398 | |
8f8bd565 TR |
399 | if (iface->desc.bNumEndpoints != 1) |
400 | return 0; | |
affae2bf WD |
401 | |
402 | ep = &iface->ep_desc[0]; | |
403 | ||
9a8c72a6 | 404 | /* Check if endpoint 1 is interrupt endpoint */ |
00b7d6ec MV |
405 | if (!(ep->bEndpointAddress & 0x80)) |
406 | return 0; | |
9a8c72a6 | 407 | |
00b7d6ec MV |
408 | if ((ep->bmAttributes & 3) != 3) |
409 | return 0; | |
9a8c72a6 MV |
410 | |
411 | USB_KBD_PRINTF("USB KBD: found set protocol...\n"); | |
412 | ||
413 | data = malloc(sizeof(struct usb_kbd_pdata)); | |
414 | if (!data) { | |
415 | printf("USB KBD: Error allocating private data\n"); | |
416 | return 0; | |
417 | } | |
418 | ||
419 | /* Clear private data */ | |
420 | memset(data, 0, sizeof(struct usb_kbd_pdata)); | |
421 | ||
422 | /* Insert private data into USB device structure */ | |
423 | dev->privptr = data; | |
424 | ||
425 | /* Set IRQ handler */ | |
426 | dev->irq_handle = usb_kbd_irq; | |
427 | ||
affae2bf WD |
428 | pipe = usb_rcvintpipe(dev, ep->bEndpointAddress); |
429 | maxp = usb_maxpacket(dev, pipe); | |
9a8c72a6 MV |
430 | |
431 | /* We found a USB Keyboard, install it. */ | |
432 | usb_set_protocol(dev, iface->desc.bInterfaceNumber, 0); | |
433 | ||
434 | USB_KBD_PRINTF("USB KBD: found set idle...\n"); | |
435 | usb_set_idle(dev, iface->desc.bInterfaceNumber, REPEAT_RATE, 0); | |
436 | ||
437 | USB_KBD_PRINTF("USB KBD: enable interrupt pipe...\n"); | |
438 | usb_submit_int_msg(dev, pipe, data->new, maxp > 8 ? 8 : maxp, | |
00b7d6ec | 439 | ep->bInterval); |
9a8c72a6 MV |
440 | |
441 | /* Success. */ | |
affae2bf WD |
442 | return 1; |
443 | } | |
444 | ||
9a8c72a6 MV |
445 | /* Search for keyboard and register it if found. */ |
446 | int drv_usb_kbd_init(void) | |
447 | { | |
448 | struct stdio_dev usb_kbd_dev, *old_dev; | |
449 | struct usb_device *dev; | |
450 | char *stdinname = getenv("stdin"); | |
451 | int error, i; | |
452 | ||
453 | /* Scan all USB Devices */ | |
454 | for (i = 0; i < USB_MAX_DEVICE; i++) { | |
455 | /* Get USB device. */ | |
456 | dev = usb_get_dev_index(i); | |
457 | if (!dev) | |
458 | return -1; | |
459 | ||
460 | if (dev->devnum == -1) | |
461 | continue; | |
462 | ||
463 | /* Try probing the keyboard */ | |
464 | if (usb_kbd_probe(dev, 0) != 1) | |
465 | continue; | |
466 | ||
467 | /* We found a keyboard, check if it is already registered. */ | |
468 | USB_KBD_PRINTF("USB KBD: found set up device.\n"); | |
469 | old_dev = stdio_get_by_name(DEVNAME); | |
470 | if (old_dev) { | |
471 | /* Already registered, just return ok. */ | |
472 | USB_KBD_PRINTF("USB KBD: is already registered.\n"); | |
473 | return 1; | |
474 | } | |
475 | ||
476 | /* Register the keyboard */ | |
477 | USB_KBD_PRINTF("USB KBD: register.\n"); | |
478 | memset(&usb_kbd_dev, 0, sizeof(struct stdio_dev)); | |
479 | strcpy(usb_kbd_dev.name, DEVNAME); | |
480 | usb_kbd_dev.flags = DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM; | |
481 | usb_kbd_dev.putc = NULL; | |
482 | usb_kbd_dev.puts = NULL; | |
483 | usb_kbd_dev.getc = usb_kbd_getc; | |
484 | usb_kbd_dev.tstc = usb_kbd_testc; | |
485 | usb_kbd_dev.priv = (void *)dev; | |
486 | error = stdio_register(&usb_kbd_dev); | |
487 | if (error) | |
488 | return error; | |
489 | ||
fb3ef649 AM |
490 | #ifdef CONFIG_CONSOLE_MUX |
491 | error = iomux_doenv(stdin, stdinname); | |
492 | if (error) | |
493 | return error; | |
494 | #else | |
9a8c72a6 MV |
495 | /* Check if this is the standard input device. */ |
496 | if (strcmp(stdinname, DEVNAME)) | |
497 | return 1; | |
498 | ||
499 | /* Reassign the console */ | |
500 | if (overwrite_console()) | |
501 | return 1; | |
502 | ||
503 | error = console_assign(stdin, DEVNAME); | |
504 | if (error) | |
505 | return error; | |
fb3ef649 | 506 | #endif |
9a8c72a6 MV |
507 | |
508 | return 1; | |
509 | } | |
510 | ||
511 | /* No USB Keyboard found */ | |
512 | return -1; | |
513 | } | |
514 | ||
515 | /* Deregister the keyboard. */ | |
516 | int usb_kbd_deregister(void) | |
517 | { | |
518 | #ifdef CONFIG_SYS_STDIO_DEREGISTER | |
519 | return stdio_deregister(DEVNAME); | |
520 | #else | |
521 | return 1; | |
522 | #endif | |
523 | } |