thor: fix invalid larger device descriptor than requested
[profile/mobile/platform/kernel/u-boot-tm1.git] / property / usb / drv_cdc.c
index 0b726a7..8596fa2 100644 (file)
@@ -17,6 +17,7 @@
 #include <asm/arch/virtual_com.h>
 #include <asm/arch/packet.h>
 #include <asm/arch/usb20_reg_v3.h>
+#include <linux/usb/ch9.h>
 
 #define USB_DEBUG
 
@@ -44,6 +45,12 @@ int length;
 int check_usb_reconnected = 0;
 
 extern void usb_power_on(void);
+extern void usb_power_off(void);
+extern unsigned char *thor_get_device_desc(unsigned int speed);
+extern unsigned char *thor_get_config_desc(unsigned int speed);
+extern unsigned char *thor_get_string_desc(unsigned char index);
+extern unsigned char *thor_get_qualifer_desc(void);
+extern unsigned char *thor_get_other_speed_config_desc(void);
 
 extern void Dcache_InvalRegion(unsigned int addr, unsigned int length);
 extern void Dcache_CleanRegion(unsigned int addr, unsigned int length);
@@ -253,7 +260,13 @@ LOCAL void usb_get_descriptor (USB_REQUEST_1_U *request1, USB_REQUEST_2_U *reque
                case USB_DEVICE_DESCRIPTOR_TYPE:
                        send_data = (uint8 *) thor_get_device_desc(enum_speed);
 
-                       EPI0_config (0x12, 0x1, TRUE, (uint32 *) send_data);
+                       /*
+                        * only send less or equal than requested length.
+                        * no need to care about larger reqeust than possible
+                        * descriptor length because of zero-length packet
+                        * generated by usb controller
+                        */
+                       EPI0_config (min(USB_DT_DEVICE_SIZE, length), 0x1, TRUE, (uint32 *) send_data);
                        break;
 
                case USB_CONFIGURATION_DESCRIPTOR_TYPE:
@@ -384,15 +397,10 @@ LOCAL void usb_reset_pipe(uint8 epno)
 /*****************************************************************************/
 PUBLIC void usb_set_feature (void)
 {
-       volatile USB_DCFG_U *dcfg_ptr = (volatile USB_DCFG_U *) USB_DCFG;
        volatile USB_DCTL_U *dctl_ptr = (volatile USB_DCTL_U *) USB_DCTL;
-       USB_REQUEST_1_U   *request1;
        USB_REQUEST_2_U   *request2;
-       USB_REQUEST_1_U   request1_u;
        USB_REQUEST_2_U   request2_u;
-       request1_u.dwValue = s_setup_packet[0];
        request2_u.dwValue = s_setup_packet[1];
-       request1= &request1_u;
        request2= &request2_u;
 
        EPI0_config (0x0, 0x1, FALSE, NULL);
@@ -786,8 +794,6 @@ static  void usb_handler (void)
 {
        volatile USB_INTSTS_U *usb_int_ptr = (USB_INTSTS_U *) USB_GINTSTS;
        volatile USB_INTSTS_U  usb_int;
-       uint32 i=0;
-         char string[64] ={0,};
        usb_int.dwValue = usb_int_ptr->dwValue;
 
        // in endpoint interrupt
@@ -834,7 +840,6 @@ static int32 USB_ReadEx_Internal(uint8 *pBuf,uint32 len)
 {
     volatile USB_DOEPINT_U *doepint_ptr = (USB_DOEPINT_U *) USB_DOEPINT (EP_OUT);
     volatile USB_DOEPTSIZ_U *doeptsiz_ptr = (USB_DOEPTSIZ_U *) USB_DOEPTSIZ (EP_OUT);
-    int i;
 
     if(recv_length == 0)
     {
@@ -1017,11 +1022,47 @@ LOCAL void usb_core_init (void)
 //  Note:
 /*****************************************************************************/
 
+__align(64) unsigned char sprd_thor_setup_buf[512] = {0,};
+
+static int s_usb_connected = 0;
+
+extern int thor_handle(void);
+
+void sprd_usb_thor_start(void)
+{
+    g_usb_status = USB_STARTED;
+
+       do {
+               if (s_usb_connected == 0) {
+                       USB_ReadEx_Internal(sprd_thor_setup_buf, sizeof(sprd_thor_setup_buf));
+
+                       if (g_usb_status == USB_DETACHED_AFTER_USB_MODE_START)
+                               return;
+
+                       if (!strncmp((char *)sprd_thor_setup_buf, "THOR", strlen("THOR")))
+                       {
+                               usb_debug("- thor is connected!\n");
+                               USB_WriteEx((uint8 *)"ROHT", strlen("ROHT"));
+                               usb_debug("thor Setup Complete\n");
+                               s_usb_connected = 1;
+                               break;
+                       } else{
+                               usb_debug("thor_seup error - Not receiving THOR\n");
+                               s_usb_connected = 0;
+                       }
+               }
+       } while(1);
+
+       thor_handle();
+
+       usb_debug("%s : exit \n", __func__);
+       return;
+}
+
 /* Enter point */
 void thor_USB_Init(void)
 {
        usb_debug("%s : enter\n", __func__);
-       unsigned int len = 0;
 
        usb_power_on();
        usb_core_init();
@@ -1045,10 +1086,6 @@ void USB_DeInit (void)
        usb_power_off();
 }
 
-__align(64) unsigned char sprd_thor_setup_buf[512] = {0,};
-
-static int s_usb_connected = 0;
-
 /************************************************
  *
  * Register call back function for v3_protocol.
@@ -1064,39 +1101,6 @@ void sprd_usb_cb_register(void)
 }
 #endif
 
-extern int thor_handle(void);
-
-void sprd_usb_thor_start()
-{
-    g_usb_status = USB_STARTED;
-
-       do {
-               if (s_usb_connected == 0) {
-                       USB_ReadEx_Internal(sprd_thor_setup_buf, sizeof(sprd_thor_setup_buf));
-
-                       if (g_usb_status == USB_DETACHED_AFTER_USB_MODE_START)
-                               return -1;
-
-                       if (!strncmp(sprd_thor_setup_buf, "THOR", strlen("THOR")))
-                       {
-                               usb_debug("- thor is connected!\n");
-                               USB_WriteEx("ROHT", strlen("ROHT"));
-                               usb_debug("thor Setup Complete\n");
-                               s_usb_connected = 1;
-                               break;
-                       } else{
-                               usb_debug("thor_seup error - Not receiving THOR\n");
-                               s_usb_connected = 0;
-                       }
-               }
-       } while(1);
-
-       thor_handle();
-
-       usb_debug("%s : exit \n", __func__);
-       return 0;
-}
-
 void disconnect_usb(void)
 {
        s_usb_connected = 0;