Merge branch 'master' of git://git.denx.de/u-boot-spi
[oweals/u-boot.git] / board / matrix_vision / mvblx / fpga.c
index dacc13845dc473549560bdabfa48d5a4c2f98c64..7f9b24550597888c342b9cb5e9b66ec63cbd75b6 100644 (file)
@@ -7,30 +7,14 @@
  * Andre Schwarz, Matrix Vision GmbH, andre.schwarz@matrix-vision.de
  * Michael Jones, Matrix Vision GmbH, michael.jones@matrix-vision.de
  *
- * 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>
 #include <ACEX1K.h>
 #include <command.h>
 #include <asm/gpio.h>
+#include <linux/byteorder/generic.h>
 #include "fpga.h"
 
 #ifdef FPGA_DEBUG
@@ -209,9 +193,20 @@ int fpga_wr_fn(const void *buf, size_t len, int flush, int cookie)
 {
        unsigned char *data = (unsigned char *) buf;
        int i;
+       int headerlen = len - cyclone2.size;
+
+       if (headerlen < 0)
+               return FPGA_FAIL;
+       else if (headerlen == sizeof(uint32_t)) {
+               const unsigned int fpgavers_len = 11; /* '0x' + 8 hex digits + \0 */
+               char fpgavers_str[fpgavers_len];
+               snprintf(fpgavers_str, fpgavers_len, "0x%08x",
+                               be32_to_cpup((uint32_t*)data));
+               setenv("fpgavers", fpgavers_str);
+       }
 
        fpga_debug("fpga_wr: buf %p / size %d\n", buf, len);
-       for (i = 0; i < len; i++)
+       for (i = headerlen; i < len; i++)
                _write_fpga(data[i]);
        fpga_debug("-%s\n", __func__);