]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/armv7/tegra20/usb.c
e4165e04a56f840db204bb557190eb6144285dc0
[karo-tx-uboot.git] / arch / arm / cpu / armv7 / tegra20 / usb.c
1 /*
2  * Copyright (c) 2011 The Chromium OS Authors.
3  * (C) Copyright 2010,2011 NVIDIA Corporation <www.nvidia.com>
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23
24 #include <common.h>
25 #include <asm/io.h>
26 #include <asm-generic/gpio.h>
27 #include <asm/arch/clock.h>
28 #include <asm/arch/gpio.h>
29 #include <asm/arch/pinmux.h>
30 #include <asm/arch/tegra.h>
31 #include <asm/arch/usb.h>
32 #include <usb/ulpi.h>
33 #include <asm/arch-tegra/clk_rst.h>
34 #include <asm/arch-tegra/sys_proto.h>
35 #include <asm/arch-tegra/uart.h>
36 #include <libfdt.h>
37 #include <fdtdec.h>
38
39 #ifdef CONFIG_USB_ULPI
40         #ifndef CONFIG_USB_ULPI_VIEWPORT
41         #error  "To use CONFIG_USB_ULPI on Tegra Boards you have to also \
42                         define CONFIG_USB_ULPI_VIEWPORT"
43         #endif
44 #endif
45
46 enum {
47         USB_PORTS_MAX   = 3,            /* Maximum ports we allow */
48 };
49
50 /* Parameters we need for USB */
51 enum {
52         PARAM_DIVN,                     /* PLL FEEDBACK DIVIDer */
53         PARAM_DIVM,                     /* PLL INPUT DIVIDER */
54         PARAM_DIVP,                     /* POST DIVIDER (2^N) */
55         PARAM_CPCON,                    /* BASE PLLC CHARGE Pump setup ctrl */
56         PARAM_LFCON,                    /* BASE PLLC LOOP FILter setup ctrl */
57         PARAM_ENABLE_DELAY_COUNT,       /* PLL-U Enable Delay Count */
58         PARAM_STABLE_COUNT,             /* PLL-U STABLE count */
59         PARAM_ACTIVE_DELAY_COUNT,       /* PLL-U Active delay count */
60         PARAM_XTAL_FREQ_COUNT,          /* PLL-U XTAL frequency count */
61         PARAM_DEBOUNCE_A_TIME,          /* 10MS DELAY for BIAS_DEBOUNCE_A */
62         PARAM_BIAS_TIME,                /* 20US DELAY AFter bias cell op */
63
64         PARAM_COUNT
65 };
66
67 /* Possible port types (dual role mode) */
68 enum dr_mode {
69         DR_MODE_NONE = 0,
70         DR_MODE_HOST,           /* supports host operation */
71         DR_MODE_DEVICE,         /* supports device operation */
72         DR_MODE_OTG,            /* supports both */
73 };
74
75 /* Information about a USB port */
76 struct fdt_usb {
77         struct usb_ctlr *reg;   /* address of registers in physical memory */
78         unsigned utmi:1;        /* 1 if port has external tranceiver, else 0 */
79         unsigned ulpi:1;        /* 1 if port has external ULPI transceiver */
80         unsigned enabled:1;     /* 1 to enable, 0 to disable */
81         unsigned has_legacy_mode:1; /* 1 if this port has legacy mode */
82         unsigned initialized:1; /* has this port already been initialized? */
83         enum dr_mode dr_mode;   /* dual role mode */
84         enum periph_id periph_id;/* peripheral id */
85         struct fdt_gpio_state vbus_gpio;        /* GPIO for vbus enable */
86         struct fdt_gpio_state phy_reset_gpio; /* GPIO to reset ULPI phy */
87 };
88
89 static struct fdt_usb port[USB_PORTS_MAX];      /* List of valid USB ports */
90 static unsigned port_count;                     /* Number of available ports */
91
92 /*
93  * This table has USB timing parameters for each Oscillator frequency we
94  * support. There are four sets of values:
95  *
96  * 1. PLLU configuration information (reference clock is osc/clk_m and
97  * PLLU-FOs are fixed at 12MHz/60MHz/480MHz).
98  *
99  *  Reference frequency     13.0MHz      19.2MHz      12.0MHz      26.0MHz
100  *  ----------------------------------------------------------------------
101  *      DIVN                960 (0x3c0)  200 (0c8)    960 (3c0h)   960 (3c0)
102  *      DIVM                13 (0d)      4 (04)       12 (0c)      26 (1a)
103  * Filter frequency (MHz)   1            4.8          6            2
104  * CPCON                    1100b        0011b        1100b        1100b
105  * LFCON0                   0            0            0            0
106  *
107  * 2. PLL CONFIGURATION & PARAMETERS for different clock generators:
108  *
109  * Reference frequency     13.0MHz         19.2MHz         12.0MHz     26.0MHz
110  * ---------------------------------------------------------------------------
111  * PLLU_ENABLE_DLY_COUNT   02 (0x02)       03 (03)         02 (02)     04 (04)
112  * PLLU_STABLE_COUNT       51 (33)         75 (4B)         47 (2F)    102 (66)
113  * PLL_ACTIVE_DLY_COUNT    05 (05)         06 (06)         04 (04)     09 (09)
114  * XTAL_FREQ_COUNT        127 (7F)        187 (BB)        118 (76)    254 (FE)
115  *
116  * 3. Debounce values IdDig, Avalid, Bvalid, VbusValid, VbusWakeUp, and
117  * SessEnd. Each of these signals have their own debouncer and for each of
118  * those one out of two debouncing times can be chosen (BIAS_DEBOUNCE_A or
119  * BIAS_DEBOUNCE_B).
120  *
121  * The values of DEBOUNCE_A and DEBOUNCE_B are calculated as follows:
122  *    0xffff -> No debouncing at all
123  *    <n> ms = <n> *1000 / (1/19.2MHz) / 4
124  *
125  * So to program a 1 ms debounce for BIAS_DEBOUNCE_A, we have:
126  * BIAS_DEBOUNCE_A[15:0] = 1000 * 19.2 / 4  = 4800 = 0x12c0
127  *
128  * We need to use only DebounceA for BOOTROM. We don't need the DebounceB
129  * values, so we can keep those to default.
130  *
131  * 4. The 20 microsecond delay after bias cell operation.
132  */
133 static const unsigned usb_pll[CLOCK_OSC_FREQ_COUNT][PARAM_COUNT] = {
134         /* DivN, DivM, DivP, CPCON, LFCON, Delays             Debounce, Bias */
135         { 0x3C0, 0x0D, 0x00, 0xC,   0,  0x02, 0x33, 0x05, 0x7F, 0x7EF4, 5 },
136         { 0x0C8, 0x04, 0x00, 0x3,   0,  0x03, 0x4B, 0x06, 0xBB, 0xBB80, 7 },
137         { 0x3C0, 0x0C, 0x00, 0xC,   0,  0x02, 0x2F, 0x04, 0x76, 0x7530, 5 },
138         { 0x3C0, 0x1A, 0x00, 0xC,   0,  0x04, 0x66, 0x09, 0xFE, 0xFDE8, 9 }
139 };
140
141 /* UTMIP Idle Wait Delay */
142 static const u8 utmip_idle_wait_delay = 17;
143
144 /* UTMIP Elastic limit */
145 static const u8 utmip_elastic_limit = 16;
146
147 /* UTMIP High Speed Sync Start Delay */
148 static const u8 utmip_hs_sync_start_delay = 9;
149
150 /* Put the port into host mode */
151 static void set_host_mode(struct fdt_usb *config)
152 {
153         /*
154          * If we are an OTG port, check if remote host is driving VBus and
155          * bail out in this case.
156          */
157         if (config->dr_mode == DR_MODE_OTG &&
158                 (readl(&config->reg->phy_vbus_sensors) & VBUS_VLD_STS))
159                 return;
160
161         /*
162          * If not driving, we set the GPIO to enable VBUS. We assume
163          * that the pinmux is set up correctly for this.
164          */
165         if (fdt_gpio_isvalid(&config->vbus_gpio)) {
166                 fdtdec_setup_gpio(&config->vbus_gpio);
167                 gpio_direction_output(config->vbus_gpio.gpio,
168                         (config->vbus_gpio.flags & FDT_GPIO_ACTIVE_LOW) ?
169                                  0 : 1);
170                 debug("set_host_mode: GPIO %d %s\n", config->vbus_gpio.gpio,
171                         (config->vbus_gpio.flags & FDT_GPIO_ACTIVE_LOW) ?
172                                 "low" : "high");
173         }
174 }
175
176 void usbf_reset_controller(struct fdt_usb *config, struct usb_ctlr *usbctlr)
177 {
178         /* Reset the USB controller with 2us delay */
179         reset_periph(config->periph_id, 2);
180
181         /*
182          * Set USB1_NO_LEGACY_MODE to 1, Registers are accessible under
183          * base address
184          */
185         if (config->has_legacy_mode)
186                 setbits_le32(&usbctlr->usb1_legacy_ctrl, USB1_NO_LEGACY_MODE);
187
188         /* Put UTMIP1/3 in reset */
189         setbits_le32(&usbctlr->susp_ctrl, UTMIP_RESET);
190
191         /* Enable the UTMIP PHY */
192         if (config->utmi)
193                 setbits_le32(&usbctlr->susp_ctrl, UTMIP_PHY_ENB);
194
195         /*
196          * TODO: where do we take the USB1 out of reset? The old code would
197          * take USB3 out of reset, but not USB1. This code doesn't do either.
198          */
199 }
200
201 /* set up the UTMI USB controller with the parameters provided */
202 static int init_utmi_usb_controller(struct fdt_usb *config)
203 {
204         u32 val;
205         int loop_count;
206         const unsigned *timing;
207         struct usb_ctlr *usbctlr = config->reg;
208
209         clock_enable(config->periph_id);
210
211         /* Reset the usb controller */
212         usbf_reset_controller(config, usbctlr);
213
214         /* Stop crystal clock by setting UTMIP_PHY_XTAL_CLOCKEN low */
215         clrbits_le32(&usbctlr->utmip_misc_cfg1, UTMIP_PHY_XTAL_CLOCKEN);
216
217         /* Follow the crystal clock disable by >100ns delay */
218         udelay(1);
219
220         /*
221          * To Use the A Session Valid for cable detection logic, VBUS_WAKEUP
222          * mux must be switched to actually use a_sess_vld threshold.
223          */
224         if (fdt_gpio_isvalid(&config->vbus_gpio)) {
225                 clrsetbits_le32(&usbctlr->usb1_legacy_ctrl,
226                         VBUS_SENSE_CTL_MASK,
227                         VBUS_SENSE_CTL_A_SESS_VLD << VBUS_SENSE_CTL_SHIFT);
228         }
229
230         /*
231          * PLL Delay CONFIGURATION settings. The following parameters control
232          * the bring up of the plls.
233          */
234         timing = usb_pll[clock_get_osc_freq()];
235
236         val = readl(&usbctlr->utmip_misc_cfg1);
237         clrsetbits_le32(&val, UTMIP_PLLU_STABLE_COUNT_MASK,
238                 timing[PARAM_STABLE_COUNT] << UTMIP_PLLU_STABLE_COUNT_SHIFT);
239         clrsetbits_le32(&val, UTMIP_PLL_ACTIVE_DLY_COUNT_MASK,
240                 timing[PARAM_ACTIVE_DELAY_COUNT] <<
241                         UTMIP_PLL_ACTIVE_DLY_COUNT_SHIFT);
242         writel(val, &usbctlr->utmip_misc_cfg1);
243
244         /* Set PLL enable delay count and crystal frequency count */
245         val = readl(&usbctlr->utmip_pll_cfg1);
246         clrsetbits_le32(&val, UTMIP_PLLU_ENABLE_DLY_COUNT_MASK,
247                 timing[PARAM_ENABLE_DELAY_COUNT] <<
248                         UTMIP_PLLU_ENABLE_DLY_COUNT_SHIFT);
249         clrsetbits_le32(&val, UTMIP_XTAL_FREQ_COUNT_MASK,
250                 timing[PARAM_XTAL_FREQ_COUNT] <<
251                         UTMIP_XTAL_FREQ_COUNT_SHIFT);
252         writel(val, &usbctlr->utmip_pll_cfg1);
253
254         /* Setting the tracking length time */
255         clrsetbits_le32(&usbctlr->utmip_bias_cfg1,
256                 UTMIP_BIAS_PDTRK_COUNT_MASK,
257                 timing[PARAM_BIAS_TIME] << UTMIP_BIAS_PDTRK_COUNT_SHIFT);
258
259         /* Program debounce time for VBUS to become valid */
260         clrsetbits_le32(&usbctlr->utmip_debounce_cfg0,
261                 UTMIP_DEBOUNCE_CFG0_MASK,
262                 timing[PARAM_DEBOUNCE_A_TIME] << UTMIP_DEBOUNCE_CFG0_SHIFT);
263
264         setbits_le32(&usbctlr->utmip_tx_cfg0, UTMIP_FS_PREAMBLE_J);
265
266         /* Disable battery charge enabling bit */
267         setbits_le32(&usbctlr->utmip_bat_chrg_cfg0, UTMIP_PD_CHRG);
268
269         clrbits_le32(&usbctlr->utmip_xcvr_cfg0, UTMIP_XCVR_LSBIAS_SE);
270         setbits_le32(&usbctlr->utmip_spare_cfg0, FUSE_SETUP_SEL);
271
272         /*
273          * Configure the UTMIP_IDLE_WAIT and UTMIP_ELASTIC_LIMIT
274          * Setting these fields, together with default values of the
275          * other fields, results in programming the registers below as
276          * follows:
277          *         UTMIP_HSRX_CFG0 = 0x9168c000
278          *         UTMIP_HSRX_CFG1 = 0x13
279          */
280
281         /* Set PLL enable delay count and Crystal frequency count */
282         val = readl(&usbctlr->utmip_hsrx_cfg0);
283         clrsetbits_le32(&val, UTMIP_IDLE_WAIT_MASK,
284                 utmip_idle_wait_delay << UTMIP_IDLE_WAIT_SHIFT);
285         clrsetbits_le32(&val, UTMIP_ELASTIC_LIMIT_MASK,
286                 utmip_elastic_limit << UTMIP_ELASTIC_LIMIT_SHIFT);
287         writel(val, &usbctlr->utmip_hsrx_cfg0);
288
289         /* Configure the UTMIP_HS_SYNC_START_DLY */
290         clrsetbits_le32(&usbctlr->utmip_hsrx_cfg1,
291                 UTMIP_HS_SYNC_START_DLY_MASK,
292                 utmip_hs_sync_start_delay << UTMIP_HS_SYNC_START_DLY_SHIFT);
293
294         /* Preceed the crystal clock disable by >100ns delay. */
295         udelay(1);
296
297         /* Resuscitate crystal clock by setting UTMIP_PHY_XTAL_CLOCKEN */
298         setbits_le32(&usbctlr->utmip_misc_cfg1, UTMIP_PHY_XTAL_CLOCKEN);
299
300         /* Finished the per-controller init. */
301
302         /* De-assert UTMIP_RESET to bring out of reset. */
303         clrbits_le32(&usbctlr->susp_ctrl, UTMIP_RESET);
304
305         /* Wait for the phy clock to become valid in 100 ms */
306         for (loop_count = 100000; loop_count != 0; loop_count--) {
307                 if (readl(&usbctlr->susp_ctrl) & USB_PHY_CLK_VALID)
308                         break;
309                 udelay(1);
310         }
311         if (!loop_count)
312                 return -1;
313
314         /* Disable ICUSB FS/LS transceiver */
315         clrbits_le32(&usbctlr->icusb_ctrl, IC_ENB1);
316
317         /* Select UTMI parallel interface */
318         clrsetbits_le32(&usbctlr->port_sc1, PTS_MASK,
319                         PTS_UTMI << PTS_SHIFT);
320         clrbits_le32(&usbctlr->port_sc1, STS);
321
322         /* Deassert power down state */
323         clrbits_le32(&usbctlr->utmip_xcvr_cfg0, UTMIP_FORCE_PD_POWERDOWN |
324                 UTMIP_FORCE_PD2_POWERDOWN | UTMIP_FORCE_PDZI_POWERDOWN);
325         clrbits_le32(&usbctlr->utmip_xcvr_cfg1, UTMIP_FORCE_PDDISC_POWERDOWN |
326                 UTMIP_FORCE_PDCHRP_POWERDOWN | UTMIP_FORCE_PDDR_POWERDOWN);
327
328         return 0;
329 }
330
331 #ifdef CONFIG_USB_ULPI
332 /* if board file does not set a ULPI reference frequency we default to 24MHz */
333 #ifndef CONFIG_ULPI_REF_CLK
334 #define CONFIG_ULPI_REF_CLK 24000000
335 #endif
336
337 /* set up the ULPI USB controller with the parameters provided */
338 static int init_ulpi_usb_controller(struct fdt_usb *config)
339 {
340         u32 val;
341         int loop_count;
342         struct ulpi_viewport ulpi_vp;
343         struct usb_ctlr *usbctlr = config->reg;
344
345         /* set up ULPI reference clock on pllp_out4 */
346         clock_enable(PERIPH_ID_DEV2_OUT);
347         clock_set_pllout(CLOCK_ID_PERIPH, PLL_OUT4, CONFIG_ULPI_REF_CLK);
348
349         /* reset ULPI phy */
350         if (fdt_gpio_isvalid(&config->phy_reset_gpio)) {
351                 fdtdec_setup_gpio(&config->phy_reset_gpio);
352                 gpio_direction_output(config->phy_reset_gpio.gpio, 0);
353                 mdelay(5);
354                 gpio_set_value(config->phy_reset_gpio.gpio, 1);
355         }
356
357         /* Reset the usb controller */
358         clock_enable(config->periph_id);
359         usbf_reset_controller(config, usbctlr);
360
361         /* enable pinmux bypass */
362         setbits_le32(&usbctlr->ulpi_timing_ctrl_0,
363                         ULPI_CLKOUT_PINMUX_BYP | ULPI_OUTPUT_PINMUX_BYP);
364
365         /* Select ULPI parallel interface */
366         clrsetbits_le32(&usbctlr->port_sc1, PTS_MASK, PTS_ULPI << PTS_SHIFT);
367
368         /* enable ULPI transceiver */
369         setbits_le32(&usbctlr->susp_ctrl, ULPI_PHY_ENB);
370
371         /* configure ULPI transceiver timings */
372         val = 0;
373         writel(val, &usbctlr->ulpi_timing_ctrl_1);
374
375         val |= ULPI_DATA_TRIMMER_SEL(4);
376         val |= ULPI_STPDIRNXT_TRIMMER_SEL(4);
377         val |= ULPI_DIR_TRIMMER_SEL(4);
378         writel(val, &usbctlr->ulpi_timing_ctrl_1);
379         udelay(10);
380
381         val |= ULPI_DATA_TRIMMER_LOAD;
382         val |= ULPI_STPDIRNXT_TRIMMER_LOAD;
383         val |= ULPI_DIR_TRIMMER_LOAD;
384         writel(val, &usbctlr->ulpi_timing_ctrl_1);
385
386         /* set up phy for host operation with external vbus supply */
387         ulpi_vp.port_num = 0;
388         ulpi_vp.viewport_addr = (u32)&usbctlr->ulpi_viewport;
389
390         if (ulpi_init(&ulpi_vp)) {
391                 printf("Tegra ULPI viewport init failed\n");
392                 return -1;
393         }
394
395         ulpi_set_vbus(&ulpi_vp, 1, 1);
396         ulpi_set_vbus_indicator(&ulpi_vp, 1, 1, 0);
397
398         /* enable wakeup events */
399         setbits_le32(&usbctlr->port_sc1, WKCN | WKDS | WKOC);
400
401         /* Enable and wait for the phy clock to become valid in 100 ms */
402         setbits_le32(&usbctlr->susp_ctrl, USB_SUSP_CLR);
403         for (loop_count = 100000; loop_count != 0; loop_count--) {
404                 if (readl(&usbctlr->susp_ctrl) & USB_PHY_CLK_VALID)
405                         break;
406                 udelay(1);
407         }
408         if (!loop_count)
409                 return -1;
410         clrbits_le32(&usbctlr->susp_ctrl, USB_SUSP_CLR);
411
412         return 0;
413 }
414 #else
415 static int init_ulpi_usb_controller(struct fdt_usb *config)
416 {
417         printf("No code to set up ULPI controller, please enable"
418                         "CONFIG_USB_ULPI and CONFIG_USB_ULPI_VIEWPORT");
419         return -1;
420 }
421 #endif
422
423 static void config_clock(const u32 timing[])
424 {
425         clock_start_pll(CLOCK_ID_USB,
426                 timing[PARAM_DIVM], timing[PARAM_DIVN], timing[PARAM_DIVP],
427                 timing[PARAM_CPCON], timing[PARAM_LFCON]);
428 }
429
430 int tegrausb_start_port(int portnum, u32 *hccr, u32 *hcor)
431 {
432         struct fdt_usb *config;
433         struct usb_ctlr *usbctlr;
434
435         if (portnum >= port_count)
436                 return -1;
437
438         config = &port[portnum];
439
440         /* skip init, if the port is already initialized */
441         if (config->initialized)
442                 goto success;
443
444         if (config->utmi && init_utmi_usb_controller(config)) {
445                 printf("tegrausb: Cannot init port %d\n", portnum);
446                 return -1;
447         }
448
449         if (config->ulpi && init_ulpi_usb_controller(config)) {
450                 printf("tegrausb: Cannot init port %d\n", portnum);
451                 return -1;
452         }
453
454         set_host_mode(config);
455
456         config->initialized = 1;
457
458 success:
459         usbctlr = config->reg;
460         *hccr = (u32)&usbctlr->cap_length;
461         *hcor = (u32)&usbctlr->usb_cmd;
462         return 0;
463 }
464
465 int tegrausb_stop_port(int portnum)
466 {
467         struct usb_ctlr *usbctlr;
468
469         usbctlr = port[portnum].reg;
470
471         /* Stop controller */
472         writel(0, &usbctlr->usb_cmd);
473         udelay(1000);
474
475         /* Initiate controller reset */
476         writel(2, &usbctlr->usb_cmd);
477         udelay(1000);
478
479         port[portnum].initialized = 0;
480
481         return 0;
482 }
483
484 int fdt_decode_usb(const void *blob, int node, struct fdt_usb *config)
485 {
486         const char *phy, *mode;
487
488         config->reg = (struct usb_ctlr *)fdtdec_get_addr(blob, node, "reg");
489         mode = fdt_getprop(blob, node, "dr_mode", NULL);
490         if (mode) {
491                 if (0 == strcmp(mode, "host"))
492                         config->dr_mode = DR_MODE_HOST;
493                 else if (0 == strcmp(mode, "peripheral"))
494                         config->dr_mode = DR_MODE_DEVICE;
495                 else if (0 == strcmp(mode, "otg"))
496                         config->dr_mode = DR_MODE_OTG;
497                 else {
498                         debug("%s: Cannot decode dr_mode '%s'\n", __func__,
499                               mode);
500                         return -FDT_ERR_NOTFOUND;
501                 }
502         } else {
503                 config->dr_mode = DR_MODE_HOST;
504         }
505
506         phy = fdt_getprop(blob, node, "phy_type", NULL);
507         config->utmi = phy && 0 == strcmp("utmi", phy);
508         config->ulpi = phy && 0 == strcmp("ulpi", phy);
509         config->enabled = fdtdec_get_is_enabled(blob, node);
510         config->has_legacy_mode = fdtdec_get_bool(blob, node,
511                                                   "nvidia,has-legacy-mode");
512         config->periph_id = clock_decode_periph_id(blob, node);
513         if (config->periph_id == PERIPH_ID_NONE) {
514                 debug("%s: Missing/invalid peripheral ID\n", __func__);
515                 return -FDT_ERR_NOTFOUND;
516         }
517         fdtdec_decode_gpio(blob, node, "nvidia,vbus-gpio", &config->vbus_gpio);
518         fdtdec_decode_gpio(blob, node, "nvidia,phy-reset-gpio",
519                         &config->phy_reset_gpio);
520         debug("enabled=%d, legacy_mode=%d, utmi=%d, ulpi=%d, periph_id=%d, "
521                 "vbus=%d, phy_reset=%d, dr_mode=%d\n",
522                 config->enabled, config->has_legacy_mode, config->utmi,
523                 config->ulpi, config->periph_id, config->vbus_gpio.gpio,
524                 config->phy_reset_gpio.gpio, config->dr_mode);
525
526         return 0;
527 }
528
529 int board_usb_init(const void *blob)
530 {
531         struct fdt_usb config;
532         enum clock_osc_freq freq;
533         int node_list[USB_PORTS_MAX];
534         int node, count, i;
535
536         /* Set up the USB clocks correctly based on our oscillator frequency */
537         freq = clock_get_osc_freq();
538         config_clock(usb_pll[freq]);
539
540         /* count may return <0 on error */
541         count = fdtdec_find_aliases_for_id(blob, "usb",
542                         COMPAT_NVIDIA_TEGRA20_USB, node_list, USB_PORTS_MAX);
543         for (i = 0; i < count; i++) {
544                 if (port_count == USB_PORTS_MAX) {
545                         printf("tegrausb: Cannot register more than %d ports\n",
546                                 USB_PORTS_MAX);
547                         return -1;
548                 }
549
550                 debug("USB %d: ", i);
551                 node = node_list[i];
552                 if (!node)
553                         continue;
554                 if (fdt_decode_usb(blob, node, &config)) {
555                         debug("Cannot decode USB node %s\n",
556                               fdt_get_name(blob, node, NULL));
557                         return -1;
558                 }
559                 config.initialized = 0;
560
561                 /* add new USB port to the list of available ports */
562                 port[port_count++] = config;
563         }
564
565         return 0;
566 }