hw_dwc_otg.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. /*
  2. * hw_dwc_otg.h
  3. *
  4. * USB register definitions for DWC-OTG USB 2.0 controller.
  5. *
  6. * Written & released by Keir Fraser <keir.xen@gmail.com>
  7. *
  8. * This is free and unencumbered software released into the public domain.
  9. * See the file COPYING for more details, or visit <http://unlicense.org>.
  10. */
  11. #define PORT_FS 0
  12. #define PORT_HS 1
  13. #define IFACE_FS 0
  14. #define IFACE_HS_EMBEDDED 1
  15. #define IFACE_HS_ULPI 2
  16. #define conf_port PORT_HS
  17. #define conf_iface IFACE_FS
  18. #define conf_nr_ep 4
  19. /* USB On-The-Go Full Speed interface */
  20. struct otg {
  21. /* GLOBAL */
  22. uint32_t gotgctl; /* 00: Control and status */
  23. uint32_t gotgint; /* 04: Interrupt */
  24. uint32_t gahbcfg; /* 08: AHB configuration */
  25. uint32_t gusbcfg; /* 0C: USB configuration */
  26. uint32_t grstctl; /* 10: Reset */
  27. uint32_t gintsts; /* 14: Core interrupt */
  28. uint32_t gintmsk; /* 18: Interrupt mask */
  29. uint32_t grxstsr; /* 1C: Receive status debug read */
  30. uint32_t grxstsp; /* 20: Receive status read & pop */
  31. uint32_t grxfsiz; /* 24: Receive FIFO size */
  32. union {
  33. uint32_t hnptxfsiz; /* 28: Host non-periodic transmit FIFO size */
  34. uint32_t dieptxf0; /* 28: Endpoint 0 transmit FIFO size */
  35. };
  36. uint32_t hnptxsts; /* 2C: Non-periodic transmit FIFO/queue status */
  37. uint32_t _0[2];
  38. uint32_t gccfg; /* 38: General core configuration */
  39. uint32_t cid; /* 3C: Core ID */
  40. uint32_t _1[48];
  41. uint32_t hptxfsiz; /* 100: Host periodic transmit FIFO size */
  42. uint32_t dieptxf[15]; /* 104: Device IN endpoint transmit FIFO sizes */
  43. };
  44. struct otgh {
  45. /* HOST */
  46. uint32_t hcfg; /* 400: Host configuration */
  47. uint32_t hfir; /* 404: Host frame interval */
  48. uint32_t hfnum; /* 408: Host frame number / frame time remaining */
  49. uint32_t _3[1]; /* 40C: */
  50. uint32_t hptxsts; /* 410: Host periodic transmit FIFO / queue status */
  51. uint32_t haint; /* 414: Host all channels interrupt status */
  52. uint32_t haintmsk; /* 418: Host all channels interrupt mask */
  53. uint32_t _4[9];
  54. uint32_t hprt; /* 440: Host port control and status */
  55. uint32_t _5[47];
  56. struct {
  57. uint32_t charac; /* +00: Host channel-x characteristics */
  58. uint32_t _0[1];
  59. uint32_t intsts; /* +08: Host channel-x interrupt status */
  60. uint32_t intmsk; /* +0C: Host channel-x interrupt mask */
  61. uint32_t tsiz; /* +10: Host channel x transfer size */
  62. uint32_t _1[3];
  63. } hc[8]; /* 500..5E0: */
  64. };
  65. struct otgd {
  66. /* DEVICE */
  67. uint32_t dcfg; /* 800: Device configuration */
  68. uint32_t dctl; /* 804: Device control */
  69. uint32_t dsts; /* 808: Device status */
  70. uint32_t _7[1];
  71. uint32_t diepmsk; /* 810: Device IN endpoint common interrupt mask */
  72. uint32_t doepmsk; /* 814: Device OUT endpoint common interrupt mask */
  73. uint32_t daint; /* 818: Device all endpoints interrupt status */
  74. uint32_t daintmsk; /* 81C: Device all endpoints interrupt mask */
  75. uint32_t _8[2];
  76. uint32_t dvbusdis; /* 828: Device VBUS discharge time */
  77. uint32_t dvbuspulse; /* 82C: Device VBUS pulsing time */
  78. uint32_t _9[1];
  79. uint32_t diepempmsk; /* 834: Device IN endpoint FIFO empty int. mask */
  80. };
  81. struct otg_diep { /* 900.. */
  82. /* DEVICE IN */
  83. uint32_t ctl; /* +00: Device IN endpoint-x control */
  84. uint32_t _0[1];
  85. uint32_t intsts; /* +08: Device IN endpoint-x interrupt status */
  86. uint32_t _1[1];
  87. uint32_t tsiz; /* +10: Device IN endpoint-x transfer size */
  88. uint32_t dma; /* +14: Device IN endpoint-x DMA address */
  89. uint32_t txfsts; /* +18: Device IN endpoint-x transmit FIFO status */
  90. uint32_t _3[1];
  91. };
  92. struct otg_doep { /* B00.. */
  93. /* DEVICE OUT */
  94. uint32_t ctl; /* +00: Device OUT endpoint-x control */
  95. uint32_t _0[1];
  96. uint32_t intsts; /* +08: Device OUT endpoint-x interrupt status */
  97. uint32_t _1[1];
  98. uint32_t tsiz; /* +10: Device OUT endpoint-x transmit FIFO status */
  99. uint32_t dma; /* +14: Device OUT endpoint-x DMA address */
  100. uint32_t _2[2];
  101. };
  102. struct otg_pcgcctl {
  103. uint32_t pcgcctl; /* E00: Power and clock gating control */
  104. };
  105. struct otg_dfifo { /* 1000.. */
  106. uint32_t x[0x1000/4];
  107. };
  108. #define OTG_GOTGCTL_CURMOD (1u<<21)
  109. #define OTG_GOTGCTL_OTGVER (1u<<20)
  110. #define OTG_GOTGCTL_BSVLD (1u<<19)
  111. #define OTG_GOTGCTL_ASVLD (1u<<18)
  112. #define OTG_GOTGCTL_DBCT (1u<<17)
  113. #define OTG_GOTGCTL_CIDSTS (1u<<16)
  114. #define OTG_GOTGCTL_EHEN (1u<<12)
  115. #define OTG_GOTGCTL_DHNPEN (1u<<11)
  116. #define OTG_GOTGCTL_HSHNPEN (1u<<10)
  117. #define OTG_GOTGCTL_HNPRQ (1u<< 9)
  118. #define OTG_GOTGCTL_HNGSCS (1u<< 8)
  119. #define OTG_GOTGCTL_BVALOVAL (1u<< 7)
  120. #define OTG_GOTGCTL_BVALOEN (1u<< 6)
  121. #define OTG_GOTGCTL_AVALOVAL (1u<< 5)
  122. #define OTG_GOTGCTL_AVALOEN (1u<< 4)
  123. #define OTG_GOTGCTL_VBVALOVAL (1u<< 3)
  124. #define OTG_GOTGCTL_VBVALOEN (1u<< 2)
  125. #define OTG_GOTGCTL_SRQ (1u<< 1)
  126. #define OTG_GOTGCTL_SRQSCS (1u<< 0)
  127. #define OTG_GAHBCFG_PTXFELVL (1u<< 8)
  128. #define OTG_GAHBCFG_TXFELVL (1u<< 7)
  129. #define OTG_GAHBCFG_GINTMSK (1u<< 0)
  130. #define OTG_GUSBCFG_CTXPKT (1u<<31)
  131. #define OTG_GUSBCFG_FDMOD (1u<<30)
  132. #define OTG_GUSBCFG_FHMOD (1u<<29)
  133. #define OTG_GUSBCFG_ULPIIPD (1u<<25)
  134. #define OTG_GUSBCFG_PTCI (1u<<24)
  135. #define OTG_GUSBCFG_PCCI (1u<<23)
  136. #define OTG_GUSBCFG_TSDPS (1u<<22)
  137. #define OTG_GUSBCFG_ULPIEVBUSI (1u<<21)
  138. #define OTG_GUSBCFG_ULPIEVBUSD (1u<<20)
  139. #define OTG_GUSBCFG_ULPICSM (1u<<19)
  140. #define OTG_GUSBCFG_ULPIAR (1u<<18)
  141. #define OTG_GUSBCFG_ULPIFSL (1u<<17)
  142. #define OTG_GUSBCFG_PHYLPC (1u<<15)
  143. #define OTG_GUSBCFG_TRDT(x) ((x)<<10)
  144. #define OTG_GUSBCFG_HNPCAP (1u<< 9)
  145. #define OTG_GUSBCFG_SRPCAP (1u<< 8)
  146. #define OTG_GUSBCFG_PHYSEL (1u<< 6)
  147. #define OTG_GUSBCFG_ULPISEL (1u<< 4)
  148. #define OTG_GUSBCFG_TOCAL(x) ((x)<< 0)
  149. #define OTG_GRSTCTL_AHBIDL (1u<<31)
  150. #define OTG_GRSTCTL_DMAREQ (1u<<30)
  151. #define OTG_GRSTCTL_TXFNUM(x) ((x)<<6)
  152. #define OTG_GRSTCTL_TXFFLSH (1u<< 5)
  153. #define OTG_GRSTCTL_RXFFLSH (1u<< 4)
  154. #define OTG_GRSTCTL_PSRST (1u<< 1)
  155. #define OTG_GRSTCTL_CSRST (1u<< 0)
  156. /* GINTSTS and GINTMSK */
  157. #define OTG_GINT_WKUPINT (1u<<31) /* Host + Device */
  158. #define OTG_GINT_SRQINT (1u<<30) /* H + D */
  159. #define OTG_GINT_DISCINT (1u<<29) /* H */
  160. #define OTG_GINT_CIDSCHG (1u<<28) /* H + D */
  161. #define OTG_GINT_PTXFE (1u<<26) /* H */
  162. #define OTG_GINT_HCINT (1u<<25) /* H */
  163. #define OTG_GINT_HPRTINT (1u<<24) /* H */
  164. #define OTG_GINT_IPXFR (1u<<21) /* H */
  165. #define OTG_GINT_IISOIXFR (1u<<20) /* D */
  166. #define OTG_GINT_OEPINT (1u<<19) /* D */
  167. #define OTG_GINT_IEPINT (1u<<18) /* D */
  168. #define OTG_GINT_EOPF (1u<<15) /* D */
  169. #define OTG_GINT_ISOODRP (1u<<14) /* D */
  170. #define OTG_GINT_ENUMDNE (1u<<13) /* D */
  171. #define OTG_GINT_USBRST (1u<<12) /* D */
  172. #define OTG_GINT_USBSUSP (1u<<11) /* D */
  173. #define OTG_GINT_ESUSP (1u<<10) /* D */
  174. #define OTG_GINT_GONAKEFF (1u<< 7) /* D */
  175. #define OTG_GINT_GINAKEFF (1u<< 6) /* D */
  176. #define OTG_GINT_NPTXFE (1u<< 5) /* H */
  177. #define OTG_GINT_RXFLVL (1u<< 4) /* H + D */
  178. #define OTG_GINT_SOF (1u<< 3) /* H + D */
  179. #define OTG_GINT_OTGINT (1u<< 2) /* H + D */
  180. #define OTG_GINT_MMIS (1u<< 1) /* H + D */
  181. #define OTG_GINT_CMOD (1u<< 0) /* H + D */
  182. #define STS_GOUT_NAK 1U
  183. #define STS_DATA_UPDT 2U
  184. #define STS_XFER_COMP 3U
  185. #define STS_SETUP_COMP 4U
  186. #define STS_SETUP_UPDT 6U
  187. #define OTG_RXSTS_PKTSTS(r) (((r)>>17)&0xf)
  188. #define OTG_RXSTS_BCNT(r) (((r)>>4)&0x7ff)
  189. #define OTG_RXSTS_CHNUM(r) ((r)&0xf)
  190. #define OTG_GCCFG_PHYHSEN (1u<<23)
  191. #define OTG_GCCFG_VBDEN (1u<<21)
  192. #define OTG_GCCFG_PWRDWN (1u<<16)
  193. #define OTG_HCFG_FSLSS (1u<<2)
  194. #define OTG_HCFG_FSLSPCS (3u<<0)
  195. #define OTG_HCFG_FSLSPCS_48 (1u<<0)
  196. #define OTG_HCFG_FSLSPCS_6 (2u<<0)
  197. #define OTG_HPRT_PSPD_FULL (1u<<17)
  198. #define OTG_HPRT_PSPD_LOW (2u<<17)
  199. #define OTG_HPRT_PSPD_MASK (1u<<17) /* read-only */
  200. #define OTG_HPRT_PPWR (1u<<12)
  201. #define OTG_HPRT_PRST (1u<< 8)
  202. #define OTG_HPRT_PSUSP (1u<< 7)
  203. #define OTG_HPRT_PRES (1u<< 6)
  204. #define OTG_HPRT_POCCHNG (1u<< 5) /* raises HPRTINT */
  205. #define OTG_HPRT_POCA (1u<< 4)
  206. #define OTG_HPRT_PENCHNG (1u<< 3) /* raises HPRTINT */
  207. #define OTG_HPRT_PENA (1u<< 2)
  208. #define OTG_HPRT_PCDET (1u<< 1) /* raises HPRTINT */
  209. #define OTG_HPRT_PCSTS (1u<< 0)
  210. #define OTG_HPRT_INTS (OTG_HPRT_POCCHNG|OTG_HPRT_PENCHNG|OTG_HPRT_PCDET| \
  211. OTG_HPRT_PENA) /* PENA is also set-to-clear */
  212. /* HCINTSTS and HCINTMSK */
  213. #define OTG_HCINT_DTERR (1u<<10)
  214. #define OTG_HCINT_FRMOR (1u<< 9)
  215. #define OTG_HCINT_BBERR (1u<< 8)
  216. #define OTG_HCINT_TXERR (1u<< 7)
  217. #define OTG_HCINT_NYET (1u<< 6) /* high-speed only; not STM32F10x */
  218. #define OTG_HCINT_ACK (1u<< 5)
  219. #define OTG_HCINT_NAK (1u<< 4)
  220. #define OTG_HCINT_STALL (1u<< 3)
  221. #define OTG_HCINT_CHH (1u<< 1)
  222. #define OTG_HCINT_XFRC (1u<< 0)
  223. #define OTG_HCCHAR_CHENA (1u<<31)
  224. #define OTG_HCCHAR_CHDIS (1u<<30)
  225. #define OTG_HCCHAR_ODDFRM (1u<<29)
  226. #define OTG_HCCHAR_DAD(x) ((x)<<22)
  227. #define OTG_HCCHAR_MCNT(x) ((x)<<20)
  228. #define OTG_HCCHAR_ETYP_CTRL (0u<<18)
  229. #define OTG_HCCHAR_ETYP_ISO (1u<<18)
  230. #define OTG_HCCHAR_ETYP_BULK (2u<<18)
  231. #define OTG_HCCHAR_ETYP_INT (3u<<18)
  232. #define OTG_HCCHAR_LSDEV (1u<<17)
  233. #define OTG_HCCHAR_EPDIR_OUT (0u<<15)
  234. #define OTG_HCCHAR_EPDIR_IN (1u<<15)
  235. #define OTG_HCCHAR_EPNUM(x) ((x)<<11)
  236. #define OTG_HCCHAR_MPSIZ(x) ((x)<< 0)
  237. #define OTG_HCTSIZ_DPID_DATA0 (0u<<29)
  238. #define OTG_HCTSIZ_DPID_DATA2 (1u<<29)
  239. #define OTG_HCTSIZ_DPID_DATA1 (2u<<29)
  240. #define OTG_HCTSIZ_DPID_MDATA (3u<<29)
  241. #define OTG_HCTSIZ_DPID_SETUP (3u<<29)
  242. #define OTG_HCTSIZ_PKTCNT(x) ((x)<<19)
  243. #define OTG_HCTSIZ_XFRSIZ(x) ((x)<< 0)
  244. #define OTG_DCFG_PERSCHIVL(x) ((x)<<24)
  245. #define OTG_DCFG_ERRATIM (1u<<15)
  246. #define OTG_DCFG_XCVRDLY (1u<<14)
  247. #define OTG_DCFG_PFIVL(x) ((x)<<11)
  248. #define OTG_DCFG_DAD(x) ((x)<<4)
  249. #define OTG_DCFG_NZLSOHSK (1u<< 2)
  250. #define OTG_DCFG_DSPD(x) ((x)<<0)
  251. #define OTG_DCTL_DSBESLRJCT (1u<<18)
  252. #define OTG_DCTL_POPRGDNE (1u<<11)
  253. #define OTG_DCTL_CGONAK (1u<<10)
  254. #define OTG_DCTL_SGONAK (1u<< 9)
  255. #define OTG_DCTL_CGINAK (1u<< 8)
  256. #define OTG_DCTL_SGINAK (1u<< 7)
  257. #define OTG_DCTL_GONSTS (1u<< 3)
  258. #define OTG_DCTL_GINSTS (1u<< 2)
  259. #define OTG_DCTL_SDIS (1u<< 1)
  260. #define OTG_DCTL_RWUSIG (1u<< 0)
  261. #define OTG_DIEPMSK_NAKM (1u<<13)
  262. #define OTG_DIEPMSK_TXFURM (1u<< 8)
  263. #define OTG_DIEPMSK_INEPNEM (1u<< 6)
  264. #define OTG_DIEPMSK_INEPNMM (1u<< 5)
  265. #define OTG_DIEPMSK_ITTXFEMSK (1u<< 4)
  266. #define OTG_DIEPMSK_TOM (1u<< 3)
  267. #define OTG_DIEPMSK_AHBERRM (1u<< 2)
  268. #define OTG_DIEPMSK_EPDM (1u<< 1)
  269. #define OTG_DIEPMSK_XFRCM (1u<< 0)
  270. #define OTG_DIEPINT_TXFE (1u<< 7)
  271. #define OTG_DIEPINT_XFRC (1u<< 0)
  272. #define OTG_DOEPMSK_NYETMSK (1u<<14)
  273. #define OTG_DOEPMSK_NAKM (1u<<13)
  274. #define OTG_DOEPMSK_BERRM (1u<<12)
  275. #define OTG_DOEPMSK_OUTPKTERRM (1u<< 8)
  276. #define OTG_DOEPMSK_B2BSTUPM (1u<< 6)
  277. #define OTG_DOEPMSK_STSPHSRXM (1u<< 5)
  278. #define OTG_DOEPMSK_OTEPDM (1u<< 4)
  279. #define OTG_DOEPMSK_STUPM (1u<< 3)
  280. #define OTG_DOEPMSK_AHBERRM (1u<< 2)
  281. #define OTG_DOEPMSK_EPDM (1u<< 1)
  282. #define OTG_DOEPMSK_XFRCM (1u<< 0)
  283. #define OTG_DIEPCTL_EPENA (1u<<31)
  284. #define OTG_DIEPCTL_EPDIS (1u<<30)
  285. #define OTG_DIEPCTL_SODDFRM (1u<<29)
  286. #define OTG_DIEPCTL_SD0PID (1u<<28)
  287. #define OTG_DIEPCTL_SNAK (1u<<27)
  288. #define OTG_DIEPCTL_CNAK (1u<<26)
  289. #define OTG_DIEPCTL_TXFNUM(x) ((x)<<22)
  290. #define OTG_DIEPCTL_STALL (1u<<21)
  291. #define OTG_DIEPCTL_EPTYP(x) ((x)<<18)
  292. #define OTG_DIEPCTL_NAKSTS (1u<<17)
  293. #define OTG_DIEPCTL_DPID (1u<<16)
  294. #define OTG_DIEPCTL_USBAEP (1u<<15)
  295. #define OTG_DIEPCTL_MPSIZ(x) ((x)<<0)
  296. #define OTG_DIEPTSIZ_PKTCNT(x) ((x)<<19)
  297. #define OTG_DIEPTSIZ_XFRSIZ(x) ((x)<<0)
  298. #define OTG_DOEPCTL_EPENA (1u<<31)
  299. #define OTG_DOEPCTL_EPDIS (1u<<30)
  300. #define OTG_DOEPCTL_SD1PID (1u<<29)
  301. #define OTG_DOEPCTL_SD0PID (1u<<28)
  302. #define OTG_DOEPCTL_SNAK (1u<<27)
  303. #define OTG_DOEPCTL_CNAK (1u<<26)
  304. #define OTG_DOEPCTL_STALL (1u<<21)
  305. #define OTG_DOEPCTL_SNPM (1u<<20)
  306. #define OTG_DOEPCTL_EPTYP(x) ((x)<<18)
  307. #define OTG_DOEPCTL_NAKSTS (1u<<17)
  308. #define OTG_DOEPCTL_DPID (1u<<16)
  309. #define OTG_DOEPCTL_USBAEP (1u<<15)
  310. #define OTG_DOEPCTL_MPSIZ(x) ((x)<<0)
  311. #define OTG_DOEPTSZ_STUPCNT (3u<<29)
  312. #define OTG_DOEPTSZ_PKTCNT(x) ((x)<<19)
  313. #define OTG_DOEPTSZ_XFERSIZ(x) ((x)<<0)
  314. /* C pointer types */
  315. #define OTG volatile struct otg * const
  316. #define OTGH volatile struct otgh * const
  317. #define OTGD volatile struct otgd * const
  318. #define OTG_DIEP volatile struct otg_diep * const
  319. #define OTG_DOEP volatile struct otg_doep * const
  320. #define OTG_PCGCCTL volatile struct otg_pcgcctl * const
  321. #define OTG_DFIFO volatile struct otg_dfifo * const
  322. /* C-accessible registers. */
  323. #if conf_port == PORT_FS
  324. #define OTG_BASE USB_OTG_FS_BASE
  325. #else
  326. #define OTG_BASE USB_OTG_HS_BASE
  327. #endif
  328. static OTG otg = (struct otg *)(OTG_BASE + 0x000);
  329. static OTGH otgh = (struct otgh *)(OTG_BASE + 0x400);
  330. static OTGD otgd = (struct otgd *)(OTG_BASE + 0x800);
  331. static OTG_DIEP otg_diep = (struct otg_diep *)(OTG_BASE + 0x900);
  332. static OTG_DOEP otg_doep = (struct otg_doep *)(OTG_BASE + 0xb00);
  333. static OTG_PCGCCTL otg_pcgcctl = (struct otg_pcgcctl *)(OTG_BASE + 0xe00);
  334. static OTG_DFIFO otg_dfifo = (struct otg_dfifo *)(OTG_BASE + 0x1000);
  335. /*
  336. * Local variables:
  337. * mode: C
  338. * c-file-style: "Linux"
  339. * c-basic-offset: 4
  340. * tab-width: 4
  341. * indent-tabs-mode: nil
  342. * End:
  343. */