blob: 9fa9e76e6663b94dd50d963702aaa0714fa516c5 [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>
8#include <fdtdec.h>
Simon Glassa7b51302019-11-14 12:57:46 -07009#include <init.h>
Michal Simek4b066a12018-08-22 14:55:27 +020010#include <malloc.h>
Simon Glass495a5dc2019-11-14 12:57:30 -070011#include <time.h>
Michal Simek4b066a12018-08-22 14:55:27 +020012#include <asm/io.h>
13#include <asm/arch/hardware.h>
Michal Simek21eb5cc2019-04-29 09:39:09 -070014#include <asm/arch/sys_proto.h>
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +053015#include <dm/device.h>
16#include <dm/uclass.h>
Siva Durga Prasad Paladugub7398972019-08-05 15:54:59 +053017#include <versalpl.h>
Siva Durga Prasad Paladuguc5cf9d12019-08-05 23:28:30 +053018#include <linux/sizes.h>
Michal Simek4b066a12018-08-22 14:55:27 +020019
20DECLARE_GLOBAL_DATA_PTR;
21
Siva Durga Prasad Paladugub7398972019-08-05 15:54:59 +053022#if defined(CONFIG_FPGA_VERSALPL)
23static xilinx_desc versalpl = XILINX_VERSAL_DESC;
24#endif
25
Michal Simek4b066a12018-08-22 14:55:27 +020026int board_init(void)
27{
28 printf("EL Level:\tEL%d\n", current_el());
29
Siva Durga Prasad Paladugub7398972019-08-05 15:54:59 +053030#if defined(CONFIG_FPGA_VERSALPL)
31 fpga_init();
32 fpga_add(fpga_xilinx, &versalpl);
33#endif
34
Michal Simek4b066a12018-08-22 14:55:27 +020035 return 0;
36}
37
38int board_early_init_r(void)
39{
Michal Simek19f6c972019-01-28 11:08:00 +010040 u32 val;
Michal Simek4b066a12018-08-22 14:55:27 +020041
Michal Simek19f6c972019-01-28 11:08:00 +010042 if (current_el() != 3)
43 return 0;
Michal Simek4b066a12018-08-22 14:55:27 +020044
Michal Simekf56f7d12019-01-28 11:12:41 +010045 debug("iou_switch ctrl div0 %x\n",
46 readl(&crlapb_base->iou_switch_ctrl));
47
Michal Simek19f6c972019-01-28 11:08:00 +010048 writel(IOU_SWITCH_CTRL_CLKACT_BIT |
Michal Simekf56f7d12019-01-28 11:12:41 +010049 (CONFIG_IOU_SWITCH_DIVISOR0 << IOU_SWITCH_CTRL_DIVISOR0_SHIFT),
Michal Simek19f6c972019-01-28 11:08:00 +010050 &crlapb_base->iou_switch_ctrl);
Michal Simek4b066a12018-08-22 14:55:27 +020051
Michal Simek19f6c972019-01-28 11:08:00 +010052 /* Global timer init - Program time stamp reference clk */
53 val = readl(&crlapb_base->timestamp_ref_ctrl);
54 val |= CRL_APB_TIMESTAMP_REF_CTRL_CLKACT_BIT;
55 writel(val, &crlapb_base->timestamp_ref_ctrl);
Michal Simek4b066a12018-08-22 14:55:27 +020056
Michal Simek19f6c972019-01-28 11:08:00 +010057 debug("ref ctrl 0x%x\n",
58 readl(&crlapb_base->timestamp_ref_ctrl));
Michal Simek4b066a12018-08-22 14:55:27 +020059
Michal Simek19f6c972019-01-28 11:08:00 +010060 /* Clear reset of timestamp reg */
61 writel(0, &crlapb_base->rst_timestamp);
Michal Simek4b066a12018-08-22 14:55:27 +020062
Michal Simek19f6c972019-01-28 11:08:00 +010063 /*
64 * Program freq register in System counter and
65 * enable system counter.
66 */
67 writel(COUNTER_FREQUENCY,
68 &iou_scntr_secure->base_frequency_id_register);
Michal Simek4b066a12018-08-22 14:55:27 +020069
Michal Simek19f6c972019-01-28 11:08:00 +010070 debug("counter val 0x%x\n",
71 readl(&iou_scntr_secure->base_frequency_id_register));
72
73 writel(IOU_SCNTRS_CONTROL_EN,
74 &iou_scntr_secure->counter_control_register);
Michal Simek4b066a12018-08-22 14:55:27 +020075
Michal Simek19f6c972019-01-28 11:08:00 +010076 debug("scntrs control 0x%x\n",
77 readl(&iou_scntr_secure->counter_control_register));
78 debug("timer 0x%llx\n", get_ticks());
79 debug("timer 0x%llx\n", get_ticks());
Michal Simek4b066a12018-08-22 14:55:27 +020080
81 return 0;
82}
83
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +053084int board_late_init(void)
85{
86 u32 reg = 0;
87 u8 bootmode;
88 struct udevice *dev;
89 int bootseq = -1;
90 int bootseq_len = 0;
91 int env_targets_len = 0;
92 const char *mode;
93 char *new_targets;
94 char *env_targets;
Siva Durga Prasad Paladuguc5cf9d12019-08-05 23:28:30 +053095 ulong initrd_hi;
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +053096
97 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
98 debug("Saved variables - Skipping\n");
99 return 0;
100 }
101
102 reg = readl(&crp_base->boot_mode_usr);
103
104 if (reg >> BOOT_MODE_ALT_SHIFT)
105 reg >>= BOOT_MODE_ALT_SHIFT;
106
107 bootmode = reg & BOOT_MODES_MASK;
108
109 puts("Bootmode: ");
110 switch (bootmode) {
T Karthik Reddyfacca9a2019-07-11 16:07:57 +0530111 case USB_MODE:
112 puts("USB_MODE\n");
113 mode = "dfu_usb";
114 break;
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +0530115 case JTAG_MODE:
116 puts("JTAG_MODE\n");
Siva Durga Prasad Paladugu00784e02019-06-25 17:13:14 +0530117 mode = "jtag pxe dhcp";
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +0530118 break;
119 case QSPI_MODE_24BIT:
120 puts("QSPI_MODE_24\n");
121 mode = "xspi0";
122 break;
123 case QSPI_MODE_32BIT:
124 puts("QSPI_MODE_32\n");
125 mode = "xspi0";
126 break;
127 case OSPI_MODE:
128 puts("OSPI_MODE\n");
129 mode = "xspi0";
130 break;
131 case EMMC_MODE:
132 puts("EMMC_MODE\n");
T Karthik Reddybc2b9642019-12-16 04:44:26 -0700133 if (uclass_get_device_by_name(UCLASS_MMC,
134 "sdhci@f1050000", &dev)) {
135 puts("Boot from EMMC but without SD1 enabled!\n");
136 return -1;
137 }
138 debug("mmc1 device found at %p, seq %d\n", dev, dev->seq);
139 mode = "mmc";
140 bootseq = dev->seq;
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +0530141 break;
142 case SD_MODE:
143 puts("SD_MODE\n");
144 if (uclass_get_device_by_name(UCLASS_MMC,
145 "sdhci@f1040000", &dev)) {
146 puts("Boot from SD0 but without SD0 enabled!\n");
147 return -1;
148 }
149 debug("mmc0 device found at %p, seq %d\n", dev, dev->seq);
150
151 mode = "mmc";
152 bootseq = dev->seq;
153 break;
154 case SD1_LSHFT_MODE:
155 puts("LVL_SHFT_");
156 /* fall through */
157 case SD_MODE1:
158 puts("SD_MODE1\n");
159 if (uclass_get_device_by_name(UCLASS_MMC,
160 "sdhci@f1050000", &dev)) {
161 puts("Boot from SD1 but without SD1 enabled!\n");
162 return -1;
163 }
164 debug("mmc1 device found at %p, seq %d\n", dev, dev->seq);
165
166 mode = "mmc";
167 bootseq = dev->seq;
168 break;
169 default:
170 mode = "";
171 printf("Invalid Boot Mode:0x%x\n", bootmode);
172 break;
173 }
174
175 if (bootseq >= 0) {
176 bootseq_len = snprintf(NULL, 0, "%i", bootseq);
177 debug("Bootseq len: %x\n", bootseq_len);
178 }
179
180 /*
181 * One terminating char + one byte for space between mode
182 * and default boot_targets
183 */
184 env_targets = env_get("boot_targets");
185 if (env_targets)
186 env_targets_len = strlen(env_targets);
187
188 new_targets = calloc(1, strlen(mode) + env_targets_len + 2 +
189 bootseq_len);
190 if (!new_targets)
191 return -ENOMEM;
192
193 if (bootseq >= 0)
194 sprintf(new_targets, "%s%x %s", mode, bootseq,
195 env_targets ? env_targets : "");
196 else
197 sprintf(new_targets, "%s %s", mode,
198 env_targets ? env_targets : "");
199
200 env_set("boot_targets", new_targets);
201
Siva Durga Prasad Paladuguc5cf9d12019-08-05 23:28:30 +0530202 initrd_hi = gd->start_addr_sp - CONFIG_STACK_SIZE;
203 initrd_hi = round_down(initrd_hi, SZ_16M);
204 env_set_addr("initrd_high", (void *)initrd_hi);
205
T Karthik Reddy5fa6c1e2019-12-18 03:34:41 -0700206 env_set_hex("script_offset_f", CONFIG_BOOT_SCRIPT_OFFSET);
207
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +0530208 return 0;
209}
210
Michal Simek4b066a12018-08-22 14:55:27 +0200211int dram_init_banksize(void)
212{
Michal Simek21eb5cc2019-04-29 09:39:09 -0700213 int ret;
214
215 ret = fdtdec_setup_memory_banksize();
216 if (ret)
217 return ret;
218
219 mem_map_fill();
Michal Simek4b066a12018-08-22 14:55:27 +0200220
221 return 0;
222}
223
224int dram_init(void)
225{
226 if (fdtdec_setup_mem_size_base() != 0)
227 return -EINVAL;
228
229 return 0;
230}
231
232void reset_cpu(ulong addr)
233{
234}