1
2
3
4
5
6
7
8
9
10
11
12 #ifndef __LINUX_CDNS3_GADGET
13 #define __LINUX_CDNS3_GADGET
14 #include <linux/usb/gadget.h>
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 struct cdns3_usb_regs {
71 __le32 usb_conf;
72 __le32 usb_sts;
73 __le32 usb_cmd;
74 __le32 usb_itpn;
75 __le32 usb_lpm;
76 __le32 usb_ien;
77 __le32 usb_ists;
78 __le32 ep_sel;
79 __le32 ep_traddr;
80 __le32 ep_cfg;
81 __le32 ep_cmd;
82 __le32 ep_sts;
83 __le32 ep_sts_sid;
84 __le32 ep_sts_en;
85 __le32 drbl;
86 __le32 ep_ien;
87 __le32 ep_ists;
88 __le32 usb_pwr;
89 __le32 usb_conf2;
90 __le32 usb_cap1;
91 __le32 usb_cap2;
92 __le32 usb_cap3;
93 __le32 usb_cap4;
94 __le32 usb_cap5;
95 __le32 usb_cap6;
96 __le32 usb_cpkt1;
97 __le32 usb_cpkt2;
98 __le32 usb_cpkt3;
99 __le32 ep_dma_ext_addr;
100 __le32 buf_addr;
101 __le32 buf_data;
102 __le32 buf_ctrl;
103 __le32 dtrans;
104 __le32 tdl_from_trb;
105 __le32 tdl_beh;
106 __le32 ep_tdl;
107 __le32 tdl_beh2;
108 __le32 dma_adv_td;
109 __le32 reserved1[26];
110 __le32 cfg_reg1;
111 __le32 dbg_link1;
112 __le32 dbg_link2;
113 __le32 cfg_regs[74];
114 __le32 reserved2[51];
115 __le32 dma_axi_ctrl;
116 __le32 dma_axi_id;
117 __le32 dma_axi_cap;
118 __le32 dma_axi_ctrl0;
119 __le32 dma_axi_ctrl1;
120 };
121
122
123
124 #define USB_CONF_CFGRST BIT(0)
125
126 #define USB_CONF_CFGSET BIT(1)
127
128 #define USB_CONF_USB3DIS BIT(3)
129
130 #define USB_CONF_USB2DIS BIT(4)
131
132 #define USB_CONF_LENDIAN BIT(5)
133
134
135
136
137
138 #define USB_CONF_BENDIAN BIT(6)
139
140 #define USB_CONF_SWRST BIT(7)
141
142 #define USB_CONF_DSING BIT(8)
143
144 #define USB_CONF_DMULT BIT(9)
145
146 #define USB_CONF_DMAOFFEN BIT(10)
147
148 #define USB_CONF_DMAOFFDS BIT(11)
149
150 #define USB_CONF_CFORCE_FS BIT(12)
151
152 #define USB_CONF_SFORCE_FS BIT(13)
153
154 #define USB_CONF_DEVEN BIT(14)
155
156 #define USB_CONF_DEVDS BIT(15)
157
158 #define USB_CONF_L1EN BIT(16)
159
160 #define USB_CONF_L1DS BIT(17)
161
162 #define USB_CONF_CLK2OFFEN BIT(18)
163
164 #define USB_CONF_CLK2OFFDS BIT(19)
165
166 #define USB_CONF_LGO_L0 BIT(20)
167
168 #define USB_CONF_CLK3OFFEN BIT(21)
169
170 #define USB_CONF_CLK3OFFDS BIT(22)
171
172
173 #define USB_CONF_U1EN BIT(24)
174
175 #define USB_CONF_U1DS BIT(25)
176
177 #define USB_CONF_U2EN BIT(26)
178
179 #define USB_CONF_U2DS BIT(27)
180
181 #define USB_CONF_LGO_U0 BIT(28)
182
183 #define USB_CONF_LGO_U1 BIT(29)
184
185 #define USB_CONF_LGO_U2 BIT(30)
186
187 #define USB_CONF_LGO_SSINACT BIT(31)
188
189
190
191
192
193
194
195 #define USB_STS_CFGSTS_MASK BIT(0)
196 #define USB_STS_CFGSTS(p) ((p) & USB_STS_CFGSTS_MASK)
197
198
199
200
201
202 #define USB_STS_OV_MASK BIT(1)
203 #define USB_STS_OV(p) ((p) & USB_STS_OV_MASK)
204
205
206
207
208
209 #define USB_STS_USB3CONS_MASK BIT(2)
210 #define USB_STS_USB3CONS(p) ((p) & USB_STS_USB3CONS_MASK)
211
212
213
214
215
216
217 #define USB_STS_DTRANS_MASK BIT(3)
218 #define USB_STS_DTRANS(p) ((p) & USB_STS_DTRANS_MASK)
219
220
221
222
223
224
225
226
227 #define USB_STS_USBSPEED_MASK GENMASK(6, 4)
228 #define USB_STS_USBSPEED(p) (((p) & USB_STS_USBSPEED_MASK) >> 4)
229 #define USB_STS_LS (0x1 << 4)
230 #define USB_STS_FS (0x2 << 4)
231 #define USB_STS_HS (0x3 << 4)
232 #define USB_STS_SS (0x4 << 4)
233 #define DEV_UNDEFSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == (0x0 << 4))
234 #define DEV_LOWSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == USB_STS_LS)
235 #define DEV_FULLSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == USB_STS_FS)
236 #define DEV_HIGHSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == USB_STS_HS)
237 #define DEV_SUPERSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == USB_STS_SS)
238
239
240
241
242
243 #define USB_STS_ENDIAN_MASK BIT(7)
244 #define USB_STS_ENDIAN(p) ((p) & USB_STS_ENDIAN_MASK)
245
246
247
248
249
250
251 #define USB_STS_CLK2OFF_MASK BIT(8)
252 #define USB_STS_CLK2OFF(p) ((p) & USB_STS_CLK2OFF_MASK)
253
254
255
256
257
258
259 #define USB_STS_CLK3OFF_MASK BIT(9)
260 #define USB_STS_CLK3OFF(p) ((p) & USB_STS_CLK3OFF_MASK)
261
262
263
264
265
266 #define USB_STS_IN_RST_MASK BIT(10)
267 #define USB_STS_IN_RST(p) ((p) & USB_STS_IN_RST_MASK)
268
269
270
271
272
273
274 #define USB_STS_TDL_TRB_ENABLED BIT(11)
275
276
277
278
279
280 #define USB_STS_DEVS_MASK BIT(14)
281 #define USB_STS_DEVS(p) ((p) & USB_STS_DEVS_MASK)
282
283
284
285
286
287 #define USB_STS_ADDRESSED_MASK BIT(15)
288 #define USB_STS_ADDRESSED(p) ((p) & USB_STS_ADDRESSED_MASK)
289
290
291
292
293
294 #define USB_STS_L1ENS_MASK BIT(16)
295 #define USB_STS_L1ENS(p) ((p) & USB_STS_L1ENS_MASK)
296
297
298
299
300
301 #define USB_STS_VBUSS_MASK BIT(17)
302 #define USB_STS_VBUSS(p) ((p) & USB_STS_VBUSS_MASK)
303
304
305
306
307
308
309
310 #define USB_STS_LPMST_MASK GENMASK(19, 18)
311 #define DEV_L0_STATE(p) (((p) & USB_STS_LPMST_MASK) == (0x0 << 18))
312 #define DEV_L1_STATE(p) (((p) & USB_STS_LPMST_MASK) == (0x1 << 18))
313 #define DEV_L2_STATE(p) (((p) & USB_STS_LPMST_MASK) == (0x2 << 18))
314 #define DEV_L3_STATE(p) (((p) & USB_STS_LPMST_MASK) == (0x3 << 18))
315
316
317
318
319
320 #define USB_STS_USB2CONS_MASK BIT(20)
321 #define USB_STS_USB2CONS(p) ((p) & USB_STS_USB2CONS_MASK)
322
323
324
325
326
327 #define USB_STS_DISABLE_HS_MASK BIT(21)
328 #define USB_STS_DISABLE_HS(p) ((p) & USB_STS_DISABLE_HS_MASK)
329
330
331
332
333
334 #define USB_STS_U1ENS_MASK BIT(24)
335 #define USB_STS_U1ENS(p) ((p) & USB_STS_U1ENS_MASK)
336
337
338
339
340
341 #define USB_STS_U2ENS_MASK BIT(25)
342 #define USB_STS_U2ENS(p) ((p) & USB_STS_U2ENS_MASK)
343
344
345
346
347 #define USB_STS_LST_MASK GENMASK(29, 26)
348 #define DEV_LST_U0 (((p) & USB_STS_LST_MASK) == (0x0 << 26))
349 #define DEV_LST_U1 (((p) & USB_STS_LST_MASK) == (0x1 << 26))
350 #define DEV_LST_U2 (((p) & USB_STS_LST_MASK) == (0x2 << 26))
351 #define DEV_LST_U3 (((p) & USB_STS_LST_MASK) == (0x3 << 26))
352 #define DEV_LST_DISABLED (((p) & USB_STS_LST_MASK) == (0x4 << 26))
353 #define DEV_LST_RXDETECT (((p) & USB_STS_LST_MASK) == (0x5 << 26))
354 #define DEV_LST_INACTIVE (((p) & USB_STS_LST_MASK) == (0x6 << 26))
355 #define DEV_LST_POLLING (((p) & USB_STS_LST_MASK) == (0x7 << 26))
356 #define DEV_LST_RECOVERY (((p) & USB_STS_LST_MASK) == (0x8 << 26))
357 #define DEV_LST_HOT_RESET (((p) & USB_STS_LST_MASK) == (0x9 << 26))
358 #define DEV_LST_COMP_MODE (((p) & USB_STS_LST_MASK) == (0xa << 26))
359 #define DEV_LST_LB_STATE (((p) & USB_STS_LST_MASK) == (0xb << 26))
360
361
362
363
364
365 #define USB_STS_DMAOFF_MASK BIT(30)
366 #define USB_STS_DMAOFF(p) ((p) & USB_STS_DMAOFF_MASK)
367
368
369
370
371
372 #define USB_STS_ENDIAN2_MASK BIT(31)
373 #define USB_STS_ENDIAN2(p) ((p) & USB_STS_ENDIAN2_MASK)
374
375
376
377 #define USB_CMD_SET_ADDR BIT(0)
378
379
380
381
382
383
384
385 #define USB_CMD_FADDR_MASK GENMASK(7, 1)
386 #define USB_CMD_FADDR(p) (((p) << 1) & USB_CMD_FADDR_MASK)
387
388 #define USB_CMD_SDNFW BIT(8)
389
390 #define USB_CMD_STMODE BIT(9)
391
392 #define USB_STS_TMODE_SEL_MASK GENMASK(11, 10)
393 #define USB_STS_TMODE_SEL(p) (((p) << 10) & USB_STS_TMODE_SEL_MASK)
394
395
396
397
398 #define USB_CMD_SDNLTM BIT(12)
399
400 #define USB_CMD_SPKT BIT(13)
401
402 #define USB_CMD_DNFW_INT_MASK GENMASK(23, 16)
403 #define USB_STS_DNFW_INT(p) (((p) << 16) & USB_CMD_DNFW_INT_MASK)
404
405
406
407
408 #define USB_CMD_DNLTM_BELT_MASK GENMASK(27, 16)
409 #define USB_STS_DNLTM_BELT(p) (((p) << 16) & USB_CMD_DNLTM_BELT_MASK)
410
411
412
413
414
415
416
417 #define USB_ITPN_MASK GENMASK(13, 0)
418 #define USB_ITPN(p) ((p) & USB_ITPN_MASK)
419
420
421
422 #define USB_LPM_HIRD_MASK GENMASK(3, 0)
423 #define USB_LPM_HIRD(p) ((p) & USB_LPM_HIRD_MASK)
424
425 #define USB_LPM_BRW BIT(4)
426
427
428
429 #define USB_IEN_CONIEN BIT(0)
430
431 #define USB_IEN_DISIEN BIT(1)
432
433 #define USB_IEN_UWRESIEN BIT(2)
434
435 #define USB_IEN_UHRESIEN BIT(3)
436
437 #define USB_IEN_U3ENTIEN BIT(4)
438
439 #define USB_IEN_U3EXTIEN BIT(5)
440
441 #define USB_IEN_U2ENTIEN BIT(6)
442
443 #define USB_IEN_U2EXTIEN BIT(7)
444
445 #define USB_IEN_U1ENTIEN BIT(8)
446
447 #define USB_IEN_U1EXTIEN BIT(9)
448
449 #define USB_IEN_ITPIEN BIT(10)
450
451 #define USB_IEN_WAKEIEN BIT(11)
452
453 #define USB_IEN_SPKTIEN BIT(12)
454
455 #define USB_IEN_CON2IEN BIT(16)
456
457 #define USB_IEN_DIS2IEN BIT(17)
458
459 #define USB_IEN_U2RESIEN BIT(18)
460
461 #define USB_IEN_L2ENTIEN BIT(20)
462
463 #define USB_IEN_L2EXTIEN BIT(21)
464
465 #define USB_IEN_L1ENTIEN BIT(24)
466
467 #define USB_IEN_L1EXTIEN BIT(25)
468
469 #define USB_IEN_CFGRESIEN BIT(26)
470
471 #define USB_IEN_UWRESSIEN BIT(28)
472
473 #define USB_IEN_UWRESEIEN BIT(29)
474
475 #define USB_IEN_INIT (USB_IEN_U2RESIEN | USB_ISTS_DIS2I | USB_IEN_CON2IEN \
476 | USB_IEN_UHRESIEN | USB_IEN_UWRESIEN | USB_IEN_DISIEN \
477 | USB_IEN_CONIEN | USB_IEN_U3EXTIEN | USB_IEN_L2ENTIEN \
478 | USB_IEN_L2EXTIEN | USB_IEN_L1ENTIEN | USB_IEN_U3ENTIEN)
479
480
481
482 #define USB_ISTS_CONI BIT(0)
483
484 #define USB_ISTS_DISI BIT(1)
485
486 #define USB_ISTS_UWRESI BIT(2)
487
488 #define USB_ISTS_UHRESI BIT(3)
489
490 #define USB_ISTS_U3ENTI BIT(4)
491
492 #define USB_ISTS_U3EXTI BIT(5)
493
494 #define USB_ISTS_U2ENTI BIT(6)
495
496 #define USB_ISTS_U2EXTI BIT(7)
497
498 #define USB_ISTS_U1ENTI BIT(8)
499
500 #define USB_ISTS_U1EXTI BIT(9)
501
502 #define USB_ISTS_ITPI BIT(10)
503
504 #define USB_ISTS_WAKEI BIT(11)
505
506 #define USB_ISTS_SPKTI BIT(12)
507
508 #define USB_ISTS_CON2I BIT(16)
509
510 #define USB_ISTS_DIS2I BIT(17)
511
512 #define USB_ISTS_U2RESI BIT(18)
513
514 #define USB_ISTS_L2ENTI BIT(20)
515
516 #define USB_ISTS_L2EXTI BIT(21)
517
518 #define USB_ISTS_L1ENTI BIT(24)
519
520 #define USB_ISTS_L1EXTI BIT(25)
521
522 #define USB_ISTS_CFGRESI BIT(26)
523
524 #define USB_ISTS_UWRESSI BIT(28)
525
526 #define USB_ISTS_UWRESEI BIT(29)
527
528
529 #define EP_SEL_EPNO_MASK GENMASK(3, 0)
530
531 #define EP_SEL_EPNO(p) ((p) & EP_SEL_EPNO_MASK)
532
533 #define EP_SEL_DIR BIT(7)
534
535 #define select_ep_in(nr) (EP_SEL_EPNO(p) | EP_SEL_DIR)
536 #define select_ep_out (EP_SEL_EPNO(p))
537
538
539
540 #define EP_TRADDR_TRADDR(p) ((p))
541
542
543
544 #define EP_CFG_ENABLE BIT(0)
545
546
547
548
549
550
551 #define EP_CFG_EPTYPE_MASK GENMASK(2, 1)
552 #define EP_CFG_EPTYPE(p) (((p) << 1) & EP_CFG_EPTYPE_MASK)
553
554 #define EP_CFG_STREAM_EN BIT(3)
555
556 #define EP_CFG_TDL_CHK BIT(4)
557
558 #define EP_CFG_SID_CHK BIT(5)
559
560 #define EP_CFG_EPENDIAN BIT(7)
561
562 #define EP_CFG_MAXBURST_MASK GENMASK(11, 8)
563 #define EP_CFG_MAXBURST(p) (((p) << 8) & EP_CFG_MAXBURST_MASK)
564
565 #define EP_CFG_MULT_MASK GENMASK(15, 14)
566 #define EP_CFG_MULT(p) (((p) << 14) & EP_CFG_MULT_MASK)
567
568 #define EP_CFG_MAXPKTSIZE_MASK GENMASK(26, 16)
569 #define EP_CFG_MAXPKTSIZE(p) (((p) << 16) & EP_CFG_MAXPKTSIZE_MASK)
570
571 #define EP_CFG_BUFFERING_MASK GENMASK(31, 27)
572 #define EP_CFG_BUFFERING(p) (((p) << 27) & EP_CFG_BUFFERING_MASK)
573
574
575
576 #define EP_CMD_EPRST BIT(0)
577
578 #define EP_CMD_SSTALL BIT(1)
579
580 #define EP_CMD_CSTALL BIT(2)
581
582 #define EP_CMD_ERDY BIT(3)
583
584 #define EP_CMD_REQ_CMPL BIT(5)
585
586 #define EP_CMD_DRDY BIT(6)
587
588 #define EP_CMD_DFLUSH BIT(7)
589
590
591
592
593
594 #define EP_CMD_STDL BIT(8)
595
596
597
598
599 #define EP_CMD_TDL_MASK GENMASK(15, 9)
600 #define EP_CMD_TDL_SET(p) (((p) << 9) & EP_CMD_TDL_MASK)
601 #define EP_CMD_TDL_GET(p) (((p) & EP_CMD_TDL_MASK) >> 9)
602
603
604 #define EP_CMD_ERDY_SID_MASK GENMASK(31, 16)
605 #define EP_CMD_ERDY_SID(p) (((p) << 16) & EP_CMD_ERDY_SID_MASK)
606
607
608
609 #define EP_STS_SETUP BIT(0)
610
611 #define EP_STS_STALL(p) ((p) & BIT(1))
612
613 #define EP_STS_IOC BIT(2)
614
615 #define EP_STS_ISP BIT(3)
616
617 #define EP_STS_DESCMIS BIT(4)
618
619 #define EP_STS_STREAMR BIT(5)
620
621 #define EP_STS_MD_EXIT BIT(6)
622
623 #define EP_STS_TRBERR BIT(7)
624
625 #define EP_STS_NRDY BIT(8)
626
627 #define EP_STS_DBUSY BIT(9)
628
629 #define EP_STS_BUFFEMPTY(p) ((p) & BIT(10))
630
631 #define EP_STS_CCS(p) ((p) & BIT(11))
632
633 #define EP_STS_PRIME BIT(12)
634
635 #define EP_STS_SIDERR BIT(13)
636
637 #define EP_STS_OUTSMM BIT(14)
638
639 #define EP_STS_ISOERR BIT(15)
640
641 #define EP_STS_HOSTPP(p) ((p) & BIT(16))
642
643 #define EP_STS_SPSMST_MASK GENMASK(18, 17)
644 #define EP_STS_SPSMST_DISABLED(p) (((p) & EP_STS_SPSMST_MASK) >> 17)
645 #define EP_STS_SPSMST_IDLE(p) (((p) & EP_STS_SPSMST_MASK) >> 17)
646 #define EP_STS_SPSMST_START_STREAM(p) (((p) & EP_STS_SPSMST_MASK) >> 17)
647 #define EP_STS_SPSMST_MOVE_DATA(p) (((p) & EP_STS_SPSMST_MASK) >> 17)
648
649 #define EP_STS_IOT BIT(19)
650
651 #define EP_STS_OUTQ_NO_MASK GENMASK(27, 24)
652 #define EP_STS_OUTQ_NO(p) (((p) & EP_STS_OUTQ_NO_MASK) >> 24)
653
654 #define EP_STS_OUTQ_VAL_MASK BIT(28)
655 #define EP_STS_OUTQ_VAL(p) ((p) & EP_STS_OUTQ_VAL_MASK)
656
657 #define EP_STS_STPWAIT BIT(31)
658
659
660
661 #define EP_STS_SID_MASK GENMASK(15, 0)
662 #define EP_STS_SID(p) ((p) & EP_STS_SID_MASK)
663
664
665
666 #define EP_STS_EN_SETUPEN BIT(0)
667
668 #define EP_STS_EN_DESCMISEN BIT(4)
669
670 #define EP_STS_EN_STREAMREN BIT(5)
671
672 #define EP_STS_EN_MD_EXITEN BIT(6)
673
674 #define EP_STS_EN_TRBERREN BIT(7)
675
676 #define EP_STS_EN_NRDYEN BIT(8)
677
678 #define EP_STS_EN_PRIMEEEN BIT(12)
679
680 #define EP_STS_EN_SIDERREN BIT(13)
681
682 #define EP_STS_EN_OUTSMMEN BIT(14)
683
684 #define EP_STS_EN_ISOERREN BIT(15)
685
686 #define EP_STS_EN_IOTEN BIT(19)
687
688 #define EP_STS_EN_STPWAITEN BIT(31)
689
690
691 #define DB_VALUE_BY_INDEX(index) (1 << (index))
692 #define DB_VALUE_EP0_OUT BIT(0)
693 #define DB_VALUE_EP0_IN BIT(16)
694
695
696 #define EP_IEN(index) (1 << (index))
697 #define EP_IEN_EP_OUT0 BIT(0)
698 #define EP_IEN_EP_IN0 BIT(16)
699
700
701 #define EP_ISTS(index) (1 << (index))
702 #define EP_ISTS_EP_OUT0 BIT(0)
703 #define EP_ISTS_EP_IN0 BIT(16)
704
705
706
707 #define PUSB_PWR_PSO_EN BIT(0)
708
709 #define PUSB_PWR_PSO_DS BIT(1)
710
711
712
713
714
715 #define PUSB_PWR_STB_CLK_SWITCH_EN BIT(8)
716
717
718
719
720 #define PUSB_PWR_STB_CLK_SWITCH_DONE BIT(9)
721
722 #define PUSB_PWR_FST_REG_ACCESS_STAT BIT(30)
723
724 #define PUSB_PWR_FST_REG_ACCESS BIT(31)
725
726
727
728
729
730
731
732 #define USB_CONF2_DIS_TDL_TRB BIT(1)
733
734
735
736
737
738 #define USB_CONF2_EN_TDL_TRB BIT(2)
739
740
741
742
743
744
745
746
747
748
749
750 #define USB_CAP1_SFR_TYPE_MASK GENMASK(3, 0)
751 #define DEV_SFR_TYPE_OCP(p) (((p) & USB_CAP1_SFR_TYPE_MASK) == 0x0)
752 #define DEV_SFR_TYPE_AHB(p) (((p) & USB_CAP1_SFR_TYPE_MASK) == 0x1)
753 #define DEV_SFR_TYPE_PLB(p) (((p) & USB_CAP1_SFR_TYPE_MASK) == 0x2)
754 #define DEV_SFR_TYPE_AXI(p) (((p) & USB_CAP1_SFR_TYPE_MASK) == 0x3)
755
756
757
758
759
760
761
762
763
764 #define USB_CAP1_SFR_WIDTH_MASK GENMASK(7, 4)
765 #define DEV_SFR_WIDTH_8(p) (((p) & USB_CAP1_SFR_WIDTH_MASK) == (0x0 << 4))
766 #define DEV_SFR_WIDTH_16(p) (((p) & USB_CAP1_SFR_WIDTH_MASK) == (0x1 << 4))
767 #define DEV_SFR_WIDTH_32(p) (((p) & USB_CAP1_SFR_WIDTH_MASK) == (0x2 << 4))
768 #define DEV_SFR_WIDTH_64(p) (((p) & USB_CAP1_SFR_WIDTH_MASK) == (0x3 << 4))
769
770
771
772
773
774
775
776
777
778 #define USB_CAP1_DMA_TYPE_MASK GENMASK(11, 8)
779 #define DEV_DMA_TYPE_OCP(p) (((p) & USB_CAP1_DMA_TYPE_MASK) == (0x0 << 8))
780 #define DEV_DMA_TYPE_AHB(p) (((p) & USB_CAP1_DMA_TYPE_MASK) == (0x1 << 8))
781 #define DEV_DMA_TYPE_PLB(p) (((p) & USB_CAP1_DMA_TYPE_MASK) == (0x2 << 8))
782 #define DEV_DMA_TYPE_AXI(p) (((p) & USB_CAP1_DMA_TYPE_MASK) == (0x3 << 8))
783
784
785
786
787
788
789
790
791
792 #define USB_CAP1_DMA_WIDTH_MASK GENMASK(15, 12)
793 #define DEV_DMA_WIDTH_32(p) (((p) & USB_CAP1_DMA_WIDTH_MASK) == (0x2 << 12))
794 #define DEV_DMA_WIDTH_64(p) (((p) & USB_CAP1_DMA_WIDTH_MASK) == (0x3 << 12))
795
796
797
798
799
800
801
802 #define USB_CAP1_U3PHY_TYPE_MASK GENMASK(19, 16)
803 #define DEV_U3PHY_PIPE(p) (((p) & USB_CAP1_U3PHY_TYPE_MASK) == (0x0 << 16))
804 #define DEV_U3PHY_RMMI(p) (((p) & USB_CAP1_U3PHY_TYPE_MASK) == (0x1 << 16))
805
806
807
808
809
810
811
812
813
814
815
816 #define USB_CAP1_U3PHY_WIDTH_MASK GENMASK(23, 20)
817 #define DEV_U3PHY_WIDTH_8(p) \
818 (((p) & USB_CAP1_U3PHY_WIDTH_MASK) == (0x0 << 20))
819 #define DEV_U3PHY_WIDTH_16(p) \
820 (((p) & USB_CAP1_U3PHY_WIDTH_MASK) == (0x1 << 16))
821 #define DEV_U3PHY_WIDTH_32(p) \
822 (((p) & USB_CAP1_U3PHY_WIDTH_MASK) == (0x2 << 20))
823 #define DEV_U3PHY_WIDTH_64(p) \
824 (((p) & USB_CAP1_U3PHY_WIDTH_MASK) == (0x3 << 16))
825
826
827
828
829
830
831
832 #define USB_CAP1_U2PHY_EN(p) ((p) & BIT(24))
833
834
835
836
837
838
839 #define DEV_U2PHY_ULPI(p) ((p) & BIT(25))
840
841
842
843
844
845
846
847 #define DEV_U2PHY_WIDTH_16(p) ((p) & BIT(26))
848
849
850
851
852
853 #define USB_CAP1_OTG_READY(p) ((p) & BIT(27))
854
855
856
857
858
859
860 #define USB_CAP1_TDL_FROM_TRB(p) ((p) & BIT(28))
861
862
863
864
865
866
867
868 #define USB_CAP2_ACTUAL_MEM_SIZE(p) ((p) & GENMASK(7, 0))
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883 #define USB_CAP2_MAX_MEM_SIZE(p) ((p) & GENMASK(11, 8))
884
885
886 #define EP_IS_IMPLEMENTED(reg, index) ((reg) & (1 << (index)))
887
888
889 #define EP_SUPPORT_ISO(reg, index) ((reg) & (1 << (index)))
890
891
892 #define EP_SUPPORT_STREAM(reg, index) ((reg) & (1 << (index)))
893
894
895
896 #define GET_DEV_BASE_VERSION(p) ((p) & GENMASK(23, 0))
897
898 #define GET_DEV_CUSTOM_VERSION(p) ((p) & GENMASK(31, 24))
899
900 #define DEV_VER_NXP_V1 0x00024502
901 #define DEV_VER_TI_V1 0x00024509
902 #define DEV_VER_V2 0x0002450C
903 #define DEV_VER_V3 0x0002450d
904
905
906
907
908
909
910 #define DBG_LINK1_LFPS_MIN_DET_U1_EXIT(p) ((p) & GENMASK(7, 0))
911
912
913
914
915 #define DBG_LINK1_LFPS_MIN_GEN_U1_EXIT_MASK GENMASK(15, 8)
916 #define DBG_LINK1_LFPS_MIN_GEN_U1_EXIT(p) (((p) << 8) & GENMASK(15, 8))
917
918
919
920
921
922
923
924
925 #define DBG_LINK1_RXDET_BREAK_DIS BIT(16)
926
927 #define DBG_LINK1_LFPS_GEN_PING(p) (((p) << 17) & GENMASK(21, 17))
928
929
930
931
932
933 #define DBG_LINK1_LFPS_MIN_DET_U1_EXIT_SET BIT(24)
934
935
936
937
938
939 #define DBG_LINK1_LFPS_MIN_GEN_U1_EXIT_SET BIT(25)
940
941
942
943
944
945 #define DBG_LINK1_RXDET_BREAK_DIS_SET BIT(26)
946
947
948
949
950
951 #define DBG_LINK1_LFPS_GEN_PING_SET BIT(27)
952
953
954
955 #define DMA_AXI_CTRL_MARPROT(p) ((p) & GENMASK(2, 0))
956
957 #define DMA_AXI_CTRL_MAWPROT(p) (((p) & GENMASK(2, 0)) << 16)
958 #define DMA_AXI_CTRL_NON_SECURE 0x02
959
960 #define gadget_to_cdns3_device(g) (container_of(g, struct cdns3_device, gadget))
961
962 #define ep_to_cdns3_ep(ep) (container_of(ep, struct cdns3_endpoint, endpoint))
963
964
965
966
967
968 #define TRBS_PER_SEGMENT 40
969
970 #define ISO_MAX_INTERVAL 10
971
972 #if TRBS_PER_SEGMENT < 2
973 #error "Incorrect TRBS_PER_SEGMENT. Minimal Transfer Ring size is 2."
974 #endif
975
976
977
978
979
980
981
982
983 #define TRBS_PER_ISOC_SEGMENT (ISO_MAX_INTERVAL * 8)
984
985 #define GET_TRBS_PER_SEGMENT(ep_type) ((ep_type) == USB_ENDPOINT_XFER_ISOC ? \
986 TRBS_PER_ISOC_SEGMENT : TRBS_PER_SEGMENT)
987
988
989
990
991
992
993
994
995 struct cdns3_trb {
996 __le32 buffer;
997 __le32 length;
998 __le32 control;
999 };
1000
1001 #define TRB_SIZE (sizeof(struct cdns3_trb))
1002 #define TRB_RING_SIZE (TRB_SIZE * TRBS_PER_SEGMENT)
1003 #define TRB_ISO_RING_SIZE (TRB_SIZE * TRBS_PER_ISOC_SEGMENT)
1004 #define TRB_CTRL_RING_SIZE (TRB_SIZE * 2)
1005
1006
1007 #define TRB_TYPE_BITMASK GENMASK(15, 10)
1008 #define TRB_TYPE(p) ((p) << 10)
1009 #define TRB_FIELD_TO_TYPE(p) (((p) & TRB_TYPE_BITMASK) >> 10)
1010
1011
1012
1013 #define TRB_NORMAL 1
1014
1015 #define TRB_LINK 6
1016
1017
1018 #define TRB_CYCLE BIT(0)
1019
1020
1021
1022 #define TRB_TOGGLE BIT(1)
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032 #define TRB_SP BIT(1)
1033
1034
1035 #define TRB_ISP BIT(2)
1036
1037 #define TRB_FIFO_MODE BIT(3)
1038
1039 #define TRB_CHAIN BIT(4)
1040
1041 #define TRB_IOC BIT(5)
1042
1043
1044 #define TRB_STREAM_ID_BITMASK GENMASK(31, 16)
1045 #define TRB_STREAM_ID(p) ((p) << 16)
1046 #define TRB_FIELD_TO_STREAMID(p) (((p) & TRB_STREAM_ID_BITMASK) >> 16)
1047
1048
1049 #define TRB_TDL_HS_SIZE(p) (((p) << 16) & GENMASK(31, 16))
1050 #define TRB_TDL_HS_SIZE_GET(p) (((p) & GENMASK(31, 16)) >> 16)
1051
1052
1053 #define TRB_LEN(p) ((p) & GENMASK(16, 0))
1054
1055
1056 #define TRB_TDL_SS_SIZE(p) (((p) << 17) & GENMASK(23, 17))
1057 #define TRB_TDL_SS_SIZE_GET(p) (((p) & GENMASK(23, 17)) >> 17)
1058
1059
1060 #define TRB_BURST_LEN(p) (((p) << 24) & GENMASK(31, 24))
1061 #define TRB_BURST_LEN_GET(p) (((p) & GENMASK(31, 24)) >> 24)
1062
1063
1064 #define TRB_BUFFER(p) ((p) & GENMASK(31, 0))
1065
1066
1067
1068
1069
1070 #define USB_DEVICE_MAX_ADDRESS 127
1071
1072
1073 #define CDNS3_EP_MAX_PACKET_LIMIT 1024
1074 #define CDNS3_EP_MAX_STREAMS 15
1075 #define CDNS3_EP0_MAX_PACKET_LIMIT 512
1076
1077
1078 #define CDNS3_ENDPOINTS_MAX_COUNT 32
1079 #define CDNS3_EP_ZLP_BUF_SIZE 1024
1080
1081 #define CDNS3_EP_BUF_SIZE 2
1082 #define CDNS3_EP_ISO_HS_MULT 3
1083 #define CDNS3_EP_ISO_SS_BURST 3
1084 #define CDNS3_MAX_NUM_DESCMISS_BUF 32
1085 #define CDNS3_DESCMIS_BUF_SIZE 2048
1086 #define CDNS3_WA2_NUM_BUFFERS 128
1087
1088
1089
1090 struct cdns3_device;
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118 struct cdns3_endpoint {
1119 struct usb_ep endpoint;
1120 struct list_head pending_req_list;
1121 struct list_head deferred_req_list;
1122 struct list_head wa2_descmiss_req_list;
1123 int wa2_counter;
1124
1125 struct cdns3_trb *trb_pool;
1126 dma_addr_t trb_pool_dma;
1127
1128 struct cdns3_device *cdns3_dev;
1129 char name[20];
1130
1131 #define EP_ENABLED BIT(0)
1132 #define EP_STALLED BIT(1)
1133 #define EP_STALL_PENDING BIT(2)
1134 #define EP_WEDGE BIT(3)
1135 #define EP_TRANSFER_STARTED BIT(4)
1136 #define EP_UPDATE_EP_TRBADDR BIT(5)
1137 #define EP_PENDING_REQUEST BIT(6)
1138 #define EP_RING_FULL BIT(7)
1139 #define EP_CLAIMED BIT(8)
1140 #define EP_DEFERRED_DRDY BIT(9)
1141 #define EP_QUIRK_ISO_OUT_EN BIT(10)
1142 #define EP_QUIRK_END_TRANSFER BIT(11)
1143 #define EP_QUIRK_EXTRA_BUF_DET BIT(12)
1144 #define EP_QUIRK_EXTRA_BUF_EN BIT(13)
1145 u32 flags;
1146
1147 struct cdns3_request *descmis_req;
1148
1149 u8 dir;
1150 u8 num;
1151 u8 type;
1152 int interval;
1153
1154 int free_trbs;
1155 int num_trbs;
1156 u8 pcs;
1157 u8 ccs;
1158 int enqueue;
1159 int dequeue;
1160 u8 trb_burst_size;
1161
1162 unsigned int wa1_set:1;
1163 struct cdns3_trb *wa1_trb;
1164 unsigned int wa1_trb_index;
1165 unsigned int wa1_cycle_bit:1;
1166 };
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177 struct cdns3_aligned_buf {
1178 void *buf;
1179 dma_addr_t dma;
1180 u32 size;
1181 int in_use:1;
1182 struct list_head list;
1183 };
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198 struct cdns3_request {
1199 struct usb_request request;
1200 struct cdns3_endpoint *priv_ep;
1201 struct cdns3_trb *trb;
1202 int start_trb;
1203 int end_trb;
1204 struct cdns3_aligned_buf *aligned_buf;
1205 #define REQUEST_PENDING BIT(0)
1206 #define REQUEST_INTERNAL BIT(1)
1207 #define REQUEST_INTERNAL_CH BIT(2)
1208 #define REQUEST_ZLP BIT(3)
1209 #define REQUEST_UNALIGNED BIT(4)
1210 u32 flags;
1211 struct list_head list;
1212 };
1213
1214 #define to_cdns3_request(r) (container_of(r, struct cdns3_request, request))
1215
1216
1217 #define CDNS3_SETUP_STAGE 0x0
1218 #define CDNS3_DATA_STAGE 0x1
1219 #define CDNS3_STATUS_STAGE 0x2
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254 struct cdns3_device {
1255 struct device *dev;
1256 struct device *sysdev;
1257
1258 struct usb_gadget gadget;
1259 struct usb_gadget_driver *gadget_driver;
1260
1261 #define CDNS_REVISION_V0 0x00024501
1262 #define CDNS_REVISION_V1 0x00024509
1263 u32 dev_ver;
1264
1265
1266 spinlock_t lock;
1267
1268 struct cdns3_usb_regs __iomem *regs;
1269
1270 struct usb_ctrlrequest *setup_buf;
1271 dma_addr_t setup_dma;
1272 void *zlp_buf;
1273
1274 u8 ep0_stage;
1275 int ep0_data_dir;
1276
1277 struct cdns3_endpoint *eps[CDNS3_ENDPOINTS_MAX_COUNT];
1278
1279 struct list_head aligned_buf_list;
1280 struct work_struct aligned_buf_wq;
1281
1282 u32 selected_ep;
1283 u16 isoch_delay;
1284
1285 unsigned wait_for_setup:1;
1286 unsigned u1_allowed:1;
1287 unsigned u2_allowed:1;
1288 unsigned is_selfpowered:1;
1289 unsigned setup_pending:1;
1290 int hw_configured_flag:1;
1291 int wake_up_flag:1;
1292 unsigned status_completion_no_call:1;
1293 int out_mem_is_allocated;
1294
1295 struct work_struct pending_status_wq;
1296 struct usb_request *pending_status_request;
1297
1298
1299 u16 onchip_buffers;
1300 u16 onchip_used_size;
1301 };
1302
1303 void cdns3_set_register_bit(void __iomem *ptr, u32 mask);
1304 dma_addr_t cdns3_trb_virt_to_dma(struct cdns3_endpoint *priv_ep,
1305 struct cdns3_trb *trb);
1306 enum usb_device_speed cdns3_get_speed(struct cdns3_device *priv_dev);
1307 void cdns3_pending_setup_status_handler(struct work_struct *work);
1308 void cdns3_hw_reset_eps_config(struct cdns3_device *priv_dev);
1309 void cdns3_set_hw_configuration(struct cdns3_device *priv_dev);
1310 void cdns3_select_ep(struct cdns3_device *priv_dev, u32 ep);
1311 void cdns3_allow_enable_l1(struct cdns3_device *priv_dev, int enable);
1312 struct usb_request *cdns3_next_request(struct list_head *list);
1313 int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep,
1314 struct usb_request *request);
1315 void cdns3_rearm_transfer(struct cdns3_endpoint *priv_ep, u8 rearm);
1316 int cdns3_allocate_trb_pool(struct cdns3_endpoint *priv_ep);
1317 u8 cdns3_ep_addr_to_index(u8 ep_addr);
1318 int cdns3_gadget_ep_set_wedge(struct usb_ep *ep);
1319 int cdns3_gadget_ep_set_halt(struct usb_ep *ep, int value);
1320 void __cdns3_gadget_ep_set_halt(struct cdns3_endpoint *priv_ep);
1321 int __cdns3_gadget_ep_clear_halt(struct cdns3_endpoint *priv_ep);
1322 struct usb_request *cdns3_gadget_ep_alloc_request(struct usb_ep *ep,
1323 gfp_t gfp_flags);
1324 void cdns3_gadget_ep_free_request(struct usb_ep *ep,
1325 struct usb_request *request);
1326 int cdns3_gadget_ep_dequeue(struct usb_ep *ep, struct usb_request *request);
1327 void cdns3_gadget_giveback(struct cdns3_endpoint *priv_ep,
1328 struct cdns3_request *priv_req,
1329 int status);
1330
1331 int cdns3_init_ep0(struct cdns3_device *priv_dev,
1332 struct cdns3_endpoint *priv_ep);
1333 void cdns3_ep0_config(struct cdns3_device *priv_dev);
1334 void cdns3_ep_config(struct cdns3_endpoint *priv_ep);
1335 void cdns3_check_ep0_interrupt_proceed(struct cdns3_device *priv_dev, int dir);
1336 int __cdns3_gadget_wakeup(struct cdns3_device *priv_dev);
1337
1338 #endif