From 500b0887632165f77f2604b07df746b4a3a16d2c Mon Sep 17 00:00:00 2001
From: Hugo Villeneuve <hugo@hugovil.com>
Date: Fri, 6 Mar 2009 10:23:44 -0500
Subject: [PATCH 10/12] Add generic FPGA bitstream loader driver
This driver is a generic interface for programming a
bitstream into a FPGA. It can work with serial or
parallel programming interfaces and support multiple
devices and partial reconfiguration. Currently Xilinx
XC3S and XC4V FPGAs are implemented, but other
manufacturers like Altera could be easily added.
Signed-off-by: Hugo Villeneuve <hugo@hugovil.com>
---
drivers/misc/Kconfig | 31 ++
drivers/misc/Makefile | 3 +
drivers/misc/fpgadl.c | 806 +++++++++++++++++++++++++++++++++++++++++++++
drivers/misc/fpgadl_par.c | 258 +++++++++++++++
drivers/misc/fpgadl_ser.c | 244 ++++++++++++++
include/linux/fpgadl.h | 96 ++++++
6 files changed, 1438 insertions(+), 0 deletions(-)
create mode 100644 drivers/misc/fpgadl.c
create mode 100644 drivers/misc/fpgadl_par.c
create mode 100644 drivers/misc/fpgadl_ser.c
create mode 100644 include/linux/fpgadl.h
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index a11e2a0..bdc0517 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -510,6 +510,37 @@ config SGI_GRU_DEBUG
This option enables addition debugging code for the SGI GRU driver. If
you are unsure, say N.
+config FPGADL
+ tristate "FPGA bitstream loader support"
+ help
+ This option enables support for the FPGA bitstream loader.
+
+ To compile this driver as a module, choose M here: the
+ module will be called fpgadl.
+
+ If unsure, say N.
+
+config FPGADL_SER
+ tristate "FPGA serial programming driver"
+ depends on SPI_MASTER && FPGADL
+ help
+ Say Y here if your FPGA bitstream is loaded using a serial
+ interface (SPI).
+
+ To compile this driver as a module, choose M here: the
+ module will be called fpgadl_ser.
+
+config FPGADL_PAR
+ tristate "FPGA parallel programming driver"
+ depends on FPGADL
+ select BITREVERSE
+ help
+ Say Y here if your FPGA bitstream is loaded using a parallel
+ interface.
+
+ To compile this driver as a module, choose M here: the
+ module will be called fpgadl_par.
+
source "drivers/misc/c2port/Kconfig"
endif # MISC_DEVICES
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 78be134..4fb6dfc 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -32,5 +32,8 @@ obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o
obj-$(CONFIG_KGDB_TESTS) += kgdbts.o
obj-$(CONFIG_SGI_XP) += sgi-xp/
obj-$(CONFIG_SGI_GRU) += sgi-gru/
+obj-$(CONFIG_FPGADL) += fpgadl.o
+obj-$(CONFIG_FPGADL_SER) += fpgadl_ser.o
+obj-$(CONFIG_FPGADL_PAR) += fpgadl_par.o
obj-$(CONFIG_HP_ILO) += hpilo.o
obj-$(CONFIG_C2PORT) += c2port/
diff --git a/drivers/misc/fpgadl.c b/drivers/misc/fpgadl.c
new file mode 100644
index 0000000..2f03d9b
--- /dev/null
+++ b/drivers/misc/fpgadl.c
@@ -0,0 +1,806 @@
+/*
+ * fpgadl core driver
+ *
+ * Copyright (C) 2008 Lyrtech <www.lyrtech.com>
+ *
+ * Based on code found in book "Linux Device Drivers" by
+ * Alessandro Rubini and Jonathan Corbet, published by O'Reilly & Associates.
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/miscdevice.h>
+#include <linux/string.h>
+#include <linux/err.h>
+#include <linux/fs.h>
+#include <linux/firmware.h>
+#include <linux/delay.h>
+#include <linux/fpgadl.h>
+
+#include <asm/gpio.h>
+#include <asm/uaccess.h>
+
+#define MODULE_NAME "fpgadl"
+
+/* Define this to enable verbose debug messages */
+#define FPGADL_DEBUG 1
+
+static const char fpgadl_driver_version[] = "v1.0";
+
+/* Module parameters */
+static unsigned int fpgadl_debug;
+EXPORT_SYMBOL_GPL(fpgadl_debug);
+module_param_named(debug, fpgadl_debug, int, 0644);
+
+#ifdef FPGADL_DEBUG
+#define INFOMSG(fmt, args...) \
+ do { \
+ printk(KERN_INFO "%s: "fmt"\n", MODULE_NAME, ## args); \
+ } while (0)
+#define DBGMSG(fmt, args...) \
+ do { \
+ if (fpgadl_debug > 0) \
+ printk(KERN_DEBUG "%s: "fmt"\n", \
+ MODULE_NAME, ## args); \
+ } while (0)
+#define DBGMSG_ENTER() \
|