2 * arch/arm/mach-tegra/usb_phy.c
4 * Copyright (C) 2010 Google, Inc.
7 * Erik Gilling <konkers@google.com>
8 * Benoit Goby <benoit@android.com>
10 * This software is licensed under the terms of the GNU General Public
11 * License version 2, as published by the Free Software Foundation, and
12 * may be copied, distributed, and modified under those terms.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
21 #include <linux/resource.h>
22 #include <linux/delay.h>
23 #include <linux/slab.h>
24 #include <linux/err.h>
25 #include <linux/platform_device.h>
27 #include <linux/gpio.h>
28 #include <asm/mach-types.h>
29 #include <mach/usb_phy.h>
30 #include <mach/iomap.h>
32 #define USB_USBSTS 0x144
33 #define USB_USBSTS_PCI (1 << 2)
35 #define ULPI_VIEWPORT 0x170
36 #define ULPI_WAKEUP (1 << 31)
37 #define ULPI_RUN (1 << 30)
38 #define ULPI_RD_RW_WRITE (1 << 29)
39 #define ULPI_RD_RW_READ (0 << 29)
40 #define ULPI_PORT(x) (((x) & 0x7) << 24)
41 #define ULPI_ADDR(x) (((x) & 0xff) << 16)
42 #define ULPI_DATA_RD(x) (((x) & 0xff) << 8)
43 #define ULPI_DATA_WR(x) (((x) & 0xff) << 0)
45 #define USB_PORTSC1 0x184
46 #define USB_PORTSC1_PTS(x) (((x) & 0x3) << 30)
47 #define USB_PORTSC1_PSPD(x) (((x) & 0x3) << 26)
48 #define USB_PORTSC1_PHCD (1 << 23)
49 #define USB_PORTSC1_WKOC (1 << 22)
50 #define USB_PORTSC1_WKDS (1 << 21)
51 #define USB_PORTSC1_WKCN (1 << 20)
52 #define USB_PORTSC1_PTC(x) (((x) & 0xf) << 16)
53 #define USB_PORTSC1_PP (1 << 12)
54 #define USB_PORTSC1_SUSP (1 << 7)
55 #define USB_PORTSC1_PE (1 << 2)
56 #define USB_PORTSC1_CCS (1 << 0)
58 #define USB_SUSP_CTRL 0x400
59 #define USB_WAKE_ON_CNNT_EN_DEV (1 << 3)
60 #define USB_WAKE_ON_DISCON_EN_DEV (1 << 4)
61 #define USB_SUSP_CLR (1 << 5)
62 #define USB_PHY_CLK_VALID (1 << 7)
63 #define UTMIP_RESET (1 << 11)
64 #define UHSIC_RESET (1 << 11)
65 #define UTMIP_PHY_ENABLE (1 << 12)
66 #define ULPI_PHY_ENABLE (1 << 13)
67 #define USB_SUSP_SET (1 << 14)
68 #define USB_WAKEUP_DEBOUNCE_COUNT(x) (((x) & 0x7) << 16)
70 #define USB1_LEGACY_CTRL 0x410
71 #define USB1_NO_LEGACY_MODE (1 << 0)
72 #define USB1_VBUS_SENSE_CTL_MASK (3 << 1)
73 #define USB1_VBUS_SENSE_CTL_VBUS_WAKEUP (0 << 1)
74 #define USB1_VBUS_SENSE_CTL_AB_SESS_VLD_OR_VBUS_WAKEUP \
76 #define USB1_VBUS_SENSE_CTL_AB_SESS_VLD (2 << 1)
77 #define USB1_VBUS_SENSE_CTL_A_SESS_VLD (3 << 1)
79 #define ULPI_TIMING_CTRL_0 0x424
80 #define ULPI_OUTPUT_PINMUX_BYP (1 << 10)
81 #define ULPI_CLKOUT_PINMUX_BYP (1 << 11)
83 #define ULPI_TIMING_CTRL_1 0x428
84 #define ULPI_DATA_TRIMMER_LOAD (1 << 0)
85 #define ULPI_DATA_TRIMMER_SEL(x) (((x) & 0x7) << 1)
86 #define ULPI_STPDIRNXT_TRIMMER_LOAD (1 << 16)
87 #define ULPI_STPDIRNXT_TRIMMER_SEL(x) (((x) & 0x7) << 17)
88 #define ULPI_DIR_TRIMMER_LOAD (1 << 24)
89 #define ULPI_DIR_TRIMMER_SEL(x) (((x) & 0x7) << 25)
91 #define UTMIP_PLL_CFG1 0x804
92 #define UTMIP_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0)
93 #define UTMIP_PLLU_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 27)
95 #define UTMIP_XCVR_CFG0 0x808
96 #define UTMIP_XCVR_SETUP(x) (((x) & 0xf) << 0)
97 #define UTMIP_XCVR_LSRSLEW(x) (((x) & 0x3) << 8)
98 #define UTMIP_XCVR_LSFSLEW(x) (((x) & 0x3) << 10)
99 #define UTMIP_FORCE_PD_POWERDOWN (1 << 14)
100 #define UTMIP_FORCE_PD2_POWERDOWN (1 << 16)
101 #define UTMIP_FORCE_PDZI_POWERDOWN (1 << 18)
102 #define UTMIP_XCVR_HSSLEW_MSB(x) (((x) & 0x7f) << 25)
104 #define UTMIP_BIAS_CFG0 0x80c
105 #define UTMIP_OTGPD (1 << 11)
106 #define UTMIP_BIASPD (1 << 10)
108 #define UTMIP_HSRX_CFG0 0x810
109 #define UTMIP_ELASTIC_LIMIT(x) (((x) & 0x1f) << 10)
110 #define UTMIP_IDLE_WAIT(x) (((x) & 0x1f) << 15)
112 #define UTMIP_HSRX_CFG1 0x814
113 #define UTMIP_HS_SYNC_START_DLY(x) (((x) & 0x1f) << 1)
115 #define UTMIP_TX_CFG0 0x820
116 #define UTMIP_FS_PREABMLE_J (1 << 19)
117 #define UTMIP_HS_DISCON_DISABLE (1 << 8)
119 #define UTMIP_MISC_CFG0 0x824
120 #define UTMIP_SUSPEND_EXIT_ON_EDGE (1 << 22)
122 #define UTMIP_MISC_CFG1 0x828
123 #define UTMIP_PLL_ACTIVE_DLY_COUNT(x) (((x) & 0x1f) << 18)
124 #define UTMIP_PLLU_STABLE_COUNT(x) (((x) & 0xfff) << 6)
126 #define UTMIP_DEBOUNCE_CFG0 0x82c
127 #define UTMIP_BIAS_DEBOUNCE_A(x) (((x) & 0xffff) << 0)
129 #define UTMIP_BAT_CHRG_CFG0 0x830
130 #define UTMIP_PD_CHRG (1 << 0)
132 #define UTMIP_SPARE_CFG0 0x834
133 #define FUSE_SETUP_SEL (1 << 3);
135 #define UTMIP_XCVR_CFG1 0x838
136 #define UTMIP_FORCE_PDDISC_POWERDOWN (1 << 0)
137 #define UTMIP_FORCE_PDCHRP_POWERDOWN (1 << 2)
138 #define UTMIP_FORCE_PDDR_POWERDOWN (1 << 4)
139 #define UTMIP_XCVR_TERM_RANGE_ADJ(x) (((x) & 0xf) << 18)
141 #define UTMIP_BIAS_CFG1 0x83c
142 #define UTMIP_BIAS_PDTRK_COUNT(x) (((x) & 0x1f) << 3)
144 static DEFINE_SPINLOCK(utmip_pad_lock);
145 static int utmip_pad_count;
147 static const int udc_freq_table[] = {
154 static const u8 udc_delay_table[][4] = {
155 /* ENABLE_DLY, STABLE_CNT, ACTIVE_DLY, XTAL_FREQ_CNT */
156 {0x02, 0x2F, 0x04, 0x76}, /* 12 MHz */
157 {0x02, 0x33, 0x05, 0x7F}, /* 13 MHz */
158 {0x03, 0x4B, 0x06, 0xBB}, /* 19.2 MHz */
159 {0x04, 0x66, 0x09, 0xFE}, /* 26 Mhz */
162 static const u16 udc_debounce_table[] = {
165 0xBB80, /* 19.2 MHz */
169 static struct tegra_utmip_config utmip_default[] = {
171 .hssync_start_delay = 9,
172 .idle_wait_delay = 17,
180 .hssync_start_delay = 9,
181 .idle_wait_delay = 17,
190 static int utmip_pad_open(struct tegra_usb_phy *phy)
192 phy->pad_clk = clk_get_sys("utmip-pad", NULL);
193 if (IS_ERR(phy->pad_clk)) {
194 pr_err("%s: can't get utmip pad clock\n", __func__);
198 if (phy->instance == 0) {
199 phy->pad_regs = phy->regs;
201 phy->pad_regs = ioremap(TEGRA_USB_BASE, TEGRA_USB_SIZE);
202 if (!phy->pad_regs) {
203 pr_err("%s: can't remap usb registers\n", __func__);
204 clk_put(phy->pad_clk);
211 static void utmip_pad_close(struct tegra_usb_phy *phy)
213 if (phy->instance != 0)
214 iounmap(phy->pad_regs);
215 clk_put(phy->pad_clk);
218 static void utmip_pad_power_on(struct tegra_usb_phy *phy)
220 unsigned long val, flags;
221 void __iomem *base = phy->pad_regs;
223 clk_enable(phy->pad_clk);
225 spin_lock_irqsave(&utmip_pad_lock, flags);
227 if (utmip_pad_count++ == 0) {
228 val = readl(base + UTMIP_BIAS_CFG0);
229 val &= ~(UTMIP_OTGPD | UTMIP_BIASPD);
230 writel(val, base + UTMIP_BIAS_CFG0);
233 spin_unlock_irqrestore(&utmip_pad_lock, flags);
235 clk_disable(phy->pad_clk);
238 static int utmip_pad_power_off(struct tegra_usb_phy *phy)
240 unsigned long val, flags;
241 void __iomem *base = phy->pad_regs;
243 if (!utmip_pad_count) {
244 pr_err("%s: utmip pad already powered off\n", __func__);
248 clk_enable(phy->pad_clk);
250 spin_lock_irqsave(&utmip_pad_lock, flags);
252 if (--utmip_pad_count == 0) {
253 val = readl(base + UTMIP_BIAS_CFG0);
254 val |= UTMIP_OTGPD | UTMIP_BIASPD;
255 writel(val, base + UTMIP_BIAS_CFG0);
258 spin_unlock_irqrestore(&utmip_pad_lock, flags);
260 clk_disable(phy->pad_clk);
265 static int utmi_wait_register(void __iomem *reg, u32 mask, u32 result)
267 unsigned long timeout = 2000;
269 if ((readl(reg) & mask) == result)
277 static void utmi_phy_clk_disable(struct tegra_usb_phy *phy)
280 void __iomem *base = phy->regs;
282 if (phy->instance == 0) {
283 val = readl(base + USB_SUSP_CTRL);
285 writel(val, base + USB_SUSP_CTRL);
289 val = readl(base + USB_SUSP_CTRL);
290 val &= ~USB_SUSP_SET;
291 writel(val, base + USB_SUSP_CTRL);
294 if (phy->instance == 2) {
295 val = readl(base + USB_PORTSC1);
296 val |= USB_PORTSC1_PHCD;
297 writel(val, base + USB_PORTSC1);
300 if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, 0) < 0)
301 pr_err("%s: timeout waiting for phy to stabilize\n", __func__);
304 static void utmi_phy_clk_enable(struct tegra_usb_phy *phy)
307 void __iomem *base = phy->regs;
309 if (phy->instance == 0) {
310 val = readl(base + USB_SUSP_CTRL);
312 writel(val, base + USB_SUSP_CTRL);
316 val = readl(base + USB_SUSP_CTRL);
317 val &= ~USB_SUSP_CLR;
318 writel(val, base + USB_SUSP_CTRL);
321 if (phy->instance == 2) {
322 val = readl(base + USB_PORTSC1);
323 val &= ~USB_PORTSC1_PHCD;
324 writel(val, base + USB_PORTSC1);
327 if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID,
329 pr_err("%s: timeout waiting for phy to stabilize\n", __func__);
332 static void utmi_phy_power_on(struct tegra_usb_phy *phy)
335 void __iomem *base = phy->regs;
336 struct tegra_utmip_config *config = phy->config;
338 val = readl(base + USB_SUSP_CTRL);
340 writel(val, base + USB_SUSP_CTRL);
342 if (phy->instance == 0) {
343 val = readl(base + USB1_LEGACY_CTRL);
344 val |= USB1_NO_LEGACY_MODE;
345 writel(val, base + USB1_LEGACY_CTRL);
348 val = readl(base + UTMIP_TX_CFG0);
349 val &= ~UTMIP_FS_PREABMLE_J;
350 writel(val, base + UTMIP_TX_CFG0);
352 val = readl(base + UTMIP_HSRX_CFG0);
353 val &= ~(UTMIP_IDLE_WAIT(~0) | UTMIP_ELASTIC_LIMIT(~0));
354 val |= UTMIP_IDLE_WAIT(config->idle_wait_delay);
355 val |= UTMIP_ELASTIC_LIMIT(config->elastic_limit);
356 writel(val, base + UTMIP_HSRX_CFG0);
358 val = readl(base + UTMIP_HSRX_CFG1);
359 val &= ~UTMIP_HS_SYNC_START_DLY(~0);
360 val |= UTMIP_HS_SYNC_START_DLY(config->hssync_start_delay);
361 writel(val, base + UTMIP_HSRX_CFG1);
363 val = readl(base + UTMIP_DEBOUNCE_CFG0);
364 val &= ~UTMIP_BIAS_DEBOUNCE_A(~0);
365 val |= UTMIP_BIAS_DEBOUNCE_A(udc_debounce_table[phy->freq_sel]);
366 writel(val, base + UTMIP_DEBOUNCE_CFG0);
368 val = readl(base + UTMIP_MISC_CFG0);
369 val &= ~UTMIP_SUSPEND_EXIT_ON_EDGE;
370 writel(val, base + UTMIP_MISC_CFG0);
372 val = readl(base + UTMIP_MISC_CFG1);
373 val &= ~(UTMIP_PLL_ACTIVE_DLY_COUNT(~0) | UTMIP_PLLU_STABLE_COUNT(~0));
374 val |= UTMIP_PLL_ACTIVE_DLY_COUNT(udc_delay_table[phy->freq_sel][2]) |
375 UTMIP_PLLU_STABLE_COUNT(udc_delay_table[phy->freq_sel][1]);
376 writel(val, base + UTMIP_MISC_CFG1);
378 val = readl(base + UTMIP_PLL_CFG1);
379 val &= ~(UTMIP_XTAL_FREQ_COUNT(~0) | UTMIP_PLLU_ENABLE_DLY_COUNT(~0));
380 val |= UTMIP_XTAL_FREQ_COUNT(udc_delay_table[phy->freq_sel][3]) |
381 UTMIP_PLLU_ENABLE_DLY_COUNT(udc_delay_table[phy->freq_sel][0]);
382 writel(val, base + UTMIP_PLL_CFG1);
384 if (phy->mode == TEGRA_USB_PHY_MODE_DEVICE) {
385 val = readl(base + USB_SUSP_CTRL);
386 val &= ~(USB_WAKE_ON_CNNT_EN_DEV | USB_WAKE_ON_DISCON_EN_DEV);
387 writel(val, base + USB_SUSP_CTRL);
390 utmip_pad_power_on(phy);
392 val = readl(base + UTMIP_XCVR_CFG0);
393 val &= ~(UTMIP_FORCE_PD_POWERDOWN | UTMIP_FORCE_PD2_POWERDOWN |
394 UTMIP_FORCE_PDZI_POWERDOWN | UTMIP_XCVR_SETUP(~0) |
395 UTMIP_XCVR_LSFSLEW(~0) | UTMIP_XCVR_LSRSLEW(~0) |
396 UTMIP_XCVR_HSSLEW_MSB(~0));
397 val |= UTMIP_XCVR_SETUP(config->xcvr_setup);
398 val |= UTMIP_XCVR_LSFSLEW(config->xcvr_lsfslew);
399 val |= UTMIP_XCVR_LSRSLEW(config->xcvr_lsrslew);
400 writel(val, base + UTMIP_XCVR_CFG0);
402 val = readl(base + UTMIP_XCVR_CFG1);
403 val &= ~(UTMIP_FORCE_PDDISC_POWERDOWN | UTMIP_FORCE_PDCHRP_POWERDOWN |
404 UTMIP_FORCE_PDDR_POWERDOWN | UTMIP_XCVR_TERM_RANGE_ADJ(~0));
405 val |= UTMIP_XCVR_TERM_RANGE_ADJ(config->term_range_adj);
406 writel(val, base + UTMIP_XCVR_CFG1);
408 val = readl(base + UTMIP_BAT_CHRG_CFG0);
409 val &= ~UTMIP_PD_CHRG;
410 writel(val, base + UTMIP_BAT_CHRG_CFG0);
412 val = readl(base + UTMIP_BIAS_CFG1);
413 val &= ~UTMIP_BIAS_PDTRK_COUNT(~0);
414 val |= UTMIP_BIAS_PDTRK_COUNT(0x5);
415 writel(val, base + UTMIP_BIAS_CFG1);
417 if (phy->instance == 2) {
418 val = readl(base + USB_SUSP_CTRL);
419 val |= UTMIP_PHY_ENABLE;
420 writel(val, base + USB_SUSP_CTRL);
423 val = readl(base + USB_SUSP_CTRL);
425 writel(val, base + USB_SUSP_CTRL);
427 if (phy->instance == 0) {
428 val = readl(base + USB1_LEGACY_CTRL);
429 val &= ~USB1_VBUS_SENSE_CTL_MASK;
430 val |= USB1_VBUS_SENSE_CTL_A_SESS_VLD;
431 writel(val, base + USB1_LEGACY_CTRL);
433 val = readl(base + USB_SUSP_CTRL);
434 val &= ~USB_SUSP_SET;
435 writel(val, base + USB_SUSP_CTRL);
438 utmi_phy_clk_enable(phy);
440 if (phy->instance == 2) {
441 val = readl(base + USB_PORTSC1);
442 val &= ~USB_PORTSC1_PTS(~0);
443 writel(val, base + USB_PORTSC1);
447 static void utmi_phy_power_off(struct tegra_usb_phy *phy)
450 void __iomem *base = phy->regs;
452 utmi_phy_clk_disable(phy);
454 if (phy->mode == TEGRA_USB_PHY_MODE_DEVICE) {
455 val = readl(base + USB_SUSP_CTRL);
456 val &= ~USB_WAKEUP_DEBOUNCE_COUNT(~0);
457 val |= USB_WAKE_ON_CNNT_EN_DEV | USB_WAKEUP_DEBOUNCE_COUNT(5);
458 writel(val, base + USB_SUSP_CTRL);
461 val = readl(base + USB_SUSP_CTRL);
463 writel(val, base + USB_SUSP_CTRL);
465 val = readl(base + UTMIP_BAT_CHRG_CFG0);
466 val |= UTMIP_PD_CHRG;
467 writel(val, base + UTMIP_BAT_CHRG_CFG0);
469 val = readl(base + UTMIP_XCVR_CFG0);
470 val |= UTMIP_FORCE_PD_POWERDOWN | UTMIP_FORCE_PD2_POWERDOWN |
471 UTMIP_FORCE_PDZI_POWERDOWN;
472 writel(val, base + UTMIP_XCVR_CFG0);
474 val = readl(base + UTMIP_XCVR_CFG1);
475 val |= UTMIP_FORCE_PDDISC_POWERDOWN | UTMIP_FORCE_PDCHRP_POWERDOWN |
476 UTMIP_FORCE_PDDR_POWERDOWN;
477 writel(val, base + UTMIP_XCVR_CFG1);
479 utmip_pad_power_off(phy);
482 static void utmi_phy_preresume(struct tegra_usb_phy *phy)
485 void __iomem *base = phy->regs;
487 val = readl(base + UTMIP_TX_CFG0);
488 val |= UTMIP_HS_DISCON_DISABLE;
489 writel(val, base + UTMIP_TX_CFG0);
492 static void utmi_phy_postresume(struct tegra_usb_phy *phy)
495 void __iomem *base = phy->regs;
497 val = readl(base + UTMIP_TX_CFG0);
498 val &= ~UTMIP_HS_DISCON_DISABLE;
499 writel(val, base + UTMIP_TX_CFG0);
502 static void ulpi_viewport_write(struct tegra_usb_phy *phy, u8 addr, u8 data)
505 void __iomem *base = phy->regs;
507 val = ULPI_RUN | ULPI_RD_RW_WRITE | ULPI_PORT(0);
508 val |= ULPI_ADDR(addr) | ULPI_DATA_WR(data);
509 writel(val, base + ULPI_VIEWPORT);
511 if (utmi_wait_register(base + ULPI_VIEWPORT, ULPI_RUN, 0))
512 pr_err("%s: timeout accessing ulpi phy\n", __func__);
515 static void ulpi_phy_power_on(struct tegra_usb_phy *phy)
518 void __iomem *base = phy->regs;
519 struct tegra_ulpi_config *config = phy->config;
521 gpio_direction_output(config->reset_gpio, 0);
523 gpio_direction_output(config->reset_gpio, 1);
525 clk_enable(phy->clk);
528 val = readl(base + USB_SUSP_CTRL);
530 writel(val, base + USB_SUSP_CTRL);
532 val = readl(base + ULPI_TIMING_CTRL_0);
533 val |= ULPI_OUTPUT_PINMUX_BYP | ULPI_CLKOUT_PINMUX_BYP;
534 writel(val, base + ULPI_TIMING_CTRL_0);
536 val = readl(base + USB_SUSP_CTRL);
537 val |= ULPI_PHY_ENABLE;
538 writel(val, base + USB_SUSP_CTRL);
541 writel(val, base + ULPI_TIMING_CTRL_1);
543 val |= ULPI_DATA_TRIMMER_SEL(4);
544 val |= ULPI_STPDIRNXT_TRIMMER_SEL(4);
545 val |= ULPI_DIR_TRIMMER_SEL(4);
546 writel(val, base + ULPI_TIMING_CTRL_1);
549 val |= ULPI_DATA_TRIMMER_LOAD;
550 val |= ULPI_STPDIRNXT_TRIMMER_LOAD;
551 val |= ULPI_DIR_TRIMMER_LOAD;
552 writel(val, base + ULPI_TIMING_CTRL_1);
554 val = ULPI_WAKEUP | ULPI_RD_RW_WRITE | ULPI_PORT(0);
555 writel(val, base + ULPI_VIEWPORT);
557 if (utmi_wait_register(base + ULPI_VIEWPORT, ULPI_WAKEUP, 0)) {
558 pr_err("%s: timeout waiting for ulpi phy wakeup\n", __func__);
562 /* Fix VbusInvalid due to floating VBUS */
563 ulpi_viewport_write(phy, 0x08, 0x40);
564 ulpi_viewport_write(phy, 0x0B, 0x80);
566 val = readl(base + USB_PORTSC1);
567 val |= USB_PORTSC1_WKOC | USB_PORTSC1_WKDS | USB_PORTSC1_WKCN;
568 writel(val, base + USB_PORTSC1);
570 val = readl(base + USB_SUSP_CTRL);
572 writel(val, base + USB_SUSP_CTRL);
575 val = readl(base + USB_SUSP_CTRL);
576 val &= ~USB_SUSP_CLR;
577 writel(val, base + USB_SUSP_CTRL);
580 static void ulpi_phy_power_off(struct tegra_usb_phy *phy)
583 void __iomem *base = phy->regs;
584 struct tegra_ulpi_config *config = phy->config;
586 /* Clear WKCN/WKDS/WKOC wake-on events that can cause the USB
587 * Controller to immediately bring the ULPI PHY out of low power
589 val = readl(base + USB_PORTSC1);
590 val &= ~(USB_PORTSC1_WKOC | USB_PORTSC1_WKDS | USB_PORTSC1_WKCN);
591 writel(val, base + USB_PORTSC1);
593 gpio_direction_output(config->reset_gpio, 0);
594 clk_disable(phy->clk);
597 struct tegra_usb_phy *tegra_usb_phy_open(int instance, void __iomem *regs,
598 void *config, enum tegra_usb_phy_mode phy_mode)
600 struct tegra_usb_phy *phy;
601 struct tegra_ulpi_config *ulpi_config;
602 unsigned long parent_rate;
606 phy = kmalloc(sizeof(struct tegra_usb_phy), GFP_KERNEL);
608 return ERR_PTR(-ENOMEM);
610 phy->instance = instance;
612 phy->config = config;
613 phy->context.valid = false;
614 phy->mode = phy_mode;
618 pr_err("%s: ulpi phy configuration missing", __func__);
622 phy->config = &utmip_default[instance];
626 phy->pll_u = clk_get_sys(NULL, "pll_u");
627 if (IS_ERR(phy->pll_u)) {
628 pr_err("Can't get pll_u clock\n");
629 err = PTR_ERR(phy->pll_u);
632 clk_enable(phy->pll_u);
634 parent_rate = clk_get_rate(clk_get_parent(phy->pll_u));
635 for (freq_sel = 0; freq_sel < ARRAY_SIZE(udc_freq_table); freq_sel++) {
636 if (udc_freq_table[freq_sel] == parent_rate)
639 if (freq_sel == ARRAY_SIZE(udc_freq_table)) {
640 pr_err("invalid pll_u parent rate %ld\n", parent_rate);
644 phy->freq_sel = freq_sel;
646 if (phy->instance == 1) {
647 ulpi_config = config;
648 phy->clk = clk_get_sys(NULL, ulpi_config->clk);
649 if (IS_ERR(phy->clk)) {
650 pr_err("%s: can't get ulpi clock\n", __func__);
654 tegra_gpio_enable(ulpi_config->reset_gpio);
655 gpio_request(ulpi_config->reset_gpio, "ulpi_phy_reset_b");
656 gpio_direction_output(ulpi_config->reset_gpio, 0);
658 err = utmip_pad_open(phy);
666 clk_disable(phy->pll_u);
673 int tegra_usb_phy_power_on(struct tegra_usb_phy *phy)
675 if (phy->instance == 1)
676 ulpi_phy_power_on(phy);
678 utmi_phy_power_on(phy);
683 int tegra_usb_phy_power_off(struct tegra_usb_phy *phy)
685 if (phy->instance == 1)
686 ulpi_phy_power_off(phy);
688 utmi_phy_power_off(phy);
693 int tegra_usb_phy_preresume(struct tegra_usb_phy *phy)
695 if (phy->instance == 2)
696 utmi_phy_preresume(phy);
700 int tegra_usb_phy_postresume(struct tegra_usb_phy *phy)
702 if (phy->instance == 2)
703 utmi_phy_postresume(phy);
707 int tegra_usb_phy_clk_disable(struct tegra_usb_phy *phy)
709 if (phy->instance != 1)
710 utmi_phy_clk_disable(phy);
715 int tegra_usb_phy_clk_enable(struct tegra_usb_phy *phy)
717 if (phy->instance != 1)
718 utmi_phy_clk_enable(phy);
723 int tegra_usb_phy_close(struct tegra_usb_phy *phy)
725 if (phy->instance == 1)
728 utmip_pad_close(phy);
729 clk_disable(phy->pll_u);