altera.c 7.06 KB
Newer Older
wdenk's avatar
wdenk committed
1
/*
2 3 4
 * (C) Copyright 2003
 * Steven Scholz, imc Measurement & Control, steven.scholz@imc-berlin.de
 *
wdenk's avatar
wdenk committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 * (C) Copyright 2002
 * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 *
 */

/*
 *  Altera FPGA support
 */
#include <common.h>
32
#include <ACEX1K.h>
eran liberty's avatar
eran liberty committed
33
#include <stratixII.h>
wdenk's avatar
wdenk committed
34

35 36
/* Define FPGA_DEBUG to get debug printf's */
/* #define FPGA_DEBUG */
wdenk's avatar
wdenk committed
37 38 39 40 41 42 43

#ifdef	FPGA_DEBUG
#define	PRINTF(fmt,args...)	printf (fmt ,##args)
#else
#define PRINTF(fmt,args...)
#endif

44
/* Local Static Functions */
eran liberty's avatar
eran liberty committed
45
static int altera_validate (Altera_desc * desc, const char *fn);
46

wdenk's avatar
wdenk committed
47 48 49
/* ------------------------------------------------------------------------- */
int altera_load( Altera_desc *desc, void *buf, size_t bsize )
{
50 51
	int ret_val = FPGA_FAIL;	/* assume a failure */

52
	if (!altera_validate (desc, (char *)__FUNCTION__)) {
53 54 55 56
		printf ("%s: Invalid device descriptor\n", __FUNCTION__);
	} else {
		switch (desc->family) {
		case Altera_ACEX1K:
57
		case Altera_CYC2:
58
#if defined(CONFIG_FPGA_ACEX1K)
59 60 61
			PRINTF ("%s: Launching the ACEX1K Loader...\n",
					__FUNCTION__);
			ret_val = ACEX1K_load (desc, buf, bsize);
eran liberty's avatar
eran liberty committed
62
#elif defined(CONFIG_FPGA_CYCLON2)
63 64 65
			PRINTF ("%s: Launching the CYCLON II Loader...\n",
					__FUNCTION__);
			ret_val = CYC2_load (desc, buf, bsize);
66 67 68 69 70 71
#else
			printf ("%s: No support for ACEX1K devices.\n",
					__FUNCTION__);
#endif
			break;

eran liberty's avatar
eran liberty committed
72 73 74 75 76 77 78
#if defined(CONFIG_FPGA_STRATIX_II)
		case Altera_StratixII:
			PRINTF ("%s: Launching the Stratix II Loader...\n",
				__FUNCTION__);
			ret_val = StratixII_load (desc, buf, bsize);
			break;
#endif
79 80 81 82 83 84 85
		default:
			printf ("%s: Unsupported family type, %d\n",
					__FUNCTION__, desc->family);
		}
	}

	return ret_val;
wdenk's avatar
wdenk committed
86 87 88 89
}

int altera_dump( Altera_desc *desc, void *buf, size_t bsize )
{
90 91
	int ret_val = FPGA_FAIL;	/* assume a failure */

92
	if (!altera_validate (desc, (char *)__FUNCTION__)) {
93 94 95 96
		printf ("%s: Invalid device descriptor\n", __FUNCTION__);
	} else {
		switch (desc->family) {
		case Altera_ACEX1K:
97
#if defined(CONFIG_FPGA_ACEX)
98 99 100 101 102 103 104 105 106
			PRINTF ("%s: Launching the ACEX1K Reader...\n",
					__FUNCTION__);
			ret_val = ACEX1K_dump (desc, buf, bsize);
#else
			printf ("%s: No support for ACEX1K devices.\n",
					__FUNCTION__);
#endif
			break;

eran liberty's avatar
eran liberty committed
107 108 109 110 111 112 113
#if defined(CONFIG_FPGA_STRATIX_II)
		case Altera_StratixII:
			PRINTF ("%s: Launching the Stratix II Reader...\n",
				__FUNCTION__);
			ret_val = StratixII_dump (desc, buf, bsize);
			break;
#endif
114 115 116 117 118 119 120
		default:
			printf ("%s: Unsupported family type, %d\n",
					__FUNCTION__, desc->family);
		}
	}

	return ret_val;
wdenk's avatar
wdenk committed
121 122 123 124
}

int altera_info( Altera_desc *desc )
{
125 126
	int ret_val = FPGA_FAIL;

127
	if (altera_validate (desc, (char *)__FUNCTION__)) {
128 129 130 131 132
		printf ("Family:        \t");
		switch (desc->family) {
		case Altera_ACEX1K:
			printf ("ACEX1K\n");
			break;
133 134 135
		case Altera_CYC2:
			printf ("CYCLON II\n");
			break;
eran liberty's avatar
eran liberty committed
136 137 138 139
		case Altera_StratixII:
			printf ("Stratix II\n");
			break;
			/* Add new family types here */
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
		default:
			printf ("Unknown family type, %d\n", desc->family);
		}

		printf ("Interface type:\t");
		switch (desc->iface) {
		case passive_serial:
			printf ("Passive Serial (PS)\n");
			break;
		case passive_parallel_synchronous:
			printf ("Passive Parallel Synchronous (PPS)\n");
			break;
		case passive_parallel_asynchronous:
			printf ("Passive Parallel Asynchronous (PPA)\n");
			break;
		case passive_serial_asynchronous:
			printf ("Passive Serial Asynchronous (PSA)\n");
			break;
		case altera_jtag_mode:		/* Not used */
			printf ("JTAG Mode\n");
			break;
eran liberty's avatar
eran liberty committed
161 162 163 164 165 166 167
		case fast_passive_parallel:
			printf ("Fast Passive Parallel (FPP)\n");
			break;
		case fast_passive_parallel_security:
			printf
			    ("Fast Passive Parallel with Security (FPPS) \n");
			break;
168 169 170 171 172 173 174 175 176 177 178 179 180
			/* Add new interface types here */
		default:
			printf ("Unsupported interface type, %d\n", desc->iface);
		}

		printf ("Device Size:   \t%d bytes\n"
				"Cookie:        \t0x%x (%d)\n",
				desc->size, desc->cookie, desc->cookie);

		if (desc->iface_fns) {
			printf ("Device Function Table @ 0x%p\n", desc->iface_fns);
			switch (desc->family) {
			case Altera_ACEX1K:
181
			case Altera_CYC2:
182
#if defined(CONFIG_FPGA_ACEX1K)
183
				ACEX1K_info (desc);
184
#elif defined(CONFIG_FPGA_CYCLON2)
185
				CYC2_info (desc);
186 187 188 189 190 191
#else
				/* just in case */
				printf ("%s: No support for ACEX1K devices.\n",
						__FUNCTION__);
#endif
				break;
eran liberty's avatar
eran liberty committed
192 193 194 195 196
#if defined(CONFIG_FPGA_STRATIX_II)
			case Altera_StratixII:
				StratixII_info (desc);
				break;
#endif
197 198 199
				/* Add new family types here */
			default:
				/* we don't need a message here - we give one up above */
200
				break;
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
			}
		} else {
			printf ("No Device Function Table.\n");
		}

		ret_val = FPGA_SUCCESS;
	} else {
		printf ("%s: Invalid device descriptor\n", __FUNCTION__);
	}

	return ret_val;
}

int altera_reloc( Altera_desc *desc, ulong reloc_offset)
{
	int ret_val = FPGA_FAIL;	/* assume a failure */

218
	if (!altera_validate (desc, (char *)__FUNCTION__)) {
219 220 221 222
		printf ("%s: Invalid device descriptor\n", __FUNCTION__);
	} else {
		switch (desc->family) {
		case Altera_ACEX1K:
223
#if defined(CONFIG_FPGA_ACEX1K)
224 225 226
			ret_val = ACEX1K_reloc (desc, reloc_offset);
#else
			printf ("%s: No support for ACEX devices.\n",
227 228 229
					__FUNCTION__);
#endif
			break;
eran liberty's avatar
eran liberty committed
230 231 232 233 234
#if defined(CONFIG_FPGA_STRATIX_II)
		case Altera_StratixII:
			ret_val = StratixII_reloc (desc, reloc_offset);
			break;
#endif
235
		case Altera_CYC2:
236
#if defined(CONFIG_FPGA_CYCLON2)
237 238 239
			ret_val = CYC2_reloc (desc, reloc_offset);
#else
			printf ("%s: No support for CYCLON II devices.\n",
240 241 242 243 244 245 246 247 248 249 250
					__FUNCTION__);
#endif
			break;
			/* Add new family types here */
		default:
			printf ("%s: Unsupported family type, %d\n",
					__FUNCTION__, desc->family);
		}
	}

	return ret_val;
wdenk's avatar
wdenk committed
251 252 253 254
}

/* ------------------------------------------------------------------------- */

eran liberty's avatar
eran liberty committed
255
static int altera_validate (Altera_desc * desc, const char *fn)
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
{
	int ret_val = FALSE;

	if (desc) {
		if ((desc->family > min_altera_type) &&
			(desc->family < max_altera_type)) {
			if ((desc->iface > min_altera_iface_type) &&
				(desc->iface < max_altera_iface_type)) {
				if (desc->size) {
					ret_val = TRUE;
				} else {
					printf ("%s: NULL part size\n", fn);
				}
			} else {
				printf ("%s: Invalid Interface type, %d\n",
					fn, desc->iface);
			}
		} else {
			printf ("%s: Invalid family type, %d\n", fn, desc->family);
		}
	} else {
		printf ("%s: NULL descriptor!\n", fn);
	}

	return ret_val;
}
wdenk's avatar
wdenk committed
282 283

/* ------------------------------------------------------------------------- */