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> 13*bbc1b99eSStephen 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 #ifdef CONFIG_USB_EHCI_TEGRA 38237c3637SMasahiro Yamada #include <asm/arch-tegra/usb.h> 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 131871d78edSAlexandre Courbot config_gpu(); 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 { 204aa441877SThierry Reding /* Do any special system timer/TSC setup */ 205aa441877SThierry Reding #if defined(CONFIG_TEGRA_SUPPORT_NON_SECURE) 206aa441877SThierry Reding if (!tegra_cpu_is_non_secure()) 207aa441877SThierry Reding #endif 208aa441877SThierry Reding arch_timer_init(); 209aa441877SThierry Reding 210237c3637SMasahiro Yamada pinmux_init(); 211237c3637SMasahiro Yamada board_init_uart_f(); 212237c3637SMasahiro Yamada 213237c3637SMasahiro Yamada /* Initialize periph GPIOs */ 214237c3637SMasahiro Yamada gpio_early_init(); 215237c3637SMasahiro Yamada gpio_early_init_uart(); 216237c3637SMasahiro Yamada #ifdef CONFIG_LCD 217237c3637SMasahiro Yamada tegra_lcd_early_init(gd->fdt_blob); 218237c3637SMasahiro Yamada #endif 219237c3637SMasahiro Yamada 220237c3637SMasahiro Yamada return 0; 221237c3637SMasahiro Yamada } 222237c3637SMasahiro Yamada #endif /* EARLY_INIT */ 223237c3637SMasahiro Yamada 224237c3637SMasahiro Yamada int board_late_init(void) 225237c3637SMasahiro Yamada { 226237c3637SMasahiro Yamada #ifdef CONFIG_LCD 227237c3637SMasahiro Yamada /* Make sure we finish initing the LCD */ 228237c3637SMasahiro Yamada tegra_lcd_check_next_stage(gd->fdt_blob, 1); 229237c3637SMasahiro Yamada #endif 230237c3637SMasahiro Yamada #if defined(CONFIG_TEGRA_SUPPORT_NON_SECURE) 231237c3637SMasahiro Yamada if (tegra_cpu_is_non_secure()) { 232237c3637SMasahiro Yamada printf("CPU is in NS mode\n"); 233237c3637SMasahiro Yamada setenv("cpu_ns_mode", "1"); 234237c3637SMasahiro Yamada } else { 235237c3637SMasahiro Yamada setenv("cpu_ns_mode", ""); 236237c3637SMasahiro Yamada } 237237c3637SMasahiro Yamada #endif 23866999892STom Warren start_cpu_fan(); 23966999892STom Warren 240237c3637SMasahiro Yamada return 0; 241237c3637SMasahiro Yamada } 242237c3637SMasahiro Yamada 243237c3637SMasahiro Yamada #if defined(CONFIG_TEGRA_MMC) 244237c3637SMasahiro Yamada __weak void pin_mux_mmc(void) 245237c3637SMasahiro Yamada { 246237c3637SMasahiro Yamada } 247237c3637SMasahiro Yamada 248237c3637SMasahiro Yamada /* this is a weak define that we are overriding */ 249237c3637SMasahiro Yamada int board_mmc_init(bd_t *bd) 250237c3637SMasahiro Yamada { 251237c3637SMasahiro Yamada debug("%s called\n", __func__); 252237c3637SMasahiro Yamada 253237c3637SMasahiro Yamada /* Enable muxes, etc. for SDMMC controllers */ 254237c3637SMasahiro Yamada pin_mux_mmc(); 255237c3637SMasahiro Yamada 256237c3637SMasahiro Yamada debug("%s: init MMC\n", __func__); 257237c3637SMasahiro Yamada tegra_mmc_init(); 258237c3637SMasahiro Yamada 259237c3637SMasahiro Yamada return 0; 260237c3637SMasahiro Yamada } 261237c3637SMasahiro Yamada 262237c3637SMasahiro Yamada void pad_init_mmc(struct mmc_host *host) 263237c3637SMasahiro Yamada { 264237c3637SMasahiro Yamada #if defined(CONFIG_TEGRA30) 265237c3637SMasahiro Yamada enum periph_id id = host->mmc_id; 266237c3637SMasahiro Yamada u32 val; 267237c3637SMasahiro Yamada 268237c3637SMasahiro Yamada debug("%s: sdmmc address = %08x, id = %d\n", __func__, 269237c3637SMasahiro Yamada (unsigned int)host->reg, id); 270237c3637SMasahiro Yamada 271237c3637SMasahiro Yamada /* Set the pad drive strength for SDMMC1 or 3 only */ 272237c3637SMasahiro Yamada if (id != PERIPH_ID_SDMMC1 && id != PERIPH_ID_SDMMC3) { 273237c3637SMasahiro Yamada debug("%s: settings are only valid for SDMMC1/SDMMC3!\n", 274237c3637SMasahiro Yamada __func__); 275237c3637SMasahiro Yamada return; 276237c3637SMasahiro Yamada } 277237c3637SMasahiro Yamada 278237c3637SMasahiro Yamada val = readl(&host->reg->sdmemcmppadctl); 279237c3637SMasahiro Yamada val &= 0xFFFFFFF0; 280237c3637SMasahiro Yamada val |= MEMCOMP_PADCTRL_VREF; 281237c3637SMasahiro Yamada writel(val, &host->reg->sdmemcmppadctl); 282237c3637SMasahiro Yamada 283237c3637SMasahiro Yamada val = readl(&host->reg->autocalcfg); 284237c3637SMasahiro Yamada val &= 0xFFFF0000; 285237c3637SMasahiro Yamada val |= AUTO_CAL_PU_OFFSET | AUTO_CAL_PD_OFFSET | AUTO_CAL_ENABLED; 286237c3637SMasahiro Yamada writel(val, &host->reg->autocalcfg); 287237c3637SMasahiro Yamada #endif /* T30 */ 288237c3637SMasahiro Yamada } 289237c3637SMasahiro Yamada #endif /* MMC */ 29000f782a9SThierry Reding 291*bbc1b99eSStephen Warren /* 292*bbc1b99eSStephen Warren * In some SW environments, a memory carve-out exists to house a secure 293*bbc1b99eSStephen Warren * monitor, a trusted OS, and/or various statically allocated media buffers. 294*bbc1b99eSStephen Warren * 295*bbc1b99eSStephen Warren * This carveout exists at the highest possible address that is within a 296*bbc1b99eSStephen Warren * 32-bit physical address space. 297*bbc1b99eSStephen Warren * 298*bbc1b99eSStephen Warren * This function returns the total size of this carve-out. At present, the 299*bbc1b99eSStephen Warren * returned value is hard-coded for simplicity. In the future, it may be 300*bbc1b99eSStephen Warren * possible to determine the carve-out size: 301*bbc1b99eSStephen Warren * - By querying some run-time information source, such as: 302*bbc1b99eSStephen Warren * - A structure passed to U-Boot by earlier boot software. 303*bbc1b99eSStephen Warren * - SoC registers. 304*bbc1b99eSStephen Warren * - A call into the secure monitor. 305*bbc1b99eSStephen Warren * - In the per-board U-Boot configuration header, based on knowledge of the 306*bbc1b99eSStephen Warren * SW environment that U-Boot is being built for. 307*bbc1b99eSStephen Warren * 308*bbc1b99eSStephen Warren * For now, we support two configurations in U-Boot: 309*bbc1b99eSStephen Warren * - 32-bit ports without any form of carve-out. 310*bbc1b99eSStephen Warren * - 64 bit ports which are assumed to use a carve-out of a conservatively 311*bbc1b99eSStephen Warren * hard-coded size. 312*bbc1b99eSStephen Warren */ 313*bbc1b99eSStephen Warren static ulong carveout_size(void) 314*bbc1b99eSStephen Warren { 31500f782a9SThierry Reding #ifdef CONFIG_ARM64 316*bbc1b99eSStephen Warren return SZ_512M; 317*bbc1b99eSStephen Warren #else 318*bbc1b99eSStephen Warren return 0; 319*bbc1b99eSStephen Warren #endif 320*bbc1b99eSStephen Warren } 321*bbc1b99eSStephen Warren 322*bbc1b99eSStephen Warren /* 323*bbc1b99eSStephen Warren * Determine the amount of usable RAM below 4GiB, taking into account any 324*bbc1b99eSStephen Warren * carve-out that may be assigned. 325*bbc1b99eSStephen Warren */ 326*bbc1b99eSStephen Warren static ulong usable_ram_size_below_4g(void) 327*bbc1b99eSStephen Warren { 328*bbc1b99eSStephen Warren ulong total_size_below_4g; 329*bbc1b99eSStephen Warren ulong usable_size_below_4g; 330*bbc1b99eSStephen Warren 331*bbc1b99eSStephen Warren /* 332*bbc1b99eSStephen Warren * The total size of RAM below 4GiB is the lesser address of: 333*bbc1b99eSStephen Warren * (a) 2GiB itself (RAM starts at 2GiB, and 4GiB - 2GiB == 2GiB). 334*bbc1b99eSStephen Warren * (b) The size RAM physically present in the system. 335*bbc1b99eSStephen Warren */ 336*bbc1b99eSStephen Warren if (gd->ram_size < SZ_2G) 337*bbc1b99eSStephen Warren total_size_below_4g = gd->ram_size; 338*bbc1b99eSStephen Warren else 339*bbc1b99eSStephen Warren total_size_below_4g = SZ_2G; 340*bbc1b99eSStephen Warren 341*bbc1b99eSStephen Warren /* Calculate usable RAM by subtracting out any carve-out size */ 342*bbc1b99eSStephen Warren usable_size_below_4g = total_size_below_4g - carveout_size(); 343*bbc1b99eSStephen Warren 344*bbc1b99eSStephen Warren return usable_size_below_4g; 345*bbc1b99eSStephen Warren } 346*bbc1b99eSStephen Warren 347*bbc1b99eSStephen Warren /* 348*bbc1b99eSStephen Warren * Represent all available RAM in either one or two banks. 349*bbc1b99eSStephen Warren * 350*bbc1b99eSStephen Warren * The first bank describes any usable RAM below 4GiB. 351*bbc1b99eSStephen Warren * The second bank describes any RAM above 4GiB. 352*bbc1b99eSStephen Warren * 353*bbc1b99eSStephen Warren * This split is driven by the following requirements: 354*bbc1b99eSStephen Warren * - The NVIDIA L4T kernel requires separate entries in the DT /memory/reg 355*bbc1b99eSStephen Warren * property for memory below and above the 4GiB boundary. The layout of that 356*bbc1b99eSStephen Warren * DT property is directly driven by the entries in the U-Boot bank array. 357*bbc1b99eSStephen Warren * - The potential existence of a carve-out at the end of RAM below 4GiB can 358*bbc1b99eSStephen Warren * only be represented using multiple banks. 359*bbc1b99eSStephen Warren * 360*bbc1b99eSStephen Warren * Explicitly removing the carve-out RAM from the bank entries makes the RAM 361*bbc1b99eSStephen Warren * layout a bit more obvious, e.g. when running "bdinfo" at the U-Boot 362*bbc1b99eSStephen Warren * command-line. 363*bbc1b99eSStephen Warren * 364*bbc1b99eSStephen Warren * This does mean that the DT U-Boot passes to the Linux kernel will not 365*bbc1b99eSStephen Warren * include this RAM in /memory/reg at all. An alternative would be to include 366*bbc1b99eSStephen Warren * all RAM in the U-Boot banks (and hence DT), and add a /memreserve/ node 367*bbc1b99eSStephen Warren * into DT to stop the kernel from using the RAM. IIUC, I don't /think/ the 368*bbc1b99eSStephen Warren * Linux kernel will ever need to access any RAM in* the carve-out via a CPU 369*bbc1b99eSStephen Warren * mapping, so either way is acceptable. 370*bbc1b99eSStephen Warren * 371*bbc1b99eSStephen Warren * On 32-bit systems, we never define a bank for RAM above 4GiB, since the 372*bbc1b99eSStephen Warren * start address of that bank cannot be represented in the 32-bit .size 373*bbc1b99eSStephen Warren * field. 374*bbc1b99eSStephen Warren */ 375*bbc1b99eSStephen Warren void dram_init_banksize(void) 376*bbc1b99eSStephen Warren { 377*bbc1b99eSStephen Warren gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE; 378*bbc1b99eSStephen Warren gd->bd->bi_dram[0].size = usable_ram_size_below_4g(); 379*bbc1b99eSStephen Warren 380*bbc1b99eSStephen Warren #ifdef CONFIG_PHYS_64BIT 381*bbc1b99eSStephen Warren if (gd->ram_size > SZ_2G) { 382*bbc1b99eSStephen Warren gd->bd->bi_dram[1].start = 0x100000000; 383*bbc1b99eSStephen Warren gd->bd->bi_dram[1].size = gd->ram_size - SZ_2G; 384*bbc1b99eSStephen Warren } else 385*bbc1b99eSStephen Warren #endif 386*bbc1b99eSStephen Warren { 387*bbc1b99eSStephen Warren gd->bd->bi_dram[1].start = 0; 388*bbc1b99eSStephen Warren gd->bd->bi_dram[1].size = 0; 389*bbc1b99eSStephen Warren } 390*bbc1b99eSStephen Warren } 391*bbc1b99eSStephen Warren 39200f782a9SThierry Reding /* 39300f782a9SThierry Reding * Most hardware on 64-bit Tegra is still restricted to DMA to the lower 39400f782a9SThierry Reding * 32-bits of the physical address space. Cap the maximum usable RAM area 39500f782a9SThierry Reding * at 4 GiB to avoid DMA buffers from being allocated beyond the 32-bit 396*bbc1b99eSStephen Warren * boundary that most devices can address. Also, don't let U-Boot use any 397*bbc1b99eSStephen Warren * carve-out, as mentioned above. 398424afc0aSStephen Warren * 399*bbc1b99eSStephen Warren * This function is called before dram_init_banksize(), so we can't simply 400*bbc1b99eSStephen Warren * return gd->bd->bi_dram[1].start + gd->bd->bi_dram[1].size. 40100f782a9SThierry Reding */ 40200f782a9SThierry Reding ulong board_get_usable_ram_top(ulong total_size) 40300f782a9SThierry Reding { 404*bbc1b99eSStephen Warren return CONFIG_SYS_SDRAM_BASE + usable_ram_size_below_4g(); 40500f782a9SThierry Reding } 406