core.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. /**
  2. * core.h - DesignWare USB3 DRD Core Header
  3. *
  4. * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
  5. * All rights reserved.
  6. *
  7. * Authors: Felipe Balbi <balbi@ti.com>,
  8. * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * 3. The names of the above-listed copyright holders may not be used
  20. * to endorse or promote products derived from this software without
  21. * specific prior written permission.
  22. *
  23. * ALTERNATIVELY, this software may be distributed under the terms of the
  24. * GNU General Public License ("GPL") version 2, as published by the Free
  25. * Software Foundation.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  31. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  32. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  33. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  35. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  36. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  37. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. */
  39. #ifndef __DRIVERS_USB_DWC3_CORE_H
  40. #define __DRIVERS_USB_DWC3_CORE_H
  41. #include <linux/device.h>
  42. #include <linux/spinlock.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. /* Global constants */
  50. #define DWC3_ENDPOINTS_NUM 32
  51. #define DWC3_EVENT_BUFFERS_NUM 2
  52. #define DWC3_EVENT_BUFFERS_SIZE PAGE_SIZE
  53. #define DWC3_EVENT_TYPE_MASK 0xfe
  54. #define DWC3_EVENT_TYPE_DEV 0
  55. #define DWC3_EVENT_TYPE_CARKIT 3
  56. #define DWC3_EVENT_TYPE_I2C 4
  57. #define DWC3_DEVICE_EVENT_DISCONNECT 0
  58. #define DWC3_DEVICE_EVENT_RESET 1
  59. #define DWC3_DEVICE_EVENT_CONNECT_DONE 2
  60. #define DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE 3
  61. #define DWC3_DEVICE_EVENT_WAKEUP 4
  62. #define DWC3_DEVICE_EVENT_EOPF 6
  63. #define DWC3_DEVICE_EVENT_SOF 7
  64. #define DWC3_DEVICE_EVENT_ERRATIC_ERROR 9
  65. #define DWC3_DEVICE_EVENT_CMD_CMPL 10
  66. #define DWC3_DEVICE_EVENT_OVERFLOW 11
  67. #define DWC3_GEVNTCOUNT_MASK 0xfffc
  68. #define DWC3_GSNPSID_MASK 0xffff0000
  69. #define DWC3_GSNPSREV_MASK 0xffff
  70. /* Global Registers */
  71. #define DWC3_GSBUSCFG0 0xc100
  72. #define DWC3_GSBUSCFG1 0xc104
  73. #define DWC3_GTXTHRCFG 0xc108
  74. #define DWC3_GRXTHRCFG 0xc10c
  75. #define DWC3_GCTL 0xc110
  76. #define DWC3_GEVTEN 0xc114
  77. #define DWC3_GSTS 0xc118
  78. #define DWC3_GSNPSID 0xc120
  79. #define DWC3_GGPIO 0xc124
  80. #define DWC3_GUID 0xc128
  81. #define DWC3_GUCTL 0xc12c
  82. #define DWC3_GBUSERRADDR0 0xc130
  83. #define DWC3_GBUSERRADDR1 0xc134
  84. #define DWC3_GPRTBIMAP0 0xc138
  85. #define DWC3_GPRTBIMAP1 0xc13c
  86. #define DWC3_GHWPARAMS0 0xc140
  87. #define DWC3_GHWPARAMS1 0xc144
  88. #define DWC3_GHWPARAMS2 0xc148
  89. #define DWC3_GHWPARAMS3 0xc14c
  90. #define DWC3_GHWPARAMS4 0xc150
  91. #define DWC3_GHWPARAMS5 0xc154
  92. #define DWC3_GHWPARAMS6 0xc158
  93. #define DWC3_GHWPARAMS7 0xc15c
  94. #define DWC3_GDBGFIFOSPACE 0xc160
  95. #define DWC3_GDBGLTSSM 0xc164
  96. #define DWC3_GPRTBIMAP_HS0 0xc180
  97. #define DWC3_GPRTBIMAP_HS1 0xc184
  98. #define DWC3_GPRTBIMAP_FS0 0xc188
  99. #define DWC3_GPRTBIMAP_FS1 0xc18c
  100. #define DWC3_GUSB2PHYCFG(n) (0xc200 + (n * 0x04))
  101. #define DWC3_GUSB2I2CCTL(n) (0xc240 + (n * 0x04))
  102. #define DWC3_GUSB2PHYACC(n) (0xc280 + (n * 0x04))
  103. #define DWC3_GUSB3PIPECTL(n) (0xc2c0 + (n * 0x04))
  104. #define DWC3_GTXFIFOSIZ(n) (0xc300 + (n * 0x04))
  105. #define DWC3_GRXFIFOSIZ(n) (0xc380 + (n * 0x04))
  106. #define DWC3_GEVNTADRLO(n) (0xc400 + (n * 0x10))
  107. #define DWC3_GEVNTADRHI(n) (0xc404 + (n * 0x10))
  108. #define DWC3_GEVNTSIZ(n) (0xc408 + (n * 0x10))
  109. #define DWC3_GEVNTCOUNT(n) (0xc40c + (n * 0x10))
  110. #define DWC3_GHWPARAMS8 0xc600
  111. /* Device Registers */
  112. #define DWC3_DCFG 0xc700
  113. #define DWC3_DCTL 0xc704
  114. #define DWC3_DEVTEN 0xc708
  115. #define DWC3_DSTS 0xc70c
  116. #define DWC3_DGCMDPAR 0xc710
  117. #define DWC3_DGCMD 0xc714
  118. #define DWC3_DALEPENA 0xc720
  119. #define DWC3_DEPCMDPAR2(n) (0xc800 + (n * 0x10))
  120. #define DWC3_DEPCMDPAR1(n) (0xc804 + (n * 0x10))
  121. #define DWC3_DEPCMDPAR0(n) (0xc808 + (n * 0x10))
  122. #define DWC3_DEPCMD(n) (0xc80c + (n * 0x10))
  123. /* OTG Registers */
  124. #define DWC3_OCFG 0xcc00
  125. #define DWC3_OCTL 0xcc04
  126. #define DWC3_OEVTEN 0xcc08
  127. #define DWC3_OSTS 0xcc0C
  128. /* Bit fields */
  129. /* Global Configuration Register */
  130. #define DWC3_GCTL_PWRDNSCALE(n) (n << 19)
  131. #define DWC3_GCTL_U2RSTECN (1 << 16)
  132. #define DWC3_GCTL_RAMCLKSEL(x) ((x & DWC3_GCTL_CLK_MASK) << 6)
  133. #define DWC3_GCTL_CLK_BUS (0)
  134. #define DWC3_GCTL_CLK_PIPE (1)
  135. #define DWC3_GCTL_CLK_PIPEHALF (2)
  136. #define DWC3_GCTL_CLK_MASK (3)
  137. #define DWC3_GCTL_PRTCAPDIR(n) (n << 12)
  138. #define DWC3_GCTL_PRTCAP_HOST 1
  139. #define DWC3_GCTL_PRTCAP_DEVICE 2
  140. #define DWC3_GCTL_PRTCAP_OTG 3
  141. #define DWC3_GCTL_CORESOFTRESET (1 << 11)
  142. #define DWC3_GCTL_SCALEDOWN(n) (n << 4)
  143. #define DWC3_GCTL_DISSCRAMBLE (1 << 3)
  144. /* Global USB2 PHY Configuration Register */
  145. #define DWC3_GUSB2PHYCFG_PHYSOFTRST (1 << 31)
  146. #define DWC3_GUSB2PHYCFG_SUSPHY (1 << 6)
  147. /* Global USB3 PIPE Control Register */
  148. #define DWC3_GUSB3PIPECTL_PHYSOFTRST (1 << 31)
  149. #define DWC3_GUSB3PIPECTL_SUSPHY (1 << 17)
  150. /* Device Configuration Register */
  151. #define DWC3_DCFG_DEVADDR(addr) ((addr) << 3)
  152. #define DWC3_DCFG_DEVADDR_MASK DWC3_DCFG_DEVADDR(0x7f)
  153. #define DWC3_DCFG_SPEED_MASK (7 << 0)
  154. #define DWC3_DCFG_SUPERSPEED (4 << 0)
  155. #define DWC3_DCFG_HIGHSPEED (0 << 0)
  156. #define DWC3_DCFG_FULLSPEED2 (1 << 0)
  157. #define DWC3_DCFG_LOWSPEED (2 << 0)
  158. #define DWC3_DCFG_FULLSPEED1 (3 << 0)
  159. /* Device Control Register */
  160. #define DWC3_DCTL_RUN_STOP (1 << 31)
  161. #define DWC3_DCTL_CSFTRST (1 << 30)
  162. #define DWC3_DCTL_LSFTRST (1 << 29)
  163. #define DWC3_DCTL_HIRD_THRES_MASK (0x1f << 24)
  164. #define DWC3_DCTL_HIRD_THRES(n) (((n) & DWC3_DCTL_HIRD_THRES_MASK) >> 24)
  165. #define DWC3_DCTL_APPL1RES (1 << 23)
  166. #define DWC3_DCTL_INITU2ENA (1 << 12)
  167. #define DWC3_DCTL_ACCEPTU2ENA (1 << 11)
  168. #define DWC3_DCTL_INITU1ENA (1 << 10)
  169. #define DWC3_DCTL_ACCEPTU1ENA (1 << 9)
  170. #define DWC3_DCTL_TSTCTRL_MASK (0xf << 1)
  171. #define DWC3_DCTL_ULSTCHNGREQ_MASK (0x0f << 5)
  172. #define DWC3_DCTL_ULSTCHNGREQ(n) (((n) << 5) & DWC3_DCTL_ULSTCHNGREQ_MASK)
  173. #define DWC3_DCTL_ULSTCHNG_NO_ACTION (DWC3_DCTL_ULSTCHNGREQ(0))
  174. #define DWC3_DCTL_ULSTCHNG_SS_DISABLED (DWC3_DCTL_ULSTCHNGREQ(4))
  175. #define DWC3_DCTL_ULSTCHNG_RX_DETECT (DWC3_DCTL_ULSTCHNGREQ(5))
  176. #define DWC3_DCTL_ULSTCHNG_SS_INACTIVE (DWC3_DCTL_ULSTCHNGREQ(6))
  177. #define DWC3_DCTL_ULSTCHNG_RECOVERY (DWC3_DCTL_ULSTCHNGREQ(8))
  178. #define DWC3_DCTL_ULSTCHNG_COMPLIANCE (DWC3_DCTL_ULSTCHNGREQ(10))
  179. #define DWC3_DCTL_ULSTCHNG_LOOPBACK (DWC3_DCTL_ULSTCHNGREQ(11))
  180. /* Device Event Enable Register */
  181. #define DWC3_DEVTEN_VNDRDEVTSTRCVEDEN (1 << 12)
  182. #define DWC3_DEVTEN_EVNTOVERFLOWEN (1 << 11)
  183. #define DWC3_DEVTEN_CMDCMPLTEN (1 << 10)
  184. #define DWC3_DEVTEN_ERRTICERREN (1 << 9)
  185. #define DWC3_DEVTEN_SOFEN (1 << 7)
  186. #define DWC3_DEVTEN_EOPFEN (1 << 6)
  187. #define DWC3_DEVTEN_WKUPEVTEN (1 << 4)
  188. #define DWC3_DEVTEN_ULSTCNGEN (1 << 3)
  189. #define DWC3_DEVTEN_CONNECTDONEEN (1 << 2)
  190. #define DWC3_DEVTEN_USBRSTEN (1 << 1)
  191. #define DWC3_DEVTEN_DISCONNEVTEN (1 << 0)
  192. /* Device Status Register */
  193. #define DWC3_DSTS_PWRUPREQ (1 << 24)
  194. #define DWC3_DSTS_COREIDLE (1 << 23)
  195. #define DWC3_DSTS_DEVCTRLHLT (1 << 22)
  196. #define DWC3_DSTS_USBLNKST_MASK (0x0f << 18)
  197. #define DWC3_DSTS_USBLNKST(n) (((n) & DWC3_DSTS_USBLNKST_MASK) >> 18)
  198. #define DWC3_DSTS_RXFIFOEMPTY (1 << 17)
  199. #define DWC3_DSTS_SOFFN_MASK (0x3ff << 3)
  200. #define DWC3_DSTS_SOFFN(n) (((n) & DWC3_DSTS_SOFFN_MASK) >> 3)
  201. #define DWC3_DSTS_CONNECTSPD (7 << 0)
  202. #define DWC3_DSTS_SUPERSPEED (4 << 0)
  203. #define DWC3_DSTS_HIGHSPEED (0 << 0)
  204. #define DWC3_DSTS_FULLSPEED2 (1 << 0)
  205. #define DWC3_DSTS_LOWSPEED (2 << 0)
  206. #define DWC3_DSTS_FULLSPEED1 (3 << 0)
  207. /* Device Generic Command Register */
  208. #define DWC3_DGCMD_SET_LMP 0x01
  209. #define DWC3_DGCMD_SET_PERIODIC_PAR 0x02
  210. #define DWC3_DGCMD_XMIT_FUNCTION 0x03
  211. #define DWC3_DGCMD_SELECTED_FIFO_FLUSH 0x09
  212. #define DWC3_DGCMD_ALL_FIFO_FLUSH 0x0a
  213. #define DWC3_DGCMD_SET_ENDPOINT_NRDY 0x0c
  214. #define DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK 0x10
  215. /* Device Endpoint Command Register */
  216. #define DWC3_DEPCMD_PARAM_SHIFT 16
  217. #define DWC3_DEPCMD_PARAM(x) (x << DWC3_DEPCMD_PARAM_SHIFT)
  218. #define DWC3_DEPCMD_GET_RSC_IDX(x) ((x >> DWC3_DEPCMD_PARAM_SHIFT) & 0x7f)
  219. #define DWC3_DEPCMD_STATUS_MASK (0x0f << 12)
  220. #define DWC3_DEPCMD_STATUS(x) ((x & DWC3_DEPCMD_STATUS_MASK) >> 12)
  221. #define DWC3_DEPCMD_HIPRI_FORCERM (1 << 11)
  222. #define DWC3_DEPCMD_CMDACT (1 << 10)
  223. #define DWC3_DEPCMD_CMDIOC (1 << 8)
  224. #define DWC3_DEPCMD_DEPSTARTCFG (0x09 << 0)
  225. #define DWC3_DEPCMD_ENDTRANSFER (0x08 << 0)
  226. #define DWC3_DEPCMD_UPDATETRANSFER (0x07 << 0)
  227. #define DWC3_DEPCMD_STARTTRANSFER (0x06 << 0)
  228. #define DWC3_DEPCMD_CLEARSTALL (0x05 << 0)
  229. #define DWC3_DEPCMD_SETSTALL (0x04 << 0)
  230. #define DWC3_DEPCMD_GETSEQNUMBER (0x03 << 0)
  231. #define DWC3_DEPCMD_SETTRANSFRESOURCE (0x02 << 0)
  232. #define DWC3_DEPCMD_SETEPCONFIG (0x01 << 0)
  233. /* The EP number goes 0..31 so ep0 is always out and ep1 is always in */
  234. #define DWC3_DALEPENA_EP(n) (1 << n)
  235. #define DWC3_DEPCMD_TYPE_CONTROL 0
  236. #define DWC3_DEPCMD_TYPE_ISOC 1
  237. #define DWC3_DEPCMD_TYPE_BULK 2
  238. #define DWC3_DEPCMD_TYPE_INTR 3
  239. /* Structures */
  240. struct dwc3_trb_hw;
  241. /**
  242. * struct dwc3_event_buffer - Software event buffer representation
  243. * @list: a list of event buffers
  244. * @buf: _THE_ buffer
  245. * @length: size of this buffer
  246. * @dma: dma_addr_t
  247. * @dwc: pointer to DWC controller
  248. */
  249. struct dwc3_event_buffer {
  250. void *buf;
  251. unsigned length;
  252. unsigned int lpos;
  253. dma_addr_t dma;
  254. struct dwc3 *dwc;
  255. };
  256. #define DWC3_EP_FLAG_STALLED (1 << 0)
  257. #define DWC3_EP_FLAG_WEDGED (1 << 1)
  258. #define DWC3_EP_DIRECTION_TX true
  259. #define DWC3_EP_DIRECTION_RX false
  260. #define DWC3_TRB_NUM 32
  261. #define DWC3_TRB_MASK (DWC3_TRB_NUM - 1)
  262. /**
  263. * struct dwc3_ep - device side endpoint representation
  264. * @endpoint: usb endpoint
  265. * @request_list: list of requests for this endpoint
  266. * @req_queued: list of requests on this ep which have TRBs setup
  267. * @trb_pool: array of transaction buffers
  268. * @trb_pool_dma: dma address of @trb_pool
  269. * @free_slot: next slot which is going to be used
  270. * @busy_slot: first slot which is owned by HW
  271. * @desc: usb_endpoint_descriptor pointer
  272. * @dwc: pointer to DWC controller
  273. * @flags: endpoint flags (wedged, stalled, ...)
  274. * @current_trb: index of current used trb
  275. * @number: endpoint number (1 - 15)
  276. * @type: set to bmAttributes & USB_ENDPOINT_XFERTYPE_MASK
  277. * @res_trans_idx: Resource transfer index
  278. * @interval: the intervall on which the ISOC transfer is started
  279. * @name: a human readable name e.g. ep1out-bulk
  280. * @direction: true for TX, false for RX
  281. */
  282. struct dwc3_ep {
  283. struct usb_ep endpoint;
  284. struct list_head request_list;
  285. struct list_head req_queued;
  286. struct dwc3_trb_hw *trb_pool;
  287. dma_addr_t trb_pool_dma;
  288. u32 free_slot;
  289. u32 busy_slot;
  290. const struct usb_endpoint_descriptor *desc;
  291. struct dwc3 *dwc;
  292. unsigned flags;
  293. #define DWC3_EP_ENABLED (1 << 0)
  294. #define DWC3_EP_STALL (1 << 1)
  295. #define DWC3_EP_WEDGE (1 << 2)
  296. #define DWC3_EP_BUSY (1 << 4)
  297. #define DWC3_EP_PENDING_REQUEST (1 << 5)
  298. /* This last one is specific to EP0 */
  299. #define DWC3_EP0_DIR_IN (1 << 31)
  300. unsigned current_trb;
  301. u8 number;
  302. u8 type;
  303. u8 res_trans_idx;
  304. u32 interval;
  305. char name[20];
  306. unsigned direction:1;
  307. };
  308. enum dwc3_phy {
  309. DWC3_PHY_UNKNOWN = 0,
  310. DWC3_PHY_USB3,
  311. DWC3_PHY_USB2,
  312. };
  313. enum dwc3_ep0_next {
  314. DWC3_EP0_UNKNOWN = 0,
  315. DWC3_EP0_COMPLETE,
  316. DWC3_EP0_NRDY_SETUP,
  317. DWC3_EP0_NRDY_DATA,
  318. DWC3_EP0_NRDY_STATUS,
  319. };
  320. enum dwc3_ep0_state {
  321. EP0_UNCONNECTED = 0,
  322. EP0_SETUP_PHASE,
  323. EP0_DATA_PHASE,
  324. EP0_STATUS_PHASE,
  325. };
  326. enum dwc3_link_state {
  327. /* In SuperSpeed */
  328. DWC3_LINK_STATE_U0 = 0x00, /* in HS, means ON */
  329. DWC3_LINK_STATE_U1 = 0x01,
  330. DWC3_LINK_STATE_U2 = 0x02, /* in HS, means SLEEP */
  331. DWC3_LINK_STATE_U3 = 0x03, /* in HS, means SUSPEND */
  332. DWC3_LINK_STATE_SS_DIS = 0x04,
  333. DWC3_LINK_STATE_RX_DET = 0x05, /* in HS, means Early Suspend */
  334. DWC3_LINK_STATE_SS_INACT = 0x06,
  335. DWC3_LINK_STATE_POLL = 0x07,
  336. DWC3_LINK_STATE_RECOV = 0x08,
  337. DWC3_LINK_STATE_HRESET = 0x09,
  338. DWC3_LINK_STATE_CMPLY = 0x0a,
  339. DWC3_LINK_STATE_LPBK = 0x0b,
  340. DWC3_LINK_STATE_MASK = 0x0f,
  341. };
  342. enum dwc3_device_state {
  343. DWC3_DEFAULT_STATE,
  344. DWC3_ADDRESS_STATE,
  345. DWC3_CONFIGURED_STATE,
  346. };
  347. /**
  348. * struct dwc3_trb - transfer request block
  349. * @bpl: lower 32bit of the buffer
  350. * @bph: higher 32bit of the buffer
  351. * @length: buffer size (up to 16mb - 1)
  352. * @pcm1: packet count m1
  353. * @trbsts: trb status
  354. * 0 = ok
  355. * 1 = missed isoc
  356. * 2 = setup pending
  357. * @hwo: hardware owner of descriptor
  358. * @lst: last trb
  359. * @chn: chain buffers
  360. * @csp: continue on short packets (only supported on isoc eps)
  361. * @trbctl: trb control
  362. * 1 = normal
  363. * 2 = control-setup
  364. * 3 = control-status-2
  365. * 4 = control-status-3
  366. * 5 = control-data (first trb of data stage)
  367. * 6 = isochronous-first (first trb of service interval)
  368. * 7 = isochronous
  369. * 8 = link trb
  370. * others = reserved
  371. * @isp_imi: interrupt on short packet / interrupt on missed isoc
  372. * @ioc: interrupt on complete
  373. * @sid_sofn: Stream ID / SOF Number
  374. */
  375. struct dwc3_trb {
  376. u64 bplh;
  377. union {
  378. struct {
  379. u32 length:24;
  380. u32 pcm1:2;
  381. u32 reserved27_26:2;
  382. u32 trbsts:4;
  383. #define DWC3_TRB_STS_OKAY 0
  384. #define DWC3_TRB_STS_MISSED_ISOC 1
  385. #define DWC3_TRB_STS_SETUP_PENDING 2
  386. };
  387. u32 len_pcm;
  388. };
  389. union {
  390. struct {
  391. u32 hwo:1;
  392. u32 lst:1;
  393. u32 chn:1;
  394. u32 csp:1;
  395. u32 trbctl:6;
  396. u32 isp_imi:1;
  397. u32 ioc:1;
  398. u32 reserved13_12:2;
  399. u32 sid_sofn:16;
  400. u32 reserved31_30:2;
  401. };
  402. u32 control;
  403. };
  404. } __packed;
  405. /**
  406. * struct dwc3_trb_hw - transfer request block (hw format)
  407. * @bpl: DW0-3
  408. * @bph: DW4-7
  409. * @size: DW8-B
  410. * @trl: DWC-F
  411. */
  412. struct dwc3_trb_hw {
  413. __le32 bpl;
  414. __le32 bph;
  415. __le32 size;
  416. __le32 ctrl;
  417. } __packed;
  418. static inline void dwc3_trb_to_hw(struct dwc3_trb *nat, struct dwc3_trb_hw *hw)
  419. {
  420. hw->bpl = cpu_to_le32(lower_32_bits(nat->bplh));
  421. hw->bph = cpu_to_le32(upper_32_bits(nat->bplh));
  422. hw->size = cpu_to_le32p(&nat->len_pcm);
  423. /* HWO is written last */
  424. hw->ctrl = cpu_to_le32p(&nat->control);
  425. }
  426. static inline void dwc3_trb_to_nat(struct dwc3_trb_hw *hw, struct dwc3_trb *nat)
  427. {
  428. u64 bplh;
  429. bplh = le32_to_cpup(&hw->bpl);
  430. bplh |= (u64) le32_to_cpup(&hw->bph) << 32;
  431. nat->bplh = bplh;
  432. nat->len_pcm = le32_to_cpup(&hw->size);
  433. nat->control = le32_to_cpup(&hw->ctrl);
  434. }
  435. /**
  436. * struct dwc3 - representation of our controller
  437. * @ctrl_req: usb control request which is used for ep0
  438. * @ep0_trb: trb which is used for the ctrl_req
  439. * @ep0_bounce: bounce buffer for ep0
  440. * @setup_buf: used while precessing STD USB requests
  441. * @ctrl_req_addr: dma address of ctrl_req
  442. * @ep0_trb: dma address of ep0_trb
  443. * @ep0_usb_req: dummy req used while handling STD USB requests
  444. * @setup_buf_addr: dma address of setup_buf
  445. * @ep0_bounce_addr: dma address of ep0_bounce
  446. * @lock: for synchronizing
  447. * @dev: pointer to our struct device
  448. * @event_buffer_list: a list of event buffers
  449. * @gadget: device side representation of the peripheral controller
  450. * @gadget_driver: pointer to the gadget driver
  451. * @regs: base address for our registers
  452. * @regs_size: address space size
  453. * @irq: IRQ number
  454. * @revision: revision register contents
  455. * @is_selfpowered: true when we are selfpowered
  456. * @three_stage_setup: set if we perform a three phase setup
  457. * @ep0_status_pending: ep0 status response without a req is pending
  458. * @ep0_bounced: true when we used bounce buffer
  459. * @ep0_expect_in: true when we expect a DATA IN transfer
  460. * @ep0_next_event: hold the next expected event
  461. * @ep0state: state of endpoint zero
  462. * @link_state: link state
  463. * @speed: device speed (super, high, full, low)
  464. * @mem: points to start of memory which is used for this struct.
  465. * @root: debugfs root folder pointer
  466. */
  467. struct dwc3 {
  468. struct usb_ctrlrequest *ctrl_req;
  469. struct dwc3_trb_hw *ep0_trb;
  470. void *ep0_bounce;
  471. u8 *setup_buf;
  472. dma_addr_t ctrl_req_addr;
  473. dma_addr_t ep0_trb_addr;
  474. dma_addr_t setup_buf_addr;
  475. dma_addr_t ep0_bounce_addr;
  476. struct usb_request ep0_usb_req;
  477. /* device lock */
  478. spinlock_t lock;
  479. struct device *dev;
  480. struct dwc3_event_buffer *ev_buffs[DWC3_EVENT_BUFFERS_NUM];
  481. struct dwc3_ep *eps[DWC3_ENDPOINTS_NUM];
  482. struct usb_gadget gadget;
  483. struct usb_gadget_driver *gadget_driver;
  484. void __iomem *regs;
  485. size_t regs_size;
  486. int irq;
  487. u32 revision;
  488. #define DWC3_REVISION_173A 0x5533173a
  489. #define DWC3_REVISION_175A 0x5533175a
  490. #define DWC3_REVISION_180A 0x5533180a
  491. #define DWC3_REVISION_183A 0x5533183a
  492. #define DWC3_REVISION_185A 0x5533185a
  493. #define DWC3_REVISION_188A 0x5533188a
  494. #define DWC3_REVISION_190A 0x5533190a
  495. unsigned is_selfpowered:1;
  496. unsigned three_stage_setup:1;
  497. unsigned ep0_status_pending:1;
  498. unsigned ep0_bounced:1;
  499. unsigned ep0_expect_in:1;
  500. enum dwc3_ep0_next ep0_next_event;
  501. enum dwc3_ep0_state ep0state;
  502. enum dwc3_link_state link_state;
  503. enum dwc3_device_state dev_state;
  504. u8 speed;
  505. void *mem;
  506. struct dentry *root;
  507. };
  508. /* -------------------------------------------------------------------------- */
  509. #define DWC3_TRBSTS_OK 0
  510. #define DWC3_TRBSTS_MISSED_ISOC 1
  511. #define DWC3_TRBSTS_SETUP_PENDING 2
  512. #define DWC3_TRBCTL_NORMAL 1
  513. #define DWC3_TRBCTL_CONTROL_SETUP 2
  514. #define DWC3_TRBCTL_CONTROL_STATUS2 3
  515. #define DWC3_TRBCTL_CONTROL_STATUS3 4
  516. #define DWC3_TRBCTL_CONTROL_DATA 5
  517. #define DWC3_TRBCTL_ISOCHRONOUS_FIRST 6
  518. #define DWC3_TRBCTL_ISOCHRONOUS 7
  519. #define DWC3_TRBCTL_LINK_TRB 8
  520. /* -------------------------------------------------------------------------- */
  521. struct dwc3_event_type {
  522. u32 is_devspec:1;
  523. u32 type:6;
  524. u32 reserved8_31:25;
  525. } __packed;
  526. #define DWC3_DEPEVT_XFERCOMPLETE 0x01
  527. #define DWC3_DEPEVT_XFERINPROGRESS 0x02
  528. #define DWC3_DEPEVT_XFERNOTREADY 0x03
  529. #define DWC3_DEPEVT_RXTXFIFOEVT 0x04
  530. #define DWC3_DEPEVT_STREAMEVT 0x06
  531. #define DWC3_DEPEVT_EPCMDCMPLT 0x07
  532. /**
  533. * struct dwc3_event_depvt - Device Endpoint Events
  534. * @one_bit: indicates this is an endpoint event (not used)
  535. * @endpoint_number: number of the endpoint
  536. * @endpoint_event: The event we have:
  537. * 0x00 - Reserved
  538. * 0x01 - XferComplete
  539. * 0x02 - XferInProgress
  540. * 0x03 - XferNotReady
  541. * 0x04 - RxTxFifoEvt (IN->Underrun, OUT->Overrun)
  542. * 0x05 - Reserved
  543. * 0x06 - StreamEvt
  544. * 0x07 - EPCmdCmplt
  545. * @reserved11_10: Reserved, don't use.
  546. * @status: Indicates the status of the event. Refer to databook for
  547. * more information.
  548. * @parameters: Parameters of the current event. Refer to databook for
  549. * more information.
  550. */
  551. struct dwc3_event_depevt {
  552. u32 one_bit:1;
  553. u32 endpoint_number:5;
  554. u32 endpoint_event:4;
  555. u32 reserved11_10:2;
  556. u32 status:4;
  557. #define DEPEVT_STATUS_BUSERR (1 << 0)
  558. #define DEPEVT_STATUS_SHORT (1 << 1)
  559. #define DEPEVT_STATUS_IOC (1 << 2)
  560. #define DEPEVT_STATUS_LST (1 << 3)
  561. /* Control-only Status */
  562. #define DEPEVT_STATUS_CONTROL_SETUP 0
  563. #define DEPEVT_STATUS_CONTROL_DATA 1
  564. #define DEPEVT_STATUS_CONTROL_STATUS 2
  565. u32 parameters:16;
  566. } __packed;
  567. /**
  568. * struct dwc3_event_devt - Device Events
  569. * @one_bit: indicates this is a non-endpoint event (not used)
  570. * @device_event: indicates it's a device event. Should read as 0x00
  571. * @type: indicates the type of device event.
  572. * 0 - DisconnEvt
  573. * 1 - USBRst
  574. * 2 - ConnectDone
  575. * 3 - ULStChng
  576. * 4 - WkUpEvt
  577. * 5 - Reserved
  578. * 6 - EOPF
  579. * 7 - SOF
  580. * 8 - Reserved
  581. * 9 - ErrticErr
  582. * 10 - CmdCmplt
  583. * 11 - EvntOverflow
  584. * 12 - VndrDevTstRcved
  585. * @reserved15_12: Reserved, not used
  586. * @event_info: Information about this event
  587. * @reserved31_24: Reserved, not used
  588. */
  589. struct dwc3_event_devt {
  590. u32 one_bit:1;
  591. u32 device_event:7;
  592. u32 type:4;
  593. u32 reserved15_12:4;
  594. u32 event_info:8;
  595. u32 reserved31_24:8;
  596. } __packed;
  597. /**
  598. * struct dwc3_event_gevt - Other Core Events
  599. * @one_bit: indicates this is a non-endpoint event (not used)
  600. * @device_event: indicates it's (0x03) Carkit or (0x04) I2C event.
  601. * @phy_port_number: self-explanatory
  602. * @reserved31_12: Reserved, not used.
  603. */
  604. struct dwc3_event_gevt {
  605. u32 one_bit:1;
  606. u32 device_event:7;
  607. u32 phy_port_number:4;
  608. u32 reserved31_12:20;
  609. } __packed;
  610. /**
  611. * union dwc3_event - representation of Event Buffer contents
  612. * @raw: raw 32-bit event
  613. * @type: the type of the event
  614. * @depevt: Device Endpoint Event
  615. * @devt: Device Event
  616. * @gevt: Global Event
  617. */
  618. union dwc3_event {
  619. u32 raw;
  620. struct dwc3_event_type type;
  621. struct dwc3_event_depevt depevt;
  622. struct dwc3_event_devt devt;
  623. struct dwc3_event_gevt gevt;
  624. };
  625. /*
  626. * DWC3 Features to be used as Driver Data
  627. */
  628. #define DWC3_HAS_PERIPHERAL BIT(0)
  629. #define DWC3_HAS_XHCI BIT(1)
  630. #define DWC3_HAS_OTG BIT(3)
  631. #endif /* __DRIVERS_USB_DWC3_CORE_H */