]> rtime.felk.cvut.cz Git - sojka/nv-tegra/linux-3.10.git/blob - drivers/usb/phy/tegra11x_usb_phy.c
e6232ca5a933a2918e41bff6f2e67a1cfb7f49b6
[sojka/nv-tegra/linux-3.10.git] / drivers / usb / phy / tegra11x_usb_phy.c
1 /*
2  * drivers/usb/phy/tegra11x_usb_phy.c
3  *
4  * Copyright (c) 2012-2014 NVIDIA Corporation. All rights reserved.
5  *
6  *
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.
10  *
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.
15  *
16  */
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>
23 #include <linux/io.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>
35
36 #ifdef CONFIG_ARCH_TEGRA_14x_SOC
37 #include <mach/pinmux-t14.h>
38 #else
39 #include <mach/pinmux-t11.h>
40 #endif
41 #include "tegra_usb_phy.h"
42 #include "../../../arch/arm/mach-tegra/gpio-names.h"
43
44 /* HACK! This needs to come from DT */
45 #include "../../../arch/arm/mach-tegra/iomap.h"
46
47 #define USB_USBCMD              0x130
48 #define   USB_USBCMD_RS         (1 << 0)
49 #define   USB_CMD_RESET (1<<1)
50
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)
55
56 #define USB_TXFILLTUNING        0x154
57 #define   USB_FIFO_TXFILL_THRES(x)   (((x) & 0x1f) << 16)
58 #define   USB_FIFO_TXFILL_MASK    0x1f0000
59
60 #define USB_ASYNCLISTADDR       0x148
61
62 #define ICUSB_CTRL              0x15c
63
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)
68
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)
82
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)
95
96 #define USB_IF_SPARE    0x498
97 #define   USB_HS_RSM_EOP_EN         (1 << 4)
98 #define   USB_PORT_SUSPEND_EN       (1 << 5)
99
100 #define USB_NEW_CONTROL  0x4c0
101 #define   USB_COHRENCY_EN           (1 << 0)
102 #define   USB_MEM_ALLIGNMENT_MUX_EN (1 << 1)
103
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)
119
120 #define UTMIP_HSRX_CFG0         0x810
121 #define   UTMIP_ELASTIC_LIMIT(x)        (((x) & 0x1f) << 10)
122 #define   UTMIP_IDLE_WAIT(x)            (((x) & 0x1f) << 15)
123
124 #define UTMIP_HSRX_CFG1         0x814
125 #define   UTMIP_HS_SYNC_START_DLY(x)    (((x) & 0x1f) << 1)
126
127 #define UTMIP_TX_CFG0           0x820
128 #define   UTMIP_FS_PREABMLE_J           (1 << 19)
129 #define   UTMIP_HS_DISCON_DISABLE       (1 << 8)
130
131 #define UTMIP_DEBOUNCE_CFG0 0x82c
132 #define   UTMIP_BIAS_DEBOUNCE_A(x)      (((x) & 0xffff) << 0)
133
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)
141
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)
147
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)
167
168 #define UTMIP_SPARE_CFG0        0x834
169 #define   FUSE_SETUP_SEL                (1 << 3)
170 #define   FUSE_ATERM_SEL                (1 << 4)
171
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)
175
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)
180
181 #define UHSIC_HSRX_CFG1                         0xc0c
182 #define   UHSIC_HS_SYNC_START_DLY(x)            (((x) & 0x1f) << 1)
183
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)
187
188
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)
194
195 #define UHSIC_MISC_CFG1                         0xc18
196 #define   UHSIC_PLLU_STABLE_COUNT(x)            (((x) & 0xfff) << 2)
197
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)
204
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)
217
218 #define UHSIC_SPARE_CFG0                        0xc2c
219 #define   FORCE_BK_ON                           (1 << 12)
220
221 #define UHSIC_STAT_CFG0                 0xc28
222 #define   UHSIC_CONNECT_DETECT          (1 << 0)
223
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))
229
230 #define UHSIC_CMD_CFG0                  0xc24
231 #define   UHSIC_PRETEND_CONNECT_DETECT  (1 << 5)
232
233 #define USB_USBINTR                                             0x138
234
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)
253
254 #define USB1_PREFETCH_ID               6
255 #define USB2_PREFETCH_ID               18
256 #define USB3_PREFETCH_ID               17
257
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
263
264 #define APB_MISC_GP_OBSCTRL_0   0x818
265 #define APB_MISC_GP_OBSDATA_0   0x81c
266
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)
272
273 #define PADCTL_OC_DET           0x18
274 #define   ENABLE0_OC_MAP(x)     (((x) & 0x7) << 10)
275 #define   ENABLE1_OC_MAP(x)     (((x) & 0x7) << 13)
276
277 #define TEGRA_STREAM_DISABLE    0x1f8
278 #define TEGRA_STREAM_DISABLE_OFFSET     (1 << 4)
279
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
283
284 /* Maxim Debounce Timer */
285 #define MAXIM_DEBOUNCE_TIME 120
286
287 /* Force port resume wait time in micro second on remote resume */
288 #define FPR_WAIT_TIME_US 25000
289
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
295
296 struct tegra_usb_pmc_data pmc_data[3];
297
298 static struct tegra_xtal_freq utmip_freq_table[] = {
299         {
300                 .freq = 12000000,
301                 .enable_delay = 0x02,
302                 .stable_count = 0x2F,
303                 .active_delay = 0x04,
304                 .xtal_freq_count = 0x76,
305                 .debounce = 0x7530,
306                 .pdtrk_count = 5,
307         },
308         {
309                 .freq = 13000000,
310                 .enable_delay = 0x02,
311                 .stable_count = 0x33,
312                 .active_delay = 0x05,
313                 .xtal_freq_count = 0x7F,
314                 .debounce = 0x7EF4,
315                 .pdtrk_count = 5,
316         },
317         {
318                 .freq = 19200000,
319                 .enable_delay = 0x03,
320                 .stable_count = 0x4B,
321                 .active_delay = 0x06,
322                 .xtal_freq_count = 0xBB,
323                 .debounce = 0xBB80,
324                 .pdtrk_count = 7,
325         },
326         {
327                 .freq = 26000000,
328                 .enable_delay = 0x04,
329                 .stable_count = 0x66,
330                 .active_delay = 0x09,
331                 .xtal_freq_count = 0xFE,
332                 .debounce = 0xFDE8,
333                 .pdtrk_count = 9,
334         },
335 };
336
337 static struct tegra_xtal_freq uhsic_freq_table[] = {
338         {
339                 .freq = 12000000,
340                 .enable_delay = 0x02,
341                 .stable_count = 0x2F,
342                 .active_delay = 0x0,
343                 .xtal_freq_count = 0x1CA,
344         },
345         {
346                 .freq = 13000000,
347                 .enable_delay = 0x02,
348                 .stable_count = 0x33,
349                 .active_delay = 0x0,
350                 .xtal_freq_count = 0x1F0,
351         },
352         {
353                 .freq = 19200000,
354                 .enable_delay = 0x03,
355                 .stable_count = 0x4B,
356                 .active_delay = 0x0,
357                 .xtal_freq_count = 0x2DD,
358         },
359         {
360                 .freq = 26000000,
361                 .enable_delay = 0x04,
362                 .stable_count = 0x66,
363                 .active_delay = 0x0,
364                 .xtal_freq_count = 0x3E0,
365         },
366 };
367
368 static void pmc_init(struct tegra_usb_phy *phy)
369 {
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]);
375 }
376
377 static int _usb_phy_init(struct tegra_usb_phy *phy)
378 {
379         unsigned long val;
380         void __iomem *base = phy->regs;
381
382         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
383
384         val = readl(base + HOSTPC1_DEVLC);
385         val &= ~HOSTPC1_DEVLC_STS;
386         writel(val, base + HOSTPC1_DEVLC);
387
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);
392
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);
398         }
399         val =  readl(base + TEGRA_STREAM_DISABLE);
400         if (!tegra_platform_is_silicon())
401                 val |= TEGRA_STREAM_DISABLE_OFFSET;
402         else
403                 val &= ~TEGRA_STREAM_DISABLE_OFFSET;
404         writel(val , base + TEGRA_STREAM_DISABLE);
405
406         return 0;
407 }
408
409 static void usb_phy_fence_read(struct tegra_usb_phy *phy)
410 {
411         /* Fence read for coherency of AHB master intiated writes */
412         if (phy->inst == 0)
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));
418         return;
419 }
420
421 static int usb_phy_reset(struct tegra_usb_phy *phy)
422 {
423         unsigned long val;
424         void __iomem *base = phy->regs;
425
426         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
427
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);
432         }
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);
437         }
438
439 return 0;
440 }
441
442 static bool utmi_phy_remotewake_detected(struct tegra_usb_phy *phy)
443 {
444         void __iomem *base = phy->regs;
445         unsigned  int inst = phy->inst;
446         u32 val;
447
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));
456
457                         tegra_usb_pmc_reg_update(PMC_TRIGGERS, 0,
458                                 UTMIP_CLR_WAKE_ALARM(inst));
459
460                         val = readl(base + UTMIP_PMC_WAKEUP0);
461                         val &= ~EVENT_INT_ENB;
462                         writel(val, base + UTMIP_PMC_WAKEUP0);
463
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;
467                         else
468                                 phy->pmc_hotplug_wakeup = true;
469
470                         DBG("%s: utmip PMC interrupt detected\n", __func__);
471                         return true;
472                 }
473         }
474         return false;
475 }
476
477 static int usb_phy_bringup_host_controller(struct tegra_usb_phy *phy)
478 {
479         unsigned long val;
480         void __iomem *base = phy->regs;
481
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),
485                                                         phy->port_speed);
486
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);
492
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__);
496         }
497
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);
504
505         if (phy->pdata->phy_intf == TEGRA_USB_PHY_INTF_HSIC)
506                 val |= HOSTPC1_DEVLC_PTS(HOSTPC1_DEVLC_PTS_HSIC);
507         else
508                 val |= HOSTPC1_DEVLC_STS;
509         writel(val, base + HOSTPC1_DEVLC);
510
511         /* Enable Port Power */
512         val = readl(base + USB_PORTSC);
513         val |= USB_PORTSC_PP;
514         writel(val, base + USB_PORTSC);
515         udelay(10);
516
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);
531                 udelay(10);
532
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);
537                 udelay(10);
538         }
539
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__);
544         }
545
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__);
550         }
551
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);
556
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",
570                                         __func__);
571                         }
572                 }
573         }
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),
576                 phy->port_speed);
577
578         DBG("USB_USBSTS[0x%x] USB_PORTSC[0x%x]\n",
579                         readl(base + USB_USBSTS), readl(base + USB_PORTSC));
580         return 0;
581 }
582
583 static unsigned int utmi_phy_xcvr_setup_value(struct tegra_usb_phy *phy)
584 {
585         struct tegra_utmi_config *cfg = &phy->pdata->u_cfg.utmi;
586         signed long val;
587
588         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
589
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);
597                 } else {
598                         if (cfg->xcvr_setup_offset <= UTMIP_XCVR_MAX_OFFSET)
599                                 val = val + cfg->xcvr_setup_offset;
600
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",
604                                                 __func__);
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",
608                                                 __func__);
609                         }
610                 }
611         } else {
612                 val = cfg->xcvr_setup;
613         }
614
615         return (unsigned int) val;
616 }
617
618 static int utmi_phy_open(struct tegra_usb_phy *phy)
619 {
620         struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
621
622         unsigned long parent_rate;
623         int i;
624
625         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
626
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);
631         }
632         pmc_init(phy);
633
634         phy->utmi_xcvr_setup = utmi_phy_xcvr_setup_value(phy);
635
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];
641                                 break;
642                         }
643                 }
644                 if (!phy->freq) {
645                         pr_err("invalid pll_u parent rate %ld\n", parent_rate);
646                         return -EINVAL;
647                 }
648         }
649
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);
654         else
655                 tegra_usb_pmc_reg_update(PMC_USB_AO,
656                         PMC_USB_AO_VBUS_WAKEUP_PD_P0, PMC_USB_AO_ID_PD_P0);
657
658         pmc->pmc_ops->powerup_pmc_wake_detect(pmc);
659
660         return 0;
661 }
662
663 static void utmi_phy_close(struct tegra_usb_phy *phy)
664 {
665         unsigned long val;
666         void __iomem *base = phy->regs;
667         struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
668
669         DBG("%s inst:[%d]\n", __func__, phy->inst);
670
671         /* Disable PHY clock valid interrupts while going into suspend*/
672         if (phy->hot_plug) {
673                 val = readl(base + USB_SUSP_CTRL);
674                 val &= ~USB_PHY_CLK_VALID_INT_ENB;
675                 writel(val, base + USB_SUSP_CTRL);
676         }
677
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);
681
682                 phy->pmc_remote_wakeup = false;
683                 phy->pmc_hotplug_wakeup = false;
684                 PHY_DBG("%s DISABLE_PMC inst = %d\n", __func__, phy->inst);
685         }
686
687         clk_put(phy->utmi_pad_clk);
688 }
689
690 static int utmi_phy_irq(struct tegra_usb_phy *phy)
691 {
692         void __iomem *base = phy->regs;
693         unsigned long val = 0;
694         bool remote_wakeup = false;
695         int irq_status = IRQ_HANDLED;
696
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));
703         }
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;
709
710         if (phy->hot_plug) {
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));
717
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
721                          * executed
722                          */
723                         if (!remote_wakeup) {
724                                 val = readl(base + USB_USBSTS);
725                                 if (!(val  & USB_USBSTS_PCI)) {
726                                         irq_status = IRQ_NONE;
727                                         goto exit;
728                                 }
729
730                                 val = readl(base + USB_PORTSC);
731                                 if (val & USB_PORTSC_CCS)
732                                         val &= ~USB_PORTSC_WKCN;
733                                 else
734                                         val &= ~USB_PORTSC_WKDS;
735                                 val &= ~USB_PORTSC_RWC_BITS;
736                                 writel(val , (base + USB_PORTSC));
737                         }
738                 } else if (!phy->phy_clk_on) {
739                         if (remote_wakeup)
740                                 irq_status = IRQ_HANDLED;
741                         else
742                                 irq_status = IRQ_NONE;
743                         goto exit;
744                 }
745         }
746 exit:
747         return irq_status;
748 }
749
750 static void utmi_phy_enable_obs_bus(struct tegra_usb_phy *phy)
751 {
752         unsigned long val;
753         void __iomem *base = phy->regs;
754
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;
765         else
766                 val |= UTMIP_DPDM_OBSERVE_SEL_FS_K;
767         writel(val, base + UTMIP_MISC_CFG0);
768         udelay(1);
769
770         val = readl(base + UTMIP_MISC_CFG0);
771         val |= UTMIP_DPDM_OBSERVE;
772         writel(val, base + UTMIP_MISC_CFG0);
773         udelay(10);
774         DBG("%s(%d) Enable OBS bus\n", __func__, __LINE__);
775         PHY_DBG("ENABLE_OBS_BUS\n");
776 }
777
778 static int utmi_phy_disable_obs_bus(struct tegra_usb_phy *phy)
779 {
780         void __iomem *base = phy->regs;
781         unsigned long val, port_speed;
782         unsigned long flags;
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");
787
788                 /* disable ALL interrupts on current CPU */
789                 local_irq_save(flags);
790
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);
796
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);
803                 }
804
805                 /* Release UTMIP OBS bus */
806                 val = readl(base + UTMIP_MISC_CFG0);
807                 val &= ~UTMIP_DPDM_OBSERVE;
808                 writel(val, base + UTMIP_MISC_CFG0);
809
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);
815
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);
821
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",
825                                 __func__);
826                         return -ETIMEDOUT;
827                 }
828         }
829         return 0;
830 }
831
832 static int utmi_phy_post_resume(struct tegra_usb_phy *phy)
833 {
834         unsigned long val;
835         unsigned  int inst = phy->inst;
836         struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
837
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);
844
845                 utmi_phy_disable_obs_bus(phy);
846         }
847         return 0;
848 }
849
850 static int utmi_phy_pre_resume(struct tegra_usb_phy *phy, bool remote_wakeup)
851 {
852         unsigned long val;
853         unsigned  int inst = phy->inst;
854         struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
855
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);
864                 }
865         } else {
866                 if (phy->port_speed == USB_PHY_PORT_SPEED_FULL)
867                         utmi_phy_enable_obs_bus(phy);
868         }
869
870         return 0;
871 }
872
873 static int utmi_phy_power_off(struct tegra_usb_phy *phy)
874 {
875         unsigned long val;
876         void __iomem *base = phy->regs;
877         struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
878
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);
883                 return 0;
884         }
885
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);
893
894                 val = readl(base + UTMIP_BAT_CHRG_CFG0);
895                 val |= UTMIP_PD_CHRG;
896                 writel(val, base + UTMIP_BAT_CHRG_CFG0);
897         } else {
898                 phy->port_speed = (readl(base + HOSTPC1_DEVLC) >> 25) &
899                                 HOSTPC1_DEVLC_PSPD_MASK;
900
901                 /* Disable interrupts */
902                 writel(0, base + USB_USBINTR);
903
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);
908
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"
912                                                         , __func__);
913                 }
914
915                 pmc_data[phy->inst].port_speed = (readl(base +
916                                 HOSTPC1_DEVLC) >> 25) &
917                                 HOSTPC1_DEVLC_PSPD_MASK;
918
919                 if (pmc_data[phy->inst].port_speed <
920                                         USB_PMC_PORT_SPEED_UNKNOWN)
921                         phy->pmc_remote_wakeup = false;
922                 else
923                         phy->pmc_hotplug_wakeup = false;
924
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;
929                         if (id_present)
930                                 pmc->pmc_ops->setup_pmc_wake_detect(pmc);
931                 } else {
932                         pmc->pmc_ops->setup_pmc_wake_detect(pmc);
933                 }
934
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);
939
940                 val = readl(base + USB_SUSP_CTRL);
941                 val &= ~USB_WAKE_ON_CNNT_EN_DEV;
942                 writel(val, base + USB_SUSP_CTRL);
943         }
944
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);
950         }
951
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);
956
957         val = readl(base + UTMIP_BIAS_CFG1);
958         val |= UTMIP_BIAS_PDTRK_COUNT(0x5);
959         writel(val, base + UTMIP_BIAS_CFG1);
960
961         if (phy->hot_plug) {
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;
968                 }
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;
974                         else
975                                 val |= USB_PORTSC_WKCN;
976                         writel(val, base + USB_PORTSC);
977
978                         if (val & USB_PORTSC_CCS) {
979                                 val = readl(base + USB_SUSP_CTRL);
980                                 val &= ~USB_PHY_CLK_VALID_INT_ENB;
981                         } else {
982                                 val = readl(base + USB_SUSP_CTRL);
983                                 val |= USB_PHY_CLK_VALID_INT_ENB;
984                         }
985                         writel(val, base + USB_SUSP_CTRL);
986                 } else {
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);
991                 }
992         }
993
994         /* Disable PHY clock */
995         val = readl(base + HOSTPC1_DEVLC);
996         val |= HOSTPC1_DEVLC_PHCD;
997         writel(val, base + HOSTPC1_DEVLC);
998
999         if (!phy->hot_plug) {
1000                 val = readl(base + USB_SUSP_CTRL);
1001                 val |= UTMIP_RESET;
1002                 writel(val, base + USB_SUSP_CTRL);
1003         }
1004
1005         utmi_phy_pad_disable();
1006         utmi_phy_iddq_override(true);
1007
1008         phy->phy_clk_on = false;
1009         phy->hw_accessible = false;
1010
1011         PHY_DBG("%s(%d) inst:[%d] END\n", __func__, __LINE__, phy->inst);
1012
1013         return 0;
1014 }
1015
1016
1017 static int utmi_phy_power_on(struct tegra_usb_phy *phy)
1018 {
1019         unsigned long val;
1020         void __iomem *base = phy->regs;
1021 #ifdef CONFIG_ARCH_TEGRA_11x_SOC
1022         void __iomem *padctl_base = IO_ADDRESS(TEGRA_XUSB_PADCTL_BASE);
1023 #endif
1024         struct tegra_utmi_config *config = &phy->pdata->u_cfg.utmi;
1025         struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
1026
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);
1031                 return 0;
1032         }
1033         val = readl(base + USB_SUSP_CTRL);
1034         val |= UTMIP_RESET;
1035         writel(val, base + USB_SUSP_CTRL);
1036
1037         val = readl(base + UTMIP_TX_CFG0);
1038         val |= UTMIP_FS_PREABMLE_J;
1039         writel(val, base + UTMIP_TX_CFG0);
1040
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;
1045         else
1046                 val |= USB_USBMODE_DEVICE;
1047         writel(val, base + USB_USBMODE);
1048
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);
1054
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);
1059
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);
1065         }
1066
1067         val = readl(base + UTMIP_MISC_CFG0);
1068         val &= ~UTMIP_SUSPEND_EXIT_ON_EDGE;
1069         writel(val, base + UTMIP_MISC_CFG0);
1070
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);
1075
1076                 val = readl(base + UTMIP_BAT_CHRG_CFG0);
1077                 val &= ~UTMIP_PD_CHRG;
1078                 writel(val, base + UTMIP_BAT_CHRG_CFG0);
1079         } else {
1080                 val = readl(base + UTMIP_BAT_CHRG_CFG0);
1081                 val |= UTMIP_PD_CHRG;
1082                 writel(val, base + UTMIP_BAT_CHRG_CFG0);
1083         }
1084
1085         utmi_phy_pad_enable();
1086
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);
1099                 else
1100                         val |= UTMIP_XCVR_HSSLEW_MSB(config->xcvr_hsslew_msb);
1101         }
1102         if (config->xcvr_hsslew_lsb)
1103                 val |= UTMIP_XCVR_HSSLEW_LSB(config->xcvr_hsslew_lsb);
1104         writel(val, base + UTMIP_XCVR_CFG0);
1105
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);
1111
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);
1117         }
1118
1119         val = readl(base + UTMIP_SPARE_CFG0);
1120         val |= FUSE_SETUP_SEL;
1121 #ifdef CONFIG_ARCH_TEGRA_13x_SOC
1122         val &= ~FUSE_SETUP_SEL;
1123 #endif
1124         val |= FUSE_ATERM_SEL;
1125         writel(val, base + UTMIP_SPARE_CFG0);
1126
1127         val = readl(base + USB_SUSP_CTRL);
1128         val |= UTMIP_PHY_ENABLE;
1129         writel(val, base + USB_SUSP_CTRL);
1130
1131         val = readl(base + USB_SUSP_CTRL);
1132         val &= ~UTMIP_RESET;
1133         writel(val, base + USB_SUSP_CTRL);
1134
1135         /* Bring UTMIPLL out of IDDQ mode while exiting from reset/suspend */
1136         utmi_phy_iddq_override(false);
1137
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__);
1141
1142         val = readl(base + HOSTPC1_DEVLC);
1143         val &= ~HOSTPC1_DEVLC_PHCD;
1144         writel(val, base + HOSTPC1_DEVLC);
1145
1146         utmi_phy_set_snps_trking_data();
1147
1148         if (phy->inst == 2)
1149                 writel(0, base + ICUSB_CTRL);
1150
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;
1155         else
1156                 val |= USB_USBMODE_DEVICE;
1157         writel(val, base + USB_USBMODE);
1158
1159         val = readl(base + HOSTPC1_DEVLC);
1160         val &= ~HOSTPC1_DEVLC_PTS(~0);
1161         val |= HOSTPC1_DEVLC_STS;
1162         writel(val, base + HOSTPC1_DEVLC);
1163
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);
1167         }
1168
1169         if (!readl(base + USB_ASYNCLISTADDR))
1170                 _usb_phy_init(phy);
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);
1176         }
1177
1178         phy->phy_clk_on = true;
1179         phy->hw_accessible = true;
1180
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);
1185
1186         val = readl(padctl_base + PADCTL_OC_DET);
1187         if (phy->inst == 0)
1188                 val |= ENABLE0_OC_MAP(config->vbus_oc_map);
1189         if (phy->inst == 2)
1190                 val |= ENABLE1_OC_MAP(config->vbus_oc_map);
1191         writel(val, padctl_base + PADCTL_OC_DET);
1192 #endif
1193
1194         PHY_DBG("%s(%d) End inst:[%d]\n", __func__, __LINE__, phy->inst);
1195         return 0;
1196 }
1197
1198 static void utmi_phy_restore_start(struct tegra_usb_phy *phy)
1199 {
1200         unsigned long val;
1201         int inst = phy->inst;
1202         struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
1203
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
1214            utmi_phy_irq(). */
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);
1221         }
1222         if (phy->port_speed == USB_PHY_PORT_SPEED_FULL)
1223                 utmi_phy_enable_obs_bus(phy);
1224
1225 }
1226
1227 static void utmi_phy_restore_end(struct tegra_usb_phy *phy)
1228 {
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];
1233
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 */
1239                 do {
1240                         val = readl(base + USB_PORTSC);
1241                         udelay(1);
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);
1251                                 }
1252                                 pmc->pmc_ops->disable_pmc_bus_ctrl(pmc, 0);
1253                                 phy->pmc_remote_wakeup = false;
1254                                 phy->pmc_hotplug_wakeup = false;
1255
1256                                 if (phy->port_speed == USB_PHY_PORT_SPEED_FULL)
1257                                         utmi_phy_post_resume(phy);
1258                                 return;
1259                         }
1260                         wait_time_us--;
1261                 } while (val & (USB_PORTSC_RESUME | USB_PORTSC_SUSP));
1262
1263                 /* Add delay sothat resume will be driven for more than 20 ms */
1264                 if (phy->port_speed != USB_PHY_PORT_SPEED_FULL) {
1265                         mdelay(10);
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);
1271                 } else {
1272                         mdelay(25);
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);
1278                 }
1279
1280                 PHY_DBG("%s DISABLE_PMC inst = %d\n", __func__, phy->inst);
1281
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",\
1285                         __func__);
1286                 }
1287
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__);
1295                 }
1296         } else {
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);
1303                 }
1304         }
1305         if (phy->port_speed == USB_PHY_PORT_SPEED_FULL)
1306                 utmi_phy_post_resume(phy);
1307 }
1308
1309 static int utmi_phy_resume(struct tegra_usb_phy *phy)
1310 {
1311         int status = 0;
1312         unsigned long val;
1313         int port_connected = 0;
1314         int is_lp0;
1315         void __iomem *base = phy->regs;
1316         struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
1317
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)
1322                         return 0;
1323
1324                 val = readl(base + USB_PORTSC);
1325                 port_connected = val & USB_PORTSC_CCS;
1326                 is_lp0 = !(readl(base + USB_ASYNCLISTADDR));
1327
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);
1333                 } else {
1334                         pmc->pmc_ops->disable_pmc_bus_ctrl(pmc, 0);
1335                         phy->pmc_remote_wakeup = false;
1336                         phy->pmc_hotplug_wakeup = false;
1337
1338                         /* bring up the controller from suspend*/
1339                         val = readl(base + USB_USBCMD);
1340                         val |= USB_CMD_RESET;
1341                         writel(val, base + USB_USBCMD);
1342
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__);
1346                         }
1347
1348                         val = readl(base + USB_USBMODE);
1349                         val &= ~USB_USBMODE_MASK;
1350                         val |= USB_USBMODE_HOST;
1351                         writel(val, base + USB_USBMODE);
1352
1353                         val = readl(base + HOSTPC1_DEVLC);
1354                         val &= ~HOSTPC1_DEVLC_PTS(~0);
1355                         val |= HOSTPC1_DEVLC_STS;
1356                         writel(val, base + HOSTPC1_DEVLC);
1357
1358                         writel(USB_USBCMD_RS, base + USB_USBCMD);
1359
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__);
1363                         }
1364
1365                         /* Enable Port Power */
1366                         val = readl(base + USB_PORTSC);
1367                         val |= USB_PORTSC_PP;
1368                         writel(val, base + USB_PORTSC);
1369                         udelay(10);
1370
1371                         DBG("USB_USBSTS[0x%x] USB_PORTSC[0x%x]\n",
1372                         readl(base + USB_USBSTS), readl(base + USB_PORTSC));
1373                 }
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);
1379                 }
1380         }
1381
1382         return status;
1383 }
1384
1385 static unsigned long utmi_phy_set_dp_dm_pull_up_down(struct tegra_usb_phy *phy,
1386                 unsigned long pull_up_down_flags)
1387 {
1388         unsigned long val;
1389         unsigned long org;
1390         void __iomem *base = phy->regs;
1391
1392         org = readl(base + UTMIP_MISC_CFG0);
1393
1394         val = org & ~MASK_ALL_PULLUP_PULLDOWN;
1395         val |= pull_up_down_flags;
1396
1397         writel(val, base + UTMIP_MISC_CFG0);
1398
1399         usleep_range(500, 2000);
1400         return org;
1401 }
1402
1403 unsigned long utmi_phy_get_dp_dm_status(struct tegra_usb_phy *phy,
1404                 unsigned long pull_up_down_flags)
1405 {
1406         void __iomem *base = phy->regs;
1407         unsigned long org_flags;
1408         unsigned long ret;
1409
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);
1413         return ret;
1414 }
1415
1416 static void disable_charger_detection(void __iomem *base)
1417 {
1418         unsigned long val;
1419
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);
1425
1426         /* Delay of 40 ms before we pull the D+ as per battery charger spec */
1427         msleep(TDPSRC_CON_MS);
1428 }
1429
1430 /*
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.
1433  */
1434 static bool utmi_phy_dcd_detect(struct tegra_usb_phy *phy)
1435 {
1436         void __iomem *base = phy->regs;
1437         unsigned long val;
1438         unsigned long org_flags;
1439         bool ret;
1440
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);
1450
1451         ret = false;
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)))
1456                         ret = true;
1457         }
1458
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);
1462         return ret;
1463 }
1464
1465 static bool utmi_phy_charger_detect(struct tegra_usb_phy *phy)
1466 {
1467         unsigned long val;
1468         void __iomem *base = phy->regs;
1469         bool status;
1470         int dcd_timeout_ms;
1471
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 */
1476                 return false;
1477         }
1478
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);
1482
1483         /* log initial values */
1484         DBG("%s(%d) inst:[%d], UTMIP_BAT_CHRG_CFG0 = %08X\n",
1485                 __func__, __LINE__,
1486                 phy->inst, readl(base + UTMIP_BAT_CHRG_CFG0));
1487         DBG("%s(%d) inst:[%d], UTMIP_MISC_CFG0 = %08X\n",
1488                 __func__, __LINE__,
1489                 phy->inst, readl(base + UTMIP_MISC_CFG0));
1490
1491         /* DCD timeout max value is 900mS */
1492         dcd_timeout_ms = 0;
1493         while (dcd_timeout_ms < 900) {
1494                 /* standard DCD detect for SDP/DCP/CDP */
1495                 if (utmi_phy_dcd_detect(phy))
1496                         break;
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))
1502                         break;
1503                 usleep_range(20000, 22000);
1504                 dcd_timeout_ms += 22;
1505         }
1506
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);
1511
1512         /* Source should be on for 100 ms as per USB charging spec */
1513         msleep(TDP_SRC_ON_MS);
1514
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);
1520
1521         val = readl(base + USB_PHY_VBUS_WAKEUP_ID);
1522         if (val & VDAT_DET_STS)
1523                 status = true;
1524         else {
1525                 status = false;
1526                 disable_charger_detection(base);
1527         }
1528         DBG("%s(%d) inst:[%d], UTMIP_BAT_CHRG_CFG0 = %08X\n",
1529                 __func__, __LINE__,
1530                 phy->inst, readl(base + UTMIP_BAT_CHRG_CFG0));
1531         DBG("%s(%d) inst:[%d], UTMIP_MISC_CFG0 = %08X\n",
1532                 __func__, __LINE__,
1533                 phy->inst, readl(base + UTMIP_MISC_CFG0));
1534
1535         DBG("%s(%d) inst:[%d] DONE Status = %d\n",
1536                 __func__, __LINE__, phy->inst, status);
1537
1538         return status;
1539 }
1540
1541 static bool cdp_charger_detection(struct tegra_usb_phy *phy)
1542 {
1543         unsigned long val;
1544         int status;
1545         void __iomem *base = phy->regs;
1546
1547         /* SRC D- to D+ */
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);
1552
1553         DBG("%s(%d) UTMIP_BAT_CHRG_CFG0 = %08x\n",
1554                 __func__, __LINE__,
1555                 readl(base + UTMIP_BAT_CHRG_CFG0));
1556
1557         msleep(10);
1558
1559         val = readl(base + USB_PHY_VBUS_WAKEUP_ID);
1560         if (val & VDAT_DET_STS) {
1561                 status = false;
1562                 DBG("%s: DCP detected\n", __func__);
1563         } else {
1564                 status = true;
1565                 disable_charger_detection(base);
1566                 DBG("%s: No voltage from D- to D+ found\n", __func__);
1567         }
1568
1569         return status;
1570 }
1571
1572 static bool maxim_charger_detection(struct tegra_usb_phy *phy)
1573 {
1574         void __iomem *base = phy->regs;
1575         unsigned long val;
1576         unsigned long org_flags;
1577         int status;
1578
1579         /*
1580          * Enable charger detection logic
1581          * 3.3V on D+, Sink D- (high speed usb)
1582          * Maxim charger will remove short !! -- DCP will not
1583          */
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);
1592
1593         /* Source should be on at least 120 ms per Maxim spec */
1594         msleep(MAXIM_DEBOUNCE_TIME);
1595
1596         val = readl(base + USB_PHY_VBUS_WAKEUP_ID);
1597         if (val & VDAT_DET_STS) {
1598                 status = false;
1599                 DBG("%s: Maxim charger not found\n", __func__);
1600                 utmi_phy_set_dp_dm_pull_up_down(phy, org_flags);
1601         } else {
1602                 status = true;
1603                 DBG("%s: Maxim Charger detected\n", __func__);
1604         }
1605
1606         disable_charger_detection(base);
1607         return status;
1608 }
1609
1610 static bool utmi_phy_qc2_charger_detect(struct tegra_usb_phy *phy,
1611                 int max_voltage)
1612 {
1613         unsigned long val;
1614         void __iomem *base = phy->regs;
1615         int status;
1616         int qc2_timeout_ms;
1617         int vbus_stat = 0;
1618         unsigned long org_flags;
1619 #ifdef QC_MEASURE_VOLTAGES
1620         int timeout;
1621 #endif
1622
1623         DBG("%s(%d) inst:[%d] max_voltage = %d\n",
1624                 __func__, __LINE__, phy->inst, max_voltage);
1625
1626         status = false;
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:
1633                 break;
1634         default:
1635                 disable_charger_detection(base);
1636                 return status;
1637         }
1638
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);
1642
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);
1646         ssleep(1);
1647         msleep(500);
1648         utmi_phy_set_dp_dm_pull_up_down(phy, org_flags);
1649
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);
1654
1655         /* Source should be on for 100 ms as per USB charging spec */
1656         msleep(TDP_SRC_ON_MS);
1657
1658         /* if vbus drops we are connected to quick charge 2 */
1659         qc2_timeout_ms = 0;
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)) {
1665                         vbus_stat = 1;
1666                         break;
1667                 }
1668         }
1669
1670         if (vbus_stat && qc2_timeout_ms > 100) {
1671                 status = true;
1672
1673                 DBG("%s(%d) inst:[%d], QC2 DETECTED !!!",
1674                         __func__, __LINE__, phy->inst);
1675
1676                 /* Wall charger needs time before setting D+/D- */
1677                 mdelay(25);
1678
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);
1693                         break;
1694
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);
1706                         break;
1707
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);
1719                         break;
1720
1721                 case TEGRA_USB_QC2_5V:
1722                 default:
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);
1733                         break;
1734                 }
1735
1736 #ifdef QC_MEASURE_VOLTAGES
1737                 timeout = 60;
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);
1743                         ssleep(1);
1744                 }
1745 #endif
1746         }
1747
1748         /*
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
1752          */
1753         if (!status)
1754                 disable_charger_detection(base);
1755
1756         DBG("%s(%d) inst:[%d] DONE Status = %d\n",
1757                 __func__, __LINE__, phy->inst, status);
1758         return status;
1759 }
1760
1761 static bool utmi_phy_is_non_std_charger(struct tegra_usb_phy *phy)
1762 {
1763         /*
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.
1766          */
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;
1772
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;
1778
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;
1784
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;
1790
1791         utmi_phy_set_dp_dm_pull_up_down(phy, 0);
1792         return true;
1793
1794 NOT_NON_STD_CHARGER:
1795         utmi_phy_set_dp_dm_pull_up_down(phy, 0);
1796         return false;
1797
1798 }
1799
1800 static void utmi_phy_pmc_disable(struct tegra_usb_phy *phy)
1801 {
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);
1807         }
1808 }
1809 static bool utmi_phy_nv_charger_detect(struct tegra_usb_phy *phy)
1810 {
1811         int status1;
1812         int status2;
1813         int status3;
1814         bool ret;
1815
1816         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
1817
1818         if (utmi_phy_is_non_std_charger(phy))
1819                 return false;
1820
1821         ret = false;
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);
1826
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);
1831
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);
1836
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)))
1840                 ret = true;
1841
1842         /* Restore standard termination by hardware. */
1843         utmi_phy_set_dp_dm_pull_up_down(phy, 0);
1844         return ret;
1845 }
1846
1847 static bool utmi_phy_apple_charger_1000ma_detect(struct tegra_usb_phy *phy)
1848 {
1849         unsigned long val;
1850         bool ret;
1851         void __iomem *base = phy->regs;
1852         unsigned long org_flags;
1853
1854         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
1855         ret = false;
1856
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);
1864
1865         val = readl(base + USB_PHY_VBUS_WAKEUP_ID);
1866         val |= DIV_DET_EN;
1867         writel(val, base + USB_PHY_VBUS_WAKEUP_ID);
1868
1869         usleep_range(10000, 20000);
1870
1871         val = readl(base + USB_PHY_VBUS_WAKEUP_ID);
1872         val &= ~DIV_DET_EN;
1873         writel(val, base + USB_PHY_VBUS_WAKEUP_ID);
1874
1875         if ((val & VOP_DIV2P0_DET) && (val & VON_DIV2P7_DET))
1876                 ret = true;
1877
1878         utmi_phy_set_dp_dm_pull_up_down(phy, org_flags);
1879
1880         return ret;
1881 }
1882
1883 static bool utmi_phy_apple_charger_2000ma_detect(struct tegra_usb_phy *phy)
1884 {
1885         unsigned long val;
1886         bool ret;
1887         void __iomem *base = phy->regs;
1888         unsigned long org_flags;
1889
1890         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
1891         ret = false;
1892
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);
1900
1901         val = readl(base + USB_PHY_VBUS_WAKEUP_ID);
1902         val |= DIV_DET_EN;
1903         writel(val, base + USB_PHY_VBUS_WAKEUP_ID);
1904
1905         usleep_range(10000, 20000);
1906
1907         val = readl(base + USB_PHY_VBUS_WAKEUP_ID);
1908         val &= ~DIV_DET_EN;
1909         writel(val, base + USB_PHY_VBUS_WAKEUP_ID);
1910
1911         if ((val & VOP_DIV2P7_DET) && (val & VON_DIV2P0_DET))
1912                 ret = true;
1913
1914         utmi_phy_set_dp_dm_pull_up_down(phy, org_flags);
1915
1916         return ret;
1917 }
1918
1919 static bool utmi_phy_apple_charger_500ma_detect(struct tegra_usb_phy *phy)
1920 {
1921         unsigned long val;
1922         bool ret;
1923         void __iomem *base = phy->regs;
1924         unsigned long org_flags;
1925
1926         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
1927         ret = false;
1928
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);
1936
1937         val = readl(base + USB_PHY_VBUS_WAKEUP_ID);
1938         val |= DIV_DET_EN;
1939         writel(val, base + USB_PHY_VBUS_WAKEUP_ID);
1940
1941         usleep_range(10000, 20000);
1942
1943         val = readl(base + USB_PHY_VBUS_WAKEUP_ID);
1944         val &= ~DIV_DET_EN;
1945         writel(val, base + USB_PHY_VBUS_WAKEUP_ID);
1946
1947         if ((val & VOP_DIV2P0_DET) && (val & VON_DIV2P0_DET))
1948                 ret = true;
1949
1950         utmi_phy_set_dp_dm_pull_up_down(phy, org_flags);
1951
1952         return ret;
1953 }
1954
1955 static bool uhsic_phy_remotewake_detected(struct tegra_usb_phy *phy)
1956 {
1957         void __iomem *base = phy->regs;
1958         u32 val;
1959         unsigned int inst = phy->inst;
1960
1961         val = readl(base + UHSIC_PMC_WAKEUP0);
1962         if (!(val & EVENT_INT_ENB))
1963                 return false;
1964         val = tegra_usb_pmc_reg_read(UHSIC_STATUS(inst));
1965         if (!(UHSIC_WAKE_ALARM(inst) & val))
1966                 return false;
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));
1970
1971         tegra_usb_pmc_reg_update(PMC_UHSIC_TRIGGERS(inst),
1972                 0, UHSIC_CLR_WAKE_ALARM(inst));
1973
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__);
1979         return true;
1980 }
1981
1982 static void uhsic_phy_restore_start(struct tegra_usb_phy *phy)
1983 {
1984         unsigned long val;
1985         void __iomem *base = phy->regs;
1986         unsigned int inst = phy->inst;
1987         struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
1988
1989         val = tegra_usb_pmc_reg_read(UHSIC_STATUS(inst));
1990
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__);
1995         } else {
1996                 if (!((UHSIC_STROBE_VAL(inst) | UHSIC_DATA_VAL(inst)) & val)) {
1997
1998                         /*
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.
2003                          */
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",
2011                                                 __func__);
2012                                 phy->ctrlr_suspended = false;
2013                         }
2014
2015                         pmc->pmc_ops->disable_pmc_bus_ctrl(pmc, 0);
2016                         phy->pmc_remote_wakeup = false;
2017                 } else {
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);
2022                 }
2023         }
2024 }
2025
2026 static void uhsic_phy_restore_end(struct tegra_usb_phy *phy)
2027 {
2028
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;
2035
2036         DBG("%s(%d)\n", __func__, __LINE__);
2037
2038         remote_wakeup_detected = phy->pmc_remote_wakeup;
2039         /*
2040          * check whether we wake up from the remote wake detected before putting
2041          * controller in suspend in usb_phy_bringup_host_controller.
2042          */
2043         if (!phy->ctrlr_suspended) {
2044                 /* wait until FPR bit is set automatically on remote resume */
2045                 do {
2046                         val = readl(base + USB_PORTSC);
2047                         udelay(1);
2048                         if (wait_time_us == 0) {
2049                         /*
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.
2054                          */
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",
2062                                                 __func__);
2063                                 phy->ctrlr_suspended = false;
2064                         }
2065
2066                                 pmc->pmc_ops->disable_pmc_bus_ctrl(pmc, 0);
2067                                 phy->pmc_remote_wakeup = false;
2068                                 return;
2069                         }
2070                         wait_time_us--;
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;
2076         }
2077
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);
2082
2083         /*
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.
2087          */
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",
2094                                 __func__);
2095                 phy->ctrlr_suspended = false;
2096         }
2097
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);
2103         }
2104
2105         if (irq_disabled) {
2106                 local_irq_restore(flags);
2107                 mdelay(25);
2108                 local_irq_save(flags);
2109         } else
2110                 mdelay(10);
2111
2112         pmc->pmc_ops->disable_pmc_bus_ctrl(pmc, 1);
2113         phy->pmc_remote_wakeup = false;
2114
2115         /* Restore local irq if disabled before */
2116         if (irq_disabled)
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__);
2121                 return;
2122         }
2123         if (remote_wakeup_detected && phy->pdata->ops &&
2124                                         phy->pdata->ops->post_remote_wakeup)
2125                 phy->pdata->ops->post_remote_wakeup();
2126 }
2127
2128 static int uhsic_rail_enable(struct tegra_usb_phy *phy)
2129 {
2130         int ret;
2131
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;
2138                         return ret;
2139                 }
2140         }
2141
2142         ret = regulator_enable(phy->hsic_reg);
2143         if (ret < 0) {
2144                 pr_err("%s vddio_hsic could not be enabled\n", __func__);
2145                 return ret;
2146         }
2147
2148         return 0;
2149 }
2150
2151 static int uhsic_rail_disable(struct tegra_usb_phy *phy)
2152 {
2153         int ret;
2154
2155         if (phy->hsic_reg == NULL) {
2156                 pr_warn("%s: unbalanced disable\n", __func__);
2157                 return -EIO;
2158         }
2159
2160         ret = regulator_disable(phy->hsic_reg);
2161         if (ret < 0) {
2162                 pr_err("HSIC regulator vddio_hsic cannot be disabled\n");
2163                 return ret;
2164         }
2165         regulator_put(phy->hsic_reg);
2166         phy->hsic_reg = NULL;
2167         return 0;
2168 }
2169
2170 static int uhsic_phy_open(struct tegra_usb_phy *phy)
2171 {
2172         unsigned long parent_rate;
2173         int i;
2174         int ret;
2175         struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
2176
2177         phy->hsic_reg = NULL;
2178         ret = uhsic_rail_enable(phy);
2179         if (ret < 0) {
2180                 pr_err("%s vddio_hsic could not be enabled\n", __func__);
2181                 return ret;
2182         }
2183
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];
2189                         break;
2190                 }
2191         }
2192         if (!phy->freq) {
2193                 pr_err("invalid pll_u parent rate %ld\n", parent_rate);
2194                 return -EINVAL;
2195         }
2196         /* reset controller for reenumerating hsic device */
2197         tegra_periph_reset_assert(phy->ctrlr_clk);
2198         udelay(2);
2199         tegra_periph_reset_deassert(phy->ctrlr_clk);
2200         udelay(2);
2201
2202         pmc_init(phy);
2203         pmc->pmc_ops->powerup_pmc_wake_detect(pmc);
2204
2205         return 0;
2206 }
2207
2208 static void uhsic_phy_close(struct tegra_usb_phy *phy)
2209 {
2210         int ret;
2211         struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
2212
2213         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
2214         pmc->pmc_ops->powerdown_pmc_wake_detect(pmc);
2215
2216         ret = uhsic_rail_disable(phy);
2217         if (ret < 0)
2218                 pr_err("%s vddio_hsic could not be disabled\n", __func__);
2219 }
2220
2221 static int uhsic_phy_irq(struct tegra_usb_phy *phy)
2222 {
2223         unsigned long val;
2224         void __iomem *base = phy->regs;
2225         int irq_status = IRQ_HANDLED;
2226
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__);
2232
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));
2239
2240                 val = readl(base + USB_USBSTS);
2241                 if (!(val  & USB_USBSTS_PCI)) {
2242                         irq_status = IRQ_NONE;
2243                         goto exit;
2244                 }
2245
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;
2252         }
2253 exit:
2254         return irq_status;
2255 }
2256
2257 static int uhsic_phy_power_on(struct tegra_usb_phy *phy)
2258 {
2259         unsigned long val;
2260         void __iomem *base = phy->regs;
2261 #ifdef CONFIG_ARCH_TEGRA_11x_SOC
2262         void __iomem *padctl_base = IO_ADDRESS(TEGRA_XUSB_PADCTL_BASE);
2263 #endif
2264
2265         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
2266
2267         if (phy->phy_clk_on) {
2268                 DBG("%s(%d) inst:[%d] phy clk is already On\n",
2269                                         __func__, __LINE__, phy->inst);
2270                 return 0;
2271         }
2272
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);
2277 #endif
2278
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);
2283
2284         val |= (UHSIC_RX_SEL | UHSIC_PD_TX);
2285         val |= UHSIC_AUTO_RTERM_EN;
2286         writel(val, base + UHSIC_PADS_CFG1);
2287
2288         val = readl(base + USB_SUSP_CTRL);
2289         val |= UHSIC_RESET;
2290         writel(val, base + USB_SUSP_CTRL);
2291         udelay(1);
2292
2293         val = readl(base + USB_SUSP_CTRL);
2294         val |= UHSIC_PHY_ENABLE;
2295         writel(val, base + USB_SUSP_CTRL);
2296
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);
2302
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);
2306
2307         /* WAR HSIC TX */
2308         val = readl(base + UHSIC_TX_CFG0);
2309         val &= ~UHSIC_HS_READY_WAIT_FOR_VALID;
2310         writel(val, base + UHSIC_TX_CFG0);
2311
2312         val = readl(base + UHSIC_MISC_CFG0);
2313         val |= UHSIC_SUSPEND_EXIT_ON_EDGE;
2314         writel(val, base + UHSIC_MISC_CFG0);
2315
2316         val = readl(base + UHSIC_MISC_CFG1);
2317         val |= UHSIC_PLLU_STABLE_COUNT(phy->freq->stable_count);
2318         writel(val, base + UHSIC_MISC_CFG1);
2319
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);
2324
2325         val = readl(base + USB_SUSP_CTRL);
2326         val &= ~(UHSIC_RESET);
2327         writel(val, base + USB_SUSP_CTRL);
2328         udelay(1);
2329
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);
2335         }
2336
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 */
2342         udelay(25);
2343         val |= UHSIC_PD_TRK;
2344         writel(val, base + UHSIC_PADS_CFG1);
2345
2346         /* Enable bus keepers always */
2347         val = readl(base + UHSIC_SPARE_CFG0);
2348         val |= FORCE_BK_ON;
2349         writel(val, base + UHSIC_SPARE_CFG0);
2350
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);
2355
2356         val = readl(base + USB_SUSP_CTRL);
2357         val &= ~USB_SUSP_CLR;
2358         writel(val, base + USB_SUSP_CTRL);
2359
2360         val = readl(base + USB_USBMODE);
2361         val |= USB_USBMODE_HOST;
2362         writel(val, base + USB_USBMODE);
2363
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);
2372
2373         val = readl(base + USB_PORTSC);
2374         val &= ~(USB_PORTSC_WKOC | USB_PORTSC_WKDS);
2375         writel(val, base + USB_PORTSC);
2376
2377         val = readl(base + UHSIC_TX_CFG0);
2378         val |= UHSIC_HS_POSTAMBLE_OUTPUT_ENABLE;
2379         writel(val, base + UHSIC_TX_CFG0);
2380
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);
2387 #else
2388         val |= UHSIC_TX_RTUNE_P(0xC);
2389 #endif
2390         writel(val, base + UHSIC_PADS_CFG0);
2391
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__);
2395                 return -ETIMEDOUT;
2396         }
2397
2398         phy->phy_clk_on = true;
2399         phy->hw_accessible = true;
2400
2401         if (!readl(base + USB_ASYNCLISTADDR))
2402                 _usb_phy_init(phy);
2403
2404         if (phy->pmc_sleepwalk) {
2405                 DBG("%s(%d) inst:[%d] restore phy\n", __func__, __LINE__,
2406                                         phy->inst);
2407                 uhsic_phy_restore_start(phy);
2408                 usb_phy_bringup_host_controller(phy);
2409                 uhsic_phy_restore_end(phy);
2410                 phy->pmc_sleepwalk = false;
2411         }
2412
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);
2417         }
2418
2419         return 0;
2420 }
2421
2422 static int uhsic_phy_power_off(struct tegra_usb_phy *phy)
2423 {
2424         unsigned long val;
2425         void __iomem *base = phy->regs;
2426         bool port_connected;
2427         struct tegra_usb_pmc_data *pmc = &pmc_data[phy->inst];
2428
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);
2433                 return 0;
2434         }
2435
2436         /* Disable interrupts */
2437         writel(0, base + USB_USBINTR);
2438
2439         /* check for port connect status */
2440         val = readl(base + USB_PORTSC);
2441         port_connected = val & USB_PORTSC_CCS;
2442
2443         if (phy->pmc_sleepwalk == false && port_connected) {
2444                 pmc->pmc_ops->setup_pmc_wake_detect(pmc);
2445
2446                 phy->pmc_remote_wakeup = false;
2447                 phy->pmc_sleepwalk = true;
2448
2449                 val = readl(base + UHSIC_PMC_WAKEUP0);
2450                 val |= EVENT_INT_ENB;
2451                 writel(val, base + UHSIC_PMC_WAKEUP0);
2452
2453                 val = readl(base + USB_SUSP_CTRL);
2454                 val &= ~USB_WAKE_ON_CNNT_EN_DEV;
2455                 writel(val, base + USB_SUSP_CTRL);
2456         } else {
2457                 phy->pmc_sleepwalk = true;
2458         }
2459
2460         val = readl(base + HOSTPC1_DEVLC);
2461         val |= HOSTPC1_DEVLC_PHCD;
2462         writel(val, base + HOSTPC1_DEVLC);
2463
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);
2469
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__);
2473
2474         DBG("%s(%d) inst:[%d] End\n", __func__, __LINE__, phy->inst);
2475
2476         phy->phy_clk_on = false;
2477         phy->hw_accessible = false;
2478
2479         return 0;
2480 }
2481
2482 static int uhsic_phy_bus_port_power(struct tegra_usb_phy *phy)
2483 {
2484         unsigned long val;
2485         void __iomem *base = phy->regs;
2486
2487         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
2488
2489         val = readl(base + USB_USBMODE);
2490         val |= USB_USBMODE_HOST;
2491         writel(val, base + USB_USBMODE);
2492
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);
2500
2501         val = readl(base + UHSIC_MISC_CFG0);
2502         val |= UHSIC_DETECT_SHORT_CONNECT;
2503         writel(val, base + UHSIC_MISC_CFG0);
2504         udelay(1);
2505         if (phy->pdata->ops && phy->pdata->ops->port_power)
2506                 phy->pdata->ops->port_power();
2507
2508         return 0;
2509 }
2510
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,
2531 };
2532
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,
2542 };
2543
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,
2547 };
2548
2549 int tegra11x_usb_phy_init_ops(struct tegra_usb_phy *phy)
2550 {
2551         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
2552
2553         phy->ops = phy_ops[phy->pdata->phy_intf];
2554
2555         /* FIXME: uncommenting below line to make USB host mode fail*/
2556         /* pmc->pmc_ops->power_down_pmc(pmc); */
2557
2558         return 0;
2559 }