Skip to contentSkip to conversation

aspeed-smc: add support for AST2500 and DMA transfers

PATCH Superseded Cédric Le Goater 2 participants 11 messages Oct 21, 2016

Subsystems (4)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover aspeed-smc: add support for AST2500 and DMA transfers

Hello,

This patchset adds to the current aspeed SMC driver the register settings enabling support for the AST2500. Some initial work is done on the segment registers to provide a better configuration of the mapping windows on the flash modules but this area clearly needs more work to be solid.

Also, a first version of DMA read/write is provided. But the speed results are not very satisfying so they are disabled by default. You

Thanks,

C.

Changes since v1:

- included a first revert of the current driver
- merged all the difference in one patch to be sent to mainline
- added a pinctrl fix for the witherspoon.

Cédric Le Goater (6):
Revert "mtd/spi-nor: Add SPI memory controllers for Aspeed SoCs" mtd/spi-nor: Add SPI memory controllers for Aspeed SoCs
ARM: dts: aspeed-g5: update ast2500 evb with new spi-nor binding
mtd: spi-nor: aspeed: add DMA support to smc controller
ARM: dts: aspeed: update SMC controller nodes supporting DMAs
ARM: dts: witherspoon: use spi1debug pinctrl group

Milton Miller (3):
mtd: spi-nor: Add Micronix mx66l1g45g spi flash
ARM: dts: aspeed-g5: update for new spi-nor binding
ARM: dts: aspeed-g5: update witherspoon for new spi-nor binding

 .../devicetree/bindings/mtd/aspeed-smc.txt         |  37 +-
 arch/arm/boot/dts/aspeed-ast2500-evb.dts           |  28 +-
 arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dts      |   2 +
 arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts   |  31 +-
 arch/arm/boot/dts/aspeed-g5.dtsi                   |  65 ++
 drivers/mtd/spi-nor/aspeed-smc.c                   | 655 +++++++++++++++++----
 drivers/mtd/spi-nor/spi-nor.c                      |   1 +
 7 files changed, 665 insertions(+), 154 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/9 Revert "mtd/spi-nor: Add SPI memory controllers for Aspeed SoCs"

This reverts commit 94a6b4df012964167a502cf2ffb4adfff5d40b2e.

---
 .../devicetree/bindings/mtd/aspeed-smc.txt         |  75 ---
 drivers/mtd/spi-nor/Kconfig                        |  11 -
 drivers/mtd/spi-nor/Makefile                       |   1 -
 drivers/mtd/spi-nor/aspeed-smc.c                   | 567 ---------------------
 4 files changed, 654 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/mtd/aspeed-smc.txt
 delete mode 100644 drivers/mtd/spi-nor/aspeed-smc.c
Documentation/devicetree/bindings/mtd/aspeed-smc.txt deleted +0 -75
deleted file mode 100644
index a91496a6e46e..000000000000
@@ -1,75 +0,0 @@
-* Aspeed Static Memory controller in SPI mode
-* Aspeed SPI Flash Controller
-
-Required properties:
-  - compatible : Should be one of
-	"aspeed,ast2400-fmc" for the AST2400 Static Memory Controller
-	"aspeed,ast2500-fmc" for the AST2500 Static Memory Controller
-	"aspeed,ast2400-smc" for the AST2400 SPI flash controller
-  - reg : the first contains the register location and length,
-          the second through nth contains the memory mapping address and length
-	  for the access window for each chips select
-  - interrupts : Should contain the interrupt for the dma device if fmc
-  - clocks : The APB clock input to the controller
-  - #address-cells : must be 1 corresponding to chip select child binding
-  - #size-cells : must be 0 corresponding to chip select child binding
-
-
-Child node required properties:
-  - reg : must contain chip select number in first cell of address, must
-	  be 1 tuple long
-  - compatible : may contain "vendor,part", must include "jedec,spi-nor"
-		(see spi-nor.txt binding).
-
-Child node optional properties:
-  - label           - (optional) name to assign to mtd, default os assigned
-  - spi-max-frequency - (optional) max frequency of spi bus (XXX max if missing)
-  - spi-cpol        - (optional) Empty property indicating device requires
-    	 		inverse clock polarity (CPOL) mode (boolean)
-  - spi-cpha        - (optional) Empty property indicating device requires
-    			shifted clock phase (CPHA) mode (boolean)
-  - spi-tx-bus-width - (optional) The bus width(number of data wires) that
-                        used for MOSI. Defaults to 1 if not present.
-  - spi-rx-bus-width - (optional) The bus width(number of data wires) that
-                        used for MOSI. Defaults to 1 if not present.
-
-Child node optional properties:
- - see mtd/partiton.txt for partitioning bindings and mtd naming
-
-
-Example:
-
-fmc: fmc@1e620000 {
-	compatible = "aspeed,ast2400-fmc";
-	reg = < 0x1e620000 0x94
-		0x20000000 0x02000000
-		0x22000000 0x02000000 >;
-	#address-cells = <1>;
-	#size-cells = <0>;
-	flash@0 {
-		reg = < 0 >;
-		compatible = "jedec,spi-nor" ;
-		label = "bmc";
-		/* spi-max-frequency = <>; */
-		/* m25p,fast-read; */
-		#address-cells = <1>;
-		#size-cells = <1>;
-		boot@0 {
-			label = "boot-loader";
-			reg = < 0 0x8000 >
-		}
-		image@8000 {
-			label = "kernel-image";
-			reg = < 0x8000 0x1f8000 >
-		}
-	};
-	flash@1 {
-		reg = < 1 >;
-		compatible = "jedec,spi-nor" ;
-		label = "alt";
-		/* spi-max-frequency = <>; */
-		status = "fail";
-		/* m25p,fast-read; */
-	};
-};
-
drivers/mtd/spi-nor/Kconfig +0 -11
index fe336e25f8e2..d42c98e1f581 100644
@@ -49,15 +49,4 @@ config SPI_NXP_SPIFI
 	  Flash. Enable this option if you have a device with a SPIFI
 	  controller and want to access the Flash as a mtd device.
 
-config ASPEED_FLASH_SPI
-	tristate "Aspeed flash controllers in SPI mode"
-	depends on HAS_IOMEM && OF
-	depends on ARCH_ASPEED || COMPILE_TEST
-	# IO_SPACE_LIMIT must be equivalent to (~0UL)
-	depends on !NEED_MACH_IO_H
-	help
-	  This enables support for the New Static Memory Controller (FMC)
-	  in the AST2400 when attached to SPI nor chips, and support for
-	  the SPI Memory controller (SPI) for the BIOS.
-
 endif # MTD_SPI_NOR
drivers/mtd/spi-nor/Makefile +0 -1
index a20dd35877b0..0bf3a7f81675 100644
@@ -1,5 +1,4 @@
 obj-$(CONFIG_MTD_SPI_NOR)	+= spi-nor.o
 obj-$(CONFIG_SPI_FSL_QUADSPI)	+= fsl-quadspi.o
 obj-$(CONFIG_MTD_MT81xx_NOR)    += mtk-quadspi.o
-obj-$(CONFIG_ASPEED_FLASH_SPI)	+= aspeed-smc.o
 obj-$(CONFIG_SPI_NXP_SPIFI)	+= nxp-spifi.o
drivers/mtd/spi-nor/aspeed-smc.c deleted +0 -567

567 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw

PATCH v2 2/9 mtd/spi-nor: Add SPI memory controllers for Aspeed SoCs

In reply to Cédric Le Goater

This driver adds mtd support for spi-nor attached to either or both of the Firmware Memory Controller or the SPI Flash Controller (AST2400 only).

The SMC controllers on the Aspeed AST2500 SoC are very similar to the ones found on the AST2400. The differences are on the number of supported flash modules and their default mappings in the SoC address space.

The Aspeed AST2500 has one SPI controller for the BMC firmware and two for the host firmware. All controllers have now the same set of registers compatible with the AST2400 FMC controller and the legacy 'SMC' controller is fully gone.

Based on previous work from Milton D. Miller II <[email protected]>

---
 .../devicetree/bindings/mtd/aspeed-smc.txt         |  86 +++
 drivers/mtd/spi-nor/Kconfig                        |  11 +
 drivers/mtd/spi-nor/Makefile                       |   1 +
 drivers/mtd/spi-nor/aspeed-smc.c                   | 747 +++++++++++++++++++++
 4 files changed, 845 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mtd/aspeed-smc.txt
 create mode 100644 drivers/mtd/spi-nor/aspeed-smc.c
Documentation/devicetree/bindings/mtd/aspeed-smc.txt new file +86 -0
new file mode 100644
index 000000000000..f6bfa7761205
@@ -0,0 +1,86 @@
+* Aspeed Static Memory controller
+* Aspeed SPI Flash Controller
+
+The Static memory controller in the ast2400 supports 5 chip selects each
+can be attached to NAND, parallel NOR, or SPI NOR attached flash.  The
+Firmware Memory Controller in the ast2500 supports 3 chip selects, two of
+which are always in SPI-NOR mode and the third can be SPI-NOR or parallel
+flash.  The SPI flash controller in the ast2400 supports one of 2 chip
+selects selected by pinmux.  The two SPI flash controllers in the ast2500
+each support two chip selects.
+
+Required properties:
+  - compatible : Should be one of
+	"aspeed,ast2400-fmc" for the AST2400 Static Memory Controller
+	"aspeed,ast2400-smc" for the AST2400 SPI Flash Controller
+	"aspeed,ast2500-fmc" for the AST2500 Firmware SPI Memory Controller
+	"aspeed,ast2500-smc" for the AST2500 SPI Flash Controllers
+  - reg : the first contains the control register location and length,
+          the second contains the memory window mapping address and length
+  - clocks : The APB clock input to the controller
+  - #address-cells : must be 1 corresponding to chip select child binding
+  - #size-cells : must be 0 corresponding to chip select child binding
+
+Optional properties:
+  - aspeed,fmc-has-dma : controller supports DMA transfers
+  - interrupts : Should contain the interrupt for the dma device if an fmc
+
+Child node required properties:
+  - reg : must contain chip select number in first cell of address, must
+	  be 1 tuple long
+  - compatible : may contain "vendor,part", must include "jedec,spi-nor"
+		when attached to SPI flash (see spi-nor.txt binding).
+
+Child node optional properties:
+  - label           - (optional) name to assign to mtd, default os assigned
+
+Child node optional properties for SPI mode (may be ignored):
+  - spi-max-frequency - (optional) max frequency of spi bus
+  - spi-cpol        - (optional) Empty property indicating device requires
+			inverse clock polarity (CPOL) mode (boolean)
+  - spi-cpha        - (optional) Empty property indicating device requires
+			shifted clock phase (CPHA) mode (boolean)
+  - spi-tx-bus-width - (optional) The bus width(number of data wires) that
+                        used for MOSI. Defaults to 1 if not present.
+  - spi-rx-bus-width - (optional) The bus width(number of data wires) that
+                        used for MOSI. Defaults to 1 if not present.
+
+Grandchild node optional properties:
+ - see mtd/partiton.txt for partitioning bindings and mtd naming
+
+
+Example:
+
+fmc: fmc@1e620000 {
+	compatible = "aspeed,ast2400-fmc";
+	reg = < 0x1e620000 0x94
+		0x20000000 0x02000000
+		0x22000000 0x02000000 >;
+	#address-cells = <1>;
+	#size-cells = <0>;
+	flash@0 {
+		reg = < 0 >;
+		compatible = "jedec,spi-nor" ;
+		label = "bmc";
+		/* spi-max-frequency = <>; */
+		/* m25p,fast-read; */
+		#address-cells = <1>;
+		#size-cells = <1>;
+		boot@0 {
+			label = "boot-loader";
+			reg = < 0 0x8000 >
+		}
+		image@8000 {
+			label = "kernel-image";
+			reg = < 0x8000 0x1f8000 >
+		}
+	};
+	flash@1 {
+		reg = < 1 >;
+		compatible = "jedec,spi-nor" ;
+		label = "alt";
+		/* spi-max-frequency = <>; */
+		status = "fail";
+		/* m25p,fast-read; */
+	};
+};
drivers/mtd/spi-nor/Kconfig +11 -0
index d42c98e1f581..fe336e25f8e2 100644
@@ -49,4 +49,15 @@ config SPI_NXP_SPIFI
 	  Flash. Enable this option if you have a device with a SPIFI
 	  controller and want to access the Flash as a mtd device.
 
+config ASPEED_FLASH_SPI
+	tristate "Aspeed flash controllers in SPI mode"
+	depends on HAS_IOMEM && OF
+	depends on ARCH_ASPEED || COMPILE_TEST
+	# IO_SPACE_LIMIT must be equivalent to (~0UL)
+	depends on !NEED_MACH_IO_H
+	help
+	  This enables support for the New Static Memory Controller (FMC)
+	  in the AST2400 when attached to SPI nor chips, and support for
+	  the SPI Memory controller (SPI) for the BIOS.
+
 endif # MTD_SPI_NOR
drivers/mtd/spi-nor/Makefile +1 -0
index 0bf3a7f81675..a20dd35877b0 100644
@@ -1,4 +1,5 @@
 obj-$(CONFIG_MTD_SPI_NOR)	+= spi-nor.o
 obj-$(CONFIG_SPI_FSL_QUADSPI)	+= fsl-quadspi.o
 obj-$(CONFIG_MTD_MT81xx_NOR)    += mtk-quadspi.o
+obj-$(CONFIG_ASPEED_FLASH_SPI)	+= aspeed-smc.o
 obj-$(CONFIG_SPI_NXP_SPIFI)	+= nxp-spifi.o
drivers/mtd/spi-nor/aspeed-smc.c new file +747 -0

747 lines not on this page · raw message

Signature · 1 line
2.7.4
#3 lore raw

PATCH v2 3/9 mtd: spi-nor: Add Micronix mx66l1g45g spi flash

In reply to Cédric Le Goater

From: Milton Miller <[email protected]>

These modules are used on the OpenPOWER Witherspoon systems to hold the POWER9 host firmware image.

---
 drivers/mtd/spi-nor/spi-nor.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mtd/spi-nor/spi-nor.c +1 -0
index a6adb2785b14..a68073afe8a8 100644
@@ -858,6 +858,7 @@ static const struct flash_info spi_nor_ids[] = {
 	{ "mx25l25635e", INFO(0xc22019, 0, 64 * 1024, 512, 0) },
 	{ "mx25l25655e", INFO(0xc22619, 0, 64 * 1024, 512, 0) },
 	{ "mx66l51235l", INFO(0xc2201a, 0, 64 * 1024, 1024, SPI_NOR_QUAD_READ) },
+	{ "mx66l1g45g",  INFO(0xc2201b, 0, 64 * 1024, 2048, SECT_4K | SPI_NOR_QUAD_READ) },
 	{ "mx66l1g55g",  INFO(0xc2261b, 0, 64 * 1024, 2048, SPI_NOR_QUAD_READ) },
 
 	/* Micron */
Signature · 1 line
2.7.4
#4 lore raw

PATCH v2 4/9 ARM: dts: aspeed-g5: update for new spi-nor binding

In reply to Cédric Le Goater

From: Milton Miller <[email protected]>

---
 arch/arm/boot/dts/aspeed-g5.dtsi | 63 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)
arch/arm/boot/dts/aspeed-g5.dtsi +63 -0
index 7e18a8e2c083..d96f09a9eb1a 100644
@@ -24,6 +24,69 @@
 		#size-cells = <1>;
 		ranges;
 
+		fmc: flash-controller@1e620000 {
+			reg = < 0x1e620000 0xc4
+				0x20000000 0x10000000 >;
+			#address-cells = <1>;
+			#size-cells = <0>;
+			compatible = "aspeed,ast2500-fmc";
+			status = "disabled";
+			flash@0 {
+				reg = < 0 >;
+				compatible = "jedec,spi-nor";
+				status = "disabled";
+			};
+			flash@1 {
+				reg = < 1 >;
+				compatible = "jedec,spi-nor";
+				status = "disabled";
+			};
+			flash@2 {
+				reg = < 2 >;
+				compatible = "jedec,spi-nor";
+				// compatible = "cfi,flash", "jedec,flash";
+				status = "disabled";
+			};
+		};
+
+		spi1: flash-controller@1e630000 {
+			reg = < 0x1e630000 0xc4
+				0x30000000 0x08000000 >;
+			#address-cells = <1>;
+			#size-cells = <0>;
+			compatible = "aspeed,ast2500-smc";
+			status = "disabled";
+			flash@0 {
+				reg = < 0 >;
+				compatible = "jedec,spi-nor";
+				status = "disabled";
+			};
+			flash@1 {
+				reg = < 1 >;
+				compatible = "jedec,spi-nor";
+				status = "disabled";
+			};
+		};
+
+		spi2: flash-controller@1e631000 {
+			reg = < 0x1e631000 0xc4
+				0x38000000 0x08000000 >;
+			#address-cells = <1>;
+			#size-cells = <0>;
+			compatible = "aspeed,ast2500-smc";
+			status = "disabled";
+			flash@0 {
+				reg = < 0 >;
+				compatible = "jedec,spi-nor";
+				status = "disabled";
+			};
+			flash@1 {
+				reg = < 1 >;
+				compatible = "jedec,spi-nor";
+				status = "disabled";
+			};
+		};
+
 		vic: interrupt-controller@1e6c0080 {
 			compatible = "aspeed,ast2400-vic";
 			interrupt-controller;
Signature · 1 line
2.7.4
#5 lore raw

PATCH v2 5/9 ARM: dts: aspeed-g5: update witherspoon for new spi-nor binding

In reply to Cédric Le Goater

From: Milton Miller <[email protected]>

Witherspoon has two flash modules for the BMC firmware and one for the host.

---
 arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts | 28 ++++++++++++++----------
 1 file changed, 16 insertions(+), 12 deletions(-)
arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts +16 -12
index fcc880a80ee0..53af584e8f63 100644
@@ -19,20 +19,24 @@
 	memory {
 		reg = <0x80000000 0x40000000>;
 	};
+};
 
-	ahb {
-		bmc_pnor: fmc@1e620000 {
-			reg = < 0x1e620000 0x94
-				0x20000000 0x02000000 >;
-			#address-cells = <1>;
-			#size-cells = <0>;
-			compatible = "aspeed,ast2500-fmc";
-			flash@0 {
-				reg = < 0 >;
-				compatible = "jedec,spi-nor" ;
+&fmc {
+	status = "okay";
+	flash@0 {
+		status = "okay";
 #include "aspeed-bmc-opp-flash-layout.dtsi"
-			};
-		};
+	};
+	flash@1 {
+		status = "okay";
+		label = "alt";
+	};
+};
+
+&spi1 {
+	status = "okay";
+	flash@0 {
+		status = "okay";
 	};
 };
 
Signature · 1 line
2.7.4
#6 lore raw

PATCH v2 6/9 ARM: dts: aspeed-g5: update ast2500 evb with new spi-nor binding

In reply to Cédric Le Goater

The ast2500 evb has one flash module for the BMC firmware and one for the host.

---
 arch/arm/boot/dts/aspeed-ast2500-evb.dts | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)
arch/arm/boot/dts/aspeed-ast2500-evb.dts +16 -12
index d34e6f15a0cb..33b3907c436b 100644
@@ -18,23 +18,27 @@
 	memory {
 		reg = <0x80000000 0x20000000>;
 	};
+};
 
-	ahb {
-		bmc_pnor: fmc@1e620000 {
-			reg = < 0x1e620000 0x94
-				0x20000000 0x02000000 >;
-			#address-cells = <1>;
-			#size-cells = <0>;
-			compatible = "aspeed,ast2500-fmc";
-			flash@0 {
-				reg = < 0 >;
-				compatible = "jedec,spi-nor" ;
+&fmc {
+	status = "okay";
+	flash@0 {
+		status = "okay";
 #include "aspeed-bmc-opp-flash-layout.dtsi"
-			};
-		};
 	};
 };
 
+&spi1 {
+	status = "okay";
+	flash@0 {
+		status = "okay";
+	};
+};
+
+&spi2 {
+	status = "okay";
+};
+
 &uart5 {
 	status = "okay";
 };
Signature · 1 line
2.7.4
#7 lore raw

PATCH v2 7/9 mtd: spi-nor: aspeed: add DMA support to smc controller

In reply to Cédric Le Goater

The Aspeed FMC controller can handle transfers to the flash modules using DMAs. A couple of registers first need to be programmed with the DRAM and flash addresses and the length of the transfer. The transfer is then initiated using a DMA control register and an interrupt notifies the completion.

Such transfers can replace the current IO mode in the read/write ops when some conditions are met on the size and the alignment. In case of failure, a timeout for instance, the operation is restarted using the IO mode.

DMA support does not seem to be that efficient. So we provide some sysfs files for tuning and to switch it on and off (default is off)

---
 drivers/mtd/spi-nor/aspeed-smc.c | 241 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 241 insertions(+)
drivers/mtd/spi-nor/aspeed-smc.c +241 -0
index aed610d8ab2f..f220df775f2b 100644
@@ -20,10 +20,25 @@
 #include <linux/of.h>
 #include <linux/of_platform.h>
 #include <linux/sysfs.h>
+#include <linux/dma-direction.h>
+#include <linux/dma-mapping.h>
 
 #define DEVICE_NAME	"aspeed-smc"
 
 /*
+ * DMAs do not seem to be that fast, so disable by default
+ */
+static bool use_dma;
+module_param(use_dma, bool, 0644);
+
+static unsigned int min_dma_size = 256;
+module_param(min_dma_size, uint, 0644);
+
+/* with 100ms we had a couple of timeouts */
+static unsigned int dma_timeout = 200;
+module_param(dma_timeout, uint, 0644);
+
+/*
  * In user mode all data bytes read or written to the chip decode address
  * range are transferred to or from the SPI bus. The range is treated as a
  * fifo of arbitratry 1, 2, or 4 byte width but each write has to be aligned
@@ -206,6 +221,7 @@ struct aspeed_smc_chip {
 	__le32 __iomem *ctl;			/* control register */
 	void __iomem *base;			/* base of chip window */
 	__le32 ctl_val[smc_num_ctl_reg_values];	/* controls with timing */
+	unsigned long phys_base;
 	enum smc_flash_type type;		/* what type of flash */
 	struct spi_nor nor;
 };
@@ -218,6 +234,18 @@ struct aspeed_smc_controller {
 	void __iomem *regs;			/* controller registers */
 	void __iomem *windows;			/* per-chip windows resource */
 
+	/* interrupt handling */
+	int irq;
+
+	/* dma */
+	bool has_dma;
+	struct completion dma_done;
+
+	/* dma logging */
+	size_t dma_length;
+	dma_addr_t dma_addr;			/* bus address of buffer */
+	dma_addr_t flash_addr;			/* flash address */
+
 	struct aspeed_smc_chip *chips[0];	/* pointers to attached chips */
 };
 
@@ -274,11 +302,123 @@ struct aspeed_smc_controller {
 	CONTROL_SPI_IO_DUMMY_CYCLES_MASK | CONTROL_SPI_CLOCK_FREQ_SEL_MASK | \
 	CONTROL_SPI_LSB_FIRST | CONTROL_SPI_CLOCK_MODE_3)
 
+/* Interrupt Control and Status Register */
+#define INTERRUPT_STATUS_REG		0x08
+#define     INTERRUPT_DMA_ENABLE	    BIT(3)
+#define     INTERRUPT_DMA_STATUS	    BIT(11)
+
 /* Segment Address Registers */
 #define SEGMENT_ADDR_REG0		0x30
 #define     SEGMENT_ADDR_START(_r)	    ((((_r) >> 16) & 0xFF) << 23)
 #define     SEGMENT_ADDR_END(_r)	    ((((_r) >> 24) & 0xFF) << 23)
 
+
+/* DMA Registers */
+#define DMA_CONTROL_REG			0x80
+#define     DMA_ENABLE			    BIT(0)
+#define     DMA_WRITE			    BIT(1)
+
+#define DMA_FLASH_BASE_REG		0x84
+#define DMA_DRAM_BASE_REG		0x88
+#define DMA_LENGTH_REG			0x8c
+
+static void aspeed_smc_dma_done(struct aspeed_smc_controller *controller)
+{
+	writel(0, controller->regs + INTERRUPT_STATUS_REG);
+	writel(0, controller->regs + DMA_CONTROL_REG);
+}
+
+static int aspeed_smc_dma_wait(struct aspeed_smc_chip *chip)
+{
+	struct aspeed_smc_controller *controller = chip->controller;
+
+	if (!wait_for_completion_timeout(&controller->dma_done,
+					 msecs_to_jiffies(dma_timeout))) {
+		dev_err(chip->nor.dev, "timeout waiting for DMA interrupt "
+			"addr@%.8x faddr@%.8x size=%x "
+			"dram@%.8x flash@%.8x done=%x\n",
+			controller->dma_addr,
+			controller->flash_addr,
+			controller->dma_length,
+			readl(controller->regs + DMA_DRAM_BASE_REG),
+			readl(controller->regs + DMA_FLASH_BASE_REG),
+			readl(controller->regs + DMA_LENGTH_REG));
+		return -ETIMEDOUT;
+	}
+
+	return 0;
+}
+
+#define DMA_LENGTH(x) (((x) - 4) & ~0xFE000003)
+#define DMA_ADDR(x) ((x) & ~0xE0000003)
+
+static inline void aspeed_smc_chip_configure(struct aspeed_smc_chip *chip,
+					     u32 ctl)
+{
+	ctl |= CONTROL_SPI_CE_STOP_ACTIVE_CONTROL;
+	writel(ctl, chip->ctl);
+
+	ctl &= ~CONTROL_SPI_CE_STOP_ACTIVE_CONTROL;
+	writel(ctl, chip->ctl);
+}
+
+/*
+ * TODO: configure FREAD mode
+ */
+static int aspeed_smc_dma_start(struct aspeed_smc_chip *chip,
+				u32 offset, void *buf, size_t length,
+				int is_write)
+{
+	struct aspeed_smc_controller *controller = chip->controller;
+	dma_addr_t dma_addr, flash_addr;
+	int ret;
+
+	aspeed_smc_chip_configure(chip, is_write ? chip->ctl_val[smc_write] :
+		chip->ctl_val[smc_base]);
+
+	dev_dbg(chip->nor.dev, "DMA %s to=0x%08x len=0x%08x\n",
+		is_write ? "write" : "read", offset, length);
+
+	dma_addr = dma_map_single(chip->nor.dev, buf, length,
+				  (is_write ? DMA_TO_DEVICE : DMA_FROM_DEVICE));
+
+	if (unlikely(dma_mapping_error(chip->nor.dev, dma_addr))) {
+		dev_err(chip->nor.dev, "Failed to dma_map_single()\n");
+		ret = -ENOMEM;
+		goto out;
+	}
+	flash_addr = chip->phys_base + offset;
+
+	controller->dma_length = length;
+	controller->dma_addr = dma_addr;
+	controller->flash_addr = flash_addr;
+
+	reinit_completion(&controller->dma_done);
+
+	writel(0, controller->regs + DMA_CONTROL_REG);
+	writel(DMA_ADDR(flash_addr), controller->regs +
+	       DMA_FLASH_BASE_REG);
+	writel(DMA_ADDR(dma_addr), controller->regs + DMA_DRAM_BASE_REG);
+	writel(DMA_LENGTH(length), controller->regs + DMA_LENGTH_REG);
+
+	writel(INTERRUPT_DMA_ENABLE,
+	       controller->regs + INTERRUPT_STATUS_REG);
+
+	writel(DMA_ENABLE | (is_write << 1),
+	       controller->regs + DMA_CONTROL_REG);
+
+	ret = aspeed_smc_dma_wait(chip);
+	if (ret)
+		aspeed_smc_dma_done(controller);
+
+	dma_unmap_single(chip->nor.dev,
+			 controller->dma_addr, controller->dma_length,
+			 (is_write ? DMA_TO_DEVICE : DMA_FROM_DEVICE));
+out:
+	aspeed_smc_chip_configure(chip, chip->ctl_val[smc_base]);
+	return ret;
+}
+
 static u32 spi_control_fill_opcode(u8 opcode)
 {
 	return ((u32)(opcode)) << CONTROL_SPI_COMMAND_SHIFT;
@@ -400,14 +540,28 @@ static int aspeed_smc_read_user(struct spi_nor *nor, loff_t from, size_t len,
 				size_t *retlen, u_char *read_buf)
 {
 	struct aspeed_smc_chip *chip = nor->priv;
+	int ret;
 
 	mutex_lock(&chip->controller->mutex);
 
+	/*
+	 * Try DMA transfer when size and alignment are correct. In case
+	 * of failure, just restart using the IO mode.
+	 */
+	if (!(from & 0x3) && !(len & 0x3) && (len >= min_dma_size) &&
+	    chip->controller->has_dma && use_dma) {
+		ret = aspeed_smc_dma_start(chip, from, read_buf, len, 0);
+		if (!ret)
+			goto out;
+		dev_err(chip->nor.dev, "DMA read failed: %d", ret);
+	}
+
 	aspeed_smc_start_user(nor);
 	aspeed_smc_send_cmd_addr(nor, nor->read_opcode, from);
 	aspeed_smc_from_fifo(read_buf, chip->base, len);
 	aspeed_smc_stop_user(nor);
 
+out:
 	mutex_unlock(&chip->controller->mutex);
 
 	*retlen += len;
@@ -418,19 +572,102 @@ static void aspeed_smc_write_user(struct spi_nor *nor, loff_t to, size_t len,
 				  size_t *retlen, const u_char *write_buf)
 {
 	struct aspeed_smc_chip *chip = nor->priv;
+	int ret;
 
 	mutex_lock(&chip->controller->mutex);
 
+	/*
+	 * Try DMA transfer when size and alignment are correct. In case
+	 * of failure, just restart using the IO mode.
+	 */
+	if (!(to & 0x3) && !(len & 0x3) && (len >= min_dma_size) &&
+	    chip->controller->has_dma && use_dma) {
+		ret = aspeed_smc_dma_start(chip, to, (void *)write_buf,
+					   len, 1);
+		if (!ret)
+			goto out;
+		dev_err(chip->nor.dev, "DMA write failed: %d", ret);
+	}
+
 	aspeed_smc_start_user(nor);
 	aspeed_smc_send_cmd_addr(nor, nor->program_opcode, to);
 	aspeed_smc_to_fifo(chip->base, write_buf, len);
 	aspeed_smc_stop_user(nor);
 
+out:
 	mutex_unlock(&chip->controller->mutex);
 
 	*retlen += len;
 }
 
+static irqreturn_t aspeed_smc_irq(int irq, void *arg)
+{
+	struct aspeed_smc_controller *controller = arg;
+	struct device *dev = controller->dev;
+	irqreturn_t ret = IRQ_NONE;
+	u32 dma_ctl = readl(controller->regs + DMA_CONTROL_REG);
+	u32 status = readl(controller->regs + INTERRUPT_STATUS_REG);
+
+	dev_dbg(dev, "received IRQ. status: %x", status);
+
+	if (!(status & INTERRUPT_DMA_ENABLE) || !(dma_ctl & DMA_ENABLE)) {
+		dev_err(dev, "No DMA. bad IRQ status: %x", status);
+		goto out;
+	}
+
+	if (!(status & INTERRUPT_DMA_STATUS)) {
+		dev_err(dev, "DMA still in progress. length %d\n",
+			readl(controller->regs + DMA_LENGTH_REG));
+		goto out;
+	}
+
+	ret = IRQ_HANDLED;
+	aspeed_smc_dma_done(controller);
+	complete(&controller->dma_done);
+
+out:
+	return ret;
+}
+
+static int aspeed_smc_config_irq(struct aspeed_smc_controller *controller,
+				 struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	int rc;
+
+	controller->irq = platform_get_irq(pdev, 0);
+	if (!controller->irq)
+		return -ENODEV;
+
+	rc = devm_request_irq(dev, controller->irq, aspeed_smc_irq, IRQF_SHARED,
+			      DEVICE_NAME, controller);
+	if (rc < 0) {
+		dev_warn(dev, "Unable to request IRQ %d\n", controller->irq);
+		controller->irq = 0;
+		return rc;
+	}
+
+	dev_info(dev, "Using IRQ %d\n", controller->irq);
+	return 0;
+}
+
+static void aspeed_smc_dma_setup(struct aspeed_smc_controller *controller,
+				 struct platform_device *pdev)
+{
+	init_completion(&controller->dma_done);
+
+	controller->has_dma = false;
+	if (of_get_property(controller->dev->of_node, "aspeed,fmc-has-dma",
+			    NULL))
+		controller->has_dma = !aspeed_smc_config_irq(controller, pdev);
+
+	if (controller->has_dma)
+		dev_info(controller->dev, "DMA support %sactivated.\n",
+			 use_dma ? "" : "de");
+	else
+		dev_info(controller->dev, "no DMA support.\n");
+}
+
 static int aspeed_smc_remove(struct platform_device *dev)
 {
 	struct aspeed_smc_chip *chip;
@@ -540,6 +777,8 @@ static int aspeed_smc_chip_setup_init(struct aspeed_smc_chip *chip,
 		return -1;
 	}
 
+	chip->phys_base = r->start;
+
 	/*
 	 * Read the existing control register to get basic values.
 	 *
@@ -647,6 +886,8 @@ static int aspeed_smc_probe(struct platform_device *pdev)
 
 	controller->dev = &pdev->dev;
 
+	aspeed_smc_dma_setup(controller, pdev);
+
 	/* The pinmux or bootloader will disable the legacy mode controller */
 
 	/*
Signature · 1 line
2.7.4
#8 lore raw

PATCH v2 8/9 ARM: dts: aspeed: update SMC controller nodes supporting DMAs

In reply to Cédric Le Goater
---
 arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dts | 2 ++
 arch/arm/boot/dts/aspeed-g5.dtsi              | 2 ++
 2 files changed, 4 insertions(+)
arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dts +2 -0
index 5c689613e5bd..a6ebab1bfe2b 100644
@@ -43,6 +43,8 @@
 			#address-cells = <1>;
 			#size-cells = <0>;
 			compatible = "aspeed,ast2400-fmc";
+			aspeed,fmc-has-dma;
+			interrupts = <19>;
 			flash@0 {
 				reg = < 0 >;
 				compatible = "jedec,spi-nor" ;
arch/arm/boot/dts/aspeed-g5.dtsi +2 -0
index d96f09a9eb1a..d72aea7ab8f2 100644
@@ -31,6 +31,8 @@
 			#size-cells = <0>;
 			compatible = "aspeed,ast2500-fmc";
 			status = "disabled";
+			aspeed,fmc-has-dma;
+			interrupts = <19>;
 			flash@0 {
 				reg = < 0 >;
 				compatible = "jedec,spi-nor";
Signature · 1 line
2.7.4
#9 lore raw

PATCH v2 9/9 ARM: dts: witherspoon: use spi1debug pinctrl group

In reply to Cédric Le Goater

pinctrl is very strict and the device tree should match exactly how the HW is strapped.

---
 arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts | 3 +++
 1 file changed, 3 insertions(+)
arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts +3 -0
index 53af584e8f63..db3afafbfe9e 100644
@@ -35,6 +35,9 @@
 
 &spi1 {
 	status = "okay";
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_spi1debug_default>;
+
 	flash@0 {
 		status = "okay";
 	};
Signature · 1 line
2.7.4
maintainer
#10 lore raw
In reply to Cédric Le Goater
Quoted 13 lines · Cédric Le Goater

Hello,

This patchset adds to the current aspeed SMC driver the register settings enabling support for the AST2500. Some initial work is done on the segment registers to provide a better configuration of the mapping windows on the flash modules but this area clearly needs more work to be solid.

Also, a first version of DMA read/write is provided. But the speed results are not very satisfying so they are disabled by default. You

Thanks,

Quoted 7 lines

C.

Changes since v1:

- included a first revert of the current driver
- merged all the difference in one patch to be sent to mainline
- added a pinctrl fix for the witherspoon.

Series applied to dev-4.7 as of d676d5ee0e1b3b5e774c2d61d2c9a760f5df78b0.

Cheers,

Joel

Quoted 26 lines

Cédric Le Goater (6):
Revert "mtd/spi-nor: Add SPI memory controllers for Aspeed SoCs" mtd/spi-nor: Add SPI memory controllers for Aspeed SoCs
ARM: dts: aspeed-g5: update ast2500 evb with new spi-nor binding
mtd: spi-nor: aspeed: add DMA support to smc controller
ARM: dts: aspeed: update SMC controller nodes supporting DMAs
ARM: dts: witherspoon: use spi1debug pinctrl group

Milton Miller (3):
mtd: spi-nor: Add Micronix mx66l1g45g spi flash
ARM: dts: aspeed-g5: update for new spi-nor binding
ARM: dts: aspeed-g5: update witherspoon for new spi-nor binding

 .../devicetree/bindings/mtd/aspeed-smc.txt         |  37 +-
 arch/arm/boot/dts/aspeed-ast2500-evb.dts           |  28 +-
 arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dts      |   2 +
 arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts   |  31 +-
 arch/arm/boot/dts/aspeed-g5.dtsi                   |  65 ++
 drivers/mtd/spi-nor/aspeed-smc.c                   | 655 +++++++++++++++++----
 drivers/mtd/spi-nor/spi-nor.c                      |   1 +
 7 files changed, 665 insertions(+), 154 deletions(-)

--
2.7.4