rename CFG_ macros to CONFIG_SYS
[platform/kernel/u-boot.git] / common / usb_kbd.c
index 11e861d..cf14560 100644 (file)
@@ -26,8 +26,7 @@
  */
 #include <common.h>
 #include <devices.h>
-
-#ifdef CONFIG_USB_KEYBOARD
+#include <asm/byteorder.h>
 
 #include <usb.h>
 
@@ -37,7 +36,7 @@
  * are switched to the serial port, else the settings in the
  * environment are used
  */
-#ifdef CFG_CONSOLE_OVERWRITE_ROUTINE
+#ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE
 extern int overwrite_console (void);
 #else
 int overwrite_console (void)
@@ -121,7 +120,7 @@ static void usb_kbd_put_queue(char data)
 /* test if a character is in the queue */
 static int usb_kbd_testc(void)
 {
-#ifdef CFG_USB_EVENT_POLL
+#ifdef CONFIG_SYS_USB_EVENT_POLL
        usb_event_poll();
 #endif
        if(usb_in_pointer==usb_out_pointer)
@@ -134,7 +133,7 @@ static int usb_kbd_getc(void)
 {
        char c;
        while(usb_in_pointer==usb_out_pointer) {
-#ifdef CFG_USB_EVENT_POLL
+#ifdef CONFIG_SYS_USB_EVENT_POLL
                usb_event_poll();
 #endif
        }
@@ -153,7 +152,7 @@ static int usb_kbd_probe(struct usb_device *dev, unsigned int ifnum);
 /* search for keyboard and register it if found */
 int drv_usb_kbd_init(void)
 {
-       int error,i,index;
+       int error,i;
        device_t usb_kbd_dev,*old_dev;
        struct usb_device *dev;
        char *stdinname  = getenv ("stdin");
@@ -163,17 +162,17 @@ int drv_usb_kbd_init(void)
        /* scan all USB Devices */
        for(i=0;i<USB_MAX_DEVICE;i++) {
                dev=usb_get_dev_index(i); /* get device */
+               if(dev == NULL)
+                       return -1;
                if(dev->devnum!=-1) {
                        if(usb_kbd_probe(dev,0)==1) { /* Ok, we found a keyboard */
                                /* check, if it is already registered */
                                USB_KBD_PRINTF("USB KBD found set up device.\n");
-                               for (index=1; index<=ListNumItems(devlist); index++) {
-                                       old_dev = ListGetPtrToItem(devlist, index);
-                                       if(strcmp(old_dev->name,DEVNAME)==0) {
-                                               /* ok, already registered, just return ok */
-                                               USB_KBD_PRINTF("USB KBD is already registered.\n");
-                                               return 1;
-                                       }
+                               old_dev = device_get_by_name(DEVNAME);
+                               if(old_dev) {
+                                       /* ok, already registered, just return ok */
+                                       USB_KBD_PRINTF("USB KBD is already registered.\n");
+                                       return 1;
                                }
                                /* register the keyboard */
                                USB_KBD_PRINTF("USB KBD register.\n");
@@ -475,14 +474,14 @@ static int fetch_item(unsigned char *start,unsigned char *end, struct hid_item *
                                        break;
                                case 2:
                                        if ((end - start) >= 2) {
-                                               item->data.u16 = swap_16((unsigned short *)start);
+                                               item->data.u16 = le16_to_cpu((unsigned short *)start);
                                                start+=2;
                                                return item->size;
                                        }
                                case 3:
                                        item->size++;
                                        if ((end - start) >= 4) {
-                                               item->data.u32 = swap_32((unsigned long *)start);
+                                               item->data.u32 = le32_to_cpu((unsigned long *)start);
                                                start+=4;
                                                return item->size;
                                        }
@@ -705,15 +704,15 @@ static int usb_kbd_get_hid_desc(struct usb_device *dev)
        }
        index=head->bLength;
        config=(struct usb_config_descriptor *)&buffer[0];
-       len=swap_16(config->wTotalLength);
+       len=le16_to_cpu(config->wTotalLength);
        /* Ok the first entry must be a configuration entry, now process the others */
        head=(struct usb_descriptor_header *)&buffer[index];
        while(index+1 < len) {
                if(head->bDescriptorType==USB_DT_HID) {
                        printf("HID desc found\n");
                        memcpy(&usb_kbd_hid_desc,&buffer[index],buffer[index]);
-                       usb_kbd_hid_desc.bcdHID=swap_16(usb_kbd_hid_desc.bcdHID);
-                       usb_kbd_hid_desc.wDescriptorLength=swap_16(usb_kbd_hid_desc.wDescriptorLength);
+                       le16_to_cpus(&usb_kbd_hid_desc.bcdHID);
+                       le16_to_cpus(&usb_kbd_hid_desc.wDescriptorLength);
                        usb_kbd_display_hid(&usb_kbd_hid_desc);
                        len=0;
                        break;
@@ -729,8 +728,8 @@ static int usb_kbd_get_hid_desc(struct usb_device *dev)
                return -1;
        }
        printf(" report descriptor (size %u, read %d)\n", len, index);
-       start=&buffer[0];
-       end=&buffer[len];
+       start = &buffer[0];
+       end = &buffer[len];
        i=0;
        do {
                index=fetch_item(start,end,&item);
@@ -745,7 +744,4 @@ static int usb_kbd_get_hid_desc(struct usb_device *dev)
 
 }
 
-
 #endif
-
-#endif /* CONFIG_USB_KEYBOARD */