blob: f7afd4f3785a87169f29f483756055f3774b6478 [file] [log] [blame]
Suman Anna3b431102022-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 Jain155a0822023-01-31 15:35:19 +053010#include <env.h>
Suman Anna3b431102022-05-25 13:38:47 +053011#include <spl.h>
Nikhil M Jain57a531b2023-04-10 14:19:12 +053012#include <init.h>
Nikhil M Jain155a0822023-01-31 15:35:19 +053013#include <video.h>
14#include <splash.h>
Nikhil M Jain3ad584b2023-06-21 16:29:52 +053015#include <cpu_func.h>
Georgi Vlaev18c0fbf2022-06-14 17:45:33 +030016#include <k3-ddrss.h>
Suman Anna3b431102022-05-25 13:38:47 +053017#include <fdt_support.h>
Nikhil M Jain155a0822023-01-31 15:35:19 +053018#include <asm/io.h>
Suman Anna3b431102022-05-25 13:38:47 +053019#include <asm/arch/hardware.h>
Nikhil M Jain155a0822023-01-31 15:35:19 +053020#include <dm/uclass.h>
Suman Anna3b431102022-05-25 13:38:47 +053021
22DECLARE_GLOBAL_DATA_PTR;
23
Nikhil M Jain1ff64a22023-04-20 17:41:11 +053024#if CONFIG_IS_ENABLED(SPLASH_SCREEN)
Nikhil M Jain155a0822023-01-31 15:35:19 +053025static struct splash_location default_splash_locations[] = {
26 {
Nikhil M Jain1ff64a22023-04-20 17:41:11 +053027 .name = "sf",
28 .storage = SPLASH_STORAGE_SF,
29 .flags = SPLASH_STORAGE_RAW,
30 .offset = 0x700000,
31 },
32 {
Nikhil M Jain155a0822023-01-31 15:35:19 +053033 .name = "mmc",
34 .storage = SPLASH_STORAGE_MMC,
35 .flags = SPLASH_STORAGE_FS,
36 .devpart = "1:1",
37 },
38};
39
40int splash_screen_prepare(void)
41{
42 return splash_source_load(default_splash_locations,
43 ARRAY_SIZE(default_splash_locations));
44}
45#endif
46
Suman Anna3b431102022-05-25 13:38:47 +053047int board_init(void)
48{
49 return 0;
50}
51
52int dram_init(void)
53{
Georgi Vlaev8a9ceb42022-06-14 17:45:32 +030054 return fdtdec_setup_mem_size_base();
Suman Anna3b431102022-05-25 13:38:47 +053055}
56
57int dram_init_banksize(void)
58{
Georgi Vlaev8a9ceb42022-06-14 17:45:32 +030059 return fdtdec_setup_memory_banksize();
Suman Anna3b431102022-05-25 13:38:47 +053060}
Georgi Vlaev18c0fbf2022-06-14 17:45:33 +030061
62#if defined(CONFIG_SPL_BUILD)
Nikhil M Jain57a531b2023-04-10 14:19:12 +053063#ifdef CONFIG_SPL_VIDEO_TIDSS
64static int setup_dram(void)
65{
66 dram_init();
67 dram_init_banksize();
68 gd->ram_base = CFG_SYS_SDRAM_BASE;
69 gd->ram_top = gd->ram_base + gd->ram_size;
70 gd->relocaddr = gd->ram_top;
71 return 0;
72}
73
74static int video_setup(void)
75{
76 ulong addr;
77 int ret;
78 addr = gd->relocaddr;
79
80 ret = video_reserve(&addr);
81 if (ret)
82 return ret;
83 debug("Reserving %luk for video at: %08lx\n",
84 ((unsigned long)gd->relocaddr - addr) >> 10, addr);
85 gd->relocaddr = addr;
86 return 0;
87}
88
89#endif
90void spl_board_init(void)
91{
92#if defined(CONFIG_SPL_VIDEO_TIDSS)
93 setup_dram();
94 arch_reserve_mmu();
95 video_setup();
96 enable_caches();
97 splash_display();
98#endif
99}
100
Georgi Vlaev18c0fbf2022-06-14 17:45:33 +0300101#if defined(CONFIG_K3_AM64_DDRSS)
102static void fixup_ddr_driver_for_ecc(struct spl_image_info *spl_image)
103{
104 struct udevice *dev;
105 int ret;
106
107 dram_init_banksize();
108
109 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
110 if (ret)
111 panic("Cannot get RAM device for ddr size fixup: %d\n", ret);
112
113 ret = k3_ddrss_ddr_fdt_fixup(dev, spl_image->fdt_addr, gd->bd);
114 if (ret)
115 printf("Error fixing up ddr node for ECC use! %d\n", ret);
116}
117#else
118static void fixup_memory_node(struct spl_image_info *spl_image)
119{
120 u64 start[CONFIG_NR_DRAM_BANKS];
121 u64 size[CONFIG_NR_DRAM_BANKS];
122 int bank;
123 int ret;
124
125 dram_init();
126 dram_init_banksize();
127
128 for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
129 start[bank] = gd->bd->bi_dram[bank].start;
130 size[bank] = gd->bd->bi_dram[bank].size;
131 }
132
133 /* dram_init functions use SPL fdt, and we must fixup u-boot fdt */
134 ret = fdt_fixup_memory_banks(spl_image->fdt_addr, start, size,
135 CONFIG_NR_DRAM_BANKS);
136 if (ret)
137 printf("Error fixing up memory node! %d\n", ret);
138}
139#endif
140
141void spl_perform_fixups(struct spl_image_info *spl_image)
142{
143#if defined(CONFIG_K3_AM64_DDRSS)
144 fixup_ddr_driver_for_ecc(spl_image);
145#else
146 fixup_memory_node(spl_image);
147#endif
148}
149#endif