blob: 981b09c8a236449d10eb6e7275e7d3fc7f511a7b [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>
Aaron Durbinbc98cc62015-09-02 09:21:36 -050025#include <bootmode.h>
Patrick Georgi40a3e322015-06-22 19:41:29 +020026#include <bootstate.h>
27#include <cbmem.h>
28#include <console/console.h>
29#include <device/device.h>
30#include <soc/nvidia/tegra/dc.h>
31#include <soc/addressmap.h>
32#include <soc/clock.h>
33#include <soc/cpu.h>
34#include <soc/mc.h>
35#include <soc/mtc.h>
36#include <soc/nvidia/tegra/apbmisc.h>
37#include <string.h>
38#include <timer.h>
Yen Linae3d71a2015-06-01 15:32:09 -070039#include <soc/sdram.h>
40#include <soc/sdram_configs.h>
Patrick Georgi40a3e322015-06-22 19:41:29 +020041
42#include "chip.h"
43
44static void soc_read_resources(device_t dev)
45{
46 unsigned long index = 0;
47 int i; uintptr_t begin, end;
48 size_t size;
49
50 for (i = 0; i < CARVEOUT_NUM; i++) {
51 carveout_range(i, &begin, &size);
52 if (size == 0)
53 continue;
54 reserved_ram_resource(dev, index++, begin * KiB, size * KiB);
55 }
56
57 memory_in_range_below_4gb(&begin, &end);
58 size = end - begin;
59 ram_resource(dev, index++, begin * KiB, size * KiB);
60
61 memory_in_range_above_4gb(&begin, &end);
62 size = end - begin;
63 ram_resource(dev, index++, begin * KiB, size * KiB);
64}
65
66static size_t cntrl_total_cpus(void)
67{
68 return CONFIG_MAX_CPUS;
69}
70
71static int cntrl_start_cpu(unsigned int id, void (*entry)(void))
72{
73 if (id >= CONFIG_MAX_CPUS)
74 return -1;
75 start_cpu(id, entry);
76 return 0;
77}
78
79static struct cpu_control_ops cntrl_ops = {
80 .total_cpus = cntrl_total_cpus,
81 .start_cpu = cntrl_start_cpu,
82};
83
84
Patrick Georgi40a3e322015-06-22 19:41:29 +020085static void soc_init(device_t dev)
86{
87 struct soc_nvidia_tegra210_config *cfg;
88
89 clock_init_arm_generic_timer();
90
91 cfg = dev->chip_info;
92 spintable_init((void *)cfg->spintable_addr);
93 arch_initialize_cpus(dev, &cntrl_ops);
94
Aaron Durbinbc98cc62015-09-02 09:21:36 -050095 if (!IS_ENABLED(CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT))
96 return;
97
98 if (display_init_required())
Patrick Georgi40a3e322015-06-22 19:41:29 +020099 display_startup(dev);
Aaron Durbinbc98cc62015-09-02 09:21:36 -0500100 else
101 printk(BIOS_INFO, "Skipping display init.\n");
Patrick Georgi40a3e322015-06-22 19:41:29 +0200102}
103
104static void soc_noop(device_t dev)
105{
106}
107
108static struct device_operations soc_ops = {
109 .read_resources = soc_read_resources,
110 .set_resources = soc_noop,
111 .enable_resources = soc_noop,
112 .init = soc_init,
113 .scan_bus = NULL,
114};
115
116static void enable_tegra210_dev(device_t dev)
117{
118 if (dev->path.type == DEVICE_PATH_CPU_CLUSTER)
119 dev->ops = &soc_ops;
120}
121
122static void tegra210_init(void *chip_info)
123{
124 struct tegra_revision rev;
125
126 tegra_revision_info(&rev);
127
128 printk(BIOS_INFO, "chip %x rev %02x.%x\n",
129 rev.chip_id, rev.major, rev.minor);
Yen Linae3d71a2015-06-01 15:32:09 -0700130
131 /* Save sdram parameters to scratch regs to be used in LP0 resume */
132 sdram_lp0_save_params(get_sdram_config());
133 printk(BIOS_INFO, "sdram params saved.\n");
Patrick Georgi40a3e322015-06-22 19:41:29 +0200134}
135
136struct chip_operations soc_nvidia_tegra210_ops = {
137 CHIP_NAME("SOC Nvidia Tegra210")
138 .init = tegra210_init,
139 .enable_dev = enable_tegra210_dev,
140};
141
142static void tegra210_cpu_init(device_t cpu)
143{
144 if (cpu_is_bsp())
145 if (tegra210_run_mtc() != 0)
Furquan Shaikh5bcf8d62015-06-16 13:02:40 -0700146 printk(BIOS_ERR, "MTC: No training data.\n");
Patrick Georgi40a3e322015-06-22 19:41:29 +0200147}
148
149static const struct cpu_device_id ids[] = {
150 { 0x411fd071 },
151 { CPU_ID_END },
152};
153
154static struct device_operations cpu_dev_ops = {
155 .init = tegra210_cpu_init,
156};
157
158static const struct cpu_driver driver __cpu_driver = {
159 .ops = &cpu_dev_ops,
160 .id_table = ids,
161};
162
163static void enable_plld(void *unused)
164{
165 /*
166 * Configure a conservative 300MHz clock for PLLD. The kernel cannot
167 * handle PLLD not being configured so enable PLLD unconditionally
168 * with a default clock rate.
169 */
170 clock_configure_plld(300 * MHz);
171}
172
173/*
174 * The PLLD being enabled is done at BS_DEV_INIT time because mainboard_init()
175 * is the first thing called. This ensures PLLD is up and functional before
176 * anything that mainboard can do that implicitly relies on PLLD.
177 */
178BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_ENTRY, enable_plld, NULL);