]> git.sur5r.net Git - u-boot/blob - common/xilinx.c
New board directory and config for the benq delta board (copied from
[u-boot] / common / 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 (CONFIG_FPGA & CFG_FPGA_XILINX)
36
37 #if 0
38 #define FPGA_DEBUG
39 #endif
40
41 /* Define FPGA_DEBUG to get debug printf's */
42 #ifdef  FPGA_DEBUG
43 #define PRINTF(fmt,args...)     printf (fmt ,##args)
44 #else
45 #define PRINTF(fmt,args...)
46 #endif
47
48 /* Local Static Functions */
49 static int xilinx_validate (Xilinx_desc * desc, char *fn);
50
51 /* ------------------------------------------------------------------------- */
52
53 int xilinx_load (Xilinx_desc * desc, void *buf, size_t bsize)
54 {
55         int ret_val = FPGA_FAIL;        /* assume a failure */
56
57         if (!xilinx_validate (desc, (char *)__FUNCTION__)) {
58                 printf ("%s: Invalid device descriptor\n", __FUNCTION__);
59         } else
60                 switch (desc->family) {
61                 case Xilinx_Spartan2:
62 #if (CONFIG_FPGA & CFG_SPARTAN2)
63                         PRINTF ("%s: Launching the Spartan-II Loader...\n",
64                                         __FUNCTION__);
65                         ret_val = Spartan2_load (desc, buf, bsize);
66 #else
67                         printf ("%s: No support for Spartan-II devices.\n",
68                                         __FUNCTION__);
69 #endif
70                         break;
71                 case Xilinx_Spartan3:
72 #if (CONFIG_FPGA & CFG_SPARTAN3)
73                         PRINTF ("%s: Launching the Spartan-III Loader...\n",
74                                         __FUNCTION__);
75                         ret_val = Spartan3_load (desc, buf, bsize);
76 #else
77                         printf ("%s: No support for Spartan-III devices.\n",
78                                         __FUNCTION__);
79 #endif
80                         break;
81                 case Xilinx_Virtex2:
82 #if (CONFIG_FPGA & CFG_VIRTEX2)
83                         PRINTF ("%s: Launching the Virtex-II Loader...\n",
84                                         __FUNCTION__);
85                         ret_val = Virtex2_load (desc, buf, bsize);
86 #else
87                         printf ("%s: No support for Virtex-II devices.\n",
88                                         __FUNCTION__);
89 #endif
90                         break;
91
92                 default:
93                         printf ("%s: Unsupported family type, %d\n",
94                                         __FUNCTION__, desc->family);
95                 }
96
97         return ret_val;
98 }
99
100 int xilinx_dump (Xilinx_desc * desc, void *buf, size_t bsize)
101 {
102         int ret_val = FPGA_FAIL;        /* assume a failure */
103
104         if (!xilinx_validate (desc, (char *)__FUNCTION__)) {
105                 printf ("%s: Invalid device descriptor\n", __FUNCTION__);
106         } else
107                 switch (desc->family) {
108                 case Xilinx_Spartan2:
109 #if (CONFIG_FPGA & CFG_SPARTAN2)
110                         PRINTF ("%s: Launching the Spartan-II Reader...\n",
111                                         __FUNCTION__);
112                         ret_val = Spartan2_dump (desc, buf, bsize);
113 #else
114                         printf ("%s: No support for Spartan-II devices.\n",
115                                         __FUNCTION__);
116 #endif
117                         break;
118                 case Xilinx_Spartan3:
119 #if (CONFIG_FPGA & CFG_SPARTAN3)
120                         PRINTF ("%s: Launching the Spartan-III Reader...\n",
121                                         __FUNCTION__);
122                         ret_val = Spartan3_dump (desc, buf, bsize);
123 #else
124                         printf ("%s: No support for Spartan-III devices.\n",
125                                         __FUNCTION__);
126 #endif
127                         break;
128                 case Xilinx_Virtex2:
129 #if (CONFIG_FPGA & CFG_VIRTEX2)
130                         PRINTF ("%s: Launching the Virtex-II Reader...\n",
131                                         __FUNCTION__);
132                         ret_val = Virtex2_dump (desc, buf, bsize);
133 #else
134                         printf ("%s: No support for Virtex-II devices.\n",
135                                         __FUNCTION__);
136 #endif
137                         break;
138
139                 default:
140                         printf ("%s: Unsupported family type, %d\n",
141                                         __FUNCTION__, desc->family);
142                 }
143
144         return ret_val;
145 }
146
147 int xilinx_info (Xilinx_desc * desc)
148 {
149         int ret_val = FPGA_FAIL;
150
151         if (xilinx_validate (desc, (char *)__FUNCTION__)) {
152                 printf ("Family:        \t");
153                 switch (desc->family) {
154                 case Xilinx_Spartan2:
155                         printf ("Spartan-II\n");
156                         break;
157                 case Xilinx_Spartan3:
158                         printf ("Spartan-III\n");
159                         break;
160                 case Xilinx_Virtex2:
161                         printf ("Virtex-II\n");
162                         break;
163                         /* Add new family types here */
164                 default:
165                         printf ("Unknown family type, %d\n", desc->family);
166                 }
167
168                 printf ("Interface type:\t");
169                 switch (desc->iface) {
170                 case slave_serial:
171                         printf ("Slave Serial\n");
172                         break;
173                 case master_serial:     /* Not used */
174                         printf ("Master Serial\n");
175                         break;
176                 case slave_parallel:
177                         printf ("Slave Parallel\n");
178                         break;
179                 case jtag_mode:         /* Not used */
180                         printf ("JTAG Mode\n");
181                         break;
182                 case slave_selectmap:
183                         printf ("Slave SelectMap Mode\n");
184                         break;
185                 case master_selectmap:
186                         printf ("Master SelectMap Mode\n");
187                         break;
188                         /* Add new interface types here */
189                 default:
190                         printf ("Unsupported interface type, %d\n", desc->iface);
191                 }
192
193                 printf ("Device Size:   \t%d bytes\n"
194                                 "Cookie:        \t0x%x (%d)\n",
195                                 desc->size, desc->cookie, desc->cookie);
196
197                 if (desc->iface_fns) {
198                         printf ("Device Function Table @ 0x%p\n", desc->iface_fns);
199                         switch (desc->family) {
200                         case Xilinx_Spartan2:
201 #if (CONFIG_FPGA & CFG_SPARTAN2)
202                                 Spartan2_info (desc);
203 #else
204                                 /* just in case */
205                                 printf ("%s: No support for Spartan-II devices.\n",
206                                                 __FUNCTION__);
207 #endif
208                                 break;
209                         case Xilinx_Spartan3:
210 #if (CONFIG_FPGA & CFG_SPARTAN3)
211                                 Spartan3_info (desc);
212 #else
213                                 /* just in case */
214                                 printf ("%s: No support for Spartan-III devices.\n",
215                                                 __FUNCTION__);
216 #endif
217                                 break;
218                         case Xilinx_Virtex2:
219 #if (CONFIG_FPGA & CFG_VIRTEX2)
220                                 Virtex2_info (desc);
221 #else
222                                 /* just in case */
223                                 printf ("%s: No support for Virtex-II devices.\n",
224                                                 __FUNCTION__);
225 #endif
226                                 break;
227                                 /* Add new family types here */
228                         default:
229                                 /* we don't need a message here - we give one up above */
230                                 ;
231                         }
232                 } else
233                         printf ("No Device Function Table.\n");
234
235                 ret_val = FPGA_SUCCESS;
236         } else {
237                 printf ("%s: Invalid device descriptor\n", __FUNCTION__);
238         }
239
240         return ret_val;
241 }
242
243 int xilinx_reloc (Xilinx_desc * desc, ulong reloc_offset)
244 {
245         int ret_val = FPGA_FAIL;        /* assume a failure */
246
247         if (!xilinx_validate (desc, (char *)__FUNCTION__)) {
248                 printf ("%s: Invalid device descriptor\n", __FUNCTION__);
249         } else
250                 switch (desc->family) {
251                 case Xilinx_Spartan2:
252 #if (CONFIG_FPGA & CFG_SPARTAN2)
253                         ret_val = Spartan2_reloc (desc, reloc_offset);
254 #else
255                         printf ("%s: No support for Spartan-II devices.\n",
256                                         __FUNCTION__);
257 #endif
258                         break;
259                 case Xilinx_Spartan3:
260 #if (CONFIG_FPGA & CFG_SPARTAN3)
261                         ret_val = Spartan3_reloc (desc, reloc_offset);
262 #else
263                         printf ("%s: No support for Spartan-III devices.\n",
264                                         __FUNCTION__);
265 #endif
266                         break;
267                 case Xilinx_Virtex2:
268 #if (CONFIG_FPGA & CFG_VIRTEX2)
269                         ret_val = Virtex2_reloc (desc, reloc_offset);
270 #else
271                         printf ("%s: No support for Virtex-II devices.\n",
272                                         __FUNCTION__);
273 #endif
274                         break;
275                         /* Add new family types here */
276                 default:
277                         printf ("%s: Unsupported family type, %d\n",
278                                         __FUNCTION__, desc->family);
279                 }
280
281         return ret_val;
282 }
283
284
285 /* ------------------------------------------------------------------------- */
286
287 static int xilinx_validate (Xilinx_desc * desc, char *fn)
288 {
289         int ret_val = FALSE;
290
291         if (desc) {
292                 if ((desc->family > min_xilinx_type) &&
293                         (desc->family < max_xilinx_type)) {
294                         if ((desc->iface > min_xilinx_iface_type) &&
295                                 (desc->iface < max_xilinx_iface_type)) {
296                                 if (desc->size) {
297                                         ret_val = TRUE;
298                                 } else
299                                         printf ("%s: NULL part size\n", fn);
300                         } else
301                                 printf ("%s: Invalid Interface type, %d\n",
302                                                 fn, desc->iface);
303                 } else
304                         printf ("%s: Invalid family type, %d\n", fn, desc->family);
305         } else
306                 printf ("%s: NULL descriptor!\n", fn);
307
308         return ret_val;
309 }
310
311 #endif                                                  /* CONFIG_FPGA & CFG_FPGA_XILINX */