blob: 3d1d26d13d1399b38b1fadac66721a8bb4c08e2e [file] [log] [blame]
Tom Warren41b68382011-01-27 10:58:05 +00001/*
Tom Warrenab0cc6b2015-03-04 16:36:00 -07002 * (C) Copyright 2010-2015
Tom Warren41b68382011-01-27 10:58:05 +00003 * NVIDIA Corporation <www.nvidia.com>
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Tom Warren41b68382011-01-27 10:58:05 +00006 */
7
8#include <common.h>
Thomas Choue3b90262015-11-19 21:48:11 +08009#include <dm.h>
10#include <ns16550.h>
Simon Glasseec13c42015-05-13 07:02:29 -060011#include <spl.h>
Tom Warren41b68382011-01-27 10:58:05 +000012#include <asm/io.h>
Simon Glass96b7c432011-11-28 15:04:39 +000013#include <asm/arch/clock.h>
14#include <asm/arch/funcmux.h>
Marcel Ziswilerc5ecf272014-10-10 23:32:32 +020015#include <asm/arch/mc.h>
Tom Warrenab371962012-09-19 15:50:56 -070016#include <asm/arch/tegra.h>
Stephen Warren8d1fb312015-01-19 16:25:52 -070017#include <asm/arch-tegra/ap.h>
Lucas Stache80f7ca2012-09-29 10:02:08 +000018#include <asm/arch-tegra/board.h>
Tom Warrenab371962012-09-19 15:50:56 -070019#include <asm/arch-tegra/pmc.h>
20#include <asm/arch-tegra/sys_proto.h>
21#include <asm/arch-tegra/warmboot.h>
Tom Warren41b68382011-01-27 10:58:05 +000022
Tom Warren021a8bb2015-07-08 08:05:35 -070023void save_boot_params_ret(void);
24
Tom Warren41b68382011-01-27 10:58:05 +000025DECLARE_GLOBAL_DATA_PTR;
26
Simon Glass96b7c432011-11-28 15:04:39 +000027enum {
28 /* UARTs which we can enable */
29 UARTA = 1 << 0,
30 UARTB = 1 << 1,
Tom Warrene3d95bc2013-01-28 13:32:10 +000031 UARTC = 1 << 2,
Simon Glass96b7c432011-11-28 15:04:39 +000032 UARTD = 1 << 3,
Tom Warrene3d95bc2013-01-28 13:32:10 +000033 UARTE = 1 << 4,
34 UART_COUNT = 5,
Simon Glass96b7c432011-11-28 15:04:39 +000035};
36
Simon Glasseec13c42015-05-13 07:02:29 -060037static bool from_spl __attribute__ ((section(".data")));
38
39#ifndef CONFIG_SPL_BUILD
40void 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
47bool spl_was_boot_source(void)
48{
49 return from_spl;
50}
51
Stephen Warren8d1fb312015-01-19 16:25:52 -070052#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
56bool 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 Warren1b4af6b2014-07-02 14:12:30 -060070/* Read the RAM size directly from the memory controller */
Stephen Warren6718af02015-08-07 16:12:44 -060071static phys_size_t query_sdram_size(void)
Stephen Warren1b4af6b2014-07-02 14:12:30 -060072{
73 struct mc_ctlr *const mc = (struct mc_ctlr *)NV_PA_MC_BASE;
Stephen Warren6718af02015-08-07 16:12:44 -060074 u32 emem_cfg;
75 phys_size_t size_bytes;
Stephen Warren1b4af6b2014-07-02 14:12:30 -060076
Stephen Warren210bdb22014-12-23 10:34:50 -070077 emem_cfg = readl(&mc->mc_emem_cfg);
Marcel Ziswilerc5ecf272014-10-10 23:32:32 +020078#if defined(CONFIG_TEGRA20)
Stephen Warren210bdb22014-12-23 10:34:50 -070079 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 Ziswilerc5ecf272014-10-10 23:32:32 +020081#else
Stephen Warren210bdb22014-12-23 10:34:50 -070082 debug("mc->mc_emem_cfg (MEM_SIZE_MB) = 0x%08x\n", emem_cfg);
Stephen Warren6718af02015-08-07 16:12:44 -060083#ifndef CONFIG_PHYS_64BIT
Stephen Warrenc8018052014-12-23 10:34:51 -070084 /*
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 Warren6718af02015-08-07 16:12:44 -060091 } else
92#endif
93 {
Stephen Warrenc8018052014-12-23 10:34:51 -070094 /* RAM size EMC is programmed to. */
Stephen Warren6718af02015-08-07 16:12:44 -060095 size_bytes = (phys_size_t)emem_cfg * 1024 * 1024;
96#ifndef CONFIG_ARM64
Stephen Warrenc8018052014-12-23 10:34:51 -070097 /*
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 Warren6718af02015-08-07 16:12:44 -0600107#endif
Stephen Warrenc8018052014-12-23 10:34:51 -0700108 }
Marcel Ziswilerc5ecf272014-10-10 23:32:32 +0200109#endif
Stephen Warren1b4af6b2014-07-02 14:12:30 -0600110
Marcel Ziswilerc5ecf272014-10-10 23:32:32 +0200111#if defined(CONFIG_TEGRA30) || defined(CONFIG_TEGRA114)
112 /* External memory limited to 2047 MB due to IROM/HI-VEC */
Stephen Warren210bdb22014-12-23 10:34:50 -0700113 if (size_bytes == SZ_2G)
114 size_bytes -= SZ_1M;
Stephen Warren1b4af6b2014-07-02 14:12:30 -0600115#endif
Tom Warren41b68382011-01-27 10:58:05 +0000116
Stephen Warren210bdb22014-12-23 10:34:50 -0700117 return size_bytes;
Marcel Ziswilerc5ecf272014-10-10 23:32:32 +0200118}
119
Tom Warren41b68382011-01-27 10:58:05 +0000120int dram_init(void)
121{
Tom Warren41b68382011-01-27 10:58:05 +0000122 /* We do not initialise DRAM here. We just query the size */
Simon Glassf6fcbbd2011-11-05 03:56:57 +0000123 gd->ram_size = query_sdram_size();
Tom Warren41b68382011-01-27 10:58:05 +0000124 return 0;
125}
126
Stephen Warren59f90102012-05-14 13:13:45 +0000127static int uart_configs[] = {
Tom Warren61c6d0e2012-12-11 13:34:15 +0000128#if defined(CONFIG_TEGRA20)
129 #if defined(CONFIG_TEGRA_UARTA_UAA_UAB)
Stephen Warren59f90102012-05-14 13:13:45 +0000130 FUNCMUX_UART1_UAA_UAB,
Tom Warren61c6d0e2012-12-11 13:34:15 +0000131 #elif defined(CONFIG_TEGRA_UARTA_GPU)
Stephen Warrene4c01a82012-05-16 05:59:59 +0000132 FUNCMUX_UART1_GPU,
Tom Warren61c6d0e2012-12-11 13:34:15 +0000133 #elif defined(CONFIG_TEGRA_UARTA_SDIO1)
Lucas Stach4de6eec2012-05-16 08:21:02 +0000134 FUNCMUX_UART1_SDIO1,
Tom Warren61c6d0e2012-12-11 13:34:15 +0000135 #else
Stephen Warren59f90102012-05-14 13:13:45 +0000136 FUNCMUX_UART1_IRRX_IRTX,
Stephen Warren811af732013-01-22 06:20:08 +0000137#endif
138 FUNCMUX_UART2_UAD,
Stephen Warren59f90102012-05-14 13:13:45 +0000139 -1,
140 FUNCMUX_UART4_GMC,
141 -1,
Tom Warrene3d95bc2013-01-28 13:32:10 +0000142#elif defined(CONFIG_TEGRA30)
Tom Warren61c6d0e2012-12-11 13:34:15 +0000143 FUNCMUX_UART1_ULPI, /* UARTA */
144 -1,
145 -1,
146 -1,
147 -1,
Tom Warrene5ffffd2014-01-24 12:46:16 -0700148#elif defined(CONFIG_TEGRA114)
Tom Warrene3d95bc2013-01-28 13:32:10 +0000149 -1,
150 -1,
151 -1,
152 FUNCMUX_UART4_GMI, /* UARTD */
153 -1,
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700154#elif defined(CONFIG_TEGRA124)
Tom Warrene5ffffd2014-01-24 12:46:16 -0700155 FUNCMUX_UART1_KBC, /* UARTA */
156 -1,
157 -1,
158 FUNCMUX_UART4_GPIO, /* UARTD */
159 -1,
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700160#else /* Tegra210 */
161 FUNCMUX_UART1_UART1, /* UARTA */
162 -1,
163 -1,
164 FUNCMUX_UART4_UART4, /* UARTD */
165 -1,
Tom Warren61c6d0e2012-12-11 13:34:15 +0000166#endif
Stephen Warren59f90102012-05-14 13:13:45 +0000167};
168
Simon Glass96b7c432011-11-28 15:04:39 +0000169/**
170 * Set up the specified uarts
171 *
172 * @param uarts_ids Mask containing UARTs to init (UARTx)
173 */
174static 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 Warrene3d95bc2013-01-28 13:32:10 +0000181 PERIPH_ID_UART5,
Simon Glass96b7c432011-11-28 15:04:39 +0000182 };
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 Warren59f90102012-05-14 13:13:45 +0000189 funcmux_select(id, uart_configs[i]);
Simon Glass96b7c432011-11-28 15:04:39 +0000190 clock_ll_start_uart(id);
191 }
192 }
193}
194
195void board_init_uart_f(void)
196{
197 int uart_ids = 0; /* bit mask of which UART ids to enable */
198
Tom Warren22562a42012-09-04 17:00:24 -0700199#ifdef CONFIG_TEGRA_ENABLE_UARTA
Simon Glass96b7c432011-11-28 15:04:39 +0000200 uart_ids |= UARTA;
201#endif
Tom Warren22562a42012-09-04 17:00:24 -0700202#ifdef CONFIG_TEGRA_ENABLE_UARTB
Simon Glass96b7c432011-11-28 15:04:39 +0000203 uart_ids |= UARTB;
204#endif
Tom Warrene3d95bc2013-01-28 13:32:10 +0000205#ifdef CONFIG_TEGRA_ENABLE_UARTC
206 uart_ids |= UARTC;
207#endif
Tom Warren22562a42012-09-04 17:00:24 -0700208#ifdef CONFIG_TEGRA_ENABLE_UARTD
Simon Glass96b7c432011-11-28 15:04:39 +0000209 uart_ids |= UARTD;
210#endif
Tom Warrene3d95bc2013-01-28 13:32:10 +0000211#ifdef CONFIG_TEGRA_ENABLE_UARTE
212 uart_ids |= UARTE;
213#endif
Simon Glass96b7c432011-11-28 15:04:39 +0000214 setup_uarts(uart_ids);
215}
Simon Glass410012f2012-01-09 13:22:15 +0000216
Simon Glassf4402d02015-12-04 08:58:39 -0700217#if !CONFIG_IS_ENABLED(OF_CONTROL)
Thomas Choue3b90262015-11-19 21:48:11 +0800218static struct ns16550_platdata ns16550_com1_pdata = {
219 .base = CONFIG_SYS_NS16550_COM1,
220 .reg_shift = 2,
221 .clock = CONFIG_SYS_NS16550_CLK,
222};
223
224U_BOOT_DEVICE(ns16550_com1) = {
225 "ns16550_serial", &ns16550_com1_pdata
226};
227#endif
228
Thierry Reding0367dbd2015-07-27 11:45:25 -0600229#if !defined(CONFIG_SYS_DCACHE_OFF) && !defined(CONFIG_ARM64)
Simon Glass410012f2012-01-09 13:22:15 +0000230void enable_caches(void)
231{
232 /* Enable D-cache. I-cache is already enabled in start.S */
233 dcache_enable();
234}
235#endif