123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- #include <common.h> /* core U-Boot definitions */
- #include <console.h>
- #include <ACEX1K.h> /* ACEX device family */
- #ifdef FPGA_DEBUG
- #define PRINTF(fmt,args...) printf (fmt ,##args)
- #else
- #define PRINTF(fmt,args...)
- #endif
- #ifndef CONFIG_FPGA_DELAY
- #define CONFIG_FPGA_DELAY()
- #endif
- #ifndef CONFIG_SYS_FPGA_WAIT
- #define CONFIG_SYS_FPGA_WAIT CONFIG_SYS_HZ/10
- #endif
- static int ACEX1K_ps_load(Altera_desc *desc, const void *buf, size_t bsize);
- static int ACEX1K_ps_dump(Altera_desc *desc, const void *buf, size_t bsize);
- int ACEX1K_load(Altera_desc *desc, const void *buf, size_t bsize)
- {
- int ret_val = FPGA_FAIL;
- switch (desc->iface) {
- case passive_serial:
- PRINTF ("%s: Launching Passive Serial Loader\n", __FUNCTION__);
- ret_val = ACEX1K_ps_load (desc, buf, bsize);
- break;
-
- default:
- printf ("%s: Unsupported interface type, %d\n",
- __FUNCTION__, desc->iface);
- }
- return ret_val;
- }
- int ACEX1K_dump(Altera_desc *desc, const void *buf, size_t bsize)
- {
- int ret_val = FPGA_FAIL;
- switch (desc->iface) {
- case passive_serial:
- PRINTF ("%s: Launching Passive Serial Dump\n", __FUNCTION__);
- ret_val = ACEX1K_ps_dump (desc, buf, bsize);
- break;
-
- default:
- printf ("%s: Unsupported interface type, %d\n",
- __FUNCTION__, desc->iface);
- }
- return ret_val;
- }
- int ACEX1K_info( Altera_desc *desc )
- {
- return FPGA_SUCCESS;
- }
- static int ACEX1K_ps_load(Altera_desc *desc, const void *buf, size_t bsize)
- {
- int ret_val = FPGA_FAIL;
- Altera_ACEX1K_Passive_Serial_fns *fn = desc->iface_fns;
- int i;
- PRINTF ("%s: start with interface functions @ 0x%p\n",
- __FUNCTION__, fn);
- if (fn) {
- size_t bytecount = 0;
- unsigned char *data = (unsigned char *) buf;
- int cookie = desc->cookie;
- unsigned long ts;
- PRINTF ("%s: Function Table:\n"
- "ptr:\t0x%p\n"
- "struct: 0x%p\n"
- "config:\t0x%p\n"
- "status:\t0x%p\n"
- "clk:\t0x%p\n"
- "data:\t0x%p\n"
- "done:\t0x%p\n\n",
- __FUNCTION__, &fn, fn, fn->config, fn->status,
- fn->clk, fn->data, fn->done);
- #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
- printf ("Loading FPGA Device %d...", cookie);
- #endif
-
- if (*fn->pre) {
- (*fn->pre) (cookie);
- }
-
- (*fn->config) (true, true, cookie);
- udelay(2);
-
- (*fn->done) (cookie);
- if ( !(*fn->status) (cookie) ) {
- puts ("** nSTATUS is not asserted.\n");
- (*fn->abort) (cookie);
- return FPGA_FAIL;
- }
- (*fn->config) (false, true, cookie);
- udelay(2);
-
- ts = get_timer (0);
- do {
- CONFIG_FPGA_DELAY ();
- if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT) {
- puts ("** Timeout waiting for STATUS to go high.\n");
- (*fn->abort) (cookie);
- return FPGA_FAIL;
- }
- (*fn->done) (cookie);
- } while ((*fn->status) (cookie));
-
- CONFIG_FPGA_DELAY ();
-
- while (bytecount < bsize) {
- unsigned char val=0;
- #ifdef CONFIG_SYS_FPGA_CHECK_CTRLC
- if (ctrlc ()) {
- (*fn->abort) (cookie);
- return FPGA_FAIL;
- }
- #endif
-
- #if 0
- if ((*fn->done) (cookie) == 0 && (*fn->init) (cookie)) {
- puts ("** CRC error during FPGA load.\n");
- (*fn->abort) (cookie);
- return (FPGA_FAIL);
- }
- #endif
- val = data [bytecount ++ ];
- i = 8;
- do {
-
- (*fn->clk) (false, true, cookie);
- CONFIG_FPGA_DELAY ();
-
- (*fn->data) ((val & 0x01), true, cookie);
- CONFIG_FPGA_DELAY ();
-
- (*fn->clk) (true, true, cookie);
- CONFIG_FPGA_DELAY ();
- val >>= 1;
- i --;
- } while (i > 0);
- #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
- if (bytecount % (bsize / 40) == 0)
- putc ('.');
- #endif
- }
- CONFIG_FPGA_DELAY ();
- #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
- putc (' ');
- #endif
-
- if ( ! (*fn->done) (cookie) ) {
- puts ("** Booting failed! CONF_DONE is still deasserted.\n");
- (*fn->abort) (cookie);
- return (FPGA_FAIL);
- }
-
- for (i = 0; i < 12; i++) {
- CONFIG_FPGA_DELAY ();
- (*fn->clk) (true, true, cookie);
- CONFIG_FPGA_DELAY ();
- (*fn->clk) (false, true, cookie);
- }
- ret_val = FPGA_SUCCESS;
- #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
- if (ret_val == FPGA_SUCCESS) {
- puts ("Done.\n");
- }
- else {
- puts ("Fail.\n");
- }
- #endif
- (*fn->post) (cookie);
- } else {
- printf ("%s: NULL Interface function table!\n", __FUNCTION__);
- }
- return ret_val;
- }
- static int ACEX1K_ps_dump(Altera_desc *desc, const void *buf, size_t bsize)
- {
-
-
- printf ("%s: Passive Serial Dumping is unavailable\n",
- __FUNCTION__);
- return FPGA_FAIL;
- }
|