core.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968
  1. /**
  2. * core.h - DesignWare USB3 DRD Core Header
  3. *
  4. * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
  5. *
  6. * Authors: Felipe Balbi <balbi@ti.com>,
  7. * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions, and the following disclaimer,
  14. * without modification.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * 3. The names of the above-listed copyright holders may not be used
  19. * to endorse or promote products derived from this software without
  20. * specific prior written permission.
  21. *
  22. * ALTERNATIVELY, this software may be distributed under the terms of the
  23. * GNU General Public License ("GPL") version 2, as published by the Free
  24. * Software Foundation.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  27. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  30. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  31. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  32. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  33. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  34. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  35. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  36. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. */
  38. #ifndef __DRIVERS_USB_DWC3_CORE_H
  39. #define __DRIVERS_USB_DWC3_CORE_H
  40. #include <linux/device.h>
  41. #include <linux/spinlock.h>
  42. #include <linux/ioport.h>
  43. #include <linux/list.h>
  44. #include <linux/dma-mapping.h>
  45. #include <linux/mm.h>
  46. #include <linux/debugfs.h>
  47. #include <linux/usb/ch9.h>
  48. #include <linux/usb/gadget.h>
  49. #include "dwc3_otg.h"
  50. /* Global constants */
  51. #define DWC3_EP0_BOUNCE_SIZE 512
  52. #define DWC3_ENDPOINTS_NUM 32
  53. #define DWC3_XHCI_RESOURCES_NUM 2
  54. #define DWC3_EVENT_BUFFERS_SIZE (2 * PAGE_SIZE)
  55. #define DWC3_EVENT_TYPE_MASK 0xfe
  56. #define DWC3_EVENT_TYPE_DEV 0
  57. #define DWC3_EVENT_TYPE_CARKIT 3
  58. #define DWC3_EVENT_TYPE_I2C 4
  59. #define DWC3_DEVICE_EVENT_DISCONNECT 0
  60. #define DWC3_DEVICE_EVENT_RESET 1
  61. #define DWC3_DEVICE_EVENT_CONNECT_DONE 2
  62. #define DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE 3
  63. #define DWC3_DEVICE_EVENT_WAKEUP 4
  64. #define DWC3_DEVICE_EVENT_HIBER_REQ 5
  65. #define DWC3_DEVICE_EVENT_EOPF 6
  66. #define DWC3_DEVICE_EVENT_SOF 7
  67. #define DWC3_DEVICE_EVENT_ERRATIC_ERROR 9
  68. #define DWC3_DEVICE_EVENT_CMD_CMPL 10
  69. #define DWC3_DEVICE_EVENT_OVERFLOW 11
  70. #define DWC3_DEVICE_EVENT_VENDOR_DEV_TEST_LMP 12
  71. #define DWC3_GEVNTCOUNT_MASK 0xfffc
  72. #define DWC3_GSNPSID_MASK 0xffff0000
  73. #define DWC3_GSNPSREV_MASK 0xffff
  74. /* DWC3 registers memory space boundries */
  75. #define DWC3_XHCI_REGS_START 0x0
  76. #define DWC3_XHCI_REGS_END 0x7fff
  77. #define DWC3_GLOBALS_REGS_START 0xc100
  78. #define DWC3_GLOBALS_REGS_END 0xc6ff
  79. #define DWC3_DEVICE_REGS_START 0xc700
  80. #define DWC3_DEVICE_REGS_END 0xcbff
  81. #define DWC3_OTG_REGS_START 0xcc00
  82. #define DWC3_OTG_REGS_END 0xccff
  83. /* Global Registers */
  84. #define DWC3_GSBUSCFG0 0xc100
  85. #define DWC3_GSBUSCFG1 0xc104
  86. #define DWC3_GTXTHRCFG 0xc108
  87. #define DWC3_GRXTHRCFG 0xc10c
  88. #define DWC3_GCTL 0xc110
  89. #define DWC3_GEVTEN 0xc114
  90. #define DWC3_GSTS 0xc118
  91. #define DWC3_GSNPSID 0xc120
  92. #define DWC3_GGPIO 0xc124
  93. #define DWC3_GUID 0xc128
  94. #define DWC3_GUCTL 0xc12c
  95. #define DWC3_GBUSERRADDR0 0xc130
  96. #define DWC3_GBUSERRADDR1 0xc134
  97. #define DWC3_GPRTBIMAP0 0xc138
  98. #define DWC3_GPRTBIMAP1 0xc13c
  99. #define DWC3_GHWPARAMS0 0xc140
  100. #define DWC3_GHWPARAMS1 0xc144
  101. #define DWC3_GHWPARAMS2 0xc148
  102. #define DWC3_GHWPARAMS3 0xc14c
  103. #define DWC3_GHWPARAMS4 0xc150
  104. #define DWC3_GHWPARAMS5 0xc154
  105. #define DWC3_GHWPARAMS6 0xc158
  106. #define DWC3_GHWPARAMS7 0xc15c
  107. #define DWC3_GDBGFIFOSPACE 0xc160
  108. #define DWC3_GDBGLTSSM 0xc164
  109. #define DWC3_GPRTBIMAP_HS0 0xc180
  110. #define DWC3_GPRTBIMAP_HS1 0xc184
  111. #define DWC3_GPRTBIMAP_FS0 0xc188
  112. #define DWC3_GPRTBIMAP_FS1 0xc18c
  113. #define DWC3_GUSB2PHYCFG(n) (0xc200 + (n * 0x04))
  114. #define DWC3_GUSB2I2CCTL(n) (0xc240 + (n * 0x04))
  115. #define DWC3_GUSB2PHYACC(n) (0xc280 + (n * 0x04))
  116. #define DWC3_GUSB3PIPECTL(n) (0xc2c0 + (n * 0x04))
  117. #define DWC3_GTXFIFOSIZ(n) (0xc300 + (n * 0x04))
  118. #define DWC3_GRXFIFOSIZ(n) (0xc380 + (n * 0x04))
  119. #define DWC3_GEVNTADRLO(n) (0xc400 + (n * 0x10))
  120. #define DWC3_GEVNTADRHI(n) (0xc404 + (n * 0x10))
  121. #define DWC3_GEVNTSIZ(n) (0xc408 + (n * 0x10))
  122. #define DWC3_GEVNTCOUNT(n) (0xc40c + (n * 0x10))
  123. #define DWC3_GHWPARAMS8 0xc600
  124. /* Device Registers */
  125. #define DWC3_DCFG 0xc700
  126. #define DWC3_DCTL 0xc704
  127. #define DWC3_DEVTEN 0xc708
  128. #define DWC3_DSTS 0xc70c
  129. #define DWC3_DGCMDPAR 0xc710
  130. #define DWC3_DGCMD 0xc714
  131. #define DWC3_DALEPENA 0xc720
  132. #define DWC3_DEPCMDPAR2(n) (0xc800 + (n * 0x10))
  133. #define DWC3_DEPCMDPAR1(n) (0xc804 + (n * 0x10))
  134. #define DWC3_DEPCMDPAR0(n) (0xc808 + (n * 0x10))
  135. #define DWC3_DEPCMD(n) (0xc80c + (n * 0x10))
  136. /* OTG Registers */
  137. #define DWC3_OCFG 0xcc00
  138. #define DWC3_OCTL 0xcc04
  139. #define DWC3_OEVT 0xcc08
  140. #define DWC3_OEVTEN 0xcc0c
  141. #define DWC3_OSTS 0xcc10
  142. /* Bit fields */
  143. /* Global Configuration Register */
  144. #define DWC3_GCTL_PWRDNSCALE(n) ((n) << 19)
  145. #define DWC3_GCTL_PWRDNSCALEMASK (0xFFF80000)
  146. #define DWC3_GCTL_U2RSTECN (1 << 16)
  147. #define DWC3_GCTL_SOFITPSYNC (1 << 10)
  148. #define DWC3_GCTL_U2EXIT_LFPS (1 << 2)
  149. #define DWC3_GCTL_RAMCLKSEL(x) (((x) & DWC3_GCTL_CLK_MASK) << 6)
  150. #define DWC3_GCTL_CLK_BUS (0)
  151. #define DWC3_GCTL_CLK_PIPE (1)
  152. #define DWC3_GCTL_CLK_PIPEHALF (2)
  153. #define DWC3_GCTL_CLK_MASK (3)
  154. #define DWC3_GCTL_PRTCAP(n) (((n) & (3 << 12)) >> 12)
  155. #define DWC3_GCTL_PRTCAPDIR(n) ((n) << 12)
  156. #define DWC3_GCTL_PRTCAP_HOST 1
  157. #define DWC3_GCTL_PRTCAP_DEVICE 2
  158. #define DWC3_GCTL_PRTCAP_OTG 3
  159. #define DWC3_GCTL_CORESOFTRESET (1 << 11)
  160. #define DWC3_GCTL_SCALEDOWN(n) ((n) << 4)
  161. #define DWC3_GCTL_SCALEDOWN_MASK DWC3_GCTL_SCALEDOWN(3)
  162. #define DWC3_GCTL_DISSCRAMBLE (1 << 3)
  163. #define DWC3_GCTL_GBLHIBERNATIONEN (1 << 1)
  164. #define DWC3_GCTL_DSBLCLKGTNG (1 << 0)
  165. /* Global User Control Register */
  166. #define DWC3_GUCTL_REFCLKPER (0x3FF << 22)
  167. /* Global USB2 PHY Configuration Register */
  168. #define DWC3_GUSB2PHYCFG_PHYSOFTRST (1 << 31)
  169. #define DWC3_GUSB2PHYCFG_SUSPHY (1 << 6)
  170. /* Global USB3 PIPE Control Register */
  171. #define DWC3_GUSB3PIPECTL_PHYSOFTRST (1 << 31)
  172. #define DWC3_GUSB3PIPECTL_SUSPHY (1 << 17)
  173. #define DWC3_GUSB3PIPECTL_DELAY_P1P2P3 (7 << 19)
  174. #define DWC3_GUSB3PIPECTL_DIS_RXDET_U3_RXDET (1 << 22)
  175. #define DWC3_GUSB3PIPECTL_ELASTIC_BUF_MODE (1 << 0)
  176. /* Global TX Fifo Size Register */
  177. #define DWC3_GTXFIFOSIZ_TXFDEF(n) ((n) & 0xffff)
  178. #define DWC3_GTXFIFOSIZ_TXFSTADDR(n) ((n) & 0xffff0000)
  179. /* Global HWPARAMS1 Register */
  180. #define DWC3_GHWPARAMS1_EN_PWROPT(n) (((n) & (3 << 24)) >> 24)
  181. #define DWC3_GHWPARAMS1_EN_PWROPT_NO 0
  182. #define DWC3_GHWPARAMS1_EN_PWROPT_CLK 1
  183. #define DWC3_GHWPARAMS1_EN_PWROPT_HIB 2
  184. #define DWC3_GHWPARAMS1_PWROPT(n) ((n) << 24)
  185. #define DWC3_GHWPARAMS1_PWROPT_MASK DWC3_GHWPARAMS1_PWROPT(3)
  186. /* Global HWPARAMS4 Register */
  187. #define DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(n) (((n) & (0x0f << 13)) >> 13)
  188. #define DWC3_MAX_HIBER_SCRATCHBUFS 15
  189. /* Global HWPARAMS6 Register */
  190. #define DWC3_GHWPARAMS6_SRP_SUPPORT (1 << 10)
  191. /* Device Configuration Register */
  192. #define DWC3_DCFG_LPM_CAP (1 << 22)
  193. #define DWC3_DCFG_DEVADDR(addr) ((addr) << 3)
  194. #define DWC3_DCFG_DEVADDR_MASK DWC3_DCFG_DEVADDR(0x7f)
  195. #define DWC3_DCFG_SPEED_MASK (7 << 0)
  196. #define DWC3_DCFG_SUPERSPEED (4 << 0)
  197. #define DWC3_DCFG_HIGHSPEED (0 << 0)
  198. #define DWC3_DCFG_FULLSPEED2 (1 << 0)
  199. #define DWC3_DCFG_LOWSPEED (2 << 0)
  200. #define DWC3_DCFG_FULLSPEED1 (3 << 0)
  201. #define DWC3_DCFG_LPM_CAP (1 << 22)
  202. /* Device Control Register */
  203. #define DWC3_DCTL_RUN_STOP (1 << 31)
  204. #define DWC3_DCTL_CSFTRST (1 << 30)
  205. #define DWC3_DCTL_LSFTRST (1 << 29)
  206. #define DWC3_DCTL_HIRD_THRES_MASK (0x1f << 24)
  207. #define DWC3_DCTL_HIRD_THRES(n) ((n) << 24)
  208. #define DWC3_DCTL_APPL1RES (1 << 23)
  209. /* These apply for core versions 1.87a and earlier */
  210. #define DWC3_DCTL_TRGTULST_MASK (0x0f << 17)
  211. #define DWC3_DCTL_TRGTULST(n) ((n) << 17)
  212. #define DWC3_DCTL_TRGTULST_U2 (DWC3_DCTL_TRGTULST(2))
  213. #define DWC3_DCTL_TRGTULST_U3 (DWC3_DCTL_TRGTULST(3))
  214. #define DWC3_DCTL_TRGTULST_SS_DIS (DWC3_DCTL_TRGTULST(4))
  215. #define DWC3_DCTL_TRGTULST_RX_DET (DWC3_DCTL_TRGTULST(5))
  216. #define DWC3_DCTL_TRGTULST_SS_INACT (DWC3_DCTL_TRGTULST(6))
  217. /* These apply for core versions 1.94a and later */
  218. #define DWC3_DCTL_KEEP_CONNECT (1 << 19)
  219. #define DWC3_DCTL_L1_HIBER_EN (1 << 18)
  220. #define DWC3_DCTL_CRS (1 << 17)
  221. #define DWC3_DCTL_CSS (1 << 16)
  222. #define DWC3_DCTL_INITU2ENA (1 << 12)
  223. #define DWC3_DCTL_ACCEPTU2ENA (1 << 11)
  224. #define DWC3_DCTL_INITU1ENA (1 << 10)
  225. #define DWC3_DCTL_ACCEPTU1ENA (1 << 9)
  226. #define DWC3_DCTL_TSTCTRL_MASK (0xf << 1)
  227. #define DWC3_DCTL_ULSTCHNGREQ_MASK (0x0f << 5)
  228. #define DWC3_DCTL_ULSTCHNGREQ(n) (((n) << 5) & DWC3_DCTL_ULSTCHNGREQ_MASK)
  229. #define DWC3_DCTL_ULSTCHNG_NO_ACTION (DWC3_DCTL_ULSTCHNGREQ(0))
  230. #define DWC3_DCTL_ULSTCHNG_SS_DISABLED (DWC3_DCTL_ULSTCHNGREQ(4))
  231. #define DWC3_DCTL_ULSTCHNG_RX_DETECT (DWC3_DCTL_ULSTCHNGREQ(5))
  232. #define DWC3_DCTL_ULSTCHNG_SS_INACTIVE (DWC3_DCTL_ULSTCHNGREQ(6))
  233. #define DWC3_DCTL_ULSTCHNG_RECOVERY (DWC3_DCTL_ULSTCHNGREQ(8))
  234. #define DWC3_DCTL_ULSTCHNG_COMPLIANCE (DWC3_DCTL_ULSTCHNGREQ(10))
  235. #define DWC3_DCTL_ULSTCHNG_LOOPBACK (DWC3_DCTL_ULSTCHNGREQ(11))
  236. /* Device Event Enable Register */
  237. #define DWC3_DEVTEN_VNDRDEVTSTRCVEDEN (1 << 12)
  238. #define DWC3_DEVTEN_EVNTOVERFLOWEN (1 << 11)
  239. #define DWC3_DEVTEN_CMDCMPLTEN (1 << 10)
  240. #define DWC3_DEVTEN_ERRTICERREN (1 << 9)
  241. #define DWC3_DEVTEN_SOFEN (1 << 7)
  242. #define DWC3_DEVTEN_EOPFEN (1 << 6)
  243. #define DWC3_DEVTEN_HIBERNATIONREQEVTEN (1 << 5)
  244. #define DWC3_DEVTEN_WKUPEVTEN (1 << 4)
  245. #define DWC3_DEVTEN_ULSTCNGEN (1 << 3)
  246. #define DWC3_DEVTEN_CONNECTDONEEN (1 << 2)
  247. #define DWC3_DEVTEN_USBRSTEN (1 << 1)
  248. #define DWC3_DEVTEN_DISCONNEVTEN (1 << 0)
  249. /* Device Status Register */
  250. #define DWC3_DSTS_DCNRD (1 << 29)
  251. /* This applies for core versions 1.87a and earlier */
  252. #define DWC3_DSTS_PWRUPREQ (1 << 24)
  253. /* These apply for core versions 1.94a and later */
  254. #define DWC3_DSTS_RSS (1 << 25)
  255. #define DWC3_DSTS_SSS (1 << 24)
  256. #define DWC3_DSTS_COREIDLE (1 << 23)
  257. #define DWC3_DSTS_DEVCTRLHLT (1 << 22)
  258. #define DWC3_DSTS_USBLNKST_MASK (0x0f << 18)
  259. #define DWC3_DSTS_USBLNKST(n) (((n) & DWC3_DSTS_USBLNKST_MASK) >> 18)
  260. #define DWC3_DSTS_RXFIFOEMPTY (1 << 17)
  261. #define DWC3_DSTS_SOFFN_MASK (0x3fff << 3)
  262. #define DWC3_DSTS_SOFFN(n) (((n) & DWC3_DSTS_SOFFN_MASK) >> 3)
  263. #define DWC3_DSTS_CONNECTSPD (7 << 0)
  264. #define DWC3_DSTS_SUPERSPEED (4 << 0)
  265. #define DWC3_DSTS_HIGHSPEED (0 << 0)
  266. #define DWC3_DSTS_FULLSPEED2 (1 << 0)
  267. #define DWC3_DSTS_LOWSPEED (2 << 0)
  268. #define DWC3_DSTS_FULLSPEED1 (3 << 0)
  269. /* Device Generic Command Register */
  270. #define DWC3_DGCMD_SET_LMP 0x01
  271. #define DWC3_DGCMD_SET_PERIODIC_PAR 0x02
  272. #define DWC3_DGCMD_XMIT_FUNCTION 0x03
  273. /* These apply for core versions 1.94a and later */
  274. #define DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO 0x04
  275. #define DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI 0x05
  276. #define DWC3_DGCMD_SELECTED_FIFO_FLUSH 0x09
  277. #define DWC3_DGCMD_ALL_FIFO_FLUSH 0x0a
  278. #define DWC3_DGCMD_SET_ENDPOINT_NRDY 0x0c
  279. #define DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK 0x10
  280. #define DWC3_DGCMD_STATUS(n) (((n) >> 15) & 1)
  281. #define DWC3_DGCMD_CMDACT (1 << 10)
  282. #define DWC3_DGCMD_CMDIOC (1 << 8)
  283. /* Device Generic Command Parameter Register */
  284. #define DWC3_DGCMDPAR_FORCE_LINKPM_ACCEPT (1 << 0)
  285. #define DWC3_DGCMDPAR_FIFO_NUM(n) ((n) << 0)
  286. #define DWC3_DGCMDPAR_RX_FIFO (0 << 5)
  287. #define DWC3_DGCMDPAR_TX_FIFO (1 << 5)
  288. #define DWC3_DGCMDPAR_LOOPBACK_DIS (0 << 0)
  289. #define DWC3_DGCMDPAR_LOOPBACK_ENA (1 << 0)
  290. /* Device Endpoint Command Register */
  291. #define DWC3_DEPCMD_PARAM_SHIFT 16
  292. #define DWC3_DEPCMD_PARAM(x) ((x) << DWC3_DEPCMD_PARAM_SHIFT)
  293. #define DWC3_DEPCMD_GET_RSC_IDX(x) (((x) >> DWC3_DEPCMD_PARAM_SHIFT) & 0x7f)
  294. #define DWC3_DEPCMD_STATUS(x) (((x) >> 15) & 1)
  295. #define DWC3_DEPCMD_HIPRI_FORCERM (1 << 11)
  296. #define DWC3_DEPCMD_CMDACT (1 << 10)
  297. #define DWC3_DEPCMD_CMDIOC (1 << 8)
  298. #define DWC3_DEPCMD_DEPSTARTCFG (0x09 << 0)
  299. #define DWC3_DEPCMD_ENDTRANSFER (0x08 << 0)
  300. #define DWC3_DEPCMD_UPDATETRANSFER (0x07 << 0)
  301. #define DWC3_DEPCMD_STARTTRANSFER (0x06 << 0)
  302. #define DWC3_DEPCMD_CLEARSTALL (0x05 << 0)
  303. #define DWC3_DEPCMD_SETSTALL (0x04 << 0)
  304. /* This applies for core versions 1.90a and earlier */
  305. #define DWC3_DEPCMD_GETSEQNUMBER (0x03 << 0)
  306. /* This applies for core versions 1.94a and later */
  307. #define DWC3_DEPCMD_GETEPSTATE (0x03 << 0)
  308. #define DWC3_DEPCMD_SETTRANSFRESOURCE (0x02 << 0)
  309. #define DWC3_DEPCMD_SETEPCONFIG (0x01 << 0)
  310. /* The EP number goes 0..31 so ep0 is always out and ep1 is always in */
  311. #define DWC3_DALEPENA_EP(n) (1 << n)
  312. #define DWC3_DEPCMD_TYPE_CONTROL 0
  313. #define DWC3_DEPCMD_TYPE_ISOC 1
  314. #define DWC3_DEPCMD_TYPE_BULK 2
  315. #define DWC3_DEPCMD_TYPE_INTR 3
  316. /* OTG Events Register */
  317. #define DWC3_OEVT_DEVICEMODE (1 << 31)
  318. #define DWC3_OEVTEN_OTGCONIDSTSCHNGEVNT (1 << 24)
  319. #define DWC3_OEVTEN_OTGADEVBHOSTENDEVNT (1 << 20)
  320. #define DWC3_OEVTEN_OTGADEVHOSTEVNT (1 << 19)
  321. #define DWC3_OEVTEN_OTGADEVHNPCHNGEVNT (1 << 18)
  322. #define DWC3_OEVTEN_OTGADEVSRPDETEVNT (1 << 17)
  323. #define DWC3_OEVTEN_OTGADEVSESSENDDETEVNT (1 << 16)
  324. #define DWC3_OEVTEN_OTGBDEVBHOSTENDEVNT (1 << 11)
  325. #define DWC3_OEVTEN_OTGBDEVHNPCHNGEVNT (1 << 10)
  326. #define DWC3_OEVTEN_OTGBDEVSESSVLDDETEVNT (1 << 9)
  327. #define DWC3_OEVTEN_OTGBDEVVBUSCHNGEVNT (1 << 8)
  328. /* OTG OSTS register */
  329. #define DWC3_OTG_OSTS_OTGSTATE_SHIFT (8)
  330. #define DWC3_OTG_OSTS_OTGSTATE (0xF << DWC3_OTG_OSTS_OTGSTATE_SHIFT)
  331. #define DWC3_OTG_OSTS_PERIPHERALSTATE (1 << 4)
  332. #define DWC3_OTG_OSTS_XHCIPRTPOWER (1 << 3)
  333. #define DWC3_OTG_OSTS_BSESVALID (1 << 2)
  334. #define DWC3_OTG_OSTS_VBUSVALID (1 << 1)
  335. #define DWC3_OTG_OSTS_CONIDSTS (1 << 0)
  336. /* OTG OSTS register */
  337. #define DWC3_OTG_OCTL_PERIMODE (1 << 6)
  338. #define DWC3_OTG_OCTL_PRTPWRCTL (1 << 5)
  339. #define DWC3_OTG_OCTL_HNPREQ (1 << 4)
  340. #define DWC3_OTG_OCTL_SESREQ (1 << 3)
  341. #define DWC3_OTG_OCTL_TERMSELDLPULSE (1 << 2)
  342. #define DWC3_OTG_OCTL_DEVSETHNPEN (1 << 1)
  343. #define DWC3_OTG_OCTL_HSTSETHNPEN (1 << 0)
  344. /* Structures */
  345. struct dwc3_trb;
  346. /**
  347. * struct dwc3_event_buffer - Software event buffer representation
  348. * @list: a list of event buffers
  349. * @buf: _THE_ buffer
  350. * @length: size of this buffer
  351. * @dma: dma_addr_t
  352. * @dwc: pointer to DWC controller
  353. */
  354. struct dwc3_event_buffer {
  355. void *buf;
  356. unsigned length;
  357. unsigned int lpos;
  358. dma_addr_t dma;
  359. struct dwc3 *dwc;
  360. };
  361. #define DWC3_EP_FLAG_STALLED (1 << 0)
  362. #define DWC3_EP_FLAG_WEDGED (1 << 1)
  363. #define DWC3_EP_DIRECTION_TX true
  364. #define DWC3_EP_DIRECTION_RX false
  365. #define DWC3_TRB_NUM 32
  366. #define DWC3_TRB_MASK (DWC3_TRB_NUM - 1)
  367. /**
  368. * struct dwc3_ep - device side endpoint representation
  369. * @endpoint: usb endpoint
  370. * @request_list: list of requests for this endpoint
  371. * @req_queued: list of requests on this ep which have TRBs setup
  372. * @trb_pool: array of transaction buffers
  373. * @trb_pool_dma: dma address of @trb_pool
  374. * @free_slot: next slot which is going to be used
  375. * @busy_slot: first slot which is owned by HW
  376. * @desc: usb_endpoint_descriptor pointer
  377. * @dwc: pointer to DWC controller
  378. * @flags: endpoint flags (wedged, stalled, ...)
  379. * @current_trb: index of current used trb
  380. * @number: endpoint number (1 - 15)
  381. * @type: set to bmAttributes & USB_ENDPOINT_XFERTYPE_MASK
  382. * @resource_index: Resource transfer index
  383. * @current_uf: Current uf received through last event parameter
  384. * @interval: the intervall on which the ISOC transfer is started
  385. * @name: a human readable name e.g. ep1out-bulk
  386. * @direction: true for TX, false for RX
  387. * @stream_capable: true when streams are enabled
  388. */
  389. struct dwc3_ep {
  390. struct usb_ep endpoint;
  391. struct list_head request_list;
  392. struct list_head req_queued;
  393. struct dwc3_trb *trb_pool;
  394. dma_addr_t trb_pool_dma;
  395. u32 free_slot;
  396. u32 busy_slot;
  397. const struct usb_ss_ep_comp_descriptor *comp_desc;
  398. struct dwc3 *dwc;
  399. unsigned flags;
  400. #define DWC3_EP_ENABLED (1 << 0)
  401. #define DWC3_EP_STALL (1 << 1)
  402. #define DWC3_EP_WEDGE (1 << 2)
  403. #define DWC3_EP_BUSY (1 << 4)
  404. #define DWC3_EP_PENDING_REQUEST (1 << 5)
  405. #define DWC3_EP_MISSED_ISOC (1 << 6)
  406. /* This last one is specific to EP0 */
  407. #define DWC3_EP0_DIR_IN (1 << 31)
  408. unsigned current_trb;
  409. u8 number;
  410. u8 type;
  411. u8 resource_index;
  412. u16 current_uf;
  413. u32 interval;
  414. char name[20];
  415. unsigned direction:1;
  416. unsigned stream_capable:1;
  417. };
  418. enum dwc3_phy {
  419. DWC3_PHY_UNKNOWN = 0,
  420. DWC3_PHY_USB3,
  421. DWC3_PHY_USB2,
  422. };
  423. enum dwc3_ep0_next {
  424. DWC3_EP0_UNKNOWN = 0,
  425. DWC3_EP0_COMPLETE,
  426. DWC3_EP0_NRDY_DATA,
  427. DWC3_EP0_NRDY_STATUS,
  428. };
  429. enum dwc3_ep0_state {
  430. EP0_UNCONNECTED = 0,
  431. EP0_SETUP_PHASE,
  432. EP0_DATA_PHASE,
  433. EP0_STATUS_PHASE,
  434. };
  435. enum dwc3_link_state {
  436. /* In SuperSpeed */
  437. DWC3_LINK_STATE_U0 = 0x00, /* in HS, means ON */
  438. DWC3_LINK_STATE_U1 = 0x01,
  439. DWC3_LINK_STATE_U2 = 0x02, /* in HS, means SLEEP */
  440. DWC3_LINK_STATE_U3 = 0x03, /* in HS, means SUSPEND */
  441. DWC3_LINK_STATE_SS_DIS = 0x04,
  442. DWC3_LINK_STATE_RX_DET = 0x05, /* in HS, means Early Suspend */
  443. DWC3_LINK_STATE_SS_INACT = 0x06,
  444. DWC3_LINK_STATE_POLL = 0x07,
  445. DWC3_LINK_STATE_RECOV = 0x08,
  446. DWC3_LINK_STATE_HRESET = 0x09,
  447. DWC3_LINK_STATE_CMPLY = 0x0a,
  448. DWC3_LINK_STATE_LPBK = 0x0b,
  449. DWC3_LINK_STATE_RESET = 0x0e,
  450. DWC3_LINK_STATE_RESUME = 0x0f,
  451. DWC3_LINK_STATE_MASK = 0x0f,
  452. };
  453. enum dwc3_device_state {
  454. DWC3_DEFAULT_STATE,
  455. DWC3_ADDRESS_STATE,
  456. DWC3_CONFIGURED_STATE,
  457. };
  458. /* TRB Length, PCM and Status */
  459. #define DWC3_TRB_SIZE_MASK (0x00ffffff)
  460. #define DWC3_TRB_SIZE_LENGTH(n) ((n) & DWC3_TRB_SIZE_MASK)
  461. #define DWC3_TRB_SIZE_PCM1(n) (((n) & 0x03) << 24)
  462. #define DWC3_TRB_SIZE_TRBSTS(n) (((n) & (0x0f << 28)) >> 28)
  463. #define DWC3_TRBSTS_OK 0
  464. #define DWC3_TRBSTS_MISSED_ISOC 1
  465. #define DWC3_TRBSTS_SETUP_PENDING 2
  466. #define DWC3_TRB_STS_XFER_IN_PROG 4
  467. /* TRB Control */
  468. #define DWC3_TRB_CTRL_HWO (1 << 0)
  469. #define DWC3_TRB_CTRL_LST (1 << 1)
  470. #define DWC3_TRB_CTRL_CHN (1 << 2)
  471. #define DWC3_TRB_CTRL_CSP (1 << 3)
  472. #define DWC3_TRB_CTRL_TRBCTL(n) (((n) & 0x3f) << 4)
  473. #define DWC3_TRB_CTRL_ISP_IMI (1 << 10)
  474. #define DWC3_TRB_CTRL_IOC (1 << 11)
  475. #define DWC3_TRB_CTRL_SID_SOFN(n) (((n) & 0xffff) << 14)
  476. #define DWC3_TRBCTL_NORMAL DWC3_TRB_CTRL_TRBCTL(1)
  477. #define DWC3_TRBCTL_CONTROL_SETUP DWC3_TRB_CTRL_TRBCTL(2)
  478. #define DWC3_TRBCTL_CONTROL_STATUS2 DWC3_TRB_CTRL_TRBCTL(3)
  479. #define DWC3_TRBCTL_CONTROL_STATUS3 DWC3_TRB_CTRL_TRBCTL(4)
  480. #define DWC3_TRBCTL_CONTROL_DATA DWC3_TRB_CTRL_TRBCTL(5)
  481. #define DWC3_TRBCTL_ISOCHRONOUS_FIRST DWC3_TRB_CTRL_TRBCTL(6)
  482. #define DWC3_TRBCTL_ISOCHRONOUS DWC3_TRB_CTRL_TRBCTL(7)
  483. #define DWC3_TRBCTL_LINK_TRB DWC3_TRB_CTRL_TRBCTL(8)
  484. /**
  485. * struct dwc3_trb - transfer request block (hw format)
  486. * @bpl: DW0-3
  487. * @bph: DW4-7
  488. * @size: DW8-B
  489. * @trl: DWC-F
  490. */
  491. struct dwc3_trb {
  492. u32 bpl;
  493. u32 bph;
  494. u32 size;
  495. u32 ctrl;
  496. } __packed;
  497. /**
  498. * dwc3_hwparams - copy of HWPARAMS registers
  499. * @hwparams0 - GHWPARAMS0
  500. * @hwparams1 - GHWPARAMS1
  501. * @hwparams2 - GHWPARAMS2
  502. * @hwparams3 - GHWPARAMS3
  503. * @hwparams4 - GHWPARAMS4
  504. * @hwparams5 - GHWPARAMS5
  505. * @hwparams6 - GHWPARAMS6
  506. * @hwparams7 - GHWPARAMS7
  507. * @hwparams8 - GHWPARAMS8
  508. */
  509. struct dwc3_hwparams {
  510. u32 hwparams0;
  511. u32 hwparams1;
  512. u32 hwparams2;
  513. u32 hwparams3;
  514. u32 hwparams4;
  515. u32 hwparams5;
  516. u32 hwparams6;
  517. u32 hwparams7;
  518. u32 hwparams8;
  519. };
  520. /* HWPARAMS0 */
  521. #define DWC3_MODE(n) ((n) & 0x7)
  522. #define DWC3_MODE_DEVICE 0
  523. #define DWC3_MODE_HOST 1
  524. #define DWC3_MODE_DRD 2
  525. #define DWC3_MODE_HUB 3
  526. #define DWC3_MDWIDTH(n) (((n) & 0xff00) >> 8)
  527. /* HWPARAMS1 */
  528. #define DWC3_NUM_INT(n) (((n) & (0x3f << 15)) >> 15)
  529. /* HWPARAMS3 */
  530. #define DWC3_NUM_IN_EPS_MASK (0x1f << 18)
  531. #define DWC3_NUM_EPS_MASK (0x3f << 12)
  532. #define DWC3_NUM_EPS(p) (((p)->hwparams3 & \
  533. (DWC3_NUM_EPS_MASK)) >> 12)
  534. #define DWC3_NUM_IN_EPS(p) (((p)->hwparams3 & \
  535. (DWC3_NUM_IN_EPS_MASK)) >> 18)
  536. /* HWPARAMS7 */
  537. #define DWC3_RAM1_DEPTH(n) ((n) & 0xffff)
  538. struct dwc3_request {
  539. struct usb_request request;
  540. struct list_head list;
  541. struct dwc3_ep *dep;
  542. u8 epnum;
  543. struct dwc3_trb *trb;
  544. struct dwc3_trb *ztrb;
  545. dma_addr_t trb_dma;
  546. unsigned direction:1;
  547. unsigned mapped:1;
  548. unsigned queued:1;
  549. };
  550. /*
  551. * struct dwc3_scratchpad_array - hibernation scratchpad array
  552. * (format defined by hw)
  553. */
  554. struct dwc3_scratchpad_array {
  555. __le64 dma_adr[DWC3_MAX_HIBER_SCRATCHBUFS];
  556. };
  557. #define DWC3_CONTROLLER_ERROR_EVENT 0
  558. #define DWC3_CONTROLLER_RESET_EVENT 1
  559. #define DWC3_CONTROLLER_POST_RESET_EVENT 2
  560. #define DWC3_CONTROLLER_POST_INITIALIZATION_EVENT 3
  561. /**
  562. * struct dwc3 - representation of our controller
  563. * @ctrl_req: usb control request which is used for ep0
  564. * @ep0_trb: trb which is used for the ctrl_req
  565. * @ep0_bounce: bounce buffer for ep0
  566. * @setup_buf: used while precessing STD USB requests
  567. * @ctrl_req_addr: dma address of ctrl_req
  568. * @ep0_trb: dma address of ep0_trb
  569. * @ep0_usb_req: dummy req used while handling STD USB requests
  570. * @ep0_bounce_addr: dma address of ep0_bounce
  571. * @lock: for synchronizing
  572. * @dev: pointer to our struct device
  573. * @xhci: pointer to our xHCI child
  574. * @event_buffer_list: a list of event buffers
  575. * @gadget: device side representation of the peripheral controller
  576. * @gadget_driver: pointer to the gadget driver
  577. * @regs: base address for our registers
  578. * @regs_size: address space size
  579. * @irq: IRQ number
  580. * @num_event_buffers: calculated number of event buffers
  581. * @u1u2: only used on revisions <1.83a for workaround
  582. * @maximum_speed: maximum speed requested (mainly for testing purposes)
  583. * @revision: revision register contents
  584. * @mode: mode of operation
  585. * @is_selfpowered: true when we are selfpowered
  586. * @three_stage_setup: set if we perform a three phase setup
  587. * @ep0_bounced: true when we used bounce buffer
  588. * @ep0_expect_in: true when we expect a DATA IN transfer
  589. * @start_config_issued: true when StartConfig command has been issued
  590. * @setup_packet_pending: true when there's a Setup Packet in FIFO. Workaround
  591. * @needs_fifo_resize: not all users might want fifo resizing, flag it
  592. * @resize_fifos: tells us it's ok to reconfigure our TxFIFO sizes.
  593. * @isoch_delay: wValue from Set Isochronous Delay request;
  594. * @u2sel: parameter from Set SEL request.
  595. * @u2pel: parameter from Set SEL request.
  596. * @u1sel: parameter from Set SEL request.
  597. * @u1pel: parameter from Set SEL request.
  598. * @num_out_eps: number of out endpoints
  599. * @num_in_eps: number of in endpoints
  600. * @ep0_next_event: hold the next expected event
  601. * @ep0state: state of endpoint zero
  602. * @link_state: link state
  603. * @speed: device speed (super, high, full, low)
  604. * @mem: points to start of memory which is used for this struct.
  605. * @hwparams: copy of hwparams registers
  606. * @root: debugfs root folder pointer
  607. * @tx_fifo_size: Available RAM size for TX fifo allocation
  608. * @err_evt_seen: previous event in queue was erratic error
  609. * @irq_cnt: total irq count
  610. */
  611. struct dwc3 {
  612. struct usb_ctrlrequest *ctrl_req;
  613. struct dwc3_trb *ep0_trb;
  614. void *ep0_bounce;
  615. u8 *setup_buf;
  616. dma_addr_t ctrl_req_addr;
  617. dma_addr_t ep0_trb_addr;
  618. dma_addr_t ep0_bounce_addr;
  619. struct dwc3_request ep0_usb_req;
  620. /* device lock */
  621. spinlock_t lock;
  622. struct device *dev;
  623. struct dwc3_otg *dotg;
  624. struct platform_device *xhci;
  625. struct resource xhci_resources[DWC3_XHCI_RESOURCES_NUM];
  626. struct dwc3_event_buffer **ev_buffs;
  627. struct dwc3_ep *eps[DWC3_ENDPOINTS_NUM];
  628. struct usb_gadget gadget;
  629. struct usb_gadget_driver *gadget_driver;
  630. void __iomem *regs;
  631. size_t regs_size;
  632. u32 num_event_buffers;
  633. u32 u1u2;
  634. u32 maximum_speed;
  635. u32 revision;
  636. u32 mode;
  637. #define DWC3_REVISION_173A 0x5533173a
  638. #define DWC3_REVISION_175A 0x5533175a
  639. #define DWC3_REVISION_180A 0x5533180a
  640. #define DWC3_REVISION_183A 0x5533183a
  641. #define DWC3_REVISION_185A 0x5533185a
  642. #define DWC3_REVISION_187A 0x5533187a
  643. #define DWC3_REVISION_188A 0x5533188a
  644. #define DWC3_REVISION_190A 0x5533190a
  645. #define DWC3_REVISION_194A 0x5533194a
  646. #define DWC3_REVISION_200A 0x5533200a
  647. #define DWC3_REVISION_202A 0x5533202a
  648. #define DWC3_REVISION_210A 0x5533210a
  649. #define DWC3_REVISION_220A 0x5533220a
  650. #define DWC3_REVISION_230A 0x5533230a
  651. unsigned is_selfpowered:1;
  652. unsigned three_stage_setup:1;
  653. unsigned ep0_bounced:1;
  654. unsigned ep0_expect_in:1;
  655. unsigned setup_packet_pending:1;
  656. unsigned delayed_status:1;
  657. unsigned needs_fifo_resize:1;
  658. unsigned resize_fifos:1;
  659. enum dwc3_ep0_next ep0_next_event;
  660. enum dwc3_ep0_state ep0state;
  661. enum dwc3_link_state link_state;
  662. enum dwc3_device_state dev_state;
  663. u16 isoch_delay;
  664. u16 u2sel;
  665. u16 u2pel;
  666. u8 u1sel;
  667. u8 u1pel;
  668. u8 speed;
  669. u8 num_out_eps;
  670. u8 num_in_eps;
  671. void *mem;
  672. struct dwc3_hwparams hwparams;
  673. struct dentry *root;
  674. u8 test_mode;
  675. u8 test_mode_nr;
  676. /* Indicate if the gadget was powered by the otg driver */
  677. bool vbus_active;
  678. /* Indicate if software connect was issued by the usb_gadget_driver */
  679. bool softconnect;
  680. void (*notify_event) (struct dwc3 *, unsigned);
  681. #if defined(CONFIG_SEC_H_PROJECT) || defined(CONFIG_SEC_F_PROJECT) || defined(CONFIG_SEC_K_PROJECT)
  682. enum usb_device_speed speed_limit;
  683. struct work_struct reconnect_work;
  684. int ss_host_avail;
  685. bool reconnect;
  686. #endif
  687. int tx_fifo_size;
  688. bool tx_fifo_reduced;
  689. bool err_evt_seen;
  690. unsigned long irq_cnt;
  691. };
  692. /* -------------------------------------------------------------------------- */
  693. /* -------------------------------------------------------------------------- */
  694. struct dwc3_event_type {
  695. u32 is_devspec:1;
  696. u32 type:7;
  697. u32 reserved8_31:24;
  698. } __packed;
  699. #define DWC3_DEPEVT_XFERCOMPLETE 0x01
  700. #define DWC3_DEPEVT_XFERINPROGRESS 0x02
  701. #define DWC3_DEPEVT_XFERNOTREADY 0x03
  702. #define DWC3_DEPEVT_RXTXFIFOEVT 0x04
  703. #define DWC3_DEPEVT_STREAMEVT 0x06
  704. #define DWC3_DEPEVT_EPCMDCMPLT 0x07
  705. /**
  706. * struct dwc3_event_depvt - Device Endpoint Events
  707. * @one_bit: indicates this is an endpoint event (not used)
  708. * @endpoint_number: number of the endpoint
  709. * @endpoint_event: The event we have:
  710. * 0x00 - Reserved
  711. * 0x01 - XferComplete
  712. * 0x02 - XferInProgress
  713. * 0x03 - XferNotReady
  714. * 0x04 - RxTxFifoEvt (IN->Underrun, OUT->Overrun)
  715. * 0x05 - Reserved
  716. * 0x06 - StreamEvt
  717. * 0x07 - EPCmdCmplt
  718. * @reserved11_10: Reserved, don't use.
  719. * @status: Indicates the status of the event. Refer to databook for
  720. * more information.
  721. * @parameters: Parameters of the current event. Refer to databook for
  722. * more information.
  723. */
  724. struct dwc3_event_depevt {
  725. u32 one_bit:1;
  726. u32 endpoint_number:5;
  727. u32 endpoint_event:4;
  728. u32 reserved11_10:2;
  729. u32 status:4;
  730. /* Within XferNotReady */
  731. #define DEPEVT_STATUS_TRANSFER_ACTIVE (1 << 3)
  732. /* Within XferComplete */
  733. #define DEPEVT_STATUS_BUSERR (1 << 0)
  734. #define DEPEVT_STATUS_SHORT (1 << 1)
  735. #define DEPEVT_STATUS_IOC (1 << 2)
  736. #define DEPEVT_STATUS_LST (1 << 3)
  737. /* Stream event only */
  738. #define DEPEVT_STREAMEVT_FOUND 1
  739. #define DEPEVT_STREAMEVT_NOTFOUND 2
  740. /* Control-only Status */
  741. #define DEPEVT_STATUS_CONTROL_DATA 1
  742. #define DEPEVT_STATUS_CONTROL_STATUS 2
  743. u32 parameters:16;
  744. } __packed;
  745. /**
  746. * struct dwc3_event_devt - Device Events
  747. * @one_bit: indicates this is a non-endpoint event (not used)
  748. * @device_event: indicates it's a device event. Should read as 0x00
  749. * @type: indicates the type of device event.
  750. * 0 - DisconnEvt
  751. * 1 - USBRst
  752. * 2 - ConnectDone
  753. * 3 - ULStChng
  754. * 4 - WkUpEvt
  755. * 5 - Reserved
  756. * 6 - EOPF
  757. * 7 - SOF
  758. * 8 - Reserved
  759. * 9 - ErrticErr
  760. * 10 - CmdCmplt
  761. * 11 - EvntOverflow
  762. * 12 - VndrDevTstRcved
  763. * @reserved15_12: Reserved, not used
  764. * @event_info: Information about this event
  765. * @reserved31_25: Reserved, not used
  766. */
  767. struct dwc3_event_devt {
  768. u32 one_bit:1;
  769. u32 device_event:7;
  770. u32 type:4;
  771. u32 reserved15_12:4;
  772. u32 event_info:9;
  773. u32 reserved31_25:7;
  774. } __packed;
  775. /**
  776. * struct dwc3_event_gevt - Other Core Events
  777. * @one_bit: indicates this is a non-endpoint event (not used)
  778. * @device_event: indicates it's (0x03) Carkit or (0x04) I2C event.
  779. * @phy_port_number: self-explanatory
  780. * @reserved31_12: Reserved, not used.
  781. */
  782. struct dwc3_event_gevt {
  783. u32 one_bit:1;
  784. u32 device_event:7;
  785. u32 phy_port_number:4;
  786. u32 reserved31_12:20;
  787. } __packed;
  788. /**
  789. * union dwc3_event - representation of Event Buffer contents
  790. * @raw: raw 32-bit event
  791. * @type: the type of the event
  792. * @depevt: Device Endpoint Event
  793. * @devt: Device Event
  794. * @gevt: Global Event
  795. */
  796. union dwc3_event {
  797. u32 raw;
  798. struct dwc3_event_type type;
  799. struct dwc3_event_depevt depevt;
  800. struct dwc3_event_devt devt;
  801. struct dwc3_event_gevt gevt;
  802. };
  803. /*
  804. * DWC3 Features to be used as Driver Data
  805. */
  806. #define DWC3_HAS_PERIPHERAL BIT(0)
  807. #define DWC3_HAS_XHCI BIT(1)
  808. #define DWC3_HAS_OTG BIT(3)
  809. /* prototypes */
  810. void dwc3_set_mode(struct dwc3 *dwc, u32 mode);
  811. int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc);
  812. int dwc3_otg_init(struct dwc3 *dwc);
  813. void dwc3_otg_exit(struct dwc3 *dwc);
  814. int dwc3_host_init(struct dwc3 *dwc);
  815. void dwc3_host_exit(struct dwc3 *dwc);
  816. int dwc3_gadget_init(struct dwc3 *dwc);
  817. void dwc3_gadget_exit(struct dwc3 *dwc);
  818. void dwc3_gadget_restart(struct dwc3 *dwc);
  819. void dwc3_post_host_reset_core_init(struct dwc3 *dwc);
  820. int dwc3_event_buffers_setup(struct dwc3 *dwc);
  821. extern void dwc3_set_notifier(
  822. void (*notify) (struct dwc3 *dwc3, unsigned event));
  823. extern int dwc3_notify_event(struct dwc3 *dwc3, unsigned event);
  824. extern int dwc3_get_device_id(void);
  825. extern void dwc3_put_device_id(int id);
  826. #endif /* __DRIVERS_USB_DWC3_CORE_H */