]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/hymod/bsp.c
Patches by Murray Jensen, 17 Jun 2003:
[karo-tx-uboot.git] / board / hymod / bsp.c
1 /*
2  * (C) Copyright 2000
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  *
23  * hacked for Hymod FPGA support by Murray.Jensen@csiro.au, 29-Jan-01
24  */
25
26 #include <common.h>
27 #include <command.h>
28 #include <net.h>
29 #include <asm/iopin_8260.h>
30 #include <cmd_bsp.h>
31
32 /*-----------------------------------------------------------------------
33  * Board Special Commands: FPGA load/store, EEPROM erase
34  */
35
36 #if (CONFIG_COMMANDS & CFG_CMD_BSP)
37
38 #define LOAD_SUCCESS            0
39 #define LOAD_FAIL_NOCONF        1
40 #define LOAD_FAIL_NOINIT        2
41 #define LOAD_FAIL_NODONE        3
42
43 #define STORE_SUCCESS           0
44
45 /*
46  * Programming the Hymod FPGAs
47  *
48  * The 8260 io port config table is set up so that the INIT pin is
49  * held Low (Open Drain output 0) - this will delay the automatic
50  * Power-On config until INIT is released (by making it an input).
51  *
52  * If the FPGA has been programmed before, then the assertion of PROGRAM
53  * will initiate configuration (i.e. it begins clearing the RAM).
54  *
55  * When the FPGA is ready to receive configuration data (either after
56  * releasing INIT after Power-On, or after asserting PROGRAM), it will
57  * pull INIT high.
58  *
59  * Notes from Paul Dunn:
60  *
61  *  1. program pin should be forced low for >= 300ns
62  *     (about 20 bus clock cycles minimum).
63  *
64  *  2. then wait for init to go high, which signals
65  *     that the FPGA has cleared its internal memory
66  *     and is ready to load
67  *
68  *  3. perform load writes of entire config file
69  *
70  *  4. wait for done to go high, which should be
71  *     within a few bus clock cycles. If done has not
72  *     gone high after reasonable period, then load
73  *     has not worked (wait several ms?)
74  */
75
76 int
77 fpga_load (int mezz, uchar *addr, ulong size)
78 {
79         DECLARE_GLOBAL_DATA_PTR;
80
81         hymod_conf_t *cp = &gd->bd->bi_hymod_conf;
82         xlx_info_t *fp;
83         xlx_iopins_t *fpgaio;
84         volatile uchar *fpgabase;
85         volatile uint cnt;
86         uchar *eaddr = addr + size;
87         int result;
88
89         if (mezz)
90                 fp = &cp->mezz.xlx[0];
91         else
92                 fp = &cp->main.xlx[0];
93
94         if (!fp->mmap.prog.exists)
95                 return (LOAD_FAIL_NOCONF);
96
97         fpgabase = (uchar *)fp->mmap.prog.base;
98         fpgaio = &fp->iopins;
99
100         /* set enable HIGH if required */
101         if (fpgaio->enable_pin.flag)
102                 iopin_set_high (&fpgaio->enable_pin);
103
104         /* ensure INIT is released (set it to be an input) */
105         iopin_set_in (&fpgaio->init_pin);
106
107         /* toggle PROG Low then High (will already be Low after Power-On) */
108         iopin_set_low (&fpgaio->prog_pin);
109         udelay (1);     /* minimum 300ns - 1usec should do it */
110         iopin_set_high (&fpgaio->prog_pin);
111
112         /* wait for INIT High */
113         cnt = 0;
114         while (!iopin_is_high (&fpgaio->init_pin))
115                 if (++cnt == 10000000) {
116                         result = LOAD_FAIL_NOINIT;
117                         goto done;
118                 }
119
120         /* write configuration data */
121         while (addr < eaddr)
122                 *fpgabase = *addr++;
123
124         /* wait for DONE High */
125         cnt = 0;
126         while (!iopin_is_high (&fpgaio->done_pin))
127                 if (++cnt == 100000000) {
128                         result = LOAD_FAIL_NODONE;
129                         goto done;
130                 }
131
132         /* success */
133         result = LOAD_SUCCESS;
134
135   done:
136
137         if (fpgaio->enable_pin.flag)
138                 iopin_set_low (&fpgaio->enable_pin);
139
140         return (result);
141 }
142
143 /* ------------------------------------------------------------------------- */
144 int
145 do_fpga (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
146 {
147         uchar *addr, *save_addr;
148         ulong size;
149         int mezz, arg, result;
150
151         switch (argc) {
152
153         case 0:
154         case 1:
155                 break;
156
157         case 2:
158                 if (strcmp (argv[1], "info") == 0) {
159                         printf ("\nHymod FPGA Info...\n");
160                         printf ("\t\t\t\tAddress\t\tSize\n");
161                         printf ("\tMain Configuration:\t0x%08x\t%d\n",
162                                 FPGA_MAIN_CFG_BASE, FPGA_MAIN_CFG_SIZE);
163                         printf ("\tMain Register:\t\t0x%08x\t%d\n",
164                                 FPGA_MAIN_REG_BASE, FPGA_MAIN_REG_SIZE);
165                         printf ("\tMain Port:\t\t0x%08x\t%d\n",
166                                 FPGA_MAIN_PORT_BASE, FPGA_MAIN_PORT_SIZE);
167                         printf ("\tMezz Configuration:\t0x%08x\t%d\n",
168                                 FPGA_MEZZ_CFG_BASE, FPGA_MEZZ_CFG_SIZE);
169                         return 0;
170                 }
171                 break;
172
173         case 3:
174                 if (strcmp (argv[1], "store") == 0) {
175                         addr = (uchar *) simple_strtoul (argv[2], NULL, 16);
176
177                         save_addr = addr;
178 #if 0
179                         /* fpga readback unimplemented */
180                         while (more readback data)
181                                 *addr++ = *fpga;
182                         result = error ? STORE_FAIL_XXX : STORE_SUCCESS;
183 #else
184                         result = STORE_SUCCESS;
185 #endif
186
187                         if (result == STORE_SUCCESS) {
188                                 printf ("SUCCEEDED (%d bytes)\n",
189                                         addr - save_addr);
190                                 return 0;
191                         } else
192                                 printf ("FAILED (%d bytes)\n",
193                                         addr - save_addr);
194                         return 1;
195                 }
196                 break;
197
198         case 4:
199                 if (strcmp (argv[1], "tftp") == 0) {
200                         copy_filename (BootFile, argv[2], sizeof (BootFile));
201                         load_addr = simple_strtoul (argv[3], NULL, 16);
202                         NetBootFileXferSize = 0;
203
204                         if (NetLoop (TFTP) <= 0) {
205                                 printf ("tftp transfer failed - aborting "
206                                         "fgpa load\n");
207                                 return 1;
208                         }
209
210                         if (NetBootFileXferSize == 0) {
211                                 printf ("can't determine file size - "
212                                         "aborting fpga load\n");
213                                 return 1;
214                         }
215
216                         printf ("File transfer succeeded - "
217                                 "beginning fpga load...");
218
219                         result = fpga_load (0, (uchar *) load_addr,
220                                 NetBootFileXferSize);
221
222                         if (result == LOAD_SUCCESS) {
223                                 printf ("SUCCEEDED\n");
224                                 return 0;
225                         } else if (result == LOAD_FAIL_NOCONF)
226                                 printf ("FAILED (no CONF)\n");
227                         else if (result == LOAD_FAIL_NOINIT)
228                                 printf ("FAILED (no INIT)\n");
229                         else
230                                 printf ("FAILED (no DONE)\n");
231                         return 1;
232
233                 }
234                 /* fall through ... */
235
236         case 5:
237                 if (strcmp (argv[1], "load") == 0) {
238                         if (argc == 5) {
239                                 if (strcmp (argv[2], "main") == 0)
240                                         mezz = 0;
241                                 else if (strcmp (argv[2], "mezz") == 0)
242                                         mezz = 1;
243                                 else {
244                                         printf ("FPGA type must be either "
245                                                 "`main' or `mezz'\n");
246                                         return 1;
247                                 }
248                                 arg = 3;
249                         } else {
250                                 mezz = 0;
251                                 arg = 2;
252                         }
253
254                         addr = (uchar *) simple_strtoul (argv[arg++], NULL, 16);
255                         size = (ulong) simple_strtoul (argv[arg], NULL, 16);
256
257                         result = fpga_load (mezz, addr, size);
258
259                         if (result == LOAD_SUCCESS) {
260                                 printf ("SUCCEEDED\n");
261                                 return 0;
262                         } else if (result == LOAD_FAIL_NOCONF)
263                                 printf ("FAILED (no CONF)\n");
264                         else if (result == LOAD_FAIL_NOINIT)
265                                 printf ("FAILED (no INIT)\n");
266                         else
267                                 printf ("FAILED (no DONE)\n");
268                         return 1;
269                 }
270                 break;
271
272         default:
273                 break;
274         }
275
276         printf ("Usage:\n%s\n", cmdtp->usage);
277         return 1;
278 }
279
280 /* ------------------------------------------------------------------------- */
281 int
282 do_eecl (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
283 {
284         uchar data[HYMOD_EEPROM_SIZE];
285         uint addr = CFG_I2C_EEPROM_ADDR;
286
287         switch (argc) {
288
289         case 1:
290                 addr |= HYMOD_EEOFF_MAIN;
291                 break;
292
293         case 2:
294                 if (strcmp (argv[1], "main") == 0) {
295                         addr |= HYMOD_EEOFF_MAIN;
296                         break;
297                 }
298                 if (strcmp (argv[1], "mezz") == 0) {
299                         addr |= HYMOD_EEOFF_MEZZ;
300                         break;
301                 }
302                 /* fall through ... */
303
304         default:
305                 printf ("Usage:\n%s\n", cmdtp->usage);
306                 return 1;
307         }
308
309         memset (data, 0, HYMOD_EEPROM_SIZE);
310
311         eeprom_write (addr, 0, data, HYMOD_EEPROM_SIZE);
312
313         return 0;
314 }
315
316 /* ------------------------------------------------------------------------- */
317
318 #if 0
319 static uchar test_bitfile[] = {
320         /* one day ... */
321 };
322 #endif
323
324 int
325 do_htest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
326 {
327 #if 0
328         int rc;
329 #endif
330 #ifdef CONFIG_ETHER_LOOPBACK_TEST
331         extern void eth_loopback_test (void);
332 #endif /* CONFIG_ETHER_LOOPBACK_TEST */
333
334         printf ("HYMOD tests - ensure loopbacks etc. are connected\n\n");
335
336 #if 0
337         /* Load FPGA with test program */
338
339         printf ("Loading test FPGA program ...");
340
341         rc = fpga_load (0, test_bitfile, sizeof (test_bitfile));
342
343         switch (rc) {
344
345         case LOAD_SUCCESS:
346                 printf (" SUCCEEDED\n");
347                 break;
348
349         case LOAD_FAIL_NOCONF:
350                 printf (" FAILED (no configuration space defined)\n");
351                 return 1;
352
353         case LOAD_FAIL_NOINIT:
354                 printf (" FAILED (timeout - no INIT signal seen)\n");
355                 return 1;
356
357         case LOAD_FAIL_NODONE:
358                 printf (" FAILED (timeout - no DONE signal seen)\n");
359                 return 1;
360
361         default:
362                 printf (" FAILED (unknown return code from fpga_load\n");
363                 return 1;
364         }
365
366         /* run Local Bus <=> Xilinx tests */
367
368         /* tell Xilinx to run ZBT Ram, High Speed serial and Mezzanine tests */
369
370         /* run SDRAM test */
371 #endif
372
373 #ifdef CONFIG_ETHER_LOOPBACK_TEST
374         /* run Ethernet test */
375         eth_loopback_test ();
376 #endif /* CONFIG_ETHER_LOOPBACK_TEST */
377
378         return 0;
379 }
380
381 #endif  /* CFG_CMD_BSP */
382
383 /* ------------------------------------------------------------------------- */