2 * (C) Copyright 2010,2011
3 * NVIDIA Corporation <www.nvidia.com>
5 * SPDX-License-Identifier: GPL-2.0+
11 #include <linux/compiler.h>
13 #include <asm/arch/clock.h>
15 #include <asm/arch/display.h>
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>
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>
34 #ifdef CONFIG_USB_EHCI_TEGRA
35 #include <asm/arch-tegra/usb.h>
38 #ifdef CONFIG_TEGRA_MMC
39 #include <asm/arch-tegra/tegra_mmc.h>
40 #include <asm/arch-tegra/mmc.h>
42 #include <asm/arch-tegra/xusb-padctl.h>
47 DECLARE_GLOBAL_DATA_PTR;
49 #ifdef CONFIG_SPL_BUILD
50 /* TODO(sjg@chromium.org): Remove once SPL supports device tree */
51 U_BOOT_DEVICE(tegra_gpios) = {
56 __weak void pinmux_init(void) {}
57 __weak void pin_mux_usb(void) {}
58 __weak void pin_mux_spi(void) {}
59 __weak void gpio_early_init_uart(void) {}
60 __weak void pin_mux_display(void) {}
62 #if defined(CONFIG_TEGRA_NAND)
63 __weak void pin_mux_nand(void)
65 funcmux_select(PERIPH_ID_NDFLASH, FUNCMUX_DEFAULT);
70 * Routine: power_det_init
71 * Description: turn off power detects
73 static void power_det_init(void)
75 #if defined(CONFIG_TEGRA20)
76 struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
78 /* turn off power detects */
79 writel(0, &pmc->pmc_pwr_det_latch);
80 writel(0, &pmc->pmc_pwr_det);
84 __weak int tegra_board_id(void)
89 #ifdef CONFIG_DISPLAY_BOARDINFO
92 int board_id = tegra_board_id();
94 printf("Board: %s", CONFIG_TEGRA_BOARD_STRING);
96 printf(", ID: %d\n", board_id);
101 #endif /* CONFIG_DISPLAY_BOARDINFO */
104 * Routine: board_init
105 * Description: Early hardware init.
109 __maybe_unused int err;
111 /* Do clocks and UART first so that printf() works */
115 #ifdef CONFIG_TEGRA_SPI
119 #ifdef CONFIG_PWM_TEGRA
120 if (pwm_init(gd->fdt_blob))
121 debug("%s: Failed to init pwm\n", __func__);
125 tegra_lcd_check_next_stage(gd->fdt_blob, 0);
127 /* boot param addr */
128 gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100);
132 #ifdef CONFIG_SYS_I2C_TEGRA
133 # ifdef CONFIG_TEGRA_PMU
134 if (pmu_set_nominal())
135 debug("Failed to select nominal voltages\n");
136 # ifdef CONFIG_TEGRA_CLOCK_SCALING
137 err = board_emc_init();
139 debug("Memory controller init failed: %d\n", err);
141 # endif /* CONFIG_TEGRA_PMU */
142 #endif /* CONFIG_SYS_I2C_TEGRA */
144 #ifdef CONFIG_USB_EHCI_TEGRA
146 usb_process_devicetree(gd->fdt_blob);
150 tegra_lcd_check_next_stage(gd->fdt_blob, 0);
153 #ifdef CONFIG_TEGRA_NAND
157 tegra_xusb_padctl_init(gd->fdt_blob);
159 #ifdef CONFIG_TEGRA_LP0
160 /* save Sdram params to PMC 2, 4, and 24 for WB0 */
161 warmboot_save_sdram_params();
163 /* prepare the WB code to LP0 location */
164 warmboot_prepare_code(TEGRA_LP0_ADDR, TEGRA_LP0_SIZE);
170 #ifdef CONFIG_BOARD_EARLY_INIT_F
171 static void __gpio_early_init(void)
175 void gpio_early_init(void) __attribute__((weak, alias("__gpio_early_init")));
177 int board_early_init_f(void)
182 /* Initialize periph GPIOs */
184 gpio_early_init_uart();
186 tegra_lcd_early_init(gd->fdt_blob);
191 #endif /* EARLY_INIT */
193 int board_late_init(void)
196 /* Make sure we finish initing the LCD */
197 tegra_lcd_check_next_stage(gd->fdt_blob, 1);
199 #if defined(CONFIG_TEGRA_SUPPORT_NON_SECURE)
200 if (tegra_cpu_is_non_secure()) {
201 printf("CPU is in NS mode\n");
202 setenv("cpu_ns_mode", "1");
204 setenv("cpu_ns_mode", "");
210 #if defined(CONFIG_TEGRA_MMC)
211 __weak void pin_mux_mmc(void)
215 /* this is a weak define that we are overriding */
216 int board_mmc_init(bd_t *bd)
218 debug("%s called\n", __func__);
220 /* Enable muxes, etc. for SDMMC controllers */
223 debug("%s: init MMC\n", __func__);
229 void pad_init_mmc(struct mmc_host *host)
231 #if defined(CONFIG_TEGRA30)
232 enum periph_id id = host->mmc_id;
235 debug("%s: sdmmc address = %08x, id = %d\n", __func__,
236 (unsigned int)host->reg, id);
238 /* Set the pad drive strength for SDMMC1 or 3 only */
239 if (id != PERIPH_ID_SDMMC1 && id != PERIPH_ID_SDMMC3) {
240 debug("%s: settings are only valid for SDMMC1/SDMMC3!\n",
245 val = readl(&host->reg->sdmemcmppadctl);
247 val |= MEMCOMP_PADCTRL_VREF;
248 writel(val, &host->reg->sdmemcmppadctl);
250 val = readl(&host->reg->autocalcfg);
252 val |= AUTO_CAL_PU_OFFSET | AUTO_CAL_PD_OFFSET | AUTO_CAL_ENABLED;
253 writel(val, &host->reg->autocalcfg);