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 | 309ef80 | 2018-02-21 17:04:28 +0100 | [diff] [blame] | 9 | #include <dm/uclass.h> |
Michal Simek | 65ef52f | 2014-02-24 11:16:32 +0100 | [diff] [blame] | 10 | #include <fdtdec.h> |
Michal Simek | 0f79670 | 2014-04-25 13:51:17 +0200 | [diff] [blame] | 11 | #include <fpga.h> |
| 12 | #include <mmc.h> |
Michal Simek | 309ef80 | 2018-02-21 17:04:28 +0100 | [diff] [blame] | 13 | #include <wdt.h> |
Michal Simek | 15d654c | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 14 | #include <zynqpl.h> |
Michal Simek | 242192b | 2013-04-12 16:33:08 +0200 | [diff] [blame] | 15 | #include <asm/arch/hardware.h> |
| 16 | #include <asm/arch/sys_proto.h> |
Michal Simek | b8262d0 | 2017-11-10 13:01:10 +0100 | [diff] [blame] | 17 | #include <asm/arch/ps7_init_gpl.h> |
Michal Simek | af482d5 | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
Michal Simek | da71386 | 2014-03-04 12:41:05 +0100 | [diff] [blame] | 21 | #if (defined(CONFIG_FPGA) && !defined(CONFIG_SPL_BUILD)) || \ |
| 22 | (defined(CONFIG_SPL_FPGA_SUPPORT) && defined(CONFIG_SPL_BUILD)) |
Michal Simek | 0f79670 | 2014-04-25 13:51:17 +0200 | [diff] [blame] | 23 | static xilinx_desc fpga; |
Michal Simek | 15d654c | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 24 | |
| 25 | /* It can be done differently */ |
Michal Simek | 82c9702 | 2016-10-18 16:10:25 +0200 | [diff] [blame] | 26 | static xilinx_desc fpga007s = XILINX_XC7Z007S_DESC(0x7); |
Michal Simek | 0f79670 | 2014-04-25 13:51:17 +0200 | [diff] [blame] | 27 | static xilinx_desc fpga010 = XILINX_XC7Z010_DESC(0x10); |
Michal Simek | 82c9702 | 2016-10-18 16:10:25 +0200 | [diff] [blame] | 28 | static xilinx_desc fpga012s = XILINX_XC7Z012S_DESC(0x12); |
| 29 | static xilinx_desc fpga014s = XILINX_XC7Z014S_DESC(0x14); |
Michal Simek | 0f79670 | 2014-04-25 13:51:17 +0200 | [diff] [blame] | 30 | static xilinx_desc fpga015 = XILINX_XC7Z015_DESC(0x15); |
| 31 | static xilinx_desc fpga020 = XILINX_XC7Z020_DESC(0x20); |
| 32 | static xilinx_desc fpga030 = XILINX_XC7Z030_DESC(0x30); |
Siva Durga Prasad Paladugu | 77fc12c | 2014-11-25 15:29:54 +0530 | [diff] [blame] | 33 | static xilinx_desc fpga035 = XILINX_XC7Z035_DESC(0x35); |
Michal Simek | 0f79670 | 2014-04-25 13:51:17 +0200 | [diff] [blame] | 34 | static xilinx_desc fpga045 = XILINX_XC7Z045_DESC(0x45); |
| 35 | static xilinx_desc fpga100 = XILINX_XC7Z100_DESC(0x100); |
Michal Simek | 15d654c | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 36 | #endif |
| 37 | |
Michal Simek | 309ef80 | 2018-02-21 17:04:28 +0100 | [diff] [blame] | 38 | #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_WDT) |
| 39 | static struct udevice *watchdog_dev; |
| 40 | #endif |
| 41 | |
| 42 | #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_BOARD_EARLY_INIT_F) |
| 43 | int board_early_init_f(void) |
| 44 | { |
| 45 | # if defined(CONFIG_WDT) |
| 46 | /* bss is not cleared at time when watchdog_reset() is called */ |
| 47 | watchdog_dev = NULL; |
| 48 | # endif |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | #endif |
| 53 | |
Michal Simek | af482d5 | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 54 | int board_init(void) |
| 55 | { |
Michal Simek | da71386 | 2014-03-04 12:41:05 +0100 | [diff] [blame] | 56 | #if (defined(CONFIG_FPGA) && !defined(CONFIG_SPL_BUILD)) || \ |
| 57 | (defined(CONFIG_SPL_FPGA_SUPPORT) && defined(CONFIG_SPL_BUILD)) |
Michal Simek | 15d654c | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 58 | u32 idcode; |
| 59 | |
| 60 | idcode = zynq_slcr_get_idcode(); |
| 61 | |
| 62 | switch (idcode) { |
Michal Simek | 82c9702 | 2016-10-18 16:10:25 +0200 | [diff] [blame] | 63 | case XILINX_ZYNQ_7007S: |
| 64 | fpga = fpga007s; |
| 65 | break; |
Michal Simek | 15d654c | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 66 | case XILINX_ZYNQ_7010: |
| 67 | fpga = fpga010; |
| 68 | break; |
Michal Simek | 82c9702 | 2016-10-18 16:10:25 +0200 | [diff] [blame] | 69 | case XILINX_ZYNQ_7012S: |
| 70 | fpga = fpga012s; |
| 71 | break; |
| 72 | case XILINX_ZYNQ_7014S: |
| 73 | fpga = fpga014s; |
| 74 | break; |
Michal Simek | 0e91d3a | 2013-09-26 16:39:03 +0200 | [diff] [blame] | 75 | case XILINX_ZYNQ_7015: |
| 76 | fpga = fpga015; |
| 77 | break; |
Michal Simek | 15d654c | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 78 | case XILINX_ZYNQ_7020: |
| 79 | fpga = fpga020; |
| 80 | break; |
| 81 | case XILINX_ZYNQ_7030: |
| 82 | fpga = fpga030; |
| 83 | break; |
Siva Durga Prasad Paladugu | 77fc12c | 2014-11-25 15:29:54 +0530 | [diff] [blame] | 84 | case XILINX_ZYNQ_7035: |
| 85 | fpga = fpga035; |
| 86 | break; |
Michal Simek | 15d654c | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 87 | case XILINX_ZYNQ_7045: |
| 88 | fpga = fpga045; |
| 89 | break; |
Michal Simek | 52f91b5 | 2013-06-17 13:54:07 +0200 | [diff] [blame] | 90 | case XILINX_ZYNQ_7100: |
| 91 | fpga = fpga100; |
| 92 | break; |
Michal Simek | 15d654c | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 93 | } |
| 94 | #endif |
| 95 | |
Michal Simek | 309ef80 | 2018-02-21 17:04:28 +0100 | [diff] [blame] | 96 | #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_WDT) |
| 97 | if (uclass_get_device(UCLASS_WDT, 0, &watchdog_dev)) { |
| 98 | puts("Watchdog: Not found!\n"); |
| 99 | } else { |
| 100 | wdt_start(watchdog_dev, 0, 0); |
| 101 | puts("Watchdog: Started\n"); |
| 102 | } |
| 103 | # endif |
| 104 | |
Michal Simek | da71386 | 2014-03-04 12:41:05 +0100 | [diff] [blame] | 105 | #if (defined(CONFIG_FPGA) && !defined(CONFIG_SPL_BUILD)) || \ |
| 106 | (defined(CONFIG_SPL_FPGA_SUPPORT) && defined(CONFIG_SPL_BUILD)) |
Michal Simek | 15d654c | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 107 | fpga_init(); |
| 108 | fpga_add(fpga_xilinx, &fpga); |
| 109 | #endif |
| 110 | |
Michal Simek | af482d5 | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 111 | return 0; |
| 112 | } |
| 113 | |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 114 | int board_late_init(void) |
| 115 | { |
| 116 | switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) { |
Michal Simek | 1935671 | 2016-12-16 13:16:14 +0100 | [diff] [blame] | 117 | case ZYNQ_BM_QSPI: |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 118 | env_set("modeboot", "qspiboot"); |
Michal Simek | 1935671 | 2016-12-16 13:16:14 +0100 | [diff] [blame] | 119 | break; |
| 120 | case ZYNQ_BM_NAND: |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 121 | env_set("modeboot", "nandboot"); |
Michal Simek | 1935671 | 2016-12-16 13:16:14 +0100 | [diff] [blame] | 122 | break; |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 123 | case ZYNQ_BM_NOR: |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 124 | env_set("modeboot", "norboot"); |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 125 | break; |
| 126 | case ZYNQ_BM_SD: |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 127 | env_set("modeboot", "sdboot"); |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 128 | break; |
| 129 | case ZYNQ_BM_JTAG: |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 130 | env_set("modeboot", "jtagboot"); |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 131 | break; |
| 132 | default: |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 133 | env_set("modeboot", ""); |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 134 | break; |
| 135 | } |
| 136 | |
| 137 | return 0; |
| 138 | } |
Michal Simek | af482d5 | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 139 | |
Michal Simek | 3fa6445 | 2014-08-28 13:31:02 +0200 | [diff] [blame] | 140 | #ifdef CONFIG_DISPLAY_BOARDINFO |
| 141 | int checkboard(void) |
| 142 | { |
Michal Simek | b8262d0 | 2017-11-10 13:01:10 +0100 | [diff] [blame] | 143 | u32 version = zynq_get_silicon_version(); |
| 144 | |
| 145 | version <<= 1; |
| 146 | if (version > (PCW_SILICON_VERSION_3 << 1)) |
| 147 | version += 1; |
| 148 | |
Michal Simek | 47ce936 | 2016-01-25 11:04:21 +0100 | [diff] [blame] | 149 | puts("Board: Xilinx Zynq\n"); |
Michal Simek | b8262d0 | 2017-11-10 13:01:10 +0100 | [diff] [blame] | 150 | printf("Silicon: v%d.%d\n", version >> 1, version & 1); |
| 151 | |
Michal Simek | 3fa6445 | 2014-08-28 13:31:02 +0200 | [diff] [blame] | 152 | return 0; |
| 153 | } |
| 154 | #endif |
| 155 | |
Joe Hershberger | 7f4e555 | 2016-01-26 11:57:03 -0600 | [diff] [blame] | 156 | int zynq_board_read_rom_ethaddr(unsigned char *ethaddr) |
| 157 | { |
| 158 | #if defined(CONFIG_ZYNQ_GEM_EEPROM_ADDR) && \ |
| 159 | defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET) |
| 160 | if (eeprom_read(CONFIG_ZYNQ_GEM_EEPROM_ADDR, |
| 161 | CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET, |
| 162 | ethaddr, 6)) |
| 163 | printf("I2C EEPROM MAC address read failed\n"); |
| 164 | #endif |
| 165 | |
| 166 | return 0; |
| 167 | } |
| 168 | |
Michal Simek | f4780a7 | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 169 | #if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE) |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 170 | int dram_init_banksize(void) |
Nathan Rossi | c12892b | 2016-12-04 19:33:22 +1000 | [diff] [blame] | 171 | { |
Michal Simek | d5b7de6 | 2017-11-03 15:25:51 +0100 | [diff] [blame] | 172 | return fdtdec_setup_memory_banksize(); |
Tom Rini | edcfdbd | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 173 | } |
Michal Simek | f4780a7 | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 174 | |
Tom Rini | edcfdbd | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 175 | int dram_init(void) |
| 176 | { |
Nathan Rossi | 58ea0d8 | 2016-12-19 00:03:34 +1000 | [diff] [blame] | 177 | if (fdtdec_setup_memory_size() != 0) |
| 178 | return -EINVAL; |
Tom Rini | edcfdbd | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 179 | |
| 180 | zynq_ddrc_init(); |
| 181 | |
| 182 | return 0; |
Michal Simek | f4780a7 | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 183 | } |
Michal Simek | f4780a7 | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 184 | #else |
| 185 | int dram_init(void) |
| 186 | { |
Michal Simek | 1b84621 | 2018-04-11 16:12:28 +0200 | [diff] [blame^] | 187 | gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE, |
| 188 | CONFIG_SYS_SDRAM_SIZE); |
Michal Simek | f4780a7 | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 189 | |
Michal Simek | f5ff7bc | 2013-06-17 14:37:01 +0200 | [diff] [blame] | 190 | zynq_ddrc_init(); |
| 191 | |
Michal Simek | af482d5 | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 192 | return 0; |
| 193 | } |
Michal Simek | f4780a7 | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 194 | #endif |
Michal Simek | 309ef80 | 2018-02-21 17:04:28 +0100 | [diff] [blame] | 195 | |
| 196 | #if defined(CONFIG_WATCHDOG) |
| 197 | /* Called by macro WATCHDOG_RESET */ |
| 198 | void watchdog_reset(void) |
| 199 | { |
| 200 | # if !defined(CONFIG_SPL_BUILD) |
| 201 | static ulong next_reset; |
| 202 | ulong now; |
| 203 | |
| 204 | if (!watchdog_dev) |
| 205 | return; |
| 206 | |
| 207 | now = timer_get_us(); |
| 208 | |
| 209 | /* Do not reset the watchdog too often */ |
| 210 | if (now > next_reset) { |
| 211 | wdt_reset(watchdog_dev); |
| 212 | next_reset = now + 1000; |
| 213 | } |
| 214 | # endif |
| 215 | } |
| 216 | #endif |