Skip to contentSkip to conversation

sf: Add extended read commands support

PATCH New Jagannadha Sutradharudu Teki 3 participants 21 messages Jan 12, 2014 – Jan 15, 2014 1 message not in the archive Memory technology devices (MTD)

lore
Share & tools
lore

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

#1 lore raw

PATCH v7 1/17 sf: Add extended read commands support

Current sf uses FAST_READ command, this patch adds support to use the different/extended read command.

This implementation will determine the fastest command by taking the supported commands from the flash and the controller, controller is always been a priority.

---
 drivers/mtd/spi/sf_internal.h |   2 +
 drivers/mtd/spi/sf_ops.c      |   2 +-
 drivers/mtd/spi/sf_probe.c    | 190 +++++++++++++++++++++++-------------------
 include/spi.h                 |   8 ++
 include/spi_flash.h           |  10 +++
 5 files changed, 126 insertions(+), 86 deletions(-)
drivers/mtd/spi/sf_internal.h +2 -0
index d291746..938a78e 100644
@@ -36,6 +36,8 @@
 /* Read commands */
 #define CMD_READ_ARRAY_SLOW		0x03
 #define CMD_READ_ARRAY_FAST		0x0b
+#define CMD_READ_DUAL_OUTPUT_FAST	0x3b
+#define CMD_READ_DUAL_IO_FAST		0xbb
 #define CMD_READ_ID			0x9f
 
 /* Bank addr access commands */
drivers/mtd/spi/sf_ops.c +1 -1
index e316a69..49ceef0 100644
@@ -285,7 +285,7 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
 		return 0;
 	}
 
-	cmd[0] = CMD_READ_ARRAY_FAST;
+	cmd[0] = flash->read_cmd;
 	cmd[4] = 0x00;
 
 	while (len) {
drivers/mtd/spi/sf_probe.c +105 -85

239 lines not on this page · raw message

include/spi.h +8 -0
index aba7922..31195a3 100644
@@ -31,6 +31,12 @@
 #define SPI_XFER_MMAP_END	0x10	/* Memory Mapped End */
 #define SPI_XFER_ONCE		(SPI_XFER_BEGIN | SPI_XFER_END)
 
+/* SPI RX operation modes */
+#define SPI_OPM_RX_AS		1 << 0
+#define SPI_OPM_RX_DOUT		1 << 1
+#define SPI_OPM_RX_DIO		1 << 2
+#define SPI_OPM_RX_EXTN		SPI_OPM_RX_AS | SPI_OPM_RX_DOUT | SPI_OPM_RX_DIO
+
 /* Header byte that marks the start of the message */
 #define SPI_PREAMBLE_END_BYTE	0xec
 
@@ -43,6 +49,7 @@
  *
  * @bus:		ID of the bus that the slave is attached to.
  * @cs:			ID of the chip select connected to the slave.
+ * @op_mode_rx:		SPI RX operation mode.
  * @wordlen:		Size of SPI word in number of bits
  * @max_write_size:	If non-zero, the maximum number of bytes which can
  *			be written@once, excluding command bytes.
@@ -51,6 +58,7 @@
 struct spi_slave {
 	unsigned int bus;
 	unsigned int cs;
+	u8 op_mode_rx;
 	unsigned int wordlen;
 	unsigned int max_write_size;
 	void *memory_map;
include/spi_flash.h +10 -0
index afc3a58..692e143 100644
@@ -19,6 +19,14 @@
 #include <linux/types.h>
 #include <linux/compiler.h>
 
+/* Enum list - Extended read commands */
+enum spi_read_cmds {
+	ARRAY_SLOW = 1 << 0,
+	DUAL_OUTPUT_FAST = 1 << 1,
+	DUAL_IO_FAST = 1 << 2,
+};
+#define RD_EXTN		ARRAY_SLOW | DUAL_OUTPUT_FAST | DUAL_IO_FAST
+
 /**
  * struct spi_flash - SPI flash structure
  *
@@ -33,6 +41,7 @@
  * @bank_curr:		Current flash bank
  * @poll_cmd:		Poll cmd - for flash erase/program
  * @erase_cmd:		Erase cmd 4K, 32K, 64K
+ * @read_cmd:		Read cmd - Array Fast and Extn read
  * @memory_map:		Address of read-only SPI flash access
  * @read:		Flash read ops: Read len bytes@offset into buf
  *			Supported cmds: Fast Array Read
@@ -57,6 +66,7 @@ struct spi_flash {
 #endif
 	u8 poll_cmd;
 	u8 erase_cmd;
+	u8 read_cmd;
 
 	void *memory_map;
 	int (*read)(struct spi_flash *flash, u32 offset, size_t len, void *buf);
Signature · 1 line
1.8.3
#2 lore raw

PATCH v7 1/17 sf: Add extended read commands support

Quoted 7 lines · Jagannadha Sutradharudu Teki

Current sf uses FAST_READ command, this patch adds support to use the different/extended read command.

This implementation will determine the fastest command by taking the supported commands from the flash and the controller, controller is always been a priority.

I don't quite get this. You have a combination of several components which all have to participate appropriately when you want the total of it to work correctly.

How can one specific component "be a priority" there? Isn't the lowest common denominator required instead? The strength of a chain is determined by its weakest link after all.

The other issue I have here (as well as in Linux kernel changes and discussions) is that people seem to forget that the board is involved as well.

Your commit message suggests that "parallel" communication is used as soon as
- the SPI controller has such a feature
- a flash chip was detected which according to a fixed database supports this feature

This decision is automatic. Neither is there a "how is the board wired?" condition involved, nor can users or even developers adjust this behaviour (say, by optionally setting a maximum width).

I'd suggest to provide a "maximum number of lines to use" option, for the same reasons that we may want to limit transfer rates instead of always using the maximum of what individual chips could do (the reasons: the number of lines connected as well as their electrical and mechanical properties do have an impact).

Alternatively one may implement auto-detection, starting at the most capable feature and falling back until a working condition was found. But this is fragile if the communication used at detection time does not involve all potentially used lines (and in all directions, mind you). This won't solve potential bugs in chips either which the user may want to override. Or EMI related restrictions which a developer may want to apply despite the chips' and board's being more capable. Or pin mux settings which dedicate unused "upper SPI data lines" to other features (as we have seen with MMC cards recently).

virtually yours
Gerhard Sittig

Signature · 3 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr. 5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
#3 lore raw

PATCH v7 1/17 sf: Add extended read commands support

Hi Gerhard Sittig,

Thanks for your comments, please see below

Quoted 39 lines · Gerhard Sittig
Quoted 7 lines · Jagannadha Sutradharudu Teki

Current sf uses FAST_READ command, this patch adds support to use the different/extended read command.

This implementation will determine the fastest command by taking the supported commands from the flash and the controller, controller is always been a priority.

I don't quite get this. You have a combination of several components which all have to participate appropriately when you want the total of it to work correctly.

How can one specific component "be a priority" there? Isn't the lowest common denominator required instead? The strength of a chain is determined by its weakest link after all.

The other issue I have here (as well as in Linux kernel changes and discussions) is that people seem to forget that the board is involved as well.

Your commit message suggests that "parallel" communication is used as soon as
- the SPI controller has such a feature
- a flash chip was detected which according to a fixed database supports this feature

This decision is automatic. Neither is there a "how is the board wired?" condition involved, nor can users or even developers adjust this behaviour (say, by optionally setting a maximum width).

I'd suggest to provide a "maximum number of lines to use" option, for the same reasons that we may want to limit transfer rates instead of always using the maximum of what individual chips could do (the reasons: the number of lines connected as well as their electrical and mechanical properties do have an impact).

Quoted 10 lines

Alternatively one may implement auto-detection, starting at the most capable feature and falling back until a working condition was found. But this is fragile if the communication used at detection time does not involve all potentially used lines (and in all directions, mind you). This won't solve potential bugs in chips either which the user may want to override. Or EMI related restrictions which a developer may want to apply despite the chips' and board's being more capable. Or pin mux settings which dedicate unused "upper SPI data lines" to other features (as we have seen with MMC cards recently).

Yes the main reason for going maximum or based on controller setting transfer is to improve sf performance. I missed your point as didn't see much use cases from board to connected flash perceptive.

I thought we have two options to meet this requirement.
1. dynamic - auto-detection:
Get the max_nof_lines based on the board to connected flash. So-that we can configure the transfer mode based on the lines. no idea yet, how to get the max_nof_lines dynamically - any inputs.
2. static: from user level we may give the max_nof_lines
ex: sf probe probe [[[bus:]cs]:max_nof_line] [hz] [mode]
If user can't input max_nof_line so-that driver will go with single and the rest case transfer modes assigned based on the given input.

Please comment?

Signature · 2 lines
Thanks,
Jagan.
#4 lore raw

PATCH v7 1/17 sf: Add extended read commands support

Hi,

Quoted 59 lines · Jagan Teki

Hi Gerhard Sittig,

Thanks for your comments, please see below

Quoted 39 lines · Gerhard Sittig
Quoted 7 lines · Jagannadha Sutradharudu Teki

Current sf uses FAST_READ command, this patch adds support to use the different/extended read command.

This implementation will determine the fastest command by taking the supported commands from the flash and the controller, controller is always been a priority.

I don't quite get this. You have a combination of several components which all have to participate appropriately when you want the total of it to work correctly.

How can one specific component "be a priority" there? Isn't the lowest common denominator required instead? The strength of a chain is determined by its weakest link after all.

The other issue I have here (as well as in Linux kernel changes and discussions) is that people seem to forget that the board is involved as well.

Your commit message suggests that "parallel" communication is used as soon as
- the SPI controller has such a feature
- a flash chip was detected which according to a fixed database supports this feature

This decision is automatic. Neither is there a "how is the board wired?" condition involved, nor can users or even developers adjust this behaviour (say, by optionally setting a maximum width).

I'd suggest to provide a "maximum number of lines to use" option, for the same reasons that we may want to limit transfer rates instead of always using the maximum of what individual chips could do (the reasons: the number of lines connected as well as their electrical and mechanical properties do have an impact).

Quoted 10 lines

Alternatively one may implement auto-detection, starting at the most capable feature and falling back until a working condition was found. But this is fragile if the communication used at detection time does not involve all potentially used lines (and in all directions, mind you). This won't solve potential bugs in chips either which the user may want to override. Or EMI related restrictions which a developer may want to apply despite the chips' and board's being more capable. Or pin mux settings which dedicate unused "upper SPI data lines" to other features (as we have seen with MMC cards recently).

Yes the main reason for going maximum or based on controller setting transfer is to improve sf performance. I missed your point as didn't see much use cases from board to connected flash perceptive.

Quoted 9 lines

I thought we have two options to meet this requirement.
1. dynamic - auto-detection:
Get the max_nof_lines based on the board to connected flash. So-that we can configure the transfer mode based on the lines. no idea yet, how to get the max_nof_lines dynamically - any inputs.
2. static: from user level we may give the max_nof_lines
ex: sf probe probe [[[bus:]cs]:max_nof_line] [hz] [mode]
If user can't input max_nof_line so-that driver will go with single and the rest case transfer modes assigned based on the given input.

As this change involves mostly on the driver parts I a thinking to go-ahead and try to push this series to master. yes I would mark this as my TODO list and will
trigger one more thread.

Hope this idea sounds valid, let me know for any issues.

Signature · 2 lines
Thanks,
Jagan.
#5 lore raw

PATCH v7 1/17 sf: Add extended read commands support

Quoted 7 lines · Jagan Teki
Quoted 5 lines · Jagan Teki

Yes the main reason for going maximum or based on controller setting transfer is to improve sf performance. I missed your point as didn't see much use cases from board to connected flash perceptive.

Quoted 9 lines
Quoted 9 lines

I thought we have two options to meet this requirement.
1. dynamic - auto-detection:
Get the max_nof_lines based on the board to connected flash. So-that we can configure the transfer mode based on the lines. no idea yet, how to get the max_nof_lines dynamically - any inputs.
2. static: from user level we may give the max_nof_lines
ex: sf probe probe [[[bus:]cs]:max_nof_line] [hz] [mode]
If user can't input max_nof_line so-that driver will go with single and the rest case transfer modes assigned based on the given input.

As outlined in my previous reply, I'm afraid that the auto detection will always end up being inferior (unreliable, potentially dangerous, still not under the user's control).

A simple approach might be to have the user specify the number of data lines to use (as in your "static" example above). The question remains whether this specified number shall be taken as the exact number or as the maximum number of data lines.

Quoted 5 lines

As this change involves mostly on the driver parts I a thinking to go-ahead and try to push this series to master. yes I would mark this as my TODO list and will trigger one more thread.

Hope this idea sounds valid, let me know for any issues.

Agreed, as there are few or no complaints and concerns (yet?), let's address this limiting the number of data lines at a later point in time. Just keep awareness, that was my most important issue here. :)

Given that Quad-SPI is rather new, I'd expect new designs to be "consistent" (i.e. always quad capable flash chips attached to quad capable controllers and connected via the maximum number of lines known by that time), while only after some more time the "interesting" combinations crop up (like starting with non-quad flash chip and only the necessary connections and a quad capable controller, then dropping in more recent chips without re-rolling the PCB layout; or upgrading/replacing SoCs and flash chips with "compatible" devices and not being aware of the software's "detecting" the maximum while ignoring the wires on board).

virtually yours
Gerhard Sittig

Signature · 3 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr. 5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
#6 lore raw

PATCH v7 2/17 sf: Add quad read/write commands support

In reply to a message not in the archive

This patch add quad commands support like
- QUAD_PAGE_PROGRAM => for write program
- QUAD_OUTPUT_FAST ->> for read program

---
 drivers/mtd/spi/sf_internal.h |   2 +
 drivers/mtd/spi/sf_ops.c      |   2 +-
 drivers/mtd/spi/sf_probe.c    | 178 ++++++++++++++++++++++--------------------
 include/spi.h                 |   9 ++-
 include/spi_flash.h           |  11 ++-
 5 files changed, 113 insertions(+), 89 deletions(-)
drivers/mtd/spi/sf_internal.h +2 -0
index 938a78e..dcc9014 100644
@@ -28,6 +28,7 @@
 #define CMD_PAGE_PROGRAM		0x02
 #define CMD_WRITE_DISABLE		0x04
 #define CMD_READ_STATUS			0x05
+#define CMD_QUAD_PAGE_PROGRAM		0x32
 #define CMD_READ_STATUS1		0x35
 #define CMD_WRITE_ENABLE		0x06
 #define CMD_READ_CONFIG			0x35
@@ -38,6 +39,7 @@
 #define CMD_READ_ARRAY_FAST		0x0b
 #define CMD_READ_DUAL_OUTPUT_FAST	0x3b
 #define CMD_READ_DUAL_IO_FAST		0xbb
+#define CMD_READ_QUAD_OUTPUT_FAST	0x6b
 #define CMD_READ_ID			0x9f
 
 /* Bank addr access commands */
drivers/mtd/spi/sf_ops.c +1 -1
index 49ceef0..3d304ce 100644
@@ -210,7 +210,7 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
 
 	page_size = flash->page_size;
 
-	cmd[0] = CMD_PAGE_PROGRAM;
+	cmd[0] = flash->write_cmd;
 	for (actual = 0; actual < len; actual += chunk_len) {
 #ifdef CONFIG_SPI_FLASH_BAR
 		ret = spi_flash_bank(flash, offset);
drivers/mtd/spi/sf_probe.c +93 -85

210 lines not on this page · raw message

include/spi.h +8 -1
index 31195a3..5dd490a 100644
@@ -31,11 +31,16 @@
 #define SPI_XFER_MMAP_END	0x10	/* Memory Mapped End */
 #define SPI_XFER_ONCE		(SPI_XFER_BEGIN | SPI_XFER_END)
 
+/* SPI TX operation modes */
+#define SPI_OPM_TX_QPP		1 << 0
+
 /* SPI RX operation modes */
 #define SPI_OPM_RX_AS		1 << 0
 #define SPI_OPM_RX_DOUT		1 << 1
 #define SPI_OPM_RX_DIO		1 << 2
-#define SPI_OPM_RX_EXTN		SPI_OPM_RX_AS | SPI_OPM_RX_DOUT | SPI_OPM_RX_DIO
+#define SPI_OPM_RX_QOF		1 << 3
+#define SPI_OPM_RX_EXTN		SPI_OPM_RX_AS | SPI_OPM_RX_DOUT | \
+				SPI_OPM_RX_DIO | SPI_OPM_RX_QOF
 
 /* Header byte that marks the start of the message */
 #define SPI_PREAMBLE_END_BYTE	0xec
@@ -50,6 +55,7 @@
  * @bus:		ID of the bus that the slave is attached to.
  * @cs:			ID of the chip select connected to the slave.
  * @op_mode_rx:		SPI RX operation mode.
+ * @op_mode_tx:		SPI TX operation mode.
  * @wordlen:		Size of SPI word in number of bits
  * @max_write_size:	If non-zero, the maximum number of bytes which can
  *			be written@once, excluding command bytes.
@@ -59,6 +65,7 @@ struct spi_slave {
 	unsigned int bus;
 	unsigned int cs;
 	u8 op_mode_rx;
+	u8 op_mode_tx;
 	unsigned int wordlen;
 	unsigned int max_write_size;
 	void *memory_map;
include/spi_flash.h +9 -2
index 692e143..9fd9d3b 100644
@@ -19,13 +19,18 @@
 #include <linux/types.h>
 #include <linux/compiler.h>
 
-/* Enum list - Extended read commands */
+/* No enum list for write commands only QPP */
+#define WR_QPP		1 << 4
+
+/* Enum list - Full read commands */
 enum spi_read_cmds {
 	ARRAY_SLOW = 1 << 0,
 	DUAL_OUTPUT_FAST = 1 << 1,
 	DUAL_IO_FAST = 1 << 2,
+	QUAD_OUTPUT_FAST = 1 << 3,
 };
 #define RD_EXTN		ARRAY_SLOW | DUAL_OUTPUT_FAST | DUAL_IO_FAST
+#define RD_FULL		RD_EXTN | QUAD_OUTPUT_FAST
 
 /**
  * struct spi_flash - SPI flash structure
@@ -41,7 +46,8 @@ enum spi_read_cmds {
  * @bank_curr:		Current flash bank
  * @poll_cmd:		Poll cmd - for flash erase/program
  * @erase_cmd:		Erase cmd 4K, 32K, 64K
- * @read_cmd:		Read cmd - Array Fast and Extn read
+ * @read_cmd:		Read cmd - Array Fast, Extn read and quad read.
+ * @write_cmd:		Write cmd - page and quad program.
  * @memory_map:		Address of read-only SPI flash access
  * @read:		Flash read ops: Read len bytes@offset into buf
  *			Supported cmds: Fast Array Read
@@ -67,6 +73,7 @@ struct spi_flash {
 	u8 poll_cmd;
 	u8 erase_cmd;
 	u8 read_cmd;
+	u8 write_cmd;
 
 	void *memory_map;
 	int (*read)(struct spi_flash *flash, u32 offset, size_t len, void *buf);
Signature · 1 line
1.8.3
#7 lore raw

PATCH v7 3/17 sf: ops: Add configuration register writing support

In reply to a message not in the archive

This patch provides support to program a flash config register.

Configuration register contains the control bits used to configure the different configurations and security features of a device.

---
 drivers/mtd/spi/sf_ops.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
drivers/mtd/spi/sf_ops.c +24 -0
index 3d304ce..39e06ec 100644
@@ -38,6 +38,30 @@ int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr)
 	return 0;
 }
 
+static int spi_flash_cmd_write_config(struct spi_flash *flash, u8 cr)
+{
+	u8 data[2];
+	u8 cmd;
+	int ret;
+
+	cmd = CMD_READ_STATUS;
+	ret = spi_flash_read_common(flash, &cmd, 1, &data[0], 1);
+	if (ret < 0) {
+		debug("SF: fail to read status register\n");
+		return ret;
+	}
+
+	cmd = CMD_WRITE_STATUS;
+	data[1] = cr;
+	ret = spi_flash_write_common(flash, &cmd, 1, &data, 2);
+	if (ret) {
+		debug("SF: fail to write config register\n");
+		return ret;
+	}
+
+	return 0;
+}
+
 #ifdef CONFIG_SPI_FLASH_BAR
 static int spi_flash_cmd_bankaddr_write(struct spi_flash *flash, u8 bank_sel)
 {
Signature · 1 line
1.8.3
#8 lore raw

PATCH v7 4/17 sf: Set quad enable bit support

In reply to a message not in the archive

This patch provides support to set the quad enable bit on flash.

quad enable bit needs to set before performing any quad IO operations on respective SPI flashes.

Currently added set quad enable bit for winbond and spansion flash devices. stmicro flash doesn't require to set as qeb is volatile. remaining flash devices support will add in future patches.

---
 drivers/mtd/spi/sf_internal.h | 10 ++++++++--
 drivers/mtd/spi/sf_ops.c      | 26 ++++++++++++++++++++++++++
 drivers/mtd/spi/sf_probe.c    | 28 ++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+), 2 deletions(-)
drivers/mtd/spi/sf_internal.h +8 -2
index dcc9014..dca34f7 100644
@@ -12,6 +12,11 @@
 
 #define SPI_FLASH_16MB_BOUN		0x1000000
 
+/* CFI Manufacture ID's */
+#define SPI_FLASH_CFI_MFR_SPANSION	0x01
+#define SPI_FLASH_CFI_MFR_STMICRO	0x20
+#define SPI_FLASH_CFI_MFR_WINBOND	0xef
+
 /* SECT flags */
 #define SECT_4K				(1 << 1)
 #define SECT_32K			(1 << 2)
@@ -52,6 +57,7 @@
 
 /* Common status */
 #define STATUS_WIP			0x01
+#define STATUS_QEB_WINSPAN		(1 << 1)
 #define STATUS_PEC			0x80
 
 /* Flash timeout values */
@@ -93,8 +99,8 @@ int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len);
 /* Program the status register */
 int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr);
 
-/* Set quad enbale bit */
-int spi_flash_set_qeb(struct spi_flash *flash);
+/* Set quad enbale bit for winbond and spansion flashes */
+int spi_flash_set_qeb_winspan(struct spi_flash *flash);
 
 /* Enable writing on the SPI flash */
 static inline int spi_flash_cmd_write_enable(struct spi_flash *flash)
drivers/mtd/spi/sf_ops.c +26 -0
index 39e06ec..827f719 100644
@@ -38,6 +38,7 @@ int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr)
 	return 0;
 }
 
+#if defined(CONFIG_SPI_FLASH_SPANSION) || defined(CONFIG_SPI_FLASH_WINBOND)
 static int spi_flash_cmd_write_config(struct spi_flash *flash, u8 cr)
 {
 	u8 data[2];
@@ -62,6 +63,31 @@ static int spi_flash_cmd_write_config(struct spi_flash *flash, u8 cr)
 	return 0;
 }
 
+int spi_flash_set_qeb_winspan(struct spi_flash *flash)
+{
+	u8 qeb_status;
+	u8 cmd;
+	int ret;
+
+	cmd = CMD_READ_CONFIG;
+	ret = spi_flash_read_common(flash, &cmd, 1, &qeb_status, 1);
+	if (ret < 0) {
+		debug("SF: fail to read config register\n");
+		return ret;
+	}
+
+	if (qeb_status & STATUS_QEB_WINSPAN) {
+		debug("SF: Quad enable bit is already set\n");
+	} else {
+		ret = spi_flash_cmd_write_config(flash, STATUS_QEB_WINSPAN);
+		if (ret < 0)
+			return ret;
+	}
+
+	return ret;
+}
+#endif
+
 #ifdef CONFIG_SPI_FLASH_BAR
 static int spi_flash_cmd_bankaddr_write(struct spi_flash *flash, u8 bank_sel)
 {
drivers/mtd/spi/sf_probe.c +28 -0
index 3fa7363..8b2972c 100644
@@ -165,6 +165,25 @@ static u8 spi_read_cmds_array[] = {
 	CMD_READ_QUAD_OUTPUT_FAST,
 };
 
+static int spi_flash_set_qeb(struct spi_flash *flash, u8 idcode0)
+{
+	switch (idcode0) {
+#if defined(CONFIG_SPI_FLASH_SPANSION) || defined(CONFIG_SPI_FLASH_WINBOND)
+	case SPI_FLASH_CFI_MFR_SPANSION:
+	case SPI_FLASH_CFI_MFR_WINBOND:
+		return spi_flash_set_qeb_winspan(flash);
+#endif
+#ifdef CONFIG_SPI_FLASH_STMICRO
+	case SPI_FLASH_CFI_MFR_STMICRO:
+		debug("SF: QEB is volatile for %02x flash\n", idcode0);
+		return 0;
+#endif
+	default:
+		printf("SF: Need set QEB func for %02x flash\n", idcode0);
+		return -1;
+	}
+}
+
 static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,
 		u8 *idcode)
 {
@@ -250,6 +269,15 @@ static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,
 		/* Go for default supported write cmd */
 		flash->write_cmd = CMD_PAGE_PROGRAM;
 
+	/* Set the quad enable bit - only for quad commands */
+	if ((flash->read_cmd == CMD_READ_QUAD_OUTPUT_FAST) ||
+	    (flash->write_cmd == CMD_QUAD_PAGE_PROGRAM)) {
+		if (spi_flash_set_qeb(flash, idcode[0])) {
+			debug("SF: Fail to set QEB for %02x\n", idcode[0]);
+			return NULL;
+		}
+	}
+
 	/* Poll cmd seclection */
 	flash->poll_cmd = CMD_READ_STATUS;
 #ifdef CONFIG_SPI_FLASH_STMICRO
Signature · 1 line
1.8.3
#9 lore raw

PATCH v7 5/17 sf: probe: Enable RD_FULL and WR_QPP

In reply to a message not in the archive

This patch enabled RD_FULL and WR_QPP for supported flashes in micron, winbond and spansion.

Remaining parts will be add in future patches.

---
 drivers/mtd/spi/sf_probe.c | 60 +++++++++++++++++++++++-----------------------
 1 file changed, 30 insertions(+), 30 deletions(-)
drivers/mtd/spi/sf_probe.c +30 -30
index 8b2972c..f24bc1b 100644
@@ -78,15 +78,15 @@ static const struct spi_flash_params spi_flash_params_table[] = {
 	{"S25FL016A",	   0x010214, 0x0,	64 * 1024,    32,	0,			  0},
 	{"S25FL032A",	   0x010215, 0x0,	64 * 1024,    64,	0,			  0},
 	{"S25FL064A",	   0x010216, 0x0,	64 * 1024,   128,	0,			  0},
-	{"S25FL128P_256K", 0x012018, 0x0300,   256 * 1024,    64,	0,			  0},
-	{"S25FL128P_64K",  0x012018, 0x0301,    64 * 1024,   256,	0,			  0},
-	{"S25FL032P",	   0x010215, 0x4d00,    64 * 1024,    64,	0,			  0},
-	{"S25FL064P",	   0x010216, 0x4d00,    64 * 1024,   128,	0,			  0},
-	{"S25FL128S_64K",  0x012018, 0x4d01,    64 * 1024,   256,	0,			  0},
+	{"S25FL128P_256K", 0x012018, 0x0300,   256 * 1024,    64, RD_FULL,		     WR_QPP},
+	{"S25FL128P_64K",  0x012018, 0x0301,    64 * 1024,   256, RD_FULL,		     WR_QPP},
+	{"S25FL032P",	   0x010215, 0x4d00,    64 * 1024,    64, RD_FULL,		     WR_QPP},
+	{"S25FL064P",	   0x010216, 0x4d00,    64 * 1024,   128, RD_FULL,		     WR_QPP},
+	{"S25FL128S_64K",  0x012018, 0x4d01,    64 * 1024,   256, RD_FULL,		     WR_QPP},
 	{"S25FL256S_256K", 0x010219, 0x4d00,    64 * 1024,   512, RD_FULL,		     WR_QPP},
 	{"S25FL256S_64K",  0x010219, 0x4d01,	64 * 1024,   512, RD_FULL,		     WR_QPP},
-	{"S25FL512S_256K", 0x010220, 0x4d00,    64 * 1024,  1024,	0,			  0},
-	{"S25FL512S_64K",  0x010220, 0x4d01,    64 * 1024,  1024,	0,			  0},
+	{"S25FL512S_256K", 0x010220, 0x4d00,    64 * 1024,  1024, RD_FULL,		     WR_QPP},
+	{"S25FL512S_64K",  0x010220, 0x4d01,    64 * 1024,  1024, RD_FULL,		     WR_QPP},
 #endif
 #ifdef CONFIG_SPI_FLASH_STMICRO		/* STMICRO */
 	{"M25P10",	   0x202011, 0x0,	32 * 1024,     4,	0,			  0},
@@ -97,18 +97,18 @@ static const struct spi_flash_params spi_flash_params_table[] = {
 	{"M25P32",	   0x202016, 0x0,       64 * 1024,    64,	0,			  0},
 	{"M25P64",	   0x202017, 0x0,       64 * 1024,   128,	0,			  0},
 	{"M25P128",	   0x202018, 0x0,      256 * 1024,    64,	0,			  0},
-	{"N25Q32",	   0x20ba16, 0x0,       64 * 1024,    64,	0,		    SECT_4K},
-	{"N25Q32A",	   0x20bb16, 0x0,       64 * 1024,    64,	0,		    SECT_4K},
-	{"N25Q64",	   0x20ba17, 0x0,       64 * 1024,   128,	0,		    SECT_4K},
-	{"N25Q64A",	   0x20bb17, 0x0,       64 * 1024,   128,	0,		    SECT_4K},
-	{"N25Q128",	   0x20ba18, 0x0,       64 * 1024,   256,	0,		    SECT_4K},
-	{"N25Q128A",	   0x20bb18, 0x0,       64 * 1024,   256,	0,		    SECT_4K},
-	{"N25Q256",	   0x20ba19, 0x0,       64 * 1024,   512,	0,		    SECT_4K},
-	{"N25Q256A",	   0x20bb19, 0x0,       64 * 1024,   512,	0,		    SECT_4K},
-	{"N25Q512",	   0x20ba20, 0x0,       64 * 1024,  1024,       0,	    E_FSR | SECT_4K},
-	{"N25Q512A",	   0x20bb20, 0x0,       64 * 1024,  1024,       0,	    E_FSR | SECT_4K},
-	{"N25Q1024",	   0x20ba21, 0x0,       64 * 1024,  2048,       0,	    E_FSR | SECT_4K},
-	{"N25Q1024A",	   0x20bb21, 0x0,       64 * 1024,  2048,	0,	    E_FSR | SECT_4K},
+	{"N25Q32",	   0x20ba16, 0x0,       64 * 1024,    64, RD_FULL,	   WR_QPP | SECT_4K},
+	{"N25Q32A",	   0x20bb16, 0x0,       64 * 1024,    64, RD_FULL,	   WR_QPP | SECT_4K},
+	{"N25Q64",	   0x20ba17, 0x0,       64 * 1024,   128, RD_FULL,	   WR_QPP | SECT_4K},
+	{"N25Q64A",	   0x20bb17, 0x0,       64 * 1024,   128, RD_FULL,	   WR_QPP | SECT_4K},
+	{"N25Q128",	   0x20ba18, 0x0,       64 * 1024,   256, RD_FULL,	   WR_QPP | SECT_4K},
+	{"N25Q128A",	   0x20bb18, 0x0,       64 * 1024,   256, RD_FULL,	   WR_QPP | SECT_4K},
+	{"N25Q256",	   0x20ba19, 0x0,       64 * 1024,   512, RD_FULL,	   WR_QPP | SECT_4K},
+	{"N25Q256A",	   0x20bb19, 0x0,       64 * 1024,   512, RD_FULL,	   WR_QPP | SECT_4K},
+	{"N25Q512",	   0x20ba20, 0x0,       64 * 1024,  1024, RD_FULL, WR_QPP | E_FSR | SECT_4K},
+	{"N25Q512A",	   0x20bb20, 0x0,       64 * 1024,  1024, RD_FULL, WR_QPP | E_FSR | SECT_4K},
+	{"N25Q1024",	   0x20ba21, 0x0,       64 * 1024,  2048, RD_FULL, WR_QPP | E_FSR | SECT_4K},
+	{"N25Q1024A",	   0x20bb21, 0x0,       64 * 1024,  2048, RD_FULL, WR_QPP | E_FSR | SECT_4K},
 #endif
 #ifdef CONFIG_SPI_FLASH_SST		/* SST */
 	{"SST25VF040B",	   0xbf258d, 0x0,	64 * 1024,     8,	0,          SECT_4K | SST_WP},
@@ -130,17 +130,17 @@ static const struct spi_flash_params spi_flash_params_table[] = {
 	{"W25X16",	   0xef3015, 0x0,	64 * 1024,    32,	0,		     SECT_4K},
 	{"W25X32",	   0xef3016, 0x0,	64 * 1024,    64,	0,		     SECT_4K},
 	{"W25X64",	   0xef3017, 0x0,	64 * 1024,   128,	0,		     SECT_4K},
-	{"W25Q80BL",	   0xef4014, 0x0,	64 * 1024,    16,	0,		     SECT_4K},
-	{"W25Q16CL",	   0xef4015, 0x0,	64 * 1024,    32,	0,		     SECT_4K},
-	{"W25Q32BV",	   0xef4016, 0x0,	64 * 1024,    64,	0,		     SECT_4K},
-	{"W25Q64CV",	   0xef4017, 0x0,	64 * 1024,   128,	0,		     SECT_4K},
-	{"W25Q128BV",	   0xef4018, 0x0,	64 * 1024,   256,	0,		     SECT_4K},
-	{"W25Q256",	   0xef4019, 0x0,	64 * 1024,   512,	0,		     SECT_4K},
-	{"W25Q80BW",	   0xef5014, 0x0,	64 * 1024,    16,	0,		     SECT_4K},
-	{"W25Q16DW",	   0xef6015, 0x0,	64 * 1024,    32,	0,		     SECT_4K},
-	{"W25Q32DW",	   0xef6016, 0x0,	64 * 1024,    64,	0,		     SECT_4K},
-	{"W25Q64DW",	   0xef6017, 0x0,	64 * 1024,   128,	0,		     SECT_4K},
-	{"W25Q128FW",	   0xef6018, 0x0,	64 * 1024,   256,	0,		     SECT_4K},
+	{"W25Q80BL",	   0xef4014, 0x0,	64 * 1024,    16, RD_FULL,	    WR_QPP | SECT_4K},
+	{"W25Q16CL",	   0xef4015, 0x0,	64 * 1024,    32, RD_FULL,	    WR_QPP | SECT_4K},
+	{"W25Q32BV",	   0xef4016, 0x0,	64 * 1024,    64, RD_FULL,	    WR_QPP | SECT_4K},
+	{"W25Q64CV",	   0xef4017, 0x0,	64 * 1024,   128, RD_FULL,	    WR_QPP | SECT_4K},
+	{"W25Q128BV",	   0xef4018, 0x0,	64 * 1024,   256, RD_FULL,	    WR_QPP | SECT_4K},
+	{"W25Q256",	   0xef4019, 0x0,	64 * 1024,   512, RD_FULL,	    WR_QPP | SECT_4K},
+	{"W25Q80BW",	   0xef5014, 0x0,	64 * 1024,    16, RD_FULL,	    WR_QPP | SECT_4K},
+	{"W25Q16DW",	   0xef6015, 0x0,	64 * 1024,    32, RD_FULL,	    WR_QPP | SECT_4K},
+	{"W25Q32DW",	   0xef6016, 0x0,	64 * 1024,    64, RD_FULL,	    WR_QPP | SECT_4K},
+	{"W25Q64DW",	   0xef6017, 0x0,	64 * 1024,   128, RD_FULL,	    WR_QPP | SECT_4K},
+	{"W25Q128FW",	   0xef6018, 0x0,	64 * 1024,   256, RD_FULL,	    WR_QPP | SECT_4K},
 #endif
 	/*
 	 * Note:
Signature · 1 line
1.8.3
#10 lore raw

PATCH v7 6/17 sf: Separate the flash params table

In reply to a message not in the archive

Moved the flash params table from sf_probe.c and placed on to sf_params.c, hence flash params file will alter based on new addons.

---
 drivers/mtd/spi/Makefile    |   4 +-
 drivers/mtd/spi/sf_params.c | 130 +++++++++++++++++++++++++++++++++++++++
 drivers/mtd/spi/sf_probe.c  | 146 +-------------------------------------------
 include/spi_flash.h         |  23 +++++++
 4 files changed, 158 insertions(+), 145 deletions(-)
 create mode 100644 drivers/mtd/spi/sf_params.c
drivers/mtd/spi/Makefile +2 -2
index 26483a2..9e18fb4 100644
@@ -10,8 +10,8 @@ obj-$(CONFIG_SPL_SPI_LOAD)	+= spi_spl_load.o
 obj-$(CONFIG_SPL_SPI_BOOT)	+= fsl_espi_spl.o
 endif
 
-obj-$(CONFIG_CMD_SF)        += sf.o
-obj-$(CONFIG_SPI_FLASH) += sf_probe.o sf_ops.o
+obj-$(CONFIG_CMD_SF) += sf.o
+obj-$(CONFIG_SPI_FLASH) += sf_params.o sf_probe.o sf_ops.o
 obj-$(CONFIG_SPI_FRAM_RAMTRON) += ramtron.o
 obj-$(CONFIG_SPI_FLASH_SANDBOX) += sandbox.o
 obj-$(CONFIG_SPI_M95XXX) += eeprom_m95xxx.o
drivers/mtd/spi/sf_params.c new file +130 -0

130 lines not on this page · raw message

drivers/mtd/spi/sf_probe.c +3 -143

168 lines not on this page · raw message

include/spi_flash.h +23 -0
index 9fd9d3b..8e0bb46 100644
@@ -33,6 +33,29 @@ enum spi_read_cmds {
 #define RD_FULL		RD_EXTN | QUAD_OUTPUT_FAST
 
 /**
+ * struct spi_flash_params - SPI/QSPI flash device params structure
+ *
+ * @name:		Device name ([MANUFLETTER][DEVTYPE][DENSITY][EXTRAINFO])
+ * @jedec:		Device jedec ID (0x[1byte_manuf_id][2byte_dev_id])
+ * @ext_jedec:		Device ext_jedec ID
+ * @sector_size:	Sector size of this device
+ * @nr_sectors:		No.of sectors on this device
+ * @e_rd_cmd:		Enum list for read commands
+ * @flags:		Importent param, for flash specific behaviour
+ */
+struct spi_flash_params {
+	const char *name;
+	u32 jedec;
+	u16 ext_jedec;
+	u32 sector_size;
+	u32 nr_sectors;
+	u8 e_rd_cmd;
+	u16 flags;
+};
+
+extern const struct spi_flash_params spi_flash_params_table[];
+
+/**
  * struct spi_flash - SPI flash structure
  *
  * @spi:		SPI slave
Signature · 1 line
1.8.3
#11 lore raw

PATCH v7 7/17 sf: Add QUAD_IO_FAST read support

In reply to a message not in the archive

This patch adds support QUAD_IO_FAST read command.

---
 drivers/mtd/spi/sf_internal.h | 1 +
 drivers/mtd/spi/sf_probe.c    | 2 ++
 include/spi.h                 | 4 +++-
 include/spi_flash.h           | 3 ++-
 4 files changed, 8 insertions(+), 2 deletions(-)
drivers/mtd/spi/sf_internal.h +1 -0
index dca34f7..7be0292 100644
@@ -45,6 +45,7 @@
 #define CMD_READ_DUAL_OUTPUT_FAST	0x3b
 #define CMD_READ_DUAL_IO_FAST		0xbb
 #define CMD_READ_QUAD_OUTPUT_FAST	0x6b
+#define CMD_READ_QUAD_IO_FAST		0xeb
 #define CMD_READ_ID			0x9f
 
 /* Bank addr access commands */
drivers/mtd/spi/sf_probe.c +2 -0
index d95c8b9..a049e72 100644
@@ -25,6 +25,7 @@ static u8 spi_read_cmds_array[] = {
 	CMD_READ_DUAL_OUTPUT_FAST,
 	CMD_READ_DUAL_IO_FAST,
 	CMD_READ_QUAD_OUTPUT_FAST,
+	CMD_READ_QUAD_IO_FAST,
 };
 
 static int spi_flash_set_qeb(struct spi_flash *flash, u8 idcode0)
@@ -131,6 +132,7 @@ static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,
 
 	/* Set the quad enable bit - only for quad commands */
 	if ((flash->read_cmd == CMD_READ_QUAD_OUTPUT_FAST) ||
+	    (flash->read_cmd == CMD_READ_QUAD_IO_FAST) ||
 	    (flash->write_cmd == CMD_QUAD_PAGE_PROGRAM)) {
 		if (spi_flash_set_qeb(flash, idcode[0])) {
 			debug("SF: Fail to set QEB for %02x\n", idcode[0]);
include/spi.h +3 -1
index 5dd490a..c8a9d87 100644
@@ -39,8 +39,10 @@
 #define SPI_OPM_RX_DOUT		1 << 1
 #define SPI_OPM_RX_DIO		1 << 2
 #define SPI_OPM_RX_QOF		1 << 3
+#define SPI_OPM_RX_QIOF		1 << 4
 #define SPI_OPM_RX_EXTN		SPI_OPM_RX_AS | SPI_OPM_RX_DOUT | \
-				SPI_OPM_RX_DIO | SPI_OPM_RX_QOF
+				SPI_OPM_RX_DIO | SPI_OPM_RX_QOF | \
+				SPI_OPM_RX_QIOF
 
 /* Header byte that marks the start of the message */
 #define SPI_PREAMBLE_END_BYTE	0xec
include/spi_flash.h +2 -1
index 8e0bb46..99724a0 100644
@@ -28,9 +28,10 @@ enum spi_read_cmds {
 	DUAL_OUTPUT_FAST = 1 << 1,
 	DUAL_IO_FAST = 1 << 2,
 	QUAD_OUTPUT_FAST = 1 << 3,
+	QUAD_IO_FAST = 1 << 4,
 };
 #define RD_EXTN		ARRAY_SLOW | DUAL_OUTPUT_FAST | DUAL_IO_FAST
-#define RD_FULL		RD_EXTN | QUAD_OUTPUT_FAST
+#define RD_FULL		RD_EXTN | QUAD_OUTPUT_FAST | QUAD_IO_FAST
 
 /**
  * struct spi_flash_params - SPI/QSPI flash device params structure
Signature · 1 line
1.8.3
#12 lore raw

PATCH v7 8/17 sf: Discover read dummy_byte

In reply to a message not in the archive

Discovered the read dummy_byte based on the
configured read command.

---
 drivers/mtd/spi/sf_internal.h |  2 ++
 drivers/mtd/spi/sf_ops.c      | 16 +++++++++-------
 drivers/mtd/spi/sf_probe.c    | 19 +++++++++++++++++++
 include/spi_flash.h           |  2 ++
 4 files changed, 32 insertions(+), 7 deletions(-)
drivers/mtd/spi/sf_internal.h +2 -0
index 7be0292..a9f5a81 100644
@@ -10,6 +10,8 @@
 #ifndef _SF_INTERNAL_H_
 #define _SF_INTERNAL_H_
 
+#define SPI_FLASH_3B_ADDR_LEN		3
+#define SPI_FLASH_CMD_LEN		(1 + SPI_FLASH_3B_ADDR_LEN)
 #define SPI_FLASH_16MB_BOUN		0x1000000
 
 /* CFI Manufacture ID's */
drivers/mtd/spi/sf_ops.c +9 -7
index 827f719..6adee32 100644
@@ -9,6 +9,7 @@
  */
 
 #include <common.h>
+#include <malloc.h>
 #include <spi.h>
 #include <spi_flash.h>
 #include <watchdog.h>
@@ -216,7 +217,7 @@ int spi_flash_write_common(struct spi_flash *flash, const u8 *cmd,
 int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len)
 {
 	u32 erase_size;
-	u8 cmd[4];
+	u8 cmd[SPI_FLASH_CMD_LEN];
 	int ret = -1;
 
 	erase_size = flash->erase_size;
@@ -255,7 +256,7 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
 {
 	unsigned long byte_addr, page_size;
 	size_t chunk_len, actual;
-	u8 cmd[4];
+	u8 cmd[SPI_FLASH_CMD_LEN];
 	int ret = -1;
 
 	page_size = flash->page_size;
@@ -317,7 +318,7 @@ int spi_flash_read_common(struct spi_flash *flash, const u8 *cmd,
 int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
 		size_t len, void *data)
 {
-	u8 cmd[5], bank_sel = 0;
+	u8 *cmd, cmdsz, bank_sel = 0;
 	u32 remain_len, read_len;
 	int ret = -1;
 
@@ -335,9 +336,11 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
 		return 0;
 	}
 
-	cmd[0] = flash->read_cmd;
-	cmd[4] = 0x00;
+	cmdsz = SPI_FLASH_CMD_LEN + flash->dummy_byte;
+	cmd = malloc(cmdsz);
+	memset(cmd, 0, cmdsz);
 
+	cmd[0] = flash->read_cmd;
 	while (len) {
 #ifdef CONFIG_SPI_FLASH_BAR
 		bank_sel = offset / SPI_FLASH_16MB_BOUN;
@@ -356,8 +359,7 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
 
 		spi_flash_addr(offset, cmd);
 
-		ret = spi_flash_read_common(flash, cmd, sizeof(cmd),
-							data, read_len);
+		ret = spi_flash_read_common(flash, cmd, cmdsz, data, read_len);
 		if (ret < 0) {
 			debug("SF: read failed\n");
 			break;
drivers/mtd/spi/sf_probe.c +19 -0
index a049e72..8bd06ee 100644
@@ -140,6 +140,25 @@ static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,
 		}
 	}
 
+	/* Read dummy_byte: dummy byte is determined based on the
+	 * dummy cycles of a particular command.
+	 * Fast commands - dummy_byte = dummy_cycles/8
+	 * I/O commands- dummy_byte = (dummy_cycles * no.of lines)/8
+	 * For I/O commands except cmd[0] everything goes on no.of lines
+	 * based on particular command but incase of fast commands except
+	 * data all go on single line irrespective of command.
+	 */
+	switch (flash->read_cmd) {
+	case CMD_READ_QUAD_IO_FAST:
+		flash->dummy_byte = 2;
+		break;
+	case CMD_READ_ARRAY_SLOW:
+		flash->dummy_byte = 0;
+		break;
+	default:
+		flash->dummy_byte = 1;
+	}
+
 	/* Poll cmd seclection */
 	flash->poll_cmd = CMD_READ_STATUS;
 #ifdef CONFIG_SPI_FLASH_STMICRO
include/spi_flash.h +2 -0
index 99724a0..437937c 100644
@@ -72,6 +72,7 @@ extern const struct spi_flash_params spi_flash_params_table[];
  * @erase_cmd:		Erase cmd 4K, 32K, 64K
  * @read_cmd:		Read cmd - Array Fast, Extn read and quad read.
  * @write_cmd:		Write cmd - page and quad program.
+ * @dummy_byte:		Dummy cycles for read operation.
  * @memory_map:		Address of read-only SPI flash access
  * @read:		Flash read ops: Read len bytes at offset into buf
  *			Supported cmds: Fast Array Read
@@ -98,6 +99,7 @@ struct spi_flash {
 	u8 erase_cmd;
 	u8 read_cmd;
 	u8 write_cmd;
+	u8 dummy_byte;
 
 	void *memory_map;
 	int (*read)(struct spi_flash *flash, u32 offset, size_t len, void *buf);
Signature · 1 line
1.8.3
#13 lore raw

PATCH v7 9/17 sf: Add macronix set QEB support

In reply to a message not in the archive

This patch adds set QEB support for macronix flash devices which are trying to program/read quad operations.

---
 drivers/mtd/spi/sf_internal.h |  5 +++++
 drivers/mtd/spi/sf_ops.c      | 26 ++++++++++++++++++++++++++
 drivers/mtd/spi/sf_probe.c    |  4 ++++
 3 files changed, 35 insertions(+)
drivers/mtd/spi/sf_internal.h +5 -0
index a9f5a81..c69b53d 100644
@@ -17,6 +17,7 @@
 /* CFI Manufacture ID's */
 #define SPI_FLASH_CFI_MFR_SPANSION	0x01
 #define SPI_FLASH_CFI_MFR_STMICRO	0x20
+#define SPI_FLASH_CFI_MFR_MACRONIX	0xc2
 #define SPI_FLASH_CFI_MFR_WINBOND	0xef
 
 /* SECT flags */
@@ -61,6 +62,7 @@
 /* Common status */
 #define STATUS_WIP			0x01
 #define STATUS_QEB_WINSPAN		(1 << 1)
+#define STATUS_QEB_MXIC			(1 << 6)
 #define STATUS_PEC			0x80
 
 /* Flash timeout values */
@@ -102,6 +104,9 @@ int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len);
 /* Program the status register */
 int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr);
 
+/* Set quad enbale bit for macronix flashes */
+int spi_flash_set_qeb_mxic(struct spi_flash *flash);
+
 /* Set quad enbale bit for winbond and spansion flashes */
 int spi_flash_set_qeb_winspan(struct spi_flash *flash);
 
drivers/mtd/spi/sf_ops.c +26 -0
index 6adee32..05fbcbd 100644
@@ -39,6 +39,32 @@ int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr)
 	return 0;
 }
 
+#ifdef CONFIG_SPI_FLASH_MACRONIX
+int spi_flash_set_qeb_mxic(struct spi_flash *flash)
+{
+	u8 qeb_status;
+	u8 cmd;
+	int ret;
+
+	cmd = CMD_READ_STATUS;
+	ret = spi_flash_read_common(flash, &cmd, 1, &qeb_status, 1);
+	if (ret < 0) {
+		debug("SF: fail to read status register\n");
+		return ret;
+	}
+
+	if (qeb_status & STATUS_QEB_MXIC) {
+		debug("SF: Quad enable bit is already set\n");
+	} else {
+		ret = spi_flash_cmd_write_status(flash, STATUS_QEB_MXIC);
+		if (ret < 0)
+			return ret;
+	}
+
+	return ret;
+}
+#endif
+
 #if defined(CONFIG_SPI_FLASH_SPANSION) || defined(CONFIG_SPI_FLASH_WINBOND)
 static int spi_flash_cmd_write_config(struct spi_flash *flash, u8 cr)
 {
drivers/mtd/spi/sf_probe.c +4 -0
index 8bd06ee..88d1d0a 100644
@@ -31,6 +31,10 @@ static u8 spi_read_cmds_array[] = {
 static int spi_flash_set_qeb(struct spi_flash *flash, u8 idcode0)
 {
 	switch (idcode0) {
+#ifdef CONFIG_SPI_FLASH_MACRONIX
+	case SPI_FLASH_CFI_MFR_MACRONIX:
+		return spi_flash_set_qeb_mxic(flash);
+#endif
 #if defined(CONFIG_SPI_FLASH_SPANSION) || defined(CONFIG_SPI_FLASH_WINBOND)
 	case SPI_FLASH_CFI_MFR_SPANSION:
 	case SPI_FLASH_CFI_MFR_WINBOND:
Signature · 1 line
1.8.3
#14 lore raw

PATCH v7 10/17 sf: probe: Enable macronix quad read/write cmds support

In reply to a message not in the archive

Added macronix flash quad read/write commands support and it's up to the respective controller driver usecase to configure the respective commands by defining SPI RX/TX operation modes from include/spi.h on the driver.

---
 drivers/mtd/spi/sf_params.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/mtd/spi/sf_params.c +4 -4
index ad101fb..4cdb4c2 100644
@@ -40,10 +40,10 @@ const struct spi_flash_params spi_flash_params_table[] = {
 	{"MX25L1605D",	   0xc22015, 0x0,	64 * 1024,    32,	0,			  0},
 	{"MX25L3205D",	   0xc22016, 0x0,	64 * 1024,    64,	0,			  0},
 	{"MX25L6405D",	   0xc22017, 0x0,	64 * 1024,   128,	0,			  0},
-	{"MX25L12805",	   0xc22018, 0x0,	64 * 1024,   256,	0,			  0},
-	{"MX25L25635F",	   0xc22019, 0x0,	64 * 1024,   512,	0,			  0},
-	{"MX25L51235F",	   0xc2201a, 0x0,	64 * 1024,  1024,	0,			  0},
-	{"MX25L12855E",	   0xc22618, 0x0,	64 * 1024,   256,	0,			  0},
+	{"MX25L12805",	   0xc22018, 0x0,	64 * 1024,   256, RD_FULL,		     WR_QPP},
+	{"MX25L25635F",	   0xc22019, 0x0,	64 * 1024,   512, RD_FULL,		     WR_QPP},
+	{"MX25L51235F",	   0xc2201a, 0x0,	64 * 1024,  1024, RD_FULL,		     WR_QPP},
+	{"MX25L12855E",	   0xc22618, 0x0,	64 * 1024,   256, RD_FULL,		     WR_QPP},
 #endif
 #ifdef CONFIG_SPI_FLASH_SPANSION	/* SPANSION */
 	{"S25FL008A",	   0x010213, 0x0,	64 * 1024,    16,	0,			  0},
Signature · 1 line
1.8.3
#15 lore raw

PATCH v7 11/17 sf: Divide flash register ops from QEB code

In reply to a message not in the archive

QEB code comprises of couple of flash register read/write operations, this patch moved flash register operations on to sf_op

---
 drivers/mtd/spi/sf_internal.h | 11 ++++---
 drivers/mtd/spi/sf_ops.c      | 75 +++++++++++++++----------------------------
 drivers/mtd/spi/sf_probe.c    | 44 +++++++++++++++++++++++++
 3 files changed, 77 insertions(+), 53 deletions(-)
drivers/mtd/spi/sf_internal.h +7 -4
index c69b53d..c77961f 100644
@@ -101,14 +101,17 @@ int spi_flash_cmd_write(struct spi_slave *spi, const u8 *cmd, size_t cmd_len,
 /* Flash erase(sectors) operation, support all possible erase commands */
 int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len);
 
+/* Read the status register */
+int spi_flash_cmd_read_status(struct spi_flash *flash, u8 *rs);
+
 /* Program the status register */
 int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr);
 
-/* Set quad enbale bit for macronix flashes */
-int spi_flash_set_qeb_mxic(struct spi_flash *flash);
+/* Read the config register */
+int spi_flash_cmd_read_config(struct spi_flash *flash, u8 *rc);
 
-/* Set quad enbale bit for winbond and spansion flashes */
-int spi_flash_set_qeb_winspan(struct spi_flash *flash);
+/* Program the config register */
+int spi_flash_cmd_write_config(struct spi_flash *flash, u8 wc);
 
 /* Enable writing on the SPI flash */
 static inline int spi_flash_cmd_write_enable(struct spi_flash *flash)
drivers/mtd/spi/sf_ops.c +26 -49

120 lines not on this page · raw message

drivers/mtd/spi/sf_probe.c +44 -0

50 lines not on this page · raw message

Signature · 1 line
1.8.3
#16 lore raw

PATCH v7 12/17 sf: Code cleanups

In reply to a message not in the archive

- comment typo's
- func args have a proper names

---
 drivers/mtd/spi/sf_internal.h | 11 +++--------
 drivers/mtd/spi/sf_ops.c      |  6 +++---
 drivers/mtd/spi/sf_probe.c    |  4 ++--
 include/spi_flash.h           |  5 ++++-
 4 files changed, 12 insertions(+), 14 deletions(-)
drivers/mtd/spi/sf_internal.h +3 -8
index c77961f..6bcd522 100644
@@ -20,11 +20,6 @@
 #define SPI_FLASH_CFI_MFR_MACRONIX	0xc2
 #define SPI_FLASH_CFI_MFR_WINBOND	0xef
 
-/* SECT flags */
-#define SECT_4K				(1 << 1)
-#define SECT_32K			(1 << 2)
-#define E_FSR				(1 << 3)
-
 /* Erase commands */
 #define CMD_ERASE_4K			0x20
 #define CMD_ERASE_32K			0x52
@@ -60,10 +55,10 @@
 #endif
 
 /* Common status */
-#define STATUS_WIP			0x01
+#define STATUS_WIP			(1 << 0)
 #define STATUS_QEB_WINSPAN		(1 << 1)
 #define STATUS_QEB_MXIC			(1 << 6)
-#define STATUS_PEC			0x80
+#define STATUS_PEC			(1 << 7)
 
 /* Flash timeout values */
 #define SPI_FLASH_PROG_TIMEOUT		(2 * CONFIG_SYS_HZ)
@@ -105,7 +100,7 @@ int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len);
 int spi_flash_cmd_read_status(struct spi_flash *flash, u8 *rs);
 
 /* Program the status register */
-int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr);
+int spi_flash_cmd_write_status(struct spi_flash *flash, u8 ws);
 
 /* Read the config register */
 int spi_flash_cmd_read_config(struct spi_flash *flash, u8 *rc);
drivers/mtd/spi/sf_ops.c +3 -3
index 28527fa..bc4a822 100644
@@ -39,13 +39,13 @@ int spi_flash_cmd_read_status(struct spi_flash *flash, u8 *rs)
 	return 0;
 }
 
-int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr)
+int spi_flash_cmd_write_status(struct spi_flash *flash, u8 ws)
 {
 	u8 cmd;
 	int ret;
 
 	cmd = CMD_WRITE_STATUS;
-	ret = spi_flash_write_common(flash, &cmd, 1, &sr, 1);
+	ret = spi_flash_write_common(flash, &cmd, 1, &ws, 1);
 	if (ret < 0) {
 		debug("SF: fail to write status register\n");
 		return ret;
@@ -279,7 +279,7 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
 
 		spi_flash_addr(offset, cmd);
 
-		debug("PP: 0x%p => cmd = { 0x%02x 0x%02x%02x%02x } chunk_len = %zu\n",
+		debug("SF: 0x%p => cmd = { 0x%02x 0x%02x%02x%02x } chunk_len = %zu\n",
 		      buf + actual, cmd[0], cmd[1], cmd[2], cmd[3], chunk_len);
 
 		ret = spi_flash_write_common(flash, cmd, sizeof(cmd),
drivers/mtd/spi/sf_probe.c +2 -2
index 6b59f2a..ac42b60 100644
@@ -167,7 +167,7 @@ static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,
 		cmd = spi_read_cmds_array[cmd - 1];
 		flash->read_cmd = cmd;
 	} else {
-		/* Go for for default supported read cmd */
+		/* Go for default supported read cmd */
 		flash->read_cmd = CMD_READ_ARRAY_FAST;
 	}
 
@@ -207,7 +207,7 @@ static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,
 		flash->dummy_byte = 1;
 	}
 
-	/* Poll cmd seclection */
+	/* Poll cmd selection */
 	flash->poll_cmd = CMD_READ_STATUS;
 #ifdef CONFIG_SPI_FLASH_STMICRO
 	if (params->flags & E_FSR)
include/spi_flash.h +4 -1
index 437937c..213d659 100644
@@ -19,7 +19,10 @@
 #include <linux/types.h>
 #include <linux/compiler.h>
 
-/* No enum list for write commands only QPP */
+/* sf param flags */
+#define SECT_4K		1 << 1
+#define SECT_32K	1 << 2
+#define E_FSR		1 << 3
 #define WR_QPP		1 << 4
 
 /* Enum list - Full read commands */
Signature · 1 line
1.8.3
#17 lore raw

PATCH v7 13/17 sf: ops: Unify read_ops bank configuration

In reply to a message not in the archive

Unified the bar code from read_ops into a spi_flash_bar()

---
 drivers/mtd/spi/sf_ops.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/mtd/spi/sf_ops.c +5 -8
index bc4a822..7ae9582 100644
@@ -127,7 +127,7 @@ static int spi_flash_bank(struct spi_flash *flash, u32 offset)
 		return ret;
 	}
 
-	return 0;
+	return bank_sel;
 }
 #endif
 
@@ -321,8 +321,9 @@ int spi_flash_read_common(struct spi_flash *flash, const u8 *cmd,
 int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
 		size_t len, void *data)
 {
-	u8 *cmd, cmdsz, bank_sel = 0;
+	u8 *cmd, cmdsz;
 	u32 remain_len, read_len;
+	int bank_sel = 0;
 	int ret = -1;
 
 	/* Handle memory-mapped SPI */
@@ -346,13 +347,9 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
 	cmd[0] = flash->read_cmd;
 	while (len) {
 #ifdef CONFIG_SPI_FLASH_BAR
-		bank_sel = offset / 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);
+		bank_sel = spi_flash_bank(flash, offset);
+		if (bank_sel < 0)
 			return ret;
-		}
 #endif
 		remain_len = (SPI_FLASH_16MB_BOUN * (bank_sel + 1)) - offset;
 		if (len < remain_len)
Signature · 1 line
1.8.3
#18 lore raw

PATCH v7 14/17 sf: Add dual memories support - DUAL_STACKED

In reply to a message not in the archive

This patch added support for accessing dual memories in stacked connection with single chipselect line from controller.

For more info - see doc/SPI/README.dual-flash

---
 doc/SPI/README.dual-flash  | 65 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/mtd/spi/sf.c       |  3 +++
 drivers/mtd/spi/sf_ops.c   | 57 +++++++++++++++++++++++++++++++++-------
 drivers/mtd/spi/sf_probe.c |  8 +++++-
 include/spi.h              |  8 ++++++
 include/spi_flash.h        |  8 ++++++
 6 files changed, 138 insertions(+), 11 deletions(-)
 create mode 100644 doc/SPI/README.dual-flash
doc/SPI/README.dual-flash new file +65 -0
new file mode 100644
index 0000000..ba0aa26
@@ -0,0 +1,65 @@
+SPI/QSPI Dual flash connection modes:
+=====================================
+
+This describes how SPI/QSPI flash memories are connected to a given
+controller in a single chip select line.
+
+Current spi_flash framework supports, single flash memory connected
+to a given controller with single chip select line, but there are some
+hw logics(ex: xilinx zynq qspi) that describes two/dual memories are
+connected with a single chip select line from a controller.
+
+"dual_flash" from include/spi.h describes these types of connection mode
+
+Possible connections:
+--------------------
+SF_SINGLE_FLASH:
+       - single spi flash memory connected with single chip select line.
+
+  +------------+             CS         +---------------+
+  |            |----------------------->|               |
+  | Controller |         I0[3:0]        | Flash memory  |
+  | SPI/QSPI   |<======================>| (SPI/QSPI)    |
+  |            |           CLK          |               |
+  |            |----------------------->|               |
+  +------------+                        +---------------+
+
+SF_DUAL_STACKED_FLASH:
+       - 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 [1]
+
+  +------------+        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 should 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.
+
+[1] http://www.xilinx.com/support/documentation/user_guides/ug585-Zynq-7000-TRM.pdf
+
+--
+Jagannadha Sutradharudu Teki <[email protected]>
+05-01-2014.
drivers/mtd/spi/sf.c +3 -0
index d5e175c..c780a81 100644
@@ -18,6 +18,9 @@ static int spi_flash_read_write(struct spi_slave *spi,
 	unsigned long flags = SPI_XFER_BEGIN;
 	int ret;
 
+	if (spi->flags & SPI_XFER_U_PAGE)
+		flags |= SPI_XFER_U_PAGE;
+
 	if (data_len == 0)
 		flags |= SPI_XFER_END;
 
drivers/mtd/spi/sf_ops.c +47 -10

129 lines not on this page · raw message

drivers/mtd/spi/sf_probe.c +7 -1
index ac42b60..b9e14c5 100644
@@ -134,6 +134,7 @@ static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,
 	flash->spi = spi;
 	flash->name = params->name;
 	flash->memory_map = spi->memory_map;
+	flash->dual_flash = flash->spi->option;
 
 	/* Assign spi_flash ops */
 	flash->write = spi_flash_cmd_write_ops;
@@ -148,6 +149,8 @@ static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,
 	flash->page_size = (ext_jedec == 0x4d00) ? 512 : 256;
 	flash->sector_size = params->sector_size;
 	flash->size = flash->sector_size * params->nr_sectors;
+	if (flash->dual_flash & SF_DUAL_STACKED_FLASH)
+		flash->size <<= 1;
 
 	/* Compute erase sector and command */
 	if (params->flags & SECT_4K) {
@@ -324,7 +327,10 @@ static struct spi_flash *spi_flash_probe_slave(struct spi_slave *spi)
 	puts("\n");
 #endif
 #ifndef CONFIG_SPI_FLASH_BAR
-	if (flash->size > SPI_FLASH_16MB_BOUN) {
+	if (((flash->dual_flash == SF_SINGLE_FLASH) &&
+	     (flash->size > SPI_FLASH_16MB_BOUN)) ||
+	     ((flash->dual_flash > SF_SINGLE_FLASH) &&
+	     (flash->size > SPI_FLASH_16MB_BOUN << 1))) {
 		puts("SF: Warning - Only lower 16MiB accessible,");
 		puts(" Full access #define CONFIG_SPI_FLASH_BAR\n");
 	}
include/spi.h +8 -0
index c8a9d87..d214d82 100644
@@ -30,6 +30,7 @@
 #define SPI_XFER_MMAP		0x08	/* Memory Mapped start */
 #define SPI_XFER_MMAP_END	0x10	/* Memory Mapped End */
 #define SPI_XFER_ONCE		(SPI_XFER_BEGIN | SPI_XFER_END)
+#define SPI_XFER_U_PAGE		(1 << 5)
 
 /* SPI TX operation modes */
 #define SPI_OPM_TX_QPP		1 << 0
@@ -44,6 +45,9 @@
 				SPI_OPM_RX_DIO | SPI_OPM_RX_QOF | \
 				SPI_OPM_RX_QIOF
 
+/* SPI bus connection options */
+#define SPI_CONN_DUAL_SHARED	1 << 0
+
 /* Header byte that marks the start of the message */
 #define SPI_PREAMBLE_END_BYTE	0xec
 
@@ -62,6 +66,8 @@
  * @max_write_size:	If non-zero, the maximum number of bytes which can
  *			be written@once, excluding command bytes.
  * @memory_map:		Address of read-only SPI flash access.
+ * @option:		Varies SPI bus options - separate bus.
+ * @flags:		Indication of SPI flags.
  */
 struct spi_slave {
 	unsigned int bus;
@@ -71,6 +77,8 @@ struct spi_slave {
 	unsigned int wordlen;
 	unsigned int max_write_size;
 	void *memory_map;
+	u8 option;
+	u8 flags;
 };
 
 /**
include/spi_flash.h +8 -0
index 213d659..36f1f03 100644
@@ -36,6 +36,12 @@ enum spi_read_cmds {
 #define RD_EXTN		ARRAY_SLOW | DUAL_OUTPUT_FAST | DUAL_IO_FAST
 #define RD_FULL		RD_EXTN | QUAD_OUTPUT_FAST | QUAD_IO_FAST
 
+/* Dual SPI flash memories */
+enum spi_dual_flash {
+	SF_SINGLE_FLASH = 0,
+	SF_DUAL_STACKED_FLASH = 1 << 0,
+};
+
 /**
  * struct spi_flash_params - SPI/QSPI flash device params structure
  *
@@ -64,6 +70,7 @@ extern const struct spi_flash_params spi_flash_params_table[];
  *
  * @spi:		SPI slave
  * @name:		Name of SPI flash
+ * @dual_flash:		Indicates dual flash memories - dual stacked
  * @size:		Total flash size
  * @page_size:		Write (page) size
  * @sector_size:	Sector size
@@ -88,6 +95,7 @@ extern const struct spi_flash_params spi_flash_params_table[];
 struct spi_flash {
 	struct spi_slave *spi;
 	const char *name;
+	u8 dual_flash;
 
 	u32 size;
 	u32 page_size;
Signature · 1 line
1.8.3
#19 lore raw

PATCH v7 15/17 sf: Add dual memories support - DUAL_PARALLEL

In reply to a message not in the archive

This patch added support for accessing dual memories in parallel connection with single chipselect line from controller.

For more info - see doc/SPI/README.dual-flash

---
 doc/SPI/README.dual-flash  | 27 +++++++++++++++++++++++++++
 drivers/mtd/spi/sf_ops.c   |  8 ++++++--
 drivers/mtd/spi/sf_probe.c | 11 ++++++-----
 include/spi.h              |  3 ++-
 include/spi_flash.h        |  5 ++++-
 5 files changed, 45 insertions(+), 9 deletions(-)
doc/SPI/README.dual-flash +27 -0
index ba0aa26..6c88d65 100644
@@ -54,6 +54,33 @@ SF_DUAL_STACKED_FLASH:
                by default, if U_PAGE is unset lower memory should accessible,
                once user wants to access upper memory need to set U_PAGE.
 
+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 [1]
+
+  +-------------+           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.
drivers/mtd/spi/sf_ops.c +6 -2
index e877858..843f379 100644
@@ -119,7 +119,7 @@ static int spi_flash_bank(struct spi_flash *flash, u32 offset)
 	u8 bank_sel;
 	int ret;
 
-	bank_sel = offset / SPI_FLASH_16MB_BOUN;
+	bank_sel = offset / (SPI_FLASH_16MB_BOUN << flash->shift);
 
 	ret = spi_flash_cmd_bankaddr_write(flash, bank_sel);
 	if (ret) {
@@ -142,6 +142,9 @@ static void spi_flash_dual_flash(struct spi_flash *flash, u32 *addr)
 			flash->spi->flags &= ~SPI_XFER_U_PAGE;
 		}
 		break;
+	case SF_DUAL_PARALLEL_FLASH:
+		*addr >>= flash->shift;
+		break;
 	default:
 		debug("SF: Unsupported dual_flash=%d\n", flash->dual_flash);
 		break;
@@ -388,7 +391,8 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
 		if (bank_sel < 0)
 			return ret;
 #endif
-		remain_len = (SPI_FLASH_16MB_BOUN * (bank_sel + 1)) - offset;
+		remain_len = ((SPI_FLASH_16MB_BOUN << flash->shift) *
+				(bank_sel + 1)) - offset;
 		if (len < remain_len)
 			read_len = len;
 		else
drivers/mtd/spi/sf_probe.c +6 -5
index b9e14c5..48de7c1 100644
@@ -146,19 +146,20 @@ static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,
 	flash->read = spi_flash_cmd_read_ops;
 
 	/* Compute the flash size */
-	flash->page_size = (ext_jedec == 0x4d00) ? 512 : 256;
-	flash->sector_size = params->sector_size;
-	flash->size = flash->sector_size * params->nr_sectors;
+	flash->shift = (flash->dual_flash & SF_DUAL_PARALLEL_FLASH) ? 1 : 0;
+	flash->page_size = ((ext_jedec == 0x4d00) ? 512 : 256) << flash->shift;
+	flash->sector_size = params->sector_size << flash->shift;
+	flash->size = flash->sector_size * params->nr_sectors << flash->shift;
 	if (flash->dual_flash & SF_DUAL_STACKED_FLASH)
 		flash->size <<= 1;
 
 	/* Compute erase sector and command */
 	if (params->flags & SECT_4K) {
 		flash->erase_cmd = CMD_ERASE_4K;
-		flash->erase_size = 4096;
+		flash->erase_size = 4096 << flash->shift;
 	} else if (params->flags & SECT_32K) {
 		flash->erase_cmd = CMD_ERASE_32K;
-		flash->erase_size = 32768;
+		flash->erase_size = 32768 << flash->shift;
 	} else {
 		flash->erase_cmd = CMD_ERASE_64K;
 		flash->erase_size = flash->sector_size;
include/spi.h +2 -1
index d214d82..ffd6647 100644
@@ -47,6 +47,7 @@
 
 /* SPI bus connection options */
 #define SPI_CONN_DUAL_SHARED	1 << 0
+#define SPI_CONN_DUAL_SEPARATED	1 << 1
 
 /* Header byte that marks the start of the message */
 #define SPI_PREAMBLE_END_BYTE	0xec
@@ -66,7 +67,7 @@
  * @max_write_size:	If non-zero, the maximum number of bytes which can
  *			be written@once, excluding command bytes.
  * @memory_map:		Address of read-only SPI flash access.
- * @option:		Varies SPI bus options - separate bus.
+ * @option:		Varies SPI bus options - separate, shared bus.
  * @flags:		Indication of SPI flags.
  */
 struct spi_slave {
include/spi_flash.h +4 -1
index 36f1f03..f79f0ea 100644
@@ -40,6 +40,7 @@ enum spi_read_cmds {
 enum spi_dual_flash {
 	SF_SINGLE_FLASH = 0,
 	SF_DUAL_STACKED_FLASH = 1 << 0,
+	SF_DUAL_PARALLEL_FLASH = 1 << 1,
 };
 
 /**
@@ -70,7 +71,8 @@ extern const struct spi_flash_params spi_flash_params_table[];
  *
  * @spi:		SPI slave
  * @name:		Name of SPI flash
- * @dual_flash:		Indicates dual flash memories - dual stacked
+ * @dual_flash:		Indicates dual flash memories - dual stacked, parallel
+ * @shift:		Flash shift useful in dual parallel
  * @size:		Total flash size
  * @page_size:		Write (page) size
  * @sector_size:	Sector size
@@ -96,6 +98,7 @@ struct spi_flash {
 	struct spi_slave *spi;
 	const char *name;
 	u8 dual_flash;
+	u8 shift;
 
 	u32 size;
 	u32 page_size;
Signature · 1 line
1.8.3
#20 lore raw

PATCH v7 16/17 sf: Add CONFIG_SF_DUAL_FLASH

In reply to a message not in the archive

This config will use for defining greater than single flash support. currently - DUAL_STACKED and DUAL_PARALLEL.

---
 README                     |  6 ++++++
 drivers/mtd/spi/sf.c       |  3 ++-
 drivers/mtd/spi/sf_ops.c   | 14 ++++++++++----
 drivers/mtd/spi/sf_probe.c |  2 ++
 4 files changed, 20 insertions(+), 5 deletions(-)
README +6 -0
index a0646c3..aea82be 100644
@@ -2756,6 +2756,12 @@ CBFS (Coreboot Filesystem) support
 		Define this option to use the Bank addr/Extended addr
 		support on SPI flashes which has size > 16Mbytes.
 
+		CONFIG_SF_DUAL_FLASH		Dual flash memories
+
+		Define this option to use dual flash support where two flash
+		memories can be connected with a given cs line.
+		currently Xilinx Zynq qspi support these type of connections.
+
 - SystemACE Support:
 		CONFIG_SYSTEMACE
 
drivers/mtd/spi/sf.c +2 -1
index c780a81..664e860 100644
@@ -18,9 +18,10 @@ static int spi_flash_read_write(struct spi_slave *spi,
 	unsigned long flags = SPI_XFER_BEGIN;
 	int ret;
 
+#ifdef CONFIG_SF_DUAL_FLASH
 	if (spi->flags & SPI_XFER_U_PAGE)
 		flags |= SPI_XFER_U_PAGE;
-
+#endif
 	if (data_len == 0)
 		flags |= SPI_XFER_END;
 
drivers/mtd/spi/sf_ops.c +10 -4
index 843f379..1f1bb36 100644
@@ -131,6 +131,7 @@ static int spi_flash_bank(struct spi_flash *flash, u32 offset)
 }
 #endif
 
+#ifdef CONFIG_SF_DUAL_FLASH
 static void spi_flash_dual_flash(struct spi_flash *flash, u32 *addr)
 {
 	switch (flash->dual_flash) {
@@ -150,6 +151,7 @@ static void spi_flash_dual_flash(struct spi_flash *flash, u32 *addr)
 		break;
 	}
 }
+#endif
 
 int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)
 {
@@ -167,9 +169,10 @@ int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)
 		check_status = poll_bit;
 	}
 
+#ifdef CONFIG_SF_DUAL_FLASH
 	if (spi->flags & SPI_XFER_U_PAGE)
 		flags |= SPI_XFER_U_PAGE;
-
+#endif
 	ret = spi_xfer(spi, 8, &cmd, NULL, flags);
 	if (ret) {
 		debug("SF: fail to read %s status register\n",
@@ -257,9 +260,10 @@ int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len)
 	while (len) {
 		erase_addr = offset;
 
+#ifdef CONFIG_SF_DUAL_FLASH
 		if (flash->dual_flash > SF_SINGLE_FLASH)
 			spi_flash_dual_flash(flash, &erase_addr);
-
+#endif
 #ifdef CONFIG_SPI_FLASH_BAR
 		ret = spi_flash_bank(flash, erase_addr);
 		if (ret < 0)
@@ -298,9 +302,10 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
 	for (actual = 0; actual < len; actual += chunk_len) {
 		write_addr = offset;
 
+#ifdef CONFIG_SF_DUAL_FLASH
 		if (flash->dual_flash > SF_SINGLE_FLASH)
 			spi_flash_dual_flash(flash, &write_addr);
-
+#endif
 #ifdef CONFIG_SPI_FLASH_BAR
 		ret = spi_flash_bank(flash, write_addr);
 		if (ret < 0)
@@ -383,9 +388,10 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
 	while (len) {
 		read_addr = offset;
 
+#ifdef CONFIG_SF_DUAL_FLASH
 		if (flash->dual_flash > SF_SINGLE_FLASH)
 			spi_flash_dual_flash(flash, &read_addr);
-
+#endif
 #ifdef CONFIG_SPI_FLASH_BAR
 		bank_sel = spi_flash_bank(flash, read_addr);
 		if (bank_sel < 0)
drivers/mtd/spi/sf_probe.c +2 -0
index 48de7c1..bc3cf6c 100644
@@ -150,8 +150,10 @@ static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,
 	flash->page_size = ((ext_jedec == 0x4d00) ? 512 : 256) << flash->shift;
 	flash->sector_size = params->sector_size << flash->shift;
 	flash->size = flash->sector_size * params->nr_sectors << flash->shift;
+#ifdef CONFIG_SF_DUAL_FLASH
 	if (flash->dual_flash & SF_DUAL_STACKED_FLASH)
 		flash->size <<= 1;
+#endif
 
 	/* Compute erase sector and command */
 	if (params->flags & SECT_4K) {
Signature · 1 line
1.8.3
#21 lore raw

PATCH v7 17/17 doc: SPI: Update status.txt

In reply to a message not in the archive

Updated current SPI subsyetem status.

---
 doc/SPI/status.txt | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
doc/SPI/status.txt +6 -5
index 62c3c85..13889f5 100644
@@ -11,6 +11,11 @@ SPI FLASH (drivers/mtd/spi):
 - Bank Address Register (Accessing flashes > 16Mbytes in 3-byte addressing)
 - Added memory_mapped support for read operations.
 - Common probe support for all supported flash vendors except, ramtron.
+- Extended read commands support(dual read, dual IO read)
+- Quad Page Program support.
+- Quad Read support(quad fast read, quad IO read)
+- Dual flash connection topology support(accessing two spi flash memories with single cs)
+- Banking support on dual flash connection topology.
 
 SPI DRIVERS (drivers/spi):
 -
@@ -18,14 +23,10 @@ SPI DRIVERS (drivers/spi):
 TODO:
 - Runtime detection of spi_flash params, SFDP(if possible)
 - Add support for multibus build/accessing.
-- Extended read commands support(dual read, dual IO read)
-- Quad Page Program support.
-- Quad Read support(quad fast read, quad IO read)
-- Dual flash connection topology support(accessing two spi flash memories with single cs)
-- Banking support on dual flash connection topology.
 - Need proper cleanups on spi_flash and drivers.
 
 --
 Jagannadha Sutradharudu Teki <[email protected]>
 18-09-2013.
 07-10-2013.
+08-01-2014.
Signature · 1 line
1.8.3