Michal Simek | f22651c | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2012 Michal Simek <monstr@monstr.eu> |
| 3 | * |
Wolfgang Denk | 3765b3e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | f22651c | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Michal Simek | 9e0e37a | 2014-02-24 11:16:32 +0100 | [diff] [blame] | 8 | #include <fdtdec.h> |
Michal Simek | 5b73caf | 2014-04-25 13:51:17 +0200 | [diff] [blame] | 9 | #include <fpga.h> |
| 10 | #include <mmc.h> |
Michal Simek | f22651c | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 11 | #include <netdev.h> |
Michal Simek | d5dae85 | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 12 | #include <zynqpl.h> |
Michal Simek | 7193653 | 2013-04-12 16:33:08 +0200 | [diff] [blame] | 13 | #include <asm/arch/hardware.h> |
| 14 | #include <asm/arch/sys_proto.h> |
Michal Simek | f22651c | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
Michal Simek | 0b68020 | 2014-03-04 12:41:05 +0100 | [diff] [blame] | 18 | #if (defined(CONFIG_FPGA) && !defined(CONFIG_SPL_BUILD)) || \ |
| 19 | (defined(CONFIG_SPL_FPGA_SUPPORT) && defined(CONFIG_SPL_BUILD)) |
Michal Simek | 5b73caf | 2014-04-25 13:51:17 +0200 | [diff] [blame] | 20 | static xilinx_desc fpga; |
Michal Simek | d5dae85 | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 21 | |
| 22 | /* It can be done differently */ |
Michal Simek | 5b73caf | 2014-04-25 13:51:17 +0200 | [diff] [blame] | 23 | static xilinx_desc fpga010 = XILINX_XC7Z010_DESC(0x10); |
| 24 | static xilinx_desc fpga015 = XILINX_XC7Z015_DESC(0x15); |
| 25 | static xilinx_desc fpga020 = XILINX_XC7Z020_DESC(0x20); |
| 26 | static xilinx_desc fpga030 = XILINX_XC7Z030_DESC(0x30); |
Siva Durga Prasad Paladugu | b910380 | 2014-11-25 15:29:54 +0530 | [diff] [blame^] | 27 | static xilinx_desc fpga035 = XILINX_XC7Z035_DESC(0x35); |
Michal Simek | 5b73caf | 2014-04-25 13:51:17 +0200 | [diff] [blame] | 28 | static xilinx_desc fpga045 = XILINX_XC7Z045_DESC(0x45); |
| 29 | static xilinx_desc fpga100 = XILINX_XC7Z100_DESC(0x100); |
Michal Simek | d5dae85 | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 30 | #endif |
| 31 | |
Michal Simek | f22651c | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 32 | int board_init(void) |
| 33 | { |
Michal Simek | 0b68020 | 2014-03-04 12:41:05 +0100 | [diff] [blame] | 34 | #if (defined(CONFIG_FPGA) && !defined(CONFIG_SPL_BUILD)) || \ |
| 35 | (defined(CONFIG_SPL_FPGA_SUPPORT) && defined(CONFIG_SPL_BUILD)) |
Michal Simek | d5dae85 | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 36 | u32 idcode; |
| 37 | |
| 38 | idcode = zynq_slcr_get_idcode(); |
| 39 | |
| 40 | switch (idcode) { |
| 41 | case XILINX_ZYNQ_7010: |
| 42 | fpga = fpga010; |
| 43 | break; |
Michal Simek | 31993d6 | 2013-09-26 16:39:03 +0200 | [diff] [blame] | 44 | case XILINX_ZYNQ_7015: |
| 45 | fpga = fpga015; |
| 46 | break; |
Michal Simek | d5dae85 | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 47 | case XILINX_ZYNQ_7020: |
| 48 | fpga = fpga020; |
| 49 | break; |
| 50 | case XILINX_ZYNQ_7030: |
| 51 | fpga = fpga030; |
| 52 | break; |
Siva Durga Prasad Paladugu | b910380 | 2014-11-25 15:29:54 +0530 | [diff] [blame^] | 53 | case XILINX_ZYNQ_7035: |
| 54 | fpga = fpga035; |
| 55 | break; |
Michal Simek | d5dae85 | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 56 | case XILINX_ZYNQ_7045: |
| 57 | fpga = fpga045; |
| 58 | break; |
Michal Simek | fd2b10b | 2013-06-17 13:54:07 +0200 | [diff] [blame] | 59 | case XILINX_ZYNQ_7100: |
| 60 | fpga = fpga100; |
| 61 | break; |
Michal Simek | d5dae85 | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 62 | } |
| 63 | #endif |
| 64 | |
Michal Simek | 0b68020 | 2014-03-04 12:41:05 +0100 | [diff] [blame] | 65 | #if (defined(CONFIG_FPGA) && !defined(CONFIG_SPL_BUILD)) || \ |
| 66 | (defined(CONFIG_SPL_FPGA_SUPPORT) && defined(CONFIG_SPL_BUILD)) |
Michal Simek | d5dae85 | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 67 | fpga_init(); |
| 68 | fpga_add(fpga_xilinx, &fpga); |
| 69 | #endif |
| 70 | |
Michal Simek | f22651c | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 71 | return 0; |
| 72 | } |
| 73 | |
Jagannadha Sutradharudu Teki | b3de924 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 74 | int board_late_init(void) |
| 75 | { |
| 76 | switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) { |
| 77 | case ZYNQ_BM_NOR: |
| 78 | setenv("modeboot", "norboot"); |
| 79 | break; |
| 80 | case ZYNQ_BM_SD: |
| 81 | setenv("modeboot", "sdboot"); |
| 82 | break; |
| 83 | case ZYNQ_BM_JTAG: |
| 84 | setenv("modeboot", "jtagboot"); |
| 85 | break; |
| 86 | default: |
| 87 | setenv("modeboot", ""); |
| 88 | break; |
| 89 | } |
| 90 | |
| 91 | return 0; |
| 92 | } |
Michal Simek | f22651c | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 93 | |
Michal Simek | f22651c | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 94 | int board_eth_init(bd_t *bis) |
| 95 | { |
| 96 | u32 ret = 0; |
| 97 | |
Michal Simek | 2d83d33 | 2013-07-25 15:47:16 +0200 | [diff] [blame] | 98 | #ifdef CONFIG_XILINX_AXIEMAC |
| 99 | ret |= xilinx_axiemac_initialize(bis, XILINX_AXIEMAC_BASEADDR, |
| 100 | XILINX_AXIDMA_BASEADDR); |
| 101 | #endif |
| 102 | #ifdef CONFIG_XILINX_EMACLITE |
| 103 | u32 txpp = 0; |
| 104 | u32 rxpp = 0; |
| 105 | # ifdef CONFIG_XILINX_EMACLITE_TX_PING_PONG |
| 106 | txpp = 1; |
| 107 | # endif |
| 108 | # ifdef CONFIG_XILINX_EMACLITE_RX_PING_PONG |
| 109 | rxpp = 1; |
| 110 | # endif |
| 111 | ret |= xilinx_emaclite_initialize(bis, XILINX_EMACLITE_BASEADDR, |
| 112 | txpp, rxpp); |
| 113 | #endif |
| 114 | |
Michal Simek | 7193653 | 2013-04-12 16:33:08 +0200 | [diff] [blame] | 115 | #if defined(CONFIG_ZYNQ_GEM) |
| 116 | # if defined(CONFIG_ZYNQ_GEM0) |
David Andrey | 117cd4c | 2013-04-04 19:13:07 +0200 | [diff] [blame] | 117 | ret |= zynq_gem_initialize(bis, ZYNQ_GEM_BASEADDR0, |
David Andrey | 01fbf31 | 2013-04-05 17:24:24 +0200 | [diff] [blame] | 118 | CONFIG_ZYNQ_GEM_PHY_ADDR0, 0); |
Michal Simek | 7193653 | 2013-04-12 16:33:08 +0200 | [diff] [blame] | 119 | # endif |
| 120 | # if defined(CONFIG_ZYNQ_GEM1) |
David Andrey | 117cd4c | 2013-04-04 19:13:07 +0200 | [diff] [blame] | 121 | ret |= zynq_gem_initialize(bis, ZYNQ_GEM_BASEADDR1, |
David Andrey | 01fbf31 | 2013-04-05 17:24:24 +0200 | [diff] [blame] | 122 | CONFIG_ZYNQ_GEM_PHY_ADDR1, 0); |
Michal Simek | 7193653 | 2013-04-12 16:33:08 +0200 | [diff] [blame] | 123 | # endif |
Michal Simek | f22651c | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 124 | #endif |
Michal Simek | f22651c | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 125 | return ret; |
| 126 | } |
Michal Simek | f22651c | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 127 | |
Michal Simek | 293eb33 | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 128 | #ifdef CONFIG_CMD_MMC |
| 129 | int board_mmc_init(bd_t *bd) |
| 130 | { |
| 131 | int ret = 0; |
| 132 | |
| 133 | #if defined(CONFIG_ZYNQ_SDHCI) |
| 134 | # if defined(CONFIG_ZYNQ_SDHCI0) |
| 135 | ret = zynq_sdhci_init(ZYNQ_SDHCI_BASEADDR0); |
| 136 | # endif |
| 137 | # if defined(CONFIG_ZYNQ_SDHCI1) |
| 138 | ret |= zynq_sdhci_init(ZYNQ_SDHCI_BASEADDR1); |
| 139 | # endif |
| 140 | #endif |
| 141 | return ret; |
| 142 | } |
| 143 | #endif |
| 144 | |
Michal Simek | f22651c | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 145 | int dram_init(void) |
| 146 | { |
Michal Simek | 9e0e37a | 2014-02-24 11:16:32 +0100 | [diff] [blame] | 147 | #ifdef CONFIG_OF_CONTROL |
| 148 | int node; |
| 149 | fdt_addr_t addr; |
| 150 | fdt_size_t size; |
| 151 | const void *blob = gd->fdt_blob; |
Michal Simek | f22651c | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 152 | |
Michal Simek | 9e0e37a | 2014-02-24 11:16:32 +0100 | [diff] [blame] | 153 | node = fdt_node_offset_by_prop_value(blob, -1, "device_type", |
| 154 | "memory", 7); |
| 155 | if (node == -FDT_ERR_NOTFOUND) { |
| 156 | debug("ZYNQ DRAM: Can't get memory node\n"); |
| 157 | return -1; |
| 158 | } |
| 159 | addr = fdtdec_get_addr_size(blob, node, "reg", &size); |
| 160 | if (addr == FDT_ADDR_T_NONE || size == 0) { |
| 161 | debug("ZYNQ DRAM: Can't get base address or size\n"); |
| 162 | return -1; |
| 163 | } |
| 164 | gd->ram_size = size; |
| 165 | #else |
| 166 | gd->ram_size = CONFIG_SYS_SDRAM_SIZE; |
| 167 | #endif |
Michal Simek | 148ba55 | 2013-06-17 14:37:01 +0200 | [diff] [blame] | 168 | zynq_ddrc_init(); |
| 169 | |
Michal Simek | f22651c | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 170 | return 0; |
| 171 | } |