usb_ehci_reg.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. /****************************************************************************
  2. * include/nuttx/usb/ehci.h
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. /*
  21. * Copyright 2022 sakumisu
  22. *
  23. * SPDX-License-Identifier: Apache-2.0
  24. */
  25. #ifndef __INCLUDE_NUTTX_USB_EHCI_H
  26. #define __INCLUDE_NUTTX_USB_EHCI_H
  27. #define EHCI_FULL_SPEED (0) /* Full-Speed (12Mbs) */
  28. #define EHCI_LOW_SPEED (1) /* Low-Speed (1.5Mbs) */
  29. #define EHCI_HIGH_SPEED (2) /* High-Speed (480 Mb/s) */
  30. /* Host Controller Capability Register Bit Definitions **********************/
  31. /* Structural Parameters. Paragraph 2.2.3 */
  32. #define EHCI_HCSPARAMS_NPORTS_SHIFT (0) /* Bit 0-3: Number of physical downstream ports */
  33. #define EHCI_HCSPARAMS_NPORTS_MASK (15 << EHCI_HCSPARAMS_NPORTS_SHIFT)
  34. #define EHCI_HCSPARAMS_PPC (1 << 4) /* Bit 4: Port Power Control */
  35. #define EHCI_HCSPARAMS_PRR (1 << 7) /* Bit 7: Port Routing Rules */
  36. #define EHCI_HCSPARAMS_NPCC_SHIFT (8) /* Bit 8-11: Number of Ports per Companion Controller */
  37. #define EHCI_HCSPARAMS_NPCC_MASK (15 << EHCI_HCSPARAMS_NPCC_SHIFT)
  38. #define EHCI_HCSPARAMS_NCC_SHIFT (12) /* Bit 12-15: Number of Companion Controllers */
  39. #define EHCI_HCSPARAMS_NCC_MASK (15 << EHCI_HCSPARAMS_NCC_SHIFT)
  40. #define EHCI_HCSPARAMS_PIND (1 << 16) /* Bit 16: Port Indicators */
  41. #define EHCI_HCSPARAMS_DBGPORT_SHIFT (20) /* Bit 20-23: Debug Port Number */
  42. #define EHCI_HCSPARAMS_DBGPORT_MASK (15 << EHCI_HCSPARAMS_DBGPORT_SHIFT)
  43. /* Capability Parameters. Paragraph 2.2.4 */
  44. #define EHCI_HCCPARAMS_64BIT (1 << 0) /* Bit 0: 64-bit Addressing Capability */
  45. #define EHCI_HCCPARAMS_PFLF (1 << 1) /* Bit 1: Programmable Frame List Flag */
  46. #define EHCI_HCCPARAMS_ASPC (1 << 2) /* Bit 2: Asynchronous Schedule Park Capability */
  47. #define EHCI_HCCPARAMS_IST_SHIFT (4) /* Bits 4-7: Isochronous Scheduling Threshold */
  48. #define EHCI_HCCPARAMS_IST_MASK (15 << EHCI_HCCPARAMS_IST_SHIFT)
  49. #define EHCI_HCCPARAMS_EECP_SHIFT (8) /* Bits 8-15: EHCI Extended Capabilities Pointer */
  50. #define EHCI_HCCPARAMS_EECP_MASK (0xff << EHCI_HCCPARAMS_EECP_SHIFT)
  51. /* Host Controller Operational Register Bit Definitions *********************/
  52. /* USB Command. Paragraph 2.3.1 */
  53. #define EHCI_USBCMD_RUN (1 << 0) /* Bit 0: Run/Stop */
  54. #define EHCI_USBCMD_HCRESET (1 << 1) /* Bit 1: Host Controller Reset */
  55. #define EHCI_USBCMD_FLSIZE_SHIFT (2) /* Bits 2-3: Frame List Size */
  56. #define EHCI_USBCMD_FLSIZE_MASK (3 << EHCI_USBCMD_FLSIZE_SHIFT)
  57. #define EHCI_USBCMD_FLSIZE_1024 (0 << EHCI_USBCMD_FLSIZE_SHIFT) /* 1024 elements (4096 bytes) */
  58. #define EHCI_USBCMD_FLSIZE_512 (1 << EHCI_USBCMD_FLSIZE_SHIFT) /* 512 elements (2048 bytes) */
  59. #define EHCI_USBCMD_FLSIZE_256 (2 << EHCI_USBCMD_FLSIZE_SHIFT) /* 256 elements (1024 bytes) */
  60. #define EHCI_USBCMD_PSEN (1 << 4) /* Bit 4: Periodic Schedule Enable */
  61. #define EHCI_USBCMD_ASEN (1 << 5) /* Bit 5: Asynchronous Schedule Enable */
  62. #define EHCI_USBCMD_IAAD (1 << 6) /* Bit 6: Interrupt on Async Advance Doorbell */
  63. #define EHCI_USBCMD_LRESET (1 << 7) /* Bit 7: Light Host Controller Reset */
  64. #define EHCI_USBCMD_ASYNC_PARKCNT_SHIFT (8) /* Bits 8-9: Asynchronous Schedule Park Mode Count */
  65. #define EHCI_USBCMD_ASYNC_PARKCNT_MASK (3 << EHCI_USBCMD_ASYNC_PARKCNT_SHIFT)
  66. #define EHCI_USBCMD_ASYNC_PARK (1 << 11) /* Bit 11: Asynchronous Schedule Park Mode Enable */
  67. #define EHCI_USBCMD_ITHRE_SHIFT (16) /* Bits 16-23: Interrupt Threshold Control */
  68. #define EHCI_USBCMD_ITHRE_MASK (0xff << EHCI_USBCMD_ITHRE_SHIFT)
  69. #define EHCI_USBCMD_ITHRE_1MF (0x01 << EHCI_USBCMD_ITHRE_SHIFT) /* 1 micro-frame */
  70. #define EHCI_USBCMD_ITHRE_2MF (0x02 << EHCI_USBCMD_ITHRE_SHIFT) /* 2 micro-frames */
  71. #define EHCI_USBCMD_ITHRE_4MF (0x04 << EHCI_USBCMD_ITHRE_SHIFT) /* 4 micro-frames */
  72. #define EHCI_USBCMD_ITHRE_8MF (0x08 << EHCI_USBCMD_ITHRE_SHIFT) /* 8 micro-frames (default, 1 ms) */
  73. #define EHCI_USBCMD_ITHRE_16MF (0x10 << EHCI_USBCMD_ITHRE_SHIFT) /* 16 micro-frames (2 ms) */
  74. #define EHCI_USBCMD_ITHRE_32MF (0x20 << EHCI_USBCMD_ITHRE_SHIFT) /* 32 micro-frames (4 ms) */
  75. #define EHCI_USBCMD_ITHRE_64MF (0x40 << EHCI_USBCMD_ITHRE_SHIFT) /* 64 micro-frames (8 ms) */
  76. /* USB Status. Paragraph 2.3.2 */
  77. #define EHCI_USBSTS_INT (1 << 0) /* Bit 0: USB Interrupt */
  78. #define EHCI_USBSTS_ERR (1 << 1) /* Bit 1: USB Error Interrupt */
  79. #define EHCI_USBSTS_PCD (1 << 2) /* Bit 2: Port Change Detect */
  80. #define EHCI_USBSTS_FLR (1 << 3) /* Bit 3: Frame List Rollover */
  81. #define EHCI_USBSTS_FATAL (1 << 4) /* Bit 4: Host System Error */
  82. #define EHCI_USBSTS_IAA (1 << 5) /* Bit 5: Interrupt on Async Advance */
  83. #define EHCI_USBSTS_HALTED (1 << 12) /* Bit 12: HC Halted */
  84. #define EHCI_USBSTS_RECLAM (1 << 13) /* Bit 13: Reclamation */
  85. #define EHCI_USBSTS_PSS (1 << 14) /* Bit 14: Periodic Schedule Status */
  86. #define EHCI_USBSTS_ASS (1 << 15) /* Bit 15: Asynchronous Schedule Status */
  87. /* Bits 16-31: Reserved */
  88. /* USB Interrupt Enable. Paragraph 2.3.3 */
  89. #define EHCI_USBIE_INT (1 << 0) /* Bit 0: USB Interrupt */
  90. #define EHCI_USBIE_ERR (1 << 1) /* Bit 1: USB Error Interrupt */
  91. #define EHCI_USBIE_PCD (1 << 2) /* Bit 2: Port Change Detect */
  92. #define EHCI_USBIE_FLROLL (1 << 3) /* Bit 3: Frame List Rollover */
  93. #define EHCI_USBIE_FATAL (1 << 4) /* Bit 4: Host System Error */
  94. #define EHCI_USBIE_IAA (1 << 5) /* Bit 5: Interrupt on Async Advance */
  95. #define EHCI_USBIE_ALLINTS (0x3f) /* Bits 0-5: All interrupts */
  96. /* USB Frame Index. Paragraph 2.3.4 */
  97. #define EHCI_FRINDEX_MASK (0x3fff) /* Bits 0-13: Frame index */
  98. /* 4G Segment Selector.
  99. * Paragraph 2.3.5, Bits[64:32] of data structure addresses
  100. */
  101. /* Frame List Base Address. Paragraph 2.3.6 */
  102. #define EHCI_PERIODICLISTBASE_MASK (0xfffff000) /* Bits 12-31: Base Address (Low) */
  103. /* Next Asynchronous List Address. Paragraph 2.3.7 */
  104. #define EHCI_ASYNCLISTADDR_MASK (0xffffffe0) /* Bits 5-31: Link Pointer Low (LPL) */
  105. /* Configured Flag Register. Paragraph 2.3.8 */
  106. #define EHCI_CONFIGFLAG (1 << 0) /* Bit 0: Configure Flag */
  107. /* Port Status/Control, Port 1-n. Paragraph 2.3.9 */
  108. #define EHCI_PORTSC_CCS (1 << 0) /* Bit 0: Current Connect Status */
  109. #define EHCI_PORTSC_CSC (1 << 1) /* Bit 1: Connect Status Change */
  110. #define EHCI_PORTSC_PE (1 << 2) /* Bit 2: Port Enable */
  111. #define EHCI_PORTSC_PEC (1 << 3) /* Bit 3: Port Enable/Disable Change */
  112. #define EHCI_PORTSC_OCA (1 << 4) /* Bit 4: Over-current Active */
  113. #define EHCI_PORTSC_OCC (1 << 5) /* Bit 5: Over-current Change */
  114. #define EHCI_PORTSC_RESUME (1 << 6) /* Bit 6: Force Port Resume */
  115. #define EHCI_PORTSC_SUSPEND (1 << 7) /* Bit 7: Suspend */
  116. #define EHCI_PORTSC_RESET (1 << 8) /* Bit 8: Port Reset */
  117. #define EHCI_PORTSC_LSTATUS_SHIFT (10) /* Bits 10-11: Line Status */
  118. #define EHCI_PORTSC_LSTATUS_MASK (3 << EHCI_PORTSC_LSTATUS_SHIFT)
  119. #define EHCI_PORTSC_LSTATUS_SE0 (0 << EHCI_PORTSC_LSTATUS_SHIFT) /* SE0 Not Low-speed device, perform EHCI reset */
  120. #define EHCI_PORTSC_LSTATUS_KSTATE (1 << EHCI_PORTSC_LSTATUS_SHIFT) /* K-state Low-speed device, release ownership of port */
  121. #define EHCI_PORTSC_LSTATUS_JSTATE (2 << EHCI_PORTSC_LSTATUS_SHIFT) /* J-state Not Low-speed device, perform EHCI reset */
  122. #define EHCI_PORTSC_PP (1 << 12) /* Bit 12: Port Power */
  123. #define EHCI_PORTSC_OWNER (1 << 13) /* Bit 13: Port Owner */
  124. #define EHCI_PORTSC_PIC_SHIFT (14) /* Bits 14-15: Port Indicator Control */
  125. #define EHCI_PORTSC_PIC_MASK (3 << EHCI_PORTSC_PIC_SHIFT)
  126. #define EHCI_PORTSC_PIC_OFF (0 << EHCI_PORTSC_PIC_SHIFT) /* Port indicators are off */
  127. #define EHCI_PORTSC_PIC_AMBER (1 << EHCI_PORTSC_PIC_SHIFT) /* Amber */
  128. #define EHCI_PORTSC_PIC_GREEN (2 << EHCI_PORTSC_PIC_SHIFT) /* Green */
  129. #define EHCI_PORTSC_PTC_SHIFT (16) /* Bits 16-19: Port Test Control */
  130. #define EHCI_PORTSC_PTC_MASK (15 << EHCI_PORTSC_PTC_SHIFT)
  131. #define EHCI_PORTSC_PTC_DISABLED (0 << EHCI_PORTSC_PTC_SHIFT) /* Test mode not enabled */
  132. #define EHCI_PORTSC_PTC_JSTATE (1 << EHCI_PORTSC_PTC_SHIFT) /* Test J_STATE */
  133. #define EHCI_PORTSC_PTC_KSTATE (2 << EHCI_PORTSC_PTC_SHIFT) /* Test K_STATE */
  134. #define EHCI_PORTSC_PTC_SE0NAK (3 << EHCI_PORTSC_PTC_SHIFT) /* Test SE0_NAK */
  135. #define EHCI_PORTSC_PTC_PACKET (4 << EHCI_PORTSC_PTC_SHIFT) /* Test Packet */
  136. #define EHCI_PORTSC_PTC_ENABLE (5 << EHCI_PORTSC_PTC_SHIFT) /* Test FORCE_ENABLE */
  137. #define EHCI_PORTSC_WKCCNTE (1 << 20) /* Bit 20: Wake on Connect Enable */
  138. #define EHCI_PORTSC_WKDSCNNTE (1 << 21) /* Bit 21: Wake on Disconnect Enable */
  139. #define EHCI_PORTSC_WKOCE (1 << 22) /* Bit 22: Wake on Over-current Enable */
  140. /* Bits 23-31: Reserved */
  141. #define EHCI_PORTSC_ALLINTS (EHCI_PORTSC_CSC | EHCI_PORTSC_PEC | \
  142. EHCI_PORTSC_OCC | EHCI_PORTSC_RESUME)
  143. /* Queue Head. Paragraph 3.6 */
  144. /* Queue Head Horizontal Link Pointer: Queue Head DWord 0. Table 3-19 */
  145. #define QH_HLP_END 0x1
  146. #define QH_HLP_ITD(x) (((uint32_t)(x) & ~0x1F) | 0x0) /* Isochronous Transfer Descriptor */
  147. #define QH_HLP_QH(x) (((uint32_t)(x) & ~0x1F) | 0x2) /* Queue Head */
  148. #define QH_HLP_SITD(x) (((uint32_t)(x) & ~0x1F) | 0x4) /* Split Transaction Isochronous Transfer Descriptor */
  149. #define QH_HLP_FSTN(x) (((uint32_t)(x) & ~0x1F) | 0x6) /* Frame Span Traversal Node */
  150. /* Endpoint Characteristics: Queue Head DWord 1. Table 3-19 */
  151. #define QH_EPCHAR_DEVADDR_SHIFT (0) /* Bitx 0-6: Device Address */
  152. #define QH_EPCHAR_DEVADDR_MASK (0x7f << QH_EPCHAR_DEVADDR_SHIFT)
  153. #define QH_EPCHAR_I (1 << 7) /* Bit 7: Inactivate on Next Transaction */
  154. #define QH_EPCHAR_ENDPT_SHIFT (8) /* Bitx 8-11: Endpoint Number */
  155. #define QH_EPCHAR_ENDPT_MASK (15 << QH_EPCHAR_ENDPT_SHIFT)
  156. #define QH_EPCHAR_EPS_SHIFT (12) /* Bitx 12-13: Endpoint Speed */
  157. #define QH_EPCHAR_EPS_MASK (3 << QH_EPCHAR_EPS_SHIFT)
  158. #define QH_EPCHAR_EPS_FULL (0 << QH_EPCHAR_EPS_SHIFT) /* Full-Speed (12Mbs) */
  159. #define QH_EPCHAR_EPS_LOW (1 << QH_EPCHAR_EPS_SHIFT) /* Low-Speed (1.5Mbs) */
  160. #define QH_EPCHAR_EPS_HIGH (2 << QH_EPCHAR_EPS_SHIFT) /* High-Speed (480 Mb/s) */
  161. #define QH_EPCHAR_DTC (1 << 14) /* Bit 14: Data Toggle Control */
  162. #define QH_EPCHAR_H (1 << 15) /* Bit 15: Head of Reclamation List Flag */
  163. #define QH_EPCHAR_MAXPKT_SHIFT (16) /* Bitx 16-26: Maximum Packet Length */
  164. #define QH_EPCHAR_MAXPKT_MASK (0x7ff << QH_EPCHAR_MAXPKT_SHIFT)
  165. #define QH_EPCHAR_C (1 << 27) /* Bit 27: Control Endpoint Flag */
  166. #define QH_EPCHAR_RL_SHIFT (28) /* Bitx 28-31: Nak Count Reload */
  167. #define QH_EPCHAR_RL_MASK (15 << QH_EPCHAR_RL_SHIFT)
  168. /* Endpoint Capabilities: Queue Head DWord 2. Table 3-20 */
  169. #define QH_EPCAPS_SSMASK_SHIFT (0) /* Bitx 0-7: Interrupt Schedule Mask (Frame S-mask) */
  170. #define QH_EPCAPS_SSMASK_MASK (0xff << QH_EPCAPS_SSMASK_SHIFT)
  171. #define QH_EPCAPS_SSMASK(n) ((n) << QH_EPCAPS_SSMASK_SHIFT)
  172. #define QH_EPCAPS_SCMASK_SHIFT (8) /* Bitx 8-15: Split Completion Mask (Frame C-Mask) */
  173. #define QH_EPCAPS_SCMASK_MASK (0xff << QH_EPCAPS_SCMASK_SHIFT)
  174. #define QH_EPCAPS_SCMASK(n) ((n) << QH_EPCAPS_SCMASK_SHIFT)
  175. #define QH_EPCAPS_HUBADDR_SHIFT (16) /* Bitx 16-22: Hub Address */
  176. #define QH_EPCAPS_HUBADDR_MASK (0x7f << QH_EPCAPS_HUBADDR_SHIFT)
  177. #define QH_EPCAPS_HUBADDR(n) ((n) << QH_EPCAPS_HUBADDR_SHIFT)
  178. #define QH_EPCAPS_PORT_SHIFT (23) /* Bit 23-29: Port Number */
  179. #define QH_EPCAPS_PORT_MASK (0x7f << QH_EPCAPS_PORT_SHIFT)
  180. #define QH_EPCAPS_PORT(n) ((n) << QH_EPCAPS_PORT_SHIFT)
  181. #define QH_EPCAPS_MULT_SHIFT (30) /* Bit 30-31: High-Bandwidth Pipe Multiplier */
  182. #define QH_EPCAPS_MULT_MASK (3 << QH_EPCAPS_MULT_SHIFT)
  183. #define QH_EPCAPS_MULT(n) ((n) << QH_EPCAPS_MULT_SHIFT)
  184. /* qTD Token. Paragraph 3.5.3 */
  185. #define QTD_LIST_END 1
  186. #define QTD_TOKEN_STATUS_SHIFT (0) /* Bits 0-7: Status */
  187. #define QTD_TOKEN_STATUS_MASK (0xff << QTD_TOKEN_STATUS_SHIFT)
  188. #define QTD_TOKEN_STATUS_PINGSTATE (1 << 0) /* Bit 0 Ping State */
  189. #define QTD_TOKEN_STATUS_ERR (1 << 0) /* Bit 0 Error */
  190. #define QTD_TOKEN_STATUS_SPLITXSTATE (1 << 1) /* Bit 1 Split Transaction State */
  191. #define QTD_TOKEN_STATUS_MMF (1 << 2) /* Bit 2 Missed Micro-Frame */
  192. #define QTD_TOKEN_STATUS_XACTERR (1 << 3) /* Bit 3 Transaction Error */
  193. #define QTD_TOKEN_STATUS_BABBLE (1 << 4) /* Bit 4 Babble Detected */
  194. #define QTD_TOKEN_STATUS_DBERR (1 << 5) /* Bit 5 Data Buffer Error */
  195. #define QTD_TOKEN_STATUS_HALTED (1 << 6) /* Bit 6 Halted */
  196. #define QTD_TOKEN_STATUS_ACTIVE (1 << 7) /* Bit 7 Active */
  197. #define QTD_TOKEN_STATUS_ERRORS (0x78 << QTD_TOKEN_STATUS_SHIFT)
  198. #define QTD_TOKEN_PID_SHIFT (8) /* Bits 8-9: PID Code */
  199. #define QTD_TOKEN_PID_MASK (3 << QTD_TOKEN_PID_SHIFT)
  200. #define QTD_TOKEN_PID_OUT (0 << QTD_TOKEN_PID_SHIFT) /* OUT Token generates token (E1H) */
  201. #define QTD_TOKEN_PID_IN (1 << QTD_TOKEN_PID_SHIFT) /* IN Token generates token (69H) */
  202. #define QTD_TOKEN_PID_SETUP (2 << QTD_TOKEN_PID_SHIFT) /* SETUP Token generates token (2DH) */
  203. #define QTD_TOKEN_CERR_SHIFT (10) /* Bits 10-11: Error Counter */
  204. #define QTD_TOKEN_CERR_MASK (3 << QTD_TOKEN_CERR_SHIFT)
  205. #define QTD_TOKEN_CPAGE_SHIFT (12) /* Bits 12-14: Current Page */
  206. #define QTD_TOKEN_CPAGE_MASK (7 << QTD_TOKEN_CPAGE_SHIFT)
  207. #define QTD_TOKEN_IOC (1 << 15) /* Bit 15: Interrupt On Complete */
  208. #define QTD_TOKEN_NBYTES_SHIFT (16) /* Bits 16-30: Total Bytes to Transfer */
  209. #define QTD_TOKEN_NBYTES_MASK (0x7fff << QTD_TOKEN_NBYTES_SHIFT)
  210. #define QTD_TOKEN_TOGGLE (1 << 31) /* Bit 31: Data Toggle */
  211. /* Isochronous (High-Speed) Transfer Descriptor (iTD). Paragraph 3.3 */
  212. /* iTD Next Link Pointer. Paragraph 3.3.1 */
  213. #define ITD_NLP_ITD(x) (((uint32_t)(x) & ~0x1F) | 0x0)
  214. #define ITD_NLP_QH(x) (((uint32_t)(x) & ~0x1F) | 0x2)
  215. #define ITD_NLP_SITD(x) (((uint32_t)(x) & ~0x1F) | 0x4)
  216. #define ITD_NLP_FSTN(x) (((uint32_t)(x) & ~0x1F) | 0x6)
  217. /* iTD Transaction Status and Control List. Paragraph 3.3.2 */
  218. #define ITD_TSCL_XOFFS_SHIFT (0) /* Bits 0-11: Transaction X offset */
  219. #define ITD_TSCL_XOFFS_MASK (0xfff << ITD_TSCL_XOFFS_SHIFT)
  220. #define ITD_TSCL_PG_SHIFT (12) /* Bits 12-14: Page select */
  221. #define ITD_TSCL_PG_MASK (7 << ITD_TSCL_PG_SHIFT)
  222. #define ITD_TSCL_IOC (1 << 15) /* Bit 15: Interrupt On Comp */
  223. #define ITD_TSCL_LENGTH_SHIFT (16) /* Bits 16-27: Transaction length */
  224. #define ITD_TSCL_LENGTH_MASK (0xfff << ITD_TSCL_LENGTH_SHIFT)
  225. #define ITD_TSCL_STATUS_SHIFT (28) /* Bits 28-31: Transaction status */
  226. #define ITD_TSCL_STATUS_MASK (15 << ITD_TSCL_STATUS_SHIFT)
  227. #define ITD_TSCL_STATUS_XACTERR (1 << 28) /* Bit 28: Transaction error */
  228. #define ITD_TSCL_STATUS_BABBLE (1 << 29) /* Bit 29: Babble Detected */
  229. #define ITD_TSCL_STATUS_DBERROR (1 << 30) /* Bit 30: Data Buffer Error */
  230. #define ITD_TSCL_STATUS_ACTIVE (1 << 31) /* Bit 31: Active error */
  231. /* iTD Buffer Page Pointer List. Paragraph 3.3.4 */
  232. /* iTD Buffer Pointer Page 0. Table 3-4 */
  233. #define ITD_BUFPTR0_DEVADDR_SHIFT (0) /* Bits 0-6: Device Address */
  234. #define ITD_BUFPTR0_DEVADDR_MASK (0x7f << ITD_BUFPTR0_DEVADDR_SHIFT)
  235. #define ITD_BUFPTR0_ENDPT_SHIFT (8) /* Bits 8-11: Endpoint Number */
  236. #define ITD_BUFPTR0_ENDPT_MASK (15 << ITD_BUFPTR0_ENDPT_SHIFT)
  237. /* iTD Buffer Pointer Page 1. Table 3-5 */
  238. #define ITD_BUFPTR1_MAXPKT_SHIFT (0) /* Bits 0-10: Maximum Packet Size */
  239. #define ITD_BUFPTR1_MAXPKT_MASK (0x7ff << ITD_BUFPTR1_MAXPKT_SHIFT)
  240. #define ITD_BUFPTR1_DIRIN (1 << 11) /* Bit 11: Direction 1=IN */
  241. #define ITD_BUFPTR1_DIROUT (0) /* Bit 11: Direction 0=OUT */
  242. /* iTD Buffer Pointer Page 2. Table 3-6 */
  243. #define ITD_BUFPTR2_MULTI_SHIFT (0) /* Bits 0-1: Multi */
  244. #define ITD_BUFPTR2_MULTI_MASK (3 << ITD_BUFPTR2_MULTI_SHIFT)
  245. #define ITD_BUFPTR2_MULTI_1 (1 << ITD_BUFPTR2_MULTI_SHIFT) /* One transaction per micro-frame */
  246. #define ITD_BUFPTR2_MULTI_2 (2 << ITD_BUFPTR2_MULTI_SHIFT) /* Two transactions per micro-frame */
  247. #define ITD_BUFPTR2_MULTI_3 (3 << ITD_BUFPTR2_MULTI_SHIFT) /* Three transactions per micro-frame */
  248. /* Registers ****************************************************************/
  249. /* Host Controller Capability Registers.
  250. * This register block must be positioned at a well known address.
  251. */
  252. struct ehci_hccr {
  253. volatile uint8_t caplength; /* 0x00: Capability Register Length */
  254. volatile uint8_t reserved; /* 0x01: reserved */
  255. volatile uint16_t hciversion; /* 0x02: Interface Version Number */
  256. volatile uint32_t hcsparams; /* 0x04: Structural Parameters */
  257. volatile uint32_t hccparams; /* 0x08: Capability Parameters */
  258. volatile uint8_t hcspportroute[8]; /* 0x0c: Companion Port Route Description */
  259. };
  260. /* Host Controller Operational Registers.
  261. * This register block is positioned at an offset of 'caplength' from the
  262. * beginning of the Host Controller Capability Registers.
  263. */
  264. struct ehci_hcor {
  265. volatile uint32_t usbcmd; /* 0x00: USB Command */
  266. volatile uint32_t usbsts; /* 0x04: USB Status */
  267. volatile uint32_t usbintr; /* 0x08: USB Interrupt Enable */
  268. volatile uint32_t frindex; /* 0x0c: USB Frame Index */
  269. volatile uint32_t ctrldssegment; /* 0x10: 4G Segment Selector */
  270. volatile uint32_t periodiclistbase; /* 0x14: Frame List Base Address */
  271. volatile uint32_t asynclistaddr; /* 0x18: Next Asynchronous List Address */
  272. #ifndef CONFIG_USB_EHCI_HCOR_RESERVED_DISABLE
  273. uint32_t reserved[9];
  274. #endif
  275. volatile uint32_t configflag; /* 0x40: Configured Flag Register */
  276. volatile uint32_t portsc[15]; /* 0x44: Port Status/Control */
  277. };
  278. /* USB2 Debug Port Register Interface.
  279. * This register block is normally found via the PCI capabalities.
  280. * In non-PCI implementions, you need apriori information about the
  281. * location of these registers.
  282. */
  283. struct ehci_debug {
  284. uint32_t psc; /* 0x00: Debug Port Control/Status Register */
  285. uint32_t pids; /* 0x04: Debug USB PIDs Register */
  286. uint32_t data[2]; /* 0x08: Debug Data buffer Registers */
  287. uint32_t addr; /* 0x10: Device Address Register */
  288. };
  289. /* Data Structures **********************************************************/
  290. /* Queue Element Transfer Descriptor (qTD). Paragraph 3.5 */
  291. struct ehci_qtd {
  292. uint32_t next_qtd; /* 0x00-0x03: Next qTD Pointer */
  293. uint32_t alt_next_qtd; /* 0x04-0x07: Alternate Next qTD Pointer */
  294. uint32_t token; /* 0x08-0x0b: qTD Token */
  295. uint32_t bpl[5]; /* 0x0c-0x1c: Buffer Page Pointer List */
  296. };
  297. #define SIZEOF_EHCI_QTD (32) /* 8*sizeof(uint32_t) */
  298. /* Queue Head. Paragraph 3.6 */
  299. struct ehci_qh {
  300. uint32_t hlp; /* 0x00-0x03: Queue Head Horizontal Link Pointer */
  301. uint32_t epchar; /* 0x04-0x07: Endpoint Characteristics */
  302. uint32_t epcap; /* 0x08-0x0b: Endpoint Capabilities */
  303. uint32_t curr_qtd; /* 0x0c-0x0f: Current qTD Pointer */
  304. struct ehci_qtd overlay; /* 0x10-0x2c: Transfer overlay */
  305. };
  306. #define SIZEOF_EHCI_QH (48) /* 4*sizeof(uint32_t) + 32 */
  307. /* Isochronous (High-Speed) Transfer Descriptor (iTD).
  308. * Paragraph 3.3. Must be aligned to 32-byte boundaries.
  309. */
  310. struct ehci_itd {
  311. uint32_t nlp; /* 0x00-0x03: Next link pointer */
  312. uint32_t tscl[8]; /* 0x04-0x23: Transaction Status and Control List */
  313. uint32_t bpl[7]; /* 0x24-0x3c: Buffer Page Pointer List */
  314. };
  315. #define SIZEOF_EHCI_ITD (64) /* 16*sizeof(uint32_t) */
  316. /* Split Transaction Isochronous Transfer Descriptor (siTD). Paragraph 3.4 */
  317. struct ehci_sitd {
  318. uint32_t nlp; /* 0x00-0x03: Next link pointer */
  319. uint32_t epchar; /* 0x04-0x07: Endpoint and Transaction Translator Characteristics */
  320. uint32_t mfsc; /* 0x08-0x0b: Micro-frame Schedule Control */
  321. uint32_t tsc; /* 0x0c-0x0f: Transfer Status and Control */
  322. uint32_t bpl[2]; /* 0x10-0x17: Buffer Pointer List */
  323. uint32_t blp; /* 0x18-0x1b: Back link pointer */
  324. };
  325. #define SIZEOF_EHCI_SITD (28) /* 7*sizeof(uint32_t) */
  326. #endif /* __INCLUDE_NUTTX_USB_EHCI_H */