board.c 5.2 KB

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