blob: 87511a31df180526225b14efa9288e80013f6f77 [file] [log] [blame]
Tom Warren41b68382011-01-27 10:58:05 +00001/*
Tom Warrene5ffffd2014-01-24 12:46:16 -07002 * (C) Copyright 2010-2014
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>
9#include <asm/io.h>
Simon Glass96b7c432011-11-28 15:04:39 +000010#include <asm/arch/clock.h>
11#include <asm/arch/funcmux.h>
Marcel Ziswilerc5ecf272014-10-10 23:32:32 +020012#include <asm/arch/mc.h>
Tom Warrenab371962012-09-19 15:50:56 -070013#include <asm/arch/tegra.h>
Lucas Stache80f7ca2012-09-29 10:02:08 +000014#include <asm/arch-tegra/board.h>
Tom Warrenab371962012-09-19 15:50:56 -070015#include <asm/arch-tegra/pmc.h>
16#include <asm/arch-tegra/sys_proto.h>
17#include <asm/arch-tegra/warmboot.h>
Tom Warren41b68382011-01-27 10:58:05 +000018
19DECLARE_GLOBAL_DATA_PTR;
20
Simon Glass96b7c432011-11-28 15:04:39 +000021enum {
22 /* UARTs which we can enable */
23 UARTA = 1 << 0,
24 UARTB = 1 << 1,
Tom Warrene3d95bc2013-01-28 13:32:10 +000025 UARTC = 1 << 2,
Simon Glass96b7c432011-11-28 15:04:39 +000026 UARTD = 1 << 3,
Tom Warrene3d95bc2013-01-28 13:32:10 +000027 UARTE = 1 << 4,
28 UART_COUNT = 5,
Simon Glass96b7c432011-11-28 15:04:39 +000029};
30
Stephen Warren1b4af6b2014-07-02 14:12:30 -060031/* Read the RAM size directly from the memory controller */
32unsigned int query_sdram_size(void)
33{
34 struct mc_ctlr *const mc = (struct mc_ctlr *)NV_PA_MC_BASE;
Stephen Warren210bdb22014-12-23 10:34:50 -070035 u32 emem_cfg, size_bytes;
Stephen Warren1b4af6b2014-07-02 14:12:30 -060036
Stephen Warren210bdb22014-12-23 10:34:50 -070037 emem_cfg = readl(&mc->mc_emem_cfg);
Marcel Ziswilerc5ecf272014-10-10 23:32:32 +020038#if defined(CONFIG_TEGRA20)
Stephen Warren210bdb22014-12-23 10:34:50 -070039 debug("mc->mc_emem_cfg (MEM_SIZE_KB) = 0x%08x\n", emem_cfg);
40 size_bytes = get_ram_size((void *)PHYS_SDRAM_1, emem_cfg * 1024);
Marcel Ziswilerc5ecf272014-10-10 23:32:32 +020041#else
Stephen Warren210bdb22014-12-23 10:34:50 -070042 debug("mc->mc_emem_cfg (MEM_SIZE_MB) = 0x%08x\n", emem_cfg);
Stephen Warrenc8018052014-12-23 10:34:51 -070043 /*
44 * If >=4GB RAM is present, the byte RAM size won't fit into 32-bits
45 * and will wrap. Clip the reported size to the maximum that a 32-bit
46 * variable can represent (rounded to a page).
47 */
48 if (emem_cfg >= 4096) {
49 size_bytes = U32_MAX & ~(0x1000 - 1);
50 } else {
51 /* RAM size EMC is programmed to. */
52 size_bytes = emem_cfg * 1024 * 1024;
53 /*
54 * If all RAM fits within 32-bits, it can be accessed without
55 * LPAE, so go test the RAM size. Otherwise, we can't access
56 * all the RAM, and get_ram_size() would get confused, so
57 * avoid using it. There's no reason we should need this
58 * validation step anyway.
59 */
60 if (emem_cfg <= (0 - PHYS_SDRAM_1) / (1024 * 1024))
61 size_bytes = get_ram_size((void *)PHYS_SDRAM_1,
62 size_bytes);
63 }
Marcel Ziswilerc5ecf272014-10-10 23:32:32 +020064#endif
Stephen Warren1b4af6b2014-07-02 14:12:30 -060065
Marcel Ziswilerc5ecf272014-10-10 23:32:32 +020066#if defined(CONFIG_TEGRA30) || defined(CONFIG_TEGRA114)
67 /* External memory limited to 2047 MB due to IROM/HI-VEC */
Stephen Warren210bdb22014-12-23 10:34:50 -070068 if (size_bytes == SZ_2G)
69 size_bytes -= SZ_1M;
Stephen Warren1b4af6b2014-07-02 14:12:30 -060070#endif
Tom Warren41b68382011-01-27 10:58:05 +000071
Stephen Warren210bdb22014-12-23 10:34:50 -070072 return size_bytes;
Marcel Ziswilerc5ecf272014-10-10 23:32:32 +020073}
74
Tom Warren41b68382011-01-27 10:58:05 +000075int dram_init(void)
76{
Tom Warren41b68382011-01-27 10:58:05 +000077 /* We do not initialise DRAM here. We just query the size */
Simon Glassf6fcbbd2011-11-05 03:56:57 +000078 gd->ram_size = query_sdram_size();
Tom Warren41b68382011-01-27 10:58:05 +000079 return 0;
80}
81
82#ifdef CONFIG_DISPLAY_BOARDINFO
83int checkboard(void)
84{
85 printf("Board: %s\n", sysinfo.board_string);
86 return 0;
87}
88#endif /* CONFIG_DISPLAY_BOARDINFO */
Simon Glass5f3a8992011-11-05 03:56:49 +000089
Stephen Warren59f90102012-05-14 13:13:45 +000090static int uart_configs[] = {
Tom Warren61c6d0e2012-12-11 13:34:15 +000091#if defined(CONFIG_TEGRA20)
92 #if defined(CONFIG_TEGRA_UARTA_UAA_UAB)
Stephen Warren59f90102012-05-14 13:13:45 +000093 FUNCMUX_UART1_UAA_UAB,
Tom Warren61c6d0e2012-12-11 13:34:15 +000094 #elif defined(CONFIG_TEGRA_UARTA_GPU)
Stephen Warrene4c01a82012-05-16 05:59:59 +000095 FUNCMUX_UART1_GPU,
Tom Warren61c6d0e2012-12-11 13:34:15 +000096 #elif defined(CONFIG_TEGRA_UARTA_SDIO1)
Lucas Stach4de6eec2012-05-16 08:21:02 +000097 FUNCMUX_UART1_SDIO1,
Tom Warren61c6d0e2012-12-11 13:34:15 +000098 #else
Stephen Warren59f90102012-05-14 13:13:45 +000099 FUNCMUX_UART1_IRRX_IRTX,
Stephen Warren811af732013-01-22 06:20:08 +0000100#endif
101 FUNCMUX_UART2_UAD,
Stephen Warren59f90102012-05-14 13:13:45 +0000102 -1,
103 FUNCMUX_UART4_GMC,
104 -1,
Tom Warrene3d95bc2013-01-28 13:32:10 +0000105#elif defined(CONFIG_TEGRA30)
Tom Warren61c6d0e2012-12-11 13:34:15 +0000106 FUNCMUX_UART1_ULPI, /* UARTA */
107 -1,
108 -1,
109 -1,
110 -1,
Tom Warrene5ffffd2014-01-24 12:46:16 -0700111#elif defined(CONFIG_TEGRA114)
Tom Warrene3d95bc2013-01-28 13:32:10 +0000112 -1,
113 -1,
114 -1,
115 FUNCMUX_UART4_GMI, /* UARTD */
116 -1,
Tom Warrene5ffffd2014-01-24 12:46:16 -0700117#else /* Tegra124 */
118 FUNCMUX_UART1_KBC, /* UARTA */
119 -1,
120 -1,
121 FUNCMUX_UART4_GPIO, /* UARTD */
122 -1,
Tom Warren61c6d0e2012-12-11 13:34:15 +0000123#endif
Stephen Warren59f90102012-05-14 13:13:45 +0000124};
125
Simon Glass96b7c432011-11-28 15:04:39 +0000126/**
127 * Set up the specified uarts
128 *
129 * @param uarts_ids Mask containing UARTs to init (UARTx)
130 */
131static void setup_uarts(int uart_ids)
132{
133 static enum periph_id id_for_uart[] = {
134 PERIPH_ID_UART1,
135 PERIPH_ID_UART2,
136 PERIPH_ID_UART3,
137 PERIPH_ID_UART4,
Tom Warrene3d95bc2013-01-28 13:32:10 +0000138 PERIPH_ID_UART5,
Simon Glass96b7c432011-11-28 15:04:39 +0000139 };
140 size_t i;
141
142 for (i = 0; i < UART_COUNT; i++) {
143 if (uart_ids & (1 << i)) {
144 enum periph_id id = id_for_uart[i];
145
Stephen Warren59f90102012-05-14 13:13:45 +0000146 funcmux_select(id, uart_configs[i]);
Simon Glass96b7c432011-11-28 15:04:39 +0000147 clock_ll_start_uart(id);
148 }
149 }
150}
151
152void board_init_uart_f(void)
153{
154 int uart_ids = 0; /* bit mask of which UART ids to enable */
155
Tom Warren22562a42012-09-04 17:00:24 -0700156#ifdef CONFIG_TEGRA_ENABLE_UARTA
Simon Glass96b7c432011-11-28 15:04:39 +0000157 uart_ids |= UARTA;
158#endif
Tom Warren22562a42012-09-04 17:00:24 -0700159#ifdef CONFIG_TEGRA_ENABLE_UARTB
Simon Glass96b7c432011-11-28 15:04:39 +0000160 uart_ids |= UARTB;
161#endif
Tom Warrene3d95bc2013-01-28 13:32:10 +0000162#ifdef CONFIG_TEGRA_ENABLE_UARTC
163 uart_ids |= UARTC;
164#endif
Tom Warren22562a42012-09-04 17:00:24 -0700165#ifdef CONFIG_TEGRA_ENABLE_UARTD
Simon Glass96b7c432011-11-28 15:04:39 +0000166 uart_ids |= UARTD;
167#endif
Tom Warrene3d95bc2013-01-28 13:32:10 +0000168#ifdef CONFIG_TEGRA_ENABLE_UARTE
169 uart_ids |= UARTE;
170#endif
Simon Glass96b7c432011-11-28 15:04:39 +0000171 setup_uarts(uart_ids);
172}
Simon Glass410012f2012-01-09 13:22:15 +0000173
174#ifndef CONFIG_SYS_DCACHE_OFF
175void enable_caches(void)
176{
177 /* Enable D-cache. I-cache is already enabled in start.S */
178 dcache_enable();
179}
180#endif