1 // SPDX-License-Identifier: GPL-2.0+
10 #define LOG_CATEGORY UCLASS_FPGA
18 #include <stratixII.h>
20 static const struct altera_fpga {
21 enum altera_family family;
23 int (*load)(Altera_desc *, const void *, size_t);
24 int (*dump)(Altera_desc *, const void *, size_t);
25 int (*info)(Altera_desc *);
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 },
34 #if defined(CONFIG_FPGA_STRATIX_II)
35 { Altera_StratixII, "StratixII", StratixII_load,
36 StratixII_dump, StratixII_info },
38 #if defined(CONFIG_FPGA_STRATIX_V)
39 { Altera_StratixV, "StratixV", stratixv_load, NULL, NULL },
41 #if defined(CONFIG_FPGA_SOCFPGA)
42 { Altera_SoCFPGA, "SoC FPGA", socfpga_load, NULL, NULL },
44 #if defined(CONFIG_FPGA_INTEL_SDM_MAILBOX)
45 { Intel_FPGA_SDM_Mailbox, "Intel SDM Mailbox", intel_sdm_mb_load, NULL,
50 static int altera_validate(Altera_desc *desc, const char *fn)
53 printf("%s: NULL descriptor!\n", fn);
57 if ((desc->family < min_altera_type) ||
58 (desc->family > max_altera_type)) {
59 printf("%s: Invalid family type, %d\n", fn, desc->family);
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);
70 printf("%s: NULL part size\n", fn);
77 static const struct altera_fpga *
78 altera_desc_to_fpga(Altera_desc *desc, const char *fn)
82 if (altera_validate(desc, fn)) {
83 printf("%s: Invalid device descriptor\n", fn);
87 for (i = 0; i < ARRAY_SIZE(altera_fpga); i++) {
88 if (desc->family == altera_fpga[i].family)
92 if (i == ARRAY_SIZE(altera_fpga)) {
93 printf("%s: Unsupported family type, %d\n", fn, desc->family);
97 return &altera_fpga[i];
100 int altera_load(Altera_desc *desc, const void *buf, size_t bsize)
102 const struct altera_fpga *fpga = altera_desc_to_fpga(desc, __func__);
107 log_debug("Launching the %s Loader...\n", fpga->name);
109 return fpga->load(desc, buf, bsize);
113 int altera_dump(Altera_desc *desc, const void *buf, size_t bsize)
115 const struct altera_fpga *fpga = altera_desc_to_fpga(desc, __func__);
120 log_debug("Launching the %s Reader...\n", 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 case secure_device_manager_mailbox:
159 puts("Secure Device Manager (SDM) Mailbox\n");
161 /* Add new interface types here */
163 printf("Unsupported interface type, %d\n", desc->iface);
166 printf("Device Size: \t%zd bytes\n"
167 "Cookie: \t0x%x (%d)\n",
168 desc->size, desc->cookie, desc->cookie);
170 if (desc->iface_fns) {
171 printf("Device Function Table @ 0x%p\n", desc->iface_fns);
175 printf("No Device Function Table.\n");