wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 1 | /* |
wdenk | 5da627a | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 2 | * (C) Copyright 2003 |
| 3 | * Steven Scholz, imc Measurement & Control, steven.scholz@imc-berlin.de |
| 4 | * |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 5 | * (C) Copyright 2002 |
| 6 | * Rich Ireland, Enterasys Networks, rireland@enterasys.com. |
| 7 | * |
| 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 24 | * MA 02111-1307 USA |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | /* |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 29 | * Altera FPGA support |
| 30 | */ |
| 31 | #include <common.h> |
wdenk | 5da627a | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 32 | #include <ACEX1K.h> |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 33 | |
wdenk | 5da627a | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 34 | /* Define FPGA_DEBUG to get debug printf's */ |
| 35 | /* #define FPGA_DEBUG */ |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 36 | |
| 37 | #ifdef FPGA_DEBUG |
| 38 | #define PRINTF(fmt,args...) printf (fmt ,##args) |
| 39 | #else |
| 40 | #define PRINTF(fmt,args...) |
| 41 | #endif |
| 42 | |
| 43 | #if (CONFIG_FPGA & CFG_FPGA_ALTERA) |
| 44 | |
wdenk | 5da627a | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 45 | /* Local Static Functions */ |
| 46 | static int altera_validate (Altera_desc * desc, char *fn); |
| 47 | |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 48 | /* ------------------------------------------------------------------------- */ |
| 49 | int altera_load( Altera_desc *desc, void *buf, size_t bsize ) |
| 50 | { |
wdenk | 5da627a | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 51 | int ret_val = FPGA_FAIL; /* assume a failure */ |
| 52 | |
| 53 | if (!altera_validate (desc, __FUNCTION__)) { |
| 54 | printf ("%s: Invalid device descriptor\n", __FUNCTION__); |
| 55 | } else { |
| 56 | switch (desc->family) { |
| 57 | case Altera_ACEX1K: |
| 58 | #if (CONFIG_FPGA & CFG_ACEX1K) |
| 59 | PRINTF ("%s: Launching the ACEX1K Loader...\n", |
| 60 | __FUNCTION__); |
| 61 | ret_val = ACEX1K_load (desc, buf, bsize); |
| 62 | #else |
| 63 | printf ("%s: No support for ACEX1K devices.\n", |
| 64 | __FUNCTION__); |
| 65 | #endif |
| 66 | break; |
| 67 | |
| 68 | default: |
| 69 | printf ("%s: Unsupported family type, %d\n", |
| 70 | __FUNCTION__, desc->family); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | return ret_val; |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | int altera_dump( Altera_desc *desc, void *buf, size_t bsize ) |
| 78 | { |
wdenk | 5da627a | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 79 | int ret_val = FPGA_FAIL; /* assume a failure */ |
| 80 | |
| 81 | if (!altera_validate (desc, __FUNCTION__)) { |
| 82 | printf ("%s: Invalid device descriptor\n", __FUNCTION__); |
| 83 | } else { |
| 84 | switch (desc->family) { |
| 85 | case Altera_ACEX1K: |
| 86 | #if (CONFIG_FPGA & CFG_ACEX) |
| 87 | PRINTF ("%s: Launching the ACEX1K Reader...\n", |
| 88 | __FUNCTION__); |
| 89 | ret_val = ACEX1K_dump (desc, buf, bsize); |
| 90 | #else |
| 91 | printf ("%s: No support for ACEX1K devices.\n", |
| 92 | __FUNCTION__); |
| 93 | #endif |
| 94 | break; |
| 95 | |
| 96 | default: |
| 97 | printf ("%s: Unsupported family type, %d\n", |
| 98 | __FUNCTION__, desc->family); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | return ret_val; |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | int altera_info( Altera_desc *desc ) |
| 106 | { |
wdenk | 5da627a | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 107 | int ret_val = FPGA_FAIL; |
| 108 | |
| 109 | if (altera_validate (desc, __FUNCTION__)) { |
| 110 | printf ("Family: \t"); |
| 111 | switch (desc->family) { |
| 112 | case Altera_ACEX1K: |
| 113 | printf ("ACEX1K\n"); |
| 114 | break; |
| 115 | /* Add new family types here */ |
| 116 | default: |
| 117 | printf ("Unknown family type, %d\n", desc->family); |
| 118 | } |
| 119 | |
| 120 | printf ("Interface type:\t"); |
| 121 | switch (desc->iface) { |
| 122 | case passive_serial: |
| 123 | printf ("Passive Serial (PS)\n"); |
| 124 | break; |
| 125 | case passive_parallel_synchronous: |
| 126 | printf ("Passive Parallel Synchronous (PPS)\n"); |
| 127 | break; |
| 128 | case passive_parallel_asynchronous: |
| 129 | printf ("Passive Parallel Asynchronous (PPA)\n"); |
| 130 | break; |
| 131 | case passive_serial_asynchronous: |
| 132 | printf ("Passive Serial Asynchronous (PSA)\n"); |
| 133 | break; |
| 134 | case altera_jtag_mode: /* Not used */ |
| 135 | printf ("JTAG Mode\n"); |
| 136 | break; |
| 137 | /* Add new interface types here */ |
| 138 | default: |
| 139 | printf ("Unsupported interface type, %d\n", desc->iface); |
| 140 | } |
| 141 | |
| 142 | printf ("Device Size: \t%d bytes\n" |
| 143 | "Cookie: \t0x%x (%d)\n", |
| 144 | desc->size, desc->cookie, desc->cookie); |
| 145 | |
| 146 | if (desc->iface_fns) { |
| 147 | printf ("Device Function Table @ 0x%p\n", desc->iface_fns); |
| 148 | switch (desc->family) { |
| 149 | case Altera_ACEX1K: |
| 150 | #if (CONFIG_FPGA & CFG_ACEX1K) |
| 151 | ACEX1K_info (desc); |
| 152 | #else |
| 153 | /* just in case */ |
| 154 | printf ("%s: No support for ACEX1K devices.\n", |
| 155 | __FUNCTION__); |
| 156 | #endif |
| 157 | break; |
| 158 | /* Add new family types here */ |
| 159 | default: |
| 160 | /* we don't need a message here - we give one up above */ |
wdenk | b77fad3 | 2005-04-07 22:36:40 +0000 | [diff] [blame] | 161 | break; |
wdenk | 5da627a | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 162 | } |
| 163 | } else { |
| 164 | printf ("No Device Function Table.\n"); |
| 165 | } |
| 166 | |
| 167 | ret_val = FPGA_SUCCESS; |
| 168 | } else { |
| 169 | printf ("%s: Invalid device descriptor\n", __FUNCTION__); |
| 170 | } |
| 171 | |
| 172 | return ret_val; |
| 173 | } |
| 174 | |
| 175 | int altera_reloc( Altera_desc *desc, ulong reloc_offset) |
| 176 | { |
| 177 | int ret_val = FPGA_FAIL; /* assume a failure */ |
| 178 | |
| 179 | if (!altera_validate (desc, __FUNCTION__)) { |
| 180 | printf ("%s: Invalid device descriptor\n", __FUNCTION__); |
| 181 | } else { |
| 182 | switch (desc->family) { |
| 183 | case Altera_ACEX1K: |
| 184 | #if (CONFIG_FPGA & CFG_ACEX1K) |
| 185 | ret_val = ACEX1K_reloc (desc, reloc_offset); |
| 186 | #else |
| 187 | printf ("%s: No support for ACEX devices.\n", |
| 188 | __FUNCTION__); |
| 189 | #endif |
| 190 | break; |
| 191 | /* Add new family types here */ |
| 192 | default: |
| 193 | printf ("%s: Unsupported family type, %d\n", |
| 194 | __FUNCTION__, desc->family); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | return ret_val; |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | /* ------------------------------------------------------------------------- */ |
| 202 | |
wdenk | 5da627a | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 203 | static int altera_validate (Altera_desc * desc, char *fn) |
| 204 | { |
| 205 | int ret_val = FALSE; |
| 206 | |
| 207 | if (desc) { |
| 208 | if ((desc->family > min_altera_type) && |
| 209 | (desc->family < max_altera_type)) { |
| 210 | if ((desc->iface > min_altera_iface_type) && |
| 211 | (desc->iface < max_altera_iface_type)) { |
| 212 | if (desc->size) { |
| 213 | ret_val = TRUE; |
| 214 | } else { |
| 215 | printf ("%s: NULL part size\n", fn); |
| 216 | } |
| 217 | } else { |
| 218 | printf ("%s: Invalid Interface type, %d\n", |
| 219 | fn, desc->iface); |
| 220 | } |
| 221 | } else { |
| 222 | printf ("%s: Invalid family type, %d\n", fn, desc->family); |
| 223 | } |
| 224 | } else { |
| 225 | printf ("%s: NULL descriptor!\n", fn); |
| 226 | } |
| 227 | |
| 228 | return ret_val; |
| 229 | } |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 230 | |
| 231 | /* ------------------------------------------------------------------------- */ |
| 232 | |
wdenk | 5da627a | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 233 | #endif /* CONFIG_FPGA & CFG_FPGA_ALTERA */ |