添加了牛皮藓,主要方便不知情的人联系我。有洁癖者自己去除代码,在
[ddnasgpl.git] / common / altera.c
blobebd50382c63225eedf2dedc2b1ec06db43a19489
1 /*
2 * (C) Copyright 2003
3 * Steven Scholz, imc Measurement & Control, steven.scholz@imc-berlin.de
5 * (C) Copyright 2002
6 * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
8 * See file CREDITS for list of people who contributed to this
9 * project.
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 * MA 02111-1307 USA
29 * Altera FPGA support
31 #include <common.h>
32 #include <ACEX1K.h>
34 /* Define FPGA_DEBUG to get debug printf's */
35 /* #define FPGA_DEBUG */
37 #ifdef FPGA_DEBUG
38 #define PRINTF(fmt,args...) printf (fmt ,##args)
39 #else
40 #define PRINTF(fmt,args...)
41 #endif
43 #if (CONFIG_FPGA & CFG_FPGA_ALTERA)
45 /* Local Static Functions */
46 static int altera_validate (Altera_desc * desc, char *fn);
48 /* ------------------------------------------------------------------------- */
49 int altera_load( Altera_desc *desc, void *buf, size_t bsize )
51 int ret_val = FPGA_FAIL; /* assume a failure */
53 if (!altera_validate (desc, __FUNCTION__)) {
54 printf ("%s: Invalid device descriptor\n", __FUNCTION__);
55 } else {
56 switch (desc->family) {
57 case Altera_ACEX1K:
58 #if (CONFIG_FPGA & CFG_ACEX1K)
59 PRINTF ("%s: Launching the ACEX1K Loader...\n",
60 __FUNCTION__);
61 ret_val = ACEX1K_load (desc, buf, bsize);
62 #else
63 printf ("%s: No support for ACEX1K devices.\n",
64 __FUNCTION__);
65 #endif
66 break;
68 default:
69 printf ("%s: Unsupported family type, %d\n",
70 __FUNCTION__, desc->family);
74 return ret_val;
77 int altera_dump( Altera_desc *desc, void *buf, size_t bsize )
79 int ret_val = FPGA_FAIL; /* assume a failure */
81 if (!altera_validate (desc, __FUNCTION__)) {
82 printf ("%s: Invalid device descriptor\n", __FUNCTION__);
83 } else {
84 switch (desc->family) {
85 case Altera_ACEX1K:
86 #if (CONFIG_FPGA & CFG_ACEX)
87 PRINTF ("%s: Launching the ACEX1K Reader...\n",
88 __FUNCTION__);
89 ret_val = ACEX1K_dump (desc, buf, bsize);
90 #else
91 printf ("%s: No support for ACEX1K devices.\n",
92 __FUNCTION__);
93 #endif
94 break;
96 default:
97 printf ("%s: Unsupported family type, %d\n",
98 __FUNCTION__, desc->family);
102 return ret_val;
105 int altera_info( Altera_desc *desc )
107 int ret_val = FPGA_FAIL;
109 if (altera_validate (desc, __FUNCTION__)) {
110 printf ("Family: \t");
111 switch (desc->family) {
112 case Altera_ACEX1K:
113 printf ("ACEX1K\n");
114 break;
115 /* Add new family types here */
116 default:
117 printf ("Unknown family type, %d\n", desc->family);
120 printf ("Interface type:\t");
121 switch (desc->iface) {
122 case passive_serial:
123 printf ("Passive Serial (PS)\n");
124 break;
125 case passive_parallel_synchronous:
126 printf ("Passive Parallel Synchronous (PPS)\n");
127 break;
128 case passive_parallel_asynchronous:
129 printf ("Passive Parallel Asynchronous (PPA)\n");
130 break;
131 case passive_serial_asynchronous:
132 printf ("Passive Serial Asynchronous (PSA)\n");
133 break;
134 case altera_jtag_mode: /* Not used */
135 printf ("JTAG Mode\n");
136 break;
137 /* Add new interface types here */
138 default:
139 printf ("Unsupported interface type, %d\n", desc->iface);
142 printf ("Device Size: \t%d bytes\n"
143 "Cookie: \t0x%x (%d)\n",
144 desc->size, desc->cookie, desc->cookie);
146 if (desc->iface_fns) {
147 printf ("Device Function Table @ 0x%p\n", desc->iface_fns);
148 switch (desc->family) {
149 case Altera_ACEX1K:
150 #if (CONFIG_FPGA & CFG_ACEX1K)
151 ACEX1K_info (desc);
152 #else
153 /* just in case */
154 printf ("%s: No support for ACEX1K devices.\n",
155 __FUNCTION__);
156 #endif
157 break;
158 /* Add new family types here */
159 default:
160 /* we don't need a message here - we give one up above */
161 break;
163 } else {
164 printf ("No Device Function Table.\n");
167 ret_val = FPGA_SUCCESS;
168 } else {
169 printf ("%s: Invalid device descriptor\n", __FUNCTION__);
172 return ret_val;
175 int altera_reloc( Altera_desc *desc, ulong reloc_offset)
177 int ret_val = FPGA_FAIL; /* assume a failure */
179 if (!altera_validate (desc, __FUNCTION__)) {
180 printf ("%s: Invalid device descriptor\n", __FUNCTION__);
181 } else {
182 switch (desc->family) {
183 case Altera_ACEX1K:
184 #if (CONFIG_FPGA & CFG_ACEX1K)
185 ret_val = ACEX1K_reloc (desc, reloc_offset);
186 #else
187 printf ("%s: No support for ACEX devices.\n",
188 __FUNCTION__);
189 #endif
190 break;
191 /* Add new family types here */
192 default:
193 printf ("%s: Unsupported family type, %d\n",
194 __FUNCTION__, desc->family);
198 return ret_val;
201 /* ------------------------------------------------------------------------- */
203 static int altera_validate (Altera_desc * desc, char *fn)
205 int ret_val = FALSE;
207 if (desc) {
208 if ((desc->family > min_altera_type) &&
209 (desc->family < max_altera_type)) {
210 if ((desc->iface > min_altera_iface_type) &&
211 (desc->iface < max_altera_iface_type)) {
212 if (desc->size) {
213 ret_val = TRUE;
214 } else {
215 printf ("%s: NULL part size\n", fn);
217 } else {
218 printf ("%s: Invalid Interface type, %d\n",
219 fn, desc->iface);
221 } else {
222 printf ("%s: Invalid family type, %d\n", fn, desc->family);
224 } else {
225 printf ("%s: NULL descriptor!\n", fn);
228 return ret_val;
231 /* ------------------------------------------------------------------------- */
233 #endif /* CONFIG_FPGA & CFG_FPGA_ALTERA */