Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2010,2011 |
| 3 | * NVIDIA Corporation <www.nvidia.com> |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | 74472ac | 2014-11-10 17:16:51 -0700 | [diff] [blame] | 9 | #include <dm.h> |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 10 | #include <ns16550.h> |
Jimmy Zhang | a308d46 | 2012-04-10 05:17:06 +0000 | [diff] [blame] | 11 | #include <linux/compiler.h> |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 12 | #include <asm/io.h> |
Simon Glass | 16134fd | 2011-08-30 06:23:13 +0000 | [diff] [blame] | 13 | #include <asm/arch/clock.h> |
Tom Warren | d32b2a4 | 2012-12-11 13:34:17 +0000 | [diff] [blame] | 14 | #ifdef CONFIG_LCD |
Simon Glass | 4f476f3 | 2012-10-17 13:24:52 +0000 | [diff] [blame] | 15 | #include <asm/arch/display.h> |
Tom Warren | d32b2a4 | 2012-12-11 13:34:17 +0000 | [diff] [blame] | 16 | #endif |
Lucas Stach | 0458584 | 2012-09-29 10:02:09 +0000 | [diff] [blame] | 17 | #include <asm/arch/funcmux.h> |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 18 | #include <asm/arch/pinmux.h> |
Simon Glass | e772be8 | 2012-04-02 13:18:54 +0000 | [diff] [blame] | 19 | #include <asm/arch/pmu.h> |
Tom Warren | d32b2a4 | 2012-12-11 13:34:17 +0000 | [diff] [blame] | 20 | #ifdef CONFIG_PWM_TEGRA |
Simon Glass | 1564f34 | 2012-10-17 13:24:49 +0000 | [diff] [blame] | 21 | #include <asm/arch/pwm.h> |
Tom Warren | d32b2a4 | 2012-12-11 13:34:17 +0000 | [diff] [blame] | 22 | #endif |
Tom Warren | ab37196 | 2012-09-19 15:50:56 -0700 | [diff] [blame] | 23 | #include <asm/arch/tegra.h> |
Tom Warren | ab37196 | 2012-09-19 15:50:56 -0700 | [diff] [blame] | 24 | #include <asm/arch-tegra/board.h> |
| 25 | #include <asm/arch-tegra/clk_rst.h> |
| 26 | #include <asm/arch-tegra/pmc.h> |
| 27 | #include <asm/arch-tegra/sys_proto.h> |
| 28 | #include <asm/arch-tegra/uart.h> |
| 29 | #include <asm/arch-tegra/warmboot.h> |
Tom Warren | d32b2a4 | 2012-12-11 13:34:17 +0000 | [diff] [blame] | 30 | #ifdef CONFIG_TEGRA_CLOCK_SCALING |
| 31 | #include <asm/arch/emc.h> |
| 32 | #endif |
| 33 | #ifdef CONFIG_USB_EHCI_TEGRA |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 34 | #include <asm/arch-tegra/usb.h> |
Mateusz Zalega | d862f89 | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 35 | #include <usb.h> |
Tom Warren | d32b2a4 | 2012-12-11 13:34:17 +0000 | [diff] [blame] | 36 | #endif |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 37 | #ifdef CONFIG_TEGRA_MMC |
Tom Warren | f5d874d | 2013-02-26 12:26:55 -0700 | [diff] [blame] | 38 | #include <asm/arch-tegra/tegra_mmc.h> |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 39 | #include <asm/arch-tegra/mmc.h> |
| 40 | #endif |
Thierry Reding | f202e02 | 2014-12-09 22:25:09 -0700 | [diff] [blame] | 41 | #include <asm/arch-tegra/xusb-padctl.h> |
Simon Glass | 87cc3d1 | 2012-02-03 15:13:57 +0000 | [diff] [blame] | 42 | #include <i2c.h> |
Tom Warren | d32b2a4 | 2012-12-11 13:34:17 +0000 | [diff] [blame] | 43 | #include <spi.h> |
Jimmy Zhang | a308d46 | 2012-04-10 05:17:06 +0000 | [diff] [blame] | 44 | #include "emc.h" |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 45 | |
| 46 | DECLARE_GLOBAL_DATA_PTR; |
| 47 | |
Simon Glass | 74472ac | 2014-11-10 17:16:51 -0700 | [diff] [blame] | 48 | #ifdef CONFIG_SPL_BUILD |
| 49 | /* TODO(sjg@chromium.org): Remove once SPL supports device tree */ |
| 50 | U_BOOT_DEVICE(tegra_gpios) = { |
| 51 | "gpio_tegra" |
| 52 | }; |
| 53 | #endif |
| 54 | |
Tom Warren | 22562a4 | 2012-09-04 17:00:24 -0700 | [diff] [blame] | 55 | const struct tegra_sysinfo sysinfo = { |
| 56 | CONFIG_TEGRA_BOARD_STRING |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
Jeroen Hofstee | 93dfae7 | 2014-10-08 22:57:46 +0200 | [diff] [blame] | 59 | __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) {} |
Lucas Stach | 18561f7 | 2012-09-25 20:21:14 +0000 | [diff] [blame] | 64 | |
Tom Warren | 6b33c83 | 2014-01-24 12:46:11 -0700 | [diff] [blame] | 65 | #if defined(CONFIG_TEGRA_NAND) |
Jeroen Hofstee | 93dfae7 | 2014-10-08 22:57:46 +0200 | [diff] [blame] | 66 | __weak void pin_mux_nand(void) |
Lucas Stach | 0458584 | 2012-09-29 10:02:09 +0000 | [diff] [blame] | 67 | { |
| 68 | funcmux_select(PERIPH_ID_NDFLASH, FUNCMUX_DEFAULT); |
| 69 | } |
Tom Warren | 6b33c83 | 2014-01-24 12:46:11 -0700 | [diff] [blame] | 70 | #endif |
Lucas Stach | 0458584 | 2012-09-29 10:02:09 +0000 | [diff] [blame] | 71 | |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 72 | /* |
Wei Ni | 39d45ed | 2012-04-02 13:18:58 +0000 | [diff] [blame] | 73 | * Routine: power_det_init |
| 74 | * Description: turn off power detects |
| 75 | */ |
| 76 | static void power_det_init(void) |
| 77 | { |
Allen Martin | 55d98a1 | 2012-08-31 08:30:00 +0000 | [diff] [blame] | 78 | #if defined(CONFIG_TEGRA20) |
Tom Warren | 22562a4 | 2012-09-04 17:00:24 -0700 | [diff] [blame] | 79 | struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE; |
Wei Ni | 39d45ed | 2012-04-02 13:18:58 +0000 | [diff] [blame] | 80 | |
| 81 | /* turn off power detects */ |
| 82 | writel(0, &pmc->pmc_pwr_det_latch); |
| 83 | writel(0, &pmc->pmc_pwr_det); |
| 84 | #endif |
| 85 | } |
| 86 | |
| 87 | /* |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 88 | * Routine: board_init |
| 89 | * Description: Early hardware init. |
| 90 | */ |
| 91 | int board_init(void) |
| 92 | { |
Jimmy Zhang | a308d46 | 2012-04-10 05:17:06 +0000 | [diff] [blame] | 93 | __maybe_unused int err; |
| 94 | |
Simon Glass | 704e60d | 2011-11-05 04:46:51 +0000 | [diff] [blame] | 95 | /* Do clocks and UART first so that printf() works */ |
Simon Glass | c2ea5e4 | 2011-09-21 12:40:04 +0000 | [diff] [blame] | 96 | clock_init(); |
| 97 | clock_verify(); |
| 98 | |
Simon Glass | 1121b1b | 2014-10-13 23:42:13 -0600 | [diff] [blame] | 99 | #ifdef CONFIG_TEGRA_SPI |
Stephen Warren | d2f67fe | 2012-06-12 08:33:40 +0000 | [diff] [blame] | 100 | pin_mux_spi(); |
Tom Warren | ee554f8 | 2011-11-05 09:48:11 +0000 | [diff] [blame] | 101 | #endif |
Allen Martin | ba4fb9b | 2013-01-29 13:51:28 +0000 | [diff] [blame] | 102 | |
Simon Glass | 1564f34 | 2012-10-17 13:24:49 +0000 | [diff] [blame] | 103 | #ifdef CONFIG_PWM_TEGRA |
| 104 | if (pwm_init(gd->fdt_blob)) |
| 105 | debug("%s: Failed to init pwm\n", __func__); |
| 106 | #endif |
Simon Glass | 4f476f3 | 2012-10-17 13:24:52 +0000 | [diff] [blame] | 107 | #ifdef CONFIG_LCD |
Marc Dietrich | 9bbe64b | 2012-11-25 11:26:11 +0000 | [diff] [blame] | 108 | pin_mux_display(); |
Simon Glass | 4f476f3 | 2012-10-17 13:24:52 +0000 | [diff] [blame] | 109 | tegra_lcd_check_next_stage(gd->fdt_blob, 0); |
| 110 | #endif |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 111 | /* boot param addr */ |
| 112 | gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100); |
Wei Ni | 39d45ed | 2012-04-02 13:18:58 +0000 | [diff] [blame] | 113 | |
| 114 | power_det_init(); |
| 115 | |
Simon Glass | 026fefb | 2012-10-30 07:28:53 +0000 | [diff] [blame] | 116 | #ifdef CONFIG_SYS_I2C_TEGRA |
Simon Glass | e772be8 | 2012-04-02 13:18:54 +0000 | [diff] [blame] | 117 | # ifdef CONFIG_TEGRA_PMU |
| 118 | if (pmu_set_nominal()) |
| 119 | debug("Failed to select nominal voltages\n"); |
Jimmy Zhang | a308d46 | 2012-04-10 05:17:06 +0000 | [diff] [blame] | 120 | # ifdef CONFIG_TEGRA_CLOCK_SCALING |
| 121 | err = board_emc_init(); |
| 122 | if (err) |
| 123 | debug("Memory controller init failed: %d\n", err); |
| 124 | # endif |
| 125 | # endif /* CONFIG_TEGRA_PMU */ |
Simon Glass | 026fefb | 2012-10-30 07:28:53 +0000 | [diff] [blame] | 126 | #endif /* CONFIG_SYS_I2C_TEGRA */ |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 127 | |
Simon Glass | 5d73a8d | 2012-02-27 10:52:50 +0000 | [diff] [blame] | 128 | #ifdef CONFIG_USB_EHCI_TEGRA |
| 129 | pin_mux_usb(); |
Mateusz Zalega | d862f89 | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 130 | usb_process_devicetree(gd->fdt_blob); |
Simon Glass | 5d73a8d | 2012-02-27 10:52:50 +0000 | [diff] [blame] | 131 | #endif |
Mateusz Zalega | d862f89 | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 132 | |
Simon Glass | 4f476f3 | 2012-10-17 13:24:52 +0000 | [diff] [blame] | 133 | #ifdef CONFIG_LCD |
| 134 | tegra_lcd_check_next_stage(gd->fdt_blob, 0); |
| 135 | #endif |
Simon Glass | 5d73a8d | 2012-02-27 10:52:50 +0000 | [diff] [blame] | 136 | |
Lucas Stach | 0458584 | 2012-09-29 10:02:09 +0000 | [diff] [blame] | 137 | #ifdef CONFIG_TEGRA_NAND |
| 138 | pin_mux_nand(); |
| 139 | #endif |
| 140 | |
Thierry Reding | f202e02 | 2014-12-09 22:25:09 -0700 | [diff] [blame] | 141 | tegra_xusb_padctl_init(gd->fdt_blob); |
| 142 | |
Tom Warren | 22562a4 | 2012-09-04 17:00:24 -0700 | [diff] [blame] | 143 | #ifdef CONFIG_TEGRA_LP0 |
Allen Martin | 0ca1a45 | 2012-08-31 08:30:11 +0000 | [diff] [blame] | 144 | /* save Sdram params to PMC 2, 4, and 24 for WB0 */ |
| 145 | warmboot_save_sdram_params(); |
| 146 | |
Simon Glass | 8cc8f61 | 2012-04-02 13:18:57 +0000 | [diff] [blame] | 147 | /* prepare the WB code to LP0 location */ |
| 148 | warmboot_prepare_code(TEGRA_LP0_ADDR, TEGRA_LP0_SIZE); |
| 149 | #endif |
| 150 | |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 151 | return 0; |
| 152 | } |
Simon Glass | dfcee79 | 2011-09-21 12:40:03 +0000 | [diff] [blame] | 153 | |
| 154 | #ifdef CONFIG_BOARD_EARLY_INIT_F |
Thierry Reding | 2fa4db0 | 2012-06-04 20:02:27 +0000 | [diff] [blame] | 155 | static void __gpio_early_init(void) |
| 156 | { |
| 157 | } |
| 158 | |
| 159 | void gpio_early_init(void) __attribute__((weak, alias("__gpio_early_init"))); |
| 160 | |
Simon Glass | dfcee79 | 2011-09-21 12:40:03 +0000 | [diff] [blame] | 161 | int board_early_init_f(void) |
| 162 | { |
Tom Warren | d32b2a4 | 2012-12-11 13:34:17 +0000 | [diff] [blame] | 163 | pinmux_init(); |
Simon Glass | a8ccc8b | 2011-11-28 15:04:40 +0000 | [diff] [blame] | 164 | board_init_uart_f(); |
Simon Glass | dfcee79 | 2011-09-21 12:40:03 +0000 | [diff] [blame] | 165 | |
| 166 | /* Initialize periph GPIOs */ |
Thierry Reding | 2fa4db0 | 2012-06-04 20:02:27 +0000 | [diff] [blame] | 167 | gpio_early_init(); |
Simon Glass | 704e60d | 2011-11-05 04:46:51 +0000 | [diff] [blame] | 168 | gpio_early_init_uart(); |
Simon Glass | 4f476f3 | 2012-10-17 13:24:52 +0000 | [diff] [blame] | 169 | #ifdef CONFIG_LCD |
| 170 | tegra_lcd_early_init(gd->fdt_blob); |
| 171 | #endif |
Lucas Stach | 18561f7 | 2012-09-25 20:21:14 +0000 | [diff] [blame] | 172 | |
Simon Glass | dfcee79 | 2011-09-21 12:40:03 +0000 | [diff] [blame] | 173 | return 0; |
| 174 | } |
| 175 | #endif /* EARLY_INIT */ |
Simon Glass | 4f476f3 | 2012-10-17 13:24:52 +0000 | [diff] [blame] | 176 | |
| 177 | int board_late_init(void) |
| 178 | { |
| 179 | #ifdef CONFIG_LCD |
| 180 | /* Make sure we finish initing the LCD */ |
| 181 | tegra_lcd_check_next_stage(gd->fdt_blob, 1); |
| 182 | #endif |
| 183 | return 0; |
| 184 | } |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 185 | |
| 186 | #if defined(CONFIG_TEGRA_MMC) |
Jeroen Hofstee | 93dfae7 | 2014-10-08 22:57:46 +0200 | [diff] [blame] | 187 | __weak void pin_mux_mmc(void) |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 188 | { |
| 189 | } |
| 190 | |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 191 | /* this is a weak define that we are overriding */ |
| 192 | int board_mmc_init(bd_t *bd) |
| 193 | { |
| 194 | debug("%s called\n", __func__); |
| 195 | |
| 196 | /* Enable muxes, etc. for SDMMC controllers */ |
| 197 | pin_mux_mmc(); |
| 198 | |
| 199 | debug("%s: init MMC\n", __func__); |
| 200 | tegra_mmc_init(); |
| 201 | |
| 202 | return 0; |
| 203 | } |
Tom Warren | f5d874d | 2013-02-26 12:26:55 -0700 | [diff] [blame] | 204 | |
| 205 | void pad_init_mmc(struct mmc_host *host) |
| 206 | { |
| 207 | #if defined(CONFIG_TEGRA30) |
| 208 | enum periph_id id = host->mmc_id; |
| 209 | u32 val; |
| 210 | |
| 211 | debug("%s: sdmmc address = %08x, id = %d\n", __func__, |
| 212 | (unsigned int)host->reg, id); |
| 213 | |
| 214 | /* Set the pad drive strength for SDMMC1 or 3 only */ |
| 215 | if (id != PERIPH_ID_SDMMC1 && id != PERIPH_ID_SDMMC3) { |
| 216 | debug("%s: settings are only valid for SDMMC1/SDMMC3!\n", |
| 217 | __func__); |
| 218 | return; |
| 219 | } |
| 220 | |
| 221 | val = readl(&host->reg->sdmemcmppadctl); |
| 222 | val &= 0xFFFFFFF0; |
| 223 | val |= MEMCOMP_PADCTRL_VREF; |
| 224 | writel(val, &host->reg->sdmemcmppadctl); |
| 225 | |
| 226 | val = readl(&host->reg->autocalcfg); |
| 227 | val &= 0xFFFF0000; |
| 228 | val |= AUTO_CAL_PU_OFFSET | AUTO_CAL_PD_OFFSET | AUTO_CAL_ENABLED; |
| 229 | writel(val, &host->reg->autocalcfg); |
| 230 | #endif /* T30 */ |
| 231 | } |
| 232 | #endif /* MMC */ |