Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2002 |
| 4 | * Rich Ireland, Enterasys Networks, rireland@enterasys.com. |
| 5 | * Keith Outwater, keith_outwater@mvis.com |
Robert Hancock | 175dccd | 2019-06-18 09:47:16 -0600 | [diff] [blame^] | 6 | * |
| 7 | * Copyright (c) 2019 SED Systems, a division of Calian Ltd. |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * Configuration support for Xilinx Virtex2 devices. Based |
| 12 | * on spartan2.c (Rich Ireland, rireland@enterasys.com). |
| 13 | */ |
| 14 | |
| 15 | #include <common.h> |
Simon Glass | 24b852a | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 16 | #include <console.h> |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 17 | #include <virtex2.h> |
| 18 | |
Wolfgang Denk | 9a9200b | 2005-09-24 23:41:00 +0200 | [diff] [blame] | 19 | #if 0 |
| 20 | #define FPGA_DEBUG |
Wolfgang Denk | 265817c | 2005-09-25 00:53:22 +0200 | [diff] [blame] | 21 | #endif |
Wolfgang Denk | 9a9200b | 2005-09-24 23:41:00 +0200 | [diff] [blame] | 22 | |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 23 | #ifdef FPGA_DEBUG |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 24 | #define PRINTF(fmt, args...) printf(fmt, ##args) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 25 | #else |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 26 | #define PRINTF(fmt, args...) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 27 | #endif |
| 28 | |
| 29 | /* |
| 30 | * If the SelectMap interface can be overrun by the processor, define |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 31 | * CONFIG_SYS_FPGA_CHECK_BUSY and/or CONFIG_FPGA_DELAY in the board |
| 32 | * configuration file and add board-specific support for checking BUSY status. |
| 33 | * By default, assume that the SelectMap interface cannot be overrun. |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 34 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 35 | #ifndef CONFIG_SYS_FPGA_CHECK_BUSY |
| 36 | #undef CONFIG_SYS_FPGA_CHECK_BUSY |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 37 | #endif |
| 38 | |
| 39 | #ifndef CONFIG_FPGA_DELAY |
| 40 | #define CONFIG_FPGA_DELAY() |
| 41 | #endif |
| 42 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 43 | #ifndef CONFIG_SYS_FPGA_PROG_FEEDBACK |
| 44 | #define CONFIG_SYS_FPGA_PROG_FEEDBACK |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 45 | #endif |
| 46 | |
| 47 | /* |
| 48 | * Don't allow config cycle to be interrupted |
| 49 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 50 | #ifndef CONFIG_SYS_FPGA_CHECK_CTRLC |
| 51 | #undef CONFIG_SYS_FPGA_CHECK_CTRLC |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 52 | #endif |
| 53 | |
| 54 | /* |
| 55 | * Check for errors during configuration by default |
| 56 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 57 | #ifndef CONFIG_SYS_FPGA_CHECK_ERROR |
| 58 | #define CONFIG_SYS_FPGA_CHECK_ERROR |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 59 | #endif |
| 60 | |
| 61 | /* |
| 62 | * The default timeout in mS for INIT_B to deassert after PROG_B has |
| 63 | * been deasserted. Per the latest Virtex II Handbook (page 347), the |
| 64 | * max time from PORG_B deassertion to INIT_B deassertion is 4uS per |
| 65 | * data frame for the XC2V8000. The XC2V8000 has 2860 data frames |
| 66 | * which yields 11.44 mS. So let's make it bigger in order to handle |
| 67 | * an XC2V1000, if anyone can ever get ahold of one. |
| 68 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 69 | #ifndef CONFIG_SYS_FPGA_WAIT_INIT |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 70 | #define CONFIG_SYS_FPGA_WAIT_INIT CONFIG_SYS_HZ / 2 /* 500 ms */ |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 71 | #endif |
| 72 | |
| 73 | /* |
| 74 | * The default timeout for waiting for BUSY to deassert during configuration. |
| 75 | * This is normally not necessary since for most reasonable configuration |
| 76 | * clock frequencies (i.e. 66 MHz or less), BUSY monitoring is unnecessary. |
| 77 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 78 | #ifndef CONFIG_SYS_FPGA_WAIT_BUSY |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 79 | #define CONFIG_SYS_FPGA_WAIT_BUSY CONFIG_SYS_HZ / 200 /* 5 ms*/ |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 80 | #endif |
| 81 | |
| 82 | /* Default timeout for waiting for FPGA to enter operational mode after |
| 83 | * configuration data has been written. |
| 84 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 85 | #ifndef CONFIG_SYS_FPGA_WAIT_CONFIG |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 86 | #define CONFIG_SYS_FPGA_WAIT_CONFIG CONFIG_SYS_HZ / 5 /* 200 ms */ |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 87 | #endif |
| 88 | |
Michal Simek | f8c1be9 | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 89 | static int virtex2_ssm_load(xilinx_desc *desc, const void *buf, size_t bsize); |
| 90 | static int virtex2_ssm_dump(xilinx_desc *desc, const void *buf, size_t bsize); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 91 | |
Michal Simek | f8c1be9 | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 92 | static int virtex2_ss_load(xilinx_desc *desc, const void *buf, size_t bsize); |
| 93 | static int virtex2_ss_dump(xilinx_desc *desc, const void *buf, size_t bsize); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 94 | |
Michal Simek | 7a78bd2 | 2014-05-02 14:09:30 +0200 | [diff] [blame] | 95 | static int virtex2_load(xilinx_desc *desc, const void *buf, size_t bsize, |
| 96 | bitstream_type bstype) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 97 | { |
| 98 | int ret_val = FPGA_FAIL; |
| 99 | |
| 100 | switch (desc->iface) { |
| 101 | case slave_serial: |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 102 | PRINTF("%s: Launching Slave Serial Load\n", __func__); |
Michal Simek | d9071ce | 2014-03-13 11:33:36 +0100 | [diff] [blame] | 103 | ret_val = virtex2_ss_load(desc, buf, bsize); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 104 | break; |
| 105 | |
| 106 | case slave_selectmap: |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 107 | PRINTF("%s: Launching Slave Parallel Load\n", __func__); |
Michal Simek | d9071ce | 2014-03-13 11:33:36 +0100 | [diff] [blame] | 108 | ret_val = virtex2_ssm_load(desc, buf, bsize); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 109 | break; |
| 110 | |
| 111 | default: |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 112 | printf("%s: Unsupported interface type, %d\n", |
| 113 | __func__, desc->iface); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 114 | } |
| 115 | return ret_val; |
| 116 | } |
| 117 | |
Michal Simek | 14cfc4f | 2014-03-13 13:07:57 +0100 | [diff] [blame] | 118 | static int virtex2_dump(xilinx_desc *desc, const void *buf, size_t bsize) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 119 | { |
| 120 | int ret_val = FPGA_FAIL; |
| 121 | |
| 122 | switch (desc->iface) { |
| 123 | case slave_serial: |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 124 | PRINTF("%s: Launching Slave Serial Dump\n", __func__); |
Michal Simek | d9071ce | 2014-03-13 11:33:36 +0100 | [diff] [blame] | 125 | ret_val = virtex2_ss_dump(desc, buf, bsize); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 126 | break; |
| 127 | |
| 128 | case slave_parallel: |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 129 | PRINTF("%s: Launching Slave Parallel Dump\n", __func__); |
Michal Simek | d9071ce | 2014-03-13 11:33:36 +0100 | [diff] [blame] | 130 | ret_val = virtex2_ssm_dump(desc, buf, bsize); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 131 | break; |
| 132 | |
| 133 | default: |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 134 | printf("%s: Unsupported interface type, %d\n", |
| 135 | __func__, desc->iface); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 136 | } |
| 137 | return ret_val; |
| 138 | } |
| 139 | |
Michal Simek | 14cfc4f | 2014-03-13 13:07:57 +0100 | [diff] [blame] | 140 | static int virtex2_info(xilinx_desc *desc) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 141 | { |
| 142 | return FPGA_SUCCESS; |
| 143 | } |
| 144 | |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 145 | /* |
Robert Hancock | 175dccd | 2019-06-18 09:47:16 -0600 | [diff] [blame^] | 146 | * Virtex-II Slave SelectMap or Serial configuration loader. Configuration |
| 147 | * is as follows: |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 148 | * 1. Set the FPGA's PROG_B line low. |
| 149 | * 2. Set the FPGA's PROG_B line high. Wait for INIT_B to go high. |
| 150 | * 3. Write data to the SelectMap port. If INIT_B goes low at any time |
| 151 | * this process, a configuration error (most likely CRC failure) has |
| 152 | * ocurred. At this point a status word may be read from the |
| 153 | * SelectMap interface to determine the source of the problem (You |
Wolfgang Denk | 9a9200b | 2005-09-24 23:41:00 +0200 | [diff] [blame] | 154 | * could, for instance, put this in your 'abort' function handler). |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 155 | * 4. After all data has been written, test the state of the FPGA |
| 156 | * INIT_B and DONE lines. If both are high, configuration has |
| 157 | * succeeded. Congratulations! |
| 158 | */ |
Robert Hancock | 175dccd | 2019-06-18 09:47:16 -0600 | [diff] [blame^] | 159 | static int virtex2_slave_pre(xilinx_virtex2_slave_fns *fn, int cookie) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 160 | { |
Robert Hancock | 3372081 | 2019-06-18 09:47:14 -0600 | [diff] [blame] | 161 | unsigned long ts; |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 162 | |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 163 | PRINTF("%s:%d: Start with interface functions @ 0x%p\n", |
| 164 | __func__, __LINE__, fn); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 165 | |
Robert Hancock | 3372081 | 2019-06-18 09:47:14 -0600 | [diff] [blame] | 166 | if (!fn) { |
| 167 | printf("%s:%d: NULL Interface function table!\n", |
| 168 | __func__, __LINE__); |
| 169 | return FPGA_FAIL; |
| 170 | } |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 171 | |
Robert Hancock | 3372081 | 2019-06-18 09:47:14 -0600 | [diff] [blame] | 172 | /* Gotta split this one up (so the stack won't blow??) */ |
| 173 | PRINTF("%s:%d: Function Table:\n" |
| 174 | " base 0x%p\n" |
| 175 | " struct 0x%p\n" |
| 176 | " pre 0x%p\n" |
| 177 | " prog 0x%p\n" |
| 178 | " init 0x%p\n" |
| 179 | " error 0x%p\n", |
| 180 | __func__, __LINE__, |
| 181 | &fn, fn, fn->pre, fn->pgm, fn->init, fn->err); |
| 182 | PRINTF(" clock 0x%p\n" |
| 183 | " cs 0x%p\n" |
| 184 | " write 0x%p\n" |
| 185 | " rdata 0x%p\n" |
| 186 | " wdata 0x%p\n" |
| 187 | " busy 0x%p\n" |
| 188 | " abort 0x%p\n" |
| 189 | " post 0x%p\n\n", |
| 190 | fn->clk, fn->cs, fn->wr, fn->rdata, fn->wdata, |
| 191 | fn->busy, fn->abort, fn->post); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 192 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 193 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
Robert Hancock | 3372081 | 2019-06-18 09:47:14 -0600 | [diff] [blame] | 194 | printf("Initializing FPGA Device %d...\n", cookie); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 195 | #endif |
Robert Hancock | 3372081 | 2019-06-18 09:47:14 -0600 | [diff] [blame] | 196 | /* |
| 197 | * Run the pre configuration function if there is one. |
| 198 | */ |
| 199 | if (*fn->pre) |
| 200 | (*fn->pre)(cookie); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 201 | |
Robert Hancock | 3372081 | 2019-06-18 09:47:14 -0600 | [diff] [blame] | 202 | /* |
| 203 | * Assert the program line. The minimum pulse width for |
| 204 | * Virtex II devices is 300 nS (Tprogram parameter in datasheet). |
| 205 | * There is no maximum value for the pulse width. Check to make |
| 206 | * sure that INIT_B goes low after assertion of PROG_B |
| 207 | */ |
| 208 | (*fn->pgm)(true, true, cookie); |
| 209 | udelay(10); |
| 210 | ts = get_timer(0); |
| 211 | do { |
| 212 | if (get_timer(ts) > CONFIG_SYS_FPGA_WAIT_INIT) { |
| 213 | printf("%s:%d: ** Timeout after %d ticks waiting for INIT to assert.\n", |
| 214 | __func__, __LINE__, CONFIG_SYS_FPGA_WAIT_INIT); |
| 215 | (*fn->abort)(cookie); |
| 216 | return FPGA_FAIL; |
| 217 | } |
| 218 | } while (!(*fn->init)(cookie)); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 219 | |
Robert Hancock | 3372081 | 2019-06-18 09:47:14 -0600 | [diff] [blame] | 220 | (*fn->pgm)(false, true, cookie); |
| 221 | CONFIG_FPGA_DELAY(); |
| 222 | if (fn->clk) |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 223 | (*fn->clk)(true, true, cookie); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 224 | |
Robert Hancock | 3372081 | 2019-06-18 09:47:14 -0600 | [diff] [blame] | 225 | /* |
| 226 | * Start a timer and wait for INIT_B to go high |
| 227 | */ |
| 228 | ts = get_timer(0); |
| 229 | do { |
| 230 | CONFIG_FPGA_DELAY(); |
| 231 | if (get_timer(ts) > CONFIG_SYS_FPGA_WAIT_INIT) { |
| 232 | printf("%s:%d: ** Timeout after %d ticks waiting for INIT to deassert.\n", |
| 233 | __func__, __LINE__, CONFIG_SYS_FPGA_WAIT_INIT); |
| 234 | (*fn->abort)(cookie); |
| 235 | return FPGA_FAIL; |
| 236 | } |
| 237 | } while ((*fn->init)(cookie) && (*fn->busy)(cookie)); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 238 | |
Robert Hancock | 3372081 | 2019-06-18 09:47:14 -0600 | [diff] [blame] | 239 | if (fn->wr) |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 240 | (*fn->wr)(true, true, cookie); |
Robert Hancock | 3372081 | 2019-06-18 09:47:14 -0600 | [diff] [blame] | 241 | if (fn->cs) |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 242 | (*fn->cs)(true, true, cookie); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 243 | |
Robert Hancock | 3372081 | 2019-06-18 09:47:14 -0600 | [diff] [blame] | 244 | mdelay(10); |
| 245 | return FPGA_SUCCESS; |
| 246 | } |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 247 | |
Robert Hancock | 175dccd | 2019-06-18 09:47:16 -0600 | [diff] [blame^] | 248 | static int virtex2_slave_post(xilinx_virtex2_slave_fns *fn, |
Robert Hancock | 3372081 | 2019-06-18 09:47:14 -0600 | [diff] [blame] | 249 | int cookie) |
| 250 | { |
| 251 | int ret_val = FPGA_SUCCESS; |
Robert Hancock | a0549f7 | 2019-06-18 09:47:15 -0600 | [diff] [blame] | 252 | int num_done = 0; |
Robert Hancock | 3372081 | 2019-06-18 09:47:14 -0600 | [diff] [blame] | 253 | unsigned long ts; |
Wolfgang Denk | 9a9200b | 2005-09-24 23:41:00 +0200 | [diff] [blame] | 254 | |
Robert Hancock | 3372081 | 2019-06-18 09:47:14 -0600 | [diff] [blame] | 255 | /* |
| 256 | * Finished writing the data; deassert FPGA CS_B and WRITE_B signals. |
| 257 | */ |
| 258 | CONFIG_FPGA_DELAY(); |
| 259 | if (fn->cs) |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 260 | (*fn->cs)(false, true, cookie); |
Robert Hancock | 3372081 | 2019-06-18 09:47:14 -0600 | [diff] [blame] | 261 | if (fn->wr) |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 262 | (*fn->wr)(false, true, cookie); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 263 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 264 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
Robert Hancock | 3372081 | 2019-06-18 09:47:14 -0600 | [diff] [blame] | 265 | putc('\n'); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 266 | #endif |
| 267 | |
Robert Hancock | 3372081 | 2019-06-18 09:47:14 -0600 | [diff] [blame] | 268 | /* |
| 269 | * Check for successful configuration. FPGA INIT_B and DONE |
Robert Hancock | a0549f7 | 2019-06-18 09:47:15 -0600 | [diff] [blame] | 270 | * should both be high upon successful configuration. Continue pulsing |
| 271 | * clock with data set to all ones until DONE is asserted and for 8 |
| 272 | * clock cycles afterwards. |
Robert Hancock | 3372081 | 2019-06-18 09:47:14 -0600 | [diff] [blame] | 273 | */ |
| 274 | ts = get_timer(0); |
Robert Hancock | a0549f7 | 2019-06-18 09:47:15 -0600 | [diff] [blame] | 275 | while (true) { |
| 276 | if ((*fn->done)(cookie) == FPGA_SUCCESS && |
| 277 | !((*fn->init)(cookie))) { |
| 278 | if (num_done++ >= 8) |
| 279 | break; |
| 280 | } |
| 281 | |
Robert Hancock | 3372081 | 2019-06-18 09:47:14 -0600 | [diff] [blame] | 282 | if (get_timer(ts) > CONFIG_SYS_FPGA_WAIT_CONFIG) { |
| 283 | printf("%s:%d: ** Timeout after %d ticks waiting for DONE to assert and INIT to deassert\n", |
| 284 | __func__, __LINE__, CONFIG_SYS_FPGA_WAIT_CONFIG); |
| 285 | (*fn->abort)(cookie); |
| 286 | ret_val = FPGA_FAIL; |
| 287 | break; |
| 288 | } |
Robert Hancock | 175dccd | 2019-06-18 09:47:16 -0600 | [diff] [blame^] | 289 | if (fn->wbulkdata) { |
| 290 | unsigned char dummy = 0xff; |
| 291 | (*fn->wbulkdata)(&dummy, 1, true, cookie); |
| 292 | } else { |
| 293 | (*fn->wdata)(0xff, true, cookie); |
| 294 | CONFIG_FPGA_DELAY(); |
| 295 | (*fn->clk)(false, true, cookie); |
| 296 | CONFIG_FPGA_DELAY(); |
| 297 | (*fn->clk)(true, true, cookie); |
| 298 | } |
Robert Hancock | 3372081 | 2019-06-18 09:47:14 -0600 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | if (ret_val == FPGA_SUCCESS) { |
| 302 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
| 303 | printf("Initialization of FPGA device %d complete\n", cookie); |
| 304 | #endif |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 305 | /* |
Robert Hancock | 3372081 | 2019-06-18 09:47:14 -0600 | [diff] [blame] | 306 | * Run the post configuration function if there is one. |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 307 | */ |
Robert Hancock | 3372081 | 2019-06-18 09:47:14 -0600 | [diff] [blame] | 308 | if (*fn->post) |
| 309 | (*fn->post)(cookie); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 310 | } else { |
Robert Hancock | 3372081 | 2019-06-18 09:47:14 -0600 | [diff] [blame] | 311 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
| 312 | printf("** Initialization of FPGA device %d FAILED\n", |
| 313 | cookie); |
| 314 | #endif |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 315 | } |
| 316 | return ret_val; |
| 317 | } |
| 318 | |
Robert Hancock | 3372081 | 2019-06-18 09:47:14 -0600 | [diff] [blame] | 319 | static int virtex2_ssm_load(xilinx_desc *desc, const void *buf, size_t bsize) |
| 320 | { |
| 321 | int ret_val = FPGA_FAIL; |
Robert Hancock | 175dccd | 2019-06-18 09:47:16 -0600 | [diff] [blame^] | 322 | xilinx_virtex2_slave_fns *fn = desc->iface_fns; |
Robert Hancock | 3372081 | 2019-06-18 09:47:14 -0600 | [diff] [blame] | 323 | size_t bytecount = 0; |
| 324 | unsigned char *data = (unsigned char *)buf; |
| 325 | int cookie = desc->cookie; |
| 326 | |
| 327 | ret_val = virtex2_slave_pre(fn, cookie); |
| 328 | if (ret_val != FPGA_SUCCESS) |
| 329 | return ret_val; |
| 330 | |
| 331 | /* |
| 332 | * Load the data byte by byte |
| 333 | */ |
| 334 | while (bytecount < bsize) { |
| 335 | #ifdef CONFIG_SYS_FPGA_CHECK_CTRLC |
| 336 | if (ctrlc()) { |
| 337 | (*fn->abort)(cookie); |
| 338 | return FPGA_FAIL; |
| 339 | } |
| 340 | #endif |
| 341 | |
| 342 | if ((*fn->done)(cookie) == FPGA_SUCCESS) { |
| 343 | PRINTF("%s:%d:done went active early, bytecount = %d\n", |
| 344 | __func__, __LINE__, bytecount); |
| 345 | break; |
| 346 | } |
| 347 | |
| 348 | #ifdef CONFIG_SYS_FPGA_CHECK_ERROR |
| 349 | if ((*fn->init)(cookie)) { |
| 350 | printf("\n%s:%d: ** Error: INIT asserted during configuration\n", |
| 351 | __func__, __LINE__); |
| 352 | printf("%zu = buffer offset, %zu = buffer size\n", |
| 353 | bytecount, bsize); |
| 354 | (*fn->abort)(cookie); |
| 355 | return FPGA_FAIL; |
| 356 | } |
| 357 | #endif |
| 358 | |
| 359 | (*fn->wdata)(data[bytecount++], true, cookie); |
| 360 | CONFIG_FPGA_DELAY(); |
| 361 | |
| 362 | /* |
| 363 | * Cycle the clock pin |
| 364 | */ |
| 365 | (*fn->clk)(false, true, cookie); |
| 366 | CONFIG_FPGA_DELAY(); |
| 367 | (*fn->clk)(true, true, cookie); |
| 368 | |
| 369 | #ifdef CONFIG_SYS_FPGA_CHECK_BUSY |
| 370 | ts = get_timer(0); |
| 371 | while ((*fn->busy)(cookie)) { |
| 372 | if (get_timer(ts) > CONFIG_SYS_FPGA_WAIT_BUSY) { |
| 373 | printf("%s:%d: ** Timeout after %d ticks waiting for BUSY to deassert\n", |
| 374 | __func__, __LINE__, |
| 375 | CONFIG_SYS_FPGA_WAIT_BUSY); |
| 376 | (*fn->abort)(cookie); |
| 377 | return FPGA_FAIL; |
| 378 | } |
| 379 | } |
| 380 | #endif |
| 381 | |
| 382 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
| 383 | if (bytecount % (bsize / 40) == 0) |
| 384 | putc('.'); |
| 385 | #endif |
| 386 | } |
| 387 | |
| 388 | return virtex2_slave_post(fn, cookie); |
| 389 | } |
| 390 | |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 391 | /* |
| 392 | * Read the FPGA configuration data |
| 393 | */ |
Michal Simek | f8c1be9 | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 394 | static int virtex2_ssm_dump(xilinx_desc *desc, const void *buf, size_t bsize) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 395 | { |
| 396 | int ret_val = FPGA_FAIL; |
Robert Hancock | 175dccd | 2019-06-18 09:47:16 -0600 | [diff] [blame^] | 397 | xilinx_virtex2_slave_fns *fn = desc->iface_fns; |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 398 | |
| 399 | if (fn) { |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 400 | unsigned char *data = (unsigned char *)buf; |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 401 | size_t bytecount = 0; |
| 402 | int cookie = desc->cookie; |
| 403 | |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 404 | printf("Starting Dump of FPGA Device %d...\n", cookie); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 405 | |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 406 | (*fn->cs)(true, true, cookie); |
| 407 | (*fn->clk)(true, true, cookie); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 408 | |
| 409 | while (bytecount < bsize) { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 410 | #ifdef CONFIG_SYS_FPGA_CHECK_CTRLC |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 411 | if (ctrlc()) { |
| 412 | (*fn->abort)(cookie); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 413 | return FPGA_FAIL; |
| 414 | } |
| 415 | #endif |
| 416 | /* |
| 417 | * Cycle the clock and read the data |
| 418 | */ |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 419 | (*fn->clk)(false, true, cookie); |
| 420 | (*fn->clk)(true, true, cookie); |
| 421 | (*fn->rdata)(&data[bytecount++], cookie); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 422 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 423 | if (bytecount % (bsize / 40) == 0) |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 424 | putc('.'); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 425 | #endif |
| 426 | } |
| 427 | |
| 428 | /* |
| 429 | * Deassert CS_B and cycle the clock to deselect the device. |
| 430 | */ |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 431 | (*fn->cs)(false, false, cookie); |
| 432 | (*fn->clk)(false, true, cookie); |
| 433 | (*fn->clk)(true, true, cookie); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 434 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 435 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 436 | putc('\n'); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 437 | #endif |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 438 | puts("Done.\n"); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 439 | } else { |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 440 | printf("%s:%d: NULL Interface function table!\n", |
| 441 | __func__, __LINE__); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 442 | } |
| 443 | return ret_val; |
| 444 | } |
| 445 | |
Michal Simek | f8c1be9 | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 446 | static int virtex2_ss_load(xilinx_desc *desc, const void *buf, size_t bsize) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 447 | { |
Robert Hancock | 175dccd | 2019-06-18 09:47:16 -0600 | [diff] [blame^] | 448 | int ret_val = FPGA_FAIL; |
| 449 | xilinx_virtex2_slave_fns *fn = desc->iface_fns; |
| 450 | unsigned char *data = (unsigned char *)buf; |
| 451 | int cookie = desc->cookie; |
| 452 | |
| 453 | ret_val = virtex2_slave_pre(fn, cookie); |
| 454 | if (ret_val != FPGA_SUCCESS) |
| 455 | return ret_val; |
| 456 | |
| 457 | if (fn->wbulkdata) { |
| 458 | /* Load the data in a single chunk */ |
| 459 | (*fn->wbulkdata)(data, bsize, true, cookie); |
| 460 | } else { |
| 461 | size_t bytecount = 0; |
| 462 | |
| 463 | /* |
| 464 | * Load the data bit by bit |
| 465 | */ |
| 466 | while (bytecount < bsize) { |
| 467 | unsigned char curr_data = data[bytecount++]; |
| 468 | int bit; |
| 469 | |
| 470 | #ifdef CONFIG_SYS_FPGA_CHECK_CTRLC |
| 471 | if (ctrlc()) { |
| 472 | (*fn->abort) (cookie); |
| 473 | return FPGA_FAIL; |
| 474 | } |
| 475 | #endif |
| 476 | |
| 477 | if ((*fn->done)(cookie) == FPGA_SUCCESS) { |
| 478 | PRINTF("%s:%d:done went active early, bytecount = %d\n", |
| 479 | __func__, __LINE__, bytecount); |
| 480 | break; |
| 481 | } |
| 482 | |
| 483 | #ifdef CONFIG_SYS_FPGA_CHECK_ERROR |
| 484 | if ((*fn->init)(cookie)) { |
| 485 | printf("\n%s:%d: ** Error: INIT asserted during configuration\n", |
| 486 | __func__, __LINE__); |
| 487 | printf("%zu = buffer offset, %zu = buffer size\n", |
| 488 | bytecount, bsize); |
| 489 | (*fn->abort)(cookie); |
| 490 | return FPGA_FAIL; |
| 491 | } |
| 492 | #endif |
| 493 | |
| 494 | for (bit = 7; bit >= 0; --bit) { |
| 495 | unsigned char curr_bit = (curr_data >> bit) & 1; |
| 496 | (*fn->wdata)(curr_bit, true, cookie); |
| 497 | CONFIG_FPGA_DELAY(); |
| 498 | (*fn->clk)(false, true, cookie); |
| 499 | CONFIG_FPGA_DELAY(); |
| 500 | (*fn->clk)(true, true, cookie); |
| 501 | } |
| 502 | |
| 503 | /* Slave serial never uses a busy pin */ |
| 504 | |
| 505 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
| 506 | if (bytecount % (bsize / 40) == 0) |
| 507 | putc('.'); |
| 508 | #endif |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | return virtex2_slave_post(fn, cookie); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 513 | } |
| 514 | |
Michal Simek | f8c1be9 | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 515 | static int virtex2_ss_dump(xilinx_desc *desc, const void *buf, size_t bsize) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 516 | { |
Robert Hancock | fa57af0 | 2019-06-18 09:47:12 -0600 | [diff] [blame] | 517 | printf("%s: Slave Serial Dumping is unsupported\n", __func__); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 518 | return FPGA_FAIL; |
| 519 | } |
| 520 | |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 521 | /* vim: set ts=4 tw=78: */ |
Michal Simek | 14cfc4f | 2014-03-13 13:07:57 +0100 | [diff] [blame] | 522 | |
| 523 | struct xilinx_fpga_op virtex2_op = { |
| 524 | .load = virtex2_load, |
| 525 | .dump = virtex2_dump, |
| 526 | .info = virtex2_info, |
| 527 | }; |