board.c 5.2 KB

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