musb_gadget.h 2.4 KB

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