Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/usb/usb_t210.h
1476 views
1
/*
2
* Enhanced & eXtensible USB device (EDCI & XDCI) driver for Tegra X1
3
*
4
* Copyright (c) 2019-2021 CTCaer
5
*
6
* This program is free software; you can redistribute it and/or modify it
7
* under the terms and conditions of the GNU General Public License,
8
* version 2, as published by the Free Software Foundation.
9
*
10
* This program is distributed in the hope it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13
* more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#ifndef _USB_T210_H_
20
#define _USB_T210_H_
21
22
#include <utils/types.h>
23
24
/* EHCI USB */
25
26
/* General USB registers */
27
#define USB1_IF_USB_SUSP_CTRL 0x400
28
#define SUSP_CTRL_USB_WAKE_ON_CNNT_EN_DEV BIT(3)
29
#define SUSP_CTRL_USB_WAKE_ON_DISCON_EN_DEV BIT(4)
30
#define SUSP_CTRL_USB_PHY_CLK_VALID BIT(7)
31
#define SUSP_CTRL_UTMIP_RESET BIT(11)
32
#define SUSP_CTRL_UTMIP_PHY_ENB BIT(12)
33
#define SUSP_CTRL_UTMIP_UTMIP_SUSPL1_SET BIT(25)
34
#define USB1_IF_USB_PHY_VBUS_SENSORS 0x404
35
#define USB1_UTMIP_XCVR_CFG0 0x808
36
#define USB1_UTMIP_BIAS_CFG0 0x80C
37
#define USB1_UTMIP_HSRX_CFG0 0x810
38
#define USB1_UTMIP_HSRX_CFG1 0x814
39
#define USB1_UTMIP_TX_CFG0 0x820
40
#define USB1_UTMIP_MISC_CFG1 0x828
41
#define USB1_UTMIP_DEBOUNCE_CFG0 0x82C
42
#define USB1_UTMIP_BAT_CHRG_CFG0 0x830
43
#define BAT_CHRG_CFG0_PWRDOWN_CHRG BIT(0)
44
#define BAT_CHRG_CFG0_OP_SRC_EN BIT(3)
45
#define USB1_UTMIP_SPARE_CFG0 0x834
46
#define USB1_UTMIP_XCVR_CFG1 0x838
47
#define USB1_UTMIP_BIAS_CFG1 0x83C
48
#define USB1_UTMIP_BIAS_CFG2 0x850
49
#define USB1_UTMIP_XCVR_CFG2 0x854
50
#define USB1_UTMIP_XCVR_CFG3 0x858
51
52
/* USB Queue Head Descriptor */
53
#define USB2_QH_USB2D_QH_EP_BASE (USB_BASE + 0x1000)
54
#define USB_QHD_EP_CAP_IOS_ENABLE BIT(15)
55
#define USB_QHD_EP_CAP_MAX_PKT_LEN_MASK 0x7FF
56
#define USB_QHD_EP_CAP_ZERO_LEN_TERM_DIS BIT(29)
57
#define USB_QHD_EP_CAP_MULTI_NON_ISO (0 << 30)
58
#define USB_QHD_EP_CAP_MULTI_1 (1 << 30)
59
#define USB_QHD_EP_CAP_MULTI_2 (2 << 30)
60
#define USB_QHD_EP_CAP_MULTI_3 (3 << 30)
61
62
#define USB_QHD_TOKEN_XFER_ERROR BIT(3)
63
#define USB_QHD_TOKEN_BUFFER_ERROR BIT(5)
64
#define USB_QHD_TOKEN_HALTED BIT(6)
65
#define USB_QHD_TOKEN_ACTIVE BIT(7)
66
#define USB_QHD_TOKEN_MULT_OVERR_MASK (2 << 10)
67
#define USB_QHD_TOKEN_IRQ_ON_COMPLETE BIT(15)
68
#define USB_QHD_TOKEN_TOTAL_BYTES_SHIFT 16
69
70
/* USB_OTG/USB_1 controllers register bits */
71
#define USB2D_PORTSC1_SUSP BIT(7)
72
73
#define USB2D_USBCMD_RUN BIT(0)
74
#define USB2D_USBCMD_RESET BIT(1)
75
#define USB2D_USBCMD_ITC_MASK (0xFF << 16)
76
77
#define USB2D_USBSTS_UI BIT(0)
78
#define USB2D_USBSTS_UEI BIT(1)
79
#define USB2D_USBSTS_PCI BIT(2)
80
#define USB2D_USBSTS_FRI BIT(3)
81
#define USB2D_USBSTS_SEI BIT(4)
82
#define USB2D_USBSTS_AAI BIT(5)
83
#define USB2D_USBSTS_URI BIT(6)
84
#define USB2D_USBSTS_SRI BIT(7)
85
#define USB2D_USBSTS_SLI BIT(8)
86
87
#define USB2D_USBMODE_CM_MASK (3 << 0)
88
#define USB2D_USBMODE_CM_IDLE 0
89
#define USB2D_USBMODE_CM_RSVD 1
90
#define USB2D_USBMODE_CM_DEVICE 2
91
#define USB2D_USBMODE_CM_HOST 3
92
93
#define USB2D_ENDPT_STATUS_RX_OFFSET BIT(0)
94
#define USB2D_ENDPT_STATUS_TX_OFFSET BIT(16)
95
96
#define USB2D_ENDPTCTRL_RX_EP_STALL BIT(0)
97
#define USB2D_ENDPTCTRL_RX_EP_TYPE_CTRL (0 << 2)
98
#define USB2D_ENDPTCTRL_RX_EP_TYPE_ISO (1 << 2)
99
#define USB2D_ENDPTCTRL_RX_EP_TYPE_BULK (2 << 2)
100
#define USB2D_ENDPTCTRL_RX_EP_TYPE_INTR (3 << 2)
101
#define USB2D_ENDPTCTRL_RX_EP_TYPE_MASK (3 << 2)
102
#define USB2D_ENDPTCTRL_RX_EP_INHIBIT BIT(5)
103
#define USB2D_ENDPTCTRL_RX_EP_RESET BIT(6)
104
#define USB2D_ENDPTCTRL_RX_EP_ENABLE BIT(7)
105
#define USB2D_ENDPTCTRL_TX_EP_STALL BIT(16)
106
#define USB2D_ENDPTCTRL_TX_EP_TYPE_CTRL (0 << 18)
107
#define USB2D_ENDPTCTRL_TX_EP_TYPE_ISO (1 << 18)
108
#define USB2D_ENDPTCTRL_TX_EP_TYPE_BULK (2 << 18)
109
#define USB2D_ENDPTCTRL_TX_EP_TYPE_INTR (3 << 18)
110
#define USB2D_ENDPTCTRL_TX_EP_TYPE_MASK (3 << 18)
111
#define USB2D_ENDPTCTRL_TX_EP_INHIBIT BIT(21)
112
#define USB2D_ENDPTCTRL_TX_EP_RESET BIT(22)
113
#define USB2D_ENDPTCTRL_TX_EP_ENABLE BIT(23)
114
115
#define USB2D_HOSTPC1_DEVLC_ASUS BIT(17)
116
#define USB2D_HOSTPC1_DEVLC_PHCD BIT(22)
117
#define USB2D_HOSTPC1_DEVLC_PSPD_MASK (3 << 25)
118
119
#define USB2D_OTGSC_USB_ID_PULLUP BIT(5)
120
#define USB2D_OTGSC_USB_IRQ_STS_MASK (0x7F << 16)
121
122
/* USB_OTG/USB_1 controllers registers */
123
typedef struct _t210_usb2d_t
124
{
125
vu32 id;
126
vu32 unk0;
127
vu32 hw_host;
128
vu32 hw_device;
129
vu32 hw_txbuf;
130
vu32 hw_rxbuf;
131
vu32 unk1[26];
132
vu32 gptimer0ld;
133
vu32 gptimer0ctrl;
134
vu32 gptimer1ld;
135
vu32 gptimer1ctrl;
136
vu32 unk2[28];
137
vu16 caplength;
138
vu16 hciversion;
139
vu32 hcsparams;
140
vu32 hccparams;
141
vu32 unk3[5];
142
vu32 dciversion;
143
vu32 dccparams;
144
vu32 extsts;
145
vu32 usbextintr;
146
vu32 usbcmd;
147
vu32 usbsts;
148
vu32 usbintr;
149
vu32 frindex;
150
vu32 unk4;
151
vu32 periodiclistbase;
152
vu32 asynclistaddr;
153
vu32 asyncttsts;
154
vu32 burstsize;
155
vu32 txfilltuning;
156
vu32 unk6;
157
vu32 icusb_ctrl;
158
vu32 ulpi_viewport;
159
vu32 rsvd0[4];
160
vu32 portsc1;
161
vu32 rsvd1[15];
162
vu32 hostpc1_devlc;
163
vu32 rsvd2[15];
164
vu32 otgsc;
165
vu32 usbmode;
166
vu32 unk10;
167
vu32 endptnak;
168
vu32 endptnak_enable;
169
vu32 endptsetupstat;
170
vu32 endptprime;
171
vu32 endptflush;
172
vu32 endptstatus;
173
vu32 endptcomplete;
174
vu32 endptctrl[16];
175
} t210_usb2d_t;
176
177
178
/* XHCI USB */
179
180
/* XUSB DEV XHCI registers */
181
#define XUSB_DEV_XHCI_DB 0x4
182
#define XUSB_DEV_XHCI_ERSTSZ 0x8
183
#define XUSB_DEV_XHCI_ERST0BALO 0x10
184
#define XUSB_DEV_XHCI_ERST0BAHI 0x14
185
#define XUSB_DEV_XHCI_ERST1BALO 0x18
186
#define XUSB_DEV_XHCI_ERST1BAHI 0x1C
187
#define XUSB_DEV_XHCI_ERDPLO 0x20
188
#define XHCI_ERDPLO_EHB BIT(3)
189
#define XUSB_DEV_XHCI_ERDPHI 0x24
190
#define XUSB_DEV_XHCI_EREPLO 0x28
191
#define XCHI_ECS BIT(0)
192
#define XUSB_DEV_XHCI_EREPHI 0x2C
193
#define XUSB_DEV_XHCI_CTRL 0x30
194
#define XHCI_CTRL_RUN BIT(0)
195
#define XHCI_CTRL_LSE BIT(1)
196
#define XHCI_CTRL_IE BIT(4)
197
#define XHCI_CTRL_ENABLE BIT(31)
198
#define XUSB_DEV_XHCI_ST 0x34
199
#define XHCI_ST_RC BIT(0)
200
#define XHCI_ST_IP BIT(4)
201
#define XUSB_DEV_XHCI_RT_IMOD 0x38
202
#define XUSB_DEV_XHCI_PORTSC 0x3C
203
#define XHCI_PORTSC_CCS BIT(0)
204
#define XHCI_PORTSC_PED BIT(1)
205
#define XHCI_PORTSC_PR BIT(4)
206
#define XHCI_PORTSC_PLS_MASK (0xF << 5)
207
#define XHCI_PORTSC_PLS_U0 (0 << 5)
208
#define XHCI_PORTSC_PLS_U1 (1 << 5)
209
#define XHCI_PORTSC_PLS_U2 (2 << 5)
210
#define XHCI_PORTSC_PLS_U3 (3 << 5)
211
#define XHCI_PORTSC_PLS_DISABLED (4 << 5)
212
#define XHCI_PORTSC_PLS_RXDETECT (5 << 5)
213
#define XHCI_PORTSC_PLS_INACTIVE (6 << 5)
214
#define XHCI_PORTSC_PLS_POLLING (7 << 5)
215
#define XHCI_PORTSC_PLS_RECOVERY (8 << 5)
216
#define XHCI_PORTSC_PLS_HOTRESET (9 << 5)
217
#define XHCI_PORTSC_PLS_COMPLIANCE (10 << 5)
218
#define XHCI_PORTSC_PLS_LOOPBACK (11 << 5)
219
#define XHCI_PORTSC_PLS_RESUME (15 << 5)
220
#define XHCI_PORTSC_PS (0xF << 10)
221
#define XHCI_PORTSC_LWS BIT(16)
222
#define XHCI_PORTSC_CSC BIT(17)
223
#define XHCI_PORTSC_WRC BIT(19)
224
#define XHCI_PORTSC_PRC BIT(21)
225
#define XHCI_PORTSC_PLC BIT(22)
226
#define XHCI_PORTSC_CEC BIT(23)
227
#define XHCI_PORTSC_WPR BIT(30)
228
#define XUSB_DEV_XHCI_ECPLO 0x40
229
#define XUSB_DEV_XHCI_ECPHI 0x44
230
#define XUSB_DEV_XHCI_EP_HALT 0x50
231
#define XHCI_EP_HALT_DCI_EP0_IN BIT(0)
232
#define XUSB_DEV_XHCI_EP_PAUSE 0x54
233
#define XUSB_DEV_XHCI_EP_RELOAD 0x58
234
#define XUSB_DEV_XHCI_EP_STCHG 0x5C
235
#define XUSB_DEV_XHCI_PORTHALT 0x6C
236
#define XUSB_DEV_XHCI_EP_STOPPED 0x78
237
#define XHCI_PORTHALT_HALT_LTSSM BIT(0)
238
#define XHCI_PORTHALT_STCHG_REQ BIT(20)
239
#define XUSB_DEV_XHCI_CFG_DEV_FE 0x85C
240
#define XHCI_CFG_DEV_FE_PORTREGSEL_MASK (3 << 0)
241
#define XHCI_CFG_DEV_FE_PORTREGSEL_SS (1 << 0)
242
#define XHCI_CFG_DEV_FE_PORTREGSEL_HSFS (2 << 0)
243
244
/* XUSB DEV PCI registers */
245
#define XUSB_CFG_1 0x4
246
#define CFG_1_IO_SPACE BIT(0)
247
#define CFG_1_MEMORY_SPACE BIT(1)
248
#define CFG_1_BUS_MASTER BIT(2)
249
#define XUSB_CFG_4 0x10
250
#define CFG_4_ADDRESS_TYPE_32_BIT (0 << 1)
251
#define CFG_4_ADDRESS_TYPE_64_BIT (2 << 1)
252
253
/* XUSB DEV Device registers */
254
#define XUSB_DEV_CONFIGURATION 0x180
255
#define DEV_CONFIGURATION_EN_FPCI BIT(0)
256
#define XUSB_DEV_INTR_MASK 0x188
257
#define DEV_INTR_MASK_IP_INT_MASK BIT(16)
258
259
/* XUSB Pad Control registers */
260
#define XUSB_PADCTL_USB2_PAD_MUX 0x4
261
#define PADCTL_USB2_PAD_MUX_USB2_OTG_PAD_PORT0_USB2 (0 << 0)
262
#define PADCTL_USB2_PAD_MUX_USB2_OTG_PAD_PORT0_XUSB (1 << 0)
263
#define PADCTL_USB2_PAD_MUX_USB2_OTG_PAD_PORT0_MASK (3 << 0)
264
#define PADCTL_USB2_PAD_MUX_USB2_BIAS_PAD_USB2 (0 << 18)
265
#define PADCTL_USB2_PAD_MUX_USB2_BIAS_PAD_XUSB (1 << 18)
266
#define PADCTL_USB2_PAD_MUX_USB2_BIAS_PAD_MASK (3 << 18)
267
#define XUSB_PADCTL_USB2_PORT_CAP 0x8
268
#define PADCTL_USB2_PORT_CAP_PORT_0_CAP_DIS (0 << 0)
269
#define PADCTL_USB2_PORT_CAP_PORT_0_CAP_HOST (1 << 0)
270
#define PADCTL_USB2_PORT_CAP_PORT_0_CAP_DEV (2 << 0)
271
#define PADCTL_USB2_PORT_CAP_PORT_0_CAP_OTG (3 << 0)
272
#define PADCTL_USB2_PORT_CAP_PORT_0_CAP_MASK (3 << 0)
273
#define XUSB_PADCTL_SS_PORT_MAP 0x14
274
#define PADCTL_SS_PORT_MAP_PORT0_MASK (0xF << 0)
275
#define XUSB_PADCTL_ELPG_PROGRAM_0 0x20
276
#define XUSB_PADCTL_ELPG_PROGRAM_1 0x24
277
#define XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD0_CTL0 0x80
278
#define XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD0_CTL1 0x84
279
#define XUSB_PADCTL_USB2_OTG_PAD0_CTL_0 0x88
280
#define XUSB_PADCTL_USB2_OTG_PAD0_CTL_1 0x8C
281
#define XUSB_PADCTL_USB2_BIAS_PAD_CTL_0 0x284
282
#define XUSB_PADCTL_USB2_BIAS_PAD_CTL_1 0x288
283
#define XUSB_PADCTL_USB2_VBUS_ID 0xC60
284
#define PADCTL_USB2_VBUS_ID_VBUS_OVR_EN (1 << 12)
285
#define PADCTL_USB2_VBUS_ID_VBUS_OVR_MASK (3 << 12)
286
#define PADCTL_USB2_VBUS_ID_VBUS_ON BIT(14)
287
#define PADCTL_USB2_VBUS_ID_SRC_ID_OVR_EN (1 << 16)
288
#define PADCTL_USB2_VBUS_ID_SRC_MASK (3 << 16)
289
#define PADCTL_USB2_VBUS_ID_OVR_GND (0 << 18)
290
#define PADCTL_USB2_VBUS_ID_OVR_C (1 << 18)
291
#define PADCTL_USB2_VBUS_ID_OVR_B (2 << 18)
292
#define PADCTL_USB2_VBUS_ID_OVR_A (4 << 18)
293
#define PADCTL_USB2_VBUS_ID_OVR_FLOAT (8 << 18)
294
#define PADCTL_USB2_VBUS_ID_OVR_MASK (0xF << 18)
295
296
#endif
297
298