3 * Denis Peter, MPL AG Switzerland
5 * Part of this source has been derived from the Linux USB
8 * See file CREDITS for list of people who contributed to this
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.
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.
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,
29 #include <stdio_dev.h>
30 #include <asm/byteorder.h>
35 #define USB_KBD_PRINTF(fmt, args...) printf(fmt, ##args)
37 #define USB_KBD_PRINTF(fmt, args...)
41 * If overwrite_console returns 1, the stdin, stderr and stdout
42 * are switched to the serial port, else the settings in the
43 * environment are used
45 #ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE
46 extern int overwrite_console(void);
48 int overwrite_console(void)
54 /* Keyboard sampling rate */
55 #define REPEAT_RATE (40 / 4) /* 40msec -> 25cps */
56 #define REPEAT_DELAY 10 /* 10 x REPEAT_RATE = 400msec */
59 #define CAPS_LOCK 0x39
60 #define SCROLL_LOCK 0x47
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)
72 /* Size of the keyboard buffer */
73 #define USB_KBD_BUFFER_LEN 0x20
76 #define DEVNAME "usbkbd"
79 static const unsigned char usb_kbd_numkey[] = {
80 '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
81 '\r', 0x1b, '\b', '\t', ' ', '-', '=', '[', ']',
82 '\\', '#', ';', '\'', '`', ',', '.', '/'
84 static const unsigned char usb_kbd_numkey_shifted[] = {
85 '!', '@', '#', '$', '%', '^', '&', '*', '(', ')',
86 '\r', 0x1b, '\b', '\t', ' ', '_', '+', '{', '}',
87 '|', '~', ':', '"', '~', '<', '>', '?'
91 * NOTE: It's important for the NUM, CAPS, SCROLL-lock bits to be in this
92 * order. See usb_kbd_setled() function!
94 #define USB_KBD_NUMLOCK (1 << 0)
95 #define USB_KBD_CAPSLOCK (1 << 1)
96 #define USB_KBD_SCROLLLOCK (1 << 2)
97 #define USB_KBD_CTRL (1 << 3)
99 #define USB_KBD_LEDMASK \
100 (USB_KBD_NUMLOCK | USB_KBD_CAPSLOCK | USB_KBD_SCROLLLOCK)
102 struct usb_kbd_pdata {
103 uint32_t repeat_delay;
105 uint32_t usb_in_pointer;
106 uint32_t usb_out_pointer;
107 uint8_t usb_kbd_buffer[USB_KBD_BUFFER_LEN];
115 /* Generic keyboard event polling. */
116 void usb_kbd_generic_poll(void)
118 struct stdio_dev *dev;
119 struct usb_device *usb_kbd_dev;
120 struct usb_kbd_pdata *data;
121 struct usb_interface *iface;
122 struct usb_endpoint_descriptor *ep;
126 /* Get the pointer to USB Keyboard device pointer */
127 dev = stdio_get_by_name(DEVNAME);
128 usb_kbd_dev = (struct usb_device *)dev->priv;
129 data = usb_kbd_dev->privptr;
130 iface = &usb_kbd_dev->config.if_desc[0];
131 ep = &iface->ep_desc[0];
132 pipe = usb_rcvintpipe(usb_kbd_dev, ep->bEndpointAddress);
134 /* Submit a interrupt transfer request */
135 maxp = usb_maxpacket(usb_kbd_dev, pipe);
136 usb_submit_int_msg(usb_kbd_dev, pipe, data->new,
137 maxp > 8 ? 8 : maxp, ep->bInterval);
140 /* Puts character in the queue and sets up the in and out pointer. */
141 static void usb_kbd_put_queue(struct usb_kbd_pdata *data, char c)
143 if (data->usb_in_pointer == USB_KBD_BUFFER_LEN - 1) {
144 /* Check for buffer full. */
145 if (data->usb_out_pointer == 0)
148 data->usb_in_pointer = 0;
150 /* Check for buffer full. */
151 if (data->usb_in_pointer == data->usb_out_pointer - 1)
154 data->usb_in_pointer++;
157 data->usb_kbd_buffer[data->usb_in_pointer] = c;
161 * Set the LEDs. Since this is used in the irq routine, the control job is
162 * issued with a timeout of 0. This means, that the job is queued without
163 * waiting for job completion.
165 static void usb_kbd_setled(struct usb_device *dev)
167 struct usb_interface *iface = &dev->config.if_desc[0];
168 struct usb_kbd_pdata *data = dev->privptr;
169 uint32_t leds = data->flags & USB_KBD_LEDMASK;
171 usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
172 USB_REQ_SET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
173 0x200, iface->desc.bInterfaceNumber, (void *)&leds, 1, 0);
176 #define CAPITAL_MASK 0x20
177 /* Translate the scancode in ASCII */
178 static int usb_kbd_translate(struct usb_kbd_pdata *data, unsigned char scancode,
179 unsigned char modifier, int pressed)
185 data->repeat_delay = 0;
190 data->repeat_delay++;
191 if (data->repeat_delay < REPEAT_DELAY)
194 data->repeat_delay = REPEAT_DELAY;
197 /* Alphanumeric values */
198 if ((scancode > 3) && (scancode <= 0x1d)) {
199 keycode = scancode - 4 + 'a';
201 if (data->flags & USB_KBD_CAPSLOCK)
202 keycode &= ~CAPITAL_MASK;
204 if (modifier & (LEFT_SHIFT | RIGHT_SHIFT)) {
205 /* Handle CAPSLock + Shift pressed simultaneously */
206 if (keycode & CAPITAL_MASK)
207 keycode &= ~CAPITAL_MASK;
209 keycode |= CAPITAL_MASK;
213 if ((scancode > 0x1d) && (scancode < 0x3a)) {
215 if (modifier & (LEFT_SHIFT | RIGHT_SHIFT))
216 keycode = usb_kbd_numkey_shifted[scancode - 0x1e];
218 keycode = usb_kbd_numkey[scancode - 0x1e];
221 if (data->flags & USB_KBD_CTRL)
222 keycode = scancode - 0x3;
225 if (scancode == NUM_LOCK) {
226 data->flags ^= USB_KBD_NUMLOCK;
230 if (scancode == CAPS_LOCK) {
231 data->flags ^= USB_KBD_CAPSLOCK;
234 if (scancode == SCROLL_LOCK) {
235 data->flags ^= USB_KBD_SCROLLLOCK;
240 /* Report keycode if any */
242 USB_KBD_PRINTF("%c", keycode);
243 usb_kbd_put_queue(data, keycode);
249 static uint32_t usb_kbd_service_key(struct usb_device *dev, int i, int up)
252 struct usb_kbd_pdata *data = dev->privptr;
264 if ((old[i] > 3) && (memscan(new + 2, old[i], 6) == new + 8))
265 res |= usb_kbd_translate(data, old[i], data->new[0], up);
270 /* Interrupt service routine */
271 static int usb_kbd_irq_worker(struct usb_device *dev)
273 struct usb_kbd_pdata *data = dev->privptr;
276 /* No combo key pressed */
277 if (data->new[0] == 0x00)
278 data->flags &= ~USB_KBD_CTRL;
279 /* Left or Right Ctrl pressed */
280 else if ((data->new[0] == LEFT_CNTR) || (data->new[0] == RIGHT_CNTR))
281 data->flags |= USB_KBD_CTRL;
283 for (i = 2; i < 8; i++) {
284 res |= usb_kbd_service_key(dev, i, 0);
285 res |= usb_kbd_service_key(dev, i, 1);
288 /* Key is still pressed */
289 if ((data->new[2] > 3) && (data->old[2] == data->new[2]))
290 res |= usb_kbd_translate(data, data->new[2], data->new[0], 2);
295 memcpy(data->old, data->new, 8);
300 /* Keyboard interrupt handler */
301 static int usb_kbd_irq(struct usb_device *dev)
303 if ((dev->irq_status != 0) || (dev->irq_act_len != 8)) {
304 USB_KBD_PRINTF("USB KBD: Error %lX, len %d\n",
305 dev->irq_status, dev->irq_act_len);
309 return usb_kbd_irq_worker(dev);
312 /* Interrupt polling */
313 static inline void usb_kbd_poll_for_event(struct usb_device *dev)
315 #if defined(CONFIG_SYS_USB_EVENT_POLL)
317 usb_kbd_irq_worker(dev);
318 #elif defined(CONFIG_SYS_USB_EVENT_POLL_VIA_CONTROL_EP)
319 struct usb_interface *iface;
320 struct usb_kbd_pdata *data = dev->privptr;
321 iface = &dev->config.if_desc[0];
322 usb_get_report(dev, iface->desc.bInterfaceNumber,
323 1, 1, data->new, sizeof(data->new));
324 if (memcmp(data->old, data->new, sizeof(data->new)))
325 usb_kbd_irq_worker(dev);
329 /* test if a character is in the queue */
330 static int usb_kbd_testc(void)
332 struct stdio_dev *dev;
333 struct usb_device *usb_kbd_dev;
334 struct usb_kbd_pdata *data;
336 dev = stdio_get_by_name(DEVNAME);
337 usb_kbd_dev = (struct usb_device *)dev->priv;
338 data = usb_kbd_dev->privptr;
340 usb_kbd_poll_for_event(usb_kbd_dev);
342 return !(data->usb_in_pointer == data->usb_out_pointer);
345 /* gets the character from the queue */
346 static int usb_kbd_getc(void)
348 struct stdio_dev *dev;
349 struct usb_device *usb_kbd_dev;
350 struct usb_kbd_pdata *data;
352 dev = stdio_get_by_name(DEVNAME);
353 usb_kbd_dev = (struct usb_device *)dev->priv;
354 data = usb_kbd_dev->privptr;
356 while (data->usb_in_pointer == data->usb_out_pointer)
357 usb_kbd_poll_for_event(usb_kbd_dev);
359 if (data->usb_out_pointer == USB_KBD_BUFFER_LEN - 1)
360 data->usb_out_pointer = 0;
362 data->usb_out_pointer++;
364 return data->usb_kbd_buffer[data->usb_out_pointer];
367 /* probes the USB device dev for keyboard type. */
368 static int usb_kbd_probe(struct usb_device *dev, unsigned int ifnum)
370 struct usb_interface *iface;
371 struct usb_endpoint_descriptor *ep;
372 struct usb_kbd_pdata *data;
375 if (dev->descriptor.bNumConfigurations != 1)
378 iface = &dev->config.if_desc[ifnum];
380 if (iface->desc.bInterfaceClass != 3)
383 if (iface->desc.bInterfaceSubClass != 1)
386 if (iface->desc.bInterfaceProtocol != 1)
389 if (iface->desc.bNumEndpoints != 1)
392 ep = &iface->ep_desc[0];
394 /* Check if endpoint 1 is interrupt endpoint */
395 if (!(ep->bEndpointAddress & 0x80))
398 if ((ep->bmAttributes & 3) != 3)
401 USB_KBD_PRINTF("USB KBD: found set protocol...\n");
403 data = malloc(sizeof(struct usb_kbd_pdata));
405 printf("USB KBD: Error allocating private data\n");
409 /* Clear private data */
410 memset(data, 0, sizeof(struct usb_kbd_pdata));
412 /* Insert private data into USB device structure */
415 /* Set IRQ handler */
416 dev->irq_handle = usb_kbd_irq;
418 pipe = usb_rcvintpipe(dev, ep->bEndpointAddress);
419 maxp = usb_maxpacket(dev, pipe);
421 /* We found a USB Keyboard, install it. */
422 usb_set_protocol(dev, iface->desc.bInterfaceNumber, 0);
424 USB_KBD_PRINTF("USB KBD: found set idle...\n");
425 usb_set_idle(dev, iface->desc.bInterfaceNumber, REPEAT_RATE, 0);
427 USB_KBD_PRINTF("USB KBD: enable interrupt pipe...\n");
428 usb_submit_int_msg(dev, pipe, data->new, maxp > 8 ? 8 : maxp,
435 /* Search for keyboard and register it if found. */
436 int drv_usb_kbd_init(void)
438 struct stdio_dev usb_kbd_dev, *old_dev;
439 struct usb_device *dev;
440 char *stdinname = getenv("stdin");
443 /* Scan all USB Devices */
444 for (i = 0; i < USB_MAX_DEVICE; i++) {
445 /* Get USB device. */
446 dev = usb_get_dev_index(i);
450 if (dev->devnum == -1)
453 /* Try probing the keyboard */
454 if (usb_kbd_probe(dev, 0) != 1)
457 /* We found a keyboard, check if it is already registered. */
458 USB_KBD_PRINTF("USB KBD: found set up device.\n");
459 old_dev = stdio_get_by_name(DEVNAME);
461 /* Already registered, just return ok. */
462 USB_KBD_PRINTF("USB KBD: is already registered.\n");
466 /* Register the keyboard */
467 USB_KBD_PRINTF("USB KBD: register.\n");
468 memset(&usb_kbd_dev, 0, sizeof(struct stdio_dev));
469 strcpy(usb_kbd_dev.name, DEVNAME);
470 usb_kbd_dev.flags = DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
471 usb_kbd_dev.putc = NULL;
472 usb_kbd_dev.puts = NULL;
473 usb_kbd_dev.getc = usb_kbd_getc;
474 usb_kbd_dev.tstc = usb_kbd_testc;
475 usb_kbd_dev.priv = (void *)dev;
476 error = stdio_register(&usb_kbd_dev);
480 /* Check if this is the standard input device. */
481 if (strcmp(stdinname, DEVNAME))
484 /* Reassign the console */
485 if (overwrite_console())
488 error = console_assign(stdin, DEVNAME);
495 /* No USB Keyboard found */
499 /* Deregister the keyboard. */
500 int usb_kbd_deregister(void)
502 #ifdef CONFIG_SYS_STDIO_DEREGISTER
503 return stdio_deregister(DEVNAME);
510 struct usb_hid_descriptor {
511 unsigned char bLength;
512 unsigned char bDescriptorType; /* 0x21 for HID */
513 unsigned short bcdHID; /* release number */
514 unsigned char bCountryCode;
515 unsigned char bNumDescriptors;
516 unsigned char bReportDescriptorType;
517 unsigned short wDescriptorLength;
521 * We parse each description item into this structure. Short items data
522 * values are expanded to 32-bit signed int, long items contain a pointer
523 * into the data area.
527 unsigned char format;
538 unsigned char *longdata;
543 * HID report item format
546 #define HID_ITEM_FORMAT_SHORT 0
547 #define HID_ITEM_FORMAT_LONG 1
550 * Special tag indicating long items
553 #define HID_ITEM_TAG_LONG 15
556 static struct usb_hid_descriptor usb_kbd_hid_desc;
558 void usb_kbd_display_hid(struct usb_hid_descriptor *hid)
560 printf("USB_HID_DESC:\n");
561 printf(" bLenght 0x%x\n", hid->bLength);
562 printf(" bcdHID 0x%x\n", hid->bcdHID);
563 printf(" bCountryCode %d\n", hid->bCountryCode);
564 printf(" bNumDescriptors 0x%x\n", hid->bNumDescriptors);
565 printf(" bReportDescriptorType 0x%x\n", hid->bReportDescriptorType);
566 printf(" wDescriptorLength 0x%x\n", hid->wDescriptorLength);
571 * Fetch a report description item from the data stream. We support long
572 * items, though they are not used yet.
575 static int fetch_item(unsigned char *start, unsigned char *end,
576 struct hid_item *item)
578 if ((end - start) > 0) {
579 unsigned char b = *start++;
580 item->type = (b >> 2) & 3;
581 item->tag = (b >> 4) & 15;
582 if (item->tag == HID_ITEM_TAG_LONG) {
583 item->format = HID_ITEM_FORMAT_LONG;
584 if ((end - start) >= 2) {
585 item->size = *start++;
586 item->tag = *start++;
587 if ((end - start) >= item->size) {
588 item->data.longdata = start;
594 item->format = HID_ITEM_FORMAT_SHORT;
596 switch (item->size) {
600 if ((end - start) >= 1) {
601 item->data.u8 = *start++;
606 if ((end - start) >= 2) {
607 item->data.u16 = le16_to_cpu(
608 (unsigned short *)start);
614 if ((end - start) >= 4) {
615 item->data.u32 = le32_to_cpu(
616 (unsigned long *)start);
627 * HID report descriptor item type (prefix bit 2, 3)
630 #define HID_ITEM_TYPE_MAIN 0
631 #define HID_ITEM_TYPE_GLOBAL 1
632 #define HID_ITEM_TYPE_LOCAL 2
633 #define HID_ITEM_TYPE_RESERVED 3
635 * HID report descriptor main item tags
638 #define HID_MAIN_ITEM_TAG_INPUT 8
639 #define HID_MAIN_ITEM_TAG_OUTPUT 9
640 #define HID_MAIN_ITEM_TAG_FEATURE 11
641 #define HID_MAIN_ITEM_TAG_BEGIN_COLLECTION 10
642 #define HID_MAIN_ITEM_TAG_END_COLLECTION 12
644 * HID report descriptor main item contents
647 #define HID_MAIN_ITEM_CONSTANT 0x001
648 #define HID_MAIN_ITEM_VARIABLE 0x002
649 #define HID_MAIN_ITEM_RELATIVE 0x004
650 #define HID_MAIN_ITEM_WRAP 0x008
651 #define HID_MAIN_ITEM_NONLINEAR 0x010
652 #define HID_MAIN_ITEM_NO_PREFERRED 0x020
653 #define HID_MAIN_ITEM_NULL_STATE 0x040
654 #define HID_MAIN_ITEM_VOLATILE 0x080
655 #define HID_MAIN_ITEM_BUFFERED_BYTE 0x100
658 * HID report descriptor collection item types
661 #define HID_COLLECTION_PHYSICAL 0
662 #define HID_COLLECTION_APPLICATION 1
663 #define HID_COLLECTION_LOGICAL 2
665 * HID report descriptor global item tags
668 #define HID_GLOBAL_ITEM_TAG_USAGE_PAGE 0
669 #define HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM 1
670 #define HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM 2
671 #define HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM 3
672 #define HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM 4
673 #define HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT 5
674 #define HID_GLOBAL_ITEM_TAG_UNIT 6
675 #define HID_GLOBAL_ITEM_TAG_REPORT_SIZE 7
676 #define HID_GLOBAL_ITEM_TAG_REPORT_ID 8
677 #define HID_GLOBAL_ITEM_TAG_REPORT_COUNT 9
678 #define HID_GLOBAL_ITEM_TAG_PUSH 10
679 #define HID_GLOBAL_ITEM_TAG_POP 11
682 * HID report descriptor local item tags
685 #define HID_LOCAL_ITEM_TAG_USAGE 0
686 #define HID_LOCAL_ITEM_TAG_USAGE_MINIMUM 1
687 #define HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM 2
688 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_INDEX 3
689 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MINIMUM 4
690 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MAXIMUM 5
691 #define HID_LOCAL_ITEM_TAG_STRING_INDEX 7
692 #define HID_LOCAL_ITEM_TAG_STRING_MINIMUM 8
693 #define HID_LOCAL_ITEM_TAG_STRING_MAXIMUM 9
694 #define HID_LOCAL_ITEM_TAG_DELIMITER 10
697 static void usb_kbd_show_item(struct hid_item *item)
699 switch (item->type) {
700 case HID_ITEM_TYPE_MAIN:
702 case HID_MAIN_ITEM_TAG_INPUT:
703 printf("Main Input");
705 case HID_MAIN_ITEM_TAG_OUTPUT:
706 printf("Main Output");
708 case HID_MAIN_ITEM_TAG_FEATURE:
709 printf("Main Feature");
711 case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
712 printf("Main Begin Collection");
714 case HID_MAIN_ITEM_TAG_END_COLLECTION:
715 printf("Main End Collection");
718 printf("Main reserved %d", item->tag);
722 case HID_ITEM_TYPE_GLOBAL:
724 case HID_GLOBAL_ITEM_TAG_USAGE_PAGE:
725 printf("- Global Usage Page");
727 case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM:
728 printf("- Global Logical Minimum");
730 case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM:
731 printf("- Global Logical Maximum");
733 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM:
734 printf("- Global physical Minimum");
736 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM:
737 printf("- Global physical Maximum");
739 case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT:
740 printf("- Global Unit Exponent");
742 case HID_GLOBAL_ITEM_TAG_UNIT:
743 printf("- Global Unit");
745 case HID_GLOBAL_ITEM_TAG_REPORT_SIZE:
746 printf("- Global Report Size");
748 case HID_GLOBAL_ITEM_TAG_REPORT_ID:
749 printf("- Global Report ID");
751 case HID_GLOBAL_ITEM_TAG_REPORT_COUNT:
752 printf("- Global Report Count");
754 case HID_GLOBAL_ITEM_TAG_PUSH:
755 printf("- Global Push");
757 case HID_GLOBAL_ITEM_TAG_POP:
758 printf("- Global Pop");
761 printf("- Global reserved %d", item->tag);
765 case HID_ITEM_TYPE_LOCAL:
767 case HID_LOCAL_ITEM_TAG_USAGE:
768 printf("-- Local Usage");
770 case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
771 printf("-- Local Usage Minimum");
773 case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
774 printf("-- Local Usage Maximum");
776 case HID_LOCAL_ITEM_TAG_DESIGNATOR_INDEX:
777 printf("-- Local Designator Index");
779 case HID_LOCAL_ITEM_TAG_DESIGNATOR_MINIMUM:
780 printf("-- Local Designator Minimum");
782 case HID_LOCAL_ITEM_TAG_DESIGNATOR_MAXIMUM:
783 printf("-- Local Designator Maximum");
785 case HID_LOCAL_ITEM_TAG_STRING_INDEX:
786 printf("-- Local String Index");
788 case HID_LOCAL_ITEM_TAG_STRING_MINIMUM:
789 printf("-- Local String Minimum");
791 case HID_LOCAL_ITEM_TAG_STRING_MAXIMUM:
792 printf("-- Local String Maximum");
794 case HID_LOCAL_ITEM_TAG_DELIMITER:
795 printf("-- Local Delimiter");
798 printf("-- Local reserved %d", item->tag);
803 printf("--- reserved %d", item->type);
806 switch (item->size) {
808 printf(" %d", item->data.u8);
811 printf(" %d", item->data.u16);
814 printf(" %ld", item->data.u32);
821 static int usb_kbd_get_hid_desc(struct usb_device *dev)
823 unsigned char buffer[256];
824 struct usb_descriptor_header *head;
825 struct usb_config_descriptor *config;
827 unsigned char *start, *end;
828 struct hid_item item;
830 if (usb_get_configuration_no(dev, &buffer[0], 0) == -1)
832 head = (struct usb_descriptor_header *)&buffer[0];
833 if (head->bDescriptorType != USB_DT_CONFIG) {
834 printf(" ERROR: NOT USB_CONFIG_DESC %x\n",
835 head->bDescriptorType);
838 index = head->bLength;
839 config = (struct usb_config_descriptor *)&buffer[0];
840 len = le16_to_cpu(config->wTotalLength);
842 * Ok the first entry must be a configuration entry,
843 * now process the others
845 head = (struct usb_descriptor_header *)&buffer[index];
846 while (index+1 < len) {
847 if (head->bDescriptorType == USB_DT_HID) {
848 printf("HID desc found\n");
849 memcpy(&usb_kbd_hid_desc, &buffer[index],
851 le16_to_cpus(&usb_kbd_hid_desc.bcdHID);
852 le16_to_cpus(&usb_kbd_hid_desc.wDescriptorLength);
853 usb_kbd_display_hid(&usb_kbd_hid_desc);
857 index += head->bLength;
858 head = (struct usb_descriptor_header *)&buffer[index];
862 len = usb_kbd_hid_desc.wDescriptorLength;
863 index = usb_get_class_descriptor(dev, 0, USB_DT_REPORT, 0, &buffer[0],
866 printf("reading report descriptor failed\n");
869 printf(" report descriptor (size %u, read %d)\n", len, index);
874 index = fetch_item(start, end, &item);
878 usb_kbd_show_item(&item);
882 } while (index >= 0);