]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/tegra-common/board.c
Merge branch 'master' of git://git.denx.de/u-boot-arc
[karo-tx-uboot.git] / arch / arm / cpu / tegra-common / 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/tegra.h>
13 #include <asm/arch-tegra/board.h>
14 #include <asm/arch-tegra/pmc.h>
15 #include <asm/arch-tegra/sys_proto.h>
16 #include <asm/arch-tegra/warmboot.h>
17
18 DECLARE_GLOBAL_DATA_PTR;
19
20 enum {
21         /* UARTs which we can enable */
22         UARTA   = 1 << 0,
23         UARTB   = 1 << 1,
24         UARTC   = 1 << 2,
25         UARTD   = 1 << 3,
26         UARTE   = 1 << 4,
27         UART_COUNT = 5,
28 };
29
30 #if defined(CONFIG_TEGRA20) || defined(CONFIG_TEGRA30) || \
31         defined(CONFIG_TEGRA114)
32 /*
33  * Boot ROM initializes the odmdata in APBDEV_PMC_SCRATCH20_0,
34  * so we are using this value to identify memory size.
35  */
36 unsigned int query_sdram_size(void)
37 {
38         struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
39         u32 reg;
40
41         reg = readl(&pmc->pmc_scratch20);
42         debug("pmc->pmc_scratch20 (ODMData) = 0x%08x\n", reg);
43
44 #if defined(CONFIG_TEGRA20)
45         /* bits 30:28 in OdmData are used for RAM size on T20  */
46         reg &= 0x70000000;
47
48         switch ((reg) >> 28) {
49         case 1:
50                 return 0x10000000;      /* 256 MB */
51         case 0:
52         case 2:
53         default:
54                 return 0x20000000;      /* 512 MB */
55         case 3:
56                 return 0x40000000;      /* 1GB */
57         }
58 #else   /* Tegra30/Tegra114 */
59         /* 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
75 }
76 #else
77 #include <asm/arch/mc.h>
78
79 /* Read the RAM size directly from the memory controller */
80 unsigned 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
91
92 int dram_init(void)
93 {
94         /* We do not initialise DRAM here. We just query the size */
95         gd->ram_size = query_sdram_size();
96         return 0;
97 }
98
99 #ifdef CONFIG_DISPLAY_BOARDINFO
100 int checkboard(void)
101 {
102         printf("Board: %s\n", sysinfo.board_string);
103         return 0;
104 }
105 #endif  /* CONFIG_DISPLAY_BOARDINFO */
106
107 static int uart_configs[] = {
108 #if defined(CONFIG_TEGRA20)
109  #if defined(CONFIG_TEGRA_UARTA_UAA_UAB)
110         FUNCMUX_UART1_UAA_UAB,
111  #elif defined(CONFIG_TEGRA_UARTA_GPU)
112         FUNCMUX_UART1_GPU,
113  #elif defined(CONFIG_TEGRA_UARTA_SDIO1)
114         FUNCMUX_UART1_SDIO1,
115  #else
116         FUNCMUX_UART1_IRRX_IRTX,
117 #endif
118         FUNCMUX_UART2_UAD,
119         -1,
120         FUNCMUX_UART4_GMC,
121         -1,
122 #elif defined(CONFIG_TEGRA30)
123         FUNCMUX_UART1_ULPI,     /* UARTA */
124         -1,
125         -1,
126         -1,
127         -1,
128 #elif defined(CONFIG_TEGRA114)
129         -1,
130         -1,
131         -1,
132         FUNCMUX_UART4_GMI,      /* UARTD */
133         -1,
134 #else   /* Tegra124 */
135         FUNCMUX_UART1_KBC,      /* UARTA */
136         -1,
137         -1,
138         FUNCMUX_UART4_GPIO,     /* UARTD */
139         -1,
140 #endif
141 };
142
143 /**
144  * Set up the specified uarts
145  *
146  * @param uarts_ids     Mask containing UARTs to init (UARTx)
147  */
148 static 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,
155                 PERIPH_ID_UART5,
156         };
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
163                         funcmux_select(id, uart_configs[i]);
164                         clock_ll_start_uart(id);
165                 }
166         }
167 }
168
169 void board_init_uart_f(void)
170 {
171         int uart_ids = 0;       /* bit mask of which UART ids to enable */
172
173 #ifdef CONFIG_TEGRA_ENABLE_UARTA
174         uart_ids |= UARTA;
175 #endif
176 #ifdef CONFIG_TEGRA_ENABLE_UARTB
177         uart_ids |= UARTB;
178 #endif
179 #ifdef CONFIG_TEGRA_ENABLE_UARTC
180         uart_ids |= UARTC;
181 #endif
182 #ifdef CONFIG_TEGRA_ENABLE_UARTD
183         uart_ids |= UARTD;
184 #endif
185 #ifdef CONFIG_TEGRA_ENABLE_UARTE
186         uart_ids |= UARTE;
187 #endif
188         setup_uarts(uart_ids);
189 }
190
191 #ifndef CONFIG_SYS_DCACHE_OFF
192 void enable_caches(void)
193 {
194         /* Enable D-cache. I-cache is already enabled in start.S */
195         dcache_enable();
196 }
197 #endif