board.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * (C) Copyright 2010,2011
  3. * NVIDIA Corporation <www.nvidia.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <dm.h>
  9. #include <ns16550.h>
  10. #include <linux/compiler.h>
  11. #include <asm/io.h>
  12. #include <asm/arch/clock.h>
  13. #ifdef CONFIG_LCD
  14. #include <asm/arch/display.h>
  15. #endif
  16. #include <asm/arch/funcmux.h>
  17. #include <asm/arch/pinmux.h>
  18. #include <asm/arch/pmu.h>
  19. #ifdef CONFIG_PWM_TEGRA
  20. #include <asm/arch/pwm.h>
  21. #endif
  22. #include <asm/arch/tegra.h>
  23. #include <asm/arch-tegra/board.h>
  24. #include <asm/arch-tegra/clk_rst.h>
  25. #include <asm/arch-tegra/pmc.h>
  26. #include <asm/arch-tegra/sys_proto.h>
  27. #include <asm/arch-tegra/uart.h>
  28. #include <asm/arch-tegra/warmboot.h>
  29. #ifdef CONFIG_TEGRA_CLOCK_SCALING
  30. #include <asm/arch/emc.h>
  31. #endif
  32. #ifdef CONFIG_USB_EHCI_TEGRA
  33. #include <asm/arch-tegra/usb.h>
  34. #include <usb.h>
  35. #endif
  36. #ifdef CONFIG_TEGRA_MMC
  37. #include <asm/arch-tegra/tegra_mmc.h>
  38. #include <asm/arch-tegra/mmc.h>
  39. #endif
  40. #include <asm/arch-tegra/xusb-padctl.h>
  41. #include <i2c.h>
  42. #include <spi.h>
  43. #include "emc.h"
  44. DECLARE_GLOBAL_DATA_PTR;
  45. #ifdef CONFIG_SPL_BUILD
  46. /* TODO(sjg@chromium.org): Remove once SPL supports device tree */
  47. U_BOOT_DEVICE(tegra_gpios) = {
  48. "gpio_tegra"
  49. };
  50. #endif
  51. const struct tegra_sysinfo sysinfo = {
  52. CONFIG_TEGRA_BOARD_STRING
  53. };
  54. __weak void pinmux_init(void) {}
  55. __weak void pin_mux_usb(void) {}
  56. __weak void pin_mux_spi(void) {}
  57. __weak void gpio_early_init_uart(void) {}
  58. __weak void pin_mux_display(void) {}
  59. #if defined(CONFIG_TEGRA_NAND)
  60. __weak void pin_mux_nand(void)
  61. {
  62. funcmux_select(PERIPH_ID_NDFLASH, FUNCMUX_DEFAULT);
  63. }
  64. #endif
  65. /*
  66. * Routine: power_det_init
  67. * Description: turn off power detects
  68. */
  69. static void power_det_init(void)
  70. {
  71. #if defined(CONFIG_TEGRA20)
  72. struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  73. /* turn off power detects */
  74. writel(0, &pmc->pmc_pwr_det_latch);
  75. writel(0, &pmc->pmc_pwr_det);
  76. #endif
  77. }
  78. /*
  79. * Routine: board_init
  80. * Description: Early hardware init.
  81. */
  82. int board_init(void)
  83. {
  84. __maybe_unused int err;
  85. /* Do clocks and UART first so that printf() works */
  86. clock_init();
  87. clock_verify();
  88. #ifdef CONFIG_TEGRA_SPI
  89. pin_mux_spi();
  90. #endif
  91. #ifdef CONFIG_PWM_TEGRA
  92. if (pwm_init(gd->fdt_blob))
  93. debug("%s: Failed to init pwm\n", __func__);
  94. #endif
  95. #ifdef CONFIG_LCD
  96. pin_mux_display();
  97. tegra_lcd_check_next_stage(gd->fdt_blob, 0);
  98. #endif
  99. /* boot param addr */
  100. gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100);
  101. power_det_init();
  102. #ifdef CONFIG_SYS_I2C_TEGRA
  103. # ifdef CONFIG_TEGRA_PMU
  104. if (pmu_set_nominal())
  105. debug("Failed to select nominal voltages\n");
  106. # ifdef CONFIG_TEGRA_CLOCK_SCALING
  107. err = board_emc_init();
  108. if (err)
  109. debug("Memory controller init failed: %d\n", err);
  110. # endif
  111. # endif /* CONFIG_TEGRA_PMU */
  112. #endif /* CONFIG_SYS_I2C_TEGRA */
  113. #ifdef CONFIG_USB_EHCI_TEGRA
  114. pin_mux_usb();
  115. usb_process_devicetree(gd->fdt_blob);
  116. #endif
  117. #ifdef CONFIG_LCD
  118. tegra_lcd_check_next_stage(gd->fdt_blob, 0);
  119. #endif
  120. #ifdef CONFIG_TEGRA_NAND
  121. pin_mux_nand();
  122. #endif
  123. tegra_xusb_padctl_init(gd->fdt_blob);
  124. #ifdef CONFIG_TEGRA_LP0
  125. /* save Sdram params to PMC 2, 4, and 24 for WB0 */
  126. warmboot_save_sdram_params();
  127. /* prepare the WB code to LP0 location */
  128. warmboot_prepare_code(TEGRA_LP0_ADDR, TEGRA_LP0_SIZE);
  129. #endif
  130. return 0;
  131. }
  132. #ifdef CONFIG_BOARD_EARLY_INIT_F
  133. static void __gpio_early_init(void)
  134. {
  135. }
  136. void gpio_early_init(void) __attribute__((weak, alias("__gpio_early_init")));
  137. int board_early_init_f(void)
  138. {
  139. pinmux_init();
  140. board_init_uart_f();
  141. /* Initialize periph GPIOs */
  142. gpio_early_init();
  143. gpio_early_init_uart();
  144. #ifdef CONFIG_LCD
  145. tegra_lcd_early_init(gd->fdt_blob);
  146. #endif
  147. return 0;
  148. }
  149. #endif /* EARLY_INIT */
  150. int board_late_init(void)
  151. {
  152. #ifdef CONFIG_LCD
  153. /* Make sure we finish initing the LCD */
  154. tegra_lcd_check_next_stage(gd->fdt_blob, 1);
  155. #endif
  156. return 0;
  157. }
  158. #if defined(CONFIG_TEGRA_MMC)
  159. __weak void pin_mux_mmc(void)
  160. {
  161. }
  162. /* this is a weak define that we are overriding */
  163. int board_mmc_init(bd_t *bd)
  164. {
  165. debug("%s called\n", __func__);
  166. /* Enable muxes, etc. for SDMMC controllers */
  167. pin_mux_mmc();
  168. debug("%s: init MMC\n", __func__);
  169. tegra_mmc_init();
  170. return 0;
  171. }
  172. void pad_init_mmc(struct mmc_host *host)
  173. {
  174. #if defined(CONFIG_TEGRA30)
  175. enum periph_id id = host->mmc_id;
  176. u32 val;
  177. debug("%s: sdmmc address = %08x, id = %d\n", __func__,
  178. (unsigned int)host->reg, id);
  179. /* Set the pad drive strength for SDMMC1 or 3 only */
  180. if (id != PERIPH_ID_SDMMC1 && id != PERIPH_ID_SDMMC3) {
  181. debug("%s: settings are only valid for SDMMC1/SDMMC3!\n",
  182. __func__);
  183. return;
  184. }
  185. val = readl(&host->reg->sdmemcmppadctl);
  186. val &= 0xFFFFFFF0;
  187. val |= MEMCOMP_PADCTRL_VREF;
  188. writel(val, &host->reg->sdmemcmppadctl);
  189. val = readl(&host->reg->autocalcfg);
  190. val &= 0xFFFF0000;
  191. val |= AUTO_CAL_PU_OFFSET | AUTO_CAL_PD_OFFSET | AUTO_CAL_ENABLED;
  192. writel(val, &host->reg->autocalcfg);
  193. #endif /* T30 */
  194. }
  195. #endif /* MMC */