blob: 760031927f7c58709df83cc851f1d841cf5497d4 [file] [log] [blame]
Michal Simek2e53eb22022-09-19 14:21:02 +02001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2021 - 2022, Xilinx, Inc.
4 * Copyright (C) 2022, Advanced Micro Devices, Inc.
5 *
6 * Michal Simek <michal.simek@amd.com>
7 */
8
9#include <common.h>
10#include <cpu_func.h>
11#include <fdtdec.h>
12#include <init.h>
13#include <log.h>
14#include <malloc.h>
15#include <time.h>
16#include <asm/cache.h>
17#include <asm/global_data.h>
18#include <asm/io.h>
19#include <asm/arch/hardware.h>
20#include <asm/arch/sys_proto.h>
21#include <dm/device.h>
22#include <dm/uclass.h>
23#include "../common/board.h"
24
25#include <linux/bitfield.h>
26#include <debug_uart.h>
27#include <generated/dt.h>
28
29DECLARE_GLOBAL_DATA_PTR;
30
31int board_init(void)
32{
33 printf("EL Level:\tEL%d\n", current_el());
34
35 return 0;
36}
37
38static u32 platform_id, platform_version;
39
40char *soc_name_decode(void)
41{
42 char *name, *platform_name;
43
44 switch (platform_id) {
45 case VERSAL_NET_SPP:
46 platform_name = "ipp";
47 break;
48 case VERSAL_NET_EMU:
49 platform_name = "emu";
50 break;
51 case VERSAL_NET_QEMU:
52 platform_name = "qemu";
53 break;
54 default:
55 return NULL;
56 }
57
58 /*
59 * --rev. are 6 chars
60 * max platform name is qemu which is 4 chars
61 * platform version number are 1+1
62 * Plus 1 char for \n
63 */
64 name = calloc(1, strlen(CONFIG_SYS_BOARD) + 13);
65 if (!name)
66 return NULL;
67
68 sprintf(name, "%s-%s-rev%d.%d", CONFIG_SYS_BOARD,
69 platform_name, platform_version / 10,
70 platform_version % 10);
71
72 return name;
73}
74
75bool soc_detection(void)
76{
77 u32 version;
78
79 version = readl(PMC_TAP_VERSION);
80 platform_id = FIELD_GET(PLATFORM_MASK, version);
81
82 debug("idcode %x, version %x, usercode %x\n",
83 readl(PMC_TAP_IDCODE), version,
84 readl(PMC_TAP_USERCODE));
85
86 debug("pmc_ver %lx, ps version %lx, rtl version %lx\n",
87 FIELD_GET(PMC_VERSION_MASK, version),
88 FIELD_GET(PS_VERSION_MASK, version),
89 FIELD_GET(RTL_VERSION_MASK, version));
90
91 platform_version = FIELD_GET(PLATFORM_VERSION_MASK, version);
92
93 if (platform_id == VERSAL_NET_SPP ||
94 platform_id == VERSAL_NET_EMU) {
95 /*
96 * 9 is diff for
97 * 0 means 0.9 version
98 * 1 means 1.0 version
99 * 2 means 1.1 version
100 * etc,
101 */
102 platform_version += 9;
103 }
104
105 debug("Platform id: %d version: %d.%d\n", platform_id,
106 platform_version / 10, platform_version % 10);
107
108 return true;
109}
110
111int board_early_init_f(void)
112{
113 if (IS_ENABLED(CONFIG_DEBUG_UART)) {
114 /* Uart debug for sure */
115 debug_uart_init();
116 puts("Debug uart enabled\n"); /* or printch() */
117 }
118
119 return 0;
120}
121
122int board_early_init_r(void)
123{
124 return 0;
125}
126
127int board_late_init(void)
128{
129 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
130 debug("Saved variables - Skipping\n");
131 return 0;
132 }
133
134 if (!CONFIG_IS_ENABLED(ENV_VARS_UBOOT_RUNTIME_CONFIG))
135 return 0;
136
137 return board_late_init_xilinx();
138}
139
140int dram_init_banksize(void)
141{
142 int ret;
143
144 ret = fdtdec_setup_memory_banksize();
145 if (ret)
146 return ret;
147
148 mem_map_fill();
149
150 return 0;
151}
152
153int dram_init(void)
154{
155 int ret;
156
157 if (CONFIG_IS_ENABLED(SYS_MEM_RSVD_FOR_MMU))
158 ret = fdtdec_setup_mem_size_base();
159 else
160 ret = fdtdec_setup_mem_size_base_lowest();
161
162 if (ret)
163 return -EINVAL;
164
165 return 0;
166}
167
168void reset_cpu(void)
169{
170}