Skip to contentSkip to conversation

mtd: spi-nor: Add support for S3AN spi-nor devices

PATCH Superseded Ricardo Ribalda Delgado 2 participants 3 messages May 11, 2016 – Jul 14, 2016

Subsystems (2)

v3 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 mtd: spi-nor: Add support for S3AN spi-nor devices

Xilinx Spartan-3AN FPGAs contain an In-System Flash where they keep their configuration data and (optionally) some user data.

The protocol of this flash follows most of the spi-nor standard. With the following differences:

- Page size might not be a power of two.
- The address calculation (default addressing mode).
- The spi nor commands used.

Protocol is described on Xilinx User Guide UG333

---

v3:
-Rebase on top of mtd-next
-Rename ADDR_NATIVE to ADDR_DEFAULT to follow UG333 naming -Fix bug on probe

v2: Suggested by Brian Norris <[email protected]>

-Remove inline qualifier
-Improve documentation of Default Addressing Mode
-Convert function callbacks into SNOR_F_
-Fix missmatch braces
-Improve documentation of SPI_S3AN flag

 drivers/mtd/devices/m25p80.c  |   3 ++
 drivers/mtd/spi-nor/spi-nor.c | 110 ++++++++++++++++++++++++++++++++++++++++--
 include/linux/mtd/spi-nor.h   |  26 ++++++++++
 3 files changed, 136 insertions(+), 3 deletions(-)
drivers/mtd/devices/m25p80.c +3 -0
index 9d6854467651..cc5363301252 100644
@@ -49,6 +49,9 @@ static int m25p80_read_reg(struct spi_nor *nor, u8 code, u8 *val, int len)
 
 static void m25p_addr2cmd(struct spi_nor *nor, unsigned int addr, u8 *cmd)
 {
+	if (nor->flags & SNOR_F_S3AN_ADDR_DEFAULT)
+		addr = spi_nor_s3an_addr_convert(nor, addr);
+
 	/* opcode is in cmd[0] */
 	cmd[1] = addr >> (nor->addr_width * 8 -  8);
 	cmd[2] = addr >> (nor->addr_width * 8 - 16);
drivers/mtd/spi-nor/spi-nor.c +107 -3

176 lines not on this page · raw message

include/linux/mtd/spi-nor.h +26 -0
index 7f041bd88b82..42977c0c9435 100644
@@ -68,6 +68,15 @@
 #define SPINOR_OP_WRDI		0x04	/* Write disable */
 #define SPINOR_OP_AAI_WP	0xad	/* Auto address increment word program */
 
+/* Used for S3AN flashes only */
+#define SPINOR_OP_XSE		0x50	/* Sector erase */
+#define SPINOR_OP_XPP		0x82	/* Page program */
+#define SPINOR_OP_XRDSR		0xd7	/* Read status register */
+
+#define XSR_PAGESIZE		BIT(0)	/* Page size in Po2 or Linear */
+#define XSR_RDY			BIT(7)	/* Ready */
+
+
 /* Used for Macronix and Winbond flashes. */
 #define SPINOR_OP_EN4B		0xb7	/* Enter 4-byte mode */
 #define SPINOR_OP_EX4B		0xe9	/* Exit 4-byte mode */
@@ -119,6 +128,9 @@ enum spi_nor_ops {
 enum spi_nor_option_flags {
 	SNOR_F_USE_FSR		= BIT(0),
 	SNOR_F_HAS_SR_TB	= BIT(1),
+	SNOR_F_NO_OP_CHIP_ERASE	= BIT(2),
+	SNOR_F_S3AN_ADDR_DEFAULT = BIT(3),
+	SNOR_F_READY_XSR_RDY	= BIT(4),
 };
 
 /**
@@ -197,6 +209,20 @@ static inline struct device_node *spi_nor_get_flash_node(struct spi_nor *nor)
 	return mtd_get_of_node(&nor->mtd);
 }
 
+
+/**
+ * spi_nor_s3an_addr_convert() - convert an address to Default Address Mode
+ * @nor:	the spi_nor structure
+ * @addr:	the contiguous address value
+ *
+ * Spartan-3AN In-System Flash requires an special address mode to access its
+ * whole Flash area. This address mode, named Default Address Mode by Xilinx,
+ * has non power of two page sizes.
+ *
+ * Return: Address in Default Address Mode
+ */
+unsigned int spi_nor_s3an_addr_convert(struct spi_nor *nor, unsigned int addr);
+
 /**
  * spi_nor_scan() - scan the SPI NOR
  * @nor:	the spi_nor structure
Signature · 1 line
2.8.0.rc3
#1 lore raw
Quoted 22 lines · Ricardo Ribalda Delgado

Xilinx Spartan-3AN FPGAs contain an In-System Flash where they keep their configuration data and (optionally) some user data.

The protocol of this flash follows most of the spi-nor standard. With the following differences:

- Page size might not be a power of two.
- The address calculation (default addressing mode).
- The spi nor commands used.

Protocol is described on Xilinx User Guide UG333

---

v3:

(quoted diff) +0 -3
-Rebase on top of mtd-next
-Rename ADDR_NATIVE to ADDR_DEFAULT to follow UG333 naming
-Fix bug on probe

v2: Suggested by Brian Norris <[email protected]>

Review

Quoted 10 lines
(quoted diff) +0 -5
-Remove inline qualifier
-Improve documentation of Default Addressing Mode
-Convert function callbacks into SNOR_F_
-Fix missmatch braces
-Improve documentation of SPI_S3AN flag
 
 drivers/mtd/devices/m25p80.c  |   3 ++
 drivers/mtd/spi-nor/spi-nor.c | 110 ++++++++++++++++++++++++++++++++++++++++--
 include/linux/mtd/spi-nor.h   |  26 ++++++++++
 3 files changed, 136 insertions(+), 3 deletions(-)

This still doesn't apply to l2-mtd.git / linux-next.git. If I get time, I'll see how easily I can fix that up myself.

#2 lore raw

Hi Brian:

On Thu, Jul 14, 2016 at 8:07 PM, Brian Norris
<[email protected]> wrote:)

Quoted 4 lines

This still doesn't apply to l2-mtd.git / linux-next.git. If I get time, I'll see how easily I can fix that up myself.

v3 was from May 11.

I have just updated a V4 rebased over l2-mtd/master.

Thanks

Signature · 1 line
Ricardo Ribalda