]> git.sur5r.net Git - u-boot/blob - arch/arm/mach-tegra/board.c
Merge branch 'master' of git://git.denx.de/u-boot-tegra
[u-boot] / arch / arm / mach-tegra / board.c
1 /*
2  *  (C) Copyright 2010-2014
3  *  NVIDIA Corporation <www.nvidia.com>
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7
8 #include <common.h>
9 #include <asm/io.h>
10 #include <asm/arch/clock.h>
11 #include <asm/arch/funcmux.h>
12 #include <asm/arch/mc.h>
13 #include <asm/arch/tegra.h>
14 #include <asm/arch-tegra/ap.h>
15 #include <asm/arch-tegra/board.h>
16 #include <asm/arch-tegra/pmc.h>
17 #include <asm/arch-tegra/sys_proto.h>
18 #include <asm/arch-tegra/warmboot.h>
19
20 DECLARE_GLOBAL_DATA_PTR;
21
22 enum {
23         /* UARTs which we can enable */
24         UARTA   = 1 << 0,
25         UARTB   = 1 << 1,
26         UARTC   = 1 << 2,
27         UARTD   = 1 << 3,
28         UARTE   = 1 << 4,
29         UART_COUNT = 5,
30 };
31
32 #if defined(CONFIG_TEGRA_SUPPORT_NON_SECURE)
33 #if !defined(CONFIG_TEGRA124)
34 #error tegra_cpu_is_non_secure has only been validated on Tegra124
35 #endif
36 bool tegra_cpu_is_non_secure(void)
37 {
38         /*
39          * This register reads 0xffffffff in non-secure mode. This register
40          * only implements bits 31:20, so the lower bits will always read 0 in
41          * secure mode. Thus, the lower bits are an indicator for secure vs.
42          * non-secure mode.
43          */
44         struct mc_ctlr *mc = (struct mc_ctlr *)NV_PA_MC_BASE;
45         uint32_t mc_s_cfg0 = readl(&mc->mc_security_cfg0);
46         return (mc_s_cfg0 & 1) == 1;
47 }
48 #endif
49
50 /* Read the RAM size directly from the memory controller */
51 unsigned int query_sdram_size(void)
52 {
53         struct mc_ctlr *const mc = (struct mc_ctlr *)NV_PA_MC_BASE;
54         u32 emem_cfg, size_bytes;
55
56         emem_cfg = readl(&mc->mc_emem_cfg);
57 #if defined(CONFIG_TEGRA20)
58         debug("mc->mc_emem_cfg (MEM_SIZE_KB) = 0x%08x\n", emem_cfg);
59         size_bytes = get_ram_size((void *)PHYS_SDRAM_1, emem_cfg * 1024);
60 #else
61         debug("mc->mc_emem_cfg (MEM_SIZE_MB) = 0x%08x\n", emem_cfg);
62         /*
63          * If >=4GB RAM is present, the byte RAM size won't fit into 32-bits
64          * and will wrap. Clip the reported size to the maximum that a 32-bit
65          * variable can represent (rounded to a page).
66          */
67         if (emem_cfg >= 4096) {
68                 size_bytes = U32_MAX & ~(0x1000 - 1);
69         } else {
70                 /* RAM size EMC is programmed to. */
71                 size_bytes = emem_cfg * 1024 * 1024;
72                 /*
73                  * If all RAM fits within 32-bits, it can be accessed without
74                  * LPAE, so go test the RAM size. Otherwise, we can't access
75                  * all the RAM, and get_ram_size() would get confused, so
76                  * avoid using it. There's no reason we should need this
77                  * validation step anyway.
78                  */
79                 if (emem_cfg <= (0 - PHYS_SDRAM_1) / (1024 * 1024))
80                         size_bytes = get_ram_size((void *)PHYS_SDRAM_1,
81                                                   size_bytes);
82         }
83 #endif
84
85 #if defined(CONFIG_TEGRA30) || defined(CONFIG_TEGRA114)
86         /* External memory limited to 2047 MB due to IROM/HI-VEC */
87         if (size_bytes == SZ_2G)
88                 size_bytes -= SZ_1M;
89 #endif
90
91         return size_bytes;
92 }
93
94 int dram_init(void)
95 {
96         /* We do not initialise DRAM here. We just query the size */
97         gd->ram_size = query_sdram_size();
98         return 0;
99 }
100
101 static int uart_configs[] = {
102 #if defined(CONFIG_TEGRA20)
103  #if defined(CONFIG_TEGRA_UARTA_UAA_UAB)
104         FUNCMUX_UART1_UAA_UAB,
105  #elif defined(CONFIG_TEGRA_UARTA_GPU)
106         FUNCMUX_UART1_GPU,
107  #elif defined(CONFIG_TEGRA_UARTA_SDIO1)
108         FUNCMUX_UART1_SDIO1,
109  #else
110         FUNCMUX_UART1_IRRX_IRTX,
111 #endif
112         FUNCMUX_UART2_UAD,
113         -1,
114         FUNCMUX_UART4_GMC,
115         -1,
116 #elif defined(CONFIG_TEGRA30)
117         FUNCMUX_UART1_ULPI,     /* UARTA */
118         -1,
119         -1,
120         -1,
121         -1,
122 #elif defined(CONFIG_TEGRA114)
123         -1,
124         -1,
125         -1,
126         FUNCMUX_UART4_GMI,      /* UARTD */
127         -1,
128 #else   /* Tegra124 */
129         FUNCMUX_UART1_KBC,      /* UARTA */
130         -1,
131         -1,
132         FUNCMUX_UART4_GPIO,     /* UARTD */
133         -1,
134 #endif
135 };
136
137 /**
138  * Set up the specified uarts
139  *
140  * @param uarts_ids     Mask containing UARTs to init (UARTx)
141  */
142 static void setup_uarts(int uart_ids)
143 {
144         static enum periph_id id_for_uart[] = {
145                 PERIPH_ID_UART1,
146                 PERIPH_ID_UART2,
147                 PERIPH_ID_UART3,
148                 PERIPH_ID_UART4,
149                 PERIPH_ID_UART5,
150         };
151         size_t i;
152
153         for (i = 0; i < UART_COUNT; i++) {
154                 if (uart_ids & (1 << i)) {
155                         enum periph_id id = id_for_uart[i];
156
157                         funcmux_select(id, uart_configs[i]);
158                         clock_ll_start_uart(id);
159                 }
160         }
161 }
162
163 void board_init_uart_f(void)
164 {
165         int uart_ids = 0;       /* bit mask of which UART ids to enable */
166
167 #ifdef CONFIG_TEGRA_ENABLE_UARTA
168         uart_ids |= UARTA;
169 #endif
170 #ifdef CONFIG_TEGRA_ENABLE_UARTB
171         uart_ids |= UARTB;
172 #endif
173 #ifdef CONFIG_TEGRA_ENABLE_UARTC
174         uart_ids |= UARTC;
175 #endif
176 #ifdef CONFIG_TEGRA_ENABLE_UARTD
177         uart_ids |= UARTD;
178 #endif
179 #ifdef CONFIG_TEGRA_ENABLE_UARTE
180         uart_ids |= UARTE;
181 #endif
182         setup_uarts(uart_ids);
183 }
184
185 #ifndef CONFIG_SYS_DCACHE_OFF
186 void enable_caches(void)
187 {
188         /* Enable D-cache. I-cache is already enabled in start.S */
189         dcache_enable();
190 }
191 #endif