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