blob: fd23de180476b830fbb91da86d01d6a9c3b8ffd6 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Tom Warren41b68382011-01-27 10:58:05 +00002/*
Tom Warrenab0cc6b2015-03-04 16:36:00 -07003 * (C) Copyright 2010-2015
Tom Warren41b68382011-01-27 10:58:05 +00004 * NVIDIA Corporation <www.nvidia.com>
Tom Warren41b68382011-01-27 10:58:05 +00005 */
6
7#include <common.h>
Thomas Choue3b90262015-11-19 21:48:11 +08008#include <dm.h>
9#include <ns16550.h>
Simon Glasseec13c42015-05-13 07:02:29 -060010#include <spl.h>
Tom Warren41b68382011-01-27 10:58:05 +000011#include <asm/io.h>
Thierry Reding45ad0b02019-04-15 11:32:18 +020012#if IS_ENABLED(CONFIG_TEGRA_CLKRST)
Simon Glass96b7c432011-11-28 15:04:39 +000013#include <asm/arch/clock.h>
Thierry Reding45ad0b02019-04-15 11:32:18 +020014#endif
Thierry Reding7c0b1502019-04-15 11:32:21 +020015#if IS_ENABLED(CONFIG_TEGRA_PINCTRL)
Simon Glass96b7c432011-11-28 15:04:39 +000016#include <asm/arch/funcmux.h>
Thierry Reding7c0b1502019-04-15 11:32:21 +020017#endif
Thierry Reding17987bb2019-04-15 11:32:20 +020018#if IS_ENABLED(CONFIG_TEGRA_MC)
Marcel Ziswilerc5ecf272014-10-10 23:32:32 +020019#include <asm/arch/mc.h>
Thierry Reding17987bb2019-04-15 11:32:20 +020020#endif
Tom Warrenab371962012-09-19 15:50:56 -070021#include <asm/arch/tegra.h>
Stephen Warren8d1fb312015-01-19 16:25:52 -070022#include <asm/arch-tegra/ap.h>
Lucas Stache80f7ca2012-09-29 10:02:08 +000023#include <asm/arch-tegra/board.h>
Tom Warrenab371962012-09-19 15:50:56 -070024#include <asm/arch-tegra/pmc.h>
25#include <asm/arch-tegra/sys_proto.h>
26#include <asm/arch-tegra/warmboot.h>
Tom Warren41b68382011-01-27 10:58:05 +000027
Tom Warren021a8bb2015-07-08 08:05:35 -070028void save_boot_params_ret(void);
29
Tom Warren41b68382011-01-27 10:58:05 +000030DECLARE_GLOBAL_DATA_PTR;
31
Simon Glass96b7c432011-11-28 15:04:39 +000032enum {
33 /* UARTs which we can enable */
34 UARTA = 1 << 0,
35 UARTB = 1 << 1,
Tom Warrene3d95bc2013-01-28 13:32:10 +000036 UARTC = 1 << 2,
Simon Glass96b7c432011-11-28 15:04:39 +000037 UARTD = 1 << 3,
Tom Warrene3d95bc2013-01-28 13:32:10 +000038 UARTE = 1 << 4,
39 UART_COUNT = 5,
Simon Glass96b7c432011-11-28 15:04:39 +000040};
41
Simon Glasseec13c42015-05-13 07:02:29 -060042static bool from_spl __attribute__ ((section(".data")));
43
44#ifndef CONFIG_SPL_BUILD
45void save_boot_params(u32 r0, u32 r1, u32 r2, u32 r3)
46{
47 from_spl = r0 != UBOOT_NOT_LOADED_FROM_SPL;
48 save_boot_params_ret();
49}
50#endif
51
52bool spl_was_boot_source(void)
53{
54 return from_spl;
55}
56
Stephen Warren8d1fb312015-01-19 16:25:52 -070057#if defined(CONFIG_TEGRA_SUPPORT_NON_SECURE)
58#if !defined(CONFIG_TEGRA124)
59#error tegra_cpu_is_non_secure has only been validated on Tegra124
60#endif
61bool tegra_cpu_is_non_secure(void)
62{
63 /*
64 * This register reads 0xffffffff in non-secure mode. This register
65 * only implements bits 31:20, so the lower bits will always read 0 in
66 * secure mode. Thus, the lower bits are an indicator for secure vs.
67 * non-secure mode.
68 */
69 struct mc_ctlr *mc = (struct mc_ctlr *)NV_PA_MC_BASE;
70 uint32_t mc_s_cfg0 = readl(&mc->mc_security_cfg0);
71 return (mc_s_cfg0 & 1) == 1;
72}
73#endif
74
Thierry Reding17987bb2019-04-15 11:32:20 +020075#if IS_ENABLED(CONFIG_TEGRA_MC)
Stephen Warren1b4af6b2014-07-02 14:12:30 -060076/* Read the RAM size directly from the memory controller */
Stephen Warren6718af02015-08-07 16:12:44 -060077static phys_size_t query_sdram_size(void)
Stephen Warren1b4af6b2014-07-02 14:12:30 -060078{
79 struct mc_ctlr *const mc = (struct mc_ctlr *)NV_PA_MC_BASE;
Stephen Warren6718af02015-08-07 16:12:44 -060080 u32 emem_cfg;
81 phys_size_t size_bytes;
Stephen Warren1b4af6b2014-07-02 14:12:30 -060082
Stephen Warren210bdb22014-12-23 10:34:50 -070083 emem_cfg = readl(&mc->mc_emem_cfg);
Marcel Ziswilerc5ecf272014-10-10 23:32:32 +020084#if defined(CONFIG_TEGRA20)
Stephen Warren210bdb22014-12-23 10:34:50 -070085 debug("mc->mc_emem_cfg (MEM_SIZE_KB) = 0x%08x\n", emem_cfg);
86 size_bytes = get_ram_size((void *)PHYS_SDRAM_1, emem_cfg * 1024);
Marcel Ziswilerc5ecf272014-10-10 23:32:32 +020087#else
Stephen Warren210bdb22014-12-23 10:34:50 -070088 debug("mc->mc_emem_cfg (MEM_SIZE_MB) = 0x%08x\n", emem_cfg);
Stephen Warren6718af02015-08-07 16:12:44 -060089#ifndef CONFIG_PHYS_64BIT
Stephen Warrenc8018052014-12-23 10:34:51 -070090 /*
91 * If >=4GB RAM is present, the byte RAM size won't fit into 32-bits
92 * and will wrap. Clip the reported size to the maximum that a 32-bit
93 * variable can represent (rounded to a page).
94 */
95 if (emem_cfg >= 4096) {
96 size_bytes = U32_MAX & ~(0x1000 - 1);
Stephen Warren6718af02015-08-07 16:12:44 -060097 } else
98#endif
99 {
Stephen Warrenc8018052014-12-23 10:34:51 -0700100 /* RAM size EMC is programmed to. */
Stephen Warren6718af02015-08-07 16:12:44 -0600101 size_bytes = (phys_size_t)emem_cfg * 1024 * 1024;
102#ifndef CONFIG_ARM64
Stephen Warrenc8018052014-12-23 10:34:51 -0700103 /*
104 * If all RAM fits within 32-bits, it can be accessed without
105 * LPAE, so go test the RAM size. Otherwise, we can't access
106 * all the RAM, and get_ram_size() would get confused, so
107 * avoid using it. There's no reason we should need this
108 * validation step anyway.
109 */
110 if (emem_cfg <= (0 - PHYS_SDRAM_1) / (1024 * 1024))
111 size_bytes = get_ram_size((void *)PHYS_SDRAM_1,
112 size_bytes);
Stephen Warren6718af02015-08-07 16:12:44 -0600113#endif
Stephen Warrenc8018052014-12-23 10:34:51 -0700114 }
Marcel Ziswilerc5ecf272014-10-10 23:32:32 +0200115#endif
Stephen Warren1b4af6b2014-07-02 14:12:30 -0600116
Marcel Ziswilerc5ecf272014-10-10 23:32:32 +0200117#if defined(CONFIG_TEGRA30) || defined(CONFIG_TEGRA114)
118 /* External memory limited to 2047 MB due to IROM/HI-VEC */
Stephen Warren210bdb22014-12-23 10:34:50 -0700119 if (size_bytes == SZ_2G)
120 size_bytes -= SZ_1M;
Stephen Warren1b4af6b2014-07-02 14:12:30 -0600121#endif
Tom Warren41b68382011-01-27 10:58:05 +0000122
Stephen Warren210bdb22014-12-23 10:34:50 -0700123 return size_bytes;
Marcel Ziswilerc5ecf272014-10-10 23:32:32 +0200124}
Thierry Reding17987bb2019-04-15 11:32:20 +0200125#endif
Marcel Ziswilerc5ecf272014-10-10 23:32:32 +0200126
Tom Warren41b68382011-01-27 10:58:05 +0000127int dram_init(void)
128{
Thierry Reding17987bb2019-04-15 11:32:20 +0200129#if IS_ENABLED(CONFIG_TEGRA_MC)
Tom Warren41b68382011-01-27 10:58:05 +0000130 /* We do not initialise DRAM here. We just query the size */
Simon Glassf6fcbbd2011-11-05 03:56:57 +0000131 gd->ram_size = query_sdram_size();
Thierry Reding17987bb2019-04-15 11:32:20 +0200132#endif
133
Tom Warren41b68382011-01-27 10:58:05 +0000134 return 0;
135}
136
Thierry Reding7c0b1502019-04-15 11:32:21 +0200137#if IS_ENABLED(CONFIG_TEGRA_PINCTRL)
Stephen Warren59f90102012-05-14 13:13:45 +0000138static int uart_configs[] = {
Tom Warren61c6d0e2012-12-11 13:34:15 +0000139#if defined(CONFIG_TEGRA20)
140 #if defined(CONFIG_TEGRA_UARTA_UAA_UAB)
Stephen Warren59f90102012-05-14 13:13:45 +0000141 FUNCMUX_UART1_UAA_UAB,
Tom Warren61c6d0e2012-12-11 13:34:15 +0000142 #elif defined(CONFIG_TEGRA_UARTA_GPU)
Stephen Warrene4c01a82012-05-16 05:59:59 +0000143 FUNCMUX_UART1_GPU,
Tom Warren61c6d0e2012-12-11 13:34:15 +0000144 #elif defined(CONFIG_TEGRA_UARTA_SDIO1)
Lucas Stach4de6eec2012-05-16 08:21:02 +0000145 FUNCMUX_UART1_SDIO1,
Tom Warren61c6d0e2012-12-11 13:34:15 +0000146 #else
Stephen Warren59f90102012-05-14 13:13:45 +0000147 FUNCMUX_UART1_IRRX_IRTX,
Stephen Warren811af732013-01-22 06:20:08 +0000148#endif
149 FUNCMUX_UART2_UAD,
Stephen Warren59f90102012-05-14 13:13:45 +0000150 -1,
151 FUNCMUX_UART4_GMC,
152 -1,
Tom Warrene3d95bc2013-01-28 13:32:10 +0000153#elif defined(CONFIG_TEGRA30)
Tom Warren61c6d0e2012-12-11 13:34:15 +0000154 FUNCMUX_UART1_ULPI, /* UARTA */
155 -1,
156 -1,
157 -1,
158 -1,
Tom Warrene5ffffd2014-01-24 12:46:16 -0700159#elif defined(CONFIG_TEGRA114)
Tom Warrene3d95bc2013-01-28 13:32:10 +0000160 -1,
161 -1,
162 -1,
163 FUNCMUX_UART4_GMI, /* UARTD */
164 -1,
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700165#elif defined(CONFIG_TEGRA124)
Tom Warrene5ffffd2014-01-24 12:46:16 -0700166 FUNCMUX_UART1_KBC, /* UARTA */
167 -1,
168 -1,
169 FUNCMUX_UART4_GPIO, /* UARTD */
170 -1,
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700171#else /* Tegra210 */
172 FUNCMUX_UART1_UART1, /* UARTA */
173 -1,
174 -1,
175 FUNCMUX_UART4_UART4, /* UARTD */
176 -1,
Tom Warren61c6d0e2012-12-11 13:34:15 +0000177#endif
Stephen Warren59f90102012-05-14 13:13:45 +0000178};
179
Simon Glass96b7c432011-11-28 15:04:39 +0000180/**
181 * Set up the specified uarts
182 *
183 * @param uarts_ids Mask containing UARTs to init (UARTx)
184 */
185static void setup_uarts(int uart_ids)
186{
187 static enum periph_id id_for_uart[] = {
188 PERIPH_ID_UART1,
189 PERIPH_ID_UART2,
190 PERIPH_ID_UART3,
191 PERIPH_ID_UART4,
Tom Warrene3d95bc2013-01-28 13:32:10 +0000192 PERIPH_ID_UART5,
Simon Glass96b7c432011-11-28 15:04:39 +0000193 };
194 size_t i;
195
196 for (i = 0; i < UART_COUNT; i++) {
197 if (uart_ids & (1 << i)) {
198 enum periph_id id = id_for_uart[i];
199
Stephen Warren59f90102012-05-14 13:13:45 +0000200 funcmux_select(id, uart_configs[i]);
Simon Glass96b7c432011-11-28 15:04:39 +0000201 clock_ll_start_uart(id);
202 }
203 }
204}
Thierry Reding7c0b1502019-04-15 11:32:21 +0200205#endif
Simon Glass96b7c432011-11-28 15:04:39 +0000206
207void board_init_uart_f(void)
208{
Thierry Reding7c0b1502019-04-15 11:32:21 +0200209#if IS_ENABLED(CONFIG_TEGRA_PINCTRL)
Simon Glass96b7c432011-11-28 15:04:39 +0000210 int uart_ids = 0; /* bit mask of which UART ids to enable */
211
Tom Warren22562a42012-09-04 17:00:24 -0700212#ifdef CONFIG_TEGRA_ENABLE_UARTA
Simon Glass96b7c432011-11-28 15:04:39 +0000213 uart_ids |= UARTA;
214#endif
Tom Warren22562a42012-09-04 17:00:24 -0700215#ifdef CONFIG_TEGRA_ENABLE_UARTB
Simon Glass96b7c432011-11-28 15:04:39 +0000216 uart_ids |= UARTB;
217#endif
Tom Warrene3d95bc2013-01-28 13:32:10 +0000218#ifdef CONFIG_TEGRA_ENABLE_UARTC
219 uart_ids |= UARTC;
220#endif
Tom Warren22562a42012-09-04 17:00:24 -0700221#ifdef CONFIG_TEGRA_ENABLE_UARTD
Simon Glass96b7c432011-11-28 15:04:39 +0000222 uart_ids |= UARTD;
223#endif
Tom Warrene3d95bc2013-01-28 13:32:10 +0000224#ifdef CONFIG_TEGRA_ENABLE_UARTE
225 uart_ids |= UARTE;
226#endif
Simon Glass96b7c432011-11-28 15:04:39 +0000227 setup_uarts(uart_ids);
Thierry Reding7c0b1502019-04-15 11:32:21 +0200228#endif
Simon Glass96b7c432011-11-28 15:04:39 +0000229}
Simon Glass410012f2012-01-09 13:22:15 +0000230
Simon Glassf4402d02015-12-04 08:58:39 -0700231#if !CONFIG_IS_ENABLED(OF_CONTROL)
Thomas Choue3b90262015-11-19 21:48:11 +0800232static struct ns16550_platdata ns16550_com1_pdata = {
233 .base = CONFIG_SYS_NS16550_COM1,
234 .reg_shift = 2,
235 .clock = CONFIG_SYS_NS16550_CLK,
Heiko Schocher06f108e2017-01-18 08:05:49 +0100236 .fcr = UART_FCR_DEFVAL,
Thomas Choue3b90262015-11-19 21:48:11 +0800237};
238
239U_BOOT_DEVICE(ns16550_com1) = {
240 "ns16550_serial", &ns16550_com1_pdata
241};
242#endif
243
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400244#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) && !defined(CONFIG_ARM64)
Simon Glass410012f2012-01-09 13:22:15 +0000245void enable_caches(void)
246{
247 /* Enable D-cache. I-cache is already enabled in start.S */
248 dcache_enable();
249}
250#endif