Debian Codegraph @

src/soc/qualcomm/x1p42100/usb/snps_usb_phy.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <console/console.h>
4 #include <soc/usb/snps_usb_phy.h>
5 #include <soc/addressmap.h>
6 #include <commonlib/helpers.h>
7 #include <soc/usb/usb.h>
8 #include <delay.h>
9
10 #define SLEEPM BIT(0)
11
12 #define TERMSEL BIT(5)
13
14 #define POR BIT(1)
15
16 /* Updated FSEL_MASK based on the table feedback (GENMASK(6,4) for 38.4MHz) */
17 #define FSEL_MASK GENMASK(6, 4)
18 #define FSEL_DEFAULT (0x3 << 4) /* Original value, may not be used directly */
19
20 #define VBUSVLDEXTSEL0 BIT(4)
21 #define PLLBTUNE BIT(5)
22
23 #define VREGBYPASS BIT(0)
24
25 #define VBUSVLDEXT0 BIT(0)
26
27 /* Updated macros for clarity as per feedback */
28 #define USB2_SUSPEND_N_BIT BIT(2)
29 #define USB2_SUSPEND_N_SEL_BIT BIT(3)
30
31 #define UTMI_PHY_CMN_CTRL_OVERRIDE_EN BIT(1)
32
33 #define REFCLK_SEL_MASK GENMASK(1, 0)
34 #define REFCLK_SEL_DEFAULT (0x2 << 0)
35
36 #define PARAM_OVRD_MASK 0xFF
37
38 /* Streamlined macros for common control bits (from previous feedback) */
39 #define USB_PHY_ENABLE_BIT BIT(0)
40 #define USB_PHY_RETENABLEN_BIT BIT(3)
41 #define APB_LOGIC_RESET_BIT BIT(2)
42 #define TESTBURNIN_BIT BIT(6)
43 #define FSEL_SEL_BIT BIT(0)
44
45 /* New macros from table requirements (to be used in sequence) */
46 #define FSEL_38_4_MHZ_VAL (0x4 << 4) /* 3'b100 for bits 6:4 -> 0x4, shifted by 4 */
47 #define SIDDQ_SEL_BIT BIT(1)
48 #define SIDDQ_DISABLE_BIT BIT(2) /* SIDDQ is set to 0, means power up analog blocks */
49
50 #define CFG_CTRL_2_VALUE 0xC8 /* For phy_cfg_pll_fb_div_7_0 */
51
52 #define CFG_CTRL_3_FB_DIV_MASK GENMASK(3, 0)
53 #define CFG_CTRL_3_FB_DIV_VALUE 0x0 /* 4'b0000 */
54
55 #define CFG_CTRL_3_REF_DIV_MASK GENMASK(7, 4)
56 #define CFG_CTRL_3_REF_DIV_VALUE (0x0 << 4) /* 4'b0000 shifted to bits 7:4 */
57
58 #define CFG_CTRL_1_PLL_CPBIAS_MASK GENMASK(7, 1)
59 #define CFG_CTRL_1_PLL_CPBIAS_VALUE (0x0 << 1) /* 7'b0000000 shifted to bits 7:1 */
60
61 #define CFG_CTRL_4_PLL_VCO_GAIN_MASK GENMASK(1, 0)
62 #define CFG_CTRL_4_PLL_VCO_GAIN_VALUE 0x1 /* 2'b01 */
63
64 #define CFG_CTRL_4_PLL_INT_GAIN_MASK GENMASK(7, 2)
65 #define CFG_CTRL_4_PLL_INT_GAIN_VALUE (0x8 << 2) /* 6'b001000 shifted to bits 7:2 */
66
67 #define CFG_CTRL_5_PLL_PROP_GAIN_MASK GENMASK(5, 0)
68 #define CFG_CTRL_5_PLL_PROP_GAIN_VALUE 0x10 /* 6'b010000 */
69
70 #define CFG_CTRL_6_PLL_VCO_CFG_MASK GENMASK(2, 0)
71 #define CFG_CTRL_6_PLL_VCO_CFG_VALUE 0x0 /* 3'b000 */
72
73 #define CFG_CTRL_5_PLL_VREF_TUNE_MASK GENMASK(7, 6)
74 #define CFG_CTRL_5_PLL_VREF_TUNE_VALUE (0x1 << 6) /* 2'b01 shifted to bits 7:6 */
75
76 #define VBUS_DET_EXT_SEL_BIT BIT(4)
77 #define VBUS_VALID_EXT_BIT BIT(0)
78
79 #define CFG_CTRL_9_TX_PREEMP_MASK GENMASK(2, 0)
80 #define CFG_CTRL_9_TX_PREEMP_VALUE 0x0 /* 3'b000 */
81
82 #define CFG_CTRL_8_TX_HS_VREF_MASK GENMASK(5, 3)
83 #define CFG_CTRL_8_TX_HS_VREF_VALUE (0x3 << 3) /* 3'b011 shifted to bits 5:3 */
84
85 #define CFG_CTRL_9_TX_RISE_TUNE_MASK GENMASK(6, 5)
86 #define CFG_CTRL_9_TX_RISE_TUNE_VALUE (0x2 << 5) /* 2'b10 shifted to bits 6:5 */
87
88 #define CFG_CTRL_8_TX_HS_XV_TUNE_MASK GENMASK(7, 6)
89 #define CFG_CTRL_8_TX_HS_XV_TUNE_VALUE (0x0 << 6) /* 2'b00 shifted to bits 7:6 */
90
91 #define CFG_CTRL_9_TX_RES_TUNE_MASK GENMASK(4, 3)
92 #define CFG_CTRL_9_TX_RES_TUNE_VALUE (0x1 << 3) /* 2'b01 shifted to bits 4:3 */
93
94
95 struct hs_usb_phy_reg *hs_phy_reg = NULL;
96 void hs_usb_phy_init(int index)
97 {
98 if (index == 0)
99 hs_phy_reg = (void *)HS_USB_MP0_PHY_BASE;
100 else
101 hs_phy_reg = (void *)HS_USB_MP1_PHY_BASE;
102
103 /*
104 * This sequence initializes the USB HS PHY.
105 */
106
107 /* Step 1: USB_PHY_CFG0[1] = 1'b1 (UTMI_PHY_CMN_CNTRL_OVERRIDE_EN=1) */
108 /* This is a MUX select signal to enable software override of UTMI PHY common control. */
109 clrsetbits32(&hs_phy_reg->cfg0, UTMI_PHY_CMN_CTRL_OVERRIDE_EN,
110 UTMI_PHY_CMN_CTRL_OVERRIDE_EN);
111
112 /* Step 2: USB_PHY_UTMI_CTRL5[1] = 1'b1 (POR asserted) */
113 /* Assert the PHY reset. This reset must be held for at least 10us after all supplies ramp up. */
114 clrsetbits32(&hs_phy_reg->utmi_ctrl5, POR, POR);
115 udelay(10); /* Hold POR for 10us */
116
117 /* Step 3: USB_PHY_HS_PHY_CTRL_COMMON0[0] = 1'b1 (phy_enable='1') */
118 /* Asynchronous enable for the PHY. If low during POR de-assertion, PHY remains inactive. */
119 clrsetbits32(&hs_phy_reg->hs_phy_ctrl_common0, USB_PHY_ENABLE_BIT, USB_PHY_ENABLE_BIT);
120
121 /* Step 4: USB_PHY_HS_PHY_CTRL_COMMON0[3] = 1'b1 (Retention Mode Enable) */
122 /* Set retenable_n = 1'b1. This signal must be high when VDD supply is powered. */
123 clrsetbits32(&hs_phy_reg->hs_phy_ctrl_common0, USB_PHY_RETENABLEN_BIT, USB_PHY_RETENABLEN_BIT);
124
125 /* Step 5: USB_PHY_APB_ACCESS_CMD[2] = 1'b1 (APB Logic Reset) */
126 /* Reset all APB related logic, including SNPS APB FSM but not the APB registers. */
127 clrsetbits32(&hs_phy_reg->usb_phy_apb_access_cmd, APB_LOGIC_RESET_BIT, APB_LOGIC_RESET_BIT);
128
129 /* Step 6: UTMI_PHY_CMN_CTRL0[6] = 1'b0 (Burn-in Test Enable - clear the bit) */
130 /* De-assert test_burnin. If asserted, PHY performs power-on-reset and enters HS Loopback mode. */
131 clrsetbits32(&hs_phy_reg->utmi_phy_cmn_ctrl0, TESTBURNIN_BIT, 0);
132
133 /* Step 7: USB_PHY_FSEL_SEL = 1'b1 (FSEL MUX select for SW override) */
134 /* Select software override for frequency selection. */
135 clrsetbits32(&hs_phy_reg->usb_phy_fsel_sel, FSEL_SEL_BIT, FSEL_SEL_BIT);
136
137 /* Step 8: USB_PHY_HS_PHY_CTRL_COMMON0[6:4] = 3'b100 (Sets refclk frequency to 38.4 MHz) */
138 /* Configure the reference clock frequency. */
139 clrsetbits32(&hs_phy_reg->hs_phy_ctrl_common0, FSEL_MASK, FSEL_38_4_MHZ_VAL);
140
141 /* Step 9: USB_PHY_CFG_CTRL_2[7:0] = 8'b11001000 (Control of the feedback multiplication ratio) */
142 /* Configure phy_cfg_pll_fb_div_7_0. */
143 clrsetbits32(&hs_phy_reg->cfg_ctrl_2, 0xFF, CFG_CTRL_2_VALUE); /* Using 0xFF for full 8-bit mask */
144
145 /* Step 10: USB_PHY_CFG_CTRL_3[3:0] = 4'b0000 (Control of the feedback multiplication ratio) */
146 /* Configure phy_cfg_pll_fb_div_11_8. */
147 clrsetbits32(&hs_phy_reg->cfg_ctrl_3, CFG_CTRL_3_FB_DIV_MASK, CFG_CTRL_3_FB_DIV_VALUE);
148
149 /* Step 11: USB_PHY_CFG_CTRL_3[7:4] = 4'b0000 (Control of the input frequency division ratio) */
150 /* Configure phy_cfg_pll_ref_div. */
151 clrsetbits32(&hs_phy_reg->cfg_ctrl_3, CFG_CTRL_3_REF_DIV_MASK, CFG_CTRL_3_REF_DIV_VALUE);
152
153 /* Step 12: USB_PHY_CFG_CTRL_1[7:1] = 7'b0000000 (PLL loop bias configuration) */
154 /* Configure phy_cfg_pll_cpbias_cntrl. */
155 clrsetbits32(&hs_phy_reg->cfg_ctrl_1, CFG_CTRL_1_PLL_CPBIAS_MASK, CFG_CTRL_1_PLL_CPBIAS_VALUE);
156
157 /* Step 13: USB_PHY_CFG_CTRL_4[1:0] = 2'b01 (PLL vco source gain) */
158 /* Configure phy_cfg_pll_gmp_cntrl. */
159 clrsetbits32(&hs_phy_reg->cfg_ctrl_4, CFG_CTRL_4_PLL_VCO_GAIN_MASK, CFG_CTRL_4_PLL_VCO_GAIN_VALUE);
160
161 /* Step 14: USB_PHY_CFG_CTRL_4[7:2] = 6'b001000 (Gain of PLL Integral Charge Pump) */
162 /* Configure phy_cfg_pll_int_cntrl. */
163 clrsetbits32(&hs_phy_reg->cfg_ctrl_4, CFG_CTRL_4_PLL_INT_GAIN_MASK, CFG_CTRL_4_PLL_INT_GAIN_VALUE);
164
165 /* Step 15: USB_PHY_CFG_CTRL_5[5:0] = 6'b010000 (Gain of PLL Proportional Charge Pump) */
166 /* Configure phy_cfg_pll_prop_cntrl. */
167 clrsetbits32(&hs_phy_reg->cfg_ctrl_5, CFG_CTRL_5_PLL_PROP_GAIN_MASK, CFG_CTRL_5_PLL_PROP_GAIN_VALUE);
168
169 /* Step 16: USB_PHY_CFG_CTRL_6[2:0] = 3'b000 (PLL VCO configuration) */
170 /* Configure phy_cfg_pll_vco_cntrl. */
171 clrsetbits32(&hs_phy_reg->cfg_ctrl_6, CFG_CTRL_6_PLL_VCO_CFG_MASK, CFG_CTRL_6_PLL_VCO_CFG_VALUE);
172
173 /* Step 17: USB_PHY_CFG_CTRL_5[7:6] = 2'b01 (Configuration for PLL voltage reference level) */
174 /* Configure phy_cfg_pll_vref_tune. */
175 clrsetbits32(&hs_phy_reg->cfg_ctrl_5, CFG_CTRL_5_PLL_VREF_TUNE_MASK, CFG_CTRL_5_PLL_VREF_TUNE_VALUE);
176
177 /* Step 18: Selects UTMI data bus width. Wordinterface<#> = 0; for 8 bits interface (60 MHz)
178 * No register control, tied at chip top.
179 */
180
181 /* Step 19: USB_PHY_HS_PHY_CTRL2[4] = 1'b1 (VBUS MUX Selection) */
182 /* Select software control for VBUS detection. */
183 clrsetbits32(&hs_phy_reg->hs_phy_ctrl2, VBUS_DET_EXT_SEL_BIT, VBUS_DET_EXT_SEL_BIT);
184
185 /* Step 20: USB_PHY_HS_PHY_CTRL2[0] = 1'b1 (VBUS valid indication) */
186 /* Software writes this bit to indicate VBUS status. */
187 clrsetbits32(&hs_phy_reg->hs_phy_ctrl2, VBUS_VALID_EXT_BIT, VBUS_VALID_EXT_BIT);
188
189 /* Step 21: USB_PHY_CFG_CTRL_9[2:0] = 3'b000 (HS Transmitter Pre-Emphasis Control) */
190 /* Set HS Transmitter pre-emphasis to off (design default). */
191 clrsetbits32(&hs_phy_reg->cfg_ctrl_9, CFG_CTRL_9_TX_PREEMP_MASK, CFG_CTRL_9_TX_PREEMP_VALUE);
192
193 /* Step 22: USB_PHY_CFG_CTRL_8[5:3] = 3'b011 (HS DC Voltage Level Adjustment) */
194 /* Set HS DC Voltage Level to default (increased). */
195 clrsetbits32(&hs_phy_reg->cfg_ctrl_8, CFG_CTRL_8_TX_HS_VREF_MASK, CFG_CTRL_8_TX_HS_VREF_VALUE);
196
197 /* Step 23: USB_PHY_CFG_CTRL_9[6:5] = 2'b10 (HS Transmitter Rise/Fall Time Adjustment) */
198 /* Set HS Transmitter Rise/Fall Time Adjustment to default. */
199 clrsetbits32(&hs_phy_reg->cfg_ctrl_9, CFG_CTRL_9_TX_RISE_TUNE_MASK, CFG_CTRL_9_TX_RISE_TUNE_VALUE);
200
201 /* Step 24: USB_PHY_CFG_CTRL_8[7:6] = 2'b00 (Transmitter High-Speed Crossover Adjustment) */
202 /* Set Transmitter High-Speed Crossover Adjustment to default (0V). */
203 clrsetbits32(&hs_phy_reg->cfg_ctrl_8, CFG_CTRL_8_TX_HS_XV_TUNE_MASK, CFG_CTRL_8_TX_HS_XV_TUNE_VALUE);
204
205 /* Step 25: USB_PHY_CFG_CTRL_9[4:3] = 2'b01 (USB Source Impedance Adjustment) */
206 /* Set USB Source Impedance Adjustment to default. */
207 clrsetbits32(&hs_phy_reg->cfg_ctrl_9, CFG_CTRL_9_TX_RES_TUNE_MASK, CFG_CTRL_9_TX_RES_TUNE_VALUE);
208
209 /* Step 26: USB_PHY_HS_PHY_CTRL2[3] = 1'b1 (USB2_SUSPEND_N_SEL) */
210 /* Select SW option for suspend_n signal. */
211 clrsetbits32(&hs_phy_reg->hs_phy_ctrl2, USB2_SUSPEND_N_SEL_BIT, USB2_SUSPEND_N_SEL_BIT);
212
213 /* Step 27: USB_PHY_HS_PHY_CTRL2[2] = 1'b1 (USB2_SUSPEND_N) */
214 /* Assert USB2_SUSPEND_N. */
215 clrsetbits32(&hs_phy_reg->hs_phy_ctrl2, USB2_SUSPEND_N_BIT, USB2_SUSPEND_N_BIT);
216
217 /* Step 28: USB_PHY_UTMI_CTRL0[0] = 1'b1 (SLEEPM) */
218 /* Set sleepm = 1; until PHYCLOCK is available. */
219 clrsetbits32(&hs_phy_reg->utmi_ctrl0, SLEEPM, SLEEPM);
220
221 /* Step 29: USB_PHY_HS_PHY_CTRL_COMMON0[1] = 1'b1 (SIDDQ MUX Selection) */
222 /* Select internal CSR register (SIDDQ) for SIDDQ control. */
223 clrsetbits32(&hs_phy_reg->hs_phy_ctrl_common0, SIDDQ_SEL_BIT, SIDDQ_SEL_BIT);
224
225 /* Step 30: USB_PHY_HS_PHY_CTRL_COMMON0[2] = 1'b0 (SIDDQ set to 0) */
226 /* Power up the analog blocks by setting SIDDQ to 0. */
227 clrsetbits32(&hs_phy_reg->hs_phy_ctrl_common0, SIDDQ_DISABLE_BIT, 0);
228
229 /* Step 31: USB_PHY_UTMI_CTRL5[1] = 1'b0 (POR release) */
230 /* Release the POR from high to low. */
231 clrsetbits32(&hs_phy_reg->utmi_ctrl5, POR, 0);
232
233 /* Step 32: USB_PHY_HS_PHY_CTRL2[3] = 1'b0 (USB2_SUSPEND_N_SEL de-selects SW override) */
234 /* De-select SW override for suspend_n, allowing HW control. */
235 clrsetbits32(&hs_phy_reg->hs_phy_ctrl2, USB2_SUSPEND_N_SEL_BIT, 0);
236
237 udelay(20);
238 printk(BIOS_DEBUG, "USB HS PHY initialized for index %d\n", index);
239 }