Skip to contentSkip to conversation

sf: Add support for accessing dual parallel memories

PATCH New Jagannadha Sutradharudu Teki 1 participant 5 messages Jul 29, 2013 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#1 lore raw

PATCH 1/5 sf: Add support for accessing dual parallel memories

In reply to a message not in the archive

This patch added support for accessing dual memories in parallel connections with single chipselect line from controller. this connection mode is implemented in xilinx zynq qspi controller.

For more info, see doc/README.spi-flash-conn-modes

Below are the changes for dual parallel to work:
- mtd layer -> addr/2, page_size*2, sector_size*2
- driver -> enable SEP_BUS[BIT:29],TWO_MEM[BIT:30] on LQSPI_CFG reg.

---
 doc/README.spi-flash-conn-modes | 68 +++++++++++++++++++++++++++++++++++++++++
 drivers/mtd/spi/spi_flash.c     | 52 ++++++++++++++++++++++---------
 include/spi.h                   |  2 ++
 include/spi_flash.h             |  7 +++++
 4 files changed, 114 insertions(+), 15 deletions(-)
 create mode 100644 doc/README.spi-flash-conn-modes
doc/README.spi-flash-conn-modes new file +68 -0
new file mode 100644
index 0000000..f0c94b7
@@ -0,0 +1,68 @@
+#
+# (C) Copyright 2013 Xilinx, Inc.
+#
+#  SPDX-License-Identifier:      GPL-2.0+
+
+SPI/QSPI flash connection modes:
+================================
+
+This describes how SPI/QSPI flash memories are connected to a given
+controller in a single chipselect line.
+
+Current spi_flash framework supports, single flash memory connected
+to a given controller with single chipselect line, but there are some
+hw logics(ex: xilinx zynq qspi) that describes two/dual memories are
+connected with a single chipselect line from a controller.
+
+"is_dual" from include/spi.h decribes these types of connection modes.
+
+Possible connections:
+--------------------
+SPI_FLASH_CONN_UNKNOWN:
+SPI_FLASH_CONN_SINGLE:
+	- single spi flash memory connected with single chip select line.
+
+  +-------------+           CS		+---------------+
+  |		|---------------------->|		|
+  | Controller	|        I0[3:0]	| Flash memory	|
+  | SPI/QSPI	|<=====================>| (SPI/QSPI)	|
+  |		|	   CLK		|		|
+  |		|---------------------->|		|
+  +-------------+			+---------------+
+
+SPI_FLASH_CONN_DUALPARALLEL:
+	- dual spi/qspi flash memories are connected with a single chipselect
+	  line and these two memories are operating parallel with separate buses.
+	- xilinx zynq qspi controller has implemented this feature.
+	  see trm for more info
+	  http://www.xilinx.com/support/documentation/user_guides/ug585-Zynq-7000-TRM.pdf
+
+  +-------------+           CS		+---------------+
+  |		|---------------------->|		|
+  | 		|        I0[3:0]	| Upper Flash	|
+  | 		|<=====================>| memory	|
+  |		|	   CLK		| (SPI/QSPI)	|
+  |		|---------------------->|		|
+  | Controller	|	    CS		+---------------+
+  | SPI/QSPI	|---------------------->|		|
+  | 		|        I0[3:0]	| Lower Flash	|
+  | 		|<=====================>| memory	|
+  |		|	   CLK		| (SPI/QSPI)	|
+  |		|---------------------->|		|
+  +-------------+			+---------------+
+
+	- two memory flash devices should has same hw part attributes (like size,
+	  vendor..etc)
+	- Configurations:
+		Need to enable SEP_BUS[BIT:29],TWO_MEM[BIT:30] on LQSPI_CFG register.
+	- Operation:
+		Even bits, i.e. bit 0, 2, 4 ., of a data word is located in the lower memory
+		and odd bits, i.e. bit 1, 3, 5, ., of a data word is located in the upper memory.
+
+Note: Technically there is only one CS line from the controller, but
+zynq qspi controller has an internal hw logic to enable additional CS
+when controller is configured for dual memories.
+
+--
+Jagannadha Sutradharudu Teki <[email protected]>
+29-07-2013.
drivers/mtd/spi/spi_flash.c +37 -15

141 lines not on this page · raw message

include/spi.h +2 -0
index c0dab57..bb242bd 100644
@@ -40,11 +40,13 @@
  *   cs:	ID of the chip select connected to the slave.
  *   max_write_size:	If non-zero, the maximum number of bytes which can
  *		be written at once, excluding command bytes.
+ *   is_dual:	Indicates whether dual memories are used.
  */
 struct spi_slave {
 	unsigned int	bus;
 	unsigned int	cs;
 	unsigned int max_write_size;
+	int	is_dual;
 };
 
 /*-----------------------------------------------------------------------
include/spi_flash.h +7 -0
index bfc59aa..fb132ab 100644
@@ -17,6 +17,13 @@
 #include <linux/types.h>
 #include <linux/compiler.h>
 
+/* SPI connection modes */
+enum spi_conn_modes {
+	SPI_FLASH_CONN_UNKNOWN = -1,
+	SPI_FLASH_CONN_SINGLE,
+	SPI_FLASH_CONN_DUALPARALLEL,
+};
+
 struct spi_flash {
 	struct spi_slave *spi;
 
Signature · 1 line
1.8.3
#2 lore raw

PATCH 2/5 sf: spansion|stmicro: Enable dual parallel access

In reply to a message not in the archive

Dual parallel accessing can be done by updating flash part attributes like page_size*2, sector_size*2

---
 drivers/mtd/spi/spansion.c | 6 ++++++
 drivers/mtd/spi/stmicro.c  | 6 ++++++
 2 files changed, 12 insertions(+)
drivers/mtd/spi/spansion.c +6 -0
index 47a4897..a4ea16b 100644
@@ -134,6 +134,12 @@ struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode)
 
 	flash->page_size = 256;
 	flash->sector_size = 256 * params->pages_per_sector;
+
+	if (flash->spi->is_dual == SPI_FLASH_CONN_DUALPARALLEL) {
+		flash->page_size *= 2;
+		flash->sector_size *= 2;
+	}
+
 	flash->size = flash->sector_size * params->nr_sectors;
 
 	return flash;
drivers/mtd/spi/stmicro.c +6 -0
index 0ca00f1..e9b4bc6 100644
@@ -192,6 +192,12 @@ struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode)
 
 	flash->page_size = 256;
 	flash->sector_size = 256 * params->pages_per_sector;
+
+	if (flash->spi->is_dual == SPI_FLASH_CONN_DUALPARALLEL) {
+		flash->page_size *= 2;
+		flash->sector_size *= 2;
+	}
+
 	flash->size = flash->sector_size * params->nr_sectors;
 
 	/* for >= 512MiB flashes, use flag status instead of read_status */
Signature · 1 line
1.8.3
#3 lore raw

PATCH 3/5 sf: Add support for accessing dual stacked memories

In reply to a message not in the archive

This patch added support for accessing dual memories in stacked connections with single chipselect line from controller. this connection mode is implemented in xilinx zynq qspi controller.

For more info, see doc/README.spi-flash-conn-modes

Below are the changes for dual stacked to work:
- mtd layer -> sector_size*2, update the U_PAGE flag when memory change happen.
- driver -> on LQSPI_CFG, Enable TWO_MEM[BIT:30] on LQSPI_CFG Enable U_PAGE[BIT:28] if U_PAGE flag set - upper memory Disable U_PAGE[BIT:28] if U_PAGE flag unset - lower memory

---
 doc/README.spi-flash-conn-modes | 36 ++++++++++++++++++++++++++++++++++++
 drivers/mtd/spi/spi_flash.c     | 30 ++++++++++++++++++++++++++++--
 include/spi.h                   |  3 +++
 include/spi_flash.h             |  1 +
 4 files changed, 68 insertions(+), 2 deletions(-)
doc/README.spi-flash-conn-modes +36 -0
index f0c94b7..ab03b22 100644
@@ -63,6 +63,42 @@ Note: Technically there is only one CS line from the controller, but
 zynq qspi controller has an internal hw logic to enable additional CS
 when controller is configured for dual memories.
 
+SPI_FLASH_CONN_DUALSTACKED:
+	- dual spi/qspi flash memories are connected with a single chipselect
+	  line and these two memories are operating stacked fasion with shared buses.
+	- xilinx zynq qspi controller has implemented this feature.
+	  see trm for more info
+	  http://www.xilinx.com/support/documentation/user_guides/ug585-Zynq-7000-TRM.pdf
+
+  +-------------+        CS		+---------------+
+  |		|---------------------->|		|
+  | 		|              I0[3:0]	| Upper Flash	|
+  | 		|	     +=========>| memory	|
+  |		|	     | 	   CLK	| (SPI/QSPI)	|
+  |		|	     |	  +---->|		|
+  | Controller	|	 CS  |	  |	+---------------+
+  | SPI/QSPI	|------------|----|---->|		|
+  | 		|    I0[3:0] | 	  |	| Lower Flash	|
+  | 		|<===========+====|====>| memory	|
+  |		|	   CLK	  |	| (SPI/QSPI)	|
+  |		|-----------------+---->|		|
+  +-------------+			+---------------+
+
+	- two memory flash devices should has same hw part attributes (like size,
+	  vendor..etc)
+	- Configurations:
+		on LQSPI_CFG register, Enable TWO_MEM[BIT:30] on LQSPI_CFG
+		Enable U_PAGE[BIT:28] if U_PAGE flag set - upper memory
+		Disable U_PAGE[BIT:28] if U_PAGE flag unset - lower memory
+	- Operation:
+		accessing memories serially like one after another.
+		by default, if U_PAGE is unset lower memory sould accessible,
+		once user wants to access upper memory need to set U_PAGE.
+
+Note: Technically there is only one CS line from the controller, but
+zynq qspi controller has an internal hw logic to enable additional CS
+when controller is configured for dual memories.
+
 --
 Jagannadha Sutradharudu Teki <[email protected]>
 29-07-2013.
drivers/mtd/spi/spi_flash.c +28 -2
index 3ed90bd..f7443fa 100644
@@ -34,6 +34,9 @@ static int spi_flash_read_write(struct spi_slave *spi,
 	unsigned long flags = SPI_XFER_BEGIN;
 	int ret;
 
+	if ((spi->is_dual == SPI_FLASH_CONN_DUALSTACKED) && (spi->u_page == 1))
+		flags |= SPI_FLASH_U_PAGE;
+
 	if (data_len == 0)
 		flags |= SPI_XFER_END;
 
@@ -176,6 +179,13 @@ int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len)
 		erase_addr = offset;
 		if (is_dual == SPI_FLASH_CONN_DUALPARALLEL)
 			erase_addr /= 2;
+
+		if (is_dual == SPI_FLASH_CONN_DUALSTACKED) {
+			if (erase_addr >= (flash->size / 2))
+				flash->spi->u_page = 1;
+			else
+				flash->spi->u_page = 0;
+		}
 #ifdef CONFIG_SPI_FLASH_BAR
 		u8 bank_sel;
 
@@ -221,6 +231,13 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset,
 		write_addr = offset;
 		if (is_dual == SPI_FLASH_CONN_DUALPARALLEL)
 			write_addr /= 2;
+
+		if (is_dual == SPI_FLASH_CONN_DUALSTACKED) {
+			if (write_addr >= (flash->size / 2))
+				flash->spi->u_page = 1;
+			else
+				flash->spi->u_page = 0;
+		}
 #ifdef CONFIG_SPI_FLASH_BAR
 		u8 bank_sel;
 
@@ -304,6 +321,13 @@ int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,
 		read_addr = offset;
 		if (is_dual == SPI_FLASH_CONN_DUALPARALLEL)
 			read_addr /= 2;
+
+		if (is_dual == SPI_FLASH_CONN_DUALSTACKED) {
+			if (read_addr >= (flash->size / 2))
+				flash->spi->u_page = 1;
+			else
+				flash->spi->u_page = 0;
+		}
 #ifdef CONFIG_SPI_FLASH_BAR
 		bank_sel = read_addr / SPI_FLASH_16MB_BOUN;
 
@@ -398,7 +422,8 @@ int spi_flash_bank_config(struct spi_flash *flash, u8 idcode0)
 	cmd = flash->bank_read_cmd;
 	if (((flash->spi->is_dual == SPI_FLASH_CONN_SINGLE) &&
 			(flash->size > SPI_FLASH_16MB_BOUN)) ||
-			((flash->spi->is_dual == SPI_FLASH_CONN_DUALPARALLEL) &&
+			(((flash->spi->is_dual == SPI_FLASH_CONN_DUALSTACKED) ||
+			(flash->spi->is_dual == SPI_FLASH_CONN_DUALPARALLEL)) &&
 			((flash->size / 2) > SPI_FLASH_16MB_BOUN))) {
 		if (spi_flash_read_common(flash, &cmd, 1, &curr_bank, 1)) {
 			debug("SF: fail to read bank addr register\n");
@@ -582,7 +607,8 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
 #ifndef CONFIG_SPI_FLASH_BAR
 	if (((flash->spi->is_dual == SPI_FLASH_CONN_SINGLE) &&
 			(flash->size > SPI_FLASH_16MB_BOUN)) ||
-			((flash->spi->is_dual == SPI_FLASH_CONN_DUALPARALLEL) &&
+			(((flash->spi->is_dual == SPI_FLASH_CONN_DUALSTACKED) ||
+			(flash->spi->is_dual == SPI_FLASH_CONN_DUALPARALLEL)) &&
 			((flash->size / 2) > SPI_FLASH_16MB_BOUN))) {
 		puts("SF: Warning - Only lower 16MiB accessible for given");
 		puts("device, Full access #define CONFIG_SPI_FLASH_BAR\n");
include/spi.h +3 -0
index bb242bd..d8756ce 100644
@@ -27,6 +27,7 @@
 /* SPI transfer flags */
 #define SPI_XFER_BEGIN	0x01			/* Assert CS before transfer */
 #define SPI_XFER_END	0x02			/* Deassert CS after transfer */
+#define SPI_FLASH_U_PAGE	0x04		/* Enable Upper memory page */
 
 /* Header byte that marks the start of the message */
 #define SPI_PREAMBLE_END_BYTE	0xec
@@ -41,12 +42,14 @@
  *   max_write_size:	If non-zero, the maximum number of bytes which can
  *		be written at once, excluding command bytes.
  *   is_dual:	Indicates whether dual memories are used.
+ *   u_page:	Indicates the upper memory page, in dual stacked connection.
  */
 struct spi_slave {
 	unsigned int	bus;
 	unsigned int	cs;
 	unsigned int max_write_size;
 	int	is_dual;
+	u8	u_page;
 };
 
 /*-----------------------------------------------------------------------
include/spi_flash.h +1 -0
index fb132ab..a58bf69 100644
@@ -21,6 +21,7 @@
 enum spi_conn_modes {
 	SPI_FLASH_CONN_UNKNOWN = -1,
 	SPI_FLASH_CONN_SINGLE,
+	SPI_FLASH_CONN_DUALSTACKED,
 	SPI_FLASH_CONN_DUALPARALLEL,
 };
 
Signature · 1 line
1.8.3
#4 lore raw

PATCH 4/5 sf: spansion|stmicro: Enable dual stacked access

In reply to a message not in the archive

Dual stacked accessing can be done by updating flash part attributes like sector_size*2

---
 drivers/mtd/spi/spansion.c | 3 +++
 drivers/mtd/spi/stmicro.c  | 3 +++
 2 files changed, 6 insertions(+)
drivers/mtd/spi/spansion.c +3 -0
index a4ea16b..49ee842 100644
@@ -140,6 +140,9 @@ struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode)
 		flash->sector_size *= 2;
 	}
 
+	if (flash->spi->is_dual == SPI_FLASH_CONN_DUALSTACKED)
+		flash->sector_size *= 2;
+
 	flash->size = flash->sector_size * params->nr_sectors;
 
 	return flash;
drivers/mtd/spi/stmicro.c +3 -0
index e9b4bc6..a701571 100644
@@ -198,6 +198,9 @@ struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode)
 		flash->sector_size *= 2;
 	}
 
+	if (flash->spi->is_dual == SPI_FLASH_CONN_DUALSTACKED)
+		flash->sector_size *= 2;
+
 	flash->size = flash->sector_size * params->nr_sectors;
 
 	/* for >= 512MiB flashes, use flag status instead of read_status */
Signature · 1 line
1.8.3
#5 lore raw

PATCH 5/5 sf: Add bank selection support for dual stacked access

In reply to a message not in the archive

For upper memory, bank selection on dual stacked access needs to subtract the calculated banks from the number of banks available on a single memory.

---
 drivers/mtd/spi/spi_flash.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/mtd/spi/spi_flash.c +13 -0
index f7443fa..58d5899 100644
@@ -190,6 +190,9 @@ int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len)
 		u8 bank_sel;
 
 		bank_sel = erase_addr / SPI_FLASH_16MB_BOUN;
+		if ((is_dual == SPI_FLASH_CONN_DUALSTACKED) &&
+				(flash->spi->u_page == 1))
+			bank_sel -= ((flash->size / 2) / SPI_FLASH_16MB_BOUN);
 
 		ret = spi_flash_cmd_bankaddr_write(flash, bank_sel);
 		if (ret) {
@@ -242,6 +245,9 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset,
 		u8 bank_sel;
 
 		bank_sel = write_addr / SPI_FLASH_16MB_BOUN;
+		if ((is_dual == SPI_FLASH_CONN_DUALSTACKED) &&
+				(flash->spi->u_page == 1))
+			bank_sel -= ((flash->size / 2) / SPI_FLASH_16MB_BOUN);
 
 		ret = spi_flash_cmd_bankaddr_write(flash, bank_sel);
 		if (ret) {
@@ -330,12 +336,19 @@ int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,
 		}
 #ifdef CONFIG_SPI_FLASH_BAR
 		bank_sel = read_addr / SPI_FLASH_16MB_BOUN;
+		if ((is_dual == SPI_FLASH_CONN_DUALSTACKED) &&
+				(flash->spi->u_page == 1))
+			bank_sel -= ((flash->size / 2) / SPI_FLASH_16MB_BOUN);
 
 		ret = spi_flash_cmd_bankaddr_write(flash, bank_sel);
 		if (ret) {
 			debug("SF: fail to set bank%d\n", bank_sel);
 			return ret;
 		}
+
+		if ((is_dual == SPI_FLASH_CONN_DUALSTACKED) &&
+				(flash->spi->u_page == 1))
+			bank_sel += ((flash->size / 2) / SPI_FLASH_16MB_BOUN);
 #endif
 		remain_len = (bank_boun * (bank_sel + 1) - read_addr);
 		if (len < remain_len)
Signature · 1 line
1.8.3