board2.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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 <errno.h>
  10. #include <ns16550.h>
  11. #include <linux/compiler.h>
  12. #include <asm/io.h>
  13. #include <asm/arch/clock.h>
  14. #ifdef CONFIG_LCD
  15. #include <asm/arch/display.h>
  16. #endif
  17. #include <asm/arch/funcmux.h>
  18. #include <asm/arch/pinmux.h>
  19. #include <asm/arch/pmu.h>
  20. #ifdef CONFIG_PWM_TEGRA
  21. #include <asm/arch/pwm.h>
  22. #endif
  23. #include <asm/arch/tegra.h>
  24. #include <asm/arch-tegra/ap.h>
  25. #include <asm/arch-tegra/board.h>
  26. #include <asm/arch-tegra/clk_rst.h>
  27. #include <asm/arch-tegra/pmc.h>
  28. #include <asm/arch-tegra/sys_proto.h>
  29. #include <asm/arch-tegra/uart.h>
  30. #include <asm/arch-tegra/warmboot.h>
  31. #include <asm/arch-tegra/gpu.h>
  32. #ifdef CONFIG_TEGRA_CLOCK_SCALING
  33. #include <asm/arch/emc.h>
  34. #endif
  35. #ifdef CONFIG_USB_EHCI_TEGRA
  36. #include <asm/arch-tegra/usb.h>
  37. #include <usb.h>
  38. #endif
  39. #ifdef CONFIG_TEGRA_MMC
  40. #include <asm/arch-tegra/tegra_mmc.h>
  41. #include <asm/arch-tegra/mmc.h>
  42. #endif
  43. #include <asm/arch-tegra/xusb-padctl.h>
  44. #include <power/as3722.h>
  45. #include <i2c.h>
  46. #include <spi.h>
  47. #include "emc.h"
  48. DECLARE_GLOBAL_DATA_PTR;
  49. #ifdef CONFIG_SPL_BUILD
  50. /* TODO(sjg@chromium.org): Remove once SPL supports device tree */
  51. U_BOOT_DEVICE(tegra_gpios) = {
  52. "gpio_tegra"
  53. };
  54. #endif
  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. __weak void start_cpu_fan(void) {}
  61. #if defined(CONFIG_TEGRA_NAND)
  62. __weak void pin_mux_nand(void)
  63. {
  64. funcmux_select(PERIPH_ID_NDFLASH, FUNCMUX_DEFAULT);
  65. }
  66. #endif
  67. /*
  68. * Routine: power_det_init
  69. * Description: turn off power detects
  70. */
  71. static void power_det_init(void)
  72. {
  73. #if defined(CONFIG_TEGRA20)
  74. struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  75. /* turn off power detects */
  76. writel(0, &pmc->pmc_pwr_det_latch);
  77. writel(0, &pmc->pmc_pwr_det);
  78. #endif
  79. }
  80. __weak int tegra_board_id(void)
  81. {
  82. return -1;
  83. }
  84. #ifdef CONFIG_DISPLAY_BOARDINFO
  85. int checkboard(void)
  86. {
  87. int board_id = tegra_board_id();
  88. printf("Board: %s", CONFIG_TEGRA_BOARD_STRING);
  89. if (board_id != -1)
  90. printf(", ID: %d\n", board_id);
  91. printf("\n");
  92. return 0;
  93. }
  94. #endif /* CONFIG_DISPLAY_BOARDINFO */
  95. __weak int tegra_lcd_pmic_init(int board_it)
  96. {
  97. return 0;
  98. }
  99. __weak int nvidia_board_init(void)
  100. {
  101. return 0;
  102. }
  103. /*
  104. * Routine: board_init
  105. * Description: Early hardware init.
  106. */
  107. int board_init(void)
  108. {
  109. __maybe_unused int err;
  110. __maybe_unused int board_id;
  111. /* Do clocks and UART first so that printf() works */
  112. clock_init();
  113. clock_verify();
  114. config_gpu();
  115. #ifdef CONFIG_TEGRA_SPI
  116. pin_mux_spi();
  117. #endif
  118. #ifdef CONFIG_PWM_TEGRA
  119. if (pwm_init(gd->fdt_blob))
  120. debug("%s: Failed to init pwm\n", __func__);
  121. #endif
  122. #ifdef CONFIG_LCD
  123. pin_mux_display();
  124. tegra_lcd_check_next_stage(gd->fdt_blob, 0);
  125. #endif
  126. /* boot param addr */
  127. gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100);
  128. power_det_init();
  129. #ifdef CONFIG_SYS_I2C_TEGRA
  130. # ifdef CONFIG_TEGRA_PMU
  131. if (pmu_set_nominal())
  132. debug("Failed to select nominal voltages\n");
  133. # ifdef CONFIG_TEGRA_CLOCK_SCALING
  134. err = board_emc_init();
  135. if (err)
  136. debug("Memory controller init failed: %d\n", err);
  137. # endif
  138. # endif /* CONFIG_TEGRA_PMU */
  139. #ifdef CONFIG_AS3722_POWER
  140. err = as3722_init(NULL);
  141. if (err && err != -ENODEV)
  142. return err;
  143. #endif
  144. #endif /* CONFIG_SYS_I2C_TEGRA */
  145. #ifdef CONFIG_USB_EHCI_TEGRA
  146. pin_mux_usb();
  147. #endif
  148. #ifdef CONFIG_LCD
  149. board_id = tegra_board_id();
  150. err = tegra_lcd_pmic_init(board_id);
  151. if (err)
  152. return err;
  153. tegra_lcd_check_next_stage(gd->fdt_blob, 0);
  154. #endif
  155. #ifdef CONFIG_TEGRA_NAND
  156. pin_mux_nand();
  157. #endif
  158. tegra_xusb_padctl_init(gd->fdt_blob);
  159. #ifdef CONFIG_TEGRA_LP0
  160. /* save Sdram params to PMC 2, 4, and 24 for WB0 */
  161. warmboot_save_sdram_params();
  162. /* prepare the WB code to LP0 location */
  163. warmboot_prepare_code(TEGRA_LP0_ADDR, TEGRA_LP0_SIZE);
  164. #endif
  165. return nvidia_board_init();
  166. }
  167. #ifdef CONFIG_BOARD_EARLY_INIT_F
  168. static void __gpio_early_init(void)
  169. {
  170. }
  171. void gpio_early_init(void) __attribute__((weak, alias("__gpio_early_init")));
  172. int board_early_init_f(void)
  173. {
  174. /* Do any special system timer/TSC setup */
  175. #if defined(CONFIG_TEGRA_SUPPORT_NON_SECURE)
  176. if (!tegra_cpu_is_non_secure())
  177. #endif
  178. arch_timer_init();
  179. pinmux_init();
  180. board_init_uart_f();
  181. /* Initialize periph GPIOs */
  182. gpio_early_init();
  183. gpio_early_init_uart();
  184. #ifdef CONFIG_LCD
  185. tegra_lcd_early_init(gd->fdt_blob);
  186. #endif
  187. return 0;
  188. }
  189. #endif /* EARLY_INIT */
  190. int board_late_init(void)
  191. {
  192. #ifdef CONFIG_LCD
  193. /* Make sure we finish initing the LCD */
  194. tegra_lcd_check_next_stage(gd->fdt_blob, 1);
  195. #endif
  196. #if defined(CONFIG_TEGRA_SUPPORT_NON_SECURE)
  197. if (tegra_cpu_is_non_secure()) {
  198. printf("CPU is in NS mode\n");
  199. setenv("cpu_ns_mode", "1");
  200. } else {
  201. setenv("cpu_ns_mode", "");
  202. }
  203. #endif
  204. start_cpu_fan();
  205. return 0;
  206. }
  207. #if defined(CONFIG_TEGRA_MMC)
  208. __weak void pin_mux_mmc(void)
  209. {
  210. }
  211. /* this is a weak define that we are overriding */
  212. int board_mmc_init(bd_t *bd)
  213. {
  214. debug("%s called\n", __func__);
  215. /* Enable muxes, etc. for SDMMC controllers */
  216. pin_mux_mmc();
  217. debug("%s: init MMC\n", __func__);
  218. tegra_mmc_init();
  219. return 0;
  220. }
  221. void pad_init_mmc(struct mmc_host *host)
  222. {
  223. #if defined(CONFIG_TEGRA30)
  224. enum periph_id id = host->mmc_id;
  225. u32 val;
  226. debug("%s: sdmmc address = %08x, id = %d\n", __func__,
  227. (unsigned int)host->reg, id);
  228. /* Set the pad drive strength for SDMMC1 or 3 only */
  229. if (id != PERIPH_ID_SDMMC1 && id != PERIPH_ID_SDMMC3) {
  230. debug("%s: settings are only valid for SDMMC1/SDMMC3!\n",
  231. __func__);
  232. return;
  233. }
  234. val = readl(&host->reg->sdmemcmppadctl);
  235. val &= 0xFFFFFFF0;
  236. val |= MEMCOMP_PADCTRL_VREF;
  237. writel(val, &host->reg->sdmemcmppadctl);
  238. val = readl(&host->reg->autocalcfg);
  239. val &= 0xFFFF0000;
  240. val |= AUTO_CAL_PU_OFFSET | AUTO_CAL_PD_OFFSET | AUTO_CAL_ENABLED;
  241. writel(val, &host->reg->autocalcfg);
  242. #endif /* T30 */
  243. }
  244. #endif /* MMC */
  245. #ifdef CONFIG_ARM64
  246. /*
  247. * Most hardware on 64-bit Tegra is still restricted to DMA to the lower
  248. * 32-bits of the physical address space. Cap the maximum usable RAM area
  249. * at 4 GiB to avoid DMA buffers from being allocated beyond the 32-bit
  250. * boundary that most devices can address.
  251. *
  252. * Additionally, ARM64 devices typically run a secure monitor in EL3 and
  253. * U-Boot in EL2, and set up some secure RAM carve-outs to contain the EL3
  254. * code and data. These carve-outs are located at the top of 32-bit address
  255. * space. Restrict U-Boot's RAM usage to well below the location of those
  256. * carve-outs. Ideally, we would the secure monitor would inform U-Boot of
  257. * exactly which RAM it could use at run-time. However, I'm not sure how to
  258. * do that at present (and even if such a mechanism does exist, it would
  259. * likely not be generic across all forms of secure monitor).
  260. */
  261. ulong board_get_usable_ram_top(ulong total_size)
  262. {
  263. if (gd->ram_top > 0xe0000000)
  264. return 0xe0000000;
  265. return gd->ram_top;
  266. }
  267. #endif