]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - drivers/fpga/spartan2.c
Merge branch 'master' of git://www.denx.de/git/u-boot-imx
[people/ms/u-boot.git] / drivers / fpga / spartan2.c
index cd16a9c44c29046571c527d6118b208c194a58c0..859fb3c7787af8562336e6c7e378b70b9fb3c994 100644 (file)
@@ -2,24 +2,7 @@
  * (C) Copyright 2002
  * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
  *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
- *
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>            /* core U-Boot definitions */
 #define CONFIG_SYS_FPGA_WAIT CONFIG_SYS_HZ/100 /* 10 ms */
 #endif
 
-static int Spartan2_sp_load( Xilinx_desc *desc, void *buf, size_t bsize );
-static int Spartan2_sp_dump( Xilinx_desc *desc, void *buf, size_t bsize );
-/* static int Spartan2_sp_info( Xilinx_desc *desc ); */
+static int spartan2_sp_load(xilinx_desc *desc, const void *buf, size_t bsize);
+static int spartan2_sp_dump(xilinx_desc *desc, const void *buf, size_t bsize);
+/* static int spartan2_sp_info(xilinx_desc *desc ); */
 
-static int Spartan2_ss_load( Xilinx_desc *desc, void *buf, size_t bsize );
-static int Spartan2_ss_dump( Xilinx_desc *desc, void *buf, size_t bsize );
-/* static int Spartan2_ss_info( Xilinx_desc *desc ); */
+static int spartan2_ss_load(xilinx_desc *desc, const void *buf, size_t bsize);
+static int spartan2_ss_dump(xilinx_desc *desc, const void *buf, size_t bsize);
+/* static int spartan2_ss_info(xilinx_desc *desc ); */
 
 /* ------------------------------------------------------------------------- */
 /* Spartan-II Generic Implementation */
-int Spartan2_load (Xilinx_desc * desc, void *buf, size_t bsize)
+static int spartan2_load(xilinx_desc *desc, const void *buf, size_t bsize,
+                        bitstream_type bstype)
 {
        int ret_val = FPGA_FAIL;
 
        switch (desc->iface) {
        case slave_serial:
                PRINTF ("%s: Launching Slave Serial Load\n", __FUNCTION__);
-               ret_val = Spartan2_ss_load (desc, buf, bsize);
+               ret_val = spartan2_ss_load(desc, buf, bsize);
                break;
 
        case slave_parallel:
                PRINTF ("%s: Launching Slave Parallel Load\n", __FUNCTION__);
-               ret_val = Spartan2_sp_load (desc, buf, bsize);
+               ret_val = spartan2_sp_load(desc, buf, bsize);
                break;
 
        default:
@@ -81,19 +65,19 @@ int Spartan2_load (Xilinx_desc * desc, void *buf, size_t bsize)
        return ret_val;
 }
 
-int Spartan2_dump (Xilinx_desc * desc, void *buf, size_t bsize)
+static int spartan2_dump(xilinx_desc *desc, const void *buf, size_t bsize)
 {
        int ret_val = FPGA_FAIL;
 
        switch (desc->iface) {
        case slave_serial:
                PRINTF ("%s: Launching Slave Serial Dump\n", __FUNCTION__);
-               ret_val = Spartan2_ss_dump (desc, buf, bsize);
+               ret_val = spartan2_ss_dump(desc, buf, bsize);
                break;
 
        case slave_parallel:
                PRINTF ("%s: Launching Slave Parallel Dump\n", __FUNCTION__);
-               ret_val = Spartan2_sp_dump (desc, buf, bsize);
+               ret_val = spartan2_sp_dump(desc, buf, bsize);
                break;
 
        default:
@@ -104,7 +88,7 @@ int Spartan2_dump (Xilinx_desc * desc, void *buf, size_t bsize)
        return ret_val;
 }
 
-int Spartan2_info( Xilinx_desc *desc )
+static int spartan2_info(xilinx_desc *desc)
 {
        return FPGA_SUCCESS;
 }
@@ -113,10 +97,10 @@ int Spartan2_info( Xilinx_desc *desc )
 /* ------------------------------------------------------------------------- */
 /* Spartan-II Slave Parallel Generic Implementation */
 
-static int Spartan2_sp_load (Xilinx_desc * desc, void *buf, size_t bsize)
+static int spartan2_sp_load(xilinx_desc *desc, const void *buf, size_t bsize)
 {
        int ret_val = FPGA_FAIL;        /* assume the worst */
-       Xilinx_Spartan2_Slave_Parallel_fns *fn = desc->iface_fns;
+       xilinx_spartan2_slave_parallel_fns *fn = desc->iface_fns;
 
        PRINTF ("%s: start with interface functions @ 0x%p\n",
                        __FUNCTION__, fn);
@@ -162,11 +146,11 @@ static int Spartan2_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 */
@@ -179,20 +163,20 @@ static int Spartan2_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 */
@@ -201,9 +185,9 @@ static int Spartan2_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");
@@ -220,8 +204,8 @@ static int Spartan2_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 */
@@ -233,9 +217,9 @@ static int Spartan2_sp_load (Xilinx_desc * desc, void *buf, size_t bsize)
                while ((*fn->done) (cookie) == FPGA_FAIL) {
 
                        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");
@@ -265,10 +249,10 @@ static int Spartan2_sp_load (Xilinx_desc * desc, void *buf, size_t bsize)
        return ret_val;
 }
 
-static int Spartan2_sp_dump (Xilinx_desc * desc, void *buf, size_t bsize)
+static int spartan2_sp_dump(xilinx_desc *desc, const void *buf, size_t bsize)
 {
        int ret_val = FPGA_FAIL;        /* assume the worst */
-       Xilinx_Spartan2_Slave_Parallel_fns *fn = desc->iface_fns;
+       xilinx_spartan2_slave_parallel_fns *fn = desc->iface_fns;
 
        if (fn) {
                unsigned char *data = (unsigned char *) buf;
@@ -277,15 +261,15 @@ static int Spartan2_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)
@@ -293,9 +277,9 @@ static int Spartan2_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 */
@@ -313,10 +297,10 @@ static int Spartan2_sp_dump (Xilinx_desc * desc, void *buf, size_t bsize)
 
 /* ------------------------------------------------------------------------- */
 
-static int Spartan2_ss_load (Xilinx_desc * desc, void *buf, size_t bsize)
+static int spartan2_ss_load(xilinx_desc *desc, const void *buf, size_t bsize)
 {
        int ret_val = FPGA_FAIL;        /* assume the worst */
-       Xilinx_Spartan2_Slave_Serial_fns *fn = desc->iface_fns;
+       xilinx_spartan2_slave_serial_fns *fn = desc->iface_fns;
        int i;
        unsigned char val;
 
@@ -351,7 +335,7 @@ static int Spartan2_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 */
@@ -365,7 +349,7 @@ static int Spartan2_ss_load (Xilinx_desc * desc, void *buf, size_t bsize)
 
                /* 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 */
@@ -390,13 +374,13 @@ static int Spartan2_ss_load (Xilinx_desc * desc, void *buf, size_t bsize)
                        i = 8;
                        do {
                                /* Deassert the clock */
-                               (*fn->clk) (FALSE, TRUE, cookie);
+                               (*fn->clk) (false, true, cookie);
                                CONFIG_FPGA_DELAY ();
                                /* Write data */
-                               (*fn->wr) ((val & 0x80), TRUE, cookie);
+                               (*fn->wr) ((val & 0x80), true, cookie);
                                CONFIG_FPGA_DELAY ();
                                /* Assert the clock */
-                               (*fn->clk) (TRUE, TRUE, cookie);
+                               (*fn->clk) (true, true, cookie);
                                CONFIG_FPGA_DELAY ();
                                val <<= 1;
                                i --;
@@ -417,14 +401,14 @@ static int Spartan2_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)) {
 
                        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 ('*');
 
@@ -456,7 +440,7 @@ static int Spartan2_ss_load (Xilinx_desc * desc, void *buf, size_t bsize)
        return ret_val;
 }
 
-static int Spartan2_ss_dump (Xilinx_desc * desc, void *buf, size_t bsize)
+static int spartan2_ss_dump(xilinx_desc *desc, const void *buf, size_t bsize)
 {
        /* Readback is only available through the Slave Parallel and         */
        /* boundary-scan interfaces.                                         */
@@ -464,3 +448,9 @@ static int Spartan2_ss_dump (Xilinx_desc * desc, void *buf, size_t bsize)
                        __FUNCTION__);
        return FPGA_FAIL;
 }
+
+struct xilinx_fpga_op spartan2_op = {
+       .load = spartan2_load,
+       .dump = spartan2_dump,
+       .info = spartan2_info,
+};