musb_gadget.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #ifdef __UBOOT__
  13. #include <asm/byteorder.h>
  14. #include <linux/errno.h>
  15. #include <linux/usb/ch9.h>
  16. #include <linux/usb/gadget.h>
  17. #endif
  18. enum buffer_map_state {
  19. UN_MAPPED = 0,
  20. PRE_MAPPED,
  21. MUSB_MAPPED
  22. };
  23. struct musb_request {
  24. struct usb_request request;
  25. struct list_head list;
  26. struct musb_ep *ep;
  27. struct musb *musb;
  28. u8 tx; /* endpoint direction */
  29. u8 epnum;
  30. enum buffer_map_state map_state;
  31. };
  32. static inline struct musb_request *to_musb_request(struct usb_request *req)
  33. {
  34. return req ? container_of(req, struct musb_request, request) : NULL;
  35. }
  36. extern struct usb_request *
  37. musb_alloc_request(struct usb_ep *ep, gfp_t gfp_flags);
  38. extern void musb_free_request(struct usb_ep *ep, struct usb_request *req);
  39. /*
  40. * struct musb_ep - peripheral side view of endpoint rx or tx side
  41. */
  42. struct musb_ep {
  43. /* stuff towards the head is basically write-once. */
  44. struct usb_ep end_point;
  45. char name[12];
  46. struct musb_hw_ep *hw_ep;
  47. struct musb *musb;
  48. u8 current_epnum;
  49. /* ... when enabled/disabled ... */
  50. u8 type;
  51. u8 is_in;
  52. u16 packet_sz;
  53. const struct usb_endpoint_descriptor *desc;
  54. struct dma_channel *dma;
  55. /* later things are modified based on usage */
  56. struct list_head req_list;
  57. u8 wedged;
  58. /* true if lock must be dropped but req_list may not be advanced */
  59. u8 busy;
  60. u8 hb_mult;
  61. };
  62. static inline struct musb_ep *to_musb_ep(struct usb_ep *ep)
  63. {
  64. return ep ? container_of(ep, struct musb_ep, end_point) : NULL;
  65. }
  66. static inline struct musb_request *next_request(struct musb_ep *ep)
  67. {
  68. struct list_head *queue = &ep->req_list;
  69. if (list_empty(queue))
  70. return NULL;
  71. return container_of(queue->next, struct musb_request, list);
  72. }
  73. extern void musb_g_tx(struct musb *musb, u8 epnum);
  74. extern void musb_g_rx(struct musb *musb, u8 epnum);
  75. extern const struct usb_ep_ops musb_g_ep0_ops;
  76. extern int musb_gadget_setup(struct musb *);
  77. extern void musb_gadget_cleanup(struct musb *);
  78. extern void musb_g_giveback(struct musb_ep *, struct usb_request *, int);
  79. extern void musb_ep_restart(struct musb *, struct musb_request *);
  80. #ifdef __UBOOT__
  81. int musb_gadget_start(struct usb_gadget *g, struct usb_gadget_driver *driver);
  82. #endif
  83. #endif /* __MUSB_GADGET_H */