mv_udc.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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 of the GNU General Public License as published by the
  6. * Free Software Foundation; either version 2 of the License, or (at your
  7. * option) any later version.
  8. */
  9. #ifndef __MV_UDC_H
  10. #define __MV_UDC_H
  11. #define VUSBHS_MAX_PORTS 8
  12. #define DQH_ALIGNMENT 2048
  13. #define DTD_ALIGNMENT 64
  14. #define DMA_BOUNDARY 4096
  15. #define EP_DIR_IN 1
  16. #define EP_DIR_OUT 0
  17. #define DMA_ADDR_INVALID (~(dma_addr_t)0)
  18. #define EP0_MAX_PKT_SIZE 64
  19. /* ep0 transfer state */
  20. #define WAIT_FOR_SETUP 0
  21. #define DATA_STATE_XMIT 1
  22. #define DATA_STATE_NEED_ZLP 2
  23. #define WAIT_FOR_OUT_STATUS 3
  24. #define DATA_STATE_RECV 4
  25. #define CAPLENGTH_MASK (0xff)
  26. #define DCCPARAMS_DEN_MASK (0x1f)
  27. #define HCSPARAMS_PPC (0x10)
  28. /* Frame Index Register Bit Masks */
  29. #define USB_FRINDEX_MASKS 0x3fff
  30. /* Command Register Bit Masks */
  31. #define USBCMD_RUN_STOP (0x00000001)
  32. #define USBCMD_CTRL_RESET (0x00000002)
  33. #define USBCMD_SETUP_TRIPWIRE_SET (0x00002000)
  34. #define USBCMD_SETUP_TRIPWIRE_CLEAR (~USBCMD_SETUP_TRIPWIRE_SET)
  35. #define USBCMD_ATDTW_TRIPWIRE_SET (0x00004000)
  36. #define USBCMD_ATDTW_TRIPWIRE_CLEAR (~USBCMD_ATDTW_TRIPWIRE_SET)
  37. /* bit 15,3,2 are for frame list size */
  38. #define USBCMD_FRAME_SIZE_1024 (0x00000000) /* 000 */
  39. #define USBCMD_FRAME_SIZE_512 (0x00000004) /* 001 */
  40. #define USBCMD_FRAME_SIZE_256 (0x00000008) /* 010 */
  41. #define USBCMD_FRAME_SIZE_128 (0x0000000C) /* 011 */
  42. #define USBCMD_FRAME_SIZE_64 (0x00008000) /* 100 */
  43. #define USBCMD_FRAME_SIZE_32 (0x00008004) /* 101 */
  44. #define USBCMD_FRAME_SIZE_16 (0x00008008) /* 110 */
  45. #define USBCMD_FRAME_SIZE_8 (0x0000800C) /* 111 */
  46. #define EPCTRL_TX_ALL_MASK (0xFFFF0000)
  47. #define EPCTRL_RX_ALL_MASK (0x0000FFFF)
  48. #define EPCTRL_TX_DATA_TOGGLE_RST (0x00400000)
  49. #define EPCTRL_TX_EP_STALL (0x00010000)
  50. #define EPCTRL_RX_EP_STALL (0x00000001)
  51. #define EPCTRL_RX_DATA_TOGGLE_RST (0x00000040)
  52. #define EPCTRL_RX_ENABLE (0x00000080)
  53. #define EPCTRL_TX_ENABLE (0x00800000)
  54. #define EPCTRL_CONTROL (0x00000000)
  55. #define EPCTRL_ISOCHRONOUS (0x00040000)
  56. #define EPCTRL_BULK (0x00080000)
  57. #define EPCTRL_INT (0x000C0000)
  58. #define EPCTRL_TX_TYPE (0x000C0000)
  59. #define EPCTRL_RX_TYPE (0x0000000C)
  60. #define EPCTRL_DATA_TOGGLE_INHIBIT (0x00000020)
  61. #define EPCTRL_TX_EP_TYPE_SHIFT (18)
  62. #define EPCTRL_RX_EP_TYPE_SHIFT (2)
  63. #define EPCOMPLETE_MAX_ENDPOINTS (16)
  64. /* endpoint list address bit masks */
  65. #define USB_EP_LIST_ADDRESS_MASK 0xfffff800
  66. #define PORTSCX_W1C_BITS 0x2a
  67. #define PORTSCX_PORT_RESET 0x00000100
  68. #define PORTSCX_PORT_POWER 0x00001000
  69. #define PORTSCX_FORCE_FULL_SPEED_CONNECT 0x01000000
  70. #define PORTSCX_PAR_XCVR_SELECT 0xC0000000
  71. #define PORTSCX_PORT_FORCE_RESUME 0x00000040
  72. #define PORTSCX_PORT_SUSPEND 0x00000080
  73. #define PORTSCX_PORT_SPEED_FULL 0x00000000
  74. #define PORTSCX_PORT_SPEED_LOW 0x04000000
  75. #define PORTSCX_PORT_SPEED_HIGH 0x08000000
  76. #define PORTSCX_PORT_SPEED_MASK 0x0C000000
  77. /* USB MODE Register Bit Masks */
  78. #define USBMODE_CTRL_MODE_IDLE 0x00000000
  79. #define USBMODE_CTRL_MODE_DEVICE 0x00000002
  80. #define USBMODE_CTRL_MODE_HOST 0x00000003
  81. #define USBMODE_CTRL_MODE_RSV 0x00000001
  82. #define USBMODE_SETUP_LOCK_OFF 0x00000008
  83. #define USBMODE_STREAM_DISABLE 0x00000010
  84. /* USB STS Register Bit Masks */
  85. #define USBSTS_INT 0x00000001
  86. #define USBSTS_ERR 0x00000002
  87. #define USBSTS_PORT_CHANGE 0x00000004
  88. #define USBSTS_FRM_LST_ROLL 0x00000008
  89. #define USBSTS_SYS_ERR 0x00000010
  90. #define USBSTS_IAA 0x00000020
  91. #define USBSTS_RESET 0x00000040
  92. #define USBSTS_SOF 0x00000080
  93. #define USBSTS_SUSPEND 0x00000100
  94. #define USBSTS_HC_HALTED 0x00001000
  95. #define USBSTS_RCL 0x00002000
  96. #define USBSTS_PERIODIC_SCHEDULE 0x00004000
  97. #define USBSTS_ASYNC_SCHEDULE 0x00008000
  98. /* Interrupt Enable Register Bit Masks */
  99. #define USBINTR_INT_EN (0x00000001)
  100. #define USBINTR_ERR_INT_EN (0x00000002)
  101. #define USBINTR_PORT_CHANGE_DETECT_EN (0x00000004)
  102. #define USBINTR_ASYNC_ADV_AAE (0x00000020)
  103. #define USBINTR_ASYNC_ADV_AAE_ENABLE (0x00000020)
  104. #define USBINTR_ASYNC_ADV_AAE_DISABLE (0xFFFFFFDF)
  105. #define USBINTR_RESET_EN (0x00000040)
  106. #define USBINTR_SOF_UFRAME_EN (0x00000080)
  107. #define USBINTR_DEVICE_SUSPEND (0x00000100)
  108. #define USB_DEVICE_ADDRESS_MASK (0xfe000000)
  109. #define USB_DEVICE_ADDRESS_BIT_SHIFT (25)
  110. struct mv_cap_regs {
  111. u32 caplength_hciversion;
  112. u32 hcsparams; /* HC structural parameters */
  113. u32 hccparams; /* HC Capability Parameters*/
  114. u32 reserved[5];
  115. u32 dciversion; /* DC version number and reserved 16 bits */
  116. u32 dccparams; /* DC Capability Parameters */
  117. };
  118. struct mv_op_regs {
  119. u32 usbcmd; /* Command register */
  120. u32 usbsts; /* Status register */
  121. u32 usbintr; /* Interrupt enable */
  122. u32 frindex; /* Frame index */
  123. u32 reserved1[1];
  124. u32 deviceaddr; /* Device Address */
  125. u32 eplistaddr; /* Endpoint List Address */
  126. u32 ttctrl; /* HOST TT status and control */
  127. u32 burstsize; /* Programmable Burst Size */
  128. u32 txfilltuning; /* Host Transmit Pre-Buffer Packet Tuning */
  129. u32 reserved[4];
  130. u32 epnak; /* Endpoint NAK */
  131. u32 epnaken; /* Endpoint NAK Enable */
  132. u32 configflag; /* Configured Flag register */
  133. u32 portsc[VUSBHS_MAX_PORTS]; /* Port Status/Control x, x = 1..8 */
  134. u32 otgsc;
  135. u32 usbmode; /* USB Host/Device mode */
  136. u32 epsetupstat; /* Endpoint Setup Status */
  137. u32 epprime; /* Endpoint Initialize */
  138. u32 epflush; /* Endpoint De-initialize */
  139. u32 epstatus; /* Endpoint Status */
  140. u32 epcomplete; /* Endpoint Interrupt On Complete */
  141. u32 epctrlx[16]; /* Endpoint Control, where x = 0.. 15 */
  142. u32 mcr; /* Mux Control */
  143. u32 isr; /* Interrupt Status */
  144. u32 ier; /* Interrupt Enable */
  145. };
  146. struct mv_udc {
  147. struct usb_gadget gadget;
  148. struct usb_gadget_driver *driver;
  149. spinlock_t lock;
  150. struct completion *done;
  151. struct platform_device *dev;
  152. int irq;
  153. struct mv_cap_regs __iomem *cap_regs;
  154. struct mv_op_regs __iomem *op_regs;
  155. void __iomem *phy_regs;
  156. unsigned int max_eps;
  157. struct mv_dqh *ep_dqh;
  158. size_t ep_dqh_size;
  159. dma_addr_t ep_dqh_dma;
  160. struct dma_pool *dtd_pool;
  161. struct mv_ep *eps;
  162. struct mv_dtd *dtd_head;
  163. struct mv_dtd *dtd_tail;
  164. unsigned int dtd_entries;
  165. struct mv_req *status_req;
  166. struct usb_ctrlrequest local_setup_buff;
  167. unsigned int resume_state; /* USB state to resume */
  168. unsigned int usb_state; /* USB current state */
  169. unsigned int ep0_state; /* Endpoint zero state */
  170. unsigned int ep0_dir;
  171. unsigned int dev_addr;
  172. unsigned int test_mode;
  173. int errors;
  174. unsigned softconnect:1,
  175. vbus_active:1,
  176. remote_wakeup:1,
  177. softconnected:1,
  178. force_fs:1,
  179. clock_gating:1,
  180. active:1,
  181. stopped:1; /* stop bit is setted */
  182. struct work_struct vbus_work;
  183. struct workqueue_struct *qwork;
  184. struct usb_phy *transceiver;
  185. struct mv_usb_platform_data *pdata;
  186. /* some SOC has mutiple clock sources for USB*/
  187. struct clk *clk;
  188. };
  189. /* endpoint data structure */
  190. struct mv_ep {
  191. struct usb_ep ep;
  192. struct mv_udc *udc;
  193. struct list_head queue;
  194. struct mv_dqh *dqh;
  195. u32 direction;
  196. char name[14];
  197. unsigned stopped:1,
  198. wedge:1,
  199. ep_type:2,
  200. ep_num:8;
  201. };
  202. /* request data structure */
  203. struct mv_req {
  204. struct usb_request req;
  205. struct mv_dtd *dtd, *head, *tail;
  206. struct mv_ep *ep;
  207. struct list_head queue;
  208. unsigned int test_mode;
  209. unsigned dtd_count;
  210. unsigned mapped:1;
  211. };
  212. #define EP_QUEUE_HEAD_MULT_POS 30
  213. #define EP_QUEUE_HEAD_ZLT_SEL 0x20000000
  214. #define EP_QUEUE_HEAD_MAX_PKT_LEN_POS 16
  215. #define EP_QUEUE_HEAD_MAX_PKT_LEN(ep_info) (((ep_info)>>16)&0x07ff)
  216. #define EP_QUEUE_HEAD_IOS 0x00008000
  217. #define EP_QUEUE_HEAD_NEXT_TERMINATE 0x00000001
  218. #define EP_QUEUE_HEAD_IOC 0x00008000
  219. #define EP_QUEUE_HEAD_MULTO 0x00000C00
  220. #define EP_QUEUE_HEAD_STATUS_HALT 0x00000040
  221. #define EP_QUEUE_HEAD_STATUS_ACTIVE 0x00000080
  222. #define EP_QUEUE_CURRENT_OFFSET_MASK 0x00000FFF
  223. #define EP_QUEUE_HEAD_NEXT_POINTER_MASK 0xFFFFFFE0
  224. #define EP_QUEUE_FRINDEX_MASK 0x000007FF
  225. #define EP_MAX_LENGTH_TRANSFER 0x4000
  226. struct mv_dqh {
  227. /* Bits 16..26 Bit 15 is Interrupt On Setup */
  228. u32 max_packet_length;
  229. u32 curr_dtd_ptr; /* Current dTD Pointer */
  230. u32 next_dtd_ptr; /* Next dTD Pointer */
  231. /* Total bytes (16..30), IOC (15), INT (8), STS (0-7) */
  232. u32 size_ioc_int_sts;
  233. u32 buff_ptr0; /* Buffer pointer Page 0 (12-31) */
  234. u32 buff_ptr1; /* Buffer pointer Page 1 (12-31) */
  235. u32 buff_ptr2; /* Buffer pointer Page 2 (12-31) */
  236. u32 buff_ptr3; /* Buffer pointer Page 3 (12-31) */
  237. u32 buff_ptr4; /* Buffer pointer Page 4 (12-31) */
  238. u32 reserved1;
  239. /* 8 bytes of setup data that follows the Setup PID */
  240. u8 setup_buffer[8];
  241. u32 reserved2[4];
  242. };
  243. #define DTD_NEXT_TERMINATE (0x00000001)
  244. #define DTD_IOC (0x00008000)
  245. #define DTD_STATUS_ACTIVE (0x00000080)
  246. #define DTD_STATUS_HALTED (0x00000040)
  247. #define DTD_STATUS_DATA_BUFF_ERR (0x00000020)
  248. #define DTD_STATUS_TRANSACTION_ERR (0x00000008)
  249. #define DTD_RESERVED_FIELDS (0x00007F00)
  250. #define DTD_ERROR_MASK (0x68)
  251. #define DTD_ADDR_MASK (0xFFFFFFE0)
  252. #define DTD_PACKET_SIZE 0x7FFF0000
  253. #define DTD_LENGTH_BIT_POS (16)
  254. struct mv_dtd {
  255. u32 dtd_next;
  256. u32 size_ioc_sts;
  257. u32 buff_ptr0; /* Buffer pointer Page 0 */
  258. u32 buff_ptr1; /* Buffer pointer Page 1 */
  259. u32 buff_ptr2; /* Buffer pointer Page 2 */
  260. u32 buff_ptr3; /* Buffer pointer Page 3 */
  261. u32 buff_ptr4; /* Buffer pointer Page 4 */
  262. u32 scratch_ptr;
  263. /* 32 bytes */
  264. dma_addr_t td_dma; /* dma address for this td */
  265. struct mv_dtd *next_dtd_virt;
  266. };
  267. #endif