wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Rich Ireland, Enterasys Networks, rireland@enterasys.com. |
| 4 | * Keith Outwater, keith_outwater@mvis.com |
| 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 22 | * MA 02111-1307 USA |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | /* |
| 27 | * Xilinx FPGA support |
| 28 | */ |
| 29 | |
| 30 | #include <common.h> |
| 31 | #include <virtex2.h> |
| 32 | #include <spartan2.h> |
Wolfgang Denk | 875c789 | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 33 | #include <spartan3.h> |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 34 | |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 35 | #if 0 |
| 36 | #define FPGA_DEBUG |
| 37 | #endif |
| 38 | |
| 39 | /* Define FPGA_DEBUG to get debug printf's */ |
| 40 | #ifdef FPGA_DEBUG |
| 41 | #define PRINTF(fmt,args...) printf (fmt ,##args) |
| 42 | #else |
| 43 | #define PRINTF(fmt,args...) |
| 44 | #endif |
| 45 | |
| 46 | /* Local Static Functions */ |
| 47 | static int xilinx_validate (Xilinx_desc * desc, char *fn); |
| 48 | |
| 49 | /* ------------------------------------------------------------------------- */ |
| 50 | |
Wolfgang Denk | e6a857d | 2011-07-30 13:33:49 +0000 | [diff] [blame] | 51 | int xilinx_load(Xilinx_desc *desc, const void *buf, size_t bsize) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 52 | { |
| 53 | int ret_val = FPGA_FAIL; /* assume a failure */ |
| 54 | |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 55 | if (!xilinx_validate (desc, (char *)__FUNCTION__)) { |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 56 | printf ("%s: Invalid device descriptor\n", __FUNCTION__); |
| 57 | } else |
| 58 | switch (desc->family) { |
| 59 | case Xilinx_Spartan2: |
Matthias Fuchs | 0133502 | 2007-12-27 17:12:34 +0100 | [diff] [blame] | 60 | #if defined(CONFIG_FPGA_SPARTAN2) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 61 | PRINTF ("%s: Launching the Spartan-II Loader...\n", |
| 62 | __FUNCTION__); |
| 63 | ret_val = Spartan2_load (desc, buf, bsize); |
| 64 | #else |
| 65 | printf ("%s: No support for Spartan-II devices.\n", |
| 66 | __FUNCTION__); |
| 67 | #endif |
| 68 | break; |
Wolfgang Denk | 875c789 | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 69 | case Xilinx_Spartan3: |
Matthias Fuchs | 0133502 | 2007-12-27 17:12:34 +0100 | [diff] [blame] | 70 | #if defined(CONFIG_FPGA_SPARTAN3) |
Wolfgang Denk | 875c789 | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 71 | PRINTF ("%s: Launching the Spartan-III Loader...\n", |
| 72 | __FUNCTION__); |
| 73 | ret_val = Spartan3_load (desc, buf, bsize); |
| 74 | #else |
| 75 | printf ("%s: No support for Spartan-III devices.\n", |
| 76 | __FUNCTION__); |
| 77 | #endif |
| 78 | break; |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 79 | case Xilinx_Virtex2: |
Matthias Fuchs | 0133502 | 2007-12-27 17:12:34 +0100 | [diff] [blame] | 80 | #if defined(CONFIG_FPGA_VIRTEX2) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 81 | PRINTF ("%s: Launching the Virtex-II Loader...\n", |
| 82 | __FUNCTION__); |
| 83 | ret_val = Virtex2_load (desc, buf, bsize); |
| 84 | #else |
| 85 | printf ("%s: No support for Virtex-II devices.\n", |
| 86 | __FUNCTION__); |
| 87 | #endif |
| 88 | break; |
| 89 | |
| 90 | default: |
| 91 | printf ("%s: Unsupported family type, %d\n", |
| 92 | __FUNCTION__, desc->family); |
| 93 | } |
| 94 | |
| 95 | return ret_val; |
| 96 | } |
| 97 | |
Wolfgang Denk | e6a857d | 2011-07-30 13:33:49 +0000 | [diff] [blame] | 98 | int xilinx_dump(Xilinx_desc *desc, const void *buf, size_t bsize) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 99 | { |
| 100 | int ret_val = FPGA_FAIL; /* assume a failure */ |
| 101 | |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 102 | if (!xilinx_validate (desc, (char *)__FUNCTION__)) { |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 103 | printf ("%s: Invalid device descriptor\n", __FUNCTION__); |
| 104 | } else |
| 105 | switch (desc->family) { |
| 106 | case Xilinx_Spartan2: |
Matthias Fuchs | 0133502 | 2007-12-27 17:12:34 +0100 | [diff] [blame] | 107 | #if defined(CONFIG_FPGA_SPARTAN2) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 108 | PRINTF ("%s: Launching the Spartan-II Reader...\n", |
| 109 | __FUNCTION__); |
| 110 | ret_val = Spartan2_dump (desc, buf, bsize); |
| 111 | #else |
| 112 | printf ("%s: No support for Spartan-II devices.\n", |
| 113 | __FUNCTION__); |
| 114 | #endif |
| 115 | break; |
Wolfgang Denk | 875c789 | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 116 | case Xilinx_Spartan3: |
Matthias Fuchs | 0133502 | 2007-12-27 17:12:34 +0100 | [diff] [blame] | 117 | #if defined(CONFIG_FPGA_SPARTAN3) |
Wolfgang Denk | 875c789 | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 118 | PRINTF ("%s: Launching the Spartan-III Reader...\n", |
| 119 | __FUNCTION__); |
| 120 | ret_val = Spartan3_dump (desc, buf, bsize); |
| 121 | #else |
| 122 | printf ("%s: No support for Spartan-III devices.\n", |
| 123 | __FUNCTION__); |
| 124 | #endif |
| 125 | break; |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 126 | case Xilinx_Virtex2: |
Matthias Fuchs | 0133502 | 2007-12-27 17:12:34 +0100 | [diff] [blame] | 127 | #if defined( CONFIG_FPGA_VIRTEX2) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 128 | PRINTF ("%s: Launching the Virtex-II Reader...\n", |
| 129 | __FUNCTION__); |
| 130 | ret_val = Virtex2_dump (desc, buf, bsize); |
| 131 | #else |
| 132 | printf ("%s: No support for Virtex-II devices.\n", |
| 133 | __FUNCTION__); |
| 134 | #endif |
| 135 | break; |
| 136 | |
| 137 | default: |
| 138 | printf ("%s: Unsupported family type, %d\n", |
| 139 | __FUNCTION__, desc->family); |
| 140 | } |
| 141 | |
| 142 | return ret_val; |
| 143 | } |
| 144 | |
| 145 | int xilinx_info (Xilinx_desc * desc) |
| 146 | { |
| 147 | int ret_val = FPGA_FAIL; |
| 148 | |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 149 | if (xilinx_validate (desc, (char *)__FUNCTION__)) { |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 150 | printf ("Family: \t"); |
| 151 | switch (desc->family) { |
| 152 | case Xilinx_Spartan2: |
| 153 | printf ("Spartan-II\n"); |
| 154 | break; |
Wolfgang Denk | 875c789 | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 155 | case Xilinx_Spartan3: |
| 156 | printf ("Spartan-III\n"); |
| 157 | break; |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 158 | case Xilinx_Virtex2: |
| 159 | printf ("Virtex-II\n"); |
| 160 | break; |
| 161 | /* Add new family types here */ |
| 162 | default: |
| 163 | printf ("Unknown family type, %d\n", desc->family); |
| 164 | } |
| 165 | |
| 166 | printf ("Interface type:\t"); |
| 167 | switch (desc->iface) { |
| 168 | case slave_serial: |
| 169 | printf ("Slave Serial\n"); |
| 170 | break; |
| 171 | case master_serial: /* Not used */ |
| 172 | printf ("Master Serial\n"); |
| 173 | break; |
| 174 | case slave_parallel: |
| 175 | printf ("Slave Parallel\n"); |
| 176 | break; |
| 177 | case jtag_mode: /* Not used */ |
| 178 | printf ("JTAG Mode\n"); |
| 179 | break; |
| 180 | case slave_selectmap: |
| 181 | printf ("Slave SelectMap Mode\n"); |
| 182 | break; |
| 183 | case master_selectmap: |
| 184 | printf ("Master SelectMap Mode\n"); |
| 185 | break; |
| 186 | /* Add new interface types here */ |
| 187 | default: |
| 188 | printf ("Unsupported interface type, %d\n", desc->iface); |
| 189 | } |
| 190 | |
| 191 | printf ("Device Size: \t%d bytes\n" |
| 192 | "Cookie: \t0x%x (%d)\n", |
| 193 | desc->size, desc->cookie, desc->cookie); |
| 194 | |
| 195 | if (desc->iface_fns) { |
| 196 | printf ("Device Function Table @ 0x%p\n", desc->iface_fns); |
| 197 | switch (desc->family) { |
| 198 | case Xilinx_Spartan2: |
Matthias Fuchs | 0133502 | 2007-12-27 17:12:34 +0100 | [diff] [blame] | 199 | #if defined(CONFIG_FPGA_SPARTAN2) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 200 | Spartan2_info (desc); |
| 201 | #else |
| 202 | /* just in case */ |
| 203 | printf ("%s: No support for Spartan-II devices.\n", |
| 204 | __FUNCTION__); |
| 205 | #endif |
| 206 | break; |
Wolfgang Denk | 875c789 | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 207 | case Xilinx_Spartan3: |
Matthias Fuchs | 0133502 | 2007-12-27 17:12:34 +0100 | [diff] [blame] | 208 | #if defined(CONFIG_FPGA_SPARTAN3) |
Wolfgang Denk | 875c789 | 2005-09-25 16:44:21 +0200 | [diff] [blame] | 209 | Spartan3_info (desc); |
| 210 | #else |
| 211 | /* just in case */ |
| 212 | printf ("%s: No support for Spartan-III devices.\n", |
| 213 | __FUNCTION__); |
| 214 | #endif |
| 215 | break; |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 216 | case Xilinx_Virtex2: |
Matthias Fuchs | 0133502 | 2007-12-27 17:12:34 +0100 | [diff] [blame] | 217 | #if defined(CONFIG_FPGA_VIRTEX2) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 218 | Virtex2_info (desc); |
| 219 | #else |
| 220 | /* just in case */ |
| 221 | printf ("%s: No support for Virtex-II devices.\n", |
| 222 | __FUNCTION__); |
| 223 | #endif |
| 224 | break; |
| 225 | /* Add new family types here */ |
| 226 | default: |
| 227 | /* we don't need a message here - we give one up above */ |
wdenk | a8c7c70 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 228 | ; |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 229 | } |
| 230 | } else |
| 231 | printf ("No Device Function Table.\n"); |
| 232 | |
| 233 | ret_val = FPGA_SUCCESS; |
| 234 | } else { |
| 235 | printf ("%s: Invalid device descriptor\n", __FUNCTION__); |
| 236 | } |
| 237 | |
| 238 | return ret_val; |
| 239 | } |
| 240 | |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 241 | /* ------------------------------------------------------------------------- */ |
| 242 | |
| 243 | static int xilinx_validate (Xilinx_desc * desc, char *fn) |
| 244 | { |
York Sun | 472d546 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 245 | int ret_val = false; |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 246 | |
| 247 | if (desc) { |
| 248 | if ((desc->family > min_xilinx_type) && |
| 249 | (desc->family < max_xilinx_type)) { |
| 250 | if ((desc->iface > min_xilinx_iface_type) && |
| 251 | (desc->iface < max_xilinx_iface_type)) { |
| 252 | if (desc->size) { |
York Sun | 472d546 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 253 | ret_val = true; |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 254 | } else |
| 255 | printf ("%s: NULL part size\n", fn); |
| 256 | } else |
| 257 | printf ("%s: Invalid Interface type, %d\n", |
| 258 | fn, desc->iface); |
| 259 | } else |
| 260 | printf ("%s: Invalid family type, %d\n", fn, desc->family); |
| 261 | } else |
| 262 | printf ("%s: NULL descriptor!\n", fn); |
| 263 | |
| 264 | return ret_val; |
| 265 | } |