aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-tegra/usb_phy.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/mach-tegra/usb_phy.c')
-rw-r--r--arch/arm/mach-tegra/usb_phy.c3019
1 files changed, 3019 insertions, 0 deletions
diff --git a/arch/arm/mach-tegra/usb_phy.c b/arch/arm/mach-tegra/usb_phy.c
new file mode 100644
index 00000000000..d154b0649d1
--- /dev/null
+++ b/arch/arm/mach-tegra/usb_phy.c
@@ -0,0 +1,3019 @@
1/*
2 * arch/arm/mach-tegra/usb_phy.c
3 *
4 * Copyright (C) 2010 Google, Inc.
5 * Copyright (C) 2010 - 2011 NVIDIA Corporation
6 *
7 * Author:
8 * Erik Gilling <konkers@google.com>
9 * Benoit Goby <benoit@android.com>
10 *
11 * This software is licensed under the terms of the GNU General Public
12 * License version 2, as published by the Free Software Foundation, and
13 * may be copied, distributed, and modified under those terms.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 */
21
22#include <linux/resource.h>
23#include <linux/delay.h>
24#include <linux/interrupt.h>
25#include <linux/slab.h>
26#include <linux/err.h>
27#include <linux/platform_device.h>
28#include <linux/io.h>
29#include <linux/gpio.h>
30#include <linux/usb/otg.h>
31#include <linux/usb/ulpi.h>
32#include <asm/mach-types.h>
33#include <mach/usb_phy.h>
34#include <mach/iomap.h>
35#include <mach/pinmux.h>
36#include "fuse.h"
37
38
39#ifdef CONFIG_ARCH_TEGRA_2x_SOC
40#define USB_USBCMD 0x140
41#define USB_USBCMD_RS (1 << 0)
42
43#define USB_USBSTS 0x144
44#define USB_USBSTS_PCI (1 << 2)
45#define USB_USBSTS_HCH (1 << 12)
46
47#define USB_TXFILLTUNING 0x164
48#define USB_FIFO_TXFILL_THRES(x) (((x) & 0x1f) << 16)
49#define USB_FIFO_TXFILL_MASK 0x1f0000
50
51#define ULPI_VIEWPORT 0x170
52#define ULPI_WAKEUP (1 << 31)
53#define ULPI_RUN (1 << 30)
54#define ULPI_RD_WR (1 << 29)
55
56#define USB_PORTSC1 0x184
57#define USB_PORTSC1_PTS(x) (((x) & 0x3) << 30)
58#define USB_PORTSC1_PSPD(x) (((x) & 0x3) << 26)
59#define USB_PORTSC1_PHCD (1 << 23)
60#define USB_PORTSC1_WKOC (1 << 22)
61#define USB_PORTSC1_WKDS (1 << 21)
62#define USB_PORTSC1_WKCN (1 << 20)
63#define USB_PORTSC1_PTC(x) (((x) & 0xf) << 16)
64#define USB_PORTSC1_PP (1 << 12)
65#define USB_PORTSC1_LS(x) (((x) & 0x3) << 10)
66#define USB_PORTSC1_SUSP (1 << 7)
67#define USB_PORTSC1_PE (1 << 2)
68#define USB_PORTSC1_CCS (1 << 0)
69
70#define USB_SUSP_CTRL 0x400
71#define USB_WAKE_ON_CNNT_EN_DEV (1 << 3)
72#define USB_WAKE_ON_DISCON_EN_DEV (1 << 4)
73#define USB_SUSP_CLR (1 << 5)
74#define USB_CLKEN (1 << 6)
75#define USB_PHY_CLK_VALID (1 << 7)
76#define USB_PHY_CLK_VALID_INT_ENB (1 << 9)
77#define UTMIP_RESET (1 << 11)
78#define UHSIC_RESET (1 << 11)
79#define UTMIP_PHY_ENABLE (1 << 12)
80#define UHSIC_PHY_ENABLE (1 << 12)
81#define ULPI_PHY_ENABLE (1 << 13)
82#define USB_SUSP_SET (1 << 14)
83#define USB_WAKEUP_DEBOUNCE_COUNT(x) (((x) & 0x7) << 16)
84
85#define USB_PHY_VBUS_WAKEUP_ID 0x408
86#define VDAT_DET_INT_EN (1 << 16)
87#define VDAT_DET_CHG_DET (1 << 17)
88#define VDAT_DET_STS (1 << 18)
89
90#define USB1_LEGACY_CTRL 0x410
91#define USB1_NO_LEGACY_MODE (1 << 0)
92#define USB1_VBUS_SENSE_CTL_MASK (3 << 1)
93#define USB1_VBUS_SENSE_CTL_VBUS_WAKEUP (0 << 1)
94#define USB1_VBUS_SENSE_CTL_AB_SESS_VLD_OR_VBUS_WAKEUP \
95 (1 << 1)
96#define USB1_VBUS_SENSE_CTL_AB_SESS_VLD (2 << 1)
97#define USB1_VBUS_SENSE_CTL_A_SESS_VLD (3 << 1)
98
99
100#define UTMIP_PLL_CFG1 0x804
101#define UTMIP_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0)
102#define UTMIP_PLLU_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 27)
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
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_BIAS_CFG0 0x80c
121#define UTMIP_OTGPD (1 << 11)
122#define UTMIP_BIASPD (1 << 10)
123
124#define UTMIP_HSRX_CFG0 0x810
125#define UTMIP_ELASTIC_LIMIT(x) (((x) & 0x1f) << 10)
126#define UTMIP_IDLE_WAIT(x) (((x) & 0x1f) << 15)
127
128#define UTMIP_HSRX_CFG1 0x814
129#define UTMIP_HS_SYNC_START_DLY(x) (((x) & 0x1f) << 1)
130
131#define UTMIP_TX_CFG0 0x820
132#define UTMIP_FS_PREABMLE_J (1 << 19)
133#define UTMIP_HS_DISCON_DISABLE (1 << 8)
134
135#define UTMIP_MISC_CFG1 0x828
136#define UTMIP_PLL_ACTIVE_DLY_COUNT(x) (((x) & 0x1f) << 18)
137#define UTMIP_PLLU_STABLE_COUNT(x) (((x) & 0xfff) << 6)
138
139#define UTMIP_DEBOUNCE_CFG0 0x82c
140#define UTMIP_BIAS_DEBOUNCE_A(x) (((x) & 0xffff) << 0)
141
142#define UTMIP_BAT_CHRG_CFG0 0x830
143#define UTMIP_PD_CHRG (1 << 0)
144#define UTMIP_ON_SINK_EN (1 << 2)
145#define UTMIP_OP_SRC_EN (1 << 3)
146
147#define UTMIP_XCVR_CFG1 0x838
148#define UTMIP_FORCE_PDDISC_POWERDOWN (1 << 0)
149#define UTMIP_FORCE_PDCHRP_POWERDOWN (1 << 2)
150#define UTMIP_FORCE_PDDR_POWERDOWN (1 << 4)
151#define UTMIP_XCVR_TERM_RANGE_ADJ(x) (((x) & 0xf) << 18)
152
153#define UTMIP_BIAS_CFG1 0x83c
154#define UTMIP_BIAS_PDTRK_COUNT(x) (((x) & 0x1f) << 3)
155
156#define UHSIC_PLL_CFG1 0x804
157#define UHSIC_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0)
158#define UHSIC_PLLU_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 14)
159
160#define UHSIC_HSRX_CFG0 0x808
161#define UHSIC_ELASTIC_UNDERRUN_LIMIT(x) (((x) & 0x1f) << 2)
162#define UHSIC_ELASTIC_OVERRUN_LIMIT(x) (((x) & 0x1f) << 8)
163#define UHSIC_IDLE_WAIT(x) (((x) & 0x1f) << 13)
164
165#define UHSIC_HSRX_CFG1 0x80c
166#define UHSIC_HS_SYNC_START_DLY(x) (((x) & 0x1f) << 1)
167
168#define UHSIC_TX_CFG0 0x810
169#define UHSIC_HS_POSTAMBLE_OUTPUT_ENABLE (1 << 6)
170
171#define UHSIC_MISC_CFG0 0x814
172#define UHSIC_SUSPEND_EXIT_ON_EDGE (1 << 7)
173#define UHSIC_DETECT_SHORT_CONNECT (1 << 8)
174#define UHSIC_FORCE_XCVR_MODE (1 << 15)
175
176#define UHSIC_MISC_CFG1 0X818
177#define UHSIC_PLLU_STABLE_COUNT(x) (((x) & 0xfff) << 2)
178
179#define UHSIC_PADS_CFG0 0x81c
180#define UHSIC_TX_RTUNEN 0xf000
181#define UHSIC_TX_RTUNE(x) (((x) & 0xf) << 12)
182
183#define UHSIC_PADS_CFG1 0x820
184#define UHSIC_PD_BG (1 << 2)
185#define UHSIC_PD_TX (1 << 3)
186#define UHSIC_PD_TRK (1 << 4)
187#define UHSIC_PD_RX (1 << 5)
188#define UHSIC_PD_ZI (1 << 6)
189#define UHSIC_RX_SEL (1 << 7)
190#define UHSIC_RPD_DATA (1 << 9)
191#define UHSIC_RPD_STROBE (1 << 10)
192#define UHSIC_RPU_DATA (1 << 11)
193#define UHSIC_RPU_STROBE (1 << 12)
194
195#define UHSIC_STAT_CFG0 0x828
196#define UHSIC_CONNECT_DETECT (1 << 0)
197
198
199#else
200
201#define USB_USBCMD 0x130
202#define USB_USBCMD_RS (1 << 0)
203
204#define USB_USBSTS 0x134
205#define USB_USBSTS_PCI (1 << 2)
206#define USB_USBSTS_SRI (1 << 7)
207#define USB_USBSTS_HCH (1 << 12)
208
209#define USB_TXFILLTUNING 0x154
210#define USB_FIFO_TXFILL_THRES(x) (((x) & 0x1f) << 16)
211#define USB_FIFO_TXFILL_MASK 0x1f0000
212
213#define ULPI_VIEWPORT 0x160
214
215#define USB_PORTSC1 0x174
216#define USB_PORTSC1_WKOC (1 << 22)
217#define USB_PORTSC1_WKDS (1 << 21)
218#define USB_PORTSC1_WKCN (1 << 20)
219#define USB_PORTSC1_PTC(x) (((x) & 0xf) << 16)
220#define USB_PORTSC1_PP (1 << 12)
221#define USB_PORTSC1_LS(x) (((x) & 0x3) << 10)
222#define USB_PORTSC1_SUSP (1 << 7)
223#define USB_PORTSC1_RESUME (1 << 6)
224#define USB_PORTSC1_PE (1 << 2)
225#define USB_PORTSC1_CCS (1 << 0)
226
227#define USB_SUSP_CTRL 0x400
228#define USB_WAKE_ON_CNNT_EN_DEV (1 << 3)
229#define USB_WAKE_ON_DISCON_EN_DEV (1 << 4)
230#define USB_SUSP_CLR (1 << 5)
231#define USB_PHY_CLK_VALID (1 << 7)
232#define USB_PHY_CLK_VALID_INT_ENB (1 << 9)
233
234
235#define UTMIP_RESET (1 << 11)
236#define UTMIP_PHY_ENABLE (1 << 12)
237#define ULPI_PHY_ENABLE (1 << 13)
238#define UHSIC_RESET (1 << 14)
239
240#define USB_WAKEUP_DEBOUNCE_COUNT(x) (((x) & 0x7) << 16)
241#define UHSIC_PHY_ENABLE (1 << 19)
242#define ULPIS2S_SLV0_RESET (1 << 20)
243#define ULPIS2S_SLV1_RESET (1 << 21)
244#define ULPIS2S_LINE_RESET (1 << 22)
245#define ULPI_PADS_RESET (1 << 23)
246#define ULPI_PADS_CLKEN_RESET (1 << 24)
247
248#define USB_PHY_VBUS_WAKEUP_ID 0x408
249#define VDAT_DET_INT_EN (1 << 16)
250#define VDAT_DET_CHG_DET (1 << 17)
251#define VDAT_DET_STS (1 << 18)
252
253#define USB1_LEGACY_CTRL 0x410
254#define USB1_NO_LEGACY_MODE (1 << 0)
255#define USB1_VBUS_SENSE_CTL_MASK (3 << 1)
256#define USB1_VBUS_SENSE_CTL_VBUS_WAKEUP (0 << 1)
257#define USB1_VBUS_SENSE_CTL_AB_SESS_VLD_OR_VBUS_WAKEUP \
258 (1 << 1)
259#define USB1_VBUS_SENSE_CTL_AB_SESS_VLD (2 << 1)
260#define USB1_VBUS_SENSE_CTL_A_SESS_VLD (3 << 1)
261
262#define UTMIP_PLL_CFG1 0x804
263#define UTMIP_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0)
264#define UTMIP_PLLU_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 27)
265
266#define UTMIP_XCVR_CFG0 0x808
267#define UTMIP_XCVR_SETUP(x) (((x) & 0xf) << 0)
268#define UTMIP_XCVR_LSRSLEW(x) (((x) & 0x3) << 8)
269#define UTMIP_XCVR_LSFSLEW(x) (((x) & 0x3) << 10)
270#define UTMIP_FORCE_PD_POWERDOWN (1 << 14)
271#define UTMIP_FORCE_PD2_POWERDOWN (1 << 16)
272#define UTMIP_FORCE_PDZI_POWERDOWN (1 << 18)
273#define UTMIP_XCVR_LSBIAS_SEL (1 << 21)
274#define UTMIP_XCVR_SETUP_MSB(x) (((x) & 0x7) << 22)
275#define UTMIP_XCVR_HSSLEW_MSB(x) (((x) & 0x7f) << 25)
276
277#define UTMIP_XCVR_MAX_OFFSET 2
278#define UTMIP_XCVR_SETUP_MAX_VALUE 0x7f
279#define UTMIP_XCVR_SETUP_MIN_VALUE 0
280#define XCVR_SETUP_MSB_CALIB(x) ((x) >> 4)
281
282#define UTMIP_BIAS_CFG0 0x80c
283#define UTMIP_OTGPD (1 << 11)
284#define UTMIP_BIASPD (1 << 10)
285#define UTMIP_HSSQUELCH_LEVEL(x) (((x) & 0x3) << 0)
286#define UTMIP_HSDISCON_LEVEL(x) (((x) & 0x3) << 2)
287#define UTMIP_HSDISCON_LEVEL_MSB (1 << 24)
288
289#define UTMIP_HSRX_CFG0 0x810
290#define UTMIP_ELASTIC_LIMIT(x) (((x) & 0x1f) << 10)
291#define UTMIP_IDLE_WAIT(x) (((x) & 0x1f) << 15)
292
293#define UTMIP_HSRX_CFG1 0x814
294#define UTMIP_HS_SYNC_START_DLY(x) (((x) & 0x1f) << 1)
295
296#define UTMIP_TX_CFG0 0x820
297#define UTMIP_FS_PREABMLE_J (1 << 19)
298#define UTMIP_HS_DISCON_DISABLE (1 << 8)
299
300#define UTMIP_MISC_CFG1 0x828
301#define UTMIP_PLL_ACTIVE_DLY_COUNT(x) (((x) & 0x1f) << 18)
302#define UTMIP_PLLU_STABLE_COUNT(x) (((x) & 0xfff) << 6)
303
304#define UTMIP_DEBOUNCE_CFG0 0x82c
305#define UTMIP_BIAS_DEBOUNCE_A(x) (((x) & 0xffff) << 0)
306
307#define UTMIP_BAT_CHRG_CFG0 0x830
308#define UTMIP_PD_CHRG (1 << 0)
309#define UTMIP_ON_SINK_EN (1 << 2)
310#define UTMIP_OP_SRC_EN (1 << 3)
311
312#define UTMIP_XCVR_CFG1 0x838
313#define UTMIP_FORCE_PDDISC_POWERDOWN (1 << 0)
314#define UTMIP_FORCE_PDCHRP_POWERDOWN (1 << 2)
315#define UTMIP_FORCE_PDDR_POWERDOWN (1 << 4)
316#define UTMIP_XCVR_TERM_RANGE_ADJ(x) (((x) & 0xf) << 18)
317
318#define UTMIP_BIAS_CFG1 0x83c
319#define UTMIP_BIAS_PDTRK_COUNT(x) (((x) & 0x1f) << 3)
320#define UTMIP_BIAS_PDTRK_POWERDOWN (1 << 0)
321#define UTMIP_BIAS_PDTRK_POWERUP (1 << 1)
322
323#define HOSTPC1_DEVLC 0x1b4
324#define HOSTPC1_DEVLC_PHCD (1 << 22)
325#define HOSTPC1_DEVLC_PTS(x) (((x) & 0x7) << 29)
326#define HOSTPC1_DEVLC_PTS_MASK 7
327#define HOSTPC1_DEVLC_PTS_HSIC 4
328#define HOSTPC1_DEVLC_STS (1 << 28)
329#define HOSTPC1_DEVLC_PSPD(x) (((x) & 0x3) << 25)
330#define HOSTPC1_DEVLC_PSPD_MASK 3
331#define HOSTPC1_DEVLC_PSPD_HIGH_SPEED 2
332
333#define TEGRA_USB_USBMODE_REG_OFFSET 0x1f8
334#define TEGRA_USB_USBMODE_HOST (3 << 0)
335
336#define TEGRA_PMC_USB_AO 0xf0
337#define TEGRA_PMC_USB_AO_VBUS_WAKEUP_PD_P0 (1 << 2)
338#define TEGRA_PMC_USB_AO_ID_PD_P0 (1 << 3)
339#define TEGRA_PMC_USB_AO_PD_P2 (0xf << 8)
340
341#define ICUSB_CTRL 0x15c
342
343#define UHSIC_PLL_CFG1 0xc04
344#define UHSIC_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0)
345#define UHSIC_PLLU_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 14)
346
347#define UHSIC_HSRX_CFG0 0xc08
348#define UHSIC_ELASTIC_UNDERRUN_LIMIT(x) (((x) & 0x1f) << 2)
349#define UHSIC_ELASTIC_OVERRUN_LIMIT(x) (((x) & 0x1f) << 8)
350#define UHSIC_IDLE_WAIT(x) (((x) & 0x1f) << 13)
351
352#define UHSIC_HSRX_CFG1 0xc0c
353#define UHSIC_HS_SYNC_START_DLY(x) (((x) & 0x1f) << 1)
354
355#define UHSIC_TX_CFG0 0xc10
356#define UHSIC_HS_READY_WAIT_FOR_VALID (1 << 9)
357
358#define UHSIC_MISC_CFG0 0xc14
359#define UHSIC_SUSPEND_EXIT_ON_EDGE (1 << 7)
360#define UHSIC_DETECT_SHORT_CONNECT (1 << 8)
361#define UHSIC_FORCE_XCVR_MODE (1 << 15)
362#define UHSIC_DISABLE_BUSRESET (1 << 20)
363
364#define UHSIC_MISC_CFG1 0xc18
365#define UHSIC_PLLU_STABLE_COUNT(x) (((x) & 0xfff) << 2)
366
367#define UHSIC_PADS_CFG0 0xc1c
368#define UHSIC_TX_RTUNEN 0xf000
369#define UHSIC_TX_RTUNE(x) (((x) & 0xf) << 12)
370
371#define UHSIC_PADS_CFG1 0xc20
372#define UHSIC_PD_BG (1 << 2)
373#define UHSIC_PD_TX (1 << 3)
374#define UHSIC_PD_TRK (1 << 4)
375#define UHSIC_PD_RX (1 << 5)
376#define UHSIC_PD_ZI (1 << 6)
377#define UHSIC_RX_SEL (1 << 7)
378#define UHSIC_RPD_DATA (1 << 9)
379#define UHSIC_RPD_STROBE (1 << 10)
380#define UHSIC_RPU_DATA (1 << 11)
381#define UHSIC_RPU_STROBE (1 << 12)
382
383#define UHSIC_STAT_CFG0 0xc28
384#define UHSIC_CONNECT_DETECT (1 << 0)
385
386#define PMC_UTMIP_MASTER_CONFIG 0x310
387#define UTMIP_PWR(inst) (1 << (inst))
388
389#define PMC_USB_DEBOUNCE 0xec
390#define UTMIP_LINE_DEB_CNT(x) (((x) & 0xf) << 16)
391
392#define PMC_UTMIP_UHSIC_FAKE 0x218
393#define USBON_VAL(inst) (1 << ((4*(inst))+1))
394#define USBON_VAL_P2 (1 << 9)
395#define USBON_VAL_P1 (1 << 5)
396#define USBON_VAL_P0 (1 << 1)
397#define USBOP_VAL(inst) (1 << (4*(inst)))
398#define USBOP_VAL_P2 (1 << 8)
399#define USBOP_VAL_P1 (1 << 4)
400#define USBOP_VAL_P0 (1 << 0)
401
402#define PMC_SLEEPWALK_CFG 0x200
403#define UTMIP_LINEVAL_WALK_EN(inst) (1 << ((8*(inst))+7))
404#define UTMIP_LINEVAL_WALK_EN_P2 (1 << 23)
405#define UTMIP_LINEVAL_WALK_EN_P1 (1 << 15)
406#define UTMIP_LINEVAL_WALK_EN_P0 (1 << 7)
407#define UTMIP_WAKE_VAL(inst, x) (((x) & 0xf) << ((8*(inst))+4))
408#define UTMIP_WAKE_VAL_P2(x) (((x) & 0xf) << 20)
409#define UTMIP_WAKE_VAL_P1(x) (((x) & 0xf) << 12)
410#define UTMIP_WAKE_VAL_P0(x) (((x) & 0xf) << 4)
411#define WAKE_VAL_NONE 0xc
412#define WAKE_VAL_FSJ 0x2
413#define WAKE_VAL_FSK 0x1
414#define WAKE_VAL_SE0 0x0
415#define WAKE_VAL_ANY 0xf
416
417#define PMC_SLEEP_CFG 0x1fc
418#define UTMIP_TCTRL_USE_PMC(inst) (1 << ((8*(inst))+3))
419#define UTMIP_TCTRL_USE_PMC_P2 (1 << 19)
420#define UTMIP_TCTRL_USE_PMC_P1 (1 << 11)
421#define UTMIP_TCTRL_USE_PMC_P0 (1 << 3)
422#define UTMIP_RCTRL_USE_PMC(inst) (1 << ((8*(inst))+2))
423#define UTMIP_RCTRL_USE_PMC_P2 (1 << 18)
424#define UTMIP_RCTRL_USE_PMC_P1 (1 << 10)
425#define UTMIP_RCTRL_USE_PMC_P0 (1 << 2)
426#define UTMIP_FSLS_USE_PMC(inst) (1 << ((8*(inst))+1))
427#define UTMIP_FSLS_USE_PMC_P2 (1 << 17)
428#define UTMIP_FSLS_USE_PMC_P1 (1 << 9)
429#define UTMIP_FSLS_USE_PMC_P0 (1 << 1)
430#define UTMIP_MASTER_ENABLE(inst) (1 << (8*(inst)))
431#define UTMIP_MASTER_ENABLE_P2 (1 << 16)
432#define UTMIP_MASTER_ENABLE_P1 (1 << 8)
433#define UTMIP_MASTER_ENABLE_P0 (1 << 0)
434
435#define PMC_USB_AO 0xf0
436#define USBON_VAL_PD(inst) (1 << ((4*(inst))+1))
437#define USBON_VAL_PD_P2 (1 << 9)
438#define USBON_VAL_PD_P1 (1 << 5)
439#define USBON_VAL_PD_P0 (1 << 1)
440#define USBOP_VAL_PD(inst) (1 << (4*(inst)))
441#define USBOP_VAL_PD_P2 (1 << 8)
442#define USBOP_VAL_PD_P1 (1 << 4)
443#define USBOP_VAL_PD_P0 (1 << 0)
444
445#define PMC_TRIGGERS 0x1ec
446#define UTMIP_CLR_WALK_PTR(inst) (1 << (inst))
447#define UTMIP_CLR_WALK_PTR_P2 (1 << 2)
448#define UTMIP_CLR_WALK_PTR_P1 (1 << 1)
449#define UTMIP_CLR_WALK_PTR_P0 (1 << 0)
450#define UTMIP_CAP_CFG(inst) (1 << ((inst)+4))
451#define UTMIP_CAP_CFG_P2 (1 << 6)
452#define UTMIP_CAP_CFG_P1 (1 << 5)
453#define UTMIP_CAP_CFG_P0 (1 << 4)
454#define UTMIP_CLR_WAKE_ALARM(inst) (1 << ((inst)+12))
455#define UTMIP_CLR_WAKE_ALARM_P2 (1 << 14)
456
457#define PMC_PAD_CFG (0x1f4)
458
459#define PMC_UTMIP_BIAS_MASTER_CNTRL 0x30c
460#define BIAS_MASTER_PROG_VAL (1 << 1)
461
462#define PMC_SLEEPWALK_REG(inst) (0x204 + (4*(inst)))
463#define PMC_SLEEPWALK_P0 0x204
464#define PMC_SLEEPWALK_P1 0x208
465#define PMC_SLEEPWALK_P2 0x20c
466#define UTMIP_USBOP_RPD_A (1 << 0)
467#define UTMIP_USBON_RPD_A (1 << 1)
468#define UTMIP_AP_A (1 << 4)
469#define UTMIP_AN_A (1 << 5)
470#define UTMIP_HIGHZ_A (1 << 6)
471#define UTMIP_USBOP_RPD_B (1 << 8)
472#define UTMIP_USBON_RPD_B (1 << 9)
473#define UTMIP_AP_B (1 << 12)
474#define UTMIP_AN_B (1 << 13)
475#define UTMIP_HIGHZ_B (1 << 14)
476#define UTMIP_USBOP_RPD_C (1 << 16)
477#define UTMIP_USBON_RPD_C (1 << 17)
478#define UTMIP_AP_C (1 << 20)
479#define UTMIP_AN_C (1 << 21)
480#define UTMIP_HIGHZ_C (1 << 22)
481#define UTMIP_USBOP_RPD_D (1 << 24)
482#define UTMIP_USBON_RPD_D (1 << 25)
483#define UTMIP_AP_D (1 << 28)
484#define UTMIP_AN_D (1 << 29)
485#define UTMIP_HIGHZ_D (1 << 30)
486
487#define UTMIP_PMC_WAKEUP0 0x84c
488#define EVENT_INT_ENB (1 << 0)
489
490#define UTMIP_UHSIC_STATUS 0x214
491#define UTMIP_WALK_PTR_VAL(inst) (0x3 << ((inst)*2))
492#define UTMIP_USBOP_VAL(inst) (1 << ((2*(inst)) + 8))
493#define UTMIP_USBOP_VAL_P2 (1 << 12)
494#define UTMIP_USBOP_VAL_P1 (1 << 10)
495#define UTMIP_USBOP_VAL_P0 (1 << 8)
496#define UTMIP_USBON_VAL(inst) (1 << ((2*(inst)) + 9))
497#define UTMIP_USBON_VAL_P2 (1 << 13)
498#define UTMIP_USBON_VAL_P1 (1 << 11)
499#define UTMIP_USBON_VAL_P0 (1 << 9)
500#define UTMIP_WAKE_ALARM(inst) (1 << ((inst) + 16))
501#define UTMIP_WAKE_ALARM_P2 (1 << 18)
502#define UTMIP_WAKE_ALARM_P1 (1 << 17)
503#define UTMIP_WAKE_ALARM_P0 (1 << 16)
504#define UTMIP_WALK_PTR(inst) (1 << ((inst)*2))
505#define UTMIP_WALK_PTR_P2 (1 << 4)
506#define UTMIP_WALK_PTR_P1 (1 << 2)
507#define UTMIP_WALK_PTR_P0 (1 << 0)
508
509#define UTMIP_BIAS_STS0 0x840
510#define UTMIP_RCTRL_VAL(x) (((x) & 0xffff) << 0)
511#define UTMIP_TCTRL_VAL(x) (((x) & (0xffff << 16)) >> 16)
512
513#define PMC_UTMIP_TERM_PAD_CFG 0x1f8
514#define PMC_TCTRL_VAL(x) (((x) & 0x1f) << 5)
515#define PMC_RCTRL_VAL(x) (((x) & 0x1f) << 0)
516
517static u32 utmip_rctrl_val, utmip_tctrl_val;
518
519#endif
520
521/* Common registers */
522#define UTMIP_MISC_CFG0 0x824
523#define UTMIP_DPDM_OBSERVE (1 << 26)
524#define UTMIP_DPDM_OBSERVE_SEL(x) (((x) & 0xf) << 27)
525#define UTMIP_DPDM_OBSERVE_SEL_FS_J UTMIP_DPDM_OBSERVE_SEL(0xf)
526#define UTMIP_DPDM_OBSERVE_SEL_FS_K UTMIP_DPDM_OBSERVE_SEL(0xe)
527#define UTMIP_DPDM_OBSERVE_SEL_FS_SE1 UTMIP_DPDM_OBSERVE_SEL(0xd)
528#define UTMIP_DPDM_OBSERVE_SEL_FS_SE0 UTMIP_DPDM_OBSERVE_SEL(0xc)
529#define UTMIP_SUSPEND_EXIT_ON_EDGE (1 << 22)
530#define FORCE_PULLDN_DM (1 << 8)
531#define FORCE_PULLDN_DP (1 << 9)
532#define COMB_TERMS (1 << 0)
533#define ALWAYS_FREE_RUNNING_TERMS (1 << 1)
534
535#define ULPIS2S_CTRL 0x418
536#define ULPIS2S_ENA (1 << 0)
537#define ULPIS2S_SUPPORT_DISCONNECT (1 << 2)
538#define ULPIS2S_PLLU_MASTER_BLASTER60 (1 << 3)
539#define ULPIS2S_SPARE(x) (((x) & 0xF) << 8)
540#define ULPIS2S_FORCE_ULPI_CLK_OUT (1 << 12)
541#define ULPIS2S_DISCON_DONT_CHECK_SE0 (1 << 13)
542#define ULPIS2S_SUPPORT_HS_KEEP_ALIVE (1 << 14)
543#define ULPIS2S_DISABLE_STP_PU (1 << 15)
544#define ULPIS2S_SLV0_CLAMP_XMIT (1 << 16)
545
546
547#define ULPI_TIMING_CTRL_0 0x424
548#define ULPI_CLOCK_OUT_DELAY(x) ((x) & 0x1F)
549#define ULPI_OUTPUT_PINMUX_BYP (1 << 10)
550#define ULPI_CLKOUT_PINMUX_BYP (1 << 11)
551#define ULPI_SHADOW_CLK_LOOPBACK_EN (1 << 12)
552#define ULPI_SHADOW_CLK_SEL (1 << 13)
553#define ULPI_CORE_CLK_SEL (1 << 14)
554#define ULPI_SHADOW_CLK_DELAY(x) (((x) & 0x1F) << 16)
555#define ULPI_LBK_PAD_EN (1 << 26)
556#define ULPI_LBK_PAD_E_INPUT_OR (1 << 27)
557#define ULPI_CLK_OUT_ENA (1 << 28)
558#define ULPI_CLK_PADOUT_ENA (1 << 29)
559
560#define ULPI_TIMING_CTRL_1 0x428
561#define ULPI_DATA_TRIMMER_LOAD (1 << 0)
562#define ULPI_DATA_TRIMMER_SEL(x) (((x) & 0x7) << 1)
563#define ULPI_STPDIRNXT_TRIMMER_LOAD (1 << 16)
564#define ULPI_STPDIRNXT_TRIMMER_SEL(x) (((x) & 0x7) << 17)
565#define ULPI_DIR_TRIMMER_LOAD (1 << 24)
566#define ULPI_DIR_TRIMMER_SEL(x) (((x) & 0x7) << 25)
567
568#define UTMIP_SPARE_CFG0 0x834
569#define FUSE_SETUP_SEL (1 << 3)
570#define FUSE_ATERM_SEL (1 << 4)
571
572#define FUSE_USB_CALIB_0 0x1F0
573#define FUSE_USB_CALIB_XCVR_SETUP(x) (((x) & 0x7F) << 0)
574
575#define UHSIC_PLL_CFG0 0x800
576
577#define UHSIC_CMD_CFG0 0x824
578#define UHSIC_PRETEND_CONNECT_DETECT (1 << 5)
579
580#define UHSIC_SPARE_CFG0 0x82c
581
582/* These values (in milli second) are taken from the battery charging spec */
583#define TDP_SRC_ON_MS 100
584#define TDPSRC_CON_MS 40
585
586#define CONNECT_DETECT_TIMEOUT 25000
587
588static DEFINE_SPINLOCK(utmip_pad_lock);
589static int utmip_pad_count;
590
591struct tegra_xtal_freq {
592 int freq;
593 u8 enable_delay;
594 u8 stable_count;
595 u8 active_delay;
596 u16 xtal_freq_count;
597 u16 debounce;
598 u8 pdtrk_count;
599};
600
601static const struct tegra_xtal_freq tegra_freq_table[] = {
602 {
603 .freq = 12000000,
604 .enable_delay = 0x02,
605 .stable_count = 0x2F,
606 .active_delay = 0x04,
607 .xtal_freq_count = 0x76,
608 .debounce = 0x7530,
609 .pdtrk_count = 5,
610 },
611 {
612 .freq = 13000000,
613 .enable_delay = 0x02,
614 .stable_count = 0x33,
615 .active_delay = 0x05,
616 .xtal_freq_count = 0x7F,
617 .debounce = 0x7EF4,
618 .pdtrk_count = 5,
619 },
620 {
621 .freq = 19200000,
622 .enable_delay = 0x03,
623 .stable_count = 0x4B,
624 .active_delay = 0x06,
625 .xtal_freq_count = 0xBB,
626 .debounce = 0xBB80,
627 .pdtrk_count = 7,
628 },
629 {
630 .freq = 26000000,
631 .enable_delay = 0x04,
632 .stable_count = 0x66,
633 .active_delay = 0x09,
634 .xtal_freq_count = 0xFE,
635 .debounce = 0xFDE8,
636 .pdtrk_count = 9,
637 },
638};
639
640static const struct tegra_xtal_freq tegra_uhsic_freq_table[] = {
641 {
642 .freq = 12000000,
643 .enable_delay = 0x02,
644 .stable_count = 0x2F,
645 .active_delay = 0x0,
646 .xtal_freq_count = 0x1CA,
647 },
648 {
649 .freq = 13000000,
650 .enable_delay = 0x02,
651 .stable_count = 0x33,
652 .active_delay = 0x0,
653 .xtal_freq_count = 0x1F0,
654 },
655 {
656 .freq = 19200000,
657 .enable_delay = 0x03,
658 .stable_count = 0x4B,
659 .active_delay = 0x0,
660 .xtal_freq_count = 0x2DD,
661 },
662 {
663 .freq = 26000000,
664 .enable_delay = 0x04,
665 .stable_count = 0x66,
666 .active_delay = 0x0,
667 .xtal_freq_count = 0x3E0,
668 },
669};
670
671static struct tegra_utmip_config utmip_default[] = {
672 [0] = {
673 .hssync_start_delay = 9,
674 .idle_wait_delay = 17,
675 .elastic_limit = 16,
676 .term_range_adj = 6,
677 .xcvr_setup = 9,
678 .xcvr_setup_offset = 0,
679 .xcvr_use_fuses = 1,
680 .xcvr_lsfslew = 2,
681 .xcvr_lsrslew = 2,
682 },
683 [2] = {
684 .hssync_start_delay = 9,
685 .idle_wait_delay = 17,
686 .elastic_limit = 16,
687 .term_range_adj = 6,
688 .xcvr_setup_offset = 0,
689 .xcvr_use_fuses = 1,
690 .xcvr_setup = 9,
691 .xcvr_lsfslew = 2,
692 .xcvr_lsrslew = 2,
693 },
694};
695
696struct usb_phy_plat_data usb_phy_data[] = {
697 { 0, 0, -1, NULL},
698 { 0, 0, -1, NULL},
699 { 0, 0, -1, NULL},
700};
701
702static int utmip_pad_open(struct tegra_usb_phy *phy)
703{
704 phy->pad_clk = clk_get_sys("utmip-pad", NULL);
705 if (IS_ERR(phy->pad_clk)) {
706 pr_err("%s: can't get utmip pad clock\n", __func__);
707 return PTR_ERR(phy->pad_clk);
708 }
709
710 if (phy->instance == 0) {
711 phy->pad_regs = phy->regs;
712 } else {
713 phy->pad_regs = ioremap(TEGRA_USB_BASE, TEGRA_USB_SIZE);
714 if (!phy->pad_regs) {
715 pr_err("%s: can't remap usb registers\n", __func__);
716 clk_put(phy->pad_clk);
717 return -ENOMEM;
718 }
719 }
720 return 0;
721}
722
723static void utmip_pad_close(struct tegra_usb_phy *phy)
724{
725 if (phy->instance != 0)
726 iounmap(phy->pad_regs);
727 clk_put(phy->pad_clk);
728}
729
730static int utmip_pad_power_on(struct tegra_usb_phy *phy)
731{
732 unsigned long val, flags;
733 void __iomem *base = phy->pad_regs;
734
735 clk_enable(phy->pad_clk);
736
737 spin_lock_irqsave(&utmip_pad_lock, flags);
738
739 utmip_pad_count++;
740 val = readl(base + UTMIP_BIAS_CFG0);
741 val &= ~(UTMIP_OTGPD | UTMIP_BIASPD);
742#ifndef CONFIG_ARCH_TEGRA_2x_SOC
743 val |= UTMIP_HSSQUELCH_LEVEL(0x2) | UTMIP_HSDISCON_LEVEL(0x1) |
744 UTMIP_HSDISCON_LEVEL_MSB;
745#endif
746 writel(val, base + UTMIP_BIAS_CFG0);
747
748 spin_unlock_irqrestore(&utmip_pad_lock, flags);
749
750 clk_disable(phy->pad_clk);
751
752 return 0;
753}
754
755static int utmip_pad_power_off(struct tegra_usb_phy *phy, bool is_dpd)
756{
757 unsigned long val, flags;
758 void __iomem *base = phy->pad_regs;
759
760 if (!utmip_pad_count) {
761 pr_err("%s: utmip pad already powered off\n", __func__);
762 return -EINVAL;
763 }
764
765 clk_enable(phy->pad_clk);
766
767 spin_lock_irqsave(&utmip_pad_lock, flags);
768
769 if (--utmip_pad_count == 0 && is_dpd) {
770 val = readl(base + UTMIP_BIAS_CFG0);
771 val |= UTMIP_OTGPD | UTMIP_BIASPD;
772#ifndef CONFIG_ARCH_TEGRA_2x_SOC
773 val &= ~(UTMIP_HSSQUELCH_LEVEL(~0) | UTMIP_HSDISCON_LEVEL(~0) |
774 UTMIP_HSDISCON_LEVEL_MSB);
775#endif
776 writel(val, base + UTMIP_BIAS_CFG0);
777 }
778
779 spin_unlock_irqrestore(&utmip_pad_lock, flags);
780
781 clk_disable(phy->pad_clk);
782
783 return 0;
784}
785
786static int utmi_wait_register(void __iomem *reg, u32 mask, u32 result)
787{
788 unsigned long timeout = 2500;
789 do {
790 if ((readl(reg) & mask) == result)
791 return 0;
792 udelay(1);
793 timeout--;
794 } while (timeout);
795 return -1;
796}
797
798static int utmi_wait_register_timeout(void __iomem *reg, u32 mask, u32 result,
799 unsigned long timeout)
800{
801 do {
802 if ((readl(reg) & mask) == result)
803 return 0;
804 udelay(1);
805 timeout--;
806 } while (timeout);
807 return -1;
808}
809
810static void utmi_phy_clk_disable(struct tegra_usb_phy *phy)
811{
812 unsigned long val;
813 void __iomem *base = phy->regs;
814
815#ifdef CONFIG_ARCH_TEGRA_2x_SOC
816 if (phy->instance == 0) {
817 val = readl(base + USB_SUSP_CTRL);
818 val |= USB_SUSP_SET;
819 writel(val, base + USB_SUSP_CTRL);
820
821 udelay(10);
822
823 val = readl(base + USB_SUSP_CTRL);
824 val &= ~USB_SUSP_SET;
825 writel(val, base + USB_SUSP_CTRL);
826 }
827
828 if (phy->instance == 2) {
829 val = readl(base + USB_PORTSC1);
830 val |= USB_PORTSC1_PHCD;
831 writel(val, base + USB_PORTSC1);
832 }
833#else
834 val = readl(base + HOSTPC1_DEVLC);
835 val |= HOSTPC1_DEVLC_PHCD;
836 writel(val, base + HOSTPC1_DEVLC);
837#endif
838 if (phy->instance == 2) {
839 val = readl(base + USB_SUSP_CTRL);
840 val |= USB_PHY_CLK_VALID_INT_ENB;
841 writel(val, base + USB_SUSP_CTRL);
842 } else {
843 val = readl(base + USB_SUSP_CTRL);
844 val |= UTMIP_RESET;
845 writel(val, base + USB_SUSP_CTRL);
846 }
847
848 if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, 0) < 0)
849 pr_err("%s: timeout waiting for phy to stabilize\n", __func__);
850}
851
852static void utmi_phy_clk_enable(struct tegra_usb_phy *phy)
853{
854 unsigned long val;
855 void __iomem *base = phy->regs;
856
857 if (phy->instance == 0) {
858 val = readl(base + USB_SUSP_CTRL);
859 val |= USB_SUSP_CLR;
860 writel(val, base + USB_SUSP_CTRL);
861
862 udelay(10);
863
864 val = readl(base + USB_SUSP_CTRL);
865 val &= ~USB_SUSP_CLR;
866 writel(val, base + USB_SUSP_CTRL);
867 }
868
869#ifdef CONFIG_ARCH_TEGRA_2x_SOC
870 if (phy->instance == 2) {
871 val = readl(base + USB_PORTSC1);
872 val &= ~USB_PORTSC1_PHCD;
873 writel(val, base + USB_PORTSC1);
874 }
875#endif
876
877 if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID,
878 USB_PHY_CLK_VALID) < 0)
879 pr_err("%s: timeout waiting for phy to stabilize\n", __func__);
880}
881
882static void vbus_enable(struct tegra_usb_phy *phy)
883{
884#ifdef CONFIG_ARCH_TEGRA_2x_SOC
885 int gpio_status;
886 int gpio = usb_phy_data[phy->instance].vbus_gpio;
887
888 if (gpio == -1)
889 return;
890
891 gpio_status = gpio_request(gpio,"VBUS_USB");
892 if (gpio_status < 0) {
893 printk("VBUS_USB request GPIO FAILED\n");
894 WARN_ON(1);
895 return;
896 }
897 if (gpio < TEGRA_NR_GPIOS) tegra_gpio_enable(gpio);
898 gpio_status = gpio_direction_output(gpio, 1);
899 if (gpio_status < 0) {
900 printk("VBUS_USB request GPIO DIRECTION FAILED \n");
901 WARN_ON(1);
902 return;
903 }
904 gpio_set_value_cansleep(gpio, 1);
905#else
906 if (phy->reg_vbus)
907 regulator_enable(phy->reg_vbus);
908#endif
909}
910
911static void vbus_disable(struct tegra_usb_phy *phy)
912{
913#ifdef CONFIG_ARCH_TEGRA_2x_SOC
914 int gpio = usb_phy_data[phy->instance].vbus_gpio;
915
916 if (gpio == -1)
917 return;
918
919 gpio_set_value_cansleep(gpio, 0);
920 gpio_free(gpio);
921#else
922 if (phy->reg_vbus)
923 regulator_disable(phy->reg_vbus);
924#endif
925}
926
927#ifndef CONFIG_ARCH_TEGRA_2x_SOC
928static void utmip_phy_enable_trking_data(struct tegra_usb_phy *phy)
929{
930 void __iomem *base = phy->pad_regs;
931 void __iomem *pmc_base = IO_ADDRESS(TEGRA_PMC_BASE);
932 static bool init_done = false;
933 u32 val;
934
935 /* Should be done only once after system boot */
936 if (init_done)
937 return;
938
939 clk_enable(phy->pad_clk);
940 /* Bias pad MASTER_ENABLE=1 */
941 val = readl(pmc_base + PMC_UTMIP_BIAS_MASTER_CNTRL);
942 val |= BIAS_MASTER_PROG_VAL;
943 writel(val, pmc_base + PMC_UTMIP_BIAS_MASTER_CNTRL);
944
945 /* Setting the tracking length time */
946 val = readl(base + UTMIP_BIAS_CFG1);
947 val &= ~UTMIP_BIAS_PDTRK_COUNT(~0);
948 val |= UTMIP_BIAS_PDTRK_COUNT(5);
949 writel(val, base + UTMIP_BIAS_CFG1);
950
951 /* Bias PDTRK is Shared and MUST be done from USB1 ONLY, PD_TRK=0 */
952 val = readl(base + UTMIP_BIAS_CFG1);
953 val &= ~ UTMIP_BIAS_PDTRK_POWERDOWN;
954 writel(val, base + UTMIP_BIAS_CFG1);
955
956 val = readl(base + UTMIP_BIAS_CFG1);
957 val |= UTMIP_BIAS_PDTRK_POWERUP;
958 writel(val, base + UTMIP_BIAS_CFG1);
959
960 /* Wait for 25usec */
961 udelay(25);
962
963 /* Bias pad MASTER_ENABLE=0 */
964 val = readl(pmc_base + PMC_UTMIP_BIAS_MASTER_CNTRL);
965 val &= ~BIAS_MASTER_PROG_VAL;
966 writel(val, pmc_base + PMC_UTMIP_BIAS_MASTER_CNTRL);
967
968 /* Wait for 1usec */
969 udelay(1);
970
971 /* Bias pad MASTER_ENABLE=1 */
972 val = readl(pmc_base + PMC_UTMIP_BIAS_MASTER_CNTRL);
973 val |= BIAS_MASTER_PROG_VAL;
974 writel(val, pmc_base + PMC_UTMIP_BIAS_MASTER_CNTRL);
975
976 /* Read RCTRL and TCTRL from UTMIP space */
977 val = readl(base + UTMIP_BIAS_STS0);
978 utmip_rctrl_val = ffz(UTMIP_RCTRL_VAL(val));
979 utmip_tctrl_val = ffz(UTMIP_TCTRL_VAL(val));
980
981 /* PD_TRK=1 */
982 val = readl(base + UTMIP_BIAS_CFG1);
983 val |= UTMIP_BIAS_PDTRK_POWERDOWN;
984 writel(val, base + UTMIP_BIAS_CFG1);
985
986 /* Program thermally encoded RCTRL_VAL, TCTRL_VAL into PMC space */
987 val = readl(pmc_base + PMC_UTMIP_TERM_PAD_CFG);
988 val = PMC_TCTRL_VAL(utmip_tctrl_val) | PMC_RCTRL_VAL(utmip_rctrl_val);
989 writel(val, pmc_base + PMC_UTMIP_TERM_PAD_CFG);
990 clk_disable(phy->pad_clk);
991 init_done = true;
992}
993#endif
994
995static unsigned int tegra_phy_xcvr_setup_value(struct tegra_utmip_config *cfg)
996{
997 signed long val;
998
999 if (cfg->xcvr_use_fuses) {
1000 val = FUSE_USB_CALIB_XCVR_SETUP(
1001 tegra_fuse_readl(FUSE_USB_CALIB_0));
1002 if (cfg->xcvr_setup_offset <= UTMIP_XCVR_MAX_OFFSET)
1003 val = val + cfg->xcvr_setup_offset;
1004
1005 if (val > UTMIP_XCVR_SETUP_MAX_VALUE) {
1006 val = UTMIP_XCVR_SETUP_MAX_VALUE;
1007 pr_info("%s: reset XCVR_SETUP to max value\n",
1008 __func__);
1009 } else if (val < UTMIP_XCVR_SETUP_MIN_VALUE) {
1010 val = UTMIP_XCVR_SETUP_MIN_VALUE;
1011 pr_info("%s: reset XCVR_SETUP to min value\n",
1012 __func__);
1013 }
1014 } else {
1015 val = cfg->xcvr_setup;
1016 }
1017
1018 return (unsigned int)val;
1019}
1020
1021static int utmi_phy_power_on(struct tegra_usb_phy *phy, bool is_dpd)
1022{
1023 unsigned long val;
1024 void __iomem *base = phy->regs;
1025 unsigned int xcvr_setup_value;
1026 struct tegra_utmip_config *config = phy->config;
1027
1028 val = readl(base + USB_SUSP_CTRL);
1029 val |= UTMIP_RESET;
1030 writel(val, base + USB_SUSP_CTRL);
1031
1032#ifdef CONFIG_ARCH_TEGRA_2x_SOC
1033 if (phy->instance == 0) {
1034 val = readl(base + USB1_LEGACY_CTRL);
1035 val |= USB1_NO_LEGACY_MODE;
1036 writel(val, base + USB1_LEGACY_CTRL);
1037 }
1038#endif
1039
1040 val = readl(base + UTMIP_TX_CFG0);
1041 val |= UTMIP_FS_PREABMLE_J;
1042 writel(val, base + UTMIP_TX_CFG0);
1043
1044 val = readl(base + UTMIP_HSRX_CFG0);
1045 val &= ~(UTMIP_IDLE_WAIT(~0) | UTMIP_ELASTIC_LIMIT(~0));
1046 val |= UTMIP_IDLE_WAIT(config->idle_wait_delay);
1047 val |= UTMIP_ELASTIC_LIMIT(config->elastic_limit);
1048 writel(val, base + UTMIP_HSRX_CFG0);
1049
1050 val = readl(base + UTMIP_HSRX_CFG1);
1051 val &= ~UTMIP_HS_SYNC_START_DLY(~0);
1052 val |= UTMIP_HS_SYNC_START_DLY(config->hssync_start_delay);
1053 writel(val, base + UTMIP_HSRX_CFG1);
1054
1055 val = readl(base + UTMIP_DEBOUNCE_CFG0);
1056 val &= ~UTMIP_BIAS_DEBOUNCE_A(~0);
1057 val |= UTMIP_BIAS_DEBOUNCE_A(phy->freq->debounce);
1058 writel(val, base + UTMIP_DEBOUNCE_CFG0);
1059
1060 val = readl(base + UTMIP_MISC_CFG0);
1061 val &= ~UTMIP_SUSPEND_EXIT_ON_EDGE;
1062 writel(val, base + UTMIP_MISC_CFG0);
1063
1064#ifdef CONFIG_ARCH_TEGRA_2x_SOC
1065 val = readl(base + UTMIP_MISC_CFG1);
1066 val &= ~(UTMIP_PLL_ACTIVE_DLY_COUNT(~0) | UTMIP_PLLU_STABLE_COUNT(~0));
1067 val |= UTMIP_PLL_ACTIVE_DLY_COUNT(phy->freq->active_delay) |
1068 UTMIP_PLLU_STABLE_COUNT(phy->freq->stable_count);
1069 writel(val, base + UTMIP_MISC_CFG1);
1070
1071 val = readl(base + UTMIP_PLL_CFG1);
1072 val &= ~(UTMIP_XTAL_FREQ_COUNT(~0) | UTMIP_PLLU_ENABLE_DLY_COUNT(~0));
1073 val |= UTMIP_XTAL_FREQ_COUNT(phy->freq->xtal_freq_count) |
1074 UTMIP_PLLU_ENABLE_DLY_COUNT(phy->freq->enable_delay);
1075 writel(val, base + UTMIP_PLL_CFG1);
1076#endif
1077
1078 if (phy->mode == TEGRA_USB_PHY_MODE_DEVICE) {
1079 val = readl(base + USB_SUSP_CTRL);
1080 val &= ~(USB_WAKE_ON_CNNT_EN_DEV | USB_WAKE_ON_DISCON_EN_DEV);
1081 writel(val, base + USB_SUSP_CTRL);
1082 }
1083
1084 utmip_pad_power_on(phy);
1085
1086 xcvr_setup_value = phy->xcvr_setup_value;
1087
1088 val = readl(base + UTMIP_XCVR_CFG0);
1089 val &= ~(UTMIP_XCVR_LSBIAS_SEL | UTMIP_FORCE_PD_POWERDOWN |
1090 UTMIP_FORCE_PD2_POWERDOWN | UTMIP_FORCE_PDZI_POWERDOWN |
1091 UTMIP_XCVR_SETUP(~0) | UTMIP_XCVR_LSFSLEW(~0) |
1092 UTMIP_XCVR_LSRSLEW(~0) | UTMIP_XCVR_HSSLEW_MSB(~0));
1093 val |= UTMIP_XCVR_SETUP(xcvr_setup_value);
1094 val |= UTMIP_XCVR_SETUP_MSB(XCVR_SETUP_MSB_CALIB(xcvr_setup_value));
1095 val |= UTMIP_XCVR_LSFSLEW(config->xcvr_lsfslew);
1096 val |= UTMIP_XCVR_LSRSLEW(config->xcvr_lsrslew);
1097#ifndef CONFIG_ARCH_TEGRA_2x_SOC
1098 val |= UTMIP_XCVR_HSSLEW_MSB(0x8);
1099#endif
1100 writel(val, base + UTMIP_XCVR_CFG0);
1101
1102 val = readl(base + UTMIP_XCVR_CFG1);
1103 val &= ~(UTMIP_FORCE_PDDISC_POWERDOWN | UTMIP_FORCE_PDCHRP_POWERDOWN |
1104 UTMIP_FORCE_PDDR_POWERDOWN | UTMIP_XCVR_TERM_RANGE_ADJ(~0));
1105 val |= UTMIP_XCVR_TERM_RANGE_ADJ(config->term_range_adj);
1106 writel(val, base + UTMIP_XCVR_CFG1);
1107
1108 val = readl(base + UTMIP_BAT_CHRG_CFG0);
1109 if (phy->mode == TEGRA_USB_PHY_MODE_HOST)
1110 val |= UTMIP_PD_CHRG;
1111 else
1112 val &= ~UTMIP_PD_CHRG;
1113 writel(val, base + UTMIP_BAT_CHRG_CFG0);
1114
1115 val = readl(base + UTMIP_BIAS_CFG1);
1116 val &= ~UTMIP_BIAS_PDTRK_COUNT(~0);
1117 val |= UTMIP_BIAS_PDTRK_COUNT(phy->freq->pdtrk_count);
1118 writel(val, base + UTMIP_BIAS_CFG1);
1119
1120#ifdef CONFIG_ARCH_TEGRA_2x_SOC
1121 val = readl(base + UTMIP_SPARE_CFG0);
1122 val &= ~FUSE_SETUP_SEL;
1123 writel(val, base + UTMIP_SPARE_CFG0);
1124
1125 if (phy->instance == 2) {
1126 val = readl(base + UTMIP_SPARE_CFG0);
1127 val |= FUSE_SETUP_SEL;
1128 writel(val, base + UTMIP_SPARE_CFG0);
1129
1130 val = readl(base + USB_SUSP_CTRL);
1131 val |= UTMIP_PHY_ENABLE;
1132 writel(val, base + USB_SUSP_CTRL);
1133 }
1134#else
1135 val = readl(base + UTMIP_SPARE_CFG0);
1136 val &= ~FUSE_SETUP_SEL;
1137 val |= FUSE_ATERM_SEL;
1138 writel(val, base + UTMIP_SPARE_CFG0);
1139
1140 val = readl(base + USB_SUSP_CTRL);
1141 val |= UTMIP_PHY_ENABLE;
1142 writel(val, base + USB_SUSP_CTRL);
1143#endif
1144
1145 val = readl(base + USB_SUSP_CTRL);
1146 val &= ~UTMIP_RESET;
1147 writel(val, base + USB_SUSP_CTRL);
1148
1149 if (phy->instance == 0) {
1150 val = readl(base + USB1_LEGACY_CTRL);
1151 val &= ~USB1_VBUS_SENSE_CTL_MASK;
1152 val |= USB1_VBUS_SENSE_CTL_A_SESS_VLD;
1153 writel(val, base + USB1_LEGACY_CTRL);
1154
1155#ifdef CONFIG_ARCH_TEGRA_2x_SOC
1156 val = readl(base + USB_SUSP_CTRL);
1157 val &= ~USB_SUSP_SET;
1158 writel(val, base + USB_SUSP_CTRL);
1159#endif
1160 }
1161
1162 utmi_phy_clk_enable(phy);
1163#ifdef CONFIG_ARCH_TEGRA_2x_SOC
1164 if (phy->instance == 2) {
1165 val = readl(base + USB_PORTSC1);
1166 val &= ~USB_PORTSC1_PTS(~0);
1167 writel(val, base + USB_PORTSC1);
1168 }
1169#else
1170 if (phy->instance == 0)
1171 utmip_phy_enable_trking_data(phy);
1172
1173 if(phy->instance == 2) {
1174 writel(0, base + ICUSB_CTRL);
1175 }
1176
1177 if (phy->mode == TEGRA_USB_PHY_MODE_HOST) {
1178 val = readl(base + TEGRA_USB_USBMODE_REG_OFFSET);
1179 writel((val | TEGRA_USB_USBMODE_HOST),
1180 (base + TEGRA_USB_USBMODE_REG_OFFSET));
1181 }
1182 val = readl(base + HOSTPC1_DEVLC);
1183 val &= ~HOSTPC1_DEVLC_PTS(~0);
1184 val |= HOSTPC1_DEVLC_STS;
1185 writel(val, base + HOSTPC1_DEVLC);
1186#endif
1187
1188 return 0;
1189}
1190
1191#ifndef CONFIG_ARCH_TEGRA_2x_SOC
1192static void utmip_setup_pmc_wake_detect(struct tegra_usb_phy *phy)
1193{
1194 unsigned long val, pmc_pad_cfg_val;
1195 void __iomem *pmc_base = IO_ADDRESS(TEGRA_PMC_BASE);
1196 unsigned int inst = phy->instance;
1197 void __iomem *base = phy->regs;
1198 bool port_connected;
1199 enum tegra_usb_phy_port_speed port_speed;
1200
1201 /* check for port connect status */
1202 val = readl(base + USB_PORTSC1);
1203 port_connected = val & USB_PORTSC1_CCS;
1204
1205 if (!port_connected)
1206 return;
1207
1208 port_speed = (readl(base + HOSTPC1_DEVLC) >> 25) &
1209 HOSTPC1_DEVLC_PSPD_MASK;
1210 /*Set PMC MASTER bits to do the following
1211 * a. Take over the UTMI drivers
1212 * b. set up such that it will take over resume
1213 * if remote wakeup is detected
1214 * Prepare PMC to take over suspend-wake detect-drive resume until USB
1215 * controller ready
1216 */
1217
1218 /* disable master enable in PMC */
1219 val = readl(pmc_base + PMC_SLEEP_CFG);
1220 val &= ~UTMIP_MASTER_ENABLE(inst);
1221 writel(val, pmc_base + PMC_SLEEP_CFG);
1222
1223 /* UTMIP_PWR_PX=1 for power savings mode */
1224 val = readl(pmc_base + PMC_UTMIP_MASTER_CONFIG);
1225 val |= UTMIP_PWR(inst);
1226 writel(val, pmc_base + PMC_UTMIP_MASTER_CONFIG);
1227
1228 /* config debouncer */
1229 val = readl(pmc_base + PMC_USB_DEBOUNCE);
1230 val &= ~UTMIP_LINE_DEB_CNT(~0);
1231 val |= UTMIP_LINE_DEB_CNT(1);
1232 writel(val, pmc_base + PMC_USB_DEBOUNCE);
1233
1234 /* Make sure nothing is happening on the line with respect to PMC */
1235 val = readl(pmc_base + PMC_UTMIP_UHSIC_FAKE);
1236 val &= ~USBOP_VAL(inst);
1237 val &= ~USBON_VAL(inst);
1238 writel(val, pmc_base + PMC_UTMIP_UHSIC_FAKE);
1239
1240 /* Make sure wake value for line is none */
1241 val = readl(pmc_base + PMC_SLEEPWALK_CFG);
1242 val &= ~UTMIP_LINEVAL_WALK_EN(inst);
1243 writel(val, pmc_base + PMC_SLEEPWALK_CFG);
1244 val = readl(pmc_base + PMC_SLEEP_CFG);
1245 val &= ~UTMIP_WAKE_VAL(inst, ~0);
1246 val |= UTMIP_WAKE_VAL(inst, WAKE_VAL_NONE);
1247 writel(val, pmc_base + PMC_SLEEP_CFG);
1248
1249 /* turn off pad detectors */
1250 val = readl(pmc_base + PMC_USB_AO);
1251 val |= (USBOP_VAL_PD(inst) | USBON_VAL_PD(inst));
1252 writel(val, pmc_base + PMC_USB_AO);
1253
1254 /* Remove fake values and make synchronizers work a bit */
1255 val = readl(pmc_base + PMC_UTMIP_UHSIC_FAKE);
1256 val &= ~USBOP_VAL(inst);
1257 val &= ~USBON_VAL(inst);
1258 writel(val, pmc_base + PMC_UTMIP_UHSIC_FAKE);
1259
1260 /* Enable which type of event can trigger a walk,
1261 in this case usb_line_wake */
1262 val = readl(pmc_base + PMC_SLEEPWALK_CFG);
1263 val |= UTMIP_LINEVAL_WALK_EN(inst);
1264 writel(val, pmc_base + PMC_SLEEPWALK_CFG);
1265
1266 /* Enable which type of event can trigger a walk,
1267 * in this case usb_line_wake */
1268 val = readl(pmc_base + PMC_SLEEPWALK_CFG);
1269 val |= UTMIP_LINEVAL_WALK_EN(inst);
1270 writel(val, pmc_base + PMC_SLEEPWALK_CFG);
1271
1272 /* Clear the walk pointers and wake alarm */
1273 val = readl(pmc_base + PMC_TRIGGERS);
1274 val |= UTMIP_CLR_WAKE_ALARM(inst) | UTMIP_CLR_WALK_PTR(inst);
1275 writel(val, pmc_base + PMC_TRIGGERS);
1276
1277
1278 /* Capture FS/LS pad configurations */
1279 pmc_pad_cfg_val = readl(pmc_base + PMC_PAD_CFG);
1280 val = readl(pmc_base + PMC_TRIGGERS);
1281 val |= UTMIP_CAP_CFG(inst);
1282 writel(val, pmc_base + PMC_TRIGGERS);
1283 udelay(1);
1284 pmc_pad_cfg_val = readl(pmc_base + PMC_PAD_CFG);
1285
1286 /* BIAS MASTER_ENABLE=0 */
1287 val = readl(pmc_base + PMC_UTMIP_BIAS_MASTER_CNTRL);
1288 val &= ~BIAS_MASTER_PROG_VAL;
1289 writel(val, pmc_base + PMC_UTMIP_BIAS_MASTER_CNTRL);
1290
1291 /* program walk sequence, maintain a J, followed by a driven K
1292 * to signal a resume once an wake event is detected */
1293 val = readl(pmc_base + PMC_SLEEPWALK_REG(inst));
1294 val &= ~UTMIP_AP_A;
1295 val |= UTMIP_USBOP_RPD_A | UTMIP_USBON_RPD_A| UTMIP_AN_A | UTMIP_HIGHZ_A |
1296 UTMIP_USBOP_RPD_B | UTMIP_USBON_RPD_B | UTMIP_AP_B |
1297 UTMIP_USBOP_RPD_C | UTMIP_USBON_RPD_C | UTMIP_AP_C |
1298 UTMIP_USBOP_RPD_D | UTMIP_USBON_RPD_D | UTMIP_AP_D;
1299 writel(val, pmc_base + PMC_SLEEPWALK_REG(inst));
1300
1301 if (port_speed == TEGRA_USB_PHY_PORT_SPEED_LOW) {
1302 val = readl(pmc_base + PMC_SLEEPWALK_REG(inst));
1303 val &= ~(UTMIP_AN_B | UTMIP_HIGHZ_B | UTMIP_AN_C |
1304 UTMIP_HIGHZ_C | UTMIP_AN_D | UTMIP_HIGHZ_D);
1305 writel(val, pmc_base + PMC_SLEEPWALK_REG(inst));
1306 } else {
1307 val = readl(pmc_base + PMC_SLEEPWALK_REG(inst));
1308 val &= ~(UTMIP_AP_B | UTMIP_HIGHZ_B | UTMIP_AP_C |
1309 UTMIP_HIGHZ_C | UTMIP_AP_D | UTMIP_HIGHZ_D);
1310 writel(val, pmc_base + PMC_SLEEPWALK_REG(inst));
1311 }
1312
1313 /* turn on pad detectors */
1314 val = readl(pmc_base + PMC_USB_AO);
1315 val &= ~(USBOP_VAL_PD(inst) | USBON_VAL_PD(inst));
1316 writel(val, pmc_base + PMC_USB_AO);
1317
1318 /* Add small delay before usb detectors provide stable line values */
1319 mdelay(1);
1320
1321 /* Program thermally encoded RCTRL_VAL, TCTRL_VAL into PMC space */
1322 val = readl(pmc_base + PMC_UTMIP_TERM_PAD_CFG);
1323 val = PMC_TCTRL_VAL(utmip_tctrl_val) | PMC_RCTRL_VAL(utmip_rctrl_val);
1324 writel(val, pmc_base + PMC_UTMIP_TERM_PAD_CFG);
1325
1326 phy->remote_wakeup = false;
1327
1328 /* Turn over pad configuration to PMC for line wake events*/
1329 val = readl(pmc_base + PMC_SLEEP_CFG);
1330 val &= ~UTMIP_WAKE_VAL(inst, ~0);
1331 val |= UTMIP_WAKE_VAL(inst, WAKE_VAL_ANY);
1332 val |= UTMIP_RCTRL_USE_PMC(inst) | UTMIP_TCTRL_USE_PMC(inst);
1333 val |= UTMIP_MASTER_ENABLE(inst) | UTMIP_FSLS_USE_PMC(inst);
1334 writel(val, pmc_base + PMC_SLEEP_CFG);
1335
1336 val = readl(base + UTMIP_PMC_WAKEUP0);
1337 val |= EVENT_INT_ENB;
1338 writel(val, base + UTMIP_PMC_WAKEUP0);
1339}
1340#endif
1341
1342static int utmi_phy_power_off(struct tegra_usb_phy *phy, bool is_dpd)
1343{
1344 unsigned long val;
1345 void __iomem *base = phy->regs;
1346
1347#ifndef CONFIG_ARCH_TEGRA_2x_SOC
1348 if (phy->mode == TEGRA_USB_PHY_MODE_HOST)
1349 utmip_setup_pmc_wake_detect(phy);
1350#endif
1351 if (phy->mode == TEGRA_USB_PHY_MODE_DEVICE) {
1352 val = readl(base + USB_SUSP_CTRL);
1353 val &= ~USB_WAKEUP_DEBOUNCE_COUNT(~0);
1354 val |= USB_WAKE_ON_CNNT_EN_DEV | USB_WAKEUP_DEBOUNCE_COUNT(5);
1355 writel(val, base + USB_SUSP_CTRL);
1356 }
1357
1358 if (phy->mode == TEGRA_USB_PHY_MODE_DEVICE) {
1359 val = readl(base + UTMIP_BAT_CHRG_CFG0);
1360 val |= UTMIP_PD_CHRG;
1361 writel(val, base + UTMIP_BAT_CHRG_CFG0);
1362 }
1363
1364 if (phy->instance != 2) {
1365 val = readl(base + UTMIP_XCVR_CFG0);
1366 val |= (UTMIP_FORCE_PD_POWERDOWN | UTMIP_FORCE_PD2_POWERDOWN |
1367 UTMIP_FORCE_PDZI_POWERDOWN);
1368 writel(val, base + UTMIP_XCVR_CFG0);
1369 }
1370 val = readl(base + UTMIP_XCVR_CFG1);
1371 val |= UTMIP_FORCE_PDDISC_POWERDOWN | UTMIP_FORCE_PDCHRP_POWERDOWN |
1372 UTMIP_FORCE_PDDR_POWERDOWN;
1373 writel(val, base + UTMIP_XCVR_CFG1);
1374
1375#ifndef CONFIG_ARCH_TEGRA_2x_SOC
1376 val = readl(base + UTMIP_BIAS_CFG1);
1377 val |= UTMIP_BIAS_PDTRK_COUNT(0x5);
1378 writel(val, base + UTMIP_BIAS_CFG1);
1379#endif
1380
1381 if (phy->hotplug) {
1382 val = readl(base + USB_PORTSC1);
1383 val |= USB_PORTSC1_WKCN;
1384 writel(val, base + USB_PORTSC1);
1385 }
1386 if (phy->instance != 0) {
1387 val = readl(base + UTMIP_BIAS_CFG0);
1388 val |= UTMIP_OTGPD;
1389 writel(val, base + UTMIP_BIAS_CFG0);
1390 }
1391
1392 utmi_phy_clk_disable(phy);
1393
1394 utmip_pad_power_off(phy, true);
1395 return 0;
1396}
1397
1398static void utmip_phy_disable_pmc_bus_ctrl(struct tegra_usb_phy *phy)
1399{
1400#ifndef CONFIG_ARCH_TEGRA_2x_SOC
1401 unsigned long val;
1402 void __iomem *pmc_base = IO_ADDRESS(TEGRA_PMC_BASE);
1403 unsigned int inst = phy->instance;
1404 void __iomem *base = phy->regs;
1405
1406 val = readl(pmc_base + PMC_SLEEP_CFG);
1407 val &= ~UTMIP_WAKE_VAL(inst, 0x0);
1408 val |= UTMIP_WAKE_VAL(inst, WAKE_VAL_NONE);
1409 writel(val, pmc_base + PMC_SLEEP_CFG);
1410
1411 val = readl(pmc_base + PMC_TRIGGERS);
1412 val |= UTMIP_CLR_WAKE_ALARM(inst) | UTMIP_CLR_WALK_PTR(inst);
1413 writel(val, pmc_base + PMC_TRIGGERS);
1414
1415 val = readl(base + UTMIP_PMC_WAKEUP0);
1416 val &= ~EVENT_INT_ENB;
1417 writel(val, base + UTMIP_PMC_WAKEUP0);
1418
1419 /* Disable PMC master mode by clearing MASTER_EN */
1420 val = readl(pmc_base + PMC_SLEEP_CFG);
1421 val &= ~(UTMIP_RCTRL_USE_PMC(inst) | UTMIP_TCTRL_USE_PMC(inst) |
1422 UTMIP_FSLS_USE_PMC(inst) | UTMIP_MASTER_ENABLE(inst));
1423 writel(val, pmc_base + PMC_SLEEP_CFG);
1424
1425 val = readl(pmc_base + PMC_TRIGGERS);
1426 val &= ~UTMIP_CAP_CFG(inst);
1427 writel(val, pmc_base + PMC_TRIGGERS);
1428
1429 /* turn off pad detectors */
1430 val = readl(pmc_base + PMC_USB_AO);
1431 val |= (USBOP_VAL_PD(inst) | USBON_VAL_PD(inst));
1432 writel(val, pmc_base + PMC_USB_AO);
1433
1434 phy->remote_wakeup = false;
1435#endif
1436}
1437
1438static void utmi_phy_enable_obs_bus(struct tegra_usb_phy *phy,
1439 enum tegra_usb_phy_port_speed port_speed)
1440{
1441 unsigned long val;
1442 void __iomem *base = phy->regs;
1443
1444 /* (2LS WAR)is not required for LS and FS devices and is only for HS */
1445 if (port_speed != TEGRA_USB_PHY_PORT_SPEED_HIGH) {
1446 /* do not enable the OBS bus */
1447 val = readl(base + UTMIP_MISC_CFG0);
1448 val &= ~UTMIP_DPDM_OBSERVE_SEL(~0);
1449 writel(val, base + UTMIP_MISC_CFG0);
1450 return;
1451 }
1452 /* Force DP/DM pulldown active for Host mode */
1453 val = readl(base + UTMIP_MISC_CFG0);
1454 val |= FORCE_PULLDN_DM | FORCE_PULLDN_DP |
1455 COMB_TERMS | ALWAYS_FREE_RUNNING_TERMS;
1456 writel(val, base + UTMIP_MISC_CFG0);
1457 val = readl(base + UTMIP_MISC_CFG0);
1458 val &= ~UTMIP_DPDM_OBSERVE_SEL(~0);
1459 if (port_speed == TEGRA_USB_PHY_PORT_SPEED_LOW)
1460 val |= UTMIP_DPDM_OBSERVE_SEL_FS_J;
1461 else
1462 val |= UTMIP_DPDM_OBSERVE_SEL_FS_K;
1463 writel(val, base + UTMIP_MISC_CFG0);
1464 udelay(1);
1465
1466 val = readl(base + UTMIP_MISC_CFG0);
1467 val |= UTMIP_DPDM_OBSERVE;
1468 writel(val, base + UTMIP_MISC_CFG0);
1469 udelay(10);
1470}
1471
1472static void utmi_phy_disable_obs_bus(struct tegra_usb_phy *phy)
1473{
1474 unsigned long val;
1475 void __iomem *base = phy->regs;
1476
1477 /* check if OBS bus is already enabled */
1478 val = readl(base + UTMIP_MISC_CFG0);
1479 if (val & UTMIP_DPDM_OBSERVE) {
1480 /* Change the UTMIP OBS bus to drive SE0 */
1481 val = readl(base + UTMIP_MISC_CFG0);
1482 val &= ~UTMIP_DPDM_OBSERVE_SEL(~0);
1483 val |= UTMIP_DPDM_OBSERVE_SEL_FS_SE0;
1484 writel(val, base + UTMIP_MISC_CFG0);
1485
1486 /* Wait for 3us(2 LS bit times) */
1487 udelay (3);
1488
1489 /* Release UTMIP OBS bus */
1490 val = readl(base + UTMIP_MISC_CFG0);
1491 val &= ~UTMIP_DPDM_OBSERVE;
1492 writel(val, base + UTMIP_MISC_CFG0);
1493
1494 /* Release DP/DM pulldown for Host mode */
1495 val = readl(base + UTMIP_MISC_CFG0);
1496 val &= ~(FORCE_PULLDN_DM | FORCE_PULLDN_DP |
1497 COMB_TERMS | ALWAYS_FREE_RUNNING_TERMS);
1498 writel(val, base + UTMIP_MISC_CFG0);
1499 }
1500}
1501
1502
1503static int utmi_phy_preresume(struct tegra_usb_phy *phy, bool remote_wakeup)
1504{
1505#ifdef CONFIG_ARCH_TEGRA_2x_SOC
1506 unsigned long val;
1507 void __iomem *base = phy->regs;
1508 enum tegra_usb_phy_port_speed port_speed;
1509
1510 val = readl(base + UTMIP_TX_CFG0);
1511 val |= UTMIP_HS_DISCON_DISABLE;
1512 writel(val, base + UTMIP_TX_CFG0);
1513
1514 port_speed = (readl(base + USB_PORTSC1) >> 26) & 0x3;
1515 utmi_phy_enable_obs_bus(phy, port_speed);
1516
1517#else
1518 unsigned long val;
1519 void __iomem *pmc_base = IO_ADDRESS(TEGRA_PMC_BASE);
1520 unsigned int inst = phy->instance;
1521 void __iomem *base = phy->regs;
1522 enum tegra_usb_phy_port_speed port_speed;
1523
1524 val = readl(pmc_base + PMC_SLEEP_CFG);
1525 if (val & UTMIP_MASTER_ENABLE(inst)) {
1526 if (!remote_wakeup)
1527 utmip_phy_disable_pmc_bus_ctrl(phy);
1528 } else {
1529 port_speed = (readl(base + HOSTPC1_DEVLC) >> 25) &
1530 HOSTPC1_DEVLC_PSPD_MASK;
1531 utmi_phy_enable_obs_bus(phy, port_speed);
1532 }
1533#endif
1534
1535 return 0;
1536}
1537
1538static int utmi_phy_postresume(struct tegra_usb_phy *phy, bool is_dpd)
1539{
1540 unsigned long val;
1541 void __iomem *base = phy->regs;
1542 void __iomem *pmc_base = IO_ADDRESS(TEGRA_PMC_BASE);
1543 unsigned int inst = phy->instance;
1544
1545#ifndef CONFIG_ARCH_TEGRA_2x_SOC
1546 val = readl(pmc_base + PMC_SLEEP_CFG);
1547 /* if PMC is not disabled by now then disable it */
1548 if (val & UTMIP_MASTER_ENABLE(inst)) {
1549 utmip_phy_disable_pmc_bus_ctrl(phy);
1550 }
1551#else
1552 val = readl(base + UTMIP_TX_CFG0);
1553 val &= ~UTMIP_HS_DISCON_DISABLE;
1554 writel(val, base + UTMIP_TX_CFG0);
1555#endif
1556
1557 utmi_phy_disable_obs_bus(phy);
1558
1559 return 0;
1560}
1561
1562static int uhsic_phy_postsuspend(struct tegra_usb_phy *phy, bool is_dpd)
1563{
1564 struct tegra_uhsic_config *uhsic_config = phy->config;
1565
1566 if (uhsic_config->postsuspend)
1567 uhsic_config->postsuspend();
1568
1569 return 0;
1570}
1571
1572static int uhsic_phy_preresume(struct tegra_usb_phy *phy, bool remote_wakeup)
1573{
1574 struct tegra_uhsic_config *uhsic_config = phy->config;
1575
1576 if (uhsic_config->preresume)
1577 uhsic_config->preresume();
1578
1579 return 0;
1580}
1581
1582static int uhsic_phy_postresume(struct tegra_usb_phy *phy, bool is_dpd)
1583{
1584 unsigned long val;
1585 void __iomem *base = phy->regs;
1586
1587 val = readl(base + USB_TXFILLTUNING);
1588 if ((val & USB_FIFO_TXFILL_MASK) != USB_FIFO_TXFILL_THRES(0x10)) {
1589 val = USB_FIFO_TXFILL_THRES(0x10);
1590 writel(val, base + USB_TXFILLTUNING);
1591 }
1592
1593 return 0;
1594}
1595
1596static void utmi_phy_restore_start(struct tegra_usb_phy *phy,
1597 enum tegra_usb_phy_port_speed port_speed)
1598{
1599#ifdef CONFIG_ARCH_TEGRA_2x_SOC
1600 unsigned long val;
1601 void __iomem *base = phy->regs;
1602
1603 val = readl(base + UTMIP_MISC_CFG0);
1604 val &= ~UTMIP_DPDM_OBSERVE_SEL(~0);
1605 if (port_speed == TEGRA_USB_PHY_PORT_SPEED_LOW)
1606 val |= UTMIP_DPDM_OBSERVE_SEL_FS_K;
1607 else
1608 val |= UTMIP_DPDM_OBSERVE_SEL_FS_J;
1609 writel(val, base + UTMIP_MISC_CFG0);
1610 udelay(1);
1611
1612 val = readl(base + UTMIP_MISC_CFG0);
1613 val |= UTMIP_DPDM_OBSERVE;
1614 writel(val, base + UTMIP_MISC_CFG0);
1615 udelay(10);
1616#else
1617 unsigned long val;
1618 void __iomem *pmc_base = IO_ADDRESS(TEGRA_PMC_BASE);
1619 int inst = phy->instance;
1620
1621 val = readl(pmc_base + UTMIP_UHSIC_STATUS);
1622 /* check whether we wake up from the remote resume */
1623 if (UTMIP_WALK_PTR_VAL(inst) & val) {
1624 phy->remote_wakeup = true;
1625 } else {
1626 if (!((UTMIP_USBON_VAL(phy->instance) |
1627 UTMIP_USBOP_VAL(phy->instance)) & val)) {
1628 utmip_phy_disable_pmc_bus_ctrl(phy);
1629 }
1630 }
1631 utmi_phy_enable_obs_bus(phy, port_speed);
1632#endif
1633}
1634
1635static void utmi_phy_restore_end(struct tegra_usb_phy *phy)
1636{
1637#ifdef CONFIG_ARCH_TEGRA_2x_SOC
1638 unsigned long val;
1639 void __iomem *base = phy->regs;
1640
1641 val = readl(base + UTMIP_MISC_CFG0);
1642 val &= ~UTMIP_DPDM_OBSERVE;
1643 writel(val, base + UTMIP_MISC_CFG0);
1644 udelay(10);
1645#else
1646 unsigned long val;
1647 void __iomem *base = phy->regs;
1648 int wait_time_us = 3000; /* FPR should be set by this time */
1649
1650 /* check whether we wake up from the remote resume */
1651 if (phy->remote_wakeup) {
1652 /* wait until FPR bit is set automatically on remote resume */
1653 do {
1654 val = readl(base + USB_PORTSC1);
1655 udelay(1);
1656 if (wait_time_us == 0) {
1657 utmip_phy_disable_pmc_bus_ctrl(phy);
1658 tegra_usb_phy_postresume(phy, false);
1659 return;
1660 }
1661 wait_time_us--;
1662 } while (!(val & USB_PORTSC1_RESUME));
1663 /* wait for 25 ms to port resume complete */
1664 msleep(25);
1665 /* disable PMC master control */
1666 utmip_phy_disable_pmc_bus_ctrl(phy);
1667
1668 /* Clear PCI and SRI bits to avoid an interrupt upon resume */
1669 val = readl(base + USB_USBSTS);
1670 writel(val, base + USB_USBSTS);
1671 /* wait to avoid SOF if there is any */
1672 if (utmi_wait_register(base + USB_USBSTS,
1673 USB_USBSTS_SRI, USB_USBSTS_SRI) < 0) {
1674 pr_err("%s: timeout waiting for SOF\n", __func__);
1675 }
1676 tegra_usb_phy_postresume(phy, false);
1677 }
1678#endif
1679}
1680
1681#ifdef CONFIG_ARCH_TEGRA_2x_SOC
1682static void ulpi_set_tristate(bool enable)
1683{
1684 int tristate = (enable)? TEGRA_TRI_TRISTATE : TEGRA_TRI_NORMAL;
1685
1686 tegra_pinmux_set_tristate(TEGRA_PINGROUP_UAA, tristate);
1687 tegra_pinmux_set_tristate(TEGRA_PINGROUP_UAB, tristate);
1688 tegra_pinmux_set_tristate(TEGRA_PINGROUP_UDA, tristate);
1689}
1690#endif
1691
1692static void ulpi_phy_reset(void __iomem *base)
1693{
1694 unsigned long val;
1695
1696 val = readl(base + USB_SUSP_CTRL);
1697 val |= UHSIC_RESET;
1698 writel(val, base + USB_SUSP_CTRL);
1699
1700#ifndef CONFIG_ARCH_TEGRA_2x_SOC
1701 val = readl(base + USB_SUSP_CTRL);
1702 val |= UTMIP_RESET;
1703 writel(val, base + USB_SUSP_CTRL);
1704#endif
1705}
1706
1707static void ulpi_set_host(void __iomem *base)
1708{
1709#ifndef CONFIG_ARCH_TEGRA_2x_SOC
1710 unsigned long val;
1711
1712 val = readl(base + TEGRA_USB_USBMODE_REG_OFFSET);
1713 val |= TEGRA_USB_USBMODE_HOST;
1714 writel(val, base + TEGRA_USB_USBMODE_REG_OFFSET);
1715
1716 val = readl(base + HOSTPC1_DEVLC);
1717 val |= HOSTPC1_DEVLC_PTS(2);
1718 writel(val, base + HOSTPC1_DEVLC);
1719#endif
1720}
1721
1722static void ulpi_set_trimmer(void __iomem *base, u8 data, u8 sdn, u8 dir)
1723{
1724 unsigned long val;
1725
1726 val = ULPI_DATA_TRIMMER_SEL(data);
1727 val |= ULPI_STPDIRNXT_TRIMMER_SEL(sdn);
1728 val |= ULPI_DIR_TRIMMER_SEL(dir);
1729 writel(val, base + ULPI_TIMING_CTRL_1);
1730 udelay(10);
1731
1732 val |= ULPI_DATA_TRIMMER_LOAD;
1733 val |= ULPI_STPDIRNXT_TRIMMER_LOAD;
1734 val |= ULPI_DIR_TRIMMER_LOAD;
1735 writel(val, base + ULPI_TIMING_CTRL_1);
1736}
1737
1738static inline void ulpi_pinmux_bypass(struct tegra_usb_phy *phy, bool enable)
1739{
1740 unsigned long val;
1741 void __iomem *base = phy->regs;
1742
1743 val = readl(base + ULPI_TIMING_CTRL_0);
1744
1745 if (enable)
1746 val |= ULPI_OUTPUT_PINMUX_BYP;
1747 else
1748 val &= ~ULPI_OUTPUT_PINMUX_BYP;
1749
1750 writel(val, base + ULPI_TIMING_CTRL_0);
1751}
1752
1753static void ulpi_phy_restore_start(struct tegra_usb_phy *phy,
1754 enum tegra_usb_phy_port_speed port_speed)
1755{
1756#ifdef CONFIG_ARCH_TEGRA_2x_SOC
1757 unsigned long val;
1758 void __iomem *base = phy->regs;
1759
1760 /*Tristate ulpi interface before USB controller resume*/
1761 ulpi_set_tristate(true);
1762
1763 val = readl(base + ULPI_TIMING_CTRL_0);
1764 val &= ~ULPI_OUTPUT_PINMUX_BYP;
1765 writel(val, base + ULPI_TIMING_CTRL_0);
1766#endif
1767}
1768
1769static void ulpi_phy_restore_end(struct tegra_usb_phy *phy)
1770{
1771#ifdef CONFIG_ARCH_TEGRA_2x_SOC
1772 unsigned long val;
1773 void __iomem *base = phy->regs;
1774
1775 val = readl(base + ULPI_TIMING_CTRL_0);
1776 val |= ULPI_OUTPUT_PINMUX_BYP;
1777 writel(val, base + ULPI_TIMING_CTRL_0);
1778
1779 ulpi_set_tristate(false);
1780#endif
1781}
1782
1783static int ulpi_phy_power_on(struct tegra_usb_phy *phy, bool is_dpd)
1784{
1785 int ret;
1786 unsigned long val;
1787 void __iomem *base = phy->regs;
1788#ifdef CONFIG_ARCH_TEGRA_2x_SOC
1789 struct tegra_ulpi_config *config = phy->config;
1790#endif
1791
1792 if (phy->clk)
1793 clk_enable(phy->clk);
1794
1795 msleep(1);
1796
1797 if (!phy->initialized) {
1798 phy->initialized = 1;
1799#ifdef CONFIG_ARCH_TEGRA_2x_SOC
1800 gpio_direction_output(config->reset_gpio, 0);
1801 msleep(5);
1802 gpio_direction_output(config->reset_gpio, 1);
1803#endif
1804 }
1805
1806 ulpi_phy_reset(base);
1807 ulpi_set_host(base);
1808
1809 val = readl(base + ULPI_TIMING_CTRL_0);
1810 val |= ULPI_OUTPUT_PINMUX_BYP | ULPI_CLKOUT_PINMUX_BYP;
1811 writel(val, base + ULPI_TIMING_CTRL_0);
1812
1813 val = readl(base + USB_SUSP_CTRL);
1814 val |= ULPI_PHY_ENABLE;
1815 writel(val, base + USB_SUSP_CTRL);
1816
1817 val = readl(base + USB_SUSP_CTRL);
1818 val |= USB_SUSP_CLR;
1819 writel(val, base + USB_SUSP_CTRL);
1820
1821#ifdef CONFIG_ARCH_TEGRA_2x_SOC
1822 if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID,
1823 USB_PHY_CLK_VALID) < 0)
1824 pr_err("%s: timeout waiting for phy to stabilize\n", __func__);
1825
1826 if (utmi_wait_register(base + USB_SUSP_CTRL, USB_CLKEN, USB_CLKEN) < 0)
1827 pr_err("%s: timeout waiting for AHB clock\n", __func__);
1828#else
1829 udelay(100);
1830#endif
1831
1832 val = readl(base + USB_SUSP_CTRL);
1833 val &= ~USB_SUSP_CLR;
1834 writel(val, base + USB_SUSP_CTRL);
1835
1836 val = 0;
1837 writel(val, base + ULPI_TIMING_CTRL_1);
1838
1839 ulpi_set_trimmer(base, 4, 4, 4);
1840
1841 /* Fix VbusInvalid due to floating VBUS */
1842 ret = otg_io_write(phy->ulpi, 0x40, 0x08);
1843 if (ret) {
1844 pr_err("%s: ulpi write failed\n", __func__);
1845 return ret;
1846 }
1847
1848 ret = otg_io_write(phy->ulpi, 0x80, 0x0B);
1849 if (ret) {
1850 pr_err("%s: ulpi write failed\n", __func__);
1851 return ret;
1852 }
1853
1854 val = readl(base + USB_PORTSC1);
1855 val |= USB_PORTSC1_WKOC | USB_PORTSC1_WKDS | USB_PORTSC1_WKCN;
1856 writel(val, base + USB_PORTSC1);
1857
1858 return 0;
1859}
1860
1861static int ulpi_phy_power_off(struct tegra_usb_phy *phy, bool is_dpd)
1862{
1863 unsigned long val;
1864 void __iomem *base = phy->regs;
1865#ifdef CONFIG_ARCH_TEGRA_2x_SOC
1866 int ret;
1867
1868 /* Disable VbusValid, SessEnd comparators */
1869 ret = otg_io_write(phy->ulpi, 0x00, 0x0D);
1870 if (ret)
1871 pr_err("%s: ulpi write 0x0D failed\n", __func__);
1872
1873 ret = otg_io_write(phy->ulpi, 0x00, 0x10);
1874 if (ret)
1875 pr_err("%s: ulpi write 0x10 failed\n", __func__);
1876
1877 /* Disable IdFloat comparator */
1878 ret = otg_io_write(phy->ulpi, 0x00, 0x19);
1879 if (ret)
1880 pr_err("%s: ulpi write 0x19 failed\n", __func__);
1881
1882 ret = otg_io_write(phy->ulpi, 0x00, 0x1D);
1883 if (ret)
1884 pr_err("%s: ulpi write 0x1D failed\n", __func__);
1885
1886 /* Clear WKCN/WKDS/WKOC wake-on events that can cause the USB
1887 * Controller to immediately bring the ULPI PHY out of low power
1888 */
1889 val = readl(base + USB_PORTSC1);
1890 val &= ~(USB_PORTSC1_WKOC | USB_PORTSC1_WKDS | USB_PORTSC1_WKCN);
1891 writel(val, base + USB_PORTSC1);
1892
1893 /* Put the PHY in the low power mode */
1894 val = readl(base + USB_PORTSC1);
1895 val |= USB_PORTSC1_PHCD;
1896 writel(val, base + USB_PORTSC1);
1897
1898 if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, 0) < 0)
1899 pr_err("%s: timeout waiting for phy to stop\n", __func__);
1900#else
1901 val = readl(base + HOSTPC1_DEVLC);
1902 val &= ~(HOSTPC1_DEVLC_PHCD);
1903 writel(val, base + HOSTPC1_DEVLC);
1904#endif
1905
1906 if(phy->clk)
1907 clk_disable(phy->clk);
1908
1909 return 0;
1910}
1911
1912static inline void null_phy_set_tristate(bool enable)
1913{
1914 int tristate = (enable) ? TEGRA_TRI_TRISTATE : TEGRA_TRI_NORMAL;
1915
1916#ifdef CONFIG_ARCH_TEGRA_2x_SOC
1917 tegra_pinmux_set_tristate(TEGRA_PINGROUP_UDA, tristate);
1918 tegra_pinmux_set_tristate(TEGRA_PINGROUP_UAA, tristate);
1919 tegra_pinmux_set_tristate(TEGRA_PINGROUP_UAB, tristate);
1920#else
1921 tegra_pinmux_set_tristate(TEGRA_PINGROUP_ULPI_DATA0, tristate);
1922 tegra_pinmux_set_tristate(TEGRA_PINGROUP_ULPI_DATA1, tristate);
1923 tegra_pinmux_set_tristate(TEGRA_PINGROUP_ULPI_DATA2, tristate);
1924 tegra_pinmux_set_tristate(TEGRA_PINGROUP_ULPI_DATA3, tristate);
1925 tegra_pinmux_set_tristate(TEGRA_PINGROUP_ULPI_DATA4, tristate);
1926 tegra_pinmux_set_tristate(TEGRA_PINGROUP_ULPI_DATA5, tristate);
1927 tegra_pinmux_set_tristate(TEGRA_PINGROUP_ULPI_DATA6, tristate);
1928 tegra_pinmux_set_tristate(TEGRA_PINGROUP_ULPI_DATA7, tristate);
1929 tegra_pinmux_set_tristate(TEGRA_PINGROUP_ULPI_NXT, tristate);
1930
1931 if (enable)
1932 tegra_pinmux_set_tristate(TEGRA_PINGROUP_ULPI_DIR, tristate);
1933#endif
1934}
1935
1936static void null_phy_restore_start(struct tegra_usb_phy *phy,
1937 enum tegra_usb_phy_port_speed port_speed)
1938{
1939 struct tegra_ulpi_config *config = phy->config;
1940
1941 if (config->phy_restore_start)
1942 config->phy_restore_start();
1943}
1944
1945static void null_phy_restore_end(struct tegra_usb_phy *phy)
1946{
1947 unsigned long val;
1948 void __iomem *base = phy->regs;
1949 struct tegra_ulpi_config *config = phy->config;
1950
1951 /* disable ULPI pinmux bypass */
1952 ulpi_pinmux_bypass(phy, false);
1953
1954 /* driving linestate using GPIO */
1955 gpio_set_value(config->ulpi_d0_gpio, 0);
1956 gpio_set_value(config->ulpi_d1_gpio, 0);
1957
1958#ifdef CONFIG_ARCH_TEGRA_2x_SOC
1959 /* driving DIR high */
1960 gpio_set_value(config->ulpi_dir_gpio, 1);
1961#endif
1962
1963 /* remove ULPI tristate */
1964 null_phy_set_tristate(false);
1965
1966 if (config->phy_restore_end)
1967 config->phy_restore_end();
1968
1969 if (gpio_is_valid(config->phy_restore_gpio)) {
1970 int phy_restore_gpio = config->phy_restore_gpio;
1971 int retry = 20000;
1972
1973 while (retry) {
1974 /* poll phy_restore_gpio high */
1975 if (gpio_get_value(phy_restore_gpio))
1976 break;
1977 retry--;
1978 }
1979
1980 if (retry == 0)
1981 pr_info("phy_restore_gpio timeout\n");
1982 }
1983
1984 /* enable ULPI CLK output pad */
1985 val = readl(base + ULPI_TIMING_CTRL_0);
1986 val |= ULPI_CLK_PADOUT_ENA;
1987 writel(val, base + ULPI_TIMING_CTRL_0);
1988
1989#ifdef CONFIG_ARCH_TEGRA_2x_SOC
1990 udelay(5); /* wait for CLK stabilize */
1991
1992 /* enable ULPI pinmux bypass */
1993 ulpi_pinmux_bypass(phy, true);
1994#else
1995 /* enable ULPI pinmux bypass */
1996 ulpi_pinmux_bypass(phy, true);
1997 udelay(5);
1998
1999 /* remove DIR tristate */
2000 tegra_pinmux_set_tristate(TEGRA_PINGROUP_ULPI_DIR, TEGRA_TRI_NORMAL);
2001#endif
2002}
2003
2004static int null_phy_power_on(struct tegra_usb_phy *phy, bool is_dpd)
2005{
2006 const struct tegra_ulpi_trimmer default_trimmer = {0, 0, 4, 4};
2007 unsigned long val;
2008 void __iomem *base = phy->regs;
2009 struct tegra_ulpi_config *config = phy->config;
2010 static bool cold_boot = true;
2011
2012 if (!config->trimmer)
2013 config->trimmer = &default_trimmer;
2014
2015 ulpi_phy_reset(base);
2016
2017#ifndef CONFIG_ARCH_TEGRA_2x_SOC
2018 /* remove ULPI PADS CLKEN reset */
2019 val = readl(base + USB_SUSP_CTRL);
2020 val &= ~ULPI_PADS_CLKEN_RESET;
2021 writel(val, base + USB_SUSP_CTRL);
2022 udelay(10);
2023#endif
2024 val = readl(base + ULPI_TIMING_CTRL_0);
2025 val |= ULPI_OUTPUT_PINMUX_BYP | ULPI_CLKOUT_PINMUX_BYP;
2026 writel(val, base + ULPI_TIMING_CTRL_0);
2027
2028 if (config->pre_phy_on && config->pre_phy_on())
2029 return -EAGAIN;
2030
2031 val = readl(base + USB_SUSP_CTRL);
2032 val |= ULPI_PHY_ENABLE;
2033 writel(val, base + USB_SUSP_CTRL);
2034 udelay(10);
2035
2036 /* set timming parameters */
2037 val = readl(base + ULPI_TIMING_CTRL_0);
2038 val |= ULPI_SHADOW_CLK_LOOPBACK_EN;
2039#ifndef CONFIG_ARCH_TEGRA_2x_SOC
2040 val &= ~ULPI_SHADOW_CLK_SEL;
2041 val &= ~ULPI_LBK_PAD_EN;
2042#else
2043 val |= ULPI_SHADOW_CLK_SEL;
2044 val |= ULPI_LBK_PAD_EN;
2045#endif
2046 val |= ULPI_SHADOW_CLK_DELAY(config->trimmer->shadow_clk_delay);
2047 val |= ULPI_CLOCK_OUT_DELAY(config->trimmer->clock_out_delay);
2048 val |= ULPI_LBK_PAD_E_INPUT_OR;
2049 writel(val, base + ULPI_TIMING_CTRL_0);
2050
2051 writel(0, base + ULPI_TIMING_CTRL_1);
2052 udelay(10);
2053
2054 /* start internal 60MHz clock */
2055 val = readl(base + ULPIS2S_CTRL);
2056 val |= ULPIS2S_ENA;
2057 val |= ULPIS2S_SUPPORT_DISCONNECT;
2058 val |= ULPIS2S_SPARE((phy->mode == TEGRA_USB_PHY_MODE_HOST) ? 3 : 1);
2059 val |= ULPIS2S_PLLU_MASTER_BLASTER60;
2060 writel(val, base + ULPIS2S_CTRL);
2061
2062 /* select ULPI_CORE_CLK_SEL to SHADOW_CLK */
2063 val = readl(base + ULPI_TIMING_CTRL_0);
2064 val |= ULPI_CORE_CLK_SEL;
2065 writel(val, base + ULPI_TIMING_CTRL_0);
2066 udelay(10);
2067
2068 /* enable ULPI null phy clock - can't set the trimmers before this */
2069 val = readl(base + ULPI_TIMING_CTRL_0);
2070 val |= ULPI_CLK_OUT_ENA;
2071 writel(val, base + ULPI_TIMING_CTRL_0);
2072 udelay(10);
2073
2074 if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID,
2075 USB_PHY_CLK_VALID)) {
2076 pr_err("%s: timeout waiting for phy to stabilize\n", __func__);
2077 return -ETIMEDOUT;
2078 }
2079
2080 /* set ULPI trimmers */
2081 ulpi_set_trimmer(base, config->trimmer->data_trimmer,
2082 config->trimmer->stpdirnxt_trimmer, 1);
2083
2084 ulpi_set_host(base);
2085
2086#ifndef CONFIG_ARCH_TEGRA_2x_SOC
2087 /* remove slave0 reset */
2088 val = readl(base + USB_SUSP_CTRL);
2089 val &= ~ULPIS2S_SLV0_RESET;
2090 writel(val, base + USB_SUSP_CTRL);
2091
2092 /* remove slave1 and line reset */
2093 val = readl(base + USB_SUSP_CTRL);
2094 val &= ~ULPIS2S_SLV1_RESET;
2095 val &= ~ULPIS2S_LINE_RESET;
2096
2097 /* remove ULPI PADS reset */
2098 val &= ~ULPI_PADS_RESET;
2099 writel(val, base + USB_SUSP_CTRL);
2100#endif
2101 if (cold_boot) {
2102 val = readl(base + ULPI_TIMING_CTRL_0);
2103 val |= ULPI_CLK_PADOUT_ENA;
2104 writel(val, base + ULPI_TIMING_CTRL_0);
2105 cold_boot = false;
2106 }
2107
2108 udelay(10);
2109
2110 if (config->post_phy_on && config->post_phy_on())
2111 return -EAGAIN;
2112
2113 return 0;
2114}
2115
2116static int null_phy_power_off(struct tegra_usb_phy *phy, bool is_dpd)
2117{
2118 struct tegra_ulpi_config *config = phy->config;
2119
2120 if (config->pre_phy_off && config->pre_phy_off())
2121 return -EAGAIN;
2122
2123 null_phy_set_tristate(true);
2124
2125 if (config->post_phy_off && config->post_phy_off())
2126 return -EAGAIN;
2127
2128 return 0;
2129}
2130
2131static int null_phy_pre_usbcmd_reset(struct tegra_usb_phy *phy, bool is_dpd)
2132{
2133#ifndef CONFIG_ARCH_TEGRA_2x_SOC
2134 unsigned long val;
2135 void __iomem *base = phy->regs;
2136
2137 val = readl(base + ULPIS2S_CTRL);
2138 val |= ULPIS2S_SLV0_CLAMP_XMIT;
2139 writel(val, base + ULPIS2S_CTRL);
2140
2141 val = readl(base + USB_SUSP_CTRL);
2142 val |= ULPIS2S_SLV0_RESET;
2143 writel(val, base + USB_SUSP_CTRL);
2144 udelay(10);
2145#endif
2146 return 0;
2147}
2148
2149static int null_phy_post_usbcmd_reset(struct tegra_usb_phy *phy, bool is_dpd)
2150{
2151#ifndef CONFIG_ARCH_TEGRA_2x_SOC
2152 unsigned long val;
2153 void __iomem *base = phy->regs;
2154
2155 ulpi_set_host(base);
2156
2157 /* remove slave0 reset */
2158 val = readl(base + USB_SUSP_CTRL);
2159 val &= ~ULPIS2S_SLV0_RESET;
2160 writel(val, base + USB_SUSP_CTRL);
2161
2162 val = readl(base + ULPIS2S_CTRL);
2163 val &= ~ULPIS2S_SLV0_CLAMP_XMIT;
2164 writel(val, base + ULPIS2S_CTRL);
2165 udelay(10);
2166#endif
2167 return 0;
2168}
2169
2170static int uhsic_phy_power_on(struct tegra_usb_phy *phy, bool is_dpd)
2171{
2172 unsigned long val;
2173 void __iomem *base = phy->regs;
2174 struct tegra_uhsic_config *uhsic_config = phy->config;
2175
2176 if (uhsic_config->enable_gpio != -1) {
2177 gpio_set_value_cansleep(uhsic_config->enable_gpio, 1);
2178 /* keep hsic reset asserted for 1 ms */
2179 udelay(1000);
2180 }
2181
2182 val = readl(base + UHSIC_PADS_CFG1);
2183 val &= ~(UHSIC_PD_BG | UHSIC_PD_TX | UHSIC_PD_TRK | UHSIC_PD_RX |
2184 UHSIC_PD_ZI | UHSIC_RPD_DATA | UHSIC_RPD_STROBE);
2185 val |= UHSIC_RX_SEL;
2186 writel(val, base + UHSIC_PADS_CFG1);
2187 udelay(2);
2188
2189 val = readl(base + USB_SUSP_CTRL);
2190 val |= UHSIC_RESET;
2191 writel(val, base + USB_SUSP_CTRL);
2192 udelay(30);
2193
2194 val = readl(base + USB_SUSP_CTRL);
2195 val |= UHSIC_PHY_ENABLE;
2196 writel(val, base + USB_SUSP_CTRL);
2197
2198 val = readl(base + UHSIC_HSRX_CFG0);
2199 val |= UHSIC_IDLE_WAIT(uhsic_config->idle_wait_delay);
2200 val |= UHSIC_ELASTIC_UNDERRUN_LIMIT(uhsic_config->elastic_underrun_limit);
2201 val |= UHSIC_ELASTIC_OVERRUN_LIMIT(uhsic_config->elastic_overrun_limit);
2202 writel(val, base + UHSIC_HSRX_CFG0);
2203
2204 val = readl(base + UHSIC_HSRX_CFG1);
2205 val |= UHSIC_HS_SYNC_START_DLY(uhsic_config->sync_start_delay);
2206 writel(val, base + UHSIC_HSRX_CFG1);
2207
2208#ifdef CONFIG_ARCH_TEGRA_3x_SOC
2209 /* WAR HSIC TX */
2210 val = readl(base + UHSIC_TX_CFG0);
2211 val &= ~UHSIC_HS_READY_WAIT_FOR_VALID;
2212 writel(val, base + UHSIC_TX_CFG0);
2213#endif
2214
2215 val = readl(base + UHSIC_MISC_CFG0);
2216 val |= UHSIC_SUSPEND_EXIT_ON_EDGE;
2217#ifdef CONFIG_ARCH_TEGRA_3x_SOC
2218 /* Disable generic bus reset, to allow AP30 specific bus reset*/
2219 val |= UHSIC_DISABLE_BUSRESET;
2220#endif
2221 writel(val, base + UHSIC_MISC_CFG0);
2222
2223 val = readl(base + UHSIC_MISC_CFG1);
2224 val |= UHSIC_PLLU_STABLE_COUNT(phy->freq->stable_count);
2225 writel(val, base + UHSIC_MISC_CFG1);
2226
2227 val = readl(base + UHSIC_PLL_CFG1);
2228 val |= UHSIC_PLLU_ENABLE_DLY_COUNT(phy->freq->enable_delay);
2229 val |= UHSIC_XTAL_FREQ_COUNT(phy->freq->xtal_freq_count);
2230 writel(val, base + UHSIC_PLL_CFG1);
2231
2232 val = readl(base + USB_SUSP_CTRL);
2233 val &= ~(UHSIC_RESET);
2234 writel(val, base + USB_SUSP_CTRL);
2235 udelay(2);
2236
2237#ifdef CONFIG_ARCH_TEGRA_2x_SOC
2238 val = readl(base + USB_PORTSC1);
2239 val &= ~USB_PORTSC1_PTS(~0);
2240 writel(val, base + USB_PORTSC1);
2241
2242#endif
2243#ifndef CONFIG_ARCH_TEGRA_2x_SOC
2244 val = readl(base + TEGRA_USB_USBMODE_REG_OFFSET);
2245 val |= TEGRA_USB_USBMODE_HOST;
2246 writel(val, base + TEGRA_USB_USBMODE_REG_OFFSET);
2247
2248 /* Change the USB controller PHY type to HSIC */
2249 val = readl(base + HOSTPC1_DEVLC);
2250 val &= ~HOSTPC1_DEVLC_PTS(HOSTPC1_DEVLC_PTS_MASK);
2251 val |= HOSTPC1_DEVLC_PTS(HOSTPC1_DEVLC_PTS_HSIC);
2252 val &= ~HOSTPC1_DEVLC_PSPD(HOSTPC1_DEVLC_PSPD_MASK);
2253 val |= HOSTPC1_DEVLC_PSPD(HOSTPC1_DEVLC_PSPD_HIGH_SPEED);
2254 writel(val, base + HOSTPC1_DEVLC);
2255#endif
2256 val = readl(base + USB_TXFILLTUNING);
2257 if ((val & USB_FIFO_TXFILL_MASK) != USB_FIFO_TXFILL_THRES(0x10)) {
2258 val = USB_FIFO_TXFILL_THRES(0x10);
2259 writel(val, base + USB_TXFILLTUNING);
2260 }
2261
2262 val = readl(base + USB_PORTSC1);
2263 val &= ~(USB_PORTSC1_WKOC | USB_PORTSC1_WKDS | USB_PORTSC1_WKCN);
2264 writel(val, base + USB_PORTSC1);
2265
2266 val = readl(base + UHSIC_PADS_CFG0);
2267 val &= ~(UHSIC_TX_RTUNEN);
2268#ifdef CONFIG_ARCH_TEGRA_2x_SOC
2269 /* set Rtune impedance to 40 ohm */
2270 val |= UHSIC_TX_RTUNE(0);
2271#else
2272 /* set Rtune impedance to 50 ohm */
2273 val |= UHSIC_TX_RTUNE(8);
2274#endif
2275 writel(val, base + UHSIC_PADS_CFG0);
2276
2277 if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID,
2278 USB_PHY_CLK_VALID)) {
2279 pr_err("%s: timeout waiting for phy to stabilize\n", __func__);
2280 return -ETIMEDOUT;
2281 }
2282
2283 return 0;
2284}
2285
2286static int uhsic_phy_power_off(struct tegra_usb_phy *phy, bool is_dpd)
2287{
2288 unsigned long val;
2289 void __iomem *base = phy->regs;
2290 struct tegra_uhsic_config *uhsic_config = phy->config;
2291
2292 val = readl(base + UHSIC_PADS_CFG1);
2293 val &= ~UHSIC_RPU_STROBE;
2294 val |= UHSIC_RPD_STROBE;
2295 writel(val, base + UHSIC_PADS_CFG1);
2296
2297 val = readl(base + USB_SUSP_CTRL);
2298 val |= UHSIC_RESET;
2299 writel(val, base + USB_SUSP_CTRL);
2300 udelay(30);
2301
2302 if (uhsic_config->enable_gpio != -1) {
2303 gpio_set_value_cansleep(uhsic_config->enable_gpio, 0);
2304 /* keep hsic reset de-asserted for 1 ms */
2305 udelay(1000);
2306 }
2307 if (uhsic_config->post_phy_off && uhsic_config->post_phy_off())
2308 return -EAGAIN;
2309
2310 return 0;
2311}
2312
2313#ifdef CONFIG_USB_TEGRA_OTG
2314extern void tegra_otg_check_vbus_detection(void);
2315#endif
2316
2317static irqreturn_t usb_phy_vbus_irq_thr(int irq, void *pdata)
2318{
2319 struct tegra_usb_phy *phy = pdata;
2320
2321 if (phy->reg_vdd && !phy->regulator_on) {
2322 regulator_enable(phy->reg_vdd);
2323 phy->regulator_on = 1;
2324 /*
2325 * Optimal time to get the regulator turned on
2326 * before detecting vbus interrupt.
2327 */
2328 mdelay(15);
2329 }
2330
2331#ifdef CONFIG_USB_TEGRA_OTG
2332 tegra_otg_check_vbus_detection();
2333#endif
2334
2335 return IRQ_HANDLED;
2336}
2337
2338struct tegra_usb_phy *tegra_usb_phy_open(int instance, void __iomem *regs,
2339 void *config, enum tegra_usb_phy_mode phy_mode,
2340 enum tegra_usb_phy_type usb_phy_type)
2341{
2342 struct tegra_usb_phy *phy;
2343 struct tegra_ulpi_config *ulpi_config;
2344 unsigned long parent_rate;
2345 int i;
2346 int err;
2347#ifndef CONFIG_ARCH_TEGRA_2x_SOC
2348 struct tegra_ulpi_config *uhsic_config;
2349 int reset_gpio, enable_gpio;
2350#endif
2351
2352 phy = kzalloc(sizeof(struct tegra_usb_phy), GFP_KERNEL);
2353 if (!phy)
2354 return ERR_PTR(-ENOMEM);
2355
2356 phy->instance = instance;
2357 phy->regs = regs;
2358 phy->config = config;
2359 phy->mode = phy_mode;
2360 phy->usb_phy_type = usb_phy_type;
2361 phy->initialized = 0;
2362 phy->regulator_on = 0;
2363 phy->power_on = 0;
2364 phy->remote_wakeup = false;
2365 phy->hotplug = 0;
2366 phy->xcvr_setup_value = 0;
2367
2368 if (!phy->config) {
2369 if (phy->usb_phy_type == TEGRA_USB_PHY_TYPE_LINK_ULPI ||
2370 phy->usb_phy_type == TEGRA_USB_PHY_TYPE_NULL_ULPI) {
2371 pr_err("%s: ulpi phy configuration missing", __func__);
2372 err = -EINVAL;
2373 goto err0;
2374 } else {
2375 phy->config = &utmip_default[instance];
2376 }
2377 }
2378
2379 phy->pll_u = clk_get_sys(NULL, "pll_u");
2380 if (IS_ERR(phy->pll_u)) {
2381 pr_err("Can't get pll_u clock\n");
2382 err = PTR_ERR(phy->pll_u);
2383 goto err0;
2384 }
2385 clk_enable(phy->pll_u);
2386
2387 parent_rate = clk_get_rate(clk_get_parent(phy->pll_u));
2388 if (phy->usb_phy_type == TEGRA_USB_PHY_TYPE_HSIC) {
2389 for (i = 0; i < ARRAY_SIZE(tegra_uhsic_freq_table); i++) {
2390 if (tegra_uhsic_freq_table[i].freq == parent_rate) {
2391 phy->freq = &tegra_uhsic_freq_table[i];
2392 break;
2393 }
2394 }
2395 } else {
2396 for (i = 0; i < ARRAY_SIZE(tegra_freq_table); i++) {
2397 if (tegra_freq_table[i].freq == parent_rate) {
2398 phy->freq = &tegra_freq_table[i];
2399 break;
2400 }
2401 }
2402 }
2403 if (!phy->freq) {
2404 pr_err("invalid pll_u parent rate %ld\n", parent_rate);
2405 err = -EINVAL;
2406 goto err1;
2407 }
2408
2409 if (phy->usb_phy_type == TEGRA_USB_PHY_TYPE_UTMIP) {
2410 err = utmip_pad_open(phy);
2411 phy->xcvr_setup_value = tegra_phy_xcvr_setup_value(phy->config);
2412 if (err < 0)
2413 goto err1;
2414 } else if (phy->usb_phy_type == TEGRA_USB_PHY_TYPE_LINK_ULPI) {
2415 ulpi_config = config;
2416
2417 if (ulpi_config->clk) {
2418 phy->clk = clk_get_sys(NULL, ulpi_config->clk);
2419 if (IS_ERR(phy->clk)) {
2420 pr_err("%s: can't get ulpi clock\n", __func__);
2421 err = -ENXIO;
2422 goto err1;
2423 }
2424 } else {
2425 /* Some USB ULPI chips are not driven by Tegra clocks or PLL */
2426 phy->clk = NULL;
2427 }
2428 tegra_gpio_enable(ulpi_config->reset_gpio);
2429 gpio_request(ulpi_config->reset_gpio, "ulpi_phy_reset_b");
2430 gpio_direction_output(ulpi_config->reset_gpio, 0);
2431 phy->ulpi = otg_ulpi_create(&ulpi_viewport_access_ops, 0);
2432 phy->ulpi->io_priv = regs + ULPI_VIEWPORT;
2433 }
2434#ifndef CONFIG_ARCH_TEGRA_2x_SOC
2435 else if (phy->usb_phy_type == TEGRA_USB_PHY_TYPE_HSIC) {
2436 uhsic_config = config;
2437 enable_gpio = gpio_request(uhsic_config->enable_gpio,
2438 "uhsic_enable");
2439 reset_gpio = gpio_request(uhsic_config->reset_gpio,
2440 "uhsic_reset");
2441 /* hsic enable signal deasserted, hsic reset asserted */
2442 if (!enable_gpio)
2443 gpio_direction_output(uhsic_config->enable_gpio,
2444 0 /* deasserted */);
2445 if (!reset_gpio)
2446 gpio_direction_output(uhsic_config->reset_gpio,
2447 0 /* asserted */);
2448 if (!enable_gpio)
2449 tegra_gpio_enable(uhsic_config->enable_gpio);
2450 if (!reset_gpio)
2451 tegra_gpio_enable(uhsic_config->reset_gpio);
2452 /* keep hsic reset asserted for 1 ms */
2453 udelay(1000);
2454 /* enable (power on) hsic */
2455 if (!enable_gpio)
2456 gpio_set_value_cansleep(uhsic_config->enable_gpio, 1);
2457 udelay(1000);
2458 /* deassert reset */
2459 if (!reset_gpio)
2460 gpio_set_value_cansleep(uhsic_config->reset_gpio, 1);
2461 }
2462#endif
2463
2464 phy->reg_vdd = regulator_get(NULL, "avdd_usb");
2465 if (IS_ERR_OR_NULL(phy->reg_vdd)) {
2466 pr_err("couldn't get regulator avdd_usb: %ld \n",
2467 PTR_ERR(phy->reg_vdd));
2468 phy->reg_vdd = NULL;
2469 }
2470
2471 if (instance == 0 && usb_phy_data[0].vbus_irq) {
2472 err = request_threaded_irq(usb_phy_data[0].vbus_irq, NULL, usb_phy_vbus_irq_thr, IRQF_SHARED,
2473 "usb_phy_vbus", phy);
2474 if (err) {
2475 pr_err("Failed to register IRQ\n");
2476 goto err1;
2477 }
2478 }
2479
2480#ifndef CONFIG_ARCH_TEGRA_2x_SOC
2481 /* Power-up the VBUS detector for UTMIP PHY */
2482 if (phy->usb_phy_type == TEGRA_USB_PHY_TYPE_UTMIP) {
2483 writel(readl((IO_ADDRESS(TEGRA_PMC_BASE) + TEGRA_PMC_USB_AO)) &
2484 ~(TEGRA_PMC_USB_AO_VBUS_WAKEUP_PD_P0 | TEGRA_PMC_USB_AO_ID_PD_P0),
2485 (IO_ADDRESS(TEGRA_PMC_BASE) + TEGRA_PMC_USB_AO));
2486
2487 if (usb_phy_data[phy->instance].vbus_reg_supply) {
2488 phy->reg_vbus = regulator_get(NULL, usb_phy_data[phy->instance].vbus_reg_supply);
2489 if (WARN_ON(IS_ERR_OR_NULL(phy->reg_vbus))) {
2490 pr_err("couldn't get regulator vdd_vbus_usb: %ld, instance : %d\n",
2491 PTR_ERR(phy->reg_vbus), phy->instance);
2492 err = PTR_ERR(phy->reg_vbus);
2493 goto err1;
2494 }
2495 }
2496 }
2497 if (instance == 2) {
2498 writel(readl((IO_ADDRESS(TEGRA_PMC_BASE) + TEGRA_PMC_USB_AO)) &
2499 (TEGRA_PMC_USB_AO_PD_P2),
2500 (IO_ADDRESS(TEGRA_PMC_BASE) + TEGRA_PMC_USB_AO));
2501 }
2502#endif
2503 if (((instance == 2) || (instance == 0)) &&
2504 (phy->mode == TEGRA_USB_PHY_MODE_HOST)) {
2505 vbus_enable(phy);
2506 }
2507 return phy;
2508
2509err1:
2510 clk_disable(phy->pll_u);
2511 clk_put(phy->pll_u);
2512err0:
2513 kfree(phy);
2514 return ERR_PTR(err);
2515}
2516
2517int tegra_usb_phy_power_on(struct tegra_usb_phy *phy, bool is_dpd)
2518{
2519 int ret = 0;
2520
2521 const tegra_phy_fp power_on[] = {
2522 utmi_phy_power_on,
2523 ulpi_phy_power_on,
2524 null_phy_power_on,
2525 uhsic_phy_power_on,
2526 };
2527
2528 if (phy->power_on)
2529 return ret;
2530
2531 if ((phy->instance == 0) && usb_phy_data[0].vbus_irq &&
2532 (phy->mode == TEGRA_USB_PHY_MODE_DEVICE))
2533 is_dpd = true;
2534
2535 if (phy->reg_vdd && !phy->regulator_on) {
2536 regulator_enable(phy->reg_vdd);
2537 phy->regulator_on = 1;
2538 }
2539
2540 if (power_on[phy->usb_phy_type])
2541 ret = power_on[phy->usb_phy_type](phy, is_dpd);
2542
2543 phy->power_on = true;
2544 return ret;
2545}
2546
2547void tegra_usb_phy_power_off(struct tegra_usb_phy *phy, bool is_dpd)
2548{
2549 const tegra_phy_fp power_off[] = {
2550 utmi_phy_power_off,
2551 ulpi_phy_power_off,
2552 null_phy_power_off,
2553 uhsic_phy_power_off,
2554 };
2555
2556 if (!phy->power_on)
2557 return;
2558
2559 if ((phy->instance == 0) && usb_phy_data[0].vbus_irq &&
2560 (phy->mode == TEGRA_USB_PHY_MODE_DEVICE))
2561 is_dpd = true;
2562
2563 if (power_off[phy->usb_phy_type])
2564 power_off[phy->usb_phy_type](phy, is_dpd);
2565
2566 if (phy->reg_vdd && phy->regulator_on && is_dpd) {
2567#ifdef CONFIG_ARCH_TEGRA_2x_SOC
2568 if (tegra_get_revision() >= TEGRA_REVISION_A03)
2569#endif
2570 regulator_disable(phy->reg_vdd);
2571 phy->regulator_on = 0;
2572 }
2573 phy->power_on = false;
2574}
2575
2576void tegra_usb_phy_preresume(struct tegra_usb_phy *phy, bool remote_wakeup)
2577{
2578 const tegra_phy_fp preresume[] = {
2579 utmi_phy_preresume,
2580 NULL,
2581 NULL,
2582 uhsic_phy_preresume,
2583 };
2584
2585 if (preresume[phy->usb_phy_type])
2586 preresume[phy->usb_phy_type](phy, remote_wakeup);
2587}
2588
2589void tegra_usb_phy_postsuspend(struct tegra_usb_phy *phy, bool is_dpd)
2590
2591{
2592 const tegra_phy_fp postsuspend[] = {
2593 NULL,
2594 NULL,
2595 NULL,
2596 uhsic_phy_postsuspend,
2597 };
2598
2599 if (postsuspend[phy->usb_phy_type])
2600 postsuspend[phy->usb_phy_type](phy, is_dpd);
2601}
2602
2603void tegra_usb_phy_postresume(struct tegra_usb_phy *phy, bool is_dpd)
2604{
2605 const tegra_phy_fp postresume[] = {
2606 utmi_phy_postresume,
2607 NULL,
2608 NULL,
2609 uhsic_phy_postresume,
2610 };
2611
2612 if (postresume[phy->usb_phy_type])
2613 postresume[phy->usb_phy_type](phy, is_dpd);
2614}
2615
2616void tegra_ehci_pre_reset(struct tegra_usb_phy *phy, bool is_dpd)
2617{
2618 const tegra_phy_fp pre_reset[] = {
2619 NULL,
2620 NULL,
2621 null_phy_pre_usbcmd_reset,
2622 NULL,
2623 };
2624
2625 if (pre_reset[phy->usb_phy_type])
2626 pre_reset[phy->usb_phy_type](phy, is_dpd);
2627}
2628
2629void tegra_ehci_post_reset(struct tegra_usb_phy *phy, bool is_dpd)
2630{
2631 const tegra_phy_fp post_reset[] = {
2632 NULL,
2633 NULL,
2634 null_phy_post_usbcmd_reset,
2635 NULL,
2636 };
2637
2638 if (post_reset[phy->usb_phy_type])
2639 post_reset[phy->usb_phy_type](phy, is_dpd);
2640}
2641
2642void tegra_ehci_phy_restore_start(struct tegra_usb_phy *phy,
2643 enum tegra_usb_phy_port_speed port_speed)
2644{
2645 const tegra_phy_restore_start_fp phy_restore_start[] = {
2646 utmi_phy_restore_start,
2647 ulpi_phy_restore_start,
2648 null_phy_restore_start,
2649 NULL,
2650 };
2651
2652 if (phy_restore_start[phy->usb_phy_type])
2653 phy_restore_start[phy->usb_phy_type](phy, port_speed);
2654}
2655
2656void tegra_ehci_phy_restore_end(struct tegra_usb_phy *phy)
2657{
2658 const tegra_phy_restore_end_fp phy_restore_end[] = {
2659 utmi_phy_restore_end,
2660 ulpi_phy_restore_end,
2661 null_phy_restore_end,
2662 NULL,
2663 };
2664
2665 if (phy_restore_end[phy->usb_phy_type])
2666 phy_restore_end[phy->usb_phy_type](phy);
2667}
2668
2669void tegra_usb_phy_clk_disable(struct tegra_usb_phy *phy)
2670{
2671 if (phy->usb_phy_type == TEGRA_USB_PHY_TYPE_UTMIP)
2672 utmi_phy_clk_disable(phy);
2673}
2674
2675void tegra_usb_phy_clk_enable(struct tegra_usb_phy *phy)
2676{
2677 if (phy->usb_phy_type == TEGRA_USB_PHY_TYPE_UTMIP)
2678 utmi_phy_clk_enable(phy);
2679}
2680
2681void tegra_usb_phy_close(struct tegra_usb_phy *phy)
2682{
2683 if (phy->usb_phy_type == TEGRA_USB_PHY_TYPE_UTMIP) {
2684 utmip_pad_close(phy);
2685 utmip_phy_disable_pmc_bus_ctrl(phy);
2686 }
2687 else if (phy->usb_phy_type == TEGRA_USB_PHY_TYPE_LINK_ULPI && phy->clk)
2688 clk_put(phy->clk);
2689 if (phy->mode == TEGRA_USB_PHY_MODE_HOST) {
2690 vbus_disable(phy);
2691 }
2692 clk_disable(phy->pll_u);
2693 clk_put(phy->pll_u);
2694 if (phy->reg_vbus)
2695 regulator_put(phy->reg_vbus);
2696 if (phy->reg_vdd)
2697 regulator_put(phy->reg_vdd);
2698 if (phy->instance == 0 && usb_phy_data[0].vbus_irq)
2699 free_irq(usb_phy_data[0].vbus_irq, phy);
2700 kfree(phy);
2701}
2702
2703int tegra_usb_phy_bus_connect(struct tegra_usb_phy *phy)
2704{
2705 unsigned long val;
2706 void __iomem *base = phy->regs;
2707 struct tegra_uhsic_config *uhsic_config = phy->config;
2708
2709 if (phy->usb_phy_type == TEGRA_USB_PHY_TYPE_HSIC) {
2710#ifndef CONFIG_ARCH_TEGRA_2x_SOC
2711 val = readl(base + TEGRA_USB_USBMODE_REG_OFFSET);
2712 val |= TEGRA_USB_USBMODE_HOST;
2713 writel(val, base + TEGRA_USB_USBMODE_REG_OFFSET);
2714
2715 /* Change the USB controller PHY type to HSIC */
2716 val = readl(base + HOSTPC1_DEVLC);
2717 val &= ~HOSTPC1_DEVLC_PTS(HOSTPC1_DEVLC_PTS_MASK);
2718 val |= HOSTPC1_DEVLC_PTS(HOSTPC1_DEVLC_PTS_HSIC);
2719 val &= ~HOSTPC1_DEVLC_PSPD(HOSTPC1_DEVLC_PSPD_MASK);
2720 val |= HOSTPC1_DEVLC_PSPD(HOSTPC1_DEVLC_PSPD_HIGH_SPEED);
2721 writel(val, base + HOSTPC1_DEVLC);
2722#endif
2723 val = readl(base + UHSIC_MISC_CFG0);
2724 val |= UHSIC_DETECT_SHORT_CONNECT;
2725 writel(val, base + UHSIC_MISC_CFG0);
2726 udelay(1);
2727
2728 val = readl(base + UHSIC_MISC_CFG0);
2729 val |= UHSIC_FORCE_XCVR_MODE;
2730 writel(val, base + UHSIC_MISC_CFG0);
2731
2732 val = readl(base + UHSIC_PADS_CFG1);
2733 val &= ~UHSIC_RPD_STROBE;
2734#ifdef CONFIG_ARCH_TEGRA_2x_SOC
2735 val |= UHSIC_RPU_STROBE;
2736#endif
2737 writel(val, base + UHSIC_PADS_CFG1);
2738
2739 if (uhsic_config->usb_phy_ready &&
2740 uhsic_config->usb_phy_ready())
2741 return -EAGAIN;
2742
2743 /* connect detect on T30 requires extra wait */
2744 if (utmi_wait_register_timeout(base + UHSIC_STAT_CFG0,
2745 UHSIC_CONNECT_DETECT, UHSIC_CONNECT_DETECT,
2746 CONNECT_DETECT_TIMEOUT) < 0) {
2747 pr_err("%s: timeout waiting for hsic connect detect\n", __func__);
2748 return -ETIMEDOUT;
2749 }
2750
2751#ifdef CONFIG_ARCH_TEGRA_2x_SOC
2752 if (utmi_wait_register(base + USB_PORTSC1, USB_PORTSC1_LS(2), USB_PORTSC1_LS(2)) < 0) {
2753 pr_err("%s: timeout waiting for dplus state\n", __func__);
2754 return -ETIMEDOUT;
2755 }
2756#endif
2757 }
2758
2759 return 0;
2760}
2761
2762int tegra_usb_phy_bus_reset(struct tegra_usb_phy *phy)
2763{
2764 unsigned long val;
2765 void __iomem *base = phy->regs;
2766
2767 if (phy->usb_phy_type == TEGRA_USB_PHY_TYPE_HSIC) {
2768#ifndef CONFIG_ARCH_TEGRA_2x_SOC
2769 /* Change the USB controller PHY type to HSIC */
2770 val = readl(base + HOSTPC1_DEVLC);
2771 val &= ~HOSTPC1_DEVLC_PTS(HOSTPC1_DEVLC_PTS_MASK);
2772 val |= HOSTPC1_DEVLC_PTS(HOSTPC1_DEVLC_PTS_HSIC);
2773 val &= ~HOSTPC1_DEVLC_PSPD(HOSTPC1_DEVLC_PSPD_MASK);
2774 val |= HOSTPC1_DEVLC_PSPD(HOSTPC1_DEVLC_PSPD_HIGH_SPEED);
2775 writel(val, base + HOSTPC1_DEVLC);
2776 /* wait here, otherwise HOSTPC1_DEVLC_PSPD will timeout */
2777 mdelay(5);
2778#endif
2779 val = readl(base + USB_PORTSC1);
2780 val |= USB_PORTSC1_PTC(5);
2781 writel(val, base + USB_PORTSC1);
2782 udelay(2);
2783
2784 val = readl(base + USB_PORTSC1);
2785 val &= ~USB_PORTSC1_PTC(~0);
2786 writel(val, base + USB_PORTSC1);
2787 udelay(2);
2788
2789 if (utmi_wait_register(base + USB_PORTSC1, USB_PORTSC1_LS(0), 0) < 0) {
2790 pr_err("%s: timeout waiting for SE0\n", __func__);
2791 return -ETIMEDOUT;
2792 }
2793
2794 if (utmi_wait_register(base + USB_PORTSC1, USB_PORTSC1_CCS, USB_PORTSC1_CCS) < 0) {
2795 pr_err("%s: timeout waiting for connection status\n", __func__);
2796 return -ETIMEDOUT;
2797 }
2798
2799#if defined(CONFIG_ARCH_TEGRA_2x_SOC)
2800 if (utmi_wait_register(base + USB_PORTSC1, USB_PORTSC1_PSPD(2), USB_PORTSC1_PSPD(2)) < 0) {
2801 pr_err("%s: timeout waiting hsic high speed configuration\n", __func__);
2802 return -ETIMEDOUT;
2803 }
2804#elif defined(CONFIG_ARCH_TEGRA_3x_SOC)
2805 if (utmi_wait_register(base + HOSTPC1_DEVLC,
2806 HOSTPC1_DEVLC_PSPD(2),
2807 HOSTPC1_DEVLC_PSPD(2)) < 0) {
2808 pr_err("%s: timeout waiting hsic high speed configuration\n", __func__);
2809 return -ETIMEDOUT;
2810 }
2811#endif
2812 val = readl(base + USB_USBCMD);
2813 val &= ~USB_USBCMD_RS;
2814 writel(val, base + USB_USBCMD);
2815
2816 if (utmi_wait_register(base + USB_USBSTS, USB_USBSTS_HCH, USB_USBSTS_HCH) < 0) {
2817 pr_err("%s: timeout waiting for stopping the controller\n", __func__);
2818 return -ETIMEDOUT;
2819 }
2820
2821 val = readl(base + UHSIC_PADS_CFG1);
2822 val &= ~UHSIC_RPU_STROBE;
2823 val |= UHSIC_RPD_STROBE;
2824 writel(val, base + UHSIC_PADS_CFG1);
2825
2826 mdelay(50);
2827
2828 val = readl(base + UHSIC_PADS_CFG1);
2829 val &= ~UHSIC_RPD_STROBE;
2830 val |= UHSIC_RPU_STROBE;
2831 writel(val, base + UHSIC_PADS_CFG1);
2832
2833 val = readl(base + USB_USBCMD);
2834 val |= USB_USBCMD_RS;
2835 writel(val, base + USB_USBCMD);
2836
2837 val = readl(base + UHSIC_PADS_CFG1);
2838 val &= ~UHSIC_RPU_STROBE;
2839 writel(val, base + UHSIC_PADS_CFG1);
2840
2841 if (utmi_wait_register(base + USB_USBCMD, USB_USBCMD_RS, USB_USBCMD_RS) < 0) {
2842 pr_err("%s: timeout waiting for starting the controller\n", __func__);
2843 return -ETIMEDOUT;
2844 }
2845 }
2846
2847 return 0;
2848}
2849
2850int tegra_usb_phy_bus_idle(struct tegra_usb_phy *phy)
2851{
2852 unsigned long val;
2853 void __iomem *base = phy->regs;
2854 struct tegra_uhsic_config *uhsic_config = phy->config;
2855
2856 if (phy->usb_phy_type == TEGRA_USB_PHY_TYPE_HSIC) {
2857
2858#ifndef CONFIG_ARCH_TEGRA_2x_SOC
2859 val = readl(base + TEGRA_USB_USBMODE_REG_OFFSET);
2860 val |= TEGRA_USB_USBMODE_HOST;
2861 writel(val, base + TEGRA_USB_USBMODE_REG_OFFSET);
2862
2863 /* Change the USB controller PHY type to HSIC */
2864 val = readl(base + HOSTPC1_DEVLC);
2865 val &= ~HOSTPC1_DEVLC_PTS(HOSTPC1_DEVLC_PTS_MASK);
2866 val |= HOSTPC1_DEVLC_PTS(HOSTPC1_DEVLC_PTS_HSIC);
2867 val &= ~HOSTPC1_DEVLC_PSPD(HOSTPC1_DEVLC_PSPD_MASK);
2868 val |= HOSTPC1_DEVLC_PSPD(HOSTPC1_DEVLC_PSPD_HIGH_SPEED);
2869 writel(val, base + HOSTPC1_DEVLC);
2870#endif
2871 val = readl(base + UHSIC_MISC_CFG0);
2872 val |= UHSIC_DETECT_SHORT_CONNECT;
2873 writel(val, base + UHSIC_MISC_CFG0);
2874 udelay(1);
2875
2876 val = readl(base + UHSIC_MISC_CFG0);
2877 val |= UHSIC_FORCE_XCVR_MODE;
2878 writel(val, base + UHSIC_MISC_CFG0);
2879
2880 val = readl(base + UHSIC_PADS_CFG1);
2881 val &= ~UHSIC_RPD_STROBE;
2882 /* safe to enable RPU on STROBE at all times during idle */
2883 val |= UHSIC_RPU_STROBE;
2884 writel(val, base + UHSIC_PADS_CFG1);
2885
2886 val = readl(base + USB_USBCMD);
2887 val &= ~USB_USBCMD_RS;
2888 writel(val, base + USB_USBCMD);
2889
2890 if (uhsic_config->usb_phy_ready &&
2891 uhsic_config->usb_phy_ready())
2892 return -EAGAIN;
2893
2894 /* connect detect on T30 requires extra wait */
2895 if (utmi_wait_register_timeout(base + UHSIC_STAT_CFG0,
2896 UHSIC_CONNECT_DETECT, UHSIC_CONNECT_DETECT,
2897 CONNECT_DETECT_TIMEOUT) < 0) {
2898 pr_err("%s: timeout waiting for hsic connect detect\n",
2899 __func__);
2900 return -ETIMEDOUT;
2901 }
2902 }
2903 return 0;
2904}
2905
2906bool tegra_usb_phy_is_device_connected(struct tegra_usb_phy *phy)
2907{
2908 void __iomem *base = phy->regs;
2909
2910 if (phy->usb_phy_type == TEGRA_USB_PHY_TYPE_HSIC) {
2911 if (utmi_wait_register(base + UHSIC_STAT_CFG0,
2912 UHSIC_CONNECT_DETECT, UHSIC_CONNECT_DETECT) < 0) {
2913 pr_err("%s: no hsic connection\n", __func__);
2914 return false;
2915 }
2916#ifdef CONFIG_ARCH_TEGRA_2x_SOC
2917 if (utmi_wait_register(base + USB_PORTSC1, USB_PORTSC1_LS(2), USB_PORTSC1_LS(2)) < 0) {
2918 pr_err("%s: timeout waiting for dplus state\n", __func__);
2919 return false;
2920 }
2921#endif
2922 }
2923 return true;
2924}
2925
2926bool tegra_usb_phy_charger_detect(struct tegra_usb_phy *phy)
2927{
2928 unsigned long val;
2929 void __iomem *base = phy->regs;
2930 bool status;
2931
2932 if (phy->usb_phy_type != TEGRA_USB_PHY_TYPE_UTMIP)
2933 {
2934 /* Charger detection is not there for ULPI
2935 * return Charger not available */
2936 return false;
2937 }
2938
2939 /* Enable charger detection logic */
2940 val = readl(base + UTMIP_BAT_CHRG_CFG0);
2941 val |= UTMIP_OP_SRC_EN | UTMIP_ON_SINK_EN;
2942 writel(val, base + UTMIP_BAT_CHRG_CFG0);
2943
2944 /* Source should be on for 100 ms as per USB charging spec */
2945 msleep(TDP_SRC_ON_MS);
2946
2947 val = readl(base + USB_PHY_VBUS_WAKEUP_ID);
2948 /* If charger is not connected disable the interrupt */
2949 val &= ~VDAT_DET_INT_EN;
2950 val |= VDAT_DET_CHG_DET;
2951 writel(val,base + USB_PHY_VBUS_WAKEUP_ID);
2952
2953 val = readl(base + USB_PHY_VBUS_WAKEUP_ID);
2954 if (val & VDAT_DET_STS)
2955 status = true;
2956 else
2957 status = false;
2958
2959 /* Disable charger detection logic */
2960 val = readl(base + UTMIP_BAT_CHRG_CFG0);
2961 val &= ~(UTMIP_OP_SRC_EN | UTMIP_ON_SINK_EN);
2962 writel(val, base + UTMIP_BAT_CHRG_CFG0);
2963
2964 /* Delay of 40 ms before we pull the D+ as per battery charger spec */
2965 msleep(TDPSRC_CON_MS);
2966
2967 return status;
2968}
2969
2970int __init tegra_usb_phy_init(struct usb_phy_plat_data *pdata, int size)
2971{
2972 if (pdata) {
2973 int i;
2974
2975 for (i = 0; i < size; i++, pdata++) {
2976 usb_phy_data[pdata->instance].instance = pdata->instance;
2977 usb_phy_data[pdata->instance].vbus_irq = pdata->vbus_irq;
2978 usb_phy_data[pdata->instance].vbus_gpio = pdata->vbus_gpio;
2979 usb_phy_data[pdata->instance].vbus_reg_supply = pdata->vbus_reg_supply;
2980 }
2981 }
2982
2983 return 0;
2984}
2985
2986/* disable walk and wake events after resume from LP0 */
2987bool tegra_usb_phy_is_remotewake_detected(struct tegra_usb_phy *phy)
2988{
2989#ifndef CONFIG_ARCH_TEGRA_2x_SOC
2990 void __iomem *pmc_base = IO_ADDRESS(TEGRA_PMC_BASE);
2991 void __iomem *base = phy->regs;
2992 unsigned int inst = phy->instance;
2993 u32 val;
2994
2995 val = readl(base + UTMIP_PMC_WAKEUP0);
2996 if (val & EVENT_INT_ENB) {
2997 val = readl(pmc_base + UTMIP_UHSIC_STATUS);
2998 if (UTMIP_WAKE_ALARM(inst) & val) {
2999 val = readl(pmc_base + PMC_SLEEP_CFG);
3000 val &= ~UTMIP_WAKE_VAL(inst, 0x0);
3001 val |= UTMIP_WAKE_VAL(inst, WAKE_VAL_NONE);
3002 writel(val, pmc_base + PMC_SLEEP_CFG);
3003
3004 val = readl(pmc_base + PMC_TRIGGERS);
3005 val |= UTMIP_CLR_WAKE_ALARM(inst) |
3006 UTMIP_CLR_WALK_PTR(inst);
3007 writel(val, pmc_base + PMC_TRIGGERS);
3008
3009 val = readl(base + UTMIP_PMC_WAKEUP0);
3010 val &= ~EVENT_INT_ENB;
3011 writel(val, base + UTMIP_PMC_WAKEUP0);
3012 phy->remote_wakeup = true;
3013 return true;
3014 }
3015 }
3016#endif
3017 return false;
3018}
3019