board.c 5.2 KB

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