2 * drivers/usb/phy/tegra11x_usb_phy.c
4 * Copyright (c) 2012-2014 NVIDIA Corporation. All rights reserved.
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
17 #include <linux/resource.h>
18 #include <linux/delay.h>
19 #include <linux/interrupt.h>
20 #include <linux/slab.h>
21 #include <linux/err.h>
22 #include <linux/platform_device.h>
24 #include <linux/gpio.h>
25 #include <linux/interrupt.h>
26 #include <linux/clk.h>
27 #include <linux/regulator/consumer.h>
28 #include <linux/platform_data/tegra_usb.h>
29 #include <linux/clk/tegra.h>
30 #include <linux/tegra-soc.h>
31 #include <linux/tegra-fuse.h>
32 #include <mach/pinmux.h>
33 #include <mach/tegra_usb_pmc.h>
34 #include <mach/tegra_usb_pad_ctrl.h>
36 #ifdef CONFIG_ARCH_TEGRA_14x_SOC
37 #include <mach/pinmux-t14.h>
39 #include <mach/pinmux-t11.h>
41 #include "tegra_usb_phy.h"
42 #include "../../../arch/arm/mach-tegra/gpio-names.h"
44 /* HACK! This needs to come from DT */
45 #include "../../../arch/arm/mach-tegra/iomap.h"
47 #define USB_USBCMD 0x130
48 #define USB_USBCMD_RS (1 << 0)
49 #define USB_CMD_RESET (1<<1)
51 #define USB_USBSTS 0x134
52 #define USB_USBSTS_PCI (1 << 2)
53 #define USB_USBSTS_SRI (1 << 7)
54 #define USB_USBSTS_HCH (1 << 12)
56 #define USB_TXFILLTUNING 0x154
57 #define USB_FIFO_TXFILL_THRES(x) (((x) & 0x1f) << 16)
58 #define USB_FIFO_TXFILL_MASK 0x1f0000
60 #define USB_ASYNCLISTADDR 0x148
62 #define ICUSB_CTRL 0x15c
64 #define USB_USBMODE 0x1f8
65 #define USB_USBMODE_MASK (3 << 0)
66 #define USB_USBMODE_HOST (3 << 0)
67 #define USB_USBMODE_DEVICE (2 << 0)
69 #define USB_SUSP_CTRL 0x400
70 #define USB_WAKE_ON_CNNT_EN_DEV (1 << 3)
71 #define USB_WAKE_ON_DISCON_EN_DEV (1 << 4)
72 #define USB_SUSP_CLR (1 << 5)
73 #define USB_CLKEN (1 << 6)
74 #define USB_PHY_CLK_VALID (1 << 7)
75 #define USB_PHY_CLK_VALID_INT_ENB (1 << 9)
76 #define USB_PHY_CLK_VALID_INT_STS (1 << 8)
77 #define UTMIP_RESET (1 << 11)
78 #define UTMIP_PHY_ENABLE (1 << 12)
79 #define UHSIC_RESET (1 << 14)
80 #define USB_WAKEUP_DEBOUNCE_COUNT(x) (((x) & 0x7) << 16)
81 #define UHSIC_PHY_ENABLE (1 << 19)
83 #define USB_PHY_VBUS_WAKEUP_ID 0x408
84 #define DIV_DET_EN (1 << 31)
85 #define VDCD_DET_STS (1 << 26)
86 #define VDCD_DET_CHG_DET (1 << 25)
87 #define VOP_DIV2P7_DET (1 << 23)
88 #define VOP_DIV2P0_DET (1 << 22)
89 #define VON_DIV2P7_DET (1 << 15)
90 #define VON_DIV2P0_DET (1 << 14)
91 #define VDAT_DET_INT_EN (1 << 16)
92 #define VDAT_DET_CHG_DET (1 << 17)
93 #define VDAT_DET_STS (1 << 18)
94 #define USB_ID_STATUS (1 << 2)
96 #define USB_IF_SPARE 0x498
97 #define USB_HS_RSM_EOP_EN (1 << 4)
98 #define USB_PORT_SUSPEND_EN (1 << 5)
100 #define USB_NEW_CONTROL 0x4c0
101 #define USB_COHRENCY_EN (1 << 0)
102 #define USB_MEM_ALLIGNMENT_MUX_EN (1 << 1)
104 #define UTMIP_XCVR_CFG0 0x808
105 #define UTMIP_XCVR_SETUP(x) (((x) & 0xf) << 0)
106 #define UTMIP_XCVR_LSRSLEW(x) (((x) & 0x3) << 8)
107 #define UTMIP_XCVR_LSFSLEW(x) (((x) & 0x3) << 10)
108 #define UTMIP_FORCE_PD_POWERDOWN (1 << 14)
109 #define UTMIP_FORCE_PD2_POWERDOWN (1 << 16)
110 #define UTMIP_FORCE_PDZI_POWERDOWN (1 << 18)
111 #define UTMIP_XCVR_LSBIAS_SEL (1 << 21)
112 #define UTMIP_XCVR_SETUP_MSB(x) (((x) & 0x7) << 22)
113 #define UTMIP_XCVR_HSSLEW_MSB(x) (((x) & 0x7f) << 25)
114 #define UTMIP_XCVR_HSSLEW_LSB(x) (((x) & 0x3) << 4)
115 #define UTMIP_XCVR_MAX_OFFSET 2
116 #define UTMIP_XCVR_SETUP_MAX_VALUE 0x7f
117 #define UTMIP_XCVR_SETUP_MIN_VALUE 0
118 #define XCVR_SETUP_MSB_CALIB(x) ((x) >> 4)
120 #define UTMIP_HSRX_CFG0 0x810
121 #define UTMIP_ELASTIC_LIMIT(x) (((x) & 0x1f) << 10)
122 #define UTMIP_IDLE_WAIT(x) (((x) & 0x1f) << 15)
124 #define UTMIP_HSRX_CFG1 0x814
125 #define UTMIP_HS_SYNC_START_DLY(x) (((x) & 0x1f) << 1)
127 #define UTMIP_TX_CFG0 0x820
128 #define UTMIP_FS_PREABMLE_J (1 << 19)
129 #define UTMIP_HS_DISCON_DISABLE (1 << 8)
131 #define UTMIP_DEBOUNCE_CFG0 0x82c
132 #define UTMIP_BIAS_DEBOUNCE_A(x) (((x) & 0xffff) << 0)
134 #define UTMIP_BAT_CHRG_CFG0 0x830
135 #define UTMIP_PD_CHRG (1 << 0)
136 #define UTMIP_OP_SINK_EN (1 << 1)
137 #define UTMIP_ON_SINK_EN (1 << 2)
138 #define UTMIP_OP_SRC_EN (1 << 3)
139 #define UTMIP_ON_SRC_EN (1 << 4)
140 #define UTMIP_OP_I_SRC_EN (1 << 5)
142 #define UTMIP_XCVR_CFG1 0x838
143 #define UTMIP_FORCE_PDDISC_POWERDOWN (1 << 0)
144 #define UTMIP_FORCE_PDCHRP_POWERDOWN (1 << 2)
145 #define UTMIP_FORCE_PDDR_POWERDOWN (1 << 4)
146 #define UTMIP_XCVR_TERM_RANGE_ADJ(x) (((x) & 0xf) << 18)
148 #define UTMIP_MISC_CFG0 0x824
149 #define UTMIP_DPDM_OBSERVE (1 << 26)
150 #define UTMIP_DPDM_OBSERVE_SEL(x) (((x) & 0xf) << 27)
151 #define UTMIP_DPDM_OBSERVE_SEL_FS_J UTMIP_DPDM_OBSERVE_SEL(0xf)
152 #define UTMIP_DPDM_OBSERVE_SEL_FS_K UTMIP_DPDM_OBSERVE_SEL(0xe)
153 #define UTMIP_DPDM_OBSERVE_SEL_FS_SE1 UTMIP_DPDM_OBSERVE_SEL(0xd)
154 #define UTMIP_DPDM_OBSERVE_SEL_FS_SE0 UTMIP_DPDM_OBSERVE_SEL(0xc)
155 #define UTMIP_SUSPEND_EXIT_ON_EDGE (1 << 22)
156 #define DISABLE_PULLUP_DP (1 << 15)
157 #define DISABLE_PULLUP_DM (1 << 14)
158 #define DISABLE_PULLDN_DP (1 << 13)
159 #define DISABLE_PULLDN_DM (1 << 12)
160 #define FORCE_PULLUP_DP (1 << 11)
161 #define FORCE_PULLUP_DM (1 << 10)
162 #define FORCE_PULLDN_DP (1 << 9)
163 #define FORCE_PULLDN_DM (1 << 8)
164 #define COMB_TERMS (1 << 0)
165 #define ALWAYS_FREE_RUNNING_TERMS (1 << 1)
166 #define MASK_ALL_PULLUP_PULLDOWN (0xff << 8)
168 #define UTMIP_SPARE_CFG0 0x834
169 #define FUSE_SETUP_SEL (1 << 3)
170 #define FUSE_ATERM_SEL (1 << 4)
172 #define UHSIC_PLL_CFG1 0xc04
173 #define UHSIC_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0)
174 #define UHSIC_PLLU_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 14)
176 #define UHSIC_HSRX_CFG0 0xc08
177 #define UHSIC_ELASTIC_UNDERRUN_LIMIT(x) (((x) & 0x1f) << 2)
178 #define UHSIC_ELASTIC_OVERRUN_LIMIT(x) (((x) & 0x1f) << 8)
179 #define UHSIC_IDLE_WAIT(x) (((x) & 0x1f) << 13)
181 #define UHSIC_HSRX_CFG1 0xc0c
182 #define UHSIC_HS_SYNC_START_DLY(x) (((x) & 0x1f) << 1)
184 #define UHSIC_TX_CFG0 0xc10
185 #define UHSIC_HS_READY_WAIT_FOR_VALID (1 << 9)
186 #define UHSIC_HS_POSTAMBLE_OUTPUT_ENABLE (1 << 6)
189 #define UHSIC_MISC_CFG0 0xc14
190 #define UHSIC_SUSPEND_EXIT_ON_EDGE (1 << 7)
191 #define UHSIC_DETECT_SHORT_CONNECT (1 << 8)
192 #define UHSIC_FORCE_XCVR_MODE (1 << 15)
193 #define UHSIC_DISABLE_BUSRESET (1 << 20)
195 #define UHSIC_MISC_CFG1 0xc18
196 #define UHSIC_PLLU_STABLE_COUNT(x) (((x) & 0xfff) << 2)
198 #define UHSIC_PADS_CFG0 0xc1c
199 #define UHSIC_TX_RTUNEN 0xf000
200 #define UHSIC_TX_RTUNEP 0xf00
201 #define UHSIC_TX_RTUNE_P(x) (((x) & 0xf) << 8)
202 #define UHSIC_TX_SLEWP (0xf << 16)
203 #define UHSIC_TX_SLEWN (0xf << 20)
205 #define UHSIC_PADS_CFG1 0xc20
206 #define UHSIC_AUTO_RTERM_EN (1 << 0)
207 #define UHSIC_PD_BG (1 << 2)
208 #define UHSIC_PD_TX (1 << 3)
209 #define UHSIC_PD_TRK (1 << 4)
210 #define UHSIC_PD_RX (1 << 5)
211 #define UHSIC_PD_ZI (1 << 6)
212 #define UHSIC_RX_SEL (1 << 7)
213 #define UHSIC_RPD_DATA (1 << 9)
214 #define UHSIC_RPD_STROBE (1 << 10)
215 #define UHSIC_RPU_DATA (1 << 11)
216 #define UHSIC_RPU_STROBE (1 << 12)
218 #define UHSIC_SPARE_CFG0 0xc2c
219 #define FORCE_BK_ON (1 << 12)
221 #define UHSIC_STAT_CFG0 0xc28
222 #define UHSIC_CONNECT_DETECT (1 << 0)
224 #define UHSIC_STATUS(inst) UHSIC_INST(inst, 0x214, 0x290)
225 #define UHSIC_WAKE_ALARM(inst) (1 << UHSIC_INST(inst, 19, 4))
226 #define UHSIC_WALK_PTR_VAL(inst) (0x3 << UHSIC_INST(inst, 6, 0))
227 #define UHSIC_DATA_VAL(inst) (1 << UHSIC_INST(inst, 15, 3))
228 #define UHSIC_STROBE_VAL(inst) (1 << UHSIC_INST(inst, 14, 2))
230 #define UHSIC_CMD_CFG0 0xc24
231 #define UHSIC_PRETEND_CONNECT_DETECT (1 << 5)
233 #define USB_USBINTR 0x138
235 #define UTMIP_STATUS 0x214
236 #define UTMIP_WALK_PTR_VAL(inst) (0x3 << ((inst)*2))
237 #define UTMIP_USBOP_VAL(inst) (1 << ((2*(inst)) + 8))
238 #define UTMIP_USBOP_VAL_P2 (1 << 12)
239 #define UTMIP_USBOP_VAL_P1 (1 << 10)
240 #define UTMIP_USBOP_VAL_P0 (1 << 8)
241 #define UTMIP_USBON_VAL(inst) (1 << ((2*(inst)) + 9))
242 #define UTMIP_USBON_VAL_P2 (1 << 13)
243 #define UTMIP_USBON_VAL_P1 (1 << 11)
244 #define UTMIP_USBON_VAL_P0 (1 << 9)
245 #define UTMIP_WAKE_ALARM(inst) (1 << ((inst) + 16))
246 #define UTMIP_WAKE_ALARM_P2 (1 << 18)
247 #define UTMIP_WAKE_ALARM_P1 (1 << 17)
248 #define UTMIP_WAKE_ALARM_P0 (1 << 16)
249 #define UTMIP_WALK_PTR(inst) (1 << ((inst)*2))
250 #define UTMIP_WALK_PTR_P2 (1 << 4)
251 #define UTMIP_WALK_PTR_P1 (1 << 2)
252 #define UTMIP_WALK_PTR_P0 (1 << 0)
254 #define USB1_PREFETCH_ID 6
255 #define USB2_PREFETCH_ID 18
256 #define USB3_PREFETCH_ID 17
258 #define FUSE_USB_CALIB_0 0x1F0
259 #define XCVR_SETUP(x) (((x) & 0x7F) << 0)
260 #define XCVR_SETUP_LSB_MASK 0xF
261 #define XCVR_SETUP_MSB_MASK 0x70
262 #define XCVR_SETUP_LSB_MAX_VAL 0xF
264 #define APB_MISC_GP_OBSCTRL_0 0x818
265 #define APB_MISC_GP_OBSDATA_0 0x81c
267 #define PADCTL_SNPS_OC_MAP 0xC
268 #define CONTROLLER_OC(inst, x) (((x) & 0x7) << (3 * (inst)))
269 #define CONTROLLER_OC_P0(x) (((x) & 0x7) << 0)
270 #define CONTROLLER_OC_P1(x) (((x) & 0x7) << 3)
271 #define CONTROLLER_OC_P2(x) (((x) & 0x7) << 6)
273 #define PADCTL_OC_DET 0x18
274 #define ENABLE0_OC_MAP(x) (((x) & 0x7) << 10)
275 #define ENABLE1_OC_MAP(x) (((x) & 0x7) << 13)
277 #define TEGRA_STREAM_DISABLE 0x1f8
278 #define TEGRA_STREAM_DISABLE_OFFSET (1 << 4)
280 /* These values (in milli second) are taken from the battery charging spec */
281 #define TDP_SRC_ON_MS 100
282 #define TDPSRC_CON_MS 40
284 /* Maxim Debounce Timer */
285 #define MAXIM_DEBOUNCE_TIME 120
287 /* Force port resume wait time in micro second on remote resume */
288 #define FPR_WAIT_TIME_US 25000
290 /* define HSIC phy params */
291 #define HSIC_SYNC_START_DELAY 9
292 #define HSIC_IDLE_WAIT_DELAY 17
293 #define HSIC_ELASTIC_UNDERRUN_LIMIT 16
294 #define HSIC_ELASTIC_OVERRUN_LIMIT 16
296 struct tegra_usb_pmc_data pmc_data[3];
298 static struct tegra_xtal_freq utmip_freq_table[] = {
301 .enable_delay = 0x02,
302 .stable_count = 0x2F,
303 .active_delay = 0x04,
304 .xtal_freq_count = 0x76,
310 .enable_delay = 0x02,
311 .stable_count = 0x33,
312 .active_delay = 0x05,
313 .xtal_freq_count = 0x7F,
319 .enable_delay = 0x03,
320 .stable_count = 0x4B,
321 .active_delay = 0x06,
322 .xtal_freq_count = 0xBB,
328 .enable_delay = 0x04,
329 .stable_count = 0x66,
330 .active_delay = 0x09,
331 .xtal_freq_count = 0xFE,
337 static struct tegra_xtal_freq uhsic_freq_table[] = {
340 .enable_delay = 0x02,
341 .stable_count = 0x2F,
343 .xtal_freq_count = 0x1CA,
347 .enable_delay = 0x02,
348 .stable_count = 0x33,
350 .xtal_freq_count = 0x1F0,
354 .enable_delay = 0x03,
355 .stable_count = 0x4B,
357 .xtal_freq_count = 0x2DD,
361 .enable_delay = 0x04,
362 .stable_count = 0x66,
364 .xtal_freq_count = 0x3E0,
368 static void pmc_init(struct tegra_usb_phy *phy)
370 pmc_data[phy->inst].instance = phy->inst;
371 pmc_data[phy->inst].phy_type = phy->pdata->phy_intf;
372 pmc_data[phy->inst].controller_type = TEGRA_USB_2_0;
373 pmc_data[phy->inst].usb_base = phy->regs;
374 tegra_usb_pmc_init(&pmc_data[phy->inst]);
377 static int _usb_phy_init(struct tegra_usb_phy *phy)
380 void __iomem *base = phy->regs;
382 DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
384 val = readl(base + HOSTPC1_DEVLC);
385 val &= ~HOSTPC1_DEVLC_STS;
386 writel(val, base + HOSTPC1_DEVLC);
388 val = readl(base + USB_IF_SPARE);
389 val |= USB_HS_RSM_EOP_EN;
390 val |= USB_PORT_SUSPEND_EN;
391 writel(val, base + USB_IF_SPARE);
393 if (phy->pdata->unaligned_dma_buf_supported == true) {
394 val = readl(base + USB_NEW_CONTROL);
395 val |= USB_COHRENCY_EN;
396 val |= USB_MEM_ALLIGNMENT_MUX_EN;
397 writel(val, base + USB_NEW_CONTROL);
399 val = readl(base + TEGRA_STREAM_DISABLE);
400 if (!tegra_platform_is_silicon())
401 val |= TEGRA_STREAM_DISABLE_OFFSET;
403 val &= ~TEGRA_STREAM_DISABLE_OFFSET;
404 writel(val , base + TEGRA_STREAM_DISABLE);
409 static void usb_phy_fence_read(struct tegra_usb_phy *phy)
411 /* Fence read for coherency of AHB master intiated writes */
413 readb(IO_ADDRESS(IO_PPCS_PHYS + USB1_PREFETCH_ID));
414 else if (phy->inst == 1)
415 readb(IO_ADDRESS(IO_PPCS_PHYS + USB2_PREFETCH_ID));
416 else if (phy->inst == 2)
417 readb(IO_ADDRESS(IO_PPCS_PHYS + USB3_PREFETCH_ID));
421 static int usb_phy_reset(struct tegra_usb_phy *phy)
424 void __iomem *base = phy->regs;
426 DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
428 if (!tegra_platform_is_silicon()) {
429 val = readl(base + TEGRA_STREAM_DISABLE);
430 val |= TEGRA_STREAM_DISABLE_OFFSET;
431 writel(val , base + TEGRA_STREAM_DISABLE);
433 val = readl(base + USB_TXFILLTUNING);
434 if ((val & USB_FIFO_TXFILL_MASK) != USB_FIFO_TXFILL_THRES(0x10)) {
435 val = USB_FIFO_TXFILL_THRES(0x10);
436 writel(val, base + USB_TXFILLTUNING);
442 static bool utmi_phy_remotewake_detected(struct tegra_usb_phy *phy)
444 void __iomem *base = phy->regs;
445 unsigned int inst = phy->inst;
448 DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
449 val = readl(base + UTMIP_PMC_WAKEUP0);
450 if (val & EVENT_INT_ENB) {
451 val = tegra_usb_pmc_reg_read(UTMIP_STATUS);
452 if (UTMIP_WAKE_ALARM(inst) & val) {
453 tegra_usb_pmc_reg_update(PMC_SLEEP_CFG,
454 UTMIP_WAKE_VAL(inst, 0xF),
455 UTMIP_WAKE_VAL(inst, WAKE_VAL_NONE));
457 tegra_usb_pmc_reg_update(PMC_TRIGGERS, 0,
458 UTMIP_CLR_WAKE_ALARM(inst));
460 val = readl(base + UTMIP_PMC_WAKEUP0);
461 val &= ~EVENT_INT_ENB;
462 writel(val, base + UTMIP_PMC_WAKEUP0);
464 val = tegra_usb_pmc_reg_read(UTMIP_STATUS);
465 if (phy->port_speed < USB_PHY_PORT_SPEED_UNKNOWN)
466 phy->pmc_remote_wakeup = true;
468 phy->pmc_hotplug_wakeup = true;
470 DBG("%s: utmip PMC interrupt detected\n", __func__);
477 static int usb_phy_bringup_host_controller(struct tegra_usb_phy *phy)
480 void __iomem *base = phy->regs;
482 DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
483 PHY_DBG("[%d] USB_USBSTS[0x%x] USB_PORTSC[0x%x] port_speed[%d]\n",
484 __LINE__, readl(base + USB_USBSTS), readl(base + USB_PORTSC),
487 /* Device is plugged in when system is in LP0 */
488 /* Bring up the controller from LP0*/
489 val = readl(base + USB_USBCMD);
490 val |= USB_CMD_RESET;
491 writel(val, base + USB_USBCMD);
493 if (usb_phy_reg_status_wait(base + USB_USBCMD,
494 USB_CMD_RESET, 0, 2500) < 0) {
495 pr_err("%s: timeout waiting for reset\n", __func__);
498 val = readl(base + USB_USBMODE);
499 val &= ~USB_USBMODE_MASK;
500 val |= USB_USBMODE_HOST;
501 writel(val, base + USB_USBMODE);
502 val = readl(base + HOSTPC1_DEVLC);
503 val &= ~HOSTPC1_DEVLC_PTS(~0);
505 if (phy->pdata->phy_intf == TEGRA_USB_PHY_INTF_HSIC)
506 val |= HOSTPC1_DEVLC_PTS(HOSTPC1_DEVLC_PTS_HSIC);
508 val |= HOSTPC1_DEVLC_STS;
509 writel(val, base + HOSTPC1_DEVLC);
511 /* Enable Port Power */
512 val = readl(base + USB_PORTSC);
513 val |= USB_PORTSC_PP;
514 writel(val, base + USB_PORTSC);
517 /* Check if the phy resume from LP0. When the phy resume from LP0
518 * USB register will be reset.to zero */
519 if (!readl(base + USB_ASYNCLISTADDR)) {
520 /* Program the field PTC based on the saved speed mode */
521 val = readl(base + USB_PORTSC);
522 val &= ~USB_PORTSC_PTC(~0);
523 if ((phy->port_speed == USB_PHY_PORT_SPEED_HIGH) ||
524 (phy->pdata->phy_intf == TEGRA_USB_PHY_INTF_HSIC))
525 val |= USB_PORTSC_PTC(5);
526 else if (phy->port_speed == USB_PHY_PORT_SPEED_FULL)
527 val |= USB_PORTSC_PTC(6);
528 else if (phy->port_speed == USB_PHY_PORT_SPEED_LOW)
529 val |= USB_PORTSC_PTC(7);
530 writel(val, base + USB_PORTSC);
533 /* Disable test mode by setting PTC field to NORMAL_OP */
534 val = readl(base + USB_PORTSC);
535 val &= ~USB_PORTSC_PTC(~0);
536 writel(val, base + USB_PORTSC);
540 /* Poll until CCS is enabled */
541 if (usb_phy_reg_status_wait(base + USB_PORTSC, USB_PORTSC_CCS,
542 USB_PORTSC_CCS, 2000)) {
543 pr_err("%s: timeout waiting for USB_PORTSC_CCS\n", __func__);
546 /* Poll until PE is enabled */
547 if (usb_phy_reg_status_wait(base + USB_PORTSC, USB_PORTSC_PE,
548 USB_PORTSC_PE, 2000)) {
549 pr_err("%s: timeout waiting for USB_PORTSC_PE\n", __func__);
552 /* Clear the PCI status, to avoid an interrupt taken upon resume */
553 val = readl(base + USB_USBSTS);
554 val |= USB_USBSTS_PCI;
555 writel(val, base + USB_USBSTS);
557 phy->ctrlr_suspended = false;
558 if (!phy->pmc_remote_wakeup) {
559 /* Put controller in suspend mode by writing 1
560 * to SUSP bit of PORTSC */
561 val = readl(base + USB_PORTSC);
562 if ((val & USB_PORTSC_PP) && (val & USB_PORTSC_PE)) {
563 val |= USB_PORTSC_SUSP;
564 writel(val, base + USB_PORTSC);
565 phy->ctrlr_suspended = true;
566 /* Wait until port suspend completes */
567 if (usb_phy_reg_status_wait(base + USB_PORTSC,
568 USB_PORTSC_SUSP, USB_PORTSC_SUSP, 4000)) {
569 pr_err("%s: timeout waiting for PORT_SUSPEND\n",
574 PHY_DBG("[%d] USB_USBSTS[0x%x] USB_PORTSC[0x%x] port_speed[%d]\n",
575 __LINE__, readl(base + USB_USBSTS), readl(base + USB_PORTSC),
578 DBG("USB_USBSTS[0x%x] USB_PORTSC[0x%x]\n",
579 readl(base + USB_USBSTS), readl(base + USB_PORTSC));
583 static unsigned int utmi_phy_xcvr_setup_value(struct tegra_usb_phy *phy)
585 struct tegra_utmi_config *cfg = &phy->pdata->u_cfg.utmi;
588 DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
590 if (cfg->xcvr_use_fuses) {
591 val = XCVR_SETUP(tegra_fuse_readl(FUSE_USB_CALIB_0));
592 if (cfg->xcvr_use_lsb) {
593 val = min((unsigned int) ((val & XCVR_SETUP_LSB_MASK)
594 + cfg->xcvr_setup_offset),
595 (unsigned int) XCVR_SETUP_LSB_MAX_VAL);
596 val |= (cfg->xcvr_setup & XCVR_SETUP_MSB_MASK);
598 if (cfg->xcvr_setup_offset <= UTMIP_XCVR_MAX_OFFSET)
599 val = val + cfg->xcvr_setup_offset;
601 if (val > UTMIP_XCVR_SETUP_MAX_VALUE) {
602 val = UTMIP_XCVR_SETUP_MAX_VALUE;
603 pr_info("%s: reset XCVR_SETUP to max value\n",
605 } else if (val < UTMIP_XCVR_SETUP_MIN_VALUE) {
606 val = UTMIP_XCVR_SETUP_MIN_VALUE;
607 pr_info("%s: reset XCVR_SETUP to min value\n",
612 val = cfg->xcvr_setup;
615 return (unsigned int) val;
618 static int utmi_phy_open(struct tegra_usb_phy *phy)
620 struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
622 unsigned long parent_rate;
625 DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
627 phy->utmi_pad_clk = clk_get_sys("utmip-pad", NULL);
628 if (IS_ERR(phy->utmi_pad_clk)) {
629 pr_err("%s: can't get utmip pad clock\n", __func__);
630 return PTR_ERR(phy->utmi_pad_clk);
634 phy->utmi_xcvr_setup = utmi_phy_xcvr_setup_value(phy);
636 if (tegra_platform_is_silicon()) {
637 parent_rate = clk_get_rate(clk_get_parent(phy->pllu_clk));
638 for (i = 0; i < ARRAY_SIZE(utmip_freq_table); i++) {
639 if (utmip_freq_table[i].freq == parent_rate) {
640 phy->freq = &utmip_freq_table[i];
645 pr_err("invalid pll_u parent rate %ld\n", parent_rate);
650 /* Power-up the VBUS, ID detector for UTMIP PHY */
651 if (phy->pdata->id_det_type == TEGRA_USB_ID)
652 tegra_usb_pmc_reg_update(PMC_USB_AO,
653 PMC_USB_AO_VBUS_WAKEUP_PD_P0 | PMC_USB_AO_ID_PD_P0, 0);
655 tegra_usb_pmc_reg_update(PMC_USB_AO,
656 PMC_USB_AO_VBUS_WAKEUP_PD_P0, PMC_USB_AO_ID_PD_P0);
658 pmc->pmc_ops->powerup_pmc_wake_detect(pmc);
663 static void utmi_phy_close(struct tegra_usb_phy *phy)
666 void __iomem *base = phy->regs;
667 struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
669 DBG("%s inst:[%d]\n", __func__, phy->inst);
671 /* Disable PHY clock valid interrupts while going into suspend*/
673 val = readl(base + USB_SUSP_CTRL);
674 val &= ~USB_PHY_CLK_VALID_INT_ENB;
675 writel(val, base + USB_SUSP_CTRL);
678 val = tegra_usb_pmc_reg_read(PMC_SLEEP_CFG);
679 if (val & UTMIP_MASTER_ENABLE(phy->inst)) {
680 pmc->pmc_ops->disable_pmc_bus_ctrl(pmc, 0);
682 phy->pmc_remote_wakeup = false;
683 phy->pmc_hotplug_wakeup = false;
684 PHY_DBG("%s DISABLE_PMC inst = %d\n", __func__, phy->inst);
687 clk_put(phy->utmi_pad_clk);
690 static int utmi_phy_irq(struct tegra_usb_phy *phy)
692 void __iomem *base = phy->regs;
693 unsigned long val = 0;
694 bool remote_wakeup = false;
695 int irq_status = IRQ_HANDLED;
697 if (phy->phy_clk_on) {
698 DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
699 DBG("USB_USBSTS[0x%x] USB_PORTSC[0x%x]\n",
700 readl(base + USB_USBSTS), readl(base + USB_PORTSC));
701 DBG("USB_USBMODE[0x%x] USB_USBCMD[0x%x]\n",
702 readl(base + USB_USBMODE), readl(base + USB_USBCMD));
704 if (!phy->pdata->unaligned_dma_buf_supported)
705 usb_phy_fence_read(phy);
706 /* check if it is pmc wake event */
707 if (utmi_phy_remotewake_detected(phy))
708 remote_wakeup = phy->pmc_remote_wakeup;
711 val = readl(base + USB_SUSP_CTRL);
712 if ((val & USB_PHY_CLK_VALID_INT_STS) &&
713 (val & USB_PHY_CLK_VALID_INT_ENB)) {
714 val &= ~USB_PHY_CLK_VALID_INT_ENB |
715 USB_PHY_CLK_VALID_INT_STS;
716 writel(val , (base + USB_SUSP_CTRL));
718 /* In case of remote wakeup PHY clock will not up
719 * immediately, so should not access any controller
720 * register but normal plug-in/plug-out should be
723 if (!remote_wakeup) {
724 val = readl(base + USB_USBSTS);
725 if (!(val & USB_USBSTS_PCI)) {
726 irq_status = IRQ_NONE;
730 val = readl(base + USB_PORTSC);
731 if (val & USB_PORTSC_CCS)
732 val &= ~USB_PORTSC_WKCN;
734 val &= ~USB_PORTSC_WKDS;
735 val &= ~USB_PORTSC_RWC_BITS;
736 writel(val , (base + USB_PORTSC));
738 } else if (!phy->phy_clk_on) {
740 irq_status = IRQ_HANDLED;
742 irq_status = IRQ_NONE;
750 static void utmi_phy_enable_obs_bus(struct tegra_usb_phy *phy)
753 void __iomem *base = phy->regs;
755 /* (2LS WAR)is not required for LS and FS devices and is only for HS */
756 /* Force DP/DM pulldown active for Host mode */
757 val = readl(base + UTMIP_MISC_CFG0);
758 val |= FORCE_PULLDN_DM | FORCE_PULLDN_DP |
759 COMB_TERMS | ALWAYS_FREE_RUNNING_TERMS;
760 writel(val, base + UTMIP_MISC_CFG0);
761 val = readl(base + UTMIP_MISC_CFG0);
762 val &= ~UTMIP_DPDM_OBSERVE_SEL(~0);
763 if (phy->port_speed == USB_PHY_PORT_SPEED_LOW)
764 val |= UTMIP_DPDM_OBSERVE_SEL_FS_J;
766 val |= UTMIP_DPDM_OBSERVE_SEL_FS_K;
767 writel(val, base + UTMIP_MISC_CFG0);
770 val = readl(base + UTMIP_MISC_CFG0);
771 val |= UTMIP_DPDM_OBSERVE;
772 writel(val, base + UTMIP_MISC_CFG0);
774 DBG("%s(%d) Enable OBS bus\n", __func__, __LINE__);
775 PHY_DBG("ENABLE_OBS_BUS\n");
778 static int utmi_phy_disable_obs_bus(struct tegra_usb_phy *phy)
780 void __iomem *base = phy->regs;
781 unsigned long val, port_speed;
783 /* check if OBS bus is already enabled */
784 val = readl(base + UTMIP_MISC_CFG0);
785 if (val & UTMIP_DPDM_OBSERVE) {
786 PHY_DBG("DISABLE_OBS_BUS\n");
788 /* disable ALL interrupts on current CPU */
789 local_irq_save(flags);
791 /* Change the UTMIP OBS bus to drive SE0 */
792 val = readl(base + UTMIP_MISC_CFG0);
793 val &= ~UTMIP_DPDM_OBSERVE_SEL(~0);
794 val |= UTMIP_DPDM_OBSERVE_SEL_FS_SE0;
795 writel(val, base + UTMIP_MISC_CFG0);
797 port_speed = (readl(base + USB_PORTSC) >> 26) &
798 USB_PORTSC_PSPD_MASK;
799 if (port_speed == USB_PHY_PORT_SPEED_FULL) {
800 val = readl(base + UTMIP_MISC_CFG0);
801 val |= UTMIP_DPDM_OBSERVE_SEL_FS_J;
802 writel(val, base + UTMIP_MISC_CFG0);
805 /* Release UTMIP OBS bus */
806 val = readl(base + UTMIP_MISC_CFG0);
807 val &= ~UTMIP_DPDM_OBSERVE;
808 writel(val, base + UTMIP_MISC_CFG0);
810 /* Release DP/DM pulldown for Host mode */
811 val = readl(base + UTMIP_MISC_CFG0);
812 val &= ~(FORCE_PULLDN_DM | FORCE_PULLDN_DP |
813 COMB_TERMS | ALWAYS_FREE_RUNNING_TERMS);
814 writel(val, base + UTMIP_MISC_CFG0);
816 val = readl(base + USB_USBCMD);
817 val |= USB_USBCMD_RS;
818 writel(val, base + USB_USBCMD);
819 /* restore ALL interrupts on current CPU */
820 local_irq_restore(flags);
822 if (usb_phy_reg_status_wait(base + USB_USBCMD, USB_USBCMD_RS,
823 USB_USBCMD_RS, 2000)) {
824 pr_err("%s: timeout waiting for USB_USBCMD_RS\n",
832 static int utmi_phy_post_resume(struct tegra_usb_phy *phy)
835 unsigned int inst = phy->inst;
836 struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
838 DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
839 if (phy->port_speed == USB_PHY_PORT_SPEED_FULL) {
840 val = tegra_usb_pmc_reg_read(PMC_SLEEP_CFG);
841 /* if PMC is not disabled by now then disable it */
842 if (val & UTMIP_MASTER_ENABLE(inst))
843 pmc->pmc_ops->disable_pmc_bus_ctrl(pmc, 0);
845 utmi_phy_disable_obs_bus(phy);
850 static int utmi_phy_pre_resume(struct tegra_usb_phy *phy, bool remote_wakeup)
853 unsigned int inst = phy->inst;
854 struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
856 DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
857 val = tegra_usb_pmc_reg_read(PMC_SLEEP_CFG);
858 if (val & UTMIP_MASTER_ENABLE(inst)) {
859 if (!remote_wakeup) {
860 pmc->pmc_ops->disable_pmc_bus_ctrl(pmc, 0);
861 phy->pmc_remote_wakeup = false;
862 phy->pmc_hotplug_wakeup = false;
863 PHY_DBG("%s DISABLE_PMC inst = %d\n", __func__, inst);
866 if (phy->port_speed == USB_PHY_PORT_SPEED_FULL)
867 utmi_phy_enable_obs_bus(phy);
873 static int utmi_phy_power_off(struct tegra_usb_phy *phy)
876 void __iomem *base = phy->regs;
877 struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
879 PHY_DBG("%s(%d) inst:[%d] BEGIN\n", __func__, __LINE__, phy->inst);
880 if (!phy->phy_clk_on) {
881 PHY_DBG("%s(%d) inst:[%d] phy clk is already off\n",
882 __func__, __LINE__, phy->inst);
886 if (phy->pdata->op_mode == TEGRA_USB_OPMODE_DEVICE) {
887 pmc_data[phy->inst].is_xhci = phy->pdata->u_data.dev.is_xhci;
888 pmc->pmc_ops->powerdown_pmc_wake_detect(pmc);
889 val = readl(base + USB_SUSP_CTRL);
890 val &= ~USB_WAKEUP_DEBOUNCE_COUNT(~0);
891 val |= USB_WAKE_ON_CNNT_EN_DEV | USB_WAKEUP_DEBOUNCE_COUNT(5);
892 writel(val, base + USB_SUSP_CTRL);
894 val = readl(base + UTMIP_BAT_CHRG_CFG0);
895 val |= UTMIP_PD_CHRG;
896 writel(val, base + UTMIP_BAT_CHRG_CFG0);
898 phy->port_speed = (readl(base + HOSTPC1_DEVLC) >> 25) &
899 HOSTPC1_DEVLC_PSPD_MASK;
901 /* Disable interrupts */
902 writel(0, base + USB_USBINTR);
904 /* Clear the run bit to stop SOFs when USB is suspended */
905 val = readl(base + USB_USBCMD);
906 val &= ~USB_USBCMD_RS;
907 writel(val, base + USB_USBCMD);
909 if (usb_phy_reg_status_wait(base + USB_USBSTS, USB_USBSTS_HCH,
910 USB_USBSTS_HCH, 2000)) {
911 pr_err("%s: timeout waiting for USB_USBSTS_HCH\n"
915 pmc_data[phy->inst].port_speed = (readl(base +
916 HOSTPC1_DEVLC) >> 25) &
917 HOSTPC1_DEVLC_PSPD_MASK;
919 if (pmc_data[phy->inst].port_speed <
920 USB_PMC_PORT_SPEED_UNKNOWN)
921 phy->pmc_remote_wakeup = false;
923 phy->pmc_hotplug_wakeup = false;
925 if (phy->pdata->port_otg) {
926 bool id_present = false;
927 val = readl(base + USB_PHY_VBUS_WAKEUP_ID);
928 id_present = (val & USB_ID_STATUS) ? false : true;
930 pmc->pmc_ops->setup_pmc_wake_detect(pmc);
932 pmc->pmc_ops->setup_pmc_wake_detect(pmc);
935 val = readl(base + UTMIP_PMC_WAKEUP0);
936 val |= EVENT_INT_ENB;
937 writel(val, base + UTMIP_PMC_WAKEUP0);
938 PHY_DBG("%s ENABLE_PMC inst = %d\n", __func__, phy->inst);
940 val = readl(base + USB_SUSP_CTRL);
941 val &= ~USB_WAKE_ON_CNNT_EN_DEV;
942 writel(val, base + USB_SUSP_CTRL);
945 if (!phy->hot_plug) {
946 val = readl(base + UTMIP_XCVR_CFG0);
947 val |= (UTMIP_FORCE_PD_POWERDOWN | UTMIP_FORCE_PD2_POWERDOWN |
948 UTMIP_FORCE_PDZI_POWERDOWN);
949 writel(val, base + UTMIP_XCVR_CFG0);
952 val = readl(base + UTMIP_XCVR_CFG1);
953 val |= UTMIP_FORCE_PDDISC_POWERDOWN | UTMIP_FORCE_PDCHRP_POWERDOWN |
954 UTMIP_FORCE_PDDR_POWERDOWN;
955 writel(val, base + UTMIP_XCVR_CFG1);
957 val = readl(base + UTMIP_BIAS_CFG1);
958 val |= UTMIP_BIAS_PDTRK_COUNT(0x5);
959 writel(val, base + UTMIP_BIAS_CFG1);
962 bool enable_hotplug = true;
963 /* if it is OTG port then make sure to enable hot-plug feature
964 only if host adaptor is connected, i.e id is low */
965 if (phy->pdata->port_otg) {
966 val = readl(base + USB_PHY_VBUS_WAKEUP_ID);
967 enable_hotplug = (val & USB_ID_STATUS) ? false : true;
969 if (enable_hotplug) {
970 /* Enable wakeup event of device plug-in/plug-out */
971 val = readl(base + USB_PORTSC);
972 if (val & USB_PORTSC_CCS)
973 val |= USB_PORTSC_WKDS;
975 val |= USB_PORTSC_WKCN;
976 writel(val, base + USB_PORTSC);
978 if (val & USB_PORTSC_CCS) {
979 val = readl(base + USB_SUSP_CTRL);
980 val &= ~USB_PHY_CLK_VALID_INT_ENB;
982 val = readl(base + USB_SUSP_CTRL);
983 val |= USB_PHY_CLK_VALID_INT_ENB;
985 writel(val, base + USB_SUSP_CTRL);
987 /* Disable PHY clock valid interrupts while going into suspend*/
988 val = readl(base + USB_SUSP_CTRL);
989 val &= ~USB_PHY_CLK_VALID_INT_ENB;
990 writel(val, base + USB_SUSP_CTRL);
994 /* Disable PHY clock */
995 val = readl(base + HOSTPC1_DEVLC);
996 val |= HOSTPC1_DEVLC_PHCD;
997 writel(val, base + HOSTPC1_DEVLC);
999 if (!phy->hot_plug) {
1000 val = readl(base + USB_SUSP_CTRL);
1002 writel(val, base + USB_SUSP_CTRL);
1005 utmi_phy_pad_disable();
1006 utmi_phy_iddq_override(true);
1008 phy->phy_clk_on = false;
1009 phy->hw_accessible = false;
1011 PHY_DBG("%s(%d) inst:[%d] END\n", __func__, __LINE__, phy->inst);
1017 static int utmi_phy_power_on(struct tegra_usb_phy *phy)
1020 void __iomem *base = phy->regs;
1021 #ifdef CONFIG_ARCH_TEGRA_11x_SOC
1022 void __iomem *padctl_base = IO_ADDRESS(TEGRA_XUSB_PADCTL_BASE);
1024 struct tegra_utmi_config *config = &phy->pdata->u_cfg.utmi;
1025 struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
1027 PHY_DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
1028 if (phy->phy_clk_on) {
1029 PHY_DBG("%s(%d) inst:[%d] phy clk is already On\n",
1030 __func__, __LINE__, phy->inst);
1033 val = readl(base + USB_SUSP_CTRL);
1035 writel(val, base + USB_SUSP_CTRL);
1037 val = readl(base + UTMIP_TX_CFG0);
1038 val |= UTMIP_FS_PREABMLE_J;
1039 writel(val, base + UTMIP_TX_CFG0);
1041 val = readl(base + USB_USBMODE);
1042 val &= ~USB_USBMODE_MASK;
1043 if (phy->pdata->op_mode == TEGRA_USB_OPMODE_HOST)
1044 val |= USB_USBMODE_HOST;
1046 val |= USB_USBMODE_DEVICE;
1047 writel(val, base + USB_USBMODE);
1049 val = readl(base + UTMIP_HSRX_CFG0);
1050 val &= ~(UTMIP_IDLE_WAIT(~0) | UTMIP_ELASTIC_LIMIT(~0));
1051 val |= UTMIP_IDLE_WAIT(config->idle_wait_delay);
1052 val |= UTMIP_ELASTIC_LIMIT(config->elastic_limit);
1053 writel(val, base + UTMIP_HSRX_CFG0);
1055 val = readl(base + UTMIP_HSRX_CFG1);
1056 val &= ~UTMIP_HS_SYNC_START_DLY(~0);
1057 val |= UTMIP_HS_SYNC_START_DLY(config->hssync_start_delay);
1058 writel(val, base + UTMIP_HSRX_CFG1);
1060 if (tegra_platform_is_silicon()) {
1061 val = readl(base + UTMIP_DEBOUNCE_CFG0);
1062 val &= ~UTMIP_BIAS_DEBOUNCE_A(~0);
1063 val |= UTMIP_BIAS_DEBOUNCE_A(phy->freq->debounce);
1064 writel(val, base + UTMIP_DEBOUNCE_CFG0);
1067 val = readl(base + UTMIP_MISC_CFG0);
1068 val &= ~UTMIP_SUSPEND_EXIT_ON_EDGE;
1069 writel(val, base + UTMIP_MISC_CFG0);
1071 if (phy->pdata->op_mode == TEGRA_USB_OPMODE_DEVICE) {
1072 val = readl(base + USB_SUSP_CTRL);
1073 val &= ~(USB_WAKE_ON_CNNT_EN_DEV | USB_WAKE_ON_DISCON_EN_DEV);
1074 writel(val, base + USB_SUSP_CTRL);
1076 val = readl(base + UTMIP_BAT_CHRG_CFG0);
1077 val &= ~UTMIP_PD_CHRG;
1078 writel(val, base + UTMIP_BAT_CHRG_CFG0);
1080 val = readl(base + UTMIP_BAT_CHRG_CFG0);
1081 val |= UTMIP_PD_CHRG;
1082 writel(val, base + UTMIP_BAT_CHRG_CFG0);
1085 utmi_phy_pad_enable();
1087 val = readl(base + UTMIP_XCVR_CFG0);
1088 val &= ~(UTMIP_XCVR_LSBIAS_SEL | UTMIP_FORCE_PD_POWERDOWN |
1089 UTMIP_FORCE_PD2_POWERDOWN | UTMIP_FORCE_PDZI_POWERDOWN |
1090 UTMIP_XCVR_SETUP(~0) | UTMIP_XCVR_LSFSLEW(~0) |
1091 UTMIP_XCVR_LSRSLEW(~0) | UTMIP_XCVR_HSSLEW_MSB(~0));
1092 val |= UTMIP_XCVR_SETUP(phy->utmi_xcvr_setup);
1093 val |= UTMIP_XCVR_SETUP_MSB(XCVR_SETUP_MSB_CALIB(phy->utmi_xcvr_setup));
1094 val |= UTMIP_XCVR_LSFSLEW(config->xcvr_lsfslew);
1095 val |= UTMIP_XCVR_LSRSLEW(config->xcvr_lsrslew);
1096 if (!config->xcvr_use_lsb) {
1097 if (!config->xcvr_hsslew_msb)
1098 val |= UTMIP_XCVR_HSSLEW_MSB(3);
1100 val |= UTMIP_XCVR_HSSLEW_MSB(config->xcvr_hsslew_msb);
1102 if (config->xcvr_hsslew_lsb)
1103 val |= UTMIP_XCVR_HSSLEW_LSB(config->xcvr_hsslew_lsb);
1104 writel(val, base + UTMIP_XCVR_CFG0);
1106 val = readl(base + UTMIP_XCVR_CFG1);
1107 val &= ~(UTMIP_FORCE_PDDISC_POWERDOWN | UTMIP_FORCE_PDCHRP_POWERDOWN |
1108 UTMIP_FORCE_PDDR_POWERDOWN | UTMIP_XCVR_TERM_RANGE_ADJ(~0));
1109 val |= UTMIP_XCVR_TERM_RANGE_ADJ(config->term_range_adj);
1110 writel(val, base + UTMIP_XCVR_CFG1);
1112 if (tegra_platform_is_silicon()) {
1113 val = readl(base + UTMIP_BIAS_CFG1);
1114 val &= ~UTMIP_BIAS_PDTRK_COUNT(~0);
1115 val |= UTMIP_BIAS_PDTRK_COUNT(phy->freq->pdtrk_count);
1116 writel(val, base + UTMIP_BIAS_CFG1);
1119 val = readl(base + UTMIP_SPARE_CFG0);
1120 val |= FUSE_SETUP_SEL;
1121 #ifdef CONFIG_ARCH_TEGRA_13x_SOC
1122 val &= ~FUSE_SETUP_SEL;
1124 val |= FUSE_ATERM_SEL;
1125 writel(val, base + UTMIP_SPARE_CFG0);
1127 val = readl(base + USB_SUSP_CTRL);
1128 val |= UTMIP_PHY_ENABLE;
1129 writel(val, base + USB_SUSP_CTRL);
1131 val = readl(base + USB_SUSP_CTRL);
1132 val &= ~UTMIP_RESET;
1133 writel(val, base + USB_SUSP_CTRL);
1135 /* Bring UTMIPLL out of IDDQ mode while exiting from reset/suspend */
1136 utmi_phy_iddq_override(false);
1138 if (usb_phy_reg_status_wait(base + USB_SUSP_CTRL,
1139 USB_PHY_CLK_VALID, USB_PHY_CLK_VALID, 2500))
1140 pr_warn("%s: timeout waiting for phy to stabilize\n", __func__);
1142 val = readl(base + HOSTPC1_DEVLC);
1143 val &= ~HOSTPC1_DEVLC_PHCD;
1144 writel(val, base + HOSTPC1_DEVLC);
1146 utmi_phy_set_snps_trking_data();
1149 writel(0, base + ICUSB_CTRL);
1151 val = readl(base + USB_USBMODE);
1152 val &= ~USB_USBMODE_MASK;
1153 if (phy->pdata->op_mode == TEGRA_USB_OPMODE_HOST)
1154 val |= USB_USBMODE_HOST;
1156 val |= USB_USBMODE_DEVICE;
1157 writel(val, base + USB_USBMODE);
1159 val = readl(base + HOSTPC1_DEVLC);
1160 val &= ~HOSTPC1_DEVLC_PTS(~0);
1161 val |= HOSTPC1_DEVLC_STS;
1162 writel(val, base + HOSTPC1_DEVLC);
1164 if (phy->pdata->op_mode == TEGRA_USB_OPMODE_DEVICE) {
1165 pmc_data[phy->inst].is_xhci = phy->pdata->u_data.dev.is_xhci;
1166 pmc->pmc_ops->powerup_pmc_wake_detect(pmc);
1169 if (!readl(base + USB_ASYNCLISTADDR))
1171 val = readl(base + USB_TXFILLTUNING);
1172 if ((val & USB_FIFO_TXFILL_MASK) !=
1173 USB_FIFO_TXFILL_THRES(0x10)) {
1174 val = USB_FIFO_TXFILL_THRES(0x10);
1175 writel(val, base + USB_TXFILLTUNING);
1178 phy->phy_clk_on = true;
1179 phy->hw_accessible = true;
1181 #ifdef CONFIG_ARCH_TEGRA_11x_SOC
1182 val = readl(padctl_base + PADCTL_SNPS_OC_MAP);
1183 val |= CONTROLLER_OC(phy->inst, 0x4);
1184 writel(val, padctl_base + PADCTL_SNPS_OC_MAP);
1186 val = readl(padctl_base + PADCTL_OC_DET);
1188 val |= ENABLE0_OC_MAP(config->vbus_oc_map);
1190 val |= ENABLE1_OC_MAP(config->vbus_oc_map);
1191 writel(val, padctl_base + PADCTL_OC_DET);
1194 PHY_DBG("%s(%d) End inst:[%d]\n", __func__, __LINE__, phy->inst);
1198 static void utmi_phy_restore_start(struct tegra_usb_phy *phy)
1201 int inst = phy->inst;
1202 struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
1204 DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
1205 val = tegra_usb_pmc_reg_read(UTMIP_STATUS);
1206 /* Check whether we wake up from the remote resume.
1207 For lp1 case, pmc is not responsible for waking the
1208 system, it's the flow controller and hence
1209 UTMIP_WALK_PTR_VAL(inst) will return 0.
1210 Also, for lp1 case phy->pmc_remote_wakeup will already be set
1211 to true by utmi_phy_irq() when the remote wakeup happens.
1212 Hence change the logic in the else part to enter only
1213 if phy->pmc_remote_wakeup is not set to true by the
1215 if (UTMIP_WALK_PTR_VAL(inst) & val) {
1216 phy->pmc_remote_wakeup = true;
1217 } else if (!phy->pmc_remote_wakeup) {
1218 val = tegra_usb_pmc_reg_read(PMC_SLEEP_CFG);
1219 if (val & UTMIP_MASTER_ENABLE(inst))
1220 pmc->pmc_ops->disable_pmc_bus_ctrl(pmc, 0);
1222 if (phy->port_speed == USB_PHY_PORT_SPEED_FULL)
1223 utmi_phy_enable_obs_bus(phy);
1227 static void utmi_phy_restore_end(struct tegra_usb_phy *phy)
1229 unsigned long val, flags = 0;
1230 void __iomem *base = phy->regs;
1231 int wait_time_us = 25000; /* FPR should be set by this time */
1232 struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
1234 DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
1235 /* check whether we wake up from the remote resume */
1236 if (phy->pmc_remote_wakeup) {
1237 /* wait until SUSPEND and RESUME bit
1238 * is cleared on remote resume */
1240 val = readl(base + USB_PORTSC);
1242 if (wait_time_us == 0) {
1243 PHY_DBG("%s PMC FPR" \
1244 "timeout val = 0x%x instance = %d\n", \
1245 __func__, (u32)val, phy->inst);
1246 if (phy->port_speed ==
1247 USB_PHY_PORT_SPEED_FULL) {
1248 val = readl(base + UTMIP_PMC_WAKEUP0);
1249 val &= ~EVENT_INT_ENB;
1250 writel(val, base + UTMIP_PMC_WAKEUP0);
1252 pmc->pmc_ops->disable_pmc_bus_ctrl(pmc, 0);
1253 phy->pmc_remote_wakeup = false;
1254 phy->pmc_hotplug_wakeup = false;
1256 if (phy->port_speed == USB_PHY_PORT_SPEED_FULL)
1257 utmi_phy_post_resume(phy);
1261 } while (val & (USB_PORTSC_RESUME | USB_PORTSC_SUSP));
1263 /* Add delay sothat resume will be driven for more than 20 ms */
1264 if (phy->port_speed != USB_PHY_PORT_SPEED_FULL) {
1266 local_irq_save(flags);
1267 pmc->pmc_ops->disable_pmc_bus_ctrl(pmc, 1);
1268 phy->pmc_remote_wakeup = false;
1269 phy->pmc_hotplug_wakeup = false;
1270 local_irq_restore(flags);
1273 local_irq_save(flags);
1274 pmc->pmc_ops->disable_pmc_bus_ctrl(pmc, 0);
1275 phy->pmc_remote_wakeup = false;
1276 phy->pmc_hotplug_wakeup = false;
1277 local_irq_restore(flags);
1280 PHY_DBG("%s DISABLE_PMC inst = %d\n", __func__, phy->inst);
1282 if (usb_phy_reg_status_wait(base + USB_USBCMD, USB_USBCMD_RS,
1283 USB_USBCMD_RS, 2000)) {
1284 pr_err("%s: timeout waiting for USB_USBCMD_RS\n",\
1288 /* Clear PCI and SRI bits to avoid an interrupt upon resume */
1289 val = readl(base + USB_USBSTS);
1290 writel(val, base + USB_USBSTS);
1291 /* wait to avoid SOF if there is any */
1292 if (usb_phy_reg_status_wait(base + USB_USBSTS,
1293 USB_USBSTS_SRI, USB_USBSTS_SRI, 2500) < 0) {
1294 pr_err("%s: timeout waiting for SOF\n", __func__);
1297 if (phy->port_speed != USB_PHY_PORT_SPEED_FULL) {
1298 pmc->pmc_ops->disable_pmc_bus_ctrl(pmc, 0);
1299 phy->pmc_remote_wakeup = false;
1300 phy->pmc_hotplug_wakeup = false;
1301 PHY_DBG("%s DISABLE_PMC inst = %d\n",
1302 __func__, phy->inst);
1305 if (phy->port_speed == USB_PHY_PORT_SPEED_FULL)
1306 utmi_phy_post_resume(phy);
1309 static int utmi_phy_resume(struct tegra_usb_phy *phy)
1313 int port_connected = 0;
1315 void __iomem *base = phy->regs;
1316 struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
1318 DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
1319 if (phy->pdata->op_mode == TEGRA_USB_OPMODE_HOST) {
1320 if (readl(base + USB_ASYNCLISTADDR) &&
1321 !phy->pdata->u_data.host.power_off_on_suspend)
1324 val = readl(base + USB_PORTSC);
1325 port_connected = val & USB_PORTSC_CCS;
1326 is_lp0 = !(readl(base + USB_ASYNCLISTADDR));
1328 if ((phy->port_speed < USB_PHY_PORT_SPEED_UNKNOWN) &&
1329 (port_connected ^ is_lp0)) {
1330 utmi_phy_restore_start(phy);
1331 usb_phy_bringup_host_controller(phy);
1332 utmi_phy_restore_end(phy);
1334 pmc->pmc_ops->disable_pmc_bus_ctrl(pmc, 0);
1335 phy->pmc_remote_wakeup = false;
1336 phy->pmc_hotplug_wakeup = false;
1338 /* bring up the controller from suspend*/
1339 val = readl(base + USB_USBCMD);
1340 val |= USB_CMD_RESET;
1341 writel(val, base + USB_USBCMD);
1343 if (usb_phy_reg_status_wait(base + USB_USBCMD,
1344 USB_CMD_RESET, 0, 2500) < 0) {
1345 pr_err("%s: timeout waiting for reset\n", __func__);
1348 val = readl(base + USB_USBMODE);
1349 val &= ~USB_USBMODE_MASK;
1350 val |= USB_USBMODE_HOST;
1351 writel(val, base + USB_USBMODE);
1353 val = readl(base + HOSTPC1_DEVLC);
1354 val &= ~HOSTPC1_DEVLC_PTS(~0);
1355 val |= HOSTPC1_DEVLC_STS;
1356 writel(val, base + HOSTPC1_DEVLC);
1358 writel(USB_USBCMD_RS, base + USB_USBCMD);
1360 if (usb_phy_reg_status_wait(base + USB_USBCMD,
1361 USB_USBCMD_RS, USB_USBCMD_RS, 2500) < 0) {
1362 pr_err("%s: timeout waiting for run bit\n", __func__);
1365 /* Enable Port Power */
1366 val = readl(base + USB_PORTSC);
1367 val |= USB_PORTSC_PP;
1368 writel(val, base + USB_PORTSC);
1371 DBG("USB_USBSTS[0x%x] USB_PORTSC[0x%x]\n",
1372 readl(base + USB_USBSTS), readl(base + USB_PORTSC));
1374 val = readl(base + USB_TXFILLTUNING);
1375 if ((val & USB_FIFO_TXFILL_MASK) !=
1376 USB_FIFO_TXFILL_THRES(0x10)) {
1377 val = USB_FIFO_TXFILL_THRES(0x10);
1378 writel(val, base + USB_TXFILLTUNING);
1385 static unsigned long utmi_phy_set_dp_dm_pull_up_down(struct tegra_usb_phy *phy,
1386 unsigned long pull_up_down_flags)
1390 void __iomem *base = phy->regs;
1392 org = readl(base + UTMIP_MISC_CFG0);
1394 val = org & ~MASK_ALL_PULLUP_PULLDOWN;
1395 val |= pull_up_down_flags;
1397 writel(val, base + UTMIP_MISC_CFG0);
1399 usleep_range(500, 2000);
1403 unsigned long utmi_phy_get_dp_dm_status(struct tegra_usb_phy *phy,
1404 unsigned long pull_up_down_flags)
1406 void __iomem *base = phy->regs;
1407 unsigned long org_flags;
1410 org_flags = utmi_phy_set_dp_dm_pull_up_down(phy, pull_up_down_flags);
1411 ret = USB_PORTSC_LINE_STATE(readl(base + USB_PORTSC));
1412 utmi_phy_set_dp_dm_pull_up_down(phy, org_flags);
1416 static void disable_charger_detection(void __iomem *base)
1420 /* Disable charger detection logic */
1421 val = readl(base + UTMIP_BAT_CHRG_CFG0);
1422 val &= ~(UTMIP_OP_SRC_EN | UTMIP_ON_SINK_EN);
1423 val &= ~(UTMIP_ON_SRC_EN | UTMIP_OP_SINK_EN);
1424 writel(val, base + UTMIP_BAT_CHRG_CFG0);
1426 /* Delay of 40 ms before we pull the D+ as per battery charger spec */
1427 msleep(TDPSRC_CON_MS);
1431 * Per Battery Charging Specification 1.2 section 3.2.3:
1432 * We check Data Contact Detect (DCD) before we check the USB cable type.
1434 static bool utmi_phy_dcd_detect(struct tegra_usb_phy *phy)
1436 void __iomem *base = phy->regs;
1438 unsigned long org_flags;
1441 val = readl(base + UTMIP_BAT_CHRG_CFG0);
1442 /* inject IDP_SRC */
1443 val |= UTMIP_OP_I_SRC_EN;
1444 writel(val, base + UTMIP_BAT_CHRG_CFG0);
1445 /* enable pull down resistor RDM_DWN on D- */
1446 org_flags = utmi_phy_set_dp_dm_pull_up_down(phy,
1447 DISABLE_PULLUP_DP | DISABLE_PULLUP_DM |
1448 DISABLE_PULLDN_DP | FORCE_PULLDN_DM);
1449 usleep_range(20000, 30000);
1452 if (0 == USB_PORTSC_LINE_STATE(readl(base + USB_PORTSC))) {
1453 /* minimum debounce time is 10mS per TDCD_DBNC */
1454 usleep_range(10000, 12000);
1455 if (0 == USB_PORTSC_LINE_STATE(readl(base + USB_PORTSC)))
1459 val &= ~UTMIP_OP_I_SRC_EN;
1460 writel(val, base + UTMIP_BAT_CHRG_CFG0);
1461 utmi_phy_set_dp_dm_pull_up_down(phy, org_flags);
1465 static bool utmi_phy_charger_detect(struct tegra_usb_phy *phy)
1468 void __iomem *base = phy->regs;
1472 DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
1473 if (phy->pdata->op_mode != TEGRA_USB_OPMODE_DEVICE) {
1474 /* Charger detection is not there for ULPI
1475 * return Charger not available */
1479 /* ensure we start from an initial state */
1480 writel(0, base + UTMIP_BAT_CHRG_CFG0);
1481 utmi_phy_set_dp_dm_pull_up_down(phy, 0);
1483 /* log initial values */
1484 DBG("%s(%d) inst:[%d], UTMIP_BAT_CHRG_CFG0 = %08X\n",
1486 phy->inst, readl(base + UTMIP_BAT_CHRG_CFG0));
1487 DBG("%s(%d) inst:[%d], UTMIP_MISC_CFG0 = %08X\n",
1489 phy->inst, readl(base + UTMIP_MISC_CFG0));
1491 /* DCD timeout max value is 900mS */
1493 while (dcd_timeout_ms < 900) {
1494 /* standard DCD detect for SDP/DCP/CDP */
1495 if (utmi_phy_dcd_detect(phy))
1497 /* for NV-charger, we wait D+/D- both set */
1498 if ((USB_PORTSC_LINE_DP_SET | USB_PORTSC_LINE_DM_SET) ==
1499 utmi_phy_get_dp_dm_status(phy,
1500 DISABLE_PULLUP_DP | DISABLE_PULLUP_DM |
1501 DISABLE_PULLDN_DP | DISABLE_PULLDN_DM))
1503 usleep_range(20000, 22000);
1504 dcd_timeout_ms += 22;
1507 /* Enable charger detection logic */
1508 val = readl(base + UTMIP_BAT_CHRG_CFG0);
1509 val |= UTMIP_OP_SRC_EN | UTMIP_ON_SINK_EN;
1510 writel(val, base + UTMIP_BAT_CHRG_CFG0);
1512 /* Source should be on for 100 ms as per USB charging spec */
1513 msleep(TDP_SRC_ON_MS);
1515 val = readl(base + USB_PHY_VBUS_WAKEUP_ID);
1516 /* If charger is not connected disable the interrupt */
1517 val &= ~VDAT_DET_INT_EN;
1518 val |= VDAT_DET_CHG_DET;
1519 writel(val, base + USB_PHY_VBUS_WAKEUP_ID);
1521 val = readl(base + USB_PHY_VBUS_WAKEUP_ID);
1522 if (val & VDAT_DET_STS)
1526 disable_charger_detection(base);
1528 DBG("%s(%d) inst:[%d], UTMIP_BAT_CHRG_CFG0 = %08X\n",
1530 phy->inst, readl(base + UTMIP_BAT_CHRG_CFG0));
1531 DBG("%s(%d) inst:[%d], UTMIP_MISC_CFG0 = %08X\n",
1533 phy->inst, readl(base + UTMIP_MISC_CFG0));
1535 DBG("%s(%d) inst:[%d] DONE Status = %d\n",
1536 __func__, __LINE__, phy->inst, status);
1541 static bool cdp_charger_detection(struct tegra_usb_phy *phy)
1545 void __iomem *base = phy->regs;
1548 val = readl(base + UTMIP_BAT_CHRG_CFG0);
1549 val &= ~(UTMIP_OP_SRC_EN | UTMIP_ON_SINK_EN);
1550 val |= UTMIP_ON_SRC_EN | UTMIP_OP_SINK_EN;
1551 writel(val, base + UTMIP_BAT_CHRG_CFG0);
1553 DBG("%s(%d) UTMIP_BAT_CHRG_CFG0 = %08x\n",
1555 readl(base + UTMIP_BAT_CHRG_CFG0));
1559 val = readl(base + USB_PHY_VBUS_WAKEUP_ID);
1560 if (val & VDAT_DET_STS) {
1562 DBG("%s: DCP detected\n", __func__);
1565 disable_charger_detection(base);
1566 DBG("%s: No voltage from D- to D+ found\n", __func__);
1572 static bool maxim_charger_detection(struct tegra_usb_phy *phy)
1574 void __iomem *base = phy->regs;
1576 unsigned long org_flags;
1580 * Enable charger detection logic
1581 * 3.3V on D+, Sink D- (high speed usb)
1582 * Maxim charger will remove short !! -- DCP will not
1584 org_flags = utmi_phy_set_dp_dm_pull_up_down(phy,
1585 FORCE_PULLUP_DP | DISABLE_PULLUP_DM |
1586 DISABLE_PULLDN_DP | DISABLE_PULLDN_DM);
1587 val = readl(base + UTMIP_BAT_CHRG_CFG0);
1588 val &= ~(UTMIP_OP_SRC_EN | UTMIP_ON_SINK_EN);
1589 val &= ~(UTMIP_ON_SRC_EN | UTMIP_OP_SINK_EN);
1590 val |= UTMIP_ON_SINK_EN;
1591 writel(val, base + UTMIP_BAT_CHRG_CFG0);
1593 /* Source should be on at least 120 ms per Maxim spec */
1594 msleep(MAXIM_DEBOUNCE_TIME);
1596 val = readl(base + USB_PHY_VBUS_WAKEUP_ID);
1597 if (val & VDAT_DET_STS) {
1599 DBG("%s: Maxim charger not found\n", __func__);
1600 utmi_phy_set_dp_dm_pull_up_down(phy, org_flags);
1603 DBG("%s: Maxim Charger detected\n", __func__);
1606 disable_charger_detection(base);
1610 static bool utmi_phy_qc2_charger_detect(struct tegra_usb_phy *phy,
1614 void __iomem *base = phy->regs;
1618 unsigned long org_flags;
1619 #ifdef QC_MEASURE_VOLTAGES
1623 DBG("%s(%d) inst:[%d] max_voltage = %d\n",
1624 __func__, __LINE__, phy->inst, max_voltage);
1627 /* no need to detect qc2 if operating at 5V */
1628 switch (max_voltage) {
1629 case TEGRA_USB_QC2_5V:
1630 case TEGRA_USB_QC2_9V:
1631 case TEGRA_USB_QC2_12V:
1632 case TEGRA_USB_QC2_20V:
1635 disable_charger_detection(base);
1639 /* Ensure we start from an initial state */
1640 writel(0, base + UTMIP_BAT_CHRG_CFG0);
1641 utmi_phy_set_dp_dm_pull_up_down(phy, 0);
1643 /* Force wall charger detection logic to reset */
1644 org_flags = utmi_phy_set_dp_dm_pull_up_down(phy,
1645 FORCE_PULLDN_DP | FORCE_PULLDN_DM);
1648 utmi_phy_set_dp_dm_pull_up_down(phy, org_flags);
1650 /* Enable charger detection logic */
1651 val = readl(base + UTMIP_BAT_CHRG_CFG0);
1652 val |= UTMIP_OP_SRC_EN | UTMIP_ON_SINK_EN;
1653 writel(val, base + UTMIP_BAT_CHRG_CFG0);
1655 /* Source should be on for 100 ms as per USB charging spec */
1656 msleep(TDP_SRC_ON_MS);
1658 /* if vbus drops we are connected to quick charge 2 */
1660 while (qc2_timeout_ms < 1500) {
1661 usleep_range(1000, 1200);
1662 qc2_timeout_ms += 1;
1663 val = readl(base + USB_PHY_VBUS_WAKEUP_ID);
1664 if (!(val & VDAT_DET_STS)) {
1670 if (vbus_stat && qc2_timeout_ms > 100) {
1673 DBG("%s(%d) inst:[%d], QC2 DETECTED !!!",
1674 __func__, __LINE__, phy->inst);
1676 /* Wall charger needs time before setting D+/D- */
1679 switch (max_voltage) {
1680 case TEGRA_USB_QC2_9V:
1681 /* Set the input voltage to 9V */
1682 /* D+ 3.3v -- D- 0.6v */
1683 DBG("%s(%d) inst:[%d], QC 9V D+ 3.3v D- 0.6v",
1684 __func__, __LINE__, phy->inst);
1685 org_flags = utmi_phy_set_dp_dm_pull_up_down(phy,
1686 FORCE_PULLUP_DP | DISABLE_PULLUP_DM |
1687 DISABLE_PULLDN_DP | DISABLE_PULLDN_DM);
1688 val = readl(base + UTMIP_BAT_CHRG_CFG0);
1689 val &= ~(UTMIP_OP_SINK_EN | UTMIP_ON_SINK_EN);
1690 val |= UTMIP_ON_SRC_EN;
1691 val &= ~UTMIP_OP_SRC_EN;
1692 writel(val, base + UTMIP_BAT_CHRG_CFG0);
1695 case TEGRA_USB_QC2_12V:
1696 /* 0.6v v on D+ and D- */
1697 DBG("%s(%d) inst:[%d], QC 12V D+ 0.6v D- 0.6v",
1698 __func__, __LINE__, phy->inst);
1699 org_flags = utmi_phy_set_dp_dm_pull_up_down(phy,
1700 DISABLE_PULLUP_DP | DISABLE_PULLUP_DM |
1701 DISABLE_PULLDN_DP | DISABLE_PULLDN_DM);
1702 val = readl(base + UTMIP_BAT_CHRG_CFG0);
1703 val &= ~(UTMIP_OP_SINK_EN | UTMIP_ON_SINK_EN);
1704 val |= (UTMIP_OP_SRC_EN | UTMIP_ON_SRC_EN);
1705 writel(val, base + UTMIP_BAT_CHRG_CFG0);
1708 case TEGRA_USB_QC2_20V:
1709 /* 3.3 v on D+ and D- */
1710 DBG("%s(%d) inst:[%d], QC 20V D+ 3.3v D- 3.3v",
1711 __func__, __LINE__, phy->inst);
1712 org_flags = utmi_phy_set_dp_dm_pull_up_down(phy,
1713 FORCE_PULLUP_DP | FORCE_PULLUP_DM |
1714 DISABLE_PULLDN_DP | DISABLE_PULLDN_DM);
1715 val = readl(base + UTMIP_BAT_CHRG_CFG0);
1716 val &= ~(UTMIP_OP_SINK_EN | UTMIP_ON_SINK_EN);
1717 val &= ~(UTMIP_OP_SRC_EN | UTMIP_ON_SRC_EN);
1718 writel(val, base + UTMIP_BAT_CHRG_CFG0);
1721 case TEGRA_USB_QC2_5V:
1723 DBG("%s(%d) inst:[%d], QC 5V D+ 0.6v D- GND",
1724 __func__, __LINE__, phy->inst);
1725 org_flags = utmi_phy_set_dp_dm_pull_up_down(phy,
1726 DISABLE_PULLUP_DP | DISABLE_PULLUP_DM |
1727 DISABLE_PULLDN_DP | FORCE_PULLDN_DM);
1728 val = readl(base + UTMIP_BAT_CHRG_CFG0);
1729 val &= ~(UTMIP_OP_SINK_EN | UTMIP_ON_SINK_EN);
1730 val |= UTMIP_OP_SRC_EN;
1731 val &= ~UTMIP_ON_SRC_EN;
1732 writel(val, base + UTMIP_BAT_CHRG_CFG0);
1736 #ifdef QC_MEASURE_VOLTAGES
1738 DBG("%s(%d) MEASURE VOLTAGES -- you have %d seconds",
1739 __func__, __LINE__, timeout);
1740 while (timeout-- > 0) {
1741 DBG("%s(%d) COUNT = %d",
1742 __func__, __LINE__, timeout);
1749 * If QC2 charger detected do not disable the charger
1750 * detection voltage on D- and D+. Doing this will
1751 * cause it to move to 5V
1754 disable_charger_detection(base);
1756 DBG("%s(%d) inst:[%d] DONE Status = %d\n",
1757 __func__, __LINE__, phy->inst, status);
1761 static bool utmi_phy_is_non_std_charger(struct tegra_usb_phy *phy)
1764 * non std charger has D+/D- line float, we can apply pull up/down on
1765 * each line and verify if line status change.
1767 /* pull up DP only */
1768 if (USB_PORTSC_LINE_DP_SET != utmi_phy_get_dp_dm_status(phy,
1769 FORCE_PULLUP_DP | DISABLE_PULLUP_DM |
1770 DISABLE_PULLDN_DP | DISABLE_PULLDN_DM))
1771 goto NOT_NON_STD_CHARGER;
1773 /* pull down DP only */
1774 if (0x0 != utmi_phy_get_dp_dm_status(phy,
1775 DISABLE_PULLUP_DP | DISABLE_PULLUP_DM |
1776 FORCE_PULLDN_DP | DISABLE_PULLDN_DM))
1777 goto NOT_NON_STD_CHARGER;
1779 /* pull up DM only */
1780 if (USB_PORTSC_LINE_DM_SET != utmi_phy_get_dp_dm_status(phy,
1781 DISABLE_PULLUP_DP | FORCE_PULLUP_DM |
1782 DISABLE_PULLDN_DP | DISABLE_PULLDN_DM))
1783 goto NOT_NON_STD_CHARGER;
1785 /* pull down DM only */
1786 if (0x0 != utmi_phy_get_dp_dm_status(phy,
1787 DISABLE_PULLUP_DP | DISABLE_PULLUP_DM |
1788 DISABLE_PULLDN_DP | FORCE_PULLDN_DM))
1789 goto NOT_NON_STD_CHARGER;
1791 utmi_phy_set_dp_dm_pull_up_down(phy, 0);
1794 NOT_NON_STD_CHARGER:
1795 utmi_phy_set_dp_dm_pull_up_down(phy, 0);
1800 static void utmi_phy_pmc_disable(struct tegra_usb_phy *phy)
1802 struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
1803 if (phy->pdata->u_data.host.turn_off_vbus_on_lp0 &&
1804 phy->pdata->port_otg) {
1805 pmc->pmc_ops->disable_pmc_bus_ctrl(pmc, 0);
1806 pmc->pmc_ops->powerdown_pmc_wake_detect(pmc);
1809 static bool utmi_phy_nv_charger_detect(struct tegra_usb_phy *phy)
1816 DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
1818 if (utmi_phy_is_non_std_charger(phy))
1822 /* Turn off all terminations except DP pulldown */
1823 status1 = utmi_phy_get_dp_dm_status(phy,
1824 DISABLE_PULLUP_DP | DISABLE_PULLUP_DM |
1825 FORCE_PULLDN_DP | DISABLE_PULLDN_DM);
1827 /* Turn off all terminations except for DP pullup */
1828 status2 = utmi_phy_get_dp_dm_status(phy,
1829 FORCE_PULLUP_DP | DISABLE_PULLUP_DM |
1830 DISABLE_PULLDN_DP | DISABLE_PULLDN_DM);
1832 /* Check for NV charger DISABLE all terminations */
1833 status3 = utmi_phy_get_dp_dm_status(phy,
1834 DISABLE_PULLUP_DP | DISABLE_PULLUP_DM |
1835 DISABLE_PULLDN_DP | DISABLE_PULLDN_DM);
1837 if ((status1 == (USB_PORTSC_LINE_DP_SET | USB_PORTSC_LINE_DM_SET)) &&
1838 (status2 == (USB_PORTSC_LINE_DP_SET | USB_PORTSC_LINE_DM_SET)) &&
1839 (status3 == (USB_PORTSC_LINE_DP_SET | USB_PORTSC_LINE_DM_SET)))
1842 /* Restore standard termination by hardware. */
1843 utmi_phy_set_dp_dm_pull_up_down(phy, 0);
1847 static bool utmi_phy_apple_charger_1000ma_detect(struct tegra_usb_phy *phy)
1851 void __iomem *base = phy->regs;
1852 unsigned long org_flags;
1854 DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
1857 org_flags = utmi_phy_set_dp_dm_pull_up_down(phy,
1858 FORCE_PULLUP_DP | FORCE_PULLUP_DM |
1859 DISABLE_PULLDN_DP | DISABLE_PULLDN_DM);
1860 usleep_range(20000, 30000);
1861 utmi_phy_set_dp_dm_pull_up_down(phy,
1862 DISABLE_PULLUP_DP | DISABLE_PULLUP_DM |
1863 DISABLE_PULLDN_DP | DISABLE_PULLDN_DM);
1865 val = readl(base + USB_PHY_VBUS_WAKEUP_ID);
1867 writel(val, base + USB_PHY_VBUS_WAKEUP_ID);
1869 usleep_range(10000, 20000);
1871 val = readl(base + USB_PHY_VBUS_WAKEUP_ID);
1873 writel(val, base + USB_PHY_VBUS_WAKEUP_ID);
1875 if ((val & VOP_DIV2P0_DET) && (val & VON_DIV2P7_DET))
1878 utmi_phy_set_dp_dm_pull_up_down(phy, org_flags);
1883 static bool utmi_phy_apple_charger_2000ma_detect(struct tegra_usb_phy *phy)
1887 void __iomem *base = phy->regs;
1888 unsigned long org_flags;
1890 DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
1893 org_flags = utmi_phy_set_dp_dm_pull_up_down(phy,
1894 FORCE_PULLUP_DP | FORCE_PULLUP_DM |
1895 DISABLE_PULLDN_DP | DISABLE_PULLDN_DM);
1896 usleep_range(20000, 30000);
1897 utmi_phy_set_dp_dm_pull_up_down(phy,
1898 DISABLE_PULLUP_DP | DISABLE_PULLUP_DM |
1899 DISABLE_PULLDN_DP | DISABLE_PULLDN_DM);
1901 val = readl(base + USB_PHY_VBUS_WAKEUP_ID);
1903 writel(val, base + USB_PHY_VBUS_WAKEUP_ID);
1905 usleep_range(10000, 20000);
1907 val = readl(base + USB_PHY_VBUS_WAKEUP_ID);
1909 writel(val, base + USB_PHY_VBUS_WAKEUP_ID);
1911 if ((val & VOP_DIV2P7_DET) && (val & VON_DIV2P0_DET))
1914 utmi_phy_set_dp_dm_pull_up_down(phy, org_flags);
1919 static bool utmi_phy_apple_charger_500ma_detect(struct tegra_usb_phy *phy)
1923 void __iomem *base = phy->regs;
1924 unsigned long org_flags;
1926 DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
1929 org_flags = utmi_phy_set_dp_dm_pull_up_down(phy,
1930 FORCE_PULLUP_DP | FORCE_PULLUP_DM |
1931 DISABLE_PULLDN_DP | DISABLE_PULLDN_DM);
1932 usleep_range(20000, 30000);
1933 utmi_phy_set_dp_dm_pull_up_down(phy,
1934 DISABLE_PULLUP_DP | DISABLE_PULLUP_DM |
1935 DISABLE_PULLDN_DP | DISABLE_PULLDN_DM);
1937 val = readl(base + USB_PHY_VBUS_WAKEUP_ID);
1939 writel(val, base + USB_PHY_VBUS_WAKEUP_ID);
1941 usleep_range(10000, 20000);
1943 val = readl(base + USB_PHY_VBUS_WAKEUP_ID);
1945 writel(val, base + USB_PHY_VBUS_WAKEUP_ID);
1947 if ((val & VOP_DIV2P0_DET) && (val & VON_DIV2P0_DET))
1950 utmi_phy_set_dp_dm_pull_up_down(phy, org_flags);
1955 static bool uhsic_phy_remotewake_detected(struct tegra_usb_phy *phy)
1957 void __iomem *base = phy->regs;
1959 unsigned int inst = phy->inst;
1961 val = readl(base + UHSIC_PMC_WAKEUP0);
1962 if (!(val & EVENT_INT_ENB))
1964 val = tegra_usb_pmc_reg_read(UHSIC_STATUS(inst));
1965 if (!(UHSIC_WAKE_ALARM(inst) & val))
1967 tegra_usb_pmc_reg_update(PMC_UHSIC_SLEEP_CFG(inst),
1968 UHSIC_WAKE_VAL(inst, WAKE_VAL_ANY),
1969 UHSIC_WAKE_VAL(inst, WAKE_VAL_NONE));
1971 tegra_usb_pmc_reg_update(PMC_UHSIC_TRIGGERS(inst),
1972 0, UHSIC_CLR_WAKE_ALARM(inst));
1974 val = readl(base + UHSIC_PMC_WAKEUP0);
1975 val &= ~EVENT_INT_ENB;
1976 writel(val, base + UHSIC_PMC_WAKEUP0);
1977 phy->pmc_remote_wakeup = true;
1978 DBG("%s:PMC interrupt detected for HSIC\n", __func__);
1982 static void uhsic_phy_restore_start(struct tegra_usb_phy *phy)
1985 void __iomem *base = phy->regs;
1986 unsigned int inst = phy->inst;
1987 struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
1989 val = tegra_usb_pmc_reg_read(UHSIC_STATUS(inst));
1991 /* check whether we wake up from the remote resume */
1992 if (UHSIC_WALK_PTR_VAL(inst) & val) {
1993 phy->pmc_remote_wakeup = true;
1994 DBG("%s: uhsic remote wakeup detected\n", __func__);
1996 if (!((UHSIC_STROBE_VAL(inst) | UHSIC_DATA_VAL(inst)) & val)) {
1999 * If pmc wakeup is detected after putting controller
2000 * in suspend in usb_phy_bringup_host_cotroller,
2001 * restart bringing up host controller as
2002 * in case of only pmc wakeup.
2004 if (phy->pmc_remote_wakeup && phy->ctrlr_suspended) {
2005 usb_phy_bringup_host_controller(phy);
2006 if (usb_phy_reg_status_wait(base + USB_PORTSC,
2007 (USB_PORTSC_RESUME | USB_PORTSC_SUSP),
2008 0, FPR_WAIT_TIME_US) < 0)
2009 pr_err("%s: timeout waiting" \
2010 "for SUSPEND to clear\n",
2012 phy->ctrlr_suspended = false;
2015 pmc->pmc_ops->disable_pmc_bus_ctrl(pmc, 0);
2016 phy->pmc_remote_wakeup = false;
2018 DBG("%s(%d): setting pretend connect\n", __func__, __LINE__);
2019 val = readl(base + UHSIC_CMD_CFG0);
2020 val |= UHSIC_PRETEND_CONNECT_DETECT;
2021 writel(val, base + UHSIC_CMD_CFG0);
2026 static void uhsic_phy_restore_end(struct tegra_usb_phy *phy)
2029 unsigned long val, flags = 0;
2030 void __iomem *base = phy->regs;
2031 int wait_time_us = FPR_WAIT_TIME_US; /* FPR should be set by this time */
2032 bool irq_disabled = false;
2033 struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
2034 bool remote_wakeup_detected;
2036 DBG("%s(%d)\n", __func__, __LINE__);
2038 remote_wakeup_detected = phy->pmc_remote_wakeup;
2040 * check whether we wake up from the remote wake detected before putting
2041 * controller in suspend in usb_phy_bringup_host_controller.
2043 if (!phy->ctrlr_suspended) {
2044 /* wait until FPR bit is set automatically on remote resume */
2046 val = readl(base + USB_PORTSC);
2048 if (wait_time_us == 0) {
2050 * If pmc wakeup is detected after putting controller
2051 * in suspend in usb_phy_bringup_host_cotroller,
2052 * restart bringing up host controller as
2053 * in case of only pmc wakeup.
2055 if (phy->pmc_remote_wakeup && phy->ctrlr_suspended) {
2056 usb_phy_bringup_host_controller(phy);
2057 if (usb_phy_reg_status_wait(base + USB_PORTSC,
2058 (USB_PORTSC_RESUME | USB_PORTSC_SUSP),
2059 0, FPR_WAIT_TIME_US) < 0)
2060 pr_err("%s: timeout waiting" \
2061 " for SUSPEND to clear\n",
2063 phy->ctrlr_suspended = false;
2066 pmc->pmc_ops->disable_pmc_bus_ctrl(pmc, 0);
2067 phy->pmc_remote_wakeup = false;
2071 } while (val & (USB_PORTSC_RESUME | USB_PORTSC_SUSP));
2072 /* In case of remote wakeup, disable local irq to prevent
2073 * context switch b/t disable PMC and set RUN bit ops */
2074 local_irq_save(flags);
2075 irq_disabled = true;
2078 /* Disable PMC remote wake-up detection */
2079 val = readl(base + UHSIC_PMC_WAKEUP0);
2080 val &= ~EVENT_INT_ENB;
2081 writel(val, base + UHSIC_PMC_WAKEUP0);
2084 * If pmc wakeup is detected after putting controller in suspend
2085 * in usb_phy_bringup_host_cotroller, restart bringing up host
2086 * controller as in case of only pmc wakeup.
2088 if (phy->pmc_remote_wakeup && phy->ctrlr_suspended) {
2089 usb_phy_bringup_host_controller(phy);
2090 if (usb_phy_reg_status_wait(base + USB_PORTSC,
2091 (USB_PORTSC_RESUME | USB_PORTSC_SUSP), 0,
2092 FPR_WAIT_TIME_US) < 0)
2093 pr_err("%s: timeout waiting for SUSPEND to clear\n",
2095 phy->ctrlr_suspended = false;
2098 val = tegra_usb_pmc_reg_read(PMC_UHSIC_SLEEP_CFG(phy->inst));
2099 if (val & UHSIC_MASTER_ENABLE(phy->inst)) {
2100 val = readl(base + UHSIC_PADS_CFG1);
2101 val &= ~(UHSIC_PD_TX);
2102 writel(val, base + UHSIC_PADS_CFG1);
2106 local_irq_restore(flags);
2108 local_irq_save(flags);
2112 pmc->pmc_ops->disable_pmc_bus_ctrl(pmc, 1);
2113 phy->pmc_remote_wakeup = false;
2115 /* Restore local irq if disabled before */
2117 local_irq_restore(flags);
2118 if (usb_phy_reg_status_wait(base + USB_USBCMD, USB_USBCMD_RS,
2119 USB_USBCMD_RS, 2000)) {
2120 pr_err("%s: timeout waiting for USB_USBCMD_RS\n", __func__);
2123 if (remote_wakeup_detected && phy->pdata->ops &&
2124 phy->pdata->ops->post_remote_wakeup)
2125 phy->pdata->ops->post_remote_wakeup();
2128 static int uhsic_rail_enable(struct tegra_usb_phy *phy)
2132 if (phy->hsic_reg == NULL) {
2133 phy->hsic_reg = regulator_get(&phy->pdev->dev, "vddio_hsic");
2134 if (IS_ERR_OR_NULL(phy->hsic_reg)) {
2135 pr_err("UHSIC: Could not get regulator vddio_hsic\n");
2136 ret = PTR_ERR(phy->hsic_reg);
2137 phy->hsic_reg = NULL;
2142 ret = regulator_enable(phy->hsic_reg);
2144 pr_err("%s vddio_hsic could not be enabled\n", __func__);
2151 static int uhsic_rail_disable(struct tegra_usb_phy *phy)
2155 if (phy->hsic_reg == NULL) {
2156 pr_warn("%s: unbalanced disable\n", __func__);
2160 ret = regulator_disable(phy->hsic_reg);
2162 pr_err("HSIC regulator vddio_hsic cannot be disabled\n");
2165 regulator_put(phy->hsic_reg);
2166 phy->hsic_reg = NULL;
2170 static int uhsic_phy_open(struct tegra_usb_phy *phy)
2172 unsigned long parent_rate;
2175 struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
2177 phy->hsic_reg = NULL;
2178 ret = uhsic_rail_enable(phy);
2180 pr_err("%s vddio_hsic could not be enabled\n", __func__);
2184 DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
2185 parent_rate = clk_get_rate(clk_get_parent(phy->pllu_clk));
2186 for (i = 0; i < ARRAY_SIZE(uhsic_freq_table); i++) {
2187 if (uhsic_freq_table[i].freq == parent_rate) {
2188 phy->freq = &uhsic_freq_table[i];
2193 pr_err("invalid pll_u parent rate %ld\n", parent_rate);
2196 /* reset controller for reenumerating hsic device */
2197 tegra_periph_reset_assert(phy->ctrlr_clk);
2199 tegra_periph_reset_deassert(phy->ctrlr_clk);
2203 pmc->pmc_ops->powerup_pmc_wake_detect(pmc);
2208 static void uhsic_phy_close(struct tegra_usb_phy *phy)
2211 struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
2213 DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
2214 pmc->pmc_ops->powerdown_pmc_wake_detect(pmc);
2216 ret = uhsic_rail_disable(phy);
2218 pr_err("%s vddio_hsic could not be disabled\n", __func__);
2221 static int uhsic_phy_irq(struct tegra_usb_phy *phy)
2224 void __iomem *base = phy->regs;
2225 int irq_status = IRQ_HANDLED;
2227 /* check if there is any remote wake event */
2228 if (!phy->pdata->unaligned_dma_buf_supported)
2229 usb_phy_fence_read(phy);
2230 if (uhsic_phy_remotewake_detected(phy))
2231 DBG("%s: uhsic remote wake detected\n", __func__);
2233 val = readl(base + USB_SUSP_CTRL);
2234 if ((val & USB_PHY_CLK_VALID_INT_STS) &&
2235 (val & USB_PHY_CLK_VALID_INT_ENB)) {
2236 val &= ~USB_PHY_CLK_VALID_INT_ENB |
2237 USB_PHY_CLK_VALID_INT_STS;
2238 writel(val , (base + USB_SUSP_CTRL));
2240 val = readl(base + USB_USBSTS);
2241 if (!(val & USB_USBSTS_PCI)) {
2242 irq_status = IRQ_NONE;
2246 val = readl(base + USB_PORTSC);
2247 if (val & USB_PORTSC_CCS)
2248 val &= ~USB_PORTSC_WKCN;
2249 val &= ~USB_PORTSC_RWC_BITS;
2250 writel(val , (base + USB_PORTSC));
2251 irq_status = IRQ_HANDLED;
2257 static int uhsic_phy_power_on(struct tegra_usb_phy *phy)
2260 void __iomem *base = phy->regs;
2261 #ifdef CONFIG_ARCH_TEGRA_11x_SOC
2262 void __iomem *padctl_base = IO_ADDRESS(TEGRA_XUSB_PADCTL_BASE);
2265 DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
2267 if (phy->phy_clk_on) {
2268 DBG("%s(%d) inst:[%d] phy clk is already On\n",
2269 __func__, __LINE__, phy->inst);
2273 #ifdef CONFIG_ARCH_TEGRA_11x_SOC
2274 val = readl(padctl_base + PADCTL_SNPS_OC_MAP);
2275 val |= CONTROLLER_OC(phy->inst, 0x7);
2276 writel(val, padctl_base + PADCTL_SNPS_OC_MAP);
2279 val = readl(base + UHSIC_PADS_CFG1);
2280 val &= ~(UHSIC_PD_BG | UHSIC_PD_RX |
2281 UHSIC_PD_ZI | UHSIC_RPD_DATA | UHSIC_RPD_STROBE);
2282 writel(val, base + UHSIC_PADS_CFG1);
2284 val |= (UHSIC_RX_SEL | UHSIC_PD_TX);
2285 val |= UHSIC_AUTO_RTERM_EN;
2286 writel(val, base + UHSIC_PADS_CFG1);
2288 val = readl(base + USB_SUSP_CTRL);
2290 writel(val, base + USB_SUSP_CTRL);
2293 val = readl(base + USB_SUSP_CTRL);
2294 val |= UHSIC_PHY_ENABLE;
2295 writel(val, base + USB_SUSP_CTRL);
2297 val = readl(base + UHSIC_HSRX_CFG0);
2298 val |= UHSIC_IDLE_WAIT(HSIC_IDLE_WAIT_DELAY);
2299 val |= UHSIC_ELASTIC_UNDERRUN_LIMIT(HSIC_ELASTIC_UNDERRUN_LIMIT);
2300 val |= UHSIC_ELASTIC_OVERRUN_LIMIT(HSIC_ELASTIC_OVERRUN_LIMIT);
2301 writel(val, base + UHSIC_HSRX_CFG0);
2303 val = readl(base + UHSIC_HSRX_CFG1);
2304 val |= UHSIC_HS_SYNC_START_DLY(HSIC_SYNC_START_DELAY);
2305 writel(val, base + UHSIC_HSRX_CFG1);
2308 val = readl(base + UHSIC_TX_CFG0);
2309 val &= ~UHSIC_HS_READY_WAIT_FOR_VALID;
2310 writel(val, base + UHSIC_TX_CFG0);
2312 val = readl(base + UHSIC_MISC_CFG0);
2313 val |= UHSIC_SUSPEND_EXIT_ON_EDGE;
2314 writel(val, base + UHSIC_MISC_CFG0);
2316 val = readl(base + UHSIC_MISC_CFG1);
2317 val |= UHSIC_PLLU_STABLE_COUNT(phy->freq->stable_count);
2318 writel(val, base + UHSIC_MISC_CFG1);
2320 val = readl(base + UHSIC_PLL_CFG1);
2321 val |= UHSIC_PLLU_ENABLE_DLY_COUNT(phy->freq->enable_delay);
2322 val |= UHSIC_XTAL_FREQ_COUNT(phy->freq->xtal_freq_count);
2323 writel(val, base + UHSIC_PLL_CFG1);
2325 val = readl(base + USB_SUSP_CTRL);
2326 val &= ~(UHSIC_RESET);
2327 writel(val, base + USB_SUSP_CTRL);
2330 val = tegra_usb_pmc_reg_read(PMC_UHSIC_SLEEP_CFG(phy->inst));
2331 if (!(val & UHSIC_MASTER_ENABLE(phy->inst))) {
2332 val = readl(base + UHSIC_PADS_CFG1);
2333 val &= ~(UHSIC_PD_TX);
2334 writel(val, base + UHSIC_PADS_CFG1);
2337 /* HSIC pad tracking circuit power down sequence */
2338 val = readl(base + UHSIC_PADS_CFG1);
2339 val &= ~(UHSIC_PD_TRK);
2340 writel(val, base + UHSIC_PADS_CFG1);
2341 /* Wait for 25usec */
2343 val |= UHSIC_PD_TRK;
2344 writel(val, base + UHSIC_PADS_CFG1);
2346 /* Enable bus keepers always */
2347 val = readl(base + UHSIC_SPARE_CFG0);
2349 writel(val, base + UHSIC_SPARE_CFG0);
2351 /*SUSP_CTRL has to be toggled to enable host PHY clock */
2352 val = readl(base + USB_SUSP_CTRL);
2353 val |= USB_SUSP_CLR;
2354 writel(val, base + USB_SUSP_CTRL);
2356 val = readl(base + USB_SUSP_CTRL);
2357 val &= ~USB_SUSP_CLR;
2358 writel(val, base + USB_SUSP_CTRL);
2360 val = readl(base + USB_USBMODE);
2361 val |= USB_USBMODE_HOST;
2362 writel(val, base + USB_USBMODE);
2364 /* Change the USB controller PHY type to HSIC */
2365 val = readl(base + HOSTPC1_DEVLC);
2366 val &= ~HOSTPC1_DEVLC_PTS(HOSTPC1_DEVLC_PTS_MASK);
2367 val |= HOSTPC1_DEVLC_PTS(HOSTPC1_DEVLC_PTS_HSIC);
2368 val &= ~HOSTPC1_DEVLC_PSPD(HOSTPC1_DEVLC_PSPD_MASK);
2369 val |= HOSTPC1_DEVLC_PSPD(HOSTPC1_DEVLC_PSPD_HIGH_SPEED);
2370 val &= ~HOSTPC1_DEVLC_STS;
2371 writel(val, base + HOSTPC1_DEVLC);
2373 val = readl(base + USB_PORTSC);
2374 val &= ~(USB_PORTSC_WKOC | USB_PORTSC_WKDS);
2375 writel(val, base + USB_PORTSC);
2377 val = readl(base + UHSIC_TX_CFG0);
2378 val |= UHSIC_HS_POSTAMBLE_OUTPUT_ENABLE;
2379 writel(val, base + UHSIC_TX_CFG0);
2381 val = readl(base + UHSIC_PADS_CFG0);
2382 /* Clear RTUNEP, SLEWP & SLEWN bit fields */
2383 val &= ~(UHSIC_TX_RTUNEP | UHSIC_TX_SLEWP | UHSIC_TX_SLEWN);
2384 /* set Rtune impedance to 50 ohm */
2385 #ifdef CONFIG_ARCH_TEGRA_12x_SOC
2386 val |= UHSIC_TX_RTUNE_P(0xA);
2388 val |= UHSIC_TX_RTUNE_P(0xC);
2390 writel(val, base + UHSIC_PADS_CFG0);
2392 if (usb_phy_reg_status_wait(base + USB_SUSP_CTRL,
2393 USB_PHY_CLK_VALID, USB_PHY_CLK_VALID, 2500)) {
2394 pr_err("%s: timeout waiting for phy to stabilize\n", __func__);
2398 phy->phy_clk_on = true;
2399 phy->hw_accessible = true;
2401 if (!readl(base + USB_ASYNCLISTADDR))
2404 if (phy->pmc_sleepwalk) {
2405 DBG("%s(%d) inst:[%d] restore phy\n", __func__, __LINE__,
2407 uhsic_phy_restore_start(phy);
2408 usb_phy_bringup_host_controller(phy);
2409 uhsic_phy_restore_end(phy);
2410 phy->pmc_sleepwalk = false;
2413 val = readl(base + USB_TXFILLTUNING);
2414 if ((val & USB_FIFO_TXFILL_MASK) != USB_FIFO_TXFILL_THRES(0x10)) {
2415 val = USB_FIFO_TXFILL_THRES(0x10);
2416 writel(val, base + USB_TXFILLTUNING);
2422 static int uhsic_phy_power_off(struct tegra_usb_phy *phy)
2425 void __iomem *base = phy->regs;
2426 bool port_connected;
2427 struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
2429 DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
2430 if (!phy->phy_clk_on) {
2431 DBG("%s(%d) inst:[%d] phy clk is already off\n",
2432 __func__, __LINE__, phy->inst);
2436 /* Disable interrupts */
2437 writel(0, base + USB_USBINTR);
2439 /* check for port connect status */
2440 val = readl(base + USB_PORTSC);
2441 port_connected = val & USB_PORTSC_CCS;
2443 if (phy->pmc_sleepwalk == false && port_connected) {
2444 pmc->pmc_ops->setup_pmc_wake_detect(pmc);
2446 phy->pmc_remote_wakeup = false;
2447 phy->pmc_sleepwalk = true;
2449 val = readl(base + UHSIC_PMC_WAKEUP0);
2450 val |= EVENT_INT_ENB;
2451 writel(val, base + UHSIC_PMC_WAKEUP0);
2453 val = readl(base + USB_SUSP_CTRL);
2454 val &= ~USB_WAKE_ON_CNNT_EN_DEV;
2455 writel(val, base + USB_SUSP_CTRL);
2457 phy->pmc_sleepwalk = true;
2460 val = readl(base + HOSTPC1_DEVLC);
2461 val |= HOSTPC1_DEVLC_PHCD;
2462 writel(val, base + HOSTPC1_DEVLC);
2464 /* Remove power downs for HSIC from PADS CFG1 register */
2465 val = readl(base + UHSIC_PADS_CFG1);
2466 val |= (UHSIC_PD_BG | UHSIC_PD_TRK |
2467 UHSIC_PD_ZI | UHSIC_PD_TX);
2468 writel(val, base + UHSIC_PADS_CFG1);
2470 if (usb_phy_reg_status_wait(base + USB_SUSP_CTRL,
2471 USB_PHY_CLK_VALID, 0, 2500))
2472 pr_warn("%s: timeout waiting for phy to disable\n", __func__);
2474 DBG("%s(%d) inst:[%d] End\n", __func__, __LINE__, phy->inst);
2476 phy->phy_clk_on = false;
2477 phy->hw_accessible = false;
2482 static int uhsic_phy_bus_port_power(struct tegra_usb_phy *phy)
2485 void __iomem *base = phy->regs;
2487 DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
2489 val = readl(base + USB_USBMODE);
2490 val |= USB_USBMODE_HOST;
2491 writel(val, base + USB_USBMODE);
2493 /* Change the USB controller PHY type to HSIC */
2494 val = readl(base + HOSTPC1_DEVLC);
2495 val &= ~(HOSTPC1_DEVLC_PTS(HOSTPC1_DEVLC_PTS_MASK));
2496 val |= HOSTPC1_DEVLC_PTS(HOSTPC1_DEVLC_PTS_HSIC);
2497 val &= ~(HOSTPC1_DEVLC_PSPD(HOSTPC1_DEVLC_PSPD_MASK));
2498 val |= HOSTPC1_DEVLC_PSPD(HOSTPC1_DEVLC_PSPD_HIGH_SPEED);
2499 writel(val, base + HOSTPC1_DEVLC);
2501 val = readl(base + UHSIC_MISC_CFG0);
2502 val |= UHSIC_DETECT_SHORT_CONNECT;
2503 writel(val, base + UHSIC_MISC_CFG0);
2505 if (phy->pdata->ops && phy->pdata->ops->port_power)
2506 phy->pdata->ops->port_power();
2511 static struct tegra_usb_phy_ops utmi_phy_ops = {
2512 .init = _usb_phy_init,
2513 .reset = usb_phy_reset,
2514 .open = utmi_phy_open,
2515 .close = utmi_phy_close,
2516 .irq = utmi_phy_irq,
2517 .power_on = utmi_phy_power_on,
2518 .power_off = utmi_phy_power_off,
2519 .pre_resume = utmi_phy_pre_resume,
2520 .resume = utmi_phy_resume,
2521 .post_resume = utmi_phy_post_resume,
2522 .charger_detect = utmi_phy_charger_detect,
2523 .qc2_charger_detect = utmi_phy_qc2_charger_detect,
2524 .cdp_charger_detect = cdp_charger_detection,
2525 .nv_charger_detect = utmi_phy_nv_charger_detect,
2526 .maxim_charger_14675 = maxim_charger_detection,
2527 .apple_charger_1000ma_detect = utmi_phy_apple_charger_1000ma_detect,
2528 .apple_charger_2000ma_detect = utmi_phy_apple_charger_2000ma_detect,
2529 .apple_charger_500ma_detect = utmi_phy_apple_charger_500ma_detect,
2530 .pmc_disable = utmi_phy_pmc_disable,
2533 static struct tegra_usb_phy_ops uhsic_phy_ops = {
2534 .init = _usb_phy_init,
2535 .reset = usb_phy_reset,
2536 .open = uhsic_phy_open,
2537 .close = uhsic_phy_close,
2538 .irq = uhsic_phy_irq,
2539 .power_on = uhsic_phy_power_on,
2540 .power_off = uhsic_phy_power_off,
2541 .port_power = uhsic_phy_bus_port_power,
2544 static struct tegra_usb_phy_ops *phy_ops[] = {
2545 [TEGRA_USB_PHY_INTF_UTMI] = &utmi_phy_ops,
2546 [TEGRA_USB_PHY_INTF_HSIC] = &uhsic_phy_ops,
2549 int tegra11x_usb_phy_init_ops(struct tegra_usb_phy *phy)
2551 DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
2553 phy->ops = phy_ops[phy->pdata->phy_intf];
2555 /* FIXME: uncommenting below line to make USB host mode fail*/
2556 /* pmc->pmc_ops->power_down_pmc(pmc); */