Skip to contentSkip to conversation

spi/sf: Updates on flash detection

PATCH Superseded Jagan Teki 4 participants 18 messages Aug 9, 2016 – Aug 10, 2016

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Jagan Teki

author
#0 lore raw

v2 cover spi/sf: Updates on flash detection

Updated spi_flash_info table in sync with Linux, and removed legacy and unsupported code.

Changes for v2:
- New patches.

Jagan Teki (22):
sf: Simplify fastest read cmd code
sf: Remove e_rd_cmd from param table
spi: Use mode for rx mode flags
sf: Remove SECT_32K
sf: Add CONFIG_SPI_FLASH_USE_4K_SECTORS in spi_flash
sf: Move flags macro's to spi_flash_params{} members
sf: Adopt flash table INFO macro from Linux
sf: Add JEDEC_ID and JEDEC_EXT macro
sf: Rename spi_flash_params => spi_flash_info
sf: Add JEDEC_MFR
sf: Simplify lock ops detection code
sf: sandbox: Fix ID exctract from spi_flash_info
sf: Cleanup spi_flash_info{}
sf: Cleanup sf_params
sf: nr_sectors -> n_sectors
sf: Add SPI_FLASH_MAX_ID_LEN
sf: Increase max id length by 1 byte
sf: Add INFO6 flash_info macro
sf: params: Add S25FS256S_64K spi flash support
sf: Remove legacy idcode detection code
sf: Remove non-meaningful comments
sf: Rename sf_params.c to spi_flash_ids

 drivers/mtd/spi/Makefile        |   2 +-
 drivers/mtd/spi/sandbox.c       |   9 +-
 drivers/mtd/spi/sf_internal.h   |  95 +++++++---------
 drivers/mtd/spi/sf_params.c     | 238 +++++++++++++++++++++------------------
 drivers/mtd/spi/spi_flash.c     | 240 ++++++++++++----------------------------
 drivers/mtd/spi/spi_flash_ids.c | 176 +++++++++++++++++++++++++++++
 drivers/spi/cadence_qspi.c      |   2 +-
 drivers/spi/ich.c               |   6 +-
 drivers/spi/spi-uclass.c        |  11 +-
 drivers/spi/ti_qspi.c           |   6 +-
 include/linux/err.h             |   5 +
 include/spi.h                   |  14 +--
 12 files changed, 444 insertions(+), 360 deletions(-)
 create mode 100644 drivers/mtd/spi/spi_flash_ids.c
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v2 1/22 sf: Simplify fastest read cmd code

Fastest read command code look for fastest read command taking inputs from spi->mode_rx and flags from param table and controller mode_rx is always been a priority.

Since mode_rx is always set from controller side this optimized code doesn't require much and this code required exctra overhead like
1) Maintain e_rx_cmd in param table
2) Maintain mode_rx in spi_slave {}

Hence removed this code, and look for read command from normal spi->mode from spi_slave{} and params->flags

Cc Simon Glass <[email protected]>
Cc Bin Meng <[email protected]>
Cc Michal Simek <[email protected]>
Cc Siva Durga Prasad Paladugu <[email protected]>
Cc Vignesh R <[email protected]>
Cc Mugunthan V N <[email protected]>
---
 drivers/mtd/spi/sf_internal.h |  4 ++++
 drivers/mtd/spi/spi_flash.c   | 28 ++++++++++------------------
 2 files changed, 14 insertions(+), 18 deletions(-)
drivers/mtd/spi/sf_internal.h +4 -0
index da2bb7b..c5cb791 100644
@@ -46,6 +46,10 @@ enum {
 	E_FSR		= BIT(2),
 	SST_WR		= BIT(3),
 	WR_QPP		= BIT(4),
+	RD_QUAD		= BIT(5),
+	RD_DUAL		= BIT(6),
+	RD_QUADIO	= BIT(7),
+	RD_DUALIO	= BIT(8),
 };
 
 enum spi_nor_option_flags {
drivers/mtd/spi/spi_flash.c +10 -18
index 64d4e0f..5fd408c 100644
@@ -1013,15 +1013,8 @@ int spi_flash_scan(struct spi_flash *flash)
 	struct spi_slave *spi = flash->spi;
 	const struct spi_flash_params *params;
 	u16 jedec, ext_jedec;
-	u8 cmd, idcode[5];
+	u8 idcode[5];
 	int ret;
-	static u8 spi_read_cmds_array[] = {
-		CMD_READ_ARRAY_SLOW,
-		CMD_READ_ARRAY_FAST,
-		CMD_READ_DUAL_OUTPUT_FAST,
-		CMD_READ_QUAD_OUTPUT_FAST,
-		CMD_READ_DUAL_IO_FAST,
-		CMD_READ_QUAD_IO_FAST };
 
 	/* Read the ID codes */
 	ret = spi_flash_cmd(spi, CMD_READ_ID, idcode, sizeof(idcode));
@@ -1177,17 +1170,16 @@ int spi_flash_scan(struct spi_flash *flash)
 	/* Now erase size becomes valid sector size */
 	flash->sector_size = flash->erase_size;
 
-	/* Look for the fastest read cmd */
-	cmd = fls(params->e_rd_cmd & spi->mode_rx);
-	if (cmd) {
-		cmd = spi_read_cmds_array[cmd - 1];
-		flash->read_cmd = cmd;
-	} else {
-		/* Go for default supported read cmd */
-		flash->read_cmd = CMD_READ_ARRAY_FAST;
-	}
+	/* Look for read commands */
+	flash->read_cmd = CMD_READ_ARRAY_FAST;
+	if (spi->mode_rx & SPI_RX_SLOW)
+		flash->read_cmd = CMD_READ_ARRAY_SLOW;
+	else if (spi->mode_rx & SPI_RX_QUAD && params->flags & RD_QUAD)
+		flash->read_cmd = CMD_READ_QUAD_OUTPUT_FAST;
+	else if (spi->mode_rx & SPI_RX_DUAL && params->flags & RD_DUAL)
+		flash->read_cmd = CMD_READ_DUAL_OUTPUT_FAST;
 
-	/* Not require to look for fastest only two write cmds yet */
+	/* Look for write commands */
 	if (params->flags & WR_QPP && spi->mode & SPI_TX_QUAD)
 		flash->write_cmd = CMD_QUAD_PAGE_PROGRAM;
 	else
Signature · 1 line
2.7.4
author
#2 lore raw

PATCH v2 2/22 sf: Remove e_rd_cmd from param table

In reply to Jagan Teki

e_rd_cmd is maintained separately for fastest read command code, since the read commands are computed normally this e_rd_cmd is not required in spi_flash_params table.

Cc Simon Glass <[email protected]>
Cc Bin Meng <[email protected]>
Cc Michal Simek <[email protected]>
Cc Siva Durga Prasad Paladugu <[email protected]>
Cc Vignesh R <[email protected]>
Cc Mugunthan V N <[email protected]>
---
 drivers/mtd/spi/sf_internal.h |  18 +---
 drivers/mtd/spi/sf_params.c   | 200 +++++++++++++++++++++---------------------
 2 files changed, 101 insertions(+), 117 deletions(-)
drivers/mtd/spi/sf_internal.h +1 -17
index c5cb791..71ba1a6 100644
@@ -20,21 +20,6 @@ enum spi_dual_flash {
 	SF_DUAL_PARALLEL_FLASH	= BIT(1),
 };
 
-/* Enum list - Full read commands */
-enum spi_read_cmds {
-	ARRAY_SLOW		= BIT(0),
-	ARRAY_FAST		= BIT(1),
-	DUAL_OUTPUT_FAST	= BIT(2),
-	QUAD_OUTPUT_FAST	= BIT(3),
-	DUAL_IO_FAST		= BIT(4),
-	QUAD_IO_FAST		= BIT(5),
-};
-
-/* Normal - Extended - Full command set */
-#define RD_NORM		(ARRAY_SLOW | ARRAY_FAST)
-#define RD_EXTN		(RD_NORM | DUAL_OUTPUT_FAST | DUAL_IO_FAST)
-#define RD_FULL		(RD_EXTN | QUAD_OUTPUT_FAST | QUAD_IO_FAST)
-
 /* sf param flags */
 enum {
 #ifndef CONFIG_SPI_FLASH_USE_4K_SECTORS
@@ -51,6 +36,7 @@ enum {
 	RD_QUADIO	= BIT(7),
 	RD_DUALIO	= BIT(8),
 };
+#define RD_FULL		RD_QUAD | RD_DUAL | RD_QUADIO | RD_DUALIO
 
 enum spi_nor_option_flags {
 	SNOR_F_SST_WR		= BIT(0),
@@ -145,7 +131,6 @@ int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,
  * @sector_size:	Isn't necessarily a sector size from vendor,
  *			the size listed here is what works with CMD_ERASE_64K
  * @nr_sectors:		No.of sectors on this device
- * @e_rd_cmd:		Enum list for read commands
  * @flags:		Important param, for flash specific behaviour
  */
 struct spi_flash_params {
@@ -154,7 +139,6 @@ struct spi_flash_params {
 	u16 ext_jedec;
 	u32 sector_size;
 	u32 nr_sectors;
-	u8 e_rd_cmd;
 	u16 flags;
 };
 
drivers/mtd/spi/sf_params.c +100 -100

222 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#3 lore raw

PATCH v2 3/22 spi: Use mode for rx mode flags

In reply to Jagan Teki

Make rx mode flags as generic to spi, earlier mode_rx is maintained separately becuase of some flash specific code.

Cc Simon Glass <[email protected]>
Cc Bin Meng <[email protected]>
Cc Michal Simek <[email protected]>
Cc Siva Durga Prasad Paladugu <[email protected]>
Cc Vignesh R <[email protected]>
Cc Mugunthan V N <[email protected]>
---
 drivers/mtd/spi/spi_flash.c |  6 +++---
 drivers/spi/cadence_qspi.c  |  2 +-
 drivers/spi/ich.c           |  6 ++----
 drivers/spi/spi-uclass.c    | 11 ++++-------
 drivers/spi/ti_qspi.c       |  6 +++---
 include/spi.h               | 14 ++++----------
 6 files changed, 17 insertions(+), 28 deletions(-)
drivers/mtd/spi/spi_flash.c +3 -3
index 5fd408c..041b64f 100644
@@ -1172,11 +1172,11 @@ int spi_flash_scan(struct spi_flash *flash)
 
 	/* Look for read commands */
 	flash->read_cmd = CMD_READ_ARRAY_FAST;
-	if (spi->mode_rx & SPI_RX_SLOW)
+	if (spi->mode & SPI_RX_SLOW)
 		flash->read_cmd = CMD_READ_ARRAY_SLOW;
-	else if (spi->mode_rx & SPI_RX_QUAD && params->flags & RD_QUAD)
+	else if (spi->mode & SPI_RX_QUAD && params->flags & RD_QUAD)
 		flash->read_cmd = CMD_READ_QUAD_OUTPUT_FAST;
-	else if (spi->mode_rx & SPI_RX_DUAL && params->flags & RD_DUAL)
+	else if (spi->mode & SPI_RX_DUAL && params->flags & RD_DUAL)
 		flash->read_cmd = CMD_READ_DUAL_OUTPUT_FAST;
 
 	/* Look for write commands */
drivers/spi/cadence_qspi.c +1 -1
index a5244ff..1d50f13 100644
@@ -251,7 +251,7 @@ static int cadence_spi_xfer(struct udevice *dev, unsigned int bitlen,
 		break;
 		case CQSPI_INDIRECT_READ:
 			err = cadence_qspi_apb_indirect_read_setup(plat,
-				priv->cmd_len, dm_plat->mode_rx, cmd_buf);
+				priv->cmd_len, dm_plat->mode, cmd_buf);
 			if (!err) {
 				err = cadence_qspi_apb_indirect_read_execute
 				(plat, data_bytes, din);
drivers/spi/ich.c +2 -4
index 00b2fed..caf0103 100644
@@ -649,10 +649,8 @@ static int ich_spi_child_pre_probe(struct udevice *dev)
 	 * ICH 7 SPI controller only supports array read command
 	 * and byte program command for SST flash
 	 */
-	if (plat->ich_version == ICHV_7) {
-		slave->mode_rx = SPI_RX_SLOW;
-		slave->mode = SPI_TX_BYTE;
-	}
+	if (plat->ich_version == ICHV_7)
+		slave->mode = SPI_RX_SLOW | SPI_TX_BYTE;
 
 	return 0;
 }
drivers/spi/spi-uclass.c +4 -7
index 247abfa..d9c49e4 100644
@@ -164,7 +164,6 @@ static int spi_child_pre_probe(struct udevice *dev)
 
 	slave->max_hz = plat->max_hz;
 	slave->mode = plat->mode;
-	slave->mode_rx = plat->mode_rx;
 	slave->wordlen = SPI_DEFAULT_WORDLEN;
 
 	return 0;
@@ -381,7 +380,7 @@ void spi_free_slave(struct spi_slave *slave)
 int spi_slave_ofdata_to_platdata(const void *blob, int node,
 				 struct dm_spi_slave_platdata *plat)
 {
-	int mode = 0, mode_rx = 0;
+	int mode = 0;
 	int value;
 
 	plat->cs = fdtdec_get_int(blob, node, "reg", -1);
@@ -413,24 +412,22 @@ int spi_slave_ofdata_to_platdata(const void *blob, int node,
 		break;
 	}
 
-	plat->mode = mode;
-
 	value = fdtdec_get_uint(blob, node, "spi-rx-bus-width", 1);
 	switch (value) {
 	case 1:
 		break;
 	case 2:
-		mode_rx |= SPI_RX_DUAL;
+		mode |= SPI_RX_DUAL;
 		break;
 	case 4:
-		mode_rx |= SPI_RX_QUAD;
+		mode |= SPI_RX_QUAD;
 		break;
 	default:
 		error("spi-rx-bus-width %d not supported\n", value);
 		break;
 	}
 
-	plat->mode_rx = mode_rx;
+	plat->mode = mode;
 
 	return 0;
 }
drivers/spi/ti_qspi.c +3 -3
index bb72cb0..37dc64f 100644
@@ -336,7 +336,7 @@ static void ti_spi_setup_spi_register(struct ti_qspi_priv *priv)
 			QSPI_SETUP0_NUM_D_BYTES_8_BITS |
 			QSPI_SETUP0_READ_QUAD | QSPI_CMD_WRITE |
 			QSPI_NUM_DUMMY_BITS);
-	slave->mode_rx = SPI_RX_QUAD;
+	slave->mode |= SPI_RX_QUAD;
 #else
 	memval |= QSPI_CMD_READ | QSPI_SETUP0_NUM_A_BYTES |
 			QSPI_SETUP0_NUM_D_BYTES_NO_BITS |
@@ -422,7 +422,7 @@ static void __ti_qspi_setup_memorymap(struct ti_qspi_priv *priv,
 				      bool enable)
 {
 	u32 memval;
-	u32 mode = slave->mode_rx & (SPI_RX_QUAD | SPI_RX_DUAL);
+	u32 mode = slave->mode | SPI_RX_QUAD | SPI_RX_DUAL;
 
 	if (!enable) {
 		writel(0, &priv->base->setup0);
@@ -436,7 +436,7 @@ static void __ti_qspi_setup_memorymap(struct ti_qspi_priv *priv,
 		memval |= QSPI_CMD_READ_QUAD;
 		memval |= QSPI_SETUP0_NUM_D_BYTES_8_BITS;
 		memval |= QSPI_SETUP0_READ_QUAD;
-		slave->mode_rx = SPI_RX_QUAD;
+		slave->mode |= SPI_RX_QUAD;
 		break;
 	case SPI_RX_DUAL:
 		memval |= QSPI_CMD_READ_DUAL;
include/spi.h +4 -10
index ca96fa4..7d92ddc 100644
@@ -26,12 +26,10 @@
 #define SPI_TX_BYTE	BIT(8)			/* transmit with 1 wire byte */
 #define SPI_TX_DUAL	BIT(9)			/* transmit with 2 wires */
 #define SPI_TX_QUAD	BIT(10)			/* transmit with 4 wires */
-
-/* SPI mode_rx flags */
-#define SPI_RX_SLOW	BIT(0)			/* receive with 1 wire slow */
-#define SPI_RX_FAST	BIT(1)			/* receive with 1 wire fast */
-#define SPI_RX_DUAL	BIT(2)			/* receive with 2 wires */
-#define SPI_RX_QUAD	BIT(3)			/* receive with 4 wires */
+#define SPI_RX_SLOW	BIT(11)			/* receive with 1 wire slow */
+#define SPI_RX_FAST	BIT(12)			/* receive with 1 wire fast */
+#define SPI_RX_DUAL	BIT(12)			/* receive with 2 wires */
+#define SPI_RX_QUAD	BIT(13)			/* receive with 4 wires */
 
 /* SPI bus connection options - see enum spi_dual_flash */
 #define SPI_CONN_DUAL_SHARED		(1 << 0)
@@ -61,13 +59,11 @@ struct dm_spi_bus {
  * @cs:		Chip select number (0..n-1)
  * @max_hz:	Maximum bus speed that this slave can tolerate
  * @mode:	SPI mode to use for this device (see SPI mode flags)
- * @mode_rx:	SPI RX mode to use for this slave (see SPI mode_rx flags)
  */
 struct dm_spi_slave_platdata {
 	unsigned int cs;
 	uint max_hz;
 	uint mode;
-	u8 mode_rx;
 };
 
 #endif /* CONFIG_DM_SPI */
@@ -94,7 +90,6 @@ struct dm_spi_slave_platdata {
  *			bus (bus->seq) so does not need to be stored
  * @cs:			ID of the chip select connected to the slave.
  * @mode:		SPI mode to use for this slave (see SPI mode flags)
- * @mode_rx:		SPI RX mode to use for this slave (see SPI mode_rx flags)
  * @wordlen:		Size of SPI word in number of bits
  * @max_write_size:	If non-zero, the maximum number of bytes which can
  *			be written at once, excluding command bytes.
@@ -112,7 +107,6 @@ struct spi_slave {
 	unsigned int cs;
 #endif
 	uint mode;
-	u8 mode_rx;
 	unsigned int wordlen;
 	unsigned int max_write_size;
 	void *memory_map;
Signature · 1 line
2.7.4
author
#6 lore raw

PATCH v2 4/22 sf: Remove SECT_32K

In reply to Jagan Teki

SECT_32K never used anywhere in the code.

Cc Simon Glass <[email protected]>
Cc Bin Meng <[email protected]>
Cc Michal Simek <[email protected]>
Cc Siva Durga Prasad Paladugu <[email protected]>
Cc Vignesh R <[email protected]>
Cc Mugunthan V N <[email protected]>
---
 drivers/mtd/spi/sf_internal.h | 16 +++++++---------
 drivers/mtd/spi/spi_flash.c   |  3 ---
 2 files changed, 7 insertions(+), 12 deletions(-)
drivers/mtd/spi/sf_internal.h +7 -9
index 71ba1a6..9eb0b84 100644
@@ -27,14 +27,13 @@ enum {
 #else
 	SECT_4K		= BIT(0),
 #endif
-	SECT_32K	= BIT(1),
-	E_FSR		= BIT(2),
-	SST_WR		= BIT(3),
-	WR_QPP		= BIT(4),
-	RD_QUAD		= BIT(5),
-	RD_DUAL		= BIT(6),
-	RD_QUADIO	= BIT(7),
-	RD_DUALIO	= BIT(8),
+	E_FSR		= BIT(1),
+	SST_WR		= BIT(2),
+	WR_QPP		= BIT(3),
+	RD_QUAD		= BIT(4),
+	RD_DUAL		= BIT(5),
+	RD_QUADIO	= BIT(6),
+	RD_DUALIO	= BIT(7),
 };
 #define RD_FULL		RD_QUAD | RD_DUAL | RD_QUADIO | RD_DUALIO
 
@@ -57,7 +56,6 @@ enum spi_nor_option_flags {
 
 /* Erase commands */
 #define CMD_ERASE_4K			0x20
-#define CMD_ERASE_32K			0x52
 #define CMD_ERASE_CHIP			0xc7
 #define CMD_ERASE_64K			0xd8
 
drivers/mtd/spi/spi_flash.c +0 -3
index 041b64f..2b2a409 100644
@@ -1159,9 +1159,6 @@ int spi_flash_scan(struct spi_flash *flash)
 	if (params->flags & SECT_4K) {
 		flash->erase_cmd = CMD_ERASE_4K;
 		flash->erase_size = 4096 << flash->shift;
-	} else if (params->flags & SECT_32K) {
-		flash->erase_cmd = CMD_ERASE_32K;
-		flash->erase_size = 32768 << flash->shift;
 	} else {
 		flash->erase_cmd = CMD_ERASE_64K;
 		flash->erase_size = flash->sector_size;
Signature · 1 line
2.7.4
author
#7 lore raw

PATCH v2 5/22 sf: Add CONFIG_SPI_FLASH_USE_4K_SECTORS in spi_flash

In reply to Jagan Teki

Add CONFIG_SPI_FLASH_USE_4K_SECTORS in spi_flash code from header file.

Cc Simon Glass <[email protected]>
Cc Bin Meng <[email protected]>
Cc Michal Simek <[email protected]>
Cc Siva Durga Prasad Paladugu <[email protected]>
Cc Vignesh R <[email protected]>
Cc Mugunthan V N <[email protected]>
---
 drivers/mtd/spi/sf_internal.h | 4 ----
 drivers/mtd/spi/spi_flash.c   | 5 ++++-
 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/mtd/spi/sf_internal.h +0 -4
index 9eb0b84..1301e48 100644
@@ -22,11 +22,7 @@ enum spi_dual_flash {
 
 /* sf param flags */
 enum {
-#ifndef CONFIG_SPI_FLASH_USE_4K_SECTORS
-	SECT_4K		= 0,
-#else
 	SECT_4K		= BIT(0),
-#endif
 	E_FSR		= BIT(1),
 	SST_WR		= BIT(2),
 	WR_QPP		= BIT(3),
drivers/mtd/spi/spi_flash.c +4 -1
index 2b2a409..7f6e9ae 100644
@@ -1155,11 +1155,14 @@ int spi_flash_scan(struct spi_flash *flash)
 		flash->size <<= 1;
 #endif
 
+#ifdef CONFIG_SPI_FLASH_USE_4K_SECTORS
 	/* Compute erase sector and command */
 	if (params->flags & SECT_4K) {
 		flash->erase_cmd = CMD_ERASE_4K;
 		flash->erase_size = 4096 << flash->shift;
-	} else {
+	} else
+#endif
+	{
 		flash->erase_cmd = CMD_ERASE_64K;
 		flash->erase_size = flash->sector_size;
 	}
Signature · 1 line
2.7.4
author
#8 lore raw

PATCH v2 6/22 sf: Move flags macro's to spi_flash_params{} members

In reply to Jagan Teki

This patch moves flags macro's to respective member position on spi_flash_params{}, for better readabilty and finding the respective member macro's easily.

Cc Simon Glass <[email protected]>
Cc Bin Meng <[email protected]>
Cc Michal Simek <[email protected]>
Cc Siva Durga Prasad Paladugu <[email protected]>
Cc Vignesh R <[email protected]>
Cc Mugunthan V N <[email protected]>
---
 drivers/mtd/spi/sf_internal.h | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)
drivers/mtd/spi/sf_internal.h +10 -13
index 1301e48..e5c38bf 100644
@@ -20,19 +20,6 @@ enum spi_dual_flash {
 	SF_DUAL_PARALLEL_FLASH	= BIT(1),
 };
 
-/* sf param flags */
-enum {
-	SECT_4K		= BIT(0),
-	E_FSR		= BIT(1),
-	SST_WR		= BIT(2),
-	WR_QPP		= BIT(3),
-	RD_QUAD		= BIT(4),
-	RD_DUAL		= BIT(5),
-	RD_QUADIO	= BIT(6),
-	RD_DUALIO	= BIT(7),
-};
-#define RD_FULL		RD_QUAD | RD_DUAL | RD_QUADIO | RD_DUALIO
-
 enum spi_nor_option_flags {
 	SNOR_F_SST_WR		= BIT(0),
 	SNOR_F_USE_FSR		= BIT(1),
@@ -133,7 +120,17 @@ struct spi_flash_params {
 	u16 ext_jedec;
 	u32 sector_size;
 	u32 nr_sectors;
+
 	u16 flags;
+#define SECT_4K 		BIT(0)
+#define E_FSR			BIT(1)
+#define SST_WR			BIT(2)
+#define WR_QPP			BIT(3)
+#define RD_QUAD 		BIT(4)
+#define RD_DUAL 		BIT(5)
+#define RD_QUADIO		BIT(6)
+#define RD_DUALIO		BIT(7)
+#define RD_FULL 		(RD_QUAD | RD_DUAL | RD_QUADIO | RD_DUALIO)
 };
 
 extern const struct spi_flash_params spi_flash_params_table[];
Signature · 1 line
2.7.4
author
#9 lore raw

PATCH v2 7/22 sf: Adopt flash table INFO macro from Linux

In reply to Jagan Teki

INFO macro make flash table entries more adjustable like adding new flash_info attributes, update ID length bytes and so on and more over it will sync to Linux way of defining flash_info attributes.

Cc Simon Glass <[email protected]>
Cc Bin Meng <[email protected]>
Cc York Sun <[email protected]>
Cc Vignesh R <[email protected]>
Cc Mugunthan V N <[email protected]>
Cc Michal Simek <[email protected]>
Cc Siva Durga Prasad Paladugu <[email protected]>
---
 drivers/mtd/spi/sf_internal.h |  15 ++-
 drivers/mtd/spi/sf_params.c   | 215 ++++++++++++++++++++++--------------------
 drivers/mtd/spi/spi_flash.c   |  61 ++++++------
 include/linux/err.h           |   5 +
 4 files changed, 160 insertions(+), 136 deletions(-)
drivers/mtd/spi/sf_internal.h +11 -4
index e5c38bf..3f20b67 100644
@@ -107,8 +107,6 @@ int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,
  * 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:	Isn't necessarily a sector size from vendor,
  *			the size listed here is what works with CMD_ERASE_64K
  * @nr_sectors:		No.of sectors on this device
@@ -116,11 +114,20 @@ int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,
  */
 struct spi_flash_params {
 	const char *name;
-	u32 jedec;
-	u16 ext_jedec;
+
+	/*
+	 * This array stores the ID bytes.
+	 * The first three bytes are the JEDIC ID.
+	 * JEDEC ID zero means "no ID" (mostly older chips).
+	 */
+	u8		id[5];
+	u8		id_len;
+
 	u32 sector_size;
 	u32 nr_sectors;
 
+	u16 page_size;
+
 	u16 flags;
 #define SECT_4K 		BIT(0)
 #define E_FSR			BIT(1)
drivers/mtd/spi/sf_params.c +115 -100

240 lines not on this page · raw message

drivers/mtd/spi/spi_flash.c +29 -32

81 lines not on this page · raw message

include/linux/err.h +5 -0
index 5b3c8bc..1bba498 100644
@@ -36,6 +36,11 @@ static inline long IS_ERR(const void *ptr)
 	return IS_ERR_VALUE((unsigned long)ptr);
 }
 
+static inline bool IS_ERR_OR_NULL(const void *ptr)
+{
+	return !ptr || IS_ERR_VALUE((unsigned long)ptr);
+}
+
 /**
  * ERR_CAST - Explicitly cast an error-valued pointer to another pointer type
  * @ptr: The pointer to cast.
Signature · 1 line
2.7.4
author
#12 lore raw

PATCH v2 8/22 sf: Add JEDEC_ID and JEDEC_EXT macro

In reply to Jagan Teki

Few of the flash families with different ext_jedec have changes in page_size so these macros check these ext_jedec and assign page_size accordingly

Cc Simon Glass <[email protected]>
Cc Bin Meng <[email protected]>
Cc York Sun <[email protected]>
Cc Vignesh R <[email protected]>
Cc Mugunthan V N <[email protected]>
Cc Michal Simek <[email protected]>
Cc Siva Durga Prasad Paladugu <[email protected]>
---
 drivers/mtd/spi/sf_internal.h |  4 ++++
 drivers/mtd/spi/spi_flash.c   | 10 ++++------
 2 files changed, 8 insertions(+), 6 deletions(-)
drivers/mtd/spi/sf_internal.h +4 -0
index 3f20b67..a57c330 100644
@@ -103,6 +103,10 @@ int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,
 #define CMD_SPANSION_RDAR	0x65 /* Read any device register */
 #define CMD_SPANSION_WRAR	0x71 /* Write any device register */
 #endif
+
+#define JEDEC_ID(params)	(((params)->id[1]) << 8 | ((params)->id[2]))
+#define JEDEC_EXT(params)	(((params)->id[3]) << 8 | ((params)->id[4]))
+
 /**
  * struct spi_flash_params - SPI/QSPI flash device params structure
  *
drivers/mtd/spi/spi_flash.c +4 -6
index 58d5a6a..c84c6b7 100644
@@ -1130,19 +1130,17 @@ int spi_flash_scan(struct spi_flash *flash)
 
 	/* Compute the flash size */
 	flash->shift = (flash->dual_flash & SF_DUAL_PARALLEL_FLASH) ? 1 : 0;
+	flash->page_size = params->page_size;
 	/*
 	 * The Spansion S25FL032P and S25FL064P have 256b pages, yet use the
 	 * 0x4d00 Extended JEDEC code. The rest of the Spansion flashes with
 	 * the 0x4d00 Extended JEDEC code have 512b pages. All of the others
 	 * have 256b pages.
 	 */
-	if (ext_jedec == 0x4d00) {
-		if ((jedec == 0x0215) || (jedec == 0x216) || (jedec == 0x220))
-			flash->page_size = 256;
-		else
+	if (JEDEC_EXT(params) == 0x4d00) {
+		if ((JEDEC_ID(params) != 0x0215) &&
+		    (JEDEC_ID(params) != 0x0216))
 			flash->page_size = 512;
-	} else {
-		flash->page_size = 256;
 	}
 	flash->page_size <<= flash->shift;
 	flash->sector_size = params->sector_size << flash->shift;
Signature · 1 line
2.7.4
author
#13 lore raw

PATCH v2 9/22 sf: Rename spi_flash_params => spi_flash_info

In reply to Jagan Teki

Renamed for more readability
- spi_flash_params => spi_flash_info
- params => info

Cc Simon Glass <[email protected]>
Cc Bin Meng <[email protected]>
Cc York Sun <[email protected]>
Cc Vignesh R <[email protected]>
Cc Mugunthan V N <[email protected]>
Cc Michal Simek <[email protected]>
Cc Siva Durga Prasad Paladugu <[email protected]>
---
 drivers/mtd/spi/sandbox.c     |  6 +++---
 drivers/mtd/spi/sf_internal.h | 10 +++++-----
 drivers/mtd/spi/sf_params.c   |  2 +-
 drivers/mtd/spi/spi_flash.c   | 46 +++++++++++++++++++++----------------------
 4 files changed, 32 insertions(+), 32 deletions(-)
drivers/mtd/spi/sandbox.c +3 -3
index 53470b9..0ac7fb7 100644
@@ -88,7 +88,7 @@ struct sandbox_spi_flash {
 	/* The current flash status (see STAT_XXX defines above) */
 	u16 status;
 	/* Data describing the flash we're emulating */
-	const struct spi_flash_params *data;
+	const struct spi_flash_info *data;
 	/* The file on disk to serv up data from */
 	int fd;
 };
@@ -112,7 +112,7 @@ static int sandbox_sf_probe(struct udevice *dev)
 	struct sandbox_spi_flash *sbsf = dev_get_priv(dev);
 	const char *file;
 	size_t len, idname_len;
-	const struct spi_flash_params *data;
+	const struct spi_flash_info *data;
 	struct sandbox_spi_flash_plat_data *pdata = dev_get_platdata(dev);
 	struct sandbox_state *state = state_get_current();
 	struct udevice *bus = dev->parent;
@@ -168,7 +168,7 @@ static int sandbox_sf_probe(struct udevice *dev)
 	}
 	debug("%s: device='%s'\n", __func__, spec);
 
-	for (data = spi_flash_params_table; data->name; data++) {
+	for (data = spi_flash_ids; data->name; data++) {
 		len = strlen(data->name);
 		if (idname_len != len)
 			continue;
drivers/mtd/spi/sf_internal.h +5 -5
index a57c330..4e9ae34 100644
@@ -104,11 +104,11 @@ int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,
 #define CMD_SPANSION_WRAR	0x71 /* Write any device register */
 #endif
 
-#define JEDEC_ID(params)	(((params)->id[1]) << 8 | ((params)->id[2]))
-#define JEDEC_EXT(params)	(((params)->id[3]) << 8 | ((params)->id[4]))
+#define JEDEC_ID(info)		(((info)->id[1]) << 8 | ((info)->id[2]))
+#define JEDEC_EXT(info) 	(((info)->id[3]) << 8 | ((info)->id[4]))
 
 /**
- * struct spi_flash_params - SPI/QSPI flash device params structure
+ * struct spi_flash_info - SPI/QSPI flash device params structure
  *
  * @name:		Device name ([MANUFLETTER][DEVTYPE][DENSITY][EXTRAINFO])
  * @sector_size:	Isn't necessarily a sector size from vendor,
@@ -116,7 +116,7 @@ int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,
  * @nr_sectors:		No.of sectors on this device
  * @flags:		Important param, for flash specific behaviour
  */
-struct spi_flash_params {
+struct spi_flash_info {
 	const char *name;
 
 	/*
@@ -144,7 +144,7 @@ struct spi_flash_params {
 #define RD_FULL 		(RD_QUAD | RD_DUAL | RD_QUADIO | RD_DUALIO)
 };
 
-extern const struct spi_flash_params spi_flash_params_table[];
+extern const struct spi_flash_info spi_flash_ids[];
 
 /* Send a single-byte command to the device and read the response */
 int spi_flash_cmd(struct spi_slave *spi, u8 cmd, void *response, size_t len);
drivers/mtd/spi/sf_params.c +1 -1
index 70d9e18..7fcc3bc 100644
@@ -28,7 +28,7 @@
 		.flags = (_flags),
 
 /* SPI/QSPI flash device params structure */
-const struct spi_flash_params spi_flash_params_table[] = {
+const struct spi_flash_info spi_flash_ids[] = {
 #ifdef CONFIG_SPI_FLASH_ATMEL		/* ATMEL */
 	{"AT45DB011D",	   INFO(0x1f2200, 0x0, 64 * 1024,     4, SECT_4K) },
 	{"AT45DB021D",	   INFO(0x1f2300, 0x0, 64 * 1024,     8, SECT_4K) },
drivers/mtd/spi/spi_flash.c +23 -23

118 lines not on this page · raw message

Signature · 1 line
2.7.4
#14 lore raw

v2 cover spi/sf: Updates on flash detection

In reply to Jagan Teki

Hi Jagan,

Quoted 6 lines · Jagan Teki

Updated spi_flash_info table in sync with Linux, and removed legacy and unsupported code.

Changes for v2:
- New patches.

Is this a new version of previous spi-nor framework work?

Regards,
Bin

maintainer
#4 lore raw

PATCH v2 3/22 spi: Use mode for rx mode flags

In reply to Jagan Teki

Hi,

Quoted 3 lines · Jagan Teki

Make rx mode flags as generic to spi, earlier mode_rx is maintained separately becuase of some flash specific code.

Nit: s/becuase/because

[...]

Quoted 14 lines
drivers/spi/ti_qspi.c +1 -1
index bb72cb0..37dc64f 100644
@@ -336,7 +336,7 @@ static void ti_spi_setup_spi_register(struct ti_qspi_priv *priv)
 			QSPI_SETUP0_NUM_D_BYTES_8_BITS |
 			QSPI_SETUP0_READ_QUAD | QSPI_CMD_WRITE |
 			QSPI_NUM_DUMMY_BITS);
-	slave->mode_rx = SPI_RX_QUAD;
+	slave->mode |= SPI_RX_QUAD;
 #else
 	memval |= QSPI_CMD_READ | QSPI_SETUP0_NUM_A_BYTES |
 			QSPI_SETUP0_NUM_D_BYTES_NO_BITS |

drivers/spi/ti_qspi.c static void __ti_qspi_setup_memorymap(struct ti_qspi_priv *priv, · line 426

Quoted 6 lines
drivers/spi/ti_qspi.c +1 -1
@@ -422,7 +422,7 @@ static void __ti_qspi_setup_memorymap(struct ti_qspi_priv *priv,
 				      bool enable)
 {
 	u32 memval;
-	u32 mode = slave->mode_rx & (SPI_RX_QUAD | SPI_RX_DUAL);
+	u32 mode = slave->mode | SPI_RX_QUAD | SPI_RX_DUAL;
 

This will break ti-qspi Quad mode operation. The code below this line (switch statement) expects mode to be either SPI_RX_DUAL or SPI_RX_QUAD but not both.

Quoted 18 lines
drivers/spi/ti_qspi.c +1 -1
 	if (!enable) {
 		writel(0, &priv->base->setup0);
@@ -436,7 +436,7 @@ static void __ti_qspi_setup_memorymap(struct ti_qspi_priv *priv,
 		memval |= QSPI_CMD_READ_QUAD;
 		memval |= QSPI_SETUP0_NUM_D_BYTES_8_BITS;
 		memval |= QSPI_SETUP0_READ_QUAD;
-		slave->mode_rx = SPI_RX_QUAD;
+		slave->mode |= SPI_RX_QUAD;
 		break;
 	case SPI_RX_DUAL:
 		memval |= QSPI_CMD_READ_DUAL;
include/spi.h +0 -0
index ca96fa4..7d92ddc 100644
@@ -26,12 +26,10 @@
 #define SPI_TX_BYTE	BIT(8)			/* transmit with 1 wire byte */
 #define SPI_TX_DUAL	BIT(9)			/* transmit with 2 wires */

include/spi.h line 31

Quoted 10 lines
include/spi.h +3 -6
 #define SPI_TX_QUAD	BIT(10)			/* transmit with 4 wires */
-
-/* SPI mode_rx flags */
-#define SPI_RX_SLOW	BIT(0)			/* receive with 1 wire slow */
-#define SPI_RX_FAST	BIT(1)			/* receive with 1 wire fast */
-#define SPI_RX_DUAL	BIT(2)			/* receive with 2 wires */
-#define SPI_RX_QUAD	BIT(3)			/* receive with 4 wires */
+#define SPI_RX_SLOW	BIT(11)			/* receive with 1 wire slow */
+#define SPI_RX_FAST	BIT(12)			/* receive with 1 wire fast */
+#define SPI_RX_DUAL	BIT(12)			/* receive with 2 wires */

Same bit for SPI_RX_FAST and SPI_RX_DUAL? Could you clarify the reason?

Signature · 2 lines
Regards
Vignesh
#15 lore raw

v2 cover spi/sf: Updates on flash detection

In reply to Bin Meng

Hi Bin,

Quoted 11 lines · Bin Meng

Hi Jagan,

Quoted 6 lines · Jagan Teki

Updated spi_flash_info table in sync with Linux, and removed legacy and unsupported code.

Changes for v2:
- New patches.

Is this a new version of previous spi-nor framework work?

Yes, and divided into separate series - fixes, MTD and spi-nor.

Signature · 1 line
Jagan.
author
#5 lore raw

PATCH v2 3/22 spi: Use mode for rx mode flags

In reply to Vignesh R
Quoted 8 lines · Vignesh R

Hi,

Quoted 3 lines · Jagan Teki

Make rx mode flags as generic to spi, earlier mode_rx is maintained separately becuase of some flash specific code.

Nit: s/becuase/because

OK.

Quoted 18 lines

[...]

Quoted 16 lines
drivers/spi/ti_qspi.c +1 -1
index bb72cb0..37dc64f 100644
@@ -336,7 +336,7 @@ static void ti_spi_setup_spi_register(struct ti_qspi_priv *priv)
 			QSPI_SETUP0_NUM_D_BYTES_8_BITS |
 			QSPI_SETUP0_READ_QUAD | QSPI_CMD_WRITE |
 			QSPI_NUM_DUMMY_BITS);
-	slave->mode_rx = SPI_RX_QUAD;
+	slave->mode |= SPI_RX_QUAD;
 #else
 	memval |= QSPI_CMD_READ | QSPI_SETUP0_NUM_A_BYTES |
 			QSPI_SETUP0_NUM_D_BYTES_NO_BITS |
@@ -422,7 +422,7 @@ static void __ti_qspi_setup_memorymap(struct ti_qspi_priv *priv,
 				      bool enable)
 {
Quoted 8 lines

drivers/spi/ti_qspi.c static void __ti_qspi_setup_memorymap(struct ti_qspi_priv *priv, · line 426

Quoted 4 lines
drivers/spi/ti_qspi.c +1 -1
 	u32 memval;
-	u32 mode = slave->mode_rx & (SPI_RX_QUAD | SPI_RX_DUAL);
+	u32 mode = slave->mode | SPI_RX_QUAD | SPI_RX_DUAL;
 

This will break ti-qspi Quad mode operation. The code below this line (switch statement) expects mode to be either SPI_RX_DUAL or SPI_RX_QUAD but not both.

Wrong usage of | instead of & will fix

Quoted 23 lines
Quoted 23 lines
drivers/spi/ti_qspi.c +1 -1
 	if (!enable) {
 		writel(0, &priv->base->setup0);
@@ -436,7 +436,7 @@ static void __ti_qspi_setup_memorymap(struct ti_qspi_priv *priv,
 		memval |= QSPI_CMD_READ_QUAD;
 		memval |= QSPI_SETUP0_NUM_D_BYTES_8_BITS;
 		memval |= QSPI_SETUP0_READ_QUAD;
-		slave->mode_rx = SPI_RX_QUAD;
+		slave->mode |= SPI_RX_QUAD;
 		break;
 	case SPI_RX_DUAL:
 		memval |= QSPI_CMD_READ_DUAL;
include/spi.h +0 -3
index ca96fa4..7d92ddc 100644
@@ -26,12 +26,10 @@
 #define SPI_TX_BYTE	BIT(8)			/* transmit with 1 wire byte */
 #define SPI_TX_DUAL	BIT(9)			/* transmit with 2 wires */
 #define SPI_TX_QUAD	BIT(10)			/* transmit with 4 wires */
-
-/* SPI mode_rx flags */
-#define SPI_RX_SLOW	BIT(0)			/* receive with 1 wire slow */
Quoted 8 lines

include/spi.h line 31

Quoted 6 lines
include/spi.h +3 -3
-#define SPI_RX_FAST	BIT(1)			/* receive with 1 wire fast */
-#define SPI_RX_DUAL	BIT(2)			/* receive with 2 wires */
-#define SPI_RX_QUAD	BIT(3)			/* receive with 4 wires */
+#define SPI_RX_SLOW	BIT(11)			/* receive with 1 wire slow */
+#define SPI_RX_FAST	BIT(12)			/* receive with 1 wire fast */
+#define SPI_RX_DUAL	BIT(12)			/* receive with 2 wires */

Same bit for SPI_RX_FAST and SPI_RX_DUAL? Could you clarify the reason?

Will fix.

maintainer
#10 lore raw

PATCH v2 7/22 sf: Adopt flash table INFO macro from Linux

In reply to Jagan Teki
Quoted 4 lines · Jagan Teki

INFO macro make flash table entries more adjustable like adding new flash_info attributes, update ID length bytes and so on and more over it will sync to Linux way of defining flash_info attributes.

[...]

Quoted 10 lines
drivers/mtd/spi/spi_flash.c +2 -0
index 7f6e9ae..58d5a6a 100644
@@ -924,6 +924,31 @@ static int micron_quad_enable(struct spi_flash *flash)
 }
 #endif
 
+static const struct spi_flash_params *spi_flash_read_id(struct spi_flash *flash)
+{

drivers/mtd/spi/spi_flash.c static int micron_quad_enable(struct spi_flash *flash) · line 938

Quoted 10 lines
drivers/mtd/spi/spi_flash.c +10 -0
+	int				tmp;
+	u8				id[5];
+	const struct spi_flash_params	*params;
+
+	tmp = spi_flash_cmd(flash->spi, CMD_READ_ID, id, 5);
+	if (tmp < 0) {
+		printf("SF: error %d reading JEDEC ID\n", tmp);
+		return ERR_PTR(tmp);
+	}
+

Could we have debug() to print the JEDEC IDs read as before?

Signature · 2 lines
Regards
Vignesh
author
#11 lore raw

PATCH v2 7/22 sf: Adopt flash table INFO macro from Linux

Quoted 16 lines · Vignesh R
Quoted 4 lines · Jagan Teki

INFO macro make flash table entries more adjustable like adding new flash_info attributes, update ID length bytes and so on and more over it will sync to Linux way of defining flash_info attributes.

[...]

Quoted 8 lines
drivers/mtd/spi/spi_flash.c +0 -0
index 7f6e9ae..58d5a6a 100644
@@ -924,6 +924,31 @@ static int micron_quad_enable(struct spi_flash *flash)
 }
 #endif
 
Quoted 14 lines

drivers/mtd/spi/spi_flash.c static int micron_quad_enable(struct spi_flash *flash) · line 938

Quoted 12 lines
drivers/mtd/spi/spi_flash.c +12 -0
+static const struct spi_flash_params *spi_flash_read_id(struct spi_flash *flash)
+{
+	int				tmp;
+	u8				id[5];
+	const struct spi_flash_params	*params;
+
+	tmp = spi_flash_cmd(flash->spi, CMD_READ_ID, id, 5);
+	if (tmp < 0) {
+		printf("SF: error %d reading JEDEC ID\n", tmp);
+		return ERR_PTR(tmp);
+	}
+

Could we have debug() to print the JEDEC IDs read as before?

Not necessary, and anyway jedec id is printing in failure/unsupported case.

#16 lore raw

v2 cover spi/sf: Updates on flash detection

In reply to Jagan Teki

Hi Jagan,

Quoted 9 lines · Jagan Teki

Hi Bin,

Quoted 6 lines · Bin Meng

Hi Jagan,

Quoted 3 lines · Jagan Teki

Updated spi_flash_info table in sync with Linux, and removed legacy and unsupported code.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Changes for v2:
- New patches.

Is this a new version of previous spi-nor framework work?

Yes, and divided into separate series - fixes, MTD and spi-nor.

OK, please specify those series: fixes, MTD and spi-nor. I want to have a testing on x86 boards for all of them.

Regards,
Bin

#17 lore raw

v2 cover spi/sf: Updates on flash detection

Hi Bin,

Quoted 16 lines · Bin Meng

Hi Jagan,

Quoted 13 lines · Jagan Teki

Hi Bin,

Quoted 10 lines · Bin Meng

Hi Jagan,

Quoted 6 lines · Jagan Teki

Updated spi_flash_info table in sync with Linux, and removed legacy and unsupported code.

Changes for v2:
- New patches.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Is this a new version of previous spi-nor framework work?

Yes, and divided into separate series - fixes, MTD and spi-nor.

OK, please specify those series: fixes, MTD and spi-nor. I want to have a testing on x86 boards for all of them.

I'm calling this series as fixes one, idea is to send the couple of patches/series before (MTD and spi-nor) and I'm planning to take these fixes first, So please test this series on your board.

Signature · 1 line
Jagan.