blob: 4072cb414a2542f01fabeb979fe00a14b00bd058 [file] [log] [blame]
wdenk5d3207d2002-08-21 22:08:56 +00001/*
2 * (C) Copyright 2002
3 * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
4 * Keith Outwater, keith_outwater@mvis.com
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 *
24 */
25
26/*
27 * Xilinx FPGA support
28 */
29
30#include <common.h>
31#include <virtex2.h>
32#include <spartan2.h>
Wolfgang Denk875c7892005-09-25 16:44:21 +020033#include <spartan3.h>
wdenk5d3207d2002-08-21 22:08:56 +000034
wdenk5d3207d2002-08-21 22:08:56 +000035#if 0
36#define FPGA_DEBUG
37#endif
38
39/* Define FPGA_DEBUG to get debug printf's */
40#ifdef FPGA_DEBUG
41#define PRINTF(fmt,args...) printf (fmt ,##args)
42#else
43#define PRINTF(fmt,args...)
44#endif
45
46/* Local Static Functions */
47static int xilinx_validate (Xilinx_desc * desc, char *fn);
48
49/* ------------------------------------------------------------------------- */
50
Wolfgang Denke6a857d2011-07-30 13:33:49 +000051int xilinx_load(Xilinx_desc *desc, const void *buf, size_t bsize)
wdenk5d3207d2002-08-21 22:08:56 +000052{
53 int ret_val = FPGA_FAIL; /* assume a failure */
54
Wolfgang Denk77ddac92005-10-13 16:45:02 +020055 if (!xilinx_validate (desc, (char *)__FUNCTION__)) {
wdenk5d3207d2002-08-21 22:08:56 +000056 printf ("%s: Invalid device descriptor\n", __FUNCTION__);
57 } else
58 switch (desc->family) {
59 case Xilinx_Spartan2:
Matthias Fuchs01335022007-12-27 17:12:34 +010060#if defined(CONFIG_FPGA_SPARTAN2)
wdenk5d3207d2002-08-21 22:08:56 +000061 PRINTF ("%s: Launching the Spartan-II Loader...\n",
62 __FUNCTION__);
63 ret_val = Spartan2_load (desc, buf, bsize);
64#else
65 printf ("%s: No support for Spartan-II devices.\n",
66 __FUNCTION__);
67#endif
68 break;
Wolfgang Denk875c7892005-09-25 16:44:21 +020069 case Xilinx_Spartan3:
Matthias Fuchs01335022007-12-27 17:12:34 +010070#if defined(CONFIG_FPGA_SPARTAN3)
Wolfgang Denk875c7892005-09-25 16:44:21 +020071 PRINTF ("%s: Launching the Spartan-III Loader...\n",
72 __FUNCTION__);
73 ret_val = Spartan3_load (desc, buf, bsize);
74#else
75 printf ("%s: No support for Spartan-III devices.\n",
76 __FUNCTION__);
77#endif
78 break;
wdenk5d3207d2002-08-21 22:08:56 +000079 case Xilinx_Virtex2:
Matthias Fuchs01335022007-12-27 17:12:34 +010080#if defined(CONFIG_FPGA_VIRTEX2)
wdenk5d3207d2002-08-21 22:08:56 +000081 PRINTF ("%s: Launching the Virtex-II Loader...\n",
82 __FUNCTION__);
83 ret_val = Virtex2_load (desc, buf, bsize);
84#else
85 printf ("%s: No support for Virtex-II devices.\n",
86 __FUNCTION__);
87#endif
88 break;
89
90 default:
91 printf ("%s: Unsupported family type, %d\n",
92 __FUNCTION__, desc->family);
93 }
94
95 return ret_val;
96}
97
Wolfgang Denke6a857d2011-07-30 13:33:49 +000098int xilinx_dump(Xilinx_desc *desc, const void *buf, size_t bsize)
wdenk5d3207d2002-08-21 22:08:56 +000099{
100 int ret_val = FPGA_FAIL; /* assume a failure */
101
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200102 if (!xilinx_validate (desc, (char *)__FUNCTION__)) {
wdenk5d3207d2002-08-21 22:08:56 +0000103 printf ("%s: Invalid device descriptor\n", __FUNCTION__);
104 } else
105 switch (desc->family) {
106 case Xilinx_Spartan2:
Matthias Fuchs01335022007-12-27 17:12:34 +0100107#if defined(CONFIG_FPGA_SPARTAN2)
wdenk5d3207d2002-08-21 22:08:56 +0000108 PRINTF ("%s: Launching the Spartan-II Reader...\n",
109 __FUNCTION__);
110 ret_val = Spartan2_dump (desc, buf, bsize);
111#else
112 printf ("%s: No support for Spartan-II devices.\n",
113 __FUNCTION__);
114#endif
115 break;
Wolfgang Denk875c7892005-09-25 16:44:21 +0200116 case Xilinx_Spartan3:
Matthias Fuchs01335022007-12-27 17:12:34 +0100117#if defined(CONFIG_FPGA_SPARTAN3)
Wolfgang Denk875c7892005-09-25 16:44:21 +0200118 PRINTF ("%s: Launching the Spartan-III Reader...\n",
119 __FUNCTION__);
120 ret_val = Spartan3_dump (desc, buf, bsize);
121#else
122 printf ("%s: No support for Spartan-III devices.\n",
123 __FUNCTION__);
124#endif
125 break;
wdenk5d3207d2002-08-21 22:08:56 +0000126 case Xilinx_Virtex2:
Matthias Fuchs01335022007-12-27 17:12:34 +0100127#if defined( CONFIG_FPGA_VIRTEX2)
wdenk5d3207d2002-08-21 22:08:56 +0000128 PRINTF ("%s: Launching the Virtex-II Reader...\n",
129 __FUNCTION__);
130 ret_val = Virtex2_dump (desc, buf, bsize);
131#else
132 printf ("%s: No support for Virtex-II devices.\n",
133 __FUNCTION__);
134#endif
135 break;
136
137 default:
138 printf ("%s: Unsupported family type, %d\n",
139 __FUNCTION__, desc->family);
140 }
141
142 return ret_val;
143}
144
145int xilinx_info (Xilinx_desc * desc)
146{
147 int ret_val = FPGA_FAIL;
148
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200149 if (xilinx_validate (desc, (char *)__FUNCTION__)) {
wdenk5d3207d2002-08-21 22:08:56 +0000150 printf ("Family: \t");
151 switch (desc->family) {
152 case Xilinx_Spartan2:
153 printf ("Spartan-II\n");
154 break;
Wolfgang Denk875c7892005-09-25 16:44:21 +0200155 case Xilinx_Spartan3:
156 printf ("Spartan-III\n");
157 break;
wdenk5d3207d2002-08-21 22:08:56 +0000158 case Xilinx_Virtex2:
159 printf ("Virtex-II\n");
160 break;
161 /* Add new family types here */
162 default:
163 printf ("Unknown family type, %d\n", desc->family);
164 }
165
166 printf ("Interface type:\t");
167 switch (desc->iface) {
168 case slave_serial:
169 printf ("Slave Serial\n");
170 break;
171 case master_serial: /* Not used */
172 printf ("Master Serial\n");
173 break;
174 case slave_parallel:
175 printf ("Slave Parallel\n");
176 break;
177 case jtag_mode: /* Not used */
178 printf ("JTAG Mode\n");
179 break;
180 case slave_selectmap:
181 printf ("Slave SelectMap Mode\n");
182 break;
183 case master_selectmap:
184 printf ("Master SelectMap Mode\n");
185 break;
186 /* Add new interface types here */
187 default:
188 printf ("Unsupported interface type, %d\n", desc->iface);
189 }
190
191 printf ("Device Size: \t%d bytes\n"
192 "Cookie: \t0x%x (%d)\n",
193 desc->size, desc->cookie, desc->cookie);
194
195 if (desc->iface_fns) {
196 printf ("Device Function Table @ 0x%p\n", desc->iface_fns);
197 switch (desc->family) {
198 case Xilinx_Spartan2:
Matthias Fuchs01335022007-12-27 17:12:34 +0100199#if defined(CONFIG_FPGA_SPARTAN2)
wdenk5d3207d2002-08-21 22:08:56 +0000200 Spartan2_info (desc);
201#else
202 /* just in case */
203 printf ("%s: No support for Spartan-II devices.\n",
204 __FUNCTION__);
205#endif
206 break;
Wolfgang Denk875c7892005-09-25 16:44:21 +0200207 case Xilinx_Spartan3:
Matthias Fuchs01335022007-12-27 17:12:34 +0100208#if defined(CONFIG_FPGA_SPARTAN3)
Wolfgang Denk875c7892005-09-25 16:44:21 +0200209 Spartan3_info (desc);
210#else
211 /* just in case */
212 printf ("%s: No support for Spartan-III devices.\n",
213 __FUNCTION__);
214#endif
215 break;
wdenk5d3207d2002-08-21 22:08:56 +0000216 case Xilinx_Virtex2:
Matthias Fuchs01335022007-12-27 17:12:34 +0100217#if defined(CONFIG_FPGA_VIRTEX2)
wdenk5d3207d2002-08-21 22:08:56 +0000218 Virtex2_info (desc);
219#else
220 /* just in case */
221 printf ("%s: No support for Virtex-II devices.\n",
222 __FUNCTION__);
223#endif
224 break;
225 /* Add new family types here */
226 default:
227 /* we don't need a message here - we give one up above */
wdenka8c7c702003-12-06 19:49:23 +0000228 ;
wdenk5d3207d2002-08-21 22:08:56 +0000229 }
230 } else
231 printf ("No Device Function Table.\n");
232
233 ret_val = FPGA_SUCCESS;
234 } else {
235 printf ("%s: Invalid device descriptor\n", __FUNCTION__);
236 }
237
238 return ret_val;
239}
240
wdenk5d3207d2002-08-21 22:08:56 +0000241/* ------------------------------------------------------------------------- */
242
243static int xilinx_validate (Xilinx_desc * desc, char *fn)
244{
245 int ret_val = FALSE;
246
247 if (desc) {
248 if ((desc->family > min_xilinx_type) &&
249 (desc->family < max_xilinx_type)) {
250 if ((desc->iface > min_xilinx_iface_type) &&
251 (desc->iface < max_xilinx_iface_type)) {
252 if (desc->size) {
253 ret_val = TRUE;
254 } else
255 printf ("%s: NULL part size\n", fn);
256 } else
257 printf ("%s: Invalid Interface type, %d\n",
258 fn, desc->iface);
259 } else
260 printf ("%s: Invalid family type, %d\n", fn, desc->family);
261 } else
262 printf ("%s: NULL descriptor!\n", fn);
263
264 return ret_val;
265}