gr_udc.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * USB Peripheral Controller driver for Aeroflex Gaisler GRUSBDC.
  4. *
  5. * 2013 (c) Aeroflex Gaisler AB
  6. *
  7. * This driver supports GRUSBDC USB Device Controller cores available in the
  8. * GRLIB VHDL IP core library.
  9. *
  10. * Full documentation of the GRUSBDC core can be found here:
  11. * http://www.gaisler.com/products/grlib/grip.pdf
  12. *
  13. * Contributors:
  14. * - Andreas Larsson <andreas@gaisler.com>
  15. * - Marko Isomaki
  16. */
  17. /* Control registers on the AMBA bus */
  18. #define GR_MAXEP 16 /* Max # endpoints for *each* direction */
  19. struct gr_epregs {
  20. u32 epctrl;
  21. union {
  22. struct { /* Slave mode*/
  23. u32 slvctrl;
  24. u32 slvdata;
  25. };
  26. struct { /* DMA mode*/
  27. u32 dmactrl;
  28. u32 dmaaddr;
  29. };
  30. };
  31. u32 epstat;
  32. };
  33. struct gr_regs {
  34. struct gr_epregs epo[GR_MAXEP]; /* 0x000 - 0x0fc */
  35. struct gr_epregs epi[GR_MAXEP]; /* 0x100 - 0x1fc */
  36. u32 control; /* 0x200 */
  37. u32 status; /* 0x204 */
  38. };
  39. #define GR_EPCTRL_BUFSZ_SCALER 8
  40. #define GR_EPCTRL_BUFSZ_MASK 0xffe00000
  41. #define GR_EPCTRL_BUFSZ_POS 21
  42. #define GR_EPCTRL_PI BIT(20)
  43. #define GR_EPCTRL_CB BIT(19)
  44. #define GR_EPCTRL_CS BIT(18)
  45. #define GR_EPCTRL_MAXPL_MASK 0x0003ff80
  46. #define GR_EPCTRL_MAXPL_POS 7
  47. #define GR_EPCTRL_NT_MASK 0x00000060
  48. #define GR_EPCTRL_NT_POS 5
  49. #define GR_EPCTRL_TT_MASK 0x00000018
  50. #define GR_EPCTRL_TT_POS 3
  51. #define GR_EPCTRL_EH BIT(2)
  52. #define GR_EPCTRL_ED BIT(1)
  53. #define GR_EPCTRL_EV BIT(0)
  54. #define GR_DMACTRL_AE BIT(10)
  55. #define GR_DMACTRL_AD BIT(3)
  56. #define GR_DMACTRL_AI BIT(2)
  57. #define GR_DMACTRL_IE BIT(1)
  58. #define GR_DMACTRL_DA BIT(0)
  59. #define GR_EPSTAT_PT BIT(29)
  60. #define GR_EPSTAT_PR BIT(29)
  61. #define GR_EPSTAT_B1CNT_MASK 0x1fff0000
  62. #define GR_EPSTAT_B1CNT_POS 16
  63. #define GR_EPSTAT_B0CNT_MASK 0x0000fff8
  64. #define GR_EPSTAT_B0CNT_POS 3
  65. #define GR_EPSTAT_B1 BIT(2)
  66. #define GR_EPSTAT_B0 BIT(1)
  67. #define GR_EPSTAT_BS BIT(0)
  68. #define GR_CONTROL_SI BIT(31)
  69. #define GR_CONTROL_UI BIT(30)
  70. #define GR_CONTROL_VI BIT(29)
  71. #define GR_CONTROL_SP BIT(28)
  72. #define GR_CONTROL_FI BIT(27)
  73. #define GR_CONTROL_EP BIT(14)
  74. #define GR_CONTROL_DH BIT(13)
  75. #define GR_CONTROL_RW BIT(12)
  76. #define GR_CONTROL_TS_MASK 0x00000e00
  77. #define GR_CONTROL_TS_POS 9
  78. #define GR_CONTROL_TM BIT(8)
  79. #define GR_CONTROL_UA_MASK 0x000000fe
  80. #define GR_CONTROL_UA_POS 1
  81. #define GR_CONTROL_SU BIT(0)
  82. #define GR_STATUS_NEPI_MASK 0xf0000000
  83. #define GR_STATUS_NEPI_POS 28
  84. #define GR_STATUS_NEPO_MASK 0x0f000000
  85. #define GR_STATUS_NEPO_POS 24
  86. #define GR_STATUS_DM BIT(23)
  87. #define GR_STATUS_SU BIT(17)
  88. #define GR_STATUS_UR BIT(16)
  89. #define GR_STATUS_VB BIT(15)
  90. #define GR_STATUS_SP BIT(14)
  91. #define GR_STATUS_AF_MASK 0x00003800
  92. #define GR_STATUS_AF_POS 11
  93. #define GR_STATUS_FN_MASK 0x000007ff
  94. #define GR_STATUS_FN_POS 0
  95. #define MAX_CTRL_PL_SIZE 64 /* As per USB standard for full and high speed */
  96. /*-------------------------------------------------------------------------*/
  97. /* Driver data structures and utilities */
  98. struct gr_dma_desc {
  99. u32 ctrl;
  100. u32 data;
  101. u32 next;
  102. /* These must be last because hw uses the previous three */
  103. u32 paddr;
  104. struct gr_dma_desc *next_desc;
  105. };
  106. #define GR_DESC_OUT_CTRL_SE BIT(17)
  107. #define GR_DESC_OUT_CTRL_IE BIT(15)
  108. #define GR_DESC_OUT_CTRL_NX BIT(14)
  109. #define GR_DESC_OUT_CTRL_EN BIT(13)
  110. #define GR_DESC_OUT_CTRL_LEN_MASK 0x00001fff
  111. #define GR_DESC_IN_CTRL_MO BIT(18)
  112. #define GR_DESC_IN_CTRL_PI BIT(17)
  113. #define GR_DESC_IN_CTRL_ML BIT(16)
  114. #define GR_DESC_IN_CTRL_IE BIT(15)
  115. #define GR_DESC_IN_CTRL_NX BIT(14)
  116. #define GR_DESC_IN_CTRL_EN BIT(13)
  117. #define GR_DESC_IN_CTRL_LEN_MASK 0x00001fff
  118. #define GR_DESC_DMAADDR_MASK 0xfffffffc
  119. struct gr_ep {
  120. struct usb_ep ep;
  121. struct gr_udc *dev;
  122. u16 bytes_per_buffer;
  123. unsigned int dma_start;
  124. struct gr_epregs __iomem *regs;
  125. unsigned num:8;
  126. unsigned is_in:1;
  127. unsigned stopped:1;
  128. unsigned wedged:1;
  129. unsigned callback:1;
  130. /* analogous to a host-side qh */
  131. struct list_head queue;
  132. struct list_head ep_list;
  133. /* Bounce buffer for end of "odd" sized OUT requests */
  134. void *tailbuf;
  135. dma_addr_t tailbuf_paddr;
  136. };
  137. struct gr_request {
  138. struct usb_request req;
  139. struct list_head queue;
  140. /* Chain of dma descriptors */
  141. struct gr_dma_desc *first_desc; /* First in the chain */
  142. struct gr_dma_desc *curr_desc; /* Current descriptor */
  143. struct gr_dma_desc *last_desc; /* Last in the chain */
  144. u16 evenlen; /* Size of even length head (if oddlen != 0) */
  145. u16 oddlen; /* Size of odd length tail if buffer length is "odd" */
  146. u8 setup; /* Setup packet */
  147. };
  148. enum gr_ep0state {
  149. GR_EP0_DISCONNECT = 0, /* No host */
  150. GR_EP0_SETUP, /* Between STATUS ack and SETUP report */
  151. GR_EP0_IDATA, /* IN data stage */
  152. GR_EP0_ODATA, /* OUT data stage */
  153. GR_EP0_ISTATUS, /* Status stage after IN data stage */
  154. GR_EP0_OSTATUS, /* Status stage after OUT data stage */
  155. GR_EP0_STALL, /* Data or status stages */
  156. GR_EP0_SUSPEND, /* USB suspend */
  157. };
  158. struct gr_udc {
  159. struct usb_gadget gadget;
  160. struct gr_ep epi[GR_MAXEP];
  161. struct gr_ep epo[GR_MAXEP];
  162. struct usb_gadget_driver *driver;
  163. struct dma_pool *desc_pool;
  164. struct device *dev;
  165. enum gr_ep0state ep0state;
  166. struct gr_request *ep0reqo;
  167. struct gr_request *ep0reqi;
  168. struct gr_regs __iomem *regs;
  169. int irq;
  170. int irqi;
  171. int irqo;
  172. unsigned added:1;
  173. unsigned irq_enabled:1;
  174. unsigned remote_wakeup:1;
  175. u8 test_mode;
  176. enum usb_device_state suspended_from;
  177. unsigned int nepi;
  178. unsigned int nepo;
  179. struct list_head ep_list;
  180. spinlock_t lock; /* General lock, a.k.a. "dev->lock" in comments */
  181. struct dentry *dfs_root;
  182. };
  183. #define to_gr_udc(gadget) (container_of((gadget), struct gr_udc, gadget))