Angel Pons | a2ee761 | 2020-04-04 18:51:15 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 2 | |
Ting Shen | dff29e0 | 2019-01-28 18:15:00 +0800 | [diff] [blame] | 3 | #include <bootmem.h> |
Aaron Durbin | bc98cc6 | 2015-09-02 09:21:36 -0500 | [diff] [blame] | 4 | #include <bootmode.h> |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 5 | #include <bootstate.h> |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 6 | #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 Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 13 | #include <soc/nvidia/tegra/apbmisc.h> |
Yen Lin | ae3d71a | 2015-06-01 15:32:09 -0700 | [diff] [blame] | 14 | #include <soc/sdram.h> |
| 15 | #include <soc/sdram_configs.h> |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 16 | |
| 17 | #include "chip.h" |
| 18 | |
Ting Shen | dff29e0 | 2019-01-28 18:15:00 +0800 | [diff] [blame] | 19 | void 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 HAOUAS | 3fcb218 | 2018-05-25 10:03:57 +0200 | [diff] [blame] | 29 | static void soc_read_resources(struct device *dev) |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 30 | { |
| 31 | unsigned long index = 0; |
| 32 | int i; uintptr_t begin, end; |
| 33 | size_t size; |
| 34 | |
Ting Shen | dff29e0 | 2019-01-28 18:15:00 +0800 | [diff] [blame] | 35 | for (i = CARVEOUT_TZ + 1; i < CARVEOUT_NUM; i++) { |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 36 | carveout_range(i, &begin, &size); |
| 37 | if (size == 0) |
| 38 | continue; |
Kyösti Mälkki | 49a8fdf | 2021-06-26 14:28:42 +0300 | [diff] [blame^] | 39 | reserved_ram_range(dev, index++, begin * MiB, size * MiB); |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | memory_in_range_below_4gb(&begin, &end); |
Kyösti Mälkki | 49a8fdf | 2021-06-26 14:28:42 +0300 | [diff] [blame^] | 43 | ram_from_to(dev, index++, begin * MiB, end * MiB); |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 44 | |
| 45 | memory_in_range_above_4gb(&begin, &end); |
Kyösti Mälkki | 49a8fdf | 2021-06-26 14:28:42 +0300 | [diff] [blame^] | 46 | ram_from_to(dev, index++, begin * MiB, end * MiB); |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 47 | } |
| 48 | |
Furquan Shaikh | fdb3a8d | 2015-10-15 15:50:30 -0700 | [diff] [blame] | 49 | static struct device_operations soc_ops = { |
| 50 | .read_resources = soc_read_resources, |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 51 | .set_resources = noop_set_resources, |
Furquan Shaikh | fdb3a8d | 2015-10-15 15:50:30 -0700 | [diff] [blame] | 52 | }; |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 53 | |
Elyes HAOUAS | 3fcb218 | 2018-05-25 10:03:57 +0200 | [diff] [blame] | 54 | static void enable_tegra210_dev(struct device *dev) |
Furquan Shaikh | fdb3a8d | 2015-10-15 15:50:30 -0700 | [diff] [blame] | 55 | { |
| 56 | if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) |
| 57 | dev->ops = &soc_ops; |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 58 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 59 | if (!CONFIG(MAINBOARD_DO_NATIVE_VGA_INIT)) |
Aaron Durbin | bc98cc6 | 2015-09-02 09:21:36 -0500 | [diff] [blame] | 60 | return; |
| 61 | |
| 62 | if (display_init_required()) |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 63 | display_startup(dev); |
Aaron Durbin | bc98cc6 | 2015-09-02 09:21:36 -0500 | [diff] [blame] | 64 | else |
| 65 | printk(BIOS_INFO, "Skipping display init.\n"); |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 66 | } |
| 67 | |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 68 | static 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 Lin | ae3d71a | 2015-06-01 15:32:09 -0700 | [diff] [blame] | 76 | |
| 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 Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | struct 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 Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 88 | static 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 | */ |
| 103 | BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_ENTRY, enable_plld, NULL); |