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 #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ALTERA) && defined(CONFIG_FPGA_CYCLON2)
32 /* Define FPGA_DEBUG to get debug printf's */
34 #define PRINTF(fmt,args...) printf (fmt ,##args)
36 #define PRINTF(fmt,args...)
39 /* Note: The assumption is that we cannot possibly run fast enough to
40 * overrun the device (the Slave Parallel mode can free run at 50MHz).
41 * If there is a need to operate slower, define CONFIG_FPGA_DELAY in
42 * the board config file to slow things down.
44 #ifndef CONFIG_FPGA_DELAY
45 #define CONFIG_FPGA_DELAY()
49 #define CFG_FPGA_WAIT CFG_HZ/10 /* 100 ms */
52 static int CYC2_ps_load( Altera_desc
*desc
, void *buf
, size_t bsize
);
53 static int CYC2_ps_dump( Altera_desc
*desc
, void *buf
, size_t bsize
);
54 /* static int CYC2_ps_info( Altera_desc *desc ); */
55 static int CYC2_ps_reloc( Altera_desc
*desc
, ulong reloc_offset
);
57 /* ------------------------------------------------------------------------- */
58 /* CYCLON2 Generic Implementation */
59 int CYC2_load (Altera_desc
* desc
, void *buf
, size_t bsize
)
61 int ret_val
= FPGA_FAIL
;
63 switch (desc
->iface
) {
65 PRINTF ("%s: Launching Passive Serial Loader\n", __FUNCTION__
);
66 ret_val
= CYC2_ps_load (desc
, buf
, bsize
);
69 /* Add new interface types here */
72 printf ("%s: Unsupported interface type, %d\n",
73 __FUNCTION__
, desc
->iface
);
79 int CYC2_dump (Altera_desc
* desc
, void *buf
, size_t bsize
)
81 int ret_val
= FPGA_FAIL
;
83 switch (desc
->iface
) {
85 PRINTF ("%s: Launching Passive Serial Dump\n", __FUNCTION__
);
86 ret_val
= CYC2_ps_dump (desc
, buf
, bsize
);
89 /* Add new interface types here */
92 printf ("%s: Unsupported interface type, %d\n",
93 __FUNCTION__
, desc
->iface
);
99 int CYC2_info( Altera_desc
*desc
)
104 int CYC2_reloc (Altera_desc
* desc
, ulong reloc_offset
)
106 int ret_val
= FPGA_FAIL
; /* assume a failure */
108 if (desc
->family
!= Altera_CYC2
) {
109 printf ("%s: Unsupported family type, %d\n",
110 __FUNCTION__
, desc
->family
);
113 switch (desc
->iface
) {
115 ret_val
= CYC2_ps_reloc (desc
, reloc_offset
);
118 /* Add new interface types here */
121 printf ("%s: Unsupported interface type, %d\n",
122 __FUNCTION__
, desc
->iface
);
128 /* ------------------------------------------------------------------------- */
129 /* CYCLON2 Passive Serial Generic Implementation */
130 static int CYC2_ps_load (Altera_desc
* desc
, void *buf
, size_t bsize
)
132 int ret_val
= FPGA_FAIL
; /* assume the worst */
133 Altera_CYC2_Passive_Serial_fns
*fn
= desc
->iface_fns
;
136 PRINTF ("%s: start with interface functions @ 0x%p\n",
140 int cookie
= desc
->cookie
; /* make a local copy */
141 unsigned long ts
; /* timestamp */
143 PRINTF ("%s: Function Table:\n"
150 __FUNCTION__
, &fn
, fn
, fn
->config
, fn
->status
,
151 fn
->write
, fn
->done
);
152 #ifdef CFG_FPGA_PROG_FEEDBACK
153 printf ("Loading FPGA Device %d...", cookie
);
157 * Run the pre configuration function if there is one.
163 /* Establish the initial state */
164 (*fn
->config
) (TRUE
, TRUE
, cookie
); /* Assert nCONFIG */
166 udelay(2); /* T_cfg > 2us */
168 /* Wait for nSTATUS to be asserted */
169 ts
= get_timer (0); /* get current time */
171 CONFIG_FPGA_DELAY ();
172 if (get_timer (ts
) > CFG_FPGA_WAIT
) { /* check the time */
173 puts ("** Timeout waiting for STATUS to go high.\n");
174 (*fn
->abort
) (cookie
);
177 } while (!(*fn
->status
) (cookie
));
179 /* Get ready for the burn */
180 CONFIG_FPGA_DELAY ();
182 ret
= (*fn
->write
) (buf
, bsize
, TRUE
, cookie
);
184 puts ("** Write failed.\n");
185 (*fn
->abort
) (cookie
);
188 #ifdef CFG_FPGA_PROG_FEEDBACK
192 CONFIG_FPGA_DELAY ();
194 #ifdef CFG_FPGA_PROG_FEEDBACK
195 putc (' '); /* terminate the dotted line */
199 * Checking FPGA's CONF_DONE signal - correctly booted ?
202 if ( ! (*fn
->done
) (cookie
) ) {
203 puts ("** Booting failed! CONF_DONE is still deasserted.\n");
204 (*fn
->abort
) (cookie
);
207 #ifdef CFG_FPGA_PROG_FEEDBACK
211 ret_val
= FPGA_SUCCESS
;
213 #ifdef CFG_FPGA_PROG_FEEDBACK
214 if (ret_val
== FPGA_SUCCESS
) {
221 (*fn
->post
) (cookie
);
224 printf ("%s: NULL Interface function table!\n", __FUNCTION__
);
230 static int CYC2_ps_dump (Altera_desc
* desc
, void *buf
, size_t bsize
)
232 /* Readback is only available through the Slave Parallel and */
233 /* boundary-scan interfaces. */
234 printf ("%s: Passive Serial Dumping is unavailable\n",
239 static int CYC2_ps_reloc (Altera_desc
* desc
, ulong reloc_offset
)
241 int ret_val
= FPGA_FAIL
; /* assume the worst */
242 Altera_CYC2_Passive_Serial_fns
*fn_r
, *fn
=
243 (Altera_CYC2_Passive_Serial_fns
*) (desc
->iface_fns
);
248 /* Get the relocated table address */
249 addr
= (ulong
) fn
+ reloc_offset
;
250 fn_r
= (Altera_CYC2_Passive_Serial_fns
*) addr
;
252 if (!fn_r
->relocated
) {
254 if (memcmp (fn_r
, fn
,
255 sizeof (Altera_CYC2_Passive_Serial_fns
))
257 /* good copy of the table, fix the descriptor pointer */
258 desc
->iface_fns
= fn_r
;
260 PRINTF ("%s: Invalid function table at 0x%p\n",
265 PRINTF ("%s: Relocating descriptor at 0x%p\n", __FUNCTION__
,
268 addr
= (ulong
) (fn
->pre
) + reloc_offset
;
269 fn_r
->pre
= (Altera_pre_fn
) addr
;
271 addr
= (ulong
) (fn
->config
) + reloc_offset
;
272 fn_r
->config
= (Altera_config_fn
) addr
;
274 addr
= (ulong
) (fn
->status
) + reloc_offset
;
275 fn_r
->status
= (Altera_status_fn
) addr
;
277 addr
= (ulong
) (fn
->done
) + reloc_offset
;
278 fn_r
->done
= (Altera_done_fn
) addr
;
280 addr
= (ulong
) (fn
->write
) + reloc_offset
;
281 fn_r
->write
= (Altera_write_fn
) addr
;
283 addr
= (ulong
) (fn
->abort
) + reloc_offset
;
284 fn_r
->abort
= (Altera_abort_fn
) addr
;
286 addr
= (ulong
) (fn
->post
) + reloc_offset
;
287 fn_r
->post
= (Altera_post_fn
) addr
;
289 fn_r
->relocated
= TRUE
;
292 /* this table has already been moved */
293 /* XXX - should check to see if the descriptor is correct */
294 desc
->iface_fns
= fn_r
;
297 ret_val
= FPGA_SUCCESS
;
299 printf ("%s: NULL Interface function table!\n", __FUNCTION__
);
305 #endif /* CONFIG_FPGA && CONFIG_FPGA_ALTERA && CONFIG_FPGA_CYCLON2 */