board.c 2.64 KB
Newer Older
Michal Simek's avatar
Michal Simek committed
1 2 3
/*
 * (C) Copyright 2012 Michal Simek <monstr@monstr.eu>
 *
4
 * SPDX-License-Identifier:	GPL-2.0+
Michal Simek's avatar
Michal Simek committed
5 6 7
 */

#include <common.h>
8
#include <fdtdec.h>
9 10
#include <fpga.h>
#include <mmc.h>
11
#include <zynqpl.h>
Michal Simek's avatar
Michal Simek committed
12 13
#include <asm/arch/hardware.h>
#include <asm/arch/sys_proto.h>
Michal Simek's avatar
Michal Simek committed
14 15 16

DECLARE_GLOBAL_DATA_PTR;

17 18
#if (defined(CONFIG_FPGA) && !defined(CONFIG_SPL_BUILD)) || \
    (defined(CONFIG_SPL_FPGA_SUPPORT) && defined(CONFIG_SPL_BUILD))
19
static xilinx_desc fpga;
20 21

/* It can be done differently */
22 23 24 25
static xilinx_desc fpga010 = XILINX_XC7Z010_DESC(0x10);
static xilinx_desc fpga015 = XILINX_XC7Z015_DESC(0x15);
static xilinx_desc fpga020 = XILINX_XC7Z020_DESC(0x20);
static xilinx_desc fpga030 = XILINX_XC7Z030_DESC(0x30);
26
static xilinx_desc fpga035 = XILINX_XC7Z035_DESC(0x35);
27 28
static xilinx_desc fpga045 = XILINX_XC7Z045_DESC(0x45);
static xilinx_desc fpga100 = XILINX_XC7Z100_DESC(0x100);
29 30
#endif

Michal Simek's avatar
Michal Simek committed
31 32
int board_init(void)
{
33 34
#if (defined(CONFIG_FPGA) && !defined(CONFIG_SPL_BUILD)) || \
    (defined(CONFIG_SPL_FPGA_SUPPORT) && defined(CONFIG_SPL_BUILD))
35 36 37 38 39 40 41 42
	u32 idcode;

	idcode = zynq_slcr_get_idcode();

	switch (idcode) {
	case XILINX_ZYNQ_7010:
		fpga = fpga010;
		break;
43 44 45
	case XILINX_ZYNQ_7015:
		fpga = fpga015;
		break;
46 47 48 49 50 51
	case XILINX_ZYNQ_7020:
		fpga = fpga020;
		break;
	case XILINX_ZYNQ_7030:
		fpga = fpga030;
		break;
52 53 54
	case XILINX_ZYNQ_7035:
		fpga = fpga035;
		break;
55 56 57
	case XILINX_ZYNQ_7045:
		fpga = fpga045;
		break;
58 59 60
	case XILINX_ZYNQ_7100:
		fpga = fpga100;
		break;
61 62 63
	}
#endif

64 65
#if (defined(CONFIG_FPGA) && !defined(CONFIG_SPL_BUILD)) || \
    (defined(CONFIG_SPL_FPGA_SUPPORT) && defined(CONFIG_SPL_BUILD))
66 67 68 69
	fpga_init();
	fpga_add(fpga_xilinx, &fpga);
#endif

Michal Simek's avatar
Michal Simek committed
70 71 72
	return 0;
}

73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
int board_late_init(void)
{
	switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) {
	case ZYNQ_BM_NOR:
		setenv("modeboot", "norboot");
		break;
	case ZYNQ_BM_SD:
		setenv("modeboot", "sdboot");
		break;
	case ZYNQ_BM_JTAG:
		setenv("modeboot", "jtagboot");
		break;
	default:
		setenv("modeboot", "");
		break;
	}

	return 0;
}
Michal Simek's avatar
Michal Simek committed
92

93 94 95 96 97 98 99 100
#ifdef CONFIG_DISPLAY_BOARDINFO
int checkboard(void)
{
	puts("Board:\tXilinx Zynq\n");
	return 0;
}
#endif

Michal Simek's avatar
Michal Simek committed
101 102
int dram_init(void)
{
103
#if CONFIG_IS_ENABLED(OF_CONTROL)
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
	int node;
	fdt_addr_t addr;
	fdt_size_t size;
	const void *blob = gd->fdt_blob;

	node = fdt_node_offset_by_prop_value(blob, -1, "device_type",
					     "memory", 7);
	if (node == -FDT_ERR_NOTFOUND) {
		debug("ZYNQ DRAM: Can't get memory node\n");
		return -1;
	}
	addr = fdtdec_get_addr_size(blob, node, "reg", &size);
	if (addr == FDT_ADDR_T_NONE || size == 0) {
		debug("ZYNQ DRAM: Can't get base address or size\n");
		return -1;
	}
	gd->ram_size = size;
#else
Michal Simek's avatar
Michal Simek committed
122
	gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
123
#endif
124 125
	zynq_ddrc_init();

Michal Simek's avatar
Michal Simek committed
126 127
	return 0;
}