summaryrefslogtreecommitdiff
path: root/src/soc/nvidia/tegra210/bootblock.c
blob: 97ea1c9b08da2ad18722dde12c4ac03f6e6f3b58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
 * This file is part of the coreboot project.
 *
 * Copyright 2014 Google Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <arch/exception.h>
#include <arch/hlt.h>
#include <arch/stages.h>
#include <bootblock_common.h>
#include <console/console.h>
#include <device/mmio.h>
#include <delay.h>
#include <program_loading.h>
#include <soc/addressmap.h>
#include <soc/clock.h>
#include <soc/nvidia/tegra/apbmisc.h>
#include <soc/pmc.h>
#include <soc/power.h>

#define BCT_OFFSET_IN_BIT	0x4c
#define ODMDATA_OFFSET_IN_BCT	0x508
#define TEGRA_SRAM_MAX		(TEGRA_SRAM_BASE + TEGRA_SRAM_SIZE)

static void save_odmdata(void)
{
	struct tegra_pmc_regs *pmc = (struct tegra_pmc_regs*)TEGRA_PMC_BASE;
	uintptr_t bct_offset;
	u32 odmdata;

	// pmc.odmdata: [18:19]: console type, [15:17]: UART id.
	// TODO(twarren) ODMDATA is stored in the BCT, from bct/odmdata.cfg.
	// I use the BCT offset in the BIT in SRAM to locate the BCT, and
	// pick up the ODMDATA word at BCT offset 0x6A8. I could use a BCT
	// struct header from cbootimage, but it seems like overkill for this.

	bct_offset = read32((void *)(TEGRA_SRAM_BASE + BCT_OFFSET_IN_BIT));
	if (bct_offset > TEGRA_SRAM_BASE && bct_offset < TEGRA_SRAM_MAX) {
		odmdata = read32((void *)(bct_offset + ODMDATA_OFFSET_IN_BCT));
		write32(&pmc->odmdata, odmdata);
	}
}

void __weak bootblock_mainboard_early_init(void)
{
	/* Empty default implementation. */
}

/*
 * Define operations for the workaround:
 *   OP_SET : [reg] = val;
 *   OP_OR  : [reg] |= val;
 *   OP_AND : [reg] &= val;
 *   OP_UDELAY : udelay(val);
 */
typedef enum {
	OP_SET,
	OP_OR,
	OP_AND,
	OP_UDELAY,	/* use val field as usec delay */
} WAR_OP;

struct workaround_op {
	WAR_OP	op;
	u32	reg;
	u32	val;
};

/*
 * An array defines the sequence to perform the workaround
 */
static struct workaround_op workaround_sequence[] = {
	{OP_OR,  0x60006410, (1 << 15)},	/* CLK_SOURCE_SOR1: */
	{OP_AND, 0x60006410, ~(1 << 14)},	/*   CLK_SEL1=1, CLK_SEL0=0 */
	{OP_OR,  0x600060d0, 0x40800000},	/* PLLD_BASE */
	{OP_SET, 0x600062ac, 0x40},		/* clear APE reset */
	{OP_SET, 0x60006294, 0x40000},		/* clear VIC reset */
	{OP_SET, 0x60006304, 0x18000000},	/* clear HOST1X & DISP1 reset */
	{OP_UDELAY, 0, 2},
	{OP_OR,  0x702d10a0, 0x400},		/* I2S0: I2S_CTRL.MASTER=1 */
	{OP_AND, 0x702d1088, ~1},		/* I2S0: I2S_CG.SLCG_ENABLE=0 */
	{OP_OR,  0x702d11a0, 0x400},		/* I2S1: I2S_CTRL.MASTER=1 */
	{OP_AND, 0x702d1188, ~1},		/* I2S1: I2S_CG.SLCG_ENABLE=0 */
	{OP_OR,  0x702d12a0, 0x400},		/* I2S2: I2S_CTRL.MASTER=1 */
	{OP_AND, 0x702d1288, ~1},		/* I2S2: I2S_CG.SLCG_ENABLE=0 */
	{OP_OR,  0x702d13a0, 0x400},		/* I2S3: I2S_CTRL.MASTER=1 */
	{OP_AND, 0x702d1388, ~1},		/* I2S3: I2S_CG.SLCG_ENABLE=0 */
	{OP_OR,  0x702d14a0, 0x400},		/* I2S4: I2S_CTRL.MASTER=1 */
	{OP_AND, 0x702d1488, ~1},		/* I2S4: I2S_CG.SLCG_ENABLE=0 */
	{OP_OR,  0x54200cf8, 4},		/* DC_COM_DSC_TOP_CTL[DSC_SLCG_OVERRIDE]=1 */
	{OP_SET, 0x543400c8, 0xffffffff},	/* NV_PVIC_THI_SLCG_OVERRIDE_LOW_A = 0xFFFF_FFFF */
	{OP_UDELAY, 0, 2},
	{OP_SET, 0x600062a8, 0x40},		/* set APE reset */
	{OP_SET, 0x60006300, 0x18000000},	/* set HOST1X & DISP1 reset */
	{OP_SET, 0x60006290, 0x40000},		/* set VIC reset */
	{OP_SET, 0x60006014, 0x020000c1},	/* CLK_ENB_H */
	{OP_SET, 0x60006010, 0x80400130},	/* CLK_ENB_L */
	{OP_SET, 0x60006018, 0x01f00200},	/* CLK_ENB_U */
	{OP_SET, 0x60006360, 0x80400808},	/* CLK_ENB_V */
	{OP_SET, 0x60006364, 0x402000fc},	/* CLK_ENB_W */
	{OP_SET, 0x60006280, 0x23000780},	/* CLK_ENB_X */
	{OP_SET, 0x60006298, 0x00000340},	/* CLK_ENB_Y */
	{OP_SET, 0x600060f8, 0x00000000},	/* LVL2_CLK_GATE_OVRA */
	{OP_SET, 0x600060fc, 0x00000000},	/* LVL2_CLK_GATE_OVRB */
	{OP_SET, 0x600063a0, 0x00000000},	/* LVL2_CLK_GATE_OVRC */
	{OP_SET, 0x600063a4, 0x01000000},	/* LVL2_CLK_GATE_OVRD, QSPI_CLK_OVR_ON=1 */
	{OP_SET, 0x60006554, 0x00000000},	/* LVL2_CLK_GATE_OVRE */
	{OP_AND, 0x600060d0, 0x1f7fffff},	/* PLLD_BASE: 31,30,29,23 = 0 */
	{OP_AND, 0x60006410, 0xffff3fff},	/* CLK_SOURCE_SOR1 15,14 = 0 */
	{OP_AND, 0x60006148, ~(7 << 29)},	/* CLK_SOURCE_VI: */
	{OP_OR,  0x60006148, (4 << 29)},	/*   SRC=PLLP_OUT0 (4) */
	{OP_AND, 0x60006180, ~(7 << 29)},	/* CLK_SOURCE_HOST1X: */
	{OP_OR,  0x60006180, (4 << 29)},	/*   SRC=PLLP_OUT0 (4) */
	{OP_AND, 0x600066a0, ~(7 << 29)},	/* CLK_SOURCE_NVENC: */
	{OP_OR,  0x600066a0, (4 << 29)}		/*   SRC=PLLP_OUT0 (4) */
};

/*
 * This workaround is to restore CAR CE's, SLCG overrides & PLLD settings
 */
static void mbist_workaround(void)
{
	int i;
	u32 val;
	struct workaround_op *wa_op;

	for (i = 0; i < ARRAY_SIZE(workaround_sequence); ++i) {
		wa_op = &workaround_sequence[i];
		switch (wa_op->op) {
		case OP_SET:
			val = wa_op->val;
			break;
		case OP_OR:
			val = read32((void *)wa_op->reg) | wa_op->val;
			break;
		case OP_AND:
			val = read32((void *)wa_op->reg) & wa_op->val;
			break;
		case OP_UDELAY:
			udelay(wa_op->val);
			/* fall thru */
		default:
			continue;
		}
		write32((void *)wa_op->reg, val);
	}
}

void main(void)
{
	// enable JTAG at the earliest stage
	enable_jtag();

	mbist_workaround();

	clock_early_uart();

	/* Configure mselect clock. */
	clock_configure_source(mselect, PLLP, 102000);

	/* Enable AVP cache, timer, APB dma, and mselect blocks.  */
	clock_enable_clear_reset(CLK_L_CACHE2 | CLK_L_TMR,
				 CLK_H_APBDMA,
				 0, CLK_V_MSELECT, 0, 0, 0);

	/* Find ODMDATA in IRAM and save it to scratch reg */
	save_odmdata();

	bootblock_mainboard_early_init();

	if (CONFIG_BOOTBLOCK_CONSOLE) {
		console_init();
		exception_init();
		printk(BIOS_INFO, "T210: Bootblock here\n");
	}

	clock_init();

	printk(BIOS_INFO, "T210 bootblock: Clock init done\n");

	pmc_print_rst_status();


	bootblock_mainboard_init();

	printk(BIOS_INFO, "T210 bootblock: Mainboard bootblock init done\n");

	run_romstage();
}