langwell_udc.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * Intel Langwell USB Device Controller driver
  3. * Copyright (C) 2008-2009, Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. */
  9. #include <linux/usb/langwell_udc.h>
  10. #include <linux/usb/langwell_otg.h>
  11. /*-------------------------------------------------------------------------*/
  12. /* driver data structures and utilities */
  13. /*
  14. * dTD: Device Endpoint Transfer Descriptor
  15. * describe to the device controller the location and quantity of
  16. * data to be send/received for given transfer
  17. */
  18. struct langwell_dtd {
  19. u32 dtd_next;
  20. /* bits 31:5, next transfer element pointer */
  21. #define DTD_NEXT(d) (((d)>>5)&0x7ffffff)
  22. #define DTD_NEXT_MASK (0x7ffffff << 5)
  23. /* terminate */
  24. #define DTD_TERM BIT(0)
  25. /* bits 7:0, execution back states */
  26. u32 dtd_status:8;
  27. #define DTD_STATUS(d) (((d)>>0)&0xff)
  28. #define DTD_STS_ACTIVE BIT(7) /* active */
  29. #define DTD_STS_HALTED BIT(6) /* halted */
  30. #define DTD_STS_DBE BIT(5) /* data buffer error */
  31. #define DTD_STS_TRE BIT(3) /* transaction error */
  32. /* bits 9:8 */
  33. u32 dtd_res0:2;
  34. /* bits 11:10, multipier override */
  35. u32 dtd_multo:2;
  36. #define DTD_MULTO (BIT(11) | BIT(10))
  37. /* bits 14:12 */
  38. u32 dtd_res1:3;
  39. /* bit 15, interrupt on complete */
  40. u32 dtd_ioc:1;
  41. #define DTD_IOC BIT(15)
  42. /* bits 30:16, total bytes */
  43. u32 dtd_total:15;
  44. #define DTD_TOTAL(d) (((d)>>16)&0x7fff)
  45. #define DTD_MAX_TRANSFER_LENGTH 0x4000
  46. /* bit 31 */
  47. u32 dtd_res2:1;
  48. /* dTD buffer pointer page 0 to 4 */
  49. u32 dtd_buf[5];
  50. #define DTD_OFFSET_MASK 0xfff
  51. /* bits 31:12, buffer pointer */
  52. #define DTD_BUFFER(d) (((d)>>12)&0x3ff)
  53. /* bits 11:0, current offset */
  54. #define DTD_C_OFFSET(d) (((d)>>0)&0xfff)
  55. /* bits 10:0, frame number */
  56. #define DTD_FRAME(d) (((d)>>0)&0x7ff)
  57. /* driver-private parts */
  58. /* dtd dma address */
  59. dma_addr_t dtd_dma;
  60. /* next dtd virtual address */
  61. struct langwell_dtd *next_dtd_virt;
  62. };
  63. /*
  64. * dQH: Device Endpoint Queue Head
  65. * describe where all transfers are managed
  66. * 48-byte data structure, aligned on 64-byte boundary
  67. *
  68. * These are associated with dTD structure
  69. */
  70. struct langwell_dqh {
  71. /* endpoint capabilities and characteristics */
  72. u32 dqh_res0:15; /* bits 14:0 */
  73. u32 dqh_ios:1; /* bit 15, interrupt on setup */
  74. #define DQH_IOS BIT(15)
  75. u32 dqh_mpl:11; /* bits 26:16, maximum packet length */
  76. #define DQH_MPL (0x7ff << 16)
  77. u32 dqh_res1:2; /* bits 28:27 */
  78. u32 dqh_zlt:1; /* bit 29, zero length termination */
  79. #define DQH_ZLT BIT(29)
  80. u32 dqh_mult:2; /* bits 31:30 */
  81. #define DQH_MULT (BIT(30) | BIT(31))
  82. /* current dTD pointer */
  83. u32 dqh_current; /* locate the transfer in progress */
  84. #define DQH_C_DTD(e) \
  85. (((e)>>5)&0x7ffffff) /* bits 31:5, current dTD pointer */
  86. /* transfer overlay, hardware parts of a struct langwell_dtd */
  87. u32 dtd_next;
  88. u32 dtd_status:8; /* bits 7:0, execution back states */
  89. u32 dtd_res0:2; /* bits 9:8 */
  90. u32 dtd_multo:2; /* bits 11:10, multipier override */
  91. u32 dtd_res1:3; /* bits 14:12 */
  92. u32 dtd_ioc:1; /* bit 15, interrupt on complete */
  93. u32 dtd_total:15; /* bits 30:16, total bytes */
  94. u32 dtd_res2:1; /* bit 31 */
  95. u32 dtd_buf[5]; /* dTD buffer pointer page 0 to 4 */
  96. u32 dqh_res2;
  97. struct usb_ctrlrequest dqh_setup; /* setup packet buffer */
  98. } __attribute__ ((aligned(64)));
  99. /* endpoint data structure */
  100. struct langwell_ep {
  101. struct usb_ep ep;
  102. dma_addr_t dma;
  103. struct langwell_udc *dev;
  104. unsigned long irqs;
  105. struct list_head queue;
  106. struct langwell_dqh *dqh;
  107. const struct usb_endpoint_descriptor *desc;
  108. char name[14];
  109. unsigned stopped:1,
  110. ep_type:2,
  111. ep_num:8;
  112. };
  113. /* request data structure */
  114. struct langwell_request {
  115. struct usb_request req;
  116. struct langwell_dtd *dtd, *head, *tail;
  117. struct langwell_ep *ep;
  118. dma_addr_t dtd_dma;
  119. struct list_head queue;
  120. unsigned dtd_count;
  121. unsigned mapped:1;
  122. };
  123. /* ep0 transfer state */
  124. enum ep0_state {
  125. WAIT_FOR_SETUP,
  126. DATA_STATE_XMIT,
  127. DATA_STATE_NEED_ZLP,
  128. WAIT_FOR_OUT_STATUS,
  129. DATA_STATE_RECV,
  130. };
  131. /* device suspend state */
  132. enum lpm_state {
  133. LPM_L0, /* on */
  134. LPM_L1, /* LPM L1 sleep */
  135. LPM_L2, /* suspend */
  136. LPM_L3, /* off */
  137. };
  138. /* device data structure */
  139. struct langwell_udc {
  140. /* each pci device provides one gadget, several endpoints */
  141. struct usb_gadget gadget;
  142. spinlock_t lock; /* device lock */
  143. struct langwell_ep *ep;
  144. struct usb_gadget_driver *driver;
  145. struct otg_transceiver *transceiver;
  146. u8 dev_addr;
  147. u32 usb_state;
  148. u32 resume_state;
  149. u32 bus_reset;
  150. enum lpm_state lpm_state;
  151. enum ep0_state ep0_state;
  152. u32 ep0_dir;
  153. u16 dciversion;
  154. unsigned ep_max;
  155. unsigned devcap:1,
  156. enabled:1,
  157. region:1,
  158. got_irq:1,
  159. powered:1,
  160. remote_wakeup:1,
  161. rate:1,
  162. is_reset:1,
  163. softconnected:1,
  164. vbus_active:1,
  165. suspended:1,
  166. stopped:1,
  167. lpm:1, /* LPM capability */
  168. has_sram:1, /* SRAM caching */
  169. got_sram:1;
  170. /* pci state used to access those endpoints */
  171. struct pci_dev *pdev;
  172. /* Langwell otg transceiver */
  173. struct langwell_otg *lotg;
  174. /* control registers */
  175. struct langwell_cap_regs __iomem *cap_regs;
  176. struct langwell_op_regs __iomem *op_regs;
  177. struct usb_ctrlrequest local_setup_buff;
  178. struct langwell_dqh *ep_dqh;
  179. size_t ep_dqh_size;
  180. dma_addr_t ep_dqh_dma;
  181. /* ep0 status request */
  182. struct langwell_request *status_req;
  183. /* dma pool */
  184. struct dma_pool *dtd_pool;
  185. /* make sure release() is done */
  186. struct completion *done;
  187. /* for private SRAM caching */
  188. unsigned int sram_addr;
  189. unsigned int sram_size;
  190. /* device status data for get_status request */
  191. u16 dev_status;
  192. };
  193. #define gadget_to_langwell(g) container_of((g), struct langwell_udc, gadget)