blob: dcfb8878c63d7e20480ff6df2e03944edcf705a2 [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>
9#include <malloc.h>
10#include <asm/io.h>
11#include <asm/arch/hardware.h>
Michal Simek21eb5cc2019-04-29 09:39:09 -070012#include <asm/arch/sys_proto.h>
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +053013#include <dm/device.h>
14#include <dm/uclass.h>
Siva Durga Prasad Paladugub7398972019-08-05 15:54:59 +053015#include <versalpl.h>
Siva Durga Prasad Paladuguc5cf9d12019-08-05 23:28:30 +053016#include <linux/sizes.h>
Michal Simek4b066a12018-08-22 14:55:27 +020017
18DECLARE_GLOBAL_DATA_PTR;
19
Siva Durga Prasad Paladugub7398972019-08-05 15:54:59 +053020#if defined(CONFIG_FPGA_VERSALPL)
21static xilinx_desc versalpl = XILINX_VERSAL_DESC;
22#endif
23
Michal Simek4b066a12018-08-22 14:55:27 +020024int board_init(void)
25{
26 printf("EL Level:\tEL%d\n", current_el());
27
Siva Durga Prasad Paladugub7398972019-08-05 15:54:59 +053028#if defined(CONFIG_FPGA_VERSALPL)
29 fpga_init();
30 fpga_add(fpga_xilinx, &versalpl);
31#endif
32
Michal Simek4b066a12018-08-22 14:55:27 +020033 return 0;
34}
35
36int board_early_init_r(void)
37{
Michal Simek19f6c972019-01-28 11:08:00 +010038 u32 val;
Michal Simek4b066a12018-08-22 14:55:27 +020039
Michal Simek19f6c972019-01-28 11:08:00 +010040 if (current_el() != 3)
41 return 0;
Michal Simek4b066a12018-08-22 14:55:27 +020042
Michal Simekf56f7d12019-01-28 11:12:41 +010043 debug("iou_switch ctrl div0 %x\n",
44 readl(&crlapb_base->iou_switch_ctrl));
45
Michal Simek19f6c972019-01-28 11:08:00 +010046 writel(IOU_SWITCH_CTRL_CLKACT_BIT |
Michal Simekf56f7d12019-01-28 11:12:41 +010047 (CONFIG_IOU_SWITCH_DIVISOR0 << IOU_SWITCH_CTRL_DIVISOR0_SHIFT),
Michal Simek19f6c972019-01-28 11:08:00 +010048 &crlapb_base->iou_switch_ctrl);
Michal Simek4b066a12018-08-22 14:55:27 +020049
Michal Simek19f6c972019-01-28 11:08:00 +010050 /* Global timer init - Program time stamp reference clk */
51 val = readl(&crlapb_base->timestamp_ref_ctrl);
52 val |= CRL_APB_TIMESTAMP_REF_CTRL_CLKACT_BIT;
53 writel(val, &crlapb_base->timestamp_ref_ctrl);
Michal Simek4b066a12018-08-22 14:55:27 +020054
Michal Simek19f6c972019-01-28 11:08:00 +010055 debug("ref ctrl 0x%x\n",
56 readl(&crlapb_base->timestamp_ref_ctrl));
Michal Simek4b066a12018-08-22 14:55:27 +020057
Michal Simek19f6c972019-01-28 11:08:00 +010058 /* Clear reset of timestamp reg */
59 writel(0, &crlapb_base->rst_timestamp);
Michal Simek4b066a12018-08-22 14:55:27 +020060
Michal Simek19f6c972019-01-28 11:08:00 +010061 /*
62 * Program freq register in System counter and
63 * enable system counter.
64 */
65 writel(COUNTER_FREQUENCY,
66 &iou_scntr_secure->base_frequency_id_register);
Michal Simek4b066a12018-08-22 14:55:27 +020067
Michal Simek19f6c972019-01-28 11:08:00 +010068 debug("counter val 0x%x\n",
69 readl(&iou_scntr_secure->base_frequency_id_register));
70
71 writel(IOU_SCNTRS_CONTROL_EN,
72 &iou_scntr_secure->counter_control_register);
Michal Simek4b066a12018-08-22 14:55:27 +020073
Michal Simek19f6c972019-01-28 11:08:00 +010074 debug("scntrs control 0x%x\n",
75 readl(&iou_scntr_secure->counter_control_register));
76 debug("timer 0x%llx\n", get_ticks());
77 debug("timer 0x%llx\n", get_ticks());
Michal Simek4b066a12018-08-22 14:55:27 +020078
79 return 0;
80}
81
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +053082int board_late_init(void)
83{
84 u32 reg = 0;
85 u8 bootmode;
86 struct udevice *dev;
87 int bootseq = -1;
88 int bootseq_len = 0;
89 int env_targets_len = 0;
90 const char *mode;
91 char *new_targets;
92 char *env_targets;
Siva Durga Prasad Paladuguc5cf9d12019-08-05 23:28:30 +053093 ulong initrd_hi;
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +053094
95 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
96 debug("Saved variables - Skipping\n");
97 return 0;
98 }
99
100 reg = readl(&crp_base->boot_mode_usr);
101
102 if (reg >> BOOT_MODE_ALT_SHIFT)
103 reg >>= BOOT_MODE_ALT_SHIFT;
104
105 bootmode = reg & BOOT_MODES_MASK;
106
107 puts("Bootmode: ");
108 switch (bootmode) {
109 case JTAG_MODE:
110 puts("JTAG_MODE\n");
Siva Durga Prasad Paladugu00784e02019-06-25 17:13:14 +0530111 mode = "jtag pxe dhcp";
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +0530112 break;
113 case QSPI_MODE_24BIT:
114 puts("QSPI_MODE_24\n");
115 mode = "xspi0";
116 break;
117 case QSPI_MODE_32BIT:
118 puts("QSPI_MODE_32\n");
119 mode = "xspi0";
120 break;
121 case OSPI_MODE:
122 puts("OSPI_MODE\n");
123 mode = "xspi0";
124 break;
125 case EMMC_MODE:
126 puts("EMMC_MODE\n");
127 mode = "mmc0";
128 break;
129 case SD_MODE:
130 puts("SD_MODE\n");
131 if (uclass_get_device_by_name(UCLASS_MMC,
132 "sdhci@f1040000", &dev)) {
133 puts("Boot from SD0 but without SD0 enabled!\n");
134 return -1;
135 }
136 debug("mmc0 device found at %p, seq %d\n", dev, dev->seq);
137
138 mode = "mmc";
139 bootseq = dev->seq;
140 break;
141 case SD1_LSHFT_MODE:
142 puts("LVL_SHFT_");
143 /* fall through */
144 case SD_MODE1:
145 puts("SD_MODE1\n");
146 if (uclass_get_device_by_name(UCLASS_MMC,
147 "sdhci@f1050000", &dev)) {
148 puts("Boot from SD1 but without SD1 enabled!\n");
149 return -1;
150 }
151 debug("mmc1 device found at %p, seq %d\n", dev, dev->seq);
152
153 mode = "mmc";
154 bootseq = dev->seq;
155 break;
156 default:
157 mode = "";
158 printf("Invalid Boot Mode:0x%x\n", bootmode);
159 break;
160 }
161
162 if (bootseq >= 0) {
163 bootseq_len = snprintf(NULL, 0, "%i", bootseq);
164 debug("Bootseq len: %x\n", bootseq_len);
165 }
166
167 /*
168 * One terminating char + one byte for space between mode
169 * and default boot_targets
170 */
171 env_targets = env_get("boot_targets");
172 if (env_targets)
173 env_targets_len = strlen(env_targets);
174
175 new_targets = calloc(1, strlen(mode) + env_targets_len + 2 +
176 bootseq_len);
177 if (!new_targets)
178 return -ENOMEM;
179
180 if (bootseq >= 0)
181 sprintf(new_targets, "%s%x %s", mode, bootseq,
182 env_targets ? env_targets : "");
183 else
184 sprintf(new_targets, "%s %s", mode,
185 env_targets ? env_targets : "");
186
187 env_set("boot_targets", new_targets);
188
Siva Durga Prasad Paladuguc5cf9d12019-08-05 23:28:30 +0530189 initrd_hi = gd->start_addr_sp - CONFIG_STACK_SIZE;
190 initrd_hi = round_down(initrd_hi, SZ_16M);
191 env_set_addr("initrd_high", (void *)initrd_hi);
192
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +0530193 return 0;
194}
195
Michal Simek4b066a12018-08-22 14:55:27 +0200196int dram_init_banksize(void)
197{
Michal Simek21eb5cc2019-04-29 09:39:09 -0700198 int ret;
199
200 ret = fdtdec_setup_memory_banksize();
201 if (ret)
202 return ret;
203
204 mem_map_fill();
Michal Simek4b066a12018-08-22 14:55:27 +0200205
206 return 0;
207}
208
209int dram_init(void)
210{
211 if (fdtdec_setup_mem_size_base() != 0)
212 return -EINVAL;
213
214 return 0;
215}
216
217void reset_cpu(ulong addr)
218{
219}