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()
46 #ifndef CONFIG_SYS_FPGA_WAIT
47 #define CONFIG_SYS_FPGA_WAIT CONFIG_SYS_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 ); */
54 /* ------------------------------------------------------------------------- */
55 /* CYCLON2 Generic Implementation */
56 int CYC2_load (Altera_desc
* desc
, void *buf
, size_t bsize
)
58 int ret_val
= FPGA_FAIL
;
60 switch (desc
->iface
) {
62 PRINTF ("%s: Launching Passive Serial Loader\n", __FUNCTION__
);
63 ret_val
= CYC2_ps_load (desc
, buf
, bsize
);
66 /* Add new interface types here */
69 printf ("%s: Unsupported interface type, %d\n",
70 __FUNCTION__
, desc
->iface
);
76 int CYC2_dump (Altera_desc
* desc
, void *buf
, size_t bsize
)
78 int ret_val
= FPGA_FAIL
;
80 switch (desc
->iface
) {
82 PRINTF ("%s: Launching Passive Serial Dump\n", __FUNCTION__
);
83 ret_val
= CYC2_ps_dump (desc
, buf
, bsize
);
86 /* Add new interface types here */
89 printf ("%s: Unsupported interface type, %d\n",
90 __FUNCTION__
, desc
->iface
);
96 int CYC2_info( Altera_desc
*desc
)
101 /* ------------------------------------------------------------------------- */
102 /* CYCLON2 Passive Serial Generic Implementation */
103 static int CYC2_ps_load (Altera_desc
* desc
, void *buf
, size_t bsize
)
105 int ret_val
= FPGA_FAIL
; /* assume the worst */
106 Altera_CYC2_Passive_Serial_fns
*fn
= desc
->iface_fns
;
109 PRINTF ("%s: start with interface functions @ 0x%p\n",
113 int cookie
= desc
->cookie
; /* make a local copy */
114 unsigned long ts
; /* timestamp */
116 PRINTF ("%s: Function Table:\n"
123 __FUNCTION__
, &fn
, fn
, fn
->config
, fn
->status
,
124 fn
->write
, fn
->done
);
125 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
126 printf ("Loading FPGA Device %d...", cookie
);
130 * Run the pre configuration function if there is one.
136 /* Establish the initial state */
137 (*fn
->config
) (TRUE
, TRUE
, cookie
); /* Assert nCONFIG */
139 udelay(2); /* T_cfg > 2us */
141 /* Wait for nSTATUS to be asserted */
142 ts
= get_timer (0); /* get current time */
144 CONFIG_FPGA_DELAY ();
145 if (get_timer (ts
) > CONFIG_SYS_FPGA_WAIT
) { /* check the time */
146 puts ("** Timeout waiting for STATUS to go high.\n");
147 (*fn
->abort
) (cookie
);
150 } while (!(*fn
->status
) (cookie
));
152 /* Get ready for the burn */
153 CONFIG_FPGA_DELAY ();
155 ret
= (*fn
->write
) (buf
, bsize
, TRUE
, cookie
);
157 puts ("** Write failed.\n");
158 (*fn
->abort
) (cookie
);
161 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
165 CONFIG_FPGA_DELAY ();
167 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
168 putc (' '); /* terminate the dotted line */
172 * Checking FPGA's CONF_DONE signal - correctly booted ?
175 if ( ! (*fn
->done
) (cookie
) ) {
176 puts ("** Booting failed! CONF_DONE is still deasserted.\n");
177 (*fn
->abort
) (cookie
);
180 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
184 ret_val
= FPGA_SUCCESS
;
186 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
187 if (ret_val
== FPGA_SUCCESS
) {
194 (*fn
->post
) (cookie
);
197 printf ("%s: NULL Interface function table!\n", __FUNCTION__
);
203 static int CYC2_ps_dump (Altera_desc
* desc
, void *buf
, size_t bsize
)
205 /* Readback is only available through the Slave Parallel and */
206 /* boundary-scan interfaces. */
207 printf ("%s: Passive Serial Dumping is unavailable\n",