blob: 41e9341874e55b6a661f154b755dff4f6597b688 [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>
Tom Warren6d6c0ba2012-12-11 13:34:17 +000032#ifdef CONFIG_TEGRA_CLOCK_SCALING
33#include <asm/arch/emc.h>
34#endif
35#ifdef CONFIG_USB_EHCI_TEGRA
Lucas Stach7ae18f32013-02-07 07:16:29 +000036#include <asm/arch-tegra/usb.h>
Mateusz Zalega16297cf2013-10-04 19:22:26 +020037#include <usb.h>
Tom Warren6d6c0ba2012-12-11 13:34:17 +000038#endif
Tom Warrenc9aa8312013-02-21 12:31:30 +000039#ifdef CONFIG_TEGRA_MMC
Tom Warren190be1f2013-02-26 12:26:55 -070040#include <asm/arch-tegra/tegra_mmc.h>
Tom Warrenc9aa8312013-02-21 12:31:30 +000041#include <asm/arch-tegra/mmc.h>
42#endif
Thierry Reding79c7a902014-12-09 22:25:09 -070043#include <asm/arch-tegra/xusb-padctl.h>
Simon Glass346451b2015-04-14 21:03:28 -060044#include <power/as3722.h>
Simon Glasscb445fb2012-02-03 15:13:57 +000045#include <i2c.h>
Tom Warren6d6c0ba2012-12-11 13:34:17 +000046#include <spi.h>
Jimmy Zhangc5b34a22012-04-10 05:17:06 +000047#include "emc.h"
Tom Warren3f82b1d2011-01-27 10:58:05 +000048
49DECLARE_GLOBAL_DATA_PTR;
50
Simon Glass0521f982014-11-10 17:16:51 -070051#ifdef CONFIG_SPL_BUILD
52/* TODO(sjg@chromium.org): Remove once SPL supports device tree */
53U_BOOT_DEVICE(tegra_gpios) = {
54 "gpio_tegra"
55};
56#endif
57
Jeroen Hofstee19d7bf32014-10-08 22:57:46 +020058__weak void pinmux_init(void) {}
59__weak void pin_mux_usb(void) {}
60__weak void pin_mux_spi(void) {}
61__weak void gpio_early_init_uart(void) {}
62__weak void pin_mux_display(void) {}
Tom Warren66999892015-02-20 12:22:22 -070063__weak void start_cpu_fan(void) {}
Lucas Stach0cd10c72012-09-25 20:21:14 +000064
Tom Warrendcd12512014-01-24 12:46:11 -070065#if defined(CONFIG_TEGRA_NAND)
Jeroen Hofstee19d7bf32014-10-08 22:57:46 +020066__weak void pin_mux_nand(void)
Lucas Stachc0720af2012-09-29 10:02:09 +000067{
68 funcmux_select(PERIPH_ID_NDFLASH, FUNCMUX_DEFAULT);
69}
Tom Warrendcd12512014-01-24 12:46:11 -070070#endif
Lucas Stachc0720af2012-09-29 10:02:09 +000071
Tom Warrenf4ef6662011-04-14 12:09:41 +000072/*
Wei Ni5aff0212012-04-02 13:18:58 +000073 * Routine: power_det_init
74 * Description: turn off power detects
75 */
76static void power_det_init(void)
77{
Allen Martin00a27492012-08-31 08:30:00 +000078#if defined(CONFIG_TEGRA20)
Tom Warren29f3e3f2012-09-04 17:00:24 -070079 struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
Wei Ni5aff0212012-04-02 13:18:58 +000080
81 /* turn off power detects */
82 writel(0, &pmc->pmc_pwr_det_latch);
83 writel(0, &pmc->pmc_pwr_det);
84#endif
85}
86
Simon Glassec746642015-04-14 21:03:25 -060087__weak int tegra_board_id(void)
88{
89 return -1;
90}
91
Simon Glass7d874132015-04-14 21:03:24 -060092#ifdef CONFIG_DISPLAY_BOARDINFO
93int checkboard(void)
94{
Simon Glassec746642015-04-14 21:03:25 -060095 int board_id = tegra_board_id();
96
97 printf("Board: %s", CONFIG_TEGRA_BOARD_STRING);
98 if (board_id != -1)
99 printf(", ID: %d\n", board_id);
100 printf("\n");
Simon Glass7d874132015-04-14 21:03:24 -0600101
102 return 0;
103}
104#endif /* CONFIG_DISPLAY_BOARDINFO */
105
Simon Glass82776362015-04-14 21:03:27 -0600106__weak int tegra_lcd_pmic_init(int board_it)
107{
108 return 0;
109}
110
Simon Glassc96d7092015-06-05 14:39:42 -0600111__weak int nvidia_board_init(void)
112{
113 return 0;
114}
115
Wei Ni5aff0212012-04-02 13:18:58 +0000116/*
Tom Warren3f82b1d2011-01-27 10:58:05 +0000117 * Routine: board_init
118 * Description: Early hardware init.
119 */
120int board_init(void)
121{
Jimmy Zhangc5b34a22012-04-10 05:17:06 +0000122 __maybe_unused int err;
Simon Glass82776362015-04-14 21:03:27 -0600123 __maybe_unused int board_id;
Jimmy Zhangc5b34a22012-04-10 05:17:06 +0000124
Simon Glassa04eba92011-11-05 04:46:51 +0000125 /* Do clocks and UART first so that printf() works */
Simon Glass4ed59e72011-09-21 12:40:04 +0000126 clock_init();
127 clock_verify();
128
Simon Glassfda6fac2014-10-13 23:42:13 -0600129#ifdef CONFIG_TEGRA_SPI
Stephen Warrene0284942012-06-12 08:33:40 +0000130 pin_mux_spi();
Tom Warren9112ef82011-11-05 09:48:11 +0000131#endif
Allen Martinb19f5742013-01-29 13:51:28 +0000132
Simon Glasse1ae0d12012-10-17 13:24:49 +0000133#ifdef CONFIG_PWM_TEGRA
134 if (pwm_init(gd->fdt_blob))
135 debug("%s: Failed to init pwm\n", __func__);
136#endif
Simon Glass1b24a502012-10-17 13:24:52 +0000137#ifdef CONFIG_LCD
Marc Dietrich716d9432012-11-25 11:26:11 +0000138 pin_mux_display();
Simon Glass1b24a502012-10-17 13:24:52 +0000139 tegra_lcd_check_next_stage(gd->fdt_blob, 0);
140#endif
Tom Warren3f82b1d2011-01-27 10:58:05 +0000141 /* boot param addr */
142 gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100);
Wei Ni5aff0212012-04-02 13:18:58 +0000143
144 power_det_init();
145
Simon Glass1f2ba722012-10-30 07:28:53 +0000146#ifdef CONFIG_SYS_I2C_TEGRA
Simon Glass87236262012-04-02 13:18:54 +0000147# ifdef CONFIG_TEGRA_PMU
148 if (pmu_set_nominal())
149 debug("Failed to select nominal voltages\n");
Jimmy Zhangc5b34a22012-04-10 05:17:06 +0000150# ifdef CONFIG_TEGRA_CLOCK_SCALING
151 err = board_emc_init();
152 if (err)
153 debug("Memory controller init failed: %d\n", err);
154# endif
155# endif /* CONFIG_TEGRA_PMU */
Simon Glass346451b2015-04-14 21:03:28 -0600156#ifdef CONFIG_AS3722_POWER
157 err = as3722_init(NULL);
158 if (err && err != -ENODEV)
159 return err;
160#endif
Simon Glass1f2ba722012-10-30 07:28:53 +0000161#endif /* CONFIG_SYS_I2C_TEGRA */
Tom Warren3f82b1d2011-01-27 10:58:05 +0000162
Simon Glassf10393e2012-02-27 10:52:50 +0000163#ifdef CONFIG_USB_EHCI_TEGRA
164 pin_mux_usb();
Simon Glassf10393e2012-02-27 10:52:50 +0000165#endif
Mateusz Zalega16297cf2013-10-04 19:22:26 +0200166
Simon Glass1b24a502012-10-17 13:24:52 +0000167#ifdef CONFIG_LCD
Simon Glass82776362015-04-14 21:03:27 -0600168 board_id = tegra_board_id();
169 err = tegra_lcd_pmic_init(board_id);
170 if (err)
171 return err;
Simon Glass1b24a502012-10-17 13:24:52 +0000172 tegra_lcd_check_next_stage(gd->fdt_blob, 0);
173#endif
Simon Glassf10393e2012-02-27 10:52:50 +0000174
Lucas Stachc0720af2012-09-29 10:02:09 +0000175#ifdef CONFIG_TEGRA_NAND
176 pin_mux_nand();
177#endif
178
Thierry Reding79c7a902014-12-09 22:25:09 -0700179 tegra_xusb_padctl_init(gd->fdt_blob);
180
Tom Warren29f3e3f2012-09-04 17:00:24 -0700181#ifdef CONFIG_TEGRA_LP0
Allen Martina49716a2012-08-31 08:30:11 +0000182 /* save Sdram params to PMC 2, 4, and 24 for WB0 */
183 warmboot_save_sdram_params();
184
Simon Glass67ac5792012-04-02 13:18:57 +0000185 /* prepare the WB code to LP0 location */
186 warmboot_prepare_code(TEGRA_LP0_ADDR, TEGRA_LP0_SIZE);
187#endif
Simon Glassc96d7092015-06-05 14:39:42 -0600188 return nvidia_board_init();
Tom Warren3f82b1d2011-01-27 10:58:05 +0000189}
Tom Warren21ef6a12011-05-31 10:30:37 +0000190
Simon Glass3e00dbd2011-09-21 12:40:03 +0000191#ifdef CONFIG_BOARD_EARLY_INIT_F
Thierry Redingcb7a1cf2012-06-04 20:02:27 +0000192static void __gpio_early_init(void)
193{
194}
195
196void gpio_early_init(void) __attribute__((weak, alias("__gpio_early_init")));
197
Simon Glass3e00dbd2011-09-21 12:40:03 +0000198int board_early_init_f(void)
199{
Thierry Redingaa441872015-07-28 11:35:53 +0200200 /* Do any special system timer/TSC setup */
201#if defined(CONFIG_TEGRA_SUPPORT_NON_SECURE)
202 if (!tegra_cpu_is_non_secure())
203#endif
204 arch_timer_init();
205
Tom Warren6d6c0ba2012-12-11 13:34:17 +0000206 pinmux_init();
Simon Glassf46a9452011-11-28 15:04:40 +0000207 board_init_uart_f();
Simon Glass3e00dbd2011-09-21 12:40:03 +0000208
209 /* Initialize periph GPIOs */
Thierry Redingcb7a1cf2012-06-04 20:02:27 +0000210 gpio_early_init();
Simon Glassa04eba92011-11-05 04:46:51 +0000211 gpio_early_init_uart();
Simon Glass1b24a502012-10-17 13:24:52 +0000212#ifdef CONFIG_LCD
213 tegra_lcd_early_init(gd->fdt_blob);
214#endif
Lucas Stach0cd10c72012-09-25 20:21:14 +0000215
Simon Glass3e00dbd2011-09-21 12:40:03 +0000216 return 0;
217}
218#endif /* EARLY_INIT */
Simon Glass1b24a502012-10-17 13:24:52 +0000219
220int board_late_init(void)
221{
222#ifdef CONFIG_LCD
223 /* Make sure we finish initing the LCD */
224 tegra_lcd_check_next_stage(gd->fdt_blob, 1);
225#endif
Stephen Warren73c38932015-01-19 16:25:52 -0700226#if defined(CONFIG_TEGRA_SUPPORT_NON_SECURE)
227 if (tegra_cpu_is_non_secure()) {
228 printf("CPU is in NS mode\n");
229 setenv("cpu_ns_mode", "1");
230 } else {
231 setenv("cpu_ns_mode", "");
232 }
233#endif
Tom Warren66999892015-02-20 12:22:22 -0700234 start_cpu_fan();
235
Simon Glass1b24a502012-10-17 13:24:52 +0000236 return 0;
237}
Tom Warrenc9aa8312013-02-21 12:31:30 +0000238
239#if defined(CONFIG_TEGRA_MMC)
Jeroen Hofstee19d7bf32014-10-08 22:57:46 +0200240__weak void pin_mux_mmc(void)
Tom Warrenc9aa8312013-02-21 12:31:30 +0000241{
242}
243
Tom Warrenc9aa8312013-02-21 12:31:30 +0000244/* this is a weak define that we are overriding */
245int board_mmc_init(bd_t *bd)
246{
247 debug("%s called\n", __func__);
248
249 /* Enable muxes, etc. for SDMMC controllers */
250 pin_mux_mmc();
251
252 debug("%s: init MMC\n", __func__);
253 tegra_mmc_init();
254
255 return 0;
256}
Tom Warren190be1f2013-02-26 12:26:55 -0700257
258void pad_init_mmc(struct mmc_host *host)
259{
260#if defined(CONFIG_TEGRA30)
261 enum periph_id id = host->mmc_id;
262 u32 val;
263
264 debug("%s: sdmmc address = %08x, id = %d\n", __func__,
265 (unsigned int)host->reg, id);
266
267 /* Set the pad drive strength for SDMMC1 or 3 only */
268 if (id != PERIPH_ID_SDMMC1 && id != PERIPH_ID_SDMMC3) {
269 debug("%s: settings are only valid for SDMMC1/SDMMC3!\n",
270 __func__);
271 return;
272 }
273
274 val = readl(&host->reg->sdmemcmppadctl);
275 val &= 0xFFFFFFF0;
276 val |= MEMCOMP_PADCTRL_VREF;
277 writel(val, &host->reg->sdmemcmppadctl);
278
279 val = readl(&host->reg->autocalcfg);
280 val &= 0xFFFF0000;
281 val |= AUTO_CAL_PU_OFFSET | AUTO_CAL_PD_OFFSET | AUTO_CAL_ENABLED;
282 writel(val, &host->reg->autocalcfg);
283#endif /* T30 */
284}
285#endif /* MMC */
Thierry Reding00f782a2015-07-27 11:45:24 -0600286
287#ifdef CONFIG_ARM64
288/*
289 * Most hardware on 64-bit Tegra is still restricted to DMA to the lower
290 * 32-bits of the physical address space. Cap the maximum usable RAM area
291 * at 4 GiB to avoid DMA buffers from being allocated beyond the 32-bit
292 * boundary that most devices can address.
Stephen Warren424afc02015-07-29 13:47:58 -0600293 *
294 * Additionally, ARM64 devices typically run a secure monitor in EL3 and
295 * U-Boot in EL2, and set up some secure RAM carve-outs to contain the EL3
296 * code and data. These carve-outs are located at the top of 32-bit address
297 * space. Restrict U-Boot's RAM usage to well below the location of those
298 * carve-outs. Ideally, we would the secure monitor would inform U-Boot of
299 * exactly which RAM it could use at run-time. However, I'm not sure how to
300 * do that at present (and even if such a mechanism does exist, it would
301 * likely not be generic across all forms of secure monitor).
Thierry Reding00f782a2015-07-27 11:45:24 -0600302 */
303ulong board_get_usable_ram_top(ulong total_size)
304{
Stephen Warren424afc02015-07-29 13:47:58 -0600305 if (gd->ram_top > 0xe0000000)
306 return 0xe0000000;
Thierry Reding00f782a2015-07-27 11:45:24 -0600307
308 return gd->ram_top;
309}
310#endif