blob: e1597c8ba9d2ab3bdfbccf794f01d9f1a556865d [file] [log] [blame]
Gabe Black5c8d3d22014-01-17 22:11:35 -08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2014 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <arch/cache.h>
21#include <arch/cpu.h>
22#include <arch/exception.h>
Gabe Black4a12cfe2014-03-24 21:24:24 -070023#include <arch/io.h>
Gabe Black5c8d3d22014-01-17 22:11:35 -080024#include <arch/stages.h>
25#include <device/device.h>
26#include <cbfs.h>
27#include <cbmem.h>
28#include <console/console.h>
Tom Warren64982c502014-01-23 13:37:50 -070029#include "sdram_configs.h"
Gabe Black4a12cfe2014-03-24 21:24:24 -070030#include <soc/nvidia/tegra/i2c.h>
31#include <soc/nvidia/tegra124/chip.h>
32#include <soc/nvidia/tegra124/clk_rst.h>
33#include <soc/nvidia/tegra124/sdram.h>
34#include <soc/addressmap.h>
35#include <soc/clock.h>
Gabe Black5c8d3d22014-01-17 22:11:35 -080036#include <soc/display.h>
37#include <timestamp.h>
38
Gabe Black4a12cfe2014-03-24 21:24:24 -070039static struct clk_rst_ctlr *clk_rst = (void *)TEGRA_CLK_RST_BASE;
40
Gabe Black5c8d3d22014-01-17 22:11:35 -080041enum {
42 L2CTLR_ECC_PARITY = 0x1 << 21,
43 L2CTLR_TAG_RAM_LATENCY_MASK = 0x7 << 6,
44 L2CTLR_TAG_RAM_LATENCY_CYCLES_3 = 2 << 6,
45 L2CTLR_DATA_RAM_LATENCY_MASK = 0x7 << 0,
46 L2CTLR_DATA_RAM_LATENCY_CYCLES_3 = 2 << 0
47};
48
49enum {
50 L2ACTLR_FORCE_L2_LOGIC_CLOCK_ENABLE_ACTIVE = 0x1 << 27,
51 L2ACTLR_ENABLE_HAZARD_DETECT_TIMEOUT = 0x1 << 7,
52 L2ACTLR_DISABLE_CLEAN_EVICT_PUSH_EXTERNAL = 0x1 << 3
53};
54
55/* Configures L2 Control Register to use 3 cycles for DATA/TAG RAM latency. */
56static void configure_l2ctlr(void)
57{
58 uint32_t val;
59
60 val = read_l2ctlr();
61 val &= ~(L2CTLR_DATA_RAM_LATENCY_MASK | L2CTLR_TAG_RAM_LATENCY_MASK);
62 val |= (L2CTLR_DATA_RAM_LATENCY_CYCLES_3 | L2CTLR_TAG_RAM_LATENCY_CYCLES_3 |
63 L2CTLR_ECC_PARITY);
64 write_l2ctlr(val);
65}
66
67/* Configures L2 Auxiliary Control Register for Cortex A15. */
68static void configure_l2actlr(void)
69{
70 uint32_t val;
71
72 val = read_l2actlr();
73 val |= (L2ACTLR_DISABLE_CLEAN_EVICT_PUSH_EXTERNAL |
74 L2ACTLR_ENABLE_HAZARD_DETECT_TIMEOUT |
75 L2ACTLR_FORCE_L2_LOGIC_CLOCK_ENABLE_ACTIVE);
76 write_l2actlr(val);
77}
78
Gabe Black4a12cfe2014-03-24 21:24:24 -070079static void setup_pinmux(void)
80{
81 // Write protect.
82 gpio_input_pullup(GPIO(R1));
83 // Recovery mode.
84 gpio_input_pullup(GPIO(Q7));
85 // Lid switch.
86 gpio_input_pullup(GPIO(R4));
87 // Power switch.
88 gpio_input_pullup(GPIO(Q0));
89 // Developer mode.
90 gpio_input_pullup(GPIO(Q6));
91 // EC in RW.
92 gpio_input_pullup(GPIO(U4));
93
94 // SOC and TPM reset GPIO, active low.
95 gpio_output(GPIO(I5), 1);
96
97 // SPI1 MOSI
98 pinmux_set_config(PINMUX_ULPI_CLK_INDEX, PINMUX_ULPI_CLK_FUNC_SPI1 |
99 PINMUX_PULL_NONE |
100 PINMUX_INPUT_ENABLE);
101 // SPI1 MISO
102 pinmux_set_config(PINMUX_ULPI_DIR_INDEX, PINMUX_ULPI_DIR_FUNC_SPI1 |
103 PINMUX_PULL_NONE |
104 PINMUX_INPUT_ENABLE);
105 // SPI1 SCLK
106 pinmux_set_config(PINMUX_ULPI_NXT_INDEX, PINMUX_ULPI_NXT_FUNC_SPI1 |
107 PINMUX_PULL_NONE |
108 PINMUX_INPUT_ENABLE);
109 // SPI1 CS0
110 pinmux_set_config(PINMUX_ULPI_STP_INDEX, PINMUX_ULPI_STP_FUNC_SPI1 |
111 PINMUX_PULL_NONE |
112 PINMUX_INPUT_ENABLE);
113
114 // I2C3 (cam) clock.
115 pinmux_set_config(PINMUX_CAM_I2C_SCL_INDEX,
116 PINMUX_CAM_I2C_SCL_FUNC_I2C3 | PINMUX_INPUT_ENABLE);
117 // I2C3 (cam) data.
118 pinmux_set_config(PINMUX_CAM_I2C_SDA_INDEX,
119 PINMUX_CAM_I2C_SDA_FUNC_I2C3 | PINMUX_INPUT_ENABLE);
120
121 // switch unused pin to GPIO
122 gpio_set_mode(GPIO(X3), GPIO_MODE_GPIO);
123 gpio_set_mode(GPIO(X4), GPIO_MODE_GPIO);
124 gpio_set_mode(GPIO(X5), GPIO_MODE_GPIO);
125 gpio_set_mode(GPIO(X6), GPIO_MODE_GPIO);
126 gpio_set_mode(GPIO(X7), GPIO_MODE_GPIO);
127 gpio_set_mode(GPIO(W3), GPIO_MODE_GPIO);
128}
129
130static void configure_ec_spi_bus(void)
131{
132 clock_configure_source(sbc1, PLLP, 5000);
133}
134
135static void configure_tpm_i2c_bus(void)
136{
137 /*
138 * The TPM is on I2C3 and can theoretically run at 400 KHz but doesn't
139 * seem to work above around 40 KHz. It's set to run at 100 KHz in the
140 * kernel.
141 */
142 clock_configure_i2c_scl_freq(i2c3, PLLP, 40);
143
144 i2c_init(2);
145}
146
Julius Wernerfd9defc2014-01-21 20:11:22 -0800147static void __attribute__((noinline)) romstage(void)
Gabe Black5c8d3d22014-01-17 22:11:35 -0800148{
149#if CONFIG_COLLECT_TIMESTAMPS
150 uint64_t romstage_start_time = timestamp_get();
151#endif
152
Gabe Black5c8d3d22014-01-17 22:11:35 -0800153 configure_l2ctlr();
154 configure_l2actlr();
155
156 console_init();
157 exception_init();
158
Tom Warren64982c502014-01-23 13:37:50 -0700159 sdram_init(get_sdram_config());
160
Gabe Black5cbbc702014-02-08 05:17:38 -0800161 /* used for MMU and CBMEM setup, in MB */
Tom Warren64982c502014-01-23 13:37:50 -0700162 u32 dram_start = (CONFIG_SYS_SDRAM_BASE >> 20);
Gabe Black5cbbc702014-02-08 05:17:38 -0800163 u32 dram_end = sdram_max_addressable_mb(); /* plus one... */
164 u32 dram_size = dram_end - dram_start;
Tom Warren64982c502014-01-23 13:37:50 -0700165
Gabe Black5c8d3d22014-01-17 22:11:35 -0800166 mmu_init();
Gabe Blackb9a4b712014-03-01 03:27:00 -0800167 /* Device memory below DRAM is uncached. */
Tom Warren64982c502014-01-23 13:37:50 -0700168 mmu_config_range(0, dram_start, DCACHE_OFF);
Gabe Blackb9a4b712014-03-01 03:27:00 -0800169 /* SRAM is cached. Round the size up to 2MB, the LPAE page size. */
170 mmu_config_range(0x40000000 >> 20, 2, DCACHE_WRITEBACK);
171 /* DRAM is cached. */
Gabe Black5cbbc702014-02-08 05:17:38 -0800172 mmu_config_range(dram_start, dram_size, DCACHE_WRITEBACK);
Gabe Blackb9a4b712014-03-01 03:27:00 -0800173 /* A window for DMA is uncached. */
Gabe Black5c8d3d22014-01-17 22:11:35 -0800174 mmu_config_range(CONFIG_DRAM_DMA_START >> 20,
175 CONFIG_DRAM_DMA_SIZE >> 20, DCACHE_OFF);
Gabe Blackb9a4b712014-03-01 03:27:00 -0800176 /* The space above DRAM is uncached. */
Gabe Black83ed8052014-02-15 00:05:03 -0800177 if (dram_end < 4096)
178 mmu_config_range(dram_end, 4096 - dram_end, DCACHE_OFF);
Gabe Black5c8d3d22014-01-17 22:11:35 -0800179 mmu_disable_range(0, 1);
Gabe Black5c8d3d22014-01-17 22:11:35 -0800180 dcache_mmu_enable();
181
182 /* For quality of the user experience, it's important to get
183 * the video going ASAP. Because there are long delays in some
184 * of the powerup steps, we do some very early setup here in
185 * romstage. The only thing setup_display does is manage
186 * 4 GPIOs, under control of the config struct members.
187 * In general, it is safe to enable panel power, and disable
188 * anything related to the backlight. If we get something wrong,
189 * we can easily fix it in ramstage by further GPIO manipulation,
190 * so we feel it is ok to do some setting at this point.
191 */
192
193 const struct device *soc = dev_find_slot(DEVICE_PATH_CPU_CLUSTER, 0);
194 printk(BIOS_SPEW, "s%s: soc is %p\n", __func__, soc);
195 if (soc && soc->chip_info) {
196 const struct soc_nvidia_tegra124_config *config =
197 soc->chip_info;
198 setup_display((struct soc_nvidia_tegra124_config *)config);
199 }
200
201 cbmem_initialize_empty();
202
203#if CONFIG_COLLECT_TIMESTAMPS
204 timestamp_init(0);
205 timestamp_add(TS_START_ROMSTAGE, romstage_start_time);
206 timestamp_add(TS_START_COPYRAM, timestamp_get());
207#endif
Gabe Black4a12cfe2014-03-24 21:24:24 -0700208
209 // Enable additional peripherals we need for ROM stage.
210 clock_enable_clear_reset(0, CLK_H_SBC1, CLK_U_I2C3, 0, 0, 0);
211
212 setup_pinmux();
213
214 configure_ec_spi_bus();
215 configure_tpm_i2c_bus();
216
Gabe Black5c8d3d22014-01-17 22:11:35 -0800217 void *entry = cbfs_load_stage(CBFS_DEFAULT_MEDIA,
218 "fallback/coreboot_ram");
219#if CONFIG_COLLECT_TIMESTAMPS
220 timestamp_add(TS_END_COPYRAM, timestamp_get());
221#endif
222 stage_exit(entry);
223}
Julius Wernerfd9defc2014-01-21 20:11:22 -0800224
225/* Stub to force arm_init_caches to the top, before any stack/memory accesses */
226void main(void)
227{
Gabe Blackf220df62014-02-08 05:01:06 -0800228 asm volatile ("bl arm_init_caches"
229 ::: "r0","r1","r2","r3","r4","r5","ip");
Julius Wernerfd9defc2014-01-21 20:11:22 -0800230 romstage();
231}