blob: f8fc042a1dcc273a1f3967f2073b00f9981cfe30 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Tom Warren3f82b1d2011-01-27 10:58:05 +00002/*
Tom Warren7aaa5a62015-03-04 16:36:00 -07003 * (C) Copyright 2010-2015
Tom Warren3f82b1d2011-01-27 10:58:05 +00004 * NVIDIA Corporation <www.nvidia.com>
Tom Warren3f82b1d2011-01-27 10:58:05 +00005 */
6
7#include <common.h>
Thomas Chou18746262015-11-19 21:48:11 +08008#include <dm.h>
9#include <ns16550.h>
Simon Glass537e9672015-05-13 07:02:29 -060010#include <spl.h>
Tom Warren3f82b1d2011-01-27 10:58:05 +000011#include <asm/io.h>
Simon Glassbb6997f2011-11-28 15:04:39 +000012#include <asm/arch/clock.h>
13#include <asm/arch/funcmux.h>
Marcel Ziswiler8c33ba72014-10-10 23:32:32 +020014#include <asm/arch/mc.h>
Tom Warren150c2492012-09-19 15:50:56 -070015#include <asm/arch/tegra.h>
Stephen Warren73c38932015-01-19 16:25:52 -070016#include <asm/arch-tegra/ap.h>
Lucas Stach516f00b2012-09-29 10:02:08 +000017#include <asm/arch-tegra/board.h>
Tom Warren150c2492012-09-19 15:50:56 -070018#include <asm/arch-tegra/pmc.h>
19#include <asm/arch-tegra/sys_proto.h>
20#include <asm/arch-tegra/warmboot.h>
Tom Warren3f82b1d2011-01-27 10:58:05 +000021
Tom Warren659a0752015-07-08 08:05:35 -070022void save_boot_params_ret(void);
23
Tom Warren3f82b1d2011-01-27 10:58:05 +000024DECLARE_GLOBAL_DATA_PTR;
25
Simon Glassbb6997f2011-11-28 15:04:39 +000026enum {
27 /* UARTs which we can enable */
28 UARTA = 1 << 0,
29 UARTB = 1 << 1,
Tom Warrene23bb6a2013-01-28 13:32:10 +000030 UARTC = 1 << 2,
Simon Glassbb6997f2011-11-28 15:04:39 +000031 UARTD = 1 << 3,
Tom Warrene23bb6a2013-01-28 13:32:10 +000032 UARTE = 1 << 4,
33 UART_COUNT = 5,
Simon Glassbb6997f2011-11-28 15:04:39 +000034};
35
Simon Glass537e9672015-05-13 07:02:29 -060036static bool from_spl __attribute__ ((section(".data")));
37
38#ifndef CONFIG_SPL_BUILD
39void save_boot_params(u32 r0, u32 r1, u32 r2, u32 r3)
40{
41 from_spl = r0 != UBOOT_NOT_LOADED_FROM_SPL;
42 save_boot_params_ret();
43}
44#endif
45
46bool spl_was_boot_source(void)
47{
48 return from_spl;
49}
50
Stephen Warren73c38932015-01-19 16:25:52 -070051#if defined(CONFIG_TEGRA_SUPPORT_NON_SECURE)
52#if !defined(CONFIG_TEGRA124)
53#error tegra_cpu_is_non_secure has only been validated on Tegra124
54#endif
55bool tegra_cpu_is_non_secure(void)
56{
57 /*
58 * This register reads 0xffffffff in non-secure mode. This register
59 * only implements bits 31:20, so the lower bits will always read 0 in
60 * secure mode. Thus, the lower bits are an indicator for secure vs.
61 * non-secure mode.
62 */
63 struct mc_ctlr *mc = (struct mc_ctlr *)NV_PA_MC_BASE;
64 uint32_t mc_s_cfg0 = readl(&mc->mc_security_cfg0);
65 return (mc_s_cfg0 & 1) == 1;
66}
67#endif
68
Stephen Warrenaeb3fcb2014-07-02 14:12:30 -060069/* Read the RAM size directly from the memory controller */
Stephen Warrena5fc3d02015-08-07 16:12:44 -060070static phys_size_t query_sdram_size(void)
Stephen Warrenaeb3fcb2014-07-02 14:12:30 -060071{
72 struct mc_ctlr *const mc = (struct mc_ctlr *)NV_PA_MC_BASE;
Stephen Warrena5fc3d02015-08-07 16:12:44 -060073 u32 emem_cfg;
74 phys_size_t size_bytes;
Stephen Warrenaeb3fcb2014-07-02 14:12:30 -060075
Stephen Warren3a2cab52014-12-23 10:34:50 -070076 emem_cfg = readl(&mc->mc_emem_cfg);
Marcel Ziswiler8c33ba72014-10-10 23:32:32 +020077#if defined(CONFIG_TEGRA20)
Stephen Warren3a2cab52014-12-23 10:34:50 -070078 debug("mc->mc_emem_cfg (MEM_SIZE_KB) = 0x%08x\n", emem_cfg);
79 size_bytes = get_ram_size((void *)PHYS_SDRAM_1, emem_cfg * 1024);
Marcel Ziswiler8c33ba72014-10-10 23:32:32 +020080#else
Stephen Warren3a2cab52014-12-23 10:34:50 -070081 debug("mc->mc_emem_cfg (MEM_SIZE_MB) = 0x%08x\n", emem_cfg);
Stephen Warrena5fc3d02015-08-07 16:12:44 -060082#ifndef CONFIG_PHYS_64BIT
Stephen Warren56519c42014-12-23 10:34:51 -070083 /*
84 * If >=4GB RAM is present, the byte RAM size won't fit into 32-bits
85 * and will wrap. Clip the reported size to the maximum that a 32-bit
86 * variable can represent (rounded to a page).
87 */
88 if (emem_cfg >= 4096) {
89 size_bytes = U32_MAX & ~(0x1000 - 1);
Stephen Warrena5fc3d02015-08-07 16:12:44 -060090 } else
91#endif
92 {
Stephen Warren56519c42014-12-23 10:34:51 -070093 /* RAM size EMC is programmed to. */
Stephen Warrena5fc3d02015-08-07 16:12:44 -060094 size_bytes = (phys_size_t)emem_cfg * 1024 * 1024;
95#ifndef CONFIG_ARM64
Stephen Warren56519c42014-12-23 10:34:51 -070096 /*
97 * If all RAM fits within 32-bits, it can be accessed without
98 * LPAE, so go test the RAM size. Otherwise, we can't access
99 * all the RAM, and get_ram_size() would get confused, so
100 * avoid using it. There's no reason we should need this
101 * validation step anyway.
102 */
103 if (emem_cfg <= (0 - PHYS_SDRAM_1) / (1024 * 1024))
104 size_bytes = get_ram_size((void *)PHYS_SDRAM_1,
105 size_bytes);
Stephen Warrena5fc3d02015-08-07 16:12:44 -0600106#endif
Stephen Warren56519c42014-12-23 10:34:51 -0700107 }
Stephen Warrenaeb3fcb2014-07-02 14:12:30 -0600108#endif
Tom Warren3f82b1d2011-01-27 10:58:05 +0000109
Marcel Ziswiler8c33ba72014-10-10 23:32:32 +0200110#if defined(CONFIG_TEGRA30) || defined(CONFIG_TEGRA114)
111 /* External memory limited to 2047 MB due to IROM/HI-VEC */
Stephen Warren3a2cab52014-12-23 10:34:50 -0700112 if (size_bytes == SZ_2G)
113 size_bytes -= SZ_1M;
Marcel Ziswiler8c33ba72014-10-10 23:32:32 +0200114#endif
115
Stephen Warren3a2cab52014-12-23 10:34:50 -0700116 return size_bytes;
Marcel Ziswiler8c33ba72014-10-10 23:32:32 +0200117}
118
Tom Warren3f82b1d2011-01-27 10:58:05 +0000119int dram_init(void)
120{
Tom Warren3f82b1d2011-01-27 10:58:05 +0000121 /* We do not initialise DRAM here. We just query the size */
Simon Glass7f8c0702011-11-05 03:56:57 +0000122 gd->ram_size = query_sdram_size();
Tom Warren3f82b1d2011-01-27 10:58:05 +0000123 return 0;
124}
125
Stephen Warrenb9607e72012-05-14 13:13:45 +0000126static int uart_configs[] = {
Tom Warrenb2871032012-12-11 13:34:15 +0000127#if defined(CONFIG_TEGRA20)
128 #if defined(CONFIG_TEGRA_UARTA_UAA_UAB)
Stephen Warrenb9607e72012-05-14 13:13:45 +0000129 FUNCMUX_UART1_UAA_UAB,
Tom Warrenb2871032012-12-11 13:34:15 +0000130 #elif defined(CONFIG_TEGRA_UARTA_GPU)
Stephen Warrene21649b2012-05-16 05:59:59 +0000131 FUNCMUX_UART1_GPU,
Tom Warrenb2871032012-12-11 13:34:15 +0000132 #elif defined(CONFIG_TEGRA_UARTA_SDIO1)
Lucas Stacha2cfe632012-05-16 08:21:02 +0000133 FUNCMUX_UART1_SDIO1,
Tom Warrenb2871032012-12-11 13:34:15 +0000134 #else
Stephen Warrenb9607e72012-05-14 13:13:45 +0000135 FUNCMUX_UART1_IRRX_IRTX,
Stephen Warren4727a132013-01-22 06:20:08 +0000136#endif
137 FUNCMUX_UART2_UAD,
Stephen Warrenb9607e72012-05-14 13:13:45 +0000138 -1,
139 FUNCMUX_UART4_GMC,
140 -1,
Tom Warrene23bb6a2013-01-28 13:32:10 +0000141#elif defined(CONFIG_TEGRA30)
Tom Warrenb2871032012-12-11 13:34:15 +0000142 FUNCMUX_UART1_ULPI, /* UARTA */
143 -1,
144 -1,
145 -1,
146 -1,
Tom Warren2f5dac92014-01-24 12:46:16 -0700147#elif defined(CONFIG_TEGRA114)
Tom Warrene23bb6a2013-01-28 13:32:10 +0000148 -1,
149 -1,
150 -1,
151 FUNCMUX_UART4_GMI, /* UARTD */
152 -1,
Tom Warren7aaa5a62015-03-04 16:36:00 -0700153#elif defined(CONFIG_TEGRA124)
Tom Warren2f5dac92014-01-24 12:46:16 -0700154 FUNCMUX_UART1_KBC, /* UARTA */
155 -1,
156 -1,
157 FUNCMUX_UART4_GPIO, /* UARTD */
158 -1,
Tom Warren7aaa5a62015-03-04 16:36:00 -0700159#else /* Tegra210 */
160 FUNCMUX_UART1_UART1, /* UARTA */
161 -1,
162 -1,
163 FUNCMUX_UART4_UART4, /* UARTD */
164 -1,
Tom Warrenb2871032012-12-11 13:34:15 +0000165#endif
Stephen Warrenb9607e72012-05-14 13:13:45 +0000166};
167
Simon Glassbb6997f2011-11-28 15:04:39 +0000168/**
169 * Set up the specified uarts
170 *
171 * @param uarts_ids Mask containing UARTs to init (UARTx)
172 */
173static void setup_uarts(int uart_ids)
174{
175 static enum periph_id id_for_uart[] = {
176 PERIPH_ID_UART1,
177 PERIPH_ID_UART2,
178 PERIPH_ID_UART3,
179 PERIPH_ID_UART4,
Tom Warrene23bb6a2013-01-28 13:32:10 +0000180 PERIPH_ID_UART5,
Simon Glassbb6997f2011-11-28 15:04:39 +0000181 };
182 size_t i;
183
184 for (i = 0; i < UART_COUNT; i++) {
185 if (uart_ids & (1 << i)) {
186 enum periph_id id = id_for_uart[i];
187
Stephen Warrenb9607e72012-05-14 13:13:45 +0000188 funcmux_select(id, uart_configs[i]);
Simon Glassbb6997f2011-11-28 15:04:39 +0000189 clock_ll_start_uart(id);
190 }
191 }
192}
193
194void board_init_uart_f(void)
195{
196 int uart_ids = 0; /* bit mask of which UART ids to enable */
197
Tom Warren29f3e3f2012-09-04 17:00:24 -0700198#ifdef CONFIG_TEGRA_ENABLE_UARTA
Simon Glassbb6997f2011-11-28 15:04:39 +0000199 uart_ids |= UARTA;
200#endif
Tom Warren29f3e3f2012-09-04 17:00:24 -0700201#ifdef CONFIG_TEGRA_ENABLE_UARTB
Simon Glassbb6997f2011-11-28 15:04:39 +0000202 uart_ids |= UARTB;
203#endif
Tom Warrene23bb6a2013-01-28 13:32:10 +0000204#ifdef CONFIG_TEGRA_ENABLE_UARTC
205 uart_ids |= UARTC;
206#endif
Tom Warren29f3e3f2012-09-04 17:00:24 -0700207#ifdef CONFIG_TEGRA_ENABLE_UARTD
Simon Glassbb6997f2011-11-28 15:04:39 +0000208 uart_ids |= UARTD;
209#endif
Tom Warrene23bb6a2013-01-28 13:32:10 +0000210#ifdef CONFIG_TEGRA_ENABLE_UARTE
211 uart_ids |= UARTE;
212#endif
Simon Glassbb6997f2011-11-28 15:04:39 +0000213 setup_uarts(uart_ids);
214}
Simon Glassbd29cb02012-01-09 13:22:15 +0000215
Simon Glass878a3ed2015-12-04 08:58:39 -0700216#if !CONFIG_IS_ENABLED(OF_CONTROL)
Thomas Chou18746262015-11-19 21:48:11 +0800217static struct ns16550_platdata ns16550_com1_pdata = {
218 .base = CONFIG_SYS_NS16550_COM1,
219 .reg_shift = 2,
220 .clock = CONFIG_SYS_NS16550_CLK,
Heiko Schocher17fa0322017-01-18 08:05:49 +0100221 .fcr = UART_FCR_DEFVAL,
Thomas Chou18746262015-11-19 21:48:11 +0800222};
223
224U_BOOT_DEVICE(ns16550_com1) = {
225 "ns16550_serial", &ns16550_com1_pdata
226};
227#endif
228
Thierry Reding32b32342015-07-27 11:45:25 -0600229#if !defined(CONFIG_SYS_DCACHE_OFF) && !defined(CONFIG_ARM64)
Simon Glassbd29cb02012-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