blob: f3290c3ac616fcf41a6722fee83e824bb506c874 [file] [log] [blame]
Patrick Georgi40a3e322015-06-22 19:41:29 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved.
5 * Copyright 2014 Google Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.
19 */
20
21#include <arch/io.h>
22#include <arch/cache.h>
23#include <arch/spintable.h>
24#include <cpu/cpu.h>
25#include <bootstate.h>
26#include <cbmem.h>
27#include <console/console.h>
28#include <device/device.h>
29#include <soc/nvidia/tegra/dc.h>
30#include <soc/addressmap.h>
31#include <soc/clock.h>
32#include <soc/cpu.h>
33#include <soc/mc.h>
34#include <soc/mtc.h>
35#include <soc/nvidia/tegra/apbmisc.h>
36#include <string.h>
37#include <timer.h>
38#include <vendorcode/google/chromeos/chromeos.h>
39
40#include "chip.h"
41
42static void soc_read_resources(device_t dev)
43{
44 unsigned long index = 0;
45 int i; uintptr_t begin, end;
46 size_t size;
47
48 for (i = 0; i < CARVEOUT_NUM; i++) {
49 carveout_range(i, &begin, &size);
50 if (size == 0)
51 continue;
52 reserved_ram_resource(dev, index++, begin * KiB, size * KiB);
53 }
54
55 memory_in_range_below_4gb(&begin, &end);
56 size = end - begin;
57 ram_resource(dev, index++, begin * KiB, size * KiB);
58
59 memory_in_range_above_4gb(&begin, &end);
60 size = end - begin;
61 ram_resource(dev, index++, begin * KiB, size * KiB);
62}
63
64static size_t cntrl_total_cpus(void)
65{
66 return CONFIG_MAX_CPUS;
67}
68
69static int cntrl_start_cpu(unsigned int id, void (*entry)(void))
70{
71 if (id >= CONFIG_MAX_CPUS)
72 return -1;
73 start_cpu(id, entry);
74 return 0;
75}
76
77static struct cpu_control_ops cntrl_ops = {
78 .total_cpus = cntrl_total_cpus,
79 .start_cpu = cntrl_start_cpu,
80};
81
82
83static void lock_down_vpr(void)
84{
85 struct tegra_mc_regs *regs = (void *)(uintptr_t)TEGRA_MC_BASE;
86
87 write32(&regs->video_protect_bom, 0);
88 write32(&regs->video_protect_size_mb, 0);
89
90 write32(&regs->video_protect_gpu_override_0, 1);
91 /*
92 * Set both _ACCESS bits so that kernel/secure code
93 * can reconfig VPR careveout as needed from the TrustZone.
94 */
95
96 write32(&regs->video_protect_reg_ctrl,
97 (MC_VPR_WR_ACCESS_DISABLE | MC_VPR_ALLOW_TZ_WR_ACCESS_ENABLE));
98}
99
100static void soc_init(device_t dev)
101{
102 struct soc_nvidia_tegra210_config *cfg;
103
104 clock_init_arm_generic_timer();
105
106 cfg = dev->chip_info;
107 spintable_init((void *)cfg->spintable_addr);
108 arch_initialize_cpus(dev, &cntrl_ops);
109
110 /* Lock down VPR */
111 lock_down_vpr();
112
113#if IS_ENABLED(CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT)
114 if (vboot_skip_display_init())
115 printk(BIOS_INFO, "Skipping display init.\n");
116 else
117 display_startup(dev);
118#endif
119}
120
121static void soc_noop(device_t dev)
122{
123}
124
125static struct device_operations soc_ops = {
126 .read_resources = soc_read_resources,
127 .set_resources = soc_noop,
128 .enable_resources = soc_noop,
129 .init = soc_init,
130 .scan_bus = NULL,
131};
132
133static void enable_tegra210_dev(device_t dev)
134{
135 if (dev->path.type == DEVICE_PATH_CPU_CLUSTER)
136 dev->ops = &soc_ops;
137}
138
139static void tegra210_init(void *chip_info)
140{
141 struct tegra_revision rev;
142
143 tegra_revision_info(&rev);
144
145 printk(BIOS_INFO, "chip %x rev %02x.%x\n",
146 rev.chip_id, rev.major, rev.minor);
147}
148
149struct chip_operations soc_nvidia_tegra210_ops = {
150 CHIP_NAME("SOC Nvidia Tegra210")
151 .init = tegra210_init,
152 .enable_dev = enable_tegra210_dev,
153};
154
155static void tegra210_cpu_init(device_t cpu)
156{
157 if (cpu_is_bsp())
158 if (tegra210_run_mtc() != 0)
159 printk(BIOS_ERR, "MTC: Training failed\n");
160}
161
162static const struct cpu_device_id ids[] = {
163 { 0x411fd071 },
164 { CPU_ID_END },
165};
166
167static struct device_operations cpu_dev_ops = {
168 .init = tegra210_cpu_init,
169};
170
171static const struct cpu_driver driver __cpu_driver = {
172 .ops = &cpu_dev_ops,
173 .id_table = ids,
174};
175
176static void enable_plld(void *unused)
177{
178 /*
179 * Configure a conservative 300MHz clock for PLLD. The kernel cannot
180 * handle PLLD not being configured so enable PLLD unconditionally
181 * with a default clock rate.
182 */
183 clock_configure_plld(300 * MHz);
184}
185
186/*
187 * The PLLD being enabled is done at BS_DEV_INIT time because mainboard_init()
188 * is the first thing called. This ensures PLLD is up and functional before
189 * anything that mainboard can do that implicitly relies on PLLD.
190 */
191BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_ENTRY, enable_plld, NULL);