musbhw.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /*++
  2. Copyright (c) 2015 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. musbhw.h
  5. Abstract:
  6. This header contains hardware definitions for the Mentor Graphics USB 2.0
  7. OTG controller.
  8. Author:
  9. Evan Green 11-Sep-2015
  10. --*/
  11. //
  12. // ------------------------------------------------------------------- Includes
  13. //
  14. //
  15. // --------------------------------------------------------------------- Macros
  16. //
  17. //
  18. // This macro returns the proper non-indexed endpoint setup register for the
  19. // given endpoint. The endpoint control registers include device address,
  20. // hub address, and hub port.
  21. //
  22. #define MUSB_ENDPOINT_SETUP(_Register, _Index) \
  23. (MUSB_ENDPOINT_SETUP_OFFSET + ((_Index) << 3) + (_Register))
  24. //
  25. // This macro returns the proper non-indexed endpoint control/status register
  26. // for the given endpoint.
  27. //
  28. #define MUSB_ENDPOINT_CONTROL(_Register, _Index) \
  29. (MUSB_ENDPOINT_CONTROL_OFFSET + (_Index << 4) + ((_Register) - 0x10))
  30. //
  31. // This macro returns the register value for the given FIFO.
  32. //
  33. #define MUSB_FIFO_REGISTER(_Index) (MusbFifo0 + ((_Index) << 2))
  34. //
  35. // ---------------------------------------------------------------- Definitions
  36. //
  37. //
  38. // Define the maximum number of endpoints.
  39. //
  40. #define MUSB_MAX_ENDPOINTS 16
  41. //
  42. // Define the non-indexed register offsets.
  43. //
  44. #define MUSB_ENDPOINT_SETUP_OFFSET 0x80
  45. #define MUSB_ENDPOINT_CONTROL_OFFSET 0x100
  46. //
  47. // Define soft reset register bits.
  48. //
  49. #define MUSB_SOFT_RESET_SOFT_RESET 0x1
  50. //
  51. // Define endpoint info register bits.
  52. //
  53. #define MUSB_ENDPOINT_INFO_TX_COUNT_MASK 0x0F
  54. #define MUSB_ENDPOINT_INFO_RX_COUNT_MASK 0xF0
  55. #define MUSB_ENDPOINT_INFO_RX_COUNT_SHIFT 4
  56. //
  57. // Define power register bits.
  58. //
  59. #define MUSB_POWER_ENTER_SUSPEND 0x01
  60. #define MUSB_POWER_SUSPEND 0x02
  61. #define MUSB_POWER_RESUME 0x04
  62. #define MUSB_POWER_RESET 0x08
  63. #define MUSB_POWER_HIGH_SPEED 0x10
  64. #define MUSB_POWER_HIGH_SPEED_ENABLE 0x20
  65. #define MUSB_POWER_SOFT_CONNECT 0x40
  66. #define MUSB_POWER_ISO_UPDATE 0x80
  67. //
  68. // Define device control register bits
  69. //
  70. #define MUSB_DEVICE_CONTROL_SESSION 0x01
  71. #define MUSB_DEVICE_CONTROL_HOST_REQUEST 0x02
  72. #define MUSB_DEVICE_CONTROL_HOST 0x04
  73. #define MUSB_DEVICE_CONTROL_VBUS_SEND 0x08
  74. #define MUSB_DEVICE_CONTROL_VBUS_AVALID 0x10
  75. #define MUSB_DEVICE_CONTROL_LOW_SPEED 0x20
  76. #define MUSB_DEVICE_CONTROL_FULL_SPEED 0x40
  77. #define MUSB_DEVICE_CONTROL_DEVICE 0x80
  78. //
  79. // Define the TX Type register bits.
  80. //
  81. #define MUSB_TXTYPE_TARGET_ENDPOINT_MASK 0x0F
  82. #define MUSB_TXTYPE_PROTOCOL_CONTROL 0x00
  83. #define MUSB_TXTYPE_PROTOCOL_ISOCHRONOUS 0x10
  84. #define MUSB_TXTYPE_PROTOCOL_BULK 0x20
  85. #define MUSB_TXTYPE_PROTOCOL_INTERRUPT 0x30
  86. #define MUSB_TXTYPE_PROTOCOL_MASK 0x30
  87. #define MUSB_TXTYPE_SPEED_HIGH 0x40
  88. #define MUSB_TXTYPE_SPEED_FULL 0x80
  89. #define MUSB_TXTYPE_SPEED_LOW 0xC0
  90. #define MUSB_TXTYPE_SPEED_MASK 0xC0
  91. //
  92. // Define endpoint 0 control/status register bits.
  93. //
  94. #define MUSB_EP0_CONTROL_RX_PACKET_READY 0x0001
  95. #define MUSB_EP0_CONTROL_TX_PACKET_READY 0x0002
  96. #define MUSB_EP0_CONTROL_RX_STALL 0x0004
  97. #define MUSB_EP0_CONTROL_SETUP_PACKET 0x0008
  98. #define MUSB_EP0_CONTROL_ERROR 0x0010
  99. #define MUSB_EP0_CONTROL_REQUEST_PACKET 0x0020
  100. #define MUSB_EP0_CONTROL_STATUS_PACKET 0x0040
  101. #define MUSB_EP0_CONTROL_NAK_TIMEOUT 0x0080
  102. #define MUSB_EP0_CONTROL_FLUSH_FIFO 0x0100
  103. #define MUSB_EP0_CONTROL_DATA_TOGGLE 0x0200
  104. #define MUSB_EP0_CONTROL_DATA_TOGGLE_WRITE 0x0400
  105. #define MUSB_EP0_CONTROL_ERROR_MASK \
  106. (MUSB_EP0_CONTROL_RX_STALL | MUSB_EP0_CONTROL_ERROR | \
  107. MUSB_EP0_CONTROL_NAK_TIMEOUT)
  108. //
  109. // Define TX control/status register bits.
  110. //
  111. #define MUSB_TX_CONTROL_PACKET_READY 0x0001
  112. #define MUSB_TX_CONTROL_FIFO_NOT_EMPTY 0x0002
  113. #define MUSB_TX_CONTROL_ERROR 0x0004
  114. #define MUSB_TX_CONTROL_FLUSH_FIFO 0x0008
  115. #define MUSB_TX_CONTROL_RX_STALL 0x0020
  116. #define MUSB_TX_CONTROL_CLEAR_TOGGLE 0x0040
  117. #define MUSB_TX_CONTROL_NAK_TIMEOUT 0x0080
  118. #define MUSB_TX_CONTROL_DATA_TOGGLE 0x0100
  119. #define MUSB_TX_CONTROL_DATA_TOGGLE_WRITE 0x0200
  120. #define MUSB_TX_CONTROL_DMA_MODE 0x0400
  121. #define MUSB_TX_CONTROL_FORCE_DATA_TOGGLE 0x0800
  122. #define MUSB_TX_CONTROL_DMA_ENABLE 0x1000
  123. #define MUSB_TX_CONTROL_TRANSMIT_MODE 0x2000
  124. #define MUSB_TX_CONTROL_ISOCHRONOUS 0x4000
  125. #define MUSB_TX_CONTROL_AUTO_SET 0x8000
  126. #define MUSB_TX_CONTROL_ERROR_MASK \
  127. (MUSB_TX_CONTROL_ERROR | \
  128. MUSB_TX_CONTROL_RX_STALL | \
  129. MUSB_TX_CONTROL_NAK_TIMEOUT)
  130. //
  131. // Define RX control/status register bits.
  132. //
  133. #define MUSB_RX_CONTROL_PACKET_READY 0x0001
  134. #define MUSB_RX_CONTROL_FIFO_FULL 0x0002
  135. #define MUSB_RX_CONTROL_OVERRUN 0x0004
  136. #define MUSB_RX_CONTROL_ERROR 0x0004
  137. #define MUSB_RX_CONTROL_DATA_ERROR_NAK_TIMEOUT 0x0008
  138. #define MUSB_RX_CONTROL_FLUSH_FIFO 0x0010
  139. #define MUSB_RX_CONTROL_SEND_STALL 0x0020
  140. #define MUSB_RX_CONTROL_REQUEST_PACKET 0x0020
  141. #define MUSB_RX_CONTROL_SENT_STALL 0x0040
  142. #define MUSB_RX_CONTROL_RX_STALL 0x0040
  143. #define MUSB_RX_CONTROL_CLEAR_TOGGLE 0x0080
  144. #define MUSB_RX_CONTROL_DATA_TOGGLE 0x0200
  145. #define MUSB_RX_CONTROL_DATA_TOGGLE_WRITE 0x0400
  146. #define MUSB_RX_CONTROL_DMA_MODE 0x0800
  147. #define MUSB_RX_CONTROL_DISABLE_NYET 0x1000
  148. #define MUSB_RX_CONTROL_PID_ERROR 0x1000
  149. #define MUSB_RX_CONTROL_DMA_ENABLE 0x2000
  150. #define MUSB_RX_CONTROL_ISOCHRONOUS 0x4000
  151. #define MUSB_RX_CONTROL_AUTO_REQUEST 0x4000
  152. #define MUSB_RX_CONTROL_AUTO_CLEAR 0x8000
  153. #define MUSB_RX_CONTROL_ERROR_MASK \
  154. (MUSB_RX_CONTROL_ERROR | MUSB_RX_CONTROL_DATA_ERROR_NAK_TIMEOUT | \
  155. MUSB_RX_CONTROL_RX_STALL)
  156. //
  157. // Define common USB interrupt bits.
  158. //
  159. #define MUSB_USB_INTERRUPT_SUSPEND 0x01
  160. #define MUSB_USB_INTERRUPT_RESUME 0x02
  161. #define MUSB_USB_INTERRUPT_RESET_BABBLE 0x04
  162. #define MUSB_USB_INTERRUPT_SOF 0x08
  163. #define MUSB_USB_INTERRUPT_CONNECT 0x10
  164. #define MUSB_USB_INTERRUPT_DISCONNECT 0x20
  165. #define MUSB_USB_INTERRUPT_SESSION 0x40
  166. #define MUSB_USB_INTERRUPT_VBUS_ERROR 0x80
  167. //
  168. // Store the shift value to convert frames to microframes.
  169. //
  170. #define MUSB_MICROFRAMES_PER_FRAME 8
  171. #define MUSB_MICROFRAMES_PER_FRAME_SHIFT 3
  172. //
  173. // ------------------------------------------------------ Data Type Definitions
  174. //
  175. //
  176. // Define the base set of registers that can always be accessed.
  177. //
  178. typedef enum _MUSB_REGISTER {
  179. MusbFunctionAddress = 0x00,
  180. MusbPower = 0x01,
  181. MusbInterruptTx = 0x02,
  182. MusbInterruptRx = 0x04,
  183. MusbInterruptEnableTx = 0x06,
  184. MusbInterruptEnableRx = 0x08,
  185. MusbInterruptUsb = 0x0A,
  186. MusbInterruptEnableUsb = 0x0B,
  187. MusbFrame = 0x0C,
  188. MusbIndex = 0x0E,
  189. MusbTestMode = 0x0F,
  190. MusbFifo0 = 0x20,
  191. MusbDeviceControl = 0x60,
  192. MusbEndpointInfo = 0x78,
  193. MusbRamInfo = 0x79,
  194. MusbLinkInfo = 0x7A,
  195. MusbVpLength = 0x7B,
  196. MusbHighSpeedEof1 = 0x7C,
  197. MusbFullSpeedEof1 = 0x7D,
  198. MusbLowSpeedEof1 = 0x7E,
  199. MusbSoftReset = 0x7F,
  200. } MUSB_REGISTER, *PMUSB_REGISTER;
  201. //
  202. // Define the offsets for indexed registers. Software writes to the index
  203. // register and then can access this set of registers for the desired endpoint.
  204. //
  205. typedef enum _MUSB_INDEXED_REGISTER {
  206. MusbTxMaxPacketSize = 0x10,
  207. MusbTxControlStatus = 0x12,
  208. MusbRxMaxPacketSize = 0x14,
  209. MusbRxControlStatus = 0x16,
  210. MusbCount = 0x18,
  211. MusbTxType = 0x1A,
  212. MusbNakLimit = 0x1B,
  213. MusbTxInterval = 0x1B,
  214. MusbRxType = 0x1C,
  215. MusbRxInterval = 0x1D,
  216. MusbConfigData = 0x1F,
  217. MusbTxFifoSize = 0x62,
  218. MusbRxFifoSize = 0x63,
  219. MusbTxFifoAddress = 0x64,
  220. MusbRxFifoAddress = 0x66
  221. } MUSB_INDEXED_REGISTER, *PMUSB_INDEXED_REGISTER;
  222. //
  223. // Define the offsets for the non-indexed endpoint setup registers, with 0
  224. // being the start of the register region.
  225. //
  226. typedef enum _MUSB_ENDPOINT_SETUP_REGISTER {
  227. MusbTxFunctionAddress = 0x00,
  228. MusbTxHubAddress = 0x02,
  229. MusbTxHubPort = 0x03,
  230. MusbRxFunctionAddress = 0x04,
  231. MusbRxHubAddress = 0x06,
  232. MusbRxHubPort = 0x07
  233. } MUSB_ENDPOINT_SETUP_REGISTER, *PMUSB_ENDPOINT_SETUP_REGISTER;
  234. //
  235. // -------------------------------------------------------------------- Globals
  236. //
  237. //
  238. // -------------------------------------------------------- Function Prototypes
  239. //