mv_u3d.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /*
  2. * Copyright (C) 2011 Marvell International Ltd. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. */
  8. #ifndef __MV_U3D_H
  9. #define __MV_U3D_H
  10. #define MV_U3D_EP_CONTEXT_ALIGNMENT 32
  11. #define MV_U3D_TRB_ALIGNMENT 16
  12. #define MV_U3D_DMA_BOUNDARY 4096
  13. #define MV_U3D_EP0_MAX_PKT_SIZE 512
  14. /* ep0 transfer state */
  15. #define MV_U3D_WAIT_FOR_SETUP 0
  16. #define MV_U3D_DATA_STATE_XMIT 1
  17. #define MV_U3D_DATA_STATE_NEED_ZLP 2
  18. #define MV_U3D_WAIT_FOR_OUT_STATUS 3
  19. #define MV_U3D_DATA_STATE_RECV 4
  20. #define MV_U3D_STATUS_STAGE 5
  21. #define MV_U3D_EP_MAX_LENGTH_TRANSFER 0x10000
  22. /* USB3 Interrupt Status */
  23. #define MV_U3D_USBINT_SETUP 0x00000001
  24. #define MV_U3D_USBINT_RX_COMPLETE 0x00000002
  25. #define MV_U3D_USBINT_TX_COMPLETE 0x00000004
  26. #define MV_U3D_USBINT_UNDER_RUN 0x00000008
  27. #define MV_U3D_USBINT_RXDESC_ERR 0x00000010
  28. #define MV_U3D_USBINT_TXDESC_ERR 0x00000020
  29. #define MV_U3D_USBINT_RX_TRB_COMPLETE 0x00000040
  30. #define MV_U3D_USBINT_TX_TRB_COMPLETE 0x00000080
  31. #define MV_U3D_USBINT_VBUS_VALID 0x00010000
  32. #define MV_U3D_USBINT_STORAGE_CMD_FULL 0x00020000
  33. #define MV_U3D_USBINT_LINK_CHG 0x01000000
  34. /* USB3 Interrupt Enable */
  35. #define MV_U3D_INTR_ENABLE_SETUP 0x00000001
  36. #define MV_U3D_INTR_ENABLE_RX_COMPLETE 0x00000002
  37. #define MV_U3D_INTR_ENABLE_TX_COMPLETE 0x00000004
  38. #define MV_U3D_INTR_ENABLE_UNDER_RUN 0x00000008
  39. #define MV_U3D_INTR_ENABLE_RXDESC_ERR 0x00000010
  40. #define MV_U3D_INTR_ENABLE_TXDESC_ERR 0x00000020
  41. #define MV_U3D_INTR_ENABLE_RX_TRB_COMPLETE 0x00000040
  42. #define MV_U3D_INTR_ENABLE_TX_TRB_COMPLETE 0x00000080
  43. #define MV_U3D_INTR_ENABLE_RX_BUFFER_ERR 0x00000100
  44. #define MV_U3D_INTR_ENABLE_VBUS_VALID 0x00010000
  45. #define MV_U3D_INTR_ENABLE_STORAGE_CMD_FULL 0x00020000
  46. #define MV_U3D_INTR_ENABLE_LINK_CHG 0x01000000
  47. #define MV_U3D_INTR_ENABLE_PRIME_STATUS 0x02000000
  48. /* USB3 Link Change */
  49. #define MV_U3D_LINK_CHANGE_LINK_UP 0x00000001
  50. #define MV_U3D_LINK_CHANGE_SUSPEND 0x00000002
  51. #define MV_U3D_LINK_CHANGE_RESUME 0x00000004
  52. #define MV_U3D_LINK_CHANGE_WRESET 0x00000008
  53. #define MV_U3D_LINK_CHANGE_HRESET 0x00000010
  54. #define MV_U3D_LINK_CHANGE_VBUS_INVALID 0x00000020
  55. #define MV_U3D_LINK_CHANGE_INACT 0x00000040
  56. #define MV_U3D_LINK_CHANGE_DISABLE_AFTER_U0 0x00000080
  57. #define MV_U3D_LINK_CHANGE_U1 0x00000100
  58. #define MV_U3D_LINK_CHANGE_U2 0x00000200
  59. #define MV_U3D_LINK_CHANGE_U3 0x00000400
  60. /* bridge setting */
  61. #define MV_U3D_BRIDGE_SETTING_VBUS_VALID (1 << 16)
  62. /* Command Register Bit Masks */
  63. #define MV_U3D_CMD_RUN_STOP 0x00000001
  64. #define MV_U3D_CMD_CTRL_RESET 0x00000002
  65. /* ep control register */
  66. #define MV_U3D_EPXCR_EP_TYPE_CONTROL 0
  67. #define MV_U3D_EPXCR_EP_TYPE_ISOC 1
  68. #define MV_U3D_EPXCR_EP_TYPE_BULK 2
  69. #define MV_U3D_EPXCR_EP_TYPE_INT 3
  70. #define MV_U3D_EPXCR_EP_ENABLE_SHIFT 4
  71. #define MV_U3D_EPXCR_MAX_BURST_SIZE_SHIFT 12
  72. #define MV_U3D_EPXCR_MAX_PACKET_SIZE_SHIFT 16
  73. #define MV_U3D_USB_BULK_BURST_OUT 6
  74. #define MV_U3D_USB_BULK_BURST_IN 14
  75. #define MV_U3D_EPXCR_EP_FLUSH (1 << 7)
  76. #define MV_U3D_EPXCR_EP_HALT (1 << 1)
  77. #define MV_U3D_EPXCR_EP_INIT (1)
  78. /* TX/RX Status Register */
  79. #define MV_U3D_XFERSTATUS_COMPLETE_SHIFT 24
  80. #define MV_U3D_COMPLETE_INVALID 0
  81. #define MV_U3D_COMPLETE_SUCCESS 1
  82. #define MV_U3D_COMPLETE_BUFF_ERR 2
  83. #define MV_U3D_COMPLETE_SHORT_PACKET 3
  84. #define MV_U3D_COMPLETE_TRB_ERR 5
  85. #define MV_U3D_XFERSTATUS_TRB_LENGTH_MASK (0xFFFFFF)
  86. #define MV_U3D_USB_LINK_BYPASS_VBUS 0x8
  87. #define MV_U3D_LTSSM_PHY_INIT_DONE 0x80000000
  88. #define MV_U3D_LTSSM_NEVER_GO_COMPLIANCE 0x40000000
  89. #define MV_U3D_USB3_OP_REGS_OFFSET 0x100
  90. #define MV_U3D_USB3_PHY_OFFSET 0xB800
  91. #define DCS_ENABLE 0x1
  92. /* timeout */
  93. #define MV_U3D_RESET_TIMEOUT 10000
  94. #define MV_U3D_FLUSH_TIMEOUT 100000
  95. #define MV_U3D_OWN_TIMEOUT 10000
  96. #define LOOPS_USEC_SHIFT 4
  97. #define LOOPS_USEC (1 << LOOPS_USEC_SHIFT)
  98. #define LOOPS(timeout) ((timeout) >> LOOPS_USEC_SHIFT)
  99. /* ep direction */
  100. #define MV_U3D_EP_DIR_IN 1
  101. #define MV_U3D_EP_DIR_OUT 0
  102. #define mv_u3d_ep_dir(ep) (((ep)->ep_num == 0) ? \
  103. ((ep)->u3d->ep0_dir) : ((ep)->direction))
  104. /* usb capability registers */
  105. struct mv_u3d_cap_regs {
  106. u32 rsvd[5];
  107. u32 dboff; /* doorbell register offset */
  108. u32 rtsoff; /* runtime register offset */
  109. u32 vuoff; /* vendor unique register offset */
  110. };
  111. /* operation registers */
  112. struct mv_u3d_op_regs {
  113. u32 usbcmd; /* Command register */
  114. u32 rsvd1[11];
  115. u32 dcbaapl; /* Device Context Base Address low register */
  116. u32 dcbaaph; /* Device Context Base Address high register */
  117. u32 rsvd2[243];
  118. u32 portsc; /* port status and control register*/
  119. u32 portlinkinfo; /* port link info register*/
  120. u32 rsvd3[9917];
  121. u32 doorbell; /* doorbell register */
  122. };
  123. /* control enpoint enable registers */
  124. struct epxcr {
  125. u32 epxoutcr0; /* ep out control 0 register */
  126. u32 epxoutcr1; /* ep out control 1 register */
  127. u32 epxincr0; /* ep in control 0 register */
  128. u32 epxincr1; /* ep in control 1 register */
  129. };
  130. /* transfer status registers */
  131. struct xferstatus {
  132. u32 curdeqlo; /* current TRB pointer low */
  133. u32 curdeqhi; /* current TRB pointer high */
  134. u32 statuslo; /* transfer status low */
  135. u32 statushi; /* transfer status high */
  136. };
  137. /* vendor unique control registers */
  138. struct mv_u3d_vuc_regs {
  139. u32 ctrlepenable; /* control endpoint enable register */
  140. u32 setuplock; /* setup lock register */
  141. u32 endcomplete; /* endpoint transfer complete register */
  142. u32 intrcause; /* interrupt cause register */
  143. u32 intrenable; /* interrupt enable register */
  144. u32 trbcomplete; /* TRB complete register */
  145. u32 linkchange; /* link change register */
  146. u32 rsvd1[5];
  147. u32 trbunderrun; /* TRB underrun register */
  148. u32 rsvd2[43];
  149. u32 bridgesetting; /* bridge setting register */
  150. u32 rsvd3[7];
  151. struct xferstatus txst[16]; /* TX status register */
  152. struct xferstatus rxst[16]; /* RX status register */
  153. u32 ltssm; /* LTSSM control register */
  154. u32 pipe; /* PIPE control register */
  155. u32 linkcr0; /* link control 0 register */
  156. u32 linkcr1; /* link control 1 register */
  157. u32 rsvd6[60];
  158. u32 mib0; /* MIB0 counter register */
  159. u32 usblink; /* usb link control register */
  160. u32 ltssmstate; /* LTSSM state register */
  161. u32 linkerrorcause; /* link error cause register */
  162. u32 rsvd7[60];
  163. u32 devaddrtiebrkr; /* device address and tie breaker */
  164. u32 itpinfo0; /* ITP info 0 register */
  165. u32 itpinfo1; /* ITP info 1 register */
  166. u32 rsvd8[61];
  167. struct epxcr epcr[16]; /* ep control register */
  168. u32 rsvd9[64];
  169. u32 phyaddr; /* PHY address register */
  170. u32 phydata; /* PHY data register */
  171. };
  172. /* Endpoint context structure */
  173. struct mv_u3d_ep_context {
  174. u32 rsvd0;
  175. u32 rsvd1;
  176. u32 trb_addr_lo; /* TRB address low 32 bit */
  177. u32 trb_addr_hi; /* TRB address high 32 bit */
  178. u32 rsvd2;
  179. u32 rsvd3;
  180. struct usb_ctrlrequest setup_buffer; /* setup data buffer */
  181. };
  182. /* TRB control data structure */
  183. struct mv_u3d_trb_ctrl {
  184. u32 own:1; /* owner of TRB */
  185. u32 rsvd1:3;
  186. u32 chain:1; /* associate this TRB with the
  187. next TRB on the Ring */
  188. u32 ioc:1; /* interrupt on complete */
  189. u32 rsvd2:4;
  190. u32 type:6; /* TRB type */
  191. #define TYPE_NORMAL 1
  192. #define TYPE_DATA 3
  193. #define TYPE_LINK 6
  194. u32 dir:1; /* Working at data stage of control endpoint
  195. operation. 0 is OUT and 1 is IN. */
  196. u32 rsvd3:15;
  197. };
  198. /* TRB data structure
  199. * For multiple TRB, all the TRBs' physical address should be continuous.
  200. */
  201. struct mv_u3d_trb_hw {
  202. u32 buf_addr_lo; /* data buffer address low 32 bit */
  203. u32 buf_addr_hi; /* data buffer address high 32 bit */
  204. u32 trb_len; /* transfer length */
  205. struct mv_u3d_trb_ctrl ctrl; /* TRB control data */
  206. };
  207. /* TRB structure */
  208. struct mv_u3d_trb {
  209. struct mv_u3d_trb_hw *trb_hw; /* point to the trb_hw structure */
  210. dma_addr_t trb_dma; /* dma address for this trb_hw */
  211. struct list_head trb_list; /* trb list */
  212. };
  213. /* device data structure */
  214. struct mv_u3d {
  215. struct usb_gadget gadget;
  216. struct usb_gadget_driver *driver;
  217. spinlock_t lock; /* device lock */
  218. struct completion *done;
  219. struct device *dev;
  220. int irq;
  221. /* usb controller registers */
  222. struct mv_u3d_cap_regs __iomem *cap_regs;
  223. struct mv_u3d_op_regs __iomem *op_regs;
  224. struct mv_u3d_vuc_regs __iomem *vuc_regs;
  225. void __iomem *phy_regs;
  226. unsigned int max_eps;
  227. struct mv_u3d_ep_context *ep_context;
  228. size_t ep_context_size;
  229. dma_addr_t ep_context_dma;
  230. struct dma_pool *trb_pool; /* for TRB data structure */
  231. struct mv_u3d_ep *eps;
  232. struct mv_u3d_req *status_req; /* ep0 status request */
  233. struct usb_ctrlrequest local_setup_buff; /* store setup data*/
  234. unsigned int resume_state; /* USB state to resume */
  235. unsigned int usb_state; /* USB current state */
  236. unsigned int ep0_state; /* Endpoint zero state */
  237. unsigned int ep0_dir;
  238. unsigned int dev_addr; /* device address */
  239. unsigned int errors;
  240. unsigned softconnect:1;
  241. unsigned vbus_active:1; /* vbus is active or not */
  242. unsigned remote_wakeup:1; /* support remote wakeup */
  243. unsigned clock_gating:1; /* clock gating or not */
  244. unsigned active:1; /* udc is active or not */
  245. unsigned vbus_valid_detect:1; /* udc vbus detection */
  246. struct mv_usb_addon_irq *vbus;
  247. unsigned int power;
  248. struct clk *clk;
  249. };
  250. /* endpoint data structure */
  251. struct mv_u3d_ep {
  252. struct usb_ep ep;
  253. struct mv_u3d *u3d;
  254. struct list_head queue; /* ep request queued hardware */
  255. struct list_head req_list; /* list of ep request */
  256. struct mv_u3d_ep_context *ep_context; /* ep context */
  257. u32 direction;
  258. char name[14];
  259. u32 processing; /* there is ep request
  260. queued on haredware */
  261. spinlock_t req_lock; /* ep lock */
  262. unsigned wedge:1;
  263. unsigned enabled:1;
  264. unsigned ep_type:2;
  265. unsigned ep_num:8;
  266. };
  267. /* request data structure */
  268. struct mv_u3d_req {
  269. struct usb_request req;
  270. struct mv_u3d_ep *ep;
  271. struct list_head queue; /* ep requst queued on hardware */
  272. struct list_head list; /* ep request list */
  273. struct list_head trb_list; /* trb list of a request */
  274. struct mv_u3d_trb *trb_head; /* point to first trb of a request */
  275. unsigned trb_count; /* TRB number in the chain */
  276. unsigned chain; /* TRB chain or not */
  277. };
  278. #endif