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