blob: af189f4ef4c580f9231a95b07ff76cbccfa23904 [file] [log] [blame]
wdenk5b845b62002-08-21 21:57:24 +00001/*
wdenk5da627a2003-10-09 20:09:04 +00002 * (C) Copyright 2003
3 * Steven Scholz, imc Measurement & Control, steven.scholz@imc-berlin.de
4 *
wdenk5b845b62002-08-21 21:57:24 +00005 * (C) Copyright 2002
6 * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
7 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
wdenk5b845b62002-08-21 21:57:24 +00009 */
10
11/*
wdenk5b845b62002-08-21 21:57:24 +000012 * Altera FPGA support
13 */
14#include <common.h>
wdenk5da627a2003-10-09 20:09:04 +000015#include <ACEX1K.h>
eran liberty3c735e72008-03-27 00:50:49 +010016#include <stratixII.h>
wdenk5b845b62002-08-21 21:57:24 +000017
wdenk5da627a2003-10-09 20:09:04 +000018/* Define FPGA_DEBUG to get debug printf's */
19/* #define FPGA_DEBUG */
wdenk5b845b62002-08-21 21:57:24 +000020
21#ifdef FPGA_DEBUG
22#define PRINTF(fmt,args...) printf (fmt ,##args)
23#else
24#define PRINTF(fmt,args...)
25#endif
26
wdenk5da627a2003-10-09 20:09:04 +000027/* Local Static Functions */
eran liberty3c735e72008-03-27 00:50:49 +010028static int altera_validate (Altera_desc * desc, const char *fn);
wdenk5da627a2003-10-09 20:09:04 +000029
wdenk5b845b62002-08-21 21:57:24 +000030/* ------------------------------------------------------------------------- */
Wolfgang Denke6a857d2011-07-30 13:33:49 +000031int altera_load(Altera_desc *desc, const void *buf, size_t bsize)
wdenk5b845b62002-08-21 21:57:24 +000032{
wdenk5da627a2003-10-09 20:09:04 +000033 int ret_val = FPGA_FAIL; /* assume a failure */
34
Stefan Roese64cd52e2006-09-18 10:48:03 +020035 if (!altera_validate (desc, (char *)__FUNCTION__)) {
wdenk5da627a2003-10-09 20:09:04 +000036 printf ("%s: Invalid device descriptor\n", __FUNCTION__);
37 } else {
38 switch (desc->family) {
39 case Altera_ACEX1K:
Stefan Roesef0ff4692006-08-15 14:15:51 +020040 case Altera_CYC2:
Matthias Fuchs01335022007-12-27 17:12:34 +010041#if defined(CONFIG_FPGA_ACEX1K)
wdenk5da627a2003-10-09 20:09:04 +000042 PRINTF ("%s: Launching the ACEX1K Loader...\n",
43 __FUNCTION__);
44 ret_val = ACEX1K_load (desc, buf, bsize);
eran liberty3c735e72008-03-27 00:50:49 +010045#elif defined(CONFIG_FPGA_CYCLON2)
Michael Jonesf18361b2011-07-14 22:09:29 +000046 PRINTF ("%s: Launching the CYCLONE II Loader...\n",
Stefan Roesef0ff4692006-08-15 14:15:51 +020047 __FUNCTION__);
48 ret_val = CYC2_load (desc, buf, bsize);
wdenk5da627a2003-10-09 20:09:04 +000049#else
50 printf ("%s: No support for ACEX1K devices.\n",
51 __FUNCTION__);
52#endif
53 break;
54
eran liberty3c735e72008-03-27 00:50:49 +010055#if defined(CONFIG_FPGA_STRATIX_II)
56 case Altera_StratixII:
57 PRINTF ("%s: Launching the Stratix II Loader...\n",
58 __FUNCTION__);
59 ret_val = StratixII_load (desc, buf, bsize);
60 break;
61#endif
wdenk5da627a2003-10-09 20:09:04 +000062 default:
63 printf ("%s: Unsupported family type, %d\n",
64 __FUNCTION__, desc->family);
65 }
66 }
67
68 return ret_val;
wdenk5b845b62002-08-21 21:57:24 +000069}
70
Wolfgang Denke6a857d2011-07-30 13:33:49 +000071int altera_dump(Altera_desc *desc, const void *buf, size_t bsize)
wdenk5b845b62002-08-21 21:57:24 +000072{
wdenk5da627a2003-10-09 20:09:04 +000073 int ret_val = FPGA_FAIL; /* assume a failure */
74
Stefan Roese64cd52e2006-09-18 10:48:03 +020075 if (!altera_validate (desc, (char *)__FUNCTION__)) {
wdenk5da627a2003-10-09 20:09:04 +000076 printf ("%s: Invalid device descriptor\n", __FUNCTION__);
77 } else {
78 switch (desc->family) {
79 case Altera_ACEX1K:
Matthias Fuchs01335022007-12-27 17:12:34 +010080#if defined(CONFIG_FPGA_ACEX)
wdenk5da627a2003-10-09 20:09:04 +000081 PRINTF ("%s: Launching the ACEX1K Reader...\n",
82 __FUNCTION__);
83 ret_val = ACEX1K_dump (desc, buf, bsize);
84#else
85 printf ("%s: No support for ACEX1K devices.\n",
86 __FUNCTION__);
87#endif
88 break;
89
eran liberty3c735e72008-03-27 00:50:49 +010090#if defined(CONFIG_FPGA_STRATIX_II)
91 case Altera_StratixII:
92 PRINTF ("%s: Launching the Stratix II Reader...\n",
93 __FUNCTION__);
94 ret_val = StratixII_dump (desc, buf, bsize);
95 break;
96#endif
wdenk5da627a2003-10-09 20:09:04 +000097 default:
98 printf ("%s: Unsupported family type, %d\n",
99 __FUNCTION__, desc->family);
100 }
101 }
102
103 return ret_val;
wdenk5b845b62002-08-21 21:57:24 +0000104}
105
106int altera_info( Altera_desc *desc )
107{
wdenk5da627a2003-10-09 20:09:04 +0000108 int ret_val = FPGA_FAIL;
109
Stefan Roese64cd52e2006-09-18 10:48:03 +0200110 if (altera_validate (desc, (char *)__FUNCTION__)) {
wdenk5da627a2003-10-09 20:09:04 +0000111 printf ("Family: \t");
112 switch (desc->family) {
113 case Altera_ACEX1K:
114 printf ("ACEX1K\n");
115 break;
Stefan Roesef0ff4692006-08-15 14:15:51 +0200116 case Altera_CYC2:
117 printf ("CYCLON II\n");
118 break;
eran liberty3c735e72008-03-27 00:50:49 +0100119 case Altera_StratixII:
120 printf ("Stratix II\n");
121 break;
122 /* Add new family types here */
wdenk5da627a2003-10-09 20:09:04 +0000123 default:
124 printf ("Unknown family type, %d\n", desc->family);
125 }
126
127 printf ("Interface type:\t");
128 switch (desc->iface) {
129 case passive_serial:
130 printf ("Passive Serial (PS)\n");
131 break;
132 case passive_parallel_synchronous:
133 printf ("Passive Parallel Synchronous (PPS)\n");
134 break;
135 case passive_parallel_asynchronous:
136 printf ("Passive Parallel Asynchronous (PPA)\n");
137 break;
138 case passive_serial_asynchronous:
139 printf ("Passive Serial Asynchronous (PSA)\n");
140 break;
141 case altera_jtag_mode: /* Not used */
142 printf ("JTAG Mode\n");
143 break;
eran liberty3c735e72008-03-27 00:50:49 +0100144 case fast_passive_parallel:
145 printf ("Fast Passive Parallel (FPP)\n");
146 break;
147 case fast_passive_parallel_security:
148 printf
149 ("Fast Passive Parallel with Security (FPPS) \n");
150 break;
wdenk5da627a2003-10-09 20:09:04 +0000151 /* Add new interface types here */
152 default:
153 printf ("Unsupported interface type, %d\n", desc->iface);
154 }
155
156 printf ("Device Size: \t%d bytes\n"
157 "Cookie: \t0x%x (%d)\n",
158 desc->size, desc->cookie, desc->cookie);
159
160 if (desc->iface_fns) {
161 printf ("Device Function Table @ 0x%p\n", desc->iface_fns);
162 switch (desc->family) {
163 case Altera_ACEX1K:
Stefan Roesef0ff4692006-08-15 14:15:51 +0200164 case Altera_CYC2:
Matthias Fuchs01335022007-12-27 17:12:34 +0100165#if defined(CONFIG_FPGA_ACEX1K)
wdenk5da627a2003-10-09 20:09:04 +0000166 ACEX1K_info (desc);
Matthias Fuchs01335022007-12-27 17:12:34 +0100167#elif defined(CONFIG_FPGA_CYCLON2)
Stefan Roesef0ff4692006-08-15 14:15:51 +0200168 CYC2_info (desc);
wdenk5da627a2003-10-09 20:09:04 +0000169#else
170 /* just in case */
171 printf ("%s: No support for ACEX1K devices.\n",
172 __FUNCTION__);
173#endif
174 break;
eran liberty3c735e72008-03-27 00:50:49 +0100175#if defined(CONFIG_FPGA_STRATIX_II)
176 case Altera_StratixII:
177 StratixII_info (desc);
178 break;
179#endif
wdenk5da627a2003-10-09 20:09:04 +0000180 /* Add new family types here */
181 default:
182 /* we don't need a message here - we give one up above */
wdenkb77fad32005-04-07 22:36:40 +0000183 break;
wdenk5da627a2003-10-09 20:09:04 +0000184 }
185 } else {
186 printf ("No Device Function Table.\n");
187 }
188
189 ret_val = FPGA_SUCCESS;
190 } else {
191 printf ("%s: Invalid device descriptor\n", __FUNCTION__);
192 }
193
194 return ret_val;
195}
196
wdenk5b845b62002-08-21 21:57:24 +0000197/* ------------------------------------------------------------------------- */
198
eran liberty3c735e72008-03-27 00:50:49 +0100199static int altera_validate (Altera_desc * desc, const char *fn)
wdenk5da627a2003-10-09 20:09:04 +0000200{
York Sun472d5462013-04-01 11:29:11 -0700201 int ret_val = false;
wdenk5da627a2003-10-09 20:09:04 +0000202
203 if (desc) {
204 if ((desc->family > min_altera_type) &&
205 (desc->family < max_altera_type)) {
206 if ((desc->iface > min_altera_iface_type) &&
207 (desc->iface < max_altera_iface_type)) {
208 if (desc->size) {
York Sun472d5462013-04-01 11:29:11 -0700209 ret_val = true;
wdenk5da627a2003-10-09 20:09:04 +0000210 } else {
211 printf ("%s: NULL part size\n", fn);
212 }
213 } else {
214 printf ("%s: Invalid Interface type, %d\n",
215 fn, desc->iface);
216 }
217 } else {
218 printf ("%s: Invalid family type, %d\n", fn, desc->family);
219 }
220 } else {
221 printf ("%s: NULL descriptor!\n", fn);
222 }
223
224 return ret_val;
225}
wdenk5b845b62002-08-21 21:57:24 +0000226
227/* ------------------------------------------------------------------------- */