1
2
3
4
5
6
7
8
9
10
11#include <common.h>
12#include <linux/bitops.h>
13
14#include "musb_core.h"
15struct musb_regs *musbr;
16
17
18
19
20void musb_start(void)
21{
22#if defined(CONFIG_USB_MUSB_HCD)
23 u8 devctl;
24 u8 busctl;
25#endif
26
27
28 writew(0, &musbr->intrtxe);
29 writew(0, &musbr->intrrxe);
30 writeb(0, &musbr->intrusbe);
31 writeb(0, &musbr->testmode);
32
33
34 writeb(MUSB_POWER_HSENAB, &musbr->power);
35#if defined(CONFIG_USB_MUSB_HCD)
36
37 if (musb_cfg.extvbus == 1) {
38 busctl = musb_read_ulpi_buscontrol(musbr);
39 musb_write_ulpi_buscontrol(musbr, busctl | ULPI_USE_EXTVBUS);
40 }
41
42 devctl = readb(&musbr->devctl);
43 writeb(devctl | MUSB_DEVCTL_SESSION, &musbr->devctl);
44#endif
45}
46
47#ifdef MUSB_NO_DYNAMIC_FIFO
48# define config_fifo(dir, idx, addr)
49#else
50# define config_fifo(dir, idx, addr) \
51 do { \
52 writeb(idx, &musbr->dir##fifosz); \
53 writew(addr, &musbr->dir##fifoadd); \
54 } while (0)
55#endif
56
57
58
59
60
61
62
63
64
65
66void musb_configure_ep(const struct musb_epinfo *epinfo, u8 cnt)
67{
68 u16 csr;
69 u16 fifoaddr = 64 >> 3;
70 u32 fifosize;
71 u8 idx;
72
73 while (cnt--) {
74
75 fifosize = epinfo->epsize >> 3;
76 idx = fifosize ? ((ffs(fifosize) - 1) & 0xF) : 0;
77
78 writeb(epinfo->epnum, &musbr->index);
79 if (epinfo->epdir) {
80
81 config_fifo(tx, idx, fifoaddr);
82
83 csr = readw(&musbr->txcsr);
84
85 writew(csr | MUSB_TXCSR_CLRDATATOG, &musbr->txcsr);
86
87 if (csr & MUSB_TXCSR_TXPKTRDY)
88 writew(csr | MUSB_TXCSR_FLUSHFIFO,
89 &musbr->txcsr);
90 } else {
91
92 config_fifo(rx, idx, fifoaddr);
93
94 csr = readw(&musbr->rxcsr);
95
96 writew(csr | MUSB_RXCSR_CLRDATATOG, &musbr->rxcsr);
97
98 if (csr & MUSB_RXCSR_RXPKTRDY)
99 writew(csr | MUSB_RXCSR_FLUSHFIFO,
100 &musbr->rxcsr);
101 }
102 fifoaddr += 1 << idx;
103 epinfo++;
104 }
105}
106
107
108
109
110
111
112
113
114__attribute__((weak))
115void write_fifo(u8 ep, u32 length, void *fifo_data)
116{
117 u8 *data = (u8 *)fifo_data;
118
119
120 writeb(ep, &musbr->index);
121
122
123 while (length--)
124 writeb(*data++, &musbr->fifox[ep]);
125}
126
127
128
129
130
131#ifndef CONFIG_USB_AM35X
132
133
134
135
136
137
138
139__attribute__((weak))
140void read_fifo(u8 ep, u32 length, void *fifo_data)
141{
142 u8 *data = (u8 *)fifo_data;
143
144
145 writeb(ep, &musbr->index);
146
147
148 while (length--)
149 *data++ = readb(&musbr->fifox[ep]);
150}
151#endif
152