blob: 01c30ff8874e62effb6a35b9a6fcb821d71b795c [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>
Tuomas Tynkkynen9fdb07f2013-07-25 21:38:08 +030034#include <linux/usb/of.h>
Benoit Goby91525d02011-03-09 16:28:55 -080035#include <asm/mach-types.h>
Stephen Warren91a687d2013-06-13 11:24:11 -060036#include <linux/usb/ehci_def.h>
Venu Byravarasu1ba82162012-09-05 18:50:23 +053037#include <linux/usb/tegra_usb_phy.h>
Mikko Perttunenf5b8c8b2013-07-17 10:37:49 +030038#include <linux/regulator/consumer.h>
Benoit Goby91525d02011-03-09 16:28:55 -080039
40#define ULPI_VIEWPORT 0x170
41
Stephen Warren91a687d2013-06-13 11:24:11 -060042/* PORTSC registers */
43#define TEGRA_USB_PORTSC1 0x184
44#define TEGRA_USB_PORTSC1_PTS(x) (((x) & 0x3) << 30)
45#define TEGRA_USB_PORTSC1_PHCD (1 << 23)
46
47/* Bits of PORTSC1, which will get cleared by writing 1 into them */
48#define TEGRA_PORTSC1_RWC_BITS (PORT_CSC | PORT_PEC | PORT_OCC)
49
Benoit Goby91525d02011-03-09 16:28:55 -080050#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
142static DEFINE_SPINLOCK(utmip_pad_lock);
143static int utmip_pad_count;
144
145struct 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
154static 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
Stephen Warren91a687d2013-06-13 11:24:11 -0600189static void set_pts(struct tegra_usb_phy *phy, u8 pts_val)
190{
191 void __iomem *base = phy->regs;
192 unsigned long val;
193
194 val = readl(base + TEGRA_USB_PORTSC1) & ~TEGRA_PORTSC1_RWC_BITS;
195 val &= ~TEGRA_USB_PORTSC1_PTS(3);
196 val |= TEGRA_USB_PORTSC1_PTS(pts_val & 3);
197 writel(val, base + TEGRA_USB_PORTSC1);
198}
199
200static void set_phcd(struct tegra_usb_phy *phy, bool enable)
201{
202 void __iomem *base = phy->regs;
203 unsigned long val;
204
205 val = readl(base + TEGRA_USB_PORTSC1) & ~TEGRA_PORTSC1_RWC_BITS;
206 if (enable)
207 val |= TEGRA_USB_PORTSC1_PHCD;
208 else
209 val &= ~TEGRA_USB_PORTSC1_PHCD;
210 writel(val, base + TEGRA_USB_PORTSC1);
211}
212
Benoit Goby91525d02011-03-09 16:28:55 -0800213static int utmip_pad_open(struct tegra_usb_phy *phy)
214{
Tuomas Tynkkynen185d0fd2013-07-25 21:38:01 +0300215 phy->pad_clk = devm_clk_get(phy->u_phy.dev, "utmi-pads");
Benoit Goby91525d02011-03-09 16:28:55 -0800216 if (IS_ERR(phy->pad_clk)) {
217 pr_err("%s: can't get utmip pad clock\n", __func__);
218 return PTR_ERR(phy->pad_clk);
219 }
220
Benoit Goby91525d02011-03-09 16:28:55 -0800221 return 0;
222}
223
Benoit Goby91525d02011-03-09 16:28:55 -0800224static void utmip_pad_power_on(struct tegra_usb_phy *phy)
225{
226 unsigned long val, flags;
227 void __iomem *base = phy->pad_regs;
228
Prashant Gaikwad6a5278d2012-06-05 09:59:35 +0530229 clk_prepare_enable(phy->pad_clk);
Benoit Goby91525d02011-03-09 16:28:55 -0800230
231 spin_lock_irqsave(&utmip_pad_lock, flags);
232
233 if (utmip_pad_count++ == 0) {
234 val = readl(base + UTMIP_BIAS_CFG0);
235 val &= ~(UTMIP_OTGPD | UTMIP_BIASPD);
236 writel(val, base + UTMIP_BIAS_CFG0);
237 }
238
239 spin_unlock_irqrestore(&utmip_pad_lock, flags);
240
Prashant Gaikwad6a5278d2012-06-05 09:59:35 +0530241 clk_disable_unprepare(phy->pad_clk);
Benoit Goby91525d02011-03-09 16:28:55 -0800242}
243
244static int utmip_pad_power_off(struct tegra_usb_phy *phy)
245{
246 unsigned long val, flags;
247 void __iomem *base = phy->pad_regs;
248
249 if (!utmip_pad_count) {
250 pr_err("%s: utmip pad already powered off\n", __func__);
251 return -EINVAL;
252 }
253
Prashant Gaikwad6a5278d2012-06-05 09:59:35 +0530254 clk_prepare_enable(phy->pad_clk);
Benoit Goby91525d02011-03-09 16:28:55 -0800255
256 spin_lock_irqsave(&utmip_pad_lock, flags);
257
258 if (--utmip_pad_count == 0) {
259 val = readl(base + UTMIP_BIAS_CFG0);
260 val |= UTMIP_OTGPD | UTMIP_BIASPD;
261 writel(val, base + UTMIP_BIAS_CFG0);
262 }
263
264 spin_unlock_irqrestore(&utmip_pad_lock, flags);
265
Prashant Gaikwad6a5278d2012-06-05 09:59:35 +0530266 clk_disable_unprepare(phy->pad_clk);
Benoit Goby91525d02011-03-09 16:28:55 -0800267
268 return 0;
269}
270
271static int utmi_wait_register(void __iomem *reg, u32 mask, u32 result)
272{
273 unsigned long timeout = 2000;
274 do {
275 if ((readl(reg) & mask) == result)
276 return 0;
277 udelay(1);
278 timeout--;
279 } while (timeout);
280 return -1;
281}
282
283static void utmi_phy_clk_disable(struct tegra_usb_phy *phy)
284{
285 unsigned long val;
286 void __iomem *base = phy->regs;
287
Venu Byravarasu3a55c6a2013-01-16 03:30:20 +0000288 if (phy->is_legacy_phy) {
Benoit Goby91525d02011-03-09 16:28:55 -0800289 val = readl(base + USB_SUSP_CTRL);
290 val |= USB_SUSP_SET;
291 writel(val, base + USB_SUSP_CTRL);
292
293 udelay(10);
294
295 val = readl(base + USB_SUSP_CTRL);
296 val &= ~USB_SUSP_SET;
297 writel(val, base + USB_SUSP_CTRL);
Venu Byravarasubbdabdb2013-01-17 20:15:37 +0000298 } else
Stephen Warren91a687d2013-06-13 11:24:11 -0600299 set_phcd(phy, true);
Benoit Goby91525d02011-03-09 16:28:55 -0800300
301 if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, 0) < 0)
302 pr_err("%s: timeout waiting for phy to stabilize\n", __func__);
303}
304
305static void utmi_phy_clk_enable(struct tegra_usb_phy *phy)
306{
307 unsigned long val;
308 void __iomem *base = phy->regs;
309
Venu Byravarasu3a55c6a2013-01-16 03:30:20 +0000310 if (phy->is_legacy_phy) {
Benoit Goby91525d02011-03-09 16:28:55 -0800311 val = readl(base + USB_SUSP_CTRL);
312 val |= USB_SUSP_CLR;
313 writel(val, base + USB_SUSP_CTRL);
314
315 udelay(10);
316
317 val = readl(base + USB_SUSP_CTRL);
318 val &= ~USB_SUSP_CLR;
319 writel(val, base + USB_SUSP_CTRL);
Venu Byravarasubbdabdb2013-01-17 20:15:37 +0000320 } else
Stephen Warren91a687d2013-06-13 11:24:11 -0600321 set_phcd(phy, false);
Benoit Goby91525d02011-03-09 16:28:55 -0800322
323 if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID,
324 USB_PHY_CLK_VALID))
325 pr_err("%s: timeout waiting for phy to stabilize\n", __func__);
326}
327
328static int utmi_phy_power_on(struct tegra_usb_phy *phy)
329{
330 unsigned long val;
331 void __iomem *base = phy->regs;
332 struct tegra_utmip_config *config = phy->config;
333
334 val = readl(base + USB_SUSP_CTRL);
335 val |= UTMIP_RESET;
336 writel(val, base + USB_SUSP_CTRL);
337
Venu Byravarasu3a55c6a2013-01-16 03:30:20 +0000338 if (phy->is_legacy_phy) {
Benoit Goby91525d02011-03-09 16:28:55 -0800339 val = readl(base + USB1_LEGACY_CTRL);
340 val |= USB1_NO_LEGACY_MODE;
341 writel(val, base + USB1_LEGACY_CTRL);
342 }
343
344 val = readl(base + UTMIP_TX_CFG0);
345 val &= ~UTMIP_FS_PREABMLE_J;
346 writel(val, base + UTMIP_TX_CFG0);
347
348 val = readl(base + UTMIP_HSRX_CFG0);
349 val &= ~(UTMIP_IDLE_WAIT(~0) | UTMIP_ELASTIC_LIMIT(~0));
350 val |= UTMIP_IDLE_WAIT(config->idle_wait_delay);
351 val |= UTMIP_ELASTIC_LIMIT(config->elastic_limit);
352 writel(val, base + UTMIP_HSRX_CFG0);
353
354 val = readl(base + UTMIP_HSRX_CFG1);
355 val &= ~UTMIP_HS_SYNC_START_DLY(~0);
356 val |= UTMIP_HS_SYNC_START_DLY(config->hssync_start_delay);
357 writel(val, base + UTMIP_HSRX_CFG1);
358
359 val = readl(base + UTMIP_DEBOUNCE_CFG0);
360 val &= ~UTMIP_BIAS_DEBOUNCE_A(~0);
361 val |= UTMIP_BIAS_DEBOUNCE_A(phy->freq->debounce);
362 writel(val, base + UTMIP_DEBOUNCE_CFG0);
363
364 val = readl(base + UTMIP_MISC_CFG0);
365 val &= ~UTMIP_SUSPEND_EXIT_ON_EDGE;
366 writel(val, base + UTMIP_MISC_CFG0);
367
368 val = readl(base + UTMIP_MISC_CFG1);
369 val &= ~(UTMIP_PLL_ACTIVE_DLY_COUNT(~0) | UTMIP_PLLU_STABLE_COUNT(~0));
370 val |= UTMIP_PLL_ACTIVE_DLY_COUNT(phy->freq->active_delay) |
371 UTMIP_PLLU_STABLE_COUNT(phy->freq->stable_count);
372 writel(val, base + UTMIP_MISC_CFG1);
373
374 val = readl(base + UTMIP_PLL_CFG1);
375 val &= ~(UTMIP_XTAL_FREQ_COUNT(~0) | UTMIP_PLLU_ENABLE_DLY_COUNT(~0));
376 val |= UTMIP_XTAL_FREQ_COUNT(phy->freq->xtal_freq_count) |
377 UTMIP_PLLU_ENABLE_DLY_COUNT(phy->freq->enable_delay);
378 writel(val, base + UTMIP_PLL_CFG1);
379
Tuomas Tynkkynen6558d7e2013-07-25 21:38:09 +0300380 if (phy->mode == USB_DR_MODE_PERIPHERAL) {
Benoit Goby91525d02011-03-09 16:28:55 -0800381 val = readl(base + USB_SUSP_CTRL);
382 val &= ~(USB_WAKE_ON_CNNT_EN_DEV | USB_WAKE_ON_DISCON_EN_DEV);
383 writel(val, base + USB_SUSP_CTRL);
384 }
385
386 utmip_pad_power_on(phy);
387
388 val = readl(base + UTMIP_XCVR_CFG0);
389 val &= ~(UTMIP_FORCE_PD_POWERDOWN | UTMIP_FORCE_PD2_POWERDOWN |
390 UTMIP_FORCE_PDZI_POWERDOWN | UTMIP_XCVR_SETUP(~0) |
391 UTMIP_XCVR_LSFSLEW(~0) | UTMIP_XCVR_LSRSLEW(~0) |
392 UTMIP_XCVR_HSSLEW_MSB(~0));
393 val |= UTMIP_XCVR_SETUP(config->xcvr_setup);
394 val |= UTMIP_XCVR_LSFSLEW(config->xcvr_lsfslew);
395 val |= UTMIP_XCVR_LSRSLEW(config->xcvr_lsrslew);
396 writel(val, base + UTMIP_XCVR_CFG0);
397
398 val = readl(base + UTMIP_XCVR_CFG1);
399 val &= ~(UTMIP_FORCE_PDDISC_POWERDOWN | UTMIP_FORCE_PDCHRP_POWERDOWN |
400 UTMIP_FORCE_PDDR_POWERDOWN | UTMIP_XCVR_TERM_RANGE_ADJ(~0));
401 val |= UTMIP_XCVR_TERM_RANGE_ADJ(config->term_range_adj);
402 writel(val, base + UTMIP_XCVR_CFG1);
403
404 val = readl(base + UTMIP_BAT_CHRG_CFG0);
405 val &= ~UTMIP_PD_CHRG;
406 writel(val, base + UTMIP_BAT_CHRG_CFG0);
407
408 val = readl(base + UTMIP_BIAS_CFG1);
409 val &= ~UTMIP_BIAS_PDTRK_COUNT(~0);
410 val |= UTMIP_BIAS_PDTRK_COUNT(0x5);
411 writel(val, base + UTMIP_BIAS_CFG1);
412
Venu Byravarasu3a55c6a2013-01-16 03:30:20 +0000413 if (phy->is_legacy_phy) {
Benoit Goby91525d02011-03-09 16:28:55 -0800414 val = readl(base + UTMIP_SPARE_CFG0);
Tuomas Tynkkynen6558d7e2013-07-25 21:38:09 +0300415 if (phy->mode == USB_DR_MODE_PERIPHERAL)
Benoit Goby91525d02011-03-09 16:28:55 -0800416 val &= ~FUSE_SETUP_SEL;
417 else
418 val |= FUSE_SETUP_SEL;
419 writel(val, base + UTMIP_SPARE_CFG0);
Venu Byravarasu3a55c6a2013-01-16 03:30:20 +0000420 } else {
Benoit Goby91525d02011-03-09 16:28:55 -0800421 val = readl(base + USB_SUSP_CTRL);
422 val |= UTMIP_PHY_ENABLE;
423 writel(val, base + USB_SUSP_CTRL);
424 }
425
426 val = readl(base + USB_SUSP_CTRL);
427 val &= ~UTMIP_RESET;
428 writel(val, base + USB_SUSP_CTRL);
429
Venu Byravarasu3a55c6a2013-01-16 03:30:20 +0000430 if (phy->is_legacy_phy) {
Benoit Goby91525d02011-03-09 16:28:55 -0800431 val = readl(base + USB1_LEGACY_CTRL);
432 val &= ~USB1_VBUS_SENSE_CTL_MASK;
433 val |= USB1_VBUS_SENSE_CTL_A_SESS_VLD;
434 writel(val, base + USB1_LEGACY_CTRL);
435
436 val = readl(base + USB_SUSP_CTRL);
437 val &= ~USB_SUSP_SET;
438 writel(val, base + USB_SUSP_CTRL);
439 }
440
441 utmi_phy_clk_enable(phy);
442
Venu Byravarasubbdabdb2013-01-17 20:15:37 +0000443 if (!phy->is_legacy_phy)
Stephen Warren91a687d2013-06-13 11:24:11 -0600444 set_pts(phy, 0);
Benoit Goby91525d02011-03-09 16:28:55 -0800445
446 return 0;
447}
448
Venu Byravarasu1ba82162012-09-05 18:50:23 +0530449static int utmi_phy_power_off(struct tegra_usb_phy *phy)
Benoit Goby91525d02011-03-09 16:28:55 -0800450{
451 unsigned long val;
452 void __iomem *base = phy->regs;
453
454 utmi_phy_clk_disable(phy);
455
Tuomas Tynkkynen6558d7e2013-07-25 21:38:09 +0300456 if (phy->mode == USB_DR_MODE_PERIPHERAL) {
Benoit Goby91525d02011-03-09 16:28:55 -0800457 val = readl(base + USB_SUSP_CTRL);
458 val &= ~USB_WAKEUP_DEBOUNCE_COUNT(~0);
459 val |= USB_WAKE_ON_CNNT_EN_DEV | USB_WAKEUP_DEBOUNCE_COUNT(5);
460 writel(val, base + USB_SUSP_CTRL);
461 }
462
463 val = readl(base + USB_SUSP_CTRL);
464 val |= UTMIP_RESET;
465 writel(val, base + USB_SUSP_CTRL);
466
467 val = readl(base + UTMIP_BAT_CHRG_CFG0);
468 val |= UTMIP_PD_CHRG;
469 writel(val, base + UTMIP_BAT_CHRG_CFG0);
470
471 val = readl(base + UTMIP_XCVR_CFG0);
472 val |= UTMIP_FORCE_PD_POWERDOWN | UTMIP_FORCE_PD2_POWERDOWN |
473 UTMIP_FORCE_PDZI_POWERDOWN;
474 writel(val, base + UTMIP_XCVR_CFG0);
475
476 val = readl(base + UTMIP_XCVR_CFG1);
477 val |= UTMIP_FORCE_PDDISC_POWERDOWN | UTMIP_FORCE_PDCHRP_POWERDOWN |
478 UTMIP_FORCE_PDDR_POWERDOWN;
479 writel(val, base + UTMIP_XCVR_CFG1);
480
Venu Byravarasu1ba82162012-09-05 18:50:23 +0530481 return utmip_pad_power_off(phy);
Benoit Goby91525d02011-03-09 16:28:55 -0800482}
483
484static void utmi_phy_preresume(struct tegra_usb_phy *phy)
485{
486 unsigned long val;
487 void __iomem *base = phy->regs;
488
489 val = readl(base + UTMIP_TX_CFG0);
490 val |= UTMIP_HS_DISCON_DISABLE;
491 writel(val, base + UTMIP_TX_CFG0);
492}
493
494static void utmi_phy_postresume(struct tegra_usb_phy *phy)
495{
496 unsigned long val;
497 void __iomem *base = phy->regs;
498
499 val = readl(base + UTMIP_TX_CFG0);
500 val &= ~UTMIP_HS_DISCON_DISABLE;
501 writel(val, base + UTMIP_TX_CFG0);
502}
503
504static void utmi_phy_restore_start(struct tegra_usb_phy *phy,
505 enum tegra_usb_phy_port_speed port_speed)
506{
507 unsigned long val;
508 void __iomem *base = phy->regs;
509
510 val = readl(base + UTMIP_MISC_CFG0);
511 val &= ~UTMIP_DPDM_OBSERVE_SEL(~0);
512 if (port_speed == TEGRA_USB_PHY_PORT_SPEED_LOW)
513 val |= UTMIP_DPDM_OBSERVE_SEL_FS_K;
514 else
515 val |= UTMIP_DPDM_OBSERVE_SEL_FS_J;
516 writel(val, base + UTMIP_MISC_CFG0);
517 udelay(1);
518
519 val = readl(base + UTMIP_MISC_CFG0);
520 val |= UTMIP_DPDM_OBSERVE;
521 writel(val, base + UTMIP_MISC_CFG0);
522 udelay(10);
523}
524
525static void utmi_phy_restore_end(struct tegra_usb_phy *phy)
526{
527 unsigned long val;
528 void __iomem *base = phy->regs;
529
530 val = readl(base + UTMIP_MISC_CFG0);
531 val &= ~UTMIP_DPDM_OBSERVE;
532 writel(val, base + UTMIP_MISC_CFG0);
533 udelay(10);
534}
535
536static int ulpi_phy_power_on(struct tegra_usb_phy *phy)
537{
538 int ret;
539 unsigned long val;
540 void __iomem *base = phy->regs;
Benoit Goby91525d02011-03-09 16:28:55 -0800541
Venu Byravarasu6829f922013-05-16 19:43:01 +0530542 ret = gpio_direction_output(phy->reset_gpio, 0);
543 if (ret < 0) {
Tuomas Tynkkynen185d0fd2013-07-25 21:38:01 +0300544 dev_err(phy->u_phy.dev, "gpio %d not set to 0\n",
545 phy->reset_gpio);
Venu Byravarasu6829f922013-05-16 19:43:01 +0530546 return ret;
547 }
Benoit Goby91525d02011-03-09 16:28:55 -0800548 msleep(5);
Venu Byravarasu6829f922013-05-16 19:43:01 +0530549 ret = gpio_direction_output(phy->reset_gpio, 1);
550 if (ret < 0) {
Tuomas Tynkkynen185d0fd2013-07-25 21:38:01 +0300551 dev_err(phy->u_phy.dev, "gpio %d not set to 1\n",
552 phy->reset_gpio);
Venu Byravarasu6829f922013-05-16 19:43:01 +0530553 return ret;
554 }
Benoit Goby91525d02011-03-09 16:28:55 -0800555
Prashant Gaikwad6a5278d2012-06-05 09:59:35 +0530556 clk_prepare_enable(phy->clk);
Benoit Goby91525d02011-03-09 16:28:55 -0800557 msleep(1);
558
559 val = readl(base + USB_SUSP_CTRL);
560 val |= UHSIC_RESET;
561 writel(val, base + USB_SUSP_CTRL);
562
563 val = readl(base + ULPI_TIMING_CTRL_0);
564 val |= ULPI_OUTPUT_PINMUX_BYP | ULPI_CLKOUT_PINMUX_BYP;
565 writel(val, base + ULPI_TIMING_CTRL_0);
566
567 val = readl(base + USB_SUSP_CTRL);
568 val |= ULPI_PHY_ENABLE;
569 writel(val, base + USB_SUSP_CTRL);
570
571 val = 0;
572 writel(val, base + ULPI_TIMING_CTRL_1);
573
574 val |= ULPI_DATA_TRIMMER_SEL(4);
575 val |= ULPI_STPDIRNXT_TRIMMER_SEL(4);
576 val |= ULPI_DIR_TRIMMER_SEL(4);
577 writel(val, base + ULPI_TIMING_CTRL_1);
578 udelay(10);
579
580 val |= ULPI_DATA_TRIMMER_LOAD;
581 val |= ULPI_STPDIRNXT_TRIMMER_LOAD;
582 val |= ULPI_DIR_TRIMMER_LOAD;
583 writel(val, base + ULPI_TIMING_CTRL_1);
584
585 /* Fix VbusInvalid due to floating VBUS */
Heikki Krogerusb96d3b02012-02-13 13:24:18 +0200586 ret = usb_phy_io_write(phy->ulpi, 0x40, 0x08);
Benoit Goby91525d02011-03-09 16:28:55 -0800587 if (ret) {
588 pr_err("%s: ulpi write failed\n", __func__);
589 return ret;
590 }
591
Heikki Krogerusb96d3b02012-02-13 13:24:18 +0200592 ret = usb_phy_io_write(phy->ulpi, 0x80, 0x0B);
Benoit Goby91525d02011-03-09 16:28:55 -0800593 if (ret) {
594 pr_err("%s: ulpi write failed\n", __func__);
595 return ret;
596 }
597
Benoit Goby91525d02011-03-09 16:28:55 -0800598 val = readl(base + USB_SUSP_CTRL);
599 val |= USB_SUSP_CLR;
600 writel(val, base + USB_SUSP_CTRL);
601 udelay(100);
602
603 val = readl(base + USB_SUSP_CTRL);
604 val &= ~USB_SUSP_CLR;
605 writel(val, base + USB_SUSP_CTRL);
606
607 return 0;
608}
609
Venu Byravarasu1ba82162012-09-05 18:50:23 +0530610static int ulpi_phy_power_off(struct tegra_usb_phy *phy)
Benoit Goby91525d02011-03-09 16:28:55 -0800611{
Benoit Goby91525d02011-03-09 16:28:55 -0800612 clk_disable(phy->clk);
Venu Byravarasu12ea18e2013-05-16 19:43:00 +0530613 return gpio_direction_output(phy->reset_gpio, 0);
Venu Byravarasu1ba82162012-09-05 18:50:23 +0530614}
615
Venu Byravarasu1ba82162012-09-05 18:50:23 +0530616static void tegra_usb_phy_close(struct usb_phy *x)
617{
618 struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy);
619
Mikko Perttunenf5b8c8b2013-07-17 10:37:49 +0300620 if (!IS_ERR(phy->vbus))
621 regulator_disable(phy->vbus);
622
Venu Byravarasu1ba82162012-09-05 18:50:23 +0530623 clk_disable_unprepare(phy->pll_u);
Venu Byravarasu1ba82162012-09-05 18:50:23 +0530624}
625
626static int tegra_usb_phy_power_on(struct tegra_usb_phy *phy)
627{
Venu Byravarasu3f9db1a2013-01-16 03:30:21 +0000628 if (phy->is_ulpi_phy)
Venu Byravarasu1ba82162012-09-05 18:50:23 +0530629 return ulpi_phy_power_on(phy);
630 else
631 return utmi_phy_power_on(phy);
632}
633
634static int tegra_usb_phy_power_off(struct tegra_usb_phy *phy)
635{
Venu Byravarasu3f9db1a2013-01-16 03:30:21 +0000636 if (phy->is_ulpi_phy)
Venu Byravarasu1ba82162012-09-05 18:50:23 +0530637 return ulpi_phy_power_off(phy);
638 else
639 return utmi_phy_power_off(phy);
640}
641
642static int tegra_usb_phy_suspend(struct usb_phy *x, int suspend)
643{
644 struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy);
645 if (suspend)
646 return tegra_usb_phy_power_off(phy);
647 else
648 return tegra_usb_phy_power_on(phy);
Benoit Goby91525d02011-03-09 16:28:55 -0800649}
650
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530651static int ulpi_open(struct tegra_usb_phy *phy)
Benoit Goby91525d02011-03-09 16:28:55 -0800652{
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530653 int err;
654
Tuomas Tynkkynen185d0fd2013-07-25 21:38:01 +0300655 phy->clk = devm_clk_get(phy->u_phy.dev, "ulpi-link");
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530656 if (IS_ERR(phy->clk)) {
657 pr_err("%s: can't get ulpi clock\n", __func__);
658 return PTR_ERR(phy->clk);
659 }
660
Tuomas Tynkkynen185d0fd2013-07-25 21:38:01 +0300661 err = devm_gpio_request(phy->u_phy.dev, phy->reset_gpio,
662 "ulpi_phy_reset_b");
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530663 if (err < 0) {
Tuomas Tynkkynen185d0fd2013-07-25 21:38:01 +0300664 dev_err(phy->u_phy.dev, "request failed for gpio: %d\n",
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530665 phy->reset_gpio);
666 return err;
667 }
668
669 err = gpio_direction_output(phy->reset_gpio, 0);
670 if (err < 0) {
Tuomas Tynkkynen185d0fd2013-07-25 21:38:01 +0300671 dev_err(phy->u_phy.dev, "gpio %d direction not set to output\n",
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530672 phy->reset_gpio);
673 return err;
674 }
675
676 phy->ulpi = otg_ulpi_create(&ulpi_viewport_access_ops, 0);
677 if (!phy->ulpi) {
Tuomas Tynkkynen185d0fd2013-07-25 21:38:01 +0300678 dev_err(phy->u_phy.dev, "otg_ulpi_create returned NULL\n");
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530679 err = -ENOMEM;
680 return err;
681 }
682
683 phy->ulpi->io_priv = phy->regs + ULPI_VIEWPORT;
684 return 0;
685}
686
687static int tegra_usb_phy_init(struct tegra_usb_phy *phy)
688{
Benoit Goby91525d02011-03-09 16:28:55 -0800689 unsigned long parent_rate;
690 int i;
691 int err;
692
Tuomas Tynkkynen185d0fd2013-07-25 21:38:01 +0300693 phy->pll_u = devm_clk_get(phy->u_phy.dev, "pll_u");
Benoit Goby91525d02011-03-09 16:28:55 -0800694 if (IS_ERR(phy->pll_u)) {
695 pr_err("Can't get pll_u clock\n");
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530696 return PTR_ERR(phy->pll_u);
Benoit Goby91525d02011-03-09 16:28:55 -0800697 }
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530698
699 err = clk_prepare_enable(phy->pll_u);
700 if (err)
701 return err;
Benoit Goby91525d02011-03-09 16:28:55 -0800702
703 parent_rate = clk_get_rate(clk_get_parent(phy->pll_u));
704 for (i = 0; i < ARRAY_SIZE(tegra_freq_table); i++) {
705 if (tegra_freq_table[i].freq == parent_rate) {
706 phy->freq = &tegra_freq_table[i];
707 break;
708 }
709 }
710 if (!phy->freq) {
711 pr_err("invalid pll_u parent rate %ld\n", parent_rate);
712 err = -EINVAL;
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530713 goto fail;
Benoit Goby91525d02011-03-09 16:28:55 -0800714 }
715
Mikko Perttunenf5b8c8b2013-07-17 10:37:49 +0300716 if (!IS_ERR(phy->vbus)) {
717 err = regulator_enable(phy->vbus);
718 if (err) {
Tuomas Tynkkynen185d0fd2013-07-25 21:38:01 +0300719 dev_err(phy->u_phy.dev,
Mikko Perttunenf5b8c8b2013-07-17 10:37:49 +0300720 "failed to enable usb vbus regulator: %d\n",
721 err);
722 goto fail;
723 }
724 }
725
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530726 if (phy->is_ulpi_phy)
727 err = ulpi_open(phy);
728 else
729 err = utmip_pad_open(phy);
730 if (err < 0)
731 goto fail;
Benoit Goby91525d02011-03-09 16:28:55 -0800732
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530733 return 0;
Benoit Goby91525d02011-03-09 16:28:55 -0800734
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530735fail:
Prashant Gaikwad6a5278d2012-06-05 09:59:35 +0530736 clk_disable_unprepare(phy->pll_u);
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530737 return err;
Benoit Goby91525d02011-03-09 16:28:55 -0800738}
739
Venu Byravarasuab137d02013-01-24 15:57:03 +0530740void tegra_usb_phy_preresume(struct usb_phy *x)
Benoit Goby91525d02011-03-09 16:28:55 -0800741{
Venu Byravarasuab137d02013-01-24 15:57:03 +0530742 struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy);
743
Venu Byravarasu3f9db1a2013-01-16 03:30:21 +0000744 if (!phy->is_ulpi_phy)
Benoit Goby91525d02011-03-09 16:28:55 -0800745 utmi_phy_preresume(phy);
746}
Arnd Bergmann4265cbf2012-03-02 15:58:42 -0500747EXPORT_SYMBOL_GPL(tegra_usb_phy_preresume);
Benoit Goby91525d02011-03-09 16:28:55 -0800748
Venu Byravarasuab137d02013-01-24 15:57:03 +0530749void tegra_usb_phy_postresume(struct usb_phy *x)
Benoit Goby91525d02011-03-09 16:28:55 -0800750{
Venu Byravarasuab137d02013-01-24 15:57:03 +0530751 struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy);
752
Venu Byravarasu3f9db1a2013-01-16 03:30:21 +0000753 if (!phy->is_ulpi_phy)
Benoit Goby91525d02011-03-09 16:28:55 -0800754 utmi_phy_postresume(phy);
755}
Arnd Bergmann4265cbf2012-03-02 15:58:42 -0500756EXPORT_SYMBOL_GPL(tegra_usb_phy_postresume);
Benoit Goby91525d02011-03-09 16:28:55 -0800757
Venu Byravarasuab137d02013-01-24 15:57:03 +0530758void tegra_ehci_phy_restore_start(struct usb_phy *x,
Benoit Goby91525d02011-03-09 16:28:55 -0800759 enum tegra_usb_phy_port_speed port_speed)
760{
Venu Byravarasuab137d02013-01-24 15:57:03 +0530761 struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy);
762
Venu Byravarasu3f9db1a2013-01-16 03:30:21 +0000763 if (!phy->is_ulpi_phy)
Benoit Goby91525d02011-03-09 16:28:55 -0800764 utmi_phy_restore_start(phy, port_speed);
765}
Arnd Bergmann4265cbf2012-03-02 15:58:42 -0500766EXPORT_SYMBOL_GPL(tegra_ehci_phy_restore_start);
Benoit Goby91525d02011-03-09 16:28:55 -0800767
Venu Byravarasuab137d02013-01-24 15:57:03 +0530768void tegra_ehci_phy_restore_end(struct usb_phy *x)
Benoit Goby91525d02011-03-09 16:28:55 -0800769{
Venu Byravarasuab137d02013-01-24 15:57:03 +0530770 struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy);
771
Venu Byravarasu3f9db1a2013-01-16 03:30:21 +0000772 if (!phy->is_ulpi_phy)
Benoit Goby91525d02011-03-09 16:28:55 -0800773 utmi_phy_restore_end(phy);
774}
Arnd Bergmann4265cbf2012-03-02 15:58:42 -0500775EXPORT_SYMBOL_GPL(tegra_ehci_phy_restore_end);
Benoit Goby91525d02011-03-09 16:28:55 -0800776
Mikko Perttunen81d5dfe2013-07-17 09:31:01 +0300777static int read_utmi_param(struct platform_device *pdev, const char *param,
778 u8 *dest)
779{
780 u32 value;
781 int err = of_property_read_u32(pdev->dev.of_node, param, &value);
782 *dest = (u8)value;
783 if (err < 0)
784 dev_err(&pdev->dev, "Failed to read USB UTMI parameter %s: %d\n",
785 param, err);
786 return err;
787}
788
789static int utmi_phy_probe(struct tegra_usb_phy *tegra_phy,
790 struct platform_device *pdev)
791{
792 struct resource *res;
793 int err;
794 struct tegra_utmip_config *config;
795
796 tegra_phy->is_ulpi_phy = false;
797
798 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
799 if (!res) {
800 dev_err(&pdev->dev, "Failed to get UTMI Pad regs\n");
801 return -ENXIO;
802 }
803
804 tegra_phy->pad_regs = devm_ioremap(&pdev->dev, res->start,
805 resource_size(res));
806 if (!tegra_phy->regs) {
807 dev_err(&pdev->dev, "Failed to remap UTMI Pad regs\n");
808 return -ENOMEM;
809 }
810
811 tegra_phy->config = devm_kzalloc(&pdev->dev,
812 sizeof(*tegra_phy->config), GFP_KERNEL);
813 if (!tegra_phy->config) {
814 dev_err(&pdev->dev,
815 "unable to allocate memory for USB UTMIP config\n");
816 return -ENOMEM;
817 }
818
819 config = tegra_phy->config;
820
821 err = read_utmi_param(pdev, "nvidia,hssync-start-delay",
822 &config->hssync_start_delay);
823 if (err < 0)
824 return err;
825
826 err = read_utmi_param(pdev, "nvidia,elastic-limit",
827 &config->elastic_limit);
828 if (err < 0)
829 return err;
830
831 err = read_utmi_param(pdev, "nvidia,idle-wait-delay",
832 &config->idle_wait_delay);
833 if (err < 0)
834 return err;
835
836 err = read_utmi_param(pdev, "nvidia,term-range-adj",
837 &config->term_range_adj);
838 if (err < 0)
839 return err;
840
841 err = read_utmi_param(pdev, "nvidia,xcvr-setup",
842 &config->xcvr_setup);
843 if (err < 0)
844 return err;
845
846 err = read_utmi_param(pdev, "nvidia,xcvr-lsfslew",
847 &config->xcvr_lsfslew);
848 if (err < 0)
849 return err;
850
851 err = read_utmi_param(pdev, "nvidia,xcvr-lsrslew",
852 &config->xcvr_lsrslew);
853 if (err < 0)
854 return err;
855
856 return 0;
857}
858
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530859static int tegra_usb_phy_probe(struct platform_device *pdev)
860{
861 struct resource *res;
862 struct tegra_usb_phy *tegra_phy = NULL;
863 struct device_node *np = pdev->dev.of_node;
Tuomas Tynkkynen9fdb07f2013-07-25 21:38:08 +0300864 enum usb_phy_interface phy_type;
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530865 int err;
866
867 tegra_phy = devm_kzalloc(&pdev->dev, sizeof(*tegra_phy), GFP_KERNEL);
868 if (!tegra_phy) {
869 dev_err(&pdev->dev, "unable to allocate memory for USB2 PHY\n");
870 return -ENOMEM;
871 }
872
873 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
874 if (!res) {
875 dev_err(&pdev->dev, "Failed to get I/O memory\n");
876 return -ENXIO;
877 }
878
879 tegra_phy->regs = devm_ioremap(&pdev->dev, res->start,
880 resource_size(res));
881 if (!tegra_phy->regs) {
882 dev_err(&pdev->dev, "Failed to remap I/O memory\n");
883 return -ENOMEM;
884 }
885
886 tegra_phy->is_legacy_phy =
887 of_property_read_bool(np, "nvidia,has-legacy-mode");
888
Tuomas Tynkkynen9fdb07f2013-07-25 21:38:08 +0300889 phy_type = of_usb_get_phy_mode(np);
890 if (phy_type == USBPHY_INTERFACE_MODE_UTMI) {
Mikko Perttunen81d5dfe2013-07-17 09:31:01 +0300891 err = utmi_phy_probe(tegra_phy, pdev);
892 if (err < 0)
893 return err;
Tuomas Tynkkynen9fdb07f2013-07-25 21:38:08 +0300894 } else if (phy_type == USBPHY_INTERFACE_MODE_ULPI) {
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530895 tegra_phy->is_ulpi_phy = true;
896
897 tegra_phy->reset_gpio =
898 of_get_named_gpio(np, "nvidia,phy-reset-gpio", 0);
899 if (!gpio_is_valid(tegra_phy->reset_gpio)) {
900 dev_err(&pdev->dev, "invalid gpio: %d\n",
901 tegra_phy->reset_gpio);
902 return tegra_phy->reset_gpio;
903 }
Mikko Perttunen81d5dfe2013-07-17 09:31:01 +0300904 tegra_phy->config = NULL;
Tuomas Tynkkynen9fdb07f2013-07-25 21:38:08 +0300905 } else {
906 dev_err(&pdev->dev, "phy_type is invalid or unsupported\n");
907 return -EINVAL;
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530908 }
909
Tuomas Tynkkynen6558d7e2013-07-25 21:38:09 +0300910 if (of_find_property(np, "dr_mode", NULL))
911 tegra_phy->mode = of_usb_get_dr_mode(np);
912 else
913 tegra_phy->mode = USB_DR_MODE_HOST;
914
915 if (tegra_phy->mode == USB_DR_MODE_UNKNOWN) {
916 dev_err(&pdev->dev, "dr_mode is invalid\n");
917 return -EINVAL;
918 }
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530919
Mikko Perttunenf5b8c8b2013-07-17 10:37:49 +0300920 /* On some boards, the VBUS regulator doesn't need to be controlled */
921 if (of_find_property(np, "vbus-supply", NULL)) {
922 tegra_phy->vbus = devm_regulator_get(&pdev->dev, "vbus");
923 if (IS_ERR(tegra_phy->vbus))
924 return PTR_ERR(tegra_phy->vbus);
925 } else {
926 dev_notice(&pdev->dev, "no vbus regulator");
927 tegra_phy->vbus = ERR_PTR(-ENODEV);
928 }
929
Tuomas Tynkkynen185d0fd2013-07-25 21:38:01 +0300930 tegra_phy->u_phy.dev = &pdev->dev;
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530931 err = tegra_usb_phy_init(tegra_phy);
932 if (err < 0)
933 return err;
934
935 tegra_phy->u_phy.shutdown = tegra_usb_phy_close;
936 tegra_phy->u_phy.set_suspend = tegra_usb_phy_suspend;
937
938 dev_set_drvdata(&pdev->dev, tegra_phy);
Tuomas Tynkkynen0ee5b4a2013-07-25 21:38:05 +0300939
940 err = usb_add_phy_dev(&tegra_phy->u_phy);
941 if (err < 0) {
942 tegra_usb_phy_close(&tegra_phy->u_phy);
943 return err;
944 }
945
946 return 0;
947}
948
949static int tegra_usb_phy_remove(struct platform_device *pdev)
950{
951 struct tegra_usb_phy *tegra_phy = platform_get_drvdata(pdev);
952
953 usb_remove_phy(&tegra_phy->u_phy);
954
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530955 return 0;
956}
957
958static struct of_device_id tegra_usb_phy_id_table[] = {
959 { .compatible = "nvidia,tegra20-usb-phy", },
960 { },
961};
962MODULE_DEVICE_TABLE(of, tegra_usb_phy_id_table);
963
964static struct platform_driver tegra_usb_phy_driver = {
965 .probe = tegra_usb_phy_probe,
Tuomas Tynkkynen0ee5b4a2013-07-25 21:38:05 +0300966 .remove = tegra_usb_phy_remove,
Venu Byravarasu2d22b422013-05-16 19:43:02 +0530967 .driver = {
968 .name = "tegra-phy",
969 .owner = THIS_MODULE,
970 .of_match_table = of_match_ptr(tegra_usb_phy_id_table),
971 },
972};
973module_platform_driver(tegra_usb_phy_driver);
974
Stephen Warren587376a2013-06-13 11:24:08 -0600975MODULE_DESCRIPTION("Tegra USB PHY driver");
976MODULE_LICENSE("GPL v2");