1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2010 Google, Inc.
4 * Copyright (C) 2013 NVIDIA Corporation
12 #include <linux/delay.h>
13 #include <linux/err.h>
14 #include <linux/export.h>
15 #include <linux/gpio/consumer.h>
16 #include <linux/iopoll.h>
17 #include <linux/module.h>
19 #include <linux/of_device.h>
20 #include <linux/platform_device.h>
21 #include <linux/resource.h>
22 #include <linux/slab.h>
23 #include <linux/spinlock.h>
25 #include <linux/regulator/consumer.h>
27 #include <linux/usb/ehci_def.h>
28 #include <linux/usb/of.h>
29 #include <linux/usb/tegra_usb_phy.h>
30 #include <linux/usb/ulpi.h>
32 #define ULPI_VIEWPORT 0x170
34 /* PORTSC PTS/PHCD bits, Tegra20 only */
35 #define TEGRA_USB_PORTSC1 0x184
36 #define TEGRA_USB_PORTSC1_PTS(x) (((x) & 0x3) << 30)
37 #define TEGRA_USB_PORTSC1_PHCD BIT(23)
39 /* HOSTPC1 PTS/PHCD bits, Tegra30 and above */
40 #define TEGRA_USB_HOSTPC1_DEVLC 0x1b4
41 #define TEGRA_USB_HOSTPC1_DEVLC_PTS(x) (((x) & 0x7) << 29)
42 #define TEGRA_USB_HOSTPC1_DEVLC_PHCD BIT(22)
44 /* Bits of PORTSC1, which will get cleared by writing 1 into them */
45 #define TEGRA_PORTSC1_RWC_BITS (PORT_CSC | PORT_PEC | PORT_OCC)
47 #define USB_SUSP_CTRL 0x400
48 #define USB_WAKE_ON_RESUME_EN BIT(2)
49 #define USB_WAKE_ON_CNNT_EN_DEV BIT(3)
50 #define USB_WAKE_ON_DISCON_EN_DEV BIT(4)
51 #define USB_SUSP_CLR BIT(5)
52 #define USB_PHY_CLK_VALID BIT(7)
53 #define UTMIP_RESET BIT(11)
54 #define UHSIC_RESET BIT(11)
55 #define UTMIP_PHY_ENABLE BIT(12)
56 #define ULPI_PHY_ENABLE BIT(13)
57 #define USB_SUSP_SET BIT(14)
58 #define USB_WAKEUP_DEBOUNCE_COUNT(x) (((x) & 0x7) << 16)
60 #define USB_PHY_VBUS_SENSORS 0x404
61 #define B_SESS_VLD_WAKEUP_EN BIT(14)
62 #define A_SESS_VLD_WAKEUP_EN BIT(22)
63 #define A_VBUS_VLD_WAKEUP_EN BIT(30)
65 #define USB_PHY_VBUS_WAKEUP_ID 0x408
66 #define ID_INT_EN BIT(0)
67 #define ID_CHG_DET BIT(1)
68 #define VBUS_WAKEUP_INT_EN BIT(8)
69 #define VBUS_WAKEUP_CHG_DET BIT(9)
70 #define VBUS_WAKEUP_STS BIT(10)
71 #define VBUS_WAKEUP_WAKEUP_EN BIT(30)
73 #define USB1_LEGACY_CTRL 0x410
74 #define USB1_NO_LEGACY_MODE BIT(0)
75 #define USB1_VBUS_SENSE_CTL_MASK (3 << 1)
76 #define USB1_VBUS_SENSE_CTL_VBUS_WAKEUP (0 << 1)
77 #define USB1_VBUS_SENSE_CTL_AB_SESS_VLD_OR_VBUS_WAKEUP \
79 #define USB1_VBUS_SENSE_CTL_AB_SESS_VLD (2 << 1)
80 #define USB1_VBUS_SENSE_CTL_A_SESS_VLD (3 << 1)
82 #define ULPI_TIMING_CTRL_0 0x424
83 #define ULPI_OUTPUT_PINMUX_BYP BIT(10)
84 #define ULPI_CLKOUT_PINMUX_BYP BIT(11)
86 #define ULPI_TIMING_CTRL_1 0x428
87 #define ULPI_DATA_TRIMMER_LOAD BIT(0)
88 #define ULPI_DATA_TRIMMER_SEL(x) (((x) & 0x7) << 1)
89 #define ULPI_STPDIRNXT_TRIMMER_LOAD BIT(16)
90 #define ULPI_STPDIRNXT_TRIMMER_SEL(x) (((x) & 0x7) << 17)
91 #define ULPI_DIR_TRIMMER_LOAD BIT(24)
92 #define ULPI_DIR_TRIMMER_SEL(x) (((x) & 0x7) << 25)
94 #define UTMIP_PLL_CFG1 0x804
95 #define UTMIP_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0)
96 #define UTMIP_PLLU_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 27)
98 #define UTMIP_XCVR_CFG0 0x808
99 #define UTMIP_XCVR_SETUP(x) (((x) & 0xf) << 0)
100 #define UTMIP_XCVR_SETUP_MSB(x) ((((x) & 0x70) >> 4) << 22)
101 #define UTMIP_XCVR_LSRSLEW(x) (((x) & 0x3) << 8)
102 #define UTMIP_XCVR_LSFSLEW(x) (((x) & 0x3) << 10)
103 #define UTMIP_FORCE_PD_POWERDOWN BIT(14)
104 #define UTMIP_FORCE_PD2_POWERDOWN BIT(16)
105 #define UTMIP_FORCE_PDZI_POWERDOWN BIT(18)
106 #define UTMIP_XCVR_LSBIAS_SEL BIT(21)
107 #define UTMIP_XCVR_HSSLEW(x) (((x) & 0x3) << 4)
108 #define UTMIP_XCVR_HSSLEW_MSB(x) ((((x) & 0x1fc) >> 2) << 25)
110 #define UTMIP_BIAS_CFG0 0x80c
111 #define UTMIP_OTGPD BIT(11)
112 #define UTMIP_BIASPD BIT(10)
113 #define UTMIP_HSSQUELCH_LEVEL(x) (((x) & 0x3) << 0)
114 #define UTMIP_HSDISCON_LEVEL(x) (((x) & 0x3) << 2)
115 #define UTMIP_HSDISCON_LEVEL_MSB(x) ((((x) & 0x4) >> 2) << 24)
117 #define UTMIP_HSRX_CFG0 0x810
118 #define UTMIP_ELASTIC_LIMIT(x) (((x) & 0x1f) << 10)
119 #define UTMIP_IDLE_WAIT(x) (((x) & 0x1f) << 15)
121 #define UTMIP_HSRX_CFG1 0x814
122 #define UTMIP_HS_SYNC_START_DLY(x) (((x) & 0x1f) << 1)
124 #define UTMIP_TX_CFG0 0x820
125 #define UTMIP_FS_PREABMLE_J BIT(19)
126 #define UTMIP_HS_DISCON_DISABLE BIT(8)
128 #define UTMIP_MISC_CFG0 0x824
129 #define UTMIP_DPDM_OBSERVE BIT(26)
130 #define UTMIP_DPDM_OBSERVE_SEL(x) (((x) & 0xf) << 27)
131 #define UTMIP_DPDM_OBSERVE_SEL_FS_J UTMIP_DPDM_OBSERVE_SEL(0xf)
132 #define UTMIP_DPDM_OBSERVE_SEL_FS_K UTMIP_DPDM_OBSERVE_SEL(0xe)
133 #define UTMIP_DPDM_OBSERVE_SEL_FS_SE1 UTMIP_DPDM_OBSERVE_SEL(0xd)
134 #define UTMIP_DPDM_OBSERVE_SEL_FS_SE0 UTMIP_DPDM_OBSERVE_SEL(0xc)
135 #define UTMIP_SUSPEND_EXIT_ON_EDGE BIT(22)
137 #define UTMIP_MISC_CFG1 0x828
138 #define UTMIP_PLL_ACTIVE_DLY_COUNT(x) (((x) & 0x1f) << 18)
139 #define UTMIP_PLLU_STABLE_COUNT(x) (((x) & 0xfff) << 6)
141 #define UTMIP_DEBOUNCE_CFG0 0x82c
142 #define UTMIP_BIAS_DEBOUNCE_A(x) (((x) & 0xffff) << 0)
144 #define UTMIP_BAT_CHRG_CFG0 0x830
145 #define UTMIP_PD_CHRG BIT(0)
147 #define UTMIP_SPARE_CFG0 0x834
148 #define FUSE_SETUP_SEL BIT(3)
150 #define UTMIP_XCVR_CFG1 0x838
151 #define UTMIP_FORCE_PDDISC_POWERDOWN BIT(0)
152 #define UTMIP_FORCE_PDCHRP_POWERDOWN BIT(2)
153 #define UTMIP_FORCE_PDDR_POWERDOWN BIT(4)
154 #define UTMIP_XCVR_TERM_RANGE_ADJ(x) (((x) & 0xf) << 18)
156 #define UTMIP_BIAS_CFG1 0x83c
157 #define UTMIP_BIAS_PDTRK_COUNT(x) (((x) & 0x1f) << 3)
159 /* For Tegra30 and above only, the address is different in Tegra20 */
160 #define USB_USBMODE 0x1f8
161 #define USB_USBMODE_MASK (3 << 0)
162 #define USB_USBMODE_HOST (3 << 0)
163 #define USB_USBMODE_DEVICE (2 << 0)
165 #define PMC_USB_AO 0xf0
166 #define VBUS_WAKEUP_PD_P0 BIT(2)
167 #define ID_PD_P0 BIT(3)
169 static DEFINE_SPINLOCK(utmip_pad_lock);
170 static unsigned int utmip_pad_count;
172 struct tegra_xtal_freq {
181 static const struct tegra_xtal_freq tegra_freq_table[] = {
184 .enable_delay = 0x02,
185 .stable_count = 0x2F,
186 .active_delay = 0x04,
187 .xtal_freq_count = 0x76,
192 .enable_delay = 0x02,
193 .stable_count = 0x33,
194 .active_delay = 0x05,
195 .xtal_freq_count = 0x7F,
200 .enable_delay = 0x03,
201 .stable_count = 0x4B,
202 .active_delay = 0x06,
203 .xtal_freq_count = 0xBB,
208 .enable_delay = 0x04,
209 .stable_count = 0x66,
210 .active_delay = 0x09,
211 .xtal_freq_count = 0xFE,
216 static inline struct tegra_usb_phy *to_tegra_usb_phy(struct usb_phy *u_phy)
218 return container_of(u_phy, struct tegra_usb_phy, u_phy);
221 static void set_pts(struct tegra_usb_phy *phy, u8 pts_val)
223 void __iomem *base = phy->regs;
226 if (phy->soc_config->has_hostpc) {
227 val = readl_relaxed(base + TEGRA_USB_HOSTPC1_DEVLC);
228 val &= ~TEGRA_USB_HOSTPC1_DEVLC_PTS(~0);
229 val |= TEGRA_USB_HOSTPC1_DEVLC_PTS(pts_val);
230 writel_relaxed(val, base + TEGRA_USB_HOSTPC1_DEVLC);
232 val = readl_relaxed(base + TEGRA_USB_PORTSC1);
233 val &= ~TEGRA_PORTSC1_RWC_BITS;
234 val &= ~TEGRA_USB_PORTSC1_PTS(~0);
235 val |= TEGRA_USB_PORTSC1_PTS(pts_val);
236 writel_relaxed(val, base + TEGRA_USB_PORTSC1);
240 static void set_phcd(struct tegra_usb_phy *phy, bool enable)
242 void __iomem *base = phy->regs;
245 if (phy->soc_config->has_hostpc) {
246 val = readl_relaxed(base + TEGRA_USB_HOSTPC1_DEVLC);
248 val |= TEGRA_USB_HOSTPC1_DEVLC_PHCD;
250 val &= ~TEGRA_USB_HOSTPC1_DEVLC_PHCD;
251 writel_relaxed(val, base + TEGRA_USB_HOSTPC1_DEVLC);
253 val = readl_relaxed(base + TEGRA_USB_PORTSC1) & ~PORT_RWC_BITS;
255 val |= TEGRA_USB_PORTSC1_PHCD;
257 val &= ~TEGRA_USB_PORTSC1_PHCD;
258 writel_relaxed(val, base + TEGRA_USB_PORTSC1);
262 static int utmip_pad_open(struct tegra_usb_phy *phy)
266 ret = clk_prepare_enable(phy->pad_clk);
268 dev_err(phy->u_phy.dev,
269 "Failed to enable UTMI-pads clock: %d\n", ret);
273 spin_lock(&utmip_pad_lock);
275 ret = reset_control_deassert(phy->pad_rst);
277 dev_err(phy->u_phy.dev,
278 "Failed to initialize UTMI-pads reset: %d\n", ret);
282 ret = reset_control_assert(phy->pad_rst);
284 dev_err(phy->u_phy.dev,
285 "Failed to assert UTMI-pads reset: %d\n", ret);
291 ret = reset_control_deassert(phy->pad_rst);
293 dev_err(phy->u_phy.dev,
294 "Failed to deassert UTMI-pads reset: %d\n", ret);
296 spin_unlock(&utmip_pad_lock);
298 clk_disable_unprepare(phy->pad_clk);
303 static int utmip_pad_close(struct tegra_usb_phy *phy)
307 ret = clk_prepare_enable(phy->pad_clk);
309 dev_err(phy->u_phy.dev,
310 "Failed to enable UTMI-pads clock: %d\n", ret);
314 ret = reset_control_assert(phy->pad_rst);
316 dev_err(phy->u_phy.dev,
317 "Failed to assert UTMI-pads reset: %d\n", ret);
321 clk_disable_unprepare(phy->pad_clk);
326 static int utmip_pad_power_on(struct tegra_usb_phy *phy)
328 struct tegra_utmip_config *config = phy->config;
329 void __iomem *base = phy->pad_regs;
333 err = clk_prepare_enable(phy->pad_clk);
337 spin_lock(&utmip_pad_lock);
339 if (utmip_pad_count++ == 0) {
340 val = readl_relaxed(base + UTMIP_BIAS_CFG0);
341 val &= ~(UTMIP_OTGPD | UTMIP_BIASPD);
343 if (phy->soc_config->requires_extra_tuning_parameters) {
344 val &= ~(UTMIP_HSSQUELCH_LEVEL(~0) |
345 UTMIP_HSDISCON_LEVEL(~0) |
346 UTMIP_HSDISCON_LEVEL_MSB(~0));
348 val |= UTMIP_HSSQUELCH_LEVEL(config->hssquelch_level);
349 val |= UTMIP_HSDISCON_LEVEL(config->hsdiscon_level);
350 val |= UTMIP_HSDISCON_LEVEL_MSB(config->hsdiscon_level);
352 writel_relaxed(val, base + UTMIP_BIAS_CFG0);
355 if (phy->pad_wakeup) {
356 phy->pad_wakeup = false;
360 spin_unlock(&utmip_pad_lock);
362 clk_disable_unprepare(phy->pad_clk);
367 static int utmip_pad_power_off(struct tegra_usb_phy *phy)
369 void __iomem *base = phy->pad_regs;
373 ret = clk_prepare_enable(phy->pad_clk);
377 spin_lock(&utmip_pad_lock);
379 if (!utmip_pad_count) {
380 dev_err(phy->u_phy.dev, "UTMIP pad already powered off\n");
386 * In accordance to TRM, OTG and Bias pad circuits could be turned off
387 * to save power if wake is enabled, but the VBUS-change detection
388 * method is board-specific and these circuits may need to be enabled
389 * to generate wakeup event, hence we will just keep them both enabled.
391 if (phy->wakeup_enabled) {
392 phy->pad_wakeup = true;
396 if (--utmip_pad_count == 0) {
397 val = readl_relaxed(base + UTMIP_BIAS_CFG0);
398 val |= UTMIP_OTGPD | UTMIP_BIASPD;
399 writel_relaxed(val, base + UTMIP_BIAS_CFG0);
402 spin_unlock(&utmip_pad_lock);
404 clk_disable_unprepare(phy->pad_clk);
409 static int utmi_wait_register(void __iomem *reg, u32 mask, u32 result)
413 return readl_relaxed_poll_timeout(reg, tmp, (tmp & mask) == result,
417 static void utmi_phy_clk_disable(struct tegra_usb_phy *phy)
419 void __iomem *base = phy->regs;
423 * The USB driver may have already initiated the phy clock
424 * disable so wait to see if the clock turns off and if not
425 * then proceed with gating the clock.
427 if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, 0) == 0)
430 if (phy->is_legacy_phy) {
431 val = readl_relaxed(base + USB_SUSP_CTRL);
433 writel_relaxed(val, base + USB_SUSP_CTRL);
435 usleep_range(10, 100);
437 val = readl_relaxed(base + USB_SUSP_CTRL);
438 val &= ~USB_SUSP_SET;
439 writel_relaxed(val, base + USB_SUSP_CTRL);
444 if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, 0))
445 dev_err(phy->u_phy.dev,
446 "Timeout waiting for PHY to stabilize on disable\n");
449 static void utmi_phy_clk_enable(struct tegra_usb_phy *phy)
451 void __iomem *base = phy->regs;
455 * The USB driver may have already initiated the phy clock
456 * enable so wait to see if the clock turns on and if not
457 * then proceed with ungating the clock.
459 if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID,
460 USB_PHY_CLK_VALID) == 0)
463 if (phy->is_legacy_phy) {
464 val = readl_relaxed(base + USB_SUSP_CTRL);
466 writel_relaxed(val, base + USB_SUSP_CTRL);
468 usleep_range(10, 100);
470 val = readl_relaxed(base + USB_SUSP_CTRL);
471 val &= ~USB_SUSP_CLR;
472 writel_relaxed(val, base + USB_SUSP_CTRL);
474 set_phcd(phy, false);
477 if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID,
479 dev_err(phy->u_phy.dev,
480 "Timeout waiting for PHY to stabilize on enable\n");
483 static int utmi_phy_power_on(struct tegra_usb_phy *phy)
485 struct tegra_utmip_config *config = phy->config;
486 void __iomem *base = phy->regs;
490 val = readl_relaxed(base + USB_SUSP_CTRL);
492 writel_relaxed(val, base + USB_SUSP_CTRL);
494 if (phy->is_legacy_phy) {
495 val = readl_relaxed(base + USB1_LEGACY_CTRL);
496 val |= USB1_NO_LEGACY_MODE;
497 writel_relaxed(val, base + USB1_LEGACY_CTRL);
500 val = readl_relaxed(base + UTMIP_TX_CFG0);
501 val |= UTMIP_FS_PREABMLE_J;
502 writel_relaxed(val, base + UTMIP_TX_CFG0);
504 val = readl_relaxed(base + UTMIP_HSRX_CFG0);
505 val &= ~(UTMIP_IDLE_WAIT(~0) | UTMIP_ELASTIC_LIMIT(~0));
506 val |= UTMIP_IDLE_WAIT(config->idle_wait_delay);
507 val |= UTMIP_ELASTIC_LIMIT(config->elastic_limit);
508 writel_relaxed(val, base + UTMIP_HSRX_CFG0);
510 val = readl_relaxed(base + UTMIP_HSRX_CFG1);
511 val &= ~UTMIP_HS_SYNC_START_DLY(~0);
512 val |= UTMIP_HS_SYNC_START_DLY(config->hssync_start_delay);
513 writel_relaxed(val, base + UTMIP_HSRX_CFG1);
515 val = readl_relaxed(base + UTMIP_DEBOUNCE_CFG0);
516 val &= ~UTMIP_BIAS_DEBOUNCE_A(~0);
517 val |= UTMIP_BIAS_DEBOUNCE_A(phy->freq->debounce);
518 writel_relaxed(val, base + UTMIP_DEBOUNCE_CFG0);
520 val = readl_relaxed(base + UTMIP_MISC_CFG0);
521 val &= ~UTMIP_SUSPEND_EXIT_ON_EDGE;
522 writel_relaxed(val, base + UTMIP_MISC_CFG0);
524 if (!phy->soc_config->utmi_pll_config_in_car_module) {
525 val = readl_relaxed(base + UTMIP_MISC_CFG1);
526 val &= ~(UTMIP_PLL_ACTIVE_DLY_COUNT(~0) |
527 UTMIP_PLLU_STABLE_COUNT(~0));
528 val |= UTMIP_PLL_ACTIVE_DLY_COUNT(phy->freq->active_delay) |
529 UTMIP_PLLU_STABLE_COUNT(phy->freq->stable_count);
530 writel_relaxed(val, base + UTMIP_MISC_CFG1);
532 val = readl_relaxed(base + UTMIP_PLL_CFG1);
533 val &= ~(UTMIP_XTAL_FREQ_COUNT(~0) |
534 UTMIP_PLLU_ENABLE_DLY_COUNT(~0));
535 val |= UTMIP_XTAL_FREQ_COUNT(phy->freq->xtal_freq_count) |
536 UTMIP_PLLU_ENABLE_DLY_COUNT(phy->freq->enable_delay);
537 writel_relaxed(val, base + UTMIP_PLL_CFG1);
540 val = readl_relaxed(base + USB_SUSP_CTRL);
541 val &= ~USB_WAKE_ON_RESUME_EN;
542 writel_relaxed(val, base + USB_SUSP_CTRL);
544 if (phy->mode != USB_DR_MODE_HOST) {
545 val = readl_relaxed(base + USB_SUSP_CTRL);
546 val &= ~(USB_WAKE_ON_CNNT_EN_DEV | USB_WAKE_ON_DISCON_EN_DEV);
547 writel_relaxed(val, base + USB_SUSP_CTRL);
549 val = readl_relaxed(base + USB_PHY_VBUS_WAKEUP_ID);
550 val &= ~VBUS_WAKEUP_WAKEUP_EN;
551 val &= ~(ID_CHG_DET | VBUS_WAKEUP_CHG_DET);
552 writel_relaxed(val, base + USB_PHY_VBUS_WAKEUP_ID);
554 val = readl_relaxed(base + USB_PHY_VBUS_SENSORS);
555 val &= ~(A_VBUS_VLD_WAKEUP_EN | A_SESS_VLD_WAKEUP_EN);
556 val &= ~(B_SESS_VLD_WAKEUP_EN);
557 writel_relaxed(val, base + USB_PHY_VBUS_SENSORS);
559 val = readl_relaxed(base + UTMIP_BAT_CHRG_CFG0);
560 val &= ~UTMIP_PD_CHRG;
561 writel_relaxed(val, base + UTMIP_BAT_CHRG_CFG0);
563 val = readl_relaxed(base + UTMIP_BAT_CHRG_CFG0);
564 val |= UTMIP_PD_CHRG;
565 writel_relaxed(val, base + UTMIP_BAT_CHRG_CFG0);
568 err = utmip_pad_power_on(phy);
572 val = readl_relaxed(base + UTMIP_XCVR_CFG0);
573 val &= ~(UTMIP_FORCE_PD_POWERDOWN | UTMIP_FORCE_PD2_POWERDOWN |
574 UTMIP_FORCE_PDZI_POWERDOWN | UTMIP_XCVR_LSBIAS_SEL |
575 UTMIP_XCVR_SETUP(~0) | UTMIP_XCVR_SETUP_MSB(~0) |
576 UTMIP_XCVR_LSFSLEW(~0) | UTMIP_XCVR_LSRSLEW(~0));
578 if (!config->xcvr_setup_use_fuses) {
579 val |= UTMIP_XCVR_SETUP(config->xcvr_setup);
580 val |= UTMIP_XCVR_SETUP_MSB(config->xcvr_setup);
582 val |= UTMIP_XCVR_LSFSLEW(config->xcvr_lsfslew);
583 val |= UTMIP_XCVR_LSRSLEW(config->xcvr_lsrslew);
585 if (phy->soc_config->requires_extra_tuning_parameters) {
586 val &= ~(UTMIP_XCVR_HSSLEW(~0) | UTMIP_XCVR_HSSLEW_MSB(~0));
587 val |= UTMIP_XCVR_HSSLEW(config->xcvr_hsslew);
588 val |= UTMIP_XCVR_HSSLEW_MSB(config->xcvr_hsslew);
590 writel_relaxed(val, base + UTMIP_XCVR_CFG0);
592 val = readl_relaxed(base + UTMIP_XCVR_CFG1);
593 val &= ~(UTMIP_FORCE_PDDISC_POWERDOWN | UTMIP_FORCE_PDCHRP_POWERDOWN |
594 UTMIP_FORCE_PDDR_POWERDOWN | UTMIP_XCVR_TERM_RANGE_ADJ(~0));
595 val |= UTMIP_XCVR_TERM_RANGE_ADJ(config->term_range_adj);
596 writel_relaxed(val, base + UTMIP_XCVR_CFG1);
598 val = readl_relaxed(base + UTMIP_BIAS_CFG1);
599 val &= ~UTMIP_BIAS_PDTRK_COUNT(~0);
600 val |= UTMIP_BIAS_PDTRK_COUNT(0x5);
601 writel_relaxed(val, base + UTMIP_BIAS_CFG1);
603 val = readl_relaxed(base + UTMIP_SPARE_CFG0);
604 if (config->xcvr_setup_use_fuses)
605 val |= FUSE_SETUP_SEL;
607 val &= ~FUSE_SETUP_SEL;
608 writel_relaxed(val, base + UTMIP_SPARE_CFG0);
610 if (!phy->is_legacy_phy) {
611 val = readl_relaxed(base + USB_SUSP_CTRL);
612 val |= UTMIP_PHY_ENABLE;
613 writel_relaxed(val, base + USB_SUSP_CTRL);
616 val = readl_relaxed(base + USB_SUSP_CTRL);
618 writel_relaxed(val, base + USB_SUSP_CTRL);
620 if (phy->is_legacy_phy) {
621 val = readl_relaxed(base + USB1_LEGACY_CTRL);
622 val &= ~USB1_VBUS_SENSE_CTL_MASK;
623 val |= USB1_VBUS_SENSE_CTL_A_SESS_VLD;
624 writel_relaxed(val, base + USB1_LEGACY_CTRL);
626 val = readl_relaxed(base + USB_SUSP_CTRL);
627 val &= ~USB_SUSP_SET;
628 writel_relaxed(val, base + USB_SUSP_CTRL);
631 utmi_phy_clk_enable(phy);
633 if (phy->soc_config->requires_usbmode_setup) {
634 val = readl_relaxed(base + USB_USBMODE);
635 val &= ~USB_USBMODE_MASK;
636 if (phy->mode == USB_DR_MODE_HOST)
637 val |= USB_USBMODE_HOST;
639 val |= USB_USBMODE_DEVICE;
640 writel_relaxed(val, base + USB_USBMODE);
643 if (!phy->is_legacy_phy)
649 static int utmi_phy_power_off(struct tegra_usb_phy *phy)
651 void __iomem *base = phy->regs;
655 * Give hardware time to settle down after VBUS disconnection,
656 * otherwise PHY will immediately wake up from suspend.
658 if (phy->wakeup_enabled && phy->mode != USB_DR_MODE_HOST)
659 readl_relaxed_poll_timeout(base + USB_PHY_VBUS_WAKEUP_ID,
660 val, !(val & VBUS_WAKEUP_STS),
663 utmi_phy_clk_disable(phy);
665 /* PHY won't resume if reset is asserted */
666 if (!phy->wakeup_enabled) {
667 val = readl_relaxed(base + USB_SUSP_CTRL);
669 writel_relaxed(val, base + USB_SUSP_CTRL);
672 val = readl_relaxed(base + UTMIP_BAT_CHRG_CFG0);
673 val |= UTMIP_PD_CHRG;
674 writel_relaxed(val, base + UTMIP_BAT_CHRG_CFG0);
676 if (!phy->wakeup_enabled) {
677 val = readl_relaxed(base + UTMIP_XCVR_CFG0);
678 val |= UTMIP_FORCE_PD_POWERDOWN | UTMIP_FORCE_PD2_POWERDOWN |
679 UTMIP_FORCE_PDZI_POWERDOWN;
680 writel_relaxed(val, base + UTMIP_XCVR_CFG0);
683 val = readl_relaxed(base + UTMIP_XCVR_CFG1);
684 val |= UTMIP_FORCE_PDDISC_POWERDOWN | UTMIP_FORCE_PDCHRP_POWERDOWN |
685 UTMIP_FORCE_PDDR_POWERDOWN;
686 writel_relaxed(val, base + UTMIP_XCVR_CFG1);
688 if (phy->wakeup_enabled) {
689 val = readl_relaxed(base + USB_SUSP_CTRL);
690 val &= ~USB_WAKEUP_DEBOUNCE_COUNT(~0);
691 val |= USB_WAKEUP_DEBOUNCE_COUNT(5);
692 val |= USB_WAKE_ON_RESUME_EN;
693 writel_relaxed(val, base + USB_SUSP_CTRL);
696 * Ask VBUS sensor to generate wake event once cable is
699 if (phy->mode != USB_DR_MODE_HOST) {
700 val = readl_relaxed(base + USB_PHY_VBUS_WAKEUP_ID);
701 val |= VBUS_WAKEUP_WAKEUP_EN;
702 val &= ~(ID_CHG_DET | VBUS_WAKEUP_CHG_DET);
703 writel_relaxed(val, base + USB_PHY_VBUS_WAKEUP_ID);
705 val = readl_relaxed(base + USB_PHY_VBUS_SENSORS);
706 val |= A_VBUS_VLD_WAKEUP_EN;
707 writel_relaxed(val, base + USB_PHY_VBUS_SENSORS);
711 return utmip_pad_power_off(phy);
714 static void utmi_phy_preresume(struct tegra_usb_phy *phy)
716 void __iomem *base = phy->regs;
719 val = readl_relaxed(base + UTMIP_TX_CFG0);
720 val |= UTMIP_HS_DISCON_DISABLE;
721 writel_relaxed(val, base + UTMIP_TX_CFG0);
724 static void utmi_phy_postresume(struct tegra_usb_phy *phy)
726 void __iomem *base = phy->regs;
729 val = readl_relaxed(base + UTMIP_TX_CFG0);
730 val &= ~UTMIP_HS_DISCON_DISABLE;
731 writel_relaxed(val, base + UTMIP_TX_CFG0);
734 static void utmi_phy_restore_start(struct tegra_usb_phy *phy,
735 enum tegra_usb_phy_port_speed port_speed)
737 void __iomem *base = phy->regs;
740 val = readl_relaxed(base + UTMIP_MISC_CFG0);
741 val &= ~UTMIP_DPDM_OBSERVE_SEL(~0);
742 if (port_speed == TEGRA_USB_PHY_PORT_SPEED_LOW)
743 val |= UTMIP_DPDM_OBSERVE_SEL_FS_K;
745 val |= UTMIP_DPDM_OBSERVE_SEL_FS_J;
746 writel_relaxed(val, base + UTMIP_MISC_CFG0);
749 val = readl_relaxed(base + UTMIP_MISC_CFG0);
750 val |= UTMIP_DPDM_OBSERVE;
751 writel_relaxed(val, base + UTMIP_MISC_CFG0);
752 usleep_range(10, 100);
755 static void utmi_phy_restore_end(struct tegra_usb_phy *phy)
757 void __iomem *base = phy->regs;
760 val = readl_relaxed(base + UTMIP_MISC_CFG0);
761 val &= ~UTMIP_DPDM_OBSERVE;
762 writel_relaxed(val, base + UTMIP_MISC_CFG0);
763 usleep_range(10, 100);
766 static int ulpi_phy_power_on(struct tegra_usb_phy *phy)
768 void __iomem *base = phy->regs;
772 gpiod_set_value_cansleep(phy->reset_gpio, 1);
774 err = clk_prepare_enable(phy->clk);
778 usleep_range(5000, 6000);
780 gpiod_set_value_cansleep(phy->reset_gpio, 0);
782 usleep_range(1000, 2000);
784 val = readl_relaxed(base + USB_SUSP_CTRL);
786 writel_relaxed(val, base + USB_SUSP_CTRL);
788 val = readl_relaxed(base + ULPI_TIMING_CTRL_0);
789 val |= ULPI_OUTPUT_PINMUX_BYP | ULPI_CLKOUT_PINMUX_BYP;
790 writel_relaxed(val, base + ULPI_TIMING_CTRL_0);
792 val = readl_relaxed(base + USB_SUSP_CTRL);
793 val |= ULPI_PHY_ENABLE;
794 writel_relaxed(val, base + USB_SUSP_CTRL);
797 writel_relaxed(val, base + ULPI_TIMING_CTRL_1);
799 val |= ULPI_DATA_TRIMMER_SEL(4);
800 val |= ULPI_STPDIRNXT_TRIMMER_SEL(4);
801 val |= ULPI_DIR_TRIMMER_SEL(4);
802 writel_relaxed(val, base + ULPI_TIMING_CTRL_1);
803 usleep_range(10, 100);
805 val |= ULPI_DATA_TRIMMER_LOAD;
806 val |= ULPI_STPDIRNXT_TRIMMER_LOAD;
807 val |= ULPI_DIR_TRIMMER_LOAD;
808 writel_relaxed(val, base + ULPI_TIMING_CTRL_1);
810 /* Fix VbusInvalid due to floating VBUS */
811 err = usb_phy_io_write(phy->ulpi, 0x40, 0x08);
813 dev_err(phy->u_phy.dev, "ULPI write failed: %d\n", err);
817 err = usb_phy_io_write(phy->ulpi, 0x80, 0x0B);
819 dev_err(phy->u_phy.dev, "ULPI write failed: %d\n", err);
823 val = readl_relaxed(base + USB_SUSP_CTRL);
825 writel_relaxed(val, base + USB_SUSP_CTRL);
826 usleep_range(100, 1000);
828 val = readl_relaxed(base + USB_SUSP_CTRL);
829 val &= ~USB_SUSP_CLR;
830 writel_relaxed(val, base + USB_SUSP_CTRL);
835 clk_disable_unprepare(phy->clk);
840 static int ulpi_phy_power_off(struct tegra_usb_phy *phy)
842 gpiod_set_value_cansleep(phy->reset_gpio, 1);
843 usleep_range(5000, 6000);
844 clk_disable_unprepare(phy->clk);
847 * Wakeup currently unimplemented for ULPI, thus PHY needs to be
850 if (WARN_ON_ONCE(phy->wakeup_enabled)) {
851 ulpi_phy_power_on(phy);
858 static int tegra_usb_phy_power_on(struct tegra_usb_phy *phy)
865 if (phy->is_ulpi_phy)
866 err = ulpi_phy_power_on(phy);
868 err = utmi_phy_power_on(phy);
872 phy->powered_on = true;
874 /* Let PHY settle down */
875 usleep_range(2000, 2500);
880 static int tegra_usb_phy_power_off(struct tegra_usb_phy *phy)
884 if (!phy->powered_on)
887 if (phy->is_ulpi_phy)
888 err = ulpi_phy_power_off(phy);
890 err = utmi_phy_power_off(phy);
894 phy->powered_on = false;
899 static void tegra_usb_phy_shutdown(struct usb_phy *u_phy)
901 struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy);
903 if (WARN_ON(!phy->freq))
906 usb_phy_set_wakeup(u_phy, false);
907 tegra_usb_phy_power_off(phy);
909 if (!phy->is_ulpi_phy)
910 utmip_pad_close(phy);
912 regulator_disable(phy->vbus);
913 clk_disable_unprepare(phy->pll_u);
918 static irqreturn_t tegra_usb_phy_isr(int irq, void *data)
920 u32 val, int_mask = ID_CHG_DET | VBUS_WAKEUP_CHG_DET;
921 struct tegra_usb_phy *phy = data;
922 void __iomem *base = phy->regs;
925 * The PHY interrupt also wakes the USB controller driver since
926 * interrupt is shared. We don't do anything in the PHY driver,
927 * so just clear the interrupt.
929 val = readl_relaxed(base + USB_PHY_VBUS_WAKEUP_ID);
930 writel_relaxed(val, base + USB_PHY_VBUS_WAKEUP_ID);
932 return val & int_mask ? IRQ_HANDLED : IRQ_NONE;
935 static int tegra_usb_phy_set_wakeup(struct usb_phy *u_phy, bool enable)
937 struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy);
938 void __iomem *base = phy->regs;
942 if (phy->wakeup_enabled && phy->mode != USB_DR_MODE_HOST &&
944 disable_irq(phy->irq);
946 val = readl_relaxed(base + USB_PHY_VBUS_WAKEUP_ID);
947 val &= ~(ID_INT_EN | VBUS_WAKEUP_INT_EN);
948 writel_relaxed(val, base + USB_PHY_VBUS_WAKEUP_ID);
950 enable_irq(phy->irq);
952 free_irq(phy->irq, phy);
954 phy->wakeup_enabled = false;
957 if (enable && phy->mode != USB_DR_MODE_HOST && phy->irq > 0) {
958 ret = request_irq(phy->irq, tegra_usb_phy_isr, IRQF_SHARED,
959 dev_name(phy->u_phy.dev), phy);
961 disable_irq(phy->irq);
964 * USB clock will be resumed once wake event will be
965 * generated. The ID-change event requires to have
966 * interrupts enabled, otherwise it won't be generated.
968 val = readl_relaxed(base + USB_PHY_VBUS_WAKEUP_ID);
969 val |= ID_INT_EN | VBUS_WAKEUP_INT_EN;
970 writel_relaxed(val, base + USB_PHY_VBUS_WAKEUP_ID);
972 enable_irq(phy->irq);
974 dev_err(phy->u_phy.dev,
975 "Failed to request interrupt: %d", ret);
980 phy->wakeup_enabled = enable;
985 static int tegra_usb_phy_set_suspend(struct usb_phy *u_phy, int suspend)
987 struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy);
990 if (WARN_ON(!phy->freq))
994 * PHY is sharing IRQ with the CI driver, hence here we either
995 * disable interrupt for both PHY and CI or for CI only. The
996 * interrupt needs to be disabled while hardware is reprogrammed
997 * because interrupt touches the programmed registers, and thus,
998 * there could be a race condition.
1001 disable_irq(phy->irq);
1004 ret = tegra_usb_phy_power_off(phy);
1006 ret = tegra_usb_phy_power_on(phy);
1009 enable_irq(phy->irq);
1014 static int tegra_usb_phy_configure_pmc(struct tegra_usb_phy *phy)
1018 /* older device-trees don't have PMC regmap */
1019 if (!phy->pmc_regmap)
1023 * Tegra20 has a different layout of PMC USB register bits and AO is
1024 * enabled by default after system reset on Tegra20, so assume nothing
1027 if (!phy->soc_config->requires_pmc_ao_power_up)
1030 /* enable VBUS wake-up detector */
1031 if (phy->mode != USB_DR_MODE_HOST)
1032 val |= VBUS_WAKEUP_PD_P0 << phy->instance * 4;
1034 /* enable ID-pin ACC detector for OTG mode switching */
1035 if (phy->mode == USB_DR_MODE_OTG)
1036 val |= ID_PD_P0 << phy->instance * 4;
1038 /* disable detectors to reset them */
1039 err = regmap_set_bits(phy->pmc_regmap, PMC_USB_AO, val);
1041 dev_err(phy->u_phy.dev, "Failed to disable PMC AO: %d\n", err);
1045 usleep_range(10, 100);
1047 /* enable detectors */
1048 err = regmap_clear_bits(phy->pmc_regmap, PMC_USB_AO, val);
1050 dev_err(phy->u_phy.dev, "Failed to enable PMC AO: %d\n", err);
1054 /* detectors starts to work after 10ms */
1055 usleep_range(10000, 15000);
1060 static int tegra_usb_phy_init(struct usb_phy *u_phy)
1062 struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy);
1063 unsigned long parent_rate;
1067 if (WARN_ON(phy->freq))
1070 err = clk_prepare_enable(phy->pll_u);
1074 parent_rate = clk_get_rate(clk_get_parent(phy->pll_u));
1075 for (i = 0; i < ARRAY_SIZE(tegra_freq_table); i++) {
1076 if (tegra_freq_table[i].freq == parent_rate) {
1077 phy->freq = &tegra_freq_table[i];
1082 dev_err(phy->u_phy.dev, "Invalid pll_u parent rate %ld\n",
1088 err = regulator_enable(phy->vbus);
1090 dev_err(phy->u_phy.dev,
1091 "Failed to enable USB VBUS regulator: %d\n", err);
1095 if (!phy->is_ulpi_phy) {
1096 err = utmip_pad_open(phy);
1101 err = tegra_usb_phy_configure_pmc(phy);
1105 err = tegra_usb_phy_power_on(phy);
1112 if (!phy->is_ulpi_phy)
1113 utmip_pad_close(phy);
1116 regulator_disable(phy->vbus);
1119 clk_disable_unprepare(phy->pll_u);
1126 void tegra_usb_phy_preresume(struct usb_phy *u_phy)
1128 struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy);
1130 if (!phy->is_ulpi_phy)
1131 utmi_phy_preresume(phy);
1133 EXPORT_SYMBOL_GPL(tegra_usb_phy_preresume);
1135 void tegra_usb_phy_postresume(struct usb_phy *u_phy)
1137 struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy);
1139 if (!phy->is_ulpi_phy)
1140 utmi_phy_postresume(phy);
1142 EXPORT_SYMBOL_GPL(tegra_usb_phy_postresume);
1144 void tegra_ehci_phy_restore_start(struct usb_phy *u_phy,
1145 enum tegra_usb_phy_port_speed port_speed)
1147 struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy);
1149 if (!phy->is_ulpi_phy)
1150 utmi_phy_restore_start(phy, port_speed);
1152 EXPORT_SYMBOL_GPL(tegra_ehci_phy_restore_start);
1154 void tegra_ehci_phy_restore_end(struct usb_phy *u_phy)
1156 struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy);
1158 if (!phy->is_ulpi_phy)
1159 utmi_phy_restore_end(phy);
1161 EXPORT_SYMBOL_GPL(tegra_ehci_phy_restore_end);
1163 static int read_utmi_param(struct platform_device *pdev, const char *param,
1169 err = of_property_read_u32(pdev->dev.of_node, param, &value);
1172 "Failed to read USB UTMI parameter %s: %d\n",
1180 static int utmi_phy_probe(struct tegra_usb_phy *tegra_phy,
1181 struct platform_device *pdev)
1183 struct tegra_utmip_config *config;
1184 struct resource *res;
1187 tegra_phy->is_ulpi_phy = false;
1189 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1191 dev_err(&pdev->dev, "Failed to get UTMI pad regs\n");
1196 * Note that UTMI pad registers are shared by all PHYs, therefore
1197 * devm_platform_ioremap_resource() can't be used here.
1199 tegra_phy->pad_regs = devm_ioremap(&pdev->dev, res->start,
1200 resource_size(res));
1201 if (!tegra_phy->pad_regs) {
1202 dev_err(&pdev->dev, "Failed to remap UTMI pad regs\n");
1206 tegra_phy->config = devm_kzalloc(&pdev->dev, sizeof(*config),
1208 if (!tegra_phy->config)
1211 config = tegra_phy->config;
1213 err = read_utmi_param(pdev, "nvidia,hssync-start-delay",
1214 &config->hssync_start_delay);
1218 err = read_utmi_param(pdev, "nvidia,elastic-limit",
1219 &config->elastic_limit);
1223 err = read_utmi_param(pdev, "nvidia,idle-wait-delay",
1224 &config->idle_wait_delay);
1228 err = read_utmi_param(pdev, "nvidia,term-range-adj",
1229 &config->term_range_adj);
1233 err = read_utmi_param(pdev, "nvidia,xcvr-lsfslew",
1234 &config->xcvr_lsfslew);
1238 err = read_utmi_param(pdev, "nvidia,xcvr-lsrslew",
1239 &config->xcvr_lsrslew);
1243 if (tegra_phy->soc_config->requires_extra_tuning_parameters) {
1244 err = read_utmi_param(pdev, "nvidia,xcvr-hsslew",
1245 &config->xcvr_hsslew);
1249 err = read_utmi_param(pdev, "nvidia,hssquelch-level",
1250 &config->hssquelch_level);
1254 err = read_utmi_param(pdev, "nvidia,hsdiscon-level",
1255 &config->hsdiscon_level);
1260 config->xcvr_setup_use_fuses = of_property_read_bool(
1261 pdev->dev.of_node, "nvidia,xcvr-setup-use-fuses");
1263 if (!config->xcvr_setup_use_fuses) {
1264 err = read_utmi_param(pdev, "nvidia,xcvr-setup",
1265 &config->xcvr_setup);
1273 static void tegra_usb_phy_put_pmc_device(void *dev)
1278 static int tegra_usb_phy_parse_pmc(struct device *dev,
1279 struct tegra_usb_phy *phy)
1281 struct platform_device *pmc_pdev;
1282 struct of_phandle_args args;
1285 err = of_parse_phandle_with_fixed_args(dev->of_node, "nvidia,pmc",
1291 dev_warn_once(dev, "nvidia,pmc is missing, please update your device-tree\n");
1295 pmc_pdev = of_find_device_by_node(args.np);
1296 of_node_put(args.np);
1300 err = devm_add_action_or_reset(dev, tegra_usb_phy_put_pmc_device,
1305 if (!platform_get_drvdata(pmc_pdev))
1306 return -EPROBE_DEFER;
1308 phy->pmc_regmap = dev_get_regmap(&pmc_pdev->dev, "usb_sleepwalk");
1309 if (!phy->pmc_regmap)
1312 phy->instance = args.args[0];
1317 static const struct tegra_phy_soc_config tegra20_soc_config = {
1318 .utmi_pll_config_in_car_module = false,
1319 .has_hostpc = false,
1320 .requires_usbmode_setup = false,
1321 .requires_extra_tuning_parameters = false,
1322 .requires_pmc_ao_power_up = false,
1325 static const struct tegra_phy_soc_config tegra30_soc_config = {
1326 .utmi_pll_config_in_car_module = true,
1328 .requires_usbmode_setup = true,
1329 .requires_extra_tuning_parameters = true,
1330 .requires_pmc_ao_power_up = true,
1333 static const struct of_device_id tegra_usb_phy_id_table[] = {
1334 { .compatible = "nvidia,tegra30-usb-phy", .data = &tegra30_soc_config },
1335 { .compatible = "nvidia,tegra20-usb-phy", .data = &tegra20_soc_config },
1338 MODULE_DEVICE_TABLE(of, tegra_usb_phy_id_table);
1340 static int tegra_usb_phy_probe(struct platform_device *pdev)
1342 struct device_node *np = pdev->dev.of_node;
1343 struct tegra_usb_phy *tegra_phy;
1344 enum usb_phy_interface phy_type;
1345 struct reset_control *reset;
1346 struct gpio_desc *gpiod;
1347 struct resource *res;
1348 struct usb_phy *phy;
1351 tegra_phy = devm_kzalloc(&pdev->dev, sizeof(*tegra_phy), GFP_KERNEL);
1355 tegra_phy->soc_config = of_device_get_match_data(&pdev->dev);
1356 tegra_phy->irq = platform_get_irq_optional(pdev, 0);
1358 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1360 dev_err(&pdev->dev, "Failed to get I/O memory\n");
1365 * Note that PHY and USB controller are using shared registers,
1366 * therefore devm_platform_ioremap_resource() can't be used here.
1368 tegra_phy->regs = devm_ioremap(&pdev->dev, res->start,
1369 resource_size(res));
1370 if (!tegra_phy->regs) {
1371 dev_err(&pdev->dev, "Failed to remap I/O memory\n");
1375 tegra_phy->is_legacy_phy =
1376 of_property_read_bool(np, "nvidia,has-legacy-mode");
1378 if (of_find_property(np, "dr_mode", NULL))
1379 tegra_phy->mode = usb_get_dr_mode(&pdev->dev);
1381 tegra_phy->mode = USB_DR_MODE_HOST;
1383 if (tegra_phy->mode == USB_DR_MODE_UNKNOWN) {
1384 dev_err(&pdev->dev, "dr_mode is invalid\n");
1388 /* On some boards, the VBUS regulator doesn't need to be controlled */
1389 tegra_phy->vbus = devm_regulator_get(&pdev->dev, "vbus");
1390 if (IS_ERR(tegra_phy->vbus))
1391 return PTR_ERR(tegra_phy->vbus);
1393 tegra_phy->pll_u = devm_clk_get(&pdev->dev, "pll_u");
1394 err = PTR_ERR_OR_ZERO(tegra_phy->pll_u);
1396 dev_err(&pdev->dev, "Failed to get pll_u clock: %d\n", err);
1400 err = tegra_usb_phy_parse_pmc(&pdev->dev, tegra_phy);
1402 dev_err_probe(&pdev->dev, err, "Failed to get PMC regmap\n");
1406 phy_type = of_usb_get_phy_mode(np);
1408 case USBPHY_INTERFACE_MODE_UTMI:
1409 err = utmi_phy_probe(tegra_phy, pdev);
1413 tegra_phy->pad_clk = devm_clk_get(&pdev->dev, "utmi-pads");
1414 err = PTR_ERR_OR_ZERO(tegra_phy->pad_clk);
1417 "Failed to get UTMIP pad clock: %d\n", err);
1421 reset = devm_reset_control_get_optional_shared(&pdev->dev,
1423 err = PTR_ERR_OR_ZERO(reset);
1426 "Failed to get UTMI-pads reset: %d\n", err);
1429 tegra_phy->pad_rst = reset;
1432 case USBPHY_INTERFACE_MODE_ULPI:
1433 tegra_phy->is_ulpi_phy = true;
1435 tegra_phy->clk = devm_clk_get(&pdev->dev, "ulpi-link");
1436 err = PTR_ERR_OR_ZERO(tegra_phy->clk);
1439 "Failed to get ULPI clock: %d\n", err);
1443 gpiod = devm_gpiod_get(&pdev->dev, "nvidia,phy-reset",
1445 err = PTR_ERR_OR_ZERO(gpiod);
1448 "Request failed for reset GPIO: %d\n", err);
1452 err = gpiod_set_consumer_name(gpiod, "ulpi_phy_reset_b");
1455 "Failed to set up reset GPIO name: %d\n", err);
1459 tegra_phy->reset_gpio = gpiod;
1461 phy = devm_otg_ulpi_create(&pdev->dev,
1462 &ulpi_viewport_access_ops, 0);
1464 dev_err(&pdev->dev, "Failed to create ULPI OTG\n");
1468 tegra_phy->ulpi = phy;
1469 tegra_phy->ulpi->io_priv = tegra_phy->regs + ULPI_VIEWPORT;
1473 dev_err(&pdev->dev, "phy_type %u is invalid or unsupported\n",
1478 tegra_phy->u_phy.dev = &pdev->dev;
1479 tegra_phy->u_phy.init = tegra_usb_phy_init;
1480 tegra_phy->u_phy.shutdown = tegra_usb_phy_shutdown;
1481 tegra_phy->u_phy.set_wakeup = tegra_usb_phy_set_wakeup;
1482 tegra_phy->u_phy.set_suspend = tegra_usb_phy_set_suspend;
1484 platform_set_drvdata(pdev, tegra_phy);
1486 return usb_add_phy_dev(&tegra_phy->u_phy);
1489 static int tegra_usb_phy_remove(struct platform_device *pdev)
1491 struct tegra_usb_phy *tegra_phy = platform_get_drvdata(pdev);
1493 usb_remove_phy(&tegra_phy->u_phy);
1498 static struct platform_driver tegra_usb_phy_driver = {
1499 .probe = tegra_usb_phy_probe,
1500 .remove = tegra_usb_phy_remove,
1502 .name = "tegra-phy",
1503 .of_match_table = tegra_usb_phy_id_table,
1506 module_platform_driver(tegra_usb_phy_driver);
1508 MODULE_DESCRIPTION("Tegra USB PHY driver");
1509 MODULE_LICENSE("GPL v2");