]> git.karo-electronics.de Git - karo-tx-uboot.git/blob - board/nvidia/common/board.c
4cc23ef6167efb465210b4a78b3db0e4a0a1f580
[karo-tx-uboot.git] / 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/ap.h>
25 #include <asm/arch-tegra/board.h>
26 #include <asm/arch-tegra/clk_rst.h>
27 #include <asm/arch-tegra/pmc.h>
28 #include <asm/arch-tegra/sys_proto.h>
29 #include <asm/arch-tegra/uart.h>
30 #include <asm/arch-tegra/warmboot.h>
31 #ifdef CONFIG_TEGRA_CLOCK_SCALING
32 #include <asm/arch/emc.h>
33 #endif
34 #ifdef CONFIG_USB_EHCI_TEGRA
35 #include <asm/arch-tegra/usb.h>
36 #include <usb.h>
37 #endif
38 #ifdef CONFIG_TEGRA_MMC
39 #include <asm/arch-tegra/tegra_mmc.h>
40 #include <asm/arch-tegra/mmc.h>
41 #endif
42 #include <asm/arch-tegra/xusb-padctl.h>
43 #include <i2c.h>
44 #include <spi.h>
45 #include "emc.h"
46
47 DECLARE_GLOBAL_DATA_PTR;
48
49 #ifdef CONFIG_SPL_BUILD
50 /* TODO(sjg@chromium.org): Remove once SPL supports device tree */
51 U_BOOT_DEVICE(tegra_gpios) = {
52         "gpio_tegra"
53 };
54 #endif
55
56 __weak void pinmux_init(void) {}
57 __weak void pin_mux_usb(void) {}
58 __weak void pin_mux_spi(void) {}
59 __weak void gpio_early_init_uart(void) {}
60 __weak void pin_mux_display(void) {}
61
62 #if defined(CONFIG_TEGRA_NAND)
63 __weak void pin_mux_nand(void)
64 {
65         funcmux_select(PERIPH_ID_NDFLASH, FUNCMUX_DEFAULT);
66 }
67 #endif
68
69 /*
70  * Routine: power_det_init
71  * Description: turn off power detects
72  */
73 static void power_det_init(void)
74 {
75 #if defined(CONFIG_TEGRA20)
76         struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
77
78         /* turn off power detects */
79         writel(0, &pmc->pmc_pwr_det_latch);
80         writel(0, &pmc->pmc_pwr_det);
81 #endif
82 }
83
84 __weak int tegra_board_id(void)
85 {
86         return -1;
87 }
88
89 #ifdef CONFIG_DISPLAY_BOARDINFO
90 int checkboard(void)
91 {
92         int board_id = tegra_board_id();
93
94         printf("Board: %s", CONFIG_TEGRA_BOARD_STRING);
95         if (board_id != -1)
96                 printf(", ID: %d\n", board_id);
97         printf("\n");
98
99         return 0;
100 }
101 #endif  /* CONFIG_DISPLAY_BOARDINFO */
102
103 __weak int tegra_lcd_pmic_init(int board_it)
104 {
105         return 0;
106 }
107
108 /*
109  * Routine: board_init
110  * Description: Early hardware init.
111  */
112 int board_init(void)
113 {
114         __maybe_unused int err;
115         __maybe_unused int board_id;
116
117         /* Do clocks and UART first so that printf() works */
118         clock_init();
119         clock_verify();
120
121 #ifdef CONFIG_TEGRA_SPI
122         pin_mux_spi();
123 #endif
124
125 #ifdef CONFIG_PWM_TEGRA
126         if (pwm_init(gd->fdt_blob))
127                 debug("%s: Failed to init pwm\n", __func__);
128 #endif
129 #ifdef CONFIG_LCD
130         pin_mux_display();
131         tegra_lcd_check_next_stage(gd->fdt_blob, 0);
132 #endif
133         /* boot param addr */
134         gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100);
135
136         power_det_init();
137
138 #ifdef CONFIG_SYS_I2C_TEGRA
139 # ifdef CONFIG_TEGRA_PMU
140         if (pmu_set_nominal())
141                 debug("Failed to select nominal voltages\n");
142 #  ifdef CONFIG_TEGRA_CLOCK_SCALING
143         err = board_emc_init();
144         if (err)
145                 debug("Memory controller init failed: %d\n", err);
146 #  endif
147 # endif /* CONFIG_TEGRA_PMU */
148 #endif /* CONFIG_SYS_I2C_TEGRA */
149
150 #ifdef CONFIG_USB_EHCI_TEGRA
151         pin_mux_usb();
152         usb_process_devicetree(gd->fdt_blob);
153 #endif
154
155 #ifdef CONFIG_LCD
156         board_id = tegra_board_id();
157         err = tegra_lcd_pmic_init(board_id);
158         if (err)
159                 return err;
160         tegra_lcd_check_next_stage(gd->fdt_blob, 0);
161 #endif
162
163 #ifdef CONFIG_TEGRA_NAND
164         pin_mux_nand();
165 #endif
166
167         tegra_xusb_padctl_init(gd->fdt_blob);
168
169 #ifdef CONFIG_TEGRA_LP0
170         /* save Sdram params to PMC 2, 4, and 24 for WB0 */
171         warmboot_save_sdram_params();
172
173         /* prepare the WB code to LP0 location */
174         warmboot_prepare_code(TEGRA_LP0_ADDR, TEGRA_LP0_SIZE);
175 #endif
176
177         return 0;
178 }
179
180 #ifdef CONFIG_BOARD_EARLY_INIT_F
181 static void __gpio_early_init(void)
182 {
183 }
184
185 void gpio_early_init(void) __attribute__((weak, alias("__gpio_early_init")));
186
187 int board_early_init_f(void)
188 {
189         pinmux_init();
190         board_init_uart_f();
191
192         /* Initialize periph GPIOs */
193         gpio_early_init();
194         gpio_early_init_uart();
195 #ifdef CONFIG_LCD
196         tegra_lcd_early_init(gd->fdt_blob);
197 #endif
198
199         return 0;
200 }
201 #endif  /* EARLY_INIT */
202
203 int board_late_init(void)
204 {
205 #ifdef CONFIG_LCD
206         /* Make sure we finish initing the LCD */
207         tegra_lcd_check_next_stage(gd->fdt_blob, 1);
208 #endif
209 #if defined(CONFIG_TEGRA_SUPPORT_NON_SECURE)
210         if (tegra_cpu_is_non_secure()) {
211                 printf("CPU is in NS mode\n");
212                 setenv("cpu_ns_mode", "1");
213         } else {
214                 setenv("cpu_ns_mode", "");
215         }
216 #endif
217         return 0;
218 }
219
220 #if defined(CONFIG_TEGRA_MMC)
221 __weak void pin_mux_mmc(void)
222 {
223 }
224
225 /* this is a weak define that we are overriding */
226 int board_mmc_init(bd_t *bd)
227 {
228         debug("%s called\n", __func__);
229
230         /* Enable muxes, etc. for SDMMC controllers */
231         pin_mux_mmc();
232
233         debug("%s: init MMC\n", __func__);
234         tegra_mmc_init();
235
236         return 0;
237 }
238
239 void pad_init_mmc(struct mmc_host *host)
240 {
241 #if defined(CONFIG_TEGRA30)
242         enum periph_id id = host->mmc_id;
243         u32 val;
244
245         debug("%s: sdmmc address = %08x, id = %d\n", __func__,
246                 (unsigned int)host->reg, id);
247
248         /* Set the pad drive strength for SDMMC1 or 3 only */
249         if (id != PERIPH_ID_SDMMC1 && id != PERIPH_ID_SDMMC3) {
250                 debug("%s: settings are only valid for SDMMC1/SDMMC3!\n",
251                         __func__);
252                 return;
253         }
254
255         val = readl(&host->reg->sdmemcmppadctl);
256         val &= 0xFFFFFFF0;
257         val |= MEMCOMP_PADCTRL_VREF;
258         writel(val, &host->reg->sdmemcmppadctl);
259
260         val = readl(&host->reg->autocalcfg);
261         val &= 0xFFFF0000;
262         val |= AUTO_CAL_PU_OFFSET | AUTO_CAL_PD_OFFSET | AUTO_CAL_ENABLED;
263         writel(val, &host->reg->autocalcfg);
264 #endif  /* T30 */
265 }
266 #endif  /* MMC */