This source file includes following definitions.
- m66592_read
- m66592_read_fifo
- m66592_write
- m66592_mdfy
- m66592_write_fifo
1
2
3
4
5
6
7
8
9
10 #ifndef __M66592_UDC_H__
11 #define __M66592_UDC_H__
12
13 #include <linux/clk.h>
14 #include <linux/usb/m66592.h>
15
16 #define M66592_SYSCFG 0x00
17 #define M66592_XTAL 0xC000
18 #define M66592_XTAL48 0x8000
19 #define M66592_XTAL24 0x4000
20 #define M66592_XTAL12 0x0000
21 #define M66592_XCKE 0x2000
22 #define M66592_RCKE 0x1000
23 #define M66592_PLLC 0x0800
24 #define M66592_SCKE 0x0400
25 #define M66592_ATCKM 0x0100
26 #define M66592_HSE 0x0080
27 #define M66592_DCFM 0x0040
28 #define M66592_DMRPD 0x0020
29 #define M66592_DPRPU 0x0010
30 #define M66592_FSRPC 0x0004
31 #define M66592_PCUT 0x0002
32 #define M66592_USBE 0x0001
33
34 #define M66592_SYSSTS 0x02
35 #define M66592_LNST 0x0003
36 #define M66592_SE1 0x0003
37 #define M66592_KSTS 0x0002
38 #define M66592_JSTS 0x0001
39 #define M66592_SE0 0x0000
40
41 #define M66592_DVSTCTR 0x04
42 #define M66592_WKUP 0x0100
43 #define M66592_RWUPE 0x0080
44 #define M66592_USBRST 0x0040
45 #define M66592_RESUME 0x0020
46 #define M66592_UACT 0x0010
47 #define M66592_RHST 0x0003
48 #define M66592_HSMODE 0x0003
49 #define M66592_FSMODE 0x0002
50 #define M66592_HSPROC 0x0001
51
52 #define M66592_TESTMODE 0x06
53 #define M66592_UTST 0x000F
54 #define M66592_H_TST_PACKET 0x000C
55 #define M66592_H_TST_SE0_NAK 0x000B
56 #define M66592_H_TST_K 0x000A
57 #define M66592_H_TST_J 0x0009
58 #define M66592_H_TST_NORMAL 0x0000
59 #define M66592_P_TST_PACKET 0x0004
60 #define M66592_P_TST_SE0_NAK 0x0003
61 #define M66592_P_TST_K 0x0002
62 #define M66592_P_TST_J 0x0001
63 #define M66592_P_TST_NORMAL 0x0000
64
65
66 #define M66592_CFBCFG 0x0A
67 #define M66592_D0FBCFG 0x0C
68 #define M66592_LITTLE 0x0100
69
70 #define M66592_PINCFG 0x0A
71 #define M66592_LDRV 0x8000
72 #define M66592_BIGEND 0x0100
73
74 #define M66592_DMA0CFG 0x0C
75 #define M66592_DMA1CFG 0x0E
76 #define M66592_DREQA 0x4000
77 #define M66592_BURST 0x2000
78 #define M66592_DACKA 0x0400
79 #define M66592_DFORM 0x0380
80 #define M66592_CPU_ADR_RD_WR 0x0000
81 #define M66592_CPU_DACK_RD_WR 0x0100
82 #define M66592_CPU_DACK_ONLY 0x0180
83 #define M66592_SPLIT_DACK_ONLY 0x0200
84 #define M66592_SPLIT_DACK_DSTB 0x0300
85 #define M66592_DENDA 0x0040
86 #define M66592_PKTM 0x0020
87 #define M66592_DENDE 0x0010
88 #define M66592_OBUS 0x0004
89
90
91 #define M66592_CFIFO 0x10
92 #define M66592_D0FIFO 0x14
93 #define M66592_D1FIFO 0x18
94
95 #define M66592_CFIFOSEL 0x1E
96 #define M66592_D0FIFOSEL 0x24
97 #define M66592_D1FIFOSEL 0x2A
98 #define M66592_RCNT 0x8000
99 #define M66592_REW 0x4000
100 #define M66592_DCLRM 0x2000
101 #define M66592_DREQE 0x1000
102 #define M66592_MBW_8 0x0000
103 #define M66592_MBW_16 0x0400
104 #define M66592_MBW_32 0x0800
105 #define M66592_TRENB 0x0200
106 #define M66592_TRCLR 0x0100
107 #define M66592_DEZPM 0x0080
108 #define M66592_ISEL 0x0020
109 #define M66592_CURPIPE 0x0007
110
111 #define M66592_CFIFOCTR 0x20
112 #define M66592_D0FIFOCTR 0x26
113 #define M66592_D1FIFOCTR 0x2c
114 #define M66592_BVAL 0x8000
115 #define M66592_BCLR 0x4000
116 #define M66592_FRDY 0x2000
117 #define M66592_DTLN 0x0FFF
118
119 #define M66592_CFIFOSIE 0x22
120 #define M66592_TGL 0x8000
121 #define M66592_SCLR 0x4000
122 #define M66592_SBUSY 0x2000
123
124 #define M66592_D0FIFOTRN 0x28
125 #define M66592_D1FIFOTRN 0x2E
126 #define M66592_TRNCNT 0xFFFF
127
128 #define M66592_INTENB0 0x30
129 #define M66592_VBSE 0x8000
130 #define M66592_RSME 0x4000
131 #define M66592_SOFE 0x2000
132 #define M66592_DVSE 0x1000
133 #define M66592_CTRE 0x0800
134 #define M66592_BEMPE 0x0400
135 #define M66592_NRDYE 0x0200
136 #define M66592_BRDYE 0x0100
137 #define M66592_URST 0x0080
138 #define M66592_SADR 0x0040
139 #define M66592_SCFG 0x0020
140 #define M66592_SUSP 0x0010
141 #define M66592_WDST 0x0008
142 #define M66592_RDST 0x0004
143 #define M66592_CMPL 0x0002
144 #define M66592_SERR 0x0001
145
146 #define M66592_INTENB1 0x32
147 #define M66592_BCHGE 0x4000
148 #define M66592_DTCHE 0x1000
149 #define M66592_SIGNE 0x0020
150 #define M66592_SACKE 0x0010
151 #define M66592_BRDYM 0x0004
152 #define M66592_INTL 0x0002
153 #define M66592_PCSE 0x0001
154
155 #define M66592_BRDYENB 0x36
156 #define M66592_BRDYSTS 0x46
157 #define M66592_BRDY7 0x0080
158 #define M66592_BRDY6 0x0040
159 #define M66592_BRDY5 0x0020
160 #define M66592_BRDY4 0x0010
161 #define M66592_BRDY3 0x0008
162 #define M66592_BRDY2 0x0004
163 #define M66592_BRDY1 0x0002
164 #define M66592_BRDY0 0x0001
165
166 #define M66592_NRDYENB 0x38
167 #define M66592_NRDYSTS 0x48
168 #define M66592_NRDY7 0x0080
169 #define M66592_NRDY6 0x0040
170 #define M66592_NRDY5 0x0020
171 #define M66592_NRDY4 0x0010
172 #define M66592_NRDY3 0x0008
173 #define M66592_NRDY2 0x0004
174 #define M66592_NRDY1 0x0002
175 #define M66592_NRDY0 0x0001
176
177 #define M66592_BEMPENB 0x3A
178 #define M66592_BEMPSTS 0x4A
179 #define M66592_BEMP7 0x0080
180 #define M66592_BEMP6 0x0040
181 #define M66592_BEMP5 0x0020
182 #define M66592_BEMP4 0x0010
183 #define M66592_BEMP3 0x0008
184 #define M66592_BEMP2 0x0004
185 #define M66592_BEMP1 0x0002
186 #define M66592_BEMP0 0x0001
187
188 #define M66592_SOFCFG 0x3C
189 #define M66592_SOFM 0x000C
190 #define M66592_SOF_125US 0x0008
191 #define M66592_SOF_1MS 0x0004
192 #define M66592_SOF_DISABLE 0x0000
193
194 #define M66592_INTSTS0 0x40
195 #define M66592_VBINT 0x8000
196 #define M66592_RESM 0x4000
197 #define M66592_SOFR 0x2000
198 #define M66592_DVST 0x1000
199 #define M66592_CTRT 0x0800
200 #define M66592_BEMP 0x0400
201 #define M66592_NRDY 0x0200
202 #define M66592_BRDY 0x0100
203 #define M66592_VBSTS 0x0080
204 #define M66592_DVSQ 0x0070
205 #define M66592_DS_SPD_CNFG 0x0070
206 #define M66592_DS_SPD_ADDR 0x0060
207 #define M66592_DS_SPD_DFLT 0x0050
208 #define M66592_DS_SPD_POWR 0x0040
209 #define M66592_DS_SUSP 0x0040
210 #define M66592_DS_CNFG 0x0030
211 #define M66592_DS_ADDS 0x0020
212 #define M66592_DS_DFLT 0x0010
213 #define M66592_DS_POWR 0x0000
214 #define M66592_DVSQS 0x0030
215 #define M66592_VALID 0x0008
216 #define M66592_CTSQ 0x0007
217 #define M66592_CS_SQER 0x0006
218 #define M66592_CS_WRND 0x0005
219 #define M66592_CS_WRSS 0x0004
220 #define M66592_CS_WRDS 0x0003
221 #define M66592_CS_RDSS 0x0002
222 #define M66592_CS_RDDS 0x0001
223 #define M66592_CS_IDST 0x0000
224
225 #define M66592_INTSTS1 0x42
226 #define M66592_BCHG 0x4000
227 #define M66592_DTCH 0x1000
228 #define M66592_SIGN 0x0020
229 #define M66592_SACK 0x0010
230
231 #define M66592_FRMNUM 0x4C
232 #define M66592_OVRN 0x8000
233 #define M66592_CRCE 0x4000
234 #define M66592_SOFRM 0x0800
235 #define M66592_FRNM 0x07FF
236
237 #define M66592_UFRMNUM 0x4E
238 #define M66592_UFRNM 0x0007
239
240 #define M66592_RECOVER 0x50
241 #define M66592_STSRECOV 0x0700
242 #define M66592_STSR_HI 0x0400
243 #define M66592_STSR_DEFAULT 0x0100
244 #define M66592_STSR_ADDRESS 0x0200
245 #define M66592_STSR_CONFIG 0x0300
246 #define M66592_USBADDR 0x007F
247
248 #define M66592_USBREQ 0x54
249 #define M66592_bRequest 0xFF00
250 #define M66592_GET_STATUS 0x0000
251 #define M66592_CLEAR_FEATURE 0x0100
252 #define M66592_ReqRESERVED 0x0200
253 #define M66592_SET_FEATURE 0x0300
254 #define M66592_ReqRESERVED1 0x0400
255 #define M66592_SET_ADDRESS 0x0500
256 #define M66592_GET_DESCRIPTOR 0x0600
257 #define M66592_SET_DESCRIPTOR 0x0700
258 #define M66592_GET_CONFIGURATION 0x0800
259 #define M66592_SET_CONFIGURATION 0x0900
260 #define M66592_GET_INTERFACE 0x0A00
261 #define M66592_SET_INTERFACE 0x0B00
262 #define M66592_SYNCH_FRAME 0x0C00
263 #define M66592_bmRequestType 0x00FF
264 #define M66592_bmRequestTypeDir 0x0080
265 #define M66592_HOST_TO_DEVICE 0x0000
266 #define M66592_DEVICE_TO_HOST 0x0080
267 #define M66592_bmRequestTypeType 0x0060
268 #define M66592_STANDARD 0x0000
269 #define M66592_CLASS 0x0020
270 #define M66592_VENDOR 0x0040
271 #define M66592_bmRequestTypeRecip 0x001F
272 #define M66592_DEVICE 0x0000
273 #define M66592_INTERFACE 0x0001
274 #define M66592_ENDPOINT 0x0002
275
276 #define M66592_USBVAL 0x56
277 #define M66592_wValue 0xFFFF
278
279 #define M66592_ENDPOINT_HALT 0x0000
280 #define M66592_DEVICE_REMOTE_WAKEUP 0x0001
281 #define M66592_TEST_MODE 0x0002
282
283 #define M66592_DT_TYPE 0xFF00
284 #define M66592_GET_DT_TYPE(v) (((v) & DT_TYPE) >> 8)
285 #define M66592_DT_DEVICE 0x01
286 #define M66592_DT_CONFIGURATION 0x02
287 #define M66592_DT_STRING 0x03
288 #define M66592_DT_INTERFACE 0x04
289 #define M66592_DT_ENDPOINT 0x05
290 #define M66592_DT_DEVICE_QUALIFIER 0x06
291 #define M66592_DT_OTHER_SPEED_CONFIGURATION 0x07
292 #define M66592_DT_INTERFACE_POWER 0x08
293 #define M66592_DT_INDEX 0x00FF
294 #define M66592_CONF_NUM 0x00FF
295 #define M66592_ALT_SET 0x00FF
296
297 #define M66592_USBINDEX 0x58
298 #define M66592_wIndex 0xFFFF
299 #define M66592_TEST_SELECT 0xFF00
300 #define M66592_TEST_J 0x0100
301 #define M66592_TEST_K 0x0200
302 #define M66592_TEST_SE0_NAK 0x0300
303 #define M66592_TEST_PACKET 0x0400
304 #define M66592_TEST_FORCE_ENABLE 0x0500
305 #define M66592_TEST_STSelectors 0x0600
306 #define M66592_TEST_Reserved 0x4000
307 #define M66592_TEST_VSTModes 0xC000
308 #define M66592_EP_DIR 0x0080
309 #define M66592_EP_DIR_IN 0x0080
310 #define M66592_EP_DIR_OUT 0x0000
311
312 #define M66592_USBLENG 0x5A
313 #define M66592_wLength 0xFFFF
314
315 #define M66592_DCPCFG 0x5C
316 #define M66592_CNTMD 0x0100
317 #define M66592_DIR 0x0010
318
319 #define M66592_DCPMAXP 0x5E
320 #define M66592_DEVSEL 0xC000
321 #define M66592_DEVICE_0 0x0000
322 #define M66592_DEVICE_1 0x4000
323 #define M66592_DEVICE_2 0x8000
324 #define M66592_DEVICE_3 0xC000
325 #define M66592_MAXP 0x007F
326
327 #define M66592_DCPCTR 0x60
328 #define M66592_BSTS 0x8000
329 #define M66592_SUREQ 0x4000
330 #define M66592_SQCLR 0x0100
331 #define M66592_SQSET 0x0080
332 #define M66592_SQMON 0x0040
333 #define M66592_CCPL 0x0004
334 #define M66592_PID 0x0003
335 #define M66592_PID_STALL 0x0002
336 #define M66592_PID_BUF 0x0001
337 #define M66592_PID_NAK 0x0000
338
339 #define M66592_PIPESEL 0x64
340 #define M66592_PIPENM 0x0007
341 #define M66592_PIPE0 0x0000
342 #define M66592_PIPE1 0x0001
343 #define M66592_PIPE2 0x0002
344 #define M66592_PIPE3 0x0003
345 #define M66592_PIPE4 0x0004
346 #define M66592_PIPE5 0x0005
347 #define M66592_PIPE6 0x0006
348 #define M66592_PIPE7 0x0007
349
350 #define M66592_PIPECFG 0x66
351 #define M66592_TYP 0xC000
352 #define M66592_ISO 0xC000
353 #define M66592_INT 0x8000
354 #define M66592_BULK 0x4000
355 #define M66592_BFRE 0x0400
356 #define M66592_DBLB 0x0200
357 #define M66592_CNTMD 0x0100
358 #define M66592_SHTNAK 0x0080
359 #define M66592_DIR 0x0010
360 #define M66592_DIR_H_OUT 0x0010
361 #define M66592_DIR_P_IN 0x0010
362 #define M66592_DIR_H_IN 0x0000
363 #define M66592_DIR_P_OUT 0x0000
364 #define M66592_EPNUM 0x000F
365 #define M66592_EP1 0x0001
366 #define M66592_EP2 0x0002
367 #define M66592_EP3 0x0003
368 #define M66592_EP4 0x0004
369 #define M66592_EP5 0x0005
370 #define M66592_EP6 0x0006
371 #define M66592_EP7 0x0007
372 #define M66592_EP8 0x0008
373 #define M66592_EP9 0x0009
374 #define M66592_EP10 0x000A
375 #define M66592_EP11 0x000B
376 #define M66592_EP12 0x000C
377 #define M66592_EP13 0x000D
378 #define M66592_EP14 0x000E
379 #define M66592_EP15 0x000F
380
381 #define M66592_PIPEBUF 0x68
382 #define M66592_BUFSIZE 0x7C00
383 #define M66592_BUF_SIZE(x) ((((x) / 64) - 1) << 10)
384 #define M66592_BUFNMB 0x00FF
385
386 #define M66592_PIPEMAXP 0x6A
387 #define M66592_MXPS 0x07FF
388
389 #define M66592_PIPEPERI 0x6C
390 #define M66592_IFIS 0x1000
391 #define M66592_IITV 0x0007
392
393 #define M66592_PIPE1CTR 0x70
394 #define M66592_PIPE2CTR 0x72
395 #define M66592_PIPE3CTR 0x74
396 #define M66592_PIPE4CTR 0x76
397 #define M66592_PIPE5CTR 0x78
398 #define M66592_PIPE6CTR 0x7A
399 #define M66592_PIPE7CTR 0x7C
400 #define M66592_BSTS 0x8000
401 #define M66592_INBUFM 0x4000
402 #define M66592_ACLRM 0x0200
403 #define M66592_SQCLR 0x0100
404 #define M66592_SQSET 0x0080
405 #define M66592_SQMON 0x0040
406 #define M66592_PID 0x0003
407
408 #define M66592_INVALID_REG 0x7E
409
410
411 #define get_pipectr_addr(pipenum) (M66592_PIPE1CTR + (pipenum - 1) * 2)
412
413 #define M66592_MAX_SAMPLING 10
414
415 #define M66592_MAX_NUM_PIPE 8
416 #define M66592_MAX_NUM_BULK 3
417 #define M66592_MAX_NUM_ISOC 2
418 #define M66592_MAX_NUM_INT 2
419
420 #define M66592_BASE_PIPENUM_BULK 3
421 #define M66592_BASE_PIPENUM_ISOC 1
422 #define M66592_BASE_PIPENUM_INT 6
423
424 #define M66592_BASE_BUFNUM 6
425 #define M66592_MAX_BUFNUM 0x4F
426
427 struct m66592_pipe_info {
428 u16 pipe;
429 u16 epnum;
430 u16 maxpacket;
431 u16 type;
432 u16 interval;
433 u16 dir_in;
434 };
435
436 struct m66592_request {
437 struct usb_request req;
438 struct list_head queue;
439 };
440
441 struct m66592_ep {
442 struct usb_ep ep;
443 struct m66592 *m66592;
444
445 struct list_head queue;
446 unsigned busy:1;
447 unsigned internal_ccpl:1;
448
449
450 unsigned use_dma:1;
451 u16 pipenum;
452 u16 type;
453
454
455 unsigned long fifoaddr;
456 unsigned long fifosel;
457 unsigned long fifoctr;
458 unsigned long fifotrn;
459 unsigned long pipectr;
460 };
461
462 struct m66592 {
463 spinlock_t lock;
464 void __iomem *reg;
465 struct clk *clk;
466 struct m66592_platdata *pdata;
467 unsigned long irq_trigger;
468
469 struct usb_gadget gadget;
470 struct usb_gadget_driver *driver;
471
472 struct m66592_ep ep[M66592_MAX_NUM_PIPE];
473 struct m66592_ep *pipenum2ep[M66592_MAX_NUM_PIPE];
474 struct m66592_ep *epaddr2ep[16];
475
476 struct usb_request *ep0_req;
477 __le16 ep0_data;
478 u16 old_vbus;
479
480 struct timer_list timer;
481
482 int scount;
483
484 int old_dvsq;
485
486
487 int bulk;
488 int interrupt;
489 int isochronous;
490 int num_dma;
491 };
492 #define to_m66592(g) (container_of((g), struct m66592, gadget))
493
494 #define gadget_to_m66592(_gadget) container_of(_gadget, struct m66592, gadget)
495 #define m66592_to_gadget(m66592) (&m66592->gadget)
496
497 #define is_bulk_pipe(pipenum) \
498 ((pipenum >= M66592_BASE_PIPENUM_BULK) && \
499 (pipenum < (M66592_BASE_PIPENUM_BULK + M66592_MAX_NUM_BULK)))
500 #define is_interrupt_pipe(pipenum) \
501 ((pipenum >= M66592_BASE_PIPENUM_INT) && \
502 (pipenum < (M66592_BASE_PIPENUM_INT + M66592_MAX_NUM_INT)))
503 #define is_isoc_pipe(pipenum) \
504 ((pipenum >= M66592_BASE_PIPENUM_ISOC) && \
505 (pipenum < (M66592_BASE_PIPENUM_ISOC + M66592_MAX_NUM_ISOC)))
506
507 #define enable_irq_ready(m66592, pipenum) \
508 enable_pipe_irq(m66592, pipenum, M66592_BRDYENB)
509 #define disable_irq_ready(m66592, pipenum) \
510 disable_pipe_irq(m66592, pipenum, M66592_BRDYENB)
511 #define enable_irq_empty(m66592, pipenum) \
512 enable_pipe_irq(m66592, pipenum, M66592_BEMPENB)
513 #define disable_irq_empty(m66592, pipenum) \
514 disable_pipe_irq(m66592, pipenum, M66592_BEMPENB)
515 #define enable_irq_nrdy(m66592, pipenum) \
516 enable_pipe_irq(m66592, pipenum, M66592_NRDYENB)
517 #define disable_irq_nrdy(m66592, pipenum) \
518 disable_pipe_irq(m66592, pipenum, M66592_NRDYENB)
519
520
521 static inline u16 m66592_read(struct m66592 *m66592, unsigned long offset)
522 {
523 return ioread16(m66592->reg + offset);
524 }
525
526 static inline void m66592_read_fifo(struct m66592 *m66592,
527 unsigned long offset,
528 void *buf, unsigned long len)
529 {
530 void __iomem *fifoaddr = m66592->reg + offset;
531
532 if (m66592->pdata->on_chip) {
533 len = (len + 3) / 4;
534 ioread32_rep(fifoaddr, buf, len);
535 } else {
536 len = (len + 1) / 2;
537 ioread16_rep(fifoaddr, buf, len);
538 }
539 }
540
541 static inline void m66592_write(struct m66592 *m66592, u16 val,
542 unsigned long offset)
543 {
544 iowrite16(val, m66592->reg + offset);
545 }
546
547 static inline void m66592_mdfy(struct m66592 *m66592, u16 val, u16 pat,
548 unsigned long offset)
549 {
550 u16 tmp;
551 tmp = m66592_read(m66592, offset);
552 tmp = tmp & (~pat);
553 tmp = tmp | val;
554 m66592_write(m66592, tmp, offset);
555 }
556
557 #define m66592_bclr(m66592, val, offset) \
558 m66592_mdfy(m66592, 0, val, offset)
559 #define m66592_bset(m66592, val, offset) \
560 m66592_mdfy(m66592, val, 0, offset)
561
562 static inline void m66592_write_fifo(struct m66592 *m66592,
563 struct m66592_ep *ep,
564 void *buf, unsigned long len)
565 {
566 void __iomem *fifoaddr = m66592->reg + ep->fifoaddr;
567
568 if (m66592->pdata->on_chip) {
569 unsigned long count;
570 unsigned char *pb;
571 int i;
572
573 count = len / 4;
574 iowrite32_rep(fifoaddr, buf, count);
575
576 if (len & 0x00000003) {
577 pb = buf + count * 4;
578 for (i = 0; i < (len & 0x00000003); i++) {
579 if (m66592_read(m66592, M66592_CFBCFG))
580 iowrite8(pb[i], fifoaddr + (3 - i));
581 else
582 iowrite8(pb[i], fifoaddr + i);
583 }
584 }
585 } else {
586 unsigned long odd = len & 0x0001;
587
588 len = len / 2;
589 iowrite16_rep(fifoaddr, buf, len);
590 if (odd) {
591 unsigned char *p = buf + len*2;
592 if (m66592->pdata->wr0_shorted_to_wr1)
593 m66592_bclr(m66592, M66592_MBW_16, ep->fifosel);
594 iowrite8(*p, fifoaddr);
595 if (m66592->pdata->wr0_shorted_to_wr1)
596 m66592_bset(m66592, M66592_MBW_16, ep->fifosel);
597 }
598 }
599 }
600
601 #endif
602
603