blob: 433da09d10c2ad59efa3fb2db9c8bf971951039c [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>
Tom Warrenab371962012-09-19 15:50:56 -070012#include <asm/arch/tegra.h>
Lucas Stache80f7ca2012-09-29 10:02:08 +000013#include <asm/arch-tegra/board.h>
Tom Warrenab371962012-09-19 15:50:56 -070014#include <asm/arch-tegra/pmc.h>
15#include <asm/arch-tegra/sys_proto.h>
16#include <asm/arch-tegra/warmboot.h>
Tom Warren41b68382011-01-27 10:58:05 +000017
18DECLARE_GLOBAL_DATA_PTR;
19
Simon Glass96b7c432011-11-28 15:04:39 +000020enum {
21 /* UARTs which we can enable */
22 UARTA = 1 << 0,
23 UARTB = 1 << 1,
Tom Warrene3d95bc2013-01-28 13:32:10 +000024 UARTC = 1 << 2,
Simon Glass96b7c432011-11-28 15:04:39 +000025 UARTD = 1 << 3,
Tom Warrene3d95bc2013-01-28 13:32:10 +000026 UARTE = 1 << 4,
27 UART_COUNT = 5,
Simon Glass96b7c432011-11-28 15:04:39 +000028};
29
Stephen Warren1b4af6b2014-07-02 14:12:30 -060030#if defined(CONFIG_TEGRA20) || defined(CONFIG_TEGRA30) || \
31 defined(CONFIG_TEGRA114)
Tom Warren41b68382011-01-27 10:58:05 +000032/*
33 * Boot ROM initializes the odmdata in APBDEV_PMC_SCRATCH20_0,
34 * so we are using this value to identify memory size.
35 */
Tom Warren41b68382011-01-27 10:58:05 +000036unsigned int query_sdram_size(void)
37{
Tom Warren22562a42012-09-04 17:00:24 -070038 struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
Tom Warren41b68382011-01-27 10:58:05 +000039 u32 reg;
40
41 reg = readl(&pmc->pmc_scratch20);
Marek Vasut8148e112011-10-24 23:41:39 +000042 debug("pmc->pmc_scratch20 (ODMData) = 0x%08x\n", reg);
Tom Warren41b68382011-01-27 10:58:05 +000043
Tom Warren61c6d0e2012-12-11 13:34:15 +000044#if defined(CONFIG_TEGRA20)
45 /* bits 30:28 in OdmData are used for RAM size on T20 */
46 reg &= 0x70000000;
47
Tom Warren41b68382011-01-27 10:58:05 +000048 switch ((reg) >> 28) {
49 case 1:
50 return 0x10000000; /* 256 MB */
Tom Warren61c6d0e2012-12-11 13:34:15 +000051 case 0:
Tom Warren41b68382011-01-27 10:58:05 +000052 case 2:
Stephen Warrenb60fa392012-01-06 12:14:41 +000053 default:
Tom Warren41b68382011-01-27 10:58:05 +000054 return 0x20000000; /* 512 MB */
55 case 3:
Tom Warren41b68382011-01-27 10:58:05 +000056 return 0x40000000; /* 1GB */
57 }
Tom Warrene3d95bc2013-01-28 13:32:10 +000058#else /* Tegra30/Tegra114 */
Tom Warren61c6d0e2012-12-11 13:34:15 +000059 /* bits 31:28 in OdmData are used for RAM size on T30 */
60 switch ((reg) >> 28) {
61 case 0:
62 case 1:
63 default:
64 return 0x10000000; /* 256 MB */
65 case 2:
66 return 0x20000000; /* 512 MB */
67 case 3:
68 return 0x30000000; /* 768 MB */
69 case 4:
70 return 0x40000000; /* 1GB */
71 case 8:
72 return 0x7ff00000; /* 2GB - 1MB */
73 }
74#endif
Tom Warren41b68382011-01-27 10:58:05 +000075}
Stephen Warren1b4af6b2014-07-02 14:12:30 -060076#else
77#include <asm/arch/mc.h>
78
79/* Read the RAM size directly from the memory controller */
80unsigned int query_sdram_size(void)
81{
82 struct mc_ctlr *const mc = (struct mc_ctlr *)NV_PA_MC_BASE;
83 u32 size_mb;
84
85 size_mb = readl(&mc->mc_emem_cfg);
86 debug("mc->mc_emem_cfg (MEM_SIZE_MB) = 0x%08x\n", size_mb);
87
88 return size_mb * 1024 * 1024;
89}
90#endif
Tom Warren41b68382011-01-27 10:58:05 +000091
Tom Warren41b68382011-01-27 10:58:05 +000092int dram_init(void)
93{
Tom Warren41b68382011-01-27 10:58:05 +000094 /* We do not initialise DRAM here. We just query the size */
Simon Glassf6fcbbd2011-11-05 03:56:57 +000095 gd->ram_size = query_sdram_size();
Tom Warren41b68382011-01-27 10:58:05 +000096 return 0;
97}
98
99#ifdef CONFIG_DISPLAY_BOARDINFO
100int checkboard(void)
101{
102 printf("Board: %s\n", sysinfo.board_string);
103 return 0;
104}
105#endif /* CONFIG_DISPLAY_BOARDINFO */
Simon Glass5f3a8992011-11-05 03:56:49 +0000106
Stephen Warren59f90102012-05-14 13:13:45 +0000107static int uart_configs[] = {
Tom Warren61c6d0e2012-12-11 13:34:15 +0000108#if defined(CONFIG_TEGRA20)
109 #if defined(CONFIG_TEGRA_UARTA_UAA_UAB)
Stephen Warren59f90102012-05-14 13:13:45 +0000110 FUNCMUX_UART1_UAA_UAB,
Tom Warren61c6d0e2012-12-11 13:34:15 +0000111 #elif defined(CONFIG_TEGRA_UARTA_GPU)
Stephen Warrene4c01a82012-05-16 05:59:59 +0000112 FUNCMUX_UART1_GPU,
Tom Warren61c6d0e2012-12-11 13:34:15 +0000113 #elif defined(CONFIG_TEGRA_UARTA_SDIO1)
Lucas Stach4de6eec2012-05-16 08:21:02 +0000114 FUNCMUX_UART1_SDIO1,
Tom Warren61c6d0e2012-12-11 13:34:15 +0000115 #else
Stephen Warren59f90102012-05-14 13:13:45 +0000116 FUNCMUX_UART1_IRRX_IRTX,
Stephen Warren811af732013-01-22 06:20:08 +0000117#endif
118 FUNCMUX_UART2_UAD,
Stephen Warren59f90102012-05-14 13:13:45 +0000119 -1,
120 FUNCMUX_UART4_GMC,
121 -1,
Tom Warrene3d95bc2013-01-28 13:32:10 +0000122#elif defined(CONFIG_TEGRA30)
Tom Warren61c6d0e2012-12-11 13:34:15 +0000123 FUNCMUX_UART1_ULPI, /* UARTA */
124 -1,
125 -1,
126 -1,
127 -1,
Tom Warrene5ffffd2014-01-24 12:46:16 -0700128#elif defined(CONFIG_TEGRA114)
Tom Warrene3d95bc2013-01-28 13:32:10 +0000129 -1,
130 -1,
131 -1,
132 FUNCMUX_UART4_GMI, /* UARTD */
133 -1,
Tom Warrene5ffffd2014-01-24 12:46:16 -0700134#else /* Tegra124 */
135 FUNCMUX_UART1_KBC, /* UARTA */
136 -1,
137 -1,
138 FUNCMUX_UART4_GPIO, /* UARTD */
139 -1,
Tom Warren61c6d0e2012-12-11 13:34:15 +0000140#endif
Stephen Warren59f90102012-05-14 13:13:45 +0000141};
142
Simon Glass96b7c432011-11-28 15:04:39 +0000143/**
144 * Set up the specified uarts
145 *
146 * @param uarts_ids Mask containing UARTs to init (UARTx)
147 */
148static void setup_uarts(int uart_ids)
149{
150 static enum periph_id id_for_uart[] = {
151 PERIPH_ID_UART1,
152 PERIPH_ID_UART2,
153 PERIPH_ID_UART3,
154 PERIPH_ID_UART4,
Tom Warrene3d95bc2013-01-28 13:32:10 +0000155 PERIPH_ID_UART5,
Simon Glass96b7c432011-11-28 15:04:39 +0000156 };
157 size_t i;
158
159 for (i = 0; i < UART_COUNT; i++) {
160 if (uart_ids & (1 << i)) {
161 enum periph_id id = id_for_uart[i];
162
Stephen Warren59f90102012-05-14 13:13:45 +0000163 funcmux_select(id, uart_configs[i]);
Simon Glass96b7c432011-11-28 15:04:39 +0000164 clock_ll_start_uart(id);
165 }
166 }
167}
168
169void board_init_uart_f(void)
170{
171 int uart_ids = 0; /* bit mask of which UART ids to enable */
172
Tom Warren22562a42012-09-04 17:00:24 -0700173#ifdef CONFIG_TEGRA_ENABLE_UARTA
Simon Glass96b7c432011-11-28 15:04:39 +0000174 uart_ids |= UARTA;
175#endif
Tom Warren22562a42012-09-04 17:00:24 -0700176#ifdef CONFIG_TEGRA_ENABLE_UARTB
Simon Glass96b7c432011-11-28 15:04:39 +0000177 uart_ids |= UARTB;
178#endif
Tom Warrene3d95bc2013-01-28 13:32:10 +0000179#ifdef CONFIG_TEGRA_ENABLE_UARTC
180 uart_ids |= UARTC;
181#endif
Tom Warren22562a42012-09-04 17:00:24 -0700182#ifdef CONFIG_TEGRA_ENABLE_UARTD
Simon Glass96b7c432011-11-28 15:04:39 +0000183 uart_ids |= UARTD;
184#endif
Tom Warrene3d95bc2013-01-28 13:32:10 +0000185#ifdef CONFIG_TEGRA_ENABLE_UARTE
186 uart_ids |= UARTE;
187#endif
Simon Glass96b7c432011-11-28 15:04:39 +0000188 setup_uarts(uart_ids);
189}
Simon Glass410012f2012-01-09 13:22:15 +0000190
191#ifndef CONFIG_SYS_DCACHE_OFF
192void enable_caches(void)
193{
194 /* Enable D-cache. I-cache is already enabled in start.S */
195 dcache_enable();
196}
197#endif