Skip to contentSkip to conversation

spi: Add Lattice ECP3 FPGA configuration via SPI

PATCH Superseded Stefan Roese 3 participants 3 messages Nov 26, 2012 1 message not in the archive SPI

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 spi: Add Lattice ECP3 FPGA configuration via SPI

This patch adds support for bitstream configuration (programming / loading) of the Lattice ECP3 FPGA's via the SPI bus.

Here an example on my custom MPC5200 based board:

$ echo 1 > /sys/class/firmware/spi0.0/loading
$ cat fpga_a4m2k.bit > /sys/class/firmware/spi0.0/data
$ echo 0 > /sys/class/firmware/spi0.0/loading

leads to these messages:

lattice-ecp3 spi0.0: FPGA Lattice ECP3-35 detected lattice-ecp3 spi0.0: Configuring the FPGA... lattice-ecp3 spi0.0: FPGA succesfully configured!

Cc Ming Lei <[email protected]>
Cc Grant Likely <grant.likely-s3s/[email protected]>

---
v2:
- Moved from drivers/firmware to drivers/spi as suggested by Ming Lei
- Removed pseudo device
- Removed static buffer pointer usage

 drivers/spi/Kconfig                   |  11 ++
 drivers/spi/Makefile                  |   1 +
 drivers/spi/spi-lattice-ecp3-config.c | 229 ++++++++++++++++++++++++++++++++++
 3 files changed, 241 insertions(+)
 create mode 100644 drivers/spi/spi-lattice-ecp3-config.c
drivers/spi/Kconfig +11 -0
index 1acae35..e7b108773 100644
@@ -461,6 +461,17 @@ config SPI_DW_MMIO
 #
 comment "SPI Protocol Masters"
 
+config SPI_LATTICE_ECP3_CONFIG
+	tristate "Lattice ECP3 FPGA bitstream configuration via SPI"
+	depends on SYSFS
+	select FW_LOADER
+	default	n
+	help
+	  This option enables support for bitstream configuration (programming
+	  or loading) of the Lattice ECP3 FPGA family via SPI.
+
+	  If unsure, say N.
+
 config SPI_SPIDEV
 	tristate "User mode SPI device driver support"
 	depends on EXPERIMENTAL
drivers/spi/Makefile +1 -0
index c48df47..9a532c0 100644
@@ -32,6 +32,7 @@ obj-$(CONFIG_SPI_FSL_ESPI)		+= spi-fsl-espi.o
 obj-$(CONFIG_SPI_FSL_SPI)		+= spi-fsl-spi.o
 obj-$(CONFIG_SPI_GPIO)			+= spi-gpio.o
 obj-$(CONFIG_SPI_IMX)			+= spi-imx.o
+obj-$(CONFIG_SPI_LATTICE_ECP3_CONFIG)	+= spi-lattice-ecp3-config.o
 obj-$(CONFIG_SPI_LM70_LLP)		+= spi-lm70llp.o
 obj-$(CONFIG_SPI_MPC512x_PSC)		+= spi-mpc512x-psc.o
 obj-$(CONFIG_SPI_MPC52xx_PSC)		+= spi-mpc52xx-psc.o
drivers/spi/spi-lattice-ecp3-config.c new file +229 -0

229 lines not on this page · raw message

Signature · 9 lines
1.8.0


------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

drivers/spi/spi-lattice-ecp3-config.c line 191

Quoted 11 lines · Stefan Roese
drivers/spi/spi-lattice-ecp3-config.c new file +11 -0
+
+static int __devinit lattice_ecp3_probe(struct spi_device *spi)
+{
+       int err;
+
+       err = request_firmware_nowait(THIS_MODULE, FW_ACTION_NOHOTPLUG,
+                                     FIRMWARE_NAME, &spi->dev,
+                                     GFP_KERNEL, spi, firmware_load);
+       if (err) {
+               dev_err(&spi->dev, "Firmware loading failed with %d!\n", err);
+               goto err;

nitpick:
the goto looks un-necessary, could we return err here and save an un-necessary branch.

drivers/spi/spi-lattice-ecp3-config.c line 201

Quoted 10 lines
drivers/spi/spi-lattice-ecp3-config.c new file +10 -0
+       }
+
+       dev_info(&spi->dev, "FPGA bitstream configuration driver registered (ver %s)\n",
+               DRIVER_VER);
+
+       return 0;
+
+err:
+       return err;
+}

------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single web console. Get in-depth insight into apps, servers, databases, vmware, SAP, cloud infrastructure, etc. Download 30-day Free Trial. Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov

#3 lore raw
In reply to a message not in the archive

drivers/spi/spi-lattice-ecp3-config.c line 206

Quoted 5 lines · Stefan Roese
drivers/spi/spi-lattice-ecp3-config.c new file +5 -0
+
+static int __devexit lattice_ecp3_remove(struct spi_device *spi)
+{
+       return 0;
+}

Since you call request_firmware_nowait() inside probe(), it is better to wait for its completion inside remove().

Thanks,
--
Ming Lei

------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single web console. Get in-depth insight into apps, servers, databases, vmware, SAP, cloud infrastructure, etc. Download 30-day Free Trial. Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov