3 * Steven Scholz, imc Measurement & Control, steven.scholz@imc-berlin.de
6 * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
8 * SPDX-License-Identifier: GPL-2.0+
11 #include <common.h> /* core U-Boot definitions */
12 #include <ACEX1K.h> /* ACEX device family */
14 /* Define FPGA_DEBUG to get debug printf's */
16 #define PRINTF(fmt,args...) printf (fmt ,##args)
18 #define PRINTF(fmt,args...)
21 /* Note: The assumption is that we cannot possibly run fast enough to
22 * overrun the device (the Slave Parallel mode can free run at 50MHz).
23 * If there is a need to operate slower, define CONFIG_FPGA_DELAY in
24 * the board config file to slow things down.
26 #ifndef CONFIG_FPGA_DELAY
27 #define CONFIG_FPGA_DELAY()
30 #ifndef CONFIG_SYS_FPGA_WAIT
31 #define CONFIG_SYS_FPGA_WAIT CONFIG_SYS_HZ/10 /* 100 ms */
34 static int ACEX1K_ps_load(Altera_desc
*desc
, const void *buf
, size_t bsize
);
35 static int ACEX1K_ps_dump(Altera_desc
*desc
, const void *buf
, size_t bsize
);
36 /* static int ACEX1K_ps_info(Altera_desc *desc); */
38 /* ------------------------------------------------------------------------- */
39 /* ACEX1K Generic Implementation */
40 int ACEX1K_load(Altera_desc
*desc
, const void *buf
, size_t bsize
)
42 int ret_val
= FPGA_FAIL
;
44 switch (desc
->iface
) {
46 PRINTF ("%s: Launching Passive Serial Loader\n", __FUNCTION__
);
47 ret_val
= ACEX1K_ps_load (desc
, buf
, bsize
);
50 /* Add new interface types here */
53 printf ("%s: Unsupported interface type, %d\n",
54 __FUNCTION__
, desc
->iface
);
60 int ACEX1K_dump(Altera_desc
*desc
, const void *buf
, size_t bsize
)
62 int ret_val
= FPGA_FAIL
;
64 switch (desc
->iface
) {
66 PRINTF ("%s: Launching Passive Serial Dump\n", __FUNCTION__
);
67 ret_val
= ACEX1K_ps_dump (desc
, buf
, bsize
);
70 /* Add new interface types here */
73 printf ("%s: Unsupported interface type, %d\n",
74 __FUNCTION__
, desc
->iface
);
80 int ACEX1K_info( Altera_desc
*desc
)
86 /* ------------------------------------------------------------------------- */
87 /* ACEX1K Passive Serial Generic Implementation */
89 static int ACEX1K_ps_load(Altera_desc
*desc
, const void *buf
, size_t bsize
)
91 int ret_val
= FPGA_FAIL
; /* assume the worst */
92 Altera_ACEX1K_Passive_Serial_fns
*fn
= desc
->iface_fns
;
95 PRINTF ("%s: start with interface functions @ 0x%p\n",
100 unsigned char *data
= (unsigned char *) buf
;
101 int cookie
= desc
->cookie
; /* make a local copy */
102 unsigned long ts
; /* timestamp */
104 PRINTF ("%s: Function Table:\n"
112 __FUNCTION__
, &fn
, fn
, fn
->config
, fn
->status
,
113 fn
->clk
, fn
->data
, fn
->done
);
114 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
115 printf ("Loading FPGA Device %d...", cookie
);
119 * Run the pre configuration function if there is one.
125 /* Establish the initial state */
126 (*fn
->config
) (true, true, cookie
); /* Assert nCONFIG */
128 udelay(2); /* T_cfg > 2us */
130 /* nSTATUS should be asserted now */
131 (*fn
->done
) (cookie
);
132 if ( !(*fn
->status
) (cookie
) ) {
133 puts ("** nSTATUS is not asserted.\n");
134 (*fn
->abort
) (cookie
);
138 (*fn
->config
) (false, true, cookie
); /* Deassert nCONFIG */
139 udelay(2); /* T_cf2st1 < 4us */
141 /* Wait for nSTATUS to be released (i.e. deasserted) */
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 (*fn
->done
) (cookie
);
151 } while ((*fn
->status
) (cookie
));
153 /* Get ready for the burn */
154 CONFIG_FPGA_DELAY ();
157 while (bytecount
< bsize
) {
159 #ifdef CONFIG_SYS_FPGA_CHECK_CTRLC
161 (*fn
->abort
) (cookie
);
165 /* Altera detects an error if INIT goes low (active)
166 while DONE is low (inactive) */
167 #if 0 /* not yet implemented */
168 if ((*fn
->done
) (cookie
) == 0 && (*fn
->init
) (cookie
)) {
169 puts ("** CRC error during FPGA load.\n");
170 (*fn
->abort
) (cookie
);
174 val
= data
[bytecount
++ ];
177 /* Deassert the clock */
178 (*fn
->clk
) (false, true, cookie
);
179 CONFIG_FPGA_DELAY ();
181 (*fn
->data
) ((val
& 0x01), true, cookie
);
182 CONFIG_FPGA_DELAY ();
183 /* Assert the clock */
184 (*fn
->clk
) (true, true, cookie
);
185 CONFIG_FPGA_DELAY ();
190 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
191 if (bytecount
% (bsize
/ 40) == 0)
192 putc ('.'); /* let them know we are alive */
196 CONFIG_FPGA_DELAY ();
198 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
199 putc (' '); /* terminate the dotted line */
203 * Checking FPGA's CONF_DONE signal - correctly booted ?
206 if ( ! (*fn
->done
) (cookie
) ) {
207 puts ("** Booting failed! CONF_DONE is still deasserted.\n");
208 (*fn
->abort
) (cookie
);
213 * "DCLK must be clocked an additional 10 times fpr ACEX 1K..."
216 for (i
= 0; i
< 12; i
++) {
217 CONFIG_FPGA_DELAY ();
218 (*fn
->clk
) (true, true, cookie
); /* Assert the clock pin */
219 CONFIG_FPGA_DELAY ();
220 (*fn
->clk
) (false, true, cookie
); /* Deassert the clock pin */
223 ret_val
= FPGA_SUCCESS
;
225 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
226 if (ret_val
== FPGA_SUCCESS
) {
233 (*fn
->post
) (cookie
);
236 printf ("%s: NULL Interface function table!\n", __FUNCTION__
);
242 static int ACEX1K_ps_dump(Altera_desc
*desc
, const void *buf
, size_t bsize
)
244 /* Readback is only available through the Slave Parallel and */
245 /* boundary-scan interfaces. */
246 printf ("%s: Passive Serial Dumping is unavailable\n",