blob: 37953cfda8a1d43109646a9b69b16dad7cefddf8 [file] [log] [blame]
Tom Warren3f82b1d2011-01-27 10:58:05 +00001/*
2 * (C) Copyright 2010,2011
3 * NVIDIA Corporation <www.nvidia.com>
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Tom Warren3f82b1d2011-01-27 10:58:05 +00006 */
7
8#include <common.h>
Simon Glass0521f982014-11-10 17:16:51 -07009#include <dm.h>
Simon Glass346451b2015-04-14 21:03:28 -060010#include <errno.h>
Tom Warren3f82b1d2011-01-27 10:58:05 +000011#include <ns16550.h>
Jimmy Zhangc5b34a22012-04-10 05:17:06 +000012#include <linux/compiler.h>
Tom Warren3f82b1d2011-01-27 10:58:05 +000013#include <asm/io.h>
Simon Glassb4ba2be2011-08-30 06:23:13 +000014#include <asm/arch/clock.h>
Tom Warren6d6c0ba2012-12-11 13:34:17 +000015#ifdef CONFIG_LCD
Simon Glass1b24a502012-10-17 13:24:52 +000016#include <asm/arch/display.h>
Tom Warren6d6c0ba2012-12-11 13:34:17 +000017#endif
Lucas Stachc0720af2012-09-29 10:02:09 +000018#include <asm/arch/funcmux.h>
Tom Warren3f82b1d2011-01-27 10:58:05 +000019#include <asm/arch/pinmux.h>
Simon Glass87236262012-04-02 13:18:54 +000020#include <asm/arch/pmu.h>
Tom Warren6d6c0ba2012-12-11 13:34:17 +000021#ifdef CONFIG_PWM_TEGRA
Simon Glasse1ae0d12012-10-17 13:24:49 +000022#include <asm/arch/pwm.h>
Tom Warren6d6c0ba2012-12-11 13:34:17 +000023#endif
Tom Warren150c2492012-09-19 15:50:56 -070024#include <asm/arch/tegra.h>
Stephen Warren73c38932015-01-19 16:25:52 -070025#include <asm/arch-tegra/ap.h>
Tom Warren150c2492012-09-19 15:50:56 -070026#include <asm/arch-tegra/board.h>
27#include <asm/arch-tegra/clk_rst.h>
28#include <asm/arch-tegra/pmc.h>
29#include <asm/arch-tegra/sys_proto.h>
30#include <asm/arch-tegra/uart.h>
31#include <asm/arch-tegra/warmboot.h>
Alexandre Courbot871d78e2015-07-09 16:33:00 +090032#include <asm/arch-tegra/gpu.h>
Tom Warren6d6c0ba2012-12-11 13:34:17 +000033#ifdef CONFIG_TEGRA_CLOCK_SCALING
34#include <asm/arch/emc.h>
35#endif
36#ifdef CONFIG_USB_EHCI_TEGRA
Lucas Stach7ae18f32013-02-07 07:16:29 +000037#include <asm/arch-tegra/usb.h>
Mateusz Zalega16297cf2013-10-04 19:22:26 +020038#include <usb.h>
Tom Warren6d6c0ba2012-12-11 13:34:17 +000039#endif
Tom Warrenc9aa8312013-02-21 12:31:30 +000040#ifdef CONFIG_TEGRA_MMC
Tom Warren190be1f2013-02-26 12:26:55 -070041#include <asm/arch-tegra/tegra_mmc.h>
Tom Warrenc9aa8312013-02-21 12:31:30 +000042#include <asm/arch-tegra/mmc.h>
43#endif
Thierry Reding79c7a902014-12-09 22:25:09 -070044#include <asm/arch-tegra/xusb-padctl.h>
Simon Glass346451b2015-04-14 21:03:28 -060045#include <power/as3722.h>
Simon Glasscb445fb2012-02-03 15:13:57 +000046#include <i2c.h>
Tom Warren6d6c0ba2012-12-11 13:34:17 +000047#include <spi.h>
Jimmy Zhangc5b34a22012-04-10 05:17:06 +000048#include "emc.h"
Tom Warren3f82b1d2011-01-27 10:58:05 +000049
50DECLARE_GLOBAL_DATA_PTR;
51
Simon Glass0521f982014-11-10 17:16:51 -070052#ifdef CONFIG_SPL_BUILD
53/* TODO(sjg@chromium.org): Remove once SPL supports device tree */
54U_BOOT_DEVICE(tegra_gpios) = {
55 "gpio_tegra"
56};
57#endif
58
Jeroen Hofstee19d7bf32014-10-08 22:57:46 +020059__weak void pinmux_init(void) {}
60__weak void pin_mux_usb(void) {}
61__weak void pin_mux_spi(void) {}
62__weak void gpio_early_init_uart(void) {}
63__weak void pin_mux_display(void) {}
Tom Warren66999892015-02-20 12:22:22 -070064__weak void start_cpu_fan(void) {}
Lucas Stach0cd10c72012-09-25 20:21:14 +000065
Tom Warrendcd12512014-01-24 12:46:11 -070066#if defined(CONFIG_TEGRA_NAND)
Jeroen Hofstee19d7bf32014-10-08 22:57:46 +020067__weak void pin_mux_nand(void)
Lucas Stachc0720af2012-09-29 10:02:09 +000068{
69 funcmux_select(PERIPH_ID_NDFLASH, FUNCMUX_DEFAULT);
70}
Tom Warrendcd12512014-01-24 12:46:11 -070071#endif
Lucas Stachc0720af2012-09-29 10:02:09 +000072
Tom Warrenf4ef6662011-04-14 12:09:41 +000073/*
Wei Ni5aff0212012-04-02 13:18:58 +000074 * Routine: power_det_init
75 * Description: turn off power detects
76 */
77static void power_det_init(void)
78{
Allen Martin00a27492012-08-31 08:30:00 +000079#if defined(CONFIG_TEGRA20)
Tom Warren29f3e3f2012-09-04 17:00:24 -070080 struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
Wei Ni5aff0212012-04-02 13:18:58 +000081
82 /* turn off power detects */
83 writel(0, &pmc->pmc_pwr_det_latch);
84 writel(0, &pmc->pmc_pwr_det);
85#endif
86}
87
Simon Glassec746642015-04-14 21:03:25 -060088__weak int tegra_board_id(void)
89{
90 return -1;
91}
92
Simon Glass7d874132015-04-14 21:03:24 -060093#ifdef CONFIG_DISPLAY_BOARDINFO
94int checkboard(void)
95{
Simon Glassec746642015-04-14 21:03:25 -060096 int board_id = tegra_board_id();
97
98 printf("Board: %s", CONFIG_TEGRA_BOARD_STRING);
99 if (board_id != -1)
100 printf(", ID: %d\n", board_id);
101 printf("\n");
Simon Glass7d874132015-04-14 21:03:24 -0600102
103 return 0;
104}
105#endif /* CONFIG_DISPLAY_BOARDINFO */
106
Simon Glass82776362015-04-14 21:03:27 -0600107__weak int tegra_lcd_pmic_init(int board_it)
108{
109 return 0;
110}
111
Simon Glassc96d7092015-06-05 14:39:42 -0600112__weak int nvidia_board_init(void)
113{
114 return 0;
115}
116
Wei Ni5aff0212012-04-02 13:18:58 +0000117/*
Tom Warren3f82b1d2011-01-27 10:58:05 +0000118 * Routine: board_init
119 * Description: Early hardware init.
120 */
121int board_init(void)
122{
Jimmy Zhangc5b34a22012-04-10 05:17:06 +0000123 __maybe_unused int err;
Simon Glass82776362015-04-14 21:03:27 -0600124 __maybe_unused int board_id;
Jimmy Zhangc5b34a22012-04-10 05:17:06 +0000125
Simon Glassa04eba92011-11-05 04:46:51 +0000126 /* Do clocks and UART first so that printf() works */
Simon Glass4ed59e72011-09-21 12:40:04 +0000127 clock_init();
128 clock_verify();
129
Alexandre Courbot871d78e2015-07-09 16:33:00 +0900130 config_gpu();
131
Simon Glassfda6fac2014-10-13 23:42:13 -0600132#ifdef CONFIG_TEGRA_SPI
Stephen Warrene0284942012-06-12 08:33:40 +0000133 pin_mux_spi();
Tom Warren9112ef82011-11-05 09:48:11 +0000134#endif
Allen Martinb19f5742013-01-29 13:51:28 +0000135
Simon Glasse1ae0d12012-10-17 13:24:49 +0000136#ifdef CONFIG_PWM_TEGRA
137 if (pwm_init(gd->fdt_blob))
138 debug("%s: Failed to init pwm\n", __func__);
139#endif
Simon Glass1b24a502012-10-17 13:24:52 +0000140#ifdef CONFIG_LCD
Marc Dietrich716d9432012-11-25 11:26:11 +0000141 pin_mux_display();
Simon Glass1b24a502012-10-17 13:24:52 +0000142 tegra_lcd_check_next_stage(gd->fdt_blob, 0);
143#endif
Tom Warren3f82b1d2011-01-27 10:58:05 +0000144 /* boot param addr */
145 gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100);
Wei Ni5aff0212012-04-02 13:18:58 +0000146
147 power_det_init();
148
Simon Glass1f2ba722012-10-30 07:28:53 +0000149#ifdef CONFIG_SYS_I2C_TEGRA
Simon Glass87236262012-04-02 13:18:54 +0000150# ifdef CONFIG_TEGRA_PMU
151 if (pmu_set_nominal())
152 debug("Failed to select nominal voltages\n");
Jimmy Zhangc5b34a22012-04-10 05:17:06 +0000153# ifdef CONFIG_TEGRA_CLOCK_SCALING
154 err = board_emc_init();
155 if (err)
156 debug("Memory controller init failed: %d\n", err);
157# endif
158# endif /* CONFIG_TEGRA_PMU */
Simon Glass346451b2015-04-14 21:03:28 -0600159#ifdef CONFIG_AS3722_POWER
160 err = as3722_init(NULL);
161 if (err && err != -ENODEV)
162 return err;
163#endif
Simon Glass1f2ba722012-10-30 07:28:53 +0000164#endif /* CONFIG_SYS_I2C_TEGRA */
Tom Warren3f82b1d2011-01-27 10:58:05 +0000165
Simon Glassf10393e2012-02-27 10:52:50 +0000166#ifdef CONFIG_USB_EHCI_TEGRA
167 pin_mux_usb();
Simon Glassf10393e2012-02-27 10:52:50 +0000168#endif
Mateusz Zalega16297cf2013-10-04 19:22:26 +0200169
Simon Glass1b24a502012-10-17 13:24:52 +0000170#ifdef CONFIG_LCD
Simon Glass82776362015-04-14 21:03:27 -0600171 board_id = tegra_board_id();
172 err = tegra_lcd_pmic_init(board_id);
173 if (err)
174 return err;
Simon Glass1b24a502012-10-17 13:24:52 +0000175 tegra_lcd_check_next_stage(gd->fdt_blob, 0);
176#endif
Simon Glassf10393e2012-02-27 10:52:50 +0000177
Lucas Stachc0720af2012-09-29 10:02:09 +0000178#ifdef CONFIG_TEGRA_NAND
179 pin_mux_nand();
180#endif
181
Thierry Reding79c7a902014-12-09 22:25:09 -0700182 tegra_xusb_padctl_init(gd->fdt_blob);
183
Tom Warren29f3e3f2012-09-04 17:00:24 -0700184#ifdef CONFIG_TEGRA_LP0
Allen Martina49716a2012-08-31 08:30:11 +0000185 /* save Sdram params to PMC 2, 4, and 24 for WB0 */
186 warmboot_save_sdram_params();
187
Simon Glass67ac5792012-04-02 13:18:57 +0000188 /* prepare the WB code to LP0 location */
189 warmboot_prepare_code(TEGRA_LP0_ADDR, TEGRA_LP0_SIZE);
190#endif
Simon Glassc96d7092015-06-05 14:39:42 -0600191 return nvidia_board_init();
Tom Warren3f82b1d2011-01-27 10:58:05 +0000192}
Tom Warren21ef6a12011-05-31 10:30:37 +0000193
Simon Glass3e00dbd2011-09-21 12:40:03 +0000194#ifdef CONFIG_BOARD_EARLY_INIT_F
Thierry Redingcb7a1cf2012-06-04 20:02:27 +0000195static void __gpio_early_init(void)
196{
197}
198
199void gpio_early_init(void) __attribute__((weak, alias("__gpio_early_init")));
200
Simon Glass3e00dbd2011-09-21 12:40:03 +0000201int board_early_init_f(void)
202{
Thierry Redingaa441872015-07-28 11:35:53 +0200203 /* Do any special system timer/TSC setup */
204#if defined(CONFIG_TEGRA_SUPPORT_NON_SECURE)
205 if (!tegra_cpu_is_non_secure())
206#endif
207 arch_timer_init();
208
Tom Warren6d6c0ba2012-12-11 13:34:17 +0000209 pinmux_init();
Simon Glassf46a9452011-11-28 15:04:40 +0000210 board_init_uart_f();
Simon Glass3e00dbd2011-09-21 12:40:03 +0000211
212 /* Initialize periph GPIOs */
Thierry Redingcb7a1cf2012-06-04 20:02:27 +0000213 gpio_early_init();
Simon Glassa04eba92011-11-05 04:46:51 +0000214 gpio_early_init_uart();
Simon Glass1b24a502012-10-17 13:24:52 +0000215#ifdef CONFIG_LCD
216 tegra_lcd_early_init(gd->fdt_blob);
217#endif
Lucas Stach0cd10c72012-09-25 20:21:14 +0000218
Simon Glass3e00dbd2011-09-21 12:40:03 +0000219 return 0;
220}
221#endif /* EARLY_INIT */
Simon Glass1b24a502012-10-17 13:24:52 +0000222
223int board_late_init(void)
224{
225#ifdef CONFIG_LCD
226 /* Make sure we finish initing the LCD */
227 tegra_lcd_check_next_stage(gd->fdt_blob, 1);
228#endif
Stephen Warren73c38932015-01-19 16:25:52 -0700229#if defined(CONFIG_TEGRA_SUPPORT_NON_SECURE)
230 if (tegra_cpu_is_non_secure()) {
231 printf("CPU is in NS mode\n");
232 setenv("cpu_ns_mode", "1");
233 } else {
234 setenv("cpu_ns_mode", "");
235 }
236#endif
Tom Warren66999892015-02-20 12:22:22 -0700237 start_cpu_fan();
238
Simon Glass1b24a502012-10-17 13:24:52 +0000239 return 0;
240}
Tom Warrenc9aa8312013-02-21 12:31:30 +0000241
242#if defined(CONFIG_TEGRA_MMC)
Jeroen Hofstee19d7bf32014-10-08 22:57:46 +0200243__weak void pin_mux_mmc(void)
Tom Warrenc9aa8312013-02-21 12:31:30 +0000244{
245}
246
Tom Warrenc9aa8312013-02-21 12:31:30 +0000247/* this is a weak define that we are overriding */
248int board_mmc_init(bd_t *bd)
249{
250 debug("%s called\n", __func__);
251
252 /* Enable muxes, etc. for SDMMC controllers */
253 pin_mux_mmc();
254
255 debug("%s: init MMC\n", __func__);
256 tegra_mmc_init();
257
258 return 0;
259}
Tom Warren190be1f2013-02-26 12:26:55 -0700260
261void pad_init_mmc(struct mmc_host *host)
262{
263#if defined(CONFIG_TEGRA30)
264 enum periph_id id = host->mmc_id;
265 u32 val;
266
267 debug("%s: sdmmc address = %08x, id = %d\n", __func__,
268 (unsigned int)host->reg, id);
269
270 /* Set the pad drive strength for SDMMC1 or 3 only */
271 if (id != PERIPH_ID_SDMMC1 && id != PERIPH_ID_SDMMC3) {
272 debug("%s: settings are only valid for SDMMC1/SDMMC3!\n",
273 __func__);
274 return;
275 }
276
277 val = readl(&host->reg->sdmemcmppadctl);
278 val &= 0xFFFFFFF0;
279 val |= MEMCOMP_PADCTRL_VREF;
280 writel(val, &host->reg->sdmemcmppadctl);
281
282 val = readl(&host->reg->autocalcfg);
283 val &= 0xFFFF0000;
284 val |= AUTO_CAL_PU_OFFSET | AUTO_CAL_PD_OFFSET | AUTO_CAL_ENABLED;
285 writel(val, &host->reg->autocalcfg);
286#endif /* T30 */
287}
288#endif /* MMC */
Thierry Reding00f782a2015-07-27 11:45:24 -0600289
290#ifdef CONFIG_ARM64
291/*
292 * Most hardware on 64-bit Tegra is still restricted to DMA to the lower
293 * 32-bits of the physical address space. Cap the maximum usable RAM area
294 * at 4 GiB to avoid DMA buffers from being allocated beyond the 32-bit
295 * boundary that most devices can address.
Stephen Warren424afc02015-07-29 13:47:58 -0600296 *
297 * Additionally, ARM64 devices typically run a secure monitor in EL3 and
298 * U-Boot in EL2, and set up some secure RAM carve-outs to contain the EL3
299 * code and data. These carve-outs are located at the top of 32-bit address
300 * space. Restrict U-Boot's RAM usage to well below the location of those
301 * carve-outs. Ideally, we would the secure monitor would inform U-Boot of
302 * exactly which RAM it could use at run-time. However, I'm not sure how to
303 * do that at present (and even if such a mechanism does exist, it would
304 * likely not be generic across all forms of secure monitor).
Thierry Reding00f782a2015-07-27 11:45:24 -0600305 */
306ulong board_get_usable_ram_top(ulong total_size)
307{
Stephen Warren424afc02015-07-29 13:47:58 -0600308 if (gd->ram_top > 0xe0000000)
309 return 0xe0000000;
Thierry Reding00f782a2015-07-27 11:45:24 -0600310
311 return gd->ram_top;
312}
313#endif