3 * Heiko Schocher, hs@denx.de
6 * See file CREDITS for list of people who contributed to this
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.
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.
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,
26 #include <common.h> /* core U-Boot definitions */
28 #include <ACEX1K.h> /* ACEX device family */
30 /* Define FPGA_DEBUG to get debug printf's */
32 #define PRINTF(fmt,args...) printf (fmt ,##args)
34 #define PRINTF(fmt,args...)
37 /* Note: The assumption is that we cannot possibly run fast enough to
38 * overrun the device (the Slave Parallel mode can free run at 50MHz).
39 * If there is a need to operate slower, define CONFIG_FPGA_DELAY in
40 * the board config file to slow things down.
42 #ifndef CONFIG_FPGA_DELAY
43 #define CONFIG_FPGA_DELAY()
47 #define CFG_FPGA_WAIT CFG_HZ/10 /* 100 ms */
50 static int CYC2_ps_load( Altera_desc *desc, void *buf, size_t bsize );
51 static int CYC2_ps_dump( Altera_desc *desc, void *buf, size_t bsize );
52 /* static int CYC2_ps_info( Altera_desc *desc ); */
53 static int CYC2_ps_reloc( Altera_desc *desc, ulong reloc_offset );
55 /* ------------------------------------------------------------------------- */
56 /* CYCLON2 Generic Implementation */
57 int CYC2_load (Altera_desc * desc, void *buf, size_t bsize)
59 int ret_val = FPGA_FAIL;
61 switch (desc->iface) {
63 PRINTF ("%s: Launching Passive Serial Loader\n", __FUNCTION__);
64 ret_val = CYC2_ps_load (desc, buf, bsize);
67 /* Add new interface types here */
70 printf ("%s: Unsupported interface type, %d\n",
71 __FUNCTION__, desc->iface);
77 int CYC2_dump (Altera_desc * desc, void *buf, size_t bsize)
79 int ret_val = FPGA_FAIL;
81 switch (desc->iface) {
83 PRINTF ("%s: Launching Passive Serial Dump\n", __FUNCTION__);
84 ret_val = CYC2_ps_dump (desc, buf, bsize);
87 /* Add new interface types here */
90 printf ("%s: Unsupported interface type, %d\n",
91 __FUNCTION__, desc->iface);
97 int CYC2_info( Altera_desc *desc )
102 int CYC2_reloc (Altera_desc * desc, ulong reloc_offset)
104 int ret_val = FPGA_FAIL; /* assume a failure */
106 if (desc->family != Altera_CYC2) {
107 printf ("%s: Unsupported family type, %d\n",
108 __FUNCTION__, desc->family);
111 switch (desc->iface) {
113 ret_val = CYC2_ps_reloc (desc, reloc_offset);
116 /* Add new interface types here */
119 printf ("%s: Unsupported interface type, %d\n",
120 __FUNCTION__, desc->iface);
126 /* ------------------------------------------------------------------------- */
127 /* CYCLON2 Passive Serial Generic Implementation */
128 static int CYC2_ps_load (Altera_desc * desc, void *buf, size_t bsize)
130 int ret_val = FPGA_FAIL; /* assume the worst */
131 Altera_CYC2_Passive_Serial_fns *fn = desc->iface_fns;
134 PRINTF ("%s: start with interface functions @ 0x%p\n",
138 int cookie = desc->cookie; /* make a local copy */
139 unsigned long ts; /* timestamp */
141 PRINTF ("%s: Function Table:\n"
148 __FUNCTION__, &fn, fn, fn->config, fn->status,
149 fn->write, fn->done);
150 #ifdef CFG_FPGA_PROG_FEEDBACK
151 printf ("Loading FPGA Device %d...", cookie);
155 * Run the pre configuration function if there is one.
161 /* Establish the initial state */
162 (*fn->config) (TRUE, TRUE, cookie); /* Assert nCONFIG */
164 udelay(2); /* T_cfg > 2us */
166 /* Wait for nSTATUS to be asserted */
167 ts = get_timer (0); /* get current time */
169 CONFIG_FPGA_DELAY ();
170 if (get_timer (ts) > CFG_FPGA_WAIT) { /* check the time */
171 puts ("** Timeout waiting for STATUS to go high.\n");
172 (*fn->abort) (cookie);
175 } while (!(*fn->status) (cookie));
177 /* Get ready for the burn */
178 CONFIG_FPGA_DELAY ();
180 ret = (*fn->write) (buf, bsize, TRUE, cookie);
182 puts ("** Write failed.\n");
183 (*fn->abort) (cookie);
186 #ifdef CFG_FPGA_PROG_FEEDBACK
190 CONFIG_FPGA_DELAY ();
192 #ifdef CFG_FPGA_PROG_FEEDBACK
193 putc (' '); /* terminate the dotted line */
197 * Checking FPGA's CONF_DONE signal - correctly booted ?
200 if ( ! (*fn->done) (cookie) ) {
201 puts ("** Booting failed! CONF_DONE is still deasserted.\n");
202 (*fn->abort) (cookie);
205 #ifdef CFG_FPGA_PROG_FEEDBACK
209 ret_val = FPGA_SUCCESS;
211 #ifdef CFG_FPGA_PROG_FEEDBACK
212 if (ret_val == FPGA_SUCCESS) {
219 (*fn->post) (cookie);
222 printf ("%s: NULL Interface function table!\n", __FUNCTION__);
228 static int CYC2_ps_dump (Altera_desc * desc, void *buf, size_t bsize)
230 /* Readback is only available through the Slave Parallel and */
231 /* boundary-scan interfaces. */
232 printf ("%s: Passive Serial Dumping is unavailable\n",
237 static int CYC2_ps_reloc (Altera_desc * desc, ulong reloc_offset)
239 int ret_val = FPGA_FAIL; /* assume the worst */
240 Altera_CYC2_Passive_Serial_fns *fn_r, *fn =
241 (Altera_CYC2_Passive_Serial_fns *) (desc->iface_fns);
246 /* Get the relocated table address */
247 addr = (ulong) fn + reloc_offset;
248 fn_r = (Altera_CYC2_Passive_Serial_fns *) addr;
250 if (!fn_r->relocated) {
252 if (memcmp (fn_r, fn,
253 sizeof (Altera_CYC2_Passive_Serial_fns))
255 /* good copy of the table, fix the descriptor pointer */
256 desc->iface_fns = fn_r;
258 PRINTF ("%s: Invalid function table at 0x%p\n",
263 PRINTF ("%s: Relocating descriptor at 0x%p\n", __FUNCTION__,
266 addr = (ulong) (fn->pre) + reloc_offset;
267 fn_r->pre = (Altera_pre_fn) addr;
269 addr = (ulong) (fn->config) + reloc_offset;
270 fn_r->config = (Altera_config_fn) addr;
272 addr = (ulong) (fn->status) + reloc_offset;
273 fn_r->status = (Altera_status_fn) addr;
275 addr = (ulong) (fn->done) + reloc_offset;
276 fn_r->done = (Altera_done_fn) addr;
278 addr = (ulong) (fn->write) + reloc_offset;
279 fn_r->write = (Altera_write_fn) addr;
281 addr = (ulong) (fn->abort) + reloc_offset;
282 fn_r->abort = (Altera_abort_fn) addr;
284 addr = (ulong) (fn->post) + reloc_offset;
285 fn_r->post = (Altera_post_fn) addr;
287 fn_r->relocated = TRUE;
290 /* this table has already been moved */
291 /* XXX - should check to see if the descriptor is correct */
292 desc->iface_fns = fn_r;
295 ret_val = FPGA_SUCCESS;
297 printf ("%s: NULL Interface function table!\n", __FUNCTION__);