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