usb.c 17 KB

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