xref: /linux/drivers/phy/tegra/xusb-tegra186.c (revision 8a922b7728a93d837954315c98b84f6b78de0c4f)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2016-2022, NVIDIA CORPORATION.  All rights reserved.
4  */
5 
6 #include <linux/delay.h>
7 #include <linux/io.h>
8 #include <linux/module.h>
9 #include <linux/of.h>
10 #include <linux/phy/phy.h>
11 #include <linux/regulator/consumer.h>
12 #include <linux/platform_device.h>
13 #include <linux/clk.h>
14 #include <linux/slab.h>
15 
16 #include <soc/tegra/fuse.h>
17 
18 #include "xusb.h"
19 
20 /* FUSE USB_CALIB registers */
21 #define HS_CURR_LEVEL_PADX_SHIFT(x)	((x) ? (11 + (x - 1) * 6) : 0)
22 #define HS_CURR_LEVEL_PAD_MASK		0x3f
23 #define HS_TERM_RANGE_ADJ_SHIFT		7
24 #define HS_TERM_RANGE_ADJ_MASK		0xf
25 #define HS_SQUELCH_SHIFT		29
26 #define HS_SQUELCH_MASK			0x7
27 
28 #define RPD_CTRL_SHIFT			0
29 #define RPD_CTRL_MASK			0x1f
30 
31 /* XUSB PADCTL registers */
32 #define XUSB_PADCTL_USB2_PAD_MUX	0x4
33 #define  USB2_PORT_SHIFT(x)		((x) * 2)
34 #define  USB2_PORT_MASK			0x3
35 #define   PORT_XUSB			1
36 #define  HSIC_PORT_SHIFT(x)		((x) + 20)
37 #define  HSIC_PORT_MASK			0x1
38 #define   PORT_HSIC			0
39 
40 #define XUSB_PADCTL_USB2_PORT_CAP	0x8
41 #define XUSB_PADCTL_SS_PORT_CAP		0xc
42 #define  PORTX_CAP_SHIFT(x)		((x) * 4)
43 #define  PORT_CAP_MASK			0x3
44 #define   PORT_CAP_DISABLED		0x0
45 #define   PORT_CAP_HOST			0x1
46 #define   PORT_CAP_DEVICE		0x2
47 #define   PORT_CAP_OTG			0x3
48 
49 #define XUSB_PADCTL_ELPG_PROGRAM		0x20
50 #define  USB2_PORT_WAKE_INTERRUPT_ENABLE(x)		BIT(x)
51 #define  USB2_PORT_WAKEUP_EVENT(x)			BIT((x) +  7)
52 #define  SS_PORT_WAKE_INTERRUPT_ENABLE(x)		BIT((x) + 14)
53 #define  SS_PORT_WAKEUP_EVENT(x)			BIT((x) + 21)
54 #define  USB2_HSIC_PORT_WAKE_INTERRUPT_ENABLE(x)	BIT((x) + 28)
55 #define  USB2_HSIC_PORT_WAKEUP_EVENT(x)			BIT((x) + 30)
56 #define  ALL_WAKE_EVENTS						\
57 	(USB2_PORT_WAKEUP_EVENT(0) | USB2_PORT_WAKEUP_EVENT(1) |	\
58 	USB2_PORT_WAKEUP_EVENT(2) | SS_PORT_WAKEUP_EVENT(0) |		\
59 	SS_PORT_WAKEUP_EVENT(1) | SS_PORT_WAKEUP_EVENT(2) |		\
60 	USB2_HSIC_PORT_WAKEUP_EVENT(0))
61 
62 #define XUSB_PADCTL_ELPG_PROGRAM_1		0x24
63 #define  SSPX_ELPG_CLAMP_EN(x)			BIT(0 + (x) * 3)
64 #define  SSPX_ELPG_CLAMP_EN_EARLY(x)		BIT(1 + (x) * 3)
65 #define  SSPX_ELPG_VCORE_DOWN(x)		BIT(2 + (x) * 3)
66 #define XUSB_PADCTL_SS_PORT_CFG			0x2c
67 #define   PORTX_SPEED_SUPPORT_SHIFT(x)		((x) * 4)
68 #define   PORTX_SPEED_SUPPORT_MASK		(0x3)
69 #define     PORT_SPEED_SUPPORT_GEN1		(0x0)
70 
71 #define XUSB_PADCTL_USB2_OTG_PADX_CTL0(x)	(0x88 + (x) * 0x40)
72 #define  HS_CURR_LEVEL(x)			((x) & 0x3f)
73 #define  TERM_SEL				BIT(25)
74 #define  USB2_OTG_PD				BIT(26)
75 #define  USB2_OTG_PD2				BIT(27)
76 #define  USB2_OTG_PD2_OVRD_EN			BIT(28)
77 #define  USB2_OTG_PD_ZI				BIT(29)
78 
79 #define XUSB_PADCTL_USB2_OTG_PADX_CTL1(x)	(0x8c + (x) * 0x40)
80 #define  USB2_OTG_PD_DR				BIT(2)
81 #define  TERM_RANGE_ADJ(x)			(((x) & 0xf) << 3)
82 #define  RPD_CTRL(x)				(((x) & 0x1f) << 26)
83 
84 #define XUSB_PADCTL_USB2_BIAS_PAD_CTL0		0x284
85 #define  BIAS_PAD_PD				BIT(11)
86 #define  HS_SQUELCH_LEVEL(x)			(((x) & 0x7) << 0)
87 
88 #define XUSB_PADCTL_USB2_BIAS_PAD_CTL1		0x288
89 #define  USB2_TRK_START_TIMER(x)		(((x) & 0x7f) << 12)
90 #define  USB2_TRK_DONE_RESET_TIMER(x)		(((x) & 0x7f) << 19)
91 #define  USB2_PD_TRK				BIT(26)
92 #define  USB2_TRK_COMPLETED			BIT(31)
93 
94 #define XUSB_PADCTL_USB2_BIAS_PAD_CTL2		0x28c
95 #define  USB2_TRK_HW_MODE			BIT(0)
96 #define  CYA_TRK_CODE_UPDATE_ON_IDLE		BIT(31)
97 
98 #define XUSB_PADCTL_HSIC_PADX_CTL0(x)		(0x300 + (x) * 0x20)
99 #define  HSIC_PD_TX_DATA0			BIT(1)
100 #define  HSIC_PD_TX_STROBE			BIT(3)
101 #define  HSIC_PD_RX_DATA0			BIT(4)
102 #define  HSIC_PD_RX_STROBE			BIT(6)
103 #define  HSIC_PD_ZI_DATA0			BIT(7)
104 #define  HSIC_PD_ZI_STROBE			BIT(9)
105 #define  HSIC_RPD_DATA0				BIT(13)
106 #define  HSIC_RPD_STROBE			BIT(15)
107 #define  HSIC_RPU_DATA0				BIT(16)
108 #define  HSIC_RPU_STROBE			BIT(18)
109 
110 #define XUSB_PADCTL_HSIC_PAD_TRK_CTL0		0x340
111 #define  HSIC_TRK_START_TIMER(x)		(((x) & 0x7f) << 5)
112 #define  HSIC_TRK_DONE_RESET_TIMER(x)		(((x) & 0x7f) << 12)
113 #define  HSIC_PD_TRK				BIT(19)
114 
115 #define USB2_VBUS_ID				0x360
116 #define  VBUS_OVERRIDE				BIT(14)
117 #define  ID_OVERRIDE(x)				(((x) & 0xf) << 18)
118 #define  ID_OVERRIDE_FLOATING			ID_OVERRIDE(8)
119 #define  ID_OVERRIDE_GROUNDED			ID_OVERRIDE(0)
120 
121 /* XUSB AO registers */
122 #define XUSB_AO_USB_DEBOUNCE_DEL		(0x4)
123 #define   UHSIC_LINE_DEB_CNT(x)			(((x) & 0xf) << 4)
124 #define   UTMIP_LINE_DEB_CNT(x)			((x) & 0xf)
125 
126 #define XUSB_AO_UTMIP_TRIGGERS(x)		(0x40 + (x) * 4)
127 #define   CLR_WALK_PTR				BIT(0)
128 #define   CAP_CFG				BIT(1)
129 #define   CLR_WAKE_ALARM			BIT(3)
130 
131 #define XUSB_AO_UHSIC_TRIGGERS(x)		(0x60 + (x) * 4)
132 #define   HSIC_CLR_WALK_PTR			BIT(0)
133 #define   HSIC_CLR_WAKE_ALARM			BIT(3)
134 #define   HSIC_CAP_CFG				BIT(4)
135 
136 #define XUSB_AO_UTMIP_SAVED_STATE(x)		(0x70 + (x) * 4)
137 #define   SPEED(x)				((x) & 0x3)
138 #define     UTMI_HS				SPEED(0)
139 #define     UTMI_FS				SPEED(1)
140 #define     UTMI_LS				SPEED(2)
141 #define     UTMI_RST				SPEED(3)
142 
143 #define XUSB_AO_UHSIC_SAVED_STATE(x)		(0x90 + (x) * 4)
144 #define   MODE(x)				((x) & 0x1)
145 #define   MODE_HS				MODE(0)
146 #define   MODE_RST				MODE(1)
147 
148 #define XUSB_AO_UTMIP_SLEEPWALK_CFG(x)		(0xd0 + (x) * 4)
149 #define XUSB_AO_UHSIC_SLEEPWALK_CFG(x)		(0xf0 + (x) * 4)
150 #define   FAKE_USBOP_VAL			BIT(0)
151 #define   FAKE_USBON_VAL			BIT(1)
152 #define   FAKE_USBOP_EN				BIT(2)
153 #define   FAKE_USBON_EN				BIT(3)
154 #define   FAKE_STROBE_VAL			BIT(0)
155 #define   FAKE_DATA_VAL				BIT(1)
156 #define   FAKE_STROBE_EN			BIT(2)
157 #define   FAKE_DATA_EN				BIT(3)
158 #define   WAKE_WALK_EN				BIT(14)
159 #define   MASTER_ENABLE				BIT(15)
160 #define   LINEVAL_WALK_EN			BIT(16)
161 #define   WAKE_VAL(x)				(((x) & 0xf) << 17)
162 #define     WAKE_VAL_NONE			WAKE_VAL(12)
163 #define     WAKE_VAL_ANY			WAKE_VAL(15)
164 #define     WAKE_VAL_DS10			WAKE_VAL(2)
165 #define   LINE_WAKEUP_EN			BIT(21)
166 #define   MASTER_CFG_SEL			BIT(22)
167 
168 #define XUSB_AO_UTMIP_SLEEPWALK(x)		(0x100 + (x) * 4)
169 /* phase A */
170 #define   USBOP_RPD_A				BIT(0)
171 #define   USBON_RPD_A				BIT(1)
172 #define   AP_A					BIT(4)
173 #define   AN_A					BIT(5)
174 #define   HIGHZ_A				BIT(6)
175 /* phase B */
176 #define   USBOP_RPD_B				BIT(8)
177 #define   USBON_RPD_B				BIT(9)
178 #define   AP_B					BIT(12)
179 #define   AN_B					BIT(13)
180 #define   HIGHZ_B				BIT(14)
181 /* phase C */
182 #define   USBOP_RPD_C				BIT(16)
183 #define   USBON_RPD_C				BIT(17)
184 #define   AP_C					BIT(20)
185 #define   AN_C					BIT(21)
186 #define   HIGHZ_C				BIT(22)
187 /* phase D */
188 #define   USBOP_RPD_D				BIT(24)
189 #define   USBON_RPD_D				BIT(25)
190 #define   AP_D					BIT(28)
191 #define   AN_D					BIT(29)
192 #define   HIGHZ_D				BIT(30)
193 
194 #define XUSB_AO_UHSIC_SLEEPWALK(x)		(0x120 + (x) * 4)
195 /* phase A */
196 #define   RPD_STROBE_A				BIT(0)
197 #define   RPD_DATA0_A				BIT(1)
198 #define   RPU_STROBE_A				BIT(2)
199 #define   RPU_DATA0_A				BIT(3)
200 /* phase B */
201 #define   RPD_STROBE_B				BIT(8)
202 #define   RPD_DATA0_B				BIT(9)
203 #define   RPU_STROBE_B				BIT(10)
204 #define   RPU_DATA0_B				BIT(11)
205 /* phase C */
206 #define   RPD_STROBE_C				BIT(16)
207 #define   RPD_DATA0_C				BIT(17)
208 #define   RPU_STROBE_C				BIT(18)
209 #define   RPU_DATA0_C				BIT(19)
210 /* phase D */
211 #define   RPD_STROBE_D				BIT(24)
212 #define   RPD_DATA0_D				BIT(25)
213 #define   RPU_STROBE_D				BIT(26)
214 #define   RPU_DATA0_D				BIT(27)
215 
216 #define XUSB_AO_UTMIP_PAD_CFG(x)		(0x130 + (x) * 4)
217 #define   FSLS_USE_XUSB_AO			BIT(3)
218 #define   TRK_CTRL_USE_XUSB_AO			BIT(4)
219 #define   RPD_CTRL_USE_XUSB_AO			BIT(5)
220 #define   RPU_USE_XUSB_AO			BIT(6)
221 #define   VREG_USE_XUSB_AO			BIT(7)
222 #define   USBOP_VAL_PD				BIT(8)
223 #define   USBON_VAL_PD				BIT(9)
224 #define   E_DPD_OVRD_EN				BIT(10)
225 #define   E_DPD_OVRD_VAL			BIT(11)
226 
227 #define XUSB_AO_UHSIC_PAD_CFG(x)		(0x150 + (x) * 4)
228 #define   STROBE_VAL_PD				BIT(0)
229 #define   DATA0_VAL_PD				BIT(1)
230 #define   USE_XUSB_AO				BIT(4)
231 
232 #define TEGRA186_LANE(_name, _offset, _shift, _mask, _type)		\
233 	{								\
234 		.name = _name,						\
235 		.offset = _offset,					\
236 		.shift = _shift,					\
237 		.mask = _mask,						\
238 		.num_funcs = ARRAY_SIZE(tegra186_##_type##_functions),	\
239 		.funcs = tegra186_##_type##_functions,			\
240 	}
241 
242 struct tegra_xusb_fuse_calibration {
243 	u32 *hs_curr_level;
244 	u32 hs_squelch;
245 	u32 hs_term_range_adj;
246 	u32 rpd_ctrl;
247 };
248 
249 struct tegra186_xusb_padctl_context {
250 	u32 vbus_id;
251 	u32 usb2_pad_mux;
252 	u32 usb2_port_cap;
253 	u32 ss_port_cap;
254 };
255 
256 struct tegra186_xusb_padctl {
257 	struct tegra_xusb_padctl base;
258 	void __iomem *ao_regs;
259 
260 	struct tegra_xusb_fuse_calibration calib;
261 
262 	/* UTMI bias and tracking */
263 	struct clk *usb2_trk_clk;
264 	unsigned int bias_pad_enable;
265 
266 	/* padctl context */
267 	struct tegra186_xusb_padctl_context context;
268 };
269 
270 static inline void ao_writel(struct tegra186_xusb_padctl *priv, u32 value, unsigned int offset)
271 {
272 	writel(value, priv->ao_regs + offset);
273 }
274 
275 static inline u32 ao_readl(struct tegra186_xusb_padctl *priv, unsigned int offset)
276 {
277 	return readl(priv->ao_regs + offset);
278 }
279 
280 static inline struct tegra186_xusb_padctl *
281 to_tegra186_xusb_padctl(struct tegra_xusb_padctl *padctl)
282 {
283 	return container_of(padctl, struct tegra186_xusb_padctl, base);
284 }
285 
286 /* USB 2.0 UTMI PHY support */
287 static struct tegra_xusb_lane *
288 tegra186_usb2_lane_probe(struct tegra_xusb_pad *pad, struct device_node *np,
289 			 unsigned int index)
290 {
291 	struct tegra_xusb_usb2_lane *usb2;
292 	int err;
293 
294 	usb2 = kzalloc(sizeof(*usb2), GFP_KERNEL);
295 	if (!usb2)
296 		return ERR_PTR(-ENOMEM);
297 
298 	INIT_LIST_HEAD(&usb2->base.list);
299 	usb2->base.soc = &pad->soc->lanes[index];
300 	usb2->base.index = index;
301 	usb2->base.pad = pad;
302 	usb2->base.np = np;
303 
304 	err = tegra_xusb_lane_parse_dt(&usb2->base, np);
305 	if (err < 0) {
306 		kfree(usb2);
307 		return ERR_PTR(err);
308 	}
309 
310 	return &usb2->base;
311 }
312 
313 static void tegra186_usb2_lane_remove(struct tegra_xusb_lane *lane)
314 {
315 	struct tegra_xusb_usb2_lane *usb2 = to_usb2_lane(lane);
316 
317 	kfree(usb2);
318 }
319 
320 static int tegra186_utmi_enable_phy_sleepwalk(struct tegra_xusb_lane *lane,
321 					      enum usb_device_speed speed)
322 {
323 	struct tegra_xusb_padctl *padctl = lane->pad->padctl;
324 	struct tegra186_xusb_padctl *priv = to_tegra186_xusb_padctl(padctl);
325 	unsigned int index = lane->index;
326 	u32 value;
327 
328 	mutex_lock(&padctl->lock);
329 
330 	/* ensure sleepwalk logic is disabled */
331 	value = ao_readl(priv, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
332 	value &= ~MASTER_ENABLE;
333 	ao_writel(priv, value, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
334 
335 	/* ensure sleepwalk logics are in low power mode */
336 	value = ao_readl(priv, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
337 	value |= MASTER_CFG_SEL;
338 	ao_writel(priv, value, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
339 
340 	/* set debounce time */
341 	value = ao_readl(priv, XUSB_AO_USB_DEBOUNCE_DEL);
342 	value &= ~UTMIP_LINE_DEB_CNT(~0);
343 	value |= UTMIP_LINE_DEB_CNT(1);
344 	ao_writel(priv, value, XUSB_AO_USB_DEBOUNCE_DEL);
345 
346 	/* ensure fake events of sleepwalk logic are desiabled */
347 	value = ao_readl(priv, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
348 	value &= ~(FAKE_USBOP_VAL | FAKE_USBON_VAL |
349 		FAKE_USBOP_EN | FAKE_USBON_EN);
350 	ao_writel(priv, value, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
351 
352 	/* ensure wake events of sleepwalk logic are not latched */
353 	value = ao_readl(priv, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
354 	value &= ~LINE_WAKEUP_EN;
355 	ao_writel(priv, value, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
356 
357 	/* disable wake event triggers of sleepwalk logic */
358 	value = ao_readl(priv, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
359 	value &= ~WAKE_VAL(~0);
360 	value |= WAKE_VAL_NONE;
361 	ao_writel(priv, value, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
362 
363 	/* power down the line state detectors of the pad */
364 	value = ao_readl(priv, XUSB_AO_UTMIP_PAD_CFG(index));
365 	value |= (USBOP_VAL_PD | USBON_VAL_PD);
366 	ao_writel(priv, value, XUSB_AO_UTMIP_PAD_CFG(index));
367 
368 	/* save state per speed */
369 	value = ao_readl(priv, XUSB_AO_UTMIP_SAVED_STATE(index));
370 	value &= ~SPEED(~0);
371 
372 	switch (speed) {
373 	case USB_SPEED_HIGH:
374 		value |= UTMI_HS;
375 		break;
376 
377 	case USB_SPEED_FULL:
378 		value |= UTMI_FS;
379 		break;
380 
381 	case USB_SPEED_LOW:
382 		value |= UTMI_LS;
383 		break;
384 
385 	default:
386 		value |= UTMI_RST;
387 		break;
388 	}
389 
390 	ao_writel(priv, value, XUSB_AO_UTMIP_SAVED_STATE(index));
391 
392 	/* enable the trigger of the sleepwalk logic */
393 	value = ao_readl(priv, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
394 	value |= LINEVAL_WALK_EN;
395 	value &= ~WAKE_WALK_EN;
396 	ao_writel(priv, value, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
397 
398 	/* reset the walk pointer and clear the alarm of the sleepwalk logic,
399 	 * as well as capture the configuration of the USB2.0 pad
400 	 */
401 	value = ao_readl(priv, XUSB_AO_UTMIP_TRIGGERS(index));
402 	value |= (CLR_WALK_PTR | CLR_WAKE_ALARM | CAP_CFG);
403 	ao_writel(priv, value, XUSB_AO_UTMIP_TRIGGERS(index));
404 
405 	/* setup the pull-ups and pull-downs of the signals during the four
406 	 * stages of sleepwalk.
407 	 * if device is connected, program sleepwalk logic to maintain a J and
408 	 * keep driving K upon seeing remote wake.
409 	 */
410 	value = USBOP_RPD_A | USBOP_RPD_B | USBOP_RPD_C | USBOP_RPD_D;
411 	value |= USBON_RPD_A | USBON_RPD_B | USBON_RPD_C | USBON_RPD_D;
412 
413 	switch (speed) {
414 	case USB_SPEED_HIGH:
415 	case USB_SPEED_FULL:
416 		/* J state: D+/D- = high/low, K state: D+/D- = low/high */
417 		value |= HIGHZ_A;
418 		value |= AP_A;
419 		value |= AN_B | AN_C | AN_D;
420 		break;
421 
422 	case USB_SPEED_LOW:
423 		/* J state: D+/D- = low/high, K state: D+/D- = high/low */
424 		value |= HIGHZ_A;
425 		value |= AN_A;
426 		value |= AP_B | AP_C | AP_D;
427 		break;
428 
429 	default:
430 		value |= HIGHZ_A | HIGHZ_B | HIGHZ_C | HIGHZ_D;
431 		break;
432 	}
433 
434 	ao_writel(priv, value, XUSB_AO_UTMIP_SLEEPWALK(index));
435 
436 	/* power up the line state detectors of the pad */
437 	value = ao_readl(priv, XUSB_AO_UTMIP_PAD_CFG(index));
438 	value &= ~(USBOP_VAL_PD | USBON_VAL_PD);
439 	ao_writel(priv, value, XUSB_AO_UTMIP_PAD_CFG(index));
440 
441 	usleep_range(150, 200);
442 
443 	/* switch the electric control of the USB2.0 pad to XUSB_AO */
444 	value = ao_readl(priv, XUSB_AO_UTMIP_PAD_CFG(index));
445 	value |= FSLS_USE_XUSB_AO | TRK_CTRL_USE_XUSB_AO | RPD_CTRL_USE_XUSB_AO |
446 		 RPU_USE_XUSB_AO | VREG_USE_XUSB_AO;
447 	ao_writel(priv, value, XUSB_AO_UTMIP_PAD_CFG(index));
448 
449 	/* set the wake signaling trigger events */
450 	value = ao_readl(priv, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
451 	value &= ~WAKE_VAL(~0);
452 	value |= WAKE_VAL_ANY;
453 	ao_writel(priv, value, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
454 
455 	/* enable the wake detection */
456 	value = ao_readl(priv, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
457 	value |= MASTER_ENABLE | LINE_WAKEUP_EN;
458 	ao_writel(priv, value, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
459 
460 	mutex_unlock(&padctl->lock);
461 
462 	return 0;
463 }
464 
465 static int tegra186_utmi_disable_phy_sleepwalk(struct tegra_xusb_lane *lane)
466 {
467 	struct tegra_xusb_padctl *padctl = lane->pad->padctl;
468 	struct tegra186_xusb_padctl *priv = to_tegra186_xusb_padctl(padctl);
469 	unsigned int index = lane->index;
470 	u32 value;
471 
472 	mutex_lock(&padctl->lock);
473 
474 	/* disable the wake detection */
475 	value = ao_readl(priv, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
476 	value &= ~(MASTER_ENABLE | LINE_WAKEUP_EN);
477 	ao_writel(priv, value, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
478 
479 	/* switch the electric control of the USB2.0 pad to XUSB vcore logic */
480 	value = ao_readl(priv, XUSB_AO_UTMIP_PAD_CFG(index));
481 	value &= ~(FSLS_USE_XUSB_AO | TRK_CTRL_USE_XUSB_AO | RPD_CTRL_USE_XUSB_AO |
482 		   RPU_USE_XUSB_AO | VREG_USE_XUSB_AO);
483 	ao_writel(priv, value, XUSB_AO_UTMIP_PAD_CFG(index));
484 
485 	/* disable wake event triggers of sleepwalk logic */
486 	value = ao_readl(priv, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
487 	value &= ~WAKE_VAL(~0);
488 	value |= WAKE_VAL_NONE;
489 	ao_writel(priv, value, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
490 
491 	/* power down the line state detectors of the port */
492 	value = ao_readl(priv, XUSB_AO_UTMIP_PAD_CFG(index));
493 	value |= USBOP_VAL_PD | USBON_VAL_PD;
494 	ao_writel(priv, value, XUSB_AO_UTMIP_PAD_CFG(index));
495 
496 	/* clear alarm of the sleepwalk logic */
497 	value = ao_readl(priv, XUSB_AO_UTMIP_TRIGGERS(index));
498 	value |= CLR_WAKE_ALARM;
499 	ao_writel(priv, value, XUSB_AO_UTMIP_TRIGGERS(index));
500 
501 	mutex_unlock(&padctl->lock);
502 
503 	return 0;
504 }
505 
506 static int tegra186_utmi_enable_phy_wake(struct tegra_xusb_lane *lane)
507 {
508 	struct tegra_xusb_padctl *padctl = lane->pad->padctl;
509 	unsigned int index = lane->index;
510 	u32 value;
511 
512 	mutex_lock(&padctl->lock);
513 
514 	value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
515 	value &= ~ALL_WAKE_EVENTS;
516 	value |= USB2_PORT_WAKEUP_EVENT(index);
517 	padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
518 
519 	usleep_range(10, 20);
520 
521 	value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
522 	value &= ~ALL_WAKE_EVENTS;
523 	value |= USB2_PORT_WAKE_INTERRUPT_ENABLE(index);
524 	padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
525 
526 	mutex_unlock(&padctl->lock);
527 
528 	return 0;
529 }
530 
531 static int tegra186_utmi_disable_phy_wake(struct tegra_xusb_lane *lane)
532 {
533 	struct tegra_xusb_padctl *padctl = lane->pad->padctl;
534 	unsigned int index = lane->index;
535 	u32 value;
536 
537 	mutex_lock(&padctl->lock);
538 
539 	value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
540 	value &= ~ALL_WAKE_EVENTS;
541 	value &= ~USB2_PORT_WAKE_INTERRUPT_ENABLE(index);
542 	padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
543 
544 	usleep_range(10, 20);
545 
546 	value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
547 	value &= ~ALL_WAKE_EVENTS;
548 	value |= USB2_PORT_WAKEUP_EVENT(index);
549 	padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
550 
551 	mutex_unlock(&padctl->lock);
552 
553 	return 0;
554 }
555 
556 static bool tegra186_utmi_phy_remote_wake_detected(struct tegra_xusb_lane *lane)
557 {
558 	struct tegra_xusb_padctl *padctl = lane->pad->padctl;
559 	unsigned int index = lane->index;
560 	u32 value;
561 
562 	value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
563 	if ((value & USB2_PORT_WAKE_INTERRUPT_ENABLE(index)) &&
564 	    (value & USB2_PORT_WAKEUP_EVENT(index)))
565 		return true;
566 
567 	return false;
568 }
569 
570 static const struct tegra_xusb_lane_ops tegra186_usb2_lane_ops = {
571 	.probe = tegra186_usb2_lane_probe,
572 	.remove = tegra186_usb2_lane_remove,
573 	.enable_phy_sleepwalk = tegra186_utmi_enable_phy_sleepwalk,
574 	.disable_phy_sleepwalk = tegra186_utmi_disable_phy_sleepwalk,
575 	.enable_phy_wake = tegra186_utmi_enable_phy_wake,
576 	.disable_phy_wake = tegra186_utmi_disable_phy_wake,
577 	.remote_wake_detected = tegra186_utmi_phy_remote_wake_detected,
578 };
579 
580 static void tegra186_utmi_bias_pad_power_on(struct tegra_xusb_padctl *padctl)
581 {
582 	struct tegra186_xusb_padctl *priv = to_tegra186_xusb_padctl(padctl);
583 	struct device *dev = padctl->dev;
584 	u32 value;
585 	int err;
586 
587 	mutex_lock(&padctl->lock);
588 
589 	if (priv->bias_pad_enable++ > 0) {
590 		mutex_unlock(&padctl->lock);
591 		return;
592 	}
593 
594 	err = clk_prepare_enable(priv->usb2_trk_clk);
595 	if (err < 0)
596 		dev_warn(dev, "failed to enable USB2 trk clock: %d\n", err);
597 
598 	value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL1);
599 	value &= ~USB2_TRK_START_TIMER(~0);
600 	value |= USB2_TRK_START_TIMER(0x1e);
601 	value &= ~USB2_TRK_DONE_RESET_TIMER(~0);
602 	value |= USB2_TRK_DONE_RESET_TIMER(0xa);
603 	padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL1);
604 
605 	value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL0);
606 	value &= ~BIAS_PAD_PD;
607 	value &= ~HS_SQUELCH_LEVEL(~0);
608 	value |= HS_SQUELCH_LEVEL(priv->calib.hs_squelch);
609 	padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL0);
610 
611 	udelay(1);
612 
613 	value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL1);
614 	value &= ~USB2_PD_TRK;
615 	padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL1);
616 
617 	if (padctl->soc->poll_trk_completed) {
618 		err = padctl_readl_poll(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL1,
619 					USB2_TRK_COMPLETED, USB2_TRK_COMPLETED, 100);
620 		if (err) {
621 			/* The failure with polling on trk complete will not
622 			 * cause the failure of powering on the bias pad.
623 			 */
624 			dev_warn(dev, "failed to poll USB2 trk completed: %d\n", err);
625 		}
626 
627 		value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL1);
628 		value |= USB2_TRK_COMPLETED;
629 		padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL1);
630 	} else {
631 		udelay(100);
632 	}
633 
634 	if (padctl->soc->trk_hw_mode) {
635 		value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL2);
636 		value |= USB2_TRK_HW_MODE;
637 		value &= ~CYA_TRK_CODE_UPDATE_ON_IDLE;
638 		padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL2);
639 	} else {
640 		clk_disable_unprepare(priv->usb2_trk_clk);
641 	}
642 
643 	mutex_unlock(&padctl->lock);
644 }
645 
646 static void tegra186_utmi_bias_pad_power_off(struct tegra_xusb_padctl *padctl)
647 {
648 	struct tegra186_xusb_padctl *priv = to_tegra186_xusb_padctl(padctl);
649 	u32 value;
650 
651 	mutex_lock(&padctl->lock);
652 
653 	if (WARN_ON(priv->bias_pad_enable == 0)) {
654 		mutex_unlock(&padctl->lock);
655 		return;
656 	}
657 
658 	if (--priv->bias_pad_enable > 0) {
659 		mutex_unlock(&padctl->lock);
660 		return;
661 	}
662 
663 	value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL1);
664 	value |= USB2_PD_TRK;
665 	padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL1);
666 
667 	if (padctl->soc->trk_hw_mode) {
668 		value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL2);
669 		value &= ~USB2_TRK_HW_MODE;
670 		padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL2);
671 		clk_disable_unprepare(priv->usb2_trk_clk);
672 	}
673 
674 	mutex_unlock(&padctl->lock);
675 }
676 
677 static void tegra186_utmi_pad_power_on(struct phy *phy)
678 {
679 	struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
680 	struct tegra_xusb_padctl *padctl = lane->pad->padctl;
681 	struct tegra_xusb_usb2_port *port;
682 	struct device *dev = padctl->dev;
683 	unsigned int index = lane->index;
684 	u32 value;
685 
686 	if (!phy)
687 		return;
688 
689 	port = tegra_xusb_find_usb2_port(padctl, index);
690 	if (!port) {
691 		dev_err(dev, "no port found for USB2 lane %u\n", index);
692 		return;
693 	}
694 
695 	dev_dbg(dev, "power on UTMI pad %u\n", index);
696 
697 	tegra186_utmi_bias_pad_power_on(padctl);
698 
699 	udelay(2);
700 
701 	value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL0(index));
702 	value &= ~USB2_OTG_PD;
703 	padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL0(index));
704 
705 	value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index));
706 	value &= ~USB2_OTG_PD_DR;
707 	padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index));
708 }
709 
710 static void tegra186_utmi_pad_power_down(struct phy *phy)
711 {
712 	struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
713 	struct tegra_xusb_padctl *padctl = lane->pad->padctl;
714 	unsigned int index = lane->index;
715 	u32 value;
716 
717 	if (!phy)
718 		return;
719 
720 	dev_dbg(padctl->dev, "power down UTMI pad %u\n", index);
721 
722 	value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL0(index));
723 	value |= USB2_OTG_PD;
724 	padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL0(index));
725 
726 	value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index));
727 	value |= USB2_OTG_PD_DR;
728 	padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index));
729 
730 	udelay(2);
731 
732 	tegra186_utmi_bias_pad_power_off(padctl);
733 }
734 
735 static int tegra186_xusb_padctl_vbus_override(struct tegra_xusb_padctl *padctl,
736 					       bool status)
737 {
738 	u32 value;
739 
740 	dev_dbg(padctl->dev, "%s vbus override\n", status ? "set" : "clear");
741 
742 	value = padctl_readl(padctl, USB2_VBUS_ID);
743 
744 	if (status) {
745 		value |= VBUS_OVERRIDE;
746 		value &= ~ID_OVERRIDE(~0);
747 		value |= ID_OVERRIDE_FLOATING;
748 	} else {
749 		value &= ~VBUS_OVERRIDE;
750 	}
751 
752 	padctl_writel(padctl, value, USB2_VBUS_ID);
753 
754 	return 0;
755 }
756 
757 static int tegra186_xusb_padctl_id_override(struct tegra_xusb_padctl *padctl,
758 					    bool status)
759 {
760 	u32 value;
761 
762 	dev_dbg(padctl->dev, "%s id override\n", status ? "set" : "clear");
763 
764 	value = padctl_readl(padctl, USB2_VBUS_ID);
765 
766 	if (status) {
767 		if (value & VBUS_OVERRIDE) {
768 			value &= ~VBUS_OVERRIDE;
769 			padctl_writel(padctl, value, USB2_VBUS_ID);
770 			usleep_range(1000, 2000);
771 
772 			value = padctl_readl(padctl, USB2_VBUS_ID);
773 		}
774 
775 		value &= ~ID_OVERRIDE(~0);
776 		value |= ID_OVERRIDE_GROUNDED;
777 	} else {
778 		value &= ~ID_OVERRIDE(~0);
779 		value |= ID_OVERRIDE_FLOATING;
780 	}
781 
782 	padctl_writel(padctl, value, USB2_VBUS_ID);
783 
784 	return 0;
785 }
786 
787 static int tegra186_utmi_phy_set_mode(struct phy *phy, enum phy_mode mode,
788 				      int submode)
789 {
790 	struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
791 	struct tegra_xusb_padctl *padctl = lane->pad->padctl;
792 	struct tegra_xusb_usb2_port *port = tegra_xusb_find_usb2_port(padctl,
793 								lane->index);
794 	int err = 0;
795 
796 	mutex_lock(&padctl->lock);
797 
798 	dev_dbg(&port->base.dev, "%s: mode %d", __func__, mode);
799 
800 	if (mode == PHY_MODE_USB_OTG) {
801 		if (submode == USB_ROLE_HOST) {
802 			tegra186_xusb_padctl_id_override(padctl, true);
803 
804 			err = regulator_enable(port->supply);
805 		} else if (submode == USB_ROLE_DEVICE) {
806 			tegra186_xusb_padctl_vbus_override(padctl, true);
807 		} else if (submode == USB_ROLE_NONE) {
808 			/*
809 			 * When port is peripheral only or role transitions to
810 			 * USB_ROLE_NONE from USB_ROLE_DEVICE, regulator is not
811 			 * enabled.
812 			 */
813 			if (regulator_is_enabled(port->supply))
814 				regulator_disable(port->supply);
815 
816 			tegra186_xusb_padctl_id_override(padctl, false);
817 			tegra186_xusb_padctl_vbus_override(padctl, false);
818 		}
819 	}
820 
821 	mutex_unlock(&padctl->lock);
822 
823 	return err;
824 }
825 
826 static int tegra186_utmi_phy_power_on(struct phy *phy)
827 {
828 	struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
829 	struct tegra_xusb_usb2_lane *usb2 = to_usb2_lane(lane);
830 	struct tegra_xusb_padctl *padctl = lane->pad->padctl;
831 	struct tegra186_xusb_padctl *priv = to_tegra186_xusb_padctl(padctl);
832 	struct tegra_xusb_usb2_port *port;
833 	unsigned int index = lane->index;
834 	struct device *dev = padctl->dev;
835 	u32 value;
836 
837 	port = tegra_xusb_find_usb2_port(padctl, index);
838 	if (!port) {
839 		dev_err(dev, "no port found for USB2 lane %u\n", index);
840 		return -ENODEV;
841 	}
842 
843 	value = padctl_readl(padctl, XUSB_PADCTL_USB2_PAD_MUX);
844 	value &= ~(USB2_PORT_MASK << USB2_PORT_SHIFT(index));
845 	value |= (PORT_XUSB << USB2_PORT_SHIFT(index));
846 	padctl_writel(padctl, value, XUSB_PADCTL_USB2_PAD_MUX);
847 
848 	value = padctl_readl(padctl, XUSB_PADCTL_USB2_PORT_CAP);
849 	value &= ~(PORT_CAP_MASK << PORTX_CAP_SHIFT(index));
850 
851 	if (port->mode == USB_DR_MODE_UNKNOWN)
852 		value |= (PORT_CAP_DISABLED << PORTX_CAP_SHIFT(index));
853 	else if (port->mode == USB_DR_MODE_PERIPHERAL)
854 		value |= (PORT_CAP_DEVICE << PORTX_CAP_SHIFT(index));
855 	else if (port->mode == USB_DR_MODE_HOST)
856 		value |= (PORT_CAP_HOST << PORTX_CAP_SHIFT(index));
857 	else if (port->mode == USB_DR_MODE_OTG)
858 		value |= (PORT_CAP_OTG << PORTX_CAP_SHIFT(index));
859 
860 	padctl_writel(padctl, value, XUSB_PADCTL_USB2_PORT_CAP);
861 
862 	value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL0(index));
863 	value &= ~USB2_OTG_PD_ZI;
864 	value |= TERM_SEL;
865 	value &= ~HS_CURR_LEVEL(~0);
866 
867 	if (usb2->hs_curr_level_offset) {
868 		int hs_current_level;
869 
870 		hs_current_level = (int)priv->calib.hs_curr_level[index] +
871 						usb2->hs_curr_level_offset;
872 
873 		if (hs_current_level < 0)
874 			hs_current_level = 0;
875 		if (hs_current_level > 0x3f)
876 			hs_current_level = 0x3f;
877 
878 		value |= HS_CURR_LEVEL(hs_current_level);
879 	} else {
880 		value |= HS_CURR_LEVEL(priv->calib.hs_curr_level[index]);
881 	}
882 
883 	padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL0(index));
884 
885 	value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index));
886 	value &= ~TERM_RANGE_ADJ(~0);
887 	value |= TERM_RANGE_ADJ(priv->calib.hs_term_range_adj);
888 	value &= ~RPD_CTRL(~0);
889 	value |= RPD_CTRL(priv->calib.rpd_ctrl);
890 	padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index));
891 
892 	tegra186_utmi_pad_power_on(phy);
893 
894 	return 0;
895 }
896 
897 static int tegra186_utmi_phy_power_off(struct phy *phy)
898 {
899 	tegra186_utmi_pad_power_down(phy);
900 
901 	return 0;
902 }
903 
904 static int tegra186_utmi_phy_init(struct phy *phy)
905 {
906 	struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
907 	struct tegra_xusb_padctl *padctl = lane->pad->padctl;
908 	struct tegra_xusb_usb2_port *port;
909 	unsigned int index = lane->index;
910 	struct device *dev = padctl->dev;
911 	int err;
912 
913 	port = tegra_xusb_find_usb2_port(padctl, index);
914 	if (!port) {
915 		dev_err(dev, "no port found for USB2 lane %u\n", index);
916 		return -ENODEV;
917 	}
918 
919 	if (port->supply && port->mode == USB_DR_MODE_HOST) {
920 		err = regulator_enable(port->supply);
921 		if (err) {
922 			dev_err(dev, "failed to enable port %u VBUS: %d\n",
923 				index, err);
924 			return err;
925 		}
926 	}
927 
928 	return 0;
929 }
930 
931 static int tegra186_utmi_phy_exit(struct phy *phy)
932 {
933 	struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
934 	struct tegra_xusb_padctl *padctl = lane->pad->padctl;
935 	struct tegra_xusb_usb2_port *port;
936 	unsigned int index = lane->index;
937 	struct device *dev = padctl->dev;
938 	int err;
939 
940 	port = tegra_xusb_find_usb2_port(padctl, index);
941 	if (!port) {
942 		dev_err(dev, "no port found for USB2 lane %u\n", index);
943 		return -ENODEV;
944 	}
945 
946 	if (port->supply && port->mode == USB_DR_MODE_HOST) {
947 		err = regulator_disable(port->supply);
948 		if (err) {
949 			dev_err(dev, "failed to disable port %u VBUS: %d\n",
950 				index, err);
951 			return err;
952 		}
953 	}
954 
955 	return 0;
956 }
957 
958 static const struct phy_ops utmi_phy_ops = {
959 	.init = tegra186_utmi_phy_init,
960 	.exit = tegra186_utmi_phy_exit,
961 	.power_on = tegra186_utmi_phy_power_on,
962 	.power_off = tegra186_utmi_phy_power_off,
963 	.set_mode = tegra186_utmi_phy_set_mode,
964 	.owner = THIS_MODULE,
965 };
966 
967 static struct tegra_xusb_pad *
968 tegra186_usb2_pad_probe(struct tegra_xusb_padctl *padctl,
969 			const struct tegra_xusb_pad_soc *soc,
970 			struct device_node *np)
971 {
972 	struct tegra186_xusb_padctl *priv = to_tegra186_xusb_padctl(padctl);
973 	struct tegra_xusb_usb2_pad *usb2;
974 	struct tegra_xusb_pad *pad;
975 	int err;
976 
977 	usb2 = kzalloc(sizeof(*usb2), GFP_KERNEL);
978 	if (!usb2)
979 		return ERR_PTR(-ENOMEM);
980 
981 	pad = &usb2->base;
982 	pad->ops = &tegra186_usb2_lane_ops;
983 	pad->soc = soc;
984 
985 	err = tegra_xusb_pad_init(pad, padctl, np);
986 	if (err < 0) {
987 		kfree(usb2);
988 		goto out;
989 	}
990 
991 	priv->usb2_trk_clk = devm_clk_get(&pad->dev, "trk");
992 	if (IS_ERR(priv->usb2_trk_clk)) {
993 		err = PTR_ERR(priv->usb2_trk_clk);
994 		dev_dbg(&pad->dev, "failed to get usb2 trk clock: %d\n", err);
995 		goto unregister;
996 	}
997 
998 	err = tegra_xusb_pad_register(pad, &utmi_phy_ops);
999 	if (err < 0)
1000 		goto unregister;
1001 
1002 	dev_set_drvdata(&pad->dev, pad);
1003 
1004 	return pad;
1005 
1006 unregister:
1007 	device_unregister(&pad->dev);
1008 out:
1009 	return ERR_PTR(err);
1010 }
1011 
1012 static void tegra186_usb2_pad_remove(struct tegra_xusb_pad *pad)
1013 {
1014 	struct tegra_xusb_usb2_pad *usb2 = to_usb2_pad(pad);
1015 
1016 	kfree(usb2);
1017 }
1018 
1019 static const struct tegra_xusb_pad_ops tegra186_usb2_pad_ops = {
1020 	.probe = tegra186_usb2_pad_probe,
1021 	.remove = tegra186_usb2_pad_remove,
1022 };
1023 
1024 static const char * const tegra186_usb2_functions[] = {
1025 	"xusb",
1026 };
1027 
1028 static int tegra186_usb2_port_enable(struct tegra_xusb_port *port)
1029 {
1030 	return 0;
1031 }
1032 
1033 static void tegra186_usb2_port_disable(struct tegra_xusb_port *port)
1034 {
1035 }
1036 
1037 static struct tegra_xusb_lane *
1038 tegra186_usb2_port_map(struct tegra_xusb_port *port)
1039 {
1040 	return tegra_xusb_find_lane(port->padctl, "usb2", port->index);
1041 }
1042 
1043 static const struct tegra_xusb_port_ops tegra186_usb2_port_ops = {
1044 	.release = tegra_xusb_usb2_port_release,
1045 	.remove = tegra_xusb_usb2_port_remove,
1046 	.enable = tegra186_usb2_port_enable,
1047 	.disable = tegra186_usb2_port_disable,
1048 	.map = tegra186_usb2_port_map,
1049 };
1050 
1051 /* SuperSpeed PHY support */
1052 static struct tegra_xusb_lane *
1053 tegra186_usb3_lane_probe(struct tegra_xusb_pad *pad, struct device_node *np,
1054 			 unsigned int index)
1055 {
1056 	struct tegra_xusb_usb3_lane *usb3;
1057 	int err;
1058 
1059 	usb3 = kzalloc(sizeof(*usb3), GFP_KERNEL);
1060 	if (!usb3)
1061 		return ERR_PTR(-ENOMEM);
1062 
1063 	INIT_LIST_HEAD(&usb3->base.list);
1064 	usb3->base.soc = &pad->soc->lanes[index];
1065 	usb3->base.index = index;
1066 	usb3->base.pad = pad;
1067 	usb3->base.np = np;
1068 
1069 	err = tegra_xusb_lane_parse_dt(&usb3->base, np);
1070 	if (err < 0) {
1071 		kfree(usb3);
1072 		return ERR_PTR(err);
1073 	}
1074 
1075 	return &usb3->base;
1076 }
1077 
1078 static void tegra186_usb3_lane_remove(struct tegra_xusb_lane *lane)
1079 {
1080 	struct tegra_xusb_usb3_lane *usb3 = to_usb3_lane(lane);
1081 
1082 	kfree(usb3);
1083 }
1084 
1085 static int tegra186_usb3_enable_phy_sleepwalk(struct tegra_xusb_lane *lane,
1086 					      enum usb_device_speed speed)
1087 {
1088 	struct tegra_xusb_padctl *padctl = lane->pad->padctl;
1089 	unsigned int index = lane->index;
1090 	u32 value;
1091 
1092 	mutex_lock(&padctl->lock);
1093 
1094 	value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM_1);
1095 	value |= SSPX_ELPG_CLAMP_EN_EARLY(index);
1096 	padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM_1);
1097 
1098 	usleep_range(100, 200);
1099 
1100 	value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM_1);
1101 	value |= SSPX_ELPG_CLAMP_EN(index);
1102 	padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM_1);
1103 
1104 	usleep_range(250, 350);
1105 
1106 	mutex_unlock(&padctl->lock);
1107 
1108 	return 0;
1109 }
1110 
1111 static int tegra186_usb3_disable_phy_sleepwalk(struct tegra_xusb_lane *lane)
1112 {
1113 	struct tegra_xusb_padctl *padctl = lane->pad->padctl;
1114 	unsigned int index = lane->index;
1115 	u32 value;
1116 
1117 	mutex_lock(&padctl->lock);
1118 
1119 	value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM_1);
1120 	value &= ~SSPX_ELPG_CLAMP_EN_EARLY(index);
1121 	padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM_1);
1122 
1123 	usleep_range(100, 200);
1124 
1125 	value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM_1);
1126 	value &= ~SSPX_ELPG_CLAMP_EN(index);
1127 	padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM_1);
1128 
1129 	mutex_unlock(&padctl->lock);
1130 
1131 	return 0;
1132 }
1133 
1134 static int tegra186_usb3_enable_phy_wake(struct tegra_xusb_lane *lane)
1135 {
1136 	struct tegra_xusb_padctl *padctl = lane->pad->padctl;
1137 	unsigned int index = lane->index;
1138 	u32 value;
1139 
1140 	mutex_lock(&padctl->lock);
1141 
1142 	value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
1143 	value &= ~ALL_WAKE_EVENTS;
1144 	value |= SS_PORT_WAKEUP_EVENT(index);
1145 	padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
1146 
1147 	usleep_range(10, 20);
1148 
1149 	value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
1150 	value &= ~ALL_WAKE_EVENTS;
1151 	value |= SS_PORT_WAKE_INTERRUPT_ENABLE(index);
1152 	padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
1153 
1154 	mutex_unlock(&padctl->lock);
1155 
1156 	return 0;
1157 }
1158 
1159 static int tegra186_usb3_disable_phy_wake(struct tegra_xusb_lane *lane)
1160 {
1161 	struct tegra_xusb_padctl *padctl = lane->pad->padctl;
1162 	unsigned int index = lane->index;
1163 	u32 value;
1164 
1165 	mutex_lock(&padctl->lock);
1166 
1167 	value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
1168 	value &= ~ALL_WAKE_EVENTS;
1169 	value &= ~SS_PORT_WAKE_INTERRUPT_ENABLE(index);
1170 	padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
1171 
1172 	usleep_range(10, 20);
1173 
1174 	value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
1175 	value &= ~ALL_WAKE_EVENTS;
1176 	value |= SS_PORT_WAKEUP_EVENT(index);
1177 	padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
1178 
1179 	mutex_unlock(&padctl->lock);
1180 
1181 	return 0;
1182 }
1183 
1184 static bool tegra186_usb3_phy_remote_wake_detected(struct tegra_xusb_lane *lane)
1185 {
1186 	struct tegra_xusb_padctl *padctl = lane->pad->padctl;
1187 	unsigned int index = lane->index;
1188 	u32 value;
1189 
1190 	value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
1191 	if ((value & SS_PORT_WAKE_INTERRUPT_ENABLE(index)) && (value & SS_PORT_WAKEUP_EVENT(index)))
1192 		return true;
1193 
1194 	return false;
1195 }
1196 
1197 static const struct tegra_xusb_lane_ops tegra186_usb3_lane_ops = {
1198 	.probe = tegra186_usb3_lane_probe,
1199 	.remove = tegra186_usb3_lane_remove,
1200 	.enable_phy_sleepwalk = tegra186_usb3_enable_phy_sleepwalk,
1201 	.disable_phy_sleepwalk = tegra186_usb3_disable_phy_sleepwalk,
1202 	.enable_phy_wake = tegra186_usb3_enable_phy_wake,
1203 	.disable_phy_wake = tegra186_usb3_disable_phy_wake,
1204 	.remote_wake_detected = tegra186_usb3_phy_remote_wake_detected,
1205 };
1206 
1207 static int tegra186_usb3_port_enable(struct tegra_xusb_port *port)
1208 {
1209 	return 0;
1210 }
1211 
1212 static void tegra186_usb3_port_disable(struct tegra_xusb_port *port)
1213 {
1214 }
1215 
1216 static struct tegra_xusb_lane *
1217 tegra186_usb3_port_map(struct tegra_xusb_port *port)
1218 {
1219 	return tegra_xusb_find_lane(port->padctl, "usb3", port->index);
1220 }
1221 
1222 static const struct tegra_xusb_port_ops tegra186_usb3_port_ops = {
1223 	.release = tegra_xusb_usb3_port_release,
1224 	.enable = tegra186_usb3_port_enable,
1225 	.disable = tegra186_usb3_port_disable,
1226 	.map = tegra186_usb3_port_map,
1227 };
1228 
1229 static int tegra186_usb3_phy_power_on(struct phy *phy)
1230 {
1231 	struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
1232 	struct tegra_xusb_padctl *padctl = lane->pad->padctl;
1233 	struct tegra_xusb_usb3_port *port;
1234 	struct tegra_xusb_usb2_port *usb2;
1235 	unsigned int index = lane->index;
1236 	struct device *dev = padctl->dev;
1237 	u32 value;
1238 
1239 	port = tegra_xusb_find_usb3_port(padctl, index);
1240 	if (!port) {
1241 		dev_err(dev, "no port found for USB3 lane %u\n", index);
1242 		return -ENODEV;
1243 	}
1244 
1245 	usb2 = tegra_xusb_find_usb2_port(padctl, port->port);
1246 	if (!usb2) {
1247 		dev_err(dev, "no companion port found for USB3 lane %u\n",
1248 			index);
1249 		return -ENODEV;
1250 	}
1251 
1252 	mutex_lock(&padctl->lock);
1253 
1254 	value = padctl_readl(padctl, XUSB_PADCTL_SS_PORT_CAP);
1255 	value &= ~(PORT_CAP_MASK << PORTX_CAP_SHIFT(index));
1256 
1257 	if (usb2->mode == USB_DR_MODE_UNKNOWN)
1258 		value |= (PORT_CAP_DISABLED << PORTX_CAP_SHIFT(index));
1259 	else if (usb2->mode == USB_DR_MODE_PERIPHERAL)
1260 		value |= (PORT_CAP_DEVICE << PORTX_CAP_SHIFT(index));
1261 	else if (usb2->mode == USB_DR_MODE_HOST)
1262 		value |= (PORT_CAP_HOST << PORTX_CAP_SHIFT(index));
1263 	else if (usb2->mode == USB_DR_MODE_OTG)
1264 		value |= (PORT_CAP_OTG << PORTX_CAP_SHIFT(index));
1265 
1266 	padctl_writel(padctl, value, XUSB_PADCTL_SS_PORT_CAP);
1267 
1268 	if (padctl->soc->supports_gen2 && port->disable_gen2) {
1269 		value = padctl_readl(padctl, XUSB_PADCTL_SS_PORT_CFG);
1270 		value &= ~(PORTX_SPEED_SUPPORT_MASK <<
1271 			PORTX_SPEED_SUPPORT_SHIFT(index));
1272 		value |= (PORT_SPEED_SUPPORT_GEN1 <<
1273 			PORTX_SPEED_SUPPORT_SHIFT(index));
1274 		padctl_writel(padctl, value, XUSB_PADCTL_SS_PORT_CFG);
1275 	}
1276 
1277 	value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM_1);
1278 	value &= ~SSPX_ELPG_VCORE_DOWN(index);
1279 	padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM_1);
1280 
1281 	usleep_range(100, 200);
1282 
1283 	value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM_1);
1284 	value &= ~SSPX_ELPG_CLAMP_EN_EARLY(index);
1285 	padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM_1);
1286 
1287 	usleep_range(100, 200);
1288 
1289 	value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM_1);
1290 	value &= ~SSPX_ELPG_CLAMP_EN(index);
1291 	padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM_1);
1292 
1293 	mutex_unlock(&padctl->lock);
1294 
1295 	return 0;
1296 }
1297 
1298 static int tegra186_usb3_phy_power_off(struct phy *phy)
1299 {
1300 	struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
1301 	struct tegra_xusb_padctl *padctl = lane->pad->padctl;
1302 	struct tegra_xusb_usb3_port *port;
1303 	unsigned int index = lane->index;
1304 	struct device *dev = padctl->dev;
1305 	u32 value;
1306 
1307 	port = tegra_xusb_find_usb3_port(padctl, index);
1308 	if (!port) {
1309 		dev_err(dev, "no port found for USB3 lane %u\n", index);
1310 		return -ENODEV;
1311 	}
1312 
1313 	mutex_lock(&padctl->lock);
1314 
1315 	value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM_1);
1316 	value |= SSPX_ELPG_CLAMP_EN_EARLY(index);
1317 	padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM_1);
1318 
1319 	usleep_range(100, 200);
1320 
1321 	value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM_1);
1322 	value |= SSPX_ELPG_CLAMP_EN(index);
1323 	padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM_1);
1324 
1325 	usleep_range(250, 350);
1326 
1327 	value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM_1);
1328 	value |= SSPX_ELPG_VCORE_DOWN(index);
1329 	padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM_1);
1330 
1331 	mutex_unlock(&padctl->lock);
1332 
1333 	return 0;
1334 }
1335 
1336 static int tegra186_usb3_phy_init(struct phy *phy)
1337 {
1338 	return 0;
1339 }
1340 
1341 static int tegra186_usb3_phy_exit(struct phy *phy)
1342 {
1343 	return 0;
1344 }
1345 
1346 static const struct phy_ops usb3_phy_ops = {
1347 	.init = tegra186_usb3_phy_init,
1348 	.exit = tegra186_usb3_phy_exit,
1349 	.power_on = tegra186_usb3_phy_power_on,
1350 	.power_off = tegra186_usb3_phy_power_off,
1351 	.owner = THIS_MODULE,
1352 };
1353 
1354 static struct tegra_xusb_pad *
1355 tegra186_usb3_pad_probe(struct tegra_xusb_padctl *padctl,
1356 			const struct tegra_xusb_pad_soc *soc,
1357 			struct device_node *np)
1358 {
1359 	struct tegra_xusb_usb3_pad *usb3;
1360 	struct tegra_xusb_pad *pad;
1361 	int err;
1362 
1363 	usb3 = kzalloc(sizeof(*usb3), GFP_KERNEL);
1364 	if (!usb3)
1365 		return ERR_PTR(-ENOMEM);
1366 
1367 	pad = &usb3->base;
1368 	pad->ops = &tegra186_usb3_lane_ops;
1369 	pad->soc = soc;
1370 
1371 	err = tegra_xusb_pad_init(pad, padctl, np);
1372 	if (err < 0) {
1373 		kfree(usb3);
1374 		goto out;
1375 	}
1376 
1377 	err = tegra_xusb_pad_register(pad, &usb3_phy_ops);
1378 	if (err < 0)
1379 		goto unregister;
1380 
1381 	dev_set_drvdata(&pad->dev, pad);
1382 
1383 	return pad;
1384 
1385 unregister:
1386 	device_unregister(&pad->dev);
1387 out:
1388 	return ERR_PTR(err);
1389 }
1390 
1391 static void tegra186_usb3_pad_remove(struct tegra_xusb_pad *pad)
1392 {
1393 	struct tegra_xusb_usb2_pad *usb2 = to_usb2_pad(pad);
1394 
1395 	kfree(usb2);
1396 }
1397 
1398 static const struct tegra_xusb_pad_ops tegra186_usb3_pad_ops = {
1399 	.probe = tegra186_usb3_pad_probe,
1400 	.remove = tegra186_usb3_pad_remove,
1401 };
1402 
1403 static const char * const tegra186_usb3_functions[] = {
1404 	"xusb",
1405 };
1406 
1407 static int
1408 tegra186_xusb_read_fuse_calibration(struct tegra186_xusb_padctl *padctl)
1409 {
1410 	struct device *dev = padctl->base.dev;
1411 	unsigned int i, count;
1412 	u32 value, *level;
1413 	int err;
1414 
1415 	count = padctl->base.soc->ports.usb2.count;
1416 
1417 	level = devm_kcalloc(dev, count, sizeof(u32), GFP_KERNEL);
1418 	if (!level)
1419 		return -ENOMEM;
1420 
1421 	err = tegra_fuse_readl(TEGRA_FUSE_SKU_CALIB_0, &value);
1422 	if (err)
1423 		return dev_err_probe(dev, err,
1424 				     "failed to read calibration fuse\n");
1425 
1426 	dev_dbg(dev, "FUSE_USB_CALIB_0 %#x\n", value);
1427 
1428 	for (i = 0; i < count; i++)
1429 		level[i] = (value >> HS_CURR_LEVEL_PADX_SHIFT(i)) &
1430 				HS_CURR_LEVEL_PAD_MASK;
1431 
1432 	padctl->calib.hs_curr_level = level;
1433 
1434 	padctl->calib.hs_squelch = (value >> HS_SQUELCH_SHIFT) &
1435 					HS_SQUELCH_MASK;
1436 	padctl->calib.hs_term_range_adj = (value >> HS_TERM_RANGE_ADJ_SHIFT) &
1437 						HS_TERM_RANGE_ADJ_MASK;
1438 
1439 	err = tegra_fuse_readl(TEGRA_FUSE_USB_CALIB_EXT_0, &value);
1440 	if (err) {
1441 		dev_err(dev, "failed to read calibration fuse: %d\n", err);
1442 		return err;
1443 	}
1444 
1445 	dev_dbg(dev, "FUSE_USB_CALIB_EXT_0 %#x\n", value);
1446 
1447 	padctl->calib.rpd_ctrl = (value >> RPD_CTRL_SHIFT) & RPD_CTRL_MASK;
1448 
1449 	return 0;
1450 }
1451 
1452 static struct tegra_xusb_padctl *
1453 tegra186_xusb_padctl_probe(struct device *dev,
1454 			   const struct tegra_xusb_padctl_soc *soc)
1455 {
1456 	struct platform_device *pdev = to_platform_device(dev);
1457 	struct tegra186_xusb_padctl *priv;
1458 	struct resource *res;
1459 	int err;
1460 
1461 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
1462 	if (!priv)
1463 		return ERR_PTR(-ENOMEM);
1464 
1465 	priv->base.dev = dev;
1466 	priv->base.soc = soc;
1467 
1468 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ao");
1469 	priv->ao_regs = devm_ioremap_resource(dev, res);
1470 	if (IS_ERR(priv->ao_regs))
1471 		return ERR_CAST(priv->ao_regs);
1472 
1473 	err = tegra186_xusb_read_fuse_calibration(priv);
1474 	if (err < 0)
1475 		return ERR_PTR(err);
1476 
1477 	return &priv->base;
1478 }
1479 
1480 static void tegra186_xusb_padctl_save(struct tegra_xusb_padctl *padctl)
1481 {
1482 	struct tegra186_xusb_padctl *priv = to_tegra186_xusb_padctl(padctl);
1483 
1484 	priv->context.vbus_id = padctl_readl(padctl, USB2_VBUS_ID);
1485 	priv->context.usb2_pad_mux = padctl_readl(padctl, XUSB_PADCTL_USB2_PAD_MUX);
1486 	priv->context.usb2_port_cap = padctl_readl(padctl, XUSB_PADCTL_USB2_PORT_CAP);
1487 	priv->context.ss_port_cap = padctl_readl(padctl, XUSB_PADCTL_SS_PORT_CAP);
1488 }
1489 
1490 static void tegra186_xusb_padctl_restore(struct tegra_xusb_padctl *padctl)
1491 {
1492 	struct tegra186_xusb_padctl *priv = to_tegra186_xusb_padctl(padctl);
1493 
1494 	padctl_writel(padctl, priv->context.usb2_pad_mux, XUSB_PADCTL_USB2_PAD_MUX);
1495 	padctl_writel(padctl, priv->context.usb2_port_cap, XUSB_PADCTL_USB2_PORT_CAP);
1496 	padctl_writel(padctl, priv->context.ss_port_cap, XUSB_PADCTL_SS_PORT_CAP);
1497 	padctl_writel(padctl, priv->context.vbus_id, USB2_VBUS_ID);
1498 }
1499 
1500 static int tegra186_xusb_padctl_suspend_noirq(struct tegra_xusb_padctl *padctl)
1501 {
1502 	tegra186_xusb_padctl_save(padctl);
1503 
1504 	return 0;
1505 }
1506 
1507 static int tegra186_xusb_padctl_resume_noirq(struct tegra_xusb_padctl *padctl)
1508 {
1509 	tegra186_xusb_padctl_restore(padctl);
1510 
1511 	return 0;
1512 }
1513 
1514 static void tegra186_xusb_padctl_remove(struct tegra_xusb_padctl *padctl)
1515 {
1516 }
1517 
1518 static const struct tegra_xusb_padctl_ops tegra186_xusb_padctl_ops = {
1519 	.probe = tegra186_xusb_padctl_probe,
1520 	.remove = tegra186_xusb_padctl_remove,
1521 	.suspend_noirq = tegra186_xusb_padctl_suspend_noirq,
1522 	.resume_noirq = tegra186_xusb_padctl_resume_noirq,
1523 	.vbus_override = tegra186_xusb_padctl_vbus_override,
1524 	.utmi_pad_power_on = tegra186_utmi_pad_power_on,
1525 	.utmi_pad_power_down = tegra186_utmi_pad_power_down,
1526 };
1527 
1528 #if IS_ENABLED(CONFIG_ARCH_TEGRA_186_SOC)
1529 static const char * const tegra186_xusb_padctl_supply_names[] = {
1530 	"avdd-pll-erefeut",
1531 	"avdd-usb",
1532 	"vclamp-usb",
1533 	"vddio-hsic",
1534 };
1535 
1536 static const struct tegra_xusb_lane_soc tegra186_usb2_lanes[] = {
1537 	TEGRA186_LANE("usb2-0", 0,  0, 0, usb2),
1538 	TEGRA186_LANE("usb2-1", 0,  0, 0, usb2),
1539 	TEGRA186_LANE("usb2-2", 0,  0, 0, usb2),
1540 };
1541 
1542 static const struct tegra_xusb_pad_soc tegra186_usb2_pad = {
1543 	.name = "usb2",
1544 	.num_lanes = ARRAY_SIZE(tegra186_usb2_lanes),
1545 	.lanes = tegra186_usb2_lanes,
1546 	.ops = &tegra186_usb2_pad_ops,
1547 };
1548 
1549 static const struct tegra_xusb_lane_soc tegra186_usb3_lanes[] = {
1550 	TEGRA186_LANE("usb3-0", 0,  0, 0, usb3),
1551 	TEGRA186_LANE("usb3-1", 0,  0, 0, usb3),
1552 	TEGRA186_LANE("usb3-2", 0,  0, 0, usb3),
1553 };
1554 
1555 static const struct tegra_xusb_pad_soc tegra186_usb3_pad = {
1556 	.name = "usb3",
1557 	.num_lanes = ARRAY_SIZE(tegra186_usb3_lanes),
1558 	.lanes = tegra186_usb3_lanes,
1559 	.ops = &tegra186_usb3_pad_ops,
1560 };
1561 
1562 static const struct tegra_xusb_pad_soc * const tegra186_pads[] = {
1563 	&tegra186_usb2_pad,
1564 	&tegra186_usb3_pad,
1565 #if 0 /* TODO implement */
1566 	&tegra186_hsic_pad,
1567 #endif
1568 };
1569 
1570 const struct tegra_xusb_padctl_soc tegra186_xusb_padctl_soc = {
1571 	.num_pads = ARRAY_SIZE(tegra186_pads),
1572 	.pads = tegra186_pads,
1573 	.ports = {
1574 		.usb2 = {
1575 			.ops = &tegra186_usb2_port_ops,
1576 			.count = 3,
1577 		},
1578 #if 0 /* TODO implement */
1579 		.hsic = {
1580 			.ops = &tegra186_hsic_port_ops,
1581 			.count = 1,
1582 		},
1583 #endif
1584 		.usb3 = {
1585 			.ops = &tegra186_usb3_port_ops,
1586 			.count = 3,
1587 		},
1588 	},
1589 	.ops = &tegra186_xusb_padctl_ops,
1590 	.supply_names = tegra186_xusb_padctl_supply_names,
1591 	.num_supplies = ARRAY_SIZE(tegra186_xusb_padctl_supply_names),
1592 };
1593 EXPORT_SYMBOL_GPL(tegra186_xusb_padctl_soc);
1594 #endif
1595 
1596 #if IS_ENABLED(CONFIG_ARCH_TEGRA_194_SOC) || \
1597 	IS_ENABLED(CONFIG_ARCH_TEGRA_234_SOC)
1598 static const char * const tegra194_xusb_padctl_supply_names[] = {
1599 	"avdd-usb",
1600 	"vclamp-usb",
1601 };
1602 
1603 static const struct tegra_xusb_lane_soc tegra194_usb2_lanes[] = {
1604 	TEGRA186_LANE("usb2-0", 0,  0, 0, usb2),
1605 	TEGRA186_LANE("usb2-1", 0,  0, 0, usb2),
1606 	TEGRA186_LANE("usb2-2", 0,  0, 0, usb2),
1607 	TEGRA186_LANE("usb2-3", 0,  0, 0, usb2),
1608 };
1609 
1610 static const struct tegra_xusb_pad_soc tegra194_usb2_pad = {
1611 	.name = "usb2",
1612 	.num_lanes = ARRAY_SIZE(tegra194_usb2_lanes),
1613 	.lanes = tegra194_usb2_lanes,
1614 	.ops = &tegra186_usb2_pad_ops,
1615 };
1616 
1617 static const struct tegra_xusb_lane_soc tegra194_usb3_lanes[] = {
1618 	TEGRA186_LANE("usb3-0", 0,  0, 0, usb3),
1619 	TEGRA186_LANE("usb3-1", 0,  0, 0, usb3),
1620 	TEGRA186_LANE("usb3-2", 0,  0, 0, usb3),
1621 	TEGRA186_LANE("usb3-3", 0,  0, 0, usb3),
1622 };
1623 
1624 static const struct tegra_xusb_pad_soc tegra194_usb3_pad = {
1625 	.name = "usb3",
1626 	.num_lanes = ARRAY_SIZE(tegra194_usb3_lanes),
1627 	.lanes = tegra194_usb3_lanes,
1628 	.ops = &tegra186_usb3_pad_ops,
1629 };
1630 
1631 static const struct tegra_xusb_pad_soc * const tegra194_pads[] = {
1632 	&tegra194_usb2_pad,
1633 	&tegra194_usb3_pad,
1634 };
1635 
1636 const struct tegra_xusb_padctl_soc tegra194_xusb_padctl_soc = {
1637 	.num_pads = ARRAY_SIZE(tegra194_pads),
1638 	.pads = tegra194_pads,
1639 	.ports = {
1640 		.usb2 = {
1641 			.ops = &tegra186_usb2_port_ops,
1642 			.count = 4,
1643 		},
1644 		.usb3 = {
1645 			.ops = &tegra186_usb3_port_ops,
1646 			.count = 4,
1647 		},
1648 	},
1649 	.ops = &tegra186_xusb_padctl_ops,
1650 	.supply_names = tegra194_xusb_padctl_supply_names,
1651 	.num_supplies = ARRAY_SIZE(tegra194_xusb_padctl_supply_names),
1652 	.supports_gen2 = true,
1653 	.poll_trk_completed = true,
1654 };
1655 EXPORT_SYMBOL_GPL(tegra194_xusb_padctl_soc);
1656 
1657 const struct tegra_xusb_padctl_soc tegra234_xusb_padctl_soc = {
1658 	.num_pads = ARRAY_SIZE(tegra194_pads),
1659 	.pads = tegra194_pads,
1660 	.ports = {
1661 		.usb2 = {
1662 			.ops = &tegra186_usb2_port_ops,
1663 			.count = 4,
1664 		},
1665 		.usb3 = {
1666 			.ops = &tegra186_usb3_port_ops,
1667 			.count = 4,
1668 		},
1669 	},
1670 	.ops = &tegra186_xusb_padctl_ops,
1671 	.supply_names = tegra194_xusb_padctl_supply_names,
1672 	.num_supplies = ARRAY_SIZE(tegra194_xusb_padctl_supply_names),
1673 	.supports_gen2 = true,
1674 	.poll_trk_completed = true,
1675 	.trk_hw_mode = true,
1676 };
1677 EXPORT_SYMBOL_GPL(tegra234_xusb_padctl_soc);
1678 #endif
1679 
1680 MODULE_AUTHOR("JC Kuo <jckuo@nvidia.com>");
1681 MODULE_DESCRIPTION("NVIDIA Tegra186 XUSB Pad Controller driver");
1682 MODULE_LICENSE("GPL v2");
1683