rename CFG_ macros to CONFIG_SYS
[oweals/u-boot.git] / common / spartan3.c
index f7c4f8cf2b24aa9e70110d68440198449d8c01b8..9ce41f1d2766daed1da0701802bd07ea1c454d7a 100644 (file)
@@ -30,8 +30,6 @@
 #include <common.h>            /* core U-Boot definitions */
 #include <spartan3.h>          /* Spartan-II device family */
 
-#if (CONFIG_FPGA & (CFG_XILINX | CFG_SPARTAN3))
-
 /* Define FPGA_DEBUG to get debug printf's */
 #ifdef FPGA_DEBUG
 #define PRINTF(fmt,args...)    printf (fmt ,##args)
@@ -39,8 +37,8 @@
 #define PRINTF(fmt,args...)
 #endif
 
-#undef CFG_FPGA_CHECK_BUSY
-#undef CFG_FPGA_PROG_FEEDBACK
+#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).
@@ -51,8 +49,8 @@
 #define CONFIG_FPGA_DELAY()
 #endif
 
-#ifndef CFG_FPGA_WAIT
-#define CFG_FPGA_WAIT CFG_HZ/100       /* 10 ms */
+#ifndef CONFIG_SYS_FPGA_WAIT
+#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 );
@@ -187,7 +185,7 @@ static int Spartan3_sp_load (Xilinx_desc * desc, void *buf, size_t bsize)
                 * Continuous Data Loading in Slave Parallel Mode for
                 * the Spartan-II Family.
                 */
-#ifdef CFG_FPGA_PROG_FEEDBACK
+#ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
                printf ("Loading FPGA Device %d...\n", cookie);
 #endif
                /*
@@ -208,7 +206,7 @@ static int Spartan3_sp_load (Xilinx_desc * desc, void *buf, size_t bsize)
                /* Now wait for INIT and BUSY to go high */
                do {
                        CONFIG_FPGA_DELAY ();
-                       if (get_timer (ts) > CFG_FPGA_WAIT) {   /* check the time */
+                       if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT) {    /* check the time */
                                puts ("** Timeout waiting for INIT to clear.\n");
                                (*fn->abort) (cookie);  /* abort the burn */
                                return FPGA_FAIL;
@@ -230,7 +228,7 @@ static int Spartan3_sp_load (Xilinx_desc * desc, void *buf, size_t bsize)
                        CONFIG_FPGA_DELAY ();
                        (*fn->clk) (TRUE, TRUE, cookie);        /* Assert the clock pin */
 
-#ifdef CFG_FPGA_CHECK_BUSY
+#ifdef CONFIG_SYS_FPGA_CHECK_BUSY
                        ts = get_timer (0);     /* get current time */
                        while ((*fn->busy) (cookie)) {
                                /* XXX - we should have a check in here somewhere to
@@ -241,7 +239,7 @@ static int Spartan3_sp_load (Xilinx_desc * desc, void *buf, size_t bsize)
                                CONFIG_FPGA_DELAY ();
                                (*fn->clk) (TRUE, TRUE, cookie);        /* Assert the clock pin */
 
-                               if (get_timer (ts) > CFG_FPGA_WAIT) {   /* check the time */
+                               if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT) {    /* check the time */
                                        puts ("** Timeout waiting for BUSY to clear.\n");
                                        (*fn->abort) (cookie);  /* abort the burn */
                                        return FPGA_FAIL;
@@ -249,7 +247,7 @@ static int Spartan3_sp_load (Xilinx_desc * desc, void *buf, size_t bsize)
                        }
 #endif
 
-#ifdef CFG_FPGA_PROG_FEEDBACK
+#ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
                        if (bytecount % (bsize / 40) == 0)
                                putc ('.');             /* let them know we are alive */
 #endif
@@ -259,7 +257,7 @@ static int Spartan3_sp_load (Xilinx_desc * desc, void *buf, size_t bsize)
                (*fn->cs) (FALSE, TRUE, cookie);        /* Deassert the chip select */
                (*fn->wr) (FALSE, TRUE, cookie);        /* Deassert the write pin */
 
-#ifdef CFG_FPGA_PROG_FEEDBACK
+#ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
                putc ('\n');                    /* terminate the dotted line */
 #endif
 
@@ -275,7 +273,7 @@ static int Spartan3_sp_load (Xilinx_desc * desc, void *buf, size_t bsize)
                        CONFIG_FPGA_DELAY ();
                        (*fn->clk) (TRUE, TRUE, cookie);        /* Assert the clock pin */
 
-                       if (get_timer (ts) > CFG_FPGA_WAIT) {   /* check the time */
+                       if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT) {    /* check the time */
                                puts ("** Timeout waiting for DONE to clear.\n");
                                (*fn->abort) (cookie);  /* abort the burn */
                                ret_val = FPGA_FAIL;
@@ -284,7 +282,7 @@ static int Spartan3_sp_load (Xilinx_desc * desc, void *buf, size_t bsize)
                }
 
                if (ret_val == FPGA_SUCCESS) {
-#ifdef CFG_FPGA_PROG_FEEDBACK
+#ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
                        puts ("Done.\n");
 #endif
                }
@@ -296,7 +294,7 @@ static int Spartan3_sp_load (Xilinx_desc * desc, void *buf, size_t bsize)
                }
 
                else {
-#ifdef CFG_FPGA_PROG_FEEDBACK
+#ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
                        puts ("Fail.\n");
 #endif
                }
@@ -330,7 +328,7 @@ static int Spartan3_sp_dump (Xilinx_desc * desc, void *buf, size_t bsize)
                        (*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 CFG_FPGA_PROG_FEEDBACK
+#ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
                        if (bytecount % (bsize / 40) == 0)
                                putc ('.');             /* let them know we are alive */
 #endif
@@ -340,7 +338,7 @@ static int Spartan3_sp_dump (Xilinx_desc * desc, void *buf, size_t bsize)
                (*fn->clk) (FALSE, TRUE, cookie);       /* Deassert the clock pin */
                (*fn->clk) (TRUE, TRUE, cookie);        /* Assert the clock pin */
 
-#ifdef CFG_FPGA_PROG_FEEDBACK
+#ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
                putc ('\n');                    /* terminate the dotted line */
 #endif
                puts ("Done.\n");
@@ -446,7 +444,7 @@ static int Spartan3_ss_load (Xilinx_desc * desc, void *buf, size_t bsize)
        int ret_val = FPGA_FAIL;        /* assume the worst */
        Xilinx_Spartan3_Slave_Serial_fns *fn = desc->iface_fns;
        int i;
-       char  val;
+       unsigned char val;
 
        PRINTF ("%s: start with interface functions @ 0x%p\n",
                        __FUNCTION__, fn);
@@ -467,7 +465,7 @@ static int Spartan3_ss_load (Xilinx_desc * desc, void *buf, size_t bsize)
                                "done:\t0x%p\n\n",
                                __FUNCTION__, &fn, fn, fn->pgm, fn->init,
                                fn->clk, fn->wr, fn->done);
-#ifdef CFG_FPGA_PROG_FEEDBACK
+#ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
                printf ("Loading FPGA Device %d...\n", cookie);
 #endif
 
@@ -485,7 +483,7 @@ static int Spartan3_ss_load (Xilinx_desc * desc, void *buf, size_t bsize)
                ts = get_timer (0);             /* get current time */
                do {
                        CONFIG_FPGA_DELAY ();
-                       if (get_timer (ts) > CFG_FPGA_WAIT) {   /* check the time */
+                       if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT) {    /* check the time */
                                puts ("** Timeout waiting for INIT to start.\n");
                                return FPGA_FAIL;
                        }
@@ -499,7 +497,7 @@ static int Spartan3_ss_load (Xilinx_desc * desc, void *buf, size_t bsize)
                /* Now wait for INIT to go high */
                do {
                        CONFIG_FPGA_DELAY ();
-                       if (get_timer (ts) > CFG_FPGA_WAIT) {   /* check the time */
+                       if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT) {    /* check the time */
                                puts ("** Timeout waiting for INIT to clear.\n");
                                return FPGA_FAIL;
                        }
@@ -530,7 +528,7 @@ static int Spartan3_ss_load (Xilinx_desc * desc, void *buf, size_t bsize)
                                i --;
                        } while (i > 0);
 
-#ifdef CFG_FPGA_PROG_FEEDBACK
+#ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
                        if (bytecount % (bsize / 40) == 0)
                                putc ('.');             /* let them know we are alive */
 #endif
@@ -538,7 +536,7 @@ static int Spartan3_ss_load (Xilinx_desc * desc, void *buf, size_t bsize)
 
                CONFIG_FPGA_DELAY ();
 
-#ifdef CFG_FPGA_PROG_FEEDBACK
+#ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
                putc ('\n');                    /* terminate the dotted line */
 #endif
 
@@ -558,7 +556,7 @@ static int Spartan3_ss_load (Xilinx_desc * desc, void *buf, size_t bsize)
 
                        putc ('*');
 
-                       if (get_timer (ts) > CFG_FPGA_WAIT) {   /* check the time */
+                       if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT) {    /* check the time */
                                puts ("** Timeout waiting for DONE to clear.\n");
                                ret_val = FPGA_FAIL;
                                break;
@@ -566,7 +564,14 @@ static int Spartan3_ss_load (Xilinx_desc * desc, void *buf, size_t bsize)
                }
                putc ('\n');                    /* terminate the dotted line */
 
-#ifdef CFG_FPGA_PROG_FEEDBACK
+               /*
+                * Run the post configuration function if there is one.
+                */
+               if (*fn->post) {
+                       (*fn->post) (cookie);
+               }
+
+#ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
                if (ret_val == FPGA_SUCCESS) {
                        puts ("Done.\n");
                }
@@ -620,8 +625,10 @@ static int Spartan3_ss_reloc (Xilinx_desc * desc, ulong reloc_offset)
                        PRINTF ("%s: Relocating descriptor at 0x%p\n", __FUNCTION__,
                                        desc);
 
-                       addr = (ulong) (fn->pre) + reloc_offset;
-                       fn_r->pre = (Xilinx_pre_fn) addr;
+                       if (fn->pre) {
+                               addr = (ulong) (fn->pre) + reloc_offset;
+                               fn_r->pre = (Xilinx_pre_fn) addr;
+                       }
 
                        addr = (ulong) (fn->pgm) + reloc_offset;
                        fn_r->pgm = (Xilinx_pgm_fn) addr;
@@ -638,6 +645,11 @@ static int Spartan3_ss_reloc (Xilinx_desc * desc, ulong reloc_offset)
                        addr = (ulong) (fn->wr) + reloc_offset;
                        fn_r->wr = (Xilinx_wr_fn) addr;
 
+                       if (fn->post) {
+                               addr = (ulong) (fn->post) + reloc_offset;
+                               fn_r->post = (Xilinx_post_fn) addr;
+                       }
+
                        fn_r->relocated = TRUE;
 
                } else {
@@ -654,5 +666,3 @@ static int Spartan3_ss_reloc (Xilinx_desc * desc, ulong reloc_offset)
        return ret_val;
 
 }
-
-#endif