1
2
3
4
5
6 #ifndef __MV_U3D_H
7 #define __MV_U3D_H
8
9 #define MV_U3D_EP_CONTEXT_ALIGNMENT 32
10 #define MV_U3D_TRB_ALIGNMENT 16
11 #define MV_U3D_DMA_BOUNDARY 4096
12 #define MV_U3D_EP0_MAX_PKT_SIZE 512
13
14
15 #define MV_U3D_WAIT_FOR_SETUP 0
16 #define MV_U3D_DATA_STATE_XMIT 1
17 #define MV_U3D_DATA_STATE_NEED_ZLP 2
18 #define MV_U3D_WAIT_FOR_OUT_STATUS 3
19 #define MV_U3D_DATA_STATE_RECV 4
20 #define MV_U3D_STATUS_STAGE 5
21
22 #define MV_U3D_EP_MAX_LENGTH_TRANSFER 0x10000
23
24
25 #define MV_U3D_USBINT_SETUP 0x00000001
26 #define MV_U3D_USBINT_RX_COMPLETE 0x00000002
27 #define MV_U3D_USBINT_TX_COMPLETE 0x00000004
28 #define MV_U3D_USBINT_UNDER_RUN 0x00000008
29 #define MV_U3D_USBINT_RXDESC_ERR 0x00000010
30 #define MV_U3D_USBINT_TXDESC_ERR 0x00000020
31 #define MV_U3D_USBINT_RX_TRB_COMPLETE 0x00000040
32 #define MV_U3D_USBINT_TX_TRB_COMPLETE 0x00000080
33 #define MV_U3D_USBINT_VBUS_VALID 0x00010000
34 #define MV_U3D_USBINT_STORAGE_CMD_FULL 0x00020000
35 #define MV_U3D_USBINT_LINK_CHG 0x01000000
36
37
38 #define MV_U3D_INTR_ENABLE_SETUP 0x00000001
39 #define MV_U3D_INTR_ENABLE_RX_COMPLETE 0x00000002
40 #define MV_U3D_INTR_ENABLE_TX_COMPLETE 0x00000004
41 #define MV_U3D_INTR_ENABLE_UNDER_RUN 0x00000008
42 #define MV_U3D_INTR_ENABLE_RXDESC_ERR 0x00000010
43 #define MV_U3D_INTR_ENABLE_TXDESC_ERR 0x00000020
44 #define MV_U3D_INTR_ENABLE_RX_TRB_COMPLETE 0x00000040
45 #define MV_U3D_INTR_ENABLE_TX_TRB_COMPLETE 0x00000080
46 #define MV_U3D_INTR_ENABLE_RX_BUFFER_ERR 0x00000100
47 #define MV_U3D_INTR_ENABLE_VBUS_VALID 0x00010000
48 #define MV_U3D_INTR_ENABLE_STORAGE_CMD_FULL 0x00020000
49 #define MV_U3D_INTR_ENABLE_LINK_CHG 0x01000000
50 #define MV_U3D_INTR_ENABLE_PRIME_STATUS 0x02000000
51
52
53 #define MV_U3D_LINK_CHANGE_LINK_UP 0x00000001
54 #define MV_U3D_LINK_CHANGE_SUSPEND 0x00000002
55 #define MV_U3D_LINK_CHANGE_RESUME 0x00000004
56 #define MV_U3D_LINK_CHANGE_WRESET 0x00000008
57 #define MV_U3D_LINK_CHANGE_HRESET 0x00000010
58 #define MV_U3D_LINK_CHANGE_VBUS_INVALID 0x00000020
59 #define MV_U3D_LINK_CHANGE_INACT 0x00000040
60 #define MV_U3D_LINK_CHANGE_DISABLE_AFTER_U0 0x00000080
61 #define MV_U3D_LINK_CHANGE_U1 0x00000100
62 #define MV_U3D_LINK_CHANGE_U2 0x00000200
63 #define MV_U3D_LINK_CHANGE_U3 0x00000400
64
65
66 #define MV_U3D_BRIDGE_SETTING_VBUS_VALID (1 << 16)
67
68
69 #define MV_U3D_CMD_RUN_STOP 0x00000001
70 #define MV_U3D_CMD_CTRL_RESET 0x00000002
71
72
73 #define MV_U3D_EPXCR_EP_TYPE_CONTROL 0
74 #define MV_U3D_EPXCR_EP_TYPE_ISOC 1
75 #define MV_U3D_EPXCR_EP_TYPE_BULK 2
76 #define MV_U3D_EPXCR_EP_TYPE_INT 3
77 #define MV_U3D_EPXCR_EP_ENABLE_SHIFT 4
78 #define MV_U3D_EPXCR_MAX_BURST_SIZE_SHIFT 12
79 #define MV_U3D_EPXCR_MAX_PACKET_SIZE_SHIFT 16
80 #define MV_U3D_USB_BULK_BURST_OUT 6
81 #define MV_U3D_USB_BULK_BURST_IN 14
82
83 #define MV_U3D_EPXCR_EP_FLUSH (1 << 7)
84 #define MV_U3D_EPXCR_EP_HALT (1 << 1)
85 #define MV_U3D_EPXCR_EP_INIT (1)
86
87
88 #define MV_U3D_XFERSTATUS_COMPLETE_SHIFT 24
89 #define MV_U3D_COMPLETE_INVALID 0
90 #define MV_U3D_COMPLETE_SUCCESS 1
91 #define MV_U3D_COMPLETE_BUFF_ERR 2
92 #define MV_U3D_COMPLETE_SHORT_PACKET 3
93 #define MV_U3D_COMPLETE_TRB_ERR 5
94 #define MV_U3D_XFERSTATUS_TRB_LENGTH_MASK (0xFFFFFF)
95
96 #define MV_U3D_USB_LINK_BYPASS_VBUS 0x8
97
98 #define MV_U3D_LTSSM_PHY_INIT_DONE 0x80000000
99 #define MV_U3D_LTSSM_NEVER_GO_COMPLIANCE 0x40000000
100
101 #define MV_U3D_USB3_OP_REGS_OFFSET 0x100
102 #define MV_U3D_USB3_PHY_OFFSET 0xB800
103
104 #define DCS_ENABLE 0x1
105
106
107 #define MV_U3D_RESET_TIMEOUT 10000
108 #define MV_U3D_FLUSH_TIMEOUT 100000
109 #define MV_U3D_OWN_TIMEOUT 10000
110 #define LOOPS_USEC_SHIFT 4
111 #define LOOPS_USEC (1 << LOOPS_USEC_SHIFT)
112 #define LOOPS(timeout) ((timeout) >> LOOPS_USEC_SHIFT)
113
114
115 #define MV_U3D_EP_DIR_IN 1
116 #define MV_U3D_EP_DIR_OUT 0
117 #define mv_u3d_ep_dir(ep) (((ep)->ep_num == 0) ? \
118 ((ep)->u3d->ep0_dir) : ((ep)->direction))
119
120
121 struct mv_u3d_cap_regs {
122 u32 rsvd[5];
123 u32 dboff;
124 u32 rtsoff;
125 u32 vuoff;
126 };
127
128
129 struct mv_u3d_op_regs {
130 u32 usbcmd;
131 u32 rsvd1[11];
132 u32 dcbaapl;
133 u32 dcbaaph;
134 u32 rsvd2[243];
135 u32 portsc;
136 u32 portlinkinfo;
137 u32 rsvd3[9917];
138 u32 doorbell;
139 };
140
141
142 struct epxcr {
143 u32 epxoutcr0;
144 u32 epxoutcr1;
145 u32 epxincr0;
146 u32 epxincr1;
147 };
148
149
150 struct xferstatus {
151 u32 curdeqlo;
152 u32 curdeqhi;
153 u32 statuslo;
154 u32 statushi;
155 };
156
157
158 struct mv_u3d_vuc_regs {
159 u32 ctrlepenable;
160 u32 setuplock;
161 u32 endcomplete;
162 u32 intrcause;
163 u32 intrenable;
164 u32 trbcomplete;
165 u32 linkchange;
166 u32 rsvd1[5];
167 u32 trbunderrun;
168 u32 rsvd2[43];
169 u32 bridgesetting;
170 u32 rsvd3[7];
171 struct xferstatus txst[16];
172 struct xferstatus rxst[16];
173 u32 ltssm;
174 u32 pipe;
175 u32 linkcr0;
176 u32 linkcr1;
177 u32 rsvd6[60];
178 u32 mib0;
179 u32 usblink;
180 u32 ltssmstate;
181 u32 linkerrorcause;
182 u32 rsvd7[60];
183 u32 devaddrtiebrkr;
184 u32 itpinfo0;
185 u32 itpinfo1;
186 u32 rsvd8[61];
187 struct epxcr epcr[16];
188 u32 rsvd9[64];
189 u32 phyaddr;
190 u32 phydata;
191 };
192
193
194 struct mv_u3d_ep_context {
195 u32 rsvd0;
196 u32 rsvd1;
197 u32 trb_addr_lo;
198 u32 trb_addr_hi;
199 u32 rsvd2;
200 u32 rsvd3;
201 struct usb_ctrlrequest setup_buffer;
202 };
203
204
205 struct mv_u3d_trb_ctrl {
206 u32 own:1;
207 u32 rsvd1:3;
208 u32 chain:1;
209
210 u32 ioc:1;
211 u32 rsvd2:4;
212 u32 type:6;
213 #define TYPE_NORMAL 1
214 #define TYPE_DATA 3
215 #define TYPE_LINK 6
216 u32 dir:1;
217
218 u32 rsvd3:15;
219 };
220
221
222
223
224 struct mv_u3d_trb_hw {
225 u32 buf_addr_lo;
226 u32 buf_addr_hi;
227 u32 trb_len;
228 struct mv_u3d_trb_ctrl ctrl;
229 };
230
231
232 struct mv_u3d_trb {
233 struct mv_u3d_trb_hw *trb_hw;
234 dma_addr_t trb_dma;
235 struct list_head trb_list;
236 };
237
238
239 struct mv_u3d {
240 struct usb_gadget gadget;
241 struct usb_gadget_driver *driver;
242 spinlock_t lock;
243 struct completion *done;
244 struct device *dev;
245 int irq;
246
247
248 struct mv_u3d_cap_regs __iomem *cap_regs;
249 struct mv_u3d_op_regs __iomem *op_regs;
250 struct mv_u3d_vuc_regs __iomem *vuc_regs;
251 void __iomem *phy_regs;
252
253 unsigned int max_eps;
254 struct mv_u3d_ep_context *ep_context;
255 size_t ep_context_size;
256 dma_addr_t ep_context_dma;
257
258 struct dma_pool *trb_pool;
259 struct mv_u3d_ep *eps;
260
261 struct mv_u3d_req *status_req;
262 struct usb_ctrlrequest local_setup_buff;
263
264 unsigned int resume_state;
265 unsigned int usb_state;
266 unsigned int ep0_state;
267 unsigned int ep0_dir;
268
269 unsigned int dev_addr;
270
271 unsigned int errors;
272
273 unsigned softconnect:1;
274 unsigned vbus_active:1;
275 unsigned remote_wakeup:1;
276 unsigned clock_gating:1;
277 unsigned active:1;
278 unsigned vbus_valid_detect:1;
279
280 struct mv_usb_addon_irq *vbus;
281 unsigned int power;
282
283 struct clk *clk;
284 };
285
286
287 struct mv_u3d_ep {
288 struct usb_ep ep;
289 struct mv_u3d *u3d;
290 struct list_head queue;
291 struct list_head req_list;
292 struct mv_u3d_ep_context *ep_context;
293 u32 direction;
294 char name[14];
295 u32 processing;
296
297 spinlock_t req_lock;
298 unsigned wedge:1;
299 unsigned enabled:1;
300 unsigned ep_type:2;
301 unsigned ep_num:8;
302 };
303
304
305 struct mv_u3d_req {
306 struct usb_request req;
307 struct mv_u3d_ep *ep;
308 struct list_head queue;
309 struct list_head list;
310 struct list_head trb_list;
311
312 struct mv_u3d_trb *trb_head;
313 unsigned trb_count;
314 unsigned chain;
315 };
316
317 #endif