]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/fpga/spartan3.c
Merge branch 'u-boot-imx/master' into 'u-boot-arm/master'
[karo-tx-uboot.git] / drivers / fpga / spartan3.c
index 0fe30410a6f93c090e9ee0e8f60fab6e22bfe66b..c63c6052925306ee799d8dce4c2cdfac276d1c00 100644 (file)
@@ -38,7 +38,6 @@
 #endif
 
 #undef CONFIG_SYS_FPGA_CHECK_BUSY
-#undef CONFIG_SYS_FPGA_PROG_FEEDBACK
 
 /* Note: The assumption is that we cannot possibly run fast enough to
  * overrun the device (the Slave Parallel mode can free run at 50MHz).
 #define CONFIG_SYS_FPGA_WAIT CONFIG_SYS_HZ/100 /* 10 ms */
 #endif
 
-static int Spartan3_sp_load( Xilinx_desc *desc, void *buf, size_t bsize );
-static int Spartan3_sp_dump( Xilinx_desc *desc, void *buf, size_t bsize );
-/* static int Spartan3_sp_info( Xilinx_desc *desc ); */
+static int Spartan3_sp_load(Xilinx_desc *desc, const void *buf, size_t bsize);
+static int Spartan3_sp_dump(Xilinx_desc *desc, const void *buf, size_t bsize);
+/* static int Spartan3_sp_info(Xilinx_desc *desc ); */
 
-static int Spartan3_ss_load( Xilinx_desc *desc, void *buf, size_t bsize );
-static int Spartan3_ss_dump( Xilinx_desc *desc, void *buf, size_t bsize );
-/* static int Spartan3_ss_info( Xilinx_desc *desc ); */
+static int Spartan3_ss_load(Xilinx_desc *desc, const void *buf, size_t bsize);
+static int Spartan3_ss_dump(Xilinx_desc *desc, const void *buf, size_t bsize);
+/* static int Spartan3_ss_info(Xilinx_desc *desc); */
 
 /* ------------------------------------------------------------------------- */
 /* Spartan-II Generic Implementation */
-int Spartan3_load (Xilinx_desc * desc, void *buf, size_t bsize)
+int Spartan3_load(Xilinx_desc *desc, const void *buf, size_t bsize)
 {
        int ret_val = FPGA_FAIL;
 
@@ -86,7 +85,7 @@ int Spartan3_load (Xilinx_desc * desc, void *buf, size_t bsize)
        return ret_val;
 }
 
-int Spartan3_dump (Xilinx_desc * desc, void *buf, size_t bsize)
+int Spartan3_dump(Xilinx_desc *desc, const void *buf, size_t bsize)
 {
        int ret_val = FPGA_FAIL;
 
@@ -118,7 +117,7 @@ int Spartan3_info( Xilinx_desc *desc )
 /* ------------------------------------------------------------------------- */
 /* Spartan-II Slave Parallel Generic Implementation */
 
-static int Spartan3_sp_load (Xilinx_desc * desc, void *buf, size_t bsize)
+static int Spartan3_sp_load(Xilinx_desc *desc, const void *buf, size_t bsize)
 {
        int ret_val = FPGA_FAIL;        /* assume the worst */
        Xilinx_Spartan3_Slave_Parallel_fns *fn = desc->iface_fns;
@@ -167,11 +166,11 @@ static int Spartan3_sp_load (Xilinx_desc * desc, void *buf, size_t bsize)
                }
 
                /* Establish the initial state */
-               (*fn->pgm) (TRUE, TRUE, cookie);        /* Assert the program, commit */
+               (*fn->pgm) (true, true, cookie);        /* Assert the program, commit */
 
                /* Get ready for the burn */
                CONFIG_FPGA_DELAY ();
-               (*fn->pgm) (FALSE, TRUE, cookie);       /* Deassert the program, commit */
+               (*fn->pgm) (false, true, cookie);       /* Deassert the program, commit */
 
                ts = get_timer (0);             /* get current time */
                /* Now wait for INIT and BUSY to go high */
@@ -184,20 +183,20 @@ static int Spartan3_sp_load (Xilinx_desc * desc, void *buf, size_t bsize)
                        }
                } while ((*fn->init) (cookie) && (*fn->busy) (cookie));
 
-               (*fn->wr) (TRUE, TRUE, cookie); /* Assert write, commit */
-               (*fn->cs) (TRUE, TRUE, cookie); /* Assert chip select, commit */
-               (*fn->clk) (TRUE, TRUE, cookie);        /* Assert the clock pin */
+               (*fn->wr) (true, true, cookie); /* Assert write, commit */
+               (*fn->cs) (true, true, cookie); /* Assert chip select, commit */
+               (*fn->clk) (true, true, cookie);        /* Assert the clock pin */
 
                /* Load the data */
                while (bytecount < bsize) {
                        /* XXX - do we check for an Ctrl-C press in here ??? */
                        /* XXX - Check the error bit? */
 
-                       (*fn->wdata) (data[bytecount++], TRUE, cookie); /* write the data */
+                       (*fn->wdata) (data[bytecount++], true, cookie); /* write the data */
                        CONFIG_FPGA_DELAY ();
-                       (*fn->clk) (FALSE, TRUE, cookie);       /* Deassert the clock pin */
+                       (*fn->clk) (false, true, cookie);       /* Deassert the clock pin */
                        CONFIG_FPGA_DELAY ();
-                       (*fn->clk) (TRUE, TRUE, cookie);        /* Assert the clock pin */
+                       (*fn->clk) (true, true, cookie);        /* Assert the clock pin */
 
 #ifdef CONFIG_SYS_FPGA_CHECK_BUSY
                        ts = get_timer (0);     /* get current time */
@@ -206,9 +205,9 @@ static int Spartan3_sp_load (Xilinx_desc * desc, void *buf, size_t bsize)
                                 * make sure we aren't busy forever... */
 
                                CONFIG_FPGA_DELAY ();
-                               (*fn->clk) (FALSE, TRUE, cookie);       /* Deassert the clock pin */
+                               (*fn->clk) (false, true, cookie);       /* Deassert the clock pin */
                                CONFIG_FPGA_DELAY ();
-                               (*fn->clk) (TRUE, TRUE, cookie);        /* Assert the clock pin */
+                               (*fn->clk) (true, true, cookie);        /* Assert the clock pin */
 
                                if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT) {    /* check the time */
                                        puts ("** Timeout waiting for BUSY to clear.\n");
@@ -225,8 +224,8 @@ static int Spartan3_sp_load (Xilinx_desc * desc, void *buf, size_t bsize)
                }
 
                CONFIG_FPGA_DELAY ();
-               (*fn->cs) (FALSE, TRUE, cookie);        /* Deassert the chip select */
-               (*fn->wr) (FALSE, TRUE, cookie);        /* Deassert the write pin */
+               (*fn->cs) (false, true, cookie);        /* Deassert the chip select */
+               (*fn->wr) (false, true, cookie);        /* Deassert the write pin */
 
 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
                putc ('\n');                    /* terminate the dotted line */
@@ -240,9 +239,9 @@ static int Spartan3_sp_load (Xilinx_desc * desc, void *buf, size_t bsize)
                         * make sure we aren't busy forever... */
 
                        CONFIG_FPGA_DELAY ();
-                       (*fn->clk) (FALSE, TRUE, cookie);       /* Deassert the clock pin */
+                       (*fn->clk) (false, true, cookie);       /* Deassert the clock pin */
                        CONFIG_FPGA_DELAY ();
-                       (*fn->clk) (TRUE, TRUE, cookie);        /* Assert the clock pin */
+                       (*fn->clk) (true, true, cookie);        /* Assert the clock pin */
 
                        if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT) {    /* check the time */
                                puts ("** Timeout waiting for DONE to clear.\n");
@@ -272,7 +271,7 @@ static int Spartan3_sp_load (Xilinx_desc * desc, void *buf, size_t bsize)
        return ret_val;
 }
 
-static int Spartan3_sp_dump (Xilinx_desc * desc, void *buf, size_t bsize)
+static int Spartan3_sp_dump(Xilinx_desc *desc, const void *buf, size_t bsize)
 {
        int ret_val = FPGA_FAIL;        /* assume the worst */
        Xilinx_Spartan3_Slave_Parallel_fns *fn = desc->iface_fns;
@@ -284,15 +283,15 @@ static int Spartan3_sp_dump (Xilinx_desc * desc, void *buf, size_t bsize)
 
                printf ("Starting Dump of FPGA Device %d...\n", cookie);
 
-               (*fn->cs) (TRUE, TRUE, cookie); /* Assert chip select, commit */
-               (*fn->clk) (TRUE, TRUE, cookie);        /* Assert the clock pin */
+               (*fn->cs) (true, true, cookie); /* Assert chip select, commit */
+               (*fn->clk) (true, true, cookie);        /* Assert the clock pin */
 
                /* dump the data */
                while (bytecount < bsize) {
                        /* XXX - do we check for an Ctrl-C press in here ??? */
 
-                       (*fn->clk) (FALSE, TRUE, cookie);       /* Deassert the clock pin */
-                       (*fn->clk) (TRUE, TRUE, cookie);        /* Assert the clock pin */
+                       (*fn->clk) (false, true, cookie);       /* Deassert the clock pin */
+                       (*fn->clk) (true, true, cookie);        /* Assert the clock pin */
                        (*fn->rdata) (&(data[bytecount++]), cookie);    /* read the data */
 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
                        if (bytecount % (bsize / 40) == 0)
@@ -300,9 +299,9 @@ static int Spartan3_sp_dump (Xilinx_desc * desc, void *buf, size_t bsize)
 #endif
                }
 
-               (*fn->cs) (FALSE, FALSE, cookie);       /* Deassert the chip select */
-               (*fn->clk) (FALSE, TRUE, cookie);       /* Deassert the clock pin */
-               (*fn->clk) (TRUE, TRUE, cookie);        /* Assert the clock pin */
+               (*fn->cs) (false, false, cookie);       /* Deassert the chip select */
+               (*fn->clk) (false, true, cookie);       /* Deassert the clock pin */
+               (*fn->clk) (true, true, cookie);        /* Assert the clock pin */
 
 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
                putc ('\n');                    /* terminate the dotted line */
@@ -320,7 +319,7 @@ static int Spartan3_sp_dump (Xilinx_desc * desc, void *buf, size_t bsize)
 
 /* ------------------------------------------------------------------------- */
 
-static int Spartan3_ss_load (Xilinx_desc * desc, void *buf, size_t bsize)
+static int Spartan3_ss_load(Xilinx_desc *desc, const void *buf, size_t bsize)
 {
        int ret_val = FPGA_FAIL;        /* assume the worst */
        Xilinx_Spartan3_Slave_Serial_fns *fn = desc->iface_fns;
@@ -358,7 +357,7 @@ static int Spartan3_ss_load (Xilinx_desc * desc, void *buf, size_t bsize)
                }
 
                /* Establish the initial state */
-               (*fn->pgm) (TRUE, TRUE, cookie);        /* Assert the program, commit */
+               (*fn->pgm) (true, true, cookie);        /* Assert the program, commit */
 
                /* Wait for INIT state (init low)                            */
                ts = get_timer (0);             /* get current time */
@@ -366,13 +365,15 @@ static int Spartan3_ss_load (Xilinx_desc * desc, void *buf, size_t bsize)
                        CONFIG_FPGA_DELAY ();
                        if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT) {    /* check the time */
                                puts ("** Timeout waiting for INIT to start.\n");
+                               if (*fn->abort)
+                                       (*fn->abort) (cookie);
                                return FPGA_FAIL;
                        }
                } while (!(*fn->init) (cookie));
 
                /* Get ready for the burn */
                CONFIG_FPGA_DELAY ();
-               (*fn->pgm) (FALSE, TRUE, cookie);       /* Deassert the program, commit */
+               (*fn->pgm) (false, true, cookie);       /* Deassert the program, commit */
 
                ts = get_timer (0);             /* get current time */
                /* Now wait for INIT to go high */
@@ -380,39 +381,47 @@ static int Spartan3_ss_load (Xilinx_desc * desc, void *buf, size_t bsize)
                        CONFIG_FPGA_DELAY ();
                        if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT) {    /* check the time */
                                puts ("** Timeout waiting for INIT to clear.\n");
+                               if (*fn->abort)
+                                       (*fn->abort) (cookie);
                                return FPGA_FAIL;
                        }
                } while ((*fn->init) (cookie));
 
                /* Load the data */
-               while (bytecount < bsize) {
-
-                       /* Xilinx detects an error if INIT goes low (active)
-                          while DONE is low (inactive) */
-                       if ((*fn->done) (cookie) == 0 && (*fn->init) (cookie)) {
-                               puts ("** CRC error during FPGA load.\n");
-                               return (FPGA_FAIL);
-                       }
-                       val = data [bytecount ++];
-                       i = 8;
-                       do {
-                               /* Deassert the clock */
-                               (*fn->clk) (FALSE, TRUE, cookie);
-                               CONFIG_FPGA_DELAY ();
-                               /* Write data */
-                               (*fn->wr) ((val & 0x80), TRUE, cookie);
-                               CONFIG_FPGA_DELAY ();
-                               /* Assert the clock */
-                               (*fn->clk) (TRUE, TRUE, cookie);
-                               CONFIG_FPGA_DELAY ();
-                               val <<= 1;
-                               i --;
-                       } while (i > 0);
+               if(*fn->bwr)
+                       (*fn->bwr) (data, bsize, true, cookie);
+               else {
+                       while (bytecount < bsize) {
+
+                               /* Xilinx detects an error if INIT goes low (active)
+                                  while DONE is low (inactive) */
+                               if ((*fn->done) (cookie) == 0 && (*fn->init) (cookie)) {
+                                       puts ("** CRC error during FPGA load.\n");
+                                       if (*fn->abort)
+                                               (*fn->abort) (cookie);
+                                       return (FPGA_FAIL);
+                               }
+                               val = data [bytecount ++];
+                               i = 8;
+                               do {
+                                       /* Deassert the clock */
+                                       (*fn->clk) (false, true, cookie);
+                                       CONFIG_FPGA_DELAY ();
+                                       /* Write data */
+                                       (*fn->wr) ((val & 0x80), true, cookie);
+                                       CONFIG_FPGA_DELAY ();
+                                       /* Assert the clock */
+                                       (*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 ('.');             /* let them know we are alive */
+                               if (bytecount % (bsize / 40) == 0)
+                                       putc ('.');             /* let them know we are alive */
 #endif
+                       }
                }
 
                CONFIG_FPGA_DELAY ();
@@ -424,16 +433,16 @@ static int Spartan3_ss_load (Xilinx_desc * desc, void *buf, size_t bsize)
                /* now check for done signal */
                ts = get_timer (0);             /* get current time */
                ret_val = FPGA_SUCCESS;
-               (*fn->wr) (TRUE, TRUE, cookie);
+               (*fn->wr) (true, true, cookie);
 
                while (! (*fn->done) (cookie)) {
                        /* XXX - we should have a check in here somewhere to
                         * make sure we aren't busy forever... */
 
                        CONFIG_FPGA_DELAY ();
-                       (*fn->clk) (FALSE, TRUE, cookie);       /* Deassert the clock pin */
+                       (*fn->clk) (false, true, cookie);       /* Deassert the clock pin */
                        CONFIG_FPGA_DELAY ();
-                       (*fn->clk) (TRUE, TRUE, cookie);        /* Assert the clock pin */
+                       (*fn->clk) (true, true, cookie);        /* Assert the clock pin */
 
                        putc ('*');
 
@@ -465,7 +474,7 @@ static int Spartan3_ss_load (Xilinx_desc * desc, void *buf, size_t bsize)
        return ret_val;
 }
 
-static int Spartan3_ss_dump (Xilinx_desc * desc, void *buf, size_t bsize)
+static int Spartan3_ss_dump(Xilinx_desc *desc, const void *buf, size_t bsize)
 {
        /* Readback is only available through the Slave Parallel and         */
        /* boundary-scan interfaces.                                         */