blob: 3d4e8812a6fb329eab936465b16f00c7a8cedc43 [file] [log] [blame]
Patrick Georgi40a3e322015-06-22 19:41:29 +02001/*
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.
Patrick Georgi40a3e322015-06-22 19:41:29 +020014 */
15
16#include <arch/exception.h>
17#include <arch/hlt.h>
Stefan Reinauera9bc3bf2015-07-09 00:18:03 +020018#include <arch/stages.h>
Patrick Georgi40a3e322015-06-22 19:41:29 +020019#include <bootblock_common.h>
20#include <console/console.h>
Yen Lina501a8f2015-05-06 18:08:22 -070021#include <delay.h>
Patrick Georgi40a3e322015-06-22 19:41:29 +020022#include <program_loading.h>
23#include <soc/addressmap.h>
24#include <soc/clock.h>
25#include <soc/nvidia/tegra/apbmisc.h>
26#include <soc/pmc.h>
27#include <soc/power.h>
28#include <timestamp.h>
29
Yen Lin5e03cd52015-05-29 16:47:30 -070030#define BCT_OFFSET_IN_BIT 0x4c
31#define ODMDATA_OFFSET_IN_BCT 0x508
Patrick Georgi40a3e322015-06-22 19:41:29 +020032#define TEGRA_SRAM_MAX (TEGRA_SRAM_BASE + TEGRA_SRAM_SIZE)
33
34static void save_odmdata(void)
35{
36 struct tegra_pmc_regs *pmc = (struct tegra_pmc_regs*)TEGRA_PMC_BASE;
37 uintptr_t bct_offset;
38 u32 odmdata;
39
40 // pmc.odmdata: [18:19]: console type, [15:17]: UART id.
41 // TODO(twarren) ODMDATA is stored in the BCT, from bct/odmdata.cfg.
42 // I use the BCT offset in the BIT in SRAM to locate the BCT, and
43 // pick up the ODMDATA word at BCT offset 0x6A8. I could use a BCT
44 // struct header from cbootimage, but it seems like overkill for this.
45
46 bct_offset = read32((void *)(TEGRA_SRAM_BASE + BCT_OFFSET_IN_BIT));
47 if (bct_offset > TEGRA_SRAM_BASE && bct_offset < TEGRA_SRAM_MAX) {
48 odmdata = read32((void *)(bct_offset + ODMDATA_OFFSET_IN_BCT));
49 write32(&pmc->odmdata, odmdata);
50 }
51}
52
53void __attribute__((weak)) bootblock_mainboard_early_init(void)
54{
55 /* Empty default implementation. */
56}
57
Yen Lina501a8f2015-05-06 18:08:22 -070058/*
59 * Define operations for the workaround:
60 * OP_SET : [reg] = val;
61 * OP_OR : [reg] |= val;
62 * OP_AND : [reg] &= val;
63 * OP_UDELAY : udelay(val);
64 */
65typedef enum {
66 OP_SET,
67 OP_OR,
68 OP_AND,
69 OP_UDELAY, /* use val field as usec delay */
70} WAR_OP;
71
72struct workaround_op {
73 WAR_OP op;
74 u32 reg;
75 u32 val;
76};
77
78/*
79 * An array defines the sequence to perform the workaround
80 */
81static struct workaround_op workaround_sequence[] = {
82 {OP_OR, 0x60006410, (1 << 15)}, /* CLK_SOURCE_SOR1: */
83 {OP_AND, 0x60006410, ~(1 << 14)}, /* CLK_SEL1=1, CLK_SEL0=0 */
84 {OP_OR, 0x600060d0, 0x40800000}, /* PLLD_BASE */
85 {OP_SET, 0x600062ac, 0x40}, /* clear APE reset */
86 {OP_SET, 0x60006294, 0x40000}, /* clear VIC reset */
87 {OP_SET, 0x60006304, 0x18000000}, /* clear HOST1X & DISP1 reset */
88 {OP_UDELAY, 0, 2},
89 {OP_OR, 0x702d10a0, 0x400}, /* I2S0: I2S_CTRL.MASTER=1 */
90 {OP_AND, 0x702d1088, ~1}, /* I2S0: I2S_CG.SLCG_ENABLE=0 */
91 {OP_OR, 0x702d11a0, 0x400}, /* I2S1: I2S_CTRL.MASTER=1 */
92 {OP_AND, 0x702d1188, ~1}, /* I2S1: I2S_CG.SLCG_ENABLE=0 */
93 {OP_OR, 0x702d12a0, 0x400}, /* I2S2: I2S_CTRL.MASTER=1 */
94 {OP_AND, 0x702d1288, ~1}, /* I2S2: I2S_CG.SLCG_ENABLE=0 */
95 {OP_OR, 0x702d13a0, 0x400}, /* I2S3: I2S_CTRL.MASTER=1 */
96 {OP_AND, 0x702d1388, ~1}, /* I2S3: I2S_CG.SLCG_ENABLE=0 */
97 {OP_OR, 0x702d14a0, 0x400}, /* I2S4: I2S_CTRL.MASTER=1 */
98 {OP_AND, 0x702d1488, ~1}, /* I2S4: I2S_CG.SLCG_ENABLE=0 */
99 {OP_OR, 0x54200cf8, 4}, /* DC_COM_DSC_TOP_CTL[DSC_SLCG_OVERRIDE]=1 */
100 {OP_SET, 0x543400c8, 0xffffffff}, /* NV_PVIC_THI_SLCG_OVERRIDE_LOW_A = 0xFFFF_FFFF */
101 {OP_UDELAY, 0, 2},
102 {OP_SET, 0x600062a8, 0x40}, /* set APE reset */
103 {OP_SET, 0x60006300, 0x18000000}, /* set HOST1X & DISP1 reset */
104 {OP_SET, 0x60006290, 0x40000}, /* set VIC reset */
105 {OP_SET, 0x60006014, 0x020000c1}, /* CLK_ENB_H */
106 {OP_SET, 0x60006010, 0x80400130}, /* CLK_ENB_L */
107 {OP_SET, 0x60006018, 0x01f00200}, /* CLK_ENB_U */
108 {OP_SET, 0x60006360, 0x80400808}, /* CLK_ENB_V */
109 {OP_SET, 0x60006364, 0x402000fc}, /* CLK_ENB_W */
110 {OP_SET, 0x60006280, 0x23000780}, /* CLK_ENB_X */
111 {OP_SET, 0x60006298, 0x00000340}, /* CLK_ENB_Y */
112 {OP_SET, 0x600060f8, 0x00000000}, /* LVL2_CLK_GATE_OVRA */
113 {OP_SET, 0x600060fc, 0x00000000}, /* LVL2_CLK_GATE_OVRB */
114 {OP_SET, 0x600063a0, 0x00000000}, /* LVL2_CLK_GATE_OVRC */
115 {OP_SET, 0x600063a4, 0x01000000}, /* LVL2_CLK_GATE_OVRD, QSPI_CLK_OVR_ON=1 */
116 {OP_SET, 0x60006554, 0x00000000}, /* LVL2_CLK_GATE_OVRE */
117 {OP_AND, 0x600060d0, 0x1f7fffff}, /* PLLD_BASE: 31,30,29,23 = 0 */
118 {OP_AND, 0x60006410, 0xffff3fff}, /* CLK_SOURCE_SOR1 15,14 = 0 */
119 {OP_AND, 0x60006148, ~(7 << 29)}, /* CLK_SOURCE_VI: */
120 {OP_OR, 0x60006148, (4 << 29)}, /* SRC=PLLP_OUT0 (4) */
121 {OP_AND, 0x60006180, ~(7 << 29)}, /* CLK_SOURCE_HOST1X: */
122 {OP_OR, 0x60006180, (4 << 29)}, /* SRC=PLLP_OUT0 (4) */
123 {OP_AND, 0x600066a0, ~(7 << 29)}, /* CLK_SOURCE_NVENC: */
124 {OP_OR, 0x600066a0, (4 << 29)} /* SRC=PLLP_OUT0 (4) */
125};
126
127/*
128 * This workaround is to restore CAR CE's, SLCG overrides & PLLD settings
129 */
130static void mbist_workaround(void)
131{
132 int i;
133 u32 val;
134 struct workaround_op *wa_op;
135
136 for (i = 0; i < ARRAY_SIZE(workaround_sequence); ++i) {
137 wa_op = &workaround_sequence[i];
138 switch (wa_op->op) {
139 case OP_SET:
140 val = wa_op->val;
141 break;
142 case OP_OR:
143 val = read32((void *)wa_op->reg) | wa_op->val;
144 break;
145 case OP_AND:
146 val = read32((void *)wa_op->reg) & wa_op->val;
147 break;
148 case OP_UDELAY:
149 udelay(wa_op->val);
150 /* fall thru */
151 default:
152 continue;
153 }
154 write32((void *)wa_op->reg, val);
155 }
156}
157
Patrick Georgi40a3e322015-06-22 19:41:29 +0200158void main(void)
159{
160 // enable JTAG at the earliest stage
161 enable_jtag();
162
Yen Lina501a8f2015-05-06 18:08:22 -0700163 mbist_workaround();
164
Patrick Georgi40a3e322015-06-22 19:41:29 +0200165 clock_early_uart();
166
167 /* Configure mselect clock. */
168 clock_configure_source(mselect, PLLP, 102000);
169
170 /* Enable AVP cache, timer, APB dma, and mselect blocks. */
171 clock_enable_clear_reset(CLK_L_CACHE2 | CLK_L_TMR,
172 CLK_H_APBDMA,
173 0, CLK_V_MSELECT, 0, 0, 0);
174
175 /* Find ODMDATA in IRAM and save it to scratch reg */
176 save_odmdata();
177
178 bootblock_mainboard_early_init();
179
180 if (CONFIG_BOOTBLOCK_CONSOLE) {
181 console_init();
182 exception_init();
183 printk(BIOS_INFO, "T210: Bootblock here\n");
184 }
185
186 clock_init();
187
188 printk(BIOS_INFO, "T210 bootblock: Clock init done\n");
189
190 pmc_print_rst_status();
191
Yen Lina501a8f2015-05-06 18:08:22 -0700192
Patrick Georgi40a3e322015-06-22 19:41:29 +0200193 bootblock_mainboard_init();
194
195 printk(BIOS_INFO, "T210 bootblock: Mainboard bootblock init done\n");
196
197 run_romstage();
198}