Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 2 | /* |
wdenk | 5da627a | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 3 | * (C) Copyright 2003 |
| 4 | * Steven Scholz, imc Measurement & Control, steven.scholz@imc-berlin.de |
| 5 | * |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 6 | * (C) Copyright 2002 |
| 7 | * Rich Ireland, Enterasys Networks, rireland@enterasys.com. |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | /* |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 11 | * Altera FPGA support |
| 12 | */ |
| 13 | #include <common.h> |
Marek Vasut | fda915a | 2014-09-16 20:33:54 +0200 | [diff] [blame] | 14 | #include <errno.h> |
wdenk | 5da627a | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 15 | #include <ACEX1K.h> |
eran liberty | 3c735e7 | 2008-03-27 00:50:49 +0100 | [diff] [blame] | 16 | #include <stratixII.h> |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 17 | |
Marek Vasut | 0ae16cb | 2014-09-16 20:21:42 +0200 | [diff] [blame] | 18 | /* Define FPGA_DEBUG to 1 to get debug printf's */ |
| 19 | #define FPGA_DEBUG 0 |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 20 | |
Marek Vasut | 2012f23 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 21 | static const struct altera_fpga { |
| 22 | enum altera_family family; |
| 23 | const char *name; |
| 24 | int (*load)(Altera_desc *, const void *, size_t); |
| 25 | int (*dump)(Altera_desc *, const void *, size_t); |
| 26 | int (*info)(Altera_desc *); |
| 27 | } altera_fpga[] = { |
| 28 | #if defined(CONFIG_FPGA_ACEX1K) |
| 29 | { Altera_ACEX1K, "ACEX1K", ACEX1K_load, ACEX1K_dump, ACEX1K_info }, |
| 30 | { Altera_CYC2, "ACEX1K", ACEX1K_load, ACEX1K_dump, ACEX1K_info }, |
| 31 | #elif defined(CONFIG_FPGA_CYCLON2) |
| 32 | { Altera_ACEX1K, "CycloneII", CYC2_load, CYC2_dump, CYC2_info }, |
| 33 | { Altera_CYC2, "CycloneII", CYC2_load, CYC2_dump, CYC2_info }, |
| 34 | #endif |
| 35 | #if defined(CONFIG_FPGA_STRATIX_II) |
| 36 | { Altera_StratixII, "StratixII", StratixII_load, |
| 37 | StratixII_dump, StratixII_info }, |
| 38 | #endif |
Stefan Roese | ff9c4c5 | 2016-02-12 13:48:02 +0100 | [diff] [blame] | 39 | #if defined(CONFIG_FPGA_STRATIX_V) |
| 40 | { Altera_StratixV, "StratixV", stratixv_load, NULL, NULL }, |
| 41 | #endif |
Pavel Machek | 230fe9b | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 42 | #if defined(CONFIG_FPGA_SOCFPGA) |
| 43 | { Altera_SoCFPGA, "SoC FPGA", socfpga_load, NULL, NULL }, |
| 44 | #endif |
Marek Vasut | 2012f23 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 45 | }; |
| 46 | |
Marek Vasut | 54c96b1 | 2014-09-16 20:32:51 +0200 | [diff] [blame] | 47 | static int altera_validate(Altera_desc *desc, const char *fn) |
| 48 | { |
| 49 | if (!desc) { |
| 50 | printf("%s: NULL descriptor!\n", fn); |
Marek Vasut | fda915a | 2014-09-16 20:33:54 +0200 | [diff] [blame] | 51 | return -EINVAL; |
Marek Vasut | 54c96b1 | 2014-09-16 20:32:51 +0200 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | if ((desc->family < min_altera_type) || |
| 55 | (desc->family > max_altera_type)) { |
| 56 | printf("%s: Invalid family type, %d\n", fn, desc->family); |
Marek Vasut | fda915a | 2014-09-16 20:33:54 +0200 | [diff] [blame] | 57 | return -EINVAL; |
Marek Vasut | 54c96b1 | 2014-09-16 20:32:51 +0200 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | if ((desc->iface < min_altera_iface_type) || |
| 61 | (desc->iface > max_altera_iface_type)) { |
| 62 | printf("%s: Invalid Interface type, %d\n", fn, desc->iface); |
Marek Vasut | fda915a | 2014-09-16 20:33:54 +0200 | [diff] [blame] | 63 | return -EINVAL; |
Marek Vasut | 54c96b1 | 2014-09-16 20:32:51 +0200 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | if (!desc->size) { |
| 67 | printf("%s: NULL part size\n", fn); |
Marek Vasut | fda915a | 2014-09-16 20:33:54 +0200 | [diff] [blame] | 68 | return -EINVAL; |
Marek Vasut | 54c96b1 | 2014-09-16 20:32:51 +0200 | [diff] [blame] | 69 | } |
| 70 | |
Marek Vasut | fda915a | 2014-09-16 20:33:54 +0200 | [diff] [blame] | 71 | return 0; |
Marek Vasut | 54c96b1 | 2014-09-16 20:32:51 +0200 | [diff] [blame] | 72 | } |
wdenk | 5da627a | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 73 | |
Marek Vasut | 2012f23 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 74 | static const struct altera_fpga * |
| 75 | altera_desc_to_fpga(Altera_desc *desc, const char *fn) |
| 76 | { |
| 77 | int i; |
| 78 | |
| 79 | if (altera_validate(desc, fn)) { |
| 80 | printf("%s: Invalid device descriptor\n", fn); |
| 81 | return NULL; |
| 82 | } |
| 83 | |
| 84 | for (i = 0; i < ARRAY_SIZE(altera_fpga); i++) { |
| 85 | if (desc->family == altera_fpga[i].family) |
| 86 | break; |
| 87 | } |
| 88 | |
| 89 | if (i == ARRAY_SIZE(altera_fpga)) { |
| 90 | printf("%s: Unsupported family type, %d\n", fn, desc->family); |
| 91 | return NULL; |
| 92 | } |
| 93 | |
| 94 | return &altera_fpga[i]; |
| 95 | } |
| 96 | |
Wolfgang Denk | e6a857d | 2011-07-30 13:33:49 +0000 | [diff] [blame] | 97 | int altera_load(Altera_desc *desc, const void *buf, size_t bsize) |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 98 | { |
Marek Vasut | 2012f23 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 99 | const struct altera_fpga *fpga = altera_desc_to_fpga(desc, __func__); |
wdenk | 5da627a | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 100 | |
Marek Vasut | 2012f23 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 101 | if (!fpga) |
Marek Vasut | 4a4c0a5 | 2014-09-16 20:29:24 +0200 | [diff] [blame] | 102 | return FPGA_FAIL; |
Marek Vasut | 4a4c0a5 | 2014-09-16 20:29:24 +0200 | [diff] [blame] | 103 | |
Marek Vasut | 2012f23 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 104 | debug_cond(FPGA_DEBUG, "%s: Launching the %s Loader...\n", |
| 105 | __func__, fpga->name); |
| 106 | if (fpga->load) |
| 107 | return fpga->load(desc, buf, bsize); |
| 108 | return 0; |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Wolfgang Denk | e6a857d | 2011-07-30 13:33:49 +0000 | [diff] [blame] | 111 | int altera_dump(Altera_desc *desc, const void *buf, size_t bsize) |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 112 | { |
Marek Vasut | 2012f23 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 113 | const struct altera_fpga *fpga = altera_desc_to_fpga(desc, __func__); |
wdenk | 5da627a | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 114 | |
Marek Vasut | 2012f23 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 115 | if (!fpga) |
Marek Vasut | 4a4c0a5 | 2014-09-16 20:29:24 +0200 | [diff] [blame] | 116 | return FPGA_FAIL; |
Marek Vasut | 4a4c0a5 | 2014-09-16 20:29:24 +0200 | [diff] [blame] | 117 | |
Marek Vasut | 2012f23 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 118 | debug_cond(FPGA_DEBUG, "%s: Launching the %s Reader...\n", |
| 119 | __func__, fpga->name); |
| 120 | if (fpga->dump) |
| 121 | return fpga->dump(desc, buf, bsize); |
| 122 | return 0; |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Marek Vasut | 4a4c0a5 | 2014-09-16 20:29:24 +0200 | [diff] [blame] | 125 | int altera_info(Altera_desc *desc) |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 126 | { |
Marek Vasut | 2012f23 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 127 | const struct altera_fpga *fpga = altera_desc_to_fpga(desc, __func__); |
wdenk | 5da627a | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 128 | |
Marek Vasut | 2012f23 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 129 | if (!fpga) |
Marek Vasut | 4a4c0a5 | 2014-09-16 20:29:24 +0200 | [diff] [blame] | 130 | return FPGA_FAIL; |
Marek Vasut | 4a4c0a5 | 2014-09-16 20:29:24 +0200 | [diff] [blame] | 131 | |
Marek Vasut | 2012f23 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 132 | printf("Family: \t%s\n", fpga->name); |
Marek Vasut | 4a4c0a5 | 2014-09-16 20:29:24 +0200 | [diff] [blame] | 133 | |
| 134 | printf("Interface type:\t"); |
| 135 | switch (desc->iface) { |
| 136 | case passive_serial: |
| 137 | printf("Passive Serial (PS)\n"); |
| 138 | break; |
| 139 | case passive_parallel_synchronous: |
| 140 | printf("Passive Parallel Synchronous (PPS)\n"); |
| 141 | break; |
| 142 | case passive_parallel_asynchronous: |
| 143 | printf("Passive Parallel Asynchronous (PPA)\n"); |
| 144 | break; |
| 145 | case passive_serial_asynchronous: |
| 146 | printf("Passive Serial Asynchronous (PSA)\n"); |
| 147 | break; |
| 148 | case altera_jtag_mode: /* Not used */ |
| 149 | printf("JTAG Mode\n"); |
| 150 | break; |
| 151 | case fast_passive_parallel: |
| 152 | printf("Fast Passive Parallel (FPP)\n"); |
| 153 | break; |
| 154 | case fast_passive_parallel_security: |
| 155 | printf("Fast Passive Parallel with Security (FPPS)\n"); |
| 156 | break; |
| 157 | /* Add new interface types here */ |
| 158 | default: |
| 159 | printf("Unsupported interface type, %d\n", desc->iface); |
| 160 | } |
| 161 | |
| 162 | printf("Device Size: \t%zd bytes\n" |
| 163 | "Cookie: \t0x%x (%d)\n", |
| 164 | desc->size, desc->cookie, desc->cookie); |
| 165 | |
| 166 | if (desc->iface_fns) { |
| 167 | printf("Device Function Table @ 0x%p\n", desc->iface_fns); |
Marek Vasut | 2012f23 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 168 | if (fpga->info) |
| 169 | fpga->info(desc); |
wdenk | 5da627a | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 170 | } else { |
Marek Vasut | 4a4c0a5 | 2014-09-16 20:29:24 +0200 | [diff] [blame] | 171 | printf("No Device Function Table.\n"); |
wdenk | 5da627a | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Marek Vasut | 2012f23 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 174 | return FPGA_SUCCESS; |
wdenk | 5da627a | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 175 | } |