board.c 5.0 KB

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