dwc_otg_pcd.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /* ==========================================================================
  2. * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.h $
  3. * $Revision: #46 $
  4. * $Date: 2011/10/20 $
  5. * $Change: 1870124 $
  6. *
  7. * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  8. * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  9. * otherwise expressly agreed to in writing between Synopsys and you.
  10. *
  11. * The Software IS NOT an item of Licensed Software or Licensed Product under
  12. * any End User Software License Agreement or Agreement for Licensed Product
  13. * with Synopsys or any supplement thereto. You are permitted to use and
  14. * redistribute this Software in source and binary forms, with or without
  15. * modification, provided that redistributions of source code must retain this
  16. * notice. You may not view, use, disclose, copy or distribute this file or
  17. * any information contained herein except pursuant to this license grant from
  18. * Synopsys. If you do not agree with this notice, including the disclaimer
  19. * below, then you are not authorized to use the Software.
  20. *
  21. * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  25. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  26. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  27. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  31. * DAMAGE.
  32. * ========================================================================== */
  33. #ifndef DWC_HOST_ONLY
  34. #if !defined(__DWC_PCD_H__)
  35. #define __DWC_PCD_H__
  36. #include "dwc_otg_os_dep.h"
  37. #include "usb.h"
  38. #include "dwc_otg_cil.h"
  39. #include "dwc_otg_pcd_if.h"
  40. struct cfiobject;
  41. /**
  42. * @file
  43. *
  44. * This file contains the structures, constants, and interfaces for
  45. * the Perpherial Contoller Driver (PCD).
  46. *
  47. * The Peripheral Controller Driver (PCD) for Linux will implement the
  48. * Gadget API, so that the existing Gadget drivers can be used. For
  49. * the Mass Storage Function driver the File-backed USB Storage Gadget
  50. * (FBS) driver will be used. The FBS driver supports the
  51. * Control-Bulk (CB), Control-Bulk-Interrupt (CBI), and Bulk-Only
  52. * transports.
  53. *
  54. */
  55. /** Invalid DMA Address */
  56. #define DWC_DMA_ADDR_INVALID (~(dwc_dma_t)0)
  57. /** Max Transfer size for any EP */
  58. #define DDMA_MAX_TRANSFER_SIZE 65535
  59. /**
  60. * Get the pointer to the core_if from the pcd pointer.
  61. */
  62. #define GET_CORE_IF( _pcd ) (_pcd->core_if)
  63. /**
  64. * States of EP0.
  65. */
  66. typedef enum ep0_state {
  67. EP0_DISCONNECT, /* no host */
  68. EP0_IDLE,
  69. EP0_IN_DATA_PHASE,
  70. EP0_OUT_DATA_PHASE,
  71. EP0_IN_STATUS_PHASE,
  72. EP0_OUT_STATUS_PHASE,
  73. EP0_STALL,
  74. } ep0state_e;
  75. /** Fordward declaration.*/
  76. struct dwc_otg_pcd;
  77. /** DWC_otg iso request structure.
  78. *
  79. */
  80. typedef struct usb_iso_request dwc_otg_pcd_iso_request_t;
  81. #ifdef DWC_UTE_PER_IO
  82. /**
  83. * This shall be the exact analogy of the same type structure defined in the
  84. * usb_gadget.h. Each descriptor contains
  85. */
  86. struct dwc_iso_pkt_desc_port {
  87. uint32_t offset;
  88. uint32_t length; /* expected length */
  89. uint32_t actual_length;
  90. uint32_t status;
  91. };
  92. struct dwc_iso_xreq_port {
  93. /** transfer/submission flag */
  94. uint32_t tr_sub_flags;
  95. /** Start the request ASAP */
  96. #define DWC_EREQ_TF_ASAP 0x00000002
  97. /** Just enqueue the request w/o initiating a transfer */
  98. #define DWC_EREQ_TF_ENQUEUE 0x00000004
  99. /**
  100. * count of ISO packets attached to this request - shall
  101. * not exceed the pio_alloc_pkt_count
  102. */
  103. uint32_t pio_pkt_count;
  104. /** count of ISO packets allocated for this request */
  105. uint32_t pio_alloc_pkt_count;
  106. /** number of ISO packet errors */
  107. uint32_t error_count;
  108. /** reserved for future extension */
  109. uint32_t res;
  110. /** Will be allocated and freed in the UTE gadget and based on the CFC value */
  111. struct dwc_iso_pkt_desc_port *per_io_frame_descs;
  112. };
  113. #endif
  114. /** DWC_otg request structure.
  115. * This structure is a list of requests.
  116. */
  117. typedef struct dwc_otg_pcd_request {
  118. void *priv;
  119. void *buf;
  120. dwc_dma_t dma;
  121. uint32_t length;
  122. uint32_t actual;
  123. unsigned sent_zlp:1;
  124. /**
  125. * Used instead of original buffer if
  126. * it(physical address) is not dword-aligned.
  127. **/
  128. uint8_t *dw_align_buf;
  129. dwc_dma_t dw_align_buf_dma;
  130. DWC_CIRCLEQ_ENTRY(dwc_otg_pcd_request) queue_entry;
  131. #ifdef DWC_UTE_PER_IO
  132. struct dwc_iso_xreq_port ext_req;
  133. //void *priv_ereq_nport; /* */
  134. #endif
  135. } dwc_otg_pcd_request_t;
  136. DWC_CIRCLEQ_HEAD(req_list, dwc_otg_pcd_request);
  137. /** PCD EP structure.
  138. * This structure describes an EP, there is an array of EPs in the PCD
  139. * structure.
  140. */
  141. typedef struct dwc_otg_pcd_ep {
  142. /** USB EP Descriptor */
  143. const usb_endpoint_descriptor_t *desc;
  144. /** queue of dwc_otg_pcd_requests. */
  145. struct req_list queue;
  146. unsigned stopped:1;
  147. unsigned disabling:1;
  148. unsigned dma:1;
  149. unsigned queue_sof:1;
  150. #ifdef DWC_EN_ISOC
  151. /** ISOC req handle passed */
  152. void *iso_req_handle;
  153. #endif //_EN_ISOC_
  154. /** DWC_otg ep data. */
  155. dwc_ep_t dwc_ep;
  156. /** Pointer to PCD */
  157. struct dwc_otg_pcd *pcd;
  158. void *priv;
  159. } dwc_otg_pcd_ep_t;
  160. /** DWC_otg PCD Structure.
  161. * This structure encapsulates the data for the dwc_otg PCD.
  162. */
  163. struct dwc_otg_pcd {
  164. const struct dwc_otg_pcd_function_ops *fops;
  165. /** The DWC otg device pointer */
  166. struct dwc_otg_device *otg_dev;
  167. /** Core Interface */
  168. dwc_otg_core_if_t *core_if;
  169. /** State of EP0 */
  170. ep0state_e ep0state;
  171. /** EP0 Request is pending */
  172. unsigned ep0_pending:1;
  173. /** Indicates when SET CONFIGURATION Request is in process */
  174. unsigned request_config:1;
  175. /** The state of the Remote Wakeup Enable. */
  176. unsigned remote_wakeup_enable:1;
  177. /** The state of the B-Device HNP Enable. */
  178. unsigned b_hnp_enable:1;
  179. /** The state of A-Device HNP Support. */
  180. unsigned a_hnp_support:1;
  181. /** The state of the A-Device Alt HNP support. */
  182. unsigned a_alt_hnp_support:1;
  183. /** Count of pending Requests */
  184. unsigned request_pending;
  185. /** SETUP packet for EP0
  186. * This structure is allocated as a DMA buffer on PCD initialization
  187. * with enough space for up to 3 setup packets.
  188. */
  189. union {
  190. usb_device_request_t req;
  191. uint32_t d32[2];
  192. } *setup_pkt;
  193. dwc_dma_t setup_pkt_dma_handle;
  194. /** 2-byte dma buffer used to return status from GET_STATUS */
  195. uint16_t *status_buf;
  196. dwc_dma_t status_buf_dma_handle;
  197. /** EP0 */
  198. dwc_otg_pcd_ep_t ep0;
  199. /** Array of IN EPs. */
  200. dwc_otg_pcd_ep_t in_ep[MAX_EPS_CHANNELS - 1];
  201. /** Array of OUT EPs. */
  202. dwc_otg_pcd_ep_t out_ep[MAX_EPS_CHANNELS - 1];
  203. /** number of valid EPs in the above array. */
  204. // unsigned num_eps : 4;
  205. dwc_spinlock_t *lock;
  206. /** Tasklet to defer starting of TEST mode transmissions until
  207. * Status Phase has been completed.
  208. */
  209. dwc_tasklet_t *test_mode_tasklet;
  210. /** Tasklet to delay starting of xfer in DMA mode */
  211. dwc_tasklet_t *start_xfer_tasklet;
  212. /** The test mode to enter when the tasklet is executed. */
  213. unsigned test_mode;
  214. /** The cfi_api structure that implements most of the CFI API
  215. * and OTG specific core configuration functionality
  216. */
  217. #ifdef DWC_UTE_CFI
  218. struct cfiobject *cfi;
  219. #endif
  220. };
  221. /** Pullup enable */
  222. static inline void dwc_otg_device_soft_connect(dwc_otg_core_if_t *_core_if) {
  223. DWC_MODIFY_REG32( &_core_if->dev_if->dev_global_regs->dctl,2,0); //clr
  224. }
  225. /** Pullup disable */
  226. static inline void dwc_otg_device_soft_disconnect(dwc_otg_core_if_t *_core_if) {
  227. DWC_MODIFY_REG32( &_core_if->dev_if->dev_global_regs->dctl,0,2); //set
  228. }
  229. int dwc_otg_charger_detect(dwc_otg_core_if_t * _core_if);
  230. //FIXME this functions should be static, and this prototypes should be removed
  231. extern void dwc_otg_request_nuke(dwc_otg_pcd_ep_t * ep);
  232. extern void dwc_otg_request_done(dwc_otg_pcd_ep_t * ep,
  233. dwc_otg_pcd_request_t * req, int32_t status);
  234. void dwc_otg_iso_buffer_done(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep,
  235. void *req_handle);
  236. extern void do_test_mode(void *data);
  237. #endif
  238. #endif /* DWC_HOST_ONLY */