]> git.ipfire.org Git - people/ms/u-boot.git/blame_incremental - board/nvidia/common/board.c
ARM: tegra: support running in non-secure mode
[people/ms/u-boot.git] / board / nvidia / common / board.c
... / ...
CommitLineData
1/*
2 * (C) Copyright 2010,2011
3 * NVIDIA Corporation <www.nvidia.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <dm.h>
10#include <ns16550.h>
11#include <linux/compiler.h>
12#include <asm/io.h>
13#include <asm/arch/clock.h>
14#ifdef CONFIG_LCD
15#include <asm/arch/display.h>
16#endif
17#include <asm/arch/funcmux.h>
18#include <asm/arch/pinmux.h>
19#include <asm/arch/pmu.h>
20#ifdef CONFIG_PWM_TEGRA
21#include <asm/arch/pwm.h>
22#endif
23#include <asm/arch/tegra.h>
24#include <asm/arch-tegra/ap.h>
25#include <asm/arch-tegra/board.h>
26#include <asm/arch-tegra/clk_rst.h>
27#include <asm/arch-tegra/pmc.h>
28#include <asm/arch-tegra/sys_proto.h>
29#include <asm/arch-tegra/uart.h>
30#include <asm/arch-tegra/warmboot.h>
31#ifdef CONFIG_TEGRA_CLOCK_SCALING
32#include <asm/arch/emc.h>
33#endif
34#ifdef CONFIG_USB_EHCI_TEGRA
35#include <asm/arch-tegra/usb.h>
36#include <usb.h>
37#endif
38#ifdef CONFIG_TEGRA_MMC
39#include <asm/arch-tegra/tegra_mmc.h>
40#include <asm/arch-tegra/mmc.h>
41#endif
42#include <asm/arch-tegra/xusb-padctl.h>
43#include <i2c.h>
44#include <spi.h>
45#include "emc.h"
46
47DECLARE_GLOBAL_DATA_PTR;
48
49#ifdef CONFIG_SPL_BUILD
50/* TODO(sjg@chromium.org): Remove once SPL supports device tree */
51U_BOOT_DEVICE(tegra_gpios) = {
52 "gpio_tegra"
53};
54#endif
55
56const struct tegra_sysinfo sysinfo = {
57 CONFIG_TEGRA_BOARD_STRING
58};
59
60__weak void pinmux_init(void) {}
61__weak void pin_mux_usb(void) {}
62__weak void pin_mux_spi(void) {}
63__weak void gpio_early_init_uart(void) {}
64__weak void pin_mux_display(void) {}
65
66#if defined(CONFIG_TEGRA_NAND)
67__weak void pin_mux_nand(void)
68{
69 funcmux_select(PERIPH_ID_NDFLASH, FUNCMUX_DEFAULT);
70}
71#endif
72
73/*
74 * Routine: power_det_init
75 * Description: turn off power detects
76 */
77static void power_det_init(void)
78{
79#if defined(CONFIG_TEGRA20)
80 struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
81
82 /* turn off power detects */
83 writel(0, &pmc->pmc_pwr_det_latch);
84 writel(0, &pmc->pmc_pwr_det);
85#endif
86}
87
88/*
89 * Routine: board_init
90 * Description: Early hardware init.
91 */
92int board_init(void)
93{
94 __maybe_unused int err;
95
96 /* Do clocks and UART first so that printf() works */
97 clock_init();
98 clock_verify();
99
100#ifdef CONFIG_TEGRA_SPI
101 pin_mux_spi();
102#endif
103
104#ifdef CONFIG_PWM_TEGRA
105 if (pwm_init(gd->fdt_blob))
106 debug("%s: Failed to init pwm\n", __func__);
107#endif
108#ifdef CONFIG_LCD
109 pin_mux_display();
110 tegra_lcd_check_next_stage(gd->fdt_blob, 0);
111#endif
112 /* boot param addr */
113 gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100);
114
115 power_det_init();
116
117#ifdef CONFIG_SYS_I2C_TEGRA
118# ifdef CONFIG_TEGRA_PMU
119 if (pmu_set_nominal())
120 debug("Failed to select nominal voltages\n");
121# ifdef CONFIG_TEGRA_CLOCK_SCALING
122 err = board_emc_init();
123 if (err)
124 debug("Memory controller init failed: %d\n", err);
125# endif
126# endif /* CONFIG_TEGRA_PMU */
127#endif /* CONFIG_SYS_I2C_TEGRA */
128
129#ifdef CONFIG_USB_EHCI_TEGRA
130 pin_mux_usb();
131 usb_process_devicetree(gd->fdt_blob);
132#endif
133
134#ifdef CONFIG_LCD
135 tegra_lcd_check_next_stage(gd->fdt_blob, 0);
136#endif
137
138#ifdef CONFIG_TEGRA_NAND
139 pin_mux_nand();
140#endif
141
142 tegra_xusb_padctl_init(gd->fdt_blob);
143
144#ifdef CONFIG_TEGRA_LP0
145 /* save Sdram params to PMC 2, 4, and 24 for WB0 */
146 warmboot_save_sdram_params();
147
148 /* prepare the WB code to LP0 location */
149 warmboot_prepare_code(TEGRA_LP0_ADDR, TEGRA_LP0_SIZE);
150#endif
151
152 return 0;
153}
154
155#ifdef CONFIG_BOARD_EARLY_INIT_F
156static void __gpio_early_init(void)
157{
158}
159
160void gpio_early_init(void) __attribute__((weak, alias("__gpio_early_init")));
161
162int board_early_init_f(void)
163{
164 pinmux_init();
165 board_init_uart_f();
166
167 /* Initialize periph GPIOs */
168 gpio_early_init();
169 gpio_early_init_uart();
170#ifdef CONFIG_LCD
171 tegra_lcd_early_init(gd->fdt_blob);
172#endif
173
174 return 0;
175}
176#endif /* EARLY_INIT */
177
178int board_late_init(void)
179{
180#ifdef CONFIG_LCD
181 /* Make sure we finish initing the LCD */
182 tegra_lcd_check_next_stage(gd->fdt_blob, 1);
183#endif
184#if defined(CONFIG_TEGRA_SUPPORT_NON_SECURE)
185 if (tegra_cpu_is_non_secure()) {
186 printf("CPU is in NS mode\n");
187 setenv("cpu_ns_mode", "1");
188 } else {
189 setenv("cpu_ns_mode", "");
190 }
191#endif
192 return 0;
193}
194
195#if defined(CONFIG_TEGRA_MMC)
196__weak void pin_mux_mmc(void)
197{
198}
199
200/* this is a weak define that we are overriding */
201int board_mmc_init(bd_t *bd)
202{
203 debug("%s called\n", __func__);
204
205 /* Enable muxes, etc. for SDMMC controllers */
206 pin_mux_mmc();
207
208 debug("%s: init MMC\n", __func__);
209 tegra_mmc_init();
210
211 return 0;
212}
213
214void pad_init_mmc(struct mmc_host *host)
215{
216#if defined(CONFIG_TEGRA30)
217 enum periph_id id = host->mmc_id;
218 u32 val;
219
220 debug("%s: sdmmc address = %08x, id = %d\n", __func__,
221 (unsigned int)host->reg, id);
222
223 /* Set the pad drive strength for SDMMC1 or 3 only */
224 if (id != PERIPH_ID_SDMMC1 && id != PERIPH_ID_SDMMC3) {
225 debug("%s: settings are only valid for SDMMC1/SDMMC3!\n",
226 __func__);
227 return;
228 }
229
230 val = readl(&host->reg->sdmemcmppadctl);
231 val &= 0xFFFFFFF0;
232 val |= MEMCOMP_PADCTRL_VREF;
233 writel(val, &host->reg->sdmemcmppadctl);
234
235 val = readl(&host->reg->autocalcfg);
236 val &= 0xFFFF0000;
237 val |= AUTO_CAL_PU_OFFSET | AUTO_CAL_PD_OFFSET | AUTO_CAL_ENABLED;
238 writel(val, &host->reg->autocalcfg);
239#endif /* T30 */
240}
241#endif /* MMC */