blob: 441c306c050f1be1ee6fafe95734de58f07d5079 [file] [log] [blame]
Benoit Goby91525d02011-03-09 16:28:55 -08001/*
Benoit Goby91525d02011-03-09 16:28:55 -08002 * Copyright (C) 2010 Google, Inc.
Venu Byravarasu2d22b422013-05-16 19:43:02 +05303 * Copyright (C) 2013 NVIDIA Corporation
Benoit Goby91525d02011-03-09 16:28:55 -08004 *
5 * Author:
6 * Erik Gilling <konkers@google.com>
7 * Benoit Goby <benoit@android.com>
Venu Byravarasu2d22b422013-05-16 19:43:02 +05308 * Venu Byravarasu <vbyravarasu@nvidia.com>
Benoit Goby91525d02011-03-09 16:28:55 -08009 *
10 * This software is licensed under the terms of the GNU General Public
11 * License version 2, as published by the Free Software Foundation, and
12 * may be copied, distributed, and modified under those terms.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 */
20
21#include <linux/resource.h>
22#include <linux/delay.h>
23#include <linux/slab.h>
24#include <linux/err.h>
Arnd Bergmann4265cbf2012-03-02 15:58:42 -050025#include <linux/export.h>
Stephen Warren587376a2013-06-13 11:24:08 -060026#include <linux/module.h>
Benoit Goby91525d02011-03-09 16:28:55 -080027#include <linux/platform_device.h>
28#include <linux/io.h>
29#include <linux/gpio.h>
Venu Byravarasu3a55c6a2013-01-16 03:30:20 +000030#include <linux/of.h>
Stephen Warrenaa607eb2012-04-12 15:46:49 -060031#include <linux/of_gpio.h>
Benoit Goby91525d02011-03-09 16:28:55 -080032#include <linux/usb/otg.h>
33#include <linux/usb/ulpi.h>
34#include <asm/mach-types.h>
Stephen Warren91a687d2013-06-13 11:24:11 -060035#include <linux/usb/ehci_def.h>
Venu Byravarasu1ba82162012-09-05 18:50:23 +053036#include <linux/usb/tegra_usb_phy.h>
Mikko Perttunenf5b8c8b2013-07-17 10:37:49 +030037#include <linux/regulator/consumer.h>
Benoit Goby91525d02011-03-09 16:28:55 -080038
39#define ULPI_VIEWPORT 0x170
40
Stephen Warren91a687d2013-06-13 11:24:11 -060041/* PORTSC registers */
42#define TEGRA_USB_PORTSC1 0x184
43#define TEGRA_USB_PORTSC1_PTS(x) (((x) & 0x3) << 30)
44#define TEGRA_USB_PORTSC1_PHCD (1 << 23)
45
46/* Bits of PORTSC1, which will get cleared by writing 1 into them */
47#define TEGRA_PORTSC1_RWC_BITS (PORT_CSC | PORT_PEC | PORT_OCC)
48
Benoit Goby91525d02011-03-09 16:28:55 -080049#define USB_SUSP_CTRL 0x400
50#define USB_WAKE_ON_CNNT_EN_DEV (1 << 3)
51#define USB_WAKE_ON_DISCON_EN_DEV (1 << 4)
52#define USB_SUSP_CLR (1 << 5)
53#define USB_PHY_CLK_VALID (1 << 7)
54#define UTMIP_RESET (1 << 11)
55#define UHSIC_RESET (1 << 11)
56#define UTMIP_PHY_ENABLE (1 << 12)
57#define ULPI_PHY_ENABLE (1 << 13)
58#define USB_SUSP_SET (1 << 14)
59#define USB_WAKEUP_DEBOUNCE_COUNT(x) (((x) & 0x7) << 16)
60
61#define USB1_LEGACY_CTRL 0x410
62#define USB1_NO_LEGACY_MODE (1 << 0)
63#define USB1_VBUS_SENSE_CTL_MASK (3 << 1)
64#define USB1_VBUS_SENSE_CTL_VBUS_WAKEUP (0 << 1)
65#define USB1_VBUS_SENSE_CTL_AB_SESS_VLD_OR_VBUS_WAKEUP \
66 (1 << 1)
67#define USB1_VBUS_SENSE_CTL_AB_SESS_VLD (2 << 1)
68#define USB1_VBUS_SENSE_CTL_A_SESS_VLD (3 << 1)
69
70#define ULPI_TIMING_CTRL_0 0x424
71#define ULPI_OUTPUT_PINMUX_BYP (1 << 10)
72#define ULPI_CLKOUT_PINMUX_BYP (1 << 11)
73
74#define ULPI_TIMING_CTRL_1 0x428
75#define ULPI_DATA_TRIMMER_LOAD (1 << 0)
76#define ULPI_DATA_TRIMMER_SEL(x) (((x) & 0x7) << 1)
77#define ULPI_STPDIRNXT_TRIMMER_LOAD (1 << 16)
78#define ULPI_STPDIRNXT_TRIMMER_SEL(x) (((x) & 0x7) << 17)
79#define ULPI_DIR_TRIMMER_LOAD (1 << 24)
80#define ULPI_DIR_TRIMMER_SEL(x) (((x) & 0x7) << 25)
81
82#define UTMIP_PLL_CFG1 0x804
83#define UTMIP_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0)
84#define UTMIP_PLLU_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 27)
85
86#define UTMIP_XCVR_CFG0 0x808
87#define UTMIP_XCVR_SETUP(x) (((x) & 0xf) << 0)
88#define UTMIP_XCVR_LSRSLEW(x) (((x) & 0x3) << 8)
89#define UTMIP_XCVR_LSFSLEW(x) (((x) & 0x3) << 10)
90#define UTMIP_FORCE_PD_POWERDOWN (1 << 14)
91#define UTMIP_FORCE_PD2_POWERDOWN (1 << 16)
92#define UTMIP_FORCE_PDZI_POWERDOWN (1 << 18)
93#define UTMIP_XCVR_HSSLEW_MSB(x) (((x) & 0x7f) << 25)
94
95#define UTMIP_BIAS_CFG0 0x80c
96#define UTMIP_OTGPD (1 << 11)
97#define UTMIP_BIASPD (1 << 10)
98
99#define UTMIP_HSRX_CFG0 0x810
100#define UTMIP_ELASTIC_LIMIT(x) (((x) & 0x1f) << 10)
101#define UTMIP_IDLE_WAIT(x) (((x) & 0x1f) << 15)
102
103#define UTMIP_HSRX_CFG1 0x814
104#define UTMIP_HS_SYNC_START_DLY(x) (((x) & 0x1f) << 1)
105
106#define UTMIP_TX_CFG0 0x820
107#define UTMIP_FS_PREABMLE_J (1 << 19)
108#define UTMIP_HS_DISCON_DISABLE (1 << 8)
109
110#define UTMIP_MISC_CFG0 0x824
111#define UTMIP_DPDM_OBSERVE (1 << 26)
112#define UTMIP_DPDM_OBSERVE_SEL(x) (((x) & 0xf) << 27)
113#define UTMIP_DPDM_OBSERVE_SEL_FS_J UTMIP_DPDM_OBSERVE_SEL(0xf)
114#define UTMIP_DPDM_OBSERVE_SEL_FS_K UTMIP_DPDM_OBSERVE_SEL(0xe)
115#define UTMIP_DPDM_OBSERVE_SEL_FS_SE1 UTMIP_DPDM_OBSERVE_SEL(0xd)
116#define UTMIP_DPDM_OBSERVE_SEL_FS_SE0 UTMIP_DPDM_OBSERVE_SEL(0xc)
117#define UTMIP_SUSPEND_EXIT_ON_EDGE (1 << 22)
118
119#define UTMIP_MISC_CFG1 0x828
120#define UTMIP_PLL_ACTIVE_DLY_COUNT(x) (((x) & 0x1f) << 18)
121#define UTMIP_PLLU_STABLE_COUNT(x) (((x) & 0xfff) << 6)
122
123#define UTMIP_DEBOUNCE_CFG0 0x82c
124#define UTMIP_BIAS_DEBOUNCE_A(x) (((x) & 0xffff) << 0)
125
126#define UTMIP_BAT_CHRG_CFG0 0x830
127#define UTMIP_PD_CHRG (1 << 0)
128
129#define UTMIP_SPARE_CFG0 0x834
130#define FUSE_SETUP_SEL (1 << 3)
131
132#define UTMIP_XCVR_CFG1 0x838
133#define UTMIP_FORCE_PDDISC_POWERDOWN (1 << 0)
134#define UTMIP_FORCE_PDCHRP_POWERDOWN (1 << 2)
135#define UTMIP_FORCE_PDDR_POWERDOWN (1 << 4)
136#define UTMIP_XCVR_TERM_RANGE_ADJ(x) (((x) & 0xf) << 18)
137
138#define UTMIP_BIAS_CFG1 0x83c
139#define UTMIP_BIAS_PDTRK_COUNT(x) (((x) & 0x1f) << 3)
140
141static DEFINE_SPINLOCK(utmip_pad_lock);
142static int utmip_pad_count;
143
144struct tegra_xtal_freq {
145 int freq;
146 u8 enable_delay;
147 u8 stable_count;
148 u8 active_delay;
149 u8 xtal_freq_count;
150 u16 debounce;
151};
152
153static const struct tegra_xtal_freq tegra_freq_table[] = {
154 {
155 .freq = 12000000,
156 .enable_delay = 0x02,
157 .stable_count = 0x2F,
158 .active_delay = 0x04,
159 .xtal_freq_count = 0x76,
160 .debounce = 0x7530,
161 },
162 {
163 .freq = 13000000,
164 .enable_delay = 0x02,
165 .stable_count = 0x33,
166 .active_delay = 0x05,
167 .xtal_freq_count = 0x7F,
168 .debounce = 0x7EF4,
169 },
170 {
171 .freq = 19200000,
172 .enable_delay = 0x03,
173 .stable_count = 0x4B,
174 .active_delay = 0x06,
175 .xtal_freq_count = 0xBB,
176 .debounce = 0xBB80,
177 },
178 {
179 .freq = 26000000,
180 .enable_delay = 0x04,
181 .stable_count = 0x66,
182 .active_delay = 0x09,
183 .xtal_freq_count = 0xFE,
184 .debounce = 0xFDE8,
185 },
186};
187
Stephen Warren91a687d2013-06-13 11:24:11 -0600188static void set_pts(struct tegra_usb_phy *phy, u8 pts_val)
189{
190 void __iomem *base = phy->regs;
191 unsigned long val;
192
193 val = readl(base + TEGRA_USB_PORTSC1) & ~TEGRA_PORTSC1_RWC_BITS;
194 val &= ~TEGRA_USB_PORTSC1_PTS(3);
195 val |= TEGRA_USB_PORTSC1_PTS(pts_val & 3);
196 writel(val, base + TEGRA_USB_PORTSC1);
197}
198
199static void set_phcd(struct tegra_usb_phy *phy, bool enable)
200{
201 void __iomem *base = phy->regs;
202 unsigned long val;
203
204 val = readl(base + TEGRA_USB_PORTSC1) & ~TEGRA_PORTSC1_RWC_BITS;
205 if (enable)
206 val |= TEGRA_USB_PORTSC1_PHCD;
207 else
208 val &= ~TEGRA_USB_PORTSC1_PHCD;
209 writel(val, base + TEGRA_USB_PORTSC1);
210}
211
Benoit Goby91525d02011-03-09 16:28:55 -0800212static int utmip_pad_open(struct tegra_usb_phy *phy)
213{
Tuomas Tynkkynen185d0fd2013-07-25 21:38:01 +0300214 phy->pad_clk = devm_clk_get(phy->u_phy.dev, "utmi-pads");
Benoit Goby91525d02011-03-09 16:28:55 -0800215 if (IS_ERR(phy->pad_clk)) {
216 pr_err("%s: can't get utmip pad clock\n", __func__);
217 return PTR_ERR(phy->pad_clk);
218 }
219
Benoit Goby91525d02011-03-09 16:28:55 -0800220 return 0;
221}
222
Benoit Goby91525d02011-03-09 16:28:55 -0800223static void utmip_pad_power_on(struct tegra_usb_phy *phy)
224{
225 unsigned long val, flags;
226 void __iomem *base = phy->pad_regs;
227
Prashant Gaikwad6a5278d2012-06-05 09:59:35 +0530228 clk_prepare_enable(phy->pad_clk);
Benoit Goby91525d02011-03-09 16:28:55 -0800229
230 spin_lock_irqsave(&utmip_pad_lock, flags);
231
232 if (utmip_pad_count++ == 0) {
233 val = readl(base + UTMIP_BIAS_CFG0);
234 val &= ~(UTMIP_OTGPD | UTMIP_BIASPD);
235 writel(val, base + UTMIP_BIAS_CFG0);
236 }
237
238 spin_unlock_irqrestore(&utmip_pad_lock, flags);
239
Prashant Gaikwad6a5278d2012-06-05 09:59:35 +0530240 clk_disable_unprepare(phy->pad_clk);
Benoit Goby91525d02011-03-09 16:28:55 -0800241}
242
243static int utmip_pad_power_off(struct tegra_usb_phy *phy)
244{
245 unsigned long val, flags;
246 void __iomem *base = phy->pad_regs;
247
248 if (!utmip_pad_count) {
249 pr_err("%s: utmip pad already powered off\n", __func__);
250 return -EINVAL;
251 }
252
Prashant Gaikwad6a5278d2012-06-05 09:59:35 +0530253 clk_prepare_enable(phy->pad_clk);
Benoit Goby91525d02011-03-09 16:28:55 -0800254
255 spin_lock_irqsave(&utmip_pad_lock, flags);
256
257 if (--utmip_pad_count == 0) {
258 val = readl(base + UTMIP_BIAS_CFG0);
259 val |= UTMIP_OTGPD | UTMIP_BIASPD;
260 writel(val, base + UTMIP_BIAS_CFG0);
261 }
262
263 spin_unlock_irqrestore(&utmip_pad_lock, flags);
264
Prashant Gaikwad6a5278d2012-06-05 09:59:35 +0530265 clk_disable_unprepare(phy->pad_clk);
Benoit Goby91525d02011-03-09 16:28:55 -0800266
267 return 0;
268}
269
270static int utmi_wait_register(void __iomem *reg, u32 mask, u32 result)
271{
272 unsigned long timeout = 2000;
273 do {
274 if ((readl(reg) & mask) == result)
275 return 0;
276 udelay(1);
277 timeout--;
278 } while (timeout);
279 return -1;
280}
281
282static void utmi_phy_clk_disable(struct tegra_usb_phy *phy)
283{
284 unsigned long val;
285 void __iomem *base = phy->regs;
286
Venu Byravarasu3a55c6a2013-01-16 03:30:20 +0000287 if (phy->is_legacy_phy) {
Benoit Goby91525d02011-03-09 16:28:55 -0800288 val = readl(base + USB_SUSP_CTRL);
289 val |= USB_SUSP_SET;
290 writel(val, base + USB_SUSP_CTRL);
291
292 udelay(10);
293
294 val = readl(base + USB_SUSP_CTRL);
295 val &= ~USB_SUSP_SET;
296 writel(val, base + USB_SUSP_CTRL);
Venu Byravarasubbdabdb2013-01-17 20:15:37 +0000297 } else
Stephen Warren91a687d2013-06-13 11:24:11 -0600298 set_phcd(phy, true);
Benoit Goby91525d02011-03-09 16:28:55 -0800299
300 if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, 0) < 0)
301 pr_err("%s: timeout waiting for phy to stabilize\n", __func__);
302}
303
304static void utmi_phy_clk_enable(struct tegra_usb_phy *phy)
305{
306 unsigned long val;
307 void __iomem *base = phy->regs;
308
Venu Byravarasu3a55c6a2013-01-16 03:30:20 +0000309 if (phy->is_legacy_phy) {
Benoit Goby91525d02011-03-09 16:28:55 -0800310 val = readl(base + USB_SUSP_CTRL);
311 val |= USB_SUSP_CLR;
312 writel(val, base + USB_SUSP_CTRL);
313
314 udelay(10);
315
316 val = readl(base + USB_SUSP_CTRL);
317 val &= ~USB_SUSP_CLR;
318 writel(val, base + USB_SUSP_CTRL);
Venu Byravarasubbdabdb2013-01-17 20:15:37 +0000319 } else
Stephen Warren91a687d2013-06-13 11:24:11 -0600320 set_phcd(phy, false);
Benoit Goby91525d02011-03-09 16:28:55 -0800321
322 if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID,
323 USB_PHY_CLK_VALID))
324 pr_err("%s: timeout waiting for phy to stabilize\n", __func__);
325}
326
327static int utmi_phy_power_on(struct tegra_usb_phy *phy)
328{
329 unsigned long val;
330 void __iomem *base = phy->regs;
331 struct tegra_utmip_config *config = phy->config;
332
333 val = readl(base + USB_SUSP_CTRL);
334 val |= UTMIP_RESET;
335 writel(val, base + USB_SUSP_CTRL);
336
Venu Byravarasu3a55c6a2013-01-16 03:30:20 +0000337 if (phy->is_legacy_phy) {
Benoit Goby91525d02011-03-09 16:28:55 -0800338 val = readl(base + USB1_LEGACY_CTRL);
339 val |= USB1_NO_LEGACY_MODE;
340 writel(val, base + USB1_LEGACY_CTRL);
341 }
342
343 val = readl(base + UTMIP_TX_CFG0);
344 val &= ~UTMIP_FS_PREABMLE_J;
345 writel(val, base + UTMIP_TX_CFG0);
346
347 val = readl(base + UTMIP_HSRX_CFG0);
348 val &= ~(UTMIP_IDLE_WAIT(~0) | UTMIP_ELASTIC_LIMIT(~0));
349 val |= UTMIP_IDLE_WAIT(config->idle_wait_delay);
350 val |= UTMIP_ELASTIC_LIMIT(config->elastic_limit);
351 writel(val, base + UTMIP_HSRX_CFG0);
352
353 val = readl(base + UTMIP_HSRX_CFG1);
354 val &= ~UTMIP_HS_SYNC_START_DLY(~0);
355 val |= UTMIP_HS_SYNC_START_DLY(config->hssync_start_delay);
356 writel(val, base + UTMIP_HSRX_CFG1);
357
358 val = readl(base + UTMIP_DEBOUNCE_CFG0);
359 val &= ~UTMIP_BIAS_DEBOUNCE_A(~0);
360 val |= UTMIP_BIAS_DEBOUNCE_A(phy->freq->debounce);
361 writel(val, base + UTMIP_DEBOUNCE_CFG0);
362
363 val = readl(base + UTMIP_MISC_CFG0);
364 val &= ~UTMIP_SUSPEND_EXIT_ON_EDGE;
365 writel(val, base + UTMIP_MISC_CFG0);
366
367 val = readl(base + UTMIP_MISC_CFG1);
368 val &= ~(UTMIP_PLL_ACTIVE_DLY_COUNT(~0) | UTMIP_PLLU_STABLE_COUNT(~0));
369 val |= UTMIP_PLL_ACTIVE_DLY_COUNT(phy->freq->active_delay) |
370 UTMIP_PLLU_STABLE_COUNT(phy->freq->stable_count);
371 writel(val, base + UTMIP_MISC_CFG1);
372
373 val = readl(base + UTMIP_PLL_CFG1);
374 val &= ~(UTMIP_XTAL_FREQ_COUNT(~0) | UTMIP_PLLU_ENABLE_DLY_COUNT(~0));
375 val |= UTMIP_XTAL_FREQ_COUNT(phy->freq->xtal_freq_count) |
376 UTMIP_PLLU_ENABLE_DLY_COUNT(phy->freq->enable_delay);
377 writel(val, base + UTMIP_PLL_CFG1);
378
379 if (phy->mode == TEGRA_USB_PHY_MODE_DEVICE) {
380 val = readl(base + USB_SUSP_CTRL);
381 val &= ~(USB_WAKE_ON_CNNT_EN_DEV | USB_WAKE_ON_DISCON_EN_DEV);
382 writel(val, base + USB_SUSP_CTRL);
383 }
384
385 utmip_pad_power_on(phy);
386
387 val = readl(base + UTMIP_XCVR_CFG0);
388 val &= ~(UTMIP_FORCE_PD_POWERDOWN | UTMIP_FORCE_PD2_POWERDOWN |
389 UTMIP_FORCE_PDZI_POWERDOWN | UTMIP_XCVR_SETUP(~0) |
390 UTMIP_XCVR_LSFSLEW(~0) | UTMIP_XCVR_LSRSLEW(~0) |
391 UTMIP_XCVR_HSSLEW_MSB(~0));
392 val |= UTMIP_XCVR_SETUP(config->xcvr_setup);
393 val |= UTMIP_XCVR_LSFSLEW(config->xcvr_lsfslew);
394 val |= UTMIP_XCVR_LSRSLEW(config->xcvr_lsrslew);
395 writel(val, base + UTMIP_XCVR_CFG0);
396
397 val = readl(base + UTMIP_XCVR_CFG1);
398 val &= ~(UTMIP_FORCE_PDDISC_POWERDOWN | UTMIP_FORCE_PDCHRP_POWERDOWN |
399 UTMIP_FORCE_PDDR_POWERDOWN | UTMIP_XCVR_TERM_RANGE_ADJ(~0));
400 val |= UTMIP_XCVR_TERM_RANGE_ADJ(config->term_range_adj);
401 writel(val, base + UTMIP_XCVR_CFG1);
402
403 val = readl(base + UTMIP_BAT_CHRG_CFG0);
404 val &= ~UTMIP_PD_CHRG;
405 writel(val, base + UTMIP_BAT_CHRG_CFG0);
406
407 val = readl(base + UTMIP_BIAS_CFG1);
408 val &= ~UTMIP_BIAS_PDTRK_COUNT(~0);
409 val |= UTMIP_BIAS_PDTRK_COUNT(0x5);
410 writel(val, base + UTMIP_BIAS_CFG1);
411
Venu Byravarasu3a55c6a2013-01-16 03:30:20 +0000412 if (phy->is_legacy_phy) {
Benoit Goby91525d02011-03-09 16:28:55 -0800413 val = readl(base + UTMIP_SPARE_CFG0);
414 if (phy->mode == TEGRA_USB_PHY_MODE_DEVICE)
415 val &= ~FUSE_SETUP_SEL;
416 else
417 val |= FUSE_SETUP_SEL;
418 writel(val, base + UTMIP_SPARE_CFG0);
Venu Byravarasu3a55c6a2013-01-16 03:30:20 +0000419 } else {
Benoit Goby91525d02011-03-09 16:28:55 -0800420 val = readl(base + USB_SUSP_CTRL);
421 val |= UTMIP_PHY_ENABLE;
422 writel(val, base + USB_SUSP_CTRL);
423 }
424
425 val = readl(base + USB_SUSP_CTRL);
426 val &= ~UTMIP_RESET;
427 writel(val, base + USB_SUSP_CTRL);
428
Venu Byravarasu3a55c6a2013-01-16 03:30:20 +0000429 if (phy->is_legacy_phy) {
Benoit Goby91525d02011-03-09 16:28:55 -0800430 val = readl(base + USB1_LEGACY_CTRL);
431 val &= ~USB1_VBUS_SENSE_CTL_MASK;
432 val |= USB1_VBUS_SENSE_CTL_A_SESS_VLD;
433 writel(val, base + USB1_LEGACY_CTRL);
434
435 val = readl(base + USB_SUSP_CTRL);
436 val &= ~USB_SUSP_SET;
437 writel(val, base + USB_SUSP_CTRL);
438 }
439
440 utmi_phy_clk_enable(phy);
441
Venu Byravarasubbdabdb2013-01-17 20:15:37 +0000442 if (!phy->is_legacy_phy)
Stephen Warren91a687d2013-06-13 11:24:11 -0600443 set_pts(phy, 0);
Benoit Goby91525d02011-03-09 16:28:55 -0800444
445 return 0;
446}
447
Venu Byravarasu1ba82162012-09-05 18:50:23 +0530448static int utmi_phy_power_off(struct tegra_usb_phy *phy)
Benoit Goby91525d02011-03-09 16:28:55 -0800449{
450 unsigned long val;
451 void __iomem *base = phy->regs;
452
453 utmi_phy_clk_disable(phy);
454
455 if (phy->mode == TEGRA_USB_PHY_MODE_DEVICE) {
456 val = readl(base + USB_SUSP_CTRL);
457 val &= ~USB_WAKEUP_DEBOUNCE_COUNT(~0);
458 val |= USB_WAKE_ON_CNNT_EN_DEV | USB_WAKEUP_DEBOUNCE_COUNT(5);
459 writel(val, base + USB_SUSP_CTRL);
460 }
461
462 val = readl(base + USB_SUSP_CTRL);
463 val |= UTMIP_RESET;
464 writel(val, base + USB_SUSP_CTRL);
465
466 val = readl(base + UTMIP_BAT_CHRG_CFG0);
467 val |= UTMIP_PD_CHRG;
468 writel(val, base + UTMIP_BAT_CHRG_CFG0);
469
470 val = readl(base + UTMIP_XCVR_CFG0);
471 val |= UTMIP_FORCE_PD_POWERDOWN | UTMIP_FORCE_PD2_POWERDOWN |
472 UTMIP_FORCE_PDZI_POWERDOWN;
473 writel(val, base + UTMIP_XCVR_CFG0);
474
475 val = readl(base + UTMIP_XCVR_CFG1);
476 val |= UTMIP_FORCE_PDDISC_POWERDOWN | UTMIP_FORCE_PDCHRP_POWERDOWN |
477 UTMIP_FORCE_PDDR_POWERDOWN;
478 writel(val, base + UTMIP_XCVR_CFG1);
479
Venu Byravarasu1ba82162012-09-05 18:50:23 +0530480 return utmip_pad_power_off(phy);
Benoit Goby91525d02011-03-09 16:28:55 -0800481}
482
483static void utmi_phy_preresume(struct tegra_usb_phy *phy)
484{
485 unsigned long val;
486 void __iomem *base = phy->regs;
487
488 val = readl(base + UTMIP_TX_CFG0);
489 val |= UTMIP_HS_DISCON_DISABLE;
490 writel(val, base + UTMIP_TX_CFG0);
491}
492
493static void utmi_phy_postresume(struct tegra_usb_phy *phy)
494{
495 unsigned long val;
496 void __iomem *base = phy->regs;
497
498 val = readl(base + UTMIP_TX_CFG0);
499 val &= ~UTMIP_HS_DISCON_DISABLE;
500 writel(val, base + UTMIP_TX_CFG0);
501}
502
503static void utmi_phy_restore_start(struct tegra_usb_phy *phy,
504 enum tegra_usb_phy_port_speed port_speed)
505{
506 unsigned long val;
507 void __iomem *base = phy->regs;
508
509 val = readl(base + UTMIP_MISC_CFG0);
510 val &= ~UTMIP_DPDM_OBSERVE_SEL(~0);
511 if (port_speed == TEGRA_USB_PHY_PORT_SPEED_LOW)
512 val |= UTMIP_DPDM_OBSERVE_SEL_FS_K;
513 else
514 val |= UTMIP_DPDM_OBSERVE_SEL_FS_J;
515 writel(val, base + UTMIP_MISC_CFG0);
516 udelay(1);
517
518 val = readl(base + UTMIP_MISC_CFG0);
519 val |= UTMIP_DPDM_OBSERVE;
520 writel(val, base + UTMIP_MISC_CFG0);
521 udelay(10);
522}
523
524static void utmi_phy_restore_end(struct tegra_usb_phy *phy)
525{
526 unsigned long val;
527 void __iomem *base = phy->regs;
528
529 val = readl(base + UTMIP_MISC_CFG0);
530 val &= ~UTMIP_DPDM_OBSERVE;
531 writel(val, base + UTMIP_MISC_CFG0);
532 udelay(10);
533}
534
535static int ulpi_phy_power_on(struct tegra_usb_phy *phy)
536{
537 int ret;
538 unsigned long val;
539 void __iomem *base = phy->regs;
Benoit Goby91525d02011-03-09 16:28:55 -0800540
Venu Byravarasu6829f922013-05-16 19:43:01 +0530541 ret = gpio_direction_output(phy->reset_gpio, 0);
542 if (ret < 0) {
Tuomas Tynkkynen185d0fd2013-07-25 21:38:01 +0300543 dev_err(phy->u_phy.dev, "gpio %d not set to 0\n",
544 phy->reset_gpio);
Venu Byravarasu6829f922013-05-16 19:43:01 +0530545 return ret;
546 }
Benoit Goby91525d02011-03-09 16:28:55 -0800547 msleep(5);
Venu Byravarasu6829f922013-05-16 19:43:01 +0530548 ret = gpio_direction_output(phy->reset_gpio, 1);
549 if (ret < 0) {
Tuomas Tynkkynen185d0fd2013-07-25 21:38:01 +0300550 dev_err(phy->u_phy.dev, "gpio %d not set to 1\n",
551 phy->reset_gpio);
Venu Byravarasu6829f922013-05-16 19:43:01 +0530552 return ret;
553 }
Benoit Goby91525d02011-03-09 16:28:55 -0800554
Prashant Gaikwad6a5278d2012-06-05 09:59:35 +0530555 clk_prepare_enable(phy->clk);
Benoit Goby91525d02011-03-09 16:28:55 -0800556 msleep(1);
557
558 val = readl(base + USB_SUSP_CTRL);
559 val |= UHSIC_RESET;
560 writel(val, base + USB_SUSP_CTRL);
561
562 val = readl(base + ULPI_TIMING_CTRL_0);
563 val |= ULPI_OUTPUT_PINMUX_BYP | ULPI_CLKOUT_PINMUX_BYP;
564 writel(val, base + ULPI_TIMING_CTRL_0);
565
566 val = readl(base + USB_SUSP_CTRL);
567 val |= ULPI_PHY_ENABLE;
568 writel(val, base + USB_SUSP_CTRL);
569
570 val = 0;
571 writel(val, base + ULPI_TIMING_CTRL_1);
572
573 val |= ULPI_DATA_TRIMMER_SEL(4);
574 val |= ULPI_STPDIRNXT_TRIMMER_SEL(4);
575 val |= ULPI_DIR_TRIMMER_SEL(4);
576 writel(val, base + ULPI_TIMING_CTRL_1);
577 udelay(10);
578
579 val |= ULPI_DATA_TRIMMER_LOAD;
580 val |= ULPI_STPDIRNXT_TRIMMER_LOAD;
581 val |= ULPI_DIR_TRIMMER_LOAD;
582 writel(val, base + ULPI_TIMING_CTRL_1);
583
584 /* Fix VbusInvalid due to floating VBUS */
Heikki Krogerusb96d3b02012-02-13 13:24:18 +0200585 ret = usb_phy_io_write(phy->ulpi, 0x40, 0x08);
Benoit Goby91525d02011-03-09 16:28:55 -0800586 if (ret) {
587 pr_err("%s: ulpi write failed\n", __func__);
588 return ret;
589 }
590
Heikki Krogerusb96d3b02012-02-13 13:24:18 +0200591 ret = usb_phy_io_write(phy->ulpi, 0x80, 0x0B);
Benoit Goby91525d02011-03-09 16:28:55 -0800592 if (ret) {
593 pr_err("%s: ulpi write failed\n", __func__);
594 return ret;
595 }
596
Benoit Goby91525d02011-03-09 16:28:55 -0800597 val = readl(base + USB_SUSP_CTRL);
598 val |= USB_SUSP_CLR;
599 writel(val, base + USB_SUSP_CTRL);
600 udelay(100);
601
602 val = readl(base + USB_SUSP_CTRL);
603 val &= ~USB_SUSP_CLR;
604 writel(val, base + USB_SUSP_CTRL);
605
606 return 0;
607}
608
Venu Byravarasu1ba82162012-09-05 18:50:23 +0530609static int ulpi_phy_power_off(struct tegra_usb_phy *phy)
Benoit Goby91525d02011-03-09 16:28:55 -0800610{
Benoit Goby91525d02011-03-09 16:28:55 -0800611 clk_disable(phy->clk);
Venu Byravarasu12ea18e2013-05-16 19:43:00 +0530612 return gpio_direction_output(phy->reset_gpio, 0);
Venu Byravarasu1ba82162012-09-05 18:50:23 +0530613}
614
Venu Byravarasu1ba82162012-09-05 18:50:23 +0530615static void tegra_usb_phy_close(struct usb_phy *x)
616{
617 struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy);
618
Mikko Perttunenf5b8c8b2013-07-17 10:37:49 +0300619 if (!IS_ERR(phy->vbus))
620 regulator_disable(phy->vbus);
621
Venu Byravarasu1ba82162012-09-05 18:50:23 +0530622 clk_disable_unprepare(phy->pll_u);
Venu Byravarasu1ba82162012-09-05 18:50:23 +0530623}
624
625static int tegra_usb_phy_power_on(struct tegra_usb_phy *phy)
626{
Venu Byravarasu3f9db1a2013-01-16 03:30:21 +0000627 if (phy->is_ulpi_phy)
Venu Byravarasu1ba82162012-09-05 18:50:23 +0530628 return ulpi_phy_power_on(phy);
629 else
630 return utmi_phy_power_on(phy);
631}
632
633static int tegra_usb_phy_power_off(struct tegra_usb_phy *phy)
634{
Venu Byravarasu3f9db1a2013-01-16 03:30:21 +0000635 if (phy->is_ulpi_phy)
Venu Byravarasu1ba82162012-09-05 18:50:23 +0530636 return ulpi_phy_power_off(phy);
637 else
638 return utmi_phy_power_off(phy);
639}
640
641static int tegra_usb_phy_suspend(struct usb_phy *x, int suspend)
642{
643 struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy);
644 if (suspend)
645 return tegra_usb_phy_power_off(phy);
646 else
647 return tegra_usb_phy_power_on(phy);
Benoit Goby91525d02011-03-09 16:28:55 -0800648}
649
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530650static int ulpi_open(struct tegra_usb_phy *phy)
Benoit Goby91525d02011-03-09 16:28:55 -0800651{
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530652 int err;
653
Tuomas Tynkkynen185d0fd2013-07-25 21:38:01 +0300654 phy->clk = devm_clk_get(phy->u_phy.dev, "ulpi-link");
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530655 if (IS_ERR(phy->clk)) {
656 pr_err("%s: can't get ulpi clock\n", __func__);
657 return PTR_ERR(phy->clk);
658 }
659
Tuomas Tynkkynen185d0fd2013-07-25 21:38:01 +0300660 err = devm_gpio_request(phy->u_phy.dev, phy->reset_gpio,
661 "ulpi_phy_reset_b");
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530662 if (err < 0) {
Tuomas Tynkkynen185d0fd2013-07-25 21:38:01 +0300663 dev_err(phy->u_phy.dev, "request failed for gpio: %d\n",
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530664 phy->reset_gpio);
665 return err;
666 }
667
668 err = gpio_direction_output(phy->reset_gpio, 0);
669 if (err < 0) {
Tuomas Tynkkynen185d0fd2013-07-25 21:38:01 +0300670 dev_err(phy->u_phy.dev, "gpio %d direction not set to output\n",
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530671 phy->reset_gpio);
672 return err;
673 }
674
675 phy->ulpi = otg_ulpi_create(&ulpi_viewport_access_ops, 0);
676 if (!phy->ulpi) {
Tuomas Tynkkynen185d0fd2013-07-25 21:38:01 +0300677 dev_err(phy->u_phy.dev, "otg_ulpi_create returned NULL\n");
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530678 err = -ENOMEM;
679 return err;
680 }
681
682 phy->ulpi->io_priv = phy->regs + ULPI_VIEWPORT;
683 return 0;
684}
685
686static int tegra_usb_phy_init(struct tegra_usb_phy *phy)
687{
Benoit Goby91525d02011-03-09 16:28:55 -0800688 unsigned long parent_rate;
689 int i;
690 int err;
691
Tuomas Tynkkynen185d0fd2013-07-25 21:38:01 +0300692 phy->pll_u = devm_clk_get(phy->u_phy.dev, "pll_u");
Benoit Goby91525d02011-03-09 16:28:55 -0800693 if (IS_ERR(phy->pll_u)) {
694 pr_err("Can't get pll_u clock\n");
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530695 return PTR_ERR(phy->pll_u);
Benoit Goby91525d02011-03-09 16:28:55 -0800696 }
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530697
698 err = clk_prepare_enable(phy->pll_u);
699 if (err)
700 return err;
Benoit Goby91525d02011-03-09 16:28:55 -0800701
702 parent_rate = clk_get_rate(clk_get_parent(phy->pll_u));
703 for (i = 0; i < ARRAY_SIZE(tegra_freq_table); i++) {
704 if (tegra_freq_table[i].freq == parent_rate) {
705 phy->freq = &tegra_freq_table[i];
706 break;
707 }
708 }
709 if (!phy->freq) {
710 pr_err("invalid pll_u parent rate %ld\n", parent_rate);
711 err = -EINVAL;
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530712 goto fail;
Benoit Goby91525d02011-03-09 16:28:55 -0800713 }
714
Mikko Perttunenf5b8c8b2013-07-17 10:37:49 +0300715 if (!IS_ERR(phy->vbus)) {
716 err = regulator_enable(phy->vbus);
717 if (err) {
Tuomas Tynkkynen185d0fd2013-07-25 21:38:01 +0300718 dev_err(phy->u_phy.dev,
Mikko Perttunenf5b8c8b2013-07-17 10:37:49 +0300719 "failed to enable usb vbus regulator: %d\n",
720 err);
721 goto fail;
722 }
723 }
724
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530725 if (phy->is_ulpi_phy)
726 err = ulpi_open(phy);
727 else
728 err = utmip_pad_open(phy);
729 if (err < 0)
730 goto fail;
Benoit Goby91525d02011-03-09 16:28:55 -0800731
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530732 return 0;
Benoit Goby91525d02011-03-09 16:28:55 -0800733
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530734fail:
Prashant Gaikwad6a5278d2012-06-05 09:59:35 +0530735 clk_disable_unprepare(phy->pll_u);
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530736 return err;
Benoit Goby91525d02011-03-09 16:28:55 -0800737}
738
Venu Byravarasuab137d02013-01-24 15:57:03 +0530739void tegra_usb_phy_preresume(struct usb_phy *x)
Benoit Goby91525d02011-03-09 16:28:55 -0800740{
Venu Byravarasuab137d02013-01-24 15:57:03 +0530741 struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy);
742
Venu Byravarasu3f9db1a2013-01-16 03:30:21 +0000743 if (!phy->is_ulpi_phy)
Benoit Goby91525d02011-03-09 16:28:55 -0800744 utmi_phy_preresume(phy);
745}
Arnd Bergmann4265cbf2012-03-02 15:58:42 -0500746EXPORT_SYMBOL_GPL(tegra_usb_phy_preresume);
Benoit Goby91525d02011-03-09 16:28:55 -0800747
Venu Byravarasuab137d02013-01-24 15:57:03 +0530748void tegra_usb_phy_postresume(struct usb_phy *x)
Benoit Goby91525d02011-03-09 16:28:55 -0800749{
Venu Byravarasuab137d02013-01-24 15:57:03 +0530750 struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy);
751
Venu Byravarasu3f9db1a2013-01-16 03:30:21 +0000752 if (!phy->is_ulpi_phy)
Benoit Goby91525d02011-03-09 16:28:55 -0800753 utmi_phy_postresume(phy);
754}
Arnd Bergmann4265cbf2012-03-02 15:58:42 -0500755EXPORT_SYMBOL_GPL(tegra_usb_phy_postresume);
Benoit Goby91525d02011-03-09 16:28:55 -0800756
Venu Byravarasuab137d02013-01-24 15:57:03 +0530757void tegra_ehci_phy_restore_start(struct usb_phy *x,
Benoit Goby91525d02011-03-09 16:28:55 -0800758 enum tegra_usb_phy_port_speed port_speed)
759{
Venu Byravarasuab137d02013-01-24 15:57:03 +0530760 struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy);
761
Venu Byravarasu3f9db1a2013-01-16 03:30:21 +0000762 if (!phy->is_ulpi_phy)
Benoit Goby91525d02011-03-09 16:28:55 -0800763 utmi_phy_restore_start(phy, port_speed);
764}
Arnd Bergmann4265cbf2012-03-02 15:58:42 -0500765EXPORT_SYMBOL_GPL(tegra_ehci_phy_restore_start);
Benoit Goby91525d02011-03-09 16:28:55 -0800766
Venu Byravarasuab137d02013-01-24 15:57:03 +0530767void tegra_ehci_phy_restore_end(struct usb_phy *x)
Benoit Goby91525d02011-03-09 16:28:55 -0800768{
Venu Byravarasuab137d02013-01-24 15:57:03 +0530769 struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy);
770
Venu Byravarasu3f9db1a2013-01-16 03:30:21 +0000771 if (!phy->is_ulpi_phy)
Benoit Goby91525d02011-03-09 16:28:55 -0800772 utmi_phy_restore_end(phy);
773}
Arnd Bergmann4265cbf2012-03-02 15:58:42 -0500774EXPORT_SYMBOL_GPL(tegra_ehci_phy_restore_end);
Benoit Goby91525d02011-03-09 16:28:55 -0800775
Mikko Perttunen81d5dfe2013-07-17 09:31:01 +0300776static int read_utmi_param(struct platform_device *pdev, const char *param,
777 u8 *dest)
778{
779 u32 value;
780 int err = of_property_read_u32(pdev->dev.of_node, param, &value);
781 *dest = (u8)value;
782 if (err < 0)
783 dev_err(&pdev->dev, "Failed to read USB UTMI parameter %s: %d\n",
784 param, err);
785 return err;
786}
787
788static int utmi_phy_probe(struct tegra_usb_phy *tegra_phy,
789 struct platform_device *pdev)
790{
791 struct resource *res;
792 int err;
793 struct tegra_utmip_config *config;
794
795 tegra_phy->is_ulpi_phy = false;
796
797 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
798 if (!res) {
799 dev_err(&pdev->dev, "Failed to get UTMI Pad regs\n");
800 return -ENXIO;
801 }
802
803 tegra_phy->pad_regs = devm_ioremap(&pdev->dev, res->start,
804 resource_size(res));
805 if (!tegra_phy->regs) {
806 dev_err(&pdev->dev, "Failed to remap UTMI Pad regs\n");
807 return -ENOMEM;
808 }
809
810 tegra_phy->config = devm_kzalloc(&pdev->dev,
811 sizeof(*tegra_phy->config), GFP_KERNEL);
812 if (!tegra_phy->config) {
813 dev_err(&pdev->dev,
814 "unable to allocate memory for USB UTMIP config\n");
815 return -ENOMEM;
816 }
817
818 config = tegra_phy->config;
819
820 err = read_utmi_param(pdev, "nvidia,hssync-start-delay",
821 &config->hssync_start_delay);
822 if (err < 0)
823 return err;
824
825 err = read_utmi_param(pdev, "nvidia,elastic-limit",
826 &config->elastic_limit);
827 if (err < 0)
828 return err;
829
830 err = read_utmi_param(pdev, "nvidia,idle-wait-delay",
831 &config->idle_wait_delay);
832 if (err < 0)
833 return err;
834
835 err = read_utmi_param(pdev, "nvidia,term-range-adj",
836 &config->term_range_adj);
837 if (err < 0)
838 return err;
839
840 err = read_utmi_param(pdev, "nvidia,xcvr-setup",
841 &config->xcvr_setup);
842 if (err < 0)
843 return err;
844
845 err = read_utmi_param(pdev, "nvidia,xcvr-lsfslew",
846 &config->xcvr_lsfslew);
847 if (err < 0)
848 return err;
849
850 err = read_utmi_param(pdev, "nvidia,xcvr-lsrslew",
851 &config->xcvr_lsrslew);
852 if (err < 0)
853 return err;
854
855 return 0;
856}
857
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530858static int tegra_usb_phy_probe(struct platform_device *pdev)
859{
860 struct resource *res;
861 struct tegra_usb_phy *tegra_phy = NULL;
862 struct device_node *np = pdev->dev.of_node;
863 int err;
864
865 tegra_phy = devm_kzalloc(&pdev->dev, sizeof(*tegra_phy), GFP_KERNEL);
866 if (!tegra_phy) {
867 dev_err(&pdev->dev, "unable to allocate memory for USB2 PHY\n");
868 return -ENOMEM;
869 }
870
871 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
872 if (!res) {
873 dev_err(&pdev->dev, "Failed to get I/O memory\n");
874 return -ENXIO;
875 }
876
877 tegra_phy->regs = devm_ioremap(&pdev->dev, res->start,
878 resource_size(res));
879 if (!tegra_phy->regs) {
880 dev_err(&pdev->dev, "Failed to remap I/O memory\n");
881 return -ENOMEM;
882 }
883
884 tegra_phy->is_legacy_phy =
885 of_property_read_bool(np, "nvidia,has-legacy-mode");
886
887 err = of_property_match_string(np, "phy_type", "ulpi");
888 if (err < 0) {
Mikko Perttunen81d5dfe2013-07-17 09:31:01 +0300889 err = utmi_phy_probe(tegra_phy, pdev);
890 if (err < 0)
891 return err;
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530892 } else {
893 tegra_phy->is_ulpi_phy = true;
894
895 tegra_phy->reset_gpio =
896 of_get_named_gpio(np, "nvidia,phy-reset-gpio", 0);
897 if (!gpio_is_valid(tegra_phy->reset_gpio)) {
898 dev_err(&pdev->dev, "invalid gpio: %d\n",
899 tegra_phy->reset_gpio);
900 return tegra_phy->reset_gpio;
901 }
Mikko Perttunen81d5dfe2013-07-17 09:31:01 +0300902
903 tegra_phy->config = NULL;
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530904 }
905
906 err = of_property_match_string(np, "dr_mode", "otg");
907 if (err < 0) {
908 err = of_property_match_string(np, "dr_mode", "peripheral");
909 if (err < 0)
910 tegra_phy->mode = TEGRA_USB_PHY_MODE_HOST;
911 else
912 tegra_phy->mode = TEGRA_USB_PHY_MODE_DEVICE;
913 } else
914 tegra_phy->mode = TEGRA_USB_PHY_MODE_OTG;
915
Mikko Perttunenf5b8c8b2013-07-17 10:37:49 +0300916 /* On some boards, the VBUS regulator doesn't need to be controlled */
917 if (of_find_property(np, "vbus-supply", NULL)) {
918 tegra_phy->vbus = devm_regulator_get(&pdev->dev, "vbus");
919 if (IS_ERR(tegra_phy->vbus))
920 return PTR_ERR(tegra_phy->vbus);
921 } else {
922 dev_notice(&pdev->dev, "no vbus regulator");
923 tegra_phy->vbus = ERR_PTR(-ENODEV);
924 }
925
Tuomas Tynkkynen185d0fd2013-07-25 21:38:01 +0300926 tegra_phy->u_phy.dev = &pdev->dev;
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530927 err = tegra_usb_phy_init(tegra_phy);
928 if (err < 0)
929 return err;
930
931 tegra_phy->u_phy.shutdown = tegra_usb_phy_close;
932 tegra_phy->u_phy.set_suspend = tegra_usb_phy_suspend;
933
934 dev_set_drvdata(&pdev->dev, tegra_phy);
Tuomas Tynkkynen0ee5b4a2013-07-25 21:38:05 +0300935
936 err = usb_add_phy_dev(&tegra_phy->u_phy);
937 if (err < 0) {
938 tegra_usb_phy_close(&tegra_phy->u_phy);
939 return err;
940 }
941
942 return 0;
943}
944
945static int tegra_usb_phy_remove(struct platform_device *pdev)
946{
947 struct tegra_usb_phy *tegra_phy = platform_get_drvdata(pdev);
948
949 usb_remove_phy(&tegra_phy->u_phy);
950
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530951 return 0;
952}
953
954static struct of_device_id tegra_usb_phy_id_table[] = {
955 { .compatible = "nvidia,tegra20-usb-phy", },
956 { },
957};
958MODULE_DEVICE_TABLE(of, tegra_usb_phy_id_table);
959
960static struct platform_driver tegra_usb_phy_driver = {
961 .probe = tegra_usb_phy_probe,
Tuomas Tynkkynen0ee5b4a2013-07-25 21:38:05 +0300962 .remove = tegra_usb_phy_remove,
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530963 .driver = {
964 .name = "tegra-phy",
965 .owner = THIS_MODULE,
966 .of_match_table = of_match_ptr(tegra_usb_phy_id_table),
967 },
968};
969module_platform_driver(tegra_usb_phy_driver);
970
971static int tegra_usb_phy_match(struct device *dev, void *data)
972{
973 struct tegra_usb_phy *tegra_phy = dev_get_drvdata(dev);
974 struct device_node *dn = data;
975
Tuomas Tynkkynen185d0fd2013-07-25 21:38:01 +0300976 return (tegra_phy->u_phy.dev->of_node == dn) ? 1 : 0;
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530977}
978
979struct usb_phy *tegra_usb_get_phy(struct device_node *dn)
980{
981 struct device *dev;
982 struct tegra_usb_phy *tegra_phy;
983
984 dev = driver_find_device(&tegra_usb_phy_driver.driver, NULL, dn,
985 tegra_usb_phy_match);
986 if (!dev)
987 return ERR_PTR(-EPROBE_DEFER);
988
989 tegra_phy = dev_get_drvdata(dev);
990
991 return &tegra_phy->u_phy;
992}
993EXPORT_SYMBOL_GPL(tegra_usb_get_phy);
Stephen Warren587376a2013-06-13 11:24:08 -0600994
995MODULE_DESCRIPTION("Tegra USB PHY driver");
996MODULE_LICENSE("GPL v2");