blob: c5e7b99d9752f545a36b8c9996ef8593099f424f [file] [log] [blame]
Michal Simekaf482d52012-09-28 09:56:37 +00001/*
2 * (C) Copyright 2012 Michal Simek <monstr@monstr.eu>
3 *
Wolfgang Denkbd8ec7e2013-10-07 13:07:26 +02004 * SPDX-License-Identifier: GPL-2.0+
Michal Simekaf482d52012-09-28 09:56:37 +00005 */
6
7#include <common.h>
Michal Simek65ef52f2014-02-24 11:16:32 +01008#include <fdtdec.h>
Michal Simek0f796702014-04-25 13:51:17 +02009#include <fpga.h>
10#include <mmc.h>
Michal Simek15d654c2013-04-22 15:43:02 +020011#include <zynqpl.h>
Michal Simek242192b2013-04-12 16:33:08 +020012#include <asm/arch/hardware.h>
13#include <asm/arch/sys_proto.h>
Michal Simekaf482d52012-09-28 09:56:37 +000014
15DECLARE_GLOBAL_DATA_PTR;
16
Michal Simekda713862014-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 Simek0f796702014-04-25 13:51:17 +020019static xilinx_desc fpga;
Michal Simek15d654c2013-04-22 15:43:02 +020020
21/* It can be done differently */
Michal Simek82c97022016-10-18 16:10:25 +020022static xilinx_desc fpga007s = XILINX_XC7Z007S_DESC(0x7);
Michal Simek0f796702014-04-25 13:51:17 +020023static xilinx_desc fpga010 = XILINX_XC7Z010_DESC(0x10);
Michal Simek82c97022016-10-18 16:10:25 +020024static xilinx_desc fpga012s = XILINX_XC7Z012S_DESC(0x12);
25static xilinx_desc fpga014s = XILINX_XC7Z014S_DESC(0x14);
Michal Simek0f796702014-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 Paladugu77fc12c2014-11-25 15:29:54 +053029static xilinx_desc fpga035 = XILINX_XC7Z035_DESC(0x35);
Michal Simek0f796702014-04-25 13:51:17 +020030static xilinx_desc fpga045 = XILINX_XC7Z045_DESC(0x45);
31static xilinx_desc fpga100 = XILINX_XC7Z100_DESC(0x100);
Michal Simek15d654c2013-04-22 15:43:02 +020032#endif
33
Michal Simekaf482d52012-09-28 09:56:37 +000034int board_init(void)
35{
Michal Simekda713862014-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 Simek15d654c2013-04-22 15:43:02 +020038 u32 idcode;
39
40 idcode = zynq_slcr_get_idcode();
41
42 switch (idcode) {
Michal Simek82c97022016-10-18 16:10:25 +020043 case XILINX_ZYNQ_7007S:
44 fpga = fpga007s;
45 break;
Michal Simek15d654c2013-04-22 15:43:02 +020046 case XILINX_ZYNQ_7010:
47 fpga = fpga010;
48 break;
Michal Simek82c97022016-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 Simek0e91d3a2013-09-26 16:39:03 +020055 case XILINX_ZYNQ_7015:
56 fpga = fpga015;
57 break;
Michal Simek15d654c2013-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 Paladugu77fc12c2014-11-25 15:29:54 +053064 case XILINX_ZYNQ_7035:
65 fpga = fpga035;
66 break;
Michal Simek15d654c2013-04-22 15:43:02 +020067 case XILINX_ZYNQ_7045:
68 fpga = fpga045;
69 break;
Michal Simek52f91b52013-06-17 13:54:07 +020070 case XILINX_ZYNQ_7100:
71 fpga = fpga100;
72 break;
Michal Simek15d654c2013-04-22 15:43:02 +020073 }
74#endif
75
Michal Simekda713862014-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 Simek15d654c2013-04-22 15:43:02 +020078 fpga_init();
79 fpga_add(fpga_xilinx, &fpga);
80#endif
81
Michal Simekaf482d52012-09-28 09:56:37 +000082 return 0;
83}
84
Jagannadha Sutradharudu Teki11704c22014-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 Simekaf482d52012-09-28 09:56:37 +0000104
Michal Simek3fa64452014-08-28 13:31:02 +0200105#ifdef CONFIG_DISPLAY_BOARDINFO
106int checkboard(void)
107{
Michal Simek47ce9362016-01-25 11:04:21 +0100108 puts("Board: Xilinx Zynq\n");
Michal Simek3fa64452014-08-28 13:31:02 +0200109 return 0;
110}
111#endif
112
Joe Hershberger7f4e5552016-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 Simekf4780a72016-04-01 15:56:33 +0200126#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
Nathan Rossic12892b2016-12-04 19:33:22 +1000127static const void *get_memory_reg_prop(const void *fdt, int *lenp)
Michal Simekf4780a72016-04-01 15:56:33 +0200128{
Nathan Rossic12892b2016-12-04 19:33:22 +1000129 int offset;
Michal Simekf4780a72016-04-01 15:56:33 +0200130
Nathan Rossic12892b2016-12-04 19:33:22 +1000131 offset = fdt_path_offset(fdt, "/memory");
132 if (offset < 0)
133 return NULL;
Michal Simekf4780a72016-04-01 15:56:33 +0200134
Nathan Rossic12892b2016-12-04 19:33:22 +1000135 return fdt_getprop(fdt, offset, "reg", lenp);
136}
Michal Simekf4780a72016-04-01 15:56:33 +0200137
Nathan Rossic12892b2016-12-04 19:33:22 +1000138void dram_init_banksize(void)
139{
140 const void *fdt = gd->fdt_blob;
141 const fdt32_t *val;
142 int ac, sc, cells, len, i;
Michal Simekf4780a72016-04-01 15:56:33 +0200143
Nathan Rossic12892b2016-12-04 19:33:22 +1000144 val = get_memory_reg_prop(fdt, &len);
145 if (len < 0)
146 return;
Michal Simekf4780a72016-04-01 15:56:33 +0200147
Nathan Rossic12892b2016-12-04 19:33:22 +1000148 ac = fdt_address_cells(fdt, 0);
149 sc = fdt_size_cells(fdt, 0);
150 if (ac < 1 || sc > 2 || sc < 1 || sc > 2) {
151 printf("invalid address/size cells\n");
152 return;
Michal Simekf4780a72016-04-01 15:56:33 +0200153 }
154
Nathan Rossic12892b2016-12-04 19:33:22 +1000155 cells = ac + sc;
Michal Simekf4780a72016-04-01 15:56:33 +0200156
Nathan Rossic12892b2016-12-04 19:33:22 +1000157 len /= sizeof(*val);
Michal Simekf4780a72016-04-01 15:56:33 +0200158
Nathan Rossic12892b2016-12-04 19:33:22 +1000159 for (i = 0; i < CONFIG_NR_DRAM_BANKS && len >= cells;
160 i++, len -= cells) {
161 gd->bd->bi_dram[i].start = fdtdec_get_number(val, ac);
162 val += ac;
163 gd->bd->bi_dram[i].size = fdtdec_get_number(val, sc);
164 val += sc;
Michal Simekf4780a72016-04-01 15:56:33 +0200165
Nathan Rossic12892b2016-12-04 19:33:22 +1000166 debug("DRAM bank %d: start = %08lx, size = %08lx\n",
167 i, (unsigned long)gd->bd->bi_dram[i].start,
168 (unsigned long)gd->bd->bi_dram[i].size);
Michal Simekf4780a72016-04-01 15:56:33 +0200169 }
170}
171
Michal Simekaf482d52012-09-28 09:56:37 +0000172int dram_init(void)
173{
Nathan Rossic12892b2016-12-04 19:33:22 +1000174 const void *fdt = gd->fdt_blob;
175 const fdt32_t *val;
176 int ac, sc, len;
Michal Simekaf482d52012-09-28 09:56:37 +0000177
Nathan Rossic12892b2016-12-04 19:33:22 +1000178 ac = fdt_address_cells(fdt, 0);
179 sc = fdt_size_cells(fdt, 0);
180 if (ac < 0 || sc < 1 || sc > 2) {
181 printf("invalid address/size cells\n");
182 return -EINVAL;
Michal Simek65ef52f2014-02-24 11:16:32 +0100183 }
Michal Simekf4780a72016-04-01 15:56:33 +0200184
Nathan Rossic12892b2016-12-04 19:33:22 +1000185 val = get_memory_reg_prop(fdt, &len);
186 if (len / sizeof(*val) < ac + sc)
187 return -EINVAL;
Michal Simekf4780a72016-04-01 15:56:33 +0200188
Nathan Rossic12892b2016-12-04 19:33:22 +1000189 val += ac;
190
191 gd->ram_size = fdtdec_get_number(val, sc);
Michal Simekf4780a72016-04-01 15:56:33 +0200192
Nathan Rossic12892b2016-12-04 19:33:22 +1000193 debug("DRAM size = %08lx\n", (unsigned long)gd->ram_size);
Michal Simekf4780a72016-04-01 15:56:33 +0200194
195 zynq_ddrc_init();
196
197 return 0;
198}
199#else
200int dram_init(void)
201{
202 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
203
Michal Simekf5ff7bc2013-06-17 14:37:01 +0200204 zynq_ddrc_init();
205
Michal Simekaf482d52012-09-28 09:56:37 +0000206 return 0;
207}
Michal Simekf4780a72016-04-01 15:56:33 +0200208#endif