Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2002 |
| 4 | * Rich Ireland, Enterasys Networks, rireland@enterasys.com. |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * Configuration support for Xilinx Spartan3 devices. Based |
| 9 | * on spartan2.c (Rich Ireland, rireland@enterasys.com). |
| 10 | */ |
Wolfgang Denk | 34ca9d3 | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 11 | |
Alexander Dahl | a151d23 | 2022-10-07 14:20:02 +0200 | [diff] [blame] | 12 | #define LOG_CATEGORY UCLASS_FPGA |
| 13 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 14 | #include <config.h> /* core U-Boot definitions */ |
Alexander Dahl | a151d23 | 2022-10-07 14:20:02 +0200 | [diff] [blame] | 15 | #include <log.h> |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 16 | #include <time.h> |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 17 | #include <spartan3.h> /* Spartan-II device family */ |
| 18 | |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 19 | /* Note: The assumption is that we cannot possibly run fast enough to |
| 20 | * overrun the device (the Slave Parallel mode can free run at 50MHz). |
Tom Rini | 88d86ec | 2022-12-04 10:03:57 -0500 | [diff] [blame] | 21 | * If there is a need to operate slower, define CFG_FPGA_DELAY in |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 22 | * the board config file to slow things down. |
| 23 | */ |
Tom Rini | 88d86ec | 2022-12-04 10:03:57 -0500 | [diff] [blame] | 24 | #ifndef CFG_FPGA_DELAY |
| 25 | #define CFG_FPGA_DELAY() |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 26 | #endif |
| 27 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 28 | #ifndef CFG_SYS_FPGA_WAIT |
| 29 | #define CFG_SYS_FPGA_WAIT CONFIG_SYS_HZ/100 /* 10 ms */ |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 30 | #endif |
| 31 | |
Michal Simek | 25e1e2e | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 32 | static int spartan3_sp_load(xilinx_desc *desc, const void *buf, size_t bsize); |
| 33 | static int spartan3_sp_dump(xilinx_desc *desc, const void *buf, size_t bsize); |
| 34 | /* static int spartan3_sp_info(xilinx_desc *desc ); */ |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 35 | |
Michal Simek | 25e1e2e | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 36 | static int spartan3_ss_load(xilinx_desc *desc, const void *buf, size_t bsize); |
| 37 | static int spartan3_ss_dump(xilinx_desc *desc, const void *buf, size_t bsize); |
| 38 | /* static int spartan3_ss_info(xilinx_desc *desc); */ |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 39 | |
| 40 | /* ------------------------------------------------------------------------- */ |
| 41 | /* Spartan-II Generic Implementation */ |
Michal Simek | 1466365 | 2014-05-02 14:09:30 +0200 | [diff] [blame] | 42 | static int spartan3_load(xilinx_desc *desc, const void *buf, size_t bsize, |
Oleksandr Suvorov | c0806cc | 2022-07-22 17:16:10 +0300 | [diff] [blame] | 43 | bitstream_type bstype, int flags) |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 44 | { |
| 45 | int ret_val = FPGA_FAIL; |
| 46 | |
| 47 | switch (desc->iface) { |
| 48 | case slave_serial: |
Alexander Dahl | a151d23 | 2022-10-07 14:20:02 +0200 | [diff] [blame] | 49 | log_debug("Launching Slave Serial Load\n"); |
Michal Simek | 2091a0c | 2014-03-13 11:28:42 +0100 | [diff] [blame] | 50 | ret_val = spartan3_ss_load(desc, buf, bsize); |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 51 | break; |
| 52 | |
| 53 | case slave_parallel: |
Alexander Dahl | a151d23 | 2022-10-07 14:20:02 +0200 | [diff] [blame] | 54 | log_debug("Launching Slave Parallel Load\n"); |
Michal Simek | 2091a0c | 2014-03-13 11:28:42 +0100 | [diff] [blame] | 55 | ret_val = spartan3_sp_load(desc, buf, bsize); |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 56 | break; |
| 57 | |
| 58 | default: |
| 59 | printf ("%s: Unsupported interface type, %d\n", |
| 60 | __FUNCTION__, desc->iface); |
| 61 | } |
| 62 | |
| 63 | return ret_val; |
| 64 | } |
| 65 | |
Michal Simek | 75fafac | 2014-03-13 13:07:57 +0100 | [diff] [blame] | 66 | static int spartan3_dump(xilinx_desc *desc, const void *buf, size_t bsize) |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 67 | { |
| 68 | int ret_val = FPGA_FAIL; |
| 69 | |
| 70 | switch (desc->iface) { |
| 71 | case slave_serial: |
Alexander Dahl | a151d23 | 2022-10-07 14:20:02 +0200 | [diff] [blame] | 72 | log_debug("Launching Slave Serial Dump\n"); |
Michal Simek | 2091a0c | 2014-03-13 11:28:42 +0100 | [diff] [blame] | 73 | ret_val = spartan3_ss_dump(desc, buf, bsize); |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 74 | break; |
| 75 | |
| 76 | case slave_parallel: |
Alexander Dahl | a151d23 | 2022-10-07 14:20:02 +0200 | [diff] [blame] | 77 | log_debug("Launching Slave Parallel Dump\n"); |
Michal Simek | 2091a0c | 2014-03-13 11:28:42 +0100 | [diff] [blame] | 78 | ret_val = spartan3_sp_dump(desc, buf, bsize); |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 79 | break; |
| 80 | |
| 81 | default: |
| 82 | printf ("%s: Unsupported interface type, %d\n", |
| 83 | __FUNCTION__, desc->iface); |
| 84 | } |
| 85 | |
| 86 | return ret_val; |
| 87 | } |
| 88 | |
Michal Simek | 75fafac | 2014-03-13 13:07:57 +0100 | [diff] [blame] | 89 | static int spartan3_info(xilinx_desc *desc) |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 90 | { |
| 91 | return FPGA_SUCCESS; |
| 92 | } |
| 93 | |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 94 | /* ------------------------------------------------------------------------- */ |
| 95 | /* Spartan-II Slave Parallel Generic Implementation */ |
| 96 | |
Michal Simek | 25e1e2e | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 97 | static int spartan3_sp_load(xilinx_desc *desc, const void *buf, size_t bsize) |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 98 | { |
| 99 | int ret_val = FPGA_FAIL; /* assume the worst */ |
Michal Simek | 2091a0c | 2014-03-13 11:28:42 +0100 | [diff] [blame] | 100 | xilinx_spartan3_slave_parallel_fns *fn = desc->iface_fns; |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 101 | |
Alexander Dahl | a151d23 | 2022-10-07 14:20:02 +0200 | [diff] [blame] | 102 | log_debug("start with interface functions @ 0x%p\n", fn); |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 103 | |
| 104 | if (fn) { |
| 105 | size_t bytecount = 0; |
| 106 | unsigned char *data = (unsigned char *) buf; |
| 107 | int cookie = desc->cookie; /* make a local copy */ |
| 108 | unsigned long ts; /* timestamp */ |
| 109 | |
Alexander Dahl | a151d23 | 2022-10-07 14:20:02 +0200 | [diff] [blame] | 110 | log_debug("Function Table:\n" |
| 111 | "ptr:\t0x%p\n" |
| 112 | "struct: 0x%p\n" |
| 113 | "pre: 0x%p\n" |
| 114 | "pgm:\t0x%p\n" |
| 115 | "init:\t0x%p\n" |
| 116 | "err:\t0x%p\n" |
| 117 | "clk:\t0x%p\n" |
| 118 | "cs:\t0x%p\n" |
| 119 | "wr:\t0x%p\n" |
| 120 | "read data:\t0x%p\n" |
| 121 | "write data:\t0x%p\n" |
| 122 | "busy:\t0x%p\n" |
| 123 | "abort:\t0x%p\n" |
| 124 | "post:\t0x%p\n\n", |
| 125 | &fn, fn, fn->pre, fn->pgm, fn->init, fn->err, |
| 126 | fn->clk, fn->cs, fn->wr, fn->rdata, fn->wdata, fn->busy, |
| 127 | fn->abort, fn->post); |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 128 | |
| 129 | /* |
| 130 | * This code is designed to emulate the "Express Style" |
| 131 | * Continuous Data Loading in Slave Parallel Mode for |
| 132 | * the Spartan-II Family. |
| 133 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 134 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 135 | printf ("Loading FPGA Device %d...\n", cookie); |
| 136 | #endif |
| 137 | /* |
| 138 | * Run the pre configuration function if there is one. |
| 139 | */ |
| 140 | if (*fn->pre) { |
| 141 | (*fn->pre) (cookie); |
| 142 | } |
| 143 | |
| 144 | /* Establish the initial state */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 145 | (*fn->pgm) (true, true, cookie); /* Assert the program, commit */ |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 146 | |
| 147 | /* Get ready for the burn */ |
Tom Rini | 88d86ec | 2022-12-04 10:03:57 -0500 | [diff] [blame] | 148 | CFG_FPGA_DELAY (); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 149 | (*fn->pgm) (false, true, cookie); /* Deassert the program, commit */ |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 150 | |
| 151 | ts = get_timer (0); /* get current time */ |
| 152 | /* Now wait for INIT and BUSY to go high */ |
| 153 | do { |
Tom Rini | 88d86ec | 2022-12-04 10:03:57 -0500 | [diff] [blame] | 154 | CFG_FPGA_DELAY (); |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 155 | if (get_timer (ts) > CFG_SYS_FPGA_WAIT) { /* check the time */ |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 156 | puts ("** Timeout waiting for INIT to clear.\n"); |
| 157 | (*fn->abort) (cookie); /* abort the burn */ |
| 158 | return FPGA_FAIL; |
| 159 | } |
| 160 | } while ((*fn->init) (cookie) && (*fn->busy) (cookie)); |
| 161 | |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 162 | (*fn->wr) (true, true, cookie); /* Assert write, commit */ |
| 163 | (*fn->cs) (true, true, cookie); /* Assert chip select, commit */ |
| 164 | (*fn->clk) (true, true, cookie); /* Assert the clock pin */ |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 165 | |
| 166 | /* Load the data */ |
| 167 | while (bytecount < bsize) { |
| 168 | /* XXX - do we check for an Ctrl-C press in here ??? */ |
| 169 | /* XXX - Check the error bit? */ |
| 170 | |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 171 | (*fn->wdata) (data[bytecount++], true, cookie); /* write the data */ |
Tom Rini | 88d86ec | 2022-12-04 10:03:57 -0500 | [diff] [blame] | 172 | CFG_FPGA_DELAY (); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 173 | (*fn->clk) (false, true, cookie); /* Deassert the clock pin */ |
Tom Rini | 88d86ec | 2022-12-04 10:03:57 -0500 | [diff] [blame] | 174 | CFG_FPGA_DELAY (); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 175 | (*fn->clk) (true, true, cookie); /* Assert the clock pin */ |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 176 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 177 | #ifdef CONFIG_SYS_FPGA_CHECK_BUSY |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 178 | ts = get_timer (0); /* get current time */ |
| 179 | while ((*fn->busy) (cookie)) { |
| 180 | /* XXX - we should have a check in here somewhere to |
| 181 | * make sure we aren't busy forever... */ |
| 182 | |
Tom Rini | 88d86ec | 2022-12-04 10:03:57 -0500 | [diff] [blame] | 183 | CFG_FPGA_DELAY (); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 184 | (*fn->clk) (false, true, cookie); /* Deassert the clock pin */ |
Tom Rini | 88d86ec | 2022-12-04 10:03:57 -0500 | [diff] [blame] | 185 | CFG_FPGA_DELAY (); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 186 | (*fn->clk) (true, true, cookie); /* Assert the clock pin */ |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 187 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 188 | if (get_timer (ts) > CFG_SYS_FPGA_WAIT) { /* check the time */ |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 189 | puts ("** Timeout waiting for BUSY to clear.\n"); |
| 190 | (*fn->abort) (cookie); /* abort the burn */ |
| 191 | return FPGA_FAIL; |
| 192 | } |
| 193 | } |
| 194 | #endif |
| 195 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 196 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 197 | if (bytecount % (bsize / 40) == 0) |
| 198 | putc ('.'); /* let them know we are alive */ |
| 199 | #endif |
| 200 | } |
| 201 | |
Tom Rini | 88d86ec | 2022-12-04 10:03:57 -0500 | [diff] [blame] | 202 | CFG_FPGA_DELAY (); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 203 | (*fn->cs) (false, true, cookie); /* Deassert the chip select */ |
| 204 | (*fn->wr) (false, true, cookie); /* Deassert the write pin */ |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 205 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 206 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 207 | putc ('\n'); /* terminate the dotted line */ |
| 208 | #endif |
| 209 | |
| 210 | /* now check for done signal */ |
| 211 | ts = get_timer (0); /* get current time */ |
| 212 | ret_val = FPGA_SUCCESS; |
| 213 | while ((*fn->done) (cookie) == FPGA_FAIL) { |
| 214 | /* XXX - we should have a check in here somewhere to |
| 215 | * make sure we aren't busy forever... */ |
| 216 | |
Tom Rini | 88d86ec | 2022-12-04 10:03:57 -0500 | [diff] [blame] | 217 | CFG_FPGA_DELAY (); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 218 | (*fn->clk) (false, true, cookie); /* Deassert the clock pin */ |
Tom Rini | 88d86ec | 2022-12-04 10:03:57 -0500 | [diff] [blame] | 219 | CFG_FPGA_DELAY (); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 220 | (*fn->clk) (true, true, cookie); /* Assert the clock pin */ |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 221 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 222 | if (get_timer (ts) > CFG_SYS_FPGA_WAIT) { /* check the time */ |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 223 | puts ("** Timeout waiting for DONE to clear.\n"); |
| 224 | (*fn->abort) (cookie); /* abort the burn */ |
| 225 | ret_val = FPGA_FAIL; |
| 226 | break; |
| 227 | } |
| 228 | } |
| 229 | |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 230 | /* |
| 231 | * Run the post configuration function if there is one. |
| 232 | */ |
Matthias Fuchs | 9308166 | 2009-02-15 22:29:15 +0100 | [diff] [blame] | 233 | if (*fn->post) |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 234 | (*fn->post) (cookie); |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 235 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 236 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
Matthias Fuchs | 9308166 | 2009-02-15 22:29:15 +0100 | [diff] [blame] | 237 | if (ret_val == FPGA_SUCCESS) |
| 238 | puts ("Done.\n"); |
| 239 | else |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 240 | puts ("Fail.\n"); |
| 241 | #endif |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 242 | |
| 243 | } else { |
| 244 | printf ("%s: NULL Interface function table!\n", __FUNCTION__); |
| 245 | } |
| 246 | |
| 247 | return ret_val; |
| 248 | } |
| 249 | |
Michal Simek | 25e1e2e | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 250 | static int spartan3_sp_dump(xilinx_desc *desc, const void *buf, size_t bsize) |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 251 | { |
| 252 | int ret_val = FPGA_FAIL; /* assume the worst */ |
Michal Simek | 2091a0c | 2014-03-13 11:28:42 +0100 | [diff] [blame] | 253 | xilinx_spartan3_slave_parallel_fns *fn = desc->iface_fns; |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 254 | |
| 255 | if (fn) { |
| 256 | unsigned char *data = (unsigned char *) buf; |
| 257 | size_t bytecount = 0; |
| 258 | int cookie = desc->cookie; /* make a local copy */ |
| 259 | |
| 260 | printf ("Starting Dump of FPGA Device %d...\n", cookie); |
| 261 | |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 262 | (*fn->cs) (true, true, cookie); /* Assert chip select, commit */ |
| 263 | (*fn->clk) (true, true, cookie); /* Assert the clock pin */ |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 264 | |
| 265 | /* dump the data */ |
| 266 | while (bytecount < bsize) { |
| 267 | /* XXX - do we check for an Ctrl-C press in here ??? */ |
| 268 | |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 269 | (*fn->clk) (false, true, cookie); /* Deassert the clock pin */ |
| 270 | (*fn->clk) (true, true, cookie); /* Assert the clock pin */ |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 271 | (*fn->rdata) (&(data[bytecount++]), cookie); /* read the data */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 272 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 273 | if (bytecount % (bsize / 40) == 0) |
| 274 | putc ('.'); /* let them know we are alive */ |
| 275 | #endif |
| 276 | } |
| 277 | |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 278 | (*fn->cs) (false, false, cookie); /* Deassert the chip select */ |
| 279 | (*fn->clk) (false, true, cookie); /* Deassert the clock pin */ |
| 280 | (*fn->clk) (true, true, cookie); /* Assert the clock pin */ |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 281 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 282 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 283 | putc ('\n'); /* terminate the dotted line */ |
| 284 | #endif |
| 285 | puts ("Done.\n"); |
| 286 | |
| 287 | /* XXX - checksum the data? */ |
| 288 | } else { |
| 289 | printf ("%s: NULL Interface function table!\n", __FUNCTION__); |
| 290 | } |
| 291 | |
| 292 | return ret_val; |
| 293 | } |
| 294 | |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 295 | /* ------------------------------------------------------------------------- */ |
| 296 | |
Michal Simek | 25e1e2e | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 297 | static int spartan3_ss_load(xilinx_desc *desc, const void *buf, size_t bsize) |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 298 | { |
| 299 | int ret_val = FPGA_FAIL; /* assume the worst */ |
Michal Simek | 2091a0c | 2014-03-13 11:28:42 +0100 | [diff] [blame] | 300 | xilinx_spartan3_slave_serial_fns *fn = desc->iface_fns; |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 301 | int i; |
Matthias Fuchs | b845b1e | 2007-12-27 17:13:05 +0100 | [diff] [blame] | 302 | unsigned char val; |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 303 | |
Alexander Dahl | a151d23 | 2022-10-07 14:20:02 +0200 | [diff] [blame] | 304 | log_debug("start with interface functions @ 0x%p\n", fn); |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 305 | |
| 306 | if (fn) { |
| 307 | size_t bytecount = 0; |
| 308 | unsigned char *data = (unsigned char *) buf; |
| 309 | int cookie = desc->cookie; /* make a local copy */ |
| 310 | unsigned long ts; /* timestamp */ |
| 311 | |
Alexander Dahl | a151d23 | 2022-10-07 14:20:02 +0200 | [diff] [blame] | 312 | log_debug("Function Table:\n" |
| 313 | "ptr:\t0x%p\n" |
| 314 | "struct: 0x%p\n" |
| 315 | "pgm:\t0x%p\n" |
| 316 | "init:\t0x%p\n" |
| 317 | "clk:\t0x%p\n" |
| 318 | "wr:\t0x%p\n" |
| 319 | "done:\t0x%p\n\n", |
| 320 | &fn, fn, fn->pgm, fn->init, |
| 321 | fn->clk, fn->wr, fn->done); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 322 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 323 | printf ("Loading FPGA Device %d...\n", cookie); |
| 324 | #endif |
| 325 | |
| 326 | /* |
| 327 | * Run the pre configuration function if there is one. |
| 328 | */ |
| 329 | if (*fn->pre) { |
| 330 | (*fn->pre) (cookie); |
| 331 | } |
| 332 | |
| 333 | /* Establish the initial state */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 334 | (*fn->pgm) (true, true, cookie); /* Assert the program, commit */ |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 335 | |
| 336 | /* Wait for INIT state (init low) */ |
| 337 | ts = get_timer (0); /* get current time */ |
| 338 | do { |
Tom Rini | 88d86ec | 2022-12-04 10:03:57 -0500 | [diff] [blame] | 339 | CFG_FPGA_DELAY (); |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 340 | if (get_timer (ts) > CFG_SYS_FPGA_WAIT) { /* check the time */ |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 341 | puts ("** Timeout waiting for INIT to start.\n"); |
Wolfgang Wegner | 015db1f | 2010-04-23 11:08:05 +0200 | [diff] [blame] | 342 | if (*fn->abort) |
| 343 | (*fn->abort) (cookie); |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 344 | return FPGA_FAIL; |
| 345 | } |
| 346 | } while (!(*fn->init) (cookie)); |
| 347 | |
| 348 | /* Get ready for the burn */ |
Tom Rini | 88d86ec | 2022-12-04 10:03:57 -0500 | [diff] [blame] | 349 | CFG_FPGA_DELAY (); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 350 | (*fn->pgm) (false, true, cookie); /* Deassert the program, commit */ |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 351 | |
| 352 | ts = get_timer (0); /* get current time */ |
| 353 | /* Now wait for INIT to go high */ |
| 354 | do { |
Tom Rini | 88d86ec | 2022-12-04 10:03:57 -0500 | [diff] [blame] | 355 | CFG_FPGA_DELAY (); |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 356 | if (get_timer (ts) > CFG_SYS_FPGA_WAIT) { /* check the time */ |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 357 | puts ("** Timeout waiting for INIT to clear.\n"); |
Wolfgang Wegner | 015db1f | 2010-04-23 11:08:05 +0200 | [diff] [blame] | 358 | if (*fn->abort) |
| 359 | (*fn->abort) (cookie); |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 360 | return FPGA_FAIL; |
| 361 | } |
| 362 | } while ((*fn->init) (cookie)); |
| 363 | |
| 364 | /* Load the data */ |
Wolfgang Wegner | d37e555 | 2009-10-30 16:55:02 +0100 | [diff] [blame] | 365 | if(*fn->bwr) |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 366 | (*fn->bwr) (data, bsize, true, cookie); |
Wolfgang Wegner | d37e555 | 2009-10-30 16:55:02 +0100 | [diff] [blame] | 367 | else { |
| 368 | while (bytecount < bsize) { |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 369 | |
Wolfgang Wegner | d37e555 | 2009-10-30 16:55:02 +0100 | [diff] [blame] | 370 | /* Xilinx detects an error if INIT goes low (active) |
| 371 | while DONE is low (inactive) */ |
| 372 | if ((*fn->done) (cookie) == 0 && (*fn->init) (cookie)) { |
| 373 | puts ("** CRC error during FPGA load.\n"); |
Wolfgang Wegner | 015db1f | 2010-04-23 11:08:05 +0200 | [diff] [blame] | 374 | if (*fn->abort) |
| 375 | (*fn->abort) (cookie); |
Wolfgang Wegner | d37e555 | 2009-10-30 16:55:02 +0100 | [diff] [blame] | 376 | return (FPGA_FAIL); |
| 377 | } |
| 378 | val = data [bytecount ++]; |
| 379 | i = 8; |
| 380 | do { |
| 381 | /* Deassert the clock */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 382 | (*fn->clk) (false, true, cookie); |
Tom Rini | 88d86ec | 2022-12-04 10:03:57 -0500 | [diff] [blame] | 383 | CFG_FPGA_DELAY (); |
Wolfgang Wegner | d37e555 | 2009-10-30 16:55:02 +0100 | [diff] [blame] | 384 | /* Write data */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 385 | (*fn->wr) ((val & 0x80), true, cookie); |
Tom Rini | 88d86ec | 2022-12-04 10:03:57 -0500 | [diff] [blame] | 386 | CFG_FPGA_DELAY (); |
Wolfgang Wegner | d37e555 | 2009-10-30 16:55:02 +0100 | [diff] [blame] | 387 | /* Assert the clock */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 388 | (*fn->clk) (true, true, cookie); |
Tom Rini | 88d86ec | 2022-12-04 10:03:57 -0500 | [diff] [blame] | 389 | CFG_FPGA_DELAY (); |
Wolfgang Wegner | d37e555 | 2009-10-30 16:55:02 +0100 | [diff] [blame] | 390 | val <<= 1; |
| 391 | i --; |
| 392 | } while (i > 0); |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 393 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 394 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
Wolfgang Wegner | d37e555 | 2009-10-30 16:55:02 +0100 | [diff] [blame] | 395 | if (bytecount % (bsize / 40) == 0) |
| 396 | putc ('.'); /* let them know we are alive */ |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 397 | #endif |
Wolfgang Wegner | d37e555 | 2009-10-30 16:55:02 +0100 | [diff] [blame] | 398 | } |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 399 | } |
| 400 | |
Tom Rini | 88d86ec | 2022-12-04 10:03:57 -0500 | [diff] [blame] | 401 | CFG_FPGA_DELAY (); |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 402 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 403 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 404 | putc ('\n'); /* terminate the dotted line */ |
| 405 | #endif |
| 406 | |
| 407 | /* now check for done signal */ |
| 408 | ts = get_timer (0); /* get current time */ |
| 409 | ret_val = FPGA_SUCCESS; |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 410 | (*fn->wr) (true, true, cookie); |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 411 | |
| 412 | while (! (*fn->done) (cookie)) { |
| 413 | /* XXX - we should have a check in here somewhere to |
| 414 | * make sure we aren't busy forever... */ |
| 415 | |
Tom Rini | 88d86ec | 2022-12-04 10:03:57 -0500 | [diff] [blame] | 416 | CFG_FPGA_DELAY (); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 417 | (*fn->clk) (false, true, cookie); /* Deassert the clock pin */ |
Tom Rini | 88d86ec | 2022-12-04 10:03:57 -0500 | [diff] [blame] | 418 | CFG_FPGA_DELAY (); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 419 | (*fn->clk) (true, true, cookie); /* Assert the clock pin */ |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 420 | |
| 421 | putc ('*'); |
| 422 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 423 | if (get_timer (ts) > CFG_SYS_FPGA_WAIT) { /* check the time */ |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 424 | puts ("** Timeout waiting for DONE to clear.\n"); |
| 425 | ret_val = FPGA_FAIL; |
| 426 | break; |
| 427 | } |
| 428 | } |
| 429 | putc ('\n'); /* terminate the dotted line */ |
| 430 | |
Matthias Fuchs | 518e2e14 | 2007-12-27 17:12:43 +0100 | [diff] [blame] | 431 | /* |
| 432 | * Run the post configuration function if there is one. |
| 433 | */ |
Matthias Fuchs | 9308166 | 2009-02-15 22:29:15 +0100 | [diff] [blame] | 434 | if (*fn->post) |
Matthias Fuchs | 518e2e14 | 2007-12-27 17:12:43 +0100 | [diff] [blame] | 435 | (*fn->post) (cookie); |
Matthias Fuchs | 518e2e14 | 2007-12-27 17:12:43 +0100 | [diff] [blame] | 436 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 437 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
Matthias Fuchs | 9308166 | 2009-02-15 22:29:15 +0100 | [diff] [blame] | 438 | if (ret_val == FPGA_SUCCESS) |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 439 | puts ("Done.\n"); |
Matthias Fuchs | 9308166 | 2009-02-15 22:29:15 +0100 | [diff] [blame] | 440 | else |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 441 | puts ("Fail.\n"); |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 442 | #endif |
| 443 | |
| 444 | } else { |
| 445 | printf ("%s: NULL Interface function table!\n", __FUNCTION__); |
| 446 | } |
| 447 | |
| 448 | return ret_val; |
| 449 | } |
| 450 | |
Michal Simek | 25e1e2e | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 451 | static int spartan3_ss_dump(xilinx_desc *desc, const void *buf, size_t bsize) |
Wolfgang Denk | c38e70c | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 452 | { |
| 453 | /* Readback is only available through the Slave Parallel and */ |
| 454 | /* boundary-scan interfaces. */ |
| 455 | printf ("%s: Slave Serial Dumping is unavailable\n", |
| 456 | __FUNCTION__); |
| 457 | return FPGA_FAIL; |
| 458 | } |
Michal Simek | 75fafac | 2014-03-13 13:07:57 +0100 | [diff] [blame] | 459 | |
| 460 | struct xilinx_fpga_op spartan3_op = { |
| 461 | .load = spartan3_load, |
| 462 | .dump = spartan3_dump, |
| 463 | .info = spartan3_info, |
| 464 | }; |