x1000_otg_dwc.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /*
  2. * File : x1000_otg_dwc.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2008 - 2012, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2017-02-03 Urey the first version
  23. */
  24. #ifndef _X1000_OTG_DWC_H_
  25. #define _X1000_OTG_DWC_H_
  26. /* Globle Regs define */
  27. #define GOTG_CTL (OTG_BASE + 0x00)
  28. #define GOTG_INTR (OTG_BASE + 0x04)
  29. #define GAHB_CFG (OTG_BASE + 0x08)
  30. #define GUSB_CFG (OTG_BASE + 0x0c)
  31. #define GRST_CTL (OTG_BASE + 0x10)
  32. #define GINT_STS (OTG_BASE + 0x14)
  33. #define GINT_MASK (OTG_BASE + 0x18)
  34. #define GRXSTS_READ (OTG_BASE + 0x1c)
  35. #define GRXSTS_POP (OTG_BASE + 0x20)
  36. #define GRXFIFO_SIZE (OTG_BASE + 0x24)
  37. #define GNPTXFIFO_SIZE (OTG_BASE + 0x28)
  38. #define GDTXFIFO_SIZE (OTG_BASE + 0x104)
  39. #define GHW_CFG1 (OTG_BASE + 0x44)
  40. #define GHW_CFG2 (OTG_BASE + 0x48)
  41. #define GHW_CFG3 (OTG_BASE + 0x4c)
  42. #define GHW_CFG4 (OTG_BASE + 0x50)
  43. #define GDFIFO_CFG (OTG_BASE + 0x5c)
  44. #define PCGC_CTL (OTG_BASE + 0xe00)
  45. /* Fifo number 1 ~ 15 */
  46. #define GDEIP_TXF(n) (OTG_BASE + (0x104 + ((n-1) * 0x4)))
  47. #define REG_GOTG_CTL REG32(GOTG_CTL)
  48. #define REG_GOTG_INTR REG32(GOTG_INTR)
  49. #define REG_GAHB_CFG REG32(GAHB_CFG)
  50. #define REG_GUSB_CFG REG32(GUSB_CFG)
  51. #define REG_GRST_CTL REG32(GRST_CTL)
  52. #define REG_GINT_STS REG32(GINT_STS)
  53. #define REG_GINT_MASK REG32(GINT_MASK)
  54. #define REG_GRXSTS_READ REG32(GRXSTS_READ)
  55. #define REG_GRXSTS_POP REG32(GRXSTS_POP)
  56. #define REG_GRXFIFO_SIZE REG32(GRXFIFO_SIZE)
  57. #define REG_GNPTXFIFO_SIZE REG32(GNPTXFIFO_SIZE)
  58. #define REG_GDTXFIFO_SIZE REG32(GDTXFIFO_SIZE)
  59. #define REG_GHW_CFG1 REG32(GHW_CFG1)
  60. #define REG_GHW_CFG2 REG32(GHW_CFG2)
  61. #define REG_GHW_CFG3 REG32(GHW_CFG3)
  62. #define REG_GHW_CFG4 REG32(GHW_CFG4)
  63. #define REG_GDFIFO_CFG REG32(GDFIFO_CFG)
  64. #define REG_GDIEP_TXF(n) REG32(GDEIP_TXF(n))
  65. #define REG_PCGC_CTL REG32(PCGC_CTL)
  66. /* Device Regs define */
  67. #define EP_FIFO(n) (OTG_BASE + (n+1)*0x1000) // FiX ME
  68. #define REG_EP_FIFO(n) REG32(EP_FIFO(n))
  69. #define OTG_DCFG (OTG_BASE + 0x800)
  70. #define OTG_DCTL (OTG_BASE + 0x804)
  71. #define OTG_DSTS (OTG_BASE + 0x808)
  72. #define DIEP_MASK (OTG_BASE + 0x810)
  73. #define DOEP_MASK (OTG_BASE + 0x814)
  74. #define OTG_DAINT (OTG_BASE + 0x818)
  75. #define DAINT_MASK (OTG_BASE + 0x81c)
  76. #define DIEP_EMPMSK (OTG_BASE + 0x834)
  77. /* It's used in OTG_MULT_PROC_INTRPT = 1
  78. #define DEACH_INT (OTG_BASE + 0x838)
  79. #define DEACH_INTMASK (OTG_BASE + 0x83c)
  80. #define DIEP0_INTMASK (OTG_BASE + 0x840)
  81. #define DIEP1_INTMASK (OTG_BASE + 0x844)
  82. #define DOEP0_INTMASK (OTG_BASE + 0x880)
  83. #define DOEP1_INTMASK (OTG_BASE + 0x884)
  84. */
  85. #define DIEP_CTL(n) (OTG_BASE + (0x900 + (n)*0x20))
  86. #define DOEP_CTL(n) (OTG_BASE + (0xb00 + (n)*0x20))
  87. #define DIEP_INT(n) (OTG_BASE + (0x908 + (n)*0x20))
  88. #define DOEP_INT(n) (OTG_BASE + (0xb08 + (n)*0x20))
  89. #define DIEP_SIZE(n) (OTG_BASE + (0x910 + (n)*0x20))
  90. #define DOEP_SIZE(n) (OTG_BASE + (0xb10 + (n)*0x20))
  91. #define DIEP_TXFSTS(n) (OTG_BASE + (0x918 + (n)*0x20))
  92. #define DIEP_DMA(n) (OTG_BASE + (0x914 + (n)*0x20))
  93. #define DOEP_DMA(n) (OTG_BASE + (0xb14 + (n)*0x20))
  94. #define REG_OTG_DCFG REG32(OTG_DCFG)
  95. #define REG_OTG_DCTL REG32(OTG_DCTL)
  96. #define REG_OTG_DSTS REG32(OTG_DSTS)
  97. #define REG_DIEP_MASK REG32(DIEP_MASK)
  98. #define REG_DOEP_MASK REG32(DOEP_MASK)
  99. #define REG_OTG_DAINT REG32(OTG_DAINT)
  100. #define REG_DAINT_MASK REG32(DAINT_MASK)
  101. #define REG_DIEP_EMPMSK REG32(DIEP_EMPMSK)
  102. #define REG_DIEP_CTL(n) REG32(DIEP_CTL(n))
  103. #define REG_DOEP_CTL(n) REG32(DOEP_CTL(n))
  104. #define REG_DIEP_INT(n) REG32(DIEP_INT(n))
  105. #define REG_DOEP_INT(n) REG32(DOEP_INT(n))
  106. #define REG_DIEP_SIZE(n) REG32(DIEP_SIZE(n))
  107. #define REG_DOEP_SIZE(n) REG32(DOEP_SIZE(n))
  108. #define REG_DIEP_TXFSTS(n) REG32(DIEP_TXFSTS(n))
  109. #define REG_DIEP_DMA(n) REG32(DIEP_DMA(n))
  110. #define REG_DOEP_DMA(n) REG32(DOEP_DMA(n))
  111. /* Regs macro define */
  112. /*************************************************/
  113. #define AHBCFG_TXFE_LVL BIT7
  114. #define AHBCFG_DMA_ENA BIT5
  115. #define AHBCFG_GLOBLE_INTRMASK BIT0
  116. #define USBCFG_FORCE_DEVICE BIT30
  117. #define USBCFG_TRDTIME_MASK (0xf << 10)
  118. #define USBCFG_TRDTIME_9 (9 << 10)
  119. #define USBCFG_TRDTIME_6 (6 << 10)
  120. /* GRSTCTL */
  121. #define RSTCTL_AHB_IDLE BIT31
  122. #define RSTCTL_TXFNUM_ALL (0x10 << 6)
  123. #define RSTCTL_TXFIFO_FLUSH BIT5
  124. #define RSTCTL_RXFIFO_FLUSH BIT4
  125. #define RSTCTL_INTK_FLUSH BIT3
  126. #define RSTCTL_FRMCNT_RST BIT2
  127. #define RSTCTL_CORE_RST BIT0
  128. /* GINTMSK */
  129. #define GINTMSK_RSUME_DETE BIT31
  130. #define GINTMSK_CONID_STSCHG BIT28
  131. #define GINTMSK_RESET_DETE BIT23
  132. #define GINTMSK_FETCH_SUSPEND BIT22
  133. #define GINTMSK_OEP_INTR BIT19
  134. #define GINTMSK_IEP_INTR BIT18
  135. #define GINTMSK_EP_MISMATCH BIT17
  136. #define GINTMSK_ENUM_DONE BIT13
  137. #define GINTMSK_USB_RESET BIT12
  138. #define GINTMSK_USB_SUSPEND BIT11
  139. #define GINTMSK_USB_EARLYSUSPEND BIT10
  140. #define GINTMSK_I2C_INT BIT9
  141. #define GINTMSK_ULPK_CKINT BIT8
  142. #define GINTMSK_GOUTNAK_EFF BIT7
  143. #define GINTMSK_GINNAK_EFF BIT6
  144. #define GINTMSK_NPTXFIFO_EMPTY BIT5
  145. #define GINTMSK_RXFIFO_NEMPTY BIT4
  146. #define GINTMSK_START_FRAM BIT3
  147. #define GINTMSK_OTG_INTR BIT2
  148. #define GINTMSK_MODE_MISMATCH BIT1
  149. /* GINTSTS */
  150. #define GINTSTS_RSUME_DETE BIT31
  151. #define GINTSTS_CONID_STSCHG BIT28
  152. #define GINTSTS_RESET_DETE BIT23
  153. #define GINTSTS_FETCH_SUSPEND BIT22
  154. #define GINTSTS_OEP_INTR BIT19
  155. #define GINTSTS_IEP_INTR BIT18
  156. #define GINTSTS_EP_MISMATCH BIT17
  157. #define GINTSTS_ENUM_DONE BIT13
  158. #define GINTSTS_USB_RESET BIT12
  159. #define GINTSTS_USB_SUSPEND BIT11
  160. #define GINTSTS_USB_EARLYSUSPEND BIT10
  161. #define GINTSTS_I2C_INT BIT9
  162. #define GINTSTS_ULPK_CKINT BIT8
  163. #define GINTSTS_GOUTNAK_EFF BIT7
  164. #define GINTSTS_GINNAK_EFF BIT6
  165. #define GINTSTS_NPTXFIFO_EMPTY BIT5
  166. #define GINTSTS_RXFIFO_NEMPTY BIT4
  167. #define GINTSTS_START_FRAM BIT3
  168. #define GINTSTS_OTG_INTR BIT2
  169. #define GINTSTS_MODE_MISMATCH BIT1
  170. /* DCTL */
  171. #define DCTL_CGOUTNAK BIT10
  172. #define DCTL_CLR_GNPINNAK BIT8
  173. #define DCTL_SGNPINNAK BIT7
  174. #define DCTL_SOFT_DISCONN BIT1
  175. #define DCTL_SGOUTNAK BIT9
  176. /* DCFG */
  177. #define DCFG_DEV_ADDR_MASK (0x7f << 4)
  178. #define DCFG_DEV_ADDR_BIT 4
  179. #define DCFG_DEV_DESC_DMA (1 << 23)
  180. /* DSTS */
  181. #define DSTS_ERRATIC_ERROR BIT3
  182. #define DSTS_ENUM_SPEED_MASK (0x3 << 1)
  183. #define DSTS_ENUM_SPEED_BIT BIT1
  184. #define DSTS_ENUM_SPEED_HIGH (0x0 << 1)
  185. #define DSTS_ENUM_SPEED_FULL_30OR60 (0x1 << 1)
  186. #define DSTS_ENUM_SPEED_LOW (0x2 << 1)
  187. #define DSTS_ENUM_SPEED_FULL_48 (0x3 << 1)
  188. /* GRXSTSR/GRXSTSP */
  189. #define GRXSTSP_PKSTS_MASK (0xf << 17)
  190. #define GRXSTSP_PKSTS_GOUT_NAK (0x1 << 17)
  191. #define GRXSTSP_PKSTS_GOUT_RECV (0x2 << 17)
  192. #define GRXSTSP_PKSTS_TX_COMP (0x3 << 17)
  193. #define GRXSTSP_PKSTS_SETUP_COMP (0x4 << 17)
  194. #define GRXSTSP_PKSTS_SETUP_RECV (0x6 << 17)
  195. #define GRXSTSP_BYTE_CNT_MASK (0x7ff << 4)
  196. #define GRXSTSP_BYTE_CNT_BIT 4
  197. #define GRXSTSP_EPNUM_MASK (0xf)
  198. #define GRXSTSP_EPNUM_BIT BIT0
  199. /* DIOEPCTL */
  200. // ep0
  201. #define DEP_EP0_MAXPKET_SIZE 64
  202. #define DEP_EP0_MPS_64 (0x0)
  203. #define DEP_EP0_MPS_32 (0x1)
  204. #define DEP_EP0_MPS_16 (0x2)
  205. #define DEP_EP0_MPS_8 (0x3)
  206. #define DEP_ENA_BIT BIT31
  207. #define DEP_DISENA_BIT BIT30
  208. #define DEP_SET_NAK BIT27
  209. #define DEP_CLEAR_NAK BIT26
  210. #define DEP_SET_STALL BIT21
  211. #define DEP_TYPE_MASK (0x3 << 18)
  212. #define DEP_TYPE_CNTL (0x0 << 18)
  213. #define DEP_TYPE_ISO (0x1 << 18)
  214. #define DEP_TYPE_BULK (0x2 << 18)
  215. #define DEP_TYPE_INTR (0x3 << 18)
  216. #define USB_ACTIVE_EP BIT15
  217. #define DEP_PKTSIZE_MASK 0x7ff
  218. #define DEP_FS_PKTSIZE 64
  219. #define DEP_HS_PKTSIZE 512
  220. /* DIOEPINT */
  221. #define DEP_NYET_INT BIT14
  222. #define DEP_NAK_INT BIT13
  223. #define DEP_BABBLE_ERR_INT BIT12
  224. #define DEP_PKT_DROP_STATUS BIT11
  225. #define DEP_BNA_INT BIT9
  226. #define DEP_TXFIFO_UNDRN BIT8 // Only for INEP
  227. #define DEP_OUTPKT_ERR BIT8 // Only for OUTEP
  228. #define DEP_TXFIFO_EMPTY BIT7
  229. #define DEP_INEP_NAKEFF BIT6 // Only for INEP
  230. #define DEP_B2B_SETUP_RECV BIT6 // Only for OUTEP0
  231. #define DEP_INTOKEN_EPMISATCH BIT5 // Only for INEP
  232. #define DEP_STATUS_PHASE_RECV BIT5 // Only for OUTEP0
  233. #define DEP_INTOKEN_RECV_TXFIFO_EMPTY BIT4 // Only for INEP
  234. #define DEP_OUTTOKEN_RECV_EPDIS BIT4 // Only for OUTEP
  235. #define DEP_TIME_OUT BIT3 // Only for INEP
  236. #define DEP_SETUP_PHASE_DONE BIT3 // Only for OUTEP0
  237. #define DEP_AHB_ERR BIT2
  238. #define DEP_EPDIS_INT BIT1
  239. #define DEP_XFER_COMP BIT0 // Used by INEP and OUTEP
  240. /* DOEPSIZ0 */
  241. #define DOEPSIZE0_SUPCNT_1 (0x1 << 29)
  242. #define DOEPSIZE0_SUPCNT_2 (0x2 << 29)
  243. #define DOEPSIZE0_SUPCNT_3 (0x3 << 29)
  244. #define DOEPSIZE0_PKTCNT_BIT BIT19
  245. #define DEP_RXFIFO_SIZE 1064
  246. #define DEP_NPTXFIFO_SIZE 1024
  247. #define DEP_DTXFIFO_SIZE 768
  248. #define DWC_GAHBCFG_INT_DMA_BURST_SINGLE 0
  249. #define DWC_GAHBCFG_INT_DMA_BURST_INCR 1
  250. #define DWC_GAHBCFG_INT_DMA_BURST_INCR4 3
  251. #define DWC_GAHBCFG_INT_DMA_BURST_INCR8 5
  252. #define DWC_GAHBCFG_INT_DMA_BURST_INCR16 7
  253. #define DWC_GAHBCFG_EXT_DMA_BURST_1word 0x0
  254. #define DWC_GAHBCFG_EXT_DMA_BURST_4word 0x1
  255. #define DWC_GAHBCFG_EXT_DMA_BURST_8word 0x2
  256. #define DWC_GAHBCFG_EXT_DMA_BURST_16word 0x3
  257. #define DWC_GAHBCFG_EXT_DMA_BURST_32word 0x4
  258. #define DWC_GAHBCFG_EXT_DMA_BURST_64word 0x5
  259. #define DWC_GAHBCFG_EXT_DMA_BURST_128word 0x6
  260. #define DWC_GAHBCFG_EXT_DMA_BURST_256word 0x7
  261. #define DEP_NUM 2
  262. #if 0
  263. #define UTMI_PHY_WIDTH 8
  264. #else
  265. #define UTMI_PHY_WIDTH 16
  266. #endif
  267. #endif /* _X1000_OTG_DWC_H_ */