musb_gadget.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * MUSB OTG driver peripheral defines
  4. *
  5. * Copyright 2005 Mentor Graphics Corporation
  6. * Copyright (C) 2005-2006 by Texas Instruments
  7. * Copyright (C) 2006-2007 Nokia Corporation
  8. */
  9. #ifndef __MUSB_GADGET_H
  10. #define __MUSB_GADGET_H
  11. #include <linux/list.h>
  12. #if IS_ENABLED(CONFIG_USB_MUSB_GADGET) || IS_ENABLED(CONFIG_USB_MUSB_DUAL_ROLE)
  13. extern irqreturn_t musb_g_ep0_irq(struct musb *);
  14. extern void musb_g_tx(struct musb *, u8);
  15. extern void musb_g_rx(struct musb *, u8);
  16. extern void musb_g_reset(struct musb *);
  17. extern void musb_g_suspend(struct musb *);
  18. extern void musb_g_resume(struct musb *);
  19. extern void musb_g_wakeup(struct musb *);
  20. extern void musb_g_disconnect(struct musb *);
  21. extern void musb_gadget_cleanup(struct musb *);
  22. extern int musb_gadget_setup(struct musb *);
  23. #else
  24. static inline irqreturn_t musb_g_ep0_irq(struct musb *musb)
  25. {
  26. return 0;
  27. }
  28. static inline void musb_g_tx(struct musb *musb, u8 epnum) {}
  29. static inline void musb_g_rx(struct musb *musb, u8 epnum) {}
  30. static inline void musb_g_reset(struct musb *musb) {}
  31. static inline void musb_g_suspend(struct musb *musb) {}
  32. static inline void musb_g_resume(struct musb *musb) {}
  33. static inline void musb_g_wakeup(struct musb *musb) {}
  34. static inline void musb_g_disconnect(struct musb *musb) {}
  35. static inline void musb_gadget_cleanup(struct musb *musb) {}
  36. static inline int musb_gadget_setup(struct musb *musb)
  37. {
  38. return 0;
  39. }
  40. #endif
  41. enum buffer_map_state {
  42. UN_MAPPED = 0,
  43. PRE_MAPPED,
  44. MUSB_MAPPED
  45. };
  46. struct musb_request {
  47. struct usb_request request;
  48. struct list_head list;
  49. struct musb_ep *ep;
  50. struct musb *musb;
  51. u8 tx; /* endpoint direction */
  52. u8 epnum;
  53. enum buffer_map_state map_state;
  54. };
  55. #define to_musb_request(r) container_of((r), struct musb_request, request)
  56. extern struct usb_request *
  57. musb_alloc_request(struct usb_ep *ep, gfp_t gfp_flags);
  58. extern void musb_free_request(struct usb_ep *ep, struct usb_request *req);
  59. /*
  60. * struct musb_ep - peripheral side view of endpoint rx or tx side
  61. */
  62. struct musb_ep {
  63. /* stuff towards the head is basically write-once. */
  64. struct usb_ep end_point;
  65. char name[12];
  66. struct musb_hw_ep *hw_ep;
  67. struct musb *musb;
  68. u8 current_epnum;
  69. /* ... when enabled/disabled ... */
  70. u8 type;
  71. u8 is_in;
  72. u16 packet_sz;
  73. const struct usb_endpoint_descriptor *desc;
  74. struct dma_channel *dma;
  75. /* later things are modified based on usage */
  76. struct list_head req_list;
  77. u8 wedged;
  78. /* true if lock must be dropped but req_list may not be advanced */
  79. u8 busy;
  80. u8 hb_mult;
  81. };
  82. #define to_musb_ep(ep) container_of((ep), struct musb_ep, end_point)
  83. static inline struct musb_request *next_request(struct musb_ep *ep)
  84. {
  85. struct list_head *queue = &ep->req_list;
  86. if (list_empty(queue))
  87. return NULL;
  88. return container_of(queue->next, struct musb_request, list);
  89. }
  90. extern const struct usb_ep_ops musb_g_ep0_ops;
  91. extern void musb_g_giveback(struct musb_ep *, struct usb_request *, int);
  92. extern void musb_ep_restart(struct musb *, struct musb_request *);
  93. #endif /* __MUSB_GADGET_H */