2 * Mentor USB OTG Core functionality common for both Host and Device
5 * Copyright (c) 2008 Texas Instruments
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * Author: Thomas Abraham t-abraham@ti.com, Texas Instruments
27 #include "musb_core.h"
28 struct musb_regs *musbr;
31 * program the mentor core to start (enable interrupts, dma, etc.)
35 #if defined(CONFIG_MUSB_HCD)
39 /* disable all interrupts */
40 writew(0, &musbr->intrtxe);
41 writew(0, &musbr->intrrxe);
42 writeb(0, &musbr->intrusbe);
43 writeb(0, &musbr->testmode);
45 /* put into basic highspeed mode and start session */
46 writeb(MUSB_POWER_HSENAB, &musbr->power);
47 #if defined(CONFIG_MUSB_HCD)
48 devctl = readb(&musbr->devctl);
49 writeb(devctl | MUSB_DEVCTL_SESSION, &musbr->devctl);
54 * This function configures the endpoint configuration. The musb hcd or musb
55 * device implementation can use this function to configure the endpoints
56 * and set the FIFO sizes. Note: The summation of FIFO sizes of all endpoints
57 * should not be more than the available FIFO size.
59 * epinfo - Pointer to EP configuration table
60 * cnt - Number of entries in the EP conf table.
62 void musb_configure_ep(struct musb_epinfo *epinfo, u8 cnt)
65 u16 fifoaddr = 64; /* First 64 bytes of FIFO reserved for EP0 */
70 /* prepare fifosize to write to register */
71 fifosize = epinfo->epsize >> 3;
72 idx = ffs(fifosize) - 1;
74 writeb(epinfo->epnum, &musbr->index);
76 /* Configure fifo size and fifo base address */
77 writeb(idx, &musbr->txfifosz);
78 writew(fifoaddr >> 3, &musbr->txfifoadd);
80 csr = readw(&musbr->txcsr);
81 #if defined(CONFIG_MUSB_HCD)
82 /* clear the data toggle bit */
83 writew(csr | MUSB_TXCSR_CLRDATATOG, &musbr->txcsr);
85 /* Flush fifo if required */
86 if (csr & MUSB_TXCSR_TXPKTRDY)
87 writew(csr | MUSB_TXCSR_FLUSHFIFO,
90 /* Configure fifo size and fifo base address */
91 writeb(idx, &musbr->rxfifosz);
92 writew(fifoaddr >> 3, &musbr->rxfifoadd);
94 csr = readw(&musbr->rxcsr);
95 #if defined(CONFIG_MUSB_HCD)
96 /* clear the data toggle bit */
97 writew(csr | MUSB_RXCSR_CLRDATATOG, &musbr->rxcsr);
99 /* Flush fifo if required */
100 if (csr & MUSB_RXCSR_RXPKTRDY)
101 writew(csr | MUSB_RXCSR_FLUSHFIFO,
104 fifoaddr += epinfo->epsize;
110 * This function writes data to endpoint fifo
112 * ep - endpoint number
113 * length - number of bytes to write to FIFO
114 * fifo_data - Pointer to data buffer that contains the data to write
116 void write_fifo(u8 ep, u32 length, void *fifo_data)
118 u8 *data = (u8 *)fifo_data;
120 /* select the endpoint index */
121 writeb(ep, &musbr->index);
123 /* write the data to the fifo */
125 writeb(*data++, &musbr->fifox[ep]);
129 * This function reads data from endpoint fifo
131 * ep - endpoint number
132 * length - number of bytes to read from FIFO
133 * fifo_data - pointer to data buffer into which data is read
135 void read_fifo(u8 ep, u32 length, void *fifo_data)
137 u8 *data = (u8 *)fifo_data;
139 /* select the endpoint index */
140 writeb(ep, &musbr->index);
142 /* read the data to the fifo */
144 *data++ = readb(&musbr->fifox[ep]);