Skip to contentSkip to conversation

mtd: add driver for the flash in Lattice machxo2 FPGAs

PATCH New Martin Fuzzey 1 participant 1 message Jul 29, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mtd: add driver for the flash in Lattice machxo2 FPGAs

This driver provides two MTD devices, one for the configuration data (FPGA bitstream) and another for the general purpose user flash.

Both behave as normal MTD devices bit the configuration one has some extra sysfs entries to synchronize updating.

---

V2: Address review comments from Varka Bhadram

---
 .../bindings/mtd/lattice-machxo2-fpga.txt          |   32 +
 Documentation/mtd/machxo2-fpga.txt                 |  104 ++
 drivers/mtd/devices/Kconfig                        |   31 +
 drivers/mtd/devices/Makefile                       |    3 
 drivers/mtd/devices/machxo2-core.c                 |  928 ++++++++++++++++++++
 drivers/mtd/devices/machxo2-spi.c                  |   96 ++
 drivers/mtd/devices/machxo2.h                      |   23 
 7 files changed, 1216 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/mtd/lattice-machxo2-fpga.txt
 create mode 100644 Documentation/mtd/machxo2-fpga.txt
 create mode 100644 drivers/mtd/devices/machxo2-core.c
 create mode 100644 drivers/mtd/devices/machxo2-spi.c
 create mode 100644 drivers/mtd/devices/machxo2.h
Documentation/devicetree/bindings/mtd/lattice-machxo2-fpga.txt new file +32 -0
new file mode 100644
index 0000000..2fd30fa
@@ -0,0 +1,32 @@
+MTD SPI driver for the configuration (bitstream) and user flash of the Lattice
+Machxo2 family FPGAs.
+
+Required properties:
+- compatible : lattice,machxo2
+
+The two flash regions of the device are represented by the child nodes:
+	"configflash" : for the configuration data (FPGA bitstream)
+	"userflash" :	for the general purpose flash memory
+
+Both of these child nodes are optional (if the child node is missing no
+mtd device will be created)
+
+Each of these child nodes have the same optional properties:
+- linux,mtd-name : name of mtd to create
+
+
+Example:
+&ecspi2 {
+	mainboard-fpga@2 {
+		compatible = "lattice,machxo2";
+		spi-max-frequency = <25000000>;
+		reg = <2>;
+		configflash {
+			linux,mtd-name = "mainboard-fpga-bitstream";
+		};
+		userflash {
+			linux,mtd-name = "mainboard-fpga-userflash";
+		};
+	};
+};
+
Documentation/mtd/machxo2-fpga.txt new file +104 -0

104 lines not on this page · raw message

drivers/mtd/devices/Kconfig +31 -0
index c49d0b1..7ecd457 100644
@@ -120,6 +120,37 @@ config MTD_BCM47XXSFLASH
 	  registered by bcma as platform devices. This enables driver for
 	  serial flash memories (only read-only mode is implemented).
 
+config MTD_MACHXO2_CORE
+	tristate "Lattice MACHXO2 family FPGAs"
+	depends on SPI_MASTER
+	help
+	  This provides access to the configuration ( bitstream) and
+	  general purpose flash memories of the Lattice MACHXO2 family FPGAs
+	  See Documenation/mtd/machxo2-fpga for usage information
+
+	  You should also select a bus interface below (currently only
+	  SPI is implemented but the hardware supports I2C too)
+
+config MTD_MACHXO2_CONFIGFLASH
+	boolean "Allow access to MACHXO2 configuration flash"
+	depends on MTD_MACHXO2_CORE
+	help
+	  If selected the configuration flash (bitstream) in the FPGA
+	  will be exposed as a linux MTD device.
+
+config MTD_MACHXO2_USERFLASH
+	boolean "Allow access to MACHXO2 user flash"
+	depends on MTD_MACHXO2_CORE
+	help
+	  If selected the general purpose user flash in the FPGA will
+	  be exposed as a linux MTD device.
+
+config MTD_MACHXO2_SPI
+	tristate "Lattice MACHXO2 family FPGAs using SPI bus interface"
+	depends on MTD_MACHXO2_CORE && SPI_MASTER
+	help
+	  Select this if your MAXCHXO2 FPGA is connected via a SPI bus.
+
 config MTD_SLRAM
 	tristate "Uncached system RAM"
 	help
drivers/mtd/devices/Makefile +2 -1
index c68868f..f39df4a 100644
@@ -17,6 +17,7 @@ obj-$(CONFIG_MTD_SPEAR_SMI)	+= spear_smi.o
 obj-$(CONFIG_MTD_SST25L)	+= sst25l.o
 obj-$(CONFIG_MTD_BCM47XXSFLASH)	+= bcm47xxsflash.o
 obj-$(CONFIG_MTD_ST_SPI_FSM)    += st_spi_fsm.o
-
+obj-$(CONFIG_MTD_MACHXO2_CORE)	+= machxo2-core.o
+obj-$(CONFIG_MTD_MACHXO2_SPI)	+= machxo2-spi.o
 
 CFLAGS_docg3.o			+= -I$(src)
drivers/mtd/devices/machxo2-core.c new file +928 -0

928 lines not on this page · raw message

drivers/mtd/devices/machxo2-spi.c new file +96 -0

96 lines not on this page · raw message

drivers/mtd/devices/machxo2.h new file +23 -0
new file mode 100644
index 0000000..6823d6c1
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2014 Parkeon
+ * Martin Fuzzey <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License version 2 as published by the
+ * Free Software Foundation.
+ */
+#ifndef __DRIVERS_MTD_MACHXO2_H
+#define __DRIVERS_MTD_MACHXO2_H
+
+struct machxo2;
+struct machxo2_busops {
+	int (*transceive)(struct device *dev,
+		const void *send_buf, unsigned send_len,
+		void *recv_buf, unsigned recv_len);
+};
+
+struct machxo2 *machxo2_create(struct device *dev,
+		struct machxo2_busops *busops);
+
+void machxo2_destroy(struct machxo2 *machxo2);
+#endif /* __DRIVERS_MTD_MACHXO2_H */