board.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * (C) Copyright 2010-2015
  3. * NVIDIA Corporation <www.nvidia.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <spl.h>
  9. #include <asm/io.h>
  10. #include <asm/arch/clock.h>
  11. #include <asm/arch/funcmux.h>
  12. #include <asm/arch/mc.h>
  13. #include <asm/arch/tegra.h>
  14. #include <asm/arch-tegra/ap.h>
  15. #include <asm/arch-tegra/board.h>
  16. #include <asm/arch-tegra/pmc.h>
  17. #include <asm/arch-tegra/sys_proto.h>
  18. #include <asm/arch-tegra/warmboot.h>
  19. void save_boot_params_ret(void);
  20. DECLARE_GLOBAL_DATA_PTR;
  21. enum {
  22. /* UARTs which we can enable */
  23. UARTA = 1 << 0,
  24. UARTB = 1 << 1,
  25. UARTC = 1 << 2,
  26. UARTD = 1 << 3,
  27. UARTE = 1 << 4,
  28. UART_COUNT = 5,
  29. };
  30. static bool from_spl __attribute__ ((section(".data")));
  31. #ifndef CONFIG_SPL_BUILD
  32. void save_boot_params(u32 r0, u32 r1, u32 r2, u32 r3)
  33. {
  34. from_spl = r0 != UBOOT_NOT_LOADED_FROM_SPL;
  35. save_boot_params_ret();
  36. }
  37. #endif
  38. bool spl_was_boot_source(void)
  39. {
  40. return from_spl;
  41. }
  42. #if defined(CONFIG_TEGRA_SUPPORT_NON_SECURE)
  43. #if !defined(CONFIG_TEGRA124)
  44. #error tegra_cpu_is_non_secure has only been validated on Tegra124
  45. #endif
  46. bool tegra_cpu_is_non_secure(void)
  47. {
  48. /*
  49. * This register reads 0xffffffff in non-secure mode. This register
  50. * only implements bits 31:20, so the lower bits will always read 0 in
  51. * secure mode. Thus, the lower bits are an indicator for secure vs.
  52. * non-secure mode.
  53. */
  54. struct mc_ctlr *mc = (struct mc_ctlr *)NV_PA_MC_BASE;
  55. uint32_t mc_s_cfg0 = readl(&mc->mc_security_cfg0);
  56. return (mc_s_cfg0 & 1) == 1;
  57. }
  58. #endif
  59. /* Read the RAM size directly from the memory controller */
  60. unsigned int query_sdram_size(void)
  61. {
  62. struct mc_ctlr *const mc = (struct mc_ctlr *)NV_PA_MC_BASE;
  63. u32 emem_cfg, size_bytes;
  64. emem_cfg = readl(&mc->mc_emem_cfg);
  65. #if defined(CONFIG_TEGRA20)
  66. debug("mc->mc_emem_cfg (MEM_SIZE_KB) = 0x%08x\n", emem_cfg);
  67. size_bytes = get_ram_size((void *)PHYS_SDRAM_1, emem_cfg * 1024);
  68. #else
  69. debug("mc->mc_emem_cfg (MEM_SIZE_MB) = 0x%08x\n", emem_cfg);
  70. /*
  71. * If >=4GB RAM is present, the byte RAM size won't fit into 32-bits
  72. * and will wrap. Clip the reported size to the maximum that a 32-bit
  73. * variable can represent (rounded to a page).
  74. */
  75. if (emem_cfg >= 4096) {
  76. size_bytes = U32_MAX & ~(0x1000 - 1);
  77. } else {
  78. /* RAM size EMC is programmed to. */
  79. size_bytes = emem_cfg * 1024 * 1024;
  80. /*
  81. * If all RAM fits within 32-bits, it can be accessed without
  82. * LPAE, so go test the RAM size. Otherwise, we can't access
  83. * all the RAM, and get_ram_size() would get confused, so
  84. * avoid using it. There's no reason we should need this
  85. * validation step anyway.
  86. */
  87. if (emem_cfg <= (0 - PHYS_SDRAM_1) / (1024 * 1024))
  88. size_bytes = get_ram_size((void *)PHYS_SDRAM_1,
  89. size_bytes);
  90. }
  91. #endif
  92. #if defined(CONFIG_TEGRA30) || defined(CONFIG_TEGRA114)
  93. /* External memory limited to 2047 MB due to IROM/HI-VEC */
  94. if (size_bytes == SZ_2G)
  95. size_bytes -= SZ_1M;
  96. #endif
  97. return size_bytes;
  98. }
  99. int dram_init(void)
  100. {
  101. /* We do not initialise DRAM here. We just query the size */
  102. gd->ram_size = query_sdram_size();
  103. return 0;
  104. }
  105. static int uart_configs[] = {
  106. #if defined(CONFIG_TEGRA20)
  107. #if defined(CONFIG_TEGRA_UARTA_UAA_UAB)
  108. FUNCMUX_UART1_UAA_UAB,
  109. #elif defined(CONFIG_TEGRA_UARTA_GPU)
  110. FUNCMUX_UART1_GPU,
  111. #elif defined(CONFIG_TEGRA_UARTA_SDIO1)
  112. FUNCMUX_UART1_SDIO1,
  113. #else
  114. FUNCMUX_UART1_IRRX_IRTX,
  115. #endif
  116. FUNCMUX_UART2_UAD,
  117. -1,
  118. FUNCMUX_UART4_GMC,
  119. -1,
  120. #elif defined(CONFIG_TEGRA30)
  121. FUNCMUX_UART1_ULPI, /* UARTA */
  122. -1,
  123. -1,
  124. -1,
  125. -1,
  126. #elif defined(CONFIG_TEGRA114)
  127. -1,
  128. -1,
  129. -1,
  130. FUNCMUX_UART4_GMI, /* UARTD */
  131. -1,
  132. #elif defined(CONFIG_TEGRA124)
  133. FUNCMUX_UART1_KBC, /* UARTA */
  134. -1,
  135. -1,
  136. FUNCMUX_UART4_GPIO, /* UARTD */
  137. -1,
  138. #else /* Tegra210 */
  139. FUNCMUX_UART1_UART1, /* UARTA */
  140. -1,
  141. -1,
  142. FUNCMUX_UART4_UART4, /* UARTD */
  143. -1,
  144. #endif
  145. };
  146. /**
  147. * Set up the specified uarts
  148. *
  149. * @param uarts_ids Mask containing UARTs to init (UARTx)
  150. */
  151. static void setup_uarts(int uart_ids)
  152. {
  153. static enum periph_id id_for_uart[] = {
  154. PERIPH_ID_UART1,
  155. PERIPH_ID_UART2,
  156. PERIPH_ID_UART3,
  157. PERIPH_ID_UART4,
  158. PERIPH_ID_UART5,
  159. };
  160. size_t i;
  161. for (i = 0; i < UART_COUNT; i++) {
  162. if (uart_ids & (1 << i)) {
  163. enum periph_id id = id_for_uart[i];
  164. funcmux_select(id, uart_configs[i]);
  165. clock_ll_start_uart(id);
  166. }
  167. }
  168. }
  169. void board_init_uart_f(void)
  170. {
  171. int uart_ids = 0; /* bit mask of which UART ids to enable */
  172. #ifdef CONFIG_TEGRA_ENABLE_UARTA
  173. uart_ids |= UARTA;
  174. #endif
  175. #ifdef CONFIG_TEGRA_ENABLE_UARTB
  176. uart_ids |= UARTB;
  177. #endif
  178. #ifdef CONFIG_TEGRA_ENABLE_UARTC
  179. uart_ids |= UARTC;
  180. #endif
  181. #ifdef CONFIG_TEGRA_ENABLE_UARTD
  182. uart_ids |= UARTD;
  183. #endif
  184. #ifdef CONFIG_TEGRA_ENABLE_UARTE
  185. uart_ids |= UARTE;
  186. #endif
  187. setup_uarts(uart_ids);
  188. }
  189. #if !defined(CONFIG_SYS_DCACHE_OFF) && !defined(CONFIG_ARM64)
  190. void enable_caches(void)
  191. {
  192. /* Enable D-cache. I-cache is already enabled in start.S */
  193. dcache_enable();
  194. }
  195. #endif