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