xref: /rk3399_ARM-atf/plat/brcm/board/stingray/include/usb_phy.h (revision 29e11bb29922da1fede56700286a967701df8289)
1*682fe370SBharat Gooty /*
2*682fe370SBharat Gooty  * Copyright (c) 2017 - 2021, Broadcom
3*682fe370SBharat Gooty  *
4*682fe370SBharat Gooty  * SPDX-License-Identifier: BSD-3-Clause
5*682fe370SBharat Gooty  */
6*682fe370SBharat Gooty 
7*682fe370SBharat Gooty #ifndef USB_PHY_H
8*682fe370SBharat Gooty #define USB_PHY_H
9*682fe370SBharat Gooty 
10*682fe370SBharat Gooty #include <stdint.h>
11*682fe370SBharat Gooty 
12*682fe370SBharat Gooty #include <common/debug.h>
13*682fe370SBharat Gooty #include <drivers/delay_timer.h>
14*682fe370SBharat Gooty #include <lib/mmio.h>
15*682fe370SBharat Gooty 
16*682fe370SBharat Gooty #include <platform_def.h>
17*682fe370SBharat Gooty 
18*682fe370SBharat Gooty #define DRDU2_U2PLL_NDIV_FRAC_OFFSET            0x0U
19*682fe370SBharat Gooty 
20*682fe370SBharat Gooty #define DRDU2_U2PLL_NDIV_INT                    0x4U
21*682fe370SBharat Gooty 
22*682fe370SBharat Gooty #define DRDU2_U2PLL_CTRL                        0x8U
23*682fe370SBharat Gooty #define DRDU2_U2PLL_LOCK                        BIT(6U)
24*682fe370SBharat Gooty #define DRDU2_U2PLL_RESETB                      BIT(5U)
25*682fe370SBharat Gooty #define DRDU2_U2PLL_PDIV_MASK                   0xFU
26*682fe370SBharat Gooty #define DRDU2_U2PLL_PDIV_OFFSET                 1U
27*682fe370SBharat Gooty #define DRDU2_U2PLL_SUSPEND_EN                  BIT(0U)
28*682fe370SBharat Gooty 
29*682fe370SBharat Gooty #define DRDU2_PHY_CTRL                          0x0CU
30*682fe370SBharat Gooty #define DRDU2_U2IDDQ                            BIT(30U)
31*682fe370SBharat Gooty #define DRDU2_U2SOFT_RST_N                      BIT(29U)
32*682fe370SBharat Gooty #define DRDU2_U2PHY_ON_FLAG                     BIT(22U)
33*682fe370SBharat Gooty #define DRDU2_U2PHY_PCTL_MASK                   0xFFFFU
34*682fe370SBharat Gooty #define DRDU2_U2PHY_PCTL_OFFSET                 6U
35*682fe370SBharat Gooty #define DRDU2_U2PHY_RESETB                      BIT(5U)
36*682fe370SBharat Gooty #define DRDU2_U2PHY_ISO                         BIT(4U)
37*682fe370SBharat Gooty #define DRDU2_U2AFE_BG_PWRDWNB                  BIT(3U)
38*682fe370SBharat Gooty #define DRDU2_U2AFE_PLL_PWRDWNB                 BIT(2U)
39*682fe370SBharat Gooty #define DRDU2_U2AFE_LDO_PWRDWNB                 BIT(1U)
40*682fe370SBharat Gooty #define DRDU2_U2CTRL_CORERDY                    BIT(0U)
41*682fe370SBharat Gooty 
42*682fe370SBharat Gooty #define DRDU2_STRAP_CTRL                        0x18U
43*682fe370SBharat Gooty #define DRDU2_FORCE_HOST_MODE                   BIT(5U)
44*682fe370SBharat Gooty #define DRDU2_FORCE_DEVICE_MODE                 BIT(4U)
45*682fe370SBharat Gooty #define BDC_USB_STP_SPD_MASK                    0x7U
46*682fe370SBharat Gooty #define BDC_USB_STP_SPD_OFFSET                  0U
47*682fe370SBharat Gooty 
48*682fe370SBharat Gooty #define DRDU2_PWR_CTRL                          0x1CU
49*682fe370SBharat Gooty #define DRDU2_U2PHY_DFE_SWITCH_PWROKIN_I        BIT(2U)
50*682fe370SBharat Gooty #define DRDU2_U2PHY_DFE_SWITCH_PWRONIN_I        BIT(1U)
51*682fe370SBharat Gooty 
52*682fe370SBharat Gooty #define DRDU2_SOFT_RESET_CTRL                   0x20U
53*682fe370SBharat Gooty #define DRDU2_BDC_AXI_SOFT_RST_N                BIT(0U)
54*682fe370SBharat Gooty 
55*682fe370SBharat Gooty #define USB3H_U2PLL_NDIV_FRAC                   0x4U
56*682fe370SBharat Gooty 
57*682fe370SBharat Gooty #define USB3H_U2PLL_NDIV_INT                    0x8U
58*682fe370SBharat Gooty 
59*682fe370SBharat Gooty #define USB3H_U2PLL_CTRL                        0xCU
60*682fe370SBharat Gooty #define USB3H_U2PLL_LOCK                        BIT(6U)
61*682fe370SBharat Gooty #define USB3H_U2PLL_RESETB                      BIT(5U)
62*682fe370SBharat Gooty #define USB3H_U2PLL_PDIV_MASK                   0xFU
63*682fe370SBharat Gooty #define USB3H_U2PLL_PDIV_OFFSET                 1U
64*682fe370SBharat Gooty 
65*682fe370SBharat Gooty #define USB3H_U2PHY_CTRL                        0x10U
66*682fe370SBharat Gooty #define USB3H_U2PHY_ON_FLAG                     22U
67*682fe370SBharat Gooty #define USB3H_U2PHY_PCTL_MASK                   0xFFFFU
68*682fe370SBharat Gooty #define USB3H_U2PHY_PCTL_OFFSET                 6U
69*682fe370SBharat Gooty #define USB3H_U2PHY_IDDQ                        BIT(29U)
70*682fe370SBharat Gooty #define USB3H_U2PHY_RESETB                      BIT(5U)
71*682fe370SBharat Gooty #define USB3H_U2PHY_ISO                         BIT(4U)
72*682fe370SBharat Gooty #define USB3H_U2AFE_BG_PWRDWNB                  BIT(3U)
73*682fe370SBharat Gooty #define USB3H_U2AFE_PLL_PWRDWNB                 BIT(2U)
74*682fe370SBharat Gooty #define USB3H_U2AFE_LDO_PWRDWNB                 BIT(1U)
75*682fe370SBharat Gooty #define USB3H_U2CTRL_CORERDY                    BIT(0U)
76*682fe370SBharat Gooty 
77*682fe370SBharat Gooty #define USB3H_U3PHY_CTRL                        0x14U
78*682fe370SBharat Gooty #define USB3H_U3SOFT_RST_N                      BIT(30U)
79*682fe370SBharat Gooty #define USB3H_U3MDIO_RESETB_I                   BIT(29U)
80*682fe370SBharat Gooty #define USB3H_U3POR_RESET_I                     BIT(28U)
81*682fe370SBharat Gooty #define USB3H_U3PHY_PCTL_MASK                   0xFFFFU
82*682fe370SBharat Gooty #define USB3H_U3PHY_PCTL_OFFSET                 2U
83*682fe370SBharat Gooty #define USB3H_U3PHY_RESETB                      BIT(1U)
84*682fe370SBharat Gooty 
85*682fe370SBharat Gooty #define USB3H_U3PHY_PLL_CTRL                    0x18U
86*682fe370SBharat Gooty #define USB3H_U3PLL_REFCLK_MASK                 0x7U
87*682fe370SBharat Gooty #define USB3H_U3PLL_REFCLK_OFFSET               4U
88*682fe370SBharat Gooty #define USB3H_U3PLL_SS_LOCK                     BIT(3U)
89*682fe370SBharat Gooty #define USB3H_U3PLL_SEQ_START                   BIT(2U)
90*682fe370SBharat Gooty #define USB3H_U3SSPLL_SUSPEND_EN                BIT(1U)
91*682fe370SBharat Gooty #define USB3H_U3PLL_RESETB                      BIT(0U)
92*682fe370SBharat Gooty 
93*682fe370SBharat Gooty #define USB3H_PWR_CTRL                          0x28U
94*682fe370SBharat Gooty #define USB3H_PWR_CTRL_OVERRIDE_I_R             4U
95*682fe370SBharat Gooty #define USB3H_PWR_CTRL_U2PHY_DFE_SWITCH_PWROKIN BIT(11U)
96*682fe370SBharat Gooty #define USB3H_PWR_CTRL_U2PHY_DFE_SWITCH_PWRONIN BIT(10U)
97*682fe370SBharat Gooty 
98*682fe370SBharat Gooty #define USB3H_SOFT_RESET_CTRL                   0x2CU
99*682fe370SBharat Gooty #define USB3H_XHC_AXI_SOFT_RST_N                BIT(1U)
100*682fe370SBharat Gooty 
101*682fe370SBharat Gooty #define USB3H_PHY_PWR_CTRL                      0x38U
102*682fe370SBharat Gooty #define USB3H_DISABLE_USB30_P0                  BIT(2U)
103*682fe370SBharat Gooty #define USB3H_DISABLE_EUSB_P1                   BIT(1U)
104*682fe370SBharat Gooty #define USB3H_DISABLE_EUSB_P0                   BIT(0U)
105*682fe370SBharat Gooty 
106*682fe370SBharat Gooty 
107*682fe370SBharat Gooty #define DRDU3_U2PLL_NDIV_FRAC                   0x4U
108*682fe370SBharat Gooty 
109*682fe370SBharat Gooty #define DRDU3_U2PLL_NDIV_INT                    0x8U
110*682fe370SBharat Gooty 
111*682fe370SBharat Gooty #define DRDU3_U2PLL_CTRL                        0xCU
112*682fe370SBharat Gooty #define DRDU3_U2PLL_LOCK                        BIT(6U)
113*682fe370SBharat Gooty #define DRDU3_U2PLL_RESETB                      BIT(5U)
114*682fe370SBharat Gooty #define DRDU3_U2PLL_PDIV_MASK                   0xFU
115*682fe370SBharat Gooty #define DRDU3_U2PLL_PDIV_OFFSET                 1U
116*682fe370SBharat Gooty 
117*682fe370SBharat Gooty #define DRDU3_U2PHY_CTRL                        0x10U
118*682fe370SBharat Gooty #define DRDU3_U2PHY_IDDQ                        BIT(29U)
119*682fe370SBharat Gooty #define DRDU3_U2PHY_ON_FLAG                     BIT(22U)
120*682fe370SBharat Gooty #define DRDU3_U2PHY_PCTL_MASK                   0xFFFFU
121*682fe370SBharat Gooty #define DRDU3_U2PHY_PCTL_OFFSET                 6U
122*682fe370SBharat Gooty #define DRDU3_U2PHY_RESETB                      BIT(5U)
123*682fe370SBharat Gooty #define DRDU3_U2PHY_ISO                         BIT(4U)
124*682fe370SBharat Gooty #define DRDU3_U2AFE_BG_PWRDWNB                  BIT(3U)
125*682fe370SBharat Gooty #define DRDU3_U2AFE_PLL_PWRDWNB                 BIT(2U)
126*682fe370SBharat Gooty #define DRDU3_U2AFE_LDO_PWRDWNB                 BIT(1U)
127*682fe370SBharat Gooty #define DRDU3_U2CTRL_CORERDY                    BIT(0U)
128*682fe370SBharat Gooty 
129*682fe370SBharat Gooty #define DRDU3_U3PHY_CTRL                        0x14U
130*682fe370SBharat Gooty #define DRDU3_U3XHC_SOFT_RST_N                  BIT(31U)
131*682fe370SBharat Gooty #define DRDU3_U3BDC_SOFT_RST_N                  BIT(30U)
132*682fe370SBharat Gooty #define DRDU3_U3MDIO_RESETB_I                   BIT(29U)
133*682fe370SBharat Gooty #define DRDU3_U3POR_RESET_I                     BIT(28U)
134*682fe370SBharat Gooty #define DRDU3_U3PHY_PCTL_MASK                   0xFFFFU
135*682fe370SBharat Gooty #define DRDU3_U3PHY_PCTL_OFFSET                 2U
136*682fe370SBharat Gooty #define DRDU3_U3PHY_RESETB                      BIT(1U)
137*682fe370SBharat Gooty 
138*682fe370SBharat Gooty #define DRDU3_U3PHY_PLL_CTRL                    0x18U
139*682fe370SBharat Gooty #define DRDU3_U3PLL_REFCLK_MASK                 0x7U
140*682fe370SBharat Gooty #define DRDU3_U3PLL_REFCLK_OFFSET               4U
141*682fe370SBharat Gooty #define DRDU3_U3PLL_SS_LOCK                     BIT(3U)
142*682fe370SBharat Gooty #define DRDU3_U3PLL_SEQ_START                   BIT(2U)
143*682fe370SBharat Gooty #define DRDU3_U3SSPLL_SUSPEND_EN                BIT(1U)
144*682fe370SBharat Gooty #define DRDU3_U3PLL_RESETB                      BIT(0U)
145*682fe370SBharat Gooty 
146*682fe370SBharat Gooty #define DRDU3_STRAP_CTRL                        0x28U
147*682fe370SBharat Gooty #define BDC_USB_STP_SPD_MASK                    0x7U
148*682fe370SBharat Gooty #define BDC_USB_STP_SPD_OFFSET                  0U
149*682fe370SBharat Gooty #define BDC_USB_STP_SPD_SS                      0x0U
150*682fe370SBharat Gooty #define BDC_USB_STP_SPD_HS                      0x2U
151*682fe370SBharat Gooty 
152*682fe370SBharat Gooty #define DRDU3_PWR_CTRL                          0x2cU
153*682fe370SBharat Gooty #define DRDU3_U2PHY_DFE_SWITCH_PWROKIN          BIT(12U)
154*682fe370SBharat Gooty #define DRDU3_U2PHY_DFE_SWITCH_PWRONIN          BIT(11U)
155*682fe370SBharat Gooty #define DRDU3_PWR_CTRL_OVERRIDE_I_R             4U
156*682fe370SBharat Gooty 
157*682fe370SBharat Gooty #define DRDU3_SOFT_RESET_CTRL                   0x30U
158*682fe370SBharat Gooty #define DRDU3_XHC_AXI_SOFT_RST_N                BIT(1U)
159*682fe370SBharat Gooty #define DRDU3_BDC_AXI_SOFT_RST_N                BIT(0U)
160*682fe370SBharat Gooty 
161*682fe370SBharat Gooty #define DRDU3_PHY_PWR_CTRL                      0x3cU
162*682fe370SBharat Gooty #define DRDU3_DISABLE_USB30_P0                  BIT(2U)
163*682fe370SBharat Gooty #define DRDU3_DISABLE_EUSB_P1                   BIT(1U)
164*682fe370SBharat Gooty #define DRDU3_DISABLE_EUSB_P0                   BIT(0U)
165*682fe370SBharat Gooty 
166*682fe370SBharat Gooty #define PLL_REFCLK_PAD                          0x0U
167*682fe370SBharat Gooty #define PLL_REFCLK_25MHZ                        0x1U
168*682fe370SBharat Gooty #define PLL_REFCLK_96MHZ                        0x2U
169*682fe370SBharat Gooty #define PLL_REFCLK_INTERNAL                     0x3U
170*682fe370SBharat Gooty /* USB PLL lock time out for 10 ms */
171*682fe370SBharat Gooty #define PLL_LOCK_RETRY_COUNT                    10000U
172*682fe370SBharat Gooty 
173*682fe370SBharat Gooty 
174*682fe370SBharat Gooty #define U2PLL_NDIV_INT_VAL                      0x13U
175*682fe370SBharat Gooty #define U2PLL_NDIV_FRAC_VAL                     0x1005U
176*682fe370SBharat Gooty #define U2PLL_PDIV_VAL                          0x1U
177*682fe370SBharat Gooty /*
178*682fe370SBharat Gooty  * Using external FSM
179*682fe370SBharat Gooty  * BIT-3:2: device mode; mode is not effect
180*682fe370SBharat Gooty  * BIT-1: soft reset active low
181*682fe370SBharat Gooty  */
182*682fe370SBharat Gooty #define U2PHY_PCTL_VAL                          0x0003U
183*682fe370SBharat Gooty /* Non-driving signal low */
184*682fe370SBharat Gooty #define U2PHY_PCTL_NON_DRV_LOW                  0x0002U
185*682fe370SBharat Gooty #define U3PHY_PCTL_VAL                          0x0006U
186*682fe370SBharat Gooty 
187*682fe370SBharat Gooty #define MAX_NR_PORTS                            3U
188*682fe370SBharat Gooty 
189*682fe370SBharat Gooty #define USB3H_DRDU2_PHY                         1U
190*682fe370SBharat Gooty #define DRDU3_PHY                               2U
191*682fe370SBharat Gooty 
192*682fe370SBharat Gooty #define USB_HOST_MODE                           1U
193*682fe370SBharat Gooty #define USB_DEV_MODE                            2U
194*682fe370SBharat Gooty 
195*682fe370SBharat Gooty #define USB3SS_PORT                             0U
196*682fe370SBharat Gooty #define DRDU2_PORT                              1U
197*682fe370SBharat Gooty #define USB3HS_PORT                             2U
198*682fe370SBharat Gooty 
199*682fe370SBharat Gooty #define DRD3SS_PORT                             0U
200*682fe370SBharat Gooty #define DRD3HS_PORT                             1U
201*682fe370SBharat Gooty 
202*682fe370SBharat Gooty #define SR_USB_PHY_COUNT                        2U
203*682fe370SBharat Gooty 
204*682fe370SBharat Gooty #define DRDU3_PIPE_CTRL			0x68500000U
205*682fe370SBharat Gooty #define DRDU3H_XHC_REGS_CPLIVER		0x68501000U
206*682fe370SBharat Gooty #define USB3H_PIPE_CTRL			0x68510000U
207*682fe370SBharat Gooty #define DRD2U3H_XHC_REGS_CPLIVER	0x68511000U
208*682fe370SBharat Gooty #define DRDU2_U2PLL_NDIV_FRAC		0x68520000U
209*682fe370SBharat Gooty 
210*682fe370SBharat Gooty #define AXI_DEBUG_CTRL				0x68500038U
211*682fe370SBharat Gooty #define AXI_DBG_CTRL_SSPHY_DRD_MODE_DISABLE	BIT(12U)
212*682fe370SBharat Gooty 
213*682fe370SBharat Gooty #define USB3H_DEBUG_CTRL			0x68510034U
214*682fe370SBharat Gooty #define USB3H_DBG_CTRL_SSPHY_DRD_MODE_DISABLE	BIT(7U)
215*682fe370SBharat Gooty 
216*682fe370SBharat Gooty typedef struct _usb_phy_port usb_phy_port_t;
217*682fe370SBharat Gooty 
218*682fe370SBharat Gooty typedef struct {
219*682fe370SBharat Gooty 	uint32_t drdu2reg;
220*682fe370SBharat Gooty 	uint32_t usb3hreg;
221*682fe370SBharat Gooty 	uint32_t drdu3reg;
222*682fe370SBharat Gooty 	uint32_t phy_id;
223*682fe370SBharat Gooty 	uint32_t ports_enabled;
224*682fe370SBharat Gooty 	uint32_t initialized;
225*682fe370SBharat Gooty 	usb_phy_port_t *phy_port;
226*682fe370SBharat Gooty } usb_phy_t;
227*682fe370SBharat Gooty 
228*682fe370SBharat Gooty struct _usb_phy_port {
229*682fe370SBharat Gooty 	uint32_t port_id;
230*682fe370SBharat Gooty 	uint32_t mode;
231*682fe370SBharat Gooty 	uint32_t enabled;
232*682fe370SBharat Gooty 	usb_phy_t *p;
233*682fe370SBharat Gooty };
234*682fe370SBharat Gooty 
235*682fe370SBharat Gooty struct u2_phy_ext_fsm {
236*682fe370SBharat Gooty 	uint32_t pll_ctrl_reg;
237*682fe370SBharat Gooty 	uint32_t phy_ctrl_reg;
238*682fe370SBharat Gooty 	uint32_t phy_iddq;
239*682fe370SBharat Gooty 	uint32_t pwr_ctrl_reg;
240*682fe370SBharat Gooty 	uint32_t pwr_okin;
241*682fe370SBharat Gooty 	uint32_t pwr_onin;
242*682fe370SBharat Gooty };
243*682fe370SBharat Gooty 
244*682fe370SBharat Gooty #endif /* USB_PHY_H */
245