2 * QEMU model of the USB DWC3 host controller emulation.
4 * This model defines global register space of DWC3 controller. Global
5 * registers control the AXI/AHB interfaces properties, external FIFO support
6 * and event count support. All of which are unimplemented at present. We are
7 * only supporting core reset and read of ID register.
9 * Copyright (c) 2020 Xilinx Inc. Vikram Garhwal<fnu.vikram@xilinx.com>
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30 #include "qemu/osdep.h"
31 #include "hw/sysbus.h"
32 #include "hw/register.h"
33 #include "qemu/bitops.h"
34 #include "qom/object.h"
35 #include "migration/vmstate.h"
36 #include "hw/qdev-properties.h"
37 #include "hw/usb/hcd-dwc3.h"
38 #include "qapi/error.h"
40 #ifndef USB_DWC3_ERR_DEBUG
41 #define USB_DWC3_ERR_DEBUG 0
45 #define FIFO_LEN 0x1000
47 REG32(GSBUSCFG0
, 0x00)
48 FIELD(GSBUSCFG0
, DATRDREQINFO
, 28, 4)
49 FIELD(GSBUSCFG0
, DESRDREQINFO
, 24, 4)
50 FIELD(GSBUSCFG0
, DATWRREQINFO
, 20, 4)
51 FIELD(GSBUSCFG0
, DESWRREQINFO
, 16, 4)
52 FIELD(GSBUSCFG0
, RESERVED_15_12
, 12, 4)
53 FIELD(GSBUSCFG0
, DATBIGEND
, 11, 1)
54 FIELD(GSBUSCFG0
, DESBIGEND
, 10, 1)
55 FIELD(GSBUSCFG0
, RESERVED_9_8
, 8, 2)
56 FIELD(GSBUSCFG0
, INCR256BRSTENA
, 7, 1)
57 FIELD(GSBUSCFG0
, INCR128BRSTENA
, 6, 1)
58 FIELD(GSBUSCFG0
, INCR64BRSTENA
, 5, 1)
59 FIELD(GSBUSCFG0
, INCR32BRSTENA
, 4, 1)
60 FIELD(GSBUSCFG0
, INCR16BRSTENA
, 3, 1)
61 FIELD(GSBUSCFG0
, INCR8BRSTENA
, 2, 1)
62 FIELD(GSBUSCFG0
, INCR4BRSTENA
, 1, 1)
63 FIELD(GSBUSCFG0
, INCRBRSTENA
, 0, 1)
64 REG32(GSBUSCFG1
, 0x04)
65 FIELD(GSBUSCFG1
, RESERVED_31_13
, 13, 19)
66 FIELD(GSBUSCFG1
, EN1KPAGE
, 12, 1)
67 FIELD(GSBUSCFG1
, PIPETRANSLIMIT
, 8, 4)
68 FIELD(GSBUSCFG1
, RESERVED_7_0
, 0, 8)
69 REG32(GTXTHRCFG
, 0x08)
70 FIELD(GTXTHRCFG
, RESERVED_31
, 31, 1)
71 FIELD(GTXTHRCFG
, RESERVED_30
, 30, 1)
72 FIELD(GTXTHRCFG
, USBTXPKTCNTSEL
, 29, 1)
73 FIELD(GTXTHRCFG
, RESERVED_28
, 28, 1)
74 FIELD(GTXTHRCFG
, USBTXPKTCNT
, 24, 4)
75 FIELD(GTXTHRCFG
, USBMAXTXBURSTSIZE
, 16, 8)
76 FIELD(GTXTHRCFG
, RESERVED_15
, 15, 1)
77 FIELD(GTXTHRCFG
, RESERVED_14
, 14, 1)
78 FIELD(GTXTHRCFG
, RESERVED_13_11
, 11, 3)
79 FIELD(GTXTHRCFG
, RESERVED_10_0
, 0, 11)
80 REG32(GRXTHRCFG
, 0x0c)
81 FIELD(GRXTHRCFG
, RESERVED_31_30
, 30, 2)
82 FIELD(GRXTHRCFG
, USBRXPKTCNTSEL
, 29, 1)
83 FIELD(GRXTHRCFG
, RESERVED_28
, 28, 1)
84 FIELD(GRXTHRCFG
, USBRXPKTCNT
, 24, 4)
85 FIELD(GRXTHRCFG
, USBMAXRXBURSTSIZE
, 19, 5)
86 FIELD(GRXTHRCFG
, RESERVED_18_16
, 16, 3)
87 FIELD(GRXTHRCFG
, RESERVED_15
, 15, 1)
88 FIELD(GRXTHRCFG
, RESERVED_14_13
, 13, 2)
89 FIELD(GRXTHRCFG
, RESVISOCOUTSPC
, 0, 13)
91 FIELD(GCTL
, PWRDNSCALE
, 19, 13)
92 FIELD(GCTL
, MASTERFILTBYPASS
, 18, 1)
93 FIELD(GCTL
, BYPSSETADDR
, 17, 1)
94 FIELD(GCTL
, U2RSTECN
, 16, 1)
95 FIELD(GCTL
, FRMSCLDWN
, 14, 2)
96 FIELD(GCTL
, PRTCAPDIR
, 12, 2)
97 FIELD(GCTL
, CORESOFTRESET
, 11, 1)
98 FIELD(GCTL
, U1U2TIMERSCALE
, 9, 1)
99 FIELD(GCTL
, DEBUGATTACH
, 8, 1)
100 FIELD(GCTL
, RAMCLKSEL
, 6, 2)
101 FIELD(GCTL
, SCALEDOWN
, 4, 2)
102 FIELD(GCTL
, DISSCRAMBLE
, 3, 1)
103 FIELD(GCTL
, U2EXIT_LFPS
, 2, 1)
104 FIELD(GCTL
, GBLHIBERNATIONEN
, 1, 1)
105 FIELD(GCTL
, DSBLCLKGTNG
, 0, 1)
108 FIELD(GSTS
, CBELT
, 20, 12)
109 FIELD(GSTS
, RESERVED_19_12
, 12, 8)
110 FIELD(GSTS
, SSIC_IP
, 11, 1)
111 FIELD(GSTS
, OTG_IP
, 10, 1)
112 FIELD(GSTS
, BC_IP
, 9, 1)
113 FIELD(GSTS
, ADP_IP
, 8, 1)
114 FIELD(GSTS
, HOST_IP
, 7, 1)
115 FIELD(GSTS
, DEVICE_IP
, 6, 1)
116 FIELD(GSTS
, CSRTIMEOUT
, 5, 1)
117 FIELD(GSTS
, BUSERRADDRVLD
, 4, 1)
118 FIELD(GSTS
, RESERVED_3_2
, 2, 2)
119 FIELD(GSTS
, CURMOD
, 0, 2)
121 FIELD(GUCTL1
, RESUME_OPMODE_HS_HOST
, 10, 1)
124 FIELD(GGPIO
, GPO
, 16, 16)
125 FIELD(GGPIO
, GPI
, 0, 16)
128 FIELD(GUCTL
, REFCLKPER
, 22, 10)
129 FIELD(GUCTL
, NOEXTRDL
, 21, 1)
130 FIELD(GUCTL
, RESERVED_20_18
, 18, 3)
131 FIELD(GUCTL
, SPRSCTRLTRANSEN
, 17, 1)
132 FIELD(GUCTL
, RESBWHSEPS
, 16, 1)
133 FIELD(GUCTL
, RESERVED_15
, 15, 1)
134 FIELD(GUCTL
, USBHSTINAUTORETRYEN
, 14, 1)
135 FIELD(GUCTL
, ENOVERLAPCHK
, 13, 1)
136 FIELD(GUCTL
, EXTCAPSUPPTEN
, 12, 1)
137 FIELD(GUCTL
, INSRTEXTRFSBODI
, 11, 1)
138 FIELD(GUCTL
, DTCT
, 9, 2)
139 FIELD(GUCTL
, DTFT
, 0, 9)
140 REG32(GBUSERRADDRLO
, 0x30)
141 REG32(GBUSERRADDRHI
, 0x34)
142 REG32(GHWPARAMS0
, 0x40)
143 FIELD(GHWPARAMS0
, GHWPARAMS0_31_24
, 24, 8)
144 FIELD(GHWPARAMS0
, GHWPARAMS0_23_16
, 16, 8)
145 FIELD(GHWPARAMS0
, GHWPARAMS0_15_8
, 8, 8)
146 FIELD(GHWPARAMS0
, GHWPARAMS0_7_6
, 6, 2)
147 FIELD(GHWPARAMS0
, GHWPARAMS0_5_3
, 3, 3)
148 FIELD(GHWPARAMS0
, GHWPARAMS0_2_0
, 0, 3)
149 REG32(GHWPARAMS1
, 0x44)
150 FIELD(GHWPARAMS1
, GHWPARAMS1_31
, 31, 1)
151 FIELD(GHWPARAMS1
, GHWPARAMS1_30
, 30, 1)
152 FIELD(GHWPARAMS1
, GHWPARAMS1_29
, 29, 1)
153 FIELD(GHWPARAMS1
, GHWPARAMS1_28
, 28, 1)
154 FIELD(GHWPARAMS1
, GHWPARAMS1_27
, 27, 1)
155 FIELD(GHWPARAMS1
, GHWPARAMS1_26
, 26, 1)
156 FIELD(GHWPARAMS1
, GHWPARAMS1_25_24
, 24, 2)
157 FIELD(GHWPARAMS1
, GHWPARAMS1_23
, 23, 1)
158 FIELD(GHWPARAMS1
, GHWPARAMS1_22_21
, 21, 2)
159 FIELD(GHWPARAMS1
, GHWPARAMS1_20_15
, 15, 6)
160 FIELD(GHWPARAMS1
, GHWPARAMS1_14_12
, 12, 3)
161 FIELD(GHWPARAMS1
, GHWPARAMS1_11_9
, 9, 3)
162 FIELD(GHWPARAMS1
, GHWPARAMS1_8_6
, 6, 3)
163 FIELD(GHWPARAMS1
, GHWPARAMS1_5_3
, 3, 3)
164 FIELD(GHWPARAMS1
, GHWPARAMS1_2_0
, 0, 3)
165 REG32(GHWPARAMS2
, 0x48)
166 REG32(GHWPARAMS3
, 0x4c)
167 FIELD(GHWPARAMS3
, GHWPARAMS3_31
, 31, 1)
168 FIELD(GHWPARAMS3
, GHWPARAMS3_30_23
, 23, 8)
169 FIELD(GHWPARAMS3
, GHWPARAMS3_22_18
, 18, 5)
170 FIELD(GHWPARAMS3
, GHWPARAMS3_17_12
, 12, 6)
171 FIELD(GHWPARAMS3
, GHWPARAMS3_11
, 11, 1)
172 FIELD(GHWPARAMS3
, GHWPARAMS3_10
, 10, 1)
173 FIELD(GHWPARAMS3
, GHWPARAMS3_9_8
, 8, 2)
174 FIELD(GHWPARAMS3
, GHWPARAMS3_7_6
, 6, 2)
175 FIELD(GHWPARAMS3
, GHWPARAMS3_5_4
, 4, 2)
176 FIELD(GHWPARAMS3
, GHWPARAMS3_3_2
, 2, 2)
177 FIELD(GHWPARAMS3
, GHWPARAMS3_1_0
, 0, 2)
178 REG32(GHWPARAMS4
, 0x50)
179 FIELD(GHWPARAMS4
, GHWPARAMS4_31_28
, 28, 4)
180 FIELD(GHWPARAMS4
, GHWPARAMS4_27_24
, 24, 4)
181 FIELD(GHWPARAMS4
, GHWPARAMS4_23
, 23, 1)
182 FIELD(GHWPARAMS4
, GHWPARAMS4_22
, 22, 1)
183 FIELD(GHWPARAMS4
, GHWPARAMS4_21
, 21, 1)
184 FIELD(GHWPARAMS4
, GHWPARAMS4_20_17
, 17, 4)
185 FIELD(GHWPARAMS4
, GHWPARAMS4_16_13
, 13, 4)
186 FIELD(GHWPARAMS4
, GHWPARAMS4_12
, 12, 1)
187 FIELD(GHWPARAMS4
, GHWPARAMS4_11
, 11, 1)
188 FIELD(GHWPARAMS4
, GHWPARAMS4_10_9
, 9, 2)
189 FIELD(GHWPARAMS4
, GHWPARAMS4_8_7
, 7, 2)
190 FIELD(GHWPARAMS4
, GHWPARAMS4_6
, 6, 1)
191 FIELD(GHWPARAMS4
, GHWPARAMS4_5_0
, 0, 6)
192 REG32(GHWPARAMS5
, 0x54)
193 FIELD(GHWPARAMS5
, GHWPARAMS5_31_28
, 28, 4)
194 FIELD(GHWPARAMS5
, GHWPARAMS5_27_22
, 22, 6)
195 FIELD(GHWPARAMS5
, GHWPARAMS5_21_16
, 16, 6)
196 FIELD(GHWPARAMS5
, GHWPARAMS5_15_10
, 10, 6)
197 FIELD(GHWPARAMS5
, GHWPARAMS5_9_4
, 4, 6)
198 FIELD(GHWPARAMS5
, GHWPARAMS5_3_0
, 0, 4)
199 REG32(GHWPARAMS6
, 0x58)
200 FIELD(GHWPARAMS6
, GHWPARAMS6_31_16
, 16, 16)
201 FIELD(GHWPARAMS6
, BUSFLTRSSUPPORT
, 15, 1)
202 FIELD(GHWPARAMS6
, BCSUPPORT
, 14, 1)
203 FIELD(GHWPARAMS6
, OTG_SS_SUPPORT
, 13, 1)
204 FIELD(GHWPARAMS6
, ADPSUPPORT
, 12, 1)
205 FIELD(GHWPARAMS6
, HNPSUPPORT
, 11, 1)
206 FIELD(GHWPARAMS6
, SRPSUPPORT
, 10, 1)
207 FIELD(GHWPARAMS6
, GHWPARAMS6_9_8
, 8, 2)
208 FIELD(GHWPARAMS6
, GHWPARAMS6_7
, 7, 1)
209 FIELD(GHWPARAMS6
, GHWPARAMS6_6
, 6, 1)
210 FIELD(GHWPARAMS6
, GHWPARAMS6_5_0
, 0, 6)
211 REG32(GHWPARAMS7
, 0x5c)
212 FIELD(GHWPARAMS7
, GHWPARAMS7_31_16
, 16, 16)
213 FIELD(GHWPARAMS7
, GHWPARAMS7_15_0
, 0, 16)
214 REG32(GDBGFIFOSPACE
, 0x60)
215 FIELD(GDBGFIFOSPACE
, SPACE_AVAILABLE
, 16, 16)
216 FIELD(GDBGFIFOSPACE
, RESERVED_15_9
, 9, 7)
217 FIELD(GDBGFIFOSPACE
, FIFO_QUEUE_SELECT
, 0, 9)
219 FIELD(GUCTL2
, RESERVED_31_26
, 26, 6)
220 FIELD(GUCTL2
, EN_HP_PM_TIMER
, 19, 7)
221 FIELD(GUCTL2
, NOLOWPWRDUR
, 15, 4)
222 FIELD(GUCTL2
, RST_ACTBITLATER
, 14, 1)
223 FIELD(GUCTL2
, RESERVED_13
, 13, 1)
224 FIELD(GUCTL2
, DISABLECFC
, 11, 1)
225 REG32(GUSB2PHYCFG
, 0x100)
226 FIELD(GUSB2PHYCFG
, U2_FREECLK_EXISTS
, 30, 1)
227 FIELD(GUSB2PHYCFG
, ULPI_LPM_WITH_OPMODE_CHK
, 29, 1)
228 FIELD(GUSB2PHYCFG
, RESERVED_25
, 25, 1)
229 FIELD(GUSB2PHYCFG
, LSTRD
, 22, 3)
230 FIELD(GUSB2PHYCFG
, LSIPD
, 19, 3)
231 FIELD(GUSB2PHYCFG
, ULPIEXTVBUSINDIACTOR
, 18, 1)
232 FIELD(GUSB2PHYCFG
, ULPIEXTVBUSDRV
, 17, 1)
233 FIELD(GUSB2PHYCFG
, RESERVED_16
, 16, 1)
234 FIELD(GUSB2PHYCFG
, ULPIAUTORES
, 15, 1)
235 FIELD(GUSB2PHYCFG
, RESERVED_14
, 14, 1)
236 FIELD(GUSB2PHYCFG
, USBTRDTIM
, 10, 4)
237 FIELD(GUSB2PHYCFG
, XCVRDLY
, 9, 1)
238 FIELD(GUSB2PHYCFG
, ENBLSLPM
, 8, 1)
239 FIELD(GUSB2PHYCFG
, PHYSEL
, 7, 1)
240 FIELD(GUSB2PHYCFG
, SUSPENDUSB20
, 6, 1)
241 FIELD(GUSB2PHYCFG
, FSINTF
, 5, 1)
242 FIELD(GUSB2PHYCFG
, ULPI_UTMI_SEL
, 4, 1)
243 FIELD(GUSB2PHYCFG
, PHYIF
, 3, 1)
244 FIELD(GUSB2PHYCFG
, TOUTCAL
, 0, 3)
245 REG32(GUSB2I2CCTL
, 0x140)
246 REG32(GUSB2PHYACC_ULPI
, 0x180)
247 FIELD(GUSB2PHYACC_ULPI
, RESERVED_31_27
, 27, 5)
248 FIELD(GUSB2PHYACC_ULPI
, DISUIPIDRVR
, 26, 1)
249 FIELD(GUSB2PHYACC_ULPI
, NEWREGREQ
, 25, 1)
250 FIELD(GUSB2PHYACC_ULPI
, VSTSDONE
, 24, 1)
251 FIELD(GUSB2PHYACC_ULPI
, VSTSBSY
, 23, 1)
252 FIELD(GUSB2PHYACC_ULPI
, REGWR
, 22, 1)
253 FIELD(GUSB2PHYACC_ULPI
, REGADDR
, 16, 6)
254 FIELD(GUSB2PHYACC_ULPI
, EXTREGADDR
, 8, 8)
255 FIELD(GUSB2PHYACC_ULPI
, REGDATA
, 0, 8)
256 REG32(GTXFIFOSIZ0
, 0x200)
257 FIELD(GTXFIFOSIZ0
, TXFSTADDR_N
, 16, 16)
258 FIELD(GTXFIFOSIZ0
, TXFDEP_N
, 0, 16)
259 REG32(GTXFIFOSIZ1
, 0x204)
260 FIELD(GTXFIFOSIZ1
, TXFSTADDR_N
, 16, 16)
261 FIELD(GTXFIFOSIZ1
, TXFDEP_N
, 0, 16)
262 REG32(GTXFIFOSIZ2
, 0x208)
263 FIELD(GTXFIFOSIZ2
, TXFSTADDR_N
, 16, 16)
264 FIELD(GTXFIFOSIZ2
, TXFDEP_N
, 0, 16)
265 REG32(GTXFIFOSIZ3
, 0x20c)
266 FIELD(GTXFIFOSIZ3
, TXFSTADDR_N
, 16, 16)
267 FIELD(GTXFIFOSIZ3
, TXFDEP_N
, 0, 16)
268 REG32(GTXFIFOSIZ4
, 0x210)
269 FIELD(GTXFIFOSIZ4
, TXFSTADDR_N
, 16, 16)
270 FIELD(GTXFIFOSIZ4
, TXFDEP_N
, 0, 16)
271 REG32(GTXFIFOSIZ5
, 0x214)
272 FIELD(GTXFIFOSIZ5
, TXFSTADDR_N
, 16, 16)
273 FIELD(GTXFIFOSIZ5
, TXFDEP_N
, 0, 16)
274 REG32(GRXFIFOSIZ0
, 0x280)
275 FIELD(GRXFIFOSIZ0
, RXFSTADDR_N
, 16, 16)
276 FIELD(GRXFIFOSIZ0
, RXFDEP_N
, 0, 16)
277 REG32(GRXFIFOSIZ1
, 0x284)
278 FIELD(GRXFIFOSIZ1
, RXFSTADDR_N
, 16, 16)
279 FIELD(GRXFIFOSIZ1
, RXFDEP_N
, 0, 16)
280 REG32(GRXFIFOSIZ2
, 0x288)
281 FIELD(GRXFIFOSIZ2
, RXFSTADDR_N
, 16, 16)
282 FIELD(GRXFIFOSIZ2
, RXFDEP_N
, 0, 16)
283 REG32(GEVNTADRLO_0
, 0x300)
284 REG32(GEVNTADRHI_0
, 0x304)
285 REG32(GEVNTSIZ_0
, 0x308)
286 FIELD(GEVNTSIZ_0
, EVNTINTRPTMASK
, 31, 1)
287 FIELD(GEVNTSIZ_0
, RESERVED_30_16
, 16, 15)
288 FIELD(GEVNTSIZ_0
, EVENTSIZ
, 0, 16)
289 REG32(GEVNTCOUNT_0
, 0x30c)
290 FIELD(GEVNTCOUNT_0
, EVNT_HANDLER_BUSY
, 31, 1)
291 FIELD(GEVNTCOUNT_0
, RESERVED_30_16
, 16, 15)
292 FIELD(GEVNTCOUNT_0
, EVNTCOUNT
, 0, 16)
293 REG32(GEVNTADRLO_1
, 0x310)
294 REG32(GEVNTADRHI_1
, 0x314)
295 REG32(GEVNTSIZ_1
, 0x318)
296 FIELD(GEVNTSIZ_1
, EVNTINTRPTMASK
, 31, 1)
297 FIELD(GEVNTSIZ_1
, RESERVED_30_16
, 16, 15)
298 FIELD(GEVNTSIZ_1
, EVENTSIZ
, 0, 16)
299 REG32(GEVNTCOUNT_1
, 0x31c)
300 FIELD(GEVNTCOUNT_1
, EVNT_HANDLER_BUSY
, 31, 1)
301 FIELD(GEVNTCOUNT_1
, RESERVED_30_16
, 16, 15)
302 FIELD(GEVNTCOUNT_1
, EVNTCOUNT
, 0, 16)
303 REG32(GEVNTADRLO_2
, 0x320)
304 REG32(GEVNTADRHI_2
, 0x324)
305 REG32(GEVNTSIZ_2
, 0x328)
306 FIELD(GEVNTSIZ_2
, EVNTINTRPTMASK
, 31, 1)
307 FIELD(GEVNTSIZ_2
, RESERVED_30_16
, 16, 15)
308 FIELD(GEVNTSIZ_2
, EVENTSIZ
, 0, 16)
309 REG32(GEVNTCOUNT_2
, 0x32c)
310 FIELD(GEVNTCOUNT_2
, EVNT_HANDLER_BUSY
, 31, 1)
311 FIELD(GEVNTCOUNT_2
, RESERVED_30_16
, 16, 15)
312 FIELD(GEVNTCOUNT_2
, EVNTCOUNT
, 0, 16)
313 REG32(GEVNTADRLO_3
, 0x330)
314 REG32(GEVNTADRHI_3
, 0x334)
315 REG32(GEVNTSIZ_3
, 0x338)
316 FIELD(GEVNTSIZ_3
, EVNTINTRPTMASK
, 31, 1)
317 FIELD(GEVNTSIZ_3
, RESERVED_30_16
, 16, 15)
318 FIELD(GEVNTSIZ_3
, EVENTSIZ
, 0, 16)
319 REG32(GEVNTCOUNT_3
, 0x33c)
320 FIELD(GEVNTCOUNT_3
, EVNT_HANDLER_BUSY
, 31, 1)
321 FIELD(GEVNTCOUNT_3
, RESERVED_30_16
, 16, 15)
322 FIELD(GEVNTCOUNT_3
, EVNTCOUNT
, 0, 16)
323 REG32(GHWPARAMS8
, 0x500)
324 REG32(GTXFIFOPRIDEV
, 0x510)
325 FIELD(GTXFIFOPRIDEV
, RESERVED_31_N
, 6, 26)
326 FIELD(GTXFIFOPRIDEV
, GTXFIFOPRIDEV
, 0, 6)
327 REG32(GTXFIFOPRIHST
, 0x518)
328 FIELD(GTXFIFOPRIHST
, RESERVED_31_16
, 3, 29)
329 FIELD(GTXFIFOPRIHST
, GTXFIFOPRIHST
, 0, 3)
330 REG32(GRXFIFOPRIHST
, 0x51c)
331 FIELD(GRXFIFOPRIHST
, RESERVED_31_16
, 3, 29)
332 FIELD(GRXFIFOPRIHST
, GRXFIFOPRIHST
, 0, 3)
333 REG32(GDMAHLRATIO
, 0x524)
334 FIELD(GDMAHLRATIO
, RESERVED_31_13
, 13, 19)
335 FIELD(GDMAHLRATIO
, HSTRXFIFO
, 8, 5)
336 FIELD(GDMAHLRATIO
, RESERVED_7_5
, 5, 3)
337 FIELD(GDMAHLRATIO
, HSTTXFIFO
, 0, 5)
339 FIELD(GFLADJ
, GFLADJ_REFCLK_240MHZDECR_PLS1
, 31, 1)
340 FIELD(GFLADJ
, GFLADJ_REFCLK_240MHZ_DECR
, 24, 7)
341 FIELD(GFLADJ
, GFLADJ_REFCLK_LPM_SEL
, 23, 1)
342 FIELD(GFLADJ
, RESERVED_22
, 22, 1)
343 FIELD(GFLADJ
, GFLADJ_REFCLK_FLADJ
, 8, 14)
344 FIELD(GFLADJ
, GFLADJ_30MHZ_SDBND_SEL
, 7, 1)
345 FIELD(GFLADJ
, GFLADJ_30MHZ
, 0, 6)
347 #define DWC3_GLOBAL_OFFSET 0xC100
348 static void reset_csr(USBDWC3
* s
)
352 * We reset all CSR regs except GCTL, GUCTL, GSTS, GSNPSID, GGPIO, GUID,
353 * GUSB2PHYCFGn registers and GUSB3PIPECTLn registers. We will skip PHY
354 * register as we don't implement them.
356 for (i
= 0; i
< USB_DWC3_R_MAX
; i
++) {
370 case R_GHWPARAMS0
...R_GHWPARAMS7
:
375 register_reset(&s
->regs_info
[i
]);
380 xhci_sysbus_reset(DEVICE(&s
->sysbus_xhci
));
383 static void usb_dwc3_gctl_postw(RegisterInfo
*reg
, uint64_t val64
)
385 USBDWC3
*s
= USB_DWC3(reg
->opaque
);
387 if (ARRAY_FIELD_EX32(s
->regs
, GCTL
, CORESOFTRESET
)) {
392 static void usb_dwc3_guid_postw(RegisterInfo
*reg
, uint64_t val64
)
394 USBDWC3
*s
= USB_DWC3(reg
->opaque
);
396 s
->regs
[R_GUID
] = s
->cfg
.dwc_usb3_user
;
399 static const RegisterAccessInfo usb_dwc3_regs_info
[] = {
400 { .name
= "GSBUSCFG0", .addr
= A_GSBUSCFG0
,
403 },{ .name
= "GSBUSCFG1", .addr
= A_GSBUSCFG1
,
407 },{ .name
= "GTXTHRCFG", .addr
= A_GTXTHRCFG
,
410 },{ .name
= "GRXTHRCFG", .addr
= A_GRXTHRCFG
,
413 },{ .name
= "GCTL", .addr
= A_GCTL
,
414 .reset
= 0x30c13004, .post_write
= usb_dwc3_gctl_postw
,
415 },{ .name
= "GPMSTS", .addr
= A_GPMSTS
,
418 },{ .name
= "GSTS", .addr
= A_GSTS
,
423 },{ .name
= "GUCTL1", .addr
= A_GUCTL1
,
427 },{ .name
= "GSNPSID", .addr
= A_GSNPSID
,
430 },{ .name
= "GGPIO", .addr
= A_GGPIO
,
433 },{ .name
= "GUID", .addr
= A_GUID
,
434 .reset
= 0x12345678, .post_write
= usb_dwc3_guid_postw
,
435 },{ .name
= "GUCTL", .addr
= A_GUCTL
,
439 },{ .name
= "GBUSERRADDRLO", .addr
= A_GBUSERRADDRLO
,
441 },{ .name
= "GBUSERRADDRHI", .addr
= A_GBUSERRADDRHI
,
443 },{ .name
= "GHWPARAMS0", .addr
= A_GHWPARAMS0
,
445 },{ .name
= "GHWPARAMS1", .addr
= A_GHWPARAMS1
,
447 },{ .name
= "GHWPARAMS2", .addr
= A_GHWPARAMS2
,
449 },{ .name
= "GHWPARAMS3", .addr
= A_GHWPARAMS3
,
451 },{ .name
= "GHWPARAMS4", .addr
= A_GHWPARAMS4
,
453 },{ .name
= "GHWPARAMS5", .addr
= A_GHWPARAMS5
,
455 },{ .name
= "GHWPARAMS6", .addr
= A_GHWPARAMS6
,
457 },{ .name
= "GHWPARAMS7", .addr
= A_GHWPARAMS7
,
459 },{ .name
= "GDBGFIFOSPACE", .addr
= A_GDBGFIFOSPACE
,
463 },{ .name
= "GUCTL2", .addr
= A_GUCTL2
,
467 },{ .name
= "GUSB2PHYCFG", .addr
= A_GUSB2PHYCFG
,
471 },{ .name
= "GUSB2I2CCTL", .addr
= A_GUSB2I2CCTL
,
474 },{ .name
= "GUSB2PHYACC_ULPI", .addr
= A_GUSB2PHYACC_ULPI
,
477 },{ .name
= "GTXFIFOSIZ0", .addr
= A_GTXFIFOSIZ0
,
480 },{ .name
= "GTXFIFOSIZ1", .addr
= A_GTXFIFOSIZ1
,
483 },{ .name
= "GTXFIFOSIZ2", .addr
= A_GTXFIFOSIZ2
,
486 },{ .name
= "GTXFIFOSIZ3", .addr
= A_GTXFIFOSIZ3
,
489 },{ .name
= "GTXFIFOSIZ4", .addr
= A_GTXFIFOSIZ4
,
492 },{ .name
= "GTXFIFOSIZ5", .addr
= A_GTXFIFOSIZ5
,
495 },{ .name
= "GRXFIFOSIZ0", .addr
= A_GRXFIFOSIZ0
,
498 },{ .name
= "GRXFIFOSIZ1", .addr
= A_GRXFIFOSIZ1
,
501 },{ .name
= "GRXFIFOSIZ2", .addr
= A_GRXFIFOSIZ2
,
504 },{ .name
= "GEVNTADRLO_0", .addr
= A_GEVNTADRLO_0
,
506 },{ .name
= "GEVNTADRHI_0", .addr
= A_GEVNTADRHI_0
,
508 },{ .name
= "GEVNTSIZ_0", .addr
= A_GEVNTSIZ_0
,
511 },{ .name
= "GEVNTCOUNT_0", .addr
= A_GEVNTCOUNT_0
,
514 },{ .name
= "GEVNTADRLO_1", .addr
= A_GEVNTADRLO_1
,
516 },{ .name
= "GEVNTADRHI_1", .addr
= A_GEVNTADRHI_1
,
518 },{ .name
= "GEVNTSIZ_1", .addr
= A_GEVNTSIZ_1
,
521 },{ .name
= "GEVNTCOUNT_1", .addr
= A_GEVNTCOUNT_1
,
524 },{ .name
= "GEVNTADRLO_2", .addr
= A_GEVNTADRLO_2
,
526 },{ .name
= "GEVNTADRHI_2", .addr
= A_GEVNTADRHI_2
,
528 },{ .name
= "GEVNTSIZ_2", .addr
= A_GEVNTSIZ_2
,
531 },{ .name
= "GEVNTCOUNT_2", .addr
= A_GEVNTCOUNT_2
,
534 },{ .name
= "GEVNTADRLO_3", .addr
= A_GEVNTADRLO_3
,
536 },{ .name
= "GEVNTADRHI_3", .addr
= A_GEVNTADRHI_3
,
538 },{ .name
= "GEVNTSIZ_3", .addr
= A_GEVNTSIZ_3
,
541 },{ .name
= "GEVNTCOUNT_3", .addr
= A_GEVNTCOUNT_3
,
544 },{ .name
= "GHWPARAMS8", .addr
= A_GHWPARAMS8
,
546 },{ .name
= "GTXFIFOPRIDEV", .addr
= A_GTXFIFOPRIDEV
,
549 },{ .name
= "GTXFIFOPRIHST", .addr
= A_GTXFIFOPRIHST
,
552 },{ .name
= "GRXFIFOPRIHST", .addr
= A_GRXFIFOPRIHST
,
555 },{ .name
= "GDMAHLRATIO", .addr
= A_GDMAHLRATIO
,
558 },{ .name
= "GFLADJ", .addr
= A_GFLADJ
,
566 static void usb_dwc3_reset(DeviceState
*dev
)
568 USBDWC3
*s
= USB_DWC3(dev
);
571 for (i
= 0; i
< ARRAY_SIZE(s
->regs_info
); ++i
) {
573 case R_GHWPARAMS0
...R_GHWPARAMS7
:
578 register_reset(&s
->regs_info
[i
]);
582 xhci_sysbus_reset(DEVICE(&s
->sysbus_xhci
));
585 static const MemoryRegionOps usb_dwc3_ops
= {
586 .read
= register_read_memory
,
587 .write
= register_write_memory
,
588 .endianness
= DEVICE_LITTLE_ENDIAN
,
590 .min_access_size
= 4,
591 .max_access_size
= 4,
595 static void usb_dwc3_realize(DeviceState
*dev
, Error
**errp
)
597 USBDWC3
*s
= USB_DWC3(dev
);
598 SysBusDevice
*sbd
= SYS_BUS_DEVICE(dev
);
601 sysbus_realize(SYS_BUS_DEVICE(&s
->sysbus_xhci
), &err
);
603 error_propagate(errp
, err
);
607 memory_region_add_subregion(&s
->iomem
, 0,
608 sysbus_mmio_get_region(SYS_BUS_DEVICE(&s
->sysbus_xhci
), 0));
609 sysbus_init_mmio(sbd
, &s
->iomem
);
612 * Device Configuration
614 s
->regs
[R_GHWPARAMS0
] = 0x40204048 | s
->cfg
.mode
;
615 s
->regs
[R_GHWPARAMS1
] = 0x222493b;
616 s
->regs
[R_GHWPARAMS2
] = 0x12345678;
617 s
->regs
[R_GHWPARAMS3
] = 0x618c088;
618 s
->regs
[R_GHWPARAMS4
] = 0x47822004;
619 s
->regs
[R_GHWPARAMS5
] = 0x4202088;
620 s
->regs
[R_GHWPARAMS6
] = 0x7850c20;
621 s
->regs
[R_GHWPARAMS7
] = 0x0;
622 s
->regs
[R_GHWPARAMS8
] = 0x478;
625 static void usb_dwc3_init(Object
*obj
)
627 USBDWC3
*s
= USB_DWC3(obj
);
628 RegisterInfoArray
*reg_array
;
630 memory_region_init(&s
->iomem
, obj
, TYPE_USB_DWC3
, DWC3_SIZE
);
632 register_init_block32(DEVICE(obj
), usb_dwc3_regs_info
,
633 ARRAY_SIZE(usb_dwc3_regs_info
),
634 s
->regs_info
, s
->regs
,
638 memory_region_add_subregion(&s
->iomem
,
641 object_initialize_child(obj
, "dwc3-xhci", &s
->sysbus_xhci
,
643 qdev_alias_all_properties(DEVICE(&s
->sysbus_xhci
), obj
);
645 s
->cfg
.mode
= HOST_MODE
;
648 static const VMStateDescription vmstate_usb_dwc3
= {
651 .fields
= (VMStateField
[]) {
652 VMSTATE_UINT32_ARRAY(regs
, USBDWC3
, USB_DWC3_R_MAX
),
653 VMSTATE_UINT8(cfg
.mode
, USBDWC3
),
654 VMSTATE_UINT32(cfg
.dwc_usb3_user
, USBDWC3
),
655 VMSTATE_END_OF_LIST()
659 static Property usb_dwc3_properties
[] = {
660 DEFINE_PROP_UINT32("DWC_USB3_USERID", USBDWC3
, cfg
.dwc_usb3_user
,
662 DEFINE_PROP_END_OF_LIST(),
665 static void usb_dwc3_class_init(ObjectClass
*klass
, void *data
)
667 DeviceClass
*dc
= DEVICE_CLASS(klass
);
669 dc
->reset
= usb_dwc3_reset
;
670 dc
->realize
= usb_dwc3_realize
;
671 dc
->vmsd
= &vmstate_usb_dwc3
;
672 device_class_set_props(dc
, usb_dwc3_properties
);
675 static const TypeInfo usb_dwc3_info
= {
676 .name
= TYPE_USB_DWC3
,
677 .parent
= TYPE_SYS_BUS_DEVICE
,
678 .instance_size
= sizeof(USBDWC3
),
679 .class_init
= usb_dwc3_class_init
,
680 .instance_init
= usb_dwc3_init
,
683 static void usb_dwc3_register_types(void)
685 type_register_static(&usb_dwc3_info
);
688 type_init(usb_dwc3_register_types
)