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