blob: 07e048681783effe4d789c4f6b46afa961ab489c [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};
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +053078#endif
Michal Simek8111aff2016-02-01 15:05:58 +010079
Siva Durga Prasad Paladugucd35d522017-07-25 11:51:38 +053080int chip_id(unsigned char id)
Michal Simek8111aff2016-02-01 15:05:58 +010081{
82 struct pt_regs regs;
Siva Durga Prasad Paladugu9f0a8e92017-07-25 11:51:36 +053083 int val = -EINVAL;
Michal Simek8111aff2016-02-01 15:05:58 +010084
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +053085 if (current_el() != 3) {
86 regs.regs[0] = ZYNQMP_SIP_SVC_CSU_DMA_CHIPID;
87 regs.regs[1] = 0;
88 regs.regs[2] = 0;
89 regs.regs[3] = 0;
Michal Simek8111aff2016-02-01 15:05:58 +010090
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +053091 smc_call(&regs);
92
93 /*
94 * SMC returns:
95 * regs[0][31:0] = status of the operation
96 * regs[0][63:32] = CSU.IDCODE register
97 * regs[1][31:0] = CSU.version register
98 */
99 switch (id) {
100 case IDCODE:
101 regs.regs[0] = upper_32_bits(regs.regs[0]);
102 regs.regs[0] &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK |
103 ZYNQMP_CSU_IDCODE_SVD_MASK;
104 regs.regs[0] >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT;
105 val = regs.regs[0];
106 break;
107 case VERSION:
108 regs.regs[1] = lower_32_bits(regs.regs[1]);
109 regs.regs[1] &= ZYNQMP_CSU_SILICON_VER_MASK;
110 val = regs.regs[1];
111 break;
112 default:
113 printf("%s, Invalid Req:0x%x\n", __func__, id);
114 }
115 } else {
116 switch (id) {
117 case IDCODE:
118 val = readl(ZYNQMP_CSU_IDCODE_ADDR);
119 val &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK |
120 ZYNQMP_CSU_IDCODE_SVD_MASK;
121 val >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT;
122 break;
123 case VERSION:
124 val = readl(ZYNQMP_CSU_VER_ADDR);
125 val &= ZYNQMP_CSU_SILICON_VER_MASK;
126 break;
127 default:
128 printf("%s, Invalid Req:0x%x\n", __func__, id);
129 }
Siva Durga Prasad Paladugu9f0a8e92017-07-25 11:51:36 +0530130 }
Soren Brinkmannd7696a52016-09-29 11:44:41 -0700131
Siva Durga Prasad Paladugu9f0a8e92017-07-25 11:51:36 +0530132 return val;
Michal Simek8111aff2016-02-01 15:05:58 +0100133}
134
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530135#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
136 !defined(CONFIG_SPL_BUILD)
Michal Simek8111aff2016-02-01 15:05:58 +0100137static char *zynqmp_get_silicon_idcode_name(void)
138{
139 uint32_t i, id;
140
Siva Durga Prasad Paladugu9f0a8e92017-07-25 11:51:36 +0530141 id = chip_id(IDCODE);
Michal Simek8111aff2016-02-01 15:05:58 +0100142 for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) {
143 if (zynqmp_devices[i].id == id)
144 return zynqmp_devices[i].name;
145 }
146 return "unknown";
147}
148#endif
149
Michal Simek8b353302017-02-07 14:32:26 +0100150int board_early_init_f(void)
151{
152#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_CLK_ZYNQMP)
153 zynqmp_pmufw_version();
154#endif
Michal Simeke0f36102017-07-12 13:08:41 +0200155
Michal Simekd8218792017-07-12 13:21:27 +0200156#if defined(CONFIG_SPL_BUILD) || defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED)
Michal Simeke0f36102017-07-12 13:08:41 +0200157 psu_init();
158#endif
159
Michal Simek8b353302017-02-07 14:32:26 +0100160 return 0;
161}
162
Michal Simek8111aff2016-02-01 15:05:58 +0100163#define ZYNQMP_VERSION_SIZE 9
164
Michal Simek04b7e622015-01-15 10:01:51 +0100165int board_init(void)
166{
Michal Simekfb7242d2015-06-22 14:31:06 +0200167 printf("EL Level:\tEL%d\n", current_el());
168
Michal Simek8111aff2016-02-01 15:05:58 +0100169#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
170 !defined(CONFIG_SPL_BUILD) || (defined(CONFIG_SPL_FPGA_SUPPORT) && \
171 defined(CONFIG_SPL_BUILD))
172 if (current_el() != 3) {
173 static char version[ZYNQMP_VERSION_SIZE];
174
175 strncat(version, "xczu", ZYNQMP_VERSION_SIZE);
176 zynqmppl.name = strncat(version,
177 zynqmp_get_silicon_idcode_name(),
178 ZYNQMP_VERSION_SIZE);
179 printf("Chip ID:\t%s\n", zynqmppl.name);
180 fpga_init();
181 fpga_add(fpga_xilinx, &zynqmppl);
182 }
183#endif
184
Michal Simek04b7e622015-01-15 10:01:51 +0100185 return 0;
186}
187
188int board_early_init_r(void)
189{
190 u32 val;
191
Michal Simek245d5282017-07-12 10:32:18 +0200192 val = readl(&crlapb_base->timestamp_ref_ctrl);
193 val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
194
195 if (current_el() == 3 && !val) {
Michal Simekc23d3f82015-11-05 08:34:35 +0100196 val = readl(&crlapb_base->timestamp_ref_ctrl);
197 val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
198 writel(val, &crlapb_base->timestamp_ref_ctrl);
Michal Simek04b7e622015-01-15 10:01:51 +0100199
Michal Simekc23d3f82015-11-05 08:34:35 +0100200 /* Program freq register in System counter */
201 writel(zynqmp_get_system_timer_freq(),
202 &iou_scntr_secure->base_frequency_id_register);
203 /* And enable system counter */
204 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
205 &iou_scntr_secure->counter_control_register);
206 }
Michal Simek04b7e622015-01-15 10:01:51 +0100207 return 0;
208}
209
Michal Simekeec32f62016-04-22 11:48:49 +0200210int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
211{
212#if defined(CONFIG_ZYNQ_GEM_EEPROM_ADDR) && \
213 defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET) && \
214 defined(CONFIG_ZYNQ_EEPROM_BUS)
215 i2c_set_bus_num(CONFIG_ZYNQ_EEPROM_BUS);
216
217 if (eeprom_read(CONFIG_ZYNQ_GEM_EEPROM_ADDR,
218 CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET,
219 ethaddr, 6))
220 printf("I2C EEPROM MAC address read failed\n");
221#endif
222
223 return 0;
224}
225
Michal Simek8faa66a2016-02-08 09:34:53 +0100226#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
Simon Glass2f949c32017-03-31 08:40:32 -0600227int dram_init_banksize(void)
Michal Simek8faa66a2016-02-08 09:34:53 +0100228{
Nathan Rossiac04bfa2016-12-19 00:03:34 +1000229 fdtdec_setup_memory_banksize();
Simon Glass2f949c32017-03-31 08:40:32 -0600230
231 return 0;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500232}
Michal Simek8faa66a2016-02-08 09:34:53 +0100233
Tom Riniedcfdbd2016-12-09 07:56:54 -0500234int dram_init(void)
235{
Nathan Rossiac04bfa2016-12-19 00:03:34 +1000236 if (fdtdec_setup_memory_size() != 0)
237 return -EINVAL;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500238
239 return 0;
Michal Simek8faa66a2016-02-08 09:34:53 +0100240}
241#else
Michal Simek04b7e622015-01-15 10:01:51 +0100242int dram_init(void)
243{
244 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
245
246 return 0;
247}
Michal Simek8faa66a2016-02-08 09:34:53 +0100248#endif
Michal Simek04b7e622015-01-15 10:01:51 +0100249
Michal Simek04b7e622015-01-15 10:01:51 +0100250void reset_cpu(ulong addr)
251{
252}
253
Michal Simek04b7e622015-01-15 10:01:51 +0100254int board_late_init(void)
255{
256 u32 reg = 0;
257 u8 bootmode;
Michal Simekecfb6dc2016-04-22 14:28:54 +0200258 const char *mode;
259 char *new_targets;
260
261 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
262 debug("Saved variables - Skipping\n");
263 return 0;
264 }
Michal Simek04b7e622015-01-15 10:01:51 +0100265
266 reg = readl(&crlapb_base->boot_mode);
Michal Simek833e0c42016-10-25 11:43:02 +0200267 if (reg >> BOOT_MODE_ALT_SHIFT)
268 reg >>= BOOT_MODE_ALT_SHIFT;
269
Michal Simek04b7e622015-01-15 10:01:51 +0100270 bootmode = reg & BOOT_MODES_MASK;
271
Michal Simekc5d95232015-09-20 17:20:42 +0200272 puts("Bootmode: ");
Michal Simek04b7e622015-01-15 10:01:51 +0100273 switch (bootmode) {
Michal Simek12398ea2016-08-19 14:14:52 +0200274 case USB_MODE:
275 puts("USB_MODE\n");
276 mode = "usb";
277 break;
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530278 case JTAG_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200279 puts("JTAG_MODE\n");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200280 mode = "pxe dhcp";
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530281 break;
282 case QSPI_MODE_24BIT:
283 case QSPI_MODE_32BIT:
Michal Simekecfb6dc2016-04-22 14:28:54 +0200284 mode = "qspi0";
Michal Simekc5d95232015-09-20 17:20:42 +0200285 puts("QSPI_MODE\n");
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530286 break;
Michal Simek02d66cd2015-04-15 15:02:28 +0200287 case EMMC_MODE:
Michal Simekdf7ff0a2015-10-05 15:59:38 +0200288 puts("EMMC_MODE\n");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200289 mode = "mmc0";
Michal Simekdf7ff0a2015-10-05 15:59:38 +0200290 break;
291 case SD_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200292 puts("SD_MODE\n");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200293 mode = "mmc0";
Michal Simek04b7e622015-01-15 10:01:51 +0100294 break;
Siva Durga Prasad Paladugu29a77d22016-09-21 11:45:05 +0530295 case SD1_LSHFT_MODE:
296 puts("LVL_SHFT_");
297 /* fall through */
Michal Simek108e1842015-10-05 10:51:12 +0200298 case SD_MODE1:
Michal Simekc5d95232015-09-20 17:20:42 +0200299 puts("SD_MODE1\n");
Michal Simek6d902452015-11-06 10:22:37 +0100300#if defined(CONFIG_ZYNQ_SDHCI0) && defined(CONFIG_ZYNQ_SDHCI1)
Michal Simekecfb6dc2016-04-22 14:28:54 +0200301 mode = "mmc1";
302#else
303 mode = "mmc0";
Michal Simek6d902452015-11-06 10:22:37 +0100304#endif
Michal Simek108e1842015-10-05 10:51:12 +0200305 break;
306 case NAND_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200307 puts("NAND_MODE\n");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200308 mode = "nand0";
Michal Simek108e1842015-10-05 10:51:12 +0200309 break;
Michal Simek04b7e622015-01-15 10:01:51 +0100310 default:
Michal Simekecfb6dc2016-04-22 14:28:54 +0200311 mode = "";
Michal Simek04b7e622015-01-15 10:01:51 +0100312 printf("Invalid Boot Mode:0x%x\n", bootmode);
313 break;
314 }
315
Michal Simekecfb6dc2016-04-22 14:28:54 +0200316 /*
317 * One terminating char + one byte for space between mode
318 * and default boot_targets
319 */
320 new_targets = calloc(1, strlen(mode) +
321 strlen(getenv("boot_targets")) + 2);
322
323 sprintf(new_targets, "%s %s", mode, getenv("boot_targets"));
324 setenv("boot_targets", new_targets);
325
Michal Simek04b7e622015-01-15 10:01:51 +0100326 return 0;
327}
Siva Durga Prasad Paladugu650e0a32015-08-04 13:01:05 +0530328
329int checkboard(void)
330{
Michal Simek47ce9362016-01-25 11:04:21 +0100331 puts("Board: Xilinx ZynqMP\n");
Siva Durga Prasad Paladugu650e0a32015-08-04 13:01:05 +0530332 return 0;
333}
Siva Durga Prasad Paladuguba1f68e2015-08-04 13:03:26 +0530334
335#ifdef CONFIG_USB_DWC3
Michal Simekea526be2016-08-08 10:11:26 +0200336static struct dwc3_device dwc3_device_data0 = {
Siva Durga Prasad Paladuguba1f68e2015-08-04 13:03:26 +0530337 .maximum_speed = USB_SPEED_HIGH,
338 .base = ZYNQMP_USB0_XHCI_BASEADDR,
339 .dr_mode = USB_DR_MODE_PERIPHERAL,
340 .index = 0,
341};
342
Michal Simekea526be2016-08-08 10:11:26 +0200343static struct dwc3_device dwc3_device_data1 = {
344 .maximum_speed = USB_SPEED_HIGH,
345 .base = ZYNQMP_USB1_XHCI_BASEADDR,
346 .dr_mode = USB_DR_MODE_PERIPHERAL,
347 .index = 1,
348};
349
Michal Simek76d0a772016-09-01 11:16:40 +0200350int usb_gadget_handle_interrupts(int index)
Siva Durga Prasad Paladuguba1f68e2015-08-04 13:03:26 +0530351{
Michal Simek76d0a772016-09-01 11:16:40 +0200352 dwc3_uboot_handle_interrupt(index);
Siva Durga Prasad Paladuguba1f68e2015-08-04 13:03:26 +0530353 return 0;
354}
355
356int board_usb_init(int index, enum usb_init_type init)
357{
Michal Simekea526be2016-08-08 10:11:26 +0200358 debug("%s: index %x\n", __func__, index);
359
Michal Simek7987d2a2016-09-01 11:27:32 +0200360#if defined(CONFIG_USB_GADGET_DOWNLOAD)
361 g_dnl_set_serialnumber(CONFIG_SYS_CONFIG_NAME);
362#endif
363
Michal Simekea526be2016-08-08 10:11:26 +0200364 switch (index) {
365 case 0:
366 return dwc3_uboot_init(&dwc3_device_data0);
367 case 1:
368 return dwc3_uboot_init(&dwc3_device_data1);
369 };
370
371 return -1;
Siva Durga Prasad Paladuguba1f68e2015-08-04 13:03:26 +0530372}
373
374int board_usb_cleanup(int index, enum usb_init_type init)
375{
376 dwc3_uboot_exit(index);
377 return 0;
378}
379#endif