Suman Anna | 900349b | 2022-05-25 13:38:47 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Board specific initialization for AM62x platforms |
| 4 | * |
| 5 | * Copyright (C) 2020-2022 Texas Instruments Incorporated - https://www.ti.com/ |
| 6 | * Suman Anna <s-anna@ti.com> |
| 7 | * |
| 8 | */ |
| 9 | |
Nikhil M Jain | d5f563c | 2023-01-31 15:35:19 +0530 | [diff] [blame] | 10 | #include <env.h> |
Suman Anna | 900349b | 2022-05-25 13:38:47 +0530 | [diff] [blame] | 11 | #include <spl.h> |
Nikhil M Jain | 7223630 | 2023-04-10 14:19:12 +0530 | [diff] [blame^] | 12 | #include <init.h> |
Nikhil M Jain | d5f563c | 2023-01-31 15:35:19 +0530 | [diff] [blame] | 13 | #include <video.h> |
| 14 | #include <splash.h> |
Georgi Vlaev | 4c092bb | 2022-06-14 17:45:33 +0300 | [diff] [blame] | 15 | #include <k3-ddrss.h> |
Suman Anna | 900349b | 2022-05-25 13:38:47 +0530 | [diff] [blame] | 16 | #include <fdt_support.h> |
Nikhil M Jain | d5f563c | 2023-01-31 15:35:19 +0530 | [diff] [blame] | 17 | #include <asm/io.h> |
Suman Anna | 900349b | 2022-05-25 13:38:47 +0530 | [diff] [blame] | 18 | #include <asm/arch/hardware.h> |
Nikhil M Jain | d5f563c | 2023-01-31 15:35:19 +0530 | [diff] [blame] | 19 | #include <dm/uclass.h> |
Suman Anna | 900349b | 2022-05-25 13:38:47 +0530 | [diff] [blame] | 20 | |
| 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
Nikhil M Jain | 53ae978 | 2023-04-20 17:41:11 +0530 | [diff] [blame] | 23 | #if CONFIG_IS_ENABLED(SPLASH_SCREEN) |
Nikhil M Jain | d5f563c | 2023-01-31 15:35:19 +0530 | [diff] [blame] | 24 | static struct splash_location default_splash_locations[] = { |
| 25 | { |
Nikhil M Jain | 53ae978 | 2023-04-20 17:41:11 +0530 | [diff] [blame] | 26 | .name = "sf", |
| 27 | .storage = SPLASH_STORAGE_SF, |
| 28 | .flags = SPLASH_STORAGE_RAW, |
| 29 | .offset = 0x700000, |
| 30 | }, |
| 31 | { |
Nikhil M Jain | d5f563c | 2023-01-31 15:35:19 +0530 | [diff] [blame] | 32 | .name = "mmc", |
| 33 | .storage = SPLASH_STORAGE_MMC, |
| 34 | .flags = SPLASH_STORAGE_FS, |
| 35 | .devpart = "1:1", |
| 36 | }, |
| 37 | }; |
| 38 | |
| 39 | int splash_screen_prepare(void) |
| 40 | { |
| 41 | return splash_source_load(default_splash_locations, |
| 42 | ARRAY_SIZE(default_splash_locations)); |
| 43 | } |
| 44 | #endif |
| 45 | |
Suman Anna | 900349b | 2022-05-25 13:38:47 +0530 | [diff] [blame] | 46 | int board_init(void) |
| 47 | { |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | int dram_init(void) |
| 52 | { |
Georgi Vlaev | 249e9f3 | 2022-06-14 17:45:32 +0300 | [diff] [blame] | 53 | return fdtdec_setup_mem_size_base(); |
Suman Anna | 900349b | 2022-05-25 13:38:47 +0530 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | int dram_init_banksize(void) |
| 57 | { |
Georgi Vlaev | 249e9f3 | 2022-06-14 17:45:32 +0300 | [diff] [blame] | 58 | return fdtdec_setup_memory_banksize(); |
Suman Anna | 900349b | 2022-05-25 13:38:47 +0530 | [diff] [blame] | 59 | } |
Georgi Vlaev | 4c092bb | 2022-06-14 17:45:33 +0300 | [diff] [blame] | 60 | |
| 61 | #if defined(CONFIG_SPL_BUILD) |
Nikhil M Jain | 7223630 | 2023-04-10 14:19:12 +0530 | [diff] [blame^] | 62 | #ifdef CONFIG_SPL_VIDEO_TIDSS |
| 63 | static int setup_dram(void) |
| 64 | { |
| 65 | dram_init(); |
| 66 | dram_init_banksize(); |
| 67 | gd->ram_base = CFG_SYS_SDRAM_BASE; |
| 68 | gd->ram_top = gd->ram_base + gd->ram_size; |
| 69 | gd->relocaddr = gd->ram_top; |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | static int video_setup(void) |
| 74 | { |
| 75 | ulong addr; |
| 76 | int ret; |
| 77 | addr = gd->relocaddr; |
| 78 | |
| 79 | ret = video_reserve(&addr); |
| 80 | if (ret) |
| 81 | return ret; |
| 82 | debug("Reserving %luk for video at: %08lx\n", |
| 83 | ((unsigned long)gd->relocaddr - addr) >> 10, addr); |
| 84 | gd->relocaddr = addr; |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | #endif |
| 89 | void spl_board_init(void) |
| 90 | { |
| 91 | #if defined(CONFIG_SPL_VIDEO_TIDSS) |
| 92 | setup_dram(); |
| 93 | arch_reserve_mmu(); |
| 94 | video_setup(); |
| 95 | enable_caches(); |
| 96 | splash_display(); |
| 97 | #endif |
| 98 | } |
| 99 | |
Georgi Vlaev | 4c092bb | 2022-06-14 17:45:33 +0300 | [diff] [blame] | 100 | #if defined(CONFIG_K3_AM64_DDRSS) |
| 101 | static void fixup_ddr_driver_for_ecc(struct spl_image_info *spl_image) |
| 102 | { |
| 103 | struct udevice *dev; |
| 104 | int ret; |
| 105 | |
| 106 | dram_init_banksize(); |
| 107 | |
| 108 | ret = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 109 | if (ret) |
| 110 | panic("Cannot get RAM device for ddr size fixup: %d\n", ret); |
| 111 | |
| 112 | ret = k3_ddrss_ddr_fdt_fixup(dev, spl_image->fdt_addr, gd->bd); |
| 113 | if (ret) |
| 114 | printf("Error fixing up ddr node for ECC use! %d\n", ret); |
| 115 | } |
| 116 | #else |
| 117 | static void fixup_memory_node(struct spl_image_info *spl_image) |
| 118 | { |
| 119 | u64 start[CONFIG_NR_DRAM_BANKS]; |
| 120 | u64 size[CONFIG_NR_DRAM_BANKS]; |
| 121 | int bank; |
| 122 | int ret; |
| 123 | |
| 124 | dram_init(); |
| 125 | dram_init_banksize(); |
| 126 | |
| 127 | for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) { |
| 128 | start[bank] = gd->bd->bi_dram[bank].start; |
| 129 | size[bank] = gd->bd->bi_dram[bank].size; |
| 130 | } |
| 131 | |
| 132 | /* dram_init functions use SPL fdt, and we must fixup u-boot fdt */ |
| 133 | ret = fdt_fixup_memory_banks(spl_image->fdt_addr, start, size, |
| 134 | CONFIG_NR_DRAM_BANKS); |
| 135 | if (ret) |
| 136 | printf("Error fixing up memory node! %d\n", ret); |
| 137 | } |
| 138 | #endif |
| 139 | |
| 140 | void spl_perform_fixups(struct spl_image_info *spl_image) |
| 141 | { |
| 142 | #if defined(CONFIG_K3_AM64_DDRSS) |
| 143 | fixup_ddr_driver_for_ecc(spl_image); |
| 144 | #else |
| 145 | fixup_memory_node(spl_image); |
| 146 | #endif |
| 147 | } |
| 148 | #endif |