1 // 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 },
46 #if defined(CONFIG_FPGA_INTEL_SDM_MAILBOX)
47 { Intel_FPGA_SDM_Mailbox, "Intel SDM Mailbox", intel_sdm_mb_load, NULL,
52 static int altera_validate(Altera_desc *desc, const char *fn)
55 printf("%s: NULL descriptor!\n", fn);
59 if ((desc->family < min_altera_type) ||
60 (desc->family > max_altera_type)) {
61 printf("%s: Invalid family type, %d\n", fn, desc->family);
65 if ((desc->iface < min_altera_iface_type) ||
66 (desc->iface > max_altera_iface_type)) {
67 printf("%s: Invalid Interface type, %d\n", fn, desc->iface);
72 printf("%s: NULL part size\n", fn);
79 static const struct altera_fpga *
80 altera_desc_to_fpga(Altera_desc *desc, const char *fn)
84 if (altera_validate(desc, fn)) {
85 printf("%s: Invalid device descriptor\n", fn);
89 for (i = 0; i < ARRAY_SIZE(altera_fpga); i++) {
90 if (desc->family == altera_fpga[i].family)
94 if (i == ARRAY_SIZE(altera_fpga)) {
95 printf("%s: Unsupported family type, %d\n", fn, desc->family);
99 return &altera_fpga[i];
102 int altera_load(Altera_desc *desc, const void *buf, size_t bsize)
104 const struct altera_fpga *fpga = altera_desc_to_fpga(desc, __func__);
109 debug_cond(FPGA_DEBUG, "%s: Launching the %s Loader...\n",
110 __func__, fpga->name);
112 return fpga->load(desc, buf, bsize);
116 int altera_dump(Altera_desc *desc, const void *buf, size_t bsize)
118 const struct altera_fpga *fpga = altera_desc_to_fpga(desc, __func__);
123 debug_cond(FPGA_DEBUG, "%s: Launching the %s Reader...\n",
124 __func__, fpga->name);
126 return fpga->dump(desc, buf, bsize);
130 int altera_info(Altera_desc *desc)
132 const struct altera_fpga *fpga = altera_desc_to_fpga(desc, __func__);
137 printf("Family: \t%s\n", fpga->name);
139 printf("Interface type:\t");
140 switch (desc->iface) {
142 printf("Passive Serial (PS)\n");
144 case passive_parallel_synchronous:
145 printf("Passive Parallel Synchronous (PPS)\n");
147 case passive_parallel_asynchronous:
148 printf("Passive Parallel Asynchronous (PPA)\n");
150 case passive_serial_asynchronous:
151 printf("Passive Serial Asynchronous (PSA)\n");
153 case altera_jtag_mode: /* Not used */
154 printf("JTAG Mode\n");
156 case fast_passive_parallel:
157 printf("Fast Passive Parallel (FPP)\n");
159 case fast_passive_parallel_security:
160 printf("Fast Passive Parallel with Security (FPPS)\n");
162 case secure_device_manager_mailbox:
163 puts("Secure Device Manager (SDM) Mailbox\n");
165 /* Add new interface types here */
167 printf("Unsupported interface type, %d\n", desc->iface);
170 printf("Device Size: \t%zd bytes\n"
171 "Cookie: \t0x%x (%d)\n",
172 desc->size, desc->cookie, desc->cookie);
174 if (desc->iface_fns) {
175 printf("Device Function Table @ 0x%p\n", desc->iface_fns);
179 printf("No Device Function Table.\n");