1 // SPDX-License-Identifier: GPL-2.0+
4 * Heiko Schocher, hs@denx.de
8 #include <common.h> /* core U-Boot definitions */
10 #include <ACEX1K.h> /* ACEX device family */
12 /* Define FPGA_DEBUG to get debug printf's */
14 #define PRINTF(fmt,args...) printf (fmt ,##args)
16 #define PRINTF(fmt,args...)
19 /* Note: The assumption is that we cannot possibly run fast enough to
20 * overrun the device (the Slave Parallel mode can free run at 50MHz).
21 * If there is a need to operate slower, define CONFIG_FPGA_DELAY in
22 * the board config file to slow things down.
24 #ifndef CONFIG_FPGA_DELAY
25 #define CONFIG_FPGA_DELAY()
28 #ifndef CONFIG_SYS_FPGA_WAIT
29 #define CONFIG_SYS_FPGA_WAIT CONFIG_SYS_HZ/10 /* 100 ms */
32 static int CYC2_ps_load(Altera_desc *desc, const void *buf, size_t bsize);
33 static int CYC2_ps_dump(Altera_desc *desc, const void *buf, size_t bsize);
34 /* static int CYC2_ps_info( Altera_desc *desc ); */
36 /* ------------------------------------------------------------------------- */
37 /* CYCLON2 Generic Implementation */
38 int CYC2_load(Altera_desc *desc, const void *buf, size_t bsize)
40 int ret_val = FPGA_FAIL;
42 switch (desc->iface) {
44 PRINTF ("%s: Launching Passive Serial Loader\n", __FUNCTION__);
45 ret_val = CYC2_ps_load (desc, buf, bsize);
48 case fast_passive_parallel:
49 /* Fast Passive Parallel (FPP) and PS only differ in what is
50 * done in the write() callback. Use the existing PS load
51 * function for FPP, too.
53 PRINTF ("%s: Launching Fast Passive Parallel Loader\n",
55 ret_val = CYC2_ps_load(desc, buf, bsize);
58 /* Add new interface types here */
61 printf ("%s: Unsupported interface type, %d\n",
62 __FUNCTION__, desc->iface);
68 int CYC2_dump(Altera_desc *desc, const void *buf, size_t bsize)
70 int ret_val = FPGA_FAIL;
72 switch (desc->iface) {
74 PRINTF ("%s: Launching Passive Serial Dump\n", __FUNCTION__);
75 ret_val = CYC2_ps_dump (desc, buf, bsize);
78 /* Add new interface types here */
81 printf ("%s: Unsupported interface type, %d\n",
82 __FUNCTION__, desc->iface);
88 int CYC2_info( Altera_desc *desc )
93 /* ------------------------------------------------------------------------- */
94 /* CYCLON2 Passive Serial Generic Implementation */
95 static int CYC2_ps_load(Altera_desc *desc, const void *buf, size_t bsize)
97 int ret_val = FPGA_FAIL; /* assume the worst */
98 Altera_CYC2_Passive_Serial_fns *fn = desc->iface_fns;
101 PRINTF ("%s: start with interface functions @ 0x%p\n",
105 int cookie = desc->cookie; /* make a local copy */
106 unsigned long ts; /* timestamp */
108 PRINTF ("%s: Function Table:\n"
115 __FUNCTION__, &fn, fn, fn->config, fn->status,
116 fn->write, fn->done);
117 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
118 printf ("Loading FPGA Device %d...", cookie);
122 * Run the pre configuration function if there is one.
128 /* Establish the initial state */
129 (*fn->config) (false, true, cookie); /* De-assert nCONFIG */
131 (*fn->config) (true, true, cookie); /* Assert nCONFIG */
133 udelay(2); /* T_cfg > 2us */
135 /* Wait for nSTATUS to be asserted */
136 ts = get_timer (0); /* get current time */
138 CONFIG_FPGA_DELAY ();
139 if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT) { /* check the time */
140 puts ("** Timeout waiting for STATUS to go high.\n");
141 (*fn->abort) (cookie);
144 } while (!(*fn->status) (cookie));
146 /* Get ready for the burn */
147 CONFIG_FPGA_DELAY ();
149 ret = (*fn->write) (buf, bsize, true, cookie);
151 puts ("** Write failed.\n");
152 (*fn->abort) (cookie);
155 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
159 CONFIG_FPGA_DELAY ();
161 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
162 putc (' '); /* terminate the dotted line */
166 * Checking FPGA's CONF_DONE signal - correctly booted ?
169 if ( ! (*fn->done) (cookie) ) {
170 puts ("** Booting failed! CONF_DONE is still deasserted.\n");
171 (*fn->abort) (cookie);
174 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
178 ret_val = FPGA_SUCCESS;
180 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
181 if (ret_val == FPGA_SUCCESS) {
188 (*fn->post) (cookie);
191 printf ("%s: NULL Interface function table!\n", __FUNCTION__);
197 static int CYC2_ps_dump(Altera_desc *desc, const void *buf, size_t bsize)
199 /* Readback is only available through the Slave Parallel and */
200 /* boundary-scan interfaces. */
201 printf ("%s: Passive Serial Dumping is unavailable\n",