xref: /openbmc/u-boot/drivers/fpga/xilinx.c (revision 5993053f)
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, const 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, const 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 /* ------------------------------------------------------------------------- */
242 
243 static 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 }
266