musb_dma.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. * MUSB OTG driver DMA controller abstraction
  3. *
  4. * Copyright 2005 Mentor Graphics Corporation
  5. * Copyright (C) 2005-2006 by Texas Instruments
  6. * Copyright (C) 2006-2007 Nokia Corporation
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  23. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  24. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  25. * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  27. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  28. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  29. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  31. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. */
  34. #ifndef __MUSB_DMA_H__
  35. #define __MUSB_DMA_H__
  36. struct musb_hw_ep;
  37. /*
  38. * DMA Controller Abstraction
  39. *
  40. * DMA Controllers are abstracted to allow use of a variety of different
  41. * implementations of DMA, as allowed by the Inventra USB cores. On the
  42. * host side, usbcore sets up the DMA mappings and flushes caches; on the
  43. * peripheral side, the gadget controller driver does. Responsibilities
  44. * of a DMA controller driver include:
  45. *
  46. * - Handling the details of moving multiple USB packets
  47. * in cooperation with the Inventra USB core, including especially
  48. * the correct RX side treatment of short packets and buffer-full
  49. * states (both of which terminate transfers).
  50. *
  51. * - Knowing the correlation between dma channels and the
  52. * Inventra core's local endpoint resources and data direction.
  53. *
  54. * - Maintaining a list of allocated/available channels.
  55. *
  56. * - Updating channel status on interrupts,
  57. * whether shared with the Inventra core or separate.
  58. */
  59. #define DMA_ADDR_INVALID (~(dma_addr_t)0)
  60. #ifdef CONFIG_MUSB_PIO_ONLY
  61. #define is_dma_capable() (0)
  62. #else
  63. #define is_dma_capable() (1)
  64. #endif
  65. #ifdef CONFIG_USB_UX500_DMA
  66. #define musb_dma_ux500(musb) (musb->io.quirks & MUSB_DMA_UX500)
  67. #else
  68. #define musb_dma_ux500(musb) 0
  69. #endif
  70. #ifdef CONFIG_USB_TI_CPPI41_DMA
  71. #define musb_dma_cppi41(musb) (musb->io.quirks & MUSB_DMA_CPPI41)
  72. #else
  73. #define musb_dma_cppi41(musb) 0
  74. #endif
  75. #ifdef CONFIG_USB_TI_CPPI_DMA
  76. #define musb_dma_cppi(musb) (musb->io.quirks & MUSB_DMA_CPPI)
  77. #else
  78. #define musb_dma_cppi(musb) 0
  79. #endif
  80. #ifdef CONFIG_USB_TUSB_OMAP_DMA
  81. #define tusb_dma_omap(musb) (musb->io.quirks & MUSB_DMA_TUSB_OMAP)
  82. #else
  83. #define tusb_dma_omap(musb) 0
  84. #endif
  85. #ifdef CONFIG_USB_INVENTRA_DMA
  86. #define musb_dma_inventra(musb) (musb->io.quirks & MUSB_DMA_INVENTRA)
  87. #else
  88. #define musb_dma_inventra(musb) 0
  89. #endif
  90. #if defined(CONFIG_USB_TI_CPPI_DMA) || defined(CONFIG_USB_TI_CPPI41_DMA)
  91. #define is_cppi_enabled(musb) \
  92. (musb_dma_cppi(musb) || musb_dma_cppi41(musb))
  93. #else
  94. #define is_cppi_enabled(musb) 0
  95. #endif
  96. /* Anomaly 05000456 - USB Receive Interrupt Is Not Generated in DMA Mode 1
  97. * Only allow DMA mode 1 to be used when the USB will actually generate the
  98. * interrupts we expect.
  99. */
  100. #ifdef CONFIG_BLACKFIN
  101. # undef USE_MODE1
  102. # if !ANOMALY_05000456
  103. # define USE_MODE1
  104. # endif
  105. #endif
  106. /*
  107. * DMA channel status ... updated by the dma controller driver whenever that
  108. * status changes, and protected by the overall controller spinlock.
  109. */
  110. enum dma_channel_status {
  111. /* unallocated */
  112. MUSB_DMA_STATUS_UNKNOWN,
  113. /* allocated ... but not busy, no errors */
  114. MUSB_DMA_STATUS_FREE,
  115. /* busy ... transactions are active */
  116. MUSB_DMA_STATUS_BUSY,
  117. /* transaction(s) aborted due to ... dma or memory bus error */
  118. MUSB_DMA_STATUS_BUS_ABORT,
  119. /* transaction(s) aborted due to ... core error or USB fault */
  120. MUSB_DMA_STATUS_CORE_ABORT
  121. };
  122. struct dma_controller;
  123. /**
  124. * struct dma_channel - A DMA channel.
  125. * @private_data: channel-private data
  126. * @max_len: the maximum number of bytes the channel can move in one
  127. * transaction (typically representing many USB maximum-sized packets)
  128. * @actual_len: how many bytes have been transferred
  129. * @status: current channel status (updated e.g. on interrupt)
  130. * @desired_mode: true if mode 1 is desired; false if mode 0 is desired
  131. *
  132. * channels are associated with an endpoint for the duration of at least
  133. * one usb transfer.
  134. */
  135. struct dma_channel {
  136. void *private_data;
  137. /* FIXME not void* private_data, but a dma_controller * */
  138. size_t max_len;
  139. size_t actual_len;
  140. enum dma_channel_status status;
  141. bool desired_mode;
  142. bool rx_packet_done;
  143. };
  144. /*
  145. * dma_channel_status - return status of dma channel
  146. * @c: the channel
  147. *
  148. * Returns the software's view of the channel status. If that status is BUSY
  149. * then it's possible that the hardware has completed (or aborted) a transfer,
  150. * so the driver needs to update that status.
  151. */
  152. static inline enum dma_channel_status
  153. dma_channel_status(struct dma_channel *c)
  154. {
  155. return (is_dma_capable() && c) ? c->status : MUSB_DMA_STATUS_UNKNOWN;
  156. }
  157. /**
  158. * struct dma_controller - A DMA Controller.
  159. * @start: call this to start a DMA controller;
  160. * return 0 on success, else negative errno
  161. * @stop: call this to stop a DMA controller
  162. * return 0 on success, else negative errno
  163. * @channel_alloc: call this to allocate a DMA channel
  164. * @channel_release: call this to release a DMA channel
  165. * @channel_abort: call this to abort a pending DMA transaction,
  166. * returning it to FREE (but allocated) state
  167. *
  168. * Controllers manage dma channels.
  169. */
  170. struct dma_controller {
  171. struct dma_channel *(*channel_alloc)(struct dma_controller *,
  172. struct musb_hw_ep *, u8 is_tx);
  173. void (*channel_release)(struct dma_channel *);
  174. int (*channel_program)(struct dma_channel *channel,
  175. u16 maxpacket, u8 mode,
  176. dma_addr_t dma_addr,
  177. u32 length);
  178. int (*channel_abort)(struct dma_channel *);
  179. int (*is_compatible)(struct dma_channel *channel,
  180. u16 maxpacket,
  181. void *buf, u32 length);
  182. };
  183. /* called after channel_program(), may indicate a fault */
  184. extern void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit);
  185. #ifdef CONFIG_MUSB_PIO_ONLY
  186. static inline struct dma_controller *
  187. musb_dma_controller_create(struct musb *m, void __iomem *io)
  188. {
  189. return NULL;
  190. }
  191. static inline void musb_dma_controller_destroy(struct dma_controller *d) { }
  192. #else
  193. extern struct dma_controller *
  194. (*musb_dma_controller_create)(struct musb *, void __iomem *);
  195. extern void (*musb_dma_controller_destroy)(struct dma_controller *);
  196. #endif
  197. /* Platform specific DMA functions */
  198. extern struct dma_controller *
  199. musbhs_dma_controller_create(struct musb *musb, void __iomem *base);
  200. extern void musbhs_dma_controller_destroy(struct dma_controller *c);
  201. extern struct dma_controller *
  202. tusb_dma_controller_create(struct musb *musb, void __iomem *base);
  203. extern void tusb_dma_controller_destroy(struct dma_controller *c);
  204. extern struct dma_controller *
  205. cppi_dma_controller_create(struct musb *musb, void __iomem *base);
  206. extern void cppi_dma_controller_destroy(struct dma_controller *c);
  207. extern struct dma_controller *
  208. cppi41_dma_controller_create(struct musb *musb, void __iomem *base);
  209. extern void cppi41_dma_controller_destroy(struct dma_controller *c);
  210. extern struct dma_controller *
  211. ux500_dma_controller_create(struct musb *musb, void __iomem *base);
  212. extern void ux500_dma_controller_destroy(struct dma_controller *c);
  213. #endif /* __MUSB_DMA_H__ */