blob: a5ca4ca87401c6bbfd5dba174c876f555827e8f4 [file] [log] [blame]
Michal Simek4b066a12018-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 Glassafb02152019-12-28 10:45:01 -07008#include <cpu_func.h>
Simon Glassed38aef2020-05-10 11:40:03 -06009#include <env.h>
Michal Simek4b066a12018-08-22 14:55:27 +020010#include <fdtdec.h>
Simon Glassa7b51302019-11-14 12:57:46 -070011#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Michal Simek4b066a12018-08-22 14:55:27 +020013#include <malloc.h>
Simon Glass495a5dc2019-11-14 12:57:30 -070014#include <time.h>
Simon Glass274e0b02020-05-10 11:39:56 -060015#include <asm/cache.h>
Michal Simek4b066a12018-08-22 14:55:27 +020016#include <asm/io.h>
17#include <asm/arch/hardware.h>
Michal Simek21eb5cc2019-04-29 09:39:09 -070018#include <asm/arch/sys_proto.h>
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +053019#include <dm/device.h>
20#include <dm/uclass.h>
Siva Durga Prasad Paladugub7398972019-08-05 15:54:59 +053021#include <versalpl.h>
Michal Simek705d44a2020-03-31 12:39:37 +020022#include "../common/board.h"
Michal Simek4b066a12018-08-22 14:55:27 +020023
24DECLARE_GLOBAL_DATA_PTR;
25
Siva Durga Prasad Paladugub7398972019-08-05 15:54:59 +053026#if defined(CONFIG_FPGA_VERSALPL)
27static xilinx_desc versalpl = XILINX_VERSAL_DESC;
28#endif
29
Michal Simek4b066a12018-08-22 14:55:27 +020030int board_init(void)
31{
32 printf("EL Level:\tEL%d\n", current_el());
33
Siva Durga Prasad Paladugub7398972019-08-05 15:54:59 +053034#if defined(CONFIG_FPGA_VERSALPL)
35 fpga_init();
36 fpga_add(fpga_xilinx, &versalpl);
37#endif
38
Michal Simek4b066a12018-08-22 14:55:27 +020039 return 0;
40}
41
42int board_early_init_r(void)
43{
Michal Simek19f6c972019-01-28 11:08:00 +010044 u32 val;
Michal Simek4b066a12018-08-22 14:55:27 +020045
Michal Simek19f6c972019-01-28 11:08:00 +010046 if (current_el() != 3)
47 return 0;
Michal Simek4b066a12018-08-22 14:55:27 +020048
Michal Simekf56f7d12019-01-28 11:12:41 +010049 debug("iou_switch ctrl div0 %x\n",
50 readl(&crlapb_base->iou_switch_ctrl));
51
Michal Simek19f6c972019-01-28 11:08:00 +010052 writel(IOU_SWITCH_CTRL_CLKACT_BIT |
Michal Simekf56f7d12019-01-28 11:12:41 +010053 (CONFIG_IOU_SWITCH_DIVISOR0 << IOU_SWITCH_CTRL_DIVISOR0_SHIFT),
Michal Simek19f6c972019-01-28 11:08:00 +010054 &crlapb_base->iou_switch_ctrl);
Michal Simek4b066a12018-08-22 14:55:27 +020055
Michal Simek19f6c972019-01-28 11:08:00 +010056 /* Global timer init - Program time stamp reference clk */
57 val = readl(&crlapb_base->timestamp_ref_ctrl);
58 val |= CRL_APB_TIMESTAMP_REF_CTRL_CLKACT_BIT;
59 writel(val, &crlapb_base->timestamp_ref_ctrl);
Michal Simek4b066a12018-08-22 14:55:27 +020060
Michal Simek19f6c972019-01-28 11:08:00 +010061 debug("ref ctrl 0x%x\n",
62 readl(&crlapb_base->timestamp_ref_ctrl));
Michal Simek4b066a12018-08-22 14:55:27 +020063
Michal Simek19f6c972019-01-28 11:08:00 +010064 /* Clear reset of timestamp reg */
65 writel(0, &crlapb_base->rst_timestamp);
Michal Simek4b066a12018-08-22 14:55:27 +020066
Michal Simek19f6c972019-01-28 11:08:00 +010067 /*
68 * Program freq register in System counter and
69 * enable system counter.
70 */
71 writel(COUNTER_FREQUENCY,
72 &iou_scntr_secure->base_frequency_id_register);
Michal Simek4b066a12018-08-22 14:55:27 +020073
Michal Simek19f6c972019-01-28 11:08:00 +010074 debug("counter val 0x%x\n",
75 readl(&iou_scntr_secure->base_frequency_id_register));
76
77 writel(IOU_SCNTRS_CONTROL_EN,
78 &iou_scntr_secure->counter_control_register);
Michal Simek4b066a12018-08-22 14:55:27 +020079
Michal Simek19f6c972019-01-28 11:08:00 +010080 debug("scntrs control 0x%x\n",
81 readl(&iou_scntr_secure->counter_control_register));
82 debug("timer 0x%llx\n", get_ticks());
83 debug("timer 0x%llx\n", get_ticks());
Michal Simek4b066a12018-08-22 14:55:27 +020084
85 return 0;
86}
87
Michal Simek9c91e612020-04-08 11:04:41 +020088static u8 versal_get_bootmode(void)
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +053089{
Michal Simek9c91e612020-04-08 11:04:41 +020090 u8 bootmode;
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +053091 u32 reg = 0;
Michal Simek9c91e612020-04-08 11:04:41 +020092
93 reg = readl(&crp_base->boot_mode_usr);
94
95 if (reg >> BOOT_MODE_ALT_SHIFT)
96 reg >>= BOOT_MODE_ALT_SHIFT;
97
98 bootmode = reg & BOOT_MODES_MASK;
99
100 return bootmode;
101}
102
103int board_late_init(void)
104{
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +0530105 u8 bootmode;
106 struct udevice *dev;
107 int bootseq = -1;
108 int bootseq_len = 0;
109 int env_targets_len = 0;
110 const char *mode;
111 char *new_targets;
112 char *env_targets;
113
114 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
115 debug("Saved variables - Skipping\n");
116 return 0;
117 }
118
Michal Simekbab07b62020-07-28 12:45:47 +0200119 if (!CONFIG_IS_ENABLED(ENV_VARS_UBOOT_RUNTIME_CONFIG))
120 return 0;
121
Michal Simek9c91e612020-04-08 11:04:41 +0200122 bootmode = versal_get_bootmode();
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +0530123
124 puts("Bootmode: ");
125 switch (bootmode) {
T Karthik Reddyfacca9a2019-07-11 16:07:57 +0530126 case USB_MODE:
127 puts("USB_MODE\n");
128 mode = "dfu_usb";
129 break;
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +0530130 case JTAG_MODE:
131 puts("JTAG_MODE\n");
Siva Durga Prasad Paladugu00784e02019-06-25 17:13:14 +0530132 mode = "jtag pxe dhcp";
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +0530133 break;
134 case QSPI_MODE_24BIT:
135 puts("QSPI_MODE_24\n");
136 mode = "xspi0";
137 break;
138 case QSPI_MODE_32BIT:
139 puts("QSPI_MODE_32\n");
140 mode = "xspi0";
141 break;
142 case OSPI_MODE:
143 puts("OSPI_MODE\n");
144 mode = "xspi0";
145 break;
146 case EMMC_MODE:
147 puts("EMMC_MODE\n");
T Karthik Reddybc2b9642019-12-16 04:44:26 -0700148 if (uclass_get_device_by_name(UCLASS_MMC,
149 "sdhci@f1050000", &dev)) {
150 puts("Boot from EMMC but without SD1 enabled!\n");
151 return -1;
152 }
153 debug("mmc1 device found at %p, seq %d\n", dev, dev->seq);
154 mode = "mmc";
155 bootseq = dev->seq;
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +0530156 break;
157 case SD_MODE:
158 puts("SD_MODE\n");
159 if (uclass_get_device_by_name(UCLASS_MMC,
160 "sdhci@f1040000", &dev)) {
161 puts("Boot from SD0 but without SD0 enabled!\n");
162 return -1;
163 }
164 debug("mmc0 device found at %p, seq %d\n", dev, dev->seq);
165
166 mode = "mmc";
167 bootseq = dev->seq;
168 break;
169 case SD1_LSHFT_MODE:
170 puts("LVL_SHFT_");
171 /* fall through */
172 case SD_MODE1:
173 puts("SD_MODE1\n");
174 if (uclass_get_device_by_name(UCLASS_MMC,
175 "sdhci@f1050000", &dev)) {
176 puts("Boot from SD1 but without SD1 enabled!\n");
177 return -1;
178 }
179 debug("mmc1 device found at %p, seq %d\n", dev, dev->seq);
180
181 mode = "mmc";
182 bootseq = dev->seq;
183 break;
184 default:
185 mode = "";
186 printf("Invalid Boot Mode:0x%x\n", bootmode);
187 break;
188 }
189
190 if (bootseq >= 0) {
191 bootseq_len = snprintf(NULL, 0, "%i", bootseq);
192 debug("Bootseq len: %x\n", bootseq_len);
193 }
194
195 /*
196 * One terminating char + one byte for space between mode
197 * and default boot_targets
198 */
199 env_targets = env_get("boot_targets");
200 if (env_targets)
201 env_targets_len = strlen(env_targets);
202
203 new_targets = calloc(1, strlen(mode) + env_targets_len + 2 +
204 bootseq_len);
205 if (!new_targets)
206 return -ENOMEM;
207
208 if (bootseq >= 0)
209 sprintf(new_targets, "%s%x %s", mode, bootseq,
210 env_targets ? env_targets : "");
211 else
212 sprintf(new_targets, "%s %s", mode,
213 env_targets ? env_targets : "");
214
215 env_set("boot_targets", new_targets);
216
Michal Simek705d44a2020-03-31 12:39:37 +0200217 return board_late_init_xilinx();
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +0530218}
219
Michal Simek4b066a12018-08-22 14:55:27 +0200220int dram_init_banksize(void)
221{
Michal Simek21eb5cc2019-04-29 09:39:09 -0700222 int ret;
223
224 ret = fdtdec_setup_memory_banksize();
225 if (ret)
226 return ret;
227
228 mem_map_fill();
Michal Simek4b066a12018-08-22 14:55:27 +0200229
230 return 0;
231}
232
233int dram_init(void)
234{
Michal Simek9134d4c2020-07-10 12:42:09 +0200235 if (fdtdec_setup_mem_size_base_lowest() != 0)
Michal Simek4b066a12018-08-22 14:55:27 +0200236 return -EINVAL;
237
238 return 0;
239}
240
241void reset_cpu(ulong addr)
242{
243}