gadget.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /**
  3. * gadget.h - DesignWare USB3 DRD Gadget Header
  4. *
  5. * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
  6. *
  7. * Authors: Felipe Balbi <balbi@ti.com>,
  8. * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  9. *
  10. * Taken from Linux Kernel v3.19-rc1 (drivers/usb/dwc3/gadget.h) and ported
  11. * to uboot.
  12. *
  13. * commit 7a60855972 : usb: dwc3: gadget: fix set_halt() bug with pending
  14. transfers
  15. *
  16. */
  17. #ifndef __DRIVERS_USB_DWC3_GADGET_H
  18. #define __DRIVERS_USB_DWC3_GADGET_H
  19. #include <linux/list.h>
  20. #include <linux/usb/gadget.h>
  21. #include "io.h"
  22. struct dwc3;
  23. #define to_dwc3_ep(ep) (container_of(ep, struct dwc3_ep, endpoint))
  24. #define gadget_to_dwc(g) (container_of(g, struct dwc3, gadget))
  25. /* DEPCFG parameter 1 */
  26. #define DWC3_DEPCFG_INT_NUM(n) ((n) << 0)
  27. #define DWC3_DEPCFG_XFER_COMPLETE_EN (1 << 8)
  28. #define DWC3_DEPCFG_XFER_IN_PROGRESS_EN (1 << 9)
  29. #define DWC3_DEPCFG_XFER_NOT_READY_EN (1 << 10)
  30. #define DWC3_DEPCFG_FIFO_ERROR_EN (1 << 11)
  31. #define DWC3_DEPCFG_STREAM_EVENT_EN (1 << 13)
  32. #define DWC3_DEPCFG_BINTERVAL_M1(n) ((n) << 16)
  33. #define DWC3_DEPCFG_STREAM_CAPABLE (1 << 24)
  34. #define DWC3_DEPCFG_EP_NUMBER(n) ((n) << 25)
  35. #define DWC3_DEPCFG_BULK_BASED (1 << 30)
  36. #define DWC3_DEPCFG_FIFO_BASED (1 << 31)
  37. /* DEPCFG parameter 0 */
  38. #define DWC3_DEPCFG_EP_TYPE(n) ((n) << 1)
  39. #define DWC3_DEPCFG_MAX_PACKET_SIZE(n) ((n) << 3)
  40. #define DWC3_DEPCFG_FIFO_NUMBER(n) ((n) << 17)
  41. #define DWC3_DEPCFG_BURST_SIZE(n) ((n) << 22)
  42. #define DWC3_DEPCFG_DATA_SEQ_NUM(n) ((n) << 26)
  43. /* This applies for core versions earlier than 1.94a */
  44. #define DWC3_DEPCFG_IGN_SEQ_NUM (1 << 31)
  45. /* These apply for core versions 1.94a and later */
  46. #define DWC3_DEPCFG_ACTION_INIT (0 << 30)
  47. #define DWC3_DEPCFG_ACTION_RESTORE (1 << 30)
  48. #define DWC3_DEPCFG_ACTION_MODIFY (2 << 30)
  49. /* DEPXFERCFG parameter 0 */
  50. #define DWC3_DEPXFERCFG_NUM_XFER_RES(n) ((n) & 0xffff)
  51. /* -------------------------------------------------------------------------- */
  52. #define to_dwc3_request(r) (container_of(r, struct dwc3_request, request))
  53. static inline struct dwc3_request *next_request(struct list_head *list)
  54. {
  55. if (list_empty(list))
  56. return NULL;
  57. return list_first_entry(list, struct dwc3_request, list);
  58. }
  59. static inline void dwc3_gadget_move_request_queued(struct dwc3_request *req)
  60. {
  61. struct dwc3_ep *dep = req->dep;
  62. req->queued = true;
  63. list_move_tail(&req->list, &dep->req_queued);
  64. }
  65. void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
  66. int status);
  67. void dwc3_ep0_interrupt(struct dwc3 *dwc,
  68. const struct dwc3_event_depevt *event);
  69. void dwc3_ep0_out_start(struct dwc3 *dwc);
  70. int __dwc3_gadget_ep0_set_halt(struct usb_ep *ep, int value);
  71. int dwc3_gadget_ep0_set_halt(struct usb_ep *ep, int value);
  72. int dwc3_gadget_ep0_queue(struct usb_ep *ep, struct usb_request *request,
  73. gfp_t gfp_flags);
  74. int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value, int protocol);
  75. void dwc3_gadget_uboot_handle_interrupt(struct dwc3 *dwc);
  76. /**
  77. * dwc3_gadget_ep_get_transfer_index - Gets transfer index from HW
  78. * @dwc: DesignWare USB3 Pointer
  79. * @number: DWC endpoint number
  80. *
  81. * Caller should take care of locking
  82. */
  83. static inline u32 dwc3_gadget_ep_get_transfer_index(struct dwc3 *dwc, u8 number)
  84. {
  85. u32 res_id;
  86. res_id = dwc3_readl(dwc->regs, DWC3_DEPCMD(number));
  87. return DWC3_DEPCMD_GET_RSC_IDX(res_id);
  88. }
  89. #endif /* __DRIVERS_USB_DWC3_GADGET_H */