board: ti: am62x: Account for DDR size fixups if ECC is enabled
[platform/kernel/u-boot.git] / board / ti / am62x / evm.c
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
10 #include <asm/io.h>
11 #include <spl.h>
12 #include <dm/uclass.h>
13 #include <k3-ddrss.h>
14 #include <fdt_support.h>
15 #include <asm/arch/hardware.h>
16 #include <asm/arch/sys_proto.h>
17 #include <env.h>
18
19 DECLARE_GLOBAL_DATA_PTR;
20
21 int board_init(void)
22 {
23         return 0;
24 }
25
26 int dram_init(void)
27 {
28         return fdtdec_setup_mem_size_base();
29 }
30
31 int dram_init_banksize(void)
32 {
33         return fdtdec_setup_memory_banksize();
34 }
35
36 #if defined(CONFIG_SPL_BUILD)
37 #if defined(CONFIG_K3_AM64_DDRSS)
38 static 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
54 static 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
77 void 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