blob: 24cff0c3706a4954b52ed14cab65c278aaf92bdf [file] [log] [blame]
Michal Simekec48b6c2018-08-22 14:55:27 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2014 - 2018 Xilinx, Inc.
4 * Michal Simek <michal.simek@xilinx.com>
5 */
6
7#include <common.h>
Simon Glass9a3b4ce2019-12-28 10:45:01 -07008#include <cpu_func.h>
Michal Simekec48b6c2018-08-22 14:55:27 +02009#include <fdtdec.h>
Simon Glass52559322019-11-14 12:57:46 -070010#include <init.h>
Michal Simekec48b6c2018-08-22 14:55:27 +020011#include <malloc.h>
Simon Glass10453152019-11-14 12:57:30 -070012#include <time.h>
Simon Glass90526e92020-05-10 11:39:56 -060013#include <asm/cache.h>
Michal Simekec48b6c2018-08-22 14:55:27 +020014#include <asm/io.h>
15#include <asm/arch/hardware.h>
Michal Simekaef149e2019-04-29 09:39:09 -070016#include <asm/arch/sys_proto.h>
Siva Durga Prasad Paladugubfd092f2019-01-31 17:28:14 +053017#include <dm/device.h>
18#include <dm/uclass.h>
Siva Durga Prasad Paladugu26e054c2019-08-05 15:54:59 +053019#include <versalpl.h>
Michal Simek80fdef12020-03-31 12:39:37 +020020#include "../common/board.h"
Michal Simekec48b6c2018-08-22 14:55:27 +020021
22DECLARE_GLOBAL_DATA_PTR;
23
Siva Durga Prasad Paladugu26e054c2019-08-05 15:54:59 +053024#if defined(CONFIG_FPGA_VERSALPL)
25static xilinx_desc versalpl = XILINX_VERSAL_DESC;
26#endif
27
Michal Simekec48b6c2018-08-22 14:55:27 +020028int board_init(void)
29{
30 printf("EL Level:\tEL%d\n", current_el());
31
Siva Durga Prasad Paladugu26e054c2019-08-05 15:54:59 +053032#if defined(CONFIG_FPGA_VERSALPL)
33 fpga_init();
34 fpga_add(fpga_xilinx, &versalpl);
35#endif
36
Michal Simekec48b6c2018-08-22 14:55:27 +020037 return 0;
38}
39
40int board_early_init_r(void)
41{
Michal Simekfb771792019-01-28 11:08:00 +010042 u32 val;
Michal Simekec48b6c2018-08-22 14:55:27 +020043
Michal Simekfb771792019-01-28 11:08:00 +010044 if (current_el() != 3)
45 return 0;
Michal Simekec48b6c2018-08-22 14:55:27 +020046
Michal Simek47a766f2019-01-28 11:12:41 +010047 debug("iou_switch ctrl div0 %x\n",
48 readl(&crlapb_base->iou_switch_ctrl));
49
Michal Simekfb771792019-01-28 11:08:00 +010050 writel(IOU_SWITCH_CTRL_CLKACT_BIT |
Michal Simek47a766f2019-01-28 11:12:41 +010051 (CONFIG_IOU_SWITCH_DIVISOR0 << IOU_SWITCH_CTRL_DIVISOR0_SHIFT),
Michal Simekfb771792019-01-28 11:08:00 +010052 &crlapb_base->iou_switch_ctrl);
Michal Simekec48b6c2018-08-22 14:55:27 +020053
Michal Simekfb771792019-01-28 11:08:00 +010054 /* Global timer init - Program time stamp reference clk */
55 val = readl(&crlapb_base->timestamp_ref_ctrl);
56 val |= CRL_APB_TIMESTAMP_REF_CTRL_CLKACT_BIT;
57 writel(val, &crlapb_base->timestamp_ref_ctrl);
Michal Simekec48b6c2018-08-22 14:55:27 +020058
Michal Simekfb771792019-01-28 11:08:00 +010059 debug("ref ctrl 0x%x\n",
60 readl(&crlapb_base->timestamp_ref_ctrl));
Michal Simekec48b6c2018-08-22 14:55:27 +020061
Michal Simekfb771792019-01-28 11:08:00 +010062 /* Clear reset of timestamp reg */
63 writel(0, &crlapb_base->rst_timestamp);
Michal Simekec48b6c2018-08-22 14:55:27 +020064
Michal Simekfb771792019-01-28 11:08:00 +010065 /*
66 * Program freq register in System counter and
67 * enable system counter.
68 */
69 writel(COUNTER_FREQUENCY,
70 &iou_scntr_secure->base_frequency_id_register);
Michal Simekec48b6c2018-08-22 14:55:27 +020071
Michal Simekfb771792019-01-28 11:08:00 +010072 debug("counter val 0x%x\n",
73 readl(&iou_scntr_secure->base_frequency_id_register));
Michal Simekec48b6c2018-08-22 14:55:27 +020074
Michal Simekfb771792019-01-28 11:08:00 +010075 writel(IOU_SCNTRS_CONTROL_EN,
76 &iou_scntr_secure->counter_control_register);
77
78 debug("scntrs control 0x%x\n",
79 readl(&iou_scntr_secure->counter_control_register));
80 debug("timer 0x%llx\n", get_ticks());
81 debug("timer 0x%llx\n", get_ticks());
Michal Simekec48b6c2018-08-22 14:55:27 +020082
83 return 0;
84}
85
Michal Simek51f6c522020-04-08 11:04:41 +020086static u8 versal_get_bootmode(void)
87{
88 u8 bootmode;
89 u32 reg = 0;
90
91 reg = readl(&crp_base->boot_mode_usr);
92
93 if (reg >> BOOT_MODE_ALT_SHIFT)
94 reg >>= BOOT_MODE_ALT_SHIFT;
95
96 bootmode = reg & BOOT_MODES_MASK;
97
98 return bootmode;
99}
100
Siva Durga Prasad Paladugubfd092f2019-01-31 17:28:14 +0530101int board_late_init(void)
102{
Siva Durga Prasad Paladugubfd092f2019-01-31 17:28:14 +0530103 u8 bootmode;
104 struct udevice *dev;
105 int bootseq = -1;
106 int bootseq_len = 0;
107 int env_targets_len = 0;
108 const char *mode;
109 char *new_targets;
110 char *env_targets;
111
112 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
113 debug("Saved variables - Skipping\n");
114 return 0;
115 }
116
Michal Simek51f6c522020-04-08 11:04:41 +0200117 bootmode = versal_get_bootmode();
Siva Durga Prasad Paladugubfd092f2019-01-31 17:28:14 +0530118
119 puts("Bootmode: ");
120 switch (bootmode) {
T Karthik Reddyf0c16cd2019-07-11 16:07:57 +0530121 case USB_MODE:
122 puts("USB_MODE\n");
123 mode = "dfu_usb";
124 break;
Siva Durga Prasad Paladugubfd092f2019-01-31 17:28:14 +0530125 case JTAG_MODE:
126 puts("JTAG_MODE\n");
Siva Durga Prasad Paladugu3d865ac2019-06-25 17:13:14 +0530127 mode = "jtag pxe dhcp";
Siva Durga Prasad Paladugubfd092f2019-01-31 17:28:14 +0530128 break;
129 case QSPI_MODE_24BIT:
130 puts("QSPI_MODE_24\n");
131 mode = "xspi0";
132 break;
133 case QSPI_MODE_32BIT:
134 puts("QSPI_MODE_32\n");
135 mode = "xspi0";
136 break;
137 case OSPI_MODE:
138 puts("OSPI_MODE\n");
139 mode = "xspi0";
140 break;
141 case EMMC_MODE:
142 puts("EMMC_MODE\n");
T Karthik Reddy7c5b7bb2019-12-16 04:44:26 -0700143 if (uclass_get_device_by_name(UCLASS_MMC,
144 "sdhci@f1050000", &dev)) {
145 puts("Boot from EMMC but without SD1 enabled!\n");
146 return -1;
147 }
148 debug("mmc1 device found at %p, seq %d\n", dev, dev->seq);
149 mode = "mmc";
150 bootseq = dev->seq;
Siva Durga Prasad Paladugubfd092f2019-01-31 17:28:14 +0530151 break;
152 case SD_MODE:
153 puts("SD_MODE\n");
154 if (uclass_get_device_by_name(UCLASS_MMC,
155 "sdhci@f1040000", &dev)) {
156 puts("Boot from SD0 but without SD0 enabled!\n");
157 return -1;
158 }
159 debug("mmc0 device found at %p, seq %d\n", dev, dev->seq);
160
161 mode = "mmc";
162 bootseq = dev->seq;
163 break;
164 case SD1_LSHFT_MODE:
165 puts("LVL_SHFT_");
166 /* fall through */
167 case SD_MODE1:
168 puts("SD_MODE1\n");
169 if (uclass_get_device_by_name(UCLASS_MMC,
170 "sdhci@f1050000", &dev)) {
171 puts("Boot from SD1 but without SD1 enabled!\n");
172 return -1;
173 }
174 debug("mmc1 device found at %p, seq %d\n", dev, dev->seq);
175
176 mode = "mmc";
177 bootseq = dev->seq;
178 break;
179 default:
180 mode = "";
181 printf("Invalid Boot Mode:0x%x\n", bootmode);
182 break;
183 }
184
185 if (bootseq >= 0) {
186 bootseq_len = snprintf(NULL, 0, "%i", bootseq);
187 debug("Bootseq len: %x\n", bootseq_len);
188 }
189
190 /*
191 * One terminating char + one byte for space between mode
192 * and default boot_targets
193 */
194 env_targets = env_get("boot_targets");
195 if (env_targets)
196 env_targets_len = strlen(env_targets);
197
198 new_targets = calloc(1, strlen(mode) + env_targets_len + 2 +
199 bootseq_len);
200 if (!new_targets)
201 return -ENOMEM;
202
203 if (bootseq >= 0)
204 sprintf(new_targets, "%s%x %s", mode, bootseq,
205 env_targets ? env_targets : "");
206 else
207 sprintf(new_targets, "%s %s", mode,
208 env_targets ? env_targets : "");
209
210 env_set("boot_targets", new_targets);
211
Michal Simek80fdef12020-03-31 12:39:37 +0200212 return board_late_init_xilinx();
Siva Durga Prasad Paladugubfd092f2019-01-31 17:28:14 +0530213}
214
Michal Simekec48b6c2018-08-22 14:55:27 +0200215int dram_init_banksize(void)
216{
Michal Simekaef149e2019-04-29 09:39:09 -0700217 int ret;
218
219 ret = fdtdec_setup_memory_banksize();
220 if (ret)
221 return ret;
222
223 mem_map_fill();
Michal Simekec48b6c2018-08-22 14:55:27 +0200224
225 return 0;
226}
227
228int dram_init(void)
229{
230 if (fdtdec_setup_mem_size_base() != 0)
231 return -EINVAL;
232
233 return 0;
234}
235
236void reset_cpu(ulong addr)
237{
238}