3 * Steven Scholz, imc Measurement & Control, steven.scholz@imc-berlin.de
6 * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
8 * SPDX-License-Identifier: GPL-2.0+
17 #include <stratixII.h>
19 /* Define FPGA_DEBUG to 1 to get debug printf's */
22 static const struct altera_fpga {
23 enum altera_family family;
25 int (*load)(Altera_desc *, const void *, size_t);
26 int (*dump)(Altera_desc *, const void *, size_t);
27 int (*info)(Altera_desc *);
29 #if defined(CONFIG_FPGA_ACEX1K)
30 { Altera_ACEX1K, "ACEX1K", ACEX1K_load, ACEX1K_dump, ACEX1K_info },
31 { Altera_CYC2, "ACEX1K", ACEX1K_load, ACEX1K_dump, ACEX1K_info },
32 #elif defined(CONFIG_FPGA_CYCLON2)
33 { Altera_ACEX1K, "CycloneII", CYC2_load, CYC2_dump, CYC2_info },
34 { Altera_CYC2, "CycloneII", CYC2_load, CYC2_dump, CYC2_info },
36 #if defined(CONFIG_FPGA_STRATIX_II)
37 { Altera_StratixII, "StratixII", StratixII_load,
38 StratixII_dump, StratixII_info },
40 #if defined(CONFIG_FPGA_STRATIX_V)
41 { Altera_StratixV, "StratixV", stratixv_load, NULL, NULL },
43 #if defined(CONFIG_FPGA_SOCFPGA)
44 { Altera_SoCFPGA, "SoC FPGA", socfpga_load, NULL, NULL },
48 static int altera_validate(Altera_desc *desc, const char *fn)
51 printf("%s: NULL descriptor!\n", fn);
55 if ((desc->family < min_altera_type) ||
56 (desc->family > max_altera_type)) {
57 printf("%s: Invalid family type, %d\n", fn, desc->family);
61 if ((desc->iface < min_altera_iface_type) ||
62 (desc->iface > max_altera_iface_type)) {
63 printf("%s: Invalid Interface type, %d\n", fn, desc->iface);
68 printf("%s: NULL part size\n", fn);
75 static const struct altera_fpga *
76 altera_desc_to_fpga(Altera_desc *desc, const char *fn)
80 if (altera_validate(desc, fn)) {
81 printf("%s: Invalid device descriptor\n", fn);
85 for (i = 0; i < ARRAY_SIZE(altera_fpga); i++) {
86 if (desc->family == altera_fpga[i].family)
90 if (i == ARRAY_SIZE(altera_fpga)) {
91 printf("%s: Unsupported family type, %d\n", fn, desc->family);
95 return &altera_fpga[i];
98 int altera_load(Altera_desc *desc, const void *buf, size_t bsize)
100 const struct altera_fpga *fpga = altera_desc_to_fpga(desc, __func__);
105 debug_cond(FPGA_DEBUG, "%s: Launching the %s Loader...\n",
106 __func__, fpga->name);
108 return fpga->load(desc, buf, bsize);
112 int altera_dump(Altera_desc *desc, const void *buf, size_t bsize)
114 const struct altera_fpga *fpga = altera_desc_to_fpga(desc, __func__);
119 debug_cond(FPGA_DEBUG, "%s: Launching the %s Reader...\n",
120 __func__, fpga->name);
122 return fpga->dump(desc, buf, bsize);
126 int altera_info(Altera_desc *desc)
128 const struct altera_fpga *fpga = altera_desc_to_fpga(desc, __func__);
133 printf("Family: \t%s\n", fpga->name);
135 printf("Interface type:\t");
136 switch (desc->iface) {
138 printf("Passive Serial (PS)\n");
140 case passive_parallel_synchronous:
141 printf("Passive Parallel Synchronous (PPS)\n");
143 case passive_parallel_asynchronous:
144 printf("Passive Parallel Asynchronous (PPA)\n");
146 case passive_serial_asynchronous:
147 printf("Passive Serial Asynchronous (PSA)\n");
149 case altera_jtag_mode: /* Not used */
150 printf("JTAG Mode\n");
152 case fast_passive_parallel:
153 printf("Fast Passive Parallel (FPP)\n");
155 case fast_passive_parallel_security:
156 printf("Fast Passive Parallel with Security (FPPS)\n");
158 /* Add new interface types here */
160 printf("Unsupported interface type, %d\n", desc->iface);
163 printf("Device Size: \t%zd bytes\n"
164 "Cookie: \t0x%x (%d)\n",
165 desc->size, desc->cookie, desc->cookie);
167 if (desc->iface_fns) {
168 printf("Device Function Table @ 0x%p\n", desc->iface_fns);
172 printf("No Device Function Table.\n");