core.h 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * core.h - DesignWare USB3 DRD Core Header
  4. *
  5. * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
  6. *
  7. * Authors: Felipe Balbi <balbi@ti.com>,
  8. * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  9. */
  10. #ifndef __DRIVERS_USB_DWC3_CORE_H
  11. #define __DRIVERS_USB_DWC3_CORE_H
  12. #include <linux/device.h>
  13. #include <linux/spinlock.h>
  14. #include <linux/ioport.h>
  15. #include <linux/list.h>
  16. #include <linux/bitops.h>
  17. #include <linux/dma-mapping.h>
  18. #include <linux/mm.h>
  19. #include <linux/debugfs.h>
  20. #include <linux/wait.h>
  21. #include <linux/workqueue.h>
  22. #include <linux/usb/ch9.h>
  23. #include <linux/usb/gadget.h>
  24. #include <linux/usb/otg.h>
  25. #include <linux/ulpi/interface.h>
  26. #include <linux/phy/phy.h>
  27. #define DWC3_MSG_MAX 500
  28. /* Global constants */
  29. #define DWC3_PULL_UP_TIMEOUT 500 /* ms */
  30. #define DWC3_BOUNCE_SIZE 1024 /* size of a superspeed bulk */
  31. #define DWC3_EP0_SETUP_SIZE 512
  32. #define DWC3_ENDPOINTS_NUM 32
  33. #define DWC3_XHCI_RESOURCES_NUM 2
  34. #define DWC3_SCRATCHBUF_SIZE 4096 /* each buffer is assumed to be 4KiB */
  35. #define DWC3_EVENT_BUFFERS_SIZE 4096
  36. #define DWC3_EVENT_TYPE_MASK 0xfe
  37. #define DWC3_EVENT_TYPE_DEV 0
  38. #define DWC3_EVENT_TYPE_CARKIT 3
  39. #define DWC3_EVENT_TYPE_I2C 4
  40. #define DWC3_DEVICE_EVENT_DISCONNECT 0
  41. #define DWC3_DEVICE_EVENT_RESET 1
  42. #define DWC3_DEVICE_EVENT_CONNECT_DONE 2
  43. #define DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE 3
  44. #define DWC3_DEVICE_EVENT_WAKEUP 4
  45. #define DWC3_DEVICE_EVENT_HIBER_REQ 5
  46. #define DWC3_DEVICE_EVENT_EOPF 6
  47. #define DWC3_DEVICE_EVENT_SOF 7
  48. #define DWC3_DEVICE_EVENT_ERRATIC_ERROR 9
  49. #define DWC3_DEVICE_EVENT_CMD_CMPL 10
  50. #define DWC3_DEVICE_EVENT_OVERFLOW 11
  51. /* Controller's role while using the OTG block */
  52. #define DWC3_OTG_ROLE_IDLE 0
  53. #define DWC3_OTG_ROLE_HOST 1
  54. #define DWC3_OTG_ROLE_DEVICE 2
  55. #define DWC3_GEVNTCOUNT_MASK 0xfffc
  56. #define DWC3_GEVNTCOUNT_EHB BIT(31)
  57. #define DWC3_GSNPSID_MASK 0xffff0000
  58. #define DWC3_GSNPSREV_MASK 0xffff
  59. /* DWC3 registers memory space boundries */
  60. #define DWC3_XHCI_REGS_START 0x0
  61. #define DWC3_XHCI_REGS_END 0x7fff
  62. #define DWC3_GLOBALS_REGS_START 0xc100
  63. #define DWC3_GLOBALS_REGS_END 0xc6ff
  64. #define DWC3_DEVICE_REGS_START 0xc700
  65. #define DWC3_DEVICE_REGS_END 0xcbff
  66. #define DWC3_OTG_REGS_START 0xcc00
  67. #define DWC3_OTG_REGS_END 0xccff
  68. /* Global Registers */
  69. #define DWC3_GSBUSCFG0 0xc100
  70. #define DWC3_GSBUSCFG1 0xc104
  71. #define DWC3_GTXTHRCFG 0xc108
  72. #define DWC3_GRXTHRCFG 0xc10c
  73. #define DWC3_GCTL 0xc110
  74. #define DWC3_GEVTEN 0xc114
  75. #define DWC3_GSTS 0xc118
  76. #define DWC3_GUCTL1 0xc11c
  77. #define DWC3_GSNPSID 0xc120
  78. #define DWC3_GGPIO 0xc124
  79. #define DWC3_GUID 0xc128
  80. #define DWC3_GUCTL 0xc12c
  81. #define DWC3_GBUSERRADDR0 0xc130
  82. #define DWC3_GBUSERRADDR1 0xc134
  83. #define DWC3_GPRTBIMAP0 0xc138
  84. #define DWC3_GPRTBIMAP1 0xc13c
  85. #define DWC3_GHWPARAMS0 0xc140
  86. #define DWC3_GHWPARAMS1 0xc144
  87. #define DWC3_GHWPARAMS2 0xc148
  88. #define DWC3_GHWPARAMS3 0xc14c
  89. #define DWC3_GHWPARAMS4 0xc150
  90. #define DWC3_GHWPARAMS5 0xc154
  91. #define DWC3_GHWPARAMS6 0xc158
  92. #define DWC3_GHWPARAMS7 0xc15c
  93. #define DWC3_GDBGFIFOSPACE 0xc160
  94. #define DWC3_GDBGLTSSM 0xc164
  95. #define DWC3_GDBGBMU 0xc16c
  96. #define DWC3_GDBGLSPMUX 0xc170
  97. #define DWC3_GDBGLSP 0xc174
  98. #define DWC3_GDBGEPINFO0 0xc178
  99. #define DWC3_GDBGEPINFO1 0xc17c
  100. #define DWC3_GPRTBIMAP_HS0 0xc180
  101. #define DWC3_GPRTBIMAP_HS1 0xc184
  102. #define DWC3_GPRTBIMAP_FS0 0xc188
  103. #define DWC3_GPRTBIMAP_FS1 0xc18c
  104. #define DWC3_GUCTL2 0xc19c
  105. #define DWC3_VER_NUMBER 0xc1a0
  106. #define DWC3_VER_TYPE 0xc1a4
  107. #define DWC3_GUSB2PHYCFG(n) (0xc200 + ((n) * 0x04))
  108. #define DWC3_GUSB2I2CCTL(n) (0xc240 + ((n) * 0x04))
  109. #define DWC3_GUSB2PHYACC(n) (0xc280 + ((n) * 0x04))
  110. #define DWC3_GUSB3PIPECTL(n) (0xc2c0 + ((n) * 0x04))
  111. #define DWC3_GTXFIFOSIZ(n) (0xc300 + ((n) * 0x04))
  112. #define DWC3_GRXFIFOSIZ(n) (0xc380 + ((n) * 0x04))
  113. #define DWC3_GEVNTADRLO(n) (0xc400 + ((n) * 0x10))
  114. #define DWC3_GEVNTADRHI(n) (0xc404 + ((n) * 0x10))
  115. #define DWC3_GEVNTSIZ(n) (0xc408 + ((n) * 0x10))
  116. #define DWC3_GEVNTCOUNT(n) (0xc40c + ((n) * 0x10))
  117. #define DWC3_GHWPARAMS8 0xc600
  118. #define DWC3_GFLADJ 0xc630
  119. /* Device Registers */
  120. #define DWC3_DCFG 0xc700
  121. #define DWC3_DCTL 0xc704
  122. #define DWC3_DEVTEN 0xc708
  123. #define DWC3_DSTS 0xc70c
  124. #define DWC3_DGCMDPAR 0xc710
  125. #define DWC3_DGCMD 0xc714
  126. #define DWC3_DALEPENA 0xc720
  127. #define DWC3_DEP_BASE(n) (0xc800 + ((n) * 0x10))
  128. #define DWC3_DEPCMDPAR2 0x00
  129. #define DWC3_DEPCMDPAR1 0x04
  130. #define DWC3_DEPCMDPAR0 0x08
  131. #define DWC3_DEPCMD 0x0c
  132. #define DWC3_DEV_IMOD(n) (0xca00 + ((n) * 0x4))
  133. /* OTG Registers */
  134. #define DWC3_OCFG 0xcc00
  135. #define DWC3_OCTL 0xcc04
  136. #define DWC3_OEVT 0xcc08
  137. #define DWC3_OEVTEN 0xcc0C
  138. #define DWC3_OSTS 0xcc10
  139. /* Bit fields */
  140. /* Global SoC Bus Configuration INCRx Register 0 */
  141. #define DWC3_GSBUSCFG0_INCR256BRSTENA (1 << 7) /* INCR256 burst */
  142. #define DWC3_GSBUSCFG0_INCR128BRSTENA (1 << 6) /* INCR128 burst */
  143. #define DWC3_GSBUSCFG0_INCR64BRSTENA (1 << 5) /* INCR64 burst */
  144. #define DWC3_GSBUSCFG0_INCR32BRSTENA (1 << 4) /* INCR32 burst */
  145. #define DWC3_GSBUSCFG0_INCR16BRSTENA (1 << 3) /* INCR16 burst */
  146. #define DWC3_GSBUSCFG0_INCR8BRSTENA (1 << 2) /* INCR8 burst */
  147. #define DWC3_GSBUSCFG0_INCR4BRSTENA (1 << 1) /* INCR4 burst */
  148. #define DWC3_GSBUSCFG0_INCRBRSTENA (1 << 0) /* undefined length enable */
  149. #define DWC3_GSBUSCFG0_INCRBRST_MASK 0xff
  150. /* Global Debug Queue/FIFO Space Available Register */
  151. #define DWC3_GDBGFIFOSPACE_NUM(n) ((n) & 0x1f)
  152. #define DWC3_GDBGFIFOSPACE_TYPE(n) (((n) << 5) & 0x1e0)
  153. #define DWC3_GDBGFIFOSPACE_SPACE_AVAILABLE(n) (((n) >> 16) & 0xffff)
  154. #define DWC3_TXFIFOQ 0
  155. #define DWC3_RXFIFOQ 1
  156. #define DWC3_TXREQQ 2
  157. #define DWC3_RXREQQ 3
  158. #define DWC3_RXINFOQ 4
  159. #define DWC3_PSTATQ 5
  160. #define DWC3_DESCFETCHQ 6
  161. #define DWC3_EVENTQ 7
  162. #define DWC3_AUXEVENTQ 8
  163. /* Global RX Threshold Configuration Register */
  164. #define DWC3_GRXTHRCFG_MAXRXBURSTSIZE(n) (((n) & 0x1f) << 19)
  165. #define DWC3_GRXTHRCFG_RXPKTCNT(n) (((n) & 0xf) << 24)
  166. #define DWC3_GRXTHRCFG_PKTCNTSEL BIT(29)
  167. /* Global RX Threshold Configuration Register for DWC_usb31 only */
  168. #define DWC31_GRXTHRCFG_MAXRXBURSTSIZE(n) (((n) & 0x1f) << 16)
  169. #define DWC31_GRXTHRCFG_RXPKTCNT(n) (((n) & 0x1f) << 21)
  170. #define DWC31_GRXTHRCFG_PKTCNTSEL BIT(26)
  171. #define DWC31_RXTHRNUMPKTSEL_HS_PRD BIT(15)
  172. #define DWC31_RXTHRNUMPKT_HS_PRD(n) (((n) & 0x3) << 13)
  173. #define DWC31_RXTHRNUMPKTSEL_PRD BIT(10)
  174. #define DWC31_RXTHRNUMPKT_PRD(n) (((n) & 0x1f) << 5)
  175. #define DWC31_MAXRXBURSTSIZE_PRD(n) ((n) & 0x1f)
  176. /* Global TX Threshold Configuration Register for DWC_usb31 only */
  177. #define DWC31_GTXTHRCFG_MAXTXBURSTSIZE(n) (((n) & 0x1f) << 16)
  178. #define DWC31_GTXTHRCFG_TXPKTCNT(n) (((n) & 0x1f) << 21)
  179. #define DWC31_GTXTHRCFG_PKTCNTSEL BIT(26)
  180. #define DWC31_TXTHRNUMPKTSEL_HS_PRD BIT(15)
  181. #define DWC31_TXTHRNUMPKT_HS_PRD(n) (((n) & 0x3) << 13)
  182. #define DWC31_TXTHRNUMPKTSEL_PRD BIT(10)
  183. #define DWC31_TXTHRNUMPKT_PRD(n) (((n) & 0x1f) << 5)
  184. #define DWC31_MAXTXBURSTSIZE_PRD(n) ((n) & 0x1f)
  185. /* Global Configuration Register */
  186. #define DWC3_GCTL_PWRDNSCALE(n) ((n) << 19)
  187. #define DWC3_GCTL_U2RSTECN BIT(16)
  188. #define DWC3_GCTL_RAMCLKSEL(x) (((x) & DWC3_GCTL_CLK_MASK) << 6)
  189. #define DWC3_GCTL_CLK_BUS (0)
  190. #define DWC3_GCTL_CLK_PIPE (1)
  191. #define DWC3_GCTL_CLK_PIPEHALF (2)
  192. #define DWC3_GCTL_CLK_MASK (3)
  193. #define DWC3_GCTL_PRTCAP(n) (((n) & (3 << 12)) >> 12)
  194. #define DWC3_GCTL_PRTCAPDIR(n) ((n) << 12)
  195. #define DWC3_GCTL_PRTCAP_HOST 1
  196. #define DWC3_GCTL_PRTCAP_DEVICE 2
  197. #define DWC3_GCTL_PRTCAP_OTG 3
  198. #define DWC3_GCTL_CORESOFTRESET BIT(11)
  199. #define DWC3_GCTL_SOFITPSYNC BIT(10)
  200. #define DWC3_GCTL_SCALEDOWN(n) ((n) << 4)
  201. #define DWC3_GCTL_SCALEDOWN_MASK DWC3_GCTL_SCALEDOWN(3)
  202. #define DWC3_GCTL_DISSCRAMBLE BIT(3)
  203. #define DWC3_GCTL_U2EXIT_LFPS BIT(2)
  204. #define DWC3_GCTL_GBLHIBERNATIONEN BIT(1)
  205. #define DWC3_GCTL_DSBLCLKGTNG BIT(0)
  206. /* Global User Control Register */
  207. #define DWC3_GUCTL_HSTINAUTORETRY BIT(14)
  208. /* Global User Control 1 Register */
  209. #define DWC3_GUCTL1_TX_IPGAP_LINECHECK_DIS BIT(28)
  210. #define DWC3_GUCTL1_DEV_L1_EXIT_BY_HW BIT(24)
  211. /* Global Status Register */
  212. #define DWC3_GSTS_OTG_IP BIT(10)
  213. #define DWC3_GSTS_BC_IP BIT(9)
  214. #define DWC3_GSTS_ADP_IP BIT(8)
  215. #define DWC3_GSTS_HOST_IP BIT(7)
  216. #define DWC3_GSTS_DEVICE_IP BIT(6)
  217. #define DWC3_GSTS_CSR_TIMEOUT BIT(5)
  218. #define DWC3_GSTS_BUS_ERR_ADDR_VLD BIT(4)
  219. /* Global USB2 PHY Configuration Register */
  220. #define DWC3_GUSB2PHYCFG_PHYSOFTRST BIT(31)
  221. #define DWC3_GUSB2PHYCFG_U2_FREECLK_EXISTS BIT(30)
  222. #define DWC3_GUSB2PHYCFG_SUSPHY BIT(6)
  223. #define DWC3_GUSB2PHYCFG_ULPI_UTMI BIT(4)
  224. #define DWC3_GUSB2PHYCFG_ENBLSLPM BIT(8)
  225. #define DWC3_GUSB2PHYCFG_PHYIF(n) (n << 3)
  226. #define DWC3_GUSB2PHYCFG_PHYIF_MASK DWC3_GUSB2PHYCFG_PHYIF(1)
  227. #define DWC3_GUSB2PHYCFG_USBTRDTIM(n) (n << 10)
  228. #define DWC3_GUSB2PHYCFG_USBTRDTIM_MASK DWC3_GUSB2PHYCFG_USBTRDTIM(0xf)
  229. #define USBTRDTIM_UTMI_8_BIT 9
  230. #define USBTRDTIM_UTMI_16_BIT 5
  231. #define UTMI_PHYIF_16_BIT 1
  232. #define UTMI_PHYIF_8_BIT 0
  233. /* Global USB2 PHY Vendor Control Register */
  234. #define DWC3_GUSB2PHYACC_NEWREGREQ BIT(25)
  235. #define DWC3_GUSB2PHYACC_BUSY BIT(23)
  236. #define DWC3_GUSB2PHYACC_WRITE BIT(22)
  237. #define DWC3_GUSB2PHYACC_ADDR(n) (n << 16)
  238. #define DWC3_GUSB2PHYACC_EXTEND_ADDR(n) (n << 8)
  239. #define DWC3_GUSB2PHYACC_DATA(n) (n & 0xff)
  240. /* Global USB3 PIPE Control Register */
  241. #define DWC3_GUSB3PIPECTL_PHYSOFTRST BIT(31)
  242. #define DWC3_GUSB3PIPECTL_U2SSINP3OK BIT(29)
  243. #define DWC3_GUSB3PIPECTL_DISRXDETINP3 BIT(28)
  244. #define DWC3_GUSB3PIPECTL_UX_EXIT_PX BIT(27)
  245. #define DWC3_GUSB3PIPECTL_REQP1P2P3 BIT(24)
  246. #define DWC3_GUSB3PIPECTL_DEP1P2P3(n) ((n) << 19)
  247. #define DWC3_GUSB3PIPECTL_DEP1P2P3_MASK DWC3_GUSB3PIPECTL_DEP1P2P3(7)
  248. #define DWC3_GUSB3PIPECTL_DEP1P2P3_EN DWC3_GUSB3PIPECTL_DEP1P2P3(1)
  249. #define DWC3_GUSB3PIPECTL_DEPOCHANGE BIT(18)
  250. #define DWC3_GUSB3PIPECTL_SUSPHY BIT(17)
  251. #define DWC3_GUSB3PIPECTL_LFPSFILT BIT(9)
  252. #define DWC3_GUSB3PIPECTL_RX_DETOPOLL BIT(8)
  253. #define DWC3_GUSB3PIPECTL_TX_DEEPH_MASK DWC3_GUSB3PIPECTL_TX_DEEPH(3)
  254. #define DWC3_GUSB3PIPECTL_TX_DEEPH(n) ((n) << 1)
  255. /* Global TX Fifo Size Register */
  256. #define DWC31_GTXFIFOSIZ_TXFRAMNUM BIT(15) /* DWC_usb31 only */
  257. #define DWC31_GTXFIFOSIZ_TXFDEF(n) ((n) & 0x7fff) /* DWC_usb31 only */
  258. #define DWC3_GTXFIFOSIZ_TXFDEF(n) ((n) & 0xffff)
  259. #define DWC3_GTXFIFOSIZ_TXFSTADDR(n) ((n) & 0xffff0000)
  260. /* Global Event Size Registers */
  261. #define DWC3_GEVNTSIZ_INTMASK BIT(31)
  262. #define DWC3_GEVNTSIZ_SIZE(n) ((n) & 0xffff)
  263. /* Global HWPARAMS0 Register */
  264. #define DWC3_GHWPARAMS0_MODE(n) ((n) & 0x3)
  265. #define DWC3_GHWPARAMS0_MODE_GADGET 0
  266. #define DWC3_GHWPARAMS0_MODE_HOST 1
  267. #define DWC3_GHWPARAMS0_MODE_DRD 2
  268. #define DWC3_GHWPARAMS0_MBUS_TYPE(n) (((n) >> 3) & 0x7)
  269. #define DWC3_GHWPARAMS0_SBUS_TYPE(n) (((n) >> 6) & 0x3)
  270. #define DWC3_GHWPARAMS0_MDWIDTH(n) (((n) >> 8) & 0xff)
  271. #define DWC3_GHWPARAMS0_SDWIDTH(n) (((n) >> 16) & 0xff)
  272. #define DWC3_GHWPARAMS0_AWIDTH(n) (((n) >> 24) & 0xff)
  273. /* Global HWPARAMS1 Register */
  274. #define DWC3_GHWPARAMS1_EN_PWROPT(n) (((n) & (3 << 24)) >> 24)
  275. #define DWC3_GHWPARAMS1_EN_PWROPT_NO 0
  276. #define DWC3_GHWPARAMS1_EN_PWROPT_CLK 1
  277. #define DWC3_GHWPARAMS1_EN_PWROPT_HIB 2
  278. #define DWC3_GHWPARAMS1_PWROPT(n) ((n) << 24)
  279. #define DWC3_GHWPARAMS1_PWROPT_MASK DWC3_GHWPARAMS1_PWROPT(3)
  280. /* Global HWPARAMS3 Register */
  281. #define DWC3_GHWPARAMS3_SSPHY_IFC(n) ((n) & 3)
  282. #define DWC3_GHWPARAMS3_SSPHY_IFC_DIS 0
  283. #define DWC3_GHWPARAMS3_SSPHY_IFC_GEN1 1
  284. #define DWC3_GHWPARAMS3_SSPHY_IFC_GEN2 2 /* DWC_usb31 only */
  285. #define DWC3_GHWPARAMS3_HSPHY_IFC(n) (((n) & (3 << 2)) >> 2)
  286. #define DWC3_GHWPARAMS3_HSPHY_IFC_DIS 0
  287. #define DWC3_GHWPARAMS3_HSPHY_IFC_UTMI 1
  288. #define DWC3_GHWPARAMS3_HSPHY_IFC_ULPI 2
  289. #define DWC3_GHWPARAMS3_HSPHY_IFC_UTMI_ULPI 3
  290. #define DWC3_GHWPARAMS3_FSPHY_IFC(n) (((n) & (3 << 4)) >> 4)
  291. #define DWC3_GHWPARAMS3_FSPHY_IFC_DIS 0
  292. #define DWC3_GHWPARAMS3_FSPHY_IFC_ENA 1
  293. /* Global HWPARAMS4 Register */
  294. #define DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(n) (((n) & (0x0f << 13)) >> 13)
  295. #define DWC3_MAX_HIBER_SCRATCHBUFS 15
  296. /* Global HWPARAMS6 Register */
  297. #define DWC3_GHWPARAMS6_BCSUPPORT BIT(14)
  298. #define DWC3_GHWPARAMS6_OTG3SUPPORT BIT(13)
  299. #define DWC3_GHWPARAMS6_ADPSUPPORT BIT(12)
  300. #define DWC3_GHWPARAMS6_HNPSUPPORT BIT(11)
  301. #define DWC3_GHWPARAMS6_SRPSUPPORT BIT(10)
  302. #define DWC3_GHWPARAMS6_EN_FPGA BIT(7)
  303. /* Global HWPARAMS7 Register */
  304. #define DWC3_GHWPARAMS7_RAM1_DEPTH(n) ((n) & 0xffff)
  305. #define DWC3_GHWPARAMS7_RAM2_DEPTH(n) (((n) >> 16) & 0xffff)
  306. /* Global Frame Length Adjustment Register */
  307. #define DWC3_GFLADJ_30MHZ_SDBND_SEL BIT(7)
  308. #define DWC3_GFLADJ_30MHZ_MASK 0x3f
  309. /* Global User Control Register 2 */
  310. #define DWC3_GUCTL2_RST_ACTBITLATER BIT(14)
  311. /* Device Configuration Register */
  312. #define DWC3_DCFG_DEVADDR(addr) ((addr) << 3)
  313. #define DWC3_DCFG_DEVADDR_MASK DWC3_DCFG_DEVADDR(0x7f)
  314. #define DWC3_DCFG_SPEED_MASK (7 << 0)
  315. #define DWC3_DCFG_SUPERSPEED_PLUS (5 << 0) /* DWC_usb31 only */
  316. #define DWC3_DCFG_SUPERSPEED (4 << 0)
  317. #define DWC3_DCFG_HIGHSPEED (0 << 0)
  318. #define DWC3_DCFG_FULLSPEED BIT(0)
  319. #define DWC3_DCFG_LOWSPEED (2 << 0)
  320. #define DWC3_DCFG_NUMP_SHIFT 17
  321. #define DWC3_DCFG_NUMP(n) (((n) >> DWC3_DCFG_NUMP_SHIFT) & 0x1f)
  322. #define DWC3_DCFG_NUMP_MASK (0x1f << DWC3_DCFG_NUMP_SHIFT)
  323. #define DWC3_DCFG_LPM_CAP BIT(22)
  324. /* Device Control Register */
  325. #define DWC3_DCTL_RUN_STOP BIT(31)
  326. #define DWC3_DCTL_CSFTRST BIT(30)
  327. #define DWC3_DCTL_LSFTRST BIT(29)
  328. #define DWC3_DCTL_HIRD_THRES_MASK (0x1f << 24)
  329. #define DWC3_DCTL_HIRD_THRES(n) ((n) << 24)
  330. #define DWC3_DCTL_APPL1RES BIT(23)
  331. /* These apply for core versions 1.87a and earlier */
  332. #define DWC3_DCTL_TRGTULST_MASK (0x0f << 17)
  333. #define DWC3_DCTL_TRGTULST(n) ((n) << 17)
  334. #define DWC3_DCTL_TRGTULST_U2 (DWC3_DCTL_TRGTULST(2))
  335. #define DWC3_DCTL_TRGTULST_U3 (DWC3_DCTL_TRGTULST(3))
  336. #define DWC3_DCTL_TRGTULST_SS_DIS (DWC3_DCTL_TRGTULST(4))
  337. #define DWC3_DCTL_TRGTULST_RX_DET (DWC3_DCTL_TRGTULST(5))
  338. #define DWC3_DCTL_TRGTULST_SS_INACT (DWC3_DCTL_TRGTULST(6))
  339. /* These apply for core versions 1.94a and later */
  340. #define DWC3_DCTL_LPM_ERRATA_MASK DWC3_DCTL_LPM_ERRATA(0xf)
  341. #define DWC3_DCTL_LPM_ERRATA(n) ((n) << 20)
  342. #define DWC3_DCTL_KEEP_CONNECT BIT(19)
  343. #define DWC3_DCTL_L1_HIBER_EN BIT(18)
  344. #define DWC3_DCTL_CRS BIT(17)
  345. #define DWC3_DCTL_CSS BIT(16)
  346. #define DWC3_DCTL_INITU2ENA BIT(12)
  347. #define DWC3_DCTL_ACCEPTU2ENA BIT(11)
  348. #define DWC3_DCTL_INITU1ENA BIT(10)
  349. #define DWC3_DCTL_ACCEPTU1ENA BIT(9)
  350. #define DWC3_DCTL_TSTCTRL_MASK (0xf << 1)
  351. #define DWC3_DCTL_ULSTCHNGREQ_MASK (0x0f << 5)
  352. #define DWC3_DCTL_ULSTCHNGREQ(n) (((n) << 5) & DWC3_DCTL_ULSTCHNGREQ_MASK)
  353. #define DWC3_DCTL_ULSTCHNG_NO_ACTION (DWC3_DCTL_ULSTCHNGREQ(0))
  354. #define DWC3_DCTL_ULSTCHNG_SS_DISABLED (DWC3_DCTL_ULSTCHNGREQ(4))
  355. #define DWC3_DCTL_ULSTCHNG_RX_DETECT (DWC3_DCTL_ULSTCHNGREQ(5))
  356. #define DWC3_DCTL_ULSTCHNG_SS_INACTIVE (DWC3_DCTL_ULSTCHNGREQ(6))
  357. #define DWC3_DCTL_ULSTCHNG_RECOVERY (DWC3_DCTL_ULSTCHNGREQ(8))
  358. #define DWC3_DCTL_ULSTCHNG_COMPLIANCE (DWC3_DCTL_ULSTCHNGREQ(10))
  359. #define DWC3_DCTL_ULSTCHNG_LOOPBACK (DWC3_DCTL_ULSTCHNGREQ(11))
  360. /* Device Event Enable Register */
  361. #define DWC3_DEVTEN_VNDRDEVTSTRCVEDEN BIT(12)
  362. #define DWC3_DEVTEN_EVNTOVERFLOWEN BIT(11)
  363. #define DWC3_DEVTEN_CMDCMPLTEN BIT(10)
  364. #define DWC3_DEVTEN_ERRTICERREN BIT(9)
  365. #define DWC3_DEVTEN_SOFEN BIT(7)
  366. #define DWC3_DEVTEN_EOPFEN BIT(6)
  367. #define DWC3_DEVTEN_HIBERNATIONREQEVTEN BIT(5)
  368. #define DWC3_DEVTEN_WKUPEVTEN BIT(4)
  369. #define DWC3_DEVTEN_ULSTCNGEN BIT(3)
  370. #define DWC3_DEVTEN_CONNECTDONEEN BIT(2)
  371. #define DWC3_DEVTEN_USBRSTEN BIT(1)
  372. #define DWC3_DEVTEN_DISCONNEVTEN BIT(0)
  373. /* Device Status Register */
  374. #define DWC3_DSTS_DCNRD BIT(29)
  375. /* This applies for core versions 1.87a and earlier */
  376. #define DWC3_DSTS_PWRUPREQ BIT(24)
  377. /* These apply for core versions 1.94a and later */
  378. #define DWC3_DSTS_RSS BIT(25)
  379. #define DWC3_DSTS_SSS BIT(24)
  380. #define DWC3_DSTS_COREIDLE BIT(23)
  381. #define DWC3_DSTS_DEVCTRLHLT BIT(22)
  382. #define DWC3_DSTS_USBLNKST_MASK (0x0f << 18)
  383. #define DWC3_DSTS_USBLNKST(n) (((n) & DWC3_DSTS_USBLNKST_MASK) >> 18)
  384. #define DWC3_DSTS_RXFIFOEMPTY BIT(17)
  385. #define DWC3_DSTS_SOFFN_MASK (0x3fff << 3)
  386. #define DWC3_DSTS_SOFFN(n) (((n) & DWC3_DSTS_SOFFN_MASK) >> 3)
  387. #define DWC3_DSTS_CONNECTSPD (7 << 0)
  388. #define DWC3_DSTS_SUPERSPEED_PLUS (5 << 0) /* DWC_usb31 only */
  389. #define DWC3_DSTS_SUPERSPEED (4 << 0)
  390. #define DWC3_DSTS_HIGHSPEED (0 << 0)
  391. #define DWC3_DSTS_FULLSPEED BIT(0)
  392. #define DWC3_DSTS_LOWSPEED (2 << 0)
  393. /* Device Generic Command Register */
  394. #define DWC3_DGCMD_SET_LMP 0x01
  395. #define DWC3_DGCMD_SET_PERIODIC_PAR 0x02
  396. #define DWC3_DGCMD_XMIT_FUNCTION 0x03
  397. /* These apply for core versions 1.94a and later */
  398. #define DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO 0x04
  399. #define DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI 0x05
  400. #define DWC3_DGCMD_SELECTED_FIFO_FLUSH 0x09
  401. #define DWC3_DGCMD_ALL_FIFO_FLUSH 0x0a
  402. #define DWC3_DGCMD_SET_ENDPOINT_NRDY 0x0c
  403. #define DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK 0x10
  404. #define DWC3_DGCMD_STATUS(n) (((n) >> 12) & 0x0F)
  405. #define DWC3_DGCMD_CMDACT BIT(10)
  406. #define DWC3_DGCMD_CMDIOC BIT(8)
  407. /* Device Generic Command Parameter Register */
  408. #define DWC3_DGCMDPAR_FORCE_LINKPM_ACCEPT BIT(0)
  409. #define DWC3_DGCMDPAR_FIFO_NUM(n) ((n) << 0)
  410. #define DWC3_DGCMDPAR_RX_FIFO (0 << 5)
  411. #define DWC3_DGCMDPAR_TX_FIFO BIT(5)
  412. #define DWC3_DGCMDPAR_LOOPBACK_DIS (0 << 0)
  413. #define DWC3_DGCMDPAR_LOOPBACK_ENA BIT(0)
  414. /* Device Endpoint Command Register */
  415. #define DWC3_DEPCMD_PARAM_SHIFT 16
  416. #define DWC3_DEPCMD_PARAM(x) ((x) << DWC3_DEPCMD_PARAM_SHIFT)
  417. #define DWC3_DEPCMD_GET_RSC_IDX(x) (((x) >> DWC3_DEPCMD_PARAM_SHIFT) & 0x7f)
  418. #define DWC3_DEPCMD_STATUS(x) (((x) >> 12) & 0x0F)
  419. #define DWC3_DEPCMD_HIPRI_FORCERM BIT(11)
  420. #define DWC3_DEPCMD_CLEARPENDIN BIT(11)
  421. #define DWC3_DEPCMD_CMDACT BIT(10)
  422. #define DWC3_DEPCMD_CMDIOC BIT(8)
  423. #define DWC3_DEPCMD_DEPSTARTCFG (0x09 << 0)
  424. #define DWC3_DEPCMD_ENDTRANSFER (0x08 << 0)
  425. #define DWC3_DEPCMD_UPDATETRANSFER (0x07 << 0)
  426. #define DWC3_DEPCMD_STARTTRANSFER (0x06 << 0)
  427. #define DWC3_DEPCMD_CLEARSTALL (0x05 << 0)
  428. #define DWC3_DEPCMD_SETSTALL (0x04 << 0)
  429. /* This applies for core versions 1.90a and earlier */
  430. #define DWC3_DEPCMD_GETSEQNUMBER (0x03 << 0)
  431. /* This applies for core versions 1.94a and later */
  432. #define DWC3_DEPCMD_GETEPSTATE (0x03 << 0)
  433. #define DWC3_DEPCMD_SETTRANSFRESOURCE (0x02 << 0)
  434. #define DWC3_DEPCMD_SETEPCONFIG (0x01 << 0)
  435. #define DWC3_DEPCMD_CMD(x) ((x) & 0xf)
  436. /* The EP number goes 0..31 so ep0 is always out and ep1 is always in */
  437. #define DWC3_DALEPENA_EP(n) BIT(n)
  438. #define DWC3_DEPCMD_TYPE_CONTROL 0
  439. #define DWC3_DEPCMD_TYPE_ISOC 1
  440. #define DWC3_DEPCMD_TYPE_BULK 2
  441. #define DWC3_DEPCMD_TYPE_INTR 3
  442. #define DWC3_DEV_IMOD_COUNT_SHIFT 16
  443. #define DWC3_DEV_IMOD_COUNT_MASK (0xffff << 16)
  444. #define DWC3_DEV_IMOD_INTERVAL_SHIFT 0
  445. #define DWC3_DEV_IMOD_INTERVAL_MASK (0xffff << 0)
  446. /* OTG Configuration Register */
  447. #define DWC3_OCFG_DISPWRCUTTOFF BIT(5)
  448. #define DWC3_OCFG_HIBDISMASK BIT(4)
  449. #define DWC3_OCFG_SFTRSTMASK BIT(3)
  450. #define DWC3_OCFG_OTGVERSION BIT(2)
  451. #define DWC3_OCFG_HNPCAP BIT(1)
  452. #define DWC3_OCFG_SRPCAP BIT(0)
  453. /* OTG CTL Register */
  454. #define DWC3_OCTL_OTG3GOERR BIT(7)
  455. #define DWC3_OCTL_PERIMODE BIT(6)
  456. #define DWC3_OCTL_PRTPWRCTL BIT(5)
  457. #define DWC3_OCTL_HNPREQ BIT(4)
  458. #define DWC3_OCTL_SESREQ BIT(3)
  459. #define DWC3_OCTL_TERMSELIDPULSE BIT(2)
  460. #define DWC3_OCTL_DEVSETHNPEN BIT(1)
  461. #define DWC3_OCTL_HSTSETHNPEN BIT(0)
  462. /* OTG Event Register */
  463. #define DWC3_OEVT_DEVICEMODE BIT(31)
  464. #define DWC3_OEVT_XHCIRUNSTPSET BIT(27)
  465. #define DWC3_OEVT_DEVRUNSTPSET BIT(26)
  466. #define DWC3_OEVT_HIBENTRY BIT(25)
  467. #define DWC3_OEVT_CONIDSTSCHNG BIT(24)
  468. #define DWC3_OEVT_HRRCONFNOTIF BIT(23)
  469. #define DWC3_OEVT_HRRINITNOTIF BIT(22)
  470. #define DWC3_OEVT_ADEVIDLE BIT(21)
  471. #define DWC3_OEVT_ADEVBHOSTEND BIT(20)
  472. #define DWC3_OEVT_ADEVHOST BIT(19)
  473. #define DWC3_OEVT_ADEVHNPCHNG BIT(18)
  474. #define DWC3_OEVT_ADEVSRPDET BIT(17)
  475. #define DWC3_OEVT_ADEVSESSENDDET BIT(16)
  476. #define DWC3_OEVT_BDEVBHOSTEND BIT(11)
  477. #define DWC3_OEVT_BDEVHNPCHNG BIT(10)
  478. #define DWC3_OEVT_BDEVSESSVLDDET BIT(9)
  479. #define DWC3_OEVT_BDEVVBUSCHNG BIT(8)
  480. #define DWC3_OEVT_BSESSVLD BIT(3)
  481. #define DWC3_OEVT_HSTNEGSTS BIT(2)
  482. #define DWC3_OEVT_SESREQSTS BIT(1)
  483. #define DWC3_OEVT_ERROR BIT(0)
  484. /* OTG Event Enable Register */
  485. #define DWC3_OEVTEN_XHCIRUNSTPSETEN BIT(27)
  486. #define DWC3_OEVTEN_DEVRUNSTPSETEN BIT(26)
  487. #define DWC3_OEVTEN_HIBENTRYEN BIT(25)
  488. #define DWC3_OEVTEN_CONIDSTSCHNGEN BIT(24)
  489. #define DWC3_OEVTEN_HRRCONFNOTIFEN BIT(23)
  490. #define DWC3_OEVTEN_HRRINITNOTIFEN BIT(22)
  491. #define DWC3_OEVTEN_ADEVIDLEEN BIT(21)
  492. #define DWC3_OEVTEN_ADEVBHOSTENDEN BIT(20)
  493. #define DWC3_OEVTEN_ADEVHOSTEN BIT(19)
  494. #define DWC3_OEVTEN_ADEVHNPCHNGEN BIT(18)
  495. #define DWC3_OEVTEN_ADEVSRPDETEN BIT(17)
  496. #define DWC3_OEVTEN_ADEVSESSENDDETEN BIT(16)
  497. #define DWC3_OEVTEN_BDEVBHOSTENDEN BIT(11)
  498. #define DWC3_OEVTEN_BDEVHNPCHNGEN BIT(10)
  499. #define DWC3_OEVTEN_BDEVSESSVLDDETEN BIT(9)
  500. #define DWC3_OEVTEN_BDEVVBUSCHNGEN BIT(8)
  501. /* OTG Status Register */
  502. #define DWC3_OSTS_DEVRUNSTP BIT(13)
  503. #define DWC3_OSTS_XHCIRUNSTP BIT(12)
  504. #define DWC3_OSTS_PERIPHERALSTATE BIT(4)
  505. #define DWC3_OSTS_XHCIPRTPOWER BIT(3)
  506. #define DWC3_OSTS_BSESVLD BIT(2)
  507. #define DWC3_OSTS_VBUSVLD BIT(1)
  508. #define DWC3_OSTS_CONIDSTS BIT(0)
  509. /* Structures */
  510. struct dwc3_trb;
  511. /**
  512. * struct dwc3_event_buffer - Software event buffer representation
  513. * @buf: _THE_ buffer
  514. * @cache: The buffer cache used in the threaded interrupt
  515. * @length: size of this buffer
  516. * @lpos: event offset
  517. * @count: cache of last read event count register
  518. * @flags: flags related to this event buffer
  519. * @dma: dma_addr_t
  520. * @dwc: pointer to DWC controller
  521. */
  522. struct dwc3_event_buffer {
  523. void *buf;
  524. void *cache;
  525. unsigned length;
  526. unsigned int lpos;
  527. unsigned int count;
  528. unsigned int flags;
  529. #define DWC3_EVENT_PENDING BIT(0)
  530. dma_addr_t dma;
  531. struct dwc3 *dwc;
  532. };
  533. #define DWC3_EP_FLAG_STALLED BIT(0)
  534. #define DWC3_EP_FLAG_WEDGED BIT(1)
  535. #define DWC3_EP_DIRECTION_TX true
  536. #define DWC3_EP_DIRECTION_RX false
  537. #define DWC3_TRB_NUM 256
  538. /**
  539. * struct dwc3_ep - device side endpoint representation
  540. * @endpoint: usb endpoint
  541. * @cancelled_list: list of cancelled requests for this endpoint
  542. * @pending_list: list of pending requests for this endpoint
  543. * @started_list: list of started requests on this endpoint
  544. * @wait_end_transfer: wait_queue_head_t for waiting on End Transfer complete
  545. * @lock: spinlock for endpoint request queue traversal
  546. * @regs: pointer to first endpoint register
  547. * @trb_pool: array of transaction buffers
  548. * @trb_pool_dma: dma address of @trb_pool
  549. * @trb_enqueue: enqueue 'pointer' into TRB array
  550. * @trb_dequeue: dequeue 'pointer' into TRB array
  551. * @dwc: pointer to DWC controller
  552. * @saved_state: ep state saved during hibernation
  553. * @flags: endpoint flags (wedged, stalled, ...)
  554. * @number: endpoint number (1 - 15)
  555. * @type: set to bmAttributes & USB_ENDPOINT_XFERTYPE_MASK
  556. * @resource_index: Resource transfer index
  557. * @frame_number: set to the frame number we want this transfer to start (ISOC)
  558. * @interval: the interval on which the ISOC transfer is started
  559. * @name: a human readable name e.g. ep1out-bulk
  560. * @direction: true for TX, false for RX
  561. * @stream_capable: true when streams are enabled
  562. */
  563. struct dwc3_ep {
  564. struct usb_ep endpoint;
  565. struct list_head cancelled_list;
  566. struct list_head pending_list;
  567. struct list_head started_list;
  568. wait_queue_head_t wait_end_transfer;
  569. spinlock_t lock;
  570. void __iomem *regs;
  571. struct dwc3_trb *trb_pool;
  572. dma_addr_t trb_pool_dma;
  573. struct dwc3 *dwc;
  574. u32 saved_state;
  575. unsigned flags;
  576. #define DWC3_EP_ENABLED BIT(0)
  577. #define DWC3_EP_STALL BIT(1)
  578. #define DWC3_EP_WEDGE BIT(2)
  579. #define DWC3_EP_TRANSFER_STARTED BIT(3)
  580. #define DWC3_EP_PENDING_REQUEST BIT(5)
  581. #define DWC3_EP_END_TRANSFER_PENDING BIT(7)
  582. /* This last one is specific to EP0 */
  583. #define DWC3_EP0_DIR_IN BIT(31)
  584. /*
  585. * IMPORTANT: we *know* we have 256 TRBs in our @trb_pool, so we will
  586. * use a u8 type here. If anybody decides to increase number of TRBs to
  587. * anything larger than 256 - I can't see why people would want to do
  588. * this though - then this type needs to be changed.
  589. *
  590. * By using u8 types we ensure that our % operator when incrementing
  591. * enqueue and dequeue get optimized away by the compiler.
  592. */
  593. u8 trb_enqueue;
  594. u8 trb_dequeue;
  595. u8 number;
  596. u8 type;
  597. u8 resource_index;
  598. u32 frame_number;
  599. u32 interval;
  600. char name[20];
  601. unsigned direction:1;
  602. unsigned stream_capable:1;
  603. };
  604. enum dwc3_phy {
  605. DWC3_PHY_UNKNOWN = 0,
  606. DWC3_PHY_USB3,
  607. DWC3_PHY_USB2,
  608. };
  609. enum dwc3_ep0_next {
  610. DWC3_EP0_UNKNOWN = 0,
  611. DWC3_EP0_COMPLETE,
  612. DWC3_EP0_NRDY_DATA,
  613. DWC3_EP0_NRDY_STATUS,
  614. };
  615. enum dwc3_ep0_state {
  616. EP0_UNCONNECTED = 0,
  617. EP0_SETUP_PHASE,
  618. EP0_DATA_PHASE,
  619. EP0_STATUS_PHASE,
  620. };
  621. enum dwc3_link_state {
  622. /* In SuperSpeed */
  623. DWC3_LINK_STATE_U0 = 0x00, /* in HS, means ON */
  624. DWC3_LINK_STATE_U1 = 0x01,
  625. DWC3_LINK_STATE_U2 = 0x02, /* in HS, means SLEEP */
  626. DWC3_LINK_STATE_U3 = 0x03, /* in HS, means SUSPEND */
  627. DWC3_LINK_STATE_SS_DIS = 0x04,
  628. DWC3_LINK_STATE_RX_DET = 0x05, /* in HS, means Early Suspend */
  629. DWC3_LINK_STATE_SS_INACT = 0x06,
  630. DWC3_LINK_STATE_POLL = 0x07,
  631. DWC3_LINK_STATE_RECOV = 0x08,
  632. DWC3_LINK_STATE_HRESET = 0x09,
  633. DWC3_LINK_STATE_CMPLY = 0x0a,
  634. DWC3_LINK_STATE_LPBK = 0x0b,
  635. DWC3_LINK_STATE_RESET = 0x0e,
  636. DWC3_LINK_STATE_RESUME = 0x0f,
  637. DWC3_LINK_STATE_MASK = 0x0f,
  638. };
  639. /* TRB Length, PCM and Status */
  640. #define DWC3_TRB_SIZE_MASK (0x00ffffff)
  641. #define DWC3_TRB_SIZE_LENGTH(n) ((n) & DWC3_TRB_SIZE_MASK)
  642. #define DWC3_TRB_SIZE_PCM1(n) (((n) & 0x03) << 24)
  643. #define DWC3_TRB_SIZE_TRBSTS(n) (((n) & (0x0f << 28)) >> 28)
  644. #define DWC3_TRBSTS_OK 0
  645. #define DWC3_TRBSTS_MISSED_ISOC 1
  646. #define DWC3_TRBSTS_SETUP_PENDING 2
  647. #define DWC3_TRB_STS_XFER_IN_PROG 4
  648. /* TRB Control */
  649. #define DWC3_TRB_CTRL_HWO BIT(0)
  650. #define DWC3_TRB_CTRL_LST BIT(1)
  651. #define DWC3_TRB_CTRL_CHN BIT(2)
  652. #define DWC3_TRB_CTRL_CSP BIT(3)
  653. #define DWC3_TRB_CTRL_TRBCTL(n) (((n) & 0x3f) << 4)
  654. #define DWC3_TRB_CTRL_ISP_IMI BIT(10)
  655. #define DWC3_TRB_CTRL_IOC BIT(11)
  656. #define DWC3_TRB_CTRL_SID_SOFN(n) (((n) & 0xffff) << 14)
  657. #define DWC3_TRBCTL_TYPE(n) ((n) & (0x3f << 4))
  658. #define DWC3_TRBCTL_NORMAL DWC3_TRB_CTRL_TRBCTL(1)
  659. #define DWC3_TRBCTL_CONTROL_SETUP DWC3_TRB_CTRL_TRBCTL(2)
  660. #define DWC3_TRBCTL_CONTROL_STATUS2 DWC3_TRB_CTRL_TRBCTL(3)
  661. #define DWC3_TRBCTL_CONTROL_STATUS3 DWC3_TRB_CTRL_TRBCTL(4)
  662. #define DWC3_TRBCTL_CONTROL_DATA DWC3_TRB_CTRL_TRBCTL(5)
  663. #define DWC3_TRBCTL_ISOCHRONOUS_FIRST DWC3_TRB_CTRL_TRBCTL(6)
  664. #define DWC3_TRBCTL_ISOCHRONOUS DWC3_TRB_CTRL_TRBCTL(7)
  665. #define DWC3_TRBCTL_LINK_TRB DWC3_TRB_CTRL_TRBCTL(8)
  666. /**
  667. * struct dwc3_trb - transfer request block (hw format)
  668. * @bpl: DW0-3
  669. * @bph: DW4-7
  670. * @size: DW8-B
  671. * @ctrl: DWC-F
  672. */
  673. struct dwc3_trb {
  674. u32 bpl;
  675. u32 bph;
  676. u32 size;
  677. u32 ctrl;
  678. } __packed;
  679. /**
  680. * struct dwc3_hwparams - copy of HWPARAMS registers
  681. * @hwparams0: GHWPARAMS0
  682. * @hwparams1: GHWPARAMS1
  683. * @hwparams2: GHWPARAMS2
  684. * @hwparams3: GHWPARAMS3
  685. * @hwparams4: GHWPARAMS4
  686. * @hwparams5: GHWPARAMS5
  687. * @hwparams6: GHWPARAMS6
  688. * @hwparams7: GHWPARAMS7
  689. * @hwparams8: GHWPARAMS8
  690. */
  691. struct dwc3_hwparams {
  692. u32 hwparams0;
  693. u32 hwparams1;
  694. u32 hwparams2;
  695. u32 hwparams3;
  696. u32 hwparams4;
  697. u32 hwparams5;
  698. u32 hwparams6;
  699. u32 hwparams7;
  700. u32 hwparams8;
  701. };
  702. /* HWPARAMS0 */
  703. #define DWC3_MODE(n) ((n) & 0x7)
  704. #define DWC3_MDWIDTH(n) (((n) & 0xff00) >> 8)
  705. /* HWPARAMS1 */
  706. #define DWC3_NUM_INT(n) (((n) & (0x3f << 15)) >> 15)
  707. /* HWPARAMS3 */
  708. #define DWC3_NUM_IN_EPS_MASK (0x1f << 18)
  709. #define DWC3_NUM_EPS_MASK (0x3f << 12)
  710. #define DWC3_NUM_EPS(p) (((p)->hwparams3 & \
  711. (DWC3_NUM_EPS_MASK)) >> 12)
  712. #define DWC3_NUM_IN_EPS(p) (((p)->hwparams3 & \
  713. (DWC3_NUM_IN_EPS_MASK)) >> 18)
  714. /* HWPARAMS7 */
  715. #define DWC3_RAM1_DEPTH(n) ((n) & 0xffff)
  716. /**
  717. * struct dwc3_request - representation of a transfer request
  718. * @request: struct usb_request to be transferred
  719. * @list: a list_head used for request queueing
  720. * @dep: struct dwc3_ep owning this request
  721. * @sg: pointer to first incomplete sg
  722. * @start_sg: pointer to the sg which should be queued next
  723. * @num_pending_sgs: counter to pending sgs
  724. * @num_queued_sgs: counter to the number of sgs which already got queued
  725. * @remaining: amount of data remaining
  726. * @epnum: endpoint number to which this request refers
  727. * @trb: pointer to struct dwc3_trb
  728. * @trb_dma: DMA address of @trb
  729. * @num_trbs: number of TRBs used by this request
  730. * @needs_extra_trb: true when request needs one extra TRB (either due to ZLP
  731. * or unaligned OUT)
  732. * @direction: IN or OUT direction flag
  733. * @mapped: true when request has been dma-mapped
  734. * @started: request is started
  735. */
  736. struct dwc3_request {
  737. struct usb_request request;
  738. struct list_head list;
  739. struct dwc3_ep *dep;
  740. struct scatterlist *sg;
  741. struct scatterlist *start_sg;
  742. unsigned num_pending_sgs;
  743. unsigned int num_queued_sgs;
  744. unsigned remaining;
  745. u8 epnum;
  746. struct dwc3_trb *trb;
  747. dma_addr_t trb_dma;
  748. unsigned num_trbs;
  749. unsigned needs_extra_trb:1;
  750. unsigned direction:1;
  751. unsigned mapped:1;
  752. unsigned started:1;
  753. };
  754. /*
  755. * struct dwc3_scratchpad_array - hibernation scratchpad array
  756. * (format defined by hw)
  757. */
  758. struct dwc3_scratchpad_array {
  759. __le64 dma_adr[DWC3_MAX_HIBER_SCRATCHBUFS];
  760. };
  761. /**
  762. * struct dwc3 - representation of our controller
  763. * @drd_work: workqueue used for role swapping
  764. * @ep0_trb: trb which is used for the ctrl_req
  765. * @bounce: address of bounce buffer
  766. * @scratchbuf: address of scratch buffer
  767. * @setup_buf: used while precessing STD USB requests
  768. * @ep0_trb_addr: dma address of @ep0_trb
  769. * @bounce_addr: dma address of @bounce
  770. * @ep0_usb_req: dummy req used while handling STD USB requests
  771. * @scratch_addr: dma address of scratchbuf
  772. * @ep0_in_setup: one control transfer is completed and enter setup phase
  773. * @lock: for synchronizing
  774. * @dev: pointer to our struct device
  775. * @sysdev: pointer to the DMA-capable device
  776. * @xhci: pointer to our xHCI child
  777. * @xhci_resources: struct resources for our @xhci child
  778. * @ev_buf: struct dwc3_event_buffer pointer
  779. * @eps: endpoint array
  780. * @gadget: device side representation of the peripheral controller
  781. * @gadget_driver: pointer to the gadget driver
  782. * @clks: array of clocks
  783. * @num_clks: number of clocks
  784. * @reset: reset control
  785. * @regs: base address for our registers
  786. * @regs_size: address space size
  787. * @fladj: frame length adjustment
  788. * @irq_gadget: peripheral controller's IRQ number
  789. * @otg_irq: IRQ number for OTG IRQs
  790. * @current_otg_role: current role of operation while using the OTG block
  791. * @desired_otg_role: desired role of operation while using the OTG block
  792. * @otg_restart_host: flag that OTG controller needs to restart host
  793. * @nr_scratch: number of scratch buffers
  794. * @u1u2: only used on revisions <1.83a for workaround
  795. * @maximum_speed: maximum speed requested (mainly for testing purposes)
  796. * @revision: revision register contents
  797. * @dr_mode: requested mode of operation
  798. * @current_dr_role: current role of operation when in dual-role mode
  799. * @desired_dr_role: desired role of operation when in dual-role mode
  800. * @edev: extcon handle
  801. * @edev_nb: extcon notifier
  802. * @hsphy_mode: UTMI phy mode, one of following:
  803. * - USBPHY_INTERFACE_MODE_UTMI
  804. * - USBPHY_INTERFACE_MODE_UTMIW
  805. * @usb2_phy: pointer to USB2 PHY
  806. * @usb3_phy: pointer to USB3 PHY
  807. * @usb2_generic_phy: pointer to USB2 PHY
  808. * @usb3_generic_phy: pointer to USB3 PHY
  809. * @phys_ready: flag to indicate that PHYs are ready
  810. * @ulpi: pointer to ulpi interface
  811. * @ulpi_ready: flag to indicate that ULPI is initialized
  812. * @u2sel: parameter from Set SEL request.
  813. * @u2pel: parameter from Set SEL request.
  814. * @u1sel: parameter from Set SEL request.
  815. * @u1pel: parameter from Set SEL request.
  816. * @num_eps: number of endpoints
  817. * @ep0_next_event: hold the next expected event
  818. * @ep0state: state of endpoint zero
  819. * @link_state: link state
  820. * @speed: device speed (super, high, full, low)
  821. * @hwparams: copy of hwparams registers
  822. * @root: debugfs root folder pointer
  823. * @regset: debugfs pointer to regdump file
  824. * @test_mode: true when we're entering a USB test mode
  825. * @test_mode_nr: test feature selector
  826. * @lpm_nyet_threshold: LPM NYET response threshold
  827. * @hird_threshold: HIRD threshold
  828. * @rx_thr_num_pkt_prd: periodic ESS receive packet count
  829. * @rx_max_burst_prd: max periodic ESS receive burst size
  830. * @tx_thr_num_pkt_prd: periodic ESS transmit packet count
  831. * @tx_max_burst_prd: max periodic ESS transmit burst size
  832. * @hsphy_interface: "utmi" or "ulpi"
  833. * @connected: true when we're connected to a host, false otherwise
  834. * @delayed_status: true when gadget driver asks for delayed status
  835. * @ep0_bounced: true when we used bounce buffer
  836. * @ep0_expect_in: true when we expect a DATA IN transfer
  837. * @has_hibernation: true when dwc3 was configured with Hibernation
  838. * @sysdev_is_parent: true when dwc3 device has a parent driver
  839. * @has_lpm_erratum: true when core was configured with LPM Erratum. Note that
  840. * there's now way for software to detect this in runtime.
  841. * @is_utmi_l1_suspend: the core asserts output signal
  842. * 0 - utmi_sleep_n
  843. * 1 - utmi_l1_suspend_n
  844. * @is_fpga: true when we are using the FPGA board
  845. * @pending_events: true when we have pending IRQs to be handled
  846. * @pullups_connected: true when Run/Stop bit is set
  847. * @setup_packet_pending: true when there's a Setup Packet in FIFO. Workaround
  848. * @three_stage_setup: set if we perform a three phase setup
  849. * @usb3_lpm_capable: set if hadrware supports Link Power Management
  850. * @disable_scramble_quirk: set if we enable the disable scramble quirk
  851. * @u2exit_lfps_quirk: set if we enable u2exit lfps quirk
  852. * @u2ss_inp3_quirk: set if we enable P3 OK for U2/SS Inactive quirk
  853. * @req_p1p2p3_quirk: set if we enable request p1p2p3 quirk
  854. * @del_p1p2p3_quirk: set if we enable delay p1p2p3 quirk
  855. * @del_phy_power_chg_quirk: set if we enable delay phy power change quirk
  856. * @lfps_filter_quirk: set if we enable LFPS filter quirk
  857. * @rx_detect_poll_quirk: set if we enable rx_detect to polling lfps quirk
  858. * @dis_u3_susphy_quirk: set if we disable usb3 suspend phy
  859. * @dis_u2_susphy_quirk: set if we disable usb2 suspend phy
  860. * @dis_enblslpm_quirk: set if we clear enblslpm in GUSB2PHYCFG,
  861. * disabling the suspend signal to the PHY.
  862. * @dis_rxdet_inp3_quirk: set if we disable Rx.Detect in P3
  863. * @dis_u2_freeclk_exists_quirk : set if we clear u2_freeclk_exists
  864. * in GUSB2PHYCFG, specify that USB2 PHY doesn't
  865. * provide a free-running PHY clock.
  866. * @dis_del_phy_power_chg_quirk: set if we disable delay phy power
  867. * change quirk.
  868. * @dis_tx_ipgap_linecheck_quirk: set if we disable u2mac linestate
  869. * check during HS transmit.
  870. * @tx_de_emphasis_quirk: set if we enable Tx de-emphasis quirk
  871. * @tx_de_emphasis: Tx de-emphasis value
  872. * 0 - -6dB de-emphasis
  873. * 1 - -3.5dB de-emphasis
  874. * 2 - No de-emphasis
  875. * 3 - Reserved
  876. * @dis_metastability_quirk: set to disable metastability quirk.
  877. * @imod_interval: set the interrupt moderation interval in 250ns
  878. * increments or 0 to disable.
  879. */
  880. struct dwc3 {
  881. struct work_struct drd_work;
  882. struct dwc3_trb *ep0_trb;
  883. void *bounce;
  884. void *scratchbuf;
  885. u8 *setup_buf;
  886. dma_addr_t ep0_trb_addr;
  887. dma_addr_t bounce_addr;
  888. dma_addr_t scratch_addr;
  889. struct dwc3_request ep0_usb_req;
  890. struct completion ep0_in_setup;
  891. /* device lock */
  892. spinlock_t lock;
  893. struct device *dev;
  894. struct device *sysdev;
  895. struct platform_device *xhci;
  896. struct resource xhci_resources[DWC3_XHCI_RESOURCES_NUM];
  897. struct dwc3_event_buffer *ev_buf;
  898. struct dwc3_ep *eps[DWC3_ENDPOINTS_NUM];
  899. struct usb_gadget gadget;
  900. struct usb_gadget_driver *gadget_driver;
  901. struct clk_bulk_data *clks;
  902. int num_clks;
  903. struct reset_control *reset;
  904. struct usb_phy *usb2_phy;
  905. struct usb_phy *usb3_phy;
  906. struct phy *usb2_generic_phy;
  907. struct phy *usb3_generic_phy;
  908. bool phys_ready;
  909. struct ulpi *ulpi;
  910. bool ulpi_ready;
  911. void __iomem *regs;
  912. size_t regs_size;
  913. enum usb_dr_mode dr_mode;
  914. u32 current_dr_role;
  915. u32 desired_dr_role;
  916. struct extcon_dev *edev;
  917. struct notifier_block edev_nb;
  918. enum usb_phy_interface hsphy_mode;
  919. u32 fladj;
  920. u32 irq_gadget;
  921. u32 otg_irq;
  922. u32 current_otg_role;
  923. u32 desired_otg_role;
  924. bool otg_restart_host;
  925. u32 nr_scratch;
  926. u32 u1u2;
  927. u32 maximum_speed;
  928. /*
  929. * All 3.1 IP version constants are greater than the 3.0 IP
  930. * version constants. This works for most version checks in
  931. * dwc3. However, in the future, this may not apply as
  932. * features may be developed on newer versions of the 3.0 IP
  933. * that are not in the 3.1 IP.
  934. */
  935. u32 revision;
  936. #define DWC3_REVISION_173A 0x5533173a
  937. #define DWC3_REVISION_175A 0x5533175a
  938. #define DWC3_REVISION_180A 0x5533180a
  939. #define DWC3_REVISION_183A 0x5533183a
  940. #define DWC3_REVISION_185A 0x5533185a
  941. #define DWC3_REVISION_187A 0x5533187a
  942. #define DWC3_REVISION_188A 0x5533188a
  943. #define DWC3_REVISION_190A 0x5533190a
  944. #define DWC3_REVISION_194A 0x5533194a
  945. #define DWC3_REVISION_200A 0x5533200a
  946. #define DWC3_REVISION_202A 0x5533202a
  947. #define DWC3_REVISION_210A 0x5533210a
  948. #define DWC3_REVISION_220A 0x5533220a
  949. #define DWC3_REVISION_230A 0x5533230a
  950. #define DWC3_REVISION_240A 0x5533240a
  951. #define DWC3_REVISION_250A 0x5533250a
  952. #define DWC3_REVISION_260A 0x5533260a
  953. #define DWC3_REVISION_270A 0x5533270a
  954. #define DWC3_REVISION_280A 0x5533280a
  955. #define DWC3_REVISION_290A 0x5533290a
  956. #define DWC3_REVISION_300A 0x5533300a
  957. #define DWC3_REVISION_310A 0x5533310a
  958. /*
  959. * NOTICE: we're using bit 31 as a "is usb 3.1" flag. This is really
  960. * just so dwc31 revisions are always larger than dwc3.
  961. */
  962. #define DWC3_REVISION_IS_DWC31 0x80000000
  963. #define DWC3_USB31_REVISION_110A (0x3131302a | DWC3_REVISION_IS_DWC31)
  964. #define DWC3_USB31_REVISION_120A (0x3132302a | DWC3_REVISION_IS_DWC31)
  965. enum dwc3_ep0_next ep0_next_event;
  966. enum dwc3_ep0_state ep0state;
  967. enum dwc3_link_state link_state;
  968. u16 u2sel;
  969. u16 u2pel;
  970. u8 u1sel;
  971. u8 u1pel;
  972. u8 speed;
  973. u8 num_eps;
  974. struct dwc3_hwparams hwparams;
  975. struct dentry *root;
  976. struct debugfs_regset32 *regset;
  977. u8 test_mode;
  978. u8 test_mode_nr;
  979. u8 lpm_nyet_threshold;
  980. u8 hird_threshold;
  981. u8 rx_thr_num_pkt_prd;
  982. u8 rx_max_burst_prd;
  983. u8 tx_thr_num_pkt_prd;
  984. u8 tx_max_burst_prd;
  985. const char *hsphy_interface;
  986. unsigned connected:1;
  987. unsigned delayed_status:1;
  988. unsigned ep0_bounced:1;
  989. unsigned ep0_expect_in:1;
  990. unsigned has_hibernation:1;
  991. unsigned sysdev_is_parent:1;
  992. unsigned has_lpm_erratum:1;
  993. unsigned is_utmi_l1_suspend:1;
  994. unsigned is_fpga:1;
  995. unsigned pending_events:1;
  996. unsigned pullups_connected:1;
  997. unsigned setup_packet_pending:1;
  998. unsigned three_stage_setup:1;
  999. unsigned usb3_lpm_capable:1;
  1000. unsigned disable_scramble_quirk:1;
  1001. unsigned u2exit_lfps_quirk:1;
  1002. unsigned u2ss_inp3_quirk:1;
  1003. unsigned req_p1p2p3_quirk:1;
  1004. unsigned del_p1p2p3_quirk:1;
  1005. unsigned del_phy_power_chg_quirk:1;
  1006. unsigned lfps_filter_quirk:1;
  1007. unsigned rx_detect_poll_quirk:1;
  1008. unsigned dis_u3_susphy_quirk:1;
  1009. unsigned dis_u2_susphy_quirk:1;
  1010. unsigned dis_enblslpm_quirk:1;
  1011. unsigned dis_rxdet_inp3_quirk:1;
  1012. unsigned dis_u2_freeclk_exists_quirk:1;
  1013. unsigned dis_del_phy_power_chg_quirk:1;
  1014. unsigned dis_tx_ipgap_linecheck_quirk:1;
  1015. unsigned tx_de_emphasis_quirk:1;
  1016. unsigned tx_de_emphasis:2;
  1017. unsigned dis_metastability_quirk:1;
  1018. u16 imod_interval;
  1019. };
  1020. #define INCRX_BURST_MODE 0
  1021. #define INCRX_UNDEF_LENGTH_BURST_MODE 1
  1022. #define work_to_dwc(w) (container_of((w), struct dwc3, drd_work))
  1023. /* -------------------------------------------------------------------------- */
  1024. struct dwc3_event_type {
  1025. u32 is_devspec:1;
  1026. u32 type:7;
  1027. u32 reserved8_31:24;
  1028. } __packed;
  1029. #define DWC3_DEPEVT_XFERCOMPLETE 0x01
  1030. #define DWC3_DEPEVT_XFERINPROGRESS 0x02
  1031. #define DWC3_DEPEVT_XFERNOTREADY 0x03
  1032. #define DWC3_DEPEVT_RXTXFIFOEVT 0x04
  1033. #define DWC3_DEPEVT_STREAMEVT 0x06
  1034. #define DWC3_DEPEVT_EPCMDCMPLT 0x07
  1035. /**
  1036. * struct dwc3_event_depvt - Device Endpoint Events
  1037. * @one_bit: indicates this is an endpoint event (not used)
  1038. * @endpoint_number: number of the endpoint
  1039. * @endpoint_event: The event we have:
  1040. * 0x00 - Reserved
  1041. * 0x01 - XferComplete
  1042. * 0x02 - XferInProgress
  1043. * 0x03 - XferNotReady
  1044. * 0x04 - RxTxFifoEvt (IN->Underrun, OUT->Overrun)
  1045. * 0x05 - Reserved
  1046. * 0x06 - StreamEvt
  1047. * 0x07 - EPCmdCmplt
  1048. * @reserved11_10: Reserved, don't use.
  1049. * @status: Indicates the status of the event. Refer to databook for
  1050. * more information.
  1051. * @parameters: Parameters of the current event. Refer to databook for
  1052. * more information.
  1053. */
  1054. struct dwc3_event_depevt {
  1055. u32 one_bit:1;
  1056. u32 endpoint_number:5;
  1057. u32 endpoint_event:4;
  1058. u32 reserved11_10:2;
  1059. u32 status:4;
  1060. /* Within XferNotReady */
  1061. #define DEPEVT_STATUS_TRANSFER_ACTIVE BIT(3)
  1062. /* Within XferComplete or XferInProgress */
  1063. #define DEPEVT_STATUS_BUSERR BIT(0)
  1064. #define DEPEVT_STATUS_SHORT BIT(1)
  1065. #define DEPEVT_STATUS_IOC BIT(2)
  1066. #define DEPEVT_STATUS_LST BIT(3) /* XferComplete */
  1067. #define DEPEVT_STATUS_MISSED_ISOC BIT(3) /* XferInProgress */
  1068. /* Stream event only */
  1069. #define DEPEVT_STREAMEVT_FOUND 1
  1070. #define DEPEVT_STREAMEVT_NOTFOUND 2
  1071. /* Control-only Status */
  1072. #define DEPEVT_STATUS_CONTROL_DATA 1
  1073. #define DEPEVT_STATUS_CONTROL_STATUS 2
  1074. #define DEPEVT_STATUS_CONTROL_PHASE(n) ((n) & 3)
  1075. /* In response to Start Transfer */
  1076. #define DEPEVT_TRANSFER_NO_RESOURCE 1
  1077. #define DEPEVT_TRANSFER_BUS_EXPIRY 2
  1078. u32 parameters:16;
  1079. /* For Command Complete Events */
  1080. #define DEPEVT_PARAMETER_CMD(n) (((n) & (0xf << 8)) >> 8)
  1081. } __packed;
  1082. /**
  1083. * struct dwc3_event_devt - Device Events
  1084. * @one_bit: indicates this is a non-endpoint event (not used)
  1085. * @device_event: indicates it's a device event. Should read as 0x00
  1086. * @type: indicates the type of device event.
  1087. * 0 - DisconnEvt
  1088. * 1 - USBRst
  1089. * 2 - ConnectDone
  1090. * 3 - ULStChng
  1091. * 4 - WkUpEvt
  1092. * 5 - Reserved
  1093. * 6 - EOPF
  1094. * 7 - SOF
  1095. * 8 - Reserved
  1096. * 9 - ErrticErr
  1097. * 10 - CmdCmplt
  1098. * 11 - EvntOverflow
  1099. * 12 - VndrDevTstRcved
  1100. * @reserved15_12: Reserved, not used
  1101. * @event_info: Information about this event
  1102. * @reserved31_25: Reserved, not used
  1103. */
  1104. struct dwc3_event_devt {
  1105. u32 one_bit:1;
  1106. u32 device_event:7;
  1107. u32 type:4;
  1108. u32 reserved15_12:4;
  1109. u32 event_info:9;
  1110. u32 reserved31_25:7;
  1111. } __packed;
  1112. /**
  1113. * struct dwc3_event_gevt - Other Core Events
  1114. * @one_bit: indicates this is a non-endpoint event (not used)
  1115. * @device_event: indicates it's (0x03) Carkit or (0x04) I2C event.
  1116. * @phy_port_number: self-explanatory
  1117. * @reserved31_12: Reserved, not used.
  1118. */
  1119. struct dwc3_event_gevt {
  1120. u32 one_bit:1;
  1121. u32 device_event:7;
  1122. u32 phy_port_number:4;
  1123. u32 reserved31_12:20;
  1124. } __packed;
  1125. /**
  1126. * union dwc3_event - representation of Event Buffer contents
  1127. * @raw: raw 32-bit event
  1128. * @type: the type of the event
  1129. * @depevt: Device Endpoint Event
  1130. * @devt: Device Event
  1131. * @gevt: Global Event
  1132. */
  1133. union dwc3_event {
  1134. u32 raw;
  1135. struct dwc3_event_type type;
  1136. struct dwc3_event_depevt depevt;
  1137. struct dwc3_event_devt devt;
  1138. struct dwc3_event_gevt gevt;
  1139. };
  1140. /**
  1141. * struct dwc3_gadget_ep_cmd_params - representation of endpoint command
  1142. * parameters
  1143. * @param2: third parameter
  1144. * @param1: second parameter
  1145. * @param0: first parameter
  1146. */
  1147. struct dwc3_gadget_ep_cmd_params {
  1148. u32 param2;
  1149. u32 param1;
  1150. u32 param0;
  1151. };
  1152. /*
  1153. * DWC3 Features to be used as Driver Data
  1154. */
  1155. #define DWC3_HAS_PERIPHERAL BIT(0)
  1156. #define DWC3_HAS_XHCI BIT(1)
  1157. #define DWC3_HAS_OTG BIT(3)
  1158. /* prototypes */
  1159. void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode);
  1160. void dwc3_set_mode(struct dwc3 *dwc, u32 mode);
  1161. u32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type);
  1162. /* check whether we are on the DWC_usb3 core */
  1163. static inline bool dwc3_is_usb3(struct dwc3 *dwc)
  1164. {
  1165. return !(dwc->revision & DWC3_REVISION_IS_DWC31);
  1166. }
  1167. /* check whether we are on the DWC_usb31 core */
  1168. static inline bool dwc3_is_usb31(struct dwc3 *dwc)
  1169. {
  1170. return !!(dwc->revision & DWC3_REVISION_IS_DWC31);
  1171. }
  1172. bool dwc3_has_imod(struct dwc3 *dwc);
  1173. int dwc3_event_buffers_setup(struct dwc3 *dwc);
  1174. void dwc3_event_buffers_cleanup(struct dwc3 *dwc);
  1175. #if IS_ENABLED(CONFIG_USB_DWC3_HOST) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
  1176. int dwc3_host_init(struct dwc3 *dwc);
  1177. void dwc3_host_exit(struct dwc3 *dwc);
  1178. #else
  1179. static inline int dwc3_host_init(struct dwc3 *dwc)
  1180. { return 0; }
  1181. static inline void dwc3_host_exit(struct dwc3 *dwc)
  1182. { }
  1183. #endif
  1184. #if IS_ENABLED(CONFIG_USB_DWC3_GADGET) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
  1185. int dwc3_gadget_init(struct dwc3 *dwc);
  1186. void dwc3_gadget_exit(struct dwc3 *dwc);
  1187. int dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode);
  1188. int dwc3_gadget_get_link_state(struct dwc3 *dwc);
  1189. int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state);
  1190. int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd,
  1191. struct dwc3_gadget_ep_cmd_params *params);
  1192. int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned cmd, u32 param);
  1193. #else
  1194. static inline int dwc3_gadget_init(struct dwc3 *dwc)
  1195. { return 0; }
  1196. static inline void dwc3_gadget_exit(struct dwc3 *dwc)
  1197. { }
  1198. static inline int dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode)
  1199. { return 0; }
  1200. static inline int dwc3_gadget_get_link_state(struct dwc3 *dwc)
  1201. { return 0; }
  1202. static inline int dwc3_gadget_set_link_state(struct dwc3 *dwc,
  1203. enum dwc3_link_state state)
  1204. { return 0; }
  1205. static inline int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd,
  1206. struct dwc3_gadget_ep_cmd_params *params)
  1207. { return 0; }
  1208. static inline int dwc3_send_gadget_generic_command(struct dwc3 *dwc,
  1209. int cmd, u32 param)
  1210. { return 0; }
  1211. #endif
  1212. #if IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
  1213. int dwc3_drd_init(struct dwc3 *dwc);
  1214. void dwc3_drd_exit(struct dwc3 *dwc);
  1215. void dwc3_otg_init(struct dwc3 *dwc);
  1216. void dwc3_otg_exit(struct dwc3 *dwc);
  1217. void dwc3_otg_update(struct dwc3 *dwc, bool ignore_idstatus);
  1218. void dwc3_otg_host_init(struct dwc3 *dwc);
  1219. #else
  1220. static inline int dwc3_drd_init(struct dwc3 *dwc)
  1221. { return 0; }
  1222. static inline void dwc3_drd_exit(struct dwc3 *dwc)
  1223. { }
  1224. static inline void dwc3_otg_init(struct dwc3 *dwc)
  1225. { }
  1226. static inline void dwc3_otg_exit(struct dwc3 *dwc)
  1227. { }
  1228. static inline void dwc3_otg_update(struct dwc3 *dwc, bool ignore_idstatus)
  1229. { }
  1230. static inline void dwc3_otg_host_init(struct dwc3 *dwc)
  1231. { }
  1232. #endif
  1233. /* power management interface */
  1234. #if !IS_ENABLED(CONFIG_USB_DWC3_HOST)
  1235. int dwc3_gadget_suspend(struct dwc3 *dwc);
  1236. int dwc3_gadget_resume(struct dwc3 *dwc);
  1237. void dwc3_gadget_process_pending_events(struct dwc3 *dwc);
  1238. #else
  1239. static inline int dwc3_gadget_suspend(struct dwc3 *dwc)
  1240. {
  1241. return 0;
  1242. }
  1243. static inline int dwc3_gadget_resume(struct dwc3 *dwc)
  1244. {
  1245. return 0;
  1246. }
  1247. static inline void dwc3_gadget_process_pending_events(struct dwc3 *dwc)
  1248. {
  1249. }
  1250. #endif /* !IS_ENABLED(CONFIG_USB_DWC3_HOST) */
  1251. #if IS_ENABLED(CONFIG_USB_DWC3_ULPI)
  1252. int dwc3_ulpi_init(struct dwc3 *dwc);
  1253. void dwc3_ulpi_exit(struct dwc3 *dwc);
  1254. #else
  1255. static inline int dwc3_ulpi_init(struct dwc3 *dwc)
  1256. { return 0; }
  1257. static inline void dwc3_ulpi_exit(struct dwc3 *dwc)
  1258. { }
  1259. #endif
  1260. #endif /* __DRIVERS_USB_DWC3_CORE_H */