blob: 34830f445f7bb14809592d75aa5c7a2b37707228 [file] [log] [blame]
Suman Anna900349b2022-05-25 13:38:47 +05301// 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 Jaind5f563c2023-01-31 15:35:19 +053010#include <env.h>
Suman Anna900349b2022-05-25 13:38:47 +053011#include <spl.h>
Nikhil M Jain72236302023-04-10 14:19:12 +053012#include <init.h>
Nikhil M Jaind5f563c2023-01-31 15:35:19 +053013#include <video.h>
14#include <splash.h>
Georgi Vlaev4c092bb2022-06-14 17:45:33 +030015#include <k3-ddrss.h>
Suman Anna900349b2022-05-25 13:38:47 +053016#include <fdt_support.h>
Nikhil M Jaind5f563c2023-01-31 15:35:19 +053017#include <asm/io.h>
Suman Anna900349b2022-05-25 13:38:47 +053018#include <asm/arch/hardware.h>
Nikhil M Jaind5f563c2023-01-31 15:35:19 +053019#include <dm/uclass.h>
Suman Anna900349b2022-05-25 13:38:47 +053020
21DECLARE_GLOBAL_DATA_PTR;
22
Nikhil M Jain53ae9782023-04-20 17:41:11 +053023#if CONFIG_IS_ENABLED(SPLASH_SCREEN)
Nikhil M Jaind5f563c2023-01-31 15:35:19 +053024static struct splash_location default_splash_locations[] = {
25 {
Nikhil M Jain53ae9782023-04-20 17:41:11 +053026 .name = "sf",
27 .storage = SPLASH_STORAGE_SF,
28 .flags = SPLASH_STORAGE_RAW,
29 .offset = 0x700000,
30 },
31 {
Nikhil M Jaind5f563c2023-01-31 15:35:19 +053032 .name = "mmc",
33 .storage = SPLASH_STORAGE_MMC,
34 .flags = SPLASH_STORAGE_FS,
35 .devpart = "1:1",
36 },
37};
38
39int splash_screen_prepare(void)
40{
41 return splash_source_load(default_splash_locations,
42 ARRAY_SIZE(default_splash_locations));
43}
44#endif
45
Suman Anna900349b2022-05-25 13:38:47 +053046int board_init(void)
47{
48 return 0;
49}
50
51int dram_init(void)
52{
Georgi Vlaev249e9f32022-06-14 17:45:32 +030053 return fdtdec_setup_mem_size_base();
Suman Anna900349b2022-05-25 13:38:47 +053054}
55
56int dram_init_banksize(void)
57{
Georgi Vlaev249e9f32022-06-14 17:45:32 +030058 return fdtdec_setup_memory_banksize();
Suman Anna900349b2022-05-25 13:38:47 +053059}
Georgi Vlaev4c092bb2022-06-14 17:45:33 +030060
61#if defined(CONFIG_SPL_BUILD)
Nikhil M Jain72236302023-04-10 14:19:12 +053062#ifdef CONFIG_SPL_VIDEO_TIDSS
63static 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
73static 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
89void 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 Vlaev4c092bb2022-06-14 17:45:33 +0300100#if defined(CONFIG_K3_AM64_DDRSS)
101static 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
117static 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
140void 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