ehci.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*-
  3. * Copyright (c) 2007-2008, Juniper Networks, Inc.
  4. * Copyright (c) 2008, Michael Trimarchi <trimarchimichael@yahoo.it>
  5. * All rights reserved.
  6. */
  7. #ifndef USB_EHCI_H
  8. #define USB_EHCI_H
  9. #include <usb.h>
  10. /* Section 2.2.3 - N_PORTS */
  11. #define MAX_HC_PORTS 15
  12. /*
  13. * Register Space.
  14. */
  15. struct ehci_hccr {
  16. uint32_t cr_capbase;
  17. #define HC_LENGTH(p) (((p) >> 0) & 0x00ff)
  18. #define HC_VERSION(p) (((p) >> 16) & 0xffff)
  19. uint32_t cr_hcsparams;
  20. #define HCS_PPC(p) ((p) & (1 << 4))
  21. #define HCS_INDICATOR(p) ((p) & (1 << 16)) /* Port indicators */
  22. #define HCS_N_PORTS(p) (((p) >> 0) & 0xf)
  23. uint32_t cr_hccparams;
  24. uint8_t cr_hcsp_portrt[8];
  25. } __attribute__ ((packed, aligned(4)));
  26. struct ehci_hcor {
  27. uint32_t or_usbcmd;
  28. #define CMD_PARK (1 << 11) /* enable "park" */
  29. #define CMD_PARK_CNT(c) (((c) >> 8) & 3) /* how many transfers to park */
  30. #define CMD_LRESET (1 << 7) /* partial reset */
  31. #define CMD_IAAD (1 << 6) /* "doorbell" interrupt */
  32. #define CMD_ASE (1 << 5) /* async schedule enable */
  33. #define CMD_PSE (1 << 4) /* periodic schedule enable */
  34. #define CMD_RESET (1 << 1) /* reset HC not bus */
  35. #define CMD_RUN (1 << 0) /* start/stop HC */
  36. uint32_t or_usbsts;
  37. #define STS_ASS (1 << 15)
  38. #define STS_PSS (1 << 14)
  39. #define STS_HALT (1 << 12)
  40. uint32_t or_usbintr;
  41. #define INTR_UE (1 << 0) /* USB interrupt enable */
  42. #define INTR_UEE (1 << 1) /* USB error interrupt enable */
  43. #define INTR_PCE (1 << 2) /* Port change detect enable */
  44. #define INTR_SEE (1 << 4) /* system error enable */
  45. #define INTR_AAE (1 << 5) /* Interrupt on async adavance enable */
  46. uint32_t or_frindex;
  47. uint32_t or_ctrldssegment;
  48. uint32_t or_periodiclistbase;
  49. uint32_t or_asynclistaddr;
  50. uint32_t _reserved_0_;
  51. uint32_t or_burstsize;
  52. uint32_t or_txfilltuning;
  53. #define TXFIFO_THRESH_MASK (0x3f << 16)
  54. #define TXFIFO_THRESH(p) ((p & 0x3f) << 16)
  55. uint32_t _reserved_1_[6];
  56. uint32_t or_configflag;
  57. #define FLAG_CF (1 << 0) /* true: we'll support "high speed" */
  58. uint32_t or_portsc[MAX_HC_PORTS];
  59. #define PORTSC_PSPD(x) (((x) >> 26) & 0x3)
  60. #define PORTSC_PSPD_FS 0x0
  61. #define PORTSC_PSPD_LS 0x1
  62. #define PORTSC_PSPD_HS 0x2
  63. uint32_t or_systune;
  64. } __attribute__ ((packed, aligned(4)));
  65. #define USBMODE 0x68 /* USB Device mode */
  66. #define USBMODE_SDIS (1 << 3) /* Stream disable */
  67. #define USBMODE_BE (1 << 2) /* BE/LE endiannes select */
  68. #define USBMODE_CM_HC (3 << 0) /* host controller mode */
  69. #define USBMODE_CM_IDLE (0 << 0) /* idle state */
  70. /* Interface descriptor */
  71. struct usb_linux_interface_descriptor {
  72. unsigned char bLength;
  73. unsigned char bDescriptorType;
  74. unsigned char bInterfaceNumber;
  75. unsigned char bAlternateSetting;
  76. unsigned char bNumEndpoints;
  77. unsigned char bInterfaceClass;
  78. unsigned char bInterfaceSubClass;
  79. unsigned char bInterfaceProtocol;
  80. unsigned char iInterface;
  81. } __attribute__ ((packed));
  82. /* Configuration descriptor information.. */
  83. struct usb_linux_config_descriptor {
  84. unsigned char bLength;
  85. unsigned char bDescriptorType;
  86. unsigned short wTotalLength;
  87. unsigned char bNumInterfaces;
  88. unsigned char bConfigurationValue;
  89. unsigned char iConfiguration;
  90. unsigned char bmAttributes;
  91. unsigned char MaxPower;
  92. } __attribute__ ((packed));
  93. #if defined CONFIG_EHCI_DESC_BIG_ENDIAN
  94. #define ehci_readl(x) be32_to_cpu(__raw_readl(x))
  95. #define ehci_writel(a, b) __raw_writel(cpu_to_be32(b), a)
  96. #else
  97. #define ehci_readl(x) readl(x)
  98. #define ehci_writel(a, b) writel(b, a)
  99. #endif
  100. #if defined CONFIG_EHCI_MMIO_BIG_ENDIAN
  101. #define hc32_to_cpu(x) be32_to_cpu((x))
  102. #define cpu_to_hc32(x) cpu_to_be32((x))
  103. #else
  104. #define hc32_to_cpu(x) le32_to_cpu((x))
  105. #define cpu_to_hc32(x) cpu_to_le32((x))
  106. #endif
  107. #define EHCI_PS_WKOC_E (1 << 22) /* RW wake on over current */
  108. #define EHCI_PS_WKDSCNNT_E (1 << 21) /* RW wake on disconnect */
  109. #define EHCI_PS_WKCNNT_E (1 << 20) /* RW wake on connect */
  110. #define EHCI_PS_PO (1 << 13) /* RW port owner */
  111. #define EHCI_PS_PP (1 << 12) /* RW,RO port power */
  112. #define EHCI_PS_LS (3 << 10) /* RO line status */
  113. #define EHCI_PS_PR (1 << 8) /* RW port reset */
  114. #define EHCI_PS_SUSP (1 << 7) /* RW suspend */
  115. #define EHCI_PS_FPR (1 << 6) /* RW force port resume */
  116. #define EHCI_PS_OCC (1 << 5) /* RWC over current change */
  117. #define EHCI_PS_OCA (1 << 4) /* RO over current active */
  118. #define EHCI_PS_PEC (1 << 3) /* RWC port enable change */
  119. #define EHCI_PS_PE (1 << 2) /* RW port enable */
  120. #define EHCI_PS_CSC (1 << 1) /* RWC connect status change */
  121. #define EHCI_PS_CS (1 << 0) /* RO connect status */
  122. #define EHCI_PS_CLEAR (EHCI_PS_OCC | EHCI_PS_PEC | EHCI_PS_CSC)
  123. #define EHCI_PS_IS_LOWSPEED(x) (((x) & EHCI_PS_LS) == (1 << 10))
  124. /*
  125. * Schedule Interface Space.
  126. *
  127. * IMPORTANT: Software must ensure that no interface data structure
  128. * reachable by the EHCI host controller spans a 4K page boundary!
  129. *
  130. * Periodic transfers (i.e. isochronous and interrupt transfers) are
  131. * not supported.
  132. */
  133. /* Queue Element Transfer Descriptor (qTD). */
  134. struct qTD {
  135. /* this part defined by EHCI spec */
  136. uint32_t qt_next; /* see EHCI 3.5.1 */
  137. #define QT_NEXT_TERMINATE 1
  138. uint32_t qt_altnext; /* see EHCI 3.5.2 */
  139. uint32_t qt_token; /* see EHCI 3.5.3 */
  140. #define QT_TOKEN_DT(x) (((x) & 0x1) << 31) /* Data Toggle */
  141. #define QT_TOKEN_GET_DT(x) (((x) >> 31) & 0x1)
  142. #define QT_TOKEN_TOTALBYTES(x) (((x) & 0x7fff) << 16) /* Total Bytes to Transfer */
  143. #define QT_TOKEN_GET_TOTALBYTES(x) (((x) >> 16) & 0x7fff)
  144. #define QT_TOKEN_IOC(x) (((x) & 0x1) << 15) /* Interrupt On Complete */
  145. #define QT_TOKEN_CPAGE(x) (((x) & 0x7) << 12) /* Current Page */
  146. #define QT_TOKEN_CERR(x) (((x) & 0x3) << 10) /* Error Counter */
  147. #define QT_TOKEN_PID(x) (((x) & 0x3) << 8) /* PID Code */
  148. #define QT_TOKEN_PID_OUT 0x0
  149. #define QT_TOKEN_PID_IN 0x1
  150. #define QT_TOKEN_PID_SETUP 0x2
  151. #define QT_TOKEN_STATUS(x) (((x) & 0xff) << 0) /* Status */
  152. #define QT_TOKEN_GET_STATUS(x) (((x) >> 0) & 0xff)
  153. #define QT_TOKEN_STATUS_ACTIVE 0x80
  154. #define QT_TOKEN_STATUS_HALTED 0x40
  155. #define QT_TOKEN_STATUS_DATBUFERR 0x20
  156. #define QT_TOKEN_STATUS_BABBLEDET 0x10
  157. #define QT_TOKEN_STATUS_XACTERR 0x08
  158. #define QT_TOKEN_STATUS_MISSEDUFRAME 0x04
  159. #define QT_TOKEN_STATUS_SPLITXSTATE 0x02
  160. #define QT_TOKEN_STATUS_PERR 0x01
  161. #define QT_BUFFER_CNT 5
  162. uint32_t qt_buffer[QT_BUFFER_CNT]; /* see EHCI 3.5.4 */
  163. uint32_t qt_buffer_hi[QT_BUFFER_CNT]; /* Appendix B */
  164. /* pad struct for 32 byte alignment */
  165. uint32_t unused[3];
  166. };
  167. #define EHCI_PAGE_SIZE 4096
  168. /* Queue Head (QH). */
  169. struct QH {
  170. uint32_t qh_link;
  171. #define QH_LINK_TERMINATE 1
  172. #define QH_LINK_TYPE_ITD 0
  173. #define QH_LINK_TYPE_QH 2
  174. #define QH_LINK_TYPE_SITD 4
  175. #define QH_LINK_TYPE_FSTN 6
  176. uint32_t qh_endpt1;
  177. #define QH_ENDPT1_RL(x) (((x) & 0xf) << 28) /* NAK Count Reload */
  178. #define QH_ENDPT1_C(x) (((x) & 0x1) << 27) /* Control Endpoint Flag */
  179. #define QH_ENDPT1_MAXPKTLEN(x) (((x) & 0x7ff) << 16) /* Maximum Packet Length */
  180. #define QH_ENDPT1_H(x) (((x) & 0x1) << 15) /* Head of Reclamation List Flag */
  181. #define QH_ENDPT1_DTC(x) (((x) & 0x1) << 14) /* Data Toggle Control */
  182. #define QH_ENDPT1_DTC_IGNORE_QTD_TD 0x0
  183. #define QH_ENDPT1_DTC_DT_FROM_QTD 0x1
  184. #define QH_ENDPT1_EPS(x) (((x) & 0x3) << 12) /* Endpoint Speed */
  185. #define QH_ENDPT1_EPS_FS 0x0
  186. #define QH_ENDPT1_EPS_LS 0x1
  187. #define QH_ENDPT1_EPS_HS 0x2
  188. #define QH_ENDPT1_ENDPT(x) (((x) & 0xf) << 8) /* Endpoint Number */
  189. #define QH_ENDPT1_I(x) (((x) & 0x1) << 7) /* Inactivate on Next Transaction */
  190. #define QH_ENDPT1_DEVADDR(x) (((x) & 0x7f) << 0) /* Device Address */
  191. uint32_t qh_endpt2;
  192. #define QH_ENDPT2_MULT(x) (((x) & 0x3) << 30) /* High-Bandwidth Pipe Multiplier */
  193. #define QH_ENDPT2_PORTNUM(x) (((x) & 0x7f) << 23) /* Port Number */
  194. #define QH_ENDPT2_HUBADDR(x) (((x) & 0x7f) << 16) /* Hub Address */
  195. #define QH_ENDPT2_UFCMASK(x) (((x) & 0xff) << 8) /* Split Completion Mask */
  196. #define QH_ENDPT2_UFSMASK(x) (((x) & 0xff) << 0) /* Interrupt Schedule Mask */
  197. uint32_t qh_curtd;
  198. struct qTD qh_overlay;
  199. /*
  200. * Add dummy fill value to make the size of this struct
  201. * aligned to 32 bytes
  202. */
  203. union {
  204. uint32_t fill[4];
  205. void *buffer;
  206. };
  207. };
  208. /* Tweak flags for EHCI, used to control operation */
  209. enum {
  210. /* don't use or_configflag in init */
  211. EHCI_TWEAK_NO_INIT_CF = 1 << 0,
  212. };
  213. struct ehci_ctrl;
  214. struct ehci_ops {
  215. void (*set_usb_mode)(struct ehci_ctrl *ctrl);
  216. int (*get_port_speed)(struct ehci_ctrl *ctrl, uint32_t reg);
  217. void (*powerup_fixup)(struct ehci_ctrl *ctrl, uint32_t *status_reg,
  218. uint32_t *reg);
  219. uint32_t *(*get_portsc_register)(struct ehci_ctrl *ctrl, int port);
  220. int (*init_after_reset)(struct ehci_ctrl *ctrl);
  221. };
  222. struct ehci_ctrl {
  223. enum usb_init_type init;
  224. struct ehci_hccr *hccr; /* R/O registers, not need for volatile */
  225. struct ehci_hcor *hcor;
  226. int rootdev;
  227. uint16_t portreset;
  228. struct QH qh_list __aligned(USB_DMA_MINALIGN);
  229. struct QH periodic_queue __aligned(USB_DMA_MINALIGN);
  230. uint32_t *periodic_list;
  231. int periodic_schedules;
  232. int ntds;
  233. struct ehci_ops ops;
  234. void *priv; /* client's private data */
  235. };
  236. /**
  237. * ehci_set_controller_info() - Set up private data for the controller
  238. *
  239. * This function can be called in ehci_hcd_init() to tell the EHCI layer
  240. * about the controller's private data pointer. Then in the above functions
  241. * this can be accessed given the struct ehci_ctrl pointer. Also special
  242. * EHCI operation methods can be provided if required
  243. *
  244. * @index: Controller number to set
  245. * @priv: Controller pointer
  246. * @ops: Controller operations, or NULL to use default
  247. */
  248. void ehci_set_controller_priv(int index, void *priv,
  249. const struct ehci_ops *ops);
  250. /**
  251. * ehci_get_controller_priv() - Get controller private data
  252. *
  253. * @index Controller number to get
  254. * @return controller pointer for this index
  255. */
  256. void *ehci_get_controller_priv(int index);
  257. /* Low level init functions */
  258. int ehci_hcd_init(int index, enum usb_init_type init,
  259. struct ehci_hccr **hccr, struct ehci_hcor **hcor);
  260. int ehci_hcd_stop(int index);
  261. int ehci_register(struct udevice *dev, struct ehci_hccr *hccr,
  262. struct ehci_hcor *hcor, const struct ehci_ops *ops,
  263. uint tweaks, enum usb_init_type init);
  264. int ehci_deregister(struct udevice *dev);
  265. extern struct dm_usb_ops ehci_usb_ops;
  266. #endif /* USB_EHCI_H */