]> git.sur5r.net Git - u-boot/blob - board/nvidia/common/board.c
80ef8fdcb23baf885048ac90bded1d023c3328c9
[u-boot] / board / nvidia / common / board.c
1 /*
2  *  (C) Copyright 2010,2011
3  *  NVIDIA Corporation <www.nvidia.com>
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7
8 #include <common.h>
9 #include <dm.h>
10 #include <ns16550.h>
11 #include <linux/compiler.h>
12 #include <asm/io.h>
13 #include <asm/arch/clock.h>
14 #ifdef CONFIG_LCD
15 #include <asm/arch/display.h>
16 #endif
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>
22 #endif
23 #include <asm/arch/tegra.h>
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>
30 #ifdef CONFIG_TEGRA_CLOCK_SCALING
31 #include <asm/arch/emc.h>
32 #endif
33 #ifdef CONFIG_USB_EHCI_TEGRA
34 #include <asm/arch-tegra/usb.h>
35 #include <usb.h>
36 #endif
37 #ifdef CONFIG_TEGRA_MMC
38 #include <asm/arch-tegra/tegra_mmc.h>
39 #include <asm/arch-tegra/mmc.h>
40 #endif
41 #include <asm/arch-tegra/xusb-padctl.h>
42 #include <i2c.h>
43 #include <spi.h>
44 #include "emc.h"
45
46 DECLARE_GLOBAL_DATA_PTR;
47
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
55 const struct tegra_sysinfo sysinfo = {
56         CONFIG_TEGRA_BOARD_STRING
57 };
58
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) {}
64
65 #if defined(CONFIG_TEGRA_NAND)
66 __weak void pin_mux_nand(void)
67 {
68         funcmux_select(PERIPH_ID_NDFLASH, FUNCMUX_DEFAULT);
69 }
70 #endif
71
72 /*
73  * Routine: power_det_init
74  * Description: turn off power detects
75  */
76 static void power_det_init(void)
77 {
78 #if defined(CONFIG_TEGRA20)
79         struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
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 /*
88  * Routine: board_init
89  * Description: Early hardware init.
90  */
91 int board_init(void)
92 {
93         __maybe_unused int err;
94
95         /* Do clocks and UART first so that printf() works */
96         clock_init();
97         clock_verify();
98
99 #ifdef CONFIG_TEGRA_SPI
100         pin_mux_spi();
101 #endif
102
103 #ifdef CONFIG_PWM_TEGRA
104         if (pwm_init(gd->fdt_blob))
105                 debug("%s: Failed to init pwm\n", __func__);
106 #endif
107 #ifdef CONFIG_LCD
108         pin_mux_display();
109         tegra_lcd_check_next_stage(gd->fdt_blob, 0);
110 #endif
111         /* boot param addr */
112         gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100);
113
114         power_det_init();
115
116 #ifdef CONFIG_SYS_I2C_TEGRA
117 # ifdef CONFIG_TEGRA_PMU
118         if (pmu_set_nominal())
119                 debug("Failed to select nominal voltages\n");
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 */
126 #endif /* CONFIG_SYS_I2C_TEGRA */
127
128 #ifdef CONFIG_USB_EHCI_TEGRA
129         pin_mux_usb();
130         usb_process_devicetree(gd->fdt_blob);
131 #endif
132
133 #ifdef CONFIG_LCD
134         tegra_lcd_check_next_stage(gd->fdt_blob, 0);
135 #endif
136
137 #ifdef CONFIG_TEGRA_NAND
138         pin_mux_nand();
139 #endif
140
141         tegra_xusb_padctl_init(gd->fdt_blob);
142
143 #ifdef CONFIG_TEGRA_LP0
144         /* save Sdram params to PMC 2, 4, and 24 for WB0 */
145         warmboot_save_sdram_params();
146
147         /* prepare the WB code to LP0 location */
148         warmboot_prepare_code(TEGRA_LP0_ADDR, TEGRA_LP0_SIZE);
149 #endif
150
151         return 0;
152 }
153
154 #ifdef CONFIG_BOARD_EARLY_INIT_F
155 static void __gpio_early_init(void)
156 {
157 }
158
159 void gpio_early_init(void) __attribute__((weak, alias("__gpio_early_init")));
160
161 int board_early_init_f(void)
162 {
163         pinmux_init();
164         board_init_uart_f();
165
166         /* Initialize periph GPIOs */
167         gpio_early_init();
168         gpio_early_init_uart();
169 #ifdef CONFIG_LCD
170         tegra_lcd_early_init(gd->fdt_blob);
171 #endif
172
173         return 0;
174 }
175 #endif  /* EARLY_INIT */
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 }
185
186 #if defined(CONFIG_TEGRA_MMC)
187 __weak void pin_mux_mmc(void)
188 {
189 }
190
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 }
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 */