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 */ |
wdenk | a8c7c70 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 197 | ; |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 198 | } |
| 199 | } else |
| 200 | printf ("No Device Function Table.\n"); |
| 201 | |
| 202 | ret_val = FPGA_SUCCESS; |
| 203 | } else { |
| 204 | printf ("%s: Invalid device descriptor\n", __FUNCTION__); |
| 205 | } |
| 206 | |
| 207 | return ret_val; |
| 208 | } |
| 209 | |
| 210 | int xilinx_reloc (Xilinx_desc * desc, ulong reloc_offset) |
| 211 | { |
| 212 | int ret_val = FPGA_FAIL; /* assume a failure */ |
| 213 | |
| 214 | if (!xilinx_validate (desc, __FUNCTION__)) { |
| 215 | printf ("%s: Invalid device descriptor\n", __FUNCTION__); |
| 216 | } else |
| 217 | switch (desc->family) { |
| 218 | case Xilinx_Spartan2: |
| 219 | #if (CONFIG_FPGA & CFG_SPARTAN2) |
| 220 | ret_val = Spartan2_reloc (desc, reloc_offset); |
| 221 | #else |
| 222 | printf ("%s: No support for Spartan-II devices.\n", |
| 223 | __FUNCTION__); |
| 224 | #endif |
| 225 | break; |
| 226 | case Xilinx_Virtex2: |
| 227 | #if (CONFIG_FPGA & CFG_VIRTEX2) |
| 228 | ret_val = Virtex2_reloc (desc, reloc_offset); |
| 229 | #else |
| 230 | printf ("%s: No support for Virtex-II devices.\n", |
| 231 | __FUNCTION__); |
| 232 | #endif |
| 233 | break; |
| 234 | /* Add new family types here */ |
| 235 | default: |
| 236 | printf ("%s: Unsupported family type, %d\n", |
| 237 | __FUNCTION__, desc->family); |
| 238 | } |
| 239 | |
| 240 | return ret_val; |
| 241 | } |
| 242 | |
| 243 | |
| 244 | /* ------------------------------------------------------------------------- */ |
| 245 | |
| 246 | static int xilinx_validate (Xilinx_desc * desc, char *fn) |
| 247 | { |
| 248 | int ret_val = FALSE; |
| 249 | |
| 250 | if (desc) { |
| 251 | if ((desc->family > min_xilinx_type) && |
| 252 | (desc->family < max_xilinx_type)) { |
| 253 | if ((desc->iface > min_xilinx_iface_type) && |
| 254 | (desc->iface < max_xilinx_iface_type)) { |
| 255 | if (desc->size) { |
| 256 | ret_val = TRUE; |
| 257 | } else |
| 258 | printf ("%s: NULL part size\n", fn); |
| 259 | } else |
| 260 | printf ("%s: Invalid Interface type, %d\n", |
| 261 | fn, desc->iface); |
| 262 | } else |
| 263 | printf ("%s: Invalid family type, %d\n", fn, desc->family); |
| 264 | } else |
| 265 | printf ("%s: NULL descriptor!\n", fn); |
| 266 | |
| 267 | return ret_val; |
| 268 | } |
| 269 | |
| 270 | #endif /* CONFIG_FPGA & CFG_FPGA_XILINX */ |