Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2002 |
| 4 | * Rich Ireland, Enterasys Networks, rireland@enterasys.com. |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 7 | /* Generic FPGA support */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 8 | #include <common.h> /* core U-Boot definitions */ |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 9 | #include <init.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 11 | #include <xilinx.h> /* xilinx specific definitions */ |
| 12 | #include <altera.h> /* altera specific definitions */ |
Stefano Babic | 3b8ac46 | 2010-06-29 11:47:48 +0200 | [diff] [blame] | 13 | #include <lattice.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 14 | #include <dm/device_compat.h> |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 15 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 16 | /* Local definitions */ |
| 17 | #ifndef CONFIG_MAX_FPGA_DEVICES |
| 18 | #define CONFIG_MAX_FPGA_DEVICES 5 |
| 19 | #endif |
| 20 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 21 | /* Local static data */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 22 | static int next_desc = FPGA_INVALID_DEVICE; |
| 23 | static fpga_desc desc_table[CONFIG_MAX_FPGA_DEVICES]; |
| 24 | |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 25 | /* |
| 26 | * fpga_no_sup |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 27 | * 'no support' message function |
| 28 | */ |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 29 | static void fpga_no_sup(char *fn, char *msg) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 30 | { |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 31 | if (fn && msg) |
| 32 | printf("%s: No support for %s.\n", fn, msg); |
| 33 | else if (msg) |
| 34 | printf("No support for %s.\n", msg); |
| 35 | else |
Robert P. J. Day | 62a3b7d | 2016-07-15 13:44:45 -0400 | [diff] [blame] | 36 | printf("No FPGA support!\n"); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | |
| 40 | /* fpga_get_desc |
| 41 | * map a device number to a descriptor |
| 42 | */ |
Michal Simek | ebd322d | 2015-01-13 16:09:53 +0100 | [diff] [blame] | 43 | const fpga_desc *const fpga_get_desc(int devnum) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 44 | { |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 45 | fpga_desc *desc = (fpga_desc *)NULL; |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 46 | |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 47 | if ((devnum >= 0) && (devnum < next_desc)) { |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 48 | desc = &desc_table[devnum]; |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 49 | debug("%s: found fpga descriptor #%d @ 0x%p\n", |
| 50 | __func__, devnum, desc); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | return desc; |
| 54 | } |
| 55 | |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 56 | /* |
| 57 | * fpga_validate |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 58 | * generic parameter checking code |
| 59 | */ |
Michal Simek | 6631db4 | 2013-04-26 15:04:48 +0200 | [diff] [blame] | 60 | const fpga_desc *const fpga_validate(int devnum, const void *buf, |
| 61 | size_t bsize, char *fn) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 62 | { |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 63 | const fpga_desc *desc = fpga_get_desc(devnum); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 64 | |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 65 | if (!desc) |
| 66 | printf("%s: Invalid device number %d\n", fn, devnum); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 67 | |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 68 | if (!buf) { |
| 69 | printf("%s: Null buffer.\n", fn); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 70 | return (fpga_desc * const)NULL; |
| 71 | } |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 72 | return desc; |
| 73 | } |
| 74 | |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 75 | /* |
| 76 | * fpga_dev_info |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 77 | * generic multiplexing code |
| 78 | */ |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 79 | static int fpga_dev_info(int devnum) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 80 | { |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 81 | int ret_val = FPGA_FAIL; /* assume failure */ |
| 82 | const fpga_desc * const desc = fpga_get_desc(devnum); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 83 | |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 84 | if (desc) { |
| 85 | debug("%s: Device Descriptor @ 0x%p\n", |
| 86 | __func__, desc->devdesc); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 87 | |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 88 | switch (desc->devtype) { |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 89 | case fpga_xilinx: |
Matthias Fuchs | 0133502 | 2007-12-27 17:12:34 +0100 | [diff] [blame] | 90 | #if defined(CONFIG_FPGA_XILINX) |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 91 | printf("Xilinx Device\nDescriptor @ 0x%p\n", desc); |
| 92 | ret_val = xilinx_info(desc->devdesc); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 93 | #else |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 94 | fpga_no_sup((char *)__func__, "Xilinx devices"); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 95 | #endif |
| 96 | break; |
| 97 | case fpga_altera: |
Matthias Fuchs | 0133502 | 2007-12-27 17:12:34 +0100 | [diff] [blame] | 98 | #if defined(CONFIG_FPGA_ALTERA) |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 99 | printf("Altera Device\nDescriptor @ 0x%p\n", desc); |
| 100 | ret_val = altera_info(desc->devdesc); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 101 | #else |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 102 | fpga_no_sup((char *)__func__, "Altera devices"); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 103 | #endif |
| 104 | break; |
Stefano Babic | 3b8ac46 | 2010-06-29 11:47:48 +0200 | [diff] [blame] | 105 | case fpga_lattice: |
Wolfgang Denk | 439f6f7 | 2010-10-18 21:32:14 +0200 | [diff] [blame] | 106 | #if defined(CONFIG_FPGA_LATTICE) |
Stefano Babic | 3b8ac46 | 2010-06-29 11:47:48 +0200 | [diff] [blame] | 107 | printf("Lattice Device\nDescriptor @ 0x%p\n", desc); |
| 108 | ret_val = lattice_info(desc->devdesc); |
Wolfgang Denk | 439f6f7 | 2010-10-18 21:32:14 +0200 | [diff] [blame] | 109 | #else |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 110 | fpga_no_sup((char *)__func__, "Lattice devices"); |
Wolfgang Denk | 439f6f7 | 2010-10-18 21:32:14 +0200 | [diff] [blame] | 111 | #endif |
Stefano Babic | 3b8ac46 | 2010-06-29 11:47:48 +0200 | [diff] [blame] | 112 | break; |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 113 | default: |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 114 | printf("%s: Invalid or unsupported device type %d\n", |
| 115 | __func__, desc->devtype); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 116 | } |
| 117 | } else { |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 118 | printf("%s: Invalid device number %d\n", __func__, devnum); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | return ret_val; |
| 122 | } |
| 123 | |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 124 | /* |
Michal Simek | 905bca6 | 2016-05-17 14:32:00 +0200 | [diff] [blame] | 125 | * fpga_init is usually called from misc_init_r() and MUST be called |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 126 | * before any of the other fpga functions are used. |
| 127 | */ |
Peter Tyser | 6385b28 | 2009-09-21 11:20:32 -0500 | [diff] [blame] | 128 | void fpga_init(void) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 129 | { |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 130 | next_desc = 0; |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 131 | memset(desc_table, 0, sizeof(desc_table)); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 132 | |
Michal Simek | ee976c1 | 2013-04-26 09:38:26 +0200 | [diff] [blame] | 133 | debug("%s\n", __func__); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 136 | /* |
| 137 | * fpga_count |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 138 | * Basic interface function to get the current number of devices available. |
| 139 | */ |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 140 | int fpga_count(void) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 141 | { |
| 142 | return next_desc; |
| 143 | } |
| 144 | |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 145 | /* |
| 146 | * fpga_add |
Peter Tyser | 6385b28 | 2009-09-21 11:20:32 -0500 | [diff] [blame] | 147 | * Add the device descriptor to the device table. |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 148 | */ |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 149 | int fpga_add(fpga_type devtype, void *desc) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 150 | { |
| 151 | int devnum = FPGA_INVALID_DEVICE; |
| 152 | |
Michal Simek | cda1e3f | 2018-01-26 13:17:04 +0100 | [diff] [blame] | 153 | if (!desc) { |
| 154 | printf("%s: NULL device descriptor\n", __func__); |
| 155 | return devnum; |
| 156 | } |
| 157 | |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 158 | if (next_desc < 0) { |
| 159 | printf("%s: FPGA support not initialized!\n", __func__); |
| 160 | } else if ((devtype > fpga_min_type) && (devtype < fpga_undefined)) { |
Michal Simek | cda1e3f | 2018-01-26 13:17:04 +0100 | [diff] [blame] | 161 | if (next_desc < CONFIG_MAX_FPGA_DEVICES) { |
| 162 | devnum = next_desc; |
| 163 | desc_table[next_desc].devtype = devtype; |
| 164 | desc_table[next_desc++].devdesc = desc; |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 165 | } else { |
Michal Simek | cda1e3f | 2018-01-26 13:17:04 +0100 | [diff] [blame] | 166 | printf("%s: Exceeded Max FPGA device count\n", |
| 167 | __func__); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 168 | } |
| 169 | } else { |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 170 | printf("%s: Unsupported FPGA type %d\n", __func__, devtype); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | return devnum; |
| 174 | } |
| 175 | |
| 176 | /* |
Goldschmidt Simon | 8b93a92 | 2017-11-10 14:17:41 +0000 | [diff] [blame] | 177 | * Return 1 if the fpga data is partial. |
| 178 | * This is only required for fpga drivers that support bitstream_type. |
| 179 | */ |
| 180 | int __weak fpga_is_partial_data(int devnum, size_t img_len) |
| 181 | { |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | /* |
Michal Simek | 52c2064 | 2013-04-26 13:12:07 +0200 | [diff] [blame] | 186 | * Convert bitstream data and load into the fpga |
| 187 | */ |
Michal Simek | 7a78bd2 | 2014-05-02 14:09:30 +0200 | [diff] [blame] | 188 | int __weak fpga_loadbitstream(int devnum, char *fpgadata, size_t size, |
| 189 | bitstream_type bstype) |
Michal Simek | 52c2064 | 2013-04-26 13:12:07 +0200 | [diff] [blame] | 190 | { |
| 191 | printf("Bitstream support not implemented for this FPGA device\n"); |
| 192 | return FPGA_FAIL; |
| 193 | } |
| 194 | |
Siva Durga Prasad Paladugu | 1a89766 | 2014-03-14 16:35:37 +0530 | [diff] [blame] | 195 | #if defined(CONFIG_CMD_FPGA_LOADFS) |
| 196 | int fpga_fsload(int devnum, const void *buf, size_t size, |
| 197 | fpga_fs_info *fpga_fsinfo) |
| 198 | { |
| 199 | int ret_val = FPGA_FAIL; /* assume failure */ |
| 200 | const fpga_desc *desc = fpga_validate(devnum, buf, size, |
| 201 | (char *)__func__); |
| 202 | |
| 203 | if (desc) { |
| 204 | switch (desc->devtype) { |
| 205 | case fpga_xilinx: |
| 206 | #if defined(CONFIG_FPGA_XILINX) |
| 207 | ret_val = xilinx_loadfs(desc->devdesc, buf, size, |
| 208 | fpga_fsinfo); |
| 209 | #else |
| 210 | fpga_no_sup((char *)__func__, "Xilinx devices"); |
| 211 | #endif |
| 212 | break; |
| 213 | default: |
| 214 | printf("%s: Invalid or unsupported device type %d\n", |
| 215 | __func__, desc->devtype); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | return ret_val; |
| 220 | } |
| 221 | #endif |
| 222 | |
Siva Durga Prasad Paladugu | cedd48e | 2018-05-31 15:10:22 +0530 | [diff] [blame] | 223 | #if defined(CONFIG_CMD_FPGA_LOAD_SECURE) |
| 224 | int fpga_loads(int devnum, const void *buf, size_t size, |
| 225 | struct fpga_secure_info *fpga_sec_info) |
| 226 | { |
| 227 | int ret_val = FPGA_FAIL; |
| 228 | |
| 229 | const fpga_desc *desc = fpga_validate(devnum, buf, size, |
| 230 | (char *)__func__); |
| 231 | |
| 232 | if (desc) { |
| 233 | switch (desc->devtype) { |
| 234 | case fpga_xilinx: |
| 235 | #if defined(CONFIG_FPGA_XILINX) |
| 236 | ret_val = xilinx_loads(desc->devdesc, buf, size, |
| 237 | fpga_sec_info); |
| 238 | #else |
| 239 | fpga_no_sup((char *)__func__, "Xilinx devices"); |
| 240 | #endif |
| 241 | break; |
| 242 | default: |
| 243 | printf("%s: Invalid or unsupported device type %d\n", |
| 244 | __func__, desc->devtype); |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | return ret_val; |
| 249 | } |
| 250 | #endif |
| 251 | |
Michal Simek | 52c2064 | 2013-04-26 13:12:07 +0200 | [diff] [blame] | 252 | /* |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 253 | * Generic multiplexing code |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 254 | */ |
Michal Simek | 7a78bd2 | 2014-05-02 14:09:30 +0200 | [diff] [blame] | 255 | int fpga_load(int devnum, const void *buf, size_t bsize, bitstream_type bstype) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 256 | { |
| 257 | int ret_val = FPGA_FAIL; /* assume failure */ |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 258 | const fpga_desc *desc = fpga_validate(devnum, buf, bsize, |
| 259 | (char *)__func__); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 260 | |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 261 | if (desc) { |
| 262 | switch (desc->devtype) { |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 263 | case fpga_xilinx: |
Matthias Fuchs | 0133502 | 2007-12-27 17:12:34 +0100 | [diff] [blame] | 264 | #if defined(CONFIG_FPGA_XILINX) |
Michal Simek | 7a78bd2 | 2014-05-02 14:09:30 +0200 | [diff] [blame] | 265 | ret_val = xilinx_load(desc->devdesc, buf, bsize, |
| 266 | bstype); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 267 | #else |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 268 | fpga_no_sup((char *)__func__, "Xilinx devices"); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 269 | #endif |
| 270 | break; |
| 271 | case fpga_altera: |
Matthias Fuchs | 0133502 | 2007-12-27 17:12:34 +0100 | [diff] [blame] | 272 | #if defined(CONFIG_FPGA_ALTERA) |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 273 | ret_val = altera_load(desc->devdesc, buf, bsize); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 274 | #else |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 275 | fpga_no_sup((char *)__func__, "Altera devices"); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 276 | #endif |
| 277 | break; |
Stefano Babic | 3b8ac46 | 2010-06-29 11:47:48 +0200 | [diff] [blame] | 278 | case fpga_lattice: |
Wolfgang Denk | 439f6f7 | 2010-10-18 21:32:14 +0200 | [diff] [blame] | 279 | #if defined(CONFIG_FPGA_LATTICE) |
Stefano Babic | 3b8ac46 | 2010-06-29 11:47:48 +0200 | [diff] [blame] | 280 | ret_val = lattice_load(desc->devdesc, buf, bsize); |
Wolfgang Denk | 439f6f7 | 2010-10-18 21:32:14 +0200 | [diff] [blame] | 281 | #else |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 282 | fpga_no_sup((char *)__func__, "Lattice devices"); |
Wolfgang Denk | 439f6f7 | 2010-10-18 21:32:14 +0200 | [diff] [blame] | 283 | #endif |
Stefano Babic | 3b8ac46 | 2010-06-29 11:47:48 +0200 | [diff] [blame] | 284 | break; |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 285 | default: |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 286 | printf("%s: Invalid or unsupported device type %d\n", |
| 287 | __func__, desc->devtype); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 288 | } |
| 289 | } |
| 290 | |
| 291 | return ret_val; |
| 292 | } |
| 293 | |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 294 | /* |
| 295 | * fpga_dump |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 296 | * generic multiplexing code |
| 297 | */ |
Wolfgang Denk | e6a857d | 2011-07-30 13:33:49 +0000 | [diff] [blame] | 298 | int fpga_dump(int devnum, const void *buf, size_t bsize) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 299 | { |
| 300 | int ret_val = FPGA_FAIL; /* assume failure */ |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 301 | const fpga_desc *desc = fpga_validate(devnum, buf, bsize, |
| 302 | (char *)__func__); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 303 | |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 304 | if (desc) { |
| 305 | switch (desc->devtype) { |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 306 | case fpga_xilinx: |
Matthias Fuchs | 0133502 | 2007-12-27 17:12:34 +0100 | [diff] [blame] | 307 | #if defined(CONFIG_FPGA_XILINX) |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 308 | ret_val = xilinx_dump(desc->devdesc, buf, bsize); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 309 | #else |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 310 | fpga_no_sup((char *)__func__, "Xilinx devices"); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 311 | #endif |
| 312 | break; |
| 313 | case fpga_altera: |
Matthias Fuchs | 0133502 | 2007-12-27 17:12:34 +0100 | [diff] [blame] | 314 | #if defined(CONFIG_FPGA_ALTERA) |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 315 | ret_val = altera_dump(desc->devdesc, buf, bsize); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 316 | #else |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 317 | fpga_no_sup((char *)__func__, "Altera devices"); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 318 | #endif |
| 319 | break; |
Stefano Babic | 3b8ac46 | 2010-06-29 11:47:48 +0200 | [diff] [blame] | 320 | case fpga_lattice: |
Wolfgang Denk | 439f6f7 | 2010-10-18 21:32:14 +0200 | [diff] [blame] | 321 | #if defined(CONFIG_FPGA_LATTICE) |
Stefano Babic | 3b8ac46 | 2010-06-29 11:47:48 +0200 | [diff] [blame] | 322 | ret_val = lattice_dump(desc->devdesc, buf, bsize); |
Wolfgang Denk | 439f6f7 | 2010-10-18 21:32:14 +0200 | [diff] [blame] | 323 | #else |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 324 | fpga_no_sup((char *)__func__, "Lattice devices"); |
Wolfgang Denk | 439f6f7 | 2010-10-18 21:32:14 +0200 | [diff] [blame] | 325 | #endif |
Stefano Babic | 3b8ac46 | 2010-06-29 11:47:48 +0200 | [diff] [blame] | 326 | break; |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 327 | default: |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 328 | printf("%s: Invalid or unsupported device type %d\n", |
| 329 | __func__, desc->devtype); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 330 | } |
| 331 | } |
| 332 | |
| 333 | return ret_val; |
| 334 | } |
| 335 | |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 336 | /* |
| 337 | * fpga_info |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 338 | * front end to fpga_dev_info. If devnum is invalid, report on all |
| 339 | * available devices. |
| 340 | */ |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 341 | int fpga_info(int devnum) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 342 | { |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 343 | if (devnum == FPGA_INVALID_DEVICE) { |
| 344 | if (next_desc > 0) { |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 345 | int dev; |
| 346 | |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 347 | for (dev = 0; dev < next_desc; dev++) |
| 348 | fpga_dev_info(dev); |
| 349 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 350 | return FPGA_SUCCESS; |
| 351 | } else { |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 352 | printf("%s: No FPGA devices available.\n", __func__); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 353 | return FPGA_FAIL; |
| 354 | } |
| 355 | } |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 356 | |
Michal Simek | f6555d9 | 2013-04-26 08:46:56 +0200 | [diff] [blame] | 357 | return fpga_dev_info(devnum); |
| 358 | } |