blob: 72b155ca51fe99ae509f507cb35d70a20fd45af8 [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älkki27d62992022-05-24 20:25:58 +030039 reserved_ram_resource_kb(dev, index++, begin * KiB, size * KiB);
Patrick Georgi40a3e322015-06-22 19:41:29 +020040 }
41
42 memory_in_range_below_4gb(&begin, &end);
43 size = end - begin;
Kyösti Mälkki27d62992022-05-24 20:25:58 +030044 ram_resource_kb(dev, index++, begin * KiB, size * KiB);
Patrick Georgi40a3e322015-06-22 19:41:29 +020045
46 memory_in_range_above_4gb(&begin, &end);
47 size = end - begin;
Kyösti Mälkki27d62992022-05-24 20:25:58 +030048 ram_resource_kb(dev, index++, begin * KiB, size * KiB);
Patrick Georgi40a3e322015-06-22 19:41:29 +020049}
50
Furquan Shaikhfdb3a8d2015-10-15 15:50:30 -070051static struct device_operations soc_ops = {
52 .read_resources = soc_read_resources,
Nico Huber2f8ba692020-04-05 14:05:24 +020053 .set_resources = noop_set_resources,
Furquan Shaikhfdb3a8d2015-10-15 15:50:30 -070054};
Patrick Georgi40a3e322015-06-22 19:41:29 +020055
Elyes HAOUAS3fcb2182018-05-25 10:03:57 +020056static void enable_tegra210_dev(struct device *dev)
Furquan Shaikhfdb3a8d2015-10-15 15:50:30 -070057{
58 if (dev->path.type == DEVICE_PATH_CPU_CLUSTER)
59 dev->ops = &soc_ops;
Patrick Georgi40a3e322015-06-22 19:41:29 +020060
Julius Wernercd49cce2019-03-05 16:53:33 -080061 if (!CONFIG(MAINBOARD_DO_NATIVE_VGA_INIT))
Aaron Durbinbc98cc62015-09-02 09:21:36 -050062 return;
63
64 if (display_init_required())
Patrick Georgi40a3e322015-06-22 19:41:29 +020065 display_startup(dev);
Aaron Durbinbc98cc62015-09-02 09:21:36 -050066 else
67 printk(BIOS_INFO, "Skipping display init.\n");
Patrick Georgi40a3e322015-06-22 19:41:29 +020068}
69
Patrick Georgi40a3e322015-06-22 19:41:29 +020070static void tegra210_init(void *chip_info)
71{
72 struct tegra_revision rev;
73
74 tegra_revision_info(&rev);
75
76 printk(BIOS_INFO, "chip %x rev %02x.%x\n",
77 rev.chip_id, rev.major, rev.minor);
Yen Linae3d71a2015-06-01 15:32:09 -070078
79 /* Save sdram parameters to scratch regs to be used in LP0 resume */
80 sdram_lp0_save_params(get_sdram_config());
81 printk(BIOS_INFO, "sdram params saved.\n");
Patrick Georgi40a3e322015-06-22 19:41:29 +020082}
83
84struct chip_operations soc_nvidia_tegra210_ops = {
85 CHIP_NAME("SOC Nvidia Tegra210")
86 .init = tegra210_init,
87 .enable_dev = enable_tegra210_dev,
88};
89
Patrick Georgi40a3e322015-06-22 19:41:29 +020090static void enable_plld(void *unused)
91{
92 /*
93 * Configure a conservative 300MHz clock for PLLD. The kernel cannot
94 * handle PLLD not being configured so enable PLLD unconditionally
95 * with a default clock rate.
96 */
97 clock_configure_plld(300 * MHz);
98}
99
100/*
101 * The PLLD being enabled is done at BS_DEV_INIT time because mainboard_init()
102 * is the first thing called. This ensures PLLD is up and functional before
103 * anything that mainboard can do that implicitly relies on PLLD.
104 */
105BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_ENTRY, enable_plld, NULL);