]> git.sur5r.net Git - u-boot/blobdiff - drivers/usb/musb/musb_core.c
dfu: allow backend to specify a maximum buffer size
[u-boot] / drivers / usb / musb / musb_core.c
index 22f3dba0cfc4c1f69e58f46cb4a9398c27febf76..786909fb60ceab9bf54336012e566d821f7a8783 100644 (file)
@@ -4,20 +4,7 @@
  *
  * Copyright (c) 2008 Texas Instruments
  *
- * 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+
  *
  * Author: Thomas Abraham t-abraham@ti.com, Texas Instruments
  */
@@ -34,6 +21,7 @@ void musb_start(void)
 {
 #if defined(CONFIG_MUSB_HCD)
        u8 devctl;
+       u8 busctl;
 #endif
 
        /* disable all interrupts */
@@ -45,11 +33,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
@@ -59,7 +63,7 @@ void musb_start(void)
  * epinfo      - Pointer to EP configuration table
  * cnt         - Number of entries in the EP conf table.
  */
-void musb_configure_ep(struct musb_epinfo *epinfo, u8 cnt)
+void musb_configure_ep(const struct musb_epinfo *epinfo, u8 cnt)
 {
        u16 csr;
        u16 fifoaddr = 64; /* First 64 bytes of FIFO reserved for EP0 */
@@ -74,8 +78,7 @@ 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)
@@ -88,8 +91,7 @@ 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)
@@ -113,6 +115,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;
@@ -125,6 +128,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
  *
@@ -132,6 +140,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;
@@ -143,3 +152,4 @@ void read_fifo(u8 ep, u32 length, void *fifo_data)
        while (length--)
                *data++ = readb(&musbr->fifox[ep]);
 }
+#endif /* CONFIG_USB_AM35X */