blob: e54640f2d2d63992edbc33b10947cab7e666cad1 [file] [log] [blame]
wdenk16f21702002-08-26 21:58:50 +00001/*
2 * (C) Copyright 2000
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk16f21702002-08-26 21:58:50 +00006 *
wdenk6dd652f2003-06-19 23:40:20 +00007 * hacked for Hymod FPGA support by Murray.Jensen@csiro.au, 29-Jan-01
wdenk16f21702002-08-26 21:58:50 +00008 */
9
10#include <common.h>
11#include <command.h>
12#include <net.h>
wdenk16f21702002-08-26 21:58:50 +000013#include <asm/iopin_8260.h>
wdenk16f21702002-08-26 21:58:50 +000014
Wolfgang Denkd87080b2006-03-31 18:32:53 +020015DECLARE_GLOBAL_DATA_PTR;
16
wdenk16f21702002-08-26 21:58:50 +000017/*-----------------------------------------------------------------------
18 * Board Special Commands: FPGA load/store, EEPROM erase
19 */
20
Jon Loeligerc508a4c2007-07-09 18:31:28 -050021#if defined(CONFIG_CMD_BSP)
wdenk16f21702002-08-26 21:58:50 +000022
23#define LOAD_SUCCESS 0
24#define LOAD_FAIL_NOCONF 1
25#define LOAD_FAIL_NOINIT 2
26#define LOAD_FAIL_NODONE 3
27
28#define STORE_SUCCESS 0
29
30/*
31 * Programming the Hymod FPGAs
32 *
33 * The 8260 io port config table is set up so that the INIT pin is
34 * held Low (Open Drain output 0) - this will delay the automatic
35 * Power-On config until INIT is released (by making it an input).
36 *
37 * If the FPGA has been programmed before, then the assertion of PROGRAM
38 * will initiate configuration (i.e. it begins clearing the RAM).
39 *
40 * When the FPGA is ready to receive configuration data (either after
41 * releasing INIT after Power-On, or after asserting PROGRAM), it will
42 * pull INIT high.
43 *
44 * Notes from Paul Dunn:
45 *
46 * 1. program pin should be forced low for >= 300ns
47 * (about 20 bus clock cycles minimum).
48 *
49 * 2. then wait for init to go high, which signals
50 * that the FPGA has cleared its internal memory
51 * and is ready to load
52 *
53 * 3. perform load writes of entire config file
54 *
55 * 4. wait for done to go high, which should be
56 * within a few bus clock cycles. If done has not
57 * gone high after reasonable period, then load
58 * has not worked (wait several ms?)
59 */
60
wdenk6dd652f2003-06-19 23:40:20 +000061int
Wolfgang Denke6a857d2011-07-30 13:33:49 +000062fpga_load(int mezz, const uchar *addr, ulong size)
wdenk16f21702002-08-26 21:58:50 +000063{
wdenk16f21702002-08-26 21:58:50 +000064 hymod_conf_t *cp = &gd->bd->bi_hymod_conf;
wdenk6dd652f2003-06-19 23:40:20 +000065 xlx_info_t *fp;
wdenk16f21702002-08-26 21:58:50 +000066 xlx_iopins_t *fpgaio;
67 volatile uchar *fpgabase;
68 volatile uint cnt;
Wolfgang Denke6a857d2011-07-30 13:33:49 +000069 const uchar *eaddr = addr + size;
wdenk16f21702002-08-26 21:58:50 +000070 int result;
71
wdenk6dd652f2003-06-19 23:40:20 +000072 if (mezz)
73 fp = &cp->mezz.xlx[0];
74 else
75 fp = &cp->main.xlx[0];
76
77 if (!fp->mmap.prog.exists)
78 return (LOAD_FAIL_NOCONF);
79
80 fpgabase = (uchar *)fp->mmap.prog.base;
81 fpgaio = &fp->iopins;
wdenk16f21702002-08-26 21:58:50 +000082
83 /* set enable HIGH if required */
84 if (fpgaio->enable_pin.flag)
85 iopin_set_high (&fpgaio->enable_pin);
86
87 /* ensure INIT is released (set it to be an input) */
88 iopin_set_in (&fpgaio->init_pin);
89
90 /* toggle PROG Low then High (will already be Low after Power-On) */
91 iopin_set_low (&fpgaio->prog_pin);
wdenk6dd652f2003-06-19 23:40:20 +000092 udelay (1); /* minimum 300ns - 1usec should do it */
wdenk16f21702002-08-26 21:58:50 +000093 iopin_set_high (&fpgaio->prog_pin);
94
95 /* wait for INIT High */
96 cnt = 0;
97 while (!iopin_is_high (&fpgaio->init_pin))
98 if (++cnt == 10000000) {
99 result = LOAD_FAIL_NOINIT;
100 goto done;
101 }
102
103 /* write configuration data */
104 while (addr < eaddr)
105 *fpgabase = *addr++;
106
107 /* wait for DONE High */
108 cnt = 0;
109 while (!iopin_is_high (&fpgaio->done_pin))
110 if (++cnt == 100000000) {
111 result = LOAD_FAIL_NODONE;
112 goto done;
113 }
114
115 /* success */
116 result = LOAD_SUCCESS;
117
118 done:
119
120 if (fpgaio->enable_pin.flag)
121 iopin_set_low (&fpgaio->enable_pin);
122
123 return (result);
124}
125
126/* ------------------------------------------------------------------------- */
127int
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200128do_fpga (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
wdenk16f21702002-08-26 21:58:50 +0000129{
130 uchar *addr, *save_addr;
131 ulong size;
132 int mezz, arg, result;
133
134 switch (argc) {
135
136 case 0:
137 case 1:
138 break;
139
140 case 2:
141 if (strcmp (argv[1], "info") == 0) {
142 printf ("\nHymod FPGA Info...\n");
wdenk6dd652f2003-06-19 23:40:20 +0000143 printf ("\t\t\t\tAddress\t\tSize\n");
144 printf ("\tMain Configuration:\t0x%08x\t%d\n",
145 FPGA_MAIN_CFG_BASE, FPGA_MAIN_CFG_SIZE);
146 printf ("\tMain Register:\t\t0x%08x\t%d\n",
147 FPGA_MAIN_REG_BASE, FPGA_MAIN_REG_SIZE);
148 printf ("\tMain Port:\t\t0x%08x\t%d\n",
149 FPGA_MAIN_PORT_BASE, FPGA_MAIN_PORT_SIZE);
150 printf ("\tMezz Configuration:\t0x%08x\t%d\n",
151 FPGA_MEZZ_CFG_BASE, FPGA_MEZZ_CFG_SIZE);
wdenk16f21702002-08-26 21:58:50 +0000152 return 0;
153 }
154 break;
155
156 case 3:
157 if (strcmp (argv[1], "store") == 0) {
158 addr = (uchar *) simple_strtoul (argv[2], NULL, 16);
159
160 save_addr = addr;
161#if 0
wdenk6dd652f2003-06-19 23:40:20 +0000162 /* fpga readback unimplemented */
163 while (more readback data)
164 *addr++ = *fpga;
165 result = error ? STORE_FAIL_XXX : STORE_SUCCESS;
wdenk16f21702002-08-26 21:58:50 +0000166#else
wdenk6dd652f2003-06-19 23:40:20 +0000167 result = STORE_SUCCESS;
wdenk16f21702002-08-26 21:58:50 +0000168#endif
wdenk6dd652f2003-06-19 23:40:20 +0000169
wdenk16f21702002-08-26 21:58:50 +0000170 if (result == STORE_SUCCESS) {
wdenk6dd652f2003-06-19 23:40:20 +0000171 printf ("SUCCEEDED (%d bytes)\n",
172 addr - save_addr);
wdenk16f21702002-08-26 21:58:50 +0000173 return 0;
174 } else
wdenk6dd652f2003-06-19 23:40:20 +0000175 printf ("FAILED (%d bytes)\n",
176 addr - save_addr);
wdenk16f21702002-08-26 21:58:50 +0000177 return 1;
178 }
179 break;
180
181 case 4:
182 if (strcmp (argv[1], "tftp") == 0) {
183 copy_filename (BootFile, argv[2], sizeof (BootFile));
184 load_addr = simple_strtoul (argv[3], NULL, 16);
wdenk6dd652f2003-06-19 23:40:20 +0000185 NetBootFileXferSize = 0;
wdenk16f21702002-08-26 21:58:50 +0000186
Simon Glasse4bf0c52011-10-24 18:00:02 +0000187 if (NetLoop(TFTPGET) <= 0) {
wdenk6dd652f2003-06-19 23:40:20 +0000188 printf ("tftp transfer failed - aborting "
189 "fgpa load\n");
wdenk16f21702002-08-26 21:58:50 +0000190 return 1;
191 }
192
193 if (NetBootFileXferSize == 0) {
wdenk6dd652f2003-06-19 23:40:20 +0000194 printf ("can't determine file size - "
195 "aborting fpga load\n");
wdenk16f21702002-08-26 21:58:50 +0000196 return 1;
197 }
198
wdenk6dd652f2003-06-19 23:40:20 +0000199 printf ("File transfer succeeded - "
200 "beginning fpga load...");
wdenk16f21702002-08-26 21:58:50 +0000201
202 result = fpga_load (0, (uchar *) load_addr,
wdenk6dd652f2003-06-19 23:40:20 +0000203 NetBootFileXferSize);
204
wdenk16f21702002-08-26 21:58:50 +0000205 if (result == LOAD_SUCCESS) {
206 printf ("SUCCEEDED\n");
207 return 0;
wdenk6dd652f2003-06-19 23:40:20 +0000208 } else if (result == LOAD_FAIL_NOCONF)
209 printf ("FAILED (no CONF)\n");
210 else if (result == LOAD_FAIL_NOINIT)
wdenk16f21702002-08-26 21:58:50 +0000211 printf ("FAILED (no INIT)\n");
212 else
213 printf ("FAILED (no DONE)\n");
214 return 1;
215
216 }
217 /* fall through ... */
218
219 case 5:
220 if (strcmp (argv[1], "load") == 0) {
221 if (argc == 5) {
222 if (strcmp (argv[2], "main") == 0)
223 mezz = 0;
224 else if (strcmp (argv[2], "mezz") == 0)
225 mezz = 1;
226 else {
wdenk6dd652f2003-06-19 23:40:20 +0000227 printf ("FPGA type must be either "
228 "`main' or `mezz'\n");
wdenk16f21702002-08-26 21:58:50 +0000229 return 1;
230 }
231 arg = 3;
232 } else {
233 mezz = 0;
234 arg = 2;
235 }
wdenk6dd652f2003-06-19 23:40:20 +0000236
wdenk16f21702002-08-26 21:58:50 +0000237 addr = (uchar *) simple_strtoul (argv[arg++], NULL, 16);
238 size = (ulong) simple_strtoul (argv[arg], NULL, 16);
239
240 result = fpga_load (mezz, addr, size);
wdenk6dd652f2003-06-19 23:40:20 +0000241
wdenk16f21702002-08-26 21:58:50 +0000242 if (result == LOAD_SUCCESS) {
243 printf ("SUCCEEDED\n");
244 return 0;
wdenk6dd652f2003-06-19 23:40:20 +0000245 } else if (result == LOAD_FAIL_NOCONF)
246 printf ("FAILED (no CONF)\n");
247 else if (result == LOAD_FAIL_NOINIT)
wdenk16f21702002-08-26 21:58:50 +0000248 printf ("FAILED (no INIT)\n");
249 else
250 printf ("FAILED (no DONE)\n");
251 return 1;
252 }
253 break;
254
255 default:
256 break;
257 }
258
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200259 return cmd_usage(cmdtp);
wdenk16f21702002-08-26 21:58:50 +0000260}
wdenk0d498392003-07-01 21:06:45 +0000261U_BOOT_CMD(
262 fpga, 6, 1, do_fpga,
Peter Tyser2fb26042009-01-27 18:03:12 -0600263 "FPGA sub-system",
wdenk8bde7f72003-06-27 21:31:46 +0000264 "load [type] addr size\n"
265 " - write the configuration data at memory address `addr',\n"
266 " size `size' bytes, into the FPGA of type `type' (either\n"
267 " `main' or `mezz', default `main'). e.g.\n"
268 " `fpga load 100000 7d8f'\n"
269 " loads the main FPGA with config data at address 100000\n"
270 " HEX, size 7d8f HEX (32143 DEC) bytes\n"
271 "fpga tftp file addr\n"
272 " - transfers `file' from the tftp server into memory at\n"
273 " address `addr', then writes the entire file contents\n"
274 " into the main FPGA\n"
275 "fpga store addr\n"
276 " - read configuration data from the main FPGA (the mezz\n"
277 " FPGA is write-only), into address `addr'. There must be\n"
278 " enough memory available at `addr' to hold all the config\n"
279 " data - the size of which is determined by VC:???\n"
280 "fpga info\n"
281 " - print information about the Hymod FPGA, namely the\n"
282 " memory addresses at which the four FPGA local bus\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200283 " address spaces appear in the physical address space"
wdenk8bde7f72003-06-27 21:31:46 +0000284);
wdenk16f21702002-08-26 21:58:50 +0000285/* ------------------------------------------------------------------------- */
286int
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200287do_eecl (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
wdenk16f21702002-08-26 21:58:50 +0000288{
289 uchar data[HYMOD_EEPROM_SIZE];
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200290 uint addr = CONFIG_SYS_I2C_EEPROM_ADDR;
wdenk16f21702002-08-26 21:58:50 +0000291
292 switch (argc) {
293
294 case 1:
wdenk6dd652f2003-06-19 23:40:20 +0000295 addr |= HYMOD_EEOFF_MAIN;
wdenk16f21702002-08-26 21:58:50 +0000296 break;
297
298 case 2:
299 if (strcmp (argv[1], "main") == 0) {
wdenk6dd652f2003-06-19 23:40:20 +0000300 addr |= HYMOD_EEOFF_MAIN;
wdenk16f21702002-08-26 21:58:50 +0000301 break;
302 }
303 if (strcmp (argv[1], "mezz") == 0) {
wdenk6dd652f2003-06-19 23:40:20 +0000304 addr |= HYMOD_EEOFF_MEZZ;
wdenk16f21702002-08-26 21:58:50 +0000305 break;
306 }
307 /* fall through ... */
308
309 default:
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200310 return cmd_usage(cmdtp);
wdenk16f21702002-08-26 21:58:50 +0000311 }
312
313 memset (data, 0, HYMOD_EEPROM_SIZE);
wdenk16f21702002-08-26 21:58:50 +0000314
wdenk6dd652f2003-06-19 23:40:20 +0000315 eeprom_write (addr, 0, data, HYMOD_EEPROM_SIZE);
316
317 return 0;
wdenk16f21702002-08-26 21:58:50 +0000318}
wdenk0d498392003-07-01 21:06:45 +0000319U_BOOT_CMD(
320 eeclear, 1, 0, do_eecl,
Peter Tyser2fb26042009-01-27 18:03:12 -0600321 "Clear the eeprom on a Hymod board",
wdenk8bde7f72003-06-27 21:31:46 +0000322 "[type]\n"
323 " - write zeroes into the EEPROM on the board of type `type'\n"
324 " (`type' is either `main' or `mezz' - default `main')\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200325 " Note: the EEPROM write enable jumper must be installed"
wdenk8bde7f72003-06-27 21:31:46 +0000326);
wdenk16f21702002-08-26 21:58:50 +0000327
wdenk6dd652f2003-06-19 23:40:20 +0000328/* ------------------------------------------------------------------------- */
329
wdenk6dd652f2003-06-19 23:40:20 +0000330int
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200331do_htest (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk6dd652f2003-06-19 23:40:20 +0000332{
333#if 0
334 int rc;
335#endif
336#ifdef CONFIG_ETHER_LOOPBACK_TEST
337 extern void eth_loopback_test (void);
338#endif /* CONFIG_ETHER_LOOPBACK_TEST */
339
340 printf ("HYMOD tests - ensure loopbacks etc. are connected\n\n");
341
342#if 0
343 /* Load FPGA with test program */
344
345 printf ("Loading test FPGA program ...");
346
347 rc = fpga_load (0, test_bitfile, sizeof (test_bitfile));
348
349 switch (rc) {
350
351 case LOAD_SUCCESS:
352 printf (" SUCCEEDED\n");
353 break;
354
355 case LOAD_FAIL_NOCONF:
356 printf (" FAILED (no configuration space defined)\n");
357 return 1;
358
359 case LOAD_FAIL_NOINIT:
360 printf (" FAILED (timeout - no INIT signal seen)\n");
361 return 1;
362
363 case LOAD_FAIL_NODONE:
364 printf (" FAILED (timeout - no DONE signal seen)\n");
365 return 1;
366
367 default:
368 printf (" FAILED (unknown return code from fpga_load\n");
369 return 1;
370 }
371
372 /* run Local Bus <=> Xilinx tests */
373
374 /* tell Xilinx to run ZBT Ram, High Speed serial and Mezzanine tests */
375
376 /* run SDRAM test */
377#endif
378
379#ifdef CONFIG_ETHER_LOOPBACK_TEST
380 /* run Ethernet test */
381 eth_loopback_test ();
382#endif /* CONFIG_ETHER_LOOPBACK_TEST */
383
384 return 0;
385}
386
Jon Loeliger77a31852007-07-10 10:39:10 -0500387#endif