xref: /rk3399_rockchip-uboot/arch/arm/mach-tegra/board2.c (revision dd8204de157e10c080aa2cdc0f24bcb2e4ac73dd)
1237c3637SMasahiro Yamada /*
2237c3637SMasahiro Yamada  *  (C) Copyright 2010,2011
3237c3637SMasahiro Yamada  *  NVIDIA Corporation <www.nvidia.com>
4237c3637SMasahiro Yamada  *
5237c3637SMasahiro Yamada  * SPDX-License-Identifier:	GPL-2.0+
6237c3637SMasahiro Yamada  */
7237c3637SMasahiro Yamada 
8237c3637SMasahiro Yamada #include <common.h>
9237c3637SMasahiro Yamada #include <dm.h>
10237c3637SMasahiro Yamada #include <errno.h>
11237c3637SMasahiro Yamada #include <ns16550.h>
12237c3637SMasahiro Yamada #include <linux/compiler.h>
13bbc1b99eSStephen Warren #include <linux/sizes.h>
14237c3637SMasahiro Yamada #include <asm/io.h>
15237c3637SMasahiro Yamada #include <asm/arch/clock.h>
16237c3637SMasahiro Yamada #ifdef CONFIG_LCD
17237c3637SMasahiro Yamada #include <asm/arch/display.h>
18237c3637SMasahiro Yamada #endif
19237c3637SMasahiro Yamada #include <asm/arch/funcmux.h>
20237c3637SMasahiro Yamada #include <asm/arch/pinmux.h>
21237c3637SMasahiro Yamada #include <asm/arch/pmu.h>
22237c3637SMasahiro Yamada #ifdef CONFIG_PWM_TEGRA
23237c3637SMasahiro Yamada #include <asm/arch/pwm.h>
24237c3637SMasahiro Yamada #endif
25237c3637SMasahiro Yamada #include <asm/arch/tegra.h>
26237c3637SMasahiro Yamada #include <asm/arch-tegra/ap.h>
27237c3637SMasahiro Yamada #include <asm/arch-tegra/board.h>
28237c3637SMasahiro Yamada #include <asm/arch-tegra/clk_rst.h>
29237c3637SMasahiro Yamada #include <asm/arch-tegra/pmc.h>
30237c3637SMasahiro Yamada #include <asm/arch-tegra/sys_proto.h>
31237c3637SMasahiro Yamada #include <asm/arch-tegra/uart.h>
32237c3637SMasahiro Yamada #include <asm/arch-tegra/warmboot.h>
33871d78edSAlexandre Courbot #include <asm/arch-tegra/gpu.h>
34237c3637SMasahiro Yamada #ifdef CONFIG_TEGRA_CLOCK_SCALING
35237c3637SMasahiro Yamada #include <asm/arch/emc.h>
36237c3637SMasahiro Yamada #endif
37237c3637SMasahiro Yamada #include <asm/arch-tegra/usb.h>
38*dd8204deSStephen Warren #ifdef CONFIG_USB_EHCI_TEGRA
39237c3637SMasahiro Yamada #include <usb.h>
40237c3637SMasahiro Yamada #endif
41237c3637SMasahiro Yamada #ifdef CONFIG_TEGRA_MMC
42237c3637SMasahiro Yamada #include <asm/arch-tegra/tegra_mmc.h>
43237c3637SMasahiro Yamada #include <asm/arch-tegra/mmc.h>
44237c3637SMasahiro Yamada #endif
45237c3637SMasahiro Yamada #include <asm/arch-tegra/xusb-padctl.h>
46237c3637SMasahiro Yamada #include <power/as3722.h>
47237c3637SMasahiro Yamada #include <i2c.h>
48237c3637SMasahiro Yamada #include <spi.h>
49237c3637SMasahiro Yamada #include "emc.h"
50237c3637SMasahiro Yamada 
51237c3637SMasahiro Yamada DECLARE_GLOBAL_DATA_PTR;
52237c3637SMasahiro Yamada 
53237c3637SMasahiro Yamada #ifdef CONFIG_SPL_BUILD
54237c3637SMasahiro Yamada /* TODO(sjg@chromium.org): Remove once SPL supports device tree */
55237c3637SMasahiro Yamada U_BOOT_DEVICE(tegra_gpios) = {
56237c3637SMasahiro Yamada 	"gpio_tegra"
57237c3637SMasahiro Yamada };
58237c3637SMasahiro Yamada #endif
59237c3637SMasahiro Yamada 
60237c3637SMasahiro Yamada __weak void pinmux_init(void) {}
61237c3637SMasahiro Yamada __weak void pin_mux_usb(void) {}
62237c3637SMasahiro Yamada __weak void pin_mux_spi(void) {}
63237c3637SMasahiro Yamada __weak void gpio_early_init_uart(void) {}
64237c3637SMasahiro Yamada __weak void pin_mux_display(void) {}
6566999892STom Warren __weak void start_cpu_fan(void) {}
66237c3637SMasahiro Yamada 
67237c3637SMasahiro Yamada #if defined(CONFIG_TEGRA_NAND)
68237c3637SMasahiro Yamada __weak void pin_mux_nand(void)
69237c3637SMasahiro Yamada {
70237c3637SMasahiro Yamada 	funcmux_select(PERIPH_ID_NDFLASH, FUNCMUX_DEFAULT);
71237c3637SMasahiro Yamada }
72237c3637SMasahiro Yamada #endif
73237c3637SMasahiro Yamada 
74237c3637SMasahiro Yamada /*
75237c3637SMasahiro Yamada  * Routine: power_det_init
76237c3637SMasahiro Yamada  * Description: turn off power detects
77237c3637SMasahiro Yamada  */
78237c3637SMasahiro Yamada static void power_det_init(void)
79237c3637SMasahiro Yamada {
80237c3637SMasahiro Yamada #if defined(CONFIG_TEGRA20)
81237c3637SMasahiro Yamada 	struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
82237c3637SMasahiro Yamada 
83237c3637SMasahiro Yamada 	/* turn off power detects */
84237c3637SMasahiro Yamada 	writel(0, &pmc->pmc_pwr_det_latch);
85237c3637SMasahiro Yamada 	writel(0, &pmc->pmc_pwr_det);
86237c3637SMasahiro Yamada #endif
87237c3637SMasahiro Yamada }
88237c3637SMasahiro Yamada 
89237c3637SMasahiro Yamada __weak int tegra_board_id(void)
90237c3637SMasahiro Yamada {
91237c3637SMasahiro Yamada 	return -1;
92237c3637SMasahiro Yamada }
93237c3637SMasahiro Yamada 
94237c3637SMasahiro Yamada #ifdef CONFIG_DISPLAY_BOARDINFO
95237c3637SMasahiro Yamada int checkboard(void)
96237c3637SMasahiro Yamada {
97237c3637SMasahiro Yamada 	int board_id = tegra_board_id();
98237c3637SMasahiro Yamada 
99237c3637SMasahiro Yamada 	printf("Board: %s", CONFIG_TEGRA_BOARD_STRING);
100237c3637SMasahiro Yamada 	if (board_id != -1)
101237c3637SMasahiro Yamada 		printf(", ID: %d\n", board_id);
102237c3637SMasahiro Yamada 	printf("\n");
103237c3637SMasahiro Yamada 
104237c3637SMasahiro Yamada 	return 0;
105237c3637SMasahiro Yamada }
106237c3637SMasahiro Yamada #endif	/* CONFIG_DISPLAY_BOARDINFO */
107237c3637SMasahiro Yamada 
108237c3637SMasahiro Yamada __weak int tegra_lcd_pmic_init(int board_it)
109237c3637SMasahiro Yamada {
110237c3637SMasahiro Yamada 	return 0;
111237c3637SMasahiro Yamada }
112237c3637SMasahiro Yamada 
113c96d709fSSimon Glass __weak int nvidia_board_init(void)
114c96d709fSSimon Glass {
115c96d709fSSimon Glass 	return 0;
116c96d709fSSimon Glass }
117c96d709fSSimon Glass 
118237c3637SMasahiro Yamada /*
119237c3637SMasahiro Yamada  * Routine: board_init
120237c3637SMasahiro Yamada  * Description: Early hardware init.
121237c3637SMasahiro Yamada  */
122237c3637SMasahiro Yamada int board_init(void)
123237c3637SMasahiro Yamada {
124237c3637SMasahiro Yamada 	__maybe_unused int err;
125237c3637SMasahiro Yamada 	__maybe_unused int board_id;
126237c3637SMasahiro Yamada 
127237c3637SMasahiro Yamada 	/* Do clocks and UART first so that printf() works */
128237c3637SMasahiro Yamada 	clock_init();
129237c3637SMasahiro Yamada 	clock_verify();
130237c3637SMasahiro Yamada 
131eca676bdSAlexandre Courbot 	tegra_gpu_config();
132871d78edSAlexandre Courbot 
133237c3637SMasahiro Yamada #ifdef CONFIG_TEGRA_SPI
134237c3637SMasahiro Yamada 	pin_mux_spi();
135237c3637SMasahiro Yamada #endif
136237c3637SMasahiro Yamada 
137237c3637SMasahiro Yamada #ifdef CONFIG_PWM_TEGRA
138237c3637SMasahiro Yamada 	if (pwm_init(gd->fdt_blob))
139237c3637SMasahiro Yamada 		debug("%s: Failed to init pwm\n", __func__);
140237c3637SMasahiro Yamada #endif
141237c3637SMasahiro Yamada #ifdef CONFIG_LCD
142237c3637SMasahiro Yamada 	pin_mux_display();
143237c3637SMasahiro Yamada 	tegra_lcd_check_next_stage(gd->fdt_blob, 0);
144237c3637SMasahiro Yamada #endif
145237c3637SMasahiro Yamada 	/* boot param addr */
146237c3637SMasahiro Yamada 	gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100);
147237c3637SMasahiro Yamada 
148237c3637SMasahiro Yamada 	power_det_init();
149237c3637SMasahiro Yamada 
150237c3637SMasahiro Yamada #ifdef CONFIG_SYS_I2C_TEGRA
151237c3637SMasahiro Yamada # ifdef CONFIG_TEGRA_PMU
152237c3637SMasahiro Yamada 	if (pmu_set_nominal())
153237c3637SMasahiro Yamada 		debug("Failed to select nominal voltages\n");
154237c3637SMasahiro Yamada #  ifdef CONFIG_TEGRA_CLOCK_SCALING
155237c3637SMasahiro Yamada 	err = board_emc_init();
156237c3637SMasahiro Yamada 	if (err)
157237c3637SMasahiro Yamada 		debug("Memory controller init failed: %d\n", err);
158237c3637SMasahiro Yamada #  endif
159237c3637SMasahiro Yamada # endif /* CONFIG_TEGRA_PMU */
160237c3637SMasahiro Yamada #ifdef CONFIG_AS3722_POWER
161237c3637SMasahiro Yamada 	err = as3722_init(NULL);
162237c3637SMasahiro Yamada 	if (err && err != -ENODEV)
163237c3637SMasahiro Yamada 		return err;
164237c3637SMasahiro Yamada #endif
165237c3637SMasahiro Yamada #endif /* CONFIG_SYS_I2C_TEGRA */
166237c3637SMasahiro Yamada 
167237c3637SMasahiro Yamada #ifdef CONFIG_USB_EHCI_TEGRA
168237c3637SMasahiro Yamada 	pin_mux_usb();
169534f9d3fSSimon Glass #endif
170237c3637SMasahiro Yamada 
171237c3637SMasahiro Yamada #ifdef CONFIG_LCD
172237c3637SMasahiro Yamada 	board_id = tegra_board_id();
173237c3637SMasahiro Yamada 	err = tegra_lcd_pmic_init(board_id);
174237c3637SMasahiro Yamada 	if (err)
175237c3637SMasahiro Yamada 		return err;
176237c3637SMasahiro Yamada 	tegra_lcd_check_next_stage(gd->fdt_blob, 0);
177237c3637SMasahiro Yamada #endif
178237c3637SMasahiro Yamada 
179237c3637SMasahiro Yamada #ifdef CONFIG_TEGRA_NAND
180237c3637SMasahiro Yamada 	pin_mux_nand();
181237c3637SMasahiro Yamada #endif
182237c3637SMasahiro Yamada 
183237c3637SMasahiro Yamada 	tegra_xusb_padctl_init(gd->fdt_blob);
184237c3637SMasahiro Yamada 
185237c3637SMasahiro Yamada #ifdef CONFIG_TEGRA_LP0
186237c3637SMasahiro Yamada 	/* save Sdram params to PMC 2, 4, and 24 for WB0 */
187237c3637SMasahiro Yamada 	warmboot_save_sdram_params();
188237c3637SMasahiro Yamada 
189237c3637SMasahiro Yamada 	/* prepare the WB code to LP0 location */
190237c3637SMasahiro Yamada 	warmboot_prepare_code(TEGRA_LP0_ADDR, TEGRA_LP0_SIZE);
191237c3637SMasahiro Yamada #endif
192c96d709fSSimon Glass 	return nvidia_board_init();
193237c3637SMasahiro Yamada }
194237c3637SMasahiro Yamada 
195237c3637SMasahiro Yamada #ifdef CONFIG_BOARD_EARLY_INIT_F
196237c3637SMasahiro Yamada static void __gpio_early_init(void)
197237c3637SMasahiro Yamada {
198237c3637SMasahiro Yamada }
199237c3637SMasahiro Yamada 
200237c3637SMasahiro Yamada void gpio_early_init(void) __attribute__((weak, alias("__gpio_early_init")));
201237c3637SMasahiro Yamada 
202237c3637SMasahiro Yamada int board_early_init_f(void)
203237c3637SMasahiro Yamada {
204*dd8204deSStephen Warren #if defined(CONFIG_TEGRA_DISCONNECT_UDC_ON_BOOT)
205*dd8204deSStephen Warren #define USBCMD_FS2 (1 << 15)
206*dd8204deSStephen Warren 	{
207*dd8204deSStephen Warren 		struct usb_ctlr *usbctlr = (struct usb_ctlr *)0x7d000000;
208*dd8204deSStephen Warren 		writel(USBCMD_FS2, &usbctlr->usb_cmd);
209*dd8204deSStephen Warren 	}
210*dd8204deSStephen Warren #endif
211*dd8204deSStephen Warren 
212aa441877SThierry Reding 	/* Do any special system timer/TSC setup */
213aa441877SThierry Reding #if defined(CONFIG_TEGRA_SUPPORT_NON_SECURE)
214aa441877SThierry Reding 	if (!tegra_cpu_is_non_secure())
215aa441877SThierry Reding #endif
216aa441877SThierry Reding 		arch_timer_init();
217aa441877SThierry Reding 
218237c3637SMasahiro Yamada 	pinmux_init();
219237c3637SMasahiro Yamada 	board_init_uart_f();
220237c3637SMasahiro Yamada 
221237c3637SMasahiro Yamada 	/* Initialize periph GPIOs */
222237c3637SMasahiro Yamada 	gpio_early_init();
223237c3637SMasahiro Yamada 	gpio_early_init_uart();
224237c3637SMasahiro Yamada #ifdef CONFIG_LCD
225237c3637SMasahiro Yamada 	tegra_lcd_early_init(gd->fdt_blob);
226237c3637SMasahiro Yamada #endif
227237c3637SMasahiro Yamada 
228237c3637SMasahiro Yamada 	return 0;
229237c3637SMasahiro Yamada }
230237c3637SMasahiro Yamada #endif	/* EARLY_INIT */
231237c3637SMasahiro Yamada 
232237c3637SMasahiro Yamada int board_late_init(void)
233237c3637SMasahiro Yamada {
234237c3637SMasahiro Yamada #ifdef CONFIG_LCD
235237c3637SMasahiro Yamada 	/* Make sure we finish initing the LCD */
236237c3637SMasahiro Yamada 	tegra_lcd_check_next_stage(gd->fdt_blob, 1);
237237c3637SMasahiro Yamada #endif
238237c3637SMasahiro Yamada #if defined(CONFIG_TEGRA_SUPPORT_NON_SECURE)
239237c3637SMasahiro Yamada 	if (tegra_cpu_is_non_secure()) {
240237c3637SMasahiro Yamada 		printf("CPU is in NS mode\n");
241237c3637SMasahiro Yamada 		setenv("cpu_ns_mode", "1");
242237c3637SMasahiro Yamada 	} else {
243237c3637SMasahiro Yamada 		setenv("cpu_ns_mode", "");
244237c3637SMasahiro Yamada 	}
245237c3637SMasahiro Yamada #endif
24666999892STom Warren 	start_cpu_fan();
24766999892STom Warren 
248237c3637SMasahiro Yamada 	return 0;
249237c3637SMasahiro Yamada }
250237c3637SMasahiro Yamada 
251237c3637SMasahiro Yamada #if defined(CONFIG_TEGRA_MMC)
252237c3637SMasahiro Yamada __weak void pin_mux_mmc(void)
253237c3637SMasahiro Yamada {
254237c3637SMasahiro Yamada }
255237c3637SMasahiro Yamada 
256237c3637SMasahiro Yamada /* this is a weak define that we are overriding */
257237c3637SMasahiro Yamada int board_mmc_init(bd_t *bd)
258237c3637SMasahiro Yamada {
259237c3637SMasahiro Yamada 	debug("%s called\n", __func__);
260237c3637SMasahiro Yamada 
261237c3637SMasahiro Yamada 	/* Enable muxes, etc. for SDMMC controllers */
262237c3637SMasahiro Yamada 	pin_mux_mmc();
263237c3637SMasahiro Yamada 
264237c3637SMasahiro Yamada 	debug("%s: init MMC\n", __func__);
265237c3637SMasahiro Yamada 	tegra_mmc_init();
266237c3637SMasahiro Yamada 
267237c3637SMasahiro Yamada 	return 0;
268237c3637SMasahiro Yamada }
269237c3637SMasahiro Yamada 
270237c3637SMasahiro Yamada void pad_init_mmc(struct mmc_host *host)
271237c3637SMasahiro Yamada {
272237c3637SMasahiro Yamada #if defined(CONFIG_TEGRA30)
273237c3637SMasahiro Yamada 	enum periph_id id = host->mmc_id;
274237c3637SMasahiro Yamada 	u32 val;
275237c3637SMasahiro Yamada 
276237c3637SMasahiro Yamada 	debug("%s: sdmmc address = %08x, id = %d\n", __func__,
277237c3637SMasahiro Yamada 		(unsigned int)host->reg, id);
278237c3637SMasahiro Yamada 
279237c3637SMasahiro Yamada 	/* Set the pad drive strength for SDMMC1 or 3 only */
280237c3637SMasahiro Yamada 	if (id != PERIPH_ID_SDMMC1 && id != PERIPH_ID_SDMMC3) {
281237c3637SMasahiro Yamada 		debug("%s: settings are only valid for SDMMC1/SDMMC3!\n",
282237c3637SMasahiro Yamada 			__func__);
283237c3637SMasahiro Yamada 		return;
284237c3637SMasahiro Yamada 	}
285237c3637SMasahiro Yamada 
286237c3637SMasahiro Yamada 	val = readl(&host->reg->sdmemcmppadctl);
287237c3637SMasahiro Yamada 	val &= 0xFFFFFFF0;
288237c3637SMasahiro Yamada 	val |= MEMCOMP_PADCTRL_VREF;
289237c3637SMasahiro Yamada 	writel(val, &host->reg->sdmemcmppadctl);
290237c3637SMasahiro Yamada 
291237c3637SMasahiro Yamada 	val = readl(&host->reg->autocalcfg);
292237c3637SMasahiro Yamada 	val &= 0xFFFF0000;
293237c3637SMasahiro Yamada 	val |= AUTO_CAL_PU_OFFSET | AUTO_CAL_PD_OFFSET | AUTO_CAL_ENABLED;
294237c3637SMasahiro Yamada 	writel(val, &host->reg->autocalcfg);
295237c3637SMasahiro Yamada #endif	/* T30 */
296237c3637SMasahiro Yamada }
297237c3637SMasahiro Yamada #endif	/* MMC */
29800f782a9SThierry Reding 
299bbc1b99eSStephen Warren /*
300bbc1b99eSStephen Warren  * In some SW environments, a memory carve-out exists to house a secure
301bbc1b99eSStephen Warren  * monitor, a trusted OS, and/or various statically allocated media buffers.
302bbc1b99eSStephen Warren  *
303bbc1b99eSStephen Warren  * This carveout exists at the highest possible address that is within a
304bbc1b99eSStephen Warren  * 32-bit physical address space.
305bbc1b99eSStephen Warren  *
306bbc1b99eSStephen Warren  * This function returns the total size of this carve-out. At present, the
307bbc1b99eSStephen Warren  * returned value is hard-coded for simplicity. In the future, it may be
308bbc1b99eSStephen Warren  * possible to determine the carve-out size:
309bbc1b99eSStephen Warren  * - By querying some run-time information source, such as:
310bbc1b99eSStephen Warren  *   - A structure passed to U-Boot by earlier boot software.
311bbc1b99eSStephen Warren  *   - SoC registers.
312bbc1b99eSStephen Warren  *   - A call into the secure monitor.
313bbc1b99eSStephen Warren  * - In the per-board U-Boot configuration header, based on knowledge of the
314bbc1b99eSStephen Warren  *   SW environment that U-Boot is being built for.
315bbc1b99eSStephen Warren  *
316bbc1b99eSStephen Warren  * For now, we support two configurations in U-Boot:
317bbc1b99eSStephen Warren  * - 32-bit ports without any form of carve-out.
318bbc1b99eSStephen Warren  * - 64 bit ports which are assumed to use a carve-out of a conservatively
319bbc1b99eSStephen Warren  *   hard-coded size.
320bbc1b99eSStephen Warren  */
321bbc1b99eSStephen Warren static ulong carveout_size(void)
322bbc1b99eSStephen Warren {
32300f782a9SThierry Reding #ifdef CONFIG_ARM64
324bbc1b99eSStephen Warren 	return SZ_512M;
325bbc1b99eSStephen Warren #else
326bbc1b99eSStephen Warren 	return 0;
327bbc1b99eSStephen Warren #endif
328bbc1b99eSStephen Warren }
329bbc1b99eSStephen Warren 
330bbc1b99eSStephen Warren /*
331bbc1b99eSStephen Warren  * Determine the amount of usable RAM below 4GiB, taking into account any
332bbc1b99eSStephen Warren  * carve-out that may be assigned.
333bbc1b99eSStephen Warren  */
334bbc1b99eSStephen Warren static ulong usable_ram_size_below_4g(void)
335bbc1b99eSStephen Warren {
336bbc1b99eSStephen Warren 	ulong total_size_below_4g;
337bbc1b99eSStephen Warren 	ulong usable_size_below_4g;
338bbc1b99eSStephen Warren 
339bbc1b99eSStephen Warren 	/*
340bbc1b99eSStephen Warren 	 * The total size of RAM below 4GiB is the lesser address of:
341bbc1b99eSStephen Warren 	 * (a) 2GiB itself (RAM starts at 2GiB, and 4GiB - 2GiB == 2GiB).
342bbc1b99eSStephen Warren 	 * (b) The size RAM physically present in the system.
343bbc1b99eSStephen Warren 	 */
344bbc1b99eSStephen Warren 	if (gd->ram_size < SZ_2G)
345bbc1b99eSStephen Warren 		total_size_below_4g = gd->ram_size;
346bbc1b99eSStephen Warren 	else
347bbc1b99eSStephen Warren 		total_size_below_4g = SZ_2G;
348bbc1b99eSStephen Warren 
349bbc1b99eSStephen Warren 	/* Calculate usable RAM by subtracting out any carve-out size */
350bbc1b99eSStephen Warren 	usable_size_below_4g = total_size_below_4g - carveout_size();
351bbc1b99eSStephen Warren 
352bbc1b99eSStephen Warren 	return usable_size_below_4g;
353bbc1b99eSStephen Warren }
354bbc1b99eSStephen Warren 
355bbc1b99eSStephen Warren /*
356bbc1b99eSStephen Warren  * Represent all available RAM in either one or two banks.
357bbc1b99eSStephen Warren  *
358bbc1b99eSStephen Warren  * The first bank describes any usable RAM below 4GiB.
359bbc1b99eSStephen Warren  * The second bank describes any RAM above 4GiB.
360bbc1b99eSStephen Warren  *
361bbc1b99eSStephen Warren  * This split is driven by the following requirements:
362bbc1b99eSStephen Warren  * - The NVIDIA L4T kernel requires separate entries in the DT /memory/reg
363bbc1b99eSStephen Warren  *   property for memory below and above the 4GiB boundary. The layout of that
364bbc1b99eSStephen Warren  *   DT property is directly driven by the entries in the U-Boot bank array.
365bbc1b99eSStephen Warren  * - The potential existence of a carve-out at the end of RAM below 4GiB can
366bbc1b99eSStephen Warren  *   only be represented using multiple banks.
367bbc1b99eSStephen Warren  *
368bbc1b99eSStephen Warren  * Explicitly removing the carve-out RAM from the bank entries makes the RAM
369bbc1b99eSStephen Warren  * layout a bit more obvious, e.g. when running "bdinfo" at the U-Boot
370bbc1b99eSStephen Warren  * command-line.
371bbc1b99eSStephen Warren  *
372bbc1b99eSStephen Warren  * This does mean that the DT U-Boot passes to the Linux kernel will not
373bbc1b99eSStephen Warren  * include this RAM in /memory/reg at all. An alternative would be to include
374bbc1b99eSStephen Warren  * all RAM in the U-Boot banks (and hence DT), and add a /memreserve/ node
375bbc1b99eSStephen Warren  * into DT to stop the kernel from using the RAM. IIUC, I don't /think/ the
376bbc1b99eSStephen Warren  * Linux kernel will ever need to access any RAM in* the carve-out via a CPU
377bbc1b99eSStephen Warren  * mapping, so either way is acceptable.
378bbc1b99eSStephen Warren  *
379bbc1b99eSStephen Warren  * On 32-bit systems, we never define a bank for RAM above 4GiB, since the
380bbc1b99eSStephen Warren  * start address of that bank cannot be represented in the 32-bit .size
381bbc1b99eSStephen Warren  * field.
382bbc1b99eSStephen Warren  */
383bbc1b99eSStephen Warren void dram_init_banksize(void)
384bbc1b99eSStephen Warren {
385bbc1b99eSStephen Warren 	gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
386bbc1b99eSStephen Warren 	gd->bd->bi_dram[0].size = usable_ram_size_below_4g();
387bbc1b99eSStephen Warren 
388e81ca884SSimon Glass #ifdef CONFIG_PCI
389e81ca884SSimon Glass 	gd->pci_ram_top = gd->bd->bi_dram[0].start + gd->bd->bi_dram[0].size;
390e81ca884SSimon Glass #endif
391e81ca884SSimon Glass 
392bbc1b99eSStephen Warren #ifdef CONFIG_PHYS_64BIT
393bbc1b99eSStephen Warren 	if (gd->ram_size > SZ_2G) {
394bbc1b99eSStephen Warren 		gd->bd->bi_dram[1].start = 0x100000000;
395bbc1b99eSStephen Warren 		gd->bd->bi_dram[1].size = gd->ram_size - SZ_2G;
396bbc1b99eSStephen Warren 	} else
397bbc1b99eSStephen Warren #endif
398bbc1b99eSStephen Warren 	{
399bbc1b99eSStephen Warren 		gd->bd->bi_dram[1].start = 0;
400bbc1b99eSStephen Warren 		gd->bd->bi_dram[1].size = 0;
401bbc1b99eSStephen Warren 	}
402bbc1b99eSStephen Warren }
403bbc1b99eSStephen Warren 
40400f782a9SThierry Reding /*
40500f782a9SThierry Reding  * Most hardware on 64-bit Tegra is still restricted to DMA to the lower
40600f782a9SThierry Reding  * 32-bits of the physical address space. Cap the maximum usable RAM area
40700f782a9SThierry Reding  * at 4 GiB to avoid DMA buffers from being allocated beyond the 32-bit
408bbc1b99eSStephen Warren  * boundary that most devices can address. Also, don't let U-Boot use any
409bbc1b99eSStephen Warren  * carve-out, as mentioned above.
410424afc0aSStephen Warren  *
411bbc1b99eSStephen Warren  * This function is called before dram_init_banksize(), so we can't simply
412bbc1b99eSStephen Warren  * return gd->bd->bi_dram[1].start + gd->bd->bi_dram[1].size.
41300f782a9SThierry Reding  */
41400f782a9SThierry Reding ulong board_get_usable_ram_top(ulong total_size)
41500f782a9SThierry Reding {
416bbc1b99eSStephen Warren 	return CONFIG_SYS_SDRAM_BASE + usable_ram_size_below_4g();
41700f782a9SThierry Reding }
418d6bf06c0SAlexandre Courbot 
419d6bf06c0SAlexandre Courbot /*
420d6bf06c0SAlexandre Courbot  * This function is called right before the kernel is booted. "blob" is the
421d6bf06c0SAlexandre Courbot  * device tree that will be passed to the kernel.
422d6bf06c0SAlexandre Courbot  */
423d6bf06c0SAlexandre Courbot int ft_system_setup(void *blob, bd_t *bd)
424d6bf06c0SAlexandre Courbot {
425d6bf06c0SAlexandre Courbot 	const char *gpu_path =
426d6bf06c0SAlexandre Courbot #if defined(CONFIG_TEGRA124) || defined(CONFIG_TEGRA210)
427d6bf06c0SAlexandre Courbot 		"/gpu@0,57000000";
428d6bf06c0SAlexandre Courbot #else
429d6bf06c0SAlexandre Courbot 		NULL;
430d6bf06c0SAlexandre Courbot #endif
431d6bf06c0SAlexandre Courbot 
432d6bf06c0SAlexandre Courbot 	/* Enable GPU node if GPU setup has been performed */
433d6bf06c0SAlexandre Courbot 	if (gpu_path != NULL)
434eca676bdSAlexandre Courbot 		return tegra_gpu_enable_node(blob, gpu_path);
435d6bf06c0SAlexandre Courbot 
436d6bf06c0SAlexandre Courbot 	return 0;
437d6bf06c0SAlexandre Courbot }
438