carl9170 firmware: always reset usb endpoints
authorChristian Lamparter <chunkeey@googlemail.com>
Fri, 22 Mar 2013 21:21:34 +0000 (22:21 +0100)
committerChristian Lamparter <chunkeey@googlemail.com>
Fri, 22 Mar 2013 23:13:24 +0000 (00:13 +0100)
It isn't clear what the firmware is supposed to do
when it is initializing the usb phy. The spec says
something about clearing the STALLED/HALTED flags
however the original firmware doesn't do that?!

Signed-off-by: Christian Lamparter <chunkeey@googlemail.com>
carlfw/include/usb.h
carlfw/usb/main.c
carlfw/usb/usb.c

index fb258bf16bd37be843d3542f26fa771c921e76b4..1066fe023d008085ecb8c37496fe61e42c6c79eb 100644 (file)
@@ -184,6 +184,7 @@ void __noreturn jump_to_bootcode(void);
 void send_cmd_to_host(const uint8_t len, const uint8_t type,
                      const uint8_t ext, const uint8_t *body);
 
+void usb_reset_eps(void);
 void usb_init(void);
 void usb_ep0rx(void);
 void usb_ep0tx(void);
index 890970c24ab237a7cd596eb8eb1903ecc04cc7e1..1fb119e996f8933e70b16b4d24c77337203aa834 100644 (file)
@@ -377,6 +377,7 @@ static void usb_handler(uint8_t usb_interrupt_level1)
 
                if (usb_interrupt_level2 & AR9170_USB_INTR_SRC7_USB_RESET) {
                        usb_reset_ack();
+                       usb_reset_eps();
                        reboot();
                }
 
index 0c66b8275b636e91d0a0c94e4070c32777ed6e68..d7bc4329ba8bad27bbac17bc2202d2c999abc49e 100644 (file)
@@ -166,8 +166,7 @@ static struct ar9170_usb_config usb_config_fullspeed = {
        },
 };
 
-#ifdef CONFIG_CARL9170FW_USB_MODESWITCH
-static void usb_reset_eps(void)
+void usb_reset_eps(void)
 {
        unsigned int i;
 
@@ -188,8 +187,6 @@ static void usb_reset_eps(void)
                usb_clear_output_ep_stall(i);
        }
 }
-#endif /* CONFIG_CARL9170FW_USB_MODESWITCH */
-
 
 static void usb_pta_init(void)
 {
@@ -503,7 +500,7 @@ static int usb_get_configuration(const struct usb_ctrlrequest *ctrl)
        if (USB_CHECK_REQTYPE(ctrl, USB_RECIP_DEVICE, USB_DIR_IN))
                return -1;
 
-       return usb_ep0tx_data(&fw.usb.config, 1);
+       return usb_ep0tx_data(&fw.usb.config, fw.usb.config);
 }
 
 static int usb_set_configuration(const struct usb_ctrlrequest *ctrl)
@@ -519,10 +516,10 @@ static int usb_set_configuration(const struct usb_ctrlrequest *ctrl)
                /* Disable Device */
                andb(AR9170_USB_REG_DEVICE_ADDRESS,
                      (uint8_t) ~(AR9170_USB_DEVICE_ADDRESS_CONFIGURE));
-#ifdef CONFIG_CARL9170FW_USB_MODESWITCH
        case 1:
                fw.usb.config = config;
 
+#ifdef CONFIG_CARL9170FW_USB_MODESWITCH
                if (usb_detect_highspeed()) {
                        /* High Speed Configuration */
                        usb_init_highspeed_fifo_cfg();
@@ -530,25 +527,21 @@ static int usb_set_configuration(const struct usb_ctrlrequest *ctrl)
                        /* Full Speed Configuration */
                        usb_init_fullspeed_fifo_cfg();
                }
+               /* usb_pta_init() ? */
                break;
+#endif /* CONFIG_CARL9170FW_USB_MODESWITCH */
 
-       default:
-               return -1;
-       }
-       /* usb_pta_init() ? */
+               usb_reset_eps();
+               orb(AR9170_USB_REG_DEVICE_ADDRESS,
+                   (AR9170_USB_DEVICE_ADDRESS_CONFIGURE));
 
-       usb_reset_eps();
-       orb(AR9170_USB_REG_DEVICE_ADDRESS,
-           (AR9170_USB_DEVICE_ADDRESS_CONFIGURE));
+               usb_enable_global_int();
+               usb_trigger_out();
+               return 1;
 
-       usb_enable_global_int();
-       usb_trigger_out();
-       return 1;
-#else
        default:
                return -1;
        }
-#endif /* CONFIG_CARL9170FW_USB_MODESWITCH */
 }
 
 static int usb_set_address(const struct usb_ctrlrequest *ctrl)