]> git.sur5r.net Git - u-boot/blobdiff - drivers/usb/musb/musb_udc.c
spl: disk: usb: Add dependencies to sprintf/strto*
[u-boot] / drivers / usb / musb / musb_udc.c
index fc43cf4f09d76db4d6852ee253e7eef04665f357..d643334a2e8717bd4e7cd69a7dd74788e885d160 100644 (file)
  *
  * -------------------------------------------------------------------------
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
-#include <usb/musb_udc.h>
+#include <usbdevice.h>
+#include <usb/udc.h>
 #include "../gadget/ep0.h"
 #include "musb_core.h"
 #if defined(CONFIG_USB_OMAP3)
 #include "omap3.h"
+#elif defined(CONFIG_USB_AM35X)
+#include "am35x.h"
 #elif defined(CONFIG_USB_DAVINCI)
 #include "davinci.h"
 #endif
@@ -95,7 +85,7 @@ do {                                                                  \
 /* static implies these initialized to 0 or NULL */
 static int debug_setup;
 static int debug_level;
-static struct musb_epinfo epinfo[MAX_ENDPOINT * 2];
+static struct musb_epinfo epinfo[MAX_ENDPOINT * 2 + 2];
 static enum ep0_state_enum {
        IDLE = 0,
        TX,
@@ -160,8 +150,6 @@ static void musb_db_regs(void)
 static void musb_peri_softconnect(void)
 {
        u8 power, devctl;
-       u8 intrusb;
-       u16 intrrx, intrtx;
 
        /* Power off MUSB */
        power = readb(&musbr->power);
@@ -169,9 +157,9 @@ static void musb_peri_softconnect(void)
        writeb(power, &musbr->power);
 
        /* Read intr to clear */
-       intrusb = readb(&musbr->intrusb);
-       intrrx = readw(&musbr->intrrx);
-       intrtx = readw(&musbr->intrtx);
+       readb(&musbr->intrusb);
+       readw(&musbr->intrrx);
+       readw(&musbr->intrtx);
 
        udelay(1000 * 1000); /* 1 sec */
 
@@ -640,8 +628,17 @@ static void musb_peri_ep0(void)
 
 static void musb_peri_rx_ep(unsigned int ep)
 {
-       u16 peri_rxcount = readw(&musbr->ep[ep].epN.rxcount);
+       u16 peri_rxcount;
+       u8 peri_rxcsr = readw(&musbr->ep[ep].epN.rxcsr);
+
+       if (!(peri_rxcsr & MUSB_RXCSR_RXPKTRDY)) {
+               if (debug_level > 0)
+                       serial_printf("ERROR : %s %d without MUSB_RXCSR_RXPKTRDY set\n",
+                                     __PRETTY_FUNCTION__, ep);
+               return;
+       }
 
+       peri_rxcount = readw(&musbr->ep[ep].epN.rxcount);
        if (peri_rxcount) {
                struct usb_endpoint_instance *endpoint;
                u32 length;
@@ -885,8 +882,7 @@ void udc_setup_ep(struct usb_device_instance *device, unsigned int id,
                        epinfo[id * 2].epsize = endpoint->rcv_packetSize;
                }
 
-               musb_configure_ep(&epinfo[0],
-                                 sizeof(epinfo) / sizeof(struct musb_epinfo));
+               musb_configure_ep(&epinfo[0], ARRAY_SIZE(epinfo));
        } else {
                if (debug_level > 0)
                        serial_printf("ERROR : %s endpoint request %d "
@@ -948,7 +944,7 @@ int udc_init(void)
        musbr = musb_cfg.regs;
 
        /* Initialize the endpoints */
-       for (ep_loop = 0; ep_loop < MAX_ENDPOINT * 2; ep_loop++) {
+       for (ep_loop = 0; ep_loop <= MAX_ENDPOINT * 2; ep_loop++) {
                epinfo[ep_loop].epnum = (ep_loop / 2) + 1;
                epinfo[ep_loop].epdir = ep_loop % 2; /* OUT, IN */
                epinfo[ep_loop].epsize = 0;