dwc_otg_pcd_if.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. /* ==========================================================================
  2. * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_if.h $
  3. * $Revision: #11 $
  4. * $Date: 2011/10/26 $
  5. * $Change: 1873028 $
  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_IF_H__)
  35. #define __DWC_PCD_IF_H__
  36. //#include "dwc_os.h"
  37. #include "dwc_otg_core_if.h"
  38. /** @file
  39. * This file defines DWC_OTG PCD Core API.
  40. */
  41. struct dwc_otg_pcd;
  42. typedef struct dwc_otg_pcd dwc_otg_pcd_t;
  43. /** Maxpacket size for EP0 */
  44. #define MAX_EP0_SIZE 64
  45. /** Maxpacket size for any EP */
  46. #define MAX_PACKET_SIZE 1024
  47. /** @name Function Driver Callbacks */
  48. /** @{ */
  49. /** This function will be called whenever a previously queued request has
  50. * completed. The status value will be set to -DWC_E_SHUTDOWN to indicated a
  51. * failed or aborted transfer, or -DWC_E_RESTART to indicate the device was reset,
  52. * or -DWC_E_TIMEOUT to indicate it timed out, or -DWC_E_INVALID to indicate invalid
  53. * parameters. */
  54. typedef int (*dwc_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  55. void *req_handle, int32_t status,
  56. uint32_t actual);
  57. /**
  58. * This function will be called whenever a previousle queued ISOC request has
  59. * completed. Count of ISOC packets could be read using dwc_otg_pcd_get_iso_packet_count
  60. * function.
  61. * The status of each ISOC packet could be read using dwc_otg_pcd_get_iso_packet_*
  62. * functions.
  63. */
  64. typedef int (*dwc_isoc_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  65. void *req_handle, int proc_buf_num);
  66. /** This function should handle any SETUP request that cannot be handled by the
  67. * PCD Core. This includes most GET_DESCRIPTORs, SET_CONFIGS, Any
  68. * class-specific requests, etc. The function must non-blocking.
  69. *
  70. * Returns 0 on success.
  71. * Returns -DWC_E_NOT_SUPPORTED if the request is not supported.
  72. * Returns -DWC_E_INVALID if the setup request had invalid parameters or bytes.
  73. * Returns -DWC_E_SHUTDOWN on any other error. */
  74. typedef int (*dwc_setup_cb_t) (dwc_otg_pcd_t * pcd, uint8_t * bytes);
  75. /** This is called whenever the device has been disconnected. The function
  76. * driver should take appropriate action to clean up all pending requests in the
  77. * PCD Core, remove all endpoints (except ep0), and initialize back to reset
  78. * state. */
  79. typedef int (*dwc_disconnect_cb_t) (dwc_otg_pcd_t * pcd);
  80. /** This function is called when device has been connected. */
  81. typedef int (*dwc_connect_cb_t) (dwc_otg_pcd_t * pcd, int speed);
  82. /** This function is called when device has been suspended */
  83. typedef int (*dwc_suspend_cb_t) (dwc_otg_pcd_t * pcd);
  84. /** This function is called when device has received LPM tokens, i.e.
  85. * device has been sent to sleep state. */
  86. typedef int (*dwc_sleep_cb_t) (dwc_otg_pcd_t * pcd);
  87. /** This function is called when device has been resumed
  88. * from suspend(L2) or L1 sleep state. */
  89. typedef int (*dwc_resume_cb_t) (dwc_otg_pcd_t * pcd);
  90. /** This function is called whenever hnp params has been changed.
  91. * User can call get_b_hnp_enable, get_a_hnp_support, get_a_alt_hnp_support functions
  92. * to get hnp parameters. */
  93. typedef int (*dwc_hnp_params_changed_cb_t) (dwc_otg_pcd_t * pcd);
  94. /** This function is called whenever USB RESET is detected. */
  95. typedef int (*dwc_reset_cb_t) (dwc_otg_pcd_t * pcd);
  96. typedef int (*cfi_setup_cb_t) (dwc_otg_pcd_t * pcd, void *ctrl_req_bytes);
  97. /**
  98. *
  99. * @param ep_handle Void pointer to the usb_ep structure
  100. * @param ereq_port Pointer to the extended request structure created in the
  101. * portable part.
  102. */
  103. typedef int (*xiso_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  104. void *req_handle, int32_t status,
  105. void *ereq_port);
  106. /** Function Driver Ops Data Structure */
  107. struct dwc_otg_pcd_function_ops {
  108. dwc_connect_cb_t connect;
  109. dwc_disconnect_cb_t disconnect;
  110. dwc_setup_cb_t setup;
  111. dwc_completion_cb_t complete;
  112. dwc_isoc_completion_cb_t isoc_complete;
  113. dwc_suspend_cb_t suspend;
  114. dwc_sleep_cb_t sleep;
  115. dwc_resume_cb_t resume;
  116. dwc_reset_cb_t reset;
  117. dwc_hnp_params_changed_cb_t hnp_changed;
  118. cfi_setup_cb_t cfi_setup;
  119. #ifdef DWC_UTE_PER_IO
  120. xiso_completion_cb_t xisoc_complete;
  121. #endif
  122. };
  123. /** @} */
  124. /** @name Function Driver Functions */
  125. /** @{ */
  126. /** Call this function to get pointer on dwc_otg_pcd_t,
  127. * this pointer will be used for all PCD API functions.
  128. *
  129. * @param core_if The DWC_OTG Core
  130. */
  131. extern dwc_otg_pcd_t *dwc_otg_pcd_init(dwc_otg_core_if_t * core_if);
  132. /** Frees PCD allocated by dwc_otg_pcd_init
  133. *
  134. * @param pcd The PCD
  135. */
  136. extern void dwc_otg_pcd_remove(dwc_otg_pcd_t * pcd);
  137. /** Call this to bind the function driver to the PCD Core.
  138. *
  139. * @param pcd Pointer on dwc_otg_pcd_t returned by dwc_otg_pcd_init function.
  140. * @param fops The Function Driver Ops data structure containing pointers to all callbacks.
  141. */
  142. extern void dwc_otg_pcd_start(dwc_otg_pcd_t * pcd,
  143. const struct dwc_otg_pcd_function_ops *fops);
  144. /** Enables an endpoint for use. This function enables an endpoint in
  145. * the PCD. The endpoint is described by the ep_desc which has the
  146. * same format as a USB ep descriptor. The ep_handle parameter is used to refer
  147. * to the endpoint from other API functions and in callbacks. Normally this
  148. * should be called after a SET_CONFIGURATION/SET_INTERFACE to configure the
  149. * core for that interface.
  150. *
  151. * Returns -DWC_E_INVALID if invalid parameters were passed.
  152. * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  153. * Returns 0 on success.
  154. *
  155. * @param pcd The PCD
  156. * @param ep_desc Endpoint descriptor
  157. * @param usb_ep Handle on endpoint, that will be used to identify endpoint.
  158. */
  159. extern int dwc_otg_pcd_ep_enable(dwc_otg_pcd_t * pcd,
  160. const uint8_t * ep_desc, void *usb_ep);
  161. /** Disable the endpoint referenced by ep_handle.
  162. *
  163. * Returns -DWC_E_INVALID if invalid parameters were passed.
  164. * Returns -DWC_E_SHUTDOWN if any other error occurred.
  165. * Returns 0 on success. */
  166. extern int dwc_otg_pcd_ep_disable(dwc_otg_pcd_t * pcd, void *ep_handle);
  167. /** Queue a data transfer request on the endpoint referenced by ep_handle.
  168. * After the transfer is completes, the complete callback will be called with
  169. * the request status.
  170. *
  171. * @param pcd The PCD
  172. * @param ep_handle The handle of the endpoint
  173. * @param buf The buffer for the data
  174. * @param dma_buf The DMA buffer for the data
  175. * @param buflen The length of the data transfer
  176. * @param zero Specifies whether to send zero length last packet.
  177. * @param req_handle Set this handle to any value to use to reference this
  178. * request in the ep_dequeue function or from the complete callback
  179. * @param atomic_alloc If driver need to perform atomic allocations
  180. * for internal data structures.
  181. *
  182. * Returns -DWC_E_INVALID if invalid parameters were passed.
  183. * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  184. * Returns 0 on success. */
  185. extern int dwc_otg_pcd_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  186. uint8_t * buf, dwc_dma_t dma_buf,
  187. uint32_t buflen, int zero, void *req_handle,
  188. int atomic_alloc);
  189. #ifdef DWC_UTE_PER_IO
  190. /**
  191. *
  192. * @param ereq_nonport Pointer to the extended request part of the
  193. * usb_request structure defined in usb_gadget.h file.
  194. */
  195. extern int dwc_otg_pcd_xiso_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  196. uint8_t * buf, dwc_dma_t dma_buf,
  197. uint32_t buflen, int zero,
  198. void *req_handle, int atomic_alloc,
  199. void *ereq_nonport);
  200. #endif
  201. /** De-queue the specified data transfer that has not yet completed.
  202. *
  203. * Returns -DWC_E_INVALID if invalid parameters were passed.
  204. * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  205. * Returns 0 on success. */
  206. extern int dwc_otg_pcd_ep_dequeue(dwc_otg_pcd_t * pcd, void *ep_handle,
  207. void *req_handle);
  208. /** Halt (STALL) an endpoint or clear it.
  209. *
  210. * Returns -DWC_E_INVALID if invalid parameters were passed.
  211. * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  212. * Returns -DWC_E_AGAIN if the STALL cannot be sent and must be tried again later
  213. * Returns 0 on success. */
  214. extern int dwc_otg_pcd_ep_halt(dwc_otg_pcd_t * pcd, void *ep_handle, int value);
  215. /** This function should be called on every hardware interrupt */
  216. extern int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t * pcd);
  217. /** This function returns current frame number */
  218. extern int dwc_otg_pcd_get_frame_number(dwc_otg_pcd_t * pcd);
  219. /**
  220. * Start isochronous transfers on the endpoint referenced by ep_handle.
  221. * For isochronous transfers duble buffering is used.
  222. * After processing each of buffers comlete callback will be called with
  223. * status for each transaction.
  224. *
  225. * @param pcd The PCD
  226. * @param ep_handle The handle of the endpoint
  227. * @param buf0 The virtual address of first data buffer
  228. * @param buf1 The virtual address of second data buffer
  229. * @param dma0 The DMA address of first data buffer
  230. * @param dma1 The DMA address of second data buffer
  231. * @param sync_frame Data pattern frame number
  232. * @param dp_frame Data size for pattern frame
  233. * @param data_per_frame Data size for regular frame
  234. * @param start_frame Frame number to start transfers, if -1 then start transfers ASAP.
  235. * @param buf_proc_intrvl Interval of ISOC Buffer processing
  236. * @param req_handle Handle of ISOC request
  237. * @param atomic_alloc Specefies whether to perform atomic allocation for
  238. * internal data structures.
  239. *
  240. * Returns -DWC_E_NO_MEMORY if there is no enough memory.
  241. * Returns -DWC_E_INVALID if incorrect arguments are passed to the function.
  242. * Returns -DW_E_SHUTDOWN for any other error.
  243. * Returns 0 on success
  244. */
  245. extern int dwc_otg_pcd_iso_ep_start(dwc_otg_pcd_t * pcd, void *ep_handle,
  246. uint8_t * buf0, uint8_t * buf1,
  247. dwc_dma_t dma0, dwc_dma_t dma1,
  248. int sync_frame, int dp_frame,
  249. int data_per_frame, int start_frame,
  250. int buf_proc_intrvl, void *req_handle,
  251. int atomic_alloc);
  252. /** Stop ISOC transfers on endpoint referenced by ep_handle.
  253. *
  254. * @param pcd The PCD
  255. * @param ep_handle The handle of the endpoint
  256. * @param req_handle Handle of ISOC request
  257. *
  258. * Returns -DWC_E_INVALID if incorrect arguments are passed to the function
  259. * Returns 0 on success
  260. */
  261. int dwc_otg_pcd_iso_ep_stop(dwc_otg_pcd_t * pcd, void *ep_handle,
  262. void *req_handle);
  263. /** Get ISOC packet status.
  264. *
  265. * @param pcd The PCD
  266. * @param ep_handle The handle of the endpoint
  267. * @param iso_req_handle Isochronoush request handle
  268. * @param packet Number of packet
  269. * @param status Out parameter for returning status
  270. * @param actual Out parameter for returning actual length
  271. * @param offset Out parameter for returning offset
  272. *
  273. */
  274. extern void dwc_otg_pcd_get_iso_packet_params(dwc_otg_pcd_t * pcd,
  275. void *ep_handle,
  276. void *iso_req_handle, int packet,
  277. int *status, int *actual,
  278. int *offset);
  279. /** Get ISOC packet count.
  280. *
  281. * @param pcd The PCD
  282. * @param ep_handle The handle of the endpoint
  283. * @param iso_req_handle
  284. */
  285. extern int dwc_otg_pcd_get_iso_packet_count(dwc_otg_pcd_t * pcd,
  286. void *ep_handle,
  287. void *iso_req_handle);
  288. /** This function starts the SRP Protocol if no session is in progress. If
  289. * a session is already in progress, but the device is suspended,
  290. * remote wakeup signaling is started.
  291. */
  292. extern int dwc_otg_pcd_wakeup(dwc_otg_pcd_t * pcd);
  293. /** This function returns 1 if LPM support is enabled, and 0 otherwise. */
  294. extern int dwc_otg_pcd_is_lpm_enabled(dwc_otg_pcd_t * pcd);
  295. /** This function returns 1 if remote wakeup is allowed and 0, otherwise. */
  296. extern int dwc_otg_pcd_get_rmwkup_enable(dwc_otg_pcd_t * pcd);
  297. /** Initiate SRP */
  298. extern void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t * pcd);
  299. /** Starts remote wakeup signaling. */
  300. extern void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t * pcd, int set);
  301. /** Starts micorsecond soft disconnect. */
  302. extern void dwc_otg_pcd_disconnect_us(dwc_otg_pcd_t * pcd, int no_of_usecs);
  303. /** This function returns whether device is dualspeed.*/
  304. extern uint32_t dwc_otg_pcd_is_dualspeed(dwc_otg_pcd_t * pcd);
  305. /** This function returns whether device is otg. */
  306. extern uint32_t dwc_otg_pcd_is_otg(dwc_otg_pcd_t * pcd);
  307. /** These functions allow to get hnp parameters */
  308. extern uint32_t get_b_hnp_enable(dwc_otg_pcd_t * pcd);
  309. extern uint32_t get_a_hnp_support(dwc_otg_pcd_t * pcd);
  310. extern uint32_t get_a_alt_hnp_support(dwc_otg_pcd_t * pcd);
  311. /** CFI specific Interface functions */
  312. /** Allocate a cfi buffer */
  313. extern uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep,
  314. dwc_dma_t * addr, size_t buflen,
  315. int flags);
  316. /******************************************************************************/
  317. /** @} */
  318. #endif /* __DWC_PCD_IF_H__ */
  319. #endif /* DWC_HOST_ONLY */