Merge branch 'master' of /home/wd/git/u-boot/master
[oweals/u-boot.git] / drivers / usb / musb / musb_core.c
index ec57fc811c27f55988a57eb52f56a13303e0ed36..6fe2c39bce800cb6eac58008431f8c3a2fb36f10 100644 (file)
@@ -32,7 +32,10 @@ struct musb_regs *musbr;
  */
 void musb_start(void)
 {
+#if defined(CONFIG_MUSB_HCD)
        u8 devctl;
+       u8 busctl;
+#endif
 
        /* disable all interrupts */
        writew(0, &musbr->intrtxe);
@@ -43,11 +46,27 @@ void musb_start(void)
        /* put into basic highspeed mode and start session */
        writeb(MUSB_POWER_HSENAB, &musbr->power);
 #if defined(CONFIG_MUSB_HCD)
+       /* Program PHY to use EXT VBUS if required */
+       if (musb_cfg.extvbus == 1) {
+               busctl = musb_read_ulpi_buscontrol(musbr);
+               musb_write_ulpi_buscontrol(musbr, busctl | ULPI_USE_EXTVBUS);
+       }
+
        devctl = readb(&musbr->devctl);
        writeb(devctl | MUSB_DEVCTL_SESSION, &musbr->devctl);
 #endif
 }
 
+#ifdef MUSB_NO_DYNAMIC_FIFO
+# define config_fifo(dir, idx, addr)
+#else
+# define config_fifo(dir, idx, addr) \
+       do { \
+               writeb(idx, &musbr->dir##fifosz); \
+               writew(fifoaddr >> 3, &musbr->dir##fifoadd); \
+       } while (0)
+#endif
+
 /*
  * This function configures the endpoint configuration. The musb hcd or musb
  * device implementation can use this function to configure the endpoints
@@ -72,11 +91,11 @@ void musb_configure_ep(struct musb_epinfo *epinfo, u8 cnt)
                writeb(epinfo->epnum, &musbr->index);
                if (epinfo->epdir) {
                        /* Configure fifo size and fifo base address */
-                       writeb(idx, &musbr->txfifosz);
-                       writew(fifoaddr >> 3, &musbr->txfifoadd);
+                       config_fifo(tx, idx, fifoaddr);
+
+                       csr = readw(&musbr->txcsr);
 #if defined(CONFIG_MUSB_HCD)
                        /* clear the data toggle bit */
-                       csr = readw(&musbr->txcsr);
                        writew(csr | MUSB_TXCSR_CLRDATATOG, &musbr->txcsr);
 #endif
                        /* Flush fifo if required */
@@ -85,11 +104,11 @@ void musb_configure_ep(struct musb_epinfo *epinfo, u8 cnt)
                                        &musbr->txcsr);
                } else {
                        /* Configure fifo size and fifo base address */
-                       writeb(idx, &musbr->rxfifosz);
-                       writew(fifoaddr >> 3, &musbr->rxfifoadd);
+                       config_fifo(rx, idx, fifoaddr);
+
+                       csr = readw(&musbr->rxcsr);
 #if defined(CONFIG_MUSB_HCD)
                        /* clear the data toggle bit */
-                       csr = readw(&musbr->rxcsr);
                        writew(csr | MUSB_RXCSR_CLRDATATOG, &musbr->rxcsr);
 #endif
                        /* Flush fifo if required */
@@ -109,6 +128,7 @@ void musb_configure_ep(struct musb_epinfo *epinfo, u8 cnt)
  * length      - number of bytes to write to FIFO
  * fifo_data   - Pointer to data buffer that contains the data to write
  */
+__attribute__((weak))
 void write_fifo(u8 ep, u32 length, void *fifo_data)
 {
        u8  *data = (u8 *)fifo_data;
@@ -121,6 +141,11 @@ void write_fifo(u8 ep, u32 length, void *fifo_data)
                writeb(*data++, &musbr->fifox[ep]);
 }
 
+/*
+ * AM35x supports only 32bit read operations so
+ * use seperate read_fifo() function for it.
+ */
+#ifndef CONFIG_USB_AM35X
 /*
  * This function reads data from endpoint fifo
  *
@@ -128,6 +153,7 @@ void write_fifo(u8 ep, u32 length, void *fifo_data)
  * length       - number of bytes to read from FIFO
  * fifo_data    - pointer to data buffer into which data is read
  */
+__attribute__((weak))
 void read_fifo(u8 ep, u32 length, void *fifo_data)
 {
        u8  *data = (u8 *)fifo_data;
@@ -139,3 +165,4 @@ void read_fifo(u8 ep, u32 length, void *fifo_data)
        while (length--)
                *data++ = readb(&musbr->fifox[ep]);
 }
+#endif /* CONFIG_USB_AM35X */