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