blob: b037bdfcb3bbbc2cc9450f04eee6f08a96861a51 [file] [log] [blame]
Angel Ponsa2ee7612020-04-04 18:51:15 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Patrick Georgi40a3e322015-06-22 19:41:29 +02002
Ting Shendff29e02019-01-28 18:15:00 +08003#include <bootmem.h>
Aaron Durbinbc98cc62015-09-02 09:21:36 -05004#include <bootmode.h>
Patrick Georgi40a3e322015-06-22 19:41:29 +02005#include <bootstate.h>
Patrick Georgi40a3e322015-06-22 19:41:29 +02006#include <console/console.h>
7#include <device/device.h>
8#include <soc/nvidia/tegra/dc.h>
9#include <soc/addressmap.h>
10#include <soc/clock.h>
11#include <soc/cpu.h>
12#include <soc/mc.h>
Patrick Georgi40a3e322015-06-22 19:41:29 +020013#include <soc/nvidia/tegra/apbmisc.h>
Yen Linae3d71a2015-06-01 15:32:09 -070014#include <soc/sdram.h>
15#include <soc/sdram_configs.h>
Patrick Georgi40a3e322015-06-22 19:41:29 +020016
17#include "chip.h"
18
Ting Shendff29e02019-01-28 18:15:00 +080019void bootmem_platform_add_ranges(void)
20{
21 uintptr_t begin;
22 size_t size;
23 carveout_range(CARVEOUT_TZ, &begin, &size);
24 if (size == 0)
25 return;
26 bootmem_add_range(begin * MiB, size * MiB, BM_MEM_BL31);
27}
28
Elyes HAOUAS3fcb2182018-05-25 10:03:57 +020029static void soc_read_resources(struct device *dev)
Patrick Georgi40a3e322015-06-22 19:41:29 +020030{
31 unsigned long index = 0;
32 int i; uintptr_t begin, end;
33 size_t size;
34
Ting Shendff29e02019-01-28 18:15:00 +080035 for (i = CARVEOUT_TZ + 1; i < CARVEOUT_NUM; i++) {
Patrick Georgi40a3e322015-06-22 19:41:29 +020036 carveout_range(i, &begin, &size);
37 if (size == 0)
38 continue;
Kyösti Mälkki49a8fdf2021-06-26 14:28:42 +030039 reserved_ram_range(dev, index++, begin * MiB, size * MiB);
Patrick Georgi40a3e322015-06-22 19:41:29 +020040 }
41
42 memory_in_range_below_4gb(&begin, &end);
Kyösti Mälkki49a8fdf2021-06-26 14:28:42 +030043 ram_from_to(dev, index++, begin * MiB, end * MiB);
Patrick Georgi40a3e322015-06-22 19:41:29 +020044
45 memory_in_range_above_4gb(&begin, &end);
Kyösti Mälkki49a8fdf2021-06-26 14:28:42 +030046 ram_from_to(dev, index++, begin * MiB, end * MiB);
Patrick Georgi40a3e322015-06-22 19:41:29 +020047}
48
Furquan Shaikhfdb3a8d2015-10-15 15:50:30 -070049static struct device_operations soc_ops = {
50 .read_resources = soc_read_resources,
Nico Huber2f8ba692020-04-05 14:05:24 +020051 .set_resources = noop_set_resources,
Furquan Shaikhfdb3a8d2015-10-15 15:50:30 -070052};
Patrick Georgi40a3e322015-06-22 19:41:29 +020053
Elyes HAOUAS3fcb2182018-05-25 10:03:57 +020054static void enable_tegra210_dev(struct device *dev)
Furquan Shaikhfdb3a8d2015-10-15 15:50:30 -070055{
56 if (dev->path.type == DEVICE_PATH_CPU_CLUSTER)
57 dev->ops = &soc_ops;
Patrick Georgi40a3e322015-06-22 19:41:29 +020058
Julius Wernercd49cce2019-03-05 16:53:33 -080059 if (!CONFIG(MAINBOARD_DO_NATIVE_VGA_INIT))
Aaron Durbinbc98cc62015-09-02 09:21:36 -050060 return;
61
62 if (display_init_required())
Patrick Georgi40a3e322015-06-22 19:41:29 +020063 display_startup(dev);
Aaron Durbinbc98cc62015-09-02 09:21:36 -050064 else
65 printk(BIOS_INFO, "Skipping display init.\n");
Patrick Georgi40a3e322015-06-22 19:41:29 +020066}
67
Patrick Georgi40a3e322015-06-22 19:41:29 +020068static void tegra210_init(void *chip_info)
69{
70 struct tegra_revision rev;
71
72 tegra_revision_info(&rev);
73
74 printk(BIOS_INFO, "chip %x rev %02x.%x\n",
75 rev.chip_id, rev.major, rev.minor);
Yen Linae3d71a2015-06-01 15:32:09 -070076
77 /* Save sdram parameters to scratch regs to be used in LP0 resume */
78 sdram_lp0_save_params(get_sdram_config());
79 printk(BIOS_INFO, "sdram params saved.\n");
Patrick Georgi40a3e322015-06-22 19:41:29 +020080}
81
82struct chip_operations soc_nvidia_tegra210_ops = {
83 CHIP_NAME("SOC Nvidia Tegra210")
84 .init = tegra210_init,
85 .enable_dev = enable_tegra210_dev,
86};
87
Patrick Georgi40a3e322015-06-22 19:41:29 +020088static void enable_plld(void *unused)
89{
90 /*
91 * Configure a conservative 300MHz clock for PLLD. The kernel cannot
92 * handle PLLD not being configured so enable PLLD unconditionally
93 * with a default clock rate.
94 */
95 clock_configure_plld(300 * MHz);
96}
97
98/*
99 * The PLLD being enabled is done at BS_DEV_INIT time because mainboard_init()
100 * is the first thing called. This ensures PLLD is up and functional before
101 * anything that mainboard can do that implicitly relies on PLLD.
102 */
103BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_ENTRY, enable_plld, NULL);