1 // SPDX-License-Identifier: GPL-2.0+
4 * Steven Scholz, imc Measurement & Control, steven.scholz@imc-berlin.de
7 * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
16 #include <stratixII.h>
18 /* Define FPGA_DEBUG to 1 to get debug printf's */
21 static const struct altera_fpga {
22 enum altera_family family;
24 int (*load)(Altera_desc *, const void *, size_t);
25 int (*dump)(Altera_desc *, const void *, size_t);
26 int (*info)(Altera_desc *);
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 },
35 #if defined(CONFIG_FPGA_STRATIX_II)
36 { Altera_StratixII, "StratixII", StratixII_load,
37 StratixII_dump, StratixII_info },
39 #if defined(CONFIG_FPGA_STRATIX_V)
40 { Altera_StratixV, "StratixV", stratixv_load, NULL, NULL },
42 #if defined(CONFIG_FPGA_SOCFPGA)
43 { Altera_SoCFPGA, "SoC FPGA", socfpga_load, NULL, NULL },
47 static int altera_validate(Altera_desc *desc, const char *fn)
50 printf("%s: NULL descriptor!\n", fn);
54 if ((desc->family < min_altera_type) ||
55 (desc->family > max_altera_type)) {
56 printf("%s: Invalid family type, %d\n", fn, desc->family);
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);
67 printf("%s: NULL part size\n", fn);
74 static const struct altera_fpga *
75 altera_desc_to_fpga(Altera_desc *desc, const char *fn)
79 if (altera_validate(desc, fn)) {
80 printf("%s: Invalid device descriptor\n", fn);
84 for (i = 0; i < ARRAY_SIZE(altera_fpga); i++) {
85 if (desc->family == altera_fpga[i].family)
89 if (i == ARRAY_SIZE(altera_fpga)) {
90 printf("%s: Unsupported family type, %d\n", fn, desc->family);
94 return &altera_fpga[i];
97 int altera_load(Altera_desc *desc, const void *buf, size_t bsize)
99 const struct altera_fpga *fpga = altera_desc_to_fpga(desc, __func__);
104 debug_cond(FPGA_DEBUG, "%s: Launching the %s Loader...\n",
105 __func__, fpga->name);
107 return fpga->load(desc, buf, bsize);
111 int altera_dump(Altera_desc *desc, const void *buf, size_t bsize)
113 const struct altera_fpga *fpga = altera_desc_to_fpga(desc, __func__);
118 debug_cond(FPGA_DEBUG, "%s: Launching the %s Reader...\n",
119 __func__, fpga->name);
121 return fpga->dump(desc, buf, bsize);
125 int altera_info(Altera_desc *desc)
127 const struct altera_fpga *fpga = altera_desc_to_fpga(desc, __func__);
132 printf("Family: \t%s\n", fpga->name);
134 printf("Interface type:\t");
135 switch (desc->iface) {
137 printf("Passive Serial (PS)\n");
139 case passive_parallel_synchronous:
140 printf("Passive Parallel Synchronous (PPS)\n");
142 case passive_parallel_asynchronous:
143 printf("Passive Parallel Asynchronous (PPA)\n");
145 case passive_serial_asynchronous:
146 printf("Passive Serial Asynchronous (PSA)\n");
148 case altera_jtag_mode: /* Not used */
149 printf("JTAG Mode\n");
151 case fast_passive_parallel:
152 printf("Fast Passive Parallel (FPP)\n");
154 case fast_passive_parallel_security:
155 printf("Fast Passive Parallel with Security (FPPS)\n");
157 /* Add new interface types here */
159 printf("Unsupported interface type, %d\n", desc->iface);
162 printf("Device Size: \t%zd bytes\n"
163 "Cookie: \t0x%x (%d)\n",
164 desc->size, desc->cookie, desc->cookie);
166 if (desc->iface_fns) {
167 printf("Device Function Table @ 0x%p\n", desc->iface_fns);
171 printf("No Device Function Table.\n");