dwc_otg_hcd_if.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. /* ==========================================================================
  2. * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_if.h $
  3. * $Revision: #12 $
  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_DEVICE_ONLY
  34. #ifndef __DWC_HCD_IF_H__
  35. #define __DWC_HCD_IF_H__
  36. #include "dwc_otg_core_if.h"
  37. /** @file
  38. * This file defines DWC_OTG HCD Core API.
  39. */
  40. struct dwc_otg_hcd;
  41. typedef struct dwc_otg_hcd dwc_otg_hcd_t;
  42. struct dwc_otg_hcd_urb;
  43. typedef struct dwc_otg_hcd_urb dwc_otg_hcd_urb_t;
  44. /** @name HCD Function Driver Callbacks */
  45. /** @{ */
  46. /** This function is called whenever core switches to host mode. */
  47. typedef int (*dwc_otg_hcd_start_cb_t) (dwc_otg_hcd_t * hcd);
  48. /** This function is called when device has been disconnected */
  49. typedef int (*dwc_otg_hcd_disconnect_cb_t) (dwc_otg_hcd_t * hcd);
  50. /** Wrapper provides this function to HCD to core, so it can get hub information to which device is connected */
  51. typedef int (*dwc_otg_hcd_hub_info_from_urb_cb_t) (dwc_otg_hcd_t * hcd,
  52. void *urb_handle,
  53. uint32_t * hub_addr,
  54. uint32_t * port_addr);
  55. /** Via this function HCD core gets device speed */
  56. typedef int (*dwc_otg_hcd_speed_from_urb_cb_t) (dwc_otg_hcd_t * hcd,
  57. void *urb_handle);
  58. /** This function is called when urb is completed */
  59. typedef int (*dwc_otg_hcd_complete_urb_cb_t) (dwc_otg_hcd_t * hcd,
  60. void *urb_handle,
  61. dwc_otg_hcd_urb_t * dwc_otg_urb,
  62. int32_t status);
  63. /** Via this function HCD core gets b_hnp_enable parameter */
  64. typedef int (*dwc_otg_hcd_get_b_hnp_enable) (dwc_otg_hcd_t * hcd);
  65. struct dwc_otg_hcd_function_ops {
  66. dwc_otg_hcd_start_cb_t start;
  67. dwc_otg_hcd_disconnect_cb_t disconnect;
  68. dwc_otg_hcd_hub_info_from_urb_cb_t hub_info;
  69. dwc_otg_hcd_speed_from_urb_cb_t speed;
  70. dwc_otg_hcd_complete_urb_cb_t complete;
  71. dwc_otg_hcd_get_b_hnp_enable get_b_hnp_enable;
  72. };
  73. /** @} */
  74. /** @name HCD Core API */
  75. /** @{ */
  76. /** This function allocates dwc_otg_hcd structure and returns pointer on it. */
  77. extern dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void);
  78. /** This function should be called to initiate HCD Core.
  79. *
  80. * @param hcd The HCD
  81. * @param core_if The DWC_OTG Core
  82. *
  83. * Returns -DWC_E_NO_MEMORY if no enough memory.
  84. * Returns 0 on success
  85. */
  86. extern int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if);
  87. /** Frees HCD
  88. *
  89. * @param hcd The HCD
  90. */
  91. extern void dwc_otg_hcd_remove(dwc_otg_hcd_t * hcd);
  92. /** This function should be called on every hardware interrupt.
  93. *
  94. * @param dwc_otg_hcd The HCD
  95. *
  96. * Returns non zero if interrupt is handled
  97. * Return 0 if interrupt is not handled
  98. */
  99. extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  100. /**
  101. * Returns private data set by
  102. * dwc_otg_hcd_set_priv_data function.
  103. *
  104. * @param hcd The HCD
  105. */
  106. extern void *dwc_otg_hcd_get_priv_data(dwc_otg_hcd_t * hcd);
  107. /**
  108. * Set private data.
  109. *
  110. * @param hcd The HCD
  111. * @param priv_data pointer to be stored in private data
  112. */
  113. extern void dwc_otg_hcd_set_priv_data(dwc_otg_hcd_t * hcd, void *priv_data);
  114. /**
  115. * This function initializes the HCD Core.
  116. *
  117. * @param hcd The HCD
  118. * @param fops The Function Driver Operations data structure containing pointers to all callbacks.
  119. *
  120. * Returns -DWC_E_NO_DEVICE if Core is currently is in device mode.
  121. * Returns 0 on success
  122. */
  123. extern int dwc_otg_hcd_start(dwc_otg_hcd_t * hcd,
  124. struct dwc_otg_hcd_function_ops *fops);
  125. /**
  126. * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  127. * stopped.
  128. *
  129. * @param hcd The HCD
  130. */
  131. extern void dwc_otg_hcd_stop(dwc_otg_hcd_t * hcd);
  132. /**
  133. * suspend the DWC_otg host
  134. *
  135. * @param hcd The HCD
  136. */
  137. extern int dwc_otg_hcd_suspend(dwc_otg_hcd_t *hcd);
  138. /**
  139. * resume the DWC_otg host
  140. *
  141. * @param hcd The HCD
  142. */
  143. extern int dwc_otg_hcd_resume(dwc_otg_hcd_t *hcd);
  144. /**
  145. * Handles hub class-specific requests.
  146. *
  147. * @param dwc_otg_hcd The HCD
  148. * @param typeReq Request Type
  149. * @param wValue wValue from control request
  150. * @param wIndex wIndex from control request
  151. * @param buf data buffer
  152. * @param wLength data buffer length
  153. *
  154. * Returns -DWC_E_INVALID if invalid argument is passed
  155. * Returns 0 on success
  156. */
  157. extern int dwc_otg_hcd_hub_control(dwc_otg_hcd_t * dwc_otg_hcd,
  158. uint16_t typeReq, uint16_t wValue,
  159. uint16_t wIndex, uint8_t * buf,
  160. uint16_t wLength);
  161. /**
  162. * Returns otg port number.
  163. *
  164. * @param hcd The HCD
  165. */
  166. extern uint32_t dwc_otg_hcd_otg_port(dwc_otg_hcd_t * hcd);
  167. /**
  168. * Returns OTG version - either 1.3 or 2.0.
  169. *
  170. * @param core_if The core_if structure pointer
  171. */
  172. extern uint16_t dwc_otg_get_otg_version(dwc_otg_core_if_t * core_if);
  173. /**
  174. * Returns 1 if currently core is acting as B host, and 0 otherwise.
  175. *
  176. * @param hcd The HCD
  177. */
  178. extern uint32_t dwc_otg_hcd_is_b_host(dwc_otg_hcd_t * hcd);
  179. /**
  180. * Returns current frame number.
  181. *
  182. * @param hcd The HCD
  183. */
  184. extern int dwc_otg_hcd_get_frame_number(dwc_otg_hcd_t * hcd);
  185. /**
  186. * Dumps hcd state.
  187. *
  188. * @param hcd The HCD
  189. */
  190. extern void dwc_otg_hcd_dump_state(dwc_otg_hcd_t * hcd);
  191. /**
  192. * Dump the average frame remaining at SOF. This can be used to
  193. * determine average interrupt latency. Frame remaining is also shown for
  194. * start transfer and two additional sample points.
  195. * Currently this function is not implemented.
  196. *
  197. * @param hcd The HCD
  198. */
  199. extern void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t * hcd);
  200. /**
  201. * Sends LPM transaction to the local device.
  202. *
  203. * @param hcd The HCD
  204. * @param devaddr Device Address
  205. * @param hird Host initiated resume duration
  206. * @param bRemoteWake Value of bRemoteWake field in LPM transaction
  207. *
  208. * Returns negative value if sending LPM transaction was not succeeded.
  209. * Returns 0 on success.
  210. */
  211. extern int dwc_otg_hcd_send_lpm(dwc_otg_hcd_t * hcd, uint8_t devaddr,
  212. uint8_t hird, uint8_t bRemoteWake);
  213. /* URB interface */
  214. /**
  215. * Allocates memory for dwc_otg_hcd_urb structure.
  216. * Allocated memory should be freed by call of DWC_FREE.
  217. *
  218. * @param hcd The HCD
  219. * @param iso_desc_count Count of ISOC descriptors
  220. * @param atomic_alloc Specefies whether to perform atomic allocation.
  221. */
  222. extern dwc_otg_hcd_urb_t *dwc_otg_hcd_urb_alloc(dwc_otg_hcd_t * hcd,
  223. int iso_desc_count,
  224. int atomic_alloc);
  225. /**
  226. * Set pipe information in URB.
  227. *
  228. * @param hcd_urb DWC_OTG URB
  229. * @param devaddr Device Address
  230. * @param ep_num Endpoint Number
  231. * @param ep_type Endpoint Type
  232. * @param ep_dir Endpoint Direction
  233. * @param mps Max Packet Size
  234. */
  235. extern void dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_hcd_urb_t * hcd_urb,
  236. uint8_t devaddr, uint8_t ep_num,
  237. uint8_t ep_type, uint8_t ep_dir,
  238. uint16_t mps);
  239. /* Transfer flags */
  240. #define URB_GIVEBACK_ASAP 0x1
  241. #define URB_SEND_ZERO_PACKET 0x2
  242. /**
  243. * Sets dwc_otg_hcd_urb parameters.
  244. *
  245. * @param urb DWC_OTG URB allocated by dwc_otg_hcd_urb_alloc function.
  246. * @param urb_handle Unique handle for request, this will be passed back
  247. * to function driver in completion callback.
  248. * @param buf The buffer for the data
  249. * @param dma The DMA buffer for the data
  250. * @param buflen Transfer length
  251. * @param sp Buffer for setup data
  252. * @param sp_dma DMA address of setup data buffer
  253. * @param flags Transfer flags
  254. * @param interval Polling interval for interrupt or isochronous transfers.
  255. */
  256. extern void dwc_otg_hcd_urb_set_params(dwc_otg_hcd_urb_t * urb,
  257. void *urb_handle, void *buf,
  258. dwc_dma_t dma, uint32_t buflen, void *sp,
  259. dwc_dma_t sp_dma, uint32_t flags,
  260. uint16_t interval);
  261. /** Gets status from dwc_otg_hcd_urb
  262. *
  263. * @param dwc_otg_urb DWC_OTG URB
  264. */
  265. extern uint32_t dwc_otg_hcd_urb_get_status(dwc_otg_hcd_urb_t * dwc_otg_urb);
  266. /** Gets actual length from dwc_otg_hcd_urb
  267. *
  268. * @param dwc_otg_urb DWC_OTG URB
  269. */
  270. extern uint32_t dwc_otg_hcd_urb_get_actual_length(dwc_otg_hcd_urb_t *
  271. dwc_otg_urb);
  272. /** Gets error count from dwc_otg_hcd_urb. Only for ISOC URBs
  273. *
  274. * @param dwc_otg_urb DWC_OTG URB
  275. */
  276. extern uint32_t dwc_otg_hcd_urb_get_error_count(dwc_otg_hcd_urb_t *
  277. dwc_otg_urb);
  278. /** Set ISOC descriptor offset and length
  279. *
  280. * @param dwc_otg_urb DWC_OTG URB
  281. * @param desc_num ISOC descriptor number
  282. * @param offset Offset from beginig of buffer.
  283. * @param length Transaction length
  284. */
  285. extern void dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  286. int desc_num, uint32_t offset,
  287. uint32_t length);
  288. /** Get status of ISOC descriptor, specified by desc_num
  289. *
  290. * @param dwc_otg_urb DWC_OTG URB
  291. * @param desc_num ISOC descriptor number
  292. */
  293. extern uint32_t dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_hcd_urb_t *
  294. dwc_otg_urb, int desc_num);
  295. /** Get actual length of ISOC descriptor, specified by desc_num
  296. *
  297. * @param dwc_otg_urb DWC_OTG URB
  298. * @param desc_num ISOC descriptor number
  299. */
  300. extern uint32_t dwc_otg_hcd_urb_get_iso_desc_actual_length(dwc_otg_hcd_urb_t *
  301. dwc_otg_urb,
  302. int desc_num);
  303. /** Queue URB. After transfer is completes, the complete callback will be called with the URB status
  304. *
  305. * @param dwc_otg_hcd The HCD
  306. * @param dwc_otg_urb DWC_OTG URB
  307. * @param ep_handle Out parameter for returning endpoint handle
  308. * @param atomic_alloc Flag to do atomic allocation if needed
  309. *
  310. * Returns -DWC_E_NO_DEVICE if no device is connected.
  311. * Returns -DWC_E_NO_MEMORY if there is no enough memory.
  312. * Returns 0 on success.
  313. */
  314. extern int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * dwc_otg_hcd,
  315. dwc_otg_hcd_urb_t * dwc_otg_urb,
  316. void **ep_handle, int atomic_alloc);
  317. /** De-queue the specified URB
  318. *
  319. * @param dwc_otg_hcd The HCD
  320. * @param dwc_otg_urb DWC_OTG URB
  321. */
  322. extern int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_t * dwc_otg_hcd,
  323. dwc_otg_hcd_urb_t * dwc_otg_urb);
  324. /** Frees resources in the DWC_otg controller related to a given endpoint.
  325. * Any URBs for the endpoint must already be dequeued.
  326. *
  327. * @param hcd The HCD
  328. * @param ep_handle Endpoint handle, returned by dwc_otg_hcd_urb_enqueue function
  329. * @param retry Number of retries if there are queued transfers.
  330. *
  331. * Returns -DWC_E_INVALID if invalid arguments are passed.
  332. * Returns 0 on success
  333. */
  334. extern int dwc_otg_hcd_endpoint_disable(dwc_otg_hcd_t * hcd, void *ep_handle,
  335. int retry);
  336. /* Resets the data toggle in qh structure. This function can be called from
  337. * usb_clear_halt routine.
  338. *
  339. * @param hcd The HCD
  340. * @param ep_handle Endpoint handle, returned by dwc_otg_hcd_urb_enqueue function
  341. *
  342. * Returns -DWC_E_INVALID if invalid arguments are passed.
  343. * Returns 0 on success
  344. */
  345. extern int dwc_otg_hcd_endpoint_reset(dwc_otg_hcd_t * hcd, void *ep_handle);
  346. /** Returns 1 if status of specified port is changed and 0 otherwise.
  347. *
  348. * @param hcd The HCD
  349. * @param port Port number
  350. */
  351. extern int dwc_otg_hcd_is_status_changed(dwc_otg_hcd_t * hcd, int port);
  352. /** Call this function to check if bandwidth was allocated for specified endpoint.
  353. * Only for ISOC and INTERRUPT endpoints.
  354. *
  355. * @param hcd The HCD
  356. * @param ep_handle Endpoint handle
  357. */
  358. extern int dwc_otg_hcd_is_bandwidth_allocated(dwc_otg_hcd_t * hcd,
  359. void *ep_handle);
  360. /** Call this function to check if bandwidth was freed for specified endpoint.
  361. *
  362. * @param hcd The HCD
  363. * @param ep_handle Endpoint handle
  364. */
  365. extern int dwc_otg_hcd_is_bandwidth_freed(dwc_otg_hcd_t * hcd, void *ep_handle);
  366. /** Returns bandwidth allocated for specified endpoint in microseconds.
  367. * Only for ISOC and INTERRUPT endpoints.
  368. *
  369. * @param hcd The HCD
  370. * @param ep_handle Endpoint handle
  371. */
  372. extern uint8_t dwc_otg_hcd_get_ep_bandwidth(dwc_otg_hcd_t * hcd,
  373. void *ep_handle);
  374. /** @} */
  375. #endif /* __DWC_HCD_IF_H__ */
  376. #endif /* DWC_DEVICE_ONLY */