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> |
| 33 | |
| 34 | #if (CONFIG_FPGA & CFG_FPGA_XILINX) |
| 35 | |
| 36 | #if 0 |
| 37 | #define FPGA_DEBUG |
| 38 | #endif |
| 39 | |
| 40 | /* Define FPGA_DEBUG to get debug printf's */ |
| 41 | #ifdef FPGA_DEBUG |
| 42 | #define PRINTF(fmt,args...) printf (fmt ,##args) |
| 43 | #else |
| 44 | #define PRINTF(fmt,args...) |
| 45 | #endif |
| 46 | |
| 47 | /* Local Static Functions */ |
| 48 | static int xilinx_validate (Xilinx_desc * desc, char *fn); |
| 49 | |
| 50 | /* ------------------------------------------------------------------------- */ |
| 51 | |
| 52 | int xilinx_load (Xilinx_desc * desc, void *buf, size_t bsize) |
| 53 | { |
| 54 | int ret_val = FPGA_FAIL; /* assume a failure */ |
| 55 | |
| 56 | if (!xilinx_validate (desc, __FUNCTION__)) { |
| 57 | printf ("%s: Invalid device descriptor\n", __FUNCTION__); |
| 58 | } else |
| 59 | switch (desc->family) { |
| 60 | case Xilinx_Spartan2: |
| 61 | #if (CONFIG_FPGA & CFG_SPARTAN2) |
| 62 | PRINTF ("%s: Launching the Spartan-II Loader...\n", |
| 63 | __FUNCTION__); |
| 64 | ret_val = Spartan2_load (desc, buf, bsize); |
| 65 | #else |
| 66 | printf ("%s: No support for Spartan-II devices.\n", |
| 67 | __FUNCTION__); |
| 68 | #endif |
| 69 | break; |
| 70 | case Xilinx_Virtex2: |
| 71 | #if (CONFIG_FPGA & CFG_VIRTEX2) |
| 72 | PRINTF ("%s: Launching the Virtex-II Loader...\n", |
| 73 | __FUNCTION__); |
| 74 | ret_val = Virtex2_load (desc, buf, bsize); |
| 75 | #else |
| 76 | printf ("%s: No support for Virtex-II devices.\n", |
| 77 | __FUNCTION__); |
| 78 | #endif |
| 79 | break; |
| 80 | |
| 81 | default: |
| 82 | printf ("%s: Unsupported family type, %d\n", |
| 83 | __FUNCTION__, desc->family); |
| 84 | } |
| 85 | |
| 86 | return ret_val; |
| 87 | } |
| 88 | |
| 89 | int xilinx_dump (Xilinx_desc * desc, void *buf, size_t bsize) |
| 90 | { |
| 91 | int ret_val = FPGA_FAIL; /* assume a failure */ |
| 92 | |
| 93 | if (!xilinx_validate (desc, __FUNCTION__)) { |
| 94 | printf ("%s: Invalid device descriptor\n", __FUNCTION__); |
| 95 | } else |
| 96 | switch (desc->family) { |
| 97 | case Xilinx_Spartan2: |
| 98 | #if (CONFIG_FPGA & CFG_SPARTAN2) |
| 99 | PRINTF ("%s: Launching the Spartan-II Reader...\n", |
| 100 | __FUNCTION__); |
| 101 | ret_val = Spartan2_dump (desc, buf, bsize); |
| 102 | #else |
| 103 | printf ("%s: No support for Spartan-II devices.\n", |
| 104 | __FUNCTION__); |
| 105 | #endif |
| 106 | break; |
| 107 | case Xilinx_Virtex2: |
| 108 | #if (CONFIG_FPGA & CFG_VIRTEX2) |
| 109 | PRINTF ("%s: Launching the Virtex-II Reader...\n", |
| 110 | __FUNCTION__); |
| 111 | ret_val = Virtex2_dump (desc, buf, bsize); |
| 112 | #else |
| 113 | printf ("%s: No support for Virtex-II devices.\n", |
| 114 | __FUNCTION__); |
| 115 | #endif |
| 116 | break; |
| 117 | |
| 118 | default: |
| 119 | printf ("%s: Unsupported family type, %d\n", |
| 120 | __FUNCTION__, desc->family); |
| 121 | } |
| 122 | |
| 123 | return ret_val; |
| 124 | } |
| 125 | |
| 126 | int xilinx_info (Xilinx_desc * desc) |
| 127 | { |
| 128 | int ret_val = FPGA_FAIL; |
| 129 | |
| 130 | if (xilinx_validate (desc, __FUNCTION__)) { |
| 131 | printf ("Family: \t"); |
| 132 | switch (desc->family) { |
| 133 | case Xilinx_Spartan2: |
| 134 | printf ("Spartan-II\n"); |
| 135 | break; |
| 136 | case Xilinx_Virtex2: |
| 137 | printf ("Virtex-II\n"); |
| 138 | break; |
| 139 | /* Add new family types here */ |
| 140 | default: |
| 141 | printf ("Unknown family type, %d\n", desc->family); |
| 142 | } |
| 143 | |
| 144 | printf ("Interface type:\t"); |
| 145 | switch (desc->iface) { |
| 146 | case slave_serial: |
| 147 | printf ("Slave Serial\n"); |
| 148 | break; |
| 149 | case master_serial: /* Not used */ |
| 150 | printf ("Master Serial\n"); |
| 151 | break; |
| 152 | case slave_parallel: |
| 153 | printf ("Slave Parallel\n"); |
| 154 | break; |
| 155 | case jtag_mode: /* Not used */ |
| 156 | printf ("JTAG Mode\n"); |
| 157 | break; |
| 158 | case slave_selectmap: |
| 159 | printf ("Slave SelectMap Mode\n"); |
| 160 | break; |
| 161 | case master_selectmap: |
| 162 | printf ("Master SelectMap Mode\n"); |
| 163 | break; |
| 164 | /* Add new interface types here */ |
| 165 | default: |
| 166 | printf ("Unsupported interface type, %d\n", desc->iface); |
| 167 | } |
| 168 | |
| 169 | printf ("Device Size: \t%d bytes\n" |
| 170 | "Cookie: \t0x%x (%d)\n", |
| 171 | desc->size, desc->cookie, desc->cookie); |
| 172 | |
| 173 | if (desc->iface_fns) { |
| 174 | printf ("Device Function Table @ 0x%p\n", desc->iface_fns); |
| 175 | switch (desc->family) { |
| 176 | case Xilinx_Spartan2: |
| 177 | #if (CONFIG_FPGA & CFG_SPARTAN2) |
| 178 | Spartan2_info (desc); |
| 179 | #else |
| 180 | /* just in case */ |
| 181 | printf ("%s: No support for Spartan-II devices.\n", |
| 182 | __FUNCTION__); |
| 183 | #endif |
| 184 | break; |
| 185 | case Xilinx_Virtex2: |
| 186 | #if (CONFIG_FPGA & CFG_VIRTEX2) |
| 187 | Virtex2_info (desc); |
| 188 | #else |
| 189 | /* just in case */ |
| 190 | printf ("%s: No support for Virtex-II devices.\n", |
| 191 | __FUNCTION__); |
| 192 | #endif |
| 193 | break; |
| 194 | /* Add new family types here */ |
| 195 | default: |
| 196 | /* we don't need a message here - we give one up above */ |
| 197 | } |
| 198 | } else |
| 199 | printf ("No Device Function Table.\n"); |
| 200 | |
| 201 | ret_val = FPGA_SUCCESS; |
| 202 | } else { |
| 203 | printf ("%s: Invalid device descriptor\n", __FUNCTION__); |
| 204 | } |
| 205 | |
| 206 | return ret_val; |
| 207 | } |
| 208 | |
| 209 | int xilinx_reloc (Xilinx_desc * desc, ulong reloc_offset) |
| 210 | { |
| 211 | int ret_val = FPGA_FAIL; /* assume a failure */ |
| 212 | |
| 213 | if (!xilinx_validate (desc, __FUNCTION__)) { |
| 214 | printf ("%s: Invalid device descriptor\n", __FUNCTION__); |
| 215 | } else |
| 216 | switch (desc->family) { |
| 217 | case Xilinx_Spartan2: |
| 218 | #if (CONFIG_FPGA & CFG_SPARTAN2) |
| 219 | ret_val = Spartan2_reloc (desc, reloc_offset); |
| 220 | #else |
| 221 | printf ("%s: No support for Spartan-II devices.\n", |
| 222 | __FUNCTION__); |
| 223 | #endif |
| 224 | break; |
| 225 | case Xilinx_Virtex2: |
| 226 | #if (CONFIG_FPGA & CFG_VIRTEX2) |
| 227 | ret_val = Virtex2_reloc (desc, reloc_offset); |
| 228 | #else |
| 229 | printf ("%s: No support for Virtex-II devices.\n", |
| 230 | __FUNCTION__); |
| 231 | #endif |
| 232 | break; |
| 233 | /* Add new family types here */ |
| 234 | default: |
| 235 | printf ("%s: Unsupported family type, %d\n", |
| 236 | __FUNCTION__, desc->family); |
| 237 | } |
| 238 | |
| 239 | return ret_val; |
| 240 | } |
| 241 | |
| 242 | |
| 243 | /* ------------------------------------------------------------------------- */ |
| 244 | |
| 245 | static int xilinx_validate (Xilinx_desc * desc, char *fn) |
| 246 | { |
| 247 | int ret_val = FALSE; |
| 248 | |
| 249 | if (desc) { |
| 250 | if ((desc->family > min_xilinx_type) && |
| 251 | (desc->family < max_xilinx_type)) { |
| 252 | if ((desc->iface > min_xilinx_iface_type) && |
| 253 | (desc->iface < max_xilinx_iface_type)) { |
| 254 | if (desc->size) { |
| 255 | ret_val = TRUE; |
| 256 | } else |
| 257 | printf ("%s: NULL part size\n", fn); |
| 258 | } else |
| 259 | printf ("%s: Invalid Interface type, %d\n", |
| 260 | fn, desc->iface); |
| 261 | } else |
| 262 | printf ("%s: Invalid family type, %d\n", fn, desc->family); |
| 263 | } else |
| 264 | printf ("%s: NULL descriptor!\n", fn); |
| 265 | |
| 266 | return ret_val; |
| 267 | } |
| 268 | |
| 269 | #endif /* CONFIG_FPGA & CFG_FPGA_XILINX */ |