Tom Rini | 10e4779 | 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 | 9b7f384 | 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 | |
Alexander Dahl | b9f41d5 | 2022-10-07 14:19:58 +0200 | [diff] [blame] | 10 | #define LOG_CATEGORY UCLASS_FPGA |
| 11 | |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 12 | /* |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 13 | * Altera FPGA support |
| 14 | */ |
Marek Vasut | b9d4df3 | 2014-09-16 20:33:54 +0200 | [diff] [blame] | 15 | #include <errno.h> |
wdenk | 9b7f384 | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 16 | #include <ACEX1K.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 17 | #include <log.h> |
eran liberty | 4c373a9 | 2008-03-27 00:50:49 +0100 | [diff] [blame] | 18 | #include <stratixII.h> |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 19 | |
Marek Vasut | f5d25e4 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 20 | static const struct altera_fpga { |
| 21 | enum altera_family family; |
| 22 | const char *name; |
| 23 | int (*load)(Altera_desc *, const void *, size_t); |
| 24 | int (*dump)(Altera_desc *, const void *, size_t); |
| 25 | int (*info)(Altera_desc *); |
| 26 | } altera_fpga[] = { |
| 27 | #if defined(CONFIG_FPGA_ACEX1K) |
| 28 | { Altera_ACEX1K, "ACEX1K", ACEX1K_load, ACEX1K_dump, ACEX1K_info }, |
| 29 | { Altera_CYC2, "ACEX1K", ACEX1K_load, ACEX1K_dump, ACEX1K_info }, |
| 30 | #elif defined(CONFIG_FPGA_CYCLON2) |
| 31 | { Altera_ACEX1K, "CycloneII", CYC2_load, CYC2_dump, CYC2_info }, |
| 32 | { Altera_CYC2, "CycloneII", CYC2_load, CYC2_dump, CYC2_info }, |
| 33 | #endif |
| 34 | #if defined(CONFIG_FPGA_STRATIX_II) |
| 35 | { Altera_StratixII, "StratixII", StratixII_load, |
| 36 | StratixII_dump, StratixII_info }, |
| 37 | #endif |
Stefan Roese | d919d72 | 2016-02-12 13:48:02 +0100 | [diff] [blame] | 38 | #if defined(CONFIG_FPGA_STRATIX_V) |
| 39 | { Altera_StratixV, "StratixV", stratixv_load, NULL, NULL }, |
| 40 | #endif |
Pavel Machek | c721380 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 41 | #if defined(CONFIG_FPGA_SOCFPGA) |
| 42 | { Altera_SoCFPGA, "SoC FPGA", socfpga_load, NULL, NULL }, |
| 43 | #endif |
Chee Hong Ang | 1419245 | 2020-08-07 11:50:03 +0800 | [diff] [blame] | 44 | #if defined(CONFIG_FPGA_INTEL_SDM_MAILBOX) |
| 45 | { Intel_FPGA_SDM_Mailbox, "Intel SDM Mailbox", intel_sdm_mb_load, NULL, |
| 46 | NULL }, |
| 47 | #endif |
Marek Vasut | f5d25e4 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 48 | }; |
| 49 | |
Marek Vasut | ff4072c | 2014-09-16 20:32:51 +0200 | [diff] [blame] | 50 | static int altera_validate(Altera_desc *desc, const char *fn) |
| 51 | { |
| 52 | if (!desc) { |
| 53 | printf("%s: NULL descriptor!\n", fn); |
Marek Vasut | b9d4df3 | 2014-09-16 20:33:54 +0200 | [diff] [blame] | 54 | return -EINVAL; |
Marek Vasut | ff4072c | 2014-09-16 20:32:51 +0200 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | if ((desc->family < min_altera_type) || |
| 58 | (desc->family > max_altera_type)) { |
| 59 | printf("%s: Invalid family type, %d\n", fn, desc->family); |
Marek Vasut | b9d4df3 | 2014-09-16 20:33:54 +0200 | [diff] [blame] | 60 | return -EINVAL; |
Marek Vasut | ff4072c | 2014-09-16 20:32:51 +0200 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | if ((desc->iface < min_altera_iface_type) || |
| 64 | (desc->iface > max_altera_iface_type)) { |
| 65 | printf("%s: Invalid Interface type, %d\n", fn, desc->iface); |
Marek Vasut | b9d4df3 | 2014-09-16 20:33:54 +0200 | [diff] [blame] | 66 | return -EINVAL; |
Marek Vasut | ff4072c | 2014-09-16 20:32:51 +0200 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | if (!desc->size) { |
| 70 | printf("%s: NULL part size\n", fn); |
Marek Vasut | b9d4df3 | 2014-09-16 20:33:54 +0200 | [diff] [blame] | 71 | return -EINVAL; |
Marek Vasut | ff4072c | 2014-09-16 20:32:51 +0200 | [diff] [blame] | 72 | } |
| 73 | |
Marek Vasut | b9d4df3 | 2014-09-16 20:33:54 +0200 | [diff] [blame] | 74 | return 0; |
Marek Vasut | ff4072c | 2014-09-16 20:32:51 +0200 | [diff] [blame] | 75 | } |
wdenk | 9b7f384 | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 76 | |
Marek Vasut | f5d25e4 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 77 | static const struct altera_fpga * |
| 78 | altera_desc_to_fpga(Altera_desc *desc, const char *fn) |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 79 | { |
Marek Vasut | f5d25e4 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 80 | int i; |
wdenk | 9b7f384 | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 81 | |
Marek Vasut | f5d25e4 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 82 | if (altera_validate(desc, fn)) { |
| 83 | printf("%s: Invalid device descriptor\n", fn); |
| 84 | return NULL; |
Marek Vasut | 1822135 | 2014-09-16 20:29:24 +0200 | [diff] [blame] | 85 | } |
| 86 | |
Marek Vasut | f5d25e4 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 87 | for (i = 0; i < ARRAY_SIZE(altera_fpga); i++) { |
| 88 | if (desc->family == altera_fpga[i].family) |
| 89 | break; |
| 90 | } |
wdenk | 9b7f384 | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 91 | |
Marek Vasut | f5d25e4 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 92 | if (i == ARRAY_SIZE(altera_fpga)) { |
| 93 | printf("%s: Unsupported family type, %d\n", fn, desc->family); |
| 94 | return NULL; |
wdenk | 9b7f384 | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Marek Vasut | f5d25e4 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 97 | return &altera_fpga[i]; |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 98 | } |
| 99 | |
Marek Vasut | f5d25e4 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 100 | int altera_load(Altera_desc *desc, const void *buf, size_t bsize) |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 101 | { |
Marek Vasut | f5d25e4 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 102 | const struct altera_fpga *fpga = altera_desc_to_fpga(desc, __func__); |
wdenk | 9b7f384 | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 103 | |
Marek Vasut | f5d25e4 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 104 | if (!fpga) |
Marek Vasut | 1822135 | 2014-09-16 20:29:24 +0200 | [diff] [blame] | 105 | return FPGA_FAIL; |
Marek Vasut | 1822135 | 2014-09-16 20:29:24 +0200 | [diff] [blame] | 106 | |
Alexander Dahl | b9f41d5 | 2022-10-07 14:19:58 +0200 | [diff] [blame] | 107 | log_debug("Launching the %s Loader...\n", fpga->name); |
Marek Vasut | f5d25e4 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 108 | if (fpga->load) |
| 109 | return fpga->load(desc, buf, bsize); |
| 110 | return 0; |
| 111 | } |
wdenk | 9b7f384 | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 112 | |
Marek Vasut | f5d25e4 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 113 | int altera_dump(Altera_desc *desc, const void *buf, size_t bsize) |
| 114 | { |
| 115 | const struct altera_fpga *fpga = altera_desc_to_fpga(desc, __func__); |
wdenk | 9b7f384 | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 116 | |
Marek Vasut | f5d25e4 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 117 | if (!fpga) |
| 118 | return FPGA_FAIL; |
| 119 | |
Alexander Dahl | b9f41d5 | 2022-10-07 14:19:58 +0200 | [diff] [blame] | 120 | log_debug("Launching the %s Reader...\n", fpga->name); |
Marek Vasut | f5d25e4 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 121 | if (fpga->dump) |
| 122 | return fpga->dump(desc, buf, bsize); |
| 123 | return 0; |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 124 | } |
| 125 | |
Marek Vasut | 1822135 | 2014-09-16 20:29:24 +0200 | [diff] [blame] | 126 | int altera_info(Altera_desc *desc) |
wdenk | 5b845b6 | 2002-08-21 21:57:24 +0000 | [diff] [blame] | 127 | { |
Marek Vasut | f5d25e4 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 128 | const struct altera_fpga *fpga = altera_desc_to_fpga(desc, __func__); |
wdenk | 9b7f384 | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 129 | |
Marek Vasut | f5d25e4 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 130 | if (!fpga) |
Marek Vasut | 1822135 | 2014-09-16 20:29:24 +0200 | [diff] [blame] | 131 | return FPGA_FAIL; |
wdenk | 9b7f384 | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 132 | |
Marek Vasut | f5d25e4 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 133 | printf("Family: \t%s\n", fpga->name); |
wdenk | 9b7f384 | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 134 | |
Marek Vasut | 1822135 | 2014-09-16 20:29:24 +0200 | [diff] [blame] | 135 | printf("Interface type:\t"); |
| 136 | switch (desc->iface) { |
| 137 | case passive_serial: |
| 138 | printf("Passive Serial (PS)\n"); |
| 139 | break; |
| 140 | case passive_parallel_synchronous: |
| 141 | printf("Passive Parallel Synchronous (PPS)\n"); |
| 142 | break; |
| 143 | case passive_parallel_asynchronous: |
| 144 | printf("Passive Parallel Asynchronous (PPA)\n"); |
| 145 | break; |
| 146 | case passive_serial_asynchronous: |
| 147 | printf("Passive Serial Asynchronous (PSA)\n"); |
| 148 | break; |
| 149 | case altera_jtag_mode: /* Not used */ |
| 150 | printf("JTAG Mode\n"); |
| 151 | break; |
| 152 | case fast_passive_parallel: |
| 153 | printf("Fast Passive Parallel (FPP)\n"); |
| 154 | break; |
| 155 | case fast_passive_parallel_security: |
| 156 | printf("Fast Passive Parallel with Security (FPPS)\n"); |
| 157 | break; |
Ang, Chee Hong | ff14f16 | 2018-12-19 18:35:15 -0800 | [diff] [blame] | 158 | case secure_device_manager_mailbox: |
| 159 | puts("Secure Device Manager (SDM) Mailbox\n"); |
| 160 | break; |
Marek Vasut | 1822135 | 2014-09-16 20:29:24 +0200 | [diff] [blame] | 161 | /* Add new interface types here */ |
| 162 | default: |
| 163 | printf("Unsupported interface type, %d\n", desc->iface); |
| 164 | } |
| 165 | |
| 166 | printf("Device Size: \t%zd bytes\n" |
| 167 | "Cookie: \t0x%x (%d)\n", |
| 168 | desc->size, desc->cookie, desc->cookie); |
wdenk | 9b7f384 | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 169 | |
Marek Vasut | 1822135 | 2014-09-16 20:29:24 +0200 | [diff] [blame] | 170 | if (desc->iface_fns) { |
| 171 | printf("Device Function Table @ 0x%p\n", desc->iface_fns); |
Marek Vasut | f5d25e4 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 172 | if (fpga->info) |
| 173 | fpga->info(desc); |
wdenk | 9b7f384 | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 174 | } else { |
Marek Vasut | 1822135 | 2014-09-16 20:29:24 +0200 | [diff] [blame] | 175 | printf("No Device Function Table.\n"); |
wdenk | 9b7f384 | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Marek Vasut | f5d25e4 | 2014-09-16 21:17:51 +0200 | [diff] [blame] | 178 | return FPGA_SUCCESS; |
wdenk | 9b7f384 | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 179 | } |