blob: 75056aa3d9f43cd5ff996790a896af79ff1eccce [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>
Simon Glass495a5dc2019-11-14 12:57:30 -070010#include <time.h>
Michal Simek4b066a12018-08-22 14:55:27 +020011#include <asm/io.h>
12#include <asm/arch/hardware.h>
Michal Simek21eb5cc2019-04-29 09:39:09 -070013#include <asm/arch/sys_proto.h>
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +053014#include <dm/device.h>
15#include <dm/uclass.h>
Siva Durga Prasad Paladugub7398972019-08-05 15:54:59 +053016#include <versalpl.h>
Siva Durga Prasad Paladuguc5cf9d12019-08-05 23:28:30 +053017#include <linux/sizes.h>
Michal Simek4b066a12018-08-22 14:55:27 +020018
19DECLARE_GLOBAL_DATA_PTR;
20
Siva Durga Prasad Paladugub7398972019-08-05 15:54:59 +053021#if defined(CONFIG_FPGA_VERSALPL)
22static xilinx_desc versalpl = XILINX_VERSAL_DESC;
23#endif
24
Michal Simek4b066a12018-08-22 14:55:27 +020025int board_init(void)
26{
27 printf("EL Level:\tEL%d\n", current_el());
28
Siva Durga Prasad Paladugub7398972019-08-05 15:54:59 +053029#if defined(CONFIG_FPGA_VERSALPL)
30 fpga_init();
31 fpga_add(fpga_xilinx, &versalpl);
32#endif
33
Michal Simek4b066a12018-08-22 14:55:27 +020034 return 0;
35}
36
37int board_early_init_r(void)
38{
Michal Simek19f6c972019-01-28 11:08:00 +010039 u32 val;
Michal Simek4b066a12018-08-22 14:55:27 +020040
Michal Simek19f6c972019-01-28 11:08:00 +010041 if (current_el() != 3)
42 return 0;
Michal Simek4b066a12018-08-22 14:55:27 +020043
Michal Simekf56f7d12019-01-28 11:12:41 +010044 debug("iou_switch ctrl div0 %x\n",
45 readl(&crlapb_base->iou_switch_ctrl));
46
Michal Simek19f6c972019-01-28 11:08:00 +010047 writel(IOU_SWITCH_CTRL_CLKACT_BIT |
Michal Simekf56f7d12019-01-28 11:12:41 +010048 (CONFIG_IOU_SWITCH_DIVISOR0 << IOU_SWITCH_CTRL_DIVISOR0_SHIFT),
Michal Simek19f6c972019-01-28 11:08:00 +010049 &crlapb_base->iou_switch_ctrl);
Michal Simek4b066a12018-08-22 14:55:27 +020050
Michal Simek19f6c972019-01-28 11:08:00 +010051 /* Global timer init - Program time stamp reference clk */
52 val = readl(&crlapb_base->timestamp_ref_ctrl);
53 val |= CRL_APB_TIMESTAMP_REF_CTRL_CLKACT_BIT;
54 writel(val, &crlapb_base->timestamp_ref_ctrl);
Michal Simek4b066a12018-08-22 14:55:27 +020055
Michal Simek19f6c972019-01-28 11:08:00 +010056 debug("ref ctrl 0x%x\n",
57 readl(&crlapb_base->timestamp_ref_ctrl));
Michal Simek4b066a12018-08-22 14:55:27 +020058
Michal Simek19f6c972019-01-28 11:08:00 +010059 /* Clear reset of timestamp reg */
60 writel(0, &crlapb_base->rst_timestamp);
Michal Simek4b066a12018-08-22 14:55:27 +020061
Michal Simek19f6c972019-01-28 11:08:00 +010062 /*
63 * Program freq register in System counter and
64 * enable system counter.
65 */
66 writel(COUNTER_FREQUENCY,
67 &iou_scntr_secure->base_frequency_id_register);
Michal Simek4b066a12018-08-22 14:55:27 +020068
Michal Simek19f6c972019-01-28 11:08:00 +010069 debug("counter val 0x%x\n",
70 readl(&iou_scntr_secure->base_frequency_id_register));
71
72 writel(IOU_SCNTRS_CONTROL_EN,
73 &iou_scntr_secure->counter_control_register);
Michal Simek4b066a12018-08-22 14:55:27 +020074
Michal Simek19f6c972019-01-28 11:08:00 +010075 debug("scntrs control 0x%x\n",
76 readl(&iou_scntr_secure->counter_control_register));
77 debug("timer 0x%llx\n", get_ticks());
78 debug("timer 0x%llx\n", get_ticks());
Michal Simek4b066a12018-08-22 14:55:27 +020079
80 return 0;
81}
82
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +053083int board_late_init(void)
84{
85 u32 reg = 0;
86 u8 bootmode;
87 struct udevice *dev;
88 int bootseq = -1;
89 int bootseq_len = 0;
90 int env_targets_len = 0;
91 const char *mode;
92 char *new_targets;
93 char *env_targets;
Siva Durga Prasad Paladuguc5cf9d12019-08-05 23:28:30 +053094 ulong initrd_hi;
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +053095
96 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
97 debug("Saved variables - Skipping\n");
98 return 0;
99 }
100
101 reg = readl(&crp_base->boot_mode_usr);
102
103 if (reg >> BOOT_MODE_ALT_SHIFT)
104 reg >>= BOOT_MODE_ALT_SHIFT;
105
106 bootmode = reg & BOOT_MODES_MASK;
107
108 puts("Bootmode: ");
109 switch (bootmode) {
T Karthik Reddyfacca9a2019-07-11 16:07:57 +0530110 case USB_MODE:
111 puts("USB_MODE\n");
112 mode = "dfu_usb";
113 break;
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +0530114 case JTAG_MODE:
115 puts("JTAG_MODE\n");
Siva Durga Prasad Paladugu00784e02019-06-25 17:13:14 +0530116 mode = "jtag pxe dhcp";
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +0530117 break;
118 case QSPI_MODE_24BIT:
119 puts("QSPI_MODE_24\n");
120 mode = "xspi0";
121 break;
122 case QSPI_MODE_32BIT:
123 puts("QSPI_MODE_32\n");
124 mode = "xspi0";
125 break;
126 case OSPI_MODE:
127 puts("OSPI_MODE\n");
128 mode = "xspi0";
129 break;
130 case EMMC_MODE:
131 puts("EMMC_MODE\n");
132 mode = "mmc0";
133 break;
134 case SD_MODE:
135 puts("SD_MODE\n");
136 if (uclass_get_device_by_name(UCLASS_MMC,
137 "sdhci@f1040000", &dev)) {
138 puts("Boot from SD0 but without SD0 enabled!\n");
139 return -1;
140 }
141 debug("mmc0 device found at %p, seq %d\n", dev, dev->seq);
142
143 mode = "mmc";
144 bootseq = dev->seq;
145 break;
146 case SD1_LSHFT_MODE:
147 puts("LVL_SHFT_");
148 /* fall through */
149 case SD_MODE1:
150 puts("SD_MODE1\n");
151 if (uclass_get_device_by_name(UCLASS_MMC,
152 "sdhci@f1050000", &dev)) {
153 puts("Boot from SD1 but without SD1 enabled!\n");
154 return -1;
155 }
156 debug("mmc1 device found at %p, seq %d\n", dev, dev->seq);
157
158 mode = "mmc";
159 bootseq = dev->seq;
160 break;
161 default:
162 mode = "";
163 printf("Invalid Boot Mode:0x%x\n", bootmode);
164 break;
165 }
166
167 if (bootseq >= 0) {
168 bootseq_len = snprintf(NULL, 0, "%i", bootseq);
169 debug("Bootseq len: %x\n", bootseq_len);
170 }
171
172 /*
173 * One terminating char + one byte for space between mode
174 * and default boot_targets
175 */
176 env_targets = env_get("boot_targets");
177 if (env_targets)
178 env_targets_len = strlen(env_targets);
179
180 new_targets = calloc(1, strlen(mode) + env_targets_len + 2 +
181 bootseq_len);
182 if (!new_targets)
183 return -ENOMEM;
184
185 if (bootseq >= 0)
186 sprintf(new_targets, "%s%x %s", mode, bootseq,
187 env_targets ? env_targets : "");
188 else
189 sprintf(new_targets, "%s %s", mode,
190 env_targets ? env_targets : "");
191
192 env_set("boot_targets", new_targets);
193
Siva Durga Prasad Paladuguc5cf9d12019-08-05 23:28:30 +0530194 initrd_hi = gd->start_addr_sp - CONFIG_STACK_SIZE;
195 initrd_hi = round_down(initrd_hi, SZ_16M);
196 env_set_addr("initrd_high", (void *)initrd_hi);
197
Siva Durga Prasad Paladugu37c2ff82019-01-31 17:28:14 +0530198 return 0;
199}
200
Michal Simek4b066a12018-08-22 14:55:27 +0200201int dram_init_banksize(void)
202{
Michal Simek21eb5cc2019-04-29 09:39:09 -0700203 int ret;
204
205 ret = fdtdec_setup_memory_banksize();
206 if (ret)
207 return ret;
208
209 mem_map_fill();
Michal Simek4b066a12018-08-22 14:55:27 +0200210
211 return 0;
212}
213
214int dram_init(void)
215{
216 if (fdtdec_setup_mem_size_base() != 0)
217 return -EINVAL;
218
219 return 0;
220}
221
222void reset_cpu(ulong addr)
223{
224}