board.c 4.8 KB

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