1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2014-2020, NVIDIA CORPORATION. All rights reserved.
4 * Copyright (C) 2015 Google, Inc.
8 #include <linux/clk/tegra.h>
9 #include <linux/delay.h>
11 #include <linux/mailbox_client.h>
12 #include <linux/module.h>
14 #include <linux/of_platform.h>
15 #include <linux/phy/phy.h>
16 #include <linux/platform_device.h>
17 #include <linux/regmap.h>
18 #include <linux/regulator/consumer.h>
19 #include <linux/reset.h>
20 #include <linux/slab.h>
22 #include <soc/tegra/fuse.h>
26 #define FUSE_SKU_CALIB_HS_CURR_LEVEL_PADX_SHIFT(x) \
27 ((x) ? (11 + ((x) - 1) * 6) : 0)
28 #define FUSE_SKU_CALIB_HS_CURR_LEVEL_PAD_MASK 0x3f
29 #define FUSE_SKU_CALIB_HS_TERM_RANGE_ADJ_SHIFT 7
30 #define FUSE_SKU_CALIB_HS_TERM_RANGE_ADJ_MASK 0xf
32 #define FUSE_USB_CALIB_EXT_RPD_CTRL_SHIFT 0
33 #define FUSE_USB_CALIB_EXT_RPD_CTRL_MASK 0x1f
35 #define XUSB_PADCTL_USB2_PAD_MUX 0x004
36 #define XUSB_PADCTL_USB2_PAD_MUX_HSIC_PAD_TRK_SHIFT 16
37 #define XUSB_PADCTL_USB2_PAD_MUX_HSIC_PAD_TRK_MASK 0x3
38 #define XUSB_PADCTL_USB2_PAD_MUX_HSIC_PAD_TRK_XUSB 0x1
39 #define XUSB_PADCTL_USB2_PAD_MUX_USB2_BIAS_PAD_SHIFT 18
40 #define XUSB_PADCTL_USB2_PAD_MUX_USB2_BIAS_PAD_MASK 0x3
41 #define XUSB_PADCTL_USB2_PAD_MUX_USB2_BIAS_PAD_XUSB 0x1
43 #define XUSB_PADCTL_USB2_PORT_CAP 0x008
44 #define XUSB_PADCTL_USB2_PORT_CAP_PORTX_CAP_DISABLED(x) (0x0 << ((x) * 4))
45 #define XUSB_PADCTL_USB2_PORT_CAP_PORTX_CAP_HOST(x) (0x1 << ((x) * 4))
46 #define XUSB_PADCTL_USB2_PORT_CAP_PORTX_CAP_DEVICE(x) (0x2 << ((x) * 4))
47 #define XUSB_PADCTL_USB2_PORT_CAP_PORTX_CAP_OTG(x) (0x3 << ((x) * 4))
48 #define XUSB_PADCTL_USB2_PORT_CAP_PORTX_CAP_MASK(x) (0x3 << ((x) * 4))
50 #define XUSB_PADCTL_SS_PORT_MAP 0x014
51 #define XUSB_PADCTL_SS_PORT_MAP_PORTX_INTERNAL(x) (1 << (((x) * 5) + 4))
52 #define XUSB_PADCTL_SS_PORT_MAP_PORTX_MAP_SHIFT(x) ((x) * 5)
53 #define XUSB_PADCTL_SS_PORT_MAP_PORTX_MAP_MASK(x) (0x7 << ((x) * 5))
54 #define XUSB_PADCTL_SS_PORT_MAP_PORTX_MAP(x, v) (((v) & 0x7) << ((x) * 5))
55 #define XUSB_PADCTL_SS_PORT_MAP_PORT_DISABLED 0x7
57 #define XUSB_PADCTL_ELPG_PROGRAM_0 0x20
58 #define USB2_PORT_WAKE_INTERRUPT_ENABLE(x) BIT((x))
59 #define USB2_PORT_WAKEUP_EVENT(x) BIT((x) + 7)
60 #define SS_PORT_WAKE_INTERRUPT_ENABLE(x) BIT((x) + 14)
61 #define SS_PORT_WAKEUP_EVENT(x) BIT((x) + 21)
62 #define USB2_HSIC_PORT_WAKE_INTERRUPT_ENABLE(x) BIT((x) + 28)
63 #define USB2_HSIC_PORT_WAKEUP_EVENT(x) BIT((x) + 30)
64 #define ALL_WAKE_EVENTS ( \
65 USB2_PORT_WAKEUP_EVENT(0) | USB2_PORT_WAKEUP_EVENT(1) | \
66 USB2_PORT_WAKEUP_EVENT(2) | USB2_PORT_WAKEUP_EVENT(3) | \
67 SS_PORT_WAKEUP_EVENT(0) | SS_PORT_WAKEUP_EVENT(1) | \
68 SS_PORT_WAKEUP_EVENT(2) | SS_PORT_WAKEUP_EVENT(3) | \
69 USB2_HSIC_PORT_WAKEUP_EVENT(0))
71 #define XUSB_PADCTL_ELPG_PROGRAM1 0x024
72 #define XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_VCORE_DOWN (1 << 31)
73 #define XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_CLAMP_EN_EARLY (1 << 30)
74 #define XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_CLAMP_EN (1 << 29)
75 #define XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_VCORE_DOWN(x) (1 << (2 + (x) * 3))
76 #define XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN_EARLY(x) \
78 #define XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN(x) (1 << ((x) * 3))
80 #define XUSB_PADCTL_USB3_PAD_MUX 0x028
81 #define XUSB_PADCTL_USB3_PAD_MUX_PCIE_IDDQ_DISABLE(x) (1 << (1 + (x)))
82 #define XUSB_PADCTL_USB3_PAD_MUX_SATA_IDDQ_DISABLE(x) (1 << (8 + (x)))
84 #define XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPADX_CTL0(x) (0x080 + (x) * 0x40)
85 #define XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL0_ZIP (1 << 18)
86 #define XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL0_ZIN (1 << 22)
88 #define XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPADX_CTL1(x) (0x084 + (x) * 0x40)
89 #define XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL1_VREG_LEV_SHIFT 7
90 #define XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL1_VREG_LEV_MASK 0x3
91 #define XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL1_VREG_LEV_VAL 0x1
92 #define XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL1_VREG_FIX18 (1 << 6)
94 #define XUSB_PADCTL_USB2_OTG_PADX_CTL0(x) (0x088 + (x) * 0x40)
95 #define XUSB_PADCTL_USB2_OTG_PAD_CTL0_PD_ZI (1 << 29)
96 #define XUSB_PADCTL_USB2_OTG_PAD_CTL0_PD2 (1 << 27)
97 #define XUSB_PADCTL_USB2_OTG_PAD_CTL0_PD (1 << 26)
98 #define XUSB_PADCTL_USB2_OTG_PAD_CTL0_HS_CURR_LEVEL_SHIFT 0
99 #define XUSB_PADCTL_USB2_OTG_PAD_CTL0_HS_CURR_LEVEL_MASK 0x3f
101 #define XUSB_PADCTL_USB2_OTG_PADX_CTL1(x) (0x08c + (x) * 0x40)
102 #define XUSB_PADCTL_USB2_OTG_PAD_CTL1_RPD_CTRL_SHIFT 26
103 #define XUSB_PADCTL_USB2_OTG_PAD_CTL1_RPD_CTRL_MASK 0x1f
104 #define XUSB_PADCTL_USB2_OTG_PAD_CTL1_TERM_RANGE_ADJ_SHIFT 3
105 #define XUSB_PADCTL_USB2_OTG_PAD_CTL1_TERM_RANGE_ADJ_MASK 0xf
106 #define XUSB_PADCTL_USB2_OTG_PAD_CTL1_PD_DR (1 << 2)
107 #define XUSB_PADCTL_USB2_OTG_PAD_CTL1_PD_DISC_OVRD (1 << 1)
108 #define XUSB_PADCTL_USB2_OTG_PAD_CTL1_PD_CHRP_OVRD (1 << 0)
109 #define RPD_CTRL(x) (((x) & 0x1f) << 26)
110 #define RPD_CTRL_VALUE(x) (((x) >> 26) & 0x1f)
112 #define XUSB_PADCTL_USB2_BIAS_PAD_CTL0 0x284
113 #define XUSB_PADCTL_USB2_BIAS_PAD_CTL0_PD (1 << 11)
114 #define XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_DISCON_LEVEL_SHIFT 3
115 #define XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_DISCON_LEVEL_MASK 0x7
116 #define XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_DISCON_LEVEL_VAL 0x7
117 #define XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_SQUELCH_LEVEL_SHIFT 0
118 #define XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_SQUELCH_LEVEL_MASK 0x7
119 #define XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_SQUELCH_LEVEL_VAL 0x2
121 #define XUSB_PADCTL_USB2_BIAS_PAD_CTL1 0x288
122 #define XUSB_PADCTL_USB2_BIAS_PAD_CTL1_PD_TRK (1 << 26)
123 #define XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_DONE_RESET_TIMER_SHIFT 19
124 #define XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_DONE_RESET_TIMER_MASK 0x7f
125 #define XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_DONE_RESET_TIMER_VAL 0x0a
126 #define XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_START_TIMER_SHIFT 12
127 #define XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_START_TIMER_MASK 0x7f
128 #define XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_START_TIMER_VAL 0x1e
129 #define TCTRL_VALUE(x) (((x) & 0x3f) >> 0)
130 #define PCTRL_VALUE(x) (((x) >> 6) & 0x3f)
132 #define XUSB_PADCTL_HSIC_PADX_CTL0(x) (0x300 + (x) * 0x20)
133 #define XUSB_PADCTL_HSIC_PAD_CTL0_RPU_STROBE (1 << 18)
134 #define XUSB_PADCTL_HSIC_PAD_CTL0_RPU_DATA1 (1 << 17)
135 #define XUSB_PADCTL_HSIC_PAD_CTL0_RPU_DATA0 (1 << 16)
136 #define XUSB_PADCTL_HSIC_PAD_CTL0_RPD_STROBE (1 << 15)
137 #define XUSB_PADCTL_HSIC_PAD_CTL0_RPD_DATA1 (1 << 14)
138 #define XUSB_PADCTL_HSIC_PAD_CTL0_RPD_DATA0 (1 << 13)
139 #define XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_STROBE (1 << 9)
140 #define XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_DATA1 (1 << 8)
141 #define XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_DATA0 (1 << 7)
142 #define XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_STROBE (1 << 6)
143 #define XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_DATA1 (1 << 5)
144 #define XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_DATA0 (1 << 4)
145 #define XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_STROBE (1 << 3)
146 #define XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_DATA1 (1 << 2)
147 #define XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_DATA0 (1 << 1)
149 #define XUSB_PADCTL_HSIC_PADX_CTL1(x) (0x304 + (x) * 0x20)
150 #define XUSB_PADCTL_HSIC_PAD_CTL1_TX_RTUNEP_SHIFT 0
151 #define XUSB_PADCTL_HSIC_PAD_CTL1_TX_RTUNEP_MASK 0xf
153 #define XUSB_PADCTL_HSIC_PADX_CTL2(x) (0x308 + (x) * 0x20)
154 #define XUSB_PADCTL_HSIC_PAD_CTL2_RX_STROBE_TRIM_SHIFT 8
155 #define XUSB_PADCTL_HSIC_PAD_CTL2_RX_STROBE_TRIM_MASK 0xf
156 #define XUSB_PADCTL_HSIC_PAD_CTL2_RX_DATA_TRIM_SHIFT 0
157 #define XUSB_PADCTL_HSIC_PAD_CTL2_RX_DATA_TRIM_MASK 0xff
159 #define XUSB_PADCTL_HSIC_PAD_TRK_CTL 0x340
160 #define XUSB_PADCTL_HSIC_PAD_TRK_CTL_PD_TRK (1 << 19)
161 #define XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_DONE_RESET_TIMER_SHIFT 12
162 #define XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_DONE_RESET_TIMER_MASK 0x7f
163 #define XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_DONE_RESET_TIMER_VAL 0x0a
164 #define XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_START_TIMER_SHIFT 5
165 #define XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_START_TIMER_MASK 0x7f
166 #define XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_START_TIMER_VAL 0x1e
168 #define XUSB_PADCTL_HSIC_STRB_TRIM_CONTROL 0x344
170 #define XUSB_PADCTL_UPHY_PLL_P0_CTL1 0x360
171 #define XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_SHIFT 20
172 #define XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_MASK 0xff
173 #define XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_USB_VAL 0x19
174 #define XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_SATA_VAL 0x1e
175 #define XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_MDIV_SHIFT 16
176 #define XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_MDIV_MASK 0x3
177 #define XUSB_PADCTL_UPHY_PLL_CTL1_LOCKDET_STATUS (1 << 15)
178 #define XUSB_PADCTL_UPHY_PLL_CTL1_PWR_OVRD (1 << 4)
179 #define XUSB_PADCTL_UPHY_PLL_CTL1_ENABLE (1 << 3)
180 #define XUSB_PADCTL_UPHY_PLL_CTL1_SLEEP_SHIFT 1
181 #define XUSB_PADCTL_UPHY_PLL_CTL1_SLEEP_MASK 0x3
182 #define XUSB_PADCTL_UPHY_PLL_CTL1_IDDQ (1 << 0)
184 #define XUSB_PADCTL_UPHY_PLL_P0_CTL2 0x364
185 #define XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_SHIFT 4
186 #define XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_MASK 0xffffff
187 #define XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_VAL 0x136
188 #define XUSB_PADCTL_UPHY_PLL_CTL2_CAL_OVRD (1 << 2)
189 #define XUSB_PADCTL_UPHY_PLL_CTL2_CAL_DONE (1 << 1)
190 #define XUSB_PADCTL_UPHY_PLL_CTL2_CAL_EN (1 << 0)
192 #define XUSB_PADCTL_UPHY_PLL_P0_CTL4 0x36c
193 #define XUSB_PADCTL_UPHY_PLL_CTL4_XDIGCLK_EN (1 << 19)
194 #define XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_EN (1 << 15)
195 #define XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SHIFT 12
196 #define XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_MASK 0x3
197 #define XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_USB_VAL 0x2
198 #define XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SATA_VAL 0x0
199 #define XUSB_PADCTL_UPHY_PLL_CTL4_REFCLKBUF_EN (1 << 8)
200 #define XUSB_PADCTL_UPHY_PLL_CTL4_REFCLK_SEL_SHIFT 4
201 #define XUSB_PADCTL_UPHY_PLL_CTL4_REFCLK_SEL_MASK 0xf
203 #define XUSB_PADCTL_UPHY_PLL_P0_CTL5 0x370
204 #define XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_SHIFT 16
205 #define XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_MASK 0xff
206 #define XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_VAL 0x2a
208 #define XUSB_PADCTL_UPHY_PLL_P0_CTL8 0x37c
209 #define XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_DONE (1 << 31)
210 #define XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_OVRD (1 << 15)
211 #define XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_CLK_EN (1 << 13)
212 #define XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_EN (1 << 12)
214 #define XUSB_PADCTL_UPHY_MISC_PAD_PX_CTL1(x) (0x460 + (x) * 0x40)
215 #define XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_IDLE_MODE_SHIFT 20
216 #define XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_IDLE_MODE_MASK 0x3
217 #define XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_IDLE_MODE_VAL 0x1
218 #define XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_TERM_EN BIT(18)
219 #define XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_MODE_OVRD BIT(13)
221 #define XUSB_PADCTL_UPHY_MISC_PAD_PX_CTL2(x) (0x464 + (x) * 0x40)
222 #define XUSB_PADCTL_UPHY_MISC_PAD_CTL2_TX_IDDQ BIT(0)
223 #define XUSB_PADCTL_UPHY_MISC_PAD_CTL2_TX_IDDQ_OVRD BIT(1)
224 #define XUSB_PADCTL_UPHY_MISC_PAD_CTL2_TX_SLEEP_MASK GENMASK(5, 4)
225 #define XUSB_PADCTL_UPHY_MISC_PAD_CTL2_TX_SLEEP_VAL GENMASK(5, 4)
226 #define XUSB_PADCTL_UPHY_MISC_PAD_CTL2_TX_PWR_OVRD BIT(24)
227 #define XUSB_PADCTL_UPHY_MISC_PAD_CTL2_RX_IDDQ BIT(8)
228 #define XUSB_PADCTL_UPHY_MISC_PAD_CTL2_RX_IDDQ_OVRD BIT(9)
229 #define XUSB_PADCTL_UPHY_MISC_PAD_CTL2_RX_SLEEP_MASK GENMASK(13, 12)
230 #define XUSB_PADCTL_UPHY_MISC_PAD_CTL2_RX_SLEEP_VAL GENMASK(13, 12)
231 #define XUSB_PADCTL_UPHY_MISC_PAD_CTL2_RX_PWR_OVRD BIT(25)
233 #define XUSB_PADCTL_UPHY_PLL_S0_CTL1 0x860
235 #define XUSB_PADCTL_UPHY_PLL_S0_CTL2 0x864
237 #define XUSB_PADCTL_UPHY_PLL_S0_CTL4 0x86c
239 #define XUSB_PADCTL_UPHY_PLL_S0_CTL5 0x870
241 #define XUSB_PADCTL_UPHY_PLL_S0_CTL8 0x87c
243 #define XUSB_PADCTL_UPHY_MISC_PAD_S0_CTL1 0x960
244 #define XUSB_PADCTL_UPHY_MISC_PAD_S0_CTL2 0x964
246 #define XUSB_PADCTL_UPHY_USB3_PADX_ECTL1(x) (0xa60 + (x) * 0x40)
247 #define XUSB_PADCTL_UPHY_USB3_PAD_ECTL1_TX_TERM_CTRL_SHIFT 16
248 #define XUSB_PADCTL_UPHY_USB3_PAD_ECTL1_TX_TERM_CTRL_MASK 0x3
249 #define XUSB_PADCTL_UPHY_USB3_PAD_ECTL1_TX_TERM_CTRL_VAL 0x2
251 #define XUSB_PADCTL_UPHY_USB3_PADX_ECTL2(x) (0xa64 + (x) * 0x40)
252 #define XUSB_PADCTL_UPHY_USB3_PAD_ECTL2_RX_CTLE_SHIFT 0
253 #define XUSB_PADCTL_UPHY_USB3_PAD_ECTL2_RX_CTLE_MASK 0xffff
254 #define XUSB_PADCTL_UPHY_USB3_PAD_ECTL2_RX_CTLE_VAL 0x00fc
256 #define XUSB_PADCTL_UPHY_USB3_PADX_ECTL3(x) (0xa68 + (x) * 0x40)
257 #define XUSB_PADCTL_UPHY_USB3_PAD_ECTL3_RX_DFE_VAL 0xc0077f1f
259 #define XUSB_PADCTL_UPHY_USB3_PADX_ECTL4(x) (0xa6c + (x) * 0x40)
260 #define XUSB_PADCTL_UPHY_USB3_PAD_ECTL4_RX_CDR_CTRL_SHIFT 16
261 #define XUSB_PADCTL_UPHY_USB3_PAD_ECTL4_RX_CDR_CTRL_MASK 0xffff
262 #define XUSB_PADCTL_UPHY_USB3_PAD_ECTL4_RX_CDR_CTRL_VAL 0x01c7
264 #define XUSB_PADCTL_UPHY_USB3_PADX_ECTL6(x) (0xa74 + (x) * 0x40)
265 #define XUSB_PADCTL_UPHY_USB3_PAD_ECTL6_RX_EQ_CTRL_H_VAL 0xfcf01368
267 #define XUSB_PADCTL_USB2_VBUS_ID 0xc60
268 #define XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_VBUS_ON (1 << 14)
269 #define XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_SHIFT 18
270 #define XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_MASK 0xf
271 #define XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_FLOATING 8
272 #define XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_GROUNDED 0
274 /* USB2 SLEEPWALK registers */
275 #define UTMIP(_port, _offset1, _offset2) \
276 (((_port) <= 2) ? (_offset1) : (_offset2))
278 #define PMC_UTMIP_UHSIC_SLEEP_CFG(x) UTMIP(x, 0x1fc, 0x4d0)
279 #define UTMIP_MASTER_ENABLE(x) UTMIP(x, BIT(8 * (x)), BIT(0))
280 #define UTMIP_FSLS_USE_PMC(x) UTMIP(x, BIT(8 * (x) + 1), \
282 #define UTMIP_PCTRL_USE_PMC(x) UTMIP(x, BIT(8 * (x) + 2), \
284 #define UTMIP_TCTRL_USE_PMC(x) UTMIP(x, BIT(8 * (x) + 3), \
286 #define UTMIP_WAKE_VAL(_port, _value) (((_value) & 0xf) << \
287 (UTMIP(_port, 8 * (_port) + 4, 4)))
288 #define UTMIP_WAKE_VAL_NONE(_port) UTMIP_WAKE_VAL(_port, 12)
289 #define UTMIP_WAKE_VAL_ANY(_port) UTMIP_WAKE_VAL(_port, 15)
291 #define PMC_UTMIP_UHSIC_SLEEP_CFG1 (0x4d0)
292 #define UTMIP_RPU_SWITC_LOW_USE_PMC_PX(x) BIT((x) + 8)
293 #define UTMIP_RPD_CTRL_USE_PMC_PX(x) BIT((x) + 16)
295 #define PMC_UTMIP_MASTER_CONFIG (0x274)
296 #define UTMIP_PWR(x) UTMIP(x, BIT(x), BIT(4))
297 #define UHSIC_PWR BIT(3)
299 #define PMC_USB_DEBOUNCE_DEL (0xec)
300 #define DEBOUNCE_VAL(x) (((x) & 0xffff) << 0)
301 #define UTMIP_LINE_DEB_CNT(x) (((x) & 0xf) << 16)
302 #define UHSIC_LINE_DEB_CNT(x) (((x) & 0xf) << 20)
304 #define PMC_UTMIP_UHSIC_FAKE(x) UTMIP(x, 0x218, 0x294)
305 #define UTMIP_FAKE_USBOP_VAL(x) UTMIP(x, BIT(4 * (x)), BIT(8))
306 #define UTMIP_FAKE_USBON_VAL(x) UTMIP(x, BIT(4 * (x) + 1), \
308 #define UTMIP_FAKE_USBOP_EN(x) UTMIP(x, BIT(4 * (x) + 2), \
310 #define UTMIP_FAKE_USBON_EN(x) UTMIP(x, BIT(4 * (x) + 3), \
313 #define PMC_UTMIP_UHSIC_SLEEPWALK_CFG(x) UTMIP(x, 0x200, 0x288)
314 #define UTMIP_LINEVAL_WALK_EN(x) UTMIP(x, BIT(8 * (x) + 7), \
317 #define PMC_USB_AO (0xf0)
318 #define USBOP_VAL_PD(x) UTMIP(x, BIT(4 * (x)), BIT(20))
319 #define USBON_VAL_PD(x) UTMIP(x, BIT(4 * (x) + 1), \
321 #define STROBE_VAL_PD BIT(12)
322 #define DATA0_VAL_PD BIT(13)
323 #define DATA1_VAL_PD BIT(24)
325 #define PMC_UTMIP_UHSIC_SAVED_STATE(x) UTMIP(x, 0x1f0, 0x280)
326 #define SPEED(_port, _value) (((_value) & 0x3) << \
327 (UTMIP(_port, 8 * (_port), 8)))
328 #define UTMI_HS(_port) SPEED(_port, 0)
329 #define UTMI_FS(_port) SPEED(_port, 1)
330 #define UTMI_LS(_port) SPEED(_port, 2)
331 #define UTMI_RST(_port) SPEED(_port, 3)
333 #define PMC_UTMIP_UHSIC_TRIGGERS (0x1ec)
334 #define UTMIP_CLR_WALK_PTR(x) UTMIP(x, BIT(x), BIT(16))
335 #define UTMIP_CAP_CFG(x) UTMIP(x, BIT((x) + 4), BIT(17))
336 #define UTMIP_CLR_WAKE_ALARM(x) UTMIP(x, BIT((x) + 12), \
338 #define UHSIC_CLR_WALK_PTR BIT(3)
339 #define UHSIC_CLR_WAKE_ALARM BIT(15)
341 #define PMC_UTMIP_SLEEPWALK_PX(x) UTMIP(x, 0x204 + (4 * (x)), \
344 #define UTMIP_USBOP_RPD_A BIT(0)
345 #define UTMIP_USBON_RPD_A BIT(1)
346 #define UTMIP_AP_A BIT(4)
347 #define UTMIP_AN_A BIT(5)
348 #define UTMIP_HIGHZ_A BIT(6)
350 #define UTMIP_USBOP_RPD_B BIT(8)
351 #define UTMIP_USBON_RPD_B BIT(9)
352 #define UTMIP_AP_B BIT(12)
353 #define UTMIP_AN_B BIT(13)
354 #define UTMIP_HIGHZ_B BIT(14)
356 #define UTMIP_USBOP_RPD_C BIT(16)
357 #define UTMIP_USBON_RPD_C BIT(17)
358 #define UTMIP_AP_C BIT(20)
359 #define UTMIP_AN_C BIT(21)
360 #define UTMIP_HIGHZ_C BIT(22)
362 #define UTMIP_USBOP_RPD_D BIT(24)
363 #define UTMIP_USBON_RPD_D BIT(25)
364 #define UTMIP_AP_D BIT(28)
365 #define UTMIP_AN_D BIT(29)
366 #define UTMIP_HIGHZ_D BIT(30)
368 #define PMC_UTMIP_UHSIC_LINE_WAKEUP (0x26c)
369 #define UTMIP_LINE_WAKEUP_EN(x) UTMIP(x, BIT(x), BIT(4))
370 #define UHSIC_LINE_WAKEUP_EN BIT(3)
372 #define PMC_UTMIP_TERM_PAD_CFG (0x1f8)
373 #define PCTRL_VAL(x) (((x) & 0x3f) << 1)
374 #define TCTRL_VAL(x) (((x) & 0x3f) << 7)
376 #define PMC_UTMIP_PAD_CFGX(x) (0x4c0 + (4 * (x)))
377 #define RPD_CTRL_PX(x) (((x) & 0x1f) << 22)
379 #define PMC_UHSIC_SLEEP_CFG PMC_UTMIP_UHSIC_SLEEP_CFG(0)
380 #define UHSIC_MASTER_ENABLE BIT(24)
381 #define UHSIC_WAKE_VAL(_value) (((_value) & 0xf) << 28)
382 #define UHSIC_WAKE_VAL_SD10 UHSIC_WAKE_VAL(2)
383 #define UHSIC_WAKE_VAL_NONE UHSIC_WAKE_VAL(12)
385 #define PMC_UHSIC_FAKE PMC_UTMIP_UHSIC_FAKE(0)
386 #define UHSIC_FAKE_STROBE_VAL BIT(12)
387 #define UHSIC_FAKE_DATA_VAL BIT(13)
388 #define UHSIC_FAKE_STROBE_EN BIT(14)
389 #define UHSIC_FAKE_DATA_EN BIT(15)
391 #define PMC_UHSIC_SAVED_STATE PMC_UTMIP_UHSIC_SAVED_STATE(0)
392 #define UHSIC_MODE(_value) (((_value) & 0x1) << 24)
393 #define UHSIC_HS UHSIC_MODE(0)
394 #define UHSIC_RST UHSIC_MODE(1)
396 #define PMC_UHSIC_SLEEPWALK_CFG PMC_UTMIP_UHSIC_SLEEPWALK_CFG(0)
397 #define UHSIC_WAKE_WALK_EN BIT(30)
398 #define UHSIC_LINEVAL_WALK_EN BIT(31)
400 #define PMC_UHSIC_SLEEPWALK_P0 (0x210)
401 #define UHSIC_DATA0_RPD_A BIT(1)
402 #define UHSIC_DATA0_RPU_B BIT(11)
403 #define UHSIC_DATA0_RPU_C BIT(19)
404 #define UHSIC_DATA0_RPU_D BIT(27)
405 #define UHSIC_STROBE_RPU_A BIT(2)
406 #define UHSIC_STROBE_RPD_B BIT(8)
407 #define UHSIC_STROBE_RPD_C BIT(16)
408 #define UHSIC_STROBE_RPD_D BIT(24)
410 struct tegra210_xusb_fuse_calibration
{
411 u32 hs_curr_level
[4];
412 u32 hs_term_range_adj
;
416 struct tegra210_xusb_padctl_context
{
423 struct tegra210_xusb_padctl
{
424 struct tegra_xusb_padctl base
;
425 struct regmap
*regmap
;
427 struct tegra210_xusb_fuse_calibration fuse
;
428 struct tegra210_xusb_padctl_context context
;
431 static inline struct tegra210_xusb_padctl
*
432 to_tegra210_xusb_padctl(struct tegra_xusb_padctl
*padctl
)
434 return container_of(padctl
, struct tegra210_xusb_padctl
, base
);
437 static const struct tegra_xusb_lane_map tegra210_usb3_map
[] = {
447 static int tegra210_usb3_lane_map(struct tegra_xusb_lane
*lane
)
449 const struct tegra_xusb_lane_map
*map
;
451 for (map
= tegra210_usb3_map
; map
->type
; map
++) {
452 if (map
->index
== lane
->index
&&
453 strcmp(map
->type
, lane
->pad
->soc
->name
) == 0) {
454 dev_dbg(lane
->pad
->padctl
->dev
, "lane = %s map to port = usb3-%d\n",
455 lane
->pad
->soc
->lanes
[lane
->index
].name
, map
->port
);
463 /* must be called under padctl->lock */
464 static int tegra210_pex_uphy_enable(struct tegra_xusb_padctl
*padctl
)
466 struct tegra_xusb_pcie_pad
*pcie
= to_pcie_pad(padctl
->pcie
);
467 unsigned long timeout
;
475 err
= clk_prepare_enable(pcie
->pll
);
479 if (tegra210_plle_hw_sequence_is_enabled())
482 err
= reset_control_deassert(pcie
->rst
);
486 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_P0_CTL2
);
487 value
&= ~(XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_MASK
<<
488 XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_SHIFT
);
489 value
|= XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_VAL
<<
490 XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_SHIFT
;
491 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_P0_CTL2
);
493 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_P0_CTL5
);
494 value
&= ~(XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_MASK
<<
495 XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_SHIFT
);
496 value
|= XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_VAL
<<
497 XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_SHIFT
;
498 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_P0_CTL5
);
500 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_P0_CTL1
);
501 value
|= XUSB_PADCTL_UPHY_PLL_CTL1_PWR_OVRD
;
502 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_P0_CTL1
);
504 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_P0_CTL2
);
505 value
|= XUSB_PADCTL_UPHY_PLL_CTL2_CAL_OVRD
;
506 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_P0_CTL2
);
508 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_P0_CTL8
);
509 value
|= XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_OVRD
;
510 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_P0_CTL8
);
512 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_P0_CTL4
);
513 value
&= ~((XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_MASK
<<
514 XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SHIFT
) |
515 (XUSB_PADCTL_UPHY_PLL_CTL4_REFCLK_SEL_MASK
<<
516 XUSB_PADCTL_UPHY_PLL_CTL4_REFCLK_SEL_SHIFT
));
517 value
|= (XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_USB_VAL
<<
518 XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SHIFT
) |
519 XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_EN
;
520 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_P0_CTL4
);
522 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_P0_CTL1
);
523 value
&= ~((XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_MDIV_MASK
<<
524 XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_MDIV_SHIFT
) |
525 (XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_MASK
<<
526 XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_SHIFT
));
527 value
|= XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_USB_VAL
<<
528 XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_SHIFT
;
529 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_P0_CTL1
);
531 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_P0_CTL1
);
532 value
&= ~XUSB_PADCTL_UPHY_PLL_CTL1_IDDQ
;
533 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_P0_CTL1
);
535 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_P0_CTL1
);
536 value
&= ~(XUSB_PADCTL_UPHY_PLL_CTL1_SLEEP_MASK
<<
537 XUSB_PADCTL_UPHY_PLL_CTL1_SLEEP_SHIFT
);
538 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_P0_CTL1
);
540 usleep_range(10, 20);
542 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_P0_CTL4
);
543 value
|= XUSB_PADCTL_UPHY_PLL_CTL4_REFCLKBUF_EN
;
544 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_P0_CTL4
);
546 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_P0_CTL2
);
547 value
|= XUSB_PADCTL_UPHY_PLL_CTL2_CAL_EN
;
548 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_P0_CTL2
);
550 timeout
= jiffies
+ msecs_to_jiffies(100);
552 while (time_before(jiffies
, timeout
)) {
553 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_P0_CTL2
);
554 if (value
& XUSB_PADCTL_UPHY_PLL_CTL2_CAL_DONE
)
557 usleep_range(10, 20);
560 if (time_after_eq(jiffies
, timeout
)) {
565 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_P0_CTL2
);
566 value
&= ~XUSB_PADCTL_UPHY_PLL_CTL2_CAL_EN
;
567 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_P0_CTL2
);
569 timeout
= jiffies
+ msecs_to_jiffies(100);
571 while (time_before(jiffies
, timeout
)) {
572 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_P0_CTL2
);
573 if (!(value
& XUSB_PADCTL_UPHY_PLL_CTL2_CAL_DONE
))
576 usleep_range(10, 20);
579 if (time_after_eq(jiffies
, timeout
)) {
584 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_P0_CTL1
);
585 value
|= XUSB_PADCTL_UPHY_PLL_CTL1_ENABLE
;
586 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_P0_CTL1
);
588 timeout
= jiffies
+ msecs_to_jiffies(100);
590 while (time_before(jiffies
, timeout
)) {
591 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_P0_CTL1
);
592 if (value
& XUSB_PADCTL_UPHY_PLL_CTL1_LOCKDET_STATUS
)
595 usleep_range(10, 20);
598 if (time_after_eq(jiffies
, timeout
)) {
603 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_P0_CTL8
);
604 value
|= XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_EN
|
605 XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_CLK_EN
;
606 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_P0_CTL8
);
608 timeout
= jiffies
+ msecs_to_jiffies(100);
610 while (time_before(jiffies
, timeout
)) {
611 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_P0_CTL8
);
612 if (value
& XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_DONE
)
615 usleep_range(10, 20);
618 if (time_after_eq(jiffies
, timeout
)) {
623 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_P0_CTL8
);
624 value
&= ~XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_EN
;
625 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_P0_CTL8
);
627 timeout
= jiffies
+ msecs_to_jiffies(100);
629 while (time_before(jiffies
, timeout
)) {
630 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_P0_CTL8
);
631 if (!(value
& XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_DONE
))
634 usleep_range(10, 20);
637 if (time_after_eq(jiffies
, timeout
)) {
642 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_P0_CTL8
);
643 value
&= ~XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_CLK_EN
;
644 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_P0_CTL8
);
646 tegra210_xusb_pll_hw_control_enable();
648 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_P0_CTL1
);
649 value
&= ~XUSB_PADCTL_UPHY_PLL_CTL1_PWR_OVRD
;
650 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_P0_CTL1
);
652 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_P0_CTL2
);
653 value
&= ~XUSB_PADCTL_UPHY_PLL_CTL2_CAL_OVRD
;
654 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_P0_CTL2
);
656 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_P0_CTL8
);
657 value
&= ~XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_OVRD
;
658 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_P0_CTL8
);
660 usleep_range(10, 20);
662 tegra210_xusb_pll_hw_sequence_start();
667 for (i
= 0; i
< padctl
->pcie
->soc
->num_lanes
; i
++) {
668 value
= padctl_readl(padctl
, XUSB_PADCTL_USB3_PAD_MUX
);
669 value
|= XUSB_PADCTL_USB3_PAD_MUX_PCIE_IDDQ_DISABLE(i
);
670 padctl_writel(padctl
, value
, XUSB_PADCTL_USB3_PAD_MUX
);
676 reset_control_assert(pcie
->rst
);
678 clk_disable_unprepare(pcie
->pll
);
682 static void tegra210_pex_uphy_disable(struct tegra_xusb_padctl
*padctl
)
684 struct tegra_xusb_pcie_pad
*pcie
= to_pcie_pad(padctl
->pcie
);
688 if (WARN_ON(!pcie
->enable
))
691 pcie
->enable
= false;
693 for (i
= 0; i
< padctl
->pcie
->soc
->num_lanes
; i
++) {
694 value
= padctl_readl(padctl
, XUSB_PADCTL_USB3_PAD_MUX
);
695 value
&= ~XUSB_PADCTL_USB3_PAD_MUX_PCIE_IDDQ_DISABLE(i
);
696 padctl_writel(padctl
, value
, XUSB_PADCTL_USB3_PAD_MUX
);
699 clk_disable_unprepare(pcie
->pll
);
702 /* must be called under padctl->lock */
703 static int tegra210_sata_uphy_enable(struct tegra_xusb_padctl
*padctl
)
705 struct tegra_xusb_sata_pad
*sata
= to_sata_pad(padctl
->sata
);
706 struct tegra_xusb_lane
*lane
= tegra_xusb_find_lane(padctl
, "sata", 0);
707 unsigned long timeout
;
719 if (tegra210_plle_hw_sequence_is_enabled())
722 usb
= tegra_xusb_lane_check(lane
, "usb3-ss");
724 err
= clk_prepare_enable(sata
->pll
);
728 err
= reset_control_deassert(sata
->rst
);
732 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_S0_CTL2
);
733 value
&= ~(XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_MASK
<<
734 XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_SHIFT
);
735 value
|= XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_VAL
<<
736 XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_SHIFT
;
737 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_S0_CTL2
);
739 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_S0_CTL5
);
740 value
&= ~(XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_MASK
<<
741 XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_SHIFT
);
742 value
|= XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_VAL
<<
743 XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_SHIFT
;
744 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_S0_CTL5
);
746 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_S0_CTL1
);
747 value
|= XUSB_PADCTL_UPHY_PLL_CTL1_PWR_OVRD
;
748 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_S0_CTL1
);
750 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_S0_CTL2
);
751 value
|= XUSB_PADCTL_UPHY_PLL_CTL2_CAL_OVRD
;
752 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_S0_CTL2
);
754 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_S0_CTL8
);
755 value
|= XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_OVRD
;
756 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_S0_CTL8
);
758 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_S0_CTL4
);
759 value
&= ~((XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_MASK
<<
760 XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SHIFT
) |
761 (XUSB_PADCTL_UPHY_PLL_CTL4_REFCLK_SEL_MASK
<<
762 XUSB_PADCTL_UPHY_PLL_CTL4_REFCLK_SEL_SHIFT
));
763 value
|= XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_EN
;
766 value
|= (XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_USB_VAL
<<
767 XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SHIFT
);
769 value
|= (XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SATA_VAL
<<
770 XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SHIFT
);
772 value
&= ~XUSB_PADCTL_UPHY_PLL_CTL4_XDIGCLK_EN
;
773 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_S0_CTL4
);
775 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_S0_CTL1
);
776 value
&= ~((XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_MDIV_MASK
<<
777 XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_MDIV_SHIFT
) |
778 (XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_MASK
<<
779 XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_SHIFT
));
782 value
|= XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_USB_VAL
<<
783 XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_SHIFT
;
785 value
|= XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_SATA_VAL
<<
786 XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_SHIFT
;
788 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_S0_CTL1
);
790 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_S0_CTL1
);
791 value
&= ~XUSB_PADCTL_UPHY_PLL_CTL1_IDDQ
;
792 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_S0_CTL1
);
794 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_S0_CTL1
);
795 value
&= ~(XUSB_PADCTL_UPHY_PLL_CTL1_SLEEP_MASK
<<
796 XUSB_PADCTL_UPHY_PLL_CTL1_SLEEP_SHIFT
);
797 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_S0_CTL1
);
799 usleep_range(10, 20);
801 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_S0_CTL4
);
802 value
|= XUSB_PADCTL_UPHY_PLL_CTL4_REFCLKBUF_EN
;
803 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_S0_CTL4
);
805 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_S0_CTL2
);
806 value
|= XUSB_PADCTL_UPHY_PLL_CTL2_CAL_EN
;
807 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_S0_CTL2
);
809 timeout
= jiffies
+ msecs_to_jiffies(100);
811 while (time_before(jiffies
, timeout
)) {
812 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_S0_CTL2
);
813 if (value
& XUSB_PADCTL_UPHY_PLL_CTL2_CAL_DONE
)
816 usleep_range(10, 20);
819 if (time_after_eq(jiffies
, timeout
)) {
824 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_S0_CTL2
);
825 value
&= ~XUSB_PADCTL_UPHY_PLL_CTL2_CAL_EN
;
826 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_S0_CTL2
);
828 timeout
= jiffies
+ msecs_to_jiffies(100);
830 while (time_before(jiffies
, timeout
)) {
831 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_S0_CTL2
);
832 if (!(value
& XUSB_PADCTL_UPHY_PLL_CTL2_CAL_DONE
))
835 usleep_range(10, 20);
838 if (time_after_eq(jiffies
, timeout
)) {
843 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_S0_CTL1
);
844 value
|= XUSB_PADCTL_UPHY_PLL_CTL1_ENABLE
;
845 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_S0_CTL1
);
847 timeout
= jiffies
+ msecs_to_jiffies(100);
849 while (time_before(jiffies
, timeout
)) {
850 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_S0_CTL1
);
851 if (value
& XUSB_PADCTL_UPHY_PLL_CTL1_LOCKDET_STATUS
)
854 usleep_range(10, 20);
857 if (time_after_eq(jiffies
, timeout
)) {
862 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_S0_CTL8
);
863 value
|= XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_EN
|
864 XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_CLK_EN
;
865 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_S0_CTL8
);
867 timeout
= jiffies
+ msecs_to_jiffies(100);
869 while (time_before(jiffies
, timeout
)) {
870 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_S0_CTL8
);
871 if (value
& XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_DONE
)
874 usleep_range(10, 20);
877 if (time_after_eq(jiffies
, timeout
)) {
882 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_S0_CTL8
);
883 value
&= ~XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_EN
;
884 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_S0_CTL8
);
886 timeout
= jiffies
+ msecs_to_jiffies(100);
888 while (time_before(jiffies
, timeout
)) {
889 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_S0_CTL8
);
890 if (!(value
& XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_DONE
))
893 usleep_range(10, 20);
896 if (time_after_eq(jiffies
, timeout
)) {
901 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_S0_CTL8
);
902 value
&= ~XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_CLK_EN
;
903 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_S0_CTL8
);
905 tegra210_sata_pll_hw_control_enable();
907 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_S0_CTL1
);
908 value
&= ~XUSB_PADCTL_UPHY_PLL_CTL1_PWR_OVRD
;
909 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_S0_CTL1
);
911 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_S0_CTL2
);
912 value
&= ~XUSB_PADCTL_UPHY_PLL_CTL2_CAL_OVRD
;
913 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_S0_CTL2
);
915 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_PLL_S0_CTL8
);
916 value
&= ~XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_OVRD
;
917 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_PLL_S0_CTL8
);
919 usleep_range(10, 20);
921 tegra210_sata_pll_hw_sequence_start();
926 for (i
= 0; i
< padctl
->sata
->soc
->num_lanes
; i
++) {
927 value
= padctl_readl(padctl
, XUSB_PADCTL_USB3_PAD_MUX
);
928 value
|= XUSB_PADCTL_USB3_PAD_MUX_SATA_IDDQ_DISABLE(i
);
929 padctl_writel(padctl
, value
, XUSB_PADCTL_USB3_PAD_MUX
);
935 reset_control_assert(sata
->rst
);
937 clk_disable_unprepare(sata
->pll
);
941 static void tegra210_sata_uphy_disable(struct tegra_xusb_padctl
*padctl
)
943 struct tegra_xusb_sata_pad
*sata
= to_sata_pad(padctl
->sata
);
947 if (WARN_ON(!sata
->enable
))
950 sata
->enable
= false;
952 for (i
= 0; i
< padctl
->sata
->soc
->num_lanes
; i
++) {
953 value
= padctl_readl(padctl
, XUSB_PADCTL_USB3_PAD_MUX
);
954 value
&= ~XUSB_PADCTL_USB3_PAD_MUX_SATA_IDDQ_DISABLE(i
);
955 padctl_writel(padctl
, value
, XUSB_PADCTL_USB3_PAD_MUX
);
958 clk_disable_unprepare(sata
->pll
);
961 static void tegra210_aux_mux_lp0_clamp_disable(struct tegra_xusb_padctl
*padctl
)
965 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM1
);
966 value
&= ~XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_CLAMP_EN
;
967 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM1
);
969 usleep_range(100, 200);
971 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM1
);
972 value
&= ~XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_CLAMP_EN_EARLY
;
973 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM1
);
975 usleep_range(100, 200);
977 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM1
);
978 value
&= ~XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_VCORE_DOWN
;
979 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM1
);
982 static void tegra210_aux_mux_lp0_clamp_enable(struct tegra_xusb_padctl
*padctl
)
986 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM1
);
987 value
|= XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_VCORE_DOWN
;
988 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM1
);
990 usleep_range(100, 200);
992 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM1
);
993 value
|= XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_CLAMP_EN_EARLY
;
994 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM1
);
996 usleep_range(100, 200);
998 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM1
);
999 value
|= XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_CLAMP_EN
;
1000 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM1
);
1003 static int tegra210_uphy_init(struct tegra_xusb_padctl
*padctl
)
1006 tegra210_pex_uphy_enable(padctl
);
1009 tegra210_sata_uphy_enable(padctl
);
1011 if (!tegra210_plle_hw_sequence_is_enabled())
1012 tegra210_plle_hw_sequence_start();
1014 dev_dbg(padctl
->dev
, "PLLE is already in HW control\n");
1016 tegra210_aux_mux_lp0_clamp_disable(padctl
);
1021 static void __maybe_unused
1022 tegra210_uphy_deinit(struct tegra_xusb_padctl
*padctl
)
1024 tegra210_aux_mux_lp0_clamp_enable(padctl
);
1027 tegra210_sata_uphy_disable(padctl
);
1030 tegra210_pex_uphy_disable(padctl
);
1033 static int tegra210_hsic_set_idle(struct tegra_xusb_padctl
*padctl
,
1034 unsigned int index
, bool idle
)
1038 value
= padctl_readl(padctl
, XUSB_PADCTL_HSIC_PADX_CTL0(index
));
1040 value
&= ~(XUSB_PADCTL_HSIC_PAD_CTL0_RPU_DATA0
|
1041 XUSB_PADCTL_HSIC_PAD_CTL0_RPU_DATA1
|
1042 XUSB_PADCTL_HSIC_PAD_CTL0_RPD_STROBE
);
1045 value
|= XUSB_PADCTL_HSIC_PAD_CTL0_RPD_DATA0
|
1046 XUSB_PADCTL_HSIC_PAD_CTL0_RPD_DATA1
|
1047 XUSB_PADCTL_HSIC_PAD_CTL0_RPU_STROBE
;
1049 value
&= ~(XUSB_PADCTL_HSIC_PAD_CTL0_RPD_DATA0
|
1050 XUSB_PADCTL_HSIC_PAD_CTL0_RPD_DATA1
|
1051 XUSB_PADCTL_HSIC_PAD_CTL0_RPU_STROBE
);
1053 padctl_writel(padctl
, value
, XUSB_PADCTL_HSIC_PADX_CTL0(index
));
1058 static int tegra210_usb3_enable_phy_sleepwalk(struct tegra_xusb_lane
*lane
,
1059 enum usb_device_speed speed
)
1061 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
1062 int port
= tegra210_usb3_lane_map(lane
);
1063 struct device
*dev
= padctl
->dev
;
1067 dev_err(dev
, "invalid usb3 port number\n");
1071 mutex_lock(&padctl
->lock
);
1073 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM1
);
1074 value
|= XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN_EARLY(port
);
1075 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM1
);
1077 usleep_range(100, 200);
1079 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM1
);
1080 value
|= XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN(port
);
1081 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM1
);
1083 usleep_range(250, 350);
1085 mutex_unlock(&padctl
->lock
);
1090 static int tegra210_usb3_disable_phy_sleepwalk(struct tegra_xusb_lane
*lane
)
1092 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
1093 int port
= tegra210_usb3_lane_map(lane
);
1094 struct device
*dev
= padctl
->dev
;
1098 dev_err(dev
, "invalid usb3 port number\n");
1102 mutex_lock(&padctl
->lock
);
1104 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM1
);
1105 value
&= ~XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN_EARLY(port
);
1106 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM1
);
1108 usleep_range(100, 200);
1110 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM1
);
1111 value
&= ~XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN(port
);
1112 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM1
);
1114 mutex_unlock(&padctl
->lock
);
1119 static int tegra210_usb3_enable_phy_wake(struct tegra_xusb_lane
*lane
)
1121 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
1122 int port
= tegra210_usb3_lane_map(lane
);
1123 struct device
*dev
= padctl
->dev
;
1127 dev_err(dev
, "invalid usb3 port number\n");
1131 mutex_lock(&padctl
->lock
);
1133 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1134 value
&= ~ALL_WAKE_EVENTS
;
1135 value
|= SS_PORT_WAKEUP_EVENT(port
);
1136 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1138 usleep_range(10, 20);
1140 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1141 value
&= ~ALL_WAKE_EVENTS
;
1142 value
|= SS_PORT_WAKE_INTERRUPT_ENABLE(port
);
1143 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1145 mutex_unlock(&padctl
->lock
);
1150 static int tegra210_usb3_disable_phy_wake(struct tegra_xusb_lane
*lane
)
1152 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
1153 int port
= tegra210_usb3_lane_map(lane
);
1154 struct device
*dev
= padctl
->dev
;
1158 dev_err(dev
, "invalid usb3 port number\n");
1162 mutex_lock(&padctl
->lock
);
1164 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1165 value
&= ~ALL_WAKE_EVENTS
;
1166 value
&= ~SS_PORT_WAKE_INTERRUPT_ENABLE(port
);
1167 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1169 usleep_range(10, 20);
1171 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1172 value
&= ~ALL_WAKE_EVENTS
;
1173 value
|= SS_PORT_WAKEUP_EVENT(port
);
1174 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1176 mutex_unlock(&padctl
->lock
);
1181 static bool tegra210_usb3_phy_remote_wake_detected(struct tegra_xusb_lane
*lane
)
1183 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
1184 int index
= tegra210_usb3_lane_map(lane
);
1190 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1191 if ((value
& SS_PORT_WAKE_INTERRUPT_ENABLE(index
)) && (value
& SS_PORT_WAKEUP_EVENT(index
)))
1197 static int tegra210_utmi_enable_phy_wake(struct tegra_xusb_lane
*lane
)
1199 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
1200 unsigned int index
= lane
->index
;
1203 mutex_lock(&padctl
->lock
);
1205 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1206 value
&= ~ALL_WAKE_EVENTS
;
1207 value
|= USB2_PORT_WAKEUP_EVENT(index
);
1208 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1210 usleep_range(10, 20);
1212 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1213 value
&= ~ALL_WAKE_EVENTS
;
1214 value
|= USB2_PORT_WAKE_INTERRUPT_ENABLE(index
);
1215 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1217 mutex_unlock(&padctl
->lock
);
1222 static int tegra210_utmi_disable_phy_wake(struct tegra_xusb_lane
*lane
)
1224 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
1225 unsigned int index
= lane
->index
;
1228 mutex_lock(&padctl
->lock
);
1230 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1231 value
&= ~ALL_WAKE_EVENTS
;
1232 value
&= ~USB2_PORT_WAKE_INTERRUPT_ENABLE(index
);
1233 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1235 usleep_range(10, 20);
1237 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1238 value
&= ~ALL_WAKE_EVENTS
;
1239 value
|= USB2_PORT_WAKEUP_EVENT(index
);
1240 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1242 mutex_unlock(&padctl
->lock
);
1247 static bool tegra210_utmi_phy_remote_wake_detected(struct tegra_xusb_lane
*lane
)
1249 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
1250 unsigned int index
= lane
->index
;
1253 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1254 if ((value
& USB2_PORT_WAKE_INTERRUPT_ENABLE(index
)) &&
1255 (value
& USB2_PORT_WAKEUP_EVENT(index
)))
1261 static int tegra210_hsic_enable_phy_wake(struct tegra_xusb_lane
*lane
)
1263 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
1264 unsigned int index
= lane
->index
;
1267 mutex_lock(&padctl
->lock
);
1269 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1270 value
&= ~ALL_WAKE_EVENTS
;
1271 value
|= USB2_HSIC_PORT_WAKEUP_EVENT(index
);
1272 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1274 usleep_range(10, 20);
1276 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1277 value
&= ~ALL_WAKE_EVENTS
;
1278 value
|= USB2_HSIC_PORT_WAKE_INTERRUPT_ENABLE(index
);
1279 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1281 mutex_unlock(&padctl
->lock
);
1286 static int tegra210_hsic_disable_phy_wake(struct tegra_xusb_lane
*lane
)
1288 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
1289 unsigned int index
= lane
->index
;
1292 mutex_lock(&padctl
->lock
);
1294 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1295 value
&= ~ALL_WAKE_EVENTS
;
1296 value
&= ~USB2_HSIC_PORT_WAKE_INTERRUPT_ENABLE(index
);
1297 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1299 usleep_range(10, 20);
1301 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1302 value
&= ~ALL_WAKE_EVENTS
;
1303 value
|= USB2_HSIC_PORT_WAKEUP_EVENT(index
);
1304 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1306 mutex_unlock(&padctl
->lock
);
1311 static bool tegra210_hsic_phy_remote_wake_detected(struct tegra_xusb_lane
*lane
)
1313 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
1314 unsigned int index
= lane
->index
;
1317 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM_0
);
1318 if ((value
& USB2_HSIC_PORT_WAKE_INTERRUPT_ENABLE(index
)) &&
1319 (value
& USB2_HSIC_PORT_WAKEUP_EVENT(index
)))
1325 #define padctl_pmc_readl(_priv, _offset) \
1328 WARN(regmap_read(_priv->regmap, _offset, &value), "read %s failed\n", #_offset);\
1332 #define padctl_pmc_writel(_priv, _value, _offset) \
1333 WARN(regmap_write(_priv->regmap, _offset, _value), "write %s failed\n", #_offset)
1335 static int tegra210_pmc_utmi_enable_phy_sleepwalk(struct tegra_xusb_lane
*lane
,
1336 enum usb_device_speed speed
)
1338 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
1339 struct tegra210_xusb_padctl
*priv
= to_tegra210_xusb_padctl(padctl
);
1340 unsigned int port
= lane
->index
;
1341 u32 value
, tctrl
, pctrl
, rpd_ctrl
;
1346 if (speed
> USB_SPEED_HIGH
)
1349 value
= padctl_readl(padctl
, XUSB_PADCTL_USB2_BIAS_PAD_CTL1
);
1350 tctrl
= TCTRL_VALUE(value
);
1351 pctrl
= PCTRL_VALUE(value
);
1353 value
= padctl_readl(padctl
, XUSB_PADCTL_USB2_OTG_PADX_CTL1(port
));
1354 rpd_ctrl
= RPD_CTRL_VALUE(value
);
1356 /* ensure sleepwalk logic is disabled */
1357 value
= padctl_pmc_readl(priv
, PMC_UTMIP_UHSIC_SLEEP_CFG(port
));
1358 value
&= ~UTMIP_MASTER_ENABLE(port
);
1359 padctl_pmc_writel(priv
, value
, PMC_UTMIP_UHSIC_SLEEP_CFG(port
));
1361 /* ensure sleepwalk logics are in low power mode */
1362 value
= padctl_pmc_readl(priv
, PMC_UTMIP_MASTER_CONFIG
);
1363 value
|= UTMIP_PWR(port
);
1364 padctl_pmc_writel(priv
, value
, PMC_UTMIP_MASTER_CONFIG
);
1366 /* set debounce time */
1367 value
= padctl_pmc_readl(priv
, PMC_USB_DEBOUNCE_DEL
);
1368 value
&= ~UTMIP_LINE_DEB_CNT(~0);
1369 value
|= UTMIP_LINE_DEB_CNT(0x1);
1370 padctl_pmc_writel(priv
, value
, PMC_USB_DEBOUNCE_DEL
);
1372 /* ensure fake events of sleepwalk logic are desiabled */
1373 value
= padctl_pmc_readl(priv
, PMC_UTMIP_UHSIC_FAKE(port
));
1374 value
&= ~(UTMIP_FAKE_USBOP_VAL(port
) | UTMIP_FAKE_USBON_VAL(port
) |
1375 UTMIP_FAKE_USBOP_EN(port
) | UTMIP_FAKE_USBON_EN(port
));
1376 padctl_pmc_writel(priv
, value
, PMC_UTMIP_UHSIC_FAKE(port
));
1378 /* ensure wake events of sleepwalk logic are not latched */
1379 value
= padctl_pmc_readl(priv
, PMC_UTMIP_UHSIC_LINE_WAKEUP
);
1380 value
&= ~UTMIP_LINE_WAKEUP_EN(port
);
1381 padctl_pmc_writel(priv
, value
, PMC_UTMIP_UHSIC_LINE_WAKEUP
);
1383 /* disable wake event triggers of sleepwalk logic */
1384 value
= padctl_pmc_readl(priv
, PMC_UTMIP_UHSIC_SLEEP_CFG(port
));
1385 value
&= ~UTMIP_WAKE_VAL(port
, ~0);
1386 value
|= UTMIP_WAKE_VAL_NONE(port
);
1387 padctl_pmc_writel(priv
, value
, PMC_UTMIP_UHSIC_SLEEP_CFG(port
));
1389 /* power down the line state detectors of the pad */
1390 value
= padctl_pmc_readl(priv
, PMC_USB_AO
);
1391 value
|= (USBOP_VAL_PD(port
) | USBON_VAL_PD(port
));
1392 padctl_pmc_writel(priv
, value
, PMC_USB_AO
);
1394 /* save state per speed */
1395 value
= padctl_pmc_readl(priv
, PMC_UTMIP_UHSIC_SAVED_STATE(port
));
1396 value
&= ~SPEED(port
, ~0);
1399 case USB_SPEED_HIGH
:
1400 value
|= UTMI_HS(port
);
1403 case USB_SPEED_FULL
:
1404 value
|= UTMI_FS(port
);
1408 value
|= UTMI_LS(port
);
1412 value
|= UTMI_RST(port
);
1416 padctl_pmc_writel(priv
, value
, PMC_UTMIP_UHSIC_SAVED_STATE(port
));
1418 /* enable the trigger of the sleepwalk logic */
1419 value
= padctl_pmc_readl(priv
, PMC_UTMIP_UHSIC_SLEEPWALK_CFG(port
));
1420 value
|= UTMIP_LINEVAL_WALK_EN(port
);
1421 padctl_pmc_writel(priv
, value
, PMC_UTMIP_UHSIC_SLEEPWALK_CFG(port
));
1424 * Reset the walk pointer and clear the alarm of the sleepwalk logic,
1425 * as well as capture the configuration of the USB2.0 pad.
1427 value
= padctl_pmc_readl(priv
, PMC_UTMIP_UHSIC_TRIGGERS
);
1428 value
|= UTMIP_CLR_WALK_PTR(port
) | UTMIP_CLR_WAKE_ALARM(port
) | UTMIP_CAP_CFG(port
);
1429 padctl_pmc_writel(priv
, value
, PMC_UTMIP_UHSIC_TRIGGERS
);
1431 /* program electrical parameters read from XUSB PADCTL */
1432 value
= padctl_pmc_readl(priv
, PMC_UTMIP_TERM_PAD_CFG
);
1433 value
&= ~(TCTRL_VAL(~0) | PCTRL_VAL(~0));
1434 value
|= (TCTRL_VAL(tctrl
) | PCTRL_VAL(pctrl
));
1435 padctl_pmc_writel(priv
, value
, PMC_UTMIP_TERM_PAD_CFG
);
1437 value
= padctl_pmc_readl(priv
, PMC_UTMIP_PAD_CFGX(port
));
1438 value
&= ~RPD_CTRL_PX(~0);
1439 value
|= RPD_CTRL_PX(rpd_ctrl
);
1440 padctl_pmc_writel(priv
, value
, PMC_UTMIP_PAD_CFGX(port
));
1443 * Set up the pull-ups and pull-downs of the signals during the four
1444 * stages of sleepwalk. If a device is connected, program sleepwalk
1445 * logic to maintain a J and keep driving K upon seeing remote wake.
1447 value
= padctl_pmc_readl(priv
, PMC_UTMIP_SLEEPWALK_PX(port
));
1448 value
= UTMIP_USBOP_RPD_A
| UTMIP_USBOP_RPD_B
| UTMIP_USBOP_RPD_C
| UTMIP_USBOP_RPD_D
;
1449 value
|= UTMIP_USBON_RPD_A
| UTMIP_USBON_RPD_B
| UTMIP_USBON_RPD_C
| UTMIP_USBON_RPD_D
;
1452 case USB_SPEED_HIGH
:
1453 case USB_SPEED_FULL
:
1454 /* J state: D+/D- = high/low, K state: D+/D- = low/high */
1455 value
|= UTMIP_HIGHZ_A
;
1456 value
|= UTMIP_AP_A
;
1457 value
|= UTMIP_AN_B
| UTMIP_AN_C
| UTMIP_AN_D
;
1461 /* J state: D+/D- = low/high, K state: D+/D- = high/low */
1462 value
|= UTMIP_HIGHZ_A
;
1463 value
|= UTMIP_AN_A
;
1464 value
|= UTMIP_AP_B
| UTMIP_AP_C
| UTMIP_AP_D
;
1468 value
|= UTMIP_HIGHZ_A
| UTMIP_HIGHZ_B
| UTMIP_HIGHZ_C
| UTMIP_HIGHZ_D
;
1472 padctl_pmc_writel(priv
, value
, PMC_UTMIP_SLEEPWALK_PX(port
));
1474 /* power up the line state detectors of the pad */
1475 value
= padctl_pmc_readl(priv
, PMC_USB_AO
);
1476 value
&= ~(USBOP_VAL_PD(port
) | USBON_VAL_PD(port
));
1477 padctl_pmc_writel(priv
, value
, PMC_USB_AO
);
1479 usleep_range(50, 100);
1481 /* switch the electric control of the USB2.0 pad to PMC */
1482 value
= padctl_pmc_readl(priv
, PMC_UTMIP_UHSIC_SLEEP_CFG(port
));
1483 value
|= UTMIP_FSLS_USE_PMC(port
) | UTMIP_PCTRL_USE_PMC(port
) | UTMIP_TCTRL_USE_PMC(port
);
1484 padctl_pmc_writel(priv
, value
, PMC_UTMIP_UHSIC_SLEEP_CFG(port
));
1486 value
= padctl_pmc_readl(priv
, PMC_UTMIP_UHSIC_SLEEP_CFG1
);
1487 value
|= UTMIP_RPD_CTRL_USE_PMC_PX(port
) | UTMIP_RPU_SWITC_LOW_USE_PMC_PX(port
);
1488 padctl_pmc_writel(priv
, value
, PMC_UTMIP_UHSIC_SLEEP_CFG1
);
1490 /* set the wake signaling trigger events */
1491 value
= padctl_pmc_readl(priv
, PMC_UTMIP_UHSIC_SLEEP_CFG(port
));
1492 value
&= ~UTMIP_WAKE_VAL(port
, ~0);
1493 value
|= UTMIP_WAKE_VAL_ANY(port
);
1494 padctl_pmc_writel(priv
, value
, PMC_UTMIP_UHSIC_SLEEP_CFG(port
));
1496 /* enable the wake detection */
1497 value
= padctl_pmc_readl(priv
, PMC_UTMIP_UHSIC_SLEEP_CFG(port
));
1498 value
|= UTMIP_MASTER_ENABLE(port
);
1499 padctl_pmc_writel(priv
, value
, PMC_UTMIP_UHSIC_SLEEP_CFG(port
));
1501 value
= padctl_pmc_readl(priv
, PMC_UTMIP_UHSIC_LINE_WAKEUP
);
1502 value
|= UTMIP_LINE_WAKEUP_EN(port
);
1503 padctl_pmc_writel(priv
, value
, PMC_UTMIP_UHSIC_LINE_WAKEUP
);
1508 static int tegra210_pmc_utmi_disable_phy_sleepwalk(struct tegra_xusb_lane
*lane
)
1510 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
1511 struct tegra210_xusb_padctl
*priv
= to_tegra210_xusb_padctl(padctl
);
1512 unsigned int port
= lane
->index
;
1518 /* disable the wake detection */
1519 value
= padctl_pmc_readl(priv
, PMC_UTMIP_UHSIC_SLEEP_CFG(port
));
1520 value
&= ~UTMIP_MASTER_ENABLE(port
);
1521 padctl_pmc_writel(priv
, value
, PMC_UTMIP_UHSIC_SLEEP_CFG(port
));
1523 value
= padctl_pmc_readl(priv
, PMC_UTMIP_UHSIC_LINE_WAKEUP
);
1524 value
&= ~UTMIP_LINE_WAKEUP_EN(port
);
1525 padctl_pmc_writel(priv
, value
, PMC_UTMIP_UHSIC_LINE_WAKEUP
);
1527 /* switch the electric control of the USB2.0 pad to XUSB or USB2 */
1528 value
= padctl_pmc_readl(priv
, PMC_UTMIP_UHSIC_SLEEP_CFG(port
));
1529 value
&= ~(UTMIP_FSLS_USE_PMC(port
) | UTMIP_PCTRL_USE_PMC(port
) |
1530 UTMIP_TCTRL_USE_PMC(port
));
1531 padctl_pmc_writel(priv
, value
, PMC_UTMIP_UHSIC_SLEEP_CFG(port
));
1533 value
= padctl_pmc_readl(priv
, PMC_UTMIP_UHSIC_SLEEP_CFG1
);
1534 value
&= ~(UTMIP_RPD_CTRL_USE_PMC_PX(port
) | UTMIP_RPU_SWITC_LOW_USE_PMC_PX(port
));
1535 padctl_pmc_writel(priv
, value
, PMC_UTMIP_UHSIC_SLEEP_CFG1
);
1537 /* disable wake event triggers of sleepwalk logic */
1538 value
= padctl_pmc_readl(priv
, PMC_UTMIP_UHSIC_SLEEP_CFG(port
));
1539 value
&= ~UTMIP_WAKE_VAL(port
, ~0);
1540 value
|= UTMIP_WAKE_VAL_NONE(port
);
1541 padctl_pmc_writel(priv
, value
, PMC_UTMIP_UHSIC_SLEEP_CFG(port
));
1543 /* power down the line state detectors of the port */
1544 value
= padctl_pmc_readl(priv
, PMC_USB_AO
);
1545 value
|= (USBOP_VAL_PD(port
) | USBON_VAL_PD(port
));
1546 padctl_pmc_writel(priv
, value
, PMC_USB_AO
);
1548 /* clear alarm of the sleepwalk logic */
1549 value
= padctl_pmc_readl(priv
, PMC_UTMIP_UHSIC_TRIGGERS
);
1550 value
|= UTMIP_CLR_WAKE_ALARM(port
);
1551 padctl_pmc_writel(priv
, value
, PMC_UTMIP_UHSIC_TRIGGERS
);
1556 static int tegra210_pmc_hsic_enable_phy_sleepwalk(struct tegra_xusb_lane
*lane
,
1557 enum usb_device_speed speed
)
1559 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
1560 struct tegra210_xusb_padctl
*priv
= to_tegra210_xusb_padctl(padctl
);
1566 /* ensure sleepwalk logic is disabled */
1567 value
= padctl_pmc_readl(priv
, PMC_UHSIC_SLEEP_CFG
);
1568 value
&= ~UHSIC_MASTER_ENABLE
;
1569 padctl_pmc_writel(priv
, value
, PMC_UHSIC_SLEEP_CFG
);
1571 /* ensure sleepwalk logics are in low power mode */
1572 value
= padctl_pmc_readl(priv
, PMC_UTMIP_MASTER_CONFIG
);
1574 padctl_pmc_writel(priv
, value
, PMC_UTMIP_MASTER_CONFIG
);
1576 /* set debounce time */
1577 value
= padctl_pmc_readl(priv
, PMC_USB_DEBOUNCE_DEL
);
1578 value
&= ~UHSIC_LINE_DEB_CNT(~0);
1579 value
|= UHSIC_LINE_DEB_CNT(0x1);
1580 padctl_pmc_writel(priv
, value
, PMC_USB_DEBOUNCE_DEL
);
1582 /* ensure fake events of sleepwalk logic are desiabled */
1583 value
= padctl_pmc_readl(priv
, PMC_UHSIC_FAKE
);
1584 value
&= ~(UHSIC_FAKE_STROBE_VAL
| UHSIC_FAKE_DATA_VAL
|
1585 UHSIC_FAKE_STROBE_EN
| UHSIC_FAKE_DATA_EN
);
1586 padctl_pmc_writel(priv
, value
, PMC_UHSIC_FAKE
);
1588 /* ensure wake events of sleepwalk logic are not latched */
1589 value
= padctl_pmc_readl(priv
, PMC_UTMIP_UHSIC_LINE_WAKEUP
);
1590 value
&= ~UHSIC_LINE_WAKEUP_EN
;
1591 padctl_pmc_writel(priv
, value
, PMC_UTMIP_UHSIC_LINE_WAKEUP
);
1593 /* disable wake event triggers of sleepwalk logic */
1594 value
= padctl_pmc_readl(priv
, PMC_UHSIC_SLEEP_CFG
);
1595 value
&= ~UHSIC_WAKE_VAL(~0);
1596 value
|= UHSIC_WAKE_VAL_NONE
;
1597 padctl_pmc_writel(priv
, value
, PMC_UHSIC_SLEEP_CFG
);
1599 /* power down the line state detectors of the port */
1600 value
= padctl_pmc_readl(priv
, PMC_USB_AO
);
1601 value
|= STROBE_VAL_PD
| DATA0_VAL_PD
| DATA1_VAL_PD
;
1602 padctl_pmc_writel(priv
, value
, PMC_USB_AO
);
1604 /* save state, HSIC always comes up as HS */
1605 value
= padctl_pmc_readl(priv
, PMC_UHSIC_SAVED_STATE
);
1606 value
&= ~UHSIC_MODE(~0);
1608 padctl_pmc_writel(priv
, value
, PMC_UHSIC_SAVED_STATE
);
1610 /* enable the trigger of the sleepwalk logic */
1611 value
= padctl_pmc_readl(priv
, PMC_UHSIC_SLEEPWALK_CFG
);
1612 value
|= UHSIC_WAKE_WALK_EN
| UHSIC_LINEVAL_WALK_EN
;
1613 padctl_pmc_writel(priv
, value
, PMC_UHSIC_SLEEPWALK_CFG
);
1616 * Reset the walk pointer and clear the alarm of the sleepwalk logic,
1617 * as well as capture the configuration of the USB2.0 port.
1619 value
= padctl_pmc_readl(priv
, PMC_UTMIP_UHSIC_TRIGGERS
);
1620 value
|= UHSIC_CLR_WALK_PTR
| UHSIC_CLR_WAKE_ALARM
;
1621 padctl_pmc_writel(priv
, value
, PMC_UTMIP_UHSIC_TRIGGERS
);
1624 * Set up the pull-ups and pull-downs of the signals during the four
1625 * stages of sleepwalk. Maintain a HSIC IDLE and keep driving HSIC
1626 * RESUME upon remote wake.
1628 value
= padctl_pmc_readl(priv
, PMC_UHSIC_SLEEPWALK_P0
);
1629 value
= UHSIC_DATA0_RPD_A
| UHSIC_DATA0_RPU_B
| UHSIC_DATA0_RPU_C
| UHSIC_DATA0_RPU_D
|
1630 UHSIC_STROBE_RPU_A
| UHSIC_STROBE_RPD_B
| UHSIC_STROBE_RPD_C
| UHSIC_STROBE_RPD_D
;
1631 padctl_pmc_writel(priv
, value
, PMC_UHSIC_SLEEPWALK_P0
);
1633 /* power up the line state detectors of the port */
1634 value
= padctl_pmc_readl(priv
, PMC_USB_AO
);
1635 value
&= ~(STROBE_VAL_PD
| DATA0_VAL_PD
| DATA1_VAL_PD
);
1636 padctl_pmc_writel(priv
, value
, PMC_USB_AO
);
1638 usleep_range(50, 100);
1640 /* set the wake signaling trigger events */
1641 value
= padctl_pmc_readl(priv
, PMC_UHSIC_SLEEP_CFG
);
1642 value
&= ~UHSIC_WAKE_VAL(~0);
1643 value
|= UHSIC_WAKE_VAL_SD10
;
1644 padctl_pmc_writel(priv
, value
, PMC_UHSIC_SLEEP_CFG
);
1646 /* enable the wake detection */
1647 value
= padctl_pmc_readl(priv
, PMC_UHSIC_SLEEP_CFG
);
1648 value
|= UHSIC_MASTER_ENABLE
;
1649 padctl_pmc_writel(priv
, value
, PMC_UHSIC_SLEEP_CFG
);
1651 value
= padctl_pmc_readl(priv
, PMC_UTMIP_UHSIC_LINE_WAKEUP
);
1652 value
|= UHSIC_LINE_WAKEUP_EN
;
1653 padctl_pmc_writel(priv
, value
, PMC_UTMIP_UHSIC_LINE_WAKEUP
);
1658 static int tegra210_pmc_hsic_disable_phy_sleepwalk(struct tegra_xusb_lane
*lane
)
1660 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
1661 struct tegra210_xusb_padctl
*priv
= to_tegra210_xusb_padctl(padctl
);
1667 /* disable the wake detection */
1668 value
= padctl_pmc_readl(priv
, PMC_UHSIC_SLEEP_CFG
);
1669 value
&= ~UHSIC_MASTER_ENABLE
;
1670 padctl_pmc_writel(priv
, value
, PMC_UHSIC_SLEEP_CFG
);
1672 value
= padctl_pmc_readl(priv
, PMC_UTMIP_UHSIC_LINE_WAKEUP
);
1673 value
&= ~UHSIC_LINE_WAKEUP_EN
;
1674 padctl_pmc_writel(priv
, value
, PMC_UTMIP_UHSIC_LINE_WAKEUP
);
1676 /* disable wake event triggers of sleepwalk logic */
1677 value
= padctl_pmc_readl(priv
, PMC_UHSIC_SLEEP_CFG
);
1678 value
&= ~UHSIC_WAKE_VAL(~0);
1679 value
|= UHSIC_WAKE_VAL_NONE
;
1680 padctl_pmc_writel(priv
, value
, PMC_UHSIC_SLEEP_CFG
);
1682 /* power down the line state detectors of the port */
1683 value
= padctl_pmc_readl(priv
, PMC_USB_AO
);
1684 value
|= STROBE_VAL_PD
| DATA0_VAL_PD
| DATA1_VAL_PD
;
1685 padctl_pmc_writel(priv
, value
, PMC_USB_AO
);
1687 /* clear alarm of the sleepwalk logic */
1688 value
= padctl_pmc_readl(priv
, PMC_UTMIP_UHSIC_TRIGGERS
);
1689 value
|= UHSIC_CLR_WAKE_ALARM
;
1690 padctl_pmc_writel(priv
, value
, PMC_UTMIP_UHSIC_TRIGGERS
);
1695 static int tegra210_usb3_set_lfps_detect(struct tegra_xusb_padctl
*padctl
,
1696 unsigned int index
, bool enable
)
1698 struct tegra_xusb_port
*port
;
1699 struct tegra_xusb_lane
*lane
;
1702 port
= tegra_xusb_find_port(padctl
, "usb3", index
);
1708 if (lane
->pad
== padctl
->pcie
)
1709 offset
= XUSB_PADCTL_UPHY_MISC_PAD_PX_CTL1(lane
->index
);
1711 offset
= XUSB_PADCTL_UPHY_MISC_PAD_S0_CTL1
;
1713 value
= padctl_readl(padctl
, offset
);
1715 value
&= ~((XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_IDLE_MODE_MASK
<<
1716 XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_IDLE_MODE_SHIFT
) |
1717 XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_TERM_EN
|
1718 XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_MODE_OVRD
);
1721 value
|= (XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_IDLE_MODE_VAL
<<
1722 XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_IDLE_MODE_SHIFT
) |
1723 XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_TERM_EN
|
1724 XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_MODE_OVRD
;
1727 padctl_writel(padctl
, value
, offset
);
1732 #define TEGRA210_LANE(_name, _offset, _shift, _mask, _type) \
1735 .offset = _offset, \
1738 .num_funcs = ARRAY_SIZE(tegra210_##_type##_functions), \
1739 .funcs = tegra210_##_type##_functions, \
1742 static const char *tegra210_usb2_functions
[] = {
1748 static const struct tegra_xusb_lane_soc tegra210_usb2_lanes
[] = {
1749 TEGRA210_LANE("usb2-0", 0x004, 0, 0x3, usb2
),
1750 TEGRA210_LANE("usb2-1", 0x004, 2, 0x3, usb2
),
1751 TEGRA210_LANE("usb2-2", 0x004, 4, 0x3, usb2
),
1752 TEGRA210_LANE("usb2-3", 0x004, 6, 0x3, usb2
),
1755 static struct tegra_xusb_lane
*
1756 tegra210_usb2_lane_probe(struct tegra_xusb_pad
*pad
, struct device_node
*np
,
1759 struct tegra_xusb_usb2_lane
*usb2
;
1762 usb2
= kzalloc(sizeof(*usb2
), GFP_KERNEL
);
1764 return ERR_PTR(-ENOMEM
);
1766 INIT_LIST_HEAD(&usb2
->base
.list
);
1767 usb2
->base
.soc
= &pad
->soc
->lanes
[index
];
1768 usb2
->base
.index
= index
;
1769 usb2
->base
.pad
= pad
;
1772 err
= tegra_xusb_lane_parse_dt(&usb2
->base
, np
);
1775 return ERR_PTR(err
);
1781 static void tegra210_usb2_lane_remove(struct tegra_xusb_lane
*lane
)
1783 struct tegra_xusb_usb2_lane
*usb2
= to_usb2_lane(lane
);
1788 static const struct tegra_xusb_lane_ops tegra210_usb2_lane_ops
= {
1789 .probe
= tegra210_usb2_lane_probe
,
1790 .remove
= tegra210_usb2_lane_remove
,
1791 .enable_phy_sleepwalk
= tegra210_pmc_utmi_enable_phy_sleepwalk
,
1792 .disable_phy_sleepwalk
= tegra210_pmc_utmi_disable_phy_sleepwalk
,
1793 .enable_phy_wake
= tegra210_utmi_enable_phy_wake
,
1794 .disable_phy_wake
= tegra210_utmi_disable_phy_wake
,
1795 .remote_wake_detected
= tegra210_utmi_phy_remote_wake_detected
,
1798 static int tegra210_usb2_phy_init(struct phy
*phy
)
1800 struct tegra_xusb_lane
*lane
= phy_get_drvdata(phy
);
1801 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
1802 unsigned int index
= lane
->index
;
1803 struct tegra_xusb_usb2_port
*port
;
1807 port
= tegra_xusb_find_usb2_port(padctl
, index
);
1809 dev_err(&phy
->dev
, "no port found for USB2 lane %u\n", index
);
1813 if (port
->supply
&& port
->mode
== USB_DR_MODE_HOST
) {
1814 err
= regulator_enable(port
->supply
);
1819 mutex_lock(&padctl
->lock
);
1821 value
= padctl_readl(padctl
, XUSB_PADCTL_USB2_PAD_MUX
);
1822 value
&= ~(XUSB_PADCTL_USB2_PAD_MUX_USB2_BIAS_PAD_MASK
<<
1823 XUSB_PADCTL_USB2_PAD_MUX_USB2_BIAS_PAD_SHIFT
);
1824 value
|= XUSB_PADCTL_USB2_PAD_MUX_USB2_BIAS_PAD_XUSB
<<
1825 XUSB_PADCTL_USB2_PAD_MUX_USB2_BIAS_PAD_SHIFT
;
1826 padctl_writel(padctl
, value
, XUSB_PADCTL_USB2_PAD_MUX
);
1828 mutex_unlock(&padctl
->lock
);
1833 static int tegra210_usb2_phy_exit(struct phy
*phy
)
1835 struct tegra_xusb_lane
*lane
= phy_get_drvdata(phy
);
1836 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
1837 struct tegra_xusb_usb2_port
*port
;
1840 port
= tegra_xusb_find_usb2_port(padctl
, lane
->index
);
1842 dev_err(&phy
->dev
, "no port found for USB2 lane %u\n", lane
->index
);
1846 if (port
->supply
&& port
->mode
== USB_DR_MODE_HOST
) {
1847 err
= regulator_disable(port
->supply
);
1855 static int tegra210_xusb_padctl_vbus_override(struct tegra_xusb_padctl
*padctl
,
1860 dev_dbg(padctl
->dev
, "%s vbus override\n", status
? "set" : "clear");
1862 value
= padctl_readl(padctl
, XUSB_PADCTL_USB2_VBUS_ID
);
1865 value
|= XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_VBUS_ON
;
1866 value
&= ~(XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_MASK
<<
1867 XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_SHIFT
);
1868 value
|= XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_FLOATING
<<
1869 XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_SHIFT
;
1871 value
&= ~XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_VBUS_ON
;
1874 padctl_writel(padctl
, value
, XUSB_PADCTL_USB2_VBUS_ID
);
1879 static int tegra210_xusb_padctl_id_override(struct tegra_xusb_padctl
*padctl
,
1884 dev_dbg(padctl
->dev
, "%s id override\n", status
? "set" : "clear");
1886 value
= padctl_readl(padctl
, XUSB_PADCTL_USB2_VBUS_ID
);
1889 if (value
& XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_VBUS_ON
) {
1890 value
&= ~XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_VBUS_ON
;
1891 padctl_writel(padctl
, value
, XUSB_PADCTL_USB2_VBUS_ID
);
1892 usleep_range(1000, 2000);
1894 value
= padctl_readl(padctl
, XUSB_PADCTL_USB2_VBUS_ID
);
1897 value
&= ~(XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_MASK
<<
1898 XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_SHIFT
);
1899 value
|= XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_GROUNDED
<<
1900 XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_SHIFT
;
1902 value
&= ~(XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_MASK
<<
1903 XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_SHIFT
);
1904 value
|= XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_FLOATING
<<
1905 XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_SHIFT
;
1908 padctl_writel(padctl
, value
, XUSB_PADCTL_USB2_VBUS_ID
);
1913 static int tegra210_usb2_phy_set_mode(struct phy
*phy
, enum phy_mode mode
,
1916 struct tegra_xusb_lane
*lane
= phy_get_drvdata(phy
);
1917 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
1918 struct tegra_xusb_usb2_port
*port
= tegra_xusb_find_usb2_port(padctl
,
1922 mutex_lock(&padctl
->lock
);
1924 dev_dbg(&port
->base
.dev
, "%s: mode %d", __func__
, mode
);
1926 if (mode
== PHY_MODE_USB_OTG
) {
1927 if (submode
== USB_ROLE_HOST
) {
1928 tegra210_xusb_padctl_id_override(padctl
, true);
1930 err
= regulator_enable(port
->supply
);
1931 } else if (submode
== USB_ROLE_DEVICE
) {
1932 tegra210_xusb_padctl_vbus_override(padctl
, true);
1933 } else if (submode
== USB_ROLE_NONE
) {
1935 * When port is peripheral only or role transitions to
1936 * USB_ROLE_NONE from USB_ROLE_DEVICE, regulator is not
1939 if (regulator_is_enabled(port
->supply
))
1940 regulator_disable(port
->supply
);
1942 tegra210_xusb_padctl_id_override(padctl
, false);
1943 tegra210_xusb_padctl_vbus_override(padctl
, false);
1947 mutex_unlock(&padctl
->lock
);
1952 static int tegra210_usb2_phy_power_on(struct phy
*phy
)
1954 struct tegra_xusb_lane
*lane
= phy_get_drvdata(phy
);
1955 struct tegra_xusb_usb2_lane
*usb2
= to_usb2_lane(lane
);
1956 struct tegra_xusb_usb2_pad
*pad
= to_usb2_pad(lane
->pad
);
1957 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
1958 struct tegra210_xusb_padctl
*priv
;
1959 struct tegra_xusb_usb2_port
*port
;
1960 unsigned int index
= lane
->index
;
1964 port
= tegra_xusb_find_usb2_port(padctl
, index
);
1966 dev_err(&phy
->dev
, "no port found for USB2 lane %u\n", index
);
1970 priv
= to_tegra210_xusb_padctl(padctl
);
1972 mutex_lock(&padctl
->lock
);
1974 if (port
->usb3_port_fake
!= -1) {
1975 value
= padctl_readl(padctl
, XUSB_PADCTL_SS_PORT_MAP
);
1976 value
&= ~XUSB_PADCTL_SS_PORT_MAP_PORTX_MAP_MASK(
1977 port
->usb3_port_fake
);
1978 value
|= XUSB_PADCTL_SS_PORT_MAP_PORTX_MAP(
1979 port
->usb3_port_fake
, index
);
1980 padctl_writel(padctl
, value
, XUSB_PADCTL_SS_PORT_MAP
);
1982 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM1
);
1983 value
&= ~XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_VCORE_DOWN(
1984 port
->usb3_port_fake
);
1985 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM1
);
1987 usleep_range(100, 200);
1989 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM1
);
1990 value
&= ~XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN_EARLY(
1991 port
->usb3_port_fake
);
1992 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM1
);
1994 usleep_range(100, 200);
1996 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM1
);
1997 value
&= ~XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN(
1998 port
->usb3_port_fake
);
1999 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM1
);
2002 value
= padctl_readl(padctl
, XUSB_PADCTL_USB2_BIAS_PAD_CTL0
);
2003 value
&= ~((XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_SQUELCH_LEVEL_MASK
<<
2004 XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_SQUELCH_LEVEL_SHIFT
) |
2005 (XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_DISCON_LEVEL_MASK
<<
2006 XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_DISCON_LEVEL_SHIFT
));
2007 value
|= (XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_DISCON_LEVEL_VAL
<<
2008 XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_DISCON_LEVEL_SHIFT
);
2010 if (tegra_sku_info
.revision
< TEGRA_REVISION_A02
)
2012 (XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_SQUELCH_LEVEL_VAL
<<
2013 XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_SQUELCH_LEVEL_SHIFT
);
2015 padctl_writel(padctl
, value
, XUSB_PADCTL_USB2_BIAS_PAD_CTL0
);
2017 value
= padctl_readl(padctl
, XUSB_PADCTL_USB2_PORT_CAP
);
2018 value
&= ~XUSB_PADCTL_USB2_PORT_CAP_PORTX_CAP_MASK(index
);
2019 if (port
->mode
== USB_DR_MODE_UNKNOWN
)
2020 value
|= XUSB_PADCTL_USB2_PORT_CAP_PORTX_CAP_DISABLED(index
);
2021 else if (port
->mode
== USB_DR_MODE_PERIPHERAL
)
2022 value
|= XUSB_PADCTL_USB2_PORT_CAP_PORTX_CAP_DEVICE(index
);
2023 else if (port
->mode
== USB_DR_MODE_HOST
)
2024 value
|= XUSB_PADCTL_USB2_PORT_CAP_PORTX_CAP_HOST(index
);
2025 else if (port
->mode
== USB_DR_MODE_OTG
)
2026 value
|= XUSB_PADCTL_USB2_PORT_CAP_PORTX_CAP_OTG(index
);
2027 padctl_writel(padctl
, value
, XUSB_PADCTL_USB2_PORT_CAP
);
2029 value
= padctl_readl(padctl
, XUSB_PADCTL_USB2_OTG_PADX_CTL0(index
));
2030 value
&= ~((XUSB_PADCTL_USB2_OTG_PAD_CTL0_HS_CURR_LEVEL_MASK
<<
2031 XUSB_PADCTL_USB2_OTG_PAD_CTL0_HS_CURR_LEVEL_SHIFT
) |
2032 XUSB_PADCTL_USB2_OTG_PAD_CTL0_PD
|
2033 XUSB_PADCTL_USB2_OTG_PAD_CTL0_PD2
|
2034 XUSB_PADCTL_USB2_OTG_PAD_CTL0_PD_ZI
);
2035 value
|= (priv
->fuse
.hs_curr_level
[index
] +
2036 usb2
->hs_curr_level_offset
) <<
2037 XUSB_PADCTL_USB2_OTG_PAD_CTL0_HS_CURR_LEVEL_SHIFT
;
2038 padctl_writel(padctl
, value
, XUSB_PADCTL_USB2_OTG_PADX_CTL0(index
));
2040 value
= padctl_readl(padctl
, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index
));
2041 value
&= ~((XUSB_PADCTL_USB2_OTG_PAD_CTL1_TERM_RANGE_ADJ_MASK
<<
2042 XUSB_PADCTL_USB2_OTG_PAD_CTL1_TERM_RANGE_ADJ_SHIFT
) |
2043 (XUSB_PADCTL_USB2_OTG_PAD_CTL1_RPD_CTRL_MASK
<<
2044 XUSB_PADCTL_USB2_OTG_PAD_CTL1_RPD_CTRL_SHIFT
) |
2045 XUSB_PADCTL_USB2_OTG_PAD_CTL1_PD_DR
|
2046 XUSB_PADCTL_USB2_OTG_PAD_CTL1_PD_CHRP_OVRD
|
2047 XUSB_PADCTL_USB2_OTG_PAD_CTL1_PD_DISC_OVRD
);
2048 value
|= (priv
->fuse
.hs_term_range_adj
<<
2049 XUSB_PADCTL_USB2_OTG_PAD_CTL1_TERM_RANGE_ADJ_SHIFT
) |
2050 (priv
->fuse
.rpd_ctrl
<<
2051 XUSB_PADCTL_USB2_OTG_PAD_CTL1_RPD_CTRL_SHIFT
);
2052 padctl_writel(padctl
, value
, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index
));
2054 value
= padctl_readl(padctl
,
2055 XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPADX_CTL1(index
));
2056 value
&= ~(XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL1_VREG_LEV_MASK
<<
2057 XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL1_VREG_LEV_SHIFT
);
2058 if (port
->mode
== USB_DR_MODE_HOST
)
2059 value
|= XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL1_VREG_FIX18
;
2062 XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL1_VREG_LEV_VAL
<<
2063 XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL1_VREG_LEV_SHIFT
;
2064 padctl_writel(padctl
, value
,
2065 XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPADX_CTL1(index
));
2067 if (pad
->enable
> 0) {
2069 mutex_unlock(&padctl
->lock
);
2073 err
= clk_prepare_enable(pad
->clk
);
2077 value
= padctl_readl(padctl
, XUSB_PADCTL_USB2_BIAS_PAD_CTL1
);
2078 value
&= ~((XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_START_TIMER_MASK
<<
2079 XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_START_TIMER_SHIFT
) |
2080 (XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_DONE_RESET_TIMER_MASK
<<
2081 XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_DONE_RESET_TIMER_SHIFT
));
2082 value
|= (XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_START_TIMER_VAL
<<
2083 XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_START_TIMER_SHIFT
) |
2084 (XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_DONE_RESET_TIMER_VAL
<<
2085 XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_DONE_RESET_TIMER_SHIFT
);
2086 padctl_writel(padctl
, value
, XUSB_PADCTL_USB2_BIAS_PAD_CTL1
);
2088 value
= padctl_readl(padctl
, XUSB_PADCTL_USB2_BIAS_PAD_CTL0
);
2089 value
&= ~XUSB_PADCTL_USB2_BIAS_PAD_CTL0_PD
;
2090 padctl_writel(padctl
, value
, XUSB_PADCTL_USB2_BIAS_PAD_CTL0
);
2094 value
= padctl_readl(padctl
, XUSB_PADCTL_USB2_BIAS_PAD_CTL1
);
2095 value
&= ~XUSB_PADCTL_USB2_BIAS_PAD_CTL1_PD_TRK
;
2096 padctl_writel(padctl
, value
, XUSB_PADCTL_USB2_BIAS_PAD_CTL1
);
2100 clk_disable_unprepare(pad
->clk
);
2103 mutex_unlock(&padctl
->lock
);
2108 mutex_unlock(&padctl
->lock
);
2112 static int tegra210_usb2_phy_power_off(struct phy
*phy
)
2114 struct tegra_xusb_lane
*lane
= phy_get_drvdata(phy
);
2115 struct tegra_xusb_usb2_pad
*pad
= to_usb2_pad(lane
->pad
);
2116 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
2117 struct tegra_xusb_usb2_port
*port
;
2120 port
= tegra_xusb_find_usb2_port(padctl
, lane
->index
);
2122 dev_err(&phy
->dev
, "no port found for USB2 lane %u\n",
2127 mutex_lock(&padctl
->lock
);
2129 if (port
->usb3_port_fake
!= -1) {
2130 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM1
);
2131 value
|= XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN_EARLY(
2132 port
->usb3_port_fake
);
2133 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM1
);
2135 usleep_range(100, 200);
2137 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM1
);
2138 value
|= XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN(
2139 port
->usb3_port_fake
);
2140 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM1
);
2142 usleep_range(250, 350);
2144 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM1
);
2145 value
|= XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_VCORE_DOWN(
2146 port
->usb3_port_fake
);
2147 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM1
);
2149 value
= padctl_readl(padctl
, XUSB_PADCTL_SS_PORT_MAP
);
2150 value
|= XUSB_PADCTL_SS_PORT_MAP_PORTX_MAP(port
->usb3_port_fake
,
2151 XUSB_PADCTL_SS_PORT_MAP_PORT_DISABLED
);
2152 padctl_writel(padctl
, value
, XUSB_PADCTL_SS_PORT_MAP
);
2155 if (WARN_ON(pad
->enable
== 0))
2158 if (--pad
->enable
> 0)
2161 value
= padctl_readl(padctl
, XUSB_PADCTL_USB2_BIAS_PAD_CTL0
);
2162 value
|= XUSB_PADCTL_USB2_BIAS_PAD_CTL0_PD
;
2163 padctl_writel(padctl
, value
, XUSB_PADCTL_USB2_BIAS_PAD_CTL0
);
2166 mutex_unlock(&padctl
->lock
);
2170 static const struct phy_ops tegra210_usb2_phy_ops
= {
2171 .init
= tegra210_usb2_phy_init
,
2172 .exit
= tegra210_usb2_phy_exit
,
2173 .power_on
= tegra210_usb2_phy_power_on
,
2174 .power_off
= tegra210_usb2_phy_power_off
,
2175 .set_mode
= tegra210_usb2_phy_set_mode
,
2176 .owner
= THIS_MODULE
,
2179 static struct tegra_xusb_pad
*
2180 tegra210_usb2_pad_probe(struct tegra_xusb_padctl
*padctl
,
2181 const struct tegra_xusb_pad_soc
*soc
,
2182 struct device_node
*np
)
2184 struct tegra_xusb_usb2_pad
*usb2
;
2185 struct tegra_xusb_pad
*pad
;
2188 usb2
= kzalloc(sizeof(*usb2
), GFP_KERNEL
);
2190 return ERR_PTR(-ENOMEM
);
2193 pad
->ops
= &tegra210_usb2_lane_ops
;
2196 err
= tegra_xusb_pad_init(pad
, padctl
, np
);
2202 usb2
->clk
= devm_clk_get(&pad
->dev
, "trk");
2203 if (IS_ERR(usb2
->clk
)) {
2204 err
= PTR_ERR(usb2
->clk
);
2205 dev_err(&pad
->dev
, "failed to get trk clock: %d\n", err
);
2209 err
= tegra_xusb_pad_register(pad
, &tegra210_usb2_phy_ops
);
2213 dev_set_drvdata(&pad
->dev
, pad
);
2218 device_unregister(&pad
->dev
);
2220 return ERR_PTR(err
);
2223 static void tegra210_usb2_pad_remove(struct tegra_xusb_pad
*pad
)
2225 struct tegra_xusb_usb2_pad
*usb2
= to_usb2_pad(pad
);
2230 static const struct tegra_xusb_pad_ops tegra210_usb2_ops
= {
2231 .probe
= tegra210_usb2_pad_probe
,
2232 .remove
= tegra210_usb2_pad_remove
,
2235 static const struct tegra_xusb_pad_soc tegra210_usb2_pad
= {
2237 .num_lanes
= ARRAY_SIZE(tegra210_usb2_lanes
),
2238 .lanes
= tegra210_usb2_lanes
,
2239 .ops
= &tegra210_usb2_ops
,
2242 static const char *tegra210_hsic_functions
[] = {
2247 static const struct tegra_xusb_lane_soc tegra210_hsic_lanes
[] = {
2248 TEGRA210_LANE("hsic-0", 0x004, 14, 0x1, hsic
),
2251 static struct tegra_xusb_lane
*
2252 tegra210_hsic_lane_probe(struct tegra_xusb_pad
*pad
, struct device_node
*np
,
2255 struct tegra_xusb_hsic_lane
*hsic
;
2258 hsic
= kzalloc(sizeof(*hsic
), GFP_KERNEL
);
2260 return ERR_PTR(-ENOMEM
);
2262 INIT_LIST_HEAD(&hsic
->base
.list
);
2263 hsic
->base
.soc
= &pad
->soc
->lanes
[index
];
2264 hsic
->base
.index
= index
;
2265 hsic
->base
.pad
= pad
;
2268 err
= tegra_xusb_lane_parse_dt(&hsic
->base
, np
);
2271 return ERR_PTR(err
);
2277 static void tegra210_hsic_lane_remove(struct tegra_xusb_lane
*lane
)
2279 struct tegra_xusb_hsic_lane
*hsic
= to_hsic_lane(lane
);
2284 static const struct tegra_xusb_lane_ops tegra210_hsic_lane_ops
= {
2285 .probe
= tegra210_hsic_lane_probe
,
2286 .remove
= tegra210_hsic_lane_remove
,
2287 .enable_phy_sleepwalk
= tegra210_pmc_hsic_enable_phy_sleepwalk
,
2288 .disable_phy_sleepwalk
= tegra210_pmc_hsic_disable_phy_sleepwalk
,
2289 .enable_phy_wake
= tegra210_hsic_enable_phy_wake
,
2290 .disable_phy_wake
= tegra210_hsic_disable_phy_wake
,
2291 .remote_wake_detected
= tegra210_hsic_phy_remote_wake_detected
,
2294 static int tegra210_hsic_phy_init(struct phy
*phy
)
2296 struct tegra_xusb_lane
*lane
= phy_get_drvdata(phy
);
2297 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
2300 value
= padctl_readl(padctl
, XUSB_PADCTL_USB2_PAD_MUX
);
2301 value
&= ~(XUSB_PADCTL_USB2_PAD_MUX_HSIC_PAD_TRK_MASK
<<
2302 XUSB_PADCTL_USB2_PAD_MUX_HSIC_PAD_TRK_SHIFT
);
2303 value
|= XUSB_PADCTL_USB2_PAD_MUX_HSIC_PAD_TRK_XUSB
<<
2304 XUSB_PADCTL_USB2_PAD_MUX_HSIC_PAD_TRK_SHIFT
;
2305 padctl_writel(padctl
, value
, XUSB_PADCTL_USB2_PAD_MUX
);
2310 static int tegra210_hsic_phy_exit(struct phy
*phy
)
2315 static int tegra210_hsic_phy_power_on(struct phy
*phy
)
2317 struct tegra_xusb_lane
*lane
= phy_get_drvdata(phy
);
2318 struct tegra_xusb_hsic_lane
*hsic
= to_hsic_lane(lane
);
2319 struct tegra_xusb_hsic_pad
*pad
= to_hsic_pad(lane
->pad
);
2320 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
2321 unsigned int index
= lane
->index
;
2325 err
= regulator_enable(pad
->supply
);
2329 padctl_writel(padctl
, hsic
->strobe_trim
,
2330 XUSB_PADCTL_HSIC_STRB_TRIM_CONTROL
);
2332 value
= padctl_readl(padctl
, XUSB_PADCTL_HSIC_PADX_CTL1(index
));
2333 value
&= ~(XUSB_PADCTL_HSIC_PAD_CTL1_TX_RTUNEP_MASK
<<
2334 XUSB_PADCTL_HSIC_PAD_CTL1_TX_RTUNEP_SHIFT
);
2335 value
|= (hsic
->tx_rtune_p
<<
2336 XUSB_PADCTL_HSIC_PAD_CTL1_TX_RTUNEP_SHIFT
);
2337 padctl_writel(padctl
, value
, XUSB_PADCTL_HSIC_PADX_CTL1(index
));
2339 value
= padctl_readl(padctl
, XUSB_PADCTL_HSIC_PADX_CTL2(index
));
2340 value
&= ~((XUSB_PADCTL_HSIC_PAD_CTL2_RX_STROBE_TRIM_MASK
<<
2341 XUSB_PADCTL_HSIC_PAD_CTL2_RX_STROBE_TRIM_SHIFT
) |
2342 (XUSB_PADCTL_HSIC_PAD_CTL2_RX_DATA_TRIM_MASK
<<
2343 XUSB_PADCTL_HSIC_PAD_CTL2_RX_DATA_TRIM_SHIFT
));
2344 value
|= (hsic
->rx_strobe_trim
<<
2345 XUSB_PADCTL_HSIC_PAD_CTL2_RX_STROBE_TRIM_SHIFT
) |
2346 (hsic
->rx_data_trim
<<
2347 XUSB_PADCTL_HSIC_PAD_CTL2_RX_DATA_TRIM_SHIFT
);
2348 padctl_writel(padctl
, value
, XUSB_PADCTL_HSIC_PADX_CTL2(index
));
2350 value
= padctl_readl(padctl
, XUSB_PADCTL_HSIC_PADX_CTL0(index
));
2351 value
&= ~(XUSB_PADCTL_HSIC_PAD_CTL0_RPU_DATA0
|
2352 XUSB_PADCTL_HSIC_PAD_CTL0_RPU_DATA1
|
2353 XUSB_PADCTL_HSIC_PAD_CTL0_RPU_STROBE
|
2354 XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_DATA0
|
2355 XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_DATA1
|
2356 XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_STROBE
|
2357 XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_DATA0
|
2358 XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_DATA1
|
2359 XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_STROBE
|
2360 XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_DATA0
|
2361 XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_DATA1
|
2362 XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_STROBE
);
2363 value
|= XUSB_PADCTL_HSIC_PAD_CTL0_RPD_DATA0
|
2364 XUSB_PADCTL_HSIC_PAD_CTL0_RPD_DATA1
|
2365 XUSB_PADCTL_HSIC_PAD_CTL0_RPD_STROBE
;
2366 padctl_writel(padctl
, value
, XUSB_PADCTL_HSIC_PADX_CTL0(index
));
2368 err
= clk_prepare_enable(pad
->clk
);
2372 value
= padctl_readl(padctl
, XUSB_PADCTL_HSIC_PAD_TRK_CTL
);
2373 value
&= ~((XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_START_TIMER_MASK
<<
2374 XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_START_TIMER_SHIFT
) |
2375 (XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_DONE_RESET_TIMER_MASK
<<
2376 XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_DONE_RESET_TIMER_SHIFT
));
2377 value
|= (XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_START_TIMER_VAL
<<
2378 XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_START_TIMER_SHIFT
) |
2379 (XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_DONE_RESET_TIMER_VAL
<<
2380 XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_DONE_RESET_TIMER_SHIFT
);
2381 padctl_writel(padctl
, value
, XUSB_PADCTL_HSIC_PAD_TRK_CTL
);
2385 value
= padctl_readl(padctl
, XUSB_PADCTL_HSIC_PAD_TRK_CTL
);
2386 value
&= ~XUSB_PADCTL_HSIC_PAD_TRK_CTL_PD_TRK
;
2387 padctl_writel(padctl
, value
, XUSB_PADCTL_HSIC_PAD_TRK_CTL
);
2391 clk_disable_unprepare(pad
->clk
);
2396 regulator_disable(pad
->supply
);
2400 static int tegra210_hsic_phy_power_off(struct phy
*phy
)
2402 struct tegra_xusb_lane
*lane
= phy_get_drvdata(phy
);
2403 struct tegra_xusb_hsic_pad
*pad
= to_hsic_pad(lane
->pad
);
2404 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
2405 unsigned int index
= lane
->index
;
2408 value
= padctl_readl(padctl
, XUSB_PADCTL_HSIC_PADX_CTL0(index
));
2409 value
|= XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_DATA0
|
2410 XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_DATA1
|
2411 XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_STROBE
|
2412 XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_DATA0
|
2413 XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_DATA1
|
2414 XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_STROBE
|
2415 XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_DATA0
|
2416 XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_DATA1
|
2417 XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_STROBE
;
2418 padctl_writel(padctl
, value
, XUSB_PADCTL_HSIC_PADX_CTL1(index
));
2420 regulator_disable(pad
->supply
);
2425 static const struct phy_ops tegra210_hsic_phy_ops
= {
2426 .init
= tegra210_hsic_phy_init
,
2427 .exit
= tegra210_hsic_phy_exit
,
2428 .power_on
= tegra210_hsic_phy_power_on
,
2429 .power_off
= tegra210_hsic_phy_power_off
,
2430 .owner
= THIS_MODULE
,
2433 static struct tegra_xusb_pad
*
2434 tegra210_hsic_pad_probe(struct tegra_xusb_padctl
*padctl
,
2435 const struct tegra_xusb_pad_soc
*soc
,
2436 struct device_node
*np
)
2438 struct tegra_xusb_hsic_pad
*hsic
;
2439 struct tegra_xusb_pad
*pad
;
2442 hsic
= kzalloc(sizeof(*hsic
), GFP_KERNEL
);
2444 return ERR_PTR(-ENOMEM
);
2447 pad
->ops
= &tegra210_hsic_lane_ops
;
2450 err
= tegra_xusb_pad_init(pad
, padctl
, np
);
2456 hsic
->clk
= devm_clk_get(&pad
->dev
, "trk");
2457 if (IS_ERR(hsic
->clk
)) {
2458 err
= PTR_ERR(hsic
->clk
);
2459 dev_err(&pad
->dev
, "failed to get trk clock: %d\n", err
);
2463 err
= tegra_xusb_pad_register(pad
, &tegra210_hsic_phy_ops
);
2467 dev_set_drvdata(&pad
->dev
, pad
);
2472 device_unregister(&pad
->dev
);
2474 return ERR_PTR(err
);
2477 static void tegra210_hsic_pad_remove(struct tegra_xusb_pad
*pad
)
2479 struct tegra_xusb_hsic_pad
*hsic
= to_hsic_pad(pad
);
2484 static const struct tegra_xusb_pad_ops tegra210_hsic_ops
= {
2485 .probe
= tegra210_hsic_pad_probe
,
2486 .remove
= tegra210_hsic_pad_remove
,
2489 static const struct tegra_xusb_pad_soc tegra210_hsic_pad
= {
2491 .num_lanes
= ARRAY_SIZE(tegra210_hsic_lanes
),
2492 .lanes
= tegra210_hsic_lanes
,
2493 .ops
= &tegra210_hsic_ops
,
2496 static void tegra210_uphy_lane_iddq_enable(struct tegra_xusb_lane
*lane
)
2498 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
2501 value
= padctl_readl(padctl
, lane
->soc
->regs
.misc_ctl2
);
2502 value
|= XUSB_PADCTL_UPHY_MISC_PAD_CTL2_TX_IDDQ_OVRD
;
2503 value
|= XUSB_PADCTL_UPHY_MISC_PAD_CTL2_RX_IDDQ_OVRD
;
2504 value
|= XUSB_PADCTL_UPHY_MISC_PAD_CTL2_TX_PWR_OVRD
;
2505 value
|= XUSB_PADCTL_UPHY_MISC_PAD_CTL2_RX_PWR_OVRD
;
2506 value
|= XUSB_PADCTL_UPHY_MISC_PAD_CTL2_TX_IDDQ
;
2507 value
&= ~XUSB_PADCTL_UPHY_MISC_PAD_CTL2_TX_SLEEP_MASK
;
2508 value
|= XUSB_PADCTL_UPHY_MISC_PAD_CTL2_TX_SLEEP_VAL
;
2509 value
|= XUSB_PADCTL_UPHY_MISC_PAD_CTL2_RX_IDDQ
;
2510 value
&= ~XUSB_PADCTL_UPHY_MISC_PAD_CTL2_RX_SLEEP_MASK
;
2511 value
|= XUSB_PADCTL_UPHY_MISC_PAD_CTL2_RX_SLEEP_VAL
;
2512 padctl_writel(padctl
, value
, lane
->soc
->regs
.misc_ctl2
);
2515 static void tegra210_uphy_lane_iddq_disable(struct tegra_xusb_lane
*lane
)
2517 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
2520 value
= padctl_readl(padctl
, lane
->soc
->regs
.misc_ctl2
);
2521 value
&= ~XUSB_PADCTL_UPHY_MISC_PAD_CTL2_TX_IDDQ_OVRD
;
2522 value
&= ~XUSB_PADCTL_UPHY_MISC_PAD_CTL2_RX_IDDQ_OVRD
;
2523 value
&= ~XUSB_PADCTL_UPHY_MISC_PAD_CTL2_TX_PWR_OVRD
;
2524 value
&= ~XUSB_PADCTL_UPHY_MISC_PAD_CTL2_RX_PWR_OVRD
;
2525 value
|= XUSB_PADCTL_UPHY_MISC_PAD_CTL2_TX_IDDQ
;
2526 value
&= ~XUSB_PADCTL_UPHY_MISC_PAD_CTL2_TX_SLEEP_MASK
;
2527 value
|= XUSB_PADCTL_UPHY_MISC_PAD_CTL2_TX_SLEEP_VAL
;
2528 value
|= XUSB_PADCTL_UPHY_MISC_PAD_CTL2_RX_IDDQ
;
2529 value
&= ~XUSB_PADCTL_UPHY_MISC_PAD_CTL2_RX_SLEEP_MASK
;
2530 value
|= XUSB_PADCTL_UPHY_MISC_PAD_CTL2_RX_SLEEP_VAL
;
2531 padctl_writel(padctl
, value
, lane
->soc
->regs
.misc_ctl2
);
2534 #define TEGRA210_UPHY_LANE(_name, _offset, _shift, _mask, _type, _misc) \
2537 .offset = _offset, \
2540 .num_funcs = ARRAY_SIZE(tegra210_##_type##_functions), \
2541 .funcs = tegra210_##_type##_functions, \
2542 .regs.misc_ctl2 = _misc, \
2545 static const char *tegra210_pcie_functions
[] = {
2552 static const struct tegra_xusb_lane_soc tegra210_pcie_lanes
[] = {
2553 TEGRA210_UPHY_LANE("pcie-0", 0x028, 12, 0x3, pcie
, XUSB_PADCTL_UPHY_MISC_PAD_PX_CTL2(0)),
2554 TEGRA210_UPHY_LANE("pcie-1", 0x028, 14, 0x3, pcie
, XUSB_PADCTL_UPHY_MISC_PAD_PX_CTL2(1)),
2555 TEGRA210_UPHY_LANE("pcie-2", 0x028, 16, 0x3, pcie
, XUSB_PADCTL_UPHY_MISC_PAD_PX_CTL2(2)),
2556 TEGRA210_UPHY_LANE("pcie-3", 0x028, 18, 0x3, pcie
, XUSB_PADCTL_UPHY_MISC_PAD_PX_CTL2(3)),
2557 TEGRA210_UPHY_LANE("pcie-4", 0x028, 20, 0x3, pcie
, XUSB_PADCTL_UPHY_MISC_PAD_PX_CTL2(4)),
2558 TEGRA210_UPHY_LANE("pcie-5", 0x028, 22, 0x3, pcie
, XUSB_PADCTL_UPHY_MISC_PAD_PX_CTL2(5)),
2559 TEGRA210_UPHY_LANE("pcie-6", 0x028, 24, 0x3, pcie
, XUSB_PADCTL_UPHY_MISC_PAD_PX_CTL2(6)),
2562 static struct tegra_xusb_usb3_port
*
2563 tegra210_lane_to_usb3_port(struct tegra_xusb_lane
*lane
)
2567 if (!lane
|| !lane
->pad
|| !lane
->pad
->padctl
)
2570 port
= tegra210_usb3_lane_map(lane
);
2574 return tegra_xusb_find_usb3_port(lane
->pad
->padctl
, port
);
2577 static int tegra210_usb3_phy_power_on(struct phy
*phy
)
2579 struct device
*dev
= &phy
->dev
;
2580 struct tegra_xusb_lane
*lane
= phy_get_drvdata(phy
);
2581 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
2582 struct tegra_xusb_usb3_port
*usb3
= tegra210_lane_to_usb3_port(lane
);
2587 dev_err(dev
, "no USB3 port found for lane %u\n", lane
->index
);
2591 index
= usb3
->base
.index
;
2593 value
= padctl_readl(padctl
, XUSB_PADCTL_SS_PORT_MAP
);
2595 if (!usb3
->internal
)
2596 value
&= ~XUSB_PADCTL_SS_PORT_MAP_PORTX_INTERNAL(index
);
2598 value
|= XUSB_PADCTL_SS_PORT_MAP_PORTX_INTERNAL(index
);
2600 value
&= ~XUSB_PADCTL_SS_PORT_MAP_PORTX_MAP_MASK(index
);
2601 value
|= XUSB_PADCTL_SS_PORT_MAP_PORTX_MAP(index
, usb3
->port
);
2602 padctl_writel(padctl
, value
, XUSB_PADCTL_SS_PORT_MAP
);
2604 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_USB3_PADX_ECTL1(index
));
2605 value
&= ~(XUSB_PADCTL_UPHY_USB3_PAD_ECTL1_TX_TERM_CTRL_MASK
<<
2606 XUSB_PADCTL_UPHY_USB3_PAD_ECTL1_TX_TERM_CTRL_SHIFT
);
2607 value
|= XUSB_PADCTL_UPHY_USB3_PAD_ECTL1_TX_TERM_CTRL_VAL
<<
2608 XUSB_PADCTL_UPHY_USB3_PAD_ECTL1_TX_TERM_CTRL_SHIFT
;
2609 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_USB3_PADX_ECTL1(index
));
2611 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_USB3_PADX_ECTL2(index
));
2612 value
&= ~(XUSB_PADCTL_UPHY_USB3_PAD_ECTL2_RX_CTLE_MASK
<<
2613 XUSB_PADCTL_UPHY_USB3_PAD_ECTL2_RX_CTLE_SHIFT
);
2614 value
|= XUSB_PADCTL_UPHY_USB3_PAD_ECTL2_RX_CTLE_VAL
<<
2615 XUSB_PADCTL_UPHY_USB3_PAD_ECTL2_RX_CTLE_SHIFT
;
2616 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_USB3_PADX_ECTL2(index
));
2618 padctl_writel(padctl
, XUSB_PADCTL_UPHY_USB3_PAD_ECTL3_RX_DFE_VAL
,
2619 XUSB_PADCTL_UPHY_USB3_PADX_ECTL3(index
));
2621 value
= padctl_readl(padctl
, XUSB_PADCTL_UPHY_USB3_PADX_ECTL4(index
));
2622 value
&= ~(XUSB_PADCTL_UPHY_USB3_PAD_ECTL4_RX_CDR_CTRL_MASK
<<
2623 XUSB_PADCTL_UPHY_USB3_PAD_ECTL4_RX_CDR_CTRL_SHIFT
);
2624 value
|= XUSB_PADCTL_UPHY_USB3_PAD_ECTL4_RX_CDR_CTRL_VAL
<<
2625 XUSB_PADCTL_UPHY_USB3_PAD_ECTL4_RX_CDR_CTRL_SHIFT
;
2626 padctl_writel(padctl
, value
, XUSB_PADCTL_UPHY_USB3_PADX_ECTL4(index
));
2628 padctl_writel(padctl
, XUSB_PADCTL_UPHY_USB3_PAD_ECTL6_RX_EQ_CTRL_H_VAL
,
2629 XUSB_PADCTL_UPHY_USB3_PADX_ECTL6(index
));
2631 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM1
);
2632 value
&= ~XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_VCORE_DOWN(index
);
2633 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM1
);
2635 usleep_range(100, 200);
2637 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM1
);
2638 value
&= ~XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN_EARLY(index
);
2639 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM1
);
2641 usleep_range(100, 200);
2643 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM1
);
2644 value
&= ~XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN(index
);
2645 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM1
);
2650 static int tegra210_usb3_phy_power_off(struct phy
*phy
)
2652 struct device
*dev
= &phy
->dev
;
2653 struct tegra_xusb_lane
*lane
= phy_get_drvdata(phy
);
2654 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
2655 struct tegra_xusb_usb3_port
*usb3
= tegra210_lane_to_usb3_port(lane
);
2660 dev_err(dev
, "no USB3 port found for lane %u\n", lane
->index
);
2664 index
= usb3
->base
.index
;
2666 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM1
);
2667 value
|= XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN_EARLY(index
);
2668 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM1
);
2670 usleep_range(100, 200);
2672 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM1
);
2673 value
|= XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN(index
);
2674 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM1
);
2676 usleep_range(250, 350);
2678 value
= padctl_readl(padctl
, XUSB_PADCTL_ELPG_PROGRAM1
);
2679 value
|= XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_VCORE_DOWN(index
);
2680 padctl_writel(padctl
, value
, XUSB_PADCTL_ELPG_PROGRAM1
);
2684 static struct tegra_xusb_lane
*
2685 tegra210_pcie_lane_probe(struct tegra_xusb_pad
*pad
, struct device_node
*np
,
2688 struct tegra_xusb_pcie_lane
*pcie
;
2691 pcie
= kzalloc(sizeof(*pcie
), GFP_KERNEL
);
2693 return ERR_PTR(-ENOMEM
);
2695 INIT_LIST_HEAD(&pcie
->base
.list
);
2696 pcie
->base
.soc
= &pad
->soc
->lanes
[index
];
2697 pcie
->base
.index
= index
;
2698 pcie
->base
.pad
= pad
;
2701 err
= tegra_xusb_lane_parse_dt(&pcie
->base
, np
);
2704 return ERR_PTR(err
);
2710 static void tegra210_pcie_lane_remove(struct tegra_xusb_lane
*lane
)
2712 struct tegra_xusb_pcie_lane
*pcie
= to_pcie_lane(lane
);
2717 static const struct tegra_xusb_lane_ops tegra210_pcie_lane_ops
= {
2718 .probe
= tegra210_pcie_lane_probe
,
2719 .remove
= tegra210_pcie_lane_remove
,
2720 .iddq_enable
= tegra210_uphy_lane_iddq_enable
,
2721 .iddq_disable
= tegra210_uphy_lane_iddq_disable
,
2722 .enable_phy_sleepwalk
= tegra210_usb3_enable_phy_sleepwalk
,
2723 .disable_phy_sleepwalk
= tegra210_usb3_disable_phy_sleepwalk
,
2724 .enable_phy_wake
= tegra210_usb3_enable_phy_wake
,
2725 .disable_phy_wake
= tegra210_usb3_disable_phy_wake
,
2726 .remote_wake_detected
= tegra210_usb3_phy_remote_wake_detected
,
2729 static int tegra210_pcie_phy_init(struct phy
*phy
)
2731 struct tegra_xusb_lane
*lane
= phy_get_drvdata(phy
);
2732 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
2734 mutex_lock(&padctl
->lock
);
2736 tegra210_uphy_init(padctl
);
2738 mutex_unlock(&padctl
->lock
);
2743 static int tegra210_pcie_phy_power_on(struct phy
*phy
)
2745 struct tegra_xusb_lane
*lane
= phy_get_drvdata(phy
);
2746 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
2749 mutex_lock(&padctl
->lock
);
2751 if (tegra_xusb_lane_check(lane
, "usb3-ss"))
2752 err
= tegra210_usb3_phy_power_on(phy
);
2754 mutex_unlock(&padctl
->lock
);
2758 static int tegra210_pcie_phy_power_off(struct phy
*phy
)
2760 struct tegra_xusb_lane
*lane
= phy_get_drvdata(phy
);
2761 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
2764 mutex_lock(&padctl
->lock
);
2766 if (tegra_xusb_lane_check(lane
, "usb3-ss"))
2767 err
= tegra210_usb3_phy_power_off(phy
);
2769 mutex_unlock(&padctl
->lock
);
2773 static const struct phy_ops tegra210_pcie_phy_ops
= {
2774 .init
= tegra210_pcie_phy_init
,
2775 .power_on
= tegra210_pcie_phy_power_on
,
2776 .power_off
= tegra210_pcie_phy_power_off
,
2777 .owner
= THIS_MODULE
,
2780 static struct tegra_xusb_pad
*
2781 tegra210_pcie_pad_probe(struct tegra_xusb_padctl
*padctl
,
2782 const struct tegra_xusb_pad_soc
*soc
,
2783 struct device_node
*np
)
2785 struct tegra_xusb_pcie_pad
*pcie
;
2786 struct tegra_xusb_pad
*pad
;
2789 pcie
= kzalloc(sizeof(*pcie
), GFP_KERNEL
);
2791 return ERR_PTR(-ENOMEM
);
2794 pad
->ops
= &tegra210_pcie_lane_ops
;
2797 err
= tegra_xusb_pad_init(pad
, padctl
, np
);
2803 pcie
->pll
= devm_clk_get(&pad
->dev
, "pll");
2804 if (IS_ERR(pcie
->pll
)) {
2805 err
= PTR_ERR(pcie
->pll
);
2806 dev_err(&pad
->dev
, "failed to get PLL: %d\n", err
);
2810 pcie
->rst
= devm_reset_control_get(&pad
->dev
, "phy");
2811 if (IS_ERR(pcie
->rst
)) {
2812 err
= PTR_ERR(pcie
->rst
);
2813 dev_err(&pad
->dev
, "failed to get PCIe pad reset: %d\n", err
);
2817 err
= tegra_xusb_pad_register(pad
, &tegra210_pcie_phy_ops
);
2821 dev_set_drvdata(&pad
->dev
, pad
);
2826 device_unregister(&pad
->dev
);
2828 return ERR_PTR(err
);
2831 static void tegra210_pcie_pad_remove(struct tegra_xusb_pad
*pad
)
2833 struct tegra_xusb_pcie_pad
*pcie
= to_pcie_pad(pad
);
2838 static const struct tegra_xusb_pad_ops tegra210_pcie_ops
= {
2839 .probe
= tegra210_pcie_pad_probe
,
2840 .remove
= tegra210_pcie_pad_remove
,
2843 static const struct tegra_xusb_pad_soc tegra210_pcie_pad
= {
2845 .num_lanes
= ARRAY_SIZE(tegra210_pcie_lanes
),
2846 .lanes
= tegra210_pcie_lanes
,
2847 .ops
= &tegra210_pcie_ops
,
2850 static const struct tegra_xusb_lane_soc tegra210_sata_lanes
[] = {
2851 TEGRA210_UPHY_LANE("sata-0", 0x028, 30, 0x3, pcie
, XUSB_PADCTL_UPHY_MISC_PAD_S0_CTL2
),
2854 static struct tegra_xusb_lane
*
2855 tegra210_sata_lane_probe(struct tegra_xusb_pad
*pad
, struct device_node
*np
,
2858 struct tegra_xusb_sata_lane
*sata
;
2861 sata
= kzalloc(sizeof(*sata
), GFP_KERNEL
);
2863 return ERR_PTR(-ENOMEM
);
2865 INIT_LIST_HEAD(&sata
->base
.list
);
2866 sata
->base
.soc
= &pad
->soc
->lanes
[index
];
2867 sata
->base
.index
= index
;
2868 sata
->base
.pad
= pad
;
2871 err
= tegra_xusb_lane_parse_dt(&sata
->base
, np
);
2874 return ERR_PTR(err
);
2880 static void tegra210_sata_lane_remove(struct tegra_xusb_lane
*lane
)
2882 struct tegra_xusb_sata_lane
*sata
= to_sata_lane(lane
);
2887 static const struct tegra_xusb_lane_ops tegra210_sata_lane_ops
= {
2888 .probe
= tegra210_sata_lane_probe
,
2889 .remove
= tegra210_sata_lane_remove
,
2890 .iddq_enable
= tegra210_uphy_lane_iddq_enable
,
2891 .iddq_disable
= tegra210_uphy_lane_iddq_disable
,
2892 .enable_phy_sleepwalk
= tegra210_usb3_enable_phy_sleepwalk
,
2893 .disable_phy_sleepwalk
= tegra210_usb3_disable_phy_sleepwalk
,
2894 .enable_phy_wake
= tegra210_usb3_enable_phy_wake
,
2895 .disable_phy_wake
= tegra210_usb3_disable_phy_wake
,
2896 .remote_wake_detected
= tegra210_usb3_phy_remote_wake_detected
,
2899 static int tegra210_sata_phy_init(struct phy
*phy
)
2901 struct tegra_xusb_lane
*lane
= phy_get_drvdata(phy
);
2902 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
2904 mutex_lock(&padctl
->lock
);
2906 tegra210_uphy_init(padctl
);
2908 mutex_unlock(&padctl
->lock
);
2912 static int tegra210_sata_phy_power_on(struct phy
*phy
)
2914 struct tegra_xusb_lane
*lane
= phy_get_drvdata(phy
);
2915 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
2918 mutex_lock(&padctl
->lock
);
2920 if (tegra_xusb_lane_check(lane
, "usb3-ss"))
2921 err
= tegra210_usb3_phy_power_on(phy
);
2923 mutex_unlock(&padctl
->lock
);
2927 static int tegra210_sata_phy_power_off(struct phy
*phy
)
2929 struct tegra_xusb_lane
*lane
= phy_get_drvdata(phy
);
2930 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
2933 mutex_lock(&padctl
->lock
);
2935 if (tegra_xusb_lane_check(lane
, "usb3-ss"))
2936 err
= tegra210_usb3_phy_power_off(phy
);
2938 mutex_unlock(&padctl
->lock
);
2942 static const struct phy_ops tegra210_sata_phy_ops
= {
2943 .init
= tegra210_sata_phy_init
,
2944 .power_on
= tegra210_sata_phy_power_on
,
2945 .power_off
= tegra210_sata_phy_power_off
,
2946 .owner
= THIS_MODULE
,
2949 static struct tegra_xusb_pad
*
2950 tegra210_sata_pad_probe(struct tegra_xusb_padctl
*padctl
,
2951 const struct tegra_xusb_pad_soc
*soc
,
2952 struct device_node
*np
)
2954 struct tegra_xusb_sata_pad
*sata
;
2955 struct tegra_xusb_pad
*pad
;
2958 sata
= kzalloc(sizeof(*sata
), GFP_KERNEL
);
2960 return ERR_PTR(-ENOMEM
);
2963 pad
->ops
= &tegra210_sata_lane_ops
;
2966 err
= tegra_xusb_pad_init(pad
, padctl
, np
);
2972 sata
->rst
= devm_reset_control_get(&pad
->dev
, "phy");
2973 if (IS_ERR(sata
->rst
)) {
2974 err
= PTR_ERR(sata
->rst
);
2975 dev_err(&pad
->dev
, "failed to get SATA pad reset: %d\n", err
);
2979 err
= tegra_xusb_pad_register(pad
, &tegra210_sata_phy_ops
);
2983 dev_set_drvdata(&pad
->dev
, pad
);
2988 device_unregister(&pad
->dev
);
2990 return ERR_PTR(err
);
2993 static void tegra210_sata_pad_remove(struct tegra_xusb_pad
*pad
)
2995 struct tegra_xusb_sata_pad
*sata
= to_sata_pad(pad
);
3000 static const struct tegra_xusb_pad_ops tegra210_sata_ops
= {
3001 .probe
= tegra210_sata_pad_probe
,
3002 .remove
= tegra210_sata_pad_remove
,
3005 static const struct tegra_xusb_pad_soc tegra210_sata_pad
= {
3007 .num_lanes
= ARRAY_SIZE(tegra210_sata_lanes
),
3008 .lanes
= tegra210_sata_lanes
,
3009 .ops
= &tegra210_sata_ops
,
3012 static const struct tegra_xusb_pad_soc
* const tegra210_pads
[] = {
3019 static int tegra210_usb2_port_enable(struct tegra_xusb_port
*port
)
3024 static void tegra210_usb2_port_disable(struct tegra_xusb_port
*port
)
3028 static struct tegra_xusb_lane
*
3029 tegra210_usb2_port_map(struct tegra_xusb_port
*port
)
3031 return tegra_xusb_find_lane(port
->padctl
, "usb2", port
->index
);
3034 static const struct tegra_xusb_port_ops tegra210_usb2_port_ops
= {
3035 .release
= tegra_xusb_usb2_port_release
,
3036 .remove
= tegra_xusb_usb2_port_remove
,
3037 .enable
= tegra210_usb2_port_enable
,
3038 .disable
= tegra210_usb2_port_disable
,
3039 .map
= tegra210_usb2_port_map
,
3042 static int tegra210_hsic_port_enable(struct tegra_xusb_port
*port
)
3047 static void tegra210_hsic_port_disable(struct tegra_xusb_port
*port
)
3051 static struct tegra_xusb_lane
*
3052 tegra210_hsic_port_map(struct tegra_xusb_port
*port
)
3054 return tegra_xusb_find_lane(port
->padctl
, "hsic", port
->index
);
3057 static const struct tegra_xusb_port_ops tegra210_hsic_port_ops
= {
3058 .release
= tegra_xusb_hsic_port_release
,
3059 .enable
= tegra210_hsic_port_enable
,
3060 .disable
= tegra210_hsic_port_disable
,
3061 .map
= tegra210_hsic_port_map
,
3064 static int tegra210_usb3_port_enable(struct tegra_xusb_port
*port
)
3069 static void tegra210_usb3_port_disable(struct tegra_xusb_port
*port
)
3073 static struct tegra_xusb_lane
*
3074 tegra210_usb3_port_map(struct tegra_xusb_port
*port
)
3076 return tegra_xusb_port_find_lane(port
, tegra210_usb3_map
, "usb3-ss");
3079 static const struct tegra_xusb_port_ops tegra210_usb3_port_ops
= {
3080 .release
= tegra_xusb_usb3_port_release
,
3081 .enable
= tegra210_usb3_port_enable
,
3082 .disable
= tegra210_usb3_port_disable
,
3083 .map
= tegra210_usb3_port_map
,
3086 static int tegra210_utmi_port_reset(struct phy
*phy
)
3088 struct tegra_xusb_padctl
*padctl
;
3089 struct tegra_xusb_lane
*lane
;
3092 lane
= phy_get_drvdata(phy
);
3093 padctl
= lane
->pad
->padctl
;
3095 value
= padctl_readl(padctl
,
3096 XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPADX_CTL0(lane
->index
));
3098 if ((value
& XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL0_ZIP
) ||
3099 (value
& XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL0_ZIN
)) {
3100 tegra210_xusb_padctl_vbus_override(padctl
, false);
3101 tegra210_xusb_padctl_vbus_override(padctl
, true);
3109 tegra210_xusb_read_fuse_calibration(struct tegra210_xusb_fuse_calibration
*fuse
)
3115 err
= tegra_fuse_readl(TEGRA_FUSE_SKU_CALIB_0
, &value
);
3119 for (i
= 0; i
< ARRAY_SIZE(fuse
->hs_curr_level
); i
++) {
3120 fuse
->hs_curr_level
[i
] =
3121 (value
>> FUSE_SKU_CALIB_HS_CURR_LEVEL_PADX_SHIFT(i
)) &
3122 FUSE_SKU_CALIB_HS_CURR_LEVEL_PAD_MASK
;
3125 fuse
->hs_term_range_adj
=
3126 (value
>> FUSE_SKU_CALIB_HS_TERM_RANGE_ADJ_SHIFT
) &
3127 FUSE_SKU_CALIB_HS_TERM_RANGE_ADJ_MASK
;
3129 err
= tegra_fuse_readl(TEGRA_FUSE_USB_CALIB_EXT_0
, &value
);
3134 (value
>> FUSE_USB_CALIB_EXT_RPD_CTRL_SHIFT
) &
3135 FUSE_USB_CALIB_EXT_RPD_CTRL_MASK
;
3140 static struct tegra_xusb_padctl
*
3141 tegra210_xusb_padctl_probe(struct device
*dev
,
3142 const struct tegra_xusb_padctl_soc
*soc
)
3144 struct tegra210_xusb_padctl
*padctl
;
3145 struct platform_device
*pdev
;
3146 struct device_node
*np
;
3149 padctl
= devm_kzalloc(dev
, sizeof(*padctl
), GFP_KERNEL
);
3151 return ERR_PTR(-ENOMEM
);
3153 padctl
->base
.dev
= dev
;
3154 padctl
->base
.soc
= soc
;
3156 err
= tegra210_xusb_read_fuse_calibration(&padctl
->fuse
);
3158 return ERR_PTR(err
);
3160 np
= of_parse_phandle(dev
->of_node
, "nvidia,pmc", 0);
3162 dev_warn(dev
, "nvidia,pmc property is missing\n");
3166 pdev
= of_find_device_by_node(np
);
3168 dev_warn(dev
, "PMC device is not available\n");
3172 if (!platform_get_drvdata(pdev
))
3173 return ERR_PTR(-EPROBE_DEFER
);
3175 padctl
->regmap
= dev_get_regmap(&pdev
->dev
, "usb_sleepwalk");
3176 if (!padctl
->regmap
)
3177 dev_info(dev
, "failed to find PMC regmap\n");
3180 return &padctl
->base
;
3183 static void tegra210_xusb_padctl_remove(struct tegra_xusb_padctl
*padctl
)
3187 static void tegra210_xusb_padctl_save(struct tegra_xusb_padctl
*padctl
)
3189 struct tegra210_xusb_padctl
*priv
= to_tegra210_xusb_padctl(padctl
);
3191 priv
->context
.usb2_pad_mux
=
3192 padctl_readl(padctl
, XUSB_PADCTL_USB2_PAD_MUX
);
3193 priv
->context
.usb2_port_cap
=
3194 padctl_readl(padctl
, XUSB_PADCTL_USB2_PORT_CAP
);
3195 priv
->context
.ss_port_map
=
3196 padctl_readl(padctl
, XUSB_PADCTL_SS_PORT_MAP
);
3197 priv
->context
.usb3_pad_mux
=
3198 padctl_readl(padctl
, XUSB_PADCTL_USB3_PAD_MUX
);
3201 static void tegra210_xusb_padctl_restore(struct tegra_xusb_padctl
*padctl
)
3203 struct tegra210_xusb_padctl
*priv
= to_tegra210_xusb_padctl(padctl
);
3204 struct tegra_xusb_lane
*lane
;
3206 padctl_writel(padctl
, priv
->context
.usb2_pad_mux
,
3207 XUSB_PADCTL_USB2_PAD_MUX
);
3208 padctl_writel(padctl
, priv
->context
.usb2_port_cap
,
3209 XUSB_PADCTL_USB2_PORT_CAP
);
3210 padctl_writel(padctl
, priv
->context
.ss_port_map
,
3211 XUSB_PADCTL_SS_PORT_MAP
);
3213 list_for_each_entry(lane
, &padctl
->lanes
, list
) {
3214 if (lane
->pad
->ops
->iddq_enable
)
3215 tegra210_uphy_lane_iddq_enable(lane
);
3218 padctl_writel(padctl
, priv
->context
.usb3_pad_mux
,
3219 XUSB_PADCTL_USB3_PAD_MUX
);
3221 list_for_each_entry(lane
, &padctl
->lanes
, list
) {
3222 if (lane
->pad
->ops
->iddq_disable
)
3223 tegra210_uphy_lane_iddq_disable(lane
);
3227 static int tegra210_xusb_padctl_suspend_noirq(struct tegra_xusb_padctl
*padctl
)
3229 mutex_lock(&padctl
->lock
);
3231 tegra210_uphy_deinit(padctl
);
3233 tegra210_xusb_padctl_save(padctl
);
3235 mutex_unlock(&padctl
->lock
);
3239 static int tegra210_xusb_padctl_resume_noirq(struct tegra_xusb_padctl
*padctl
)
3241 mutex_lock(&padctl
->lock
);
3243 tegra210_xusb_padctl_restore(padctl
);
3245 tegra210_uphy_init(padctl
);
3247 mutex_unlock(&padctl
->lock
);
3251 static const struct tegra_xusb_padctl_ops tegra210_xusb_padctl_ops
= {
3252 .probe
= tegra210_xusb_padctl_probe
,
3253 .remove
= tegra210_xusb_padctl_remove
,
3254 .suspend_noirq
= tegra210_xusb_padctl_suspend_noirq
,
3255 .resume_noirq
= tegra210_xusb_padctl_resume_noirq
,
3256 .usb3_set_lfps_detect
= tegra210_usb3_set_lfps_detect
,
3257 .hsic_set_idle
= tegra210_hsic_set_idle
,
3258 .vbus_override
= tegra210_xusb_padctl_vbus_override
,
3259 .utmi_port_reset
= tegra210_utmi_port_reset
,
3262 static const char * const tegra210_xusb_padctl_supply_names
[] = {
3269 const struct tegra_xusb_padctl_soc tegra210_xusb_padctl_soc
= {
3270 .num_pads
= ARRAY_SIZE(tegra210_pads
),
3271 .pads
= tegra210_pads
,
3274 .ops
= &tegra210_usb2_port_ops
,
3278 .ops
= &tegra210_hsic_port_ops
,
3282 .ops
= &tegra210_usb3_port_ops
,
3286 .ops
= &tegra210_xusb_padctl_ops
,
3287 .supply_names
= tegra210_xusb_padctl_supply_names
,
3288 .num_supplies
= ARRAY_SIZE(tegra210_xusb_padctl_supply_names
),
3289 .need_fake_usb3_port
= true,
3291 EXPORT_SYMBOL_GPL(tegra210_xusb_padctl_soc
);
3293 MODULE_AUTHOR("Andrew Bresticker <abrestic@chromium.org>");
3294 MODULE_DESCRIPTION("NVIDIA Tegra 210 XUSB Pad Controller driver");
3295 MODULE_LICENSE("GPL v2");