blob: 51a3d9f276b79f06b6731483ce4cede6c6608b83 [file] [log] [blame]
Michal Simek04b7e622015-01-15 10:01:51 +01001/*
2 * (C) Copyright 2014 - 2015 Xilinx, Inc.
3 * Michal Simek <michal.simek@xilinx.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
Michal Simekd54b1af2015-09-30 17:26:55 +02009#include <sata.h>
Michal Simekb216cc12015-07-23 13:27:40 +020010#include <ahci.h>
11#include <scsi.h>
Michal Simekecfb6dc2016-04-22 14:28:54 +020012#include <malloc.h>
Michal Simekc23d3f82015-11-05 08:34:35 +010013#include <asm/arch/clk.h>
Michal Simek04b7e622015-01-15 10:01:51 +010014#include <asm/arch/hardware.h>
15#include <asm/arch/sys_proto.h>
16#include <asm/io.h>
Siva Durga Prasad Paladuguba1f68e2015-08-04 13:03:26 +053017#include <usb.h>
18#include <dwc3-uboot.h>
Michal Simek8111aff2016-02-01 15:05:58 +010019#include <zynqmppl.h>
Michal Simekeec32f62016-04-22 11:48:49 +020020#include <i2c.h>
Michal Simek76d0a772016-09-01 11:16:40 +020021#include <g_dnl.h>
Michal Simek04b7e622015-01-15 10:01:51 +010022
23DECLARE_GLOBAL_DATA_PTR;
24
Michal Simek8111aff2016-02-01 15:05:58 +010025#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
26 !defined(CONFIG_SPL_BUILD)
27static xilinx_desc zynqmppl = XILINX_ZYNQMP_DESC;
28
29static const struct {
30 uint32_t id;
31 char *name;
32} zynqmp_devices[] = {
33 {
34 .id = 0x10,
35 .name = "3eg",
36 },
37 {
38 .id = 0x11,
39 .name = "2eg",
40 },
41 {
42 .id = 0x20,
43 .name = "5ev",
44 },
45 {
46 .id = 0x21,
47 .name = "4ev",
48 },
49 {
50 .id = 0x30,
51 .name = "7ev",
52 },
53 {
54 .id = 0x38,
55 .name = "9eg",
56 },
57 {
58 .id = 0x39,
59 .name = "6eg",
60 },
61 {
62 .id = 0x40,
63 .name = "11eg",
64 },
65 {
66 .id = 0x50,
67 .name = "15eg",
68 },
69 {
70 .id = 0x58,
71 .name = "19eg",
72 },
73 {
74 .id = 0x59,
75 .name = "17eg",
76 },
77};
78
79static int chip_id(void)
80{
81 struct pt_regs regs;
82 regs.regs[0] = ZYNQMP_SIP_SVC_CSU_DMA_CHIPID;
83 regs.regs[1] = 0;
84 regs.regs[2] = 0;
85 regs.regs[3] = 0;
86
87 smc_call(&regs);
88
Soren Brinkmannd7696a52016-09-29 11:44:41 -070089 /*
90 * SMC returns:
91 * regs[0][31:0] = status of the operation
92 * regs[0][63:32] = CSU.IDCODE register
93 * regs[1][31:0] = CSU.version register
94 */
95 regs.regs[0] = upper_32_bits(regs.regs[0]);
96 regs.regs[0] &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK |
97 ZYNQMP_CSU_IDCODE_SVD_MASK;
98 regs.regs[0] >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT;
99
Michal Simek8111aff2016-02-01 15:05:58 +0100100 return regs.regs[0];
101}
102
103static char *zynqmp_get_silicon_idcode_name(void)
104{
105 uint32_t i, id;
106
107 id = chip_id();
108 for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) {
109 if (zynqmp_devices[i].id == id)
110 return zynqmp_devices[i].name;
111 }
112 return "unknown";
113}
114#endif
115
Michal Simek8b353302017-02-07 14:32:26 +0100116int board_early_init_f(void)
117{
118#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_CLK_ZYNQMP)
119 zynqmp_pmufw_version();
120#endif
121 return 0;
122}
123
Michal Simek8111aff2016-02-01 15:05:58 +0100124#define ZYNQMP_VERSION_SIZE 9
125
Michal Simek04b7e622015-01-15 10:01:51 +0100126int board_init(void)
127{
Michal Simekfb7242d2015-06-22 14:31:06 +0200128 printf("EL Level:\tEL%d\n", current_el());
129
Michal Simek8111aff2016-02-01 15:05:58 +0100130#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
131 !defined(CONFIG_SPL_BUILD) || (defined(CONFIG_SPL_FPGA_SUPPORT) && \
132 defined(CONFIG_SPL_BUILD))
133 if (current_el() != 3) {
134 static char version[ZYNQMP_VERSION_SIZE];
135
136 strncat(version, "xczu", ZYNQMP_VERSION_SIZE);
137 zynqmppl.name = strncat(version,
138 zynqmp_get_silicon_idcode_name(),
139 ZYNQMP_VERSION_SIZE);
140 printf("Chip ID:\t%s\n", zynqmppl.name);
141 fpga_init();
142 fpga_add(fpga_xilinx, &zynqmppl);
143 }
144#endif
145
Michal Simek04b7e622015-01-15 10:01:51 +0100146 return 0;
147}
148
149int board_early_init_r(void)
150{
151 u32 val;
152
Michal Simekc23d3f82015-11-05 08:34:35 +0100153 if (current_el() == 3) {
154 val = readl(&crlapb_base->timestamp_ref_ctrl);
155 val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
156 writel(val, &crlapb_base->timestamp_ref_ctrl);
Michal Simek04b7e622015-01-15 10:01:51 +0100157
Michal Simekc23d3f82015-11-05 08:34:35 +0100158 /* Program freq register in System counter */
159 writel(zynqmp_get_system_timer_freq(),
160 &iou_scntr_secure->base_frequency_id_register);
161 /* And enable system counter */
162 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
163 &iou_scntr_secure->counter_control_register);
164 }
Michal Simek04b7e622015-01-15 10:01:51 +0100165 /* Program freq register in System counter and enable system counter */
166 writel(gd->cpu_clk, &iou_scntr->base_frequency_id_register);
167 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_HDBG |
168 ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
169 &iou_scntr->counter_control_register);
170
171 return 0;
172}
173
Michal Simekeec32f62016-04-22 11:48:49 +0200174int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
175{
176#if defined(CONFIG_ZYNQ_GEM_EEPROM_ADDR) && \
177 defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET) && \
178 defined(CONFIG_ZYNQ_EEPROM_BUS)
179 i2c_set_bus_num(CONFIG_ZYNQ_EEPROM_BUS);
180
181 if (eeprom_read(CONFIG_ZYNQ_GEM_EEPROM_ADDR,
182 CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET,
183 ethaddr, 6))
184 printf("I2C EEPROM MAC address read failed\n");
185#endif
186
187 return 0;
188}
189
Michal Simek8faa66a2016-02-08 09:34:53 +0100190#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
Simon Glass2f949c32017-03-31 08:40:32 -0600191int dram_init_banksize(void)
Michal Simek8faa66a2016-02-08 09:34:53 +0100192{
Nathan Rossiac04bfa2016-12-19 00:03:34 +1000193 fdtdec_setup_memory_banksize();
Simon Glass2f949c32017-03-31 08:40:32 -0600194
195 return 0;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500196}
Michal Simek8faa66a2016-02-08 09:34:53 +0100197
Tom Riniedcfdbd2016-12-09 07:56:54 -0500198int dram_init(void)
199{
Nathan Rossiac04bfa2016-12-19 00:03:34 +1000200 if (fdtdec_setup_memory_size() != 0)
201 return -EINVAL;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500202
203 return 0;
Michal Simek8faa66a2016-02-08 09:34:53 +0100204}
205#else
Michal Simek04b7e622015-01-15 10:01:51 +0100206int dram_init(void)
207{
208 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
209
210 return 0;
211}
Michal Simek8faa66a2016-02-08 09:34:53 +0100212#endif
Michal Simek04b7e622015-01-15 10:01:51 +0100213
Michal Simek04b7e622015-01-15 10:01:51 +0100214void reset_cpu(ulong addr)
215{
216}
217
Michal Simek04b7e622015-01-15 10:01:51 +0100218int board_late_init(void)
219{
220 u32 reg = 0;
221 u8 bootmode;
Michal Simekecfb6dc2016-04-22 14:28:54 +0200222 const char *mode;
223 char *new_targets;
224
225 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
226 debug("Saved variables - Skipping\n");
227 return 0;
228 }
Michal Simek04b7e622015-01-15 10:01:51 +0100229
230 reg = readl(&crlapb_base->boot_mode);
Michal Simek833e0c42016-10-25 11:43:02 +0200231 if (reg >> BOOT_MODE_ALT_SHIFT)
232 reg >>= BOOT_MODE_ALT_SHIFT;
233
Michal Simek04b7e622015-01-15 10:01:51 +0100234 bootmode = reg & BOOT_MODES_MASK;
235
Michal Simekc5d95232015-09-20 17:20:42 +0200236 puts("Bootmode: ");
Michal Simek04b7e622015-01-15 10:01:51 +0100237 switch (bootmode) {
Michal Simek12398ea2016-08-19 14:14:52 +0200238 case USB_MODE:
239 puts("USB_MODE\n");
240 mode = "usb";
241 break;
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530242 case JTAG_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200243 puts("JTAG_MODE\n");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200244 mode = "pxe dhcp";
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530245 break;
246 case QSPI_MODE_24BIT:
247 case QSPI_MODE_32BIT:
Michal Simekecfb6dc2016-04-22 14:28:54 +0200248 mode = "qspi0";
Michal Simekc5d95232015-09-20 17:20:42 +0200249 puts("QSPI_MODE\n");
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530250 break;
Michal Simek02d66cd2015-04-15 15:02:28 +0200251 case EMMC_MODE:
Michal Simekdf7ff0a2015-10-05 15:59:38 +0200252 puts("EMMC_MODE\n");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200253 mode = "mmc0";
Michal Simekdf7ff0a2015-10-05 15:59:38 +0200254 break;
255 case SD_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200256 puts("SD_MODE\n");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200257 mode = "mmc0";
Michal Simek04b7e622015-01-15 10:01:51 +0100258 break;
Siva Durga Prasad Paladugu29a77d22016-09-21 11:45:05 +0530259 case SD1_LSHFT_MODE:
260 puts("LVL_SHFT_");
261 /* fall through */
Michal Simek108e1842015-10-05 10:51:12 +0200262 case SD_MODE1:
Michal Simekc5d95232015-09-20 17:20:42 +0200263 puts("SD_MODE1\n");
Michal Simek6d902452015-11-06 10:22:37 +0100264#if defined(CONFIG_ZYNQ_SDHCI0) && defined(CONFIG_ZYNQ_SDHCI1)
Michal Simekecfb6dc2016-04-22 14:28:54 +0200265 mode = "mmc1";
266#else
267 mode = "mmc0";
Michal Simek6d902452015-11-06 10:22:37 +0100268#endif
Michal Simek108e1842015-10-05 10:51:12 +0200269 break;
270 case NAND_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200271 puts("NAND_MODE\n");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200272 mode = "nand0";
Michal Simek108e1842015-10-05 10:51:12 +0200273 break;
Michal Simek04b7e622015-01-15 10:01:51 +0100274 default:
Michal Simekecfb6dc2016-04-22 14:28:54 +0200275 mode = "";
Michal Simek04b7e622015-01-15 10:01:51 +0100276 printf("Invalid Boot Mode:0x%x\n", bootmode);
277 break;
278 }
279
Michal Simekecfb6dc2016-04-22 14:28:54 +0200280 /*
281 * One terminating char + one byte for space between mode
282 * and default boot_targets
283 */
284 new_targets = calloc(1, strlen(mode) +
285 strlen(getenv("boot_targets")) + 2);
286
287 sprintf(new_targets, "%s %s", mode, getenv("boot_targets"));
288 setenv("boot_targets", new_targets);
289
Michal Simek04b7e622015-01-15 10:01:51 +0100290 return 0;
291}
Siva Durga Prasad Paladugu650e0a32015-08-04 13:01:05 +0530292
293int checkboard(void)
294{
Michal Simek47ce9362016-01-25 11:04:21 +0100295 puts("Board: Xilinx ZynqMP\n");
Siva Durga Prasad Paladugu650e0a32015-08-04 13:01:05 +0530296 return 0;
297}
Siva Durga Prasad Paladuguba1f68e2015-08-04 13:03:26 +0530298
299#ifdef CONFIG_USB_DWC3
Michal Simekea526be2016-08-08 10:11:26 +0200300static struct dwc3_device dwc3_device_data0 = {
Siva Durga Prasad Paladuguba1f68e2015-08-04 13:03:26 +0530301 .maximum_speed = USB_SPEED_HIGH,
302 .base = ZYNQMP_USB0_XHCI_BASEADDR,
303 .dr_mode = USB_DR_MODE_PERIPHERAL,
304 .index = 0,
305};
306
Michal Simekea526be2016-08-08 10:11:26 +0200307static struct dwc3_device dwc3_device_data1 = {
308 .maximum_speed = USB_SPEED_HIGH,
309 .base = ZYNQMP_USB1_XHCI_BASEADDR,
310 .dr_mode = USB_DR_MODE_PERIPHERAL,
311 .index = 1,
312};
313
Michal Simek76d0a772016-09-01 11:16:40 +0200314int usb_gadget_handle_interrupts(int index)
Siva Durga Prasad Paladuguba1f68e2015-08-04 13:03:26 +0530315{
Michal Simek76d0a772016-09-01 11:16:40 +0200316 dwc3_uboot_handle_interrupt(index);
Siva Durga Prasad Paladuguba1f68e2015-08-04 13:03:26 +0530317 return 0;
318}
319
320int board_usb_init(int index, enum usb_init_type init)
321{
Michal Simekea526be2016-08-08 10:11:26 +0200322 debug("%s: index %x\n", __func__, index);
323
Michal Simek7987d2a2016-09-01 11:27:32 +0200324#if defined(CONFIG_USB_GADGET_DOWNLOAD)
325 g_dnl_set_serialnumber(CONFIG_SYS_CONFIG_NAME);
326#endif
327
Michal Simekea526be2016-08-08 10:11:26 +0200328 switch (index) {
329 case 0:
330 return dwc3_uboot_init(&dwc3_device_data0);
331 case 1:
332 return dwc3_uboot_init(&dwc3_device_data1);
333 };
334
335 return -1;
Siva Durga Prasad Paladuguba1f68e2015-08-04 13:03:26 +0530336}
337
338int board_usb_cleanup(int index, enum usb_init_type init)
339{
340 dwc3_uboot_exit(index);
341 return 0;
342}
343#endif