blob: d65ee1d69606d35decfa24a2ed84c1916ff5e9d5 [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
10#include <asm/io.h>
11#include <spl.h>
Georgi Vlaev18c0fbf2022-06-14 17:45:33 +030012#include <dm/uclass.h>
13#include <k3-ddrss.h>
Suman Anna3b431102022-05-25 13:38:47 +053014#include <fdt_support.h>
15#include <asm/arch/hardware.h>
16#include <asm/arch/sys_proto.h>
17#include <env.h>
18
19DECLARE_GLOBAL_DATA_PTR;
20
21int board_init(void)
22{
23 return 0;
24}
25
26int dram_init(void)
27{
Georgi Vlaev8a9ceb42022-06-14 17:45:32 +030028 return fdtdec_setup_mem_size_base();
Suman Anna3b431102022-05-25 13:38:47 +053029}
30
31int dram_init_banksize(void)
32{
Georgi Vlaev8a9ceb42022-06-14 17:45:32 +030033 return fdtdec_setup_memory_banksize();
Suman Anna3b431102022-05-25 13:38:47 +053034}
Georgi Vlaev18c0fbf2022-06-14 17:45:33 +030035
36#if defined(CONFIG_SPL_BUILD)
37#if defined(CONFIG_K3_AM64_DDRSS)
38static void fixup_ddr_driver_for_ecc(struct spl_image_info *spl_image)
39{
40 struct udevice *dev;
41 int ret;
42
43 dram_init_banksize();
44
45 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
46 if (ret)
47 panic("Cannot get RAM device for ddr size fixup: %d\n", ret);
48
49 ret = k3_ddrss_ddr_fdt_fixup(dev, spl_image->fdt_addr, gd->bd);
50 if (ret)
51 printf("Error fixing up ddr node for ECC use! %d\n", ret);
52}
53#else
54static void fixup_memory_node(struct spl_image_info *spl_image)
55{
56 u64 start[CONFIG_NR_DRAM_BANKS];
57 u64 size[CONFIG_NR_DRAM_BANKS];
58 int bank;
59 int ret;
60
61 dram_init();
62 dram_init_banksize();
63
64 for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
65 start[bank] = gd->bd->bi_dram[bank].start;
66 size[bank] = gd->bd->bi_dram[bank].size;
67 }
68
69 /* dram_init functions use SPL fdt, and we must fixup u-boot fdt */
70 ret = fdt_fixup_memory_banks(spl_image->fdt_addr, start, size,
71 CONFIG_NR_DRAM_BANKS);
72 if (ret)
73 printf("Error fixing up memory node! %d\n", ret);
74}
75#endif
76
77void spl_perform_fixups(struct spl_image_info *spl_image)
78{
79#if defined(CONFIG_K3_AM64_DDRSS)
80 fixup_ddr_driver_for_ecc(spl_image);
81#else
82 fixup_memory_node(spl_image);
83#endif
84}
85#endif