]> git.sur5r.net Git - u-boot/blob - drivers/fpga/xilinx.c
Merge branch 'next'
[u-boot] / drivers / fpga / xilinx.c
1 /*
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>
33 #include <spartan3.h>
34
35 #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 */
47 static int xilinx_validate (Xilinx_desc * desc, char *fn);
48
49 /* ------------------------------------------------------------------------- */
50
51 int xilinx_load (Xilinx_desc * desc, void *buf, size_t bsize)
52 {
53         int ret_val = FPGA_FAIL;        /* assume a failure */
54
55         if (!xilinx_validate (desc, (char *)__FUNCTION__)) {
56                 printf ("%s: Invalid device descriptor\n", __FUNCTION__);
57         } else
58                 switch (desc->family) {
59                 case Xilinx_Spartan2:
60 #if defined(CONFIG_FPGA_SPARTAN2)
61                         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;
69                 case Xilinx_Spartan3:
70 #if defined(CONFIG_FPGA_SPARTAN3)
71                         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;
79                 case Xilinx_Virtex2:
80 #if defined(CONFIG_FPGA_VIRTEX2)
81                         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
98 int xilinx_dump (Xilinx_desc * desc, void *buf, size_t bsize)
99 {
100         int ret_val = FPGA_FAIL;        /* assume a failure */
101
102         if (!xilinx_validate (desc, (char *)__FUNCTION__)) {
103                 printf ("%s: Invalid device descriptor\n", __FUNCTION__);
104         } else
105                 switch (desc->family) {
106                 case Xilinx_Spartan2:
107 #if defined(CONFIG_FPGA_SPARTAN2)
108                         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;
116                 case Xilinx_Spartan3:
117 #if defined(CONFIG_FPGA_SPARTAN3)
118                         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;
126                 case Xilinx_Virtex2:
127 #if defined( CONFIG_FPGA_VIRTEX2)
128                         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
145 int xilinx_info (Xilinx_desc * desc)
146 {
147         int ret_val = FPGA_FAIL;
148
149         if (xilinx_validate (desc, (char *)__FUNCTION__)) {
150                 printf ("Family:        \t");
151                 switch (desc->family) {
152                 case Xilinx_Spartan2:
153                         printf ("Spartan-II\n");
154                         break;
155                 case Xilinx_Spartan3:
156                         printf ("Spartan-III\n");
157                         break;
158                 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:
199 #if defined(CONFIG_FPGA_SPARTAN2)
200                                 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;
207                         case Xilinx_Spartan3:
208 #if defined(CONFIG_FPGA_SPARTAN3)
209                                 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;
216                         case Xilinx_Virtex2:
217 #if defined(CONFIG_FPGA_VIRTEX2)
218                                 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 */
228                                 ;
229                         }
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
241 int xilinx_reloc (Xilinx_desc * desc, ulong reloc_offset)
242 {
243         int ret_val = FPGA_FAIL;        /* assume a failure */
244
245         if (!xilinx_validate (desc, (char *)__FUNCTION__)) {
246                 printf ("%s: Invalid device descriptor\n", __FUNCTION__);
247         } else
248                 switch (desc->family) {
249                 case Xilinx_Spartan2:
250 #if defined(CONFIG_FPGA_SPARTAN2)
251                         ret_val = Spartan2_reloc (desc, reloc_offset);
252 #else
253                         printf ("%s: No support for Spartan-II devices.\n",
254                                         __FUNCTION__);
255 #endif
256                         break;
257                 case Xilinx_Spartan3:
258 #if defined(CONFIG_FPGA_SPARTAN3)
259                         ret_val = Spartan3_reloc (desc, reloc_offset);
260 #else
261                         printf ("%s: No support for Spartan-III devices.\n",
262                                         __FUNCTION__);
263 #endif
264                         break;
265                 case Xilinx_Virtex2:
266 #if defined(CONFIG_FPGA_VIRTEX2)
267                         ret_val = Virtex2_reloc (desc, reloc_offset);
268 #else
269                         printf ("%s: No support for Virtex-II devices.\n",
270                                         __FUNCTION__);
271 #endif
272                         break;
273                         /* Add new family types here */
274                 default:
275                         printf ("%s: Unsupported family type, %d\n",
276                                         __FUNCTION__, desc->family);
277                 }
278
279         return ret_val;
280 }
281
282
283 /* ------------------------------------------------------------------------- */
284
285 static int xilinx_validate (Xilinx_desc * desc, char *fn)
286 {
287         int ret_val = FALSE;
288
289         if (desc) {
290                 if ((desc->family > min_xilinx_type) &&
291                         (desc->family < max_xilinx_type)) {
292                         if ((desc->iface > min_xilinx_iface_type) &&
293                                 (desc->iface < max_xilinx_iface_type)) {
294                                 if (desc->size) {
295                                         ret_val = TRUE;
296                                 } else
297                                         printf ("%s: NULL part size\n", fn);
298                         } else
299                                 printf ("%s: Invalid Interface type, %d\n",
300                                                 fn, desc->iface);
301                 } else
302                         printf ("%s: Invalid family type, %d\n", fn, desc->family);
303         } else
304                 printf ("%s: NULL descriptor!\n", fn);
305
306         return ret_val;
307 }