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