diff options
author | Venu Byravarasu <vbyravarasu@nvidia.com> | 2012-09-05 09:20:23 -0400 |
---|---|---|
committer | Felipe Balbi <balbi@ti.com> | 2012-09-05 09:43:57 -0400 |
commit | 1ba8216f0bc02af6ba70d1108d60eb1b064395e4 (patch) | |
tree | 6b7c478d2e4f63ff837678c4a99a4a854801ec86 /drivers/usb/phy | |
parent | de4217d90fed1b1714a270ceb5d092f7314e8bda (diff) |
usb: move phy driver from mach-tegra to drivers/usb
As part of this patch:
1. Moved existing tegra phy driver to drivers/USB directory.
2. Added standard USB phy driver APIs to tegra phy driver.
Signed-off-by: Venu Byravarasu <vbyravarasu@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/phy')
-rw-r--r-- | drivers/usb/phy/Makefile | 1 | ||||
-rw-r--r-- | drivers/usb/phy/tegra_usb_phy.c | 839 |
2 files changed, 840 insertions, 0 deletions
diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile index cf38f08c818f..bb948fb8654c 100644 --- a/drivers/usb/phy/Makefile +++ b/drivers/usb/phy/Makefile | |||
@@ -6,3 +6,4 @@ ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG | |||
6 | 6 | ||
7 | obj-$(CONFIG_USB_ISP1301) += isp1301.o | 7 | obj-$(CONFIG_USB_ISP1301) += isp1301.o |
8 | obj-$(CONFIG_MV_U3D_PHY) += mv_u3d_phy.o | 8 | obj-$(CONFIG_MV_U3D_PHY) += mv_u3d_phy.o |
9 | obj-$(CONFIG_USB_EHCI_TEGRA) += tegra_usb_phy.o | ||
diff --git a/drivers/usb/phy/tegra_usb_phy.c b/drivers/usb/phy/tegra_usb_phy.c new file mode 100644 index 000000000000..4739903245e8 --- /dev/null +++ b/drivers/usb/phy/tegra_usb_phy.c | |||
@@ -0,0 +1,839 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2010 Google, Inc. | ||
3 | * | ||
4 | * Author: | ||
5 | * Erik Gilling <konkers@google.com> | ||
6 | * Benoit Goby <benoit@android.com> | ||
7 | * | ||
8 | * This software is licensed under the terms of the GNU General Public | ||
9 | * License version 2, as published by the Free Software Foundation, and | ||
10 | * may be copied, distributed, and modified under those terms. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | */ | ||
18 | |||
19 | #include <linux/resource.h> | ||
20 | #include <linux/delay.h> | ||
21 | #include <linux/slab.h> | ||
22 | #include <linux/err.h> | ||
23 | #include <linux/export.h> | ||
24 | #include <linux/platform_device.h> | ||
25 | #include <linux/io.h> | ||
26 | #include <linux/gpio.h> | ||
27 | #include <linux/of_gpio.h> | ||
28 | #include <linux/usb/otg.h> | ||
29 | #include <linux/usb/ulpi.h> | ||
30 | #include <asm/mach-types.h> | ||
31 | #include <mach/gpio-tegra.h> | ||
32 | #include <linux/usb/tegra_usb_phy.h> | ||
33 | #include <mach/iomap.h> | ||
34 | |||
35 | #define ULPI_VIEWPORT 0x170 | ||
36 | |||
37 | #define USB_PORTSC1 0x184 | ||
38 | #define USB_PORTSC1_PTS(x) (((x) & 0x3) << 30) | ||
39 | #define USB_PORTSC1_PSPD(x) (((x) & 0x3) << 26) | ||
40 | #define USB_PORTSC1_PHCD (1 << 23) | ||
41 | #define USB_PORTSC1_WKOC (1 << 22) | ||
42 | #define USB_PORTSC1_WKDS (1 << 21) | ||
43 | #define USB_PORTSC1_WKCN (1 << 20) | ||
44 | #define USB_PORTSC1_PTC(x) (((x) & 0xf) << 16) | ||
45 | #define USB_PORTSC1_PP (1 << 12) | ||
46 | #define USB_PORTSC1_SUSP (1 << 7) | ||
47 | #define USB_PORTSC1_PE (1 << 2) | ||
48 | #define USB_PORTSC1_CCS (1 << 0) | ||
49 | |||
50 | #define USB_SUSP_CTRL 0x400 | ||
51 | #define USB_WAKE_ON_CNNT_EN_DEV (1 << 3) | ||
52 | #define USB_WAKE_ON_DISCON_EN_DEV (1 << 4) | ||
53 | #define USB_SUSP_CLR (1 << 5) | ||
54 | #define USB_PHY_CLK_VALID (1 << 7) | ||
55 | #define UTMIP_RESET (1 << 11) | ||
56 | #define UHSIC_RESET (1 << 11) | ||
57 | #define UTMIP_PHY_ENABLE (1 << 12) | ||
58 | #define ULPI_PHY_ENABLE (1 << 13) | ||
59 | #define USB_SUSP_SET (1 << 14) | ||
60 | #define USB_WAKEUP_DEBOUNCE_COUNT(x) (((x) & 0x7) << 16) | ||
61 | |||
62 | #define USB1_LEGACY_CTRL 0x410 | ||
63 | #define USB1_NO_LEGACY_MODE (1 << 0) | ||
64 | #define USB1_VBUS_SENSE_CTL_MASK (3 << 1) | ||
65 | #define USB1_VBUS_SENSE_CTL_VBUS_WAKEUP (0 << 1) | ||
66 | #define USB1_VBUS_SENSE_CTL_AB_SESS_VLD_OR_VBUS_WAKEUP \ | ||
67 | (1 << 1) | ||
68 | #define USB1_VBUS_SENSE_CTL_AB_SESS_VLD (2 << 1) | ||
69 | #define USB1_VBUS_SENSE_CTL_A_SESS_VLD (3 << 1) | ||
70 | |||
71 | #define ULPI_TIMING_CTRL_0 0x424 | ||
72 | #define ULPI_OUTPUT_PINMUX_BYP (1 << 10) | ||
73 | #define ULPI_CLKOUT_PINMUX_BYP (1 << 11) | ||
74 | |||
75 | #define ULPI_TIMING_CTRL_1 0x428 | ||
76 | #define ULPI_DATA_TRIMMER_LOAD (1 << 0) | ||
77 | #define ULPI_DATA_TRIMMER_SEL(x) (((x) & 0x7) << 1) | ||
78 | #define ULPI_STPDIRNXT_TRIMMER_LOAD (1 << 16) | ||
79 | #define ULPI_STPDIRNXT_TRIMMER_SEL(x) (((x) & 0x7) << 17) | ||
80 | #define ULPI_DIR_TRIMMER_LOAD (1 << 24) | ||
81 | #define ULPI_DIR_TRIMMER_SEL(x) (((x) & 0x7) << 25) | ||
82 | |||
83 | #define UTMIP_PLL_CFG1 0x804 | ||
84 | #define UTMIP_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0) | ||
85 | #define UTMIP_PLLU_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 27) | ||
86 | |||
87 | #define UTMIP_XCVR_CFG0 0x808 | ||
88 | #define UTMIP_XCVR_SETUP(x) (((x) & 0xf) << 0) | ||
89 | #define UTMIP_XCVR_LSRSLEW(x) (((x) & 0x3) << 8) | ||
90 | #define UTMIP_XCVR_LSFSLEW(x) (((x) & 0x3) << 10) | ||
91 | #define UTMIP_FORCE_PD_POWERDOWN (1 << 14) | ||
92 | #define UTMIP_FORCE_PD2_POWERDOWN (1 << 16) | ||
93 | #define UTMIP_FORCE_PDZI_POWERDOWN (1 << 18) | ||
94 | #define UTMIP_XCVR_HSSLEW_MSB(x) (((x) & 0x7f) << 25) | ||
95 | |||
96 | #define UTMIP_BIAS_CFG0 0x80c | ||
97 | #define UTMIP_OTGPD (1 << 11) | ||
98 | #define UTMIP_BIASPD (1 << 10) | ||
99 | |||
100 | #define UTMIP_HSRX_CFG0 0x810 | ||
101 | #define UTMIP_ELASTIC_LIMIT(x) (((x) & 0x1f) << 10) | ||
102 | #define UTMIP_IDLE_WAIT(x) (((x) & 0x1f) << 15) | ||
103 | |||
104 | #define UTMIP_HSRX_CFG1 0x814 | ||
105 | #define UTMIP_HS_SYNC_START_DLY(x) (((x) & 0x1f) << 1) | ||
106 | |||
107 | #define UTMIP_TX_CFG0 0x820 | ||
108 | #define UTMIP_FS_PREABMLE_J (1 << 19) | ||
109 | #define UTMIP_HS_DISCON_DISABLE (1 << 8) | ||
110 | |||
111 | #define UTMIP_MISC_CFG0 0x824 | ||
112 | #define UTMIP_DPDM_OBSERVE (1 << 26) | ||
113 | #define UTMIP_DPDM_OBSERVE_SEL(x) (((x) & 0xf) << 27) | ||
114 | #define UTMIP_DPDM_OBSERVE_SEL_FS_J UTMIP_DPDM_OBSERVE_SEL(0xf) | ||
115 | #define UTMIP_DPDM_OBSERVE_SEL_FS_K UTMIP_DPDM_OBSERVE_SEL(0xe) | ||
116 | #define UTMIP_DPDM_OBSERVE_SEL_FS_SE1 UTMIP_DPDM_OBSERVE_SEL(0xd) | ||
117 | #define UTMIP_DPDM_OBSERVE_SEL_FS_SE0 UTMIP_DPDM_OBSERVE_SEL(0xc) | ||
118 | #define UTMIP_SUSPEND_EXIT_ON_EDGE (1 << 22) | ||
119 | |||
120 | #define UTMIP_MISC_CFG1 0x828 | ||
121 | #define UTMIP_PLL_ACTIVE_DLY_COUNT(x) (((x) & 0x1f) << 18) | ||
122 | #define UTMIP_PLLU_STABLE_COUNT(x) (((x) & 0xfff) << 6) | ||
123 | |||
124 | #define UTMIP_DEBOUNCE_CFG0 0x82c | ||
125 | #define UTMIP_BIAS_DEBOUNCE_A(x) (((x) & 0xffff) << 0) | ||
126 | |||
127 | #define UTMIP_BAT_CHRG_CFG0 0x830 | ||
128 | #define UTMIP_PD_CHRG (1 << 0) | ||
129 | |||
130 | #define UTMIP_SPARE_CFG0 0x834 | ||
131 | #define FUSE_SETUP_SEL (1 << 3) | ||
132 | |||
133 | #define UTMIP_XCVR_CFG1 0x838 | ||
134 | #define UTMIP_FORCE_PDDISC_POWERDOWN (1 << 0) | ||
135 | #define UTMIP_FORCE_PDCHRP_POWERDOWN (1 << 2) | ||
136 | #define UTMIP_FORCE_PDDR_POWERDOWN (1 << 4) | ||
137 | #define UTMIP_XCVR_TERM_RANGE_ADJ(x) (((x) & 0xf) << 18) | ||
138 | |||
139 | #define UTMIP_BIAS_CFG1 0x83c | ||
140 | #define UTMIP_BIAS_PDTRK_COUNT(x) (((x) & 0x1f) << 3) | ||
141 | |||
142 | static DEFINE_SPINLOCK(utmip_pad_lock); | ||
143 | static int utmip_pad_count; | ||
144 | |||
145 | struct tegra_xtal_freq { | ||
146 | int freq; | ||
147 | u8 enable_delay; | ||
148 | u8 stable_count; | ||
149 | u8 active_delay; | ||
150 | u8 xtal_freq_count; | ||
151 | u16 debounce; | ||
152 | }; | ||
153 | |||
154 | static const struct tegra_xtal_freq tegra_freq_table[] = { | ||
155 | { | ||
156 | .freq = 12000000, | ||
157 | .enable_delay = 0x02, | ||
158 | .stable_count = 0x2F, | ||
159 | .active_delay = 0x04, | ||
160 | .xtal_freq_count = 0x76, | ||
161 | .debounce = 0x7530, | ||
162 | }, | ||
163 | { | ||
164 | .freq = 13000000, | ||
165 | .enable_delay = 0x02, | ||
166 | .stable_count = 0x33, | ||
167 | .active_delay = 0x05, | ||
168 | .xtal_freq_count = 0x7F, | ||
169 | .debounce = 0x7EF4, | ||
170 | }, | ||
171 | { | ||
172 | .freq = 19200000, | ||
173 | .enable_delay = 0x03, | ||
174 | .stable_count = 0x4B, | ||
175 | .active_delay = 0x06, | ||
176 | .xtal_freq_count = 0xBB, | ||
177 | .debounce = 0xBB80, | ||
178 | }, | ||
179 | { | ||
180 | .freq = 26000000, | ||
181 | .enable_delay = 0x04, | ||
182 | .stable_count = 0x66, | ||
183 | .active_delay = 0x09, | ||
184 | .xtal_freq_count = 0xFE, | ||
185 | .debounce = 0xFDE8, | ||
186 | }, | ||
187 | }; | ||
188 | |||
189 | static struct tegra_utmip_config utmip_default[] = { | ||
190 | [0] = { | ||
191 | .hssync_start_delay = 9, | ||
192 | .idle_wait_delay = 17, | ||
193 | .elastic_limit = 16, | ||
194 | .term_range_adj = 6, | ||
195 | .xcvr_setup = 9, | ||
196 | .xcvr_lsfslew = 1, | ||
197 | .xcvr_lsrslew = 1, | ||
198 | }, | ||
199 | [2] = { | ||
200 | .hssync_start_delay = 9, | ||
201 | .idle_wait_delay = 17, | ||
202 | .elastic_limit = 16, | ||
203 | .term_range_adj = 6, | ||
204 | .xcvr_setup = 9, | ||
205 | .xcvr_lsfslew = 2, | ||
206 | .xcvr_lsrslew = 2, | ||
207 | }, | ||
208 | }; | ||
209 | |||
210 | static inline bool phy_is_ulpi(struct tegra_usb_phy *phy) | ||
211 | { | ||
212 | return (phy->instance == 1); | ||
213 | } | ||
214 | |||
215 | static int utmip_pad_open(struct tegra_usb_phy *phy) | ||
216 | { | ||
217 | phy->pad_clk = clk_get_sys("utmip-pad", NULL); | ||
218 | if (IS_ERR(phy->pad_clk)) { | ||
219 | pr_err("%s: can't get utmip pad clock\n", __func__); | ||
220 | return PTR_ERR(phy->pad_clk); | ||
221 | } | ||
222 | |||
223 | if (phy->instance == 0) { | ||
224 | phy->pad_regs = phy->regs; | ||
225 | } else { | ||
226 | phy->pad_regs = ioremap(TEGRA_USB_BASE, TEGRA_USB_SIZE); | ||
227 | if (!phy->pad_regs) { | ||
228 | pr_err("%s: can't remap usb registers\n", __func__); | ||
229 | clk_put(phy->pad_clk); | ||
230 | return -ENOMEM; | ||
231 | } | ||
232 | } | ||
233 | return 0; | ||
234 | } | ||
235 | |||
236 | static void utmip_pad_close(struct tegra_usb_phy *phy) | ||
237 | { | ||
238 | if (phy->instance != 0) | ||
239 | iounmap(phy->pad_regs); | ||
240 | clk_put(phy->pad_clk); | ||
241 | } | ||
242 | |||
243 | static void utmip_pad_power_on(struct tegra_usb_phy *phy) | ||
244 | { | ||
245 | unsigned long val, flags; | ||
246 | void __iomem *base = phy->pad_regs; | ||
247 | |||
248 | clk_prepare_enable(phy->pad_clk); | ||
249 | |||
250 | spin_lock_irqsave(&utmip_pad_lock, flags); | ||
251 | |||
252 | if (utmip_pad_count++ == 0) { | ||
253 | val = readl(base + UTMIP_BIAS_CFG0); | ||
254 | val &= ~(UTMIP_OTGPD | UTMIP_BIASPD); | ||
255 | writel(val, base + UTMIP_BIAS_CFG0); | ||
256 | } | ||
257 | |||
258 | spin_unlock_irqrestore(&utmip_pad_lock, flags); | ||
259 | |||
260 | clk_disable_unprepare(phy->pad_clk); | ||
261 | } | ||
262 | |||
263 | static int utmip_pad_power_off(struct tegra_usb_phy *phy) | ||
264 | { | ||
265 | unsigned long val, flags; | ||
266 | void __iomem *base = phy->pad_regs; | ||
267 | |||
268 | if (!utmip_pad_count) { | ||
269 | pr_err("%s: utmip pad already powered off\n", __func__); | ||
270 | return -EINVAL; | ||
271 | } | ||
272 | |||
273 | clk_prepare_enable(phy->pad_clk); | ||
274 | |||
275 | spin_lock_irqsave(&utmip_pad_lock, flags); | ||
276 | |||
277 | if (--utmip_pad_count == 0) { | ||
278 | val = readl(base + UTMIP_BIAS_CFG0); | ||
279 | val |= UTMIP_OTGPD | UTMIP_BIASPD; | ||
280 | writel(val, base + UTMIP_BIAS_CFG0); | ||
281 | } | ||
282 | |||
283 | spin_unlock_irqrestore(&utmip_pad_lock, flags); | ||
284 | |||
285 | clk_disable_unprepare(phy->pad_clk); | ||
286 | |||
287 | return 0; | ||
288 | } | ||
289 | |||
290 | static int utmi_wait_register(void __iomem *reg, u32 mask, u32 result) | ||
291 | { | ||
292 | unsigned long timeout = 2000; | ||
293 | do { | ||
294 | if ((readl(reg) & mask) == result) | ||
295 | return 0; | ||
296 | udelay(1); | ||
297 | timeout--; | ||
298 | } while (timeout); | ||
299 | return -1; | ||
300 | } | ||
301 | |||
302 | static void utmi_phy_clk_disable(struct tegra_usb_phy *phy) | ||
303 | { | ||
304 | unsigned long val; | ||
305 | void __iomem *base = phy->regs; | ||
306 | |||
307 | if (phy->instance == 0) { | ||
308 | val = readl(base + USB_SUSP_CTRL); | ||
309 | val |= USB_SUSP_SET; | ||
310 | writel(val, base + USB_SUSP_CTRL); | ||
311 | |||
312 | udelay(10); | ||
313 | |||
314 | val = readl(base + USB_SUSP_CTRL); | ||
315 | val &= ~USB_SUSP_SET; | ||
316 | writel(val, base + USB_SUSP_CTRL); | ||
317 | } | ||
318 | |||
319 | if (phy->instance == 2) { | ||
320 | val = readl(base + USB_PORTSC1); | ||
321 | val |= USB_PORTSC1_PHCD; | ||
322 | writel(val, base + USB_PORTSC1); | ||
323 | } | ||
324 | |||
325 | if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, 0) < 0) | ||
326 | pr_err("%s: timeout waiting for phy to stabilize\n", __func__); | ||
327 | } | ||
328 | |||
329 | static void utmi_phy_clk_enable(struct tegra_usb_phy *phy) | ||
330 | { | ||
331 | unsigned long val; | ||
332 | void __iomem *base = phy->regs; | ||
333 | |||
334 | if (phy->instance == 0) { | ||
335 | val = readl(base + USB_SUSP_CTRL); | ||
336 | val |= USB_SUSP_CLR; | ||
337 | writel(val, base + USB_SUSP_CTRL); | ||
338 | |||
339 | udelay(10); | ||
340 | |||
341 | val = readl(base + USB_SUSP_CTRL); | ||
342 | val &= ~USB_SUSP_CLR; | ||
343 | writel(val, base + USB_SUSP_CTRL); | ||
344 | } | ||
345 | |||
346 | if (phy->instance == 2) { | ||
347 | val = readl(base + USB_PORTSC1); | ||
348 | val &= ~USB_PORTSC1_PHCD; | ||
349 | writel(val, base + USB_PORTSC1); | ||
350 | } | ||
351 | |||
352 | if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, | ||
353 | USB_PHY_CLK_VALID)) | ||
354 | pr_err("%s: timeout waiting for phy to stabilize\n", __func__); | ||
355 | } | ||
356 | |||
357 | static int utmi_phy_power_on(struct tegra_usb_phy *phy) | ||
358 | { | ||
359 | unsigned long val; | ||
360 | void __iomem *base = phy->regs; | ||
361 | struct tegra_utmip_config *config = phy->config; | ||
362 | |||
363 | val = readl(base + USB_SUSP_CTRL); | ||
364 | val |= UTMIP_RESET; | ||
365 | writel(val, base + USB_SUSP_CTRL); | ||
366 | |||
367 | if (phy->instance == 0) { | ||
368 | val = readl(base + USB1_LEGACY_CTRL); | ||
369 | val |= USB1_NO_LEGACY_MODE; | ||
370 | writel(val, base + USB1_LEGACY_CTRL); | ||
371 | } | ||
372 | |||
373 | val = readl(base + UTMIP_TX_CFG0); | ||
374 | val &= ~UTMIP_FS_PREABMLE_J; | ||
375 | writel(val, base + UTMIP_TX_CFG0); | ||
376 | |||
377 | val = readl(base + UTMIP_HSRX_CFG0); | ||
378 | val &= ~(UTMIP_IDLE_WAIT(~0) | UTMIP_ELASTIC_LIMIT(~0)); | ||
379 | val |= UTMIP_IDLE_WAIT(config->idle_wait_delay); | ||
380 | val |= UTMIP_ELASTIC_LIMIT(config->elastic_limit); | ||
381 | writel(val, base + UTMIP_HSRX_CFG0); | ||
382 | |||
383 | val = readl(base + UTMIP_HSRX_CFG1); | ||
384 | val &= ~UTMIP_HS_SYNC_START_DLY(~0); | ||
385 | val |= UTMIP_HS_SYNC_START_DLY(config->hssync_start_delay); | ||
386 | writel(val, base + UTMIP_HSRX_CFG1); | ||
387 | |||
388 | val = readl(base + UTMIP_DEBOUNCE_CFG0); | ||
389 | val &= ~UTMIP_BIAS_DEBOUNCE_A(~0); | ||
390 | val |= UTMIP_BIAS_DEBOUNCE_A(phy->freq->debounce); | ||
391 | writel(val, base + UTMIP_DEBOUNCE_CFG0); | ||
392 | |||
393 | val = readl(base + UTMIP_MISC_CFG0); | ||
394 | val &= ~UTMIP_SUSPEND_EXIT_ON_EDGE; | ||
395 | writel(val, base + UTMIP_MISC_CFG0); | ||
396 | |||
397 | val = readl(base + UTMIP_MISC_CFG1); | ||
398 | val &= ~(UTMIP_PLL_ACTIVE_DLY_COUNT(~0) | UTMIP_PLLU_STABLE_COUNT(~0)); | ||
399 | val |= UTMIP_PLL_ACTIVE_DLY_COUNT(phy->freq->active_delay) | | ||
400 | UTMIP_PLLU_STABLE_COUNT(phy->freq->stable_count); | ||
401 | writel(val, base + UTMIP_MISC_CFG1); | ||
402 | |||
403 | val = readl(base + UTMIP_PLL_CFG1); | ||
404 | val &= ~(UTMIP_XTAL_FREQ_COUNT(~0) | UTMIP_PLLU_ENABLE_DLY_COUNT(~0)); | ||
405 | val |= UTMIP_XTAL_FREQ_COUNT(phy->freq->xtal_freq_count) | | ||
406 | UTMIP_PLLU_ENABLE_DLY_COUNT(phy->freq->enable_delay); | ||
407 | writel(val, base + UTMIP_PLL_CFG1); | ||
408 | |||
409 | if (phy->mode == TEGRA_USB_PHY_MODE_DEVICE) { | ||
410 | val = readl(base + USB_SUSP_CTRL); | ||
411 | val &= ~(USB_WAKE_ON_CNNT_EN_DEV | USB_WAKE_ON_DISCON_EN_DEV); | ||
412 | writel(val, base + USB_SUSP_CTRL); | ||
413 | } | ||
414 | |||
415 | utmip_pad_power_on(phy); | ||
416 | |||
417 | val = readl(base + UTMIP_XCVR_CFG0); | ||
418 | val &= ~(UTMIP_FORCE_PD_POWERDOWN | UTMIP_FORCE_PD2_POWERDOWN | | ||
419 | UTMIP_FORCE_PDZI_POWERDOWN | UTMIP_XCVR_SETUP(~0) | | ||
420 | UTMIP_XCVR_LSFSLEW(~0) | UTMIP_XCVR_LSRSLEW(~0) | | ||
421 | UTMIP_XCVR_HSSLEW_MSB(~0)); | ||
422 | val |= UTMIP_XCVR_SETUP(config->xcvr_setup); | ||
423 | val |= UTMIP_XCVR_LSFSLEW(config->xcvr_lsfslew); | ||
424 | val |= UTMIP_XCVR_LSRSLEW(config->xcvr_lsrslew); | ||
425 | writel(val, base + UTMIP_XCVR_CFG0); | ||
426 | |||
427 | val = readl(base + UTMIP_XCVR_CFG1); | ||
428 | val &= ~(UTMIP_FORCE_PDDISC_POWERDOWN | UTMIP_FORCE_PDCHRP_POWERDOWN | | ||
429 | UTMIP_FORCE_PDDR_POWERDOWN | UTMIP_XCVR_TERM_RANGE_ADJ(~0)); | ||
430 | val |= UTMIP_XCVR_TERM_RANGE_ADJ(config->term_range_adj); | ||
431 | writel(val, base + UTMIP_XCVR_CFG1); | ||
432 | |||
433 | val = readl(base + UTMIP_BAT_CHRG_CFG0); | ||
434 | val &= ~UTMIP_PD_CHRG; | ||
435 | writel(val, base + UTMIP_BAT_CHRG_CFG0); | ||
436 | |||
437 | val = readl(base + UTMIP_BIAS_CFG1); | ||
438 | val &= ~UTMIP_BIAS_PDTRK_COUNT(~0); | ||
439 | val |= UTMIP_BIAS_PDTRK_COUNT(0x5); | ||
440 | writel(val, base + UTMIP_BIAS_CFG1); | ||
441 | |||
442 | if (phy->instance == 0) { | ||
443 | val = readl(base + UTMIP_SPARE_CFG0); | ||
444 | if (phy->mode == TEGRA_USB_PHY_MODE_DEVICE) | ||
445 | val &= ~FUSE_SETUP_SEL; | ||
446 | else | ||
447 | val |= FUSE_SETUP_SEL; | ||
448 | writel(val, base + UTMIP_SPARE_CFG0); | ||
449 | } | ||
450 | |||
451 | if (phy->instance == 2) { | ||
452 | val = readl(base + USB_SUSP_CTRL); | ||
453 | val |= UTMIP_PHY_ENABLE; | ||
454 | writel(val, base + USB_SUSP_CTRL); | ||
455 | } | ||
456 | |||
457 | val = readl(base + USB_SUSP_CTRL); | ||
458 | val &= ~UTMIP_RESET; | ||
459 | writel(val, base + USB_SUSP_CTRL); | ||
460 | |||
461 | if (phy->instance == 0) { | ||
462 | val = readl(base + USB1_LEGACY_CTRL); | ||
463 | val &= ~USB1_VBUS_SENSE_CTL_MASK; | ||
464 | val |= USB1_VBUS_SENSE_CTL_A_SESS_VLD; | ||
465 | writel(val, base + USB1_LEGACY_CTRL); | ||
466 | |||
467 | val = readl(base + USB_SUSP_CTRL); | ||
468 | val &= ~USB_SUSP_SET; | ||
469 | writel(val, base + USB_SUSP_CTRL); | ||
470 | } | ||
471 | |||
472 | utmi_phy_clk_enable(phy); | ||
473 | |||
474 | if (phy->instance == 2) { | ||
475 | val = readl(base + USB_PORTSC1); | ||
476 | val &= ~USB_PORTSC1_PTS(~0); | ||
477 | writel(val, base + USB_PORTSC1); | ||
478 | } | ||
479 | |||
480 | return 0; | ||
481 | } | ||
482 | |||
483 | static int utmi_phy_power_off(struct tegra_usb_phy *phy) | ||
484 | { | ||
485 | unsigned long val; | ||
486 | void __iomem *base = phy->regs; | ||
487 | |||
488 | utmi_phy_clk_disable(phy); | ||
489 | |||
490 | if (phy->mode == TEGRA_USB_PHY_MODE_DEVICE) { | ||
491 | val = readl(base + USB_SUSP_CTRL); | ||
492 | val &= ~USB_WAKEUP_DEBOUNCE_COUNT(~0); | ||
493 | val |= USB_WAKE_ON_CNNT_EN_DEV | USB_WAKEUP_DEBOUNCE_COUNT(5); | ||
494 | writel(val, base + USB_SUSP_CTRL); | ||
495 | } | ||
496 | |||
497 | val = readl(base + USB_SUSP_CTRL); | ||
498 | val |= UTMIP_RESET; | ||
499 | writel(val, base + USB_SUSP_CTRL); | ||
500 | |||
501 | val = readl(base + UTMIP_BAT_CHRG_CFG0); | ||
502 | val |= UTMIP_PD_CHRG; | ||
503 | writel(val, base + UTMIP_BAT_CHRG_CFG0); | ||
504 | |||
505 | val = readl(base + UTMIP_XCVR_CFG0); | ||
506 | val |= UTMIP_FORCE_PD_POWERDOWN | UTMIP_FORCE_PD2_POWERDOWN | | ||
507 | UTMIP_FORCE_PDZI_POWERDOWN; | ||
508 | writel(val, base + UTMIP_XCVR_CFG0); | ||
509 | |||
510 | val = readl(base + UTMIP_XCVR_CFG1); | ||
511 | val |= UTMIP_FORCE_PDDISC_POWERDOWN | UTMIP_FORCE_PDCHRP_POWERDOWN | | ||
512 | UTMIP_FORCE_PDDR_POWERDOWN; | ||
513 | writel(val, base + UTMIP_XCVR_CFG1); | ||
514 | |||
515 | return utmip_pad_power_off(phy); | ||
516 | } | ||
517 | |||
518 | static void utmi_phy_preresume(struct tegra_usb_phy *phy) | ||
519 | { | ||
520 | unsigned long val; | ||
521 | void __iomem *base = phy->regs; | ||
522 | |||
523 | val = readl(base + UTMIP_TX_CFG0); | ||
524 | val |= UTMIP_HS_DISCON_DISABLE; | ||
525 | writel(val, base + UTMIP_TX_CFG0); | ||
526 | } | ||
527 | |||
528 | static void utmi_phy_postresume(struct tegra_usb_phy *phy) | ||
529 | { | ||
530 | unsigned long val; | ||
531 | void __iomem *base = phy->regs; | ||
532 | |||
533 | val = readl(base + UTMIP_TX_CFG0); | ||
534 | val &= ~UTMIP_HS_DISCON_DISABLE; | ||
535 | writel(val, base + UTMIP_TX_CFG0); | ||
536 | } | ||
537 | |||
538 | static void utmi_phy_restore_start(struct tegra_usb_phy *phy, | ||
539 | enum tegra_usb_phy_port_speed port_speed) | ||
540 | { | ||
541 | unsigned long val; | ||
542 | void __iomem *base = phy->regs; | ||
543 | |||
544 | val = readl(base + UTMIP_MISC_CFG0); | ||
545 | val &= ~UTMIP_DPDM_OBSERVE_SEL(~0); | ||
546 | if (port_speed == TEGRA_USB_PHY_PORT_SPEED_LOW) | ||
547 | val |= UTMIP_DPDM_OBSERVE_SEL_FS_K; | ||
548 | else | ||
549 | val |= UTMIP_DPDM_OBSERVE_SEL_FS_J; | ||
550 | writel(val, base + UTMIP_MISC_CFG0); | ||
551 | udelay(1); | ||
552 | |||
553 | val = readl(base + UTMIP_MISC_CFG0); | ||
554 | val |= UTMIP_DPDM_OBSERVE; | ||
555 | writel(val, base + UTMIP_MISC_CFG0); | ||
556 | udelay(10); | ||
557 | } | ||
558 | |||
559 | static void utmi_phy_restore_end(struct tegra_usb_phy *phy) | ||
560 | { | ||
561 | unsigned long val; | ||
562 | void __iomem *base = phy->regs; | ||
563 | |||
564 | val = readl(base + UTMIP_MISC_CFG0); | ||
565 | val &= ~UTMIP_DPDM_OBSERVE; | ||
566 | writel(val, base + UTMIP_MISC_CFG0); | ||
567 | udelay(10); | ||
568 | } | ||
569 | |||
570 | static int ulpi_phy_power_on(struct tegra_usb_phy *phy) | ||
571 | { | ||
572 | int ret; | ||
573 | unsigned long val; | ||
574 | void __iomem *base = phy->regs; | ||
575 | struct tegra_ulpi_config *config = phy->config; | ||
576 | |||
577 | gpio_direction_output(config->reset_gpio, 0); | ||
578 | msleep(5); | ||
579 | gpio_direction_output(config->reset_gpio, 1); | ||
580 | |||
581 | clk_prepare_enable(phy->clk); | ||
582 | msleep(1); | ||
583 | |||
584 | val = readl(base + USB_SUSP_CTRL); | ||
585 | val |= UHSIC_RESET; | ||
586 | writel(val, base + USB_SUSP_CTRL); | ||
587 | |||
588 | val = readl(base + ULPI_TIMING_CTRL_0); | ||
589 | val |= ULPI_OUTPUT_PINMUX_BYP | ULPI_CLKOUT_PINMUX_BYP; | ||
590 | writel(val, base + ULPI_TIMING_CTRL_0); | ||
591 | |||
592 | val = readl(base + USB_SUSP_CTRL); | ||
593 | val |= ULPI_PHY_ENABLE; | ||
594 | writel(val, base + USB_SUSP_CTRL); | ||
595 | |||
596 | val = 0; | ||
597 | writel(val, base + ULPI_TIMING_CTRL_1); | ||
598 | |||
599 | val |= ULPI_DATA_TRIMMER_SEL(4); | ||
600 | val |= ULPI_STPDIRNXT_TRIMMER_SEL(4); | ||
601 | val |= ULPI_DIR_TRIMMER_SEL(4); | ||
602 | writel(val, base + ULPI_TIMING_CTRL_1); | ||
603 | udelay(10); | ||
604 | |||
605 | val |= ULPI_DATA_TRIMMER_LOAD; | ||
606 | val |= ULPI_STPDIRNXT_TRIMMER_LOAD; | ||
607 | val |= ULPI_DIR_TRIMMER_LOAD; | ||
608 | writel(val, base + ULPI_TIMING_CTRL_1); | ||
609 | |||
610 | /* Fix VbusInvalid due to floating VBUS */ | ||
611 | ret = usb_phy_io_write(phy->ulpi, 0x40, 0x08); | ||
612 | if (ret) { | ||
613 | pr_err("%s: ulpi write failed\n", __func__); | ||
614 | return ret; | ||
615 | } | ||
616 | |||
617 | ret = usb_phy_io_write(phy->ulpi, 0x80, 0x0B); | ||
618 | if (ret) { | ||
619 | pr_err("%s: ulpi write failed\n", __func__); | ||
620 | return ret; | ||
621 | } | ||
622 | |||
623 | val = readl(base + USB_PORTSC1); | ||
624 | val |= USB_PORTSC1_WKOC | USB_PORTSC1_WKDS | USB_PORTSC1_WKCN; | ||
625 | writel(val, base + USB_PORTSC1); | ||
626 | |||
627 | val = readl(base + USB_SUSP_CTRL); | ||
628 | val |= USB_SUSP_CLR; | ||
629 | writel(val, base + USB_SUSP_CTRL); | ||
630 | udelay(100); | ||
631 | |||
632 | val = readl(base + USB_SUSP_CTRL); | ||
633 | val &= ~USB_SUSP_CLR; | ||
634 | writel(val, base + USB_SUSP_CTRL); | ||
635 | |||
636 | return 0; | ||
637 | } | ||
638 | |||
639 | static int ulpi_phy_power_off(struct tegra_usb_phy *phy) | ||
640 | { | ||
641 | unsigned long val; | ||
642 | void __iomem *base = phy->regs; | ||
643 | struct tegra_ulpi_config *config = phy->config; | ||
644 | |||
645 | /* Clear WKCN/WKDS/WKOC wake-on events that can cause the USB | ||
646 | * Controller to immediately bring the ULPI PHY out of low power | ||
647 | */ | ||
648 | val = readl(base + USB_PORTSC1); | ||
649 | val &= ~(USB_PORTSC1_WKOC | USB_PORTSC1_WKDS | USB_PORTSC1_WKCN); | ||
650 | writel(val, base + USB_PORTSC1); | ||
651 | |||
652 | clk_disable(phy->clk); | ||
653 | return gpio_direction_output(config->reset_gpio, 0); | ||
654 | } | ||
655 | |||
656 | static int tegra_phy_init(struct usb_phy *x) | ||
657 | { | ||
658 | struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy); | ||
659 | struct tegra_ulpi_config *ulpi_config; | ||
660 | int err; | ||
661 | |||
662 | if (phy_is_ulpi(phy)) { | ||
663 | ulpi_config = phy->config; | ||
664 | phy->clk = clk_get_sys(NULL, ulpi_config->clk); | ||
665 | if (IS_ERR(phy->clk)) { | ||
666 | pr_err("%s: can't get ulpi clock\n", __func__); | ||
667 | err = -ENXIO; | ||
668 | goto err1; | ||
669 | } | ||
670 | if (!gpio_is_valid(ulpi_config->reset_gpio)) | ||
671 | ulpi_config->reset_gpio = | ||
672 | of_get_named_gpio(phy->dev->of_node, | ||
673 | "nvidia,phy-reset-gpio", 0); | ||
674 | if (!gpio_is_valid(ulpi_config->reset_gpio)) { | ||
675 | pr_err("%s: invalid reset gpio: %d\n", __func__, | ||
676 | ulpi_config->reset_gpio); | ||
677 | err = -EINVAL; | ||
678 | goto err1; | ||
679 | } | ||
680 | gpio_request(ulpi_config->reset_gpio, "ulpi_phy_reset_b"); | ||
681 | gpio_direction_output(ulpi_config->reset_gpio, 0); | ||
682 | phy->ulpi = otg_ulpi_create(&ulpi_viewport_access_ops, 0); | ||
683 | phy->ulpi->io_priv = phy->regs + ULPI_VIEWPORT; | ||
684 | } else { | ||
685 | err = utmip_pad_open(phy); | ||
686 | if (err < 0) | ||
687 | goto err1; | ||
688 | } | ||
689 | return 0; | ||
690 | err1: | ||
691 | clk_disable_unprepare(phy->pll_u); | ||
692 | clk_put(phy->pll_u); | ||
693 | return err; | ||
694 | } | ||
695 | |||
696 | static void tegra_usb_phy_close(struct usb_phy *x) | ||
697 | { | ||
698 | struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy); | ||
699 | |||
700 | if (phy_is_ulpi(phy)) | ||
701 | clk_put(phy->clk); | ||
702 | else | ||
703 | utmip_pad_close(phy); | ||
704 | clk_disable_unprepare(phy->pll_u); | ||
705 | clk_put(phy->pll_u); | ||
706 | kfree(phy); | ||
707 | } | ||
708 | |||
709 | static int tegra_usb_phy_power_on(struct tegra_usb_phy *phy) | ||
710 | { | ||
711 | if (phy_is_ulpi(phy)) | ||
712 | return ulpi_phy_power_on(phy); | ||
713 | else | ||
714 | return utmi_phy_power_on(phy); | ||
715 | } | ||
716 | |||
717 | static int tegra_usb_phy_power_off(struct tegra_usb_phy *phy) | ||
718 | { | ||
719 | if (phy_is_ulpi(phy)) | ||
720 | return ulpi_phy_power_off(phy); | ||
721 | else | ||
722 | return utmi_phy_power_off(phy); | ||
723 | } | ||
724 | |||
725 | static int tegra_usb_phy_suspend(struct usb_phy *x, int suspend) | ||
726 | { | ||
727 | struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy); | ||
728 | if (suspend) | ||
729 | return tegra_usb_phy_power_off(phy); | ||
730 | else | ||
731 | return tegra_usb_phy_power_on(phy); | ||
732 | } | ||
733 | |||
734 | struct tegra_usb_phy *tegra_usb_phy_open(struct device *dev, int instance, | ||
735 | void __iomem *regs, void *config, enum tegra_usb_phy_mode phy_mode) | ||
736 | { | ||
737 | struct tegra_usb_phy *phy; | ||
738 | unsigned long parent_rate; | ||
739 | int i; | ||
740 | int err; | ||
741 | |||
742 | phy = kmalloc(sizeof(struct tegra_usb_phy), GFP_KERNEL); | ||
743 | if (!phy) | ||
744 | return ERR_PTR(-ENOMEM); | ||
745 | |||
746 | phy->instance = instance; | ||
747 | phy->regs = regs; | ||
748 | phy->config = config; | ||
749 | phy->mode = phy_mode; | ||
750 | phy->dev = dev; | ||
751 | |||
752 | if (!phy->config) { | ||
753 | if (phy_is_ulpi(phy)) { | ||
754 | pr_err("%s: ulpi phy configuration missing", __func__); | ||
755 | err = -EINVAL; | ||
756 | goto err0; | ||
757 | } else { | ||
758 | phy->config = &utmip_default[instance]; | ||
759 | } | ||
760 | } | ||
761 | |||
762 | phy->pll_u = clk_get_sys(NULL, "pll_u"); | ||
763 | if (IS_ERR(phy->pll_u)) { | ||
764 | pr_err("Can't get pll_u clock\n"); | ||
765 | err = PTR_ERR(phy->pll_u); | ||
766 | goto err0; | ||
767 | } | ||
768 | clk_prepare_enable(phy->pll_u); | ||
769 | |||
770 | parent_rate = clk_get_rate(clk_get_parent(phy->pll_u)); | ||
771 | for (i = 0; i < ARRAY_SIZE(tegra_freq_table); i++) { | ||
772 | if (tegra_freq_table[i].freq == parent_rate) { | ||
773 | phy->freq = &tegra_freq_table[i]; | ||
774 | break; | ||
775 | } | ||
776 | } | ||
777 | if (!phy->freq) { | ||
778 | pr_err("invalid pll_u parent rate %ld\n", parent_rate); | ||
779 | err = -EINVAL; | ||
780 | goto err1; | ||
781 | } | ||
782 | |||
783 | phy->u_phy.init = tegra_phy_init; | ||
784 | phy->u_phy.shutdown = tegra_usb_phy_close; | ||
785 | phy->u_phy.set_suspend = tegra_usb_phy_suspend; | ||
786 | |||
787 | return phy; | ||
788 | |||
789 | err1: | ||
790 | clk_disable_unprepare(phy->pll_u); | ||
791 | clk_put(phy->pll_u); | ||
792 | err0: | ||
793 | kfree(phy); | ||
794 | return ERR_PTR(err); | ||
795 | } | ||
796 | EXPORT_SYMBOL_GPL(tegra_usb_phy_open); | ||
797 | |||
798 | void tegra_usb_phy_preresume(struct tegra_usb_phy *phy) | ||
799 | { | ||
800 | if (!phy_is_ulpi(phy)) | ||
801 | utmi_phy_preresume(phy); | ||
802 | } | ||
803 | EXPORT_SYMBOL_GPL(tegra_usb_phy_preresume); | ||
804 | |||
805 | void tegra_usb_phy_postresume(struct tegra_usb_phy *phy) | ||
806 | { | ||
807 | if (!phy_is_ulpi(phy)) | ||
808 | utmi_phy_postresume(phy); | ||
809 | } | ||
810 | EXPORT_SYMBOL_GPL(tegra_usb_phy_postresume); | ||
811 | |||
812 | void tegra_ehci_phy_restore_start(struct tegra_usb_phy *phy, | ||
813 | enum tegra_usb_phy_port_speed port_speed) | ||
814 | { | ||
815 | if (!phy_is_ulpi(phy)) | ||
816 | utmi_phy_restore_start(phy, port_speed); | ||
817 | } | ||
818 | EXPORT_SYMBOL_GPL(tegra_ehci_phy_restore_start); | ||
819 | |||
820 | void tegra_ehci_phy_restore_end(struct tegra_usb_phy *phy) | ||
821 | { | ||
822 | if (!phy_is_ulpi(phy)) | ||
823 | utmi_phy_restore_end(phy); | ||
824 | } | ||
825 | EXPORT_SYMBOL_GPL(tegra_ehci_phy_restore_end); | ||
826 | |||
827 | void tegra_usb_phy_clk_disable(struct tegra_usb_phy *phy) | ||
828 | { | ||
829 | if (!phy_is_ulpi(phy)) | ||
830 | utmi_phy_clk_disable(phy); | ||
831 | } | ||
832 | EXPORT_SYMBOL_GPL(tegra_usb_phy_clk_disable); | ||
833 | |||
834 | void tegra_usb_phy_clk_enable(struct tegra_usb_phy *phy) | ||
835 | { | ||
836 | if (!phy_is_ulpi(phy)) | ||
837 | utmi_phy_clk_enable(phy); | ||
838 | } | ||
839 | EXPORT_SYMBOL_GPL(tegra_usb_phy_clk_enable); | ||