musb_gadget.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * MUSB OTG driver peripheral defines
  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_GADGET_H
  35. #define __MUSB_GADGET_H
  36. #include <linux/list.h>
  37. #if IS_ENABLED(CONFIG_USB_MUSB_GADGET) || IS_ENABLED(CONFIG_USB_MUSB_DUAL_ROLE)
  38. extern irqreturn_t musb_g_ep0_irq(struct musb *);
  39. extern void musb_g_tx(struct musb *, u8);
  40. extern void musb_g_rx(struct musb *, u8);
  41. extern void musb_g_reset(struct musb *);
  42. extern void musb_g_suspend(struct musb *);
  43. extern void musb_g_resume(struct musb *);
  44. extern void musb_g_wakeup(struct musb *);
  45. extern void musb_g_disconnect(struct musb *);
  46. extern void musb_gadget_cleanup(struct musb *);
  47. extern int musb_gadget_setup(struct musb *);
  48. #else
  49. static inline irqreturn_t musb_g_ep0_irq(struct musb *musb)
  50. {
  51. return 0;
  52. }
  53. static inline void musb_g_tx(struct musb *musb, u8 epnum) {}
  54. static inline void musb_g_rx(struct musb *musb, u8 epnum) {}
  55. static inline void musb_g_reset(struct musb *musb) {}
  56. static inline void musb_g_suspend(struct musb *musb) {}
  57. static inline void musb_g_resume(struct musb *musb) {}
  58. static inline void musb_g_wakeup(struct musb *musb) {}
  59. static inline void musb_g_disconnect(struct musb *musb) {}
  60. static inline void musb_gadget_cleanup(struct musb *musb) {}
  61. static inline int musb_gadget_setup(struct musb *musb)
  62. {
  63. return 0;
  64. }
  65. #endif
  66. enum buffer_map_state {
  67. UN_MAPPED = 0,
  68. PRE_MAPPED,
  69. MUSB_MAPPED
  70. };
  71. struct musb_request {
  72. struct usb_request request;
  73. struct list_head list;
  74. struct musb_ep *ep;
  75. struct musb *musb;
  76. u8 tx; /* endpoint direction */
  77. u8 epnum;
  78. enum buffer_map_state map_state;
  79. };
  80. static inline struct musb_request *to_musb_request(struct usb_request *req)
  81. {
  82. return req ? container_of(req, struct musb_request, request) : NULL;
  83. }
  84. extern struct usb_request *
  85. musb_alloc_request(struct usb_ep *ep, gfp_t gfp_flags);
  86. extern void musb_free_request(struct usb_ep *ep, struct usb_request *req);
  87. /*
  88. * struct musb_ep - peripheral side view of endpoint rx or tx side
  89. */
  90. struct musb_ep {
  91. /* stuff towards the head is basically write-once. */
  92. struct usb_ep end_point;
  93. char name[12];
  94. struct musb_hw_ep *hw_ep;
  95. struct musb *musb;
  96. u8 current_epnum;
  97. /* ... when enabled/disabled ... */
  98. u8 type;
  99. u8 is_in;
  100. u16 packet_sz;
  101. const struct usb_endpoint_descriptor *desc;
  102. struct dma_channel *dma;
  103. /* later things are modified based on usage */
  104. struct list_head req_list;
  105. u8 wedged;
  106. /* true if lock must be dropped but req_list may not be advanced */
  107. u8 busy;
  108. u8 hb_mult;
  109. };
  110. static inline struct musb_ep *to_musb_ep(struct usb_ep *ep)
  111. {
  112. return ep ? container_of(ep, struct musb_ep, end_point) : NULL;
  113. }
  114. static inline struct musb_request *next_request(struct musb_ep *ep)
  115. {
  116. struct list_head *queue = &ep->req_list;
  117. if (list_empty(queue))
  118. return NULL;
  119. return container_of(queue->next, struct musb_request, list);
  120. }
  121. extern const struct usb_ep_ops musb_g_ep0_ops;
  122. extern void musb_g_giveback(struct musb_ep *, struct usb_request *, int);
  123. extern void musb_ep_restart(struct musb *, struct musb_request *);
  124. #endif /* __MUSB_GADGET_H */