ehci-tegra.c 18 KB

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