core.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /**
  3. * core.h - DesignWare USB3 DRD Core Header
  4. *
  5. * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
  6. *
  7. * Authors: Felipe Balbi <balbi@ti.com>,
  8. * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  9. *
  10. * Taken from Linux Kernel v3.19-rc1 (drivers/usb/dwc3/core.h) and ported
  11. * to uboot.
  12. *
  13. * commit 460d098cb6 : usb: dwc3: make HIRD threshold configurable
  14. *
  15. */
  16. #ifndef __DRIVERS_USB_DWC3_CORE_H
  17. #define __DRIVERS_USB_DWC3_CORE_H
  18. #include <linux/bitops.h>
  19. #include <linux/ioport.h>
  20. #include <linux/usb/ch9.h>
  21. #include <linux/usb/otg.h>
  22. #define DWC3_MSG_MAX 500
  23. /* Global constants */
  24. #define DWC3_EP0_BOUNCE_SIZE 512
  25. #define DWC3_ENDPOINTS_NUM 32
  26. #define DWC3_XHCI_RESOURCES_NUM 2
  27. #define DWC3_SCRATCHBUF_SIZE 4096 /* each buffer is assumed to be 4KiB */
  28. #define DWC3_EVENT_SIZE 4 /* bytes */
  29. #define DWC3_EVENT_MAX_NUM 64 /* 2 events/endpoint */
  30. #define DWC3_EVENT_BUFFERS_SIZE (DWC3_EVENT_SIZE * DWC3_EVENT_MAX_NUM)
  31. #define DWC3_EVENT_TYPE_MASK 0xfe
  32. #define DWC3_EVENT_TYPE_DEV 0
  33. #define DWC3_EVENT_TYPE_CARKIT 3
  34. #define DWC3_EVENT_TYPE_I2C 4
  35. #define DWC3_DEVICE_EVENT_DISCONNECT 0
  36. #define DWC3_DEVICE_EVENT_RESET 1
  37. #define DWC3_DEVICE_EVENT_CONNECT_DONE 2
  38. #define DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE 3
  39. #define DWC3_DEVICE_EVENT_WAKEUP 4
  40. #define DWC3_DEVICE_EVENT_HIBER_REQ 5
  41. #define DWC3_DEVICE_EVENT_EOPF 6
  42. #define DWC3_DEVICE_EVENT_SOF 7
  43. #define DWC3_DEVICE_EVENT_ERRATIC_ERROR 9
  44. #define DWC3_DEVICE_EVENT_CMD_CMPL 10
  45. #define DWC3_DEVICE_EVENT_OVERFLOW 11
  46. #define DWC3_GEVNTCOUNT_MASK 0xfffc
  47. #define DWC3_GSNPSID_MASK 0xffff0000
  48. #define DWC3_GSNPSREV_MASK 0xffff
  49. /* DWC3 registers memory space boundries */
  50. #define DWC3_XHCI_REGS_START 0x0
  51. #define DWC3_XHCI_REGS_END 0x7fff
  52. #define DWC3_GLOBALS_REGS_START 0xc100
  53. #define DWC3_GLOBALS_REGS_END 0xc6ff
  54. #define DWC3_DEVICE_REGS_START 0xc700
  55. #define DWC3_DEVICE_REGS_END 0xcbff
  56. #define DWC3_OTG_REGS_START 0xcc00
  57. #define DWC3_OTG_REGS_END 0xccff
  58. /* Global Registers */
  59. #define DWC3_GSBUSCFG0 0xc100
  60. #define DWC3_GSBUSCFG1 0xc104
  61. #define DWC3_GTXTHRCFG 0xc108
  62. #define DWC3_GRXTHRCFG 0xc10c
  63. #define DWC3_GCTL 0xc110
  64. #define DWC3_GEVTEN 0xc114
  65. #define DWC3_GSTS 0xc118
  66. #define DWC3_GSNPSID 0xc120
  67. #define DWC3_GGPIO 0xc124
  68. #define DWC3_GUID 0xc128
  69. #define DWC3_GUCTL 0xc12c
  70. #define DWC3_GBUSERRADDR0 0xc130
  71. #define DWC3_GBUSERRADDR1 0xc134
  72. #define DWC3_GPRTBIMAP0 0xc138
  73. #define DWC3_GPRTBIMAP1 0xc13c
  74. #define DWC3_GHWPARAMS0 0xc140
  75. #define DWC3_GHWPARAMS1 0xc144
  76. #define DWC3_GHWPARAMS2 0xc148
  77. #define DWC3_GHWPARAMS3 0xc14c
  78. #define DWC3_GHWPARAMS4 0xc150
  79. #define DWC3_GHWPARAMS5 0xc154
  80. #define DWC3_GHWPARAMS6 0xc158
  81. #define DWC3_GHWPARAMS7 0xc15c
  82. #define DWC3_GDBGFIFOSPACE 0xc160
  83. #define DWC3_GDBGLTSSM 0xc164
  84. #define DWC3_GPRTBIMAP_HS0 0xc180
  85. #define DWC3_GPRTBIMAP_HS1 0xc184
  86. #define DWC3_GPRTBIMAP_FS0 0xc188
  87. #define DWC3_GPRTBIMAP_FS1 0xc18c
  88. #define DWC3_GUSB2PHYCFG(n) (0xc200 + (n * 0x04))
  89. #define DWC3_GUSB2I2CCTL(n) (0xc240 + (n * 0x04))
  90. #define DWC3_GUSB2PHYACC(n) (0xc280 + (n * 0x04))
  91. #define DWC3_GUSB3PIPECTL(n) (0xc2c0 + (n * 0x04))
  92. #define DWC3_GTXFIFOSIZ(n) (0xc300 + (n * 0x04))
  93. #define DWC3_GRXFIFOSIZ(n) (0xc380 + (n * 0x04))
  94. #define DWC3_GEVNTADRLO(n) (0xc400 + (n * 0x10))
  95. #define DWC3_GEVNTADRHI(n) (0xc404 + (n * 0x10))
  96. #define DWC3_GEVNTSIZ(n) (0xc408 + (n * 0x10))
  97. #define DWC3_GEVNTCOUNT(n) (0xc40c + (n * 0x10))
  98. #define DWC3_GHWPARAMS8 0xc600
  99. /* Device Registers */
  100. #define DWC3_DCFG 0xc700
  101. #define DWC3_DCTL 0xc704
  102. #define DWC3_DEVTEN 0xc708
  103. #define DWC3_DSTS 0xc70c
  104. #define DWC3_DGCMDPAR 0xc710
  105. #define DWC3_DGCMD 0xc714
  106. #define DWC3_DALEPENA 0xc720
  107. #define DWC3_DEPCMDPAR2(n) (0xc800 + (n * 0x10))
  108. #define DWC3_DEPCMDPAR1(n) (0xc804 + (n * 0x10))
  109. #define DWC3_DEPCMDPAR0(n) (0xc808 + (n * 0x10))
  110. #define DWC3_DEPCMD(n) (0xc80c + (n * 0x10))
  111. /* OTG Registers */
  112. #define DWC3_OCFG 0xcc00
  113. #define DWC3_OCTL 0xcc04
  114. #define DWC3_OEVT 0xcc08
  115. #define DWC3_OEVTEN 0xcc0C
  116. #define DWC3_OSTS 0xcc10
  117. /* Bit fields */
  118. /* Global Configuration Register */
  119. #define DWC3_GCTL_PWRDNSCALE(n) ((n) << 19)
  120. #define DWC3_GCTL_U2RSTECN (1 << 16)
  121. #define DWC3_GCTL_RAMCLKSEL(x) (((x) & DWC3_GCTL_CLK_MASK) << 6)
  122. #define DWC3_GCTL_CLK_BUS (0)
  123. #define DWC3_GCTL_CLK_PIPE (1)
  124. #define DWC3_GCTL_CLK_PIPEHALF (2)
  125. #define DWC3_GCTL_CLK_MASK (3)
  126. #define DWC3_GCTL_PRTCAP(n) (((n) & (3 << 12)) >> 12)
  127. #define DWC3_GCTL_PRTCAPDIR(n) ((n) << 12)
  128. #define DWC3_GCTL_PRTCAP_HOST 1
  129. #define DWC3_GCTL_PRTCAP_DEVICE 2
  130. #define DWC3_GCTL_PRTCAP_OTG 3
  131. #define DWC3_GCTL_CORESOFTRESET (1 << 11)
  132. #define DWC3_GCTL_SOFITPSYNC (1 << 10)
  133. #define DWC3_GCTL_SCALEDOWN(n) ((n) << 4)
  134. #define DWC3_GCTL_SCALEDOWN_MASK DWC3_GCTL_SCALEDOWN(3)
  135. #define DWC3_GCTL_DISSCRAMBLE (1 << 3)
  136. #define DWC3_GCTL_U2EXIT_LFPS (1 << 2)
  137. #define DWC3_GCTL_GBLHIBERNATIONEN (1 << 1)
  138. #define DWC3_GCTL_DSBLCLKGTNG (1 << 0)
  139. /* Global USB2 PHY Configuration Register */
  140. #define DWC3_GUSB2PHYCFG_PHYSOFTRST (1 << 31)
  141. #define DWC3_GUSB2PHYCFG_U2_FREECLK_EXISTS (1 << 30)
  142. #define DWC3_GUSB2PHYCFG_SUSPHY (1 << 6)
  143. #define DWC3_GUSB2PHYCFG_ENBLSLPM (1 << 8)
  144. #define DWC3_GUSB2PHYCFG_PHYIF(n) ((n) << 3)
  145. #define DWC3_GUSB2PHYCFG_PHYIF_MASK DWC3_GUSB2PHYCFG_PHYIF(1)
  146. #define DWC3_GUSB2PHYCFG_USBTRDTIM(n) ((n) << 10)
  147. #define DWC3_GUSB2PHYCFG_USBTRDTIM_MASK DWC3_GUSB2PHYCFG_USBTRDTIM(0xf)
  148. #define USBTRDTIM_UTMI_8_BIT 9
  149. #define USBTRDTIM_UTMI_16_BIT 5
  150. #define UTMI_PHYIF_16_BIT 1
  151. #define UTMI_PHYIF_8_BIT 0
  152. /* Global USB3 PIPE Control Register */
  153. #define DWC3_GUSB3PIPECTL_PHYSOFTRST (1 << 31)
  154. #define DWC3_GUSB3PIPECTL_U2SSINP3OK (1 << 29)
  155. #define DWC3_GUSB3PIPECTL_REQP1P2P3 (1 << 24)
  156. #define DWC3_GUSB3PIPECTL_DEP1P2P3(n) ((n) << 19)
  157. #define DWC3_GUSB3PIPECTL_DEP1P2P3_MASK DWC3_GUSB3PIPECTL_DEP1P2P3(7)
  158. #define DWC3_GUSB3PIPECTL_DEP1P2P3_EN DWC3_GUSB3PIPECTL_DEP1P2P3(1)
  159. #define DWC3_GUSB3PIPECTL_DEPOCHANGE (1 << 18)
  160. #define DWC3_GUSB3PIPECTL_SUSPHY (1 << 17)
  161. #define DWC3_GUSB3PIPECTL_LFPSFILT (1 << 9)
  162. #define DWC3_GUSB3PIPECTL_RX_DETOPOLL (1 << 8)
  163. #define DWC3_GUSB3PIPECTL_TX_DEEPH_MASK DWC3_GUSB3PIPECTL_TX_DEEPH(3)
  164. #define DWC3_GUSB3PIPECTL_TX_DEEPH(n) ((n) << 1)
  165. /* Global TX Fifo Size Register */
  166. #define DWC3_GTXFIFOSIZ_TXFDEF(n) ((n) & 0xffff)
  167. #define DWC3_GTXFIFOSIZ_TXFSTADDR(n) ((n) & 0xffff0000)
  168. /* Global Event Size Registers */
  169. #define DWC3_GEVNTSIZ_INTMASK (1 << 31)
  170. #define DWC3_GEVNTSIZ_SIZE(n) ((n) & 0xffff)
  171. /* Global HWPARAMS1 Register */
  172. #define DWC3_GHWPARAMS1_EN_PWROPT(n) (((n) & (3 << 24)) >> 24)
  173. #define DWC3_GHWPARAMS1_EN_PWROPT_NO 0
  174. #define DWC3_GHWPARAMS1_EN_PWROPT_CLK 1
  175. #define DWC3_GHWPARAMS1_EN_PWROPT_HIB 2
  176. #define DWC3_GHWPARAMS1_PWROPT(n) ((n) << 24)
  177. #define DWC3_GHWPARAMS1_PWROPT_MASK DWC3_GHWPARAMS1_PWROPT(3)
  178. /* Global HWPARAMS3 Register */
  179. #define DWC3_GHWPARAMS3_SSPHY_IFC(n) ((n) & 3)
  180. #define DWC3_GHWPARAMS3_SSPHY_IFC_DIS 0
  181. #define DWC3_GHWPARAMS3_SSPHY_IFC_ENA 1
  182. #define DWC3_GHWPARAMS3_HSPHY_IFC(n) (((n) & (3 << 2)) >> 2)
  183. #define DWC3_GHWPARAMS3_HSPHY_IFC_DIS 0
  184. #define DWC3_GHWPARAMS3_HSPHY_IFC_UTMI 1
  185. #define DWC3_GHWPARAMS3_HSPHY_IFC_ULPI 2
  186. #define DWC3_GHWPARAMS3_HSPHY_IFC_UTMI_ULPI 3
  187. #define DWC3_GHWPARAMS3_FSPHY_IFC(n) (((n) & (3 << 4)) >> 4)
  188. #define DWC3_GHWPARAMS3_FSPHY_IFC_DIS 0
  189. #define DWC3_GHWPARAMS3_FSPHY_IFC_ENA 1
  190. /* Global HWPARAMS4 Register */
  191. #define DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(n) (((n) & (0x0f << 13)) >> 13)
  192. #define DWC3_MAX_HIBER_SCRATCHBUFS 15
  193. /* Global HWPARAMS6 Register */
  194. #define DWC3_GHWPARAMS6_EN_FPGA (1 << 7)
  195. /* Device Configuration Register */
  196. #define DWC3_DCFG_DEVADDR(addr) ((addr) << 3)
  197. #define DWC3_DCFG_DEVADDR_MASK DWC3_DCFG_DEVADDR(0x7f)
  198. #define DWC3_DCFG_SPEED_MASK (7 << 0)
  199. #define DWC3_DCFG_SUPERSPEED (4 << 0)
  200. #define DWC3_DCFG_HIGHSPEED (0 << 0)
  201. #define DWC3_DCFG_FULLSPEED2 (1 << 0)
  202. #define DWC3_DCFG_LOWSPEED (2 << 0)
  203. #define DWC3_DCFG_FULLSPEED1 (3 << 0)
  204. #define DWC3_DCFG_LPM_CAP (1 << 22)
  205. /* Device Control Register */
  206. #define DWC3_DCTL_RUN_STOP (1 << 31)
  207. #define DWC3_DCTL_CSFTRST (1 << 30)
  208. #define DWC3_DCTL_LSFTRST (1 << 29)
  209. #define DWC3_DCTL_HIRD_THRES_MASK (0x1f << 24)
  210. #define DWC3_DCTL_HIRD_THRES(n) ((n) << 24)
  211. #define DWC3_DCTL_APPL1RES (1 << 23)
  212. /* These apply for core versions 1.87a and earlier */
  213. #define DWC3_DCTL_TRGTULST_MASK (0x0f << 17)
  214. #define DWC3_DCTL_TRGTULST(n) ((n) << 17)
  215. #define DWC3_DCTL_TRGTULST_U2 (DWC3_DCTL_TRGTULST(2))
  216. #define DWC3_DCTL_TRGTULST_U3 (DWC3_DCTL_TRGTULST(3))
  217. #define DWC3_DCTL_TRGTULST_SS_DIS (DWC3_DCTL_TRGTULST(4))
  218. #define DWC3_DCTL_TRGTULST_RX_DET (DWC3_DCTL_TRGTULST(5))
  219. #define DWC3_DCTL_TRGTULST_SS_INACT (DWC3_DCTL_TRGTULST(6))
  220. /* These apply for core versions 1.94a and later */
  221. #define DWC3_DCTL_LPM_ERRATA_MASK DWC3_DCTL_LPM_ERRATA(0xf)
  222. #define DWC3_DCTL_LPM_ERRATA(n) ((n) << 20)
  223. #define DWC3_DCTL_KEEP_CONNECT (1 << 19)
  224. #define DWC3_DCTL_L1_HIBER_EN (1 << 18)
  225. #define DWC3_DCTL_CRS (1 << 17)
  226. #define DWC3_DCTL_CSS (1 << 16)
  227. #define DWC3_DCTL_INITU2ENA (1 << 12)
  228. #define DWC3_DCTL_ACCEPTU2ENA (1 << 11)
  229. #define DWC3_DCTL_INITU1ENA (1 << 10)
  230. #define DWC3_DCTL_ACCEPTU1ENA (1 << 9)
  231. #define DWC3_DCTL_TSTCTRL_MASK (0xf << 1)
  232. #define DWC3_DCTL_ULSTCHNGREQ_MASK (0x0f << 5)
  233. #define DWC3_DCTL_ULSTCHNGREQ(n) (((n) << 5) & DWC3_DCTL_ULSTCHNGREQ_MASK)
  234. #define DWC3_DCTL_ULSTCHNG_NO_ACTION (DWC3_DCTL_ULSTCHNGREQ(0))
  235. #define DWC3_DCTL_ULSTCHNG_SS_DISABLED (DWC3_DCTL_ULSTCHNGREQ(4))
  236. #define DWC3_DCTL_ULSTCHNG_RX_DETECT (DWC3_DCTL_ULSTCHNGREQ(5))
  237. #define DWC3_DCTL_ULSTCHNG_SS_INACTIVE (DWC3_DCTL_ULSTCHNGREQ(6))
  238. #define DWC3_DCTL_ULSTCHNG_RECOVERY (DWC3_DCTL_ULSTCHNGREQ(8))
  239. #define DWC3_DCTL_ULSTCHNG_COMPLIANCE (DWC3_DCTL_ULSTCHNGREQ(10))
  240. #define DWC3_DCTL_ULSTCHNG_LOOPBACK (DWC3_DCTL_ULSTCHNGREQ(11))
  241. /* Device Event Enable Register */
  242. #define DWC3_DEVTEN_VNDRDEVTSTRCVEDEN (1 << 12)
  243. #define DWC3_DEVTEN_EVNTOVERFLOWEN (1 << 11)
  244. #define DWC3_DEVTEN_CMDCMPLTEN (1 << 10)
  245. #define DWC3_DEVTEN_ERRTICERREN (1 << 9)
  246. #define DWC3_DEVTEN_SOFEN (1 << 7)
  247. #define DWC3_DEVTEN_EOPFEN (1 << 6)
  248. #define DWC3_DEVTEN_HIBERNATIONREQEVTEN (1 << 5)
  249. #define DWC3_DEVTEN_WKUPEVTEN (1 << 4)
  250. #define DWC3_DEVTEN_ULSTCNGEN (1 << 3)
  251. #define DWC3_DEVTEN_CONNECTDONEEN (1 << 2)
  252. #define DWC3_DEVTEN_USBRSTEN (1 << 1)
  253. #define DWC3_DEVTEN_DISCONNEVTEN (1 << 0)
  254. /* Device Status Register */
  255. #define DWC3_DSTS_DCNRD (1 << 29)
  256. /* This applies for core versions 1.87a and earlier */
  257. #define DWC3_DSTS_PWRUPREQ (1 << 24)
  258. /* These apply for core versions 1.94a and later */
  259. #define DWC3_DSTS_RSS (1 << 25)
  260. #define DWC3_DSTS_SSS (1 << 24)
  261. #define DWC3_DSTS_COREIDLE (1 << 23)
  262. #define DWC3_DSTS_DEVCTRLHLT (1 << 22)
  263. #define DWC3_DSTS_USBLNKST_MASK (0x0f << 18)
  264. #define DWC3_DSTS_USBLNKST(n) (((n) & DWC3_DSTS_USBLNKST_MASK) >> 18)
  265. #define DWC3_DSTS_RXFIFOEMPTY (1 << 17)
  266. #define DWC3_DSTS_SOFFN_MASK (0x3fff << 3)
  267. #define DWC3_DSTS_SOFFN(n) (((n) & DWC3_DSTS_SOFFN_MASK) >> 3)
  268. #define DWC3_DSTS_CONNECTSPD (7 << 0)
  269. #define DWC3_DSTS_SUPERSPEED (4 << 0)
  270. #define DWC3_DSTS_HIGHSPEED (0 << 0)
  271. #define DWC3_DSTS_FULLSPEED2 (1 << 0)
  272. #define DWC3_DSTS_LOWSPEED (2 << 0)
  273. #define DWC3_DSTS_FULLSPEED1 (3 << 0)
  274. /* Device Generic Command Register */
  275. #define DWC3_DGCMD_SET_LMP 0x01
  276. #define DWC3_DGCMD_SET_PERIODIC_PAR 0x02
  277. #define DWC3_DGCMD_XMIT_FUNCTION 0x03
  278. /* These apply for core versions 1.94a and later */
  279. #define DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO 0x04
  280. #define DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI 0x05
  281. #define DWC3_DGCMD_SELECTED_FIFO_FLUSH 0x09
  282. #define DWC3_DGCMD_ALL_FIFO_FLUSH 0x0a
  283. #define DWC3_DGCMD_SET_ENDPOINT_NRDY 0x0c
  284. #define DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK 0x10
  285. #define DWC3_DGCMD_STATUS(n) (((n) >> 15) & 1)
  286. #define DWC3_DGCMD_CMDACT (1 << 10)
  287. #define DWC3_DGCMD_CMDIOC (1 << 8)
  288. /* Device Generic Command Parameter Register */
  289. #define DWC3_DGCMDPAR_FORCE_LINKPM_ACCEPT (1 << 0)
  290. #define DWC3_DGCMDPAR_FIFO_NUM(n) ((n) << 0)
  291. #define DWC3_DGCMDPAR_RX_FIFO (0 << 5)
  292. #define DWC3_DGCMDPAR_TX_FIFO (1 << 5)
  293. #define DWC3_DGCMDPAR_LOOPBACK_DIS (0 << 0)
  294. #define DWC3_DGCMDPAR_LOOPBACK_ENA (1 << 0)
  295. /* Device Endpoint Command Register */
  296. #define DWC3_DEPCMD_PARAM_SHIFT 16
  297. #define DWC3_DEPCMD_PARAM(x) ((x) << DWC3_DEPCMD_PARAM_SHIFT)
  298. #define DWC3_DEPCMD_GET_RSC_IDX(x) (((x) >> DWC3_DEPCMD_PARAM_SHIFT) & 0x7f)
  299. #define DWC3_DEPCMD_STATUS(x) (((x) >> 15) & 1)
  300. #define DWC3_DEPCMD_HIPRI_FORCERM (1 << 11)
  301. #define DWC3_DEPCMD_CMDACT (1 << 10)
  302. #define DWC3_DEPCMD_CMDIOC (1 << 8)
  303. #define DWC3_DEPCMD_DEPSTARTCFG (0x09 << 0)
  304. #define DWC3_DEPCMD_ENDTRANSFER (0x08 << 0)
  305. #define DWC3_DEPCMD_UPDATETRANSFER (0x07 << 0)
  306. #define DWC3_DEPCMD_STARTTRANSFER (0x06 << 0)
  307. #define DWC3_DEPCMD_CLEARSTALL (0x05 << 0)
  308. #define DWC3_DEPCMD_SETSTALL (0x04 << 0)
  309. /* This applies for core versions 1.90a and earlier */
  310. #define DWC3_DEPCMD_GETSEQNUMBER (0x03 << 0)
  311. /* This applies for core versions 1.94a and later */
  312. #define DWC3_DEPCMD_GETEPSTATE (0x03 << 0)
  313. #define DWC3_DEPCMD_SETTRANSFRESOURCE (0x02 << 0)
  314. #define DWC3_DEPCMD_SETEPCONFIG (0x01 << 0)
  315. /* The EP number goes 0..31 so ep0 is always out and ep1 is always in */
  316. #define DWC3_DALEPENA_EP(n) (1 << n)
  317. #define DWC3_DEPCMD_TYPE_CONTROL 0
  318. #define DWC3_DEPCMD_TYPE_ISOC 1
  319. #define DWC3_DEPCMD_TYPE_BULK 2
  320. #define DWC3_DEPCMD_TYPE_INTR 3
  321. /* Structures */
  322. struct dwc3_trb;
  323. /**
  324. * struct dwc3_event_buffer - Software event buffer representation
  325. * @buf: _THE_ buffer
  326. * @length: size of this buffer
  327. * @lpos: event offset
  328. * @count: cache of last read event count register
  329. * @flags: flags related to this event buffer
  330. * @dma: dma_addr_t
  331. * @dwc: pointer to DWC controller
  332. */
  333. struct dwc3_event_buffer {
  334. void *buf;
  335. unsigned length;
  336. unsigned int lpos;
  337. unsigned int count;
  338. unsigned int flags;
  339. #define DWC3_EVENT_PENDING (1UL << 0)
  340. dma_addr_t dma;
  341. struct dwc3 *dwc;
  342. };
  343. #define DWC3_EP_FLAG_STALLED (1 << 0)
  344. #define DWC3_EP_FLAG_WEDGED (1 << 1)
  345. #define DWC3_EP_DIRECTION_TX true
  346. #define DWC3_EP_DIRECTION_RX false
  347. #define DWC3_TRB_NUM 32
  348. #define DWC3_TRB_MASK (DWC3_TRB_NUM - 1)
  349. /**
  350. * struct dwc3_ep - device side endpoint representation
  351. * @endpoint: usb endpoint
  352. * @request_list: list of requests for this endpoint
  353. * @req_queued: list of requests on this ep which have TRBs setup
  354. * @trb_pool: array of transaction buffers
  355. * @trb_pool_dma: dma address of @trb_pool
  356. * @free_slot: next slot which is going to be used
  357. * @busy_slot: first slot which is owned by HW
  358. * @desc: usb_endpoint_descriptor pointer
  359. * @dwc: pointer to DWC controller
  360. * @saved_state: ep state saved during hibernation
  361. * @flags: endpoint flags (wedged, stalled, ...)
  362. * @current_trb: index of current used trb
  363. * @number: endpoint number (1 - 15)
  364. * @type: set to bmAttributes & USB_ENDPOINT_XFERTYPE_MASK
  365. * @resource_index: Resource transfer index
  366. * @interval: the interval on which the ISOC transfer is started
  367. * @name: a human readable name e.g. ep1out-bulk
  368. * @direction: true for TX, false for RX
  369. * @stream_capable: true when streams are enabled
  370. */
  371. struct dwc3_ep {
  372. struct usb_ep endpoint;
  373. struct list_head request_list;
  374. struct list_head req_queued;
  375. struct dwc3_trb *trb_pool;
  376. dma_addr_t trb_pool_dma;
  377. u32 free_slot;
  378. u32 busy_slot;
  379. const struct usb_ss_ep_comp_descriptor *comp_desc;
  380. struct dwc3 *dwc;
  381. u32 saved_state;
  382. unsigned flags;
  383. #define DWC3_EP_ENABLED (1 << 0)
  384. #define DWC3_EP_STALL (1 << 1)
  385. #define DWC3_EP_WEDGE (1 << 2)
  386. #define DWC3_EP_BUSY (1 << 4)
  387. #define DWC3_EP_PENDING_REQUEST (1 << 5)
  388. #define DWC3_EP_MISSED_ISOC (1 << 6)
  389. /* This last one is specific to EP0 */
  390. #define DWC3_EP0_DIR_IN (1 << 31)
  391. unsigned current_trb;
  392. u8 number;
  393. u8 type;
  394. u8 resource_index;
  395. u32 interval;
  396. char name[20];
  397. unsigned direction:1;
  398. unsigned stream_capable:1;
  399. };
  400. enum dwc3_phy {
  401. DWC3_PHY_UNKNOWN = 0,
  402. DWC3_PHY_USB3,
  403. DWC3_PHY_USB2,
  404. };
  405. enum dwc3_ep0_next {
  406. DWC3_EP0_UNKNOWN = 0,
  407. DWC3_EP0_COMPLETE,
  408. DWC3_EP0_NRDY_DATA,
  409. DWC3_EP0_NRDY_STATUS,
  410. };
  411. enum dwc3_ep0_state {
  412. EP0_UNCONNECTED = 0,
  413. EP0_SETUP_PHASE,
  414. EP0_DATA_PHASE,
  415. EP0_STATUS_PHASE,
  416. };
  417. enum dwc3_link_state {
  418. /* In SuperSpeed */
  419. DWC3_LINK_STATE_U0 = 0x00, /* in HS, means ON */
  420. DWC3_LINK_STATE_U1 = 0x01,
  421. DWC3_LINK_STATE_U2 = 0x02, /* in HS, means SLEEP */
  422. DWC3_LINK_STATE_U3 = 0x03, /* in HS, means SUSPEND */
  423. DWC3_LINK_STATE_SS_DIS = 0x04,
  424. DWC3_LINK_STATE_RX_DET = 0x05, /* in HS, means Early Suspend */
  425. DWC3_LINK_STATE_SS_INACT = 0x06,
  426. DWC3_LINK_STATE_POLL = 0x07,
  427. DWC3_LINK_STATE_RECOV = 0x08,
  428. DWC3_LINK_STATE_HRESET = 0x09,
  429. DWC3_LINK_STATE_CMPLY = 0x0a,
  430. DWC3_LINK_STATE_LPBK = 0x0b,
  431. DWC3_LINK_STATE_RESET = 0x0e,
  432. DWC3_LINK_STATE_RESUME = 0x0f,
  433. DWC3_LINK_STATE_MASK = 0x0f,
  434. };
  435. /* TRB Length, PCM and Status */
  436. #define DWC3_TRB_SIZE_MASK (0x00ffffff)
  437. #define DWC3_TRB_SIZE_LENGTH(n) ((n) & DWC3_TRB_SIZE_MASK)
  438. #define DWC3_TRB_SIZE_PCM1(n) (((n) & 0x03) << 24)
  439. #define DWC3_TRB_SIZE_TRBSTS(n) (((n) & (0x0f << 28)) >> 28)
  440. #define DWC3_TRBSTS_OK 0
  441. #define DWC3_TRBSTS_MISSED_ISOC 1
  442. #define DWC3_TRBSTS_SETUP_PENDING 2
  443. #define DWC3_TRB_STS_XFER_IN_PROG 4
  444. /* TRB Control */
  445. #define DWC3_TRB_CTRL_HWO (1 << 0)
  446. #define DWC3_TRB_CTRL_LST (1 << 1)
  447. #define DWC3_TRB_CTRL_CHN (1 << 2)
  448. #define DWC3_TRB_CTRL_CSP (1 << 3)
  449. #define DWC3_TRB_CTRL_TRBCTL(n) (((n) & 0x3f) << 4)
  450. #define DWC3_TRB_CTRL_ISP_IMI (1 << 10)
  451. #define DWC3_TRB_CTRL_IOC (1 << 11)
  452. #define DWC3_TRB_CTRL_SID_SOFN(n) (((n) & 0xffff) << 14)
  453. #define DWC3_TRBCTL_NORMAL DWC3_TRB_CTRL_TRBCTL(1)
  454. #define DWC3_TRBCTL_CONTROL_SETUP DWC3_TRB_CTRL_TRBCTL(2)
  455. #define DWC3_TRBCTL_CONTROL_STATUS2 DWC3_TRB_CTRL_TRBCTL(3)
  456. #define DWC3_TRBCTL_CONTROL_STATUS3 DWC3_TRB_CTRL_TRBCTL(4)
  457. #define DWC3_TRBCTL_CONTROL_DATA DWC3_TRB_CTRL_TRBCTL(5)
  458. #define DWC3_TRBCTL_ISOCHRONOUS_FIRST DWC3_TRB_CTRL_TRBCTL(6)
  459. #define DWC3_TRBCTL_ISOCHRONOUS DWC3_TRB_CTRL_TRBCTL(7)
  460. #define DWC3_TRBCTL_LINK_TRB DWC3_TRB_CTRL_TRBCTL(8)
  461. /**
  462. * struct dwc3_trb - transfer request block (hw format)
  463. * @bpl: DW0-3
  464. * @bph: DW4-7
  465. * @size: DW8-B
  466. * @trl: DWC-F
  467. */
  468. struct dwc3_trb {
  469. u32 bpl;
  470. u32 bph;
  471. u32 size;
  472. u32 ctrl;
  473. } __packed;
  474. /**
  475. * dwc3_hwparams - copy of HWPARAMS registers
  476. * @hwparams0 - GHWPARAMS0
  477. * @hwparams1 - GHWPARAMS1
  478. * @hwparams2 - GHWPARAMS2
  479. * @hwparams3 - GHWPARAMS3
  480. * @hwparams4 - GHWPARAMS4
  481. * @hwparams5 - GHWPARAMS5
  482. * @hwparams6 - GHWPARAMS6
  483. * @hwparams7 - GHWPARAMS7
  484. * @hwparams8 - GHWPARAMS8
  485. */
  486. struct dwc3_hwparams {
  487. u32 hwparams0;
  488. u32 hwparams1;
  489. u32 hwparams2;
  490. u32 hwparams3;
  491. u32 hwparams4;
  492. u32 hwparams5;
  493. u32 hwparams6;
  494. u32 hwparams7;
  495. u32 hwparams8;
  496. };
  497. /* HWPARAMS0 */
  498. #define DWC3_MODE(n) ((n) & 0x7)
  499. #define DWC3_MDWIDTH(n) (((n) & 0xff00) >> 8)
  500. /* HWPARAMS1 */
  501. #define DWC3_NUM_INT(n) (((n) & (0x3f << 15)) >> 15)
  502. /* HWPARAMS3 */
  503. #define DWC3_NUM_IN_EPS_MASK (0x1f << 18)
  504. #define DWC3_NUM_EPS_MASK (0x3f << 12)
  505. #define DWC3_NUM_EPS(p) (((p)->hwparams3 & \
  506. (DWC3_NUM_EPS_MASK)) >> 12)
  507. #define DWC3_NUM_IN_EPS(p) (((p)->hwparams3 & \
  508. (DWC3_NUM_IN_EPS_MASK)) >> 18)
  509. /* HWPARAMS7 */
  510. #define DWC3_RAM1_DEPTH(n) ((n) & 0xffff)
  511. struct dwc3_request {
  512. struct usb_request request;
  513. struct list_head list;
  514. struct dwc3_ep *dep;
  515. u32 start_slot;
  516. u8 epnum;
  517. struct dwc3_trb *trb;
  518. dma_addr_t trb_dma;
  519. unsigned direction:1;
  520. unsigned mapped:1;
  521. unsigned queued:1;
  522. };
  523. /*
  524. * struct dwc3_scratchpad_array - hibernation scratchpad array
  525. * (format defined by hw)
  526. */
  527. struct dwc3_scratchpad_array {
  528. __le64 dma_adr[DWC3_MAX_HIBER_SCRATCHBUFS];
  529. };
  530. /**
  531. * struct dwc3 - representation of our controller
  532. * @ctrl_req: usb control request which is used for ep0
  533. * @ep0_trb: trb which is used for the ctrl_req
  534. * @ep0_bounce: bounce buffer for ep0
  535. * @setup_buf: used while precessing STD USB requests
  536. * @ctrl_req_addr: dma address of ctrl_req
  537. * @ep0_trb: dma address of ep0_trb
  538. * @ep0_usb_req: dummy req used while handling STD USB requests
  539. * @ep0_bounce_addr: dma address of ep0_bounce
  540. * @scratch_addr: dma address of scratchbuf
  541. * @lock: for synchronizing
  542. * @dev: pointer to our struct device
  543. * @xhci: pointer to our xHCI child
  544. * @event_buffer_list: a list of event buffers
  545. * @gadget: device side representation of the peripheral controller
  546. * @gadget_driver: pointer to the gadget driver
  547. * @regs: base address for our registers
  548. * @regs_size: address space size
  549. * @nr_scratch: number of scratch buffers
  550. * @num_event_buffers: calculated number of event buffers
  551. * @u1u2: only used on revisions <1.83a for workaround
  552. * @maximum_speed: maximum speed requested (mainly for testing purposes)
  553. * @revision: revision register contents
  554. * @dr_mode: requested mode of operation
  555. * @dcfg: saved contents of DCFG register
  556. * @gctl: saved contents of GCTL register
  557. * @isoch_delay: wValue from Set Isochronous Delay request;
  558. * @u2sel: parameter from Set SEL request.
  559. * @u2pel: parameter from Set SEL request.
  560. * @u1sel: parameter from Set SEL request.
  561. * @u1pel: parameter from Set SEL request.
  562. * @num_out_eps: number of out endpoints
  563. * @num_in_eps: number of in endpoints
  564. * @ep0_next_event: hold the next expected event
  565. * @ep0state: state of endpoint zero
  566. * @link_state: link state
  567. * @speed: device speed (super, high, full, low)
  568. * @mem: points to start of memory which is used for this struct.
  569. * @hwparams: copy of hwparams registers
  570. * @root: debugfs root folder pointer
  571. * @regset: debugfs pointer to regdump file
  572. * @test_mode: true when we're entering a USB test mode
  573. * @test_mode_nr: test feature selector
  574. * @lpm_nyet_threshold: LPM NYET response threshold
  575. * @hird_threshold: HIRD threshold
  576. * @delayed_status: true when gadget driver asks for delayed status
  577. * @ep0_bounced: true when we used bounce buffer
  578. * @ep0_expect_in: true when we expect a DATA IN transfer
  579. * @has_hibernation: true when dwc3 was configured with Hibernation
  580. * @has_lpm_erratum: true when core was configured with LPM Erratum. Note that
  581. * there's now way for software to detect this in runtime.
  582. * @is_utmi_l1_suspend: the core asserts output signal
  583. * 0 - utmi_sleep_n
  584. * 1 - utmi_l1_suspend_n
  585. * @is_selfpowered: true when we are selfpowered
  586. * @is_fpga: true when we are using the FPGA board
  587. * @needs_fifo_resize: not all users might want fifo resizing, flag it
  588. * @pullups_connected: true when Run/Stop bit is set
  589. * @resize_fifos: tells us it's ok to reconfigure our TxFIFO sizes.
  590. * @setup_packet_pending: true when there's a Setup Packet in FIFO. Workaround
  591. * @start_config_issued: true when StartConfig command has been issued
  592. * @three_stage_setup: set if we perform a three phase setup
  593. * @disable_scramble_quirk: set if we enable the disable scramble quirk
  594. * @u2exit_lfps_quirk: set if we enable u2exit lfps quirk
  595. * @u2ss_inp3_quirk: set if we enable P3 OK for U2/SS Inactive quirk
  596. * @req_p1p2p3_quirk: set if we enable request p1p2p3 quirk
  597. * @del_p1p2p3_quirk: set if we enable delay p1p2p3 quirk
  598. * @del_phy_power_chg_quirk: set if we enable delay phy power change quirk
  599. * @lfps_filter_quirk: set if we enable LFPS filter quirk
  600. * @rx_detect_poll_quirk: set if we enable rx_detect to polling lfps quirk
  601. * @dis_u3_susphy_quirk: set if we disable usb3 suspend phy
  602. * @dis_u2_susphy_quirk: set if we disable usb2 suspend phy
  603. * @tx_de_emphasis_quirk: set if we enable Tx de-emphasis quirk
  604. * @tx_de_emphasis: Tx de-emphasis value
  605. * 0 - -6dB de-emphasis
  606. * 1 - -3.5dB de-emphasis
  607. * 2 - No de-emphasis
  608. * 3 - Reserved
  609. * @index: index of _this_ controller
  610. * @list: to maintain the list of dwc3 controllers
  611. */
  612. struct dwc3 {
  613. struct usb_ctrlrequest *ctrl_req;
  614. struct dwc3_trb *ep0_trb;
  615. void *ep0_bounce;
  616. void *scratchbuf;
  617. u8 *setup_buf;
  618. dma_addr_t ctrl_req_addr;
  619. dma_addr_t ep0_trb_addr;
  620. dma_addr_t ep0_bounce_addr;
  621. dma_addr_t scratch_addr;
  622. struct dwc3_request ep0_usb_req;
  623. /* device lock */
  624. spinlock_t lock;
  625. #if defined(__UBOOT__) && CONFIG_IS_ENABLED(DM_USB)
  626. struct udevice *dev;
  627. #else
  628. struct device *dev;
  629. #endif
  630. struct platform_device *xhci;
  631. struct resource xhci_resources[DWC3_XHCI_RESOURCES_NUM];
  632. struct dwc3_event_buffer **ev_buffs;
  633. struct dwc3_ep *eps[DWC3_ENDPOINTS_NUM];
  634. struct usb_gadget gadget;
  635. struct usb_gadget_driver *gadget_driver;
  636. void __iomem *regs;
  637. size_t regs_size;
  638. enum usb_dr_mode dr_mode;
  639. /* used for suspend/resume */
  640. u32 dcfg;
  641. u32 gctl;
  642. u32 nr_scratch;
  643. u32 num_event_buffers;
  644. u32 u1u2;
  645. u32 maximum_speed;
  646. u32 revision;
  647. #define DWC3_REVISION_173A 0x5533173a
  648. #define DWC3_REVISION_175A 0x5533175a
  649. #define DWC3_REVISION_180A 0x5533180a
  650. #define DWC3_REVISION_183A 0x5533183a
  651. #define DWC3_REVISION_185A 0x5533185a
  652. #define DWC3_REVISION_187A 0x5533187a
  653. #define DWC3_REVISION_188A 0x5533188a
  654. #define DWC3_REVISION_190A 0x5533190a
  655. #define DWC3_REVISION_194A 0x5533194a
  656. #define DWC3_REVISION_200A 0x5533200a
  657. #define DWC3_REVISION_202A 0x5533202a
  658. #define DWC3_REVISION_210A 0x5533210a
  659. #define DWC3_REVISION_220A 0x5533220a
  660. #define DWC3_REVISION_230A 0x5533230a
  661. #define DWC3_REVISION_240A 0x5533240a
  662. #define DWC3_REVISION_250A 0x5533250a
  663. #define DWC3_REVISION_260A 0x5533260a
  664. #define DWC3_REVISION_270A 0x5533270a
  665. #define DWC3_REVISION_280A 0x5533280a
  666. enum dwc3_ep0_next ep0_next_event;
  667. enum dwc3_ep0_state ep0state;
  668. enum dwc3_link_state link_state;
  669. u16 isoch_delay;
  670. u16 u2sel;
  671. u16 u2pel;
  672. u8 u1sel;
  673. u8 u1pel;
  674. u8 speed;
  675. u8 num_out_eps;
  676. u8 num_in_eps;
  677. void *mem;
  678. struct dwc3_hwparams hwparams;
  679. struct dentry *root;
  680. struct debugfs_regset32 *regset;
  681. u8 test_mode;
  682. u8 test_mode_nr;
  683. u8 lpm_nyet_threshold;
  684. u8 hird_threshold;
  685. unsigned delayed_status:1;
  686. unsigned ep0_bounced:1;
  687. unsigned ep0_expect_in:1;
  688. unsigned has_hibernation:1;
  689. unsigned has_lpm_erratum:1;
  690. unsigned is_utmi_l1_suspend:1;
  691. unsigned is_selfpowered:1;
  692. unsigned is_fpga:1;
  693. unsigned needs_fifo_resize:1;
  694. unsigned pullups_connected:1;
  695. unsigned resize_fifos:1;
  696. unsigned setup_packet_pending:1;
  697. unsigned start_config_issued:1;
  698. unsigned three_stage_setup:1;
  699. unsigned disable_scramble_quirk:1;
  700. unsigned u2exit_lfps_quirk:1;
  701. unsigned u2ss_inp3_quirk:1;
  702. unsigned req_p1p2p3_quirk:1;
  703. unsigned del_p1p2p3_quirk:1;
  704. unsigned del_phy_power_chg_quirk:1;
  705. unsigned lfps_filter_quirk:1;
  706. unsigned rx_detect_poll_quirk:1;
  707. unsigned dis_u3_susphy_quirk:1;
  708. unsigned dis_u2_susphy_quirk:1;
  709. unsigned dis_del_phy_power_chg_quirk:1;
  710. unsigned dis_enblslpm_quirk:1;
  711. unsigned dis_u2_freeclk_exists_quirk:1;
  712. unsigned tx_de_emphasis_quirk:1;
  713. unsigned tx_de_emphasis:2;
  714. int index;
  715. struct list_head list;
  716. };
  717. /* -------------------------------------------------------------------------- */
  718. /* -------------------------------------------------------------------------- */
  719. struct dwc3_event_type {
  720. u32 is_devspec:1;
  721. u32 type:7;
  722. u32 reserved8_31:24;
  723. } __packed;
  724. #define DWC3_DEPEVT_XFERCOMPLETE 0x01
  725. #define DWC3_DEPEVT_XFERINPROGRESS 0x02
  726. #define DWC3_DEPEVT_XFERNOTREADY 0x03
  727. #define DWC3_DEPEVT_RXTXFIFOEVT 0x04
  728. #define DWC3_DEPEVT_STREAMEVT 0x06
  729. #define DWC3_DEPEVT_EPCMDCMPLT 0x07
  730. /**
  731. * dwc3_ep_event_string - returns event name
  732. * @event: then event code
  733. */
  734. static inline const char *dwc3_ep_event_string(u8 event)
  735. {
  736. switch (event) {
  737. case DWC3_DEPEVT_XFERCOMPLETE:
  738. return "Transfer Complete";
  739. case DWC3_DEPEVT_XFERINPROGRESS:
  740. return "Transfer In-Progress";
  741. case DWC3_DEPEVT_XFERNOTREADY:
  742. return "Transfer Not Ready";
  743. case DWC3_DEPEVT_RXTXFIFOEVT:
  744. return "FIFO";
  745. case DWC3_DEPEVT_STREAMEVT:
  746. return "Stream";
  747. case DWC3_DEPEVT_EPCMDCMPLT:
  748. return "Endpoint Command Complete";
  749. }
  750. return "UNKNOWN";
  751. }
  752. /**
  753. * struct dwc3_event_depvt - Device Endpoint Events
  754. * @one_bit: indicates this is an endpoint event (not used)
  755. * @endpoint_number: number of the endpoint
  756. * @endpoint_event: The event we have:
  757. * 0x00 - Reserved
  758. * 0x01 - XferComplete
  759. * 0x02 - XferInProgress
  760. * 0x03 - XferNotReady
  761. * 0x04 - RxTxFifoEvt (IN->Underrun, OUT->Overrun)
  762. * 0x05 - Reserved
  763. * 0x06 - StreamEvt
  764. * 0x07 - EPCmdCmplt
  765. * @reserved11_10: Reserved, don't use.
  766. * @status: Indicates the status of the event. Refer to databook for
  767. * more information.
  768. * @parameters: Parameters of the current event. Refer to databook for
  769. * more information.
  770. */
  771. struct dwc3_event_depevt {
  772. u32 one_bit:1;
  773. u32 endpoint_number:5;
  774. u32 endpoint_event:4;
  775. u32 reserved11_10:2;
  776. u32 status:4;
  777. /* Within XferNotReady */
  778. #define DEPEVT_STATUS_TRANSFER_ACTIVE (1 << 3)
  779. /* Within XferComplete */
  780. #define DEPEVT_STATUS_BUSERR (1 << 0)
  781. #define DEPEVT_STATUS_SHORT (1 << 1)
  782. #define DEPEVT_STATUS_IOC (1 << 2)
  783. #define DEPEVT_STATUS_LST (1 << 3)
  784. /* Stream event only */
  785. #define DEPEVT_STREAMEVT_FOUND 1
  786. #define DEPEVT_STREAMEVT_NOTFOUND 2
  787. /* Control-only Status */
  788. #define DEPEVT_STATUS_CONTROL_DATA 1
  789. #define DEPEVT_STATUS_CONTROL_STATUS 2
  790. u32 parameters:16;
  791. } __packed;
  792. /**
  793. * struct dwc3_event_devt - Device Events
  794. * @one_bit: indicates this is a non-endpoint event (not used)
  795. * @device_event: indicates it's a device event. Should read as 0x00
  796. * @type: indicates the type of device event.
  797. * 0 - DisconnEvt
  798. * 1 - USBRst
  799. * 2 - ConnectDone
  800. * 3 - ULStChng
  801. * 4 - WkUpEvt
  802. * 5 - Reserved
  803. * 6 - EOPF
  804. * 7 - SOF
  805. * 8 - Reserved
  806. * 9 - ErrticErr
  807. * 10 - CmdCmplt
  808. * 11 - EvntOverflow
  809. * 12 - VndrDevTstRcved
  810. * @reserved15_12: Reserved, not used
  811. * @event_info: Information about this event
  812. * @reserved31_25: Reserved, not used
  813. */
  814. struct dwc3_event_devt {
  815. u32 one_bit:1;
  816. u32 device_event:7;
  817. u32 type:4;
  818. u32 reserved15_12:4;
  819. u32 event_info:9;
  820. u32 reserved31_25:7;
  821. } __packed;
  822. /**
  823. * struct dwc3_event_gevt - Other Core Events
  824. * @one_bit: indicates this is a non-endpoint event (not used)
  825. * @device_event: indicates it's (0x03) Carkit or (0x04) I2C event.
  826. * @phy_port_number: self-explanatory
  827. * @reserved31_12: Reserved, not used.
  828. */
  829. struct dwc3_event_gevt {
  830. u32 one_bit:1;
  831. u32 device_event:7;
  832. u32 phy_port_number:4;
  833. u32 reserved31_12:20;
  834. } __packed;
  835. /**
  836. * union dwc3_event - representation of Event Buffer contents
  837. * @raw: raw 32-bit event
  838. * @type: the type of the event
  839. * @depevt: Device Endpoint Event
  840. * @devt: Device Event
  841. * @gevt: Global Event
  842. */
  843. union dwc3_event {
  844. u32 raw;
  845. struct dwc3_event_type type;
  846. struct dwc3_event_depevt depevt;
  847. struct dwc3_event_devt devt;
  848. struct dwc3_event_gevt gevt;
  849. };
  850. /**
  851. * struct dwc3_gadget_ep_cmd_params - representation of endpoint command
  852. * parameters
  853. * @param2: third parameter
  854. * @param1: second parameter
  855. * @param0: first parameter
  856. */
  857. struct dwc3_gadget_ep_cmd_params {
  858. u32 param2;
  859. u32 param1;
  860. u32 param0;
  861. };
  862. /*
  863. * DWC3 Features to be used as Driver Data
  864. */
  865. #define DWC3_HAS_PERIPHERAL BIT(0)
  866. #define DWC3_HAS_XHCI BIT(1)
  867. #define DWC3_HAS_OTG BIT(3)
  868. /* prototypes */
  869. int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc);
  870. void dwc3_of_parse(struct dwc3 *dwc);
  871. int dwc3_init(struct dwc3 *dwc);
  872. void dwc3_remove(struct dwc3 *dwc);
  873. static inline int dwc3_host_init(struct dwc3 *dwc)
  874. { return 0; }
  875. static inline void dwc3_host_exit(struct dwc3 *dwc)
  876. { }
  877. #ifdef CONFIG_USB_DWC3_GADGET
  878. int dwc3_gadget_init(struct dwc3 *dwc);
  879. void dwc3_gadget_exit(struct dwc3 *dwc);
  880. int dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode);
  881. int dwc3_gadget_get_link_state(struct dwc3 *dwc);
  882. int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state);
  883. int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep,
  884. unsigned cmd, struct dwc3_gadget_ep_cmd_params *params);
  885. int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned cmd, u32 param);
  886. #else
  887. static inline int dwc3_gadget_init(struct dwc3 *dwc)
  888. { return 0; }
  889. static inline void dwc3_gadget_exit(struct dwc3 *dwc)
  890. { }
  891. static inline int dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode)
  892. { return 0; }
  893. static inline int dwc3_gadget_get_link_state(struct dwc3 *dwc)
  894. { return 0; }
  895. static inline int dwc3_gadget_set_link_state(struct dwc3 *dwc,
  896. enum dwc3_link_state state)
  897. { return 0; }
  898. static inline int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep,
  899. unsigned cmd, struct dwc3_gadget_ep_cmd_params *params)
  900. { return 0; }
  901. static inline int dwc3_send_gadget_generic_command(struct dwc3 *dwc,
  902. int cmd, u32 param)
  903. { return 0; }
  904. #endif
  905. #endif /* __DRIVERS_USB_DWC3_CORE_H */