blob: 2c86940957ec5d021e045d6a34be3c9f133f1a7a [file] [log] [blame]
Michal Simekf22651c2012-09-28 09:56:37 +00001/*
2 * (C) Copyright 2012 Michal Simek <monstr@monstr.eu>
3 *
Wolfgang Denk3765b3e2013-10-07 13:07:26 +02004 * SPDX-License-Identifier: GPL-2.0+
Michal Simekf22651c2012-09-28 09:56:37 +00005 */
6
7#include <common.h>
Michal Simek9e0e37a2014-02-24 11:16:32 +01008#include <fdtdec.h>
Michal Simek5b73caf2014-04-25 13:51:17 +02009#include <fpga.h>
10#include <mmc.h>
Michal Simekd5dae852013-04-22 15:43:02 +020011#include <zynqpl.h>
Michal Simek71936532013-04-12 16:33:08 +020012#include <asm/arch/hardware.h>
13#include <asm/arch/sys_proto.h>
Michal Simekf22651c2012-09-28 09:56:37 +000014
15DECLARE_GLOBAL_DATA_PTR;
16
Michal Simek0b680202014-03-04 12:41:05 +010017#if (defined(CONFIG_FPGA) && !defined(CONFIG_SPL_BUILD)) || \
18 (defined(CONFIG_SPL_FPGA_SUPPORT) && defined(CONFIG_SPL_BUILD))
Michal Simek5b73caf2014-04-25 13:51:17 +020019static xilinx_desc fpga;
Michal Simekd5dae852013-04-22 15:43:02 +020020
21/* It can be done differently */
Michal Simek05c59d02016-10-18 16:10:25 +020022static xilinx_desc fpga007s = XILINX_XC7Z007S_DESC(0x7);
Michal Simek5b73caf2014-04-25 13:51:17 +020023static xilinx_desc fpga010 = XILINX_XC7Z010_DESC(0x10);
Michal Simek05c59d02016-10-18 16:10:25 +020024static xilinx_desc fpga012s = XILINX_XC7Z012S_DESC(0x12);
25static xilinx_desc fpga014s = XILINX_XC7Z014S_DESC(0x14);
Michal Simek5b73caf2014-04-25 13:51:17 +020026static xilinx_desc fpga015 = XILINX_XC7Z015_DESC(0x15);
27static xilinx_desc fpga020 = XILINX_XC7Z020_DESC(0x20);
28static xilinx_desc fpga030 = XILINX_XC7Z030_DESC(0x30);
Siva Durga Prasad Paladugub9103802014-11-25 15:29:54 +053029static xilinx_desc fpga035 = XILINX_XC7Z035_DESC(0x35);
Michal Simek5b73caf2014-04-25 13:51:17 +020030static xilinx_desc fpga045 = XILINX_XC7Z045_DESC(0x45);
31static xilinx_desc fpga100 = XILINX_XC7Z100_DESC(0x100);
Michal Simekd5dae852013-04-22 15:43:02 +020032#endif
33
Michal Simekf22651c2012-09-28 09:56:37 +000034int board_init(void)
35{
Michal Simek0b680202014-03-04 12:41:05 +010036#if (defined(CONFIG_FPGA) && !defined(CONFIG_SPL_BUILD)) || \
37 (defined(CONFIG_SPL_FPGA_SUPPORT) && defined(CONFIG_SPL_BUILD))
Michal Simekd5dae852013-04-22 15:43:02 +020038 u32 idcode;
39
40 idcode = zynq_slcr_get_idcode();
41
42 switch (idcode) {
Michal Simek05c59d02016-10-18 16:10:25 +020043 case XILINX_ZYNQ_7007S:
44 fpga = fpga007s;
45 break;
Michal Simekd5dae852013-04-22 15:43:02 +020046 case XILINX_ZYNQ_7010:
47 fpga = fpga010;
48 break;
Michal Simek05c59d02016-10-18 16:10:25 +020049 case XILINX_ZYNQ_7012S:
50 fpga = fpga012s;
51 break;
52 case XILINX_ZYNQ_7014S:
53 fpga = fpga014s;
54 break;
Michal Simek31993d62013-09-26 16:39:03 +020055 case XILINX_ZYNQ_7015:
56 fpga = fpga015;
57 break;
Michal Simekd5dae852013-04-22 15:43:02 +020058 case XILINX_ZYNQ_7020:
59 fpga = fpga020;
60 break;
61 case XILINX_ZYNQ_7030:
62 fpga = fpga030;
63 break;
Siva Durga Prasad Paladugub9103802014-11-25 15:29:54 +053064 case XILINX_ZYNQ_7035:
65 fpga = fpga035;
66 break;
Michal Simekd5dae852013-04-22 15:43:02 +020067 case XILINX_ZYNQ_7045:
68 fpga = fpga045;
69 break;
Michal Simekfd2b10b2013-06-17 13:54:07 +020070 case XILINX_ZYNQ_7100:
71 fpga = fpga100;
72 break;
Michal Simekd5dae852013-04-22 15:43:02 +020073 }
74#endif
75
Michal Simek0b680202014-03-04 12:41:05 +010076#if (defined(CONFIG_FPGA) && !defined(CONFIG_SPL_BUILD)) || \
77 (defined(CONFIG_SPL_FPGA_SUPPORT) && defined(CONFIG_SPL_BUILD))
Michal Simekd5dae852013-04-22 15:43:02 +020078 fpga_init();
79 fpga_add(fpga_xilinx, &fpga);
80#endif
81
Michal Simekf22651c2012-09-28 09:56:37 +000082 return 0;
83}
84
Jagannadha Sutradharudu Tekib3de9242014-01-09 01:48:21 +053085int board_late_init(void)
86{
87 switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) {
88 case ZYNQ_BM_NOR:
89 setenv("modeboot", "norboot");
90 break;
91 case ZYNQ_BM_SD:
92 setenv("modeboot", "sdboot");
93 break;
94 case ZYNQ_BM_JTAG:
95 setenv("modeboot", "jtagboot");
96 break;
97 default:
98 setenv("modeboot", "");
99 break;
100 }
101
102 return 0;
103}
Michal Simekf22651c2012-09-28 09:56:37 +0000104
Michal Simek5a82d532014-08-28 13:31:02 +0200105#ifdef CONFIG_DISPLAY_BOARDINFO
106int checkboard(void)
107{
Michal Simek5af08552016-01-25 11:04:21 +0100108 puts("Board: Xilinx Zynq\n");
Michal Simek5a82d532014-08-28 13:31:02 +0200109 return 0;
110}
111#endif
112
Joe Hershbergera509a1d2016-01-26 11:57:03 -0600113int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
114{
115#if defined(CONFIG_ZYNQ_GEM_EEPROM_ADDR) && \
116 defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET)
117 if (eeprom_read(CONFIG_ZYNQ_GEM_EEPROM_ADDR,
118 CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET,
119 ethaddr, 6))
120 printf("I2C EEPROM MAC address read failed\n");
121#endif
122
123 return 0;
124}
125
Michal Simek758f29d2016-04-01 15:56:33 +0200126#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
127/*
128 * fdt_get_reg - Fill buffer by information from DT
129 */
130static phys_size_t fdt_get_reg(const void *fdt, int nodeoffset, void *buf,
131 const u32 *cell, int n)
132{
133 int i = 0, b, banks;
134 int parent_offset = fdt_parent_offset(fdt, nodeoffset);
135 int address_cells = fdt_address_cells(fdt, parent_offset);
136 int size_cells = fdt_size_cells(fdt, parent_offset);
137 char *p = buf;
138 u64 val;
139 u64 vals;
140
141 debug("%s: addr_cells=%x, size_cell=%x, buf=%p, cell=%p\n",
142 __func__, address_cells, size_cells, buf, cell);
143
144 /* Check memory bank setup */
145 banks = n % (address_cells + size_cells);
146 if (banks)
147 panic("Incorrect memory setup cells=%d, ac=%d, sc=%d\n",
148 n, address_cells, size_cells);
149
150 banks = n / (address_cells + size_cells);
151
152 for (b = 0; b < banks; b++) {
153 debug("%s: Bank #%d:\n", __func__, b);
154 if (address_cells == 2) {
155 val = cell[i + 1];
156 val <<= 32;
157 val |= cell[i];
158 val = fdt64_to_cpu(val);
159 debug("%s: addr64=%llx, ptr=%p, cell=%p\n",
160 __func__, val, p, &cell[i]);
161 *(phys_addr_t *)p = val;
162 } else {
163 debug("%s: addr32=%x, ptr=%p\n",
164 __func__, fdt32_to_cpu(cell[i]), p);
165 *(phys_addr_t *)p = fdt32_to_cpu(cell[i]);
166 }
167 p += sizeof(phys_addr_t);
168 i += address_cells;
169
170 debug("%s: pa=%p, i=%x, size=%zu\n", __func__, p, i,
171 sizeof(phys_addr_t));
172
173 if (size_cells == 2) {
174 vals = cell[i + 1];
175 vals <<= 32;
176 vals |= cell[i];
177 vals = fdt64_to_cpu(vals);
178
179 debug("%s: size64=%llx, ptr=%p, cell=%p\n",
180 __func__, vals, p, &cell[i]);
181 *(phys_size_t *)p = vals;
182 } else {
183 debug("%s: size32=%x, ptr=%p\n",
184 __func__, fdt32_to_cpu(cell[i]), p);
185 *(phys_size_t *)p = fdt32_to_cpu(cell[i]);
186 }
187 p += sizeof(phys_size_t);
188 i += size_cells;
189
190 debug("%s: ps=%p, i=%x, size=%zu\n",
191 __func__, p, i, sizeof(phys_size_t));
192 }
193
194 /* Return the first address size */
195 return *(phys_size_t *)((char *)buf + sizeof(phys_addr_t));
196}
197
198#define FDT_REG_SIZE sizeof(u32)
199/* Temp location for sharing data for storing */
200/* Up to 64-bit address + 64-bit size */
201static u8 tmp[CONFIG_NR_DRAM_BANKS * 16];
202
203void dram_init_banksize(void)
204{
205 int bank;
206
207 memcpy(&gd->bd->bi_dram[0], &tmp, sizeof(tmp));
208
209 for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
210 debug("Bank #%d: start %llx\n", bank,
211 (unsigned long long)gd->bd->bi_dram[bank].start);
212 debug("Bank #%d: size %llx\n", bank,
213 (unsigned long long)gd->bd->bi_dram[bank].size);
214 }
215}
216
Michal Simekf22651c2012-09-28 09:56:37 +0000217int dram_init(void)
218{
Michal Simek758f29d2016-04-01 15:56:33 +0200219 int node, len;
Michal Simek9e0e37a2014-02-24 11:16:32 +0100220 const void *blob = gd->fdt_blob;
Michal Simek758f29d2016-04-01 15:56:33 +0200221 const u32 *cell;
Michal Simekf22651c2012-09-28 09:56:37 +0000222
Michal Simek758f29d2016-04-01 15:56:33 +0200223 memset(&tmp, 0, sizeof(tmp));
224
225 /* find or create "/memory" node. */
226 node = fdt_subnode_offset(blob, 0, "memory");
227 if (node < 0) {
228 printf("%s: Can't get memory node\n", __func__);
229 return node;
230 }
231
232 /* Get pointer to cells and lenght of it */
233 cell = fdt_getprop(blob, node, "reg", &len);
234 if (!cell) {
235 printf("%s: Can't get reg property\n", __func__);
Michal Simek9e0e37a2014-02-24 11:16:32 +0100236 return -1;
237 }
Michal Simek758f29d2016-04-01 15:56:33 +0200238
239 gd->ram_size = fdt_get_reg(blob, node, &tmp, cell, len / FDT_REG_SIZE);
240
241 debug("%s: Initial DRAM size %llx\n", __func__, (u64)gd->ram_size);
242
Michal Simek148ba552013-06-17 14:37:01 +0200243 zynq_ddrc_init();
244
Michal Simekf22651c2012-09-28 09:56:37 +0000245 return 0;
246}
Michal Simek758f29d2016-04-01 15:56:33 +0200247#else
248int dram_init(void)
249{
250 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
251
252 zynq_ddrc_init();
253
254 return 0;
255}
256#endif