mt_ssusb.h 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  1. /*
  2. * Copyright (c) 2012 MediaTek Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files
  6. * (the "Software"), to deal in the Software without restriction,
  7. * including without limitation the rights to use, copy, modify, merge,
  8. * publish, distribute, sublicense, and/or sell copies of the Software,
  9. * and to permit persons to whom the Software is furnished to do so,
  10. * subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  20. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  21. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #ifndef _MT6771_USB_H_
  24. #define _MT6771_USB_H_
  25. #include <dev/udc.h>
  26. #include <platform/mt_typedefs.h>
  27. #include <platform/mt_gpt.h>
  28. #include <platform/mt_irq.h>
  29. /* USB registers */
  30. /* APB Module ssusb_top - USB3_BASE */
  31. #define SSUSB_DEV_BASE (USB3_BASE + 0x1000)
  32. #define SSUSB_EPCTL_CSR_BASE (USB3_BASE + 0x1800)
  33. #define SSUSB_USB3_MAC_CSR_BASE (USB3_BASE + 0x2400)
  34. #define SSUSB_USB3_SYS_CSR_BASE (USB3_BASE + 0x2400)
  35. #define SSUSB_USB2_CSR_BASE (USB3_BASE + 0x3400)
  36. #if defined(USB3_PHY_SIFV1)
  37. #define SSUSB_SIFSLV_IPPC_BASE (USB3_SIF_BASE + 0x0700)
  38. /* APB Module ssusb_top_sif - USB3_SIF_BASE */
  39. #define SSUSB_SIFSLV_SPLLC_BASE (USB3_SIF2_BASE + 0x000)
  40. #define SSUSB_SIFSLV_U2PHY_COM_BASE (USB3_SIF2_BASE + 0x800)
  41. #define SSUSB_SIFSLV_U3PHYD_BASE (USB3_SIF2_BASE + 0x900)
  42. /* APB Module ssusb_top_sif2 - USB3_SIF2_BASE */
  43. #define SSUSB_SIFSLV_U2PHY_COM_SIV_B_BASE (USB3_SIF2_BASE + 0x800)
  44. #define SSUSB_USB30_PHYA_SIV_B2_BASE (USB3_SIF2_BASE + 0xA00)
  45. #define SSUSB_USB30_PHYA_SIV_B_BASE (USB3_SIF2_BASE + 0xB00)
  46. #define SSUSB_SIFSLV_U3PHYA_DA_BASE (USB3_SIF2_BASE + 0xC00)
  47. #endif
  48. #if defined(USB3_PHY_SIFV2)
  49. #define SSUSB_SIFSLV_IPPC_BASE (USB3_BASE + 0x3E00)
  50. /* APB Module ssusb_top_sif - USB3_SIF_BASE */
  51. #define SSUSB_SIFSLV_U2PHY_COM_BASE (USB3_SIF_BASE + 0x300)
  52. #define SSUSB_SIFSLV_U2PHY_COM_SIV_B_BASE (USB3_SIF_BASE + 0x300)
  53. #define SSUSB_SIFSLV_SPLLC_BASE (USB3_SIF_BASE + 0x700)
  54. #define SSUSB_SIFSLV_U3PHYD_BASE (USB3_SIF_BASE + 0x900)
  55. #define SSUSB_USB30_PHYA_SIV_B2_BASE (USB3_SIF_BASE + 0xA00)
  56. #define SSUSB_USB30_PHYA_SIV_B_BASE (USB3_SIF_BASE + 0xB00)
  57. #define SSUSB_SIFSLV_U3PHYA_DA_BASE (USB3_SIF_BASE + 0xC00)
  58. #endif
  59. /* USB3 support */
  60. /* please define in platform/rules.mk or in target settings */
  61. //#define SUPPORT_U3
  62. #define SUPPORT_QMU
  63. //#define DBG_USB_QMU
  64. //#define DBG_USB_PHY
  65. //#define SUPPORT_DMA
  66. #define POWER_SAVING_MODE
  67. #define U2_U3_SWITCH
  68. #define EXT_VBUS_DET
  69. #define MT_EP_NUM 4
  70. #define MT_CHAN_NUM 4
  71. #define MT_EP0_FIFOSIZE 64
  72. #define MAX_EP_NUM 4
  73. #ifdef SUPPORT_U3
  74. /* EP0, TX, RX has separate SRAMs */
  75. #define USB_TX_FIFO_START_ADDRESS 0
  76. #define USB_RX_FIFO_START_ADDRESS 0
  77. #else
  78. /* EP0, TX, RX share one SRAM. 0-63 bytes are reserved for EP0 */
  79. #define USB_TX_FIFO_START_ADDRESS (64)
  80. #define USB_RX_FIFO_START_ADDRESS (64+512*MAX_EP_NUM)
  81. #endif
  82. #define EP0_MAX_PACKET_SIZE 64
  83. #define EP0_MAX_PACKET_SIZE_U3 512
  84. #define MT_BULK_MAXP 512
  85. #define MT_INT_MAXP 1024
  86. #ifdef MACH_FPGA
  87. #define CFG_FPGA_PLATFORM (1)
  88. #else
  89. #define DBG_PHY_CALIBRATION 1
  90. #endif
  91. /* choose the USB3 here when doing FPGA porting */
  92. #if CFG_FPGA_PLATFORM
  93. //#define CONFIG_A60810_SUPPORT
  94. //#define CONFIG_D60802_SUPPORT
  95. //#define CONFIG_E60802_SUPPORT
  96. #endif
  97. /* Higher level functions for abstracting away from specific device */
  98. void mt_udc_irq (
  99. unsigned int ltssm,
  100. unsigned int intrusb,
  101. unsigned int dmaintr,
  102. unsigned short intrtx,
  103. unsigned short intrrx,
  104. unsigned int intrqmu,
  105. unsigned int intrqmudone,
  106. unsigned int linkint);
  107. /* SSUSB_DEV REGISTER DEFINITION */
  108. #define U3D_LV1ISR (SSUSB_DEV_BASE+0x0000)
  109. #define U3D_LV1IER (SSUSB_DEV_BASE+0x0004)
  110. #define U3D_LV1IESR (SSUSB_DEV_BASE+0x0008)
  111. #define U3D_LV1IECR (SSUSB_DEV_BASE+0x000C)
  112. #define U3D_MAC_U1_EN_CTRL (SSUSB_DEV_BASE+0x0030)
  113. #define U3D_MAC_U2_EN_CTRL (SSUSB_DEV_BASE+0x0034)
  114. #define U3D_SRAM_DBG_CTRL (SSUSB_DEV_BASE+0x0040)
  115. #define U3D_SRAM_DBG_CTRL_1 (SSUSB_DEV_BASE+0x0044)
  116. #define U3D_RISC_SIZE (SSUSB_DEV_BASE+0x0050)
  117. #define U3D_WRBUF_ERR_STS (SSUSB_DEV_BASE+0x0070)
  118. #define U3D_BUF_ERR_EN (SSUSB_DEV_BASE+0x0074)
  119. #define U3D_EPISR (SSUSB_DEV_BASE+0x0080)
  120. #define U3D_EPIER (SSUSB_DEV_BASE+0x0084)
  121. #define U3D_EPIESR (SSUSB_DEV_BASE+0x0088)
  122. #define U3D_EPIECR (SSUSB_DEV_BASE+0x008C)
  123. #define U3D_DMAISR (SSUSB_DEV_BASE+0x0090)
  124. #define U3D_DMAIER (SSUSB_DEV_BASE+0x0094)
  125. #define U3D_DMAIESR (SSUSB_DEV_BASE+0x0098)
  126. #define U3D_DMAIECR (SSUSB_DEV_BASE+0x009C)
  127. #define U3D_EP0DMACTRL (SSUSB_DEV_BASE+0x00C0)
  128. #define U3D_EP0DMASTRADDR (SSUSB_DEV_BASE+0x00C4)
  129. #define U3D_EP0DMATFRCOUNT (SSUSB_DEV_BASE+0x00C8)
  130. #define U3D_EP0DMARLCOUNT (SSUSB_DEV_BASE+0x00CC)
  131. #define U3D_TXDMACTRL (SSUSB_DEV_BASE+0x00D0)
  132. #define U3D_TXDMASTRADDR (SSUSB_DEV_BASE+0x00D4)
  133. #define U3D_TXDMATRDCNT (SSUSB_DEV_BASE+0x00D8)
  134. #define U3D_TXDMARLCOUNT (SSUSB_DEV_BASE+0x00DC)
  135. #define U3D_RXDMACTRL (SSUSB_DEV_BASE+0x00E0)
  136. #define U3D_RXDMASTRADDR (SSUSB_DEV_BASE+0x00E4)
  137. #define U3D_RXDMATRDCNT (SSUSB_DEV_BASE+0x00E8)
  138. #define U3D_RXDMARLCOUNT (SSUSB_DEV_BASE+0x00EC)
  139. #define U3D_EP0CSR (SSUSB_DEV_BASE+0x0100)
  140. #define U3D_RXCOUNT0 (SSUSB_DEV_BASE+0x0108)
  141. #define U3D_RESERVED (SSUSB_DEV_BASE+0x010C)
  142. /* U3D_TX(ep)CSR(x): ep(1-15), offset: 0x110-0x1f8 */
  143. #define U3D_TXCSR_OFFSET (SSUSB_DEV_BASE+0x0100)
  144. /*
  145. #define U3D_TX(ep)CSR_OFFSET (U3D_TXCSR_OFFSET + ((ep) * (0x10)))
  146. #define U3D_TX(ep)CSR(x) ((U3D_TX(ep)CSR_OFFSET) + ((x) * 0x4))
  147. */
  148. #define U3D_TX1CSR0 (SSUSB_DEV_BASE+0x0110)
  149. #define U3D_TX1CSR1 (SSUSB_DEV_BASE+0x0114)
  150. #define U3D_TX1CSR2 (SSUSB_DEV_BASE+0x0118)
  151. #define U3D_TX2CSR0 (SSUSB_DEV_BASE+0x0120)
  152. #define U3D_TX2CSR1 (SSUSB_DEV_BASE+0x0124)
  153. #define U3D_TX2CSR2 (SSUSB_DEV_BASE+0x0128)
  154. #define U3D_TX3CSR0 (SSUSB_DEV_BASE+0x0130)
  155. #define U3D_TX3CSR1 (SSUSB_DEV_BASE+0x0134)
  156. #define U3D_TX3CSR2 (SSUSB_DEV_BASE+0x0138)
  157. #define U3D_TX4CSR0 (SSUSB_DEV_BASE+0x0140)
  158. #define U3D_TX4CSR1 (SSUSB_DEV_BASE+0x0144)
  159. #define U3D_TX4CSR2 (SSUSB_DEV_BASE+0x0148)
  160. #define U3D_TX5CSR0 (SSUSB_DEV_BASE+0x0150)
  161. #define U3D_TX5CSR1 (SSUSB_DEV_BASE+0x0154)
  162. #define U3D_TX5CSR2 (SSUSB_DEV_BASE+0x0158)
  163. #define U3D_TX6CSR0 (SSUSB_DEV_BASE+0x0160)
  164. #define U3D_TX6CSR1 (SSUSB_DEV_BASE+0x0164)
  165. #define U3D_TX6CSR2 (SSUSB_DEV_BASE+0x0168)
  166. #define U3D_TX7CSR0 (SSUSB_DEV_BASE+0x0170)
  167. #define U3D_TX7CSR1 (SSUSB_DEV_BASE+0x0174)
  168. #define U3D_TX7CSR2 (SSUSB_DEV_BASE+0x0178)
  169. #define U3D_TX8CSR0 (SSUSB_DEV_BASE+0x0180)
  170. #define U3D_TX8CSR1 (SSUSB_DEV_BASE+0x0184)
  171. #define U3D_TX8CSR2 (SSUSB_DEV_BASE+0x0188)
  172. #define U3D_TX9CSR0 (SSUSB_DEV_BASE+0x0190)
  173. #define U3D_TX9CSR1 (SSUSB_DEV_BASE+0x0194)
  174. #define U3D_TX9CSR2 (SSUSB_DEV_BASE+0x0198)
  175. #define U3D_TX10CSR0 (SSUSB_DEV_BASE+0x01A0)
  176. #define U3D_TX10CSR1 (SSUSB_DEV_BASE+0x01A4)
  177. #define U3D_TX10CSR2 (SSUSB_DEV_BASE+0x01A8)
  178. #define U3D_TX11CSR0 (SSUSB_DEV_BASE+0x01B0)
  179. #define U3D_TX11CSR1 (SSUSB_DEV_BASE+0x01B4)
  180. #define U3D_TX11CSR2 (SSUSB_DEV_BASE+0x01B8)
  181. #define U3D_TX12CSR0 (SSUSB_DEV_BASE+0x01C0)
  182. #define U3D_TX12CSR1 (SSUSB_DEV_BASE+0x01C4)
  183. #define U3D_TX12CSR2 (SSUSB_DEV_BASE+0x01C8)
  184. #define U3D_TX13CSR0 (SSUSB_DEV_BASE+0x01D0)
  185. #define U3D_TX13CSR1 (SSUSB_DEV_BASE+0x01D4)
  186. #define U3D_TX13CSR2 (SSUSB_DEV_BASE+0x01D8)
  187. #define U3D_TX14CSR0 (SSUSB_DEV_BASE+0x01E0)
  188. #define U3D_TX14CSR1 (SSUSB_DEV_BASE+0x01E4)
  189. #define U3D_TX14CSR2 (SSUSB_DEV_BASE+0x01E8)
  190. #define U3D_TX15CSR0 (SSUSB_DEV_BASE+0x01F0)
  191. #define U3D_TX15CSR1 (SSUSB_DEV_BASE+0x01F4)
  192. #define U3D_TX15CSR2 (SSUSB_DEV_BASE+0x01F8)
  193. /* U3D_RX(ep)CSR(x): ep(1-15), offset: 0x210-0x2f8 */
  194. #define U3D_RXCSR_OFFSET (SSUSB_DEV_BASE+0x0200)
  195. /*
  196. #define U3D_RX(ep)CSR_OFFSET (U3D_RXCSR_OFFSET + ((ep) * (0x10)))
  197. #define U3D_RX(ep)CSR(x) ((U3D_RX(ep)CSR_OFFSET) + ((x) * 0x4))
  198. */
  199. #define U3D_RX1CSR0 (SSUSB_DEV_BASE+0x0210)
  200. #define U3D_RX1CSR1 (SSUSB_DEV_BASE+0x0214)
  201. #define U3D_RX1CSR2 (SSUSB_DEV_BASE+0x0218)
  202. #define U3D_RX1CSR3 (SSUSB_DEV_BASE+0x021C)
  203. #define U3D_RX2CSR0 (SSUSB_DEV_BASE+0x0220)
  204. #define U3D_RX2CSR1 (SSUSB_DEV_BASE+0x0224)
  205. #define U3D_RX2CSR2 (SSUSB_DEV_BASE+0x0228)
  206. #define U3D_RX2CSR3 (SSUSB_DEV_BASE+0x022C)
  207. #define U3D_RX3CSR0 (SSUSB_DEV_BASE+0x0230)
  208. #define U3D_RX3CSR1 (SSUSB_DEV_BASE+0x0234)
  209. #define U3D_RX3CSR2 (SSUSB_DEV_BASE+0x0238)
  210. #define U3D_RX3CSR3 (SSUSB_DEV_BASE+0x023C)
  211. #define U3D_RX4CSR0 (SSUSB_DEV_BASE+0x0240)
  212. #define U3D_RX4CSR1 (SSUSB_DEV_BASE+0x0244)
  213. #define U3D_RX4CSR2 (SSUSB_DEV_BASE+0x0248)
  214. #define U3D_RX4CSR3 (SSUSB_DEV_BASE+0x024C)
  215. #define U3D_RX5CSR0 (SSUSB_DEV_BASE+0x0250)
  216. #define U3D_RX5CSR1 (SSUSB_DEV_BASE+0x0254)
  217. #define U3D_RX5CSR2 (SSUSB_DEV_BASE+0x0258)
  218. #define U3D_RX5CSR3 (SSUSB_DEV_BASE+0x025C)
  219. #define U3D_RX6CSR0 (SSUSB_DEV_BASE+0x0260)
  220. #define U3D_RX6CSR1 (SSUSB_DEV_BASE+0x0264)
  221. #define U3D_RX6CSR2 (SSUSB_DEV_BASE+0x0268)
  222. #define U3D_RX6CSR3 (SSUSB_DEV_BASE+0x026C)
  223. #define U3D_RX7CSR0 (SSUSB_DEV_BASE+0x0270)
  224. #define U3D_RX7CSR1 (SSUSB_DEV_BASE+0x0274)
  225. #define U3D_RX7CSR2 (SSUSB_DEV_BASE+0x0278)
  226. #define U3D_RX7CSR3 (SSUSB_DEV_BASE+0x027C)
  227. #define U3D_RX8CSR0 (SSUSB_DEV_BASE+0x0280)
  228. #define U3D_RX8CSR1 (SSUSB_DEV_BASE+0x0284)
  229. #define U3D_RX8CSR2 (SSUSB_DEV_BASE+0x0288)
  230. #define U3D_RX8CSR3 (SSUSB_DEV_BASE+0x028C)
  231. #define U3D_RX9CSR0 (SSUSB_DEV_BASE+0x0290)
  232. #define U3D_RX9CSR1 (SSUSB_DEV_BASE+0x0294)
  233. #define U3D_RX9CSR2 (SSUSB_DEV_BASE+0x0298)
  234. #define U3D_RX9CSR3 (SSUSB_DEV_BASE+0x029C)
  235. #define U3D_RX10CSR0 (SSUSB_DEV_BASE+0x02A0)
  236. #define U3D_RX10CSR1 (SSUSB_DEV_BASE+0x02A4)
  237. #define U3D_RX10CSR2 (SSUSB_DEV_BASE+0x02A8)
  238. #define U3D_RX10CSR3 (SSUSB_DEV_BASE+0x02AC)
  239. #define U3D_RX11CSR0 (SSUSB_DEV_BASE+0x02B0)
  240. #define U3D_RX11CSR1 (SSUSB_DEV_BASE+0x02B4)
  241. #define U3D_RX11CSR2 (SSUSB_DEV_BASE+0x02B8)
  242. #define U3D_RX11CSR3 (SSUSB_DEV_BASE+0x02BC)
  243. #define U3D_RX12CSR0 (SSUSB_DEV_BASE+0x02C0)
  244. #define U3D_RX12CSR1 (SSUSB_DEV_BASE+0x02C4)
  245. #define U3D_RX12CSR2 (SSUSB_DEV_BASE+0x02C8)
  246. #define U3D_RX12CSR3 (SSUSB_DEV_BASE+0x02CC)
  247. #define U3D_RX13CSR0 (SSUSB_DEV_BASE+0x02D0)
  248. #define U3D_RX13CSR1 (SSUSB_DEV_BASE+0x02D4)
  249. #define U3D_RX13CSR2 (SSUSB_DEV_BASE+0x02D8)
  250. #define U3D_RX13CSR3 (SSUSB_DEV_BASE+0x02DC)
  251. #define U3D_RX14CSR0 (SSUSB_DEV_BASE+0x02E0)
  252. #define U3D_RX14CSR1 (SSUSB_DEV_BASE+0x02E4)
  253. #define U3D_RX14CSR2 (SSUSB_DEV_BASE+0x02E8)
  254. #define U3D_RX14CSR3 (SSUSB_DEV_BASE+0x02EC)
  255. #define U3D_RX15CSR0 (SSUSB_DEV_BASE+0x02F0)
  256. #define U3D_RX15CSR1 (SSUSB_DEV_BASE+0x02F4)
  257. #define U3D_RX15CSR2 (SSUSB_DEV_BASE+0x02F8)
  258. #define U3D_RX15CSR3 (SSUSB_DEV_BASE+0x02FC)
  259. /* U3D_FIFO: ep(0-15), offset: 0x300-0x3f0 */
  260. #define U3D_FIFO_OFFSET (SSUSB_DEV_BASE + 0x0300)
  261. #define U3D_FIFO(x) (U3D_FIFO_OFFSET + ((x) * 0x10))
  262. #define USB_FIFO(x) (U3D_FIFO(x))
  263. /* U3D_QCR: (0-3), offset: 0x400-0x40c */
  264. #if 0
  265. #define U3D_QCR_OFFSET (SSUSB_DEV_BASE+0x0400)
  266. #define U3D_QCR(x) (U3D_QCR_OFFSET + ((x) * 0x4))
  267. #endif
  268. #define U3D_QCR0 (SSUSB_DEV_BASE+0x0400)
  269. #define U3D_QCR1 (SSUSB_DEV_BASE+0x0404)
  270. #define U3D_QCR2 (SSUSB_DEV_BASE+0x0408)
  271. #define U3D_QCR3 (SSUSB_DEV_BASE+0x040C)
  272. /* U3D_QGCSR: offset: 0x410 */
  273. #define U3D_QGCSR (SSUSB_DEV_BASE+0x0410)
  274. /* U3D_TXQCSR: ep(1-15), offset: 0x510-0x5f8 */
  275. #define U3D_TXQCSR_OFFSET (SSUSB_DEV_BASE + 0x0500)
  276. #define U3D_TXQCSR(x) (U3D_TXQCSR_OFFSET + ((x) * 0x10))
  277. #define U3D_TXQSAR(x) (U3D_TXQCSR(x) + 0x4)
  278. #define U3D_TXQCPR(x) (U3D_TXQCSR(x) + 0x8)
  279. /* U3D_RXQCSR: ep(1-15), offset: 0x610-0x5f8 */
  280. #define U3D_RXQCSR_OFFSET (SSUSB_DEV_BASE + 0x0600)
  281. #define U3D_RXQCSR(x) (U3D_RXQCSR_OFFSET + ((x) * 0x10))
  282. #define U3D_RXQSAR(x) (U3D_RXQCSR(x) + 0x4)
  283. #define U3D_RXQCPR(x) (U3D_RXQCSR(x) + 0x8)
  284. #define U3D_RXQLDPR(x) (U3D_RXQCSR(x) + 0xC)
  285. #define U3D_QISAR0 (SSUSB_DEV_BASE+0x0700)
  286. #define U3D_QIER0 (SSUSB_DEV_BASE+0x0704)
  287. #define U3D_QIESR0 (SSUSB_DEV_BASE+0x0708)
  288. #define U3D_QIECR0 (SSUSB_DEV_BASE+0x070C)
  289. #define U3D_QISAR1 (SSUSB_DEV_BASE+0x0710)
  290. #define U3D_QIER1 (SSUSB_DEV_BASE+0x0714)
  291. #define U3D_QIESR1 (SSUSB_DEV_BASE+0x0718)
  292. #define U3D_QIECR1 (SSUSB_DEV_BASE+0x071C)
  293. #define U3D_QEMIR (SSUSB_DEV_BASE+0x0740)
  294. #define U3D_QEMIER (SSUSB_DEV_BASE+0x0744)
  295. #define U3D_QEMIESR (SSUSB_DEV_BASE+0x0748)
  296. #define U3D_QEMIECR (SSUSB_DEV_BASE+0x074C)
  297. #define U3D_TQERRIR0 (SSUSB_DEV_BASE+0x0780)
  298. #define U3D_TQERRIER0 (SSUSB_DEV_BASE+0x0784)
  299. #define U3D_TQERRIESR0 (SSUSB_DEV_BASE+0x0788)
  300. #define U3D_TQERRIECR0 (SSUSB_DEV_BASE+0x078C)
  301. #define U3D_RQERRIR0 (SSUSB_DEV_BASE+0x07C0)
  302. #define U3D_RQERRIER0 (SSUSB_DEV_BASE+0x07C4)
  303. #define U3D_RQERRIESR0 (SSUSB_DEV_BASE+0x07C8)
  304. #define U3D_RQERRIECR0 (SSUSB_DEV_BASE+0x07CC)
  305. #define U3D_RQERRIR1 (SSUSB_DEV_BASE+0x07D0)
  306. #define U3D_RQERRIER1 (SSUSB_DEV_BASE+0x07D4)
  307. #define U3D_RQERRIESR1 (SSUSB_DEV_BASE+0x07D8)
  308. #define U3D_RQERRIECR1 (SSUSB_DEV_BASE+0x07DC)
  309. #define U3D_CAP_EP0FFSZ (SSUSB_DEV_BASE+0x0C04)
  310. #define U3D_CAP_EPNTXFFSZ (SSUSB_DEV_BASE+0x0C08)
  311. #define U3D_CAP_EPNRXFFSZ (SSUSB_DEV_BASE+0x0C0C)
  312. #define U3D_CAP_EPINFO (SSUSB_DEV_BASE+0x0C10)
  313. #define U3D_CAP_TX_SLOT1 (SSUSB_DEV_BASE+0x0C20)
  314. #define U3D_CAP_TX_SLOT2 (SSUSB_DEV_BASE+0x0C24)
  315. #define U3D_CAP_TX_SLOT3 (SSUSB_DEV_BASE+0x0C28)
  316. #define U3D_CAP_TX_SLOT4 (SSUSB_DEV_BASE+0x0C2C)
  317. #define U3D_CAP_RX_SLOT1 (SSUSB_DEV_BASE+0x0C30)
  318. #define U3D_CAP_RX_SLOT2 (SSUSB_DEV_BASE+0x0C34)
  319. #define U3D_CAP_RX_SLOT3 (SSUSB_DEV_BASE+0x0C38)
  320. #define U3D_CAP_RX_SLOT4 (SSUSB_DEV_BASE+0x0C3C)
  321. #define U3D_MISC_CTRL (SSUSB_DEV_BASE+0x0C84)
  322. /* U3D_EPISR */
  323. #define EPRISR (0x7fff << 17) /* 31:17 */
  324. #define SETUPENDISR (0x1 << 16) /* 16:16 */
  325. #define EPTISR (0x7fff << 1) /* 15:1 */
  326. #define EP0ISR (0x1 << 0) /* 0:0 */
  327. /* U3D_EP0CSR */
  328. #define EP0_EP_RESET (0x1 << 31) /* 31:31 */
  329. #define EP0_AUTOCLEAR (0x1 << 30) /* 30:30 */
  330. #define EP0_AUTOSET (0x1 << 29) /* 29:29 */
  331. #define EP0_DMAREQEN (0x1 << 28) /* 28:28 */
  332. #define EP0_SENDSTALL (0x1 << 25) /* 25:25 */
  333. #define EP0_FIFOFULL (0x1 << 23) /* 23:23 */
  334. #define EP0_SENTSTALL (0x1 << 22) /* 22:22 */
  335. #define EP0_DPHTX (0x1 << 20) /* 20:20 */
  336. #define EP0_DATAEND (0x1 << 19) /* 19:19 */
  337. #define EP0_TXPKTRDY (0x1 << 18) /* 18:18 */
  338. #define EP0_SETUPPKTRDY (0x1 << 17) /* 17:17 */
  339. #define EP0_RXPKTRDY (0x1 << 16) /* 16:16 */
  340. #define EP0_MAXPKTSZ0 (0x3ff << 0) /* 9:0 */
  341. #define EP0_W1C_BITS (~(EP0_RXPKTRDY | EP0_SETUPPKTRDY | EP0_SENTSTALL))
  342. /* U3D_LV1ISR */
  343. #define EP_CTRL_INTR (0x1 << 5) /* 5:5 */
  344. #define MAC2_INTR (0x1 << 4) /* 4:4 */
  345. #define DMA_INTR (0x1 << 3) /* 3:3 */
  346. #define MAC3_INTR (0x1 << 2) /* 2:2 */
  347. #define QMU_INTR (0x1 << 1) /* 1:1 */
  348. #define BMU_INTR (0x1 << 0) /* 0:0 */
  349. /* U3D_DMAIESR */
  350. #define RXDMAIESR (0x1 << 2) /* 2:2 */
  351. #define TXDMAIESR (0x1 << 1) /* 1:1 */
  352. #define EP0DMAIESR (0x1 << 0) /* 0:0 */
  353. /* U3D_TX1CSR0(TX1~TX15 are identical) */
  354. #define TX_EP_RESET (0x1 << 31) /* 31:31 */
  355. #define TX_AUTOSET (0x1 << 30) /* 30:30 */
  356. #define TX_DMAREQEN (0x1 << 29) /* 29:29 */
  357. #define TX_FIFOFULL (0x1 << 25) /* 25:25 */
  358. #define TX_FIFOEMPTY (0x1 << 24) /* 24:24 */
  359. #define TX_SENTSTALL (0x1 << 22) /* 22:22 */
  360. #define TX_SENDSTALL (0x1 << 21) /* 21:21 */
  361. #define TX_TXPKTRDY (0x1 << 16) /* 16:16 */
  362. #define TX_TXMAXPKTSZ (0x7ff << 0) /* 10:0 */
  363. #define TX_W1C_BITS (~(TX_SENTSTALL))
  364. /* U3D_TX1CSR1(TX1~TX15 are identical) */
  365. #define TX_MULT (0x3 << 22) /* 23:22 */
  366. #define TX_MAX_PKT (0x3f << 16) /* 21:16 */
  367. #define TX_SLOT (0x3f << 8) /* 13:8 */
  368. #define TXTYPE (0x3 << 4) /* 5:4 */
  369. #define SS_TX_BURST (0xf << 0) /* 3:0 */
  370. #define TX_MULT_OFST (22)
  371. #define TX_MAX_PKT_OFST (16)
  372. #define TX_SLOT_OFST (8)
  373. #define TXTYPE_OFST (4)
  374. #define SS_TX_BURST_OFST (0)
  375. /* U3D_TX1CSR2(TX1~TX15 are identical) */
  376. #define TXBINTERVAL (0xff << 24) /* 31:24 */
  377. #define TXFIFOSEGSIZE (0xf << 16) /* 19:16 */
  378. #define TXFIFOADDR (0x1fff << 0) /* 12:0 */
  379. #define TXBINTERVAL_OFST (24)
  380. #define TXFIFOSEGSIZE_OFST (16)
  381. #define TXFIFOADDR_OFST (0)
  382. /* U3D_RX1CSR0(RX1~RX15 are identical) */
  383. #define RX_EP_RESET (0x1 << 31) /* 31:31 */
  384. #define RX_AUTOCLEAR (0x1 << 30) /* 30:30 */
  385. #define RX_DMAREQEN (0x1 << 29) /* 29:29 */
  386. #define RX_SENTSTALL (0x1 << 22) /* 22:22 */
  387. #define RX_SENDSTALL (0x1 << 21) /* 21:21 */
  388. #define RX_FIFOFULL (0x1 << 18) /* 18:18 */
  389. #define RX_FIFOEMPTY (0x1 << 17) /* 17:17 */
  390. #define RX_RXPKTRDY (0x1 << 16) /* 16:16 */
  391. #define RX_RXMAXPKTSZ (0x7ff << 0) /* 10:0 */
  392. #define RX_W1C_BITS (~(RX_SENTSTALL|RX_RXPKTRDY))
  393. /* U3D_RX1CSR1(RX1~RX15 are identical) */
  394. #define RX_MULT (0x3 << 22) /* 23:22 */
  395. #define RX_MAX_PKT (0x3f << 16) /* 21:16 */
  396. #define RX_SLOT (0x3f << 8) /* 13:8 */
  397. #define RX_TYPE (0x3 << 4) /* 5:4 */
  398. #define SS_RX_BURST (0xf << 0) /* 3:0 */
  399. #define RX_MULT_OFST (22)
  400. #define RX_MAX_PKT_OFST (16)
  401. #define RX_SLOT_OFST (8)
  402. #define RX_TYPE_OFST (4)
  403. #define SS_RX_BURST_OFST (0)
  404. /* U3D_RX1CSR2(RX1~RX15 are identical) */
  405. #define RXBINTERVAL (0xff << 24) /* 31:24 */
  406. #define RXFIFOSEGSIZE (0xf << 16) /* 19:16 */
  407. #define RXFIFOADDR (0x1fff << 0) /* 12:0 */
  408. #define RXBINTERVAL_OFST (24)
  409. #define RXFIFOSEGSIZE_OFST (16)
  410. #define RXFIFOADDR_OFST (0)
  411. /* U3D_RX1CSR3(RX1~RX15 are identical) */
  412. #define EP_RX_COUNT (0x7ff << 16) /* 26:16 */
  413. #define EP_RX_COUNT_OFST (16)
  414. /* SSUSB_USB2_CSR REGISTER DEFINITION */
  415. #define U3D_XHCI_PORT_CTRL (SSUSB_USB2_CSR_BASE+0x0000)
  416. #define U3D_POWER_MANAGEMENT (SSUSB_USB2_CSR_BASE+0x0004)
  417. #define U3D_TIMING_TEST_MODE (SSUSB_USB2_CSR_BASE+0x0008)
  418. #define U3D_DEVICE_CONTROL (SSUSB_USB2_CSR_BASE+0x000C)
  419. #define U3D_POWER_UP_COUNTER (SSUSB_USB2_CSR_BASE+0x0010)
  420. #define U3D_USB2_TEST_MODE (SSUSB_USB2_CSR_BASE+0x0014)
  421. #define U3D_COMMON_USB_INTR_ENABLE (SSUSB_USB2_CSR_BASE+0x0018)
  422. #define U3D_COMMON_USB_INTR (SSUSB_USB2_CSR_BASE+0x001C)
  423. #define U3D_USB_BUS_PERFORMANCE (SSUSB_USB2_CSR_BASE+0x0020)
  424. #define U3D_LINK_RESET_INFO (SSUSB_USB2_CSR_BASE+0x0024)
  425. #define U3D_RESET_RESUME_TIME_VALUE (SSUSB_USB2_CSR_BASE+0x0034)
  426. #define U3D_UTMI_SIGNAL_SEL (SSUSB_USB2_CSR_BASE+0x0038)
  427. #define U3D_USB20_FRAME_NUM (SSUSB_USB2_CSR_BASE+0x003C)
  428. #define U3D_USB20_TIMING_PARAM (SSUSB_USB2_CSR_BASE+0x0040)
  429. #define U3D_USB20_LPM_PARAM (SSUSB_USB2_CSR_BASE+0x0044)
  430. #define U3D_USB20_LPM_ENTRY_COUNT (SSUSB_USB2_CSR_BASE+0x0048)
  431. #define U3D_USB20_MISC_CONTROL (SSUSB_USB2_CSR_BASE+0x004C)
  432. #define U3D_USB20_LPM_TIMING_PARAM (SSUSB_USB2_CSR_BASE+0x0050)
  433. /* U3D_USB20_MISC_CONTROL */
  434. #define LPM_U3_ACK_EN (0x1 << 0) /* 0:0 */
  435. /* U3D_COMMON_USB_INTR_ENABLE */
  436. #define LPM_RESUME_INTR_EN (0x1 << 9) /* 9:9 */
  437. #define LPM_INTR_EN (0x1 << 8) /* 8:8 */
  438. #define VBUSERR_INTR_EN (0x1 << 7) /* 7:7 */
  439. #define SESSION_REQ_INTR_EN (0x1 << 6) /* 6:6 */
  440. #define DISCONN_INTR_EN (0x1 << 5) /* 5:5 */
  441. #define CONN_INTR_EN (0x1 << 4) /* 4:4 */
  442. #define SOF_INTR_EN (0x1 << 3) /* 3:3 */
  443. #define RESET_INTR_EN (0x1 << 2) /* 2:2 */
  444. #define RESUME_INTR_EN (0x1 << 1) /* 1:1 */
  445. #define SUSPEND_INTR_EN (0x1 << 0) /* 0:0 */
  446. /* U3D_LINK_RESET_INFO */
  447. #define WRFSSE0 (0xf << 20) /* 23:20 */
  448. #define WTCHRP (0xf << 16) /* 19:16 */
  449. #define VPLEN (0xff << 8) /* 15:8 */
  450. #define WTCON (0xf << 4) /* 7:4 */
  451. #define WTID (0xf << 0) /* 3:0 */
  452. #define WRFSSE0_OFST (20)
  453. #define WTCHRP_OFST (16)
  454. #define VPLEN_OFST (8)
  455. #define WTCON_OFST (4)
  456. #define WTID_OFST (0)
  457. /* U3D_USB20_TIMING_PARAM */
  458. #define CHOPPER_DELAY_TIME (0xff << 16) /* 23:16 */
  459. #define SOFTCON_DELAY_TIME (0xff << 8) /* 15:8 */
  460. #define TIME_VALUE_1US (0xff << 0) /* 7:0 */
  461. /* U3D_POWER_MANAGEMENT */
  462. #define LPM_BESL_STALL (0x1 << 14) /* 14:14 */
  463. #define LPM_BESLD_STALL (0x1 << 13) /* 13:13 */
  464. #define BC12_EN (0x1 << 12) /* 12:12 */
  465. #define LPM_RWP (0x1 << 11) /* 11:11 */
  466. #define LPM_HRWE (0x1 << 10) /* 10:10 */
  467. #define LPM_MODE (0x3 << 8) /* 9:8 */
  468. #define ISO_UPDATE (0x1 << 7) /* 7:7 */
  469. #define SOFT_CONN (0x1 << 6) /* 6:6 */
  470. #define HS_ENABLE (0x1 << 5) /* 5:5 */
  471. #define USB_HS_MODE (0x1 << 4) /* 4:4 */
  472. #define BUS_RESET (0x1 << 3) /* 3:3 */
  473. #define RESUME (0x1 << 2) /* 2:2 */
  474. #define SUSPEND (0x1 << 1) /* 1:1 */
  475. #define SUSPENDM_ENABLE (0x1 << 0) /* 0:0 */
  476. /* LPM_MODE */
  477. #define LPM_ALWAYS_REJECT_REQ (0x01)
  478. /* U3D_COMMON_USB_INTR */
  479. #define LPM_RESUME_INTR (0x1 << 9) /* 9:9 */
  480. #define LPM_INTR (0x1 << 8) /* 8:8 */
  481. #define VBUSERR_INTR (0x1 << 7) /* 7:7 */
  482. #define SESSION_REQ_INTR (0x1 << 6) /* 6:6 */
  483. #define DISCONN_INTR (0x1 << 5) /* 5:5 */
  484. #define CONN_INTR (0x1 << 4) /* 4:4 */
  485. #define SOF_INTR (0x1 << 3) /* 3:3 */
  486. #define RESET_INTR (0x1 << 2) /* 2:2 */
  487. #define RESUME_INTR (0x1 << 1) /* 1:1 */
  488. #define SUSPEND_INTR (0x1 << 0) /* 0:0 */
  489. /* SSUSB_EPCTL_CSR REGISTER DEFINITION */
  490. #define U3D_DEVICE_CONF (SSUSB_EPCTL_CSR_BASE+0x0000)
  491. #define U3D_EP_RST (SSUSB_EPCTL_CSR_BASE+0x0004)
  492. #define U3D_USB3_ERDY_TIMING_PARAM (SSUSB_EPCTL_CSR_BASE+0x0008)
  493. #define U3D_USB3_EPCTRL_CAP (SSUSB_EPCTL_CSR_BASE+0x000C)
  494. #define U3D_USB2_ISOINEP_INCOMP_INTR (SSUSB_EPCTL_CSR_BASE+0x0010)
  495. #define U3D_USB2_ISOOUTEP_INCOMP_ERR (SSUSB_EPCTL_CSR_BASE+0x0014)
  496. #define U3D_ISO_UNDERRUN_INTR (SSUSB_EPCTL_CSR_BASE+0x0018)
  497. #define U3D_ISO_OVERRUN_INTR (SSUSB_EPCTL_CSR_BASE+0x001C)
  498. #define U3D_USB2_RX_EP_DATAERR_INTR (SSUSB_EPCTL_CSR_BASE+0x0020)
  499. #define U3D_USB2_EPCTRL_CAP (SSUSB_EPCTL_CSR_BASE+0x0024)
  500. #define U3D_USB2_EPCTL_LPM (SSUSB_EPCTL_CSR_BASE+0x0028)
  501. #define U3D_USB3_SW_ERDY (SSUSB_EPCTL_CSR_BASE+0x0030)
  502. #define U3D_EP_FLOW_CTRL (SSUSB_EPCTL_CSR_BASE+0x0040)
  503. #define U3D_USB3_EP_ACT (SSUSB_EPCTL_CSR_BASE+0x0044)
  504. #define U3D_USB3_EP_PACKET_PENDING (SSUSB_EPCTL_CSR_BASE+0x0048)
  505. #define U3D_DEV_LINK_INTR_ENABLE (SSUSB_EPCTL_CSR_BASE+0x0050)
  506. #define U3D_DEV_LINK_INTR (SSUSB_EPCTL_CSR_BASE+0x0054)
  507. #define U3D_USB2_EPCTL_LPM_FC_CHK (SSUSB_EPCTL_CSR_BASE+0x0060)
  508. #define U3D_DEVICE_MONITOR (SSUSB_EPCTL_CSR_BASE+0x0064)
  509. /* U3D_EP_RST */
  510. #define EP_IN_RST (0x7fff << 17) /* 31:17 */
  511. #define EP_OUT_RST (0x7fff << 1) /* 15:1 */
  512. #define EP0_RST (0x1 << 0) /* 0:0 */
  513. /* U3D_DEV_LINK_INTR */
  514. #define SSUSB_DEV_SPEED_CHG_INTR (0x1 << 0) /* 0:0 */
  515. /* U3D_DEV_LINK_INTR_ENABLE */
  516. #define SSUSB_DEV_SPEED_CHG_INTR_EN (0x1 << 0) /* 0:0 */
  517. /* U3D_DEVICE_CONF */
  518. #define DEV_ADDR (0x7f << 24) /* 30:24 */
  519. #define HW_USB2_3_SEL (0x1 << 18) /* 18:18 */
  520. #define SW_USB2_3_SEL_EN (0x1 << 17) /* 17:17 */
  521. #define SW_USB2_3_SEL (0x1 << 16) /* 16:16 */
  522. #define SSUSB_DEV_SPEED (0x7 << 0) /* 2:0 */
  523. #define DEV_ADDR_OFST (24)
  524. #define HW_USB2_3_SEL_OFST (18)
  525. #define SW_USB2_3_SEL_EN_OFST (17)
  526. #define SW_USB2_3_SEL_OFST (16)
  527. #define SSUSB_DEV_SPEED_OFST (0)
  528. #define RISC_SIZE_1B 0x0
  529. #define RISC_SIZE_2B 0x1
  530. #define RISC_SIZE_4B 0x2
  531. /* SSUSB_USB3_SYS_CSR REGISTER DEFINITION */
  532. #define U3D_LINK_HP_TIMER (SSUSB_USB3_SYS_CSR_BASE+0x0200)
  533. #define U3D_LINK_CMD_TIMER (SSUSB_USB3_SYS_CSR_BASE+0x0204)
  534. #define U3D_LINK_PM_TIMER (SSUSB_USB3_SYS_CSR_BASE+0x0208)
  535. #define U3D_LINK_UX_INACT_TIMER (SSUSB_USB3_SYS_CSR_BASE+0x020C)
  536. #define U3D_LINK_POWER_CONTROL (SSUSB_USB3_SYS_CSR_BASE+0x0210)
  537. #define U3D_LINK_ERR_COUNT (SSUSB_USB3_SYS_CSR_BASE+0x0214)
  538. #define U3D_LTSSM_TRANSITION (SSUSB_USB3_SYS_CSR_BASE+0x0218)
  539. #define U3D_LINK_RETRY_CTRL (SSUSB_USB3_SYS_CSR_BASE+0x0220)
  540. #define U3D_SYS_FAST_SIMULATIION (SSUSB_USB3_SYS_CSR_BASE+0x0224)
  541. #define U3D_LINK_CAPABILITY_CTRL (SSUSB_USB3_SYS_CSR_BASE+0x0228)
  542. #define U3D_LINK_DEBUG_INFO (SSUSB_USB3_SYS_CSR_BASE+0x022C)
  543. #define U3D_USB3_U1_REJECT (SSUSB_USB3_SYS_CSR_BASE+0x0240)
  544. #define U3D_USB3_U2_REJECT (SSUSB_USB3_SYS_CSR_BASE+0x0244)
  545. #define U3D_DEV_NOTIF_0 (SSUSB_USB3_SYS_CSR_BASE+0x0290)
  546. #define U3D_DEV_NOTIF_1 (SSUSB_USB3_SYS_CSR_BASE+0x0294)
  547. #define U3D_VENDOR_DEV_TEST (SSUSB_USB3_SYS_CSR_BASE+0x0298)
  548. #define U3D_VENDOR_DEF_DATA_LOW (SSUSB_USB3_SYS_CSR_BASE+0x029C)
  549. #define U3D_VENDOR_DEF_DATA_HIGH (SSUSB_USB3_SYS_CSR_BASE+0x02A0)
  550. #define U3D_HOST_SET_PORT_CTRL (SSUSB_USB3_SYS_CSR_BASE+0x02A4)
  551. #define U3D_LINK_CAP_CONTROL (SSUSB_USB3_SYS_CSR_BASE+0x02AC)
  552. #define U3D_PORT_CONF_TIMEOUT (SSUSB_USB3_SYS_CSR_BASE+0x02B0)
  553. #define U3D_TIMING_PULSE_CTRL (SSUSB_USB3_SYS_CSR_BASE+0x02B4)
  554. #define U3D_ISO_TIMESTAMP (SSUSB_USB3_SYS_CSR_BASE+0x02B8)
  555. #define U3D_RECEIVE_PKT_INTR_EN (SSUSB_USB3_SYS_CSR_BASE+0x02C0)
  556. #define U3D_RECEIVE_PKT_INTR (SSUSB_USB3_SYS_CSR_BASE+0x02C4)
  557. #define U3D_CRC_ERR_INTR_EN (SSUSB_USB3_SYS_CSR_BASE+0x02C8)
  558. #define U3D_CRC_ERR_INTR (SSUSB_USB3_SYS_CSR_BASE+0x02CC)
  559. #define U3D_PORT_STATUS_INTR_EN (SSUSB_USB3_SYS_CSR_BASE+0x02D0)
  560. #define U3D_PORT_STATUS_INTR (SSUSB_USB3_SYS_CSR_BASE+0x02D4)
  561. #define U3D_RECOVERY_COUNT (SSUSB_USB3_SYS_CSR_BASE+0x02D8)
  562. #define U3D_T2R_LOOPBACK_TEST (SSUSB_USB3_SYS_CSR_BASE+0x02DC)
  563. /* U3D_LINK_POWER_CONTROL */
  564. #define SW_U2_ACCEPT_ENABLE (0x1 << 9) /* 9:9 */
  565. #define SW_U1_ACCEPT_ENABLE (0x1 << 8) /* 8:8 */
  566. #define UX_EXIT (0x1 << 5) /* 5:5 */
  567. #define LGO_U3 (0x1 << 4) /* 4:4 */
  568. #define LGO_U2 (0x1 << 3) /* 3:3 */
  569. #define LGO_U1 (0x1 << 2) /* 2:2 */
  570. #define SW_U2_REQUEST_ENABLE (0x1 << 1) /* 1:1 */
  571. #define SW_U1_REQUEST_ENABLE (0x1 << 0) /* 0:0 */
  572. /* U3D_LINK_CAPABILITY_CTRL */
  573. #define INSERT_CRC32_ERR_DP_NUM (0xff << 16) /* 23:16 */
  574. #define INSERT_CRC32_ERR_EN (0x1 << 8) /* 8:8 */
  575. #define ZLP_CRC32_CHK_DIS (0x1 << 0) /* 0:0 */
  576. /* U3D_TIMING_PULSE_CTRL */
  577. #define CNT_1MS_VALUE (0xf << 28) /* 31:28 */
  578. #define CNT_100US_VALUE (0xf << 24) /* 27:24 */
  579. #define CNT_10US_VALUE (0xf << 20) /* 23:20 */
  580. #define CNT_1US_VALUE (0xff << 0) /* 7:0 */
  581. #define USB_END_OFFSET(_bEnd, _bOffset) ((0x10*(_bEnd-1)) + _bOffset)
  582. #define USB_WRITECSR32(_bOffset, _bEnd, _bData) \
  583. writel(_bData, USB_END_OFFSET(_bEnd, _bOffset))
  584. #define USB_READCSR32(_bOffset, _bEnd) \
  585. readl(USB_END_OFFSET(_bEnd, _bOffset))
  586. void explain_csr0(u32 csr0);
  587. /* USB SET/CLEAR MASK MACRO */
  588. #define setbits(addr, mask) writel(readl(addr) | mask, addr)
  589. #define clrbits(addr, mask) writel(readl(addr) &~mask, addr)
  590. #if defined(DBG_USB_EP0CSR)
  591. #define ep0csr_setbits(mask) \
  592. u32 _temp = readl(U3D_EP0CSR); \
  593. explain_csr0(_temp); \
  594. writel((_temp & EP0_W1C_BITS) | (mask), U3D_EP0CSR); \
  595. explain_csr0(readl(U3D_EP0CSR));
  596. #else
  597. #define ep0csr_setbits(mask) \
  598. u32 _temp = readl(U3D_EP0CSR); \
  599. writel((_temp & EP0_W1C_BITS) | (mask), U3D_EP0CSR);
  600. #endif /* if defined(DBG_USB_EP0CSR) */
  601. #define USB_RESET_AFTER_SUSPEND 1
  602. #ifdef SUPPORT_U3
  603. #define U3D_DFT_SPEED SSUSB_SPEED_SUPER
  604. #else
  605. #define U3D_DFT_SPEED SSUSB_SPEED_HIGH
  606. #endif
  607. #define TX_FIFO_NUM 5 /* including ep0 */
  608. #define RX_FIFO_NUM 5 /* including ep0 */
  609. #define USB_FIFOSZ_SIZE_8 (0x03)
  610. #define USB_FIFOSZ_SIZE_16 (0x04)
  611. #define USB_FIFOSZ_SIZE_32 (0x05)
  612. #define USB_FIFOSZ_SIZE_64 (0x06)
  613. #define USB_FIFOSZ_SIZE_128 (0x07)
  614. #define USB_FIFOSZ_SIZE_256 (0x08)
  615. #define USB_FIFOSZ_SIZE_512 (0x09)
  616. #define USB_FIFOSZ_SIZE_1024 (0x0A)
  617. #define USB_FIFOSZ_SIZE_2048 (0x0B)
  618. #define USB_FIFOSZ_SIZE_4096 (0x0C)
  619. #define USB_FIFOSZ_SIZE_8192 (0x0D)
  620. #define USB_FIFOSZ_SIZE_16384 (0x0E)
  621. #define USB_FIFOSZ_SIZE_32768 (0x0F)
  622. #define BIT0 (1 << 0)
  623. #define BIT16 (1 << 16)
  624. /* RXxCSR1 or TXxCSR1 */
  625. #define TYPE_BULK (0x00)
  626. #define TYPE_INT (0x10)
  627. #define TYPE_ISO (0x20)
  628. #define TYPE_MASK (0x30)
  629. #ifdef SUPPORT_QMU
  630. /* from mu3d_hal_hw.h */
  631. /* QMU macros */
  632. #if 0
  633. #define U3D_TXQCSR1 (SSUSB_DEV_BASE+0x0510)
  634. #define U3D_TXQSAR1 (SSUSB_DEV_BASE+0x0514)
  635. #define U3D_TXQCPR1 (SSUSB_DEV_BASE+0x0518)
  636. #define U3D_RXQCSR1 (SSUSB_DEV_BASE+0x0610)
  637. #define U3D_RXQSAR1 (SSUSB_DEV_BASE+0x0614)
  638. #define U3D_RXQCPR1 (SSUSB_DEV_BASE+0x0618)
  639. #define U3D_RXQLDPR1 (SSUSB_DEV_BASE+0x061C)
  640. #define USB_QMU_RXQCSR(n) (U3D_RXQCSR1 + 0x0010 * ((n)-1))
  641. #define USB_QMU_RXQSAR(n) (U3D_RXQSAR1 + 0x0010 * ((n)-1))
  642. #define USB_QMU_RXQCPR(n) (U3D_RXQCPR1 + 0x0010 * ((n)-1))
  643. #define USB_QMU_RXQLDPR(n) (U3D_RXQLDPR1 + 0x0010 * ((n)-1))
  644. #define USB_QMU_TXQCSR(n) (U3D_TXQCSR1 + 0x0010 * ((n)-1))
  645. #define USB_QMU_TXQSAR(n) (U3D_TXQSAR1 + 0x0010 * ((n)-1))
  646. #define USB_QMU_TXQCPR(n) (U3D_TXQCPR1 + 0x0010 * ((n)-1))
  647. /* ?? */
  648. #define USB_QMU_RQCSR(n) (U3D_RXQCSR1 + 0x0010 * ((n)-1))
  649. #define USB_QMU_RQSAR(n) (U3D_RXQSAR1 + 0x0010 * ((n)-1))
  650. #define USB_QMU_RQCPR(n) (U3D_RXQCPR1 + 0x0010 * ((n)-1))
  651. #define USB_QMU_RQLDPR(n) (U3D_RXQLDPR1 + 0x0010 * ((n)-1))
  652. #define USB_QMU_TQCSR(n) (U3D_TXQCSR1 + 0x0010 * ((n)-1))
  653. #define USB_QMU_TQSAR(n) (U3D_TXQSAR1 + 0x0010 * ((n)-1))
  654. #define USB_QMU_TQCPR(n) (U3D_TXQCPR1 + 0x0010 * ((n)-1))
  655. #endif
  656. #define QMU_Q_START (0x00000001)
  657. #define QMU_Q_RESUME (0x00000002)
  658. #define QMU_Q_STOP (0x00000004)
  659. #define QMU_Q_ACTIVE (0x00008000)
  660. #define QMU_TX_EN(n) (BIT0 << (n))
  661. #define QMU_RX_EN(n) (BIT16 << (n))
  662. #define QMU_TX_CS_EN(n) (BIT0 << (n))
  663. #define QMU_RX_CS_EN(n) (BIT16 << (n))
  664. #define QMU_TX_ZLP(n) (BIT0 << (n))
  665. #define QMU_RX_MULTIPLE(n) (BIT16 << ((n)-1))
  666. #define QMU_RX_ZLP(n) (BIT0 << (n))
  667. #define QMU_RX_COZ(n) (BIT16 << (n))
  668. #define QMU_RX_EMPTY(n) (BIT16 << (n))
  669. #define QMU_TX_EMPTY(n) (BIT0 << (n))
  670. #define QMU_RX_DONE(n) (BIT16 << (n))
  671. #define QMU_TX_DONE(n) (BIT0 << (n))
  672. #define QMU_RX_ZLP_ERR(n) (BIT16 << (n))
  673. #define QMU_RX_EP_ERR(n) (BIT0 << (n))
  674. #define QMU_RX_LEN_ERR(n) (BIT16 << (n))
  675. #define QMU_RX_CS_ERR(n) (BIT0 << (n))
  676. #define QMU_TX_LEN_ERR(n) (BIT16 << (n))
  677. #define QMU_TX_CS_ERR(n) (BIT0 << (n))
  678. #define CS_12B 1
  679. #define CS_16B 2
  680. #define CHECKSUM_TYPE CS_16B
  681. #define U3D_COMMAND_TIMER 10
  682. #if (CHECKSUM_TYPE==CS_16B)
  683. #define CHECKSUM_LENGTH 16
  684. #else
  685. #define CHECKSUM_LENGTH 12
  686. #endif
  687. /* from ssusb_dev_c_header.h */
  688. /* U3D_QCR0 */
  689. #define RXQ_CS_EN (0x7fff << 17) /* 31:17 */
  690. #define TXQ_CS_EN (0x7fff << 1) /* 15:1 */
  691. #define CS16B_EN (0x1 << 0) /* 0:0 */
  692. /* U3D_QCR1 */
  693. #define CFG_TX_ZLP_GPD (0x7fff << 1) /* 15:1 */
  694. /* U3D_QCR2 */
  695. #define CFG_TX_ZLP (0x7fff << 1) /* 15:1 */
  696. /* U3D_QCR3 */
  697. #define CFG_RX_COZ (0x7fff << 17) /* 31:17 */
  698. #define CFG_RX_ZLP (0x7fff << 1) /* 15:1 */
  699. /* U3D_QGCSR */
  700. #define RXQ_EN (0x7fff << 17) /* 31:17 */
  701. #define TXQ_EN (0x7fff << 1) /* 15:1 */
  702. /* U3D_TXQCSR1 */
  703. #define TXQ_DMGR_DMSM_CS (0xf << 16) /* 19:16 */
  704. #define TXQ_ACTIVE (0x1 << 15) /* 15:15 */
  705. #define TXQ_EPQ_STATE (0xf << 8) /* 11:8 */
  706. #define TXQ_STOP (0x1 << 2) /* 2:2 */
  707. #define TXQ_RESUME (0x1 << 1) /* 1:1 */
  708. #define TXQ_START (0x1 << 0) /* 0:0 */
  709. /* U3D_TXQSAR1 */
  710. #define TXQ_START_ADDR (0x3fffffff << 2) /* 31:2 */
  711. /* U3D_TXQCPR1 */
  712. #define TXQ_CUR_GPD_ADDR (0x3fffffff << 2) /* 31:2 */
  713. /* U3D_RXQCSR1 */
  714. #define RXQ_DMGR_DMSM_CS (0xf << 16) /* 19:16 */
  715. #define RXQ_ACTIVE (0x1 << 15) /* 15:15 */
  716. #define RXQ_EPQ_STATE (0x1f << 8) /* 12:8 */
  717. #define RXQ_STOP (0x1 << 2) /* 2:2 */
  718. #define RXQ_RESUME (0x1 << 1) /* 1:1 */
  719. #define RXQ_START (0x1 << 0) /* 0:0 */
  720. /* U3D_RXQSAR1 */
  721. #define RXQ_START_ADDR (0x3fffffff << 2) /* 31:2 */
  722. /* U3D_RXQCPR1 */
  723. #define RXQ_CUR_GPD_ADDR (0x3fffffff << 2) /* 31:2 */
  724. /* U3D_RXQLDPR1 */
  725. #define RXQ_LAST_DONE_PTR (0x3fffffff << 2) /* 31:2 */
  726. /* U3D_QISAR0 */
  727. #define RXQ_DONE_INT (0x7fff << 17) /* 31:17 */
  728. #define TXQ_DONE_INT (0x7fff << 1) /* 15:1 */
  729. /* U3D_QIER0 */
  730. #define RXQ_DONE_IER (0x7fff << 17) /* 31:17 */
  731. #define TXQ_DONE_IER (0x7fff << 1) /* 15:1 */
  732. /* U3D_QIESR0 */
  733. #define RXQ_DONE_IESR (0x7fff << 17) /* 31:17 */
  734. #define TXQ_DONE_IESR (0x7fff << 1) /* 15:1 */
  735. /* U3D_QIECR0 */
  736. #define RXQ_DONE_IECR (0x7fff << 17) /* 31:17 */
  737. #define TXQ_DONE_IECR (0x7fff << 1) /* 15:1 */
  738. /* U3D_QISAR1 */
  739. #define RXQ_ZLPERR_INT (0x1 << 20) /* 20:20 */
  740. #define RXQ_LENERR_INT (0x1 << 18) /* 18:18 */
  741. #define RXQ_CSERR_INT (0x1 << 17) /* 17:17 */
  742. #define RXQ_EMPTY_INT (0x1 << 16) /* 16:16 */
  743. #define TXQ_LENERR_INT (0x1 << 2) /* 2:2 */
  744. #define TXQ_CSERR_INT (0x1 << 1) /* 1:1 */
  745. #define TXQ_EMPTY_INT (0x1 << 0) /* 0:0 */
  746. /* U3D_QIER1 */
  747. #define RXQ_ZLPERR_IER (0x1 << 20) /* 20:20 */
  748. #define RXQ_LENERR_IER (0x1 << 18) /* 18:18 */
  749. #define RXQ_CSERR_IER (0x1 << 17) /* 17:17 */
  750. #define RXQ_EMPTY_IER (0x1 << 16) /* 16:16 */
  751. #define TXQ_LENERR_IER (0x1 << 2) /* 2:2 */
  752. #define TXQ_CSERR_IER (0x1 << 1) /* 1:1 */
  753. #define TXQ_EMPTY_IER (0x1 << 0) /* 0:0 */
  754. /* U3D_QIESR1 */
  755. #define RXQ_ZLPERR_IESR (0x1 << 20) /* 20:20 */
  756. #define RXQ_LENERR_IESR (0x1 << 18) /* 18:18 */
  757. #define RXQ_CSERR_IESR (0x1 << 17) /* 17:17 */
  758. #define RXQ_EMPTY_IESR (0x1 << 16) /* 16:16 */
  759. #define TXQ_LENERR_IESR (0x1 << 2) /* 2:2 */
  760. #define TXQ_CSERR_IESR (0x1 << 1) /* 1:1 */
  761. #define TXQ_EMPTY_IESR (0x1 << 0) /* 0:0 */
  762. /* U3D_QIECR1 */
  763. #define RXQ_ZLPERR_IECR (0x1 << 20) /* 20:20 */
  764. #define RXQ_LENERR_IECR (0x1 << 18) /* 18:18 */
  765. #define RXQ_CSERR_IECR (0x1 << 17) /* 17:17 */
  766. #define RXQ_EMPTY_IECR (0x1 << 16) /* 16:16 */
  767. #define TXQ_LENERR_IECR (0x1 << 2) /* 2:2 */
  768. #define TXQ_CSERR_IECR (0x1 << 1) /* 1:1 */
  769. #define TXQ_EMPTY_IECR (0x1 << 0) /* 0:0 */
  770. /* U3D_QEMIR */
  771. #define RXQ_EMPTY_MASK (0x7fff << 17) /* 31:17 */
  772. #define TXQ_EMPTY_MASK (0x7fff << 1) /* 15:1 */
  773. /* U3D_QEMIER */
  774. #define RXQ_EMPTY_IER_MASK (0x7fff << 17) /* 31:17 */
  775. #define TXQ_EMPTY_IER_MASK (0x7fff << 1) /* 15:1 */
  776. /* U3D_QEMIESR */
  777. #define RXQ_EMPTY_IESR_MASK (0x7fff << 17) /* 31:17 */
  778. #define TXQ_EMPTY_IESR_MASK (0x7fff << 1) /* 15:1 */
  779. /* U3D_QEMIECR */
  780. #define RXQ_EMPTY_IECR_MASK (0x7fff << 17) /* 31:17 */
  781. #define TXQ_EMPTY_IECR_MASK (0x7fff << 1) /* 15:1 */
  782. /* U3D_TQERRIR0 */
  783. #define TXQ_LENERR_MASK (0x7fff << 17) /* 31:17 */
  784. #define TXQ_CSERR_MASK (0x7fff << 1) /* 15:1 */
  785. /* U3D_TQERRIER0 */
  786. #define TXQ_LENERR_IER_MASK (0x7fff << 17) /* 31:17 */
  787. #define TXQ_CSERR_IER_MASK (0x7fff << 1) /* 15:1 */
  788. /* U3D_TQERRIESR0 */
  789. #define TXQ_LENERR_IESR_MASK (0x7fff << 17) /* 31:17 */
  790. #define TXQ_CSERR_IESR_MASK (0x7fff << 1) /* 15:1 */
  791. /* U3D_TQERRIECR0 */
  792. #define TXQ_LENERR_IECR_MASK (0x7fff << 17) /* 31:17 */
  793. #define TXQ_CSERR_IECR_MASK (0x7fff << 1) /* 15:1 */
  794. /* U3D_RQERRIR0 */
  795. #define RXQ_LENERR_MASK (0x7fff << 17) /* 31:17 */
  796. #define RXQ_CSERR_MASK (0x7fff << 1) /* 15:1 */
  797. /* U3D_RQERRIER0 */
  798. #define RXQ_LENERR_IER_MASK (0x7fff << 17) /* 31:17 */
  799. #define RXQ_CSERR_IER_MASK (0x7fff << 1) /* 15:1 */
  800. /* U3D_RQERRIESR0 */
  801. #define RXQ_LENERR_IESR_MASK (0x7fff << 17) /* 31:17 */
  802. #define RXQ_CSERR_IESR_MASK (0x7fff << 1) /* 15:1 */
  803. /* U3D_RQERRIECR0 */
  804. #define RXQ_LENERR_IECR_MASK (0x7fff << 17) /* 31:17 */
  805. #define RXQ_CSERR_IECR_MASK (0x7fff << 1) /* 15:1 */
  806. /* U3D_RQERRIR1 */
  807. #define RXQ_ZLPERR_MASK (0x7fff << 17) /* 31:17 */
  808. /* U3D_RQERRIER1 */
  809. #define RXQ_ZLPERR_IER_MASK (0x7fff << 17) /* 31:17 */
  810. /* U3D_RQERRIESR1 */
  811. #define RXQ_ZLPERR_IESR_MASK (0x7fff << 17) /* 31:17 */
  812. /* U3D_RQERRIECR1 */
  813. #define RXQ_ZLPERR_IECR_MASK (0x7fff << 17) /* 31:17 */
  814. #endif /* ifdef SUPPORT_QMU */
  815. #ifdef EXT_VBUS_DET
  816. #define FPGA_REG 0xf0008098
  817. #define VBUS_RISE_BIT (1 << 11) /* W1C */
  818. #define VBUS_FALL_BIT (1 << 12) /* W1C */
  819. #define VBUS_MSK (VBUS_RISE_BIT | VBUS_FALL_BIT)
  820. #define VBUS_RISE_IRQ 13
  821. #define VBUS_FALL_IRQ 14
  822. #endif
  823. /* mt_usb defines */
  824. typedef enum {
  825. EP0_IDLE = 0,
  826. EP0_RX,
  827. EP0_TX,
  828. } EP0_STATE;
  829. typedef enum {
  830. RET_SUCCESS = 0,
  831. RET_FAIL,
  832. } USB_RESULT;
  833. /* MTK USB3 ssusb defines */
  834. typedef enum {
  835. SSUSB_SPEED_UNKNOWN = 0,
  836. SSUSB_SPEED_FULL = 1,
  837. SSUSB_SPEED_HIGH = 2,
  838. SSUSB_SPEED_SUPER = 3,
  839. } USB_SPEED;
  840. /* from preloader */
  841. #define USB_EP_XFER_CTRL 0
  842. #define USB_EP_XFER_ISO 1
  843. #define USB_EP_XFER_BULK 2
  844. #define USB_EP_XFER_INT 3
  845. /* some macros */
  846. #define EPMASK(X) (1 << X)
  847. #define CHANMASK(X) (1 << X)
  848. void mt_usb_phy_poweron(void);
  849. void mt_usb_phy_savecurrent(void);
  850. /* mt_usbtty.c */
  851. void enable_highspeed(void);
  852. void enable_superspeed(void);
  853. /* mt_usb.c */
  854. struct udc_endpoint *mt_find_ep(int ep_num, u8 dir);
  855. void mt_setup_ep(unsigned int ep_num, struct udc_endpoint *endpoint);
  856. void mt_usb_connect_internal(void);
  857. void mt_usb_disconnect_internal(void);
  858. /* USB transfer directions */
  859. #define USB_DIR_IN DEVICE_WRITE /* val: 0x80 */
  860. #define USB_DIR_OUT DEVICE_READ /* val: 0x00 */
  861. struct urb {
  862. struct udc_endpoint *ept;
  863. struct udc_device *device;
  864. struct setup_packet device_request;
  865. u8 *buf;
  866. unsigned int actual_length;
  867. //#ifdef SUPPORT_QMU
  868. u32 qmu_complete;
  869. //#endif
  870. };
  871. /* endpoint data - mt_ep */
  872. struct udc_endpoint {
  873. /* rx side */
  874. struct urb *rcv_urb; /* active urb */
  875. /* tx side */
  876. struct urb *tx_urb; /* active urb */
  877. /* info from hsusb */
  878. struct udc_request *req;
  879. unsigned int bit; /* EPT_TX/EPT_RX */
  880. unsigned char num;
  881. unsigned char in;
  882. unsigned int maxpkt;
  883. int status; /* status for error handling */
  884. unsigned int sent; /* data already sent */
  885. unsigned int last; /* data sent in last packet XXX do we need this */
  886. unsigned char mode; /* double buffer */
  887. unsigned char type; /* Transfer type */
  888. unsigned char slot;
  889. unsigned char burst;
  890. unsigned char mult;
  891. unsigned char binterval;
  892. };
  893. /* from mt_usbtty.h */
  894. #define NUM_ENDPOINTS 3
  895. /* origin endpoint_array */
  896. struct udc_endpoint ep_list[NUM_ENDPOINTS + 1]; /* one extra for control endpoint */
  897. #endif