ehci.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*-
  2. * Copyright (c) 2007-2008, Juniper Networks, Inc.
  3. * Copyright (c) 2008, Michael Trimarchi <trimarchimichael@yahoo.it>
  4. * All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation version 2 of
  9. * the License.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  19. * MA 02111-1307 USA
  20. */
  21. #ifndef USB_EHCI_H
  22. #define USB_EHCI_H
  23. #if !defined(CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS)
  24. #define CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS 2
  25. #endif
  26. /* (shifted) direction/type/recipient from the USB 2.0 spec, table 9.2 */
  27. #define DeviceRequest \
  28. ((USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE) << 8)
  29. #define DeviceOutRequest \
  30. ((USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE) << 8)
  31. #define InterfaceRequest \
  32. ((USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_INTERFACE) << 8)
  33. #define EndpointRequest \
  34. ((USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_INTERFACE) << 8)
  35. #define EndpointOutRequest \
  36. ((USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_INTERFACE) << 8)
  37. /*
  38. * Register Space.
  39. */
  40. struct ehci_hccr {
  41. uint32_t cr_capbase;
  42. #define HC_LENGTH(p) (((p) >> 0) & 0x00ff)
  43. #define HC_VERSION(p) (((p) >> 16) & 0xffff)
  44. uint32_t cr_hcsparams;
  45. #define HCS_PPC(p) ((p) & (1 << 4))
  46. #define HCS_INDICATOR(p) ((p) & (1 << 16)) /* Port indicators */
  47. #define HCS_N_PORTS(p) (((p) >> 0) & 0xf)
  48. uint32_t cr_hccparams;
  49. uint8_t cr_hcsp_portrt[8];
  50. } __attribute__ ((packed, aligned(4)));
  51. struct ehci_hcor {
  52. uint32_t or_usbcmd;
  53. #define CMD_PARK (1 << 11) /* enable "park" */
  54. #define CMD_PARK_CNT(c) (((c) >> 8) & 3) /* how many transfers to park */
  55. #define CMD_ASE (1 << 5) /* async schedule enable */
  56. #define CMD_LRESET (1 << 7) /* partial reset */
  57. #define CMD_IAAD (1 << 5) /* "doorbell" interrupt */
  58. #define CMD_PSE (1 << 4) /* periodic schedule enable */
  59. #define CMD_RESET (1 << 1) /* reset HC not bus */
  60. #define CMD_RUN (1 << 0) /* start/stop HC */
  61. uint32_t or_usbsts;
  62. #define STS_ASS (1 << 15)
  63. #define STS_PSS (1 << 14)
  64. #define STS_HALT (1 << 12)
  65. uint32_t or_usbintr;
  66. #define INTR_UE (1 << 0) /* USB interrupt enable */
  67. #define INTR_UEE (1 << 1) /* USB error interrupt enable */
  68. #define INTR_PCE (1 << 2) /* Port change detect enable */
  69. #define INTR_SEE (1 << 4) /* system error enable */
  70. #define INTR_AAE (1 << 5) /* Interrupt on async adavance enable */
  71. uint32_t or_frindex;
  72. uint32_t or_ctrldssegment;
  73. uint32_t or_periodiclistbase;
  74. uint32_t or_asynclistaddr;
  75. uint32_t _reserved_0_;
  76. uint32_t or_burstsize;
  77. uint32_t or_txfilltuning;
  78. #define TXFIFO_THRESH_MASK (0x3f << 16)
  79. #define TXFIFO_THRESH(p) ((p & 0x3f) << 16)
  80. uint32_t _reserved_1_[6];
  81. uint32_t or_configflag;
  82. #define FLAG_CF (1 << 0) /* true: we'll support "high speed" */
  83. uint32_t or_portsc[CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS];
  84. #define PORTSC_PSPD(x) (((x) >> 26) & 0x3)
  85. #define PORTSC_PSPD_FS 0x0
  86. #define PORTSC_PSPD_LS 0x1
  87. #define PORTSC_PSPD_HS 0x2
  88. uint32_t or_systune;
  89. } __attribute__ ((packed, aligned(4)));
  90. #define USBMODE 0x68 /* USB Device mode */
  91. #define USBMODE_SDIS (1 << 3) /* Stream disable */
  92. #define USBMODE_BE (1 << 2) /* BE/LE endiannes select */
  93. #define USBMODE_CM_HC (3 << 0) /* host controller mode */
  94. #define USBMODE_CM_IDLE (0 << 0) /* idle state */
  95. /* Interface descriptor */
  96. struct usb_linux_interface_descriptor {
  97. unsigned char bLength;
  98. unsigned char bDescriptorType;
  99. unsigned char bInterfaceNumber;
  100. unsigned char bAlternateSetting;
  101. unsigned char bNumEndpoints;
  102. unsigned char bInterfaceClass;
  103. unsigned char bInterfaceSubClass;
  104. unsigned char bInterfaceProtocol;
  105. unsigned char iInterface;
  106. } __attribute__ ((packed));
  107. /* Configuration descriptor information.. */
  108. struct usb_linux_config_descriptor {
  109. unsigned char bLength;
  110. unsigned char bDescriptorType;
  111. unsigned short wTotalLength;
  112. unsigned char bNumInterfaces;
  113. unsigned char bConfigurationValue;
  114. unsigned char iConfiguration;
  115. unsigned char bmAttributes;
  116. unsigned char MaxPower;
  117. } __attribute__ ((packed));
  118. #if defined CONFIG_EHCI_DESC_BIG_ENDIAN
  119. #define ehci_readl(x) (*((volatile u32 *)(x)))
  120. #define ehci_writel(a, b) (*((volatile u32 *)(a)) = ((volatile u32)b))
  121. #else
  122. #define ehci_readl(x) cpu_to_le32((*((volatile u32 *)(x))))
  123. #define ehci_writel(a, b) (*((volatile u32 *)(a)) = \
  124. cpu_to_le32(((volatile u32)b)))
  125. #endif
  126. #if defined CONFIG_EHCI_MMIO_BIG_ENDIAN
  127. #define hc32_to_cpu(x) be32_to_cpu((x))
  128. #define cpu_to_hc32(x) cpu_to_be32((x))
  129. #else
  130. #define hc32_to_cpu(x) le32_to_cpu((x))
  131. #define cpu_to_hc32(x) cpu_to_le32((x))
  132. #endif
  133. #define EHCI_PS_WKOC_E (1 << 22) /* RW wake on over current */
  134. #define EHCI_PS_WKDSCNNT_E (1 << 21) /* RW wake on disconnect */
  135. #define EHCI_PS_WKCNNT_E (1 << 20) /* RW wake on connect */
  136. #define EHCI_PS_PO (1 << 13) /* RW port owner */
  137. #define EHCI_PS_PP (1 << 12) /* RW,RO port power */
  138. #define EHCI_PS_LS (3 << 10) /* RO line status */
  139. #define EHCI_PS_PR (1 << 8) /* RW port reset */
  140. #define EHCI_PS_SUSP (1 << 7) /* RW suspend */
  141. #define EHCI_PS_FPR (1 << 6) /* RW force port resume */
  142. #define EHCI_PS_OCC (1 << 5) /* RWC over current change */
  143. #define EHCI_PS_OCA (1 << 4) /* RO over current active */
  144. #define EHCI_PS_PEC (1 << 3) /* RWC port enable change */
  145. #define EHCI_PS_PE (1 << 2) /* RW port enable */
  146. #define EHCI_PS_CSC (1 << 1) /* RWC connect status change */
  147. #define EHCI_PS_CS (1 << 0) /* RO connect status */
  148. #define EHCI_PS_CLEAR (EHCI_PS_OCC | EHCI_PS_PEC | EHCI_PS_CSC)
  149. #define EHCI_PS_IS_LOWSPEED(x) (((x) & EHCI_PS_LS) == (1 << 10))
  150. /*
  151. * Schedule Interface Space.
  152. *
  153. * IMPORTANT: Software must ensure that no interface data structure
  154. * reachable by the EHCI host controller spans a 4K page boundary!
  155. *
  156. * Periodic transfers (i.e. isochronous and interrupt transfers) are
  157. * not supported.
  158. */
  159. /* Queue Element Transfer Descriptor (qTD). */
  160. struct qTD {
  161. /* this part defined by EHCI spec */
  162. uint32_t qt_next; /* see EHCI 3.5.1 */
  163. #define QT_NEXT_TERMINATE 1
  164. uint32_t qt_altnext; /* see EHCI 3.5.2 */
  165. uint32_t qt_token; /* see EHCI 3.5.3 */
  166. #define QT_TOKEN_DT(x) (((x) & 0x1) << 31) /* Data Toggle */
  167. #define QT_TOKEN_GET_DT(x) (((x) >> 31) & 0x1)
  168. #define QT_TOKEN_TOTALBYTES(x) (((x) & 0x7fff) << 16) /* Total Bytes to Transfer */
  169. #define QT_TOKEN_GET_TOTALBYTES(x) (((x) >> 16) & 0x7fff)
  170. #define QT_TOKEN_IOC(x) (((x) & 0x1) << 15) /* Interrupt On Complete */
  171. #define QT_TOKEN_CPAGE(x) (((x) & 0x7) << 12) /* Current Page */
  172. #define QT_TOKEN_CERR(x) (((x) & 0x3) << 10) /* Error Counter */
  173. #define QT_TOKEN_PID(x) (((x) & 0x3) << 8) /* PID Code */
  174. #define QT_TOKEN_PID_OUT 0x0
  175. #define QT_TOKEN_PID_IN 0x1
  176. #define QT_TOKEN_PID_SETUP 0x2
  177. #define QT_TOKEN_STATUS(x) (((x) & 0xff) << 0) /* Status */
  178. #define QT_TOKEN_GET_STATUS(x) (((x) >> 0) & 0xff)
  179. #define QT_TOKEN_STATUS_ACTIVE 0x80
  180. #define QT_TOKEN_STATUS_HALTED 0x40
  181. #define QT_TOKEN_STATUS_DATBUFERR 0x20
  182. #define QT_TOKEN_STATUS_BABBLEDET 0x10
  183. #define QT_TOKEN_STATUS_XACTERR 0x08
  184. #define QT_TOKEN_STATUS_MISSEDUFRAME 0x04
  185. #define QT_TOKEN_STATUS_SPLITXSTATE 0x02
  186. #define QT_TOKEN_STATUS_PERR 0x01
  187. #define QT_BUFFER_CNT 5
  188. uint32_t qt_buffer[QT_BUFFER_CNT]; /* see EHCI 3.5.4 */
  189. uint32_t qt_buffer_hi[QT_BUFFER_CNT]; /* Appendix B */
  190. /* pad struct for 32 byte alignment */
  191. uint32_t unused[3];
  192. };
  193. #define EHCI_PAGE_SIZE 4096
  194. /* Queue Head (QH). */
  195. struct QH {
  196. uint32_t qh_link;
  197. #define QH_LINK_TERMINATE 1
  198. #define QH_LINK_TYPE_ITD 0
  199. #define QH_LINK_TYPE_QH 2
  200. #define QH_LINK_TYPE_SITD 4
  201. #define QH_LINK_TYPE_FSTN 6
  202. uint32_t qh_endpt1;
  203. #define QH_ENDPT1_RL(x) (((x) & 0xf) << 28) /* NAK Count Reload */
  204. #define QH_ENDPT1_C(x) (((x) & 0x1) << 27) /* Control Endpoint Flag */
  205. #define QH_ENDPT1_MAXPKTLEN(x) (((x) & 0x7ff) << 16) /* Maximum Packet Length */
  206. #define QH_ENDPT1_H(x) (((x) & 0x1) << 15) /* Head of Reclamation List Flag */
  207. #define QH_ENDPT1_DTC(x) (((x) & 0x1) << 14) /* Data Toggle Control */
  208. #define QH_ENDPT1_DTC_IGNORE_QTD_TD 0x0
  209. #define QH_ENDPT1_DTC_DT_FROM_QTD 0x1
  210. #define QH_ENDPT1_EPS(x) (((x) & 0x3) << 12) /* Endpoint Speed */
  211. #define QH_ENDPT1_EPS_FS 0x0
  212. #define QH_ENDPT1_EPS_LS 0x1
  213. #define QH_ENDPT1_EPS_HS 0x2
  214. #define QH_ENDPT1_ENDPT(x) (((x) & 0xf) << 8) /* Endpoint Number */
  215. #define QH_ENDPT1_I(x) (((x) & 0x1) << 7) /* Inactivate on Next Transaction */
  216. #define QH_ENDPT1_DEVADDR(x) (((x) & 0x7f) << 0) /* Device Address */
  217. uint32_t qh_endpt2;
  218. #define QH_ENDPT2_MULT(x) (((x) & 0x3) << 30) /* High-Bandwidth Pipe Multiplier */
  219. #define QH_ENDPT2_PORTNUM(x) (((x) & 0x7f) << 23) /* Port Number */
  220. #define QH_ENDPT2_HUBADDR(x) (((x) & 0x7f) << 16) /* Hub Address */
  221. #define QH_ENDPT2_UFCMASK(x) (((x) & 0xff) << 8) /* Split Completion Mask */
  222. #define QH_ENDPT2_UFSMASK(x) (((x) & 0xff) << 0) /* Interrupt Schedule Mask */
  223. uint32_t qh_curtd;
  224. struct qTD qh_overlay;
  225. /*
  226. * Add dummy fill value to make the size of this struct
  227. * aligned to 32 bytes
  228. */
  229. union {
  230. uint32_t fill[4];
  231. void *buffer;
  232. };
  233. };
  234. /* Low level init functions */
  235. int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor);
  236. int ehci_hcd_stop(int index);
  237. #endif /* USB_EHCI_H */