Michal Simek | af482d5 | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2012 Michal Simek <monstr@monstr.eu> |
Michal Simek | 98d0f1f | 2018-01-17 07:37:47 +0100 | [diff] [blame^] | 3 | * (C) Copyright 2013 - 2018 Xilinx, Inc. |
Michal Simek | af482d5 | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 4 | * |
Wolfgang Denk | bd8ec7e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | af482d5 | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Michal Simek | 65ef52f | 2014-02-24 11:16:32 +0100 | [diff] [blame] | 9 | #include <fdtdec.h> |
Michal Simek | 0f79670 | 2014-04-25 13:51:17 +0200 | [diff] [blame] | 10 | #include <fpga.h> |
| 11 | #include <mmc.h> |
Michal Simek | 15d654c | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 12 | #include <zynqpl.h> |
Michal Simek | 242192b | 2013-04-12 16:33:08 +0200 | [diff] [blame] | 13 | #include <asm/arch/hardware.h> |
| 14 | #include <asm/arch/sys_proto.h> |
Michal Simek | b8262d0 | 2017-11-10 13:01:10 +0100 | [diff] [blame] | 15 | #include <asm/arch/ps7_init_gpl.h> |
Michal Simek | af482d5 | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 16 | |
| 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
Michal Simek | da71386 | 2014-03-04 12:41:05 +0100 | [diff] [blame] | 19 | #if (defined(CONFIG_FPGA) && !defined(CONFIG_SPL_BUILD)) || \ |
| 20 | (defined(CONFIG_SPL_FPGA_SUPPORT) && defined(CONFIG_SPL_BUILD)) |
Michal Simek | 0f79670 | 2014-04-25 13:51:17 +0200 | [diff] [blame] | 21 | static xilinx_desc fpga; |
Michal Simek | 15d654c | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 22 | |
| 23 | /* It can be done differently */ |
Michal Simek | 82c9702 | 2016-10-18 16:10:25 +0200 | [diff] [blame] | 24 | static xilinx_desc fpga007s = XILINX_XC7Z007S_DESC(0x7); |
Michal Simek | 0f79670 | 2014-04-25 13:51:17 +0200 | [diff] [blame] | 25 | static xilinx_desc fpga010 = XILINX_XC7Z010_DESC(0x10); |
Michal Simek | 82c9702 | 2016-10-18 16:10:25 +0200 | [diff] [blame] | 26 | static xilinx_desc fpga012s = XILINX_XC7Z012S_DESC(0x12); |
| 27 | static xilinx_desc fpga014s = XILINX_XC7Z014S_DESC(0x14); |
Michal Simek | 0f79670 | 2014-04-25 13:51:17 +0200 | [diff] [blame] | 28 | static xilinx_desc fpga015 = XILINX_XC7Z015_DESC(0x15); |
| 29 | static xilinx_desc fpga020 = XILINX_XC7Z020_DESC(0x20); |
| 30 | static xilinx_desc fpga030 = XILINX_XC7Z030_DESC(0x30); |
Siva Durga Prasad Paladugu | 77fc12c | 2014-11-25 15:29:54 +0530 | [diff] [blame] | 31 | static xilinx_desc fpga035 = XILINX_XC7Z035_DESC(0x35); |
Michal Simek | 0f79670 | 2014-04-25 13:51:17 +0200 | [diff] [blame] | 32 | static xilinx_desc fpga045 = XILINX_XC7Z045_DESC(0x45); |
| 33 | static xilinx_desc fpga100 = XILINX_XC7Z100_DESC(0x100); |
Michal Simek | 15d654c | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 34 | #endif |
| 35 | |
Michal Simek | af482d5 | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 36 | int board_init(void) |
| 37 | { |
Michal Simek | da71386 | 2014-03-04 12:41:05 +0100 | [diff] [blame] | 38 | #if (defined(CONFIG_FPGA) && !defined(CONFIG_SPL_BUILD)) || \ |
| 39 | (defined(CONFIG_SPL_FPGA_SUPPORT) && defined(CONFIG_SPL_BUILD)) |
Michal Simek | 15d654c | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 40 | u32 idcode; |
| 41 | |
| 42 | idcode = zynq_slcr_get_idcode(); |
| 43 | |
| 44 | switch (idcode) { |
Michal Simek | 82c9702 | 2016-10-18 16:10:25 +0200 | [diff] [blame] | 45 | case XILINX_ZYNQ_7007S: |
| 46 | fpga = fpga007s; |
| 47 | break; |
Michal Simek | 15d654c | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 48 | case XILINX_ZYNQ_7010: |
| 49 | fpga = fpga010; |
| 50 | break; |
Michal Simek | 82c9702 | 2016-10-18 16:10:25 +0200 | [diff] [blame] | 51 | case XILINX_ZYNQ_7012S: |
| 52 | fpga = fpga012s; |
| 53 | break; |
| 54 | case XILINX_ZYNQ_7014S: |
| 55 | fpga = fpga014s; |
| 56 | break; |
Michal Simek | 0e91d3a | 2013-09-26 16:39:03 +0200 | [diff] [blame] | 57 | case XILINX_ZYNQ_7015: |
| 58 | fpga = fpga015; |
| 59 | break; |
Michal Simek | 15d654c | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 60 | case XILINX_ZYNQ_7020: |
| 61 | fpga = fpga020; |
| 62 | break; |
| 63 | case XILINX_ZYNQ_7030: |
| 64 | fpga = fpga030; |
| 65 | break; |
Siva Durga Prasad Paladugu | 77fc12c | 2014-11-25 15:29:54 +0530 | [diff] [blame] | 66 | case XILINX_ZYNQ_7035: |
| 67 | fpga = fpga035; |
| 68 | break; |
Michal Simek | 15d654c | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 69 | case XILINX_ZYNQ_7045: |
| 70 | fpga = fpga045; |
| 71 | break; |
Michal Simek | 52f91b5 | 2013-06-17 13:54:07 +0200 | [diff] [blame] | 72 | case XILINX_ZYNQ_7100: |
| 73 | fpga = fpga100; |
| 74 | break; |
Michal Simek | 15d654c | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 75 | } |
| 76 | #endif |
| 77 | |
Michal Simek | da71386 | 2014-03-04 12:41:05 +0100 | [diff] [blame] | 78 | #if (defined(CONFIG_FPGA) && !defined(CONFIG_SPL_BUILD)) || \ |
| 79 | (defined(CONFIG_SPL_FPGA_SUPPORT) && defined(CONFIG_SPL_BUILD)) |
Michal Simek | 15d654c | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 80 | fpga_init(); |
| 81 | fpga_add(fpga_xilinx, &fpga); |
| 82 | #endif |
| 83 | |
Michal Simek | af482d5 | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 84 | return 0; |
| 85 | } |
| 86 | |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 87 | int board_late_init(void) |
| 88 | { |
| 89 | switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) { |
Michal Simek | 1935671 | 2016-12-16 13:16:14 +0100 | [diff] [blame] | 90 | case ZYNQ_BM_QSPI: |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 91 | env_set("modeboot", "qspiboot"); |
Michal Simek | 1935671 | 2016-12-16 13:16:14 +0100 | [diff] [blame] | 92 | break; |
| 93 | case ZYNQ_BM_NAND: |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 94 | env_set("modeboot", "nandboot"); |
Michal Simek | 1935671 | 2016-12-16 13:16:14 +0100 | [diff] [blame] | 95 | break; |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 96 | case ZYNQ_BM_NOR: |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 97 | env_set("modeboot", "norboot"); |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 98 | break; |
| 99 | case ZYNQ_BM_SD: |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 100 | env_set("modeboot", "sdboot"); |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 101 | break; |
| 102 | case ZYNQ_BM_JTAG: |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 103 | env_set("modeboot", "jtagboot"); |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 104 | break; |
| 105 | default: |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 106 | env_set("modeboot", ""); |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 107 | break; |
| 108 | } |
| 109 | |
| 110 | return 0; |
| 111 | } |
Michal Simek | af482d5 | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 112 | |
Michal Simek | 3fa6445 | 2014-08-28 13:31:02 +0200 | [diff] [blame] | 113 | #ifdef CONFIG_DISPLAY_BOARDINFO |
| 114 | int checkboard(void) |
| 115 | { |
Michal Simek | b8262d0 | 2017-11-10 13:01:10 +0100 | [diff] [blame] | 116 | u32 version = zynq_get_silicon_version(); |
| 117 | |
| 118 | version <<= 1; |
| 119 | if (version > (PCW_SILICON_VERSION_3 << 1)) |
| 120 | version += 1; |
| 121 | |
Michal Simek | 47ce936 | 2016-01-25 11:04:21 +0100 | [diff] [blame] | 122 | puts("Board: Xilinx Zynq\n"); |
Michal Simek | b8262d0 | 2017-11-10 13:01:10 +0100 | [diff] [blame] | 123 | printf("Silicon: v%d.%d\n", version >> 1, version & 1); |
| 124 | |
Michal Simek | 3fa6445 | 2014-08-28 13:31:02 +0200 | [diff] [blame] | 125 | return 0; |
| 126 | } |
| 127 | #endif |
| 128 | |
Joe Hershberger | 7f4e555 | 2016-01-26 11:57:03 -0600 | [diff] [blame] | 129 | int zynq_board_read_rom_ethaddr(unsigned char *ethaddr) |
| 130 | { |
| 131 | #if defined(CONFIG_ZYNQ_GEM_EEPROM_ADDR) && \ |
| 132 | defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET) |
| 133 | if (eeprom_read(CONFIG_ZYNQ_GEM_EEPROM_ADDR, |
| 134 | CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET, |
| 135 | ethaddr, 6)) |
| 136 | printf("I2C EEPROM MAC address read failed\n"); |
| 137 | #endif |
| 138 | |
| 139 | return 0; |
| 140 | } |
| 141 | |
Michal Simek | f4780a7 | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 142 | #if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE) |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 143 | int dram_init_banksize(void) |
Nathan Rossi | c12892b | 2016-12-04 19:33:22 +1000 | [diff] [blame] | 144 | { |
Michal Simek | d5b7de6 | 2017-11-03 15:25:51 +0100 | [diff] [blame] | 145 | return fdtdec_setup_memory_banksize(); |
Tom Rini | edcfdbd | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 146 | } |
Michal Simek | f4780a7 | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 147 | |
Tom Rini | edcfdbd | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 148 | int dram_init(void) |
| 149 | { |
Nathan Rossi | 58ea0d8 | 2016-12-19 00:03:34 +1000 | [diff] [blame] | 150 | if (fdtdec_setup_memory_size() != 0) |
| 151 | return -EINVAL; |
Tom Rini | edcfdbd | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 152 | |
| 153 | zynq_ddrc_init(); |
| 154 | |
| 155 | return 0; |
Michal Simek | f4780a7 | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 156 | } |
Michal Simek | f4780a7 | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 157 | #else |
| 158 | int dram_init(void) |
| 159 | { |
| 160 | gd->ram_size = CONFIG_SYS_SDRAM_SIZE; |
| 161 | |
Michal Simek | f5ff7bc | 2013-06-17 14:37:01 +0200 | [diff] [blame] | 162 | zynq_ddrc_init(); |
| 163 | |
Michal Simek | af482d5 | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 164 | return 0; |
| 165 | } |
Michal Simek | f4780a7 | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 166 | #endif |