3 * Steven Scholz, imc Measurement & Control, steven.scholz@imc-berlin.de
6 * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 #include <common.h> /* core U-Boot definitions */
29 #include <ACEX1K.h> /* ACEX device family */
31 /* Define FPGA_DEBUG to get debug printf's */
33 #define PRINTF(fmt,args...) printf (fmt ,##args)
35 #define PRINTF(fmt,args...)
38 /* Note: The assumption is that we cannot possibly run fast enough to
39 * overrun the device (the Slave Parallel mode can free run at 50MHz).
40 * If there is a need to operate slower, define CONFIG_FPGA_DELAY in
41 * the board config file to slow things down.
43 #ifndef CONFIG_FPGA_DELAY
44 #define CONFIG_FPGA_DELAY()
47 #ifndef CONFIG_SYS_FPGA_WAIT
48 #define CONFIG_SYS_FPGA_WAIT CONFIG_SYS_HZ/10 /* 100 ms */
51 static int ACEX1K_ps_load( Altera_desc
*desc
, void *buf
, size_t bsize
);
52 static int ACEX1K_ps_dump( Altera_desc
*desc
, void *buf
, size_t bsize
);
53 /* static int ACEX1K_ps_info( Altera_desc *desc ); */
55 /* ------------------------------------------------------------------------- */
56 /* ACEX1K Generic Implementation */
57 int ACEX1K_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
= ACEX1K_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 ACEX1K_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
= ACEX1K_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 ACEX1K_info( Altera_desc
*desc
)
103 /* ------------------------------------------------------------------------- */
104 /* ACEX1K Passive Serial Generic Implementation */
106 static int ACEX1K_ps_load (Altera_desc
* desc
, void *buf
, size_t bsize
)
108 int ret_val
= FPGA_FAIL
; /* assume the worst */
109 Altera_ACEX1K_Passive_Serial_fns
*fn
= desc
->iface_fns
;
112 PRINTF ("%s: start with interface functions @ 0x%p\n",
116 size_t bytecount
= 0;
117 unsigned char *data
= (unsigned char *) buf
;
118 int cookie
= desc
->cookie
; /* make a local copy */
119 unsigned long ts
; /* timestamp */
121 PRINTF ("%s: Function Table:\n"
129 __FUNCTION__
, &fn
, fn
, fn
->config
, fn
->status
,
130 fn
->clk
, fn
->data
, fn
->done
);
131 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
132 printf ("Loading FPGA Device %d...", cookie
);
136 * Run the pre configuration function if there is one.
142 /* Establish the initial state */
143 (*fn
->config
) (TRUE
, TRUE
, cookie
); /* Assert nCONFIG */
145 udelay(2); /* T_cfg > 2us */
147 /* nSTATUS should be asserted now */
148 (*fn
->done
) (cookie
);
149 if ( !(*fn
->status
) (cookie
) ) {
150 puts ("** nSTATUS is not asserted.\n");
151 (*fn
->abort
) (cookie
);
155 (*fn
->config
) (FALSE
, TRUE
, cookie
); /* Deassert nCONFIG */
156 udelay(2); /* T_cf2st1 < 4us */
158 /* Wait for nSTATUS to be released (i.e. deasserted) */
159 ts
= get_timer (0); /* get current time */
161 CONFIG_FPGA_DELAY ();
162 if (get_timer (ts
) > CONFIG_SYS_FPGA_WAIT
) { /* check the time */
163 puts ("** Timeout waiting for STATUS to go high.\n");
164 (*fn
->abort
) (cookie
);
167 (*fn
->done
) (cookie
);
168 } while ((*fn
->status
) (cookie
));
170 /* Get ready for the burn */
171 CONFIG_FPGA_DELAY ();
174 while (bytecount
< bsize
) {
176 #ifdef CONFIG_SYS_FPGA_CHECK_CTRLC
178 (*fn
->abort
) (cookie
);
182 /* Altera detects an error if INIT goes low (active)
183 while DONE is low (inactive) */
184 #if 0 /* not yet implemented */
185 if ((*fn
->done
) (cookie
) == 0 && (*fn
->init
) (cookie
)) {
186 puts ("** CRC error during FPGA load.\n");
187 (*fn
->abort
) (cookie
);
191 val
= data
[bytecount
++ ];
194 /* Deassert the clock */
195 (*fn
->clk
) (FALSE
, TRUE
, cookie
);
196 CONFIG_FPGA_DELAY ();
198 (*fn
->data
) ( (val
& 0x01), TRUE
, cookie
);
199 CONFIG_FPGA_DELAY ();
200 /* Assert the clock */
201 (*fn
->clk
) (TRUE
, TRUE
, cookie
);
202 CONFIG_FPGA_DELAY ();
207 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
208 if (bytecount
% (bsize
/ 40) == 0)
209 putc ('.'); /* let them know we are alive */
213 CONFIG_FPGA_DELAY ();
215 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
216 putc (' '); /* terminate the dotted line */
220 * Checking FPGA's CONF_DONE signal - correctly booted ?
223 if ( ! (*fn
->done
) (cookie
) ) {
224 puts ("** Booting failed! CONF_DONE is still deasserted.\n");
225 (*fn
->abort
) (cookie
);
230 * "DCLK must be clocked an additional 10 times fpr ACEX 1K..."
233 for (i
= 0; i
< 12; i
++) {
234 CONFIG_FPGA_DELAY ();
235 (*fn
->clk
) (TRUE
, TRUE
, cookie
); /* Assert the clock pin */
236 CONFIG_FPGA_DELAY ();
237 (*fn
->clk
) (FALSE
, TRUE
, cookie
); /* Deassert the clock pin */
240 ret_val
= FPGA_SUCCESS
;
242 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
243 if (ret_val
== FPGA_SUCCESS
) {
250 (*fn
->post
) (cookie
);
253 printf ("%s: NULL Interface function table!\n", __FUNCTION__
);
259 static int ACEX1K_ps_dump (Altera_desc
* desc
, void *buf
, size_t bsize
)
261 /* Readback is only available through the Slave Parallel and */
262 /* boundary-scan interfaces. */
263 printf ("%s: Passive Serial Dumping is unavailable\n",