blob: 914c925d5d3e4e54a5a3274c3d1a71bdf5c1475f [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 <cbfs.h>
25#include <cbmem.h>
26#include <console/console.h>
Gabe Blackc8522062014-05-06 15:44:14 -070027#include <mainboard/google/nyan/reset.h>
Aaron Durbine4f3e7a2015-03-17 13:25:19 -050028#include <program_loading.h>
Aaron Durbincad7c4e2014-03-20 15:08:54 -050029#include <romstage_handoff.h>
30#include <vendorcode/google/chromeos/chromeos.h>
Tom Warren64982c502014-01-23 13:37:50 -070031#include "sdram_configs.h"
Gabe Black4a12cfe2014-03-24 21:24:24 -070032#include <soc/nvidia/tegra/i2c.h>
33#include <soc/nvidia/tegra124/chip.h>
34#include <soc/nvidia/tegra124/clk_rst.h>
Gabe Blackc8522062014-05-06 15:44:14 -070035#include <soc/nvidia/tegra124/power.h>
Gabe Black4a12cfe2014-03-24 21:24:24 -070036#include <soc/nvidia/tegra124/sdram.h>
37#include <soc/addressmap.h>
38#include <soc/clock.h>
Gabe Black5c8d3d22014-01-17 22:11:35 -080039#include <soc/display.h>
40#include <timestamp.h>
41
Gabe Black4a12cfe2014-03-24 21:24:24 -070042static struct clk_rst_ctlr *clk_rst = (void *)TEGRA_CLK_RST_BASE;
43
Gabe Black5c8d3d22014-01-17 22:11:35 -080044enum {
45 L2CTLR_ECC_PARITY = 0x1 << 21,
46 L2CTLR_TAG_RAM_LATENCY_MASK = 0x7 << 6,
47 L2CTLR_TAG_RAM_LATENCY_CYCLES_3 = 2 << 6,
48 L2CTLR_DATA_RAM_LATENCY_MASK = 0x7 << 0,
49 L2CTLR_DATA_RAM_LATENCY_CYCLES_3 = 2 << 0
50};
51
52enum {
53 L2ACTLR_FORCE_L2_LOGIC_CLOCK_ENABLE_ACTIVE = 0x1 << 27,
54 L2ACTLR_ENABLE_HAZARD_DETECT_TIMEOUT = 0x1 << 7,
55 L2ACTLR_DISABLE_CLEAN_EVICT_PUSH_EXTERNAL = 0x1 << 3
56};
57
58/* Configures L2 Control Register to use 3 cycles for DATA/TAG RAM latency. */
59static void configure_l2ctlr(void)
60{
61 uint32_t val;
62
63 val = read_l2ctlr();
64 val &= ~(L2CTLR_DATA_RAM_LATENCY_MASK | L2CTLR_TAG_RAM_LATENCY_MASK);
65 val |= (L2CTLR_DATA_RAM_LATENCY_CYCLES_3 | L2CTLR_TAG_RAM_LATENCY_CYCLES_3 |
66 L2CTLR_ECC_PARITY);
67 write_l2ctlr(val);
68}
69
70/* Configures L2 Auxiliary Control Register for Cortex A15. */
71static void configure_l2actlr(void)
72{
73 uint32_t val;
74
75 val = read_l2actlr();
76 val |= (L2ACTLR_DISABLE_CLEAN_EVICT_PUSH_EXTERNAL |
77 L2ACTLR_ENABLE_HAZARD_DETECT_TIMEOUT |
78 L2ACTLR_FORCE_L2_LOGIC_CLOCK_ENABLE_ACTIVE);
79 write_l2actlr(val);
80}
81
Gabe Black4a12cfe2014-03-24 21:24:24 -070082static void setup_pinmux(void)
83{
84 // Write protect.
85 gpio_input_pullup(GPIO(R1));
86 // Recovery mode.
87 gpio_input_pullup(GPIO(Q7));
88 // Lid switch.
89 gpio_input_pullup(GPIO(R4));
90 // Power switch.
91 gpio_input_pullup(GPIO(Q0));
92 // Developer mode.
93 gpio_input_pullup(GPIO(Q6));
94 // EC in RW.
95 gpio_input_pullup(GPIO(U4));
96
Tom Warrenc05a9052014-04-14 10:01:21 -070097 // route PU4/5 to GMI to remove conflict w/PWM1/2.
98 pinmux_set_config(PINMUX_GPIO_PU4_INDEX, PINMUX_GPIO_PU4_FUNC_NOR); //s/b GMI
99 pinmux_set_config(PINMUX_GPIO_PU5_INDEX, PINMUX_GPIO_PU5_FUNC_NOR); //s/b GMI
100
Gabe Black4a12cfe2014-03-24 21:24:24 -0700101 // SOC and TPM reset GPIO, active low.
102 gpio_output(GPIO(I5), 1);
103
104 // SPI1 MOSI
105 pinmux_set_config(PINMUX_ULPI_CLK_INDEX, PINMUX_ULPI_CLK_FUNC_SPI1 |
106 PINMUX_PULL_NONE |
107 PINMUX_INPUT_ENABLE);
108 // SPI1 MISO
109 pinmux_set_config(PINMUX_ULPI_DIR_INDEX, PINMUX_ULPI_DIR_FUNC_SPI1 |
110 PINMUX_PULL_NONE |
111 PINMUX_INPUT_ENABLE);
112 // SPI1 SCLK
113 pinmux_set_config(PINMUX_ULPI_NXT_INDEX, PINMUX_ULPI_NXT_FUNC_SPI1 |
114 PINMUX_PULL_NONE |
115 PINMUX_INPUT_ENABLE);
116 // SPI1 CS0
117 pinmux_set_config(PINMUX_ULPI_STP_INDEX, PINMUX_ULPI_STP_FUNC_SPI1 |
118 PINMUX_PULL_NONE |
119 PINMUX_INPUT_ENABLE);
120
121 // I2C3 (cam) clock.
122 pinmux_set_config(PINMUX_CAM_I2C_SCL_INDEX,
123 PINMUX_CAM_I2C_SCL_FUNC_I2C3 | PINMUX_INPUT_ENABLE);
124 // I2C3 (cam) data.
125 pinmux_set_config(PINMUX_CAM_I2C_SDA_INDEX,
126 PINMUX_CAM_I2C_SDA_FUNC_I2C3 | PINMUX_INPUT_ENABLE);
127
128 // switch unused pin to GPIO
129 gpio_set_mode(GPIO(X3), GPIO_MODE_GPIO);
130 gpio_set_mode(GPIO(X4), GPIO_MODE_GPIO);
131 gpio_set_mode(GPIO(X5), GPIO_MODE_GPIO);
132 gpio_set_mode(GPIO(X6), GPIO_MODE_GPIO);
133 gpio_set_mode(GPIO(X7), GPIO_MODE_GPIO);
134 gpio_set_mode(GPIO(W3), GPIO_MODE_GPIO);
135}
136
137static void configure_ec_spi_bus(void)
138{
Gabe Black92dfa9c2014-04-07 01:19:27 -0700139 clock_configure_source(sbc1, CLK_M, 3000);
Gabe Black4a12cfe2014-03-24 21:24:24 -0700140}
141
142static void configure_tpm_i2c_bus(void)
143{
Gabe Blackb19136f2014-03-26 21:58:06 -0700144 clock_configure_i2c_scl_freq(i2c3, PLLP, 400);
Gabe Black4a12cfe2014-03-24 21:24:24 -0700145
146 i2c_init(2);
147}
148
Julius Wernerfd9defc2014-01-21 20:11:22 -0800149static void __attribute__((noinline)) romstage(void)
Gabe Black5c8d3d22014-01-17 22:11:35 -0800150{
Kyösti Mälkkif48b38b2014-12-31 08:50:36 +0200151 timestamp_init(0);
152 timestamp_add_now(TS_START_ROMSTAGE);
Gabe Black5c8d3d22014-01-17 22:11:35 -0800153
Gabe Black5c8d3d22014-01-17 22:11:35 -0800154 configure_l2ctlr();
155 configure_l2actlr();
156
157 console_init();
158 exception_init();
159
Tom Warren64982c502014-01-23 13:37:50 -0700160 sdram_init(get_sdram_config());
161
Gabe Black5cbbc702014-02-08 05:17:38 -0800162 /* used for MMU and CBMEM setup, in MB */
Tom Warren64982c502014-01-23 13:37:50 -0700163 u32 dram_start = (CONFIG_SYS_SDRAM_BASE >> 20);
Gabe Black5cbbc702014-02-08 05:17:38 -0800164 u32 dram_end = sdram_max_addressable_mb(); /* plus one... */
165 u32 dram_size = dram_end - dram_start;
Tom Warren64982c502014-01-23 13:37:50 -0700166
Gabe Black5c8d3d22014-01-17 22:11:35 -0800167 mmu_init();
Gabe Blackb9a4b712014-03-01 03:27:00 -0800168 /* Device memory below DRAM is uncached. */
Tom Warren64982c502014-01-23 13:37:50 -0700169 mmu_config_range(0, dram_start, DCACHE_OFF);
Gabe Blackb9a4b712014-03-01 03:27:00 -0800170 /* SRAM is cached. Round the size up to 2MB, the LPAE page size. */
171 mmu_config_range(0x40000000 >> 20, 2, DCACHE_WRITEBACK);
172 /* DRAM is cached. */
Gabe Black5cbbc702014-02-08 05:17:38 -0800173 mmu_config_range(dram_start, dram_size, DCACHE_WRITEBACK);
Gabe Blackb9a4b712014-03-01 03:27:00 -0800174 /* A window for DMA is uncached. */
Gabe Black5c8d3d22014-01-17 22:11:35 -0800175 mmu_config_range(CONFIG_DRAM_DMA_START >> 20,
176 CONFIG_DRAM_DMA_SIZE >> 20, DCACHE_OFF);
Gabe Blackb9a4b712014-03-01 03:27:00 -0800177 /* The space above DRAM is uncached. */
Gabe Black83ed8052014-02-15 00:05:03 -0800178 if (dram_end < 4096)
179 mmu_config_range(dram_end, 4096 - dram_end, DCACHE_OFF);
Gabe Black5c8d3d22014-01-17 22:11:35 -0800180 mmu_disable_range(0, 1);
Gabe Black5c8d3d22014-01-17 22:11:35 -0800181 dcache_mmu_enable();
182
Gabe Blackc8522062014-05-06 15:44:14 -0700183 /*
184 * A watchdog reset only resets part of the system so it ends up in
185 * a funny state. If that happens, we need to reset the whole machine.
186 */
187 if (power_reset_status() == POWER_RESET_WATCHDOG) {
188 printk(BIOS_INFO, "Watchdog reset detected, rebooting.\n");
189 cpu_reset();
190 }
191
Gabe Black5c8d3d22014-01-17 22:11:35 -0800192 cbmem_initialize_empty();
193
Gabe Black4a12cfe2014-03-24 21:24:24 -0700194 // Enable additional peripherals we need for ROM stage.
195 clock_enable_clear_reset(0, CLK_H_SBC1, CLK_U_I2C3, 0, 0, 0);
196
197 setup_pinmux();
198
199 configure_ec_spi_bus();
200 configure_tpm_i2c_bus();
201
Aaron Durbincad7c4e2014-03-20 15:08:54 -0500202 vboot_verify_firmware(romstage_handoff_find_or_add());
203
Aaron Durbine4f3e7a2015-03-17 13:25:19 -0500204 run_ramstage();
Gabe Black5c8d3d22014-01-17 22:11:35 -0800205}
Julius Wernerfd9defc2014-01-21 20:11:22 -0800206
207/* Stub to force arm_init_caches to the top, before any stack/memory accesses */
208void main(void)
209{
Gabe Blackf220df62014-02-08 05:01:06 -0800210 asm volatile ("bl arm_init_caches"
211 ::: "r0","r1","r2","r3","r4","r5","ip");
Julius Wernerfd9defc2014-01-21 20:11:22 -0800212 romstage();
213}