core.h 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448
  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. * @lock: spinlock for endpoint request queue traversal
  545. * @regs: pointer to first endpoint register
  546. * @trb_pool: array of transaction buffers
  547. * @trb_pool_dma: dma address of @trb_pool
  548. * @trb_enqueue: enqueue 'pointer' into TRB array
  549. * @trb_dequeue: dequeue 'pointer' into TRB array
  550. * @dwc: pointer to DWC controller
  551. * @saved_state: ep state saved during hibernation
  552. * @flags: endpoint flags (wedged, stalled, ...)
  553. * @number: endpoint number (1 - 15)
  554. * @type: set to bmAttributes & USB_ENDPOINT_XFERTYPE_MASK
  555. * @resource_index: Resource transfer index
  556. * @frame_number: set to the frame number we want this transfer to start (ISOC)
  557. * @interval: the interval on which the ISOC transfer is started
  558. * @name: a human readable name e.g. ep1out-bulk
  559. * @direction: true for TX, false for RX
  560. * @stream_capable: true when streams are enabled
  561. */
  562. struct dwc3_ep {
  563. struct usb_ep endpoint;
  564. struct list_head cancelled_list;
  565. struct list_head pending_list;
  566. struct list_head started_list;
  567. spinlock_t lock;
  568. void __iomem *regs;
  569. struct dwc3_trb *trb_pool;
  570. dma_addr_t trb_pool_dma;
  571. struct dwc3 *dwc;
  572. u32 saved_state;
  573. unsigned flags;
  574. #define DWC3_EP_ENABLED BIT(0)
  575. #define DWC3_EP_STALL BIT(1)
  576. #define DWC3_EP_WEDGE BIT(2)
  577. #define DWC3_EP_TRANSFER_STARTED BIT(3)
  578. #define DWC3_EP_PENDING_REQUEST BIT(5)
  579. #define DWC3_EP_END_TRANSFER_PENDING BIT(7)
  580. /* This last one is specific to EP0 */
  581. #define DWC3_EP0_DIR_IN BIT(31)
  582. /*
  583. * IMPORTANT: we *know* we have 256 TRBs in our @trb_pool, so we will
  584. * use a u8 type here. If anybody decides to increase number of TRBs to
  585. * anything larger than 256 - I can't see why people would want to do
  586. * this though - then this type needs to be changed.
  587. *
  588. * By using u8 types we ensure that our % operator when incrementing
  589. * enqueue and dequeue get optimized away by the compiler.
  590. */
  591. u8 trb_enqueue;
  592. u8 trb_dequeue;
  593. u8 number;
  594. u8 type;
  595. u8 resource_index;
  596. u32 frame_number;
  597. u32 interval;
  598. char name[20];
  599. unsigned direction:1;
  600. unsigned stream_capable:1;
  601. };
  602. enum dwc3_phy {
  603. DWC3_PHY_UNKNOWN = 0,
  604. DWC3_PHY_USB3,
  605. DWC3_PHY_USB2,
  606. };
  607. enum dwc3_ep0_next {
  608. DWC3_EP0_UNKNOWN = 0,
  609. DWC3_EP0_COMPLETE,
  610. DWC3_EP0_NRDY_DATA,
  611. DWC3_EP0_NRDY_STATUS,
  612. };
  613. enum dwc3_ep0_state {
  614. EP0_UNCONNECTED = 0,
  615. EP0_SETUP_PHASE,
  616. EP0_DATA_PHASE,
  617. EP0_STATUS_PHASE,
  618. };
  619. enum dwc3_link_state {
  620. /* In SuperSpeed */
  621. DWC3_LINK_STATE_U0 = 0x00, /* in HS, means ON */
  622. DWC3_LINK_STATE_U1 = 0x01,
  623. DWC3_LINK_STATE_U2 = 0x02, /* in HS, means SLEEP */
  624. DWC3_LINK_STATE_U3 = 0x03, /* in HS, means SUSPEND */
  625. DWC3_LINK_STATE_SS_DIS = 0x04,
  626. DWC3_LINK_STATE_RX_DET = 0x05, /* in HS, means Early Suspend */
  627. DWC3_LINK_STATE_SS_INACT = 0x06,
  628. DWC3_LINK_STATE_POLL = 0x07,
  629. DWC3_LINK_STATE_RECOV = 0x08,
  630. DWC3_LINK_STATE_HRESET = 0x09,
  631. DWC3_LINK_STATE_CMPLY = 0x0a,
  632. DWC3_LINK_STATE_LPBK = 0x0b,
  633. DWC3_LINK_STATE_RESET = 0x0e,
  634. DWC3_LINK_STATE_RESUME = 0x0f,
  635. DWC3_LINK_STATE_MASK = 0x0f,
  636. };
  637. /* TRB Length, PCM and Status */
  638. #define DWC3_TRB_SIZE_MASK (0x00ffffff)
  639. #define DWC3_TRB_SIZE_LENGTH(n) ((n) & DWC3_TRB_SIZE_MASK)
  640. #define DWC3_TRB_SIZE_PCM1(n) (((n) & 0x03) << 24)
  641. #define DWC3_TRB_SIZE_TRBSTS(n) (((n) & (0x0f << 28)) >> 28)
  642. #define DWC3_TRBSTS_OK 0
  643. #define DWC3_TRBSTS_MISSED_ISOC 1
  644. #define DWC3_TRBSTS_SETUP_PENDING 2
  645. #define DWC3_TRB_STS_XFER_IN_PROG 4
  646. /* TRB Control */
  647. #define DWC3_TRB_CTRL_HWO BIT(0)
  648. #define DWC3_TRB_CTRL_LST BIT(1)
  649. #define DWC3_TRB_CTRL_CHN BIT(2)
  650. #define DWC3_TRB_CTRL_CSP BIT(3)
  651. #define DWC3_TRB_CTRL_TRBCTL(n) (((n) & 0x3f) << 4)
  652. #define DWC3_TRB_CTRL_ISP_IMI BIT(10)
  653. #define DWC3_TRB_CTRL_IOC BIT(11)
  654. #define DWC3_TRB_CTRL_SID_SOFN(n) (((n) & 0xffff) << 14)
  655. #define DWC3_TRBCTL_TYPE(n) ((n) & (0x3f << 4))
  656. #define DWC3_TRBCTL_NORMAL DWC3_TRB_CTRL_TRBCTL(1)
  657. #define DWC3_TRBCTL_CONTROL_SETUP DWC3_TRB_CTRL_TRBCTL(2)
  658. #define DWC3_TRBCTL_CONTROL_STATUS2 DWC3_TRB_CTRL_TRBCTL(3)
  659. #define DWC3_TRBCTL_CONTROL_STATUS3 DWC3_TRB_CTRL_TRBCTL(4)
  660. #define DWC3_TRBCTL_CONTROL_DATA DWC3_TRB_CTRL_TRBCTL(5)
  661. #define DWC3_TRBCTL_ISOCHRONOUS_FIRST DWC3_TRB_CTRL_TRBCTL(6)
  662. #define DWC3_TRBCTL_ISOCHRONOUS DWC3_TRB_CTRL_TRBCTL(7)
  663. #define DWC3_TRBCTL_LINK_TRB DWC3_TRB_CTRL_TRBCTL(8)
  664. /**
  665. * struct dwc3_trb - transfer request block (hw format)
  666. * @bpl: DW0-3
  667. * @bph: DW4-7
  668. * @size: DW8-B
  669. * @ctrl: DWC-F
  670. */
  671. struct dwc3_trb {
  672. u32 bpl;
  673. u32 bph;
  674. u32 size;
  675. u32 ctrl;
  676. } __packed;
  677. /**
  678. * struct dwc3_hwparams - copy of HWPARAMS registers
  679. * @hwparams0: GHWPARAMS0
  680. * @hwparams1: GHWPARAMS1
  681. * @hwparams2: GHWPARAMS2
  682. * @hwparams3: GHWPARAMS3
  683. * @hwparams4: GHWPARAMS4
  684. * @hwparams5: GHWPARAMS5
  685. * @hwparams6: GHWPARAMS6
  686. * @hwparams7: GHWPARAMS7
  687. * @hwparams8: GHWPARAMS8
  688. */
  689. struct dwc3_hwparams {
  690. u32 hwparams0;
  691. u32 hwparams1;
  692. u32 hwparams2;
  693. u32 hwparams3;
  694. u32 hwparams4;
  695. u32 hwparams5;
  696. u32 hwparams6;
  697. u32 hwparams7;
  698. u32 hwparams8;
  699. };
  700. /* HWPARAMS0 */
  701. #define DWC3_MODE(n) ((n) & 0x7)
  702. #define DWC3_MDWIDTH(n) (((n) & 0xff00) >> 8)
  703. /* HWPARAMS1 */
  704. #define DWC3_NUM_INT(n) (((n) & (0x3f << 15)) >> 15)
  705. /* HWPARAMS3 */
  706. #define DWC3_NUM_IN_EPS_MASK (0x1f << 18)
  707. #define DWC3_NUM_EPS_MASK (0x3f << 12)
  708. #define DWC3_NUM_EPS(p) (((p)->hwparams3 & \
  709. (DWC3_NUM_EPS_MASK)) >> 12)
  710. #define DWC3_NUM_IN_EPS(p) (((p)->hwparams3 & \
  711. (DWC3_NUM_IN_EPS_MASK)) >> 18)
  712. /* HWPARAMS7 */
  713. #define DWC3_RAM1_DEPTH(n) ((n) & 0xffff)
  714. /**
  715. * struct dwc3_request - representation of a transfer request
  716. * @request: struct usb_request to be transferred
  717. * @list: a list_head used for request queueing
  718. * @dep: struct dwc3_ep owning this request
  719. * @sg: pointer to first incomplete sg
  720. * @start_sg: pointer to the sg which should be queued next
  721. * @num_pending_sgs: counter to pending sgs
  722. * @num_queued_sgs: counter to the number of sgs which already got queued
  723. * @remaining: amount of data remaining
  724. * @epnum: endpoint number to which this request refers
  725. * @trb: pointer to struct dwc3_trb
  726. * @trb_dma: DMA address of @trb
  727. * @num_trbs: number of TRBs used by this request
  728. * @needs_extra_trb: true when request needs one extra TRB (either due to ZLP
  729. * or unaligned OUT)
  730. * @direction: IN or OUT direction flag
  731. * @mapped: true when request has been dma-mapped
  732. * @started: request is started
  733. */
  734. struct dwc3_request {
  735. struct usb_request request;
  736. struct list_head list;
  737. struct dwc3_ep *dep;
  738. struct scatterlist *sg;
  739. struct scatterlist *start_sg;
  740. unsigned num_pending_sgs;
  741. unsigned int num_queued_sgs;
  742. unsigned remaining;
  743. u8 epnum;
  744. struct dwc3_trb *trb;
  745. dma_addr_t trb_dma;
  746. unsigned num_trbs;
  747. unsigned needs_extra_trb:1;
  748. unsigned direction:1;
  749. unsigned mapped:1;
  750. unsigned started:1;
  751. };
  752. /*
  753. * struct dwc3_scratchpad_array - hibernation scratchpad array
  754. * (format defined by hw)
  755. */
  756. struct dwc3_scratchpad_array {
  757. __le64 dma_adr[DWC3_MAX_HIBER_SCRATCHBUFS];
  758. };
  759. /**
  760. * struct dwc3 - representation of our controller
  761. * @drd_work: workqueue used for role swapping
  762. * @ep0_trb: trb which is used for the ctrl_req
  763. * @bounce: address of bounce buffer
  764. * @scratchbuf: address of scratch buffer
  765. * @setup_buf: used while precessing STD USB requests
  766. * @ep0_trb_addr: dma address of @ep0_trb
  767. * @bounce_addr: dma address of @bounce
  768. * @ep0_usb_req: dummy req used while handling STD USB requests
  769. * @scratch_addr: dma address of scratchbuf
  770. * @ep0_in_setup: one control transfer is completed and enter setup phase
  771. * @lock: for synchronizing
  772. * @dev: pointer to our struct device
  773. * @sysdev: pointer to the DMA-capable device
  774. * @xhci: pointer to our xHCI child
  775. * @xhci_resources: struct resources for our @xhci child
  776. * @ev_buf: struct dwc3_event_buffer pointer
  777. * @eps: endpoint array
  778. * @gadget: device side representation of the peripheral controller
  779. * @gadget_driver: pointer to the gadget driver
  780. * @clks: array of clocks
  781. * @num_clks: number of clocks
  782. * @reset: reset control
  783. * @regs: base address for our registers
  784. * @regs_size: address space size
  785. * @fladj: frame length adjustment
  786. * @irq_gadget: peripheral controller's IRQ number
  787. * @otg_irq: IRQ number for OTG IRQs
  788. * @current_otg_role: current role of operation while using the OTG block
  789. * @desired_otg_role: desired role of operation while using the OTG block
  790. * @otg_restart_host: flag that OTG controller needs to restart host
  791. * @nr_scratch: number of scratch buffers
  792. * @u1u2: only used on revisions <1.83a for workaround
  793. * @maximum_speed: maximum speed requested (mainly for testing purposes)
  794. * @revision: revision register contents
  795. * @dr_mode: requested mode of operation
  796. * @current_dr_role: current role of operation when in dual-role mode
  797. * @desired_dr_role: desired role of operation when in dual-role mode
  798. * @edev: extcon handle
  799. * @edev_nb: extcon notifier
  800. * @hsphy_mode: UTMI phy mode, one of following:
  801. * - USBPHY_INTERFACE_MODE_UTMI
  802. * - USBPHY_INTERFACE_MODE_UTMIW
  803. * @usb2_phy: pointer to USB2 PHY
  804. * @usb3_phy: pointer to USB3 PHY
  805. * @usb2_generic_phy: pointer to USB2 PHY
  806. * @usb3_generic_phy: pointer to USB3 PHY
  807. * @phys_ready: flag to indicate that PHYs are ready
  808. * @ulpi: pointer to ulpi interface
  809. * @ulpi_ready: flag to indicate that ULPI is initialized
  810. * @u2sel: parameter from Set SEL request.
  811. * @u2pel: parameter from Set SEL request.
  812. * @u1sel: parameter from Set SEL request.
  813. * @u1pel: parameter from Set SEL request.
  814. * @num_eps: number of endpoints
  815. * @ep0_next_event: hold the next expected event
  816. * @ep0state: state of endpoint zero
  817. * @link_state: link state
  818. * @speed: device speed (super, high, full, low)
  819. * @hwparams: copy of hwparams registers
  820. * @root: debugfs root folder pointer
  821. * @regset: debugfs pointer to regdump file
  822. * @test_mode: true when we're entering a USB test mode
  823. * @test_mode_nr: test feature selector
  824. * @lpm_nyet_threshold: LPM NYET response threshold
  825. * @hird_threshold: HIRD threshold
  826. * @rx_thr_num_pkt_prd: periodic ESS receive packet count
  827. * @rx_max_burst_prd: max periodic ESS receive burst size
  828. * @tx_thr_num_pkt_prd: periodic ESS transmit packet count
  829. * @tx_max_burst_prd: max periodic ESS transmit burst size
  830. * @hsphy_interface: "utmi" or "ulpi"
  831. * @connected: true when we're connected to a host, false otherwise
  832. * @delayed_status: true when gadget driver asks for delayed status
  833. * @ep0_bounced: true when we used bounce buffer
  834. * @ep0_expect_in: true when we expect a DATA IN transfer
  835. * @has_hibernation: true when dwc3 was configured with Hibernation
  836. * @sysdev_is_parent: true when dwc3 device has a parent driver
  837. * @has_lpm_erratum: true when core was configured with LPM Erratum. Note that
  838. * there's now way for software to detect this in runtime.
  839. * @is_utmi_l1_suspend: the core asserts output signal
  840. * 0 - utmi_sleep_n
  841. * 1 - utmi_l1_suspend_n
  842. * @is_fpga: true when we are using the FPGA board
  843. * @pending_events: true when we have pending IRQs to be handled
  844. * @pullups_connected: true when Run/Stop bit is set
  845. * @setup_packet_pending: true when there's a Setup Packet in FIFO. Workaround
  846. * @three_stage_setup: set if we perform a three phase setup
  847. * @usb3_lpm_capable: set if hadrware supports Link Power Management
  848. * @disable_scramble_quirk: set if we enable the disable scramble quirk
  849. * @u2exit_lfps_quirk: set if we enable u2exit lfps quirk
  850. * @u2ss_inp3_quirk: set if we enable P3 OK for U2/SS Inactive quirk
  851. * @req_p1p2p3_quirk: set if we enable request p1p2p3 quirk
  852. * @del_p1p2p3_quirk: set if we enable delay p1p2p3 quirk
  853. * @del_phy_power_chg_quirk: set if we enable delay phy power change quirk
  854. * @lfps_filter_quirk: set if we enable LFPS filter quirk
  855. * @rx_detect_poll_quirk: set if we enable rx_detect to polling lfps quirk
  856. * @dis_u3_susphy_quirk: set if we disable usb3 suspend phy
  857. * @dis_u2_susphy_quirk: set if we disable usb2 suspend phy
  858. * @dis_enblslpm_quirk: set if we clear enblslpm in GUSB2PHYCFG,
  859. * disabling the suspend signal to the PHY.
  860. * @dis_rxdet_inp3_quirk: set if we disable Rx.Detect in P3
  861. * @dis_u2_freeclk_exists_quirk : set if we clear u2_freeclk_exists
  862. * in GUSB2PHYCFG, specify that USB2 PHY doesn't
  863. * provide a free-running PHY clock.
  864. * @dis_del_phy_power_chg_quirk: set if we disable delay phy power
  865. * change quirk.
  866. * @dis_tx_ipgap_linecheck_quirk: set if we disable u2mac linestate
  867. * check during HS transmit.
  868. * @tx_de_emphasis_quirk: set if we enable Tx de-emphasis quirk
  869. * @tx_de_emphasis: Tx de-emphasis value
  870. * 0 - -6dB de-emphasis
  871. * 1 - -3.5dB de-emphasis
  872. * 2 - No de-emphasis
  873. * 3 - Reserved
  874. * @dis_metastability_quirk: set to disable metastability quirk.
  875. * @imod_interval: set the interrupt moderation interval in 250ns
  876. * increments or 0 to disable.
  877. */
  878. struct dwc3 {
  879. struct work_struct drd_work;
  880. struct dwc3_trb *ep0_trb;
  881. void *bounce;
  882. void *scratchbuf;
  883. u8 *setup_buf;
  884. dma_addr_t ep0_trb_addr;
  885. dma_addr_t bounce_addr;
  886. dma_addr_t scratch_addr;
  887. struct dwc3_request ep0_usb_req;
  888. struct completion ep0_in_setup;
  889. /* device lock */
  890. spinlock_t lock;
  891. struct device *dev;
  892. struct device *sysdev;
  893. struct platform_device *xhci;
  894. struct resource xhci_resources[DWC3_XHCI_RESOURCES_NUM];
  895. struct dwc3_event_buffer *ev_buf;
  896. struct dwc3_ep *eps[DWC3_ENDPOINTS_NUM];
  897. struct usb_gadget gadget;
  898. struct usb_gadget_driver *gadget_driver;
  899. struct clk_bulk_data *clks;
  900. int num_clks;
  901. struct reset_control *reset;
  902. struct usb_phy *usb2_phy;
  903. struct usb_phy *usb3_phy;
  904. struct phy *usb2_generic_phy;
  905. struct phy *usb3_generic_phy;
  906. bool phys_ready;
  907. struct ulpi *ulpi;
  908. bool ulpi_ready;
  909. void __iomem *regs;
  910. size_t regs_size;
  911. enum usb_dr_mode dr_mode;
  912. u32 current_dr_role;
  913. u32 desired_dr_role;
  914. struct extcon_dev *edev;
  915. struct notifier_block edev_nb;
  916. enum usb_phy_interface hsphy_mode;
  917. u32 fladj;
  918. u32 irq_gadget;
  919. u32 otg_irq;
  920. u32 current_otg_role;
  921. u32 desired_otg_role;
  922. bool otg_restart_host;
  923. u32 nr_scratch;
  924. u32 u1u2;
  925. u32 maximum_speed;
  926. /*
  927. * All 3.1 IP version constants are greater than the 3.0 IP
  928. * version constants. This works for most version checks in
  929. * dwc3. However, in the future, this may not apply as
  930. * features may be developed on newer versions of the 3.0 IP
  931. * that are not in the 3.1 IP.
  932. */
  933. u32 revision;
  934. #define DWC3_REVISION_173A 0x5533173a
  935. #define DWC3_REVISION_175A 0x5533175a
  936. #define DWC3_REVISION_180A 0x5533180a
  937. #define DWC3_REVISION_183A 0x5533183a
  938. #define DWC3_REVISION_185A 0x5533185a
  939. #define DWC3_REVISION_187A 0x5533187a
  940. #define DWC3_REVISION_188A 0x5533188a
  941. #define DWC3_REVISION_190A 0x5533190a
  942. #define DWC3_REVISION_194A 0x5533194a
  943. #define DWC3_REVISION_200A 0x5533200a
  944. #define DWC3_REVISION_202A 0x5533202a
  945. #define DWC3_REVISION_210A 0x5533210a
  946. #define DWC3_REVISION_220A 0x5533220a
  947. #define DWC3_REVISION_230A 0x5533230a
  948. #define DWC3_REVISION_240A 0x5533240a
  949. #define DWC3_REVISION_250A 0x5533250a
  950. #define DWC3_REVISION_260A 0x5533260a
  951. #define DWC3_REVISION_270A 0x5533270a
  952. #define DWC3_REVISION_280A 0x5533280a
  953. #define DWC3_REVISION_290A 0x5533290a
  954. #define DWC3_REVISION_300A 0x5533300a
  955. #define DWC3_REVISION_310A 0x5533310a
  956. /*
  957. * NOTICE: we're using bit 31 as a "is usb 3.1" flag. This is really
  958. * just so dwc31 revisions are always larger than dwc3.
  959. */
  960. #define DWC3_REVISION_IS_DWC31 0x80000000
  961. #define DWC3_USB31_REVISION_110A (0x3131302a | DWC3_REVISION_IS_DWC31)
  962. #define DWC3_USB31_REVISION_120A (0x3132302a | DWC3_REVISION_IS_DWC31)
  963. enum dwc3_ep0_next ep0_next_event;
  964. enum dwc3_ep0_state ep0state;
  965. enum dwc3_link_state link_state;
  966. u16 u2sel;
  967. u16 u2pel;
  968. u8 u1sel;
  969. u8 u1pel;
  970. u8 speed;
  971. u8 num_eps;
  972. struct dwc3_hwparams hwparams;
  973. struct dentry *root;
  974. struct debugfs_regset32 *regset;
  975. u8 test_mode;
  976. u8 test_mode_nr;
  977. u8 lpm_nyet_threshold;
  978. u8 hird_threshold;
  979. u8 rx_thr_num_pkt_prd;
  980. u8 rx_max_burst_prd;
  981. u8 tx_thr_num_pkt_prd;
  982. u8 tx_max_burst_prd;
  983. const char *hsphy_interface;
  984. unsigned connected:1;
  985. unsigned delayed_status:1;
  986. unsigned ep0_bounced:1;
  987. unsigned ep0_expect_in:1;
  988. unsigned has_hibernation:1;
  989. unsigned sysdev_is_parent:1;
  990. unsigned has_lpm_erratum:1;
  991. unsigned is_utmi_l1_suspend:1;
  992. unsigned is_fpga:1;
  993. unsigned pending_events:1;
  994. unsigned pullups_connected:1;
  995. unsigned setup_packet_pending:1;
  996. unsigned three_stage_setup:1;
  997. unsigned usb3_lpm_capable:1;
  998. unsigned disable_scramble_quirk:1;
  999. unsigned u2exit_lfps_quirk:1;
  1000. unsigned u2ss_inp3_quirk:1;
  1001. unsigned req_p1p2p3_quirk:1;
  1002. unsigned del_p1p2p3_quirk:1;
  1003. unsigned del_phy_power_chg_quirk:1;
  1004. unsigned lfps_filter_quirk:1;
  1005. unsigned rx_detect_poll_quirk:1;
  1006. unsigned dis_u3_susphy_quirk:1;
  1007. unsigned dis_u2_susphy_quirk:1;
  1008. unsigned dis_enblslpm_quirk:1;
  1009. unsigned dis_rxdet_inp3_quirk:1;
  1010. unsigned dis_u2_freeclk_exists_quirk:1;
  1011. unsigned dis_del_phy_power_chg_quirk:1;
  1012. unsigned dis_tx_ipgap_linecheck_quirk:1;
  1013. unsigned tx_de_emphasis_quirk:1;
  1014. unsigned tx_de_emphasis:2;
  1015. unsigned dis_metastability_quirk:1;
  1016. u16 imod_interval;
  1017. };
  1018. #define INCRX_BURST_MODE 0
  1019. #define INCRX_UNDEF_LENGTH_BURST_MODE 1
  1020. #define work_to_dwc(w) (container_of((w), struct dwc3, drd_work))
  1021. /* -------------------------------------------------------------------------- */
  1022. struct dwc3_event_type {
  1023. u32 is_devspec:1;
  1024. u32 type:7;
  1025. u32 reserved8_31:24;
  1026. } __packed;
  1027. #define DWC3_DEPEVT_XFERCOMPLETE 0x01
  1028. #define DWC3_DEPEVT_XFERINPROGRESS 0x02
  1029. #define DWC3_DEPEVT_XFERNOTREADY 0x03
  1030. #define DWC3_DEPEVT_RXTXFIFOEVT 0x04
  1031. #define DWC3_DEPEVT_STREAMEVT 0x06
  1032. #define DWC3_DEPEVT_EPCMDCMPLT 0x07
  1033. /**
  1034. * struct dwc3_event_depvt - Device Endpoint Events
  1035. * @one_bit: indicates this is an endpoint event (not used)
  1036. * @endpoint_number: number of the endpoint
  1037. * @endpoint_event: The event we have:
  1038. * 0x00 - Reserved
  1039. * 0x01 - XferComplete
  1040. * 0x02 - XferInProgress
  1041. * 0x03 - XferNotReady
  1042. * 0x04 - RxTxFifoEvt (IN->Underrun, OUT->Overrun)
  1043. * 0x05 - Reserved
  1044. * 0x06 - StreamEvt
  1045. * 0x07 - EPCmdCmplt
  1046. * @reserved11_10: Reserved, don't use.
  1047. * @status: Indicates the status of the event. Refer to databook for
  1048. * more information.
  1049. * @parameters: Parameters of the current event. Refer to databook for
  1050. * more information.
  1051. */
  1052. struct dwc3_event_depevt {
  1053. u32 one_bit:1;
  1054. u32 endpoint_number:5;
  1055. u32 endpoint_event:4;
  1056. u32 reserved11_10:2;
  1057. u32 status:4;
  1058. /* Within XferNotReady */
  1059. #define DEPEVT_STATUS_TRANSFER_ACTIVE BIT(3)
  1060. /* Within XferComplete or XferInProgress */
  1061. #define DEPEVT_STATUS_BUSERR BIT(0)
  1062. #define DEPEVT_STATUS_SHORT BIT(1)
  1063. #define DEPEVT_STATUS_IOC BIT(2)
  1064. #define DEPEVT_STATUS_LST BIT(3) /* XferComplete */
  1065. #define DEPEVT_STATUS_MISSED_ISOC BIT(3) /* XferInProgress */
  1066. /* Stream event only */
  1067. #define DEPEVT_STREAMEVT_FOUND 1
  1068. #define DEPEVT_STREAMEVT_NOTFOUND 2
  1069. /* Control-only Status */
  1070. #define DEPEVT_STATUS_CONTROL_DATA 1
  1071. #define DEPEVT_STATUS_CONTROL_STATUS 2
  1072. #define DEPEVT_STATUS_CONTROL_PHASE(n) ((n) & 3)
  1073. /* In response to Start Transfer */
  1074. #define DEPEVT_TRANSFER_NO_RESOURCE 1
  1075. #define DEPEVT_TRANSFER_BUS_EXPIRY 2
  1076. u32 parameters:16;
  1077. /* For Command Complete Events */
  1078. #define DEPEVT_PARAMETER_CMD(n) (((n) & (0xf << 8)) >> 8)
  1079. } __packed;
  1080. /**
  1081. * struct dwc3_event_devt - Device Events
  1082. * @one_bit: indicates this is a non-endpoint event (not used)
  1083. * @device_event: indicates it's a device event. Should read as 0x00
  1084. * @type: indicates the type of device event.
  1085. * 0 - DisconnEvt
  1086. * 1 - USBRst
  1087. * 2 - ConnectDone
  1088. * 3 - ULStChng
  1089. * 4 - WkUpEvt
  1090. * 5 - Reserved
  1091. * 6 - EOPF
  1092. * 7 - SOF
  1093. * 8 - Reserved
  1094. * 9 - ErrticErr
  1095. * 10 - CmdCmplt
  1096. * 11 - EvntOverflow
  1097. * 12 - VndrDevTstRcved
  1098. * @reserved15_12: Reserved, not used
  1099. * @event_info: Information about this event
  1100. * @reserved31_25: Reserved, not used
  1101. */
  1102. struct dwc3_event_devt {
  1103. u32 one_bit:1;
  1104. u32 device_event:7;
  1105. u32 type:4;
  1106. u32 reserved15_12:4;
  1107. u32 event_info:9;
  1108. u32 reserved31_25:7;
  1109. } __packed;
  1110. /**
  1111. * struct dwc3_event_gevt - Other Core Events
  1112. * @one_bit: indicates this is a non-endpoint event (not used)
  1113. * @device_event: indicates it's (0x03) Carkit or (0x04) I2C event.
  1114. * @phy_port_number: self-explanatory
  1115. * @reserved31_12: Reserved, not used.
  1116. */
  1117. struct dwc3_event_gevt {
  1118. u32 one_bit:1;
  1119. u32 device_event:7;
  1120. u32 phy_port_number:4;
  1121. u32 reserved31_12:20;
  1122. } __packed;
  1123. /**
  1124. * union dwc3_event - representation of Event Buffer contents
  1125. * @raw: raw 32-bit event
  1126. * @type: the type of the event
  1127. * @depevt: Device Endpoint Event
  1128. * @devt: Device Event
  1129. * @gevt: Global Event
  1130. */
  1131. union dwc3_event {
  1132. u32 raw;
  1133. struct dwc3_event_type type;
  1134. struct dwc3_event_depevt depevt;
  1135. struct dwc3_event_devt devt;
  1136. struct dwc3_event_gevt gevt;
  1137. };
  1138. /**
  1139. * struct dwc3_gadget_ep_cmd_params - representation of endpoint command
  1140. * parameters
  1141. * @param2: third parameter
  1142. * @param1: second parameter
  1143. * @param0: first parameter
  1144. */
  1145. struct dwc3_gadget_ep_cmd_params {
  1146. u32 param2;
  1147. u32 param1;
  1148. u32 param0;
  1149. };
  1150. /*
  1151. * DWC3 Features to be used as Driver Data
  1152. */
  1153. #define DWC3_HAS_PERIPHERAL BIT(0)
  1154. #define DWC3_HAS_XHCI BIT(1)
  1155. #define DWC3_HAS_OTG BIT(3)
  1156. /* prototypes */
  1157. void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode);
  1158. void dwc3_set_mode(struct dwc3 *dwc, u32 mode);
  1159. u32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type);
  1160. /* check whether we are on the DWC_usb3 core */
  1161. static inline bool dwc3_is_usb3(struct dwc3 *dwc)
  1162. {
  1163. return !(dwc->revision & DWC3_REVISION_IS_DWC31);
  1164. }
  1165. /* check whether we are on the DWC_usb31 core */
  1166. static inline bool dwc3_is_usb31(struct dwc3 *dwc)
  1167. {
  1168. return !!(dwc->revision & DWC3_REVISION_IS_DWC31);
  1169. }
  1170. bool dwc3_has_imod(struct dwc3 *dwc);
  1171. int dwc3_event_buffers_setup(struct dwc3 *dwc);
  1172. void dwc3_event_buffers_cleanup(struct dwc3 *dwc);
  1173. #if IS_ENABLED(CONFIG_USB_DWC3_HOST) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
  1174. int dwc3_host_init(struct dwc3 *dwc);
  1175. void dwc3_host_exit(struct dwc3 *dwc);
  1176. #else
  1177. static inline int dwc3_host_init(struct dwc3 *dwc)
  1178. { return 0; }
  1179. static inline void dwc3_host_exit(struct dwc3 *dwc)
  1180. { }
  1181. #endif
  1182. #if IS_ENABLED(CONFIG_USB_DWC3_GADGET) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
  1183. int dwc3_gadget_init(struct dwc3 *dwc);
  1184. void dwc3_gadget_exit(struct dwc3 *dwc);
  1185. int dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode);
  1186. int dwc3_gadget_get_link_state(struct dwc3 *dwc);
  1187. int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state);
  1188. int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd,
  1189. struct dwc3_gadget_ep_cmd_params *params);
  1190. int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned cmd, u32 param);
  1191. #else
  1192. static inline int dwc3_gadget_init(struct dwc3 *dwc)
  1193. { return 0; }
  1194. static inline void dwc3_gadget_exit(struct dwc3 *dwc)
  1195. { }
  1196. static inline int dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode)
  1197. { return 0; }
  1198. static inline int dwc3_gadget_get_link_state(struct dwc3 *dwc)
  1199. { return 0; }
  1200. static inline int dwc3_gadget_set_link_state(struct dwc3 *dwc,
  1201. enum dwc3_link_state state)
  1202. { return 0; }
  1203. static inline int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd,
  1204. struct dwc3_gadget_ep_cmd_params *params)
  1205. { return 0; }
  1206. static inline int dwc3_send_gadget_generic_command(struct dwc3 *dwc,
  1207. int cmd, u32 param)
  1208. { return 0; }
  1209. #endif
  1210. #if IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
  1211. int dwc3_drd_init(struct dwc3 *dwc);
  1212. void dwc3_drd_exit(struct dwc3 *dwc);
  1213. void dwc3_otg_init(struct dwc3 *dwc);
  1214. void dwc3_otg_exit(struct dwc3 *dwc);
  1215. void dwc3_otg_update(struct dwc3 *dwc, bool ignore_idstatus);
  1216. void dwc3_otg_host_init(struct dwc3 *dwc);
  1217. #else
  1218. static inline int dwc3_drd_init(struct dwc3 *dwc)
  1219. { return 0; }
  1220. static inline void dwc3_drd_exit(struct dwc3 *dwc)
  1221. { }
  1222. static inline void dwc3_otg_init(struct dwc3 *dwc)
  1223. { }
  1224. static inline void dwc3_otg_exit(struct dwc3 *dwc)
  1225. { }
  1226. static inline void dwc3_otg_update(struct dwc3 *dwc, bool ignore_idstatus)
  1227. { }
  1228. static inline void dwc3_otg_host_init(struct dwc3 *dwc)
  1229. { }
  1230. #endif
  1231. /* power management interface */
  1232. #if !IS_ENABLED(CONFIG_USB_DWC3_HOST)
  1233. int dwc3_gadget_suspend(struct dwc3 *dwc);
  1234. int dwc3_gadget_resume(struct dwc3 *dwc);
  1235. void dwc3_gadget_process_pending_events(struct dwc3 *dwc);
  1236. #else
  1237. static inline int dwc3_gadget_suspend(struct dwc3 *dwc)
  1238. {
  1239. return 0;
  1240. }
  1241. static inline int dwc3_gadget_resume(struct dwc3 *dwc)
  1242. {
  1243. return 0;
  1244. }
  1245. static inline void dwc3_gadget_process_pending_events(struct dwc3 *dwc)
  1246. {
  1247. }
  1248. #endif /* !IS_ENABLED(CONFIG_USB_DWC3_HOST) */
  1249. #if IS_ENABLED(CONFIG_USB_DWC3_ULPI)
  1250. int dwc3_ulpi_init(struct dwc3 *dwc);
  1251. void dwc3_ulpi_exit(struct dwc3 *dwc);
  1252. #else
  1253. static inline int dwc3_ulpi_init(struct dwc3 *dwc)
  1254. { return 0; }
  1255. static inline void dwc3_ulpi_exit(struct dwc3 *dwc)
  1256. { }
  1257. #endif
  1258. #endif /* __DRIVERS_USB_DWC3_CORE_H */