gr_udc.h 5.6 KB

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