Skip to contentSkip to conversation

sf: spi_flash_validate_params => spi_flash_scan

PATCH Superseded Jagan Teki 3 participants 18 messages Oct 27, 2015 – Oct 28, 2015 Memory technology devices (MTD)

v5 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Jagan Teki

author
#0 lore raw

PATCH v5 1/14 sf: spi_flash_validate_params => spi_flash_scan

Rename spi_flash_validate_params to spi_flash_scan as this code not only deals with params setup but also configure all spi_flash attributes.

And also moved all flash related code into spi_flash_scan for future functionality addition.

---
 drivers/mtd/spi/sf_probe.c | 145 +++++++++++++++++++++++----------------------
 1 file changed, 75 insertions(+), 70 deletions(-)
drivers/mtd/spi/sf_probe.c +75 -70
index f591ab1..a150263 100644
@@ -130,13 +130,42 @@ bank_end:
 }
 #endif
 
-static int spi_flash_validate_params(struct spi_slave *spi, u8 *idcode,
+#if CONFIG_IS_ENABLED(OF_CONTROL)
+int spi_flash_decode_fdt(const void *blob, struct spi_flash *flash)
+{
+	fdt_addr_t addr;
+	fdt_size_t size;
+	int node;
+
+	/* If there is no node, do nothing */
+	node = fdtdec_next_compatible(blob, 0, COMPAT_GENERIC_SPI_FLASH);
+	if (node < 0)
+		return 0;
+
+	addr = fdtdec_get_addr_size(blob, node, "memory-map", &size);
+	if (addr == FDT_ADDR_T_NONE) {
+		debug("%s: Cannot decode address\n", __func__);
+		return 0;
+	}
+
+	if (flash->size != size) {
+		debug("%s: Memory map must cover entire device\n", __func__);
+		return -1;
+	}
+	flash->memory_map = map_sysmem(addr, size);
+
+	return 0;
+}
+#endif /* CONFIG_IS_ENABLED(OF_CONTROL) */
+
+static int spi_flash_scan(struct spi_slave *spi, u8 *idcode,
 				     struct spi_flash *flash)
 {
 	const struct spi_flash_params *params;
 	u8 cmd;
 	u16 jedec = idcode[1] << 8 | idcode[2];
 	u16 ext_jedec = idcode[3] << 8 | idcode[4];
+	int ret;
 
 	/* Validate params from spi_flash_params table */
 	params = spi_flash_params_table;
@@ -158,6 +187,13 @@ static int spi_flash_validate_params(struct spi_slave *spi, u8 *idcode,
 		return -EPROTONOSUPPORT;
 	}
 
+	/* Flash powers up read-only, so clear BP# bits */
+#if defined(CONFIG_SPI_FLASH_ATMEL) || \
+	defined(CONFIG_SPI_FLASH_MACRONIX) || \
+	defined(CONFIG_SPI_FLASH_SST)
+		spi_flash_cmd_write_status(flash, 0);
+#endif
+
 	/* Assign spi data */
 	flash->spi = spi;
 	flash->name = params->name;
@@ -238,6 +274,17 @@ static int spi_flash_validate_params(struct spi_slave *spi, u8 *idcode,
 		/* 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->read_cmd == CMD_READ_QUAD_IO_FAST) ||
+	    (flash->write_cmd == CMD_QUAD_PAGE_PROGRAM)) {
+		ret = spi_flash_set_qeb(flash, idcode[0]);
+		if (ret) {
+			debug("SF: Fail to set QEB for %02x\n", idcode[0]);
+			return -EINVAL;
+		}
+	}
+
 	/* Read dummy_byte: dummy byte is determined based on the
 	 * dummy cycles of a particular command.
 	 * Fast commands - dummy_byte = dummy_cycles/8
@@ -264,48 +311,41 @@ static int spi_flash_validate_params(struct spi_slave *spi, u8 *idcode,
 
 	/* Configure the BAR - discover bank cmds and read current bank */
 #ifdef CONFIG_SPI_FLASH_BAR
-	int ret = spi_flash_read_bank(flash, idcode[0]);
+	ret = spi_flash_read_bank(flash, idcode[0]);
 	if (ret < 0)
 		return ret;
 #endif
 
-	/* Flash powers up read-only, so clear BP# bits */
-#if defined(CONFIG_SPI_FLASH_ATMEL) || \
-	defined(CONFIG_SPI_FLASH_MACRONIX) || \
-	defined(CONFIG_SPI_FLASH_SST)
-		spi_flash_cmd_write_status(flash, 0);
-#endif
-
-	return 0;
-}
-
 #if CONFIG_IS_ENABLED(OF_CONTROL)
-int spi_flash_decode_fdt(const void *blob, struct spi_flash *flash)
-{
-	fdt_addr_t addr;
-	fdt_size_t size;
-	int node;
-
-	/* If there is no node, do nothing */
-	node = fdtdec_next_compatible(blob, 0, COMPAT_GENERIC_SPI_FLASH);
-	if (node < 0)
-		return 0;
-
-	addr = fdtdec_get_addr_size(blob, node, "memory-map", &size);
-	if (addr == FDT_ADDR_T_NONE) {
-		debug("%s: Cannot decode address\n", __func__);
-		return 0;
+	ret = spi_flash_decode_fdt(gd->fdt_blob, flash);
+	if (ret) {
+		debug("SF: FDT decode error\n");
+		return -EINVAL;
 	}
+#endif
 
-	if (flash->size != size) {
-		debug("%s: Memory map must cover entire device\n", __func__);
-		return -1;
+#ifndef CONFIG_SPL_BUILD
+	printf("SF: Detected %s with page size ", flash->name);
+	print_size(flash->page_size, ", erase size ");
+	print_size(flash->erase_size, ", total ");
+	print_size(flash->size, "");
+	if (flash->memory_map)
+		printf(", mapped at %p", flash->memory_map);
+	puts("\n");
+#endif
+
+#ifndef CONFIG_SPI_FLASH_BAR
+	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");
 	}
-	flash->memory_map = map_sysmem(addr, size);
+#endif
 
-	return 0;
+	return ret;
 }
-#endif /* CONFIG_IS_ENABLED(OF_CONTROL) */
 
 /**
  * spi_flash_probe_slave() - Probe for a SPI flash device on a bus
@@ -344,47 +384,12 @@ int spi_flash_probe_slave(struct spi_slave *spi, struct spi_flash *flash)
 	print_buffer(0, idcode, 1, sizeof(idcode), 0);
 #endif
 
-	if (spi_flash_validate_params(spi, idcode, flash)) {
+	ret = spi_flash_scan(spi, idcode, flash);
+	if (ret) {
 		ret = -EINVAL;
 		goto err_read_id;
 	}
 
-	/* 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]);
-			ret = -EINVAL;
-			goto err_read_id;
-		}
-	}
-
-#if CONFIG_IS_ENABLED(OF_CONTROL)
-	if (spi_flash_decode_fdt(gd->fdt_blob, flash)) {
-		debug("SF: FDT decode error\n");
-		ret = -EINVAL;
-		goto err_read_id;
-	}
-#endif
-#ifndef CONFIG_SPL_BUILD
-	printf("SF: Detected %s with page size ", flash->name);
-	print_size(flash->page_size, ", erase size ");
-	print_size(flash->erase_size, ", total ");
-	print_size(flash->size, "");
-	if (flash->memory_map)
-		printf(", mapped at %p", flash->memory_map);
-	puts("\n");
-#endif
-#ifndef CONFIG_SPI_FLASH_BAR
-	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");
-	}
-#endif
 #ifdef CONFIG_SPI_FLASH_MTD
 	ret = spi_flash_mtd_register(flash);
 #endif
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH v5 2/14 sf: Move spi_flash_scan code to sf_ops

Intension is that sf_ops should deals all spi_flash related stuff and sf_probe (which should renamed future) should be an interface layer for spi_flash versus spi drivers.

sf_ops => spi_flash interface
sf_probe => interface layer vs spi_flash(sf_probe) to spi drivers

---
 drivers/mtd/spi/sf_internal.h |  14 ++
 drivers/mtd/spi/sf_ops.c      | 328 ++++++++++++++++++++++++++++++++++++++++++
 drivers/mtd/spi/sf_probe.c    | 327 -----------------------------------------
 3 files changed, 342 insertions(+), 327 deletions(-)
drivers/mtd/spi/sf_internal.h +14 -0
index 8a3e5ec..3f07560 100644
@@ -232,4 +232,18 @@ int spi_flash_mtd_register(struct spi_flash *flash);
 void spi_flash_mtd_unregister(void);
 #endif
 
+/**
+ * spi_flash_scan - scan the SPI FLASH
+ * @spi:	the spi slave structure
+ * @idcode:	idcode of spi flash
+ * @flash:	the spi flash structure
+ *
+ * The drivers can use this fuction to scan the SPI FLASH.
+ * In the scanning, it will try to get all the necessary information to
+ * fill the spi_flash{}.
+ *
+ * Return: 0 for success, others for failure.
+ */
+int spi_flash_scan(struct spi_slave *spi, u8 *idcode, struct spi_flash *flash);
+
 #endif /* _SF_INTERNAL_H_ */
drivers/mtd/spi/sf_ops.c +328 -0

343 lines not on this page · raw message

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

333 lines not on this page · raw message

Signature · 1 line
1.9.1
author
#2 lore raw

PATCH v5 3/14 sf: Move read_id code to sf_ops

In reply to Jagan Teki

read_id code is related to spi_flash stuff
hence moved to sf_ops.

---
 drivers/mtd/spi/sf_internal.h |  3 +--
 drivers/mtd/spi/sf_ops.c      | 21 ++++++++++++++++++---
 drivers/mtd/spi/sf_probe.c    | 15 +--------------
 3 files changed, 20 insertions(+), 19 deletions(-)
drivers/mtd/spi/sf_internal.h +1 -2
index 3f07560..8216fdc 100644
@@ -235,7 +235,6 @@ void spi_flash_mtd_unregister(void);
 /**
  * spi_flash_scan - scan the SPI FLASH
  * @spi:	the spi slave structure
- * @idcode:	idcode of spi flash
  * @flash:	the spi flash structure
  *
  * The drivers can use this fuction to scan the SPI FLASH.
@@ -244,6 +243,6 @@ void spi_flash_mtd_unregister(void);
  *
  * Return: 0 for success, others for failure.
  */
-int spi_flash_scan(struct spi_slave *spi, u8 *idcode, struct spi_flash *flash);
+int spi_flash_scan(struct spi_slave *spi, struct spi_flash *flash);
 
 #endif /* _SF_INTERNAL_H_ */
drivers/mtd/spi/sf_ops.c +18 -3
index d37b0a9..016a5df 100644
@@ -706,14 +706,29 @@ int spi_flash_decode_fdt(const void *blob, struct spi_flash *flash)
 }
 #endif /* CONFIG_IS_ENABLED(OF_CONTROL) */
 
-int spi_flash_scan(struct spi_slave *spi, u8 *idcode, struct spi_flash *flash)
+int spi_flash_scan(struct spi_slave *spi, struct spi_flash *flash)
 {
 	const struct spi_flash_params *params;
+	u16 jedec, ext_jedec;
+	u8 idcode[5];
 	u8 cmd;
-	u16 jedec = idcode[1] << 8 | idcode[2];
-	u16 ext_jedec = idcode[3] << 8 | idcode[4];
 	int ret;
 
+	/* Read the ID codes */
+	ret = spi_flash_cmd(spi, CMD_READ_ID, idcode, sizeof(idcode));
+	if (ret) {
+		printf("SF: Failed to get idcodes\n");
+		return -EINVAL;
+	}
+
+#ifdef DEBUG
+	printf("SF: Got idcodes\n");
+	print_buffer(0, idcode, 1, sizeof(idcode), 0);
+#endif
+
+	jedec = idcode[1] << 8 | idcode[2];
+	ext_jedec = idcode[3] << 8 | idcode[4];
+
 	/* Validate params from spi_flash_params table */
 	params = spi_flash_params_table;
 	for (; params->name != NULL; params++) {
drivers/mtd/spi/sf_probe.c +1 -14
index d2991de..a712792 100644
@@ -29,7 +29,6 @@
  */
 int spi_flash_probe_slave(struct spi_slave *spi, struct spi_flash *flash)
 {
-	u8 idcode[5];
 	int ret;
 
 	/* Setup spi_slave */
@@ -45,19 +44,7 @@ int spi_flash_probe_slave(struct spi_slave *spi, struct spi_flash *flash)
 		return ret;
 	}
 
-	/* Read the ID codes */
-	ret = spi_flash_cmd(spi, CMD_READ_ID, idcode, sizeof(idcode));
-	if (ret) {
-		printf("SF: Failed to get idcodes\n");
-		goto err_read_id;
-	}
-
-#ifdef DEBUG
-	printf("SF: Got idcodes\n");
-	print_buffer(0, idcode, 1, sizeof(idcode), 0);
-#endif
-
-	ret = spi_flash_scan(spi, idcode, flash);
+	ret = spi_flash_scan(spi, flash);
 	if (ret) {
 		ret = -EINVAL;
 		goto err_read_id;
Signature · 1 line
1.9.1
author
#3 lore raw

PATCH v5 4/14 sf: probe: Code cleanup

In reply to Jagan Teki

- Move bar read code below the bar write hance both at once place, hence it easy for #ifdef macro only once and readable.
- Move read_cmd_array at top

---
 drivers/mtd/spi/sf_ops.c | 81 +++++++++++++++++++++++-------------------------
 1 file changed, 39 insertions(+), 42 deletions(-)
drivers/mtd/spi/sf_ops.c +39 -42
index 016a5df..e20a3d6 100644
@@ -29,6 +29,16 @@ static void spi_flash_addr(u32 addr, u8 *cmd)
 	cmd[3] = addr >> 0;
 }
 
+/* Read commands array */
+static u8 spi_read_cmds_array[] = {
+	CMD_READ_ARRAY_SLOW,
+	CMD_READ_ARRAY_FAST,
+	CMD_READ_DUAL_OUTPUT_FAST,
+	CMD_READ_DUAL_IO_FAST,
+	CMD_READ_QUAD_OUTPUT_FAST,
+	CMD_READ_QUAD_IO_FAST,
+};
+
 int spi_flash_cmd_read_status(struct spi_flash *flash, u8 *rs)
 {
 	int ret;
@@ -132,6 +142,35 @@ bar_end:
 	flash->bank_curr = bank_sel;
 	return flash->bank_curr;
 }
+
+static int spi_flash_read_bank(struct spi_flash *flash, u8 idcode0)
+{
+	u8 curr_bank = 0;
+	int ret;
+
+	if (flash->size <= SPI_FLASH_16MB_BOUN)
+		goto bank_end;
+
+	switch (idcode0) {
+	case SPI_FLASH_CFI_MFR_SPANSION:
+		flash->bank_read_cmd = CMD_BANKADDR_BRRD;
+		flash->bank_write_cmd = CMD_BANKADDR_BRWR;
+	default:
+		flash->bank_read_cmd = CMD_EXTNADDR_RDEAR;
+		flash->bank_write_cmd = CMD_EXTNADDR_WREAR;
+	}
+
+	ret = spi_flash_read_common(flash, &flash->bank_read_cmd, 1,
+				    &curr_bank, 1);
+	if (ret) {
+		debug("SF: fail to read bank addr register\n");
+		return ret;
+	}
+
+bank_end:
+	flash->bank_curr = curr_bank;
+	return 0;
+}
 #endif
 
 #ifdef CONFIG_SF_DUAL_FLASH
@@ -569,17 +608,6 @@ int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,
 }
 #endif
 
-
-/* Read commands array */
-static u8 spi_read_cmds_array[] = {
-	CMD_READ_ARRAY_SLOW,
-	CMD_READ_ARRAY_FAST,
-	CMD_READ_DUAL_OUTPUT_FAST,
-	CMD_READ_DUAL_IO_FAST,
-	CMD_READ_QUAD_OUTPUT_FAST,
-	CMD_READ_QUAD_IO_FAST,
-};
-
 #ifdef CONFIG_SPI_FLASH_MACRONIX
 static int spi_flash_set_qeb_mxic(struct spi_flash *flash)
 {
@@ -647,37 +675,6 @@ static int spi_flash_set_qeb(struct spi_flash *flash, u8 idcode0)
 	}
 }
 
-#ifdef CONFIG_SPI_FLASH_BAR
-static int spi_flash_read_bank(struct spi_flash *flash, u8 idcode0)
-{
-	u8 curr_bank = 0;
-	int ret;
-
-	if (flash->size <= SPI_FLASH_16MB_BOUN)
-		goto bank_end;
-
-	switch (idcode0) {
-	case SPI_FLASH_CFI_MFR_SPANSION:
-		flash->bank_read_cmd = CMD_BANKADDR_BRRD;
-		flash->bank_write_cmd = CMD_BANKADDR_BRWR;
-	default:
-		flash->bank_read_cmd = CMD_EXTNADDR_RDEAR;
-		flash->bank_write_cmd = CMD_EXTNADDR_WREAR;
-	}
-
-	ret = spi_flash_read_common(flash, &flash->bank_read_cmd, 1,
-				    &curr_bank, 1);
-	if (ret) {
-		debug("SF: fail to read bank addr register\n");
-		return ret;
-	}
-
-bank_end:
-	flash->bank_curr = curr_bank;
-	return 0;
-}
-#endif
-
 #if CONFIG_IS_ENABLED(OF_CONTROL)
 int spi_flash_decode_fdt(const void *blob, struct spi_flash *flash)
 {
Signature · 1 line
1.9.1
author
#4 lore raw

PATCH v5 5/14 sf: Use static for file-scope functions

In reply to Jagan Teki

Use static for file-scope functions and removed
them from header files.

---
 drivers/mtd/spi/sf_internal.h | 18 ------------------
 drivers/mtd/spi/sf_ops.c      | 11 ++++++-----
 2 files changed, 6 insertions(+), 23 deletions(-)
drivers/mtd/spi/sf_internal.h +0 -18
index 8216fdc..8ef88f4 100644
@@ -167,18 +167,6 @@ 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 ws);
-
-/* Read the config register */
-int spi_flash_cmd_read_config(struct spi_flash *flash, u8 *rc);
-
-/* 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)
 {
@@ -192,12 +180,6 @@ static inline int spi_flash_cmd_write_disable(struct spi_flash *flash)
 }
 
 /*
- * Send the read status command to the device and wait for the wip
- * (write-in-progress) bit to clear itself.
- */
-int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout);
-
-/*
  * Used for spi_flash write operation
  * - SPI claim
  * - spi_flash_cmd_write_enable
drivers/mtd/spi/sf_ops.c +6 -5
index e20a3d6..af94c0b 100644
@@ -39,7 +39,7 @@ static u8 spi_read_cmds_array[] = {
 	CMD_READ_QUAD_IO_FAST,
 };
 
-int spi_flash_cmd_read_status(struct spi_flash *flash, u8 *rs)
+static int spi_flash_cmd_read_status(struct spi_flash *flash, u8 *rs)
 {
 	int ret;
 	u8 cmd;
@@ -68,7 +68,7 @@ static int read_fsr(struct spi_flash *flash, u8 *fsr)
 	return 0;
 }
 
-int spi_flash_cmd_write_status(struct spi_flash *flash, u8 ws)
+static int spi_flash_cmd_write_status(struct spi_flash *flash, u8 ws)
 {
 	u8 cmd;
 	int ret;
@@ -84,7 +84,7 @@ int spi_flash_cmd_write_status(struct spi_flash *flash, u8 ws)
 }
 
 #if defined(CONFIG_SPI_FLASH_SPANSION) || defined(CONFIG_SPI_FLASH_WINBOND)
-int spi_flash_cmd_read_config(struct spi_flash *flash, u8 *rc)
+static int spi_flash_cmd_read_config(struct spi_flash *flash, u8 *rc)
 {
 	int ret;
 	u8 cmd;
@@ -99,7 +99,7 @@ int spi_flash_cmd_read_config(struct spi_flash *flash, u8 *rc)
 	return 0;
 }
 
-int spi_flash_cmd_write_config(struct spi_flash *flash, u8 wc)
+static int spi_flash_cmd_write_config(struct spi_flash *flash, u8 wc)
 {
 	u8 data[2];
 	u8 cmd;
@@ -237,7 +237,8 @@ static int spi_flash_ready(struct spi_flash *flash)
 	return sr && fsr;
 }
 
-int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)
+static int spi_flash_cmd_wait_ready(struct spi_flash *flash,
+					unsigned long timeout)
 {
 	int timebase, ret;
 
Signature · 1 line
1.9.1
author
#5 lore raw

PATCH v5 6/14 sf: Fix Makefile

In reply to Jagan Teki

This patch removes unneeded ifdef and fixed accordingly.

---
 drivers/mtd/spi/Makefile | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/mtd/spi/Makefile +1 -5
index ff48b25..66c4424 100644
@@ -12,11 +12,7 @@ obj-$(CONFIG_SPL_SPI_LOAD)	+= spi_spl_load.o
 obj-$(CONFIG_SPL_SPI_BOOT)	+= fsl_espi_spl.o
 endif
 
-#ifndef CONFIG_DM_SPI
-obj-$(CONFIG_SPI_FLASH) += sf_probe.o
-#endif
-obj-$(CONFIG_CMD_SF) += sf.o
-obj-$(CONFIG_SPI_FLASH) += sf_ops.o sf_params.o
+obj-$(CONFIG_SPI_FLASH) += sf_probe.o sf_ops.o sf_params.o sf.o
 obj-$(CONFIG_SPI_FLASH_DATAFLASH) += sf_dataflash.o
 obj-$(CONFIG_SPI_FLASH_MTD) += sf_mtd.o
 obj-$(CONFIG_SPI_FLASH_SANDBOX) += sandbox.o
Signature · 1 line
1.9.1
author
#6 lore raw

PATCH v5 7/14 sf: Use simple name for register access functions

In reply to Jagan Teki

Most of the register access function are static,
so used simple name to represent each.

---
 drivers/mtd/spi/sf_ops.c | 42 +++++++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 21 deletions(-)
drivers/mtd/spi/sf_ops.c +21 -21
index af94c0b..97e644d 100644
@@ -39,7 +39,7 @@ static u8 spi_read_cmds_array[] = {
 	CMD_READ_QUAD_IO_FAST,
 };
 
-static int spi_flash_cmd_read_status(struct spi_flash *flash, u8 *rs)
+static int read_sr(struct spi_flash *flash, u8 *rs)
 {
 	int ret;
 	u8 cmd;
@@ -68,7 +68,7 @@ static int read_fsr(struct spi_flash *flash, u8 *fsr)
 	return 0;
 }
 
-static int spi_flash_cmd_write_status(struct spi_flash *flash, u8 ws)
+static int write_sr(struct spi_flash *flash, u8 ws)
 {
 	u8 cmd;
 	int ret;
@@ -84,7 +84,7 @@ static int spi_flash_cmd_write_status(struct spi_flash *flash, u8 ws)
 }
 
 #if defined(CONFIG_SPI_FLASH_SPANSION) || defined(CONFIG_SPI_FLASH_WINBOND)
-static int spi_flash_cmd_read_config(struct spi_flash *flash, u8 *rc)
+static int read_cr(struct spi_flash *flash, u8 *rc)
 {
 	int ret;
 	u8 cmd;
@@ -99,13 +99,13 @@ static int spi_flash_cmd_read_config(struct spi_flash *flash, u8 *rc)
 	return 0;
 }
 
-static int spi_flash_cmd_write_config(struct spi_flash *flash, u8 wc)
+static int write_cr(struct spi_flash *flash, u8 wc)
 {
 	u8 data[2];
 	u8 cmd;
 	int ret;
 
-	ret = spi_flash_cmd_read_status(flash, &data[0]);
+	ret = read_sr(flash, &data[0]);
 	if (ret < 0)
 		return ret;
 
@@ -122,7 +122,7 @@ static int spi_flash_cmd_write_config(struct spi_flash *flash, u8 wc)
 #endif
 
 #ifdef CONFIG_SPI_FLASH_BAR
-static int spi_flash_write_bank(struct spi_flash *flash, u32 offset)
+static int spi_flash_write_bar(struct spi_flash *flash, u32 offset)
 {
 	u8 cmd, bank_sel;
 	int ret;
@@ -143,7 +143,7 @@ bar_end:
 	return flash->bank_curr;
 }
 
-static int spi_flash_read_bank(struct spi_flash *flash, u8 idcode0)
+static int spi_flash_read_bar(struct spi_flash *flash, u8 idcode0)
 {
 	u8 curr_bank = 0;
 	int ret;
@@ -174,7 +174,7 @@ bank_end:
 #endif
 
 #ifdef CONFIG_SF_DUAL_FLASH
-static void spi_flash_dual_flash(struct spi_flash *flash, u32 *addr)
+static void spi_flash_dual(struct spi_flash *flash, u32 *addr)
 {
 	switch (flash->dual_flash) {
 	case SF_DUAL_STACKED_FLASH:
@@ -200,7 +200,7 @@ static int spi_flash_sr_ready(struct spi_flash *flash)
 	u8 sr;
 	int ret;
 
-	ret = spi_flash_cmd_read_status(flash, &sr);
+	ret = read_sr(flash, &sr);
 	if (ret < 0)
 		return ret;
 
@@ -316,10 +316,10 @@ int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len)
 
 #ifdef CONFIG_SF_DUAL_FLASH
 		if (flash->dual_flash > SF_SINGLE_FLASH)
-			spi_flash_dual_flash(flash, &erase_addr);
+			spi_flash_dual(flash, &erase_addr);
 #endif
 #ifdef CONFIG_SPI_FLASH_BAR
-		ret = spi_flash_write_bank(flash, erase_addr);
+		ret = spi_flash_write_bar(flash, erase_addr);
 		if (ret < 0)
 			return ret;
 #endif
@@ -358,10 +358,10 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
 
 #ifdef CONFIG_SF_DUAL_FLASH
 		if (flash->dual_flash > SF_SINGLE_FLASH)
-			spi_flash_dual_flash(flash, &write_addr);
+			spi_flash_dual(flash, &write_addr);
 #endif
 #ifdef CONFIG_SPI_FLASH_BAR
-		ret = spi_flash_write_bank(flash, write_addr);
+		ret = spi_flash_write_bar(flash, write_addr);
 		if (ret < 0)
 			return ret;
 #endif
@@ -453,10 +453,10 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
 
 #ifdef CONFIG_SF_DUAL_FLASH
 		if (flash->dual_flash > SF_SINGLE_FLASH)
-			spi_flash_dual_flash(flash, &read_addr);
+			spi_flash_dual(flash, &read_addr);
 #endif
 #ifdef CONFIG_SPI_FLASH_BAR
-		ret = spi_flash_write_bank(flash, read_addr);
+		ret = spi_flash_write_bar(flash, read_addr);
 		if (ret < 0)
 			return ret;
 		bank_sel = flash->bank_curr;
@@ -615,14 +615,14 @@ static int spi_flash_set_qeb_mxic(struct spi_flash *flash)
 	u8 qeb_status;
 	int ret;
 
-	ret = spi_flash_cmd_read_status(flash, &qeb_status);
+	ret = read_sr(flash, &qeb_status);
 	if (ret < 0)
 		return ret;
 
 	if (qeb_status & STATUS_QEB_MXIC) {
 		debug("SF: mxic: QEB is already set\n");
 	} else {
-		ret = spi_flash_cmd_write_status(flash, STATUS_QEB_MXIC);
+		ret = write_sr(flash, STATUS_QEB_MXIC);
 		if (ret < 0)
 			return ret;
 	}
@@ -637,14 +637,14 @@ static int spi_flash_set_qeb_winspan(struct spi_flash *flash)
 	u8 qeb_status;
 	int ret;
 
-	ret = spi_flash_cmd_read_config(flash, &qeb_status);
+	ret = read_cr(flash, &qeb_status);
 	if (ret < 0)
 		return ret;
 
 	if (qeb_status & STATUS_QEB_WINSPAN) {
 		debug("SF: winspan: QEB is already set\n");
 	} else {
-		ret = spi_flash_cmd_write_config(flash, STATUS_QEB_WINSPAN);
+		ret = write_cr(flash, STATUS_QEB_WINSPAN);
 		if (ret < 0)
 			return ret;
 	}
@@ -751,7 +751,7 @@ int spi_flash_scan(struct spi_slave *spi, struct spi_flash *flash)
 #if defined(CONFIG_SPI_FLASH_ATMEL) || \
 	defined(CONFIG_SPI_FLASH_MACRONIX) || \
 	defined(CONFIG_SPI_FLASH_SST)
-		spi_flash_cmd_write_status(flash, 0);
+		write_sr(flash, 0);
 #endif
 
 	/* Assign spi data */
@@ -871,7 +871,7 @@ int spi_flash_scan(struct spi_slave *spi, struct spi_flash *flash)
 
 	/* Configure the BAR - discover bank cmds and read current bank */
 #ifdef CONFIG_SPI_FLASH_BAR
-	ret = spi_flash_read_bank(flash, idcode[0]);
+	ret = spi_flash_read_bar(flash, idcode[0]);
 	if (ret < 0)
 		return ret;
 #endif
Signature · 1 line
1.9.1
author
#7 lore raw

PATCH v5 8/14 sf: Use flash function pointers in dm_spi_flash_ops

In reply to Jagan Teki

flash operations are defined as static and reuse them with function-pointers so call them with generic function pounters instead of calling like normal functions.

---
 drivers/mtd/spi/sf_ops.c   |  2 --
 drivers/mtd/spi/sf_probe.c | 15 +++------------
 include/spi_flash.h        | 13 -------------
 3 files changed, 3 insertions(+), 27 deletions(-)
drivers/mtd/spi/sf_ops.c +0 -2
index 97e644d..f63ce7a 100644
@@ -761,7 +761,6 @@ int spi_flash_scan(struct spi_slave *spi, struct spi_flash *flash)
 	flash->dual_flash = flash->spi->option;
 
 	/* Assign spi_flash ops */
-#ifndef CONFIG_DM_SPI_FLASH
 	flash->write = spi_flash_cmd_write_ops;
 #if defined(CONFIG_SPI_FLASH_SST)
 	if (params->flags & SST_WR)
@@ -776,7 +775,6 @@ int spi_flash_scan(struct spi_slave *spi, struct spi_flash *flash)
 #endif
 	flash->erase = spi_flash_cmd_erase_ops;
 	flash->read = spi_flash_cmd_read_ops;
-#endif
 
 	/* Compute the flash size */
 	flash->shift = (flash->dual_flash & SF_DUAL_PARALLEL_FLASH) ? 1 : 0;
drivers/mtd/spi/sf_probe.c +3 -12
index a712792..e2dac7e 100644
@@ -120,7 +120,7 @@ static int spi_flash_std_read(struct udevice *dev, u32 offset, size_t len,
 {
 	struct spi_flash *flash = dev_get_uclass_priv(dev);
 
-	return spi_flash_cmd_read_ops(flash, offset, len, buf);
+	return flash->read(flash, offset, len, buf);
 }
 
 int spi_flash_std_write(struct udevice *dev, u32 offset, size_t len,
@@ -128,23 +128,14 @@ int spi_flash_std_write(struct udevice *dev, u32 offset, size_t len,
 {
 	struct spi_flash *flash = dev_get_uclass_priv(dev);
 
-#if defined(CONFIG_SPI_FLASH_SST)
-	if (flash->flags & SNOR_F_SST_WR) {
-		if (flash->spi->op_mode_tx & SPI_OPM_TX_BP)
-			return sst_write_bp(flash, offset, len, buf);
-		else
-			return sst_write_wp(flash, offset, len, buf);
-	}
-#endif
-
-	return spi_flash_cmd_write_ops(flash, offset, len, buf);
+	return flash->write(flash, offset, len, buf);
 }
 
 int spi_flash_std_erase(struct udevice *dev, u32 offset, size_t len)
 {
 	struct spi_flash *flash = dev_get_uclass_priv(dev);
 
-	return spi_flash_cmd_erase_ops(flash, offset, len);
+	return flash->erase(flash, offset, len);
 }
 
 int spi_flash_std_probe(struct udevice *dev)
include/spi_flash.h +0 -13
index 4312d3d..0732172 100644
@@ -87,23 +87,10 @@ struct spi_flash {
 	u8 dummy_byte;
 
 	void *memory_map;
-#ifndef CONFIG_DM_SPI_FLASH
-	/*
-	 * These are not strictly needed for driver model, but keep them here
-	 * while the transition is in progress.
-	 *
-	 * Normally each driver would provide its own operations, but for
-	 * SPI flash most chips use the same algorithms. One approach is
-	 * to create a 'common' SPI flash device which knows how to talk
-	 * to most devices, and then allow other drivers to be used instead
-	 * if required, perhaps with a way of scanning through the list to
-	 * find the driver that matches the device.
-	 */
 	int (*read)(struct spi_flash *flash, u32 offset, size_t len, void *buf);
 	int (*write)(struct spi_flash *flash, u32 offset, size_t len,
 			const void *buf);
 	int (*erase)(struct spi_flash *flash, u32 offset, size_t len);
-#endif
 };
 
 struct dm_spi_flash_ops {
Signature · 1 line
1.9.1
author
#8 lore raw

PATCH v5 9/14 sf: Flash power up read-only based on idcode0

In reply to Jagan Teki

Using macro's for flash power up read-only access code leads wrong behaviour hence use idcode0 for runtime detection, hence the flash which require this functionality gets detected at runtime.

---
 drivers/mtd/spi/sf_internal.h | 2 ++
 drivers/mtd/spi/sf_ops.c      | 7 +++----
 2 files changed, 5 insertions(+), 4 deletions(-)
drivers/mtd/spi/sf_internal.h +2 -0
index 8ef88f4..39749c2 100644
@@ -64,7 +64,9 @@ enum spi_nor_option_flags {
 #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_SST		0xbf
 #define SPI_FLASH_CFI_MFR_WINBOND	0xef
+#define SPI_FLASH_CFI_MFR_ATMEL		0x1f
 
 /* Erase commands */
 #define CMD_ERASE_4K			0x20
drivers/mtd/spi/sf_ops.c +3 -4
index f63ce7a..f90f041 100644
@@ -748,11 +748,10 @@ int spi_flash_scan(struct spi_slave *spi, struct spi_flash *flash)
 	}
 
 	/* Flash powers up read-only, so clear BP# bits */
-#if defined(CONFIG_SPI_FLASH_ATMEL) || \
-	defined(CONFIG_SPI_FLASH_MACRONIX) || \
-	defined(CONFIG_SPI_FLASH_SST)
+	if (idcode[0] == SPI_FLASH_CFI_MFR_ATMEL ||
+	    idcode[0] == SPI_FLASH_CFI_MFR_MACRONIX ||
+	    idcode[0] == SPI_FLASH_CFI_MFR_SST)
 		write_sr(flash, 0);
-#endif
 
 	/* Assign spi data */
 	flash->spi = spi;
Signature · 1 line
1.9.1
author
#9 lore raw

PATCH v5 10/14 sf: Use static for file-scope functions

In reply to Jagan Teki

Use static for file-scope functions and removed
them from header files.

---
 drivers/mtd/spi/sf_internal.h | 20 --------------------
 drivers/mtd/spi/sf_ops.c      | 11 ++++++-----
 2 files changed, 6 insertions(+), 25 deletions(-)
drivers/mtd/spi/sf_internal.h +0 -20
index 39749c2..2873402 100644
@@ -117,11 +117,6 @@ enum spi_nor_option_flags {
 #ifdef CONFIG_SPI_FLASH_SST
 # define CMD_SST_BP		0x02    /* Byte Program */
 # define CMD_SST_AAI_WP		0xAD	/* Auto Address Incr Word Program */
-
-int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,
-		const void *buf);
-int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,
-		const void *buf);
 #endif
 
 /**
@@ -166,9 +161,6 @@ int spi_flash_cmd_write(struct spi_slave *spi, const u8 *cmd, size_t cmd_len,
 		const void *data, size_t data_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);
-
 /* Enable writing on the SPI flash */
 static inline int spi_flash_cmd_write_enable(struct spi_flash *flash)
 {
@@ -193,24 +185,12 @@ int spi_flash_write_common(struct spi_flash *flash, const u8 *cmd,
 		size_t cmd_len, const void *buf, size_t buf_len);
 
 /*
- * Flash write operation, support all possible write commands.
- * Write the requested data out breaking it up into multiple write
- * commands as needed per the write size.
- */
-int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
-		size_t len, const void *buf);
-
-/*
  * Same as spi_flash_cmd_read() except it also claims/releases the SPI
  * bus. Used as common part of the ->read() operation.
  */
 int spi_flash_read_common(struct spi_flash *flash, const u8 *cmd,
 		size_t cmd_len, void *data, size_t data_len);
 
-/* Flash read operation, support all possible read commands */
-int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
-		size_t len, void *data);
-
 #ifdef CONFIG_SPI_FLASH_MTD
 int spi_flash_mtd_register(struct spi_flash *flash);
 void spi_flash_mtd_unregister(void);
drivers/mtd/spi/sf_ops.c +6 -5
index f90f041..e04f8aa 100644
@@ -298,7 +298,8 @@ int spi_flash_write_common(struct spi_flash *flash, const u8 *cmd,
 	return ret;
 }
 
-int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len)
+static int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset,
+					size_t len)
 {
 	u32 erase_size, erase_addr;
 	u8 cmd[SPI_FLASH_CMD_LEN];
@@ -341,7 +342,7 @@ int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len)
 	return ret;
 }
 
-int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
+static int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
 		size_t len, const void *buf)
 {
 	unsigned long byte_addr, page_size;
@@ -418,7 +419,7 @@ void __weak spi_flash_copy_mmap(void *data, void *offset, size_t len)
 	memcpy(data, offset, len);
 }
 
-int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
+static int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
 		size_t len, void *data)
 {
 	u8 *cmd, cmdsz;
@@ -510,7 +511,7 @@ static int sst_byte_write(struct spi_flash *flash, u32 offset, const void *buf)
 	return spi_flash_cmd_wait_ready(flash, SPI_FLASH_PROG_TIMEOUT);
 }
 
-int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,
+static int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,
 		const void *buf)
 {
 	size_t actual, cmd_len;
@@ -577,7 +578,7 @@ int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,
 	return ret;
 }
 
-int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,
+static int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,
 		const void *buf)
 {
 	size_t actual;
Signature · 1 line
1.9.1
author
#10 lore raw

PATCH v5 11/14 sf: Remove unneeded header includes

In reply to Jagan Teki

Removed unneeded header includes in sf_ops and sf_probe.

---
 drivers/mtd/spi/sf_ops.c   | 2 --
 drivers/mtd/spi/sf_probe.c | 3 ---
 2 files changed, 5 deletions(-)
drivers/mtd/spi/sf_ops.c +0 -2
index e04f8aa..d3e8a83 100644
@@ -14,8 +14,6 @@
 #include <mapmem.h>
 #include <spi.h>
 #include <spi_flash.h>
-#include <watchdog.h>
-#include <linux/compiler.h>
 
 #include "sf_internal.h"
 
drivers/mtd/spi/sf_probe.c +0 -3
index e2dac7e..cfc696f 100644
@@ -11,12 +11,9 @@
 #include <common.h>
 #include <dm.h>
 #include <errno.h>
-#include <fdtdec.h>
 #include <malloc.h>
-#include <mapmem.h>
 #include <spi.h>
 #include <spi_flash.h>
-#include <asm/io.h>
 
 #include "sf_internal.h"
 
Signature · 1 line
1.9.1
author
#11 lore raw

PATCH v5 12/14 sf: probe: Use spi_flash_scan in dm-spi-flash

In reply to Jagan Teki

This patch add support to use spi_flash_scan in dm-spi-flash probe, so-that it can access
the spi_flash functionalities same as non-dm sf probe.

---
 drivers/mtd/spi/sf_probe.c | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)
drivers/mtd/spi/sf_probe.c +25 -3
index cfc696f..6ce82a7 100644
@@ -137,14 +137,36 @@ int spi_flash_std_erase(struct udevice *dev, u32 offset, size_t len)
 
 int spi_flash_std_probe(struct udevice *dev)
 {
-	struct spi_slave *slave = dev_get_parentdata(dev);
 	struct dm_spi_slave_platdata *plat = dev_get_parent_platdata(dev);
+	struct spi_slave *slave = dev_get_parentdata(dev);
 	struct spi_flash *flash;
+	int ret;
+
+	debug("%s: slave=%p, cs=%d\n", __func__, slave, plat->cs);
 
 	flash = dev_get_uclass_priv(dev);
 	flash->dev = dev;
-	debug("%s: slave=%p, cs=%d\n", __func__, slave, plat->cs);
-	return spi_flash_probe_slave(slave, flash);
+
+	/* Claim spi bus */
+	ret = spi_claim_bus(slave);
+	if (ret) {
+		debug("SF: Failed to claim SPI bus: %d\n", ret);
+		return ret;
+	}
+
+	ret = spi_flash_scan(slave, flash);
+	if (ret) {
+		ret = -EINVAL;
+		goto err_read_id;
+	}
+
+#ifdef CONFIG_SPI_FLASH_MTD
+	ret = spi_flash_mtd_register(flash);
+#endif
+
+err_read_id:
+	spi_release_bus(slave);
+	return ret;
 }
 
 static const struct dm_spi_flash_ops spi_flash_std_ops = {
Signature · 1 line
1.9.1
author
#12 lore raw

PATCH v5 13/14 sf: Re-factorize spi_flash_probe_tail code

In reply to Jagan Teki

spi_flash_probe_tail code looks not in proper shape to add more functionalities. hence refactorized so-that it's more readable and hence we may extend more functionalies to it.

---
 drivers/mtd/spi/sf_internal.h |  3 +-
 drivers/mtd/spi/sf_ops.c      |  7 ++---
 drivers/mtd/spi/sf_probe.c    | 72 +++++++++++++++++--------------------------
 3 files changed, 33 insertions(+), 49 deletions(-)
drivers/mtd/spi/sf_internal.h +1 -2
index 2873402..d74bc18 100644
@@ -198,7 +198,6 @@ void spi_flash_mtd_unregister(void);
 
 /**
  * spi_flash_scan - scan the SPI FLASH
- * @spi:	the spi slave structure
  * @flash:	the spi flash structure
  *
  * The drivers can use this fuction to scan the SPI FLASH.
@@ -207,6 +206,6 @@ void spi_flash_mtd_unregister(void);
  *
  * Return: 0 for success, others for failure.
  */
-int spi_flash_scan(struct spi_slave *spi, struct spi_flash *flash);
+int spi_flash_scan(struct spi_flash *flash);
 
 #endif /* _SF_INTERNAL_H_ */
drivers/mtd/spi/sf_ops.c +3 -4
index d3e8a83..703099f 100644
@@ -703,7 +703,7 @@ int spi_flash_decode_fdt(const void *blob, struct spi_flash *flash)
 }
 #endif /* CONFIG_IS_ENABLED(OF_CONTROL) */
 
-int spi_flash_scan(struct spi_slave *spi, struct spi_flash *flash)
+int spi_flash_scan(struct spi_flash *flash)
 {
 	const struct spi_flash_params *params;
 	u16 jedec, ext_jedec;
@@ -712,7 +712,7 @@ int spi_flash_scan(struct spi_slave *spi, struct spi_flash *flash)
 	int ret;
 
 	/* Read the ID codes */
-	ret = spi_flash_cmd(spi, CMD_READ_ID, idcode, sizeof(idcode));
+	ret = spi_flash_cmd(flash->spi, CMD_READ_ID, idcode, sizeof(idcode));
 	if (ret) {
 		printf("SF: Failed to get idcodes\n");
 		return -EINVAL;
@@ -753,9 +753,8 @@ int spi_flash_scan(struct spi_slave *spi, struct spi_flash *flash)
 		write_sr(flash, 0);
 
 	/* Assign spi data */
-	flash->spi = spi;
 	flash->name = params->name;
-	flash->memory_map = spi->memory_map;
+	flash->memory_map = flash->spi->memory_map;
 	flash->dual_flash = flash->spi->option;
 
 	/* Assign spi_flash ops */
drivers/mtd/spi/sf_probe.c +29 -43

91 lines not on this page · raw message

Signature · 1 line
1.9.1
author
#13 lore raw

PATCH v5 14/14 dm-sf: Re-factorize spi_flash_std_probe code

In reply to Jagan Teki

spi_flash_probe_tail code looks not in proper shape to add more functionalities. hence refactorized so-that it's more readable and hence we may extend more functionalies to it.

---
 drivers/mtd/spi/sf_probe.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
drivers/mtd/spi/sf_probe.c +14 -8
index 319b7e6..87ac33e 100644
@@ -123,15 +123,12 @@ int spi_flash_std_erase(struct udevice *dev, u32 offset, size_t len)
 
 int spi_flash_std_probe(struct udevice *dev)
 {
-	struct dm_spi_slave_platdata *plat = dev_get_parent_platdata(dev);
+	struct spi_flash *flash = dev_get_uclass_priv(dev);
 	struct spi_slave *slave = dev_get_parentdata(dev);
-	struct spi_flash *flash;
 	int ret;
 
-	debug("%s: slave=%p, cs=%d\n", __func__, slave, plat->cs);
-
-	flash = dev_get_uclass_priv(dev);
 	flash->dev = dev;
+	flash->spi = slave;
 
 	/* Claim spi bus */
 	ret = spi_claim_bus(slave);
@@ -140,17 +137,26 @@ int spi_flash_std_probe(struct udevice *dev)
 		return ret;
 	}
 
-	ret = spi_flash_scan(slave, flash);
+	ret = spi_flash_scan(flash);
 	if (ret) {
 		ret = -EINVAL;
-		goto err_read_id;
+		goto err_scan;
 	}
 
 #ifdef CONFIG_SPI_FLASH_MTD
 	ret = spi_flash_mtd_register(flash);
+	if (ret) {
+		printf("SF: failed to register mtd device: %d\n", ret);
+		goto err_mtd;
+	}
 #endif
+	return ret;
 
-err_read_id:
+#ifdef CONFIG_SPI_FLASH_MTD
+err_mtd:
+	spi_free_slave(slave);
+#endif
+err_scan:
 	spi_release_bus(slave);
 	return ret;
 }
Signature · 1 line
1.9.1
#14 lore raw

PATCH v5 14/14 dm-sf: Re-factorize spi_flash_std_probe code

Quoted 33 lines · Jagan Teki

spi_flash_probe_tail code looks not in proper shape to add more functionalities. hence refactorized so-that it's more readable and hence we may extend more functionalies to it.

---
 drivers/mtd/spi/sf_probe.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
drivers/mtd/spi/sf_probe.c +2 -5
index 319b7e6..87ac33e 100644
@@ -123,15 +123,12 @@ int spi_flash_std_erase(struct udevice *dev, u32 offset, size_t len)
 
 int spi_flash_std_probe(struct udevice *dev)
 {
-	struct dm_spi_slave_platdata *plat = dev_get_parent_platdata(dev);
+	struct spi_flash *flash = dev_get_uclass_priv(dev);
 	struct spi_slave *slave = dev_get_parentdata(dev);
-	struct spi_flash *flash;
 	int ret;
 
-	debug("%s: slave=%p, cs=%d\n", __func__, slave, plat->cs);
-
-	flash = dev_get_uclass_priv(dev);
 	flash->dev = dev;
+	flash->spi = slave;
 
 	/* Claim spi bus */
 	ret = spi_claim_bus(slave);

drivers/mtd/spi/sf_probe.c int spi_flash_std_probe(struct udevice *dev) · line 140

Quoted 5 lines
drivers/mtd/spi/sf_probe.c +1 -1
@@ -140,17 +137,26 @@ int spi_flash_std_probe(struct udevice *dev)
 		return ret;
 	}
 
-	ret = spi_flash_scan(slave, flash);
+	ret = spi_flash_scan(flash);

Is this bisectable ? It doesn't look like it.

Quoted 25 lines
drivers/mtd/spi/sf_probe.c +11 -2
 	if (ret) {
 		ret = -EINVAL;
-		goto err_read_id;
+		goto err_scan;
 	}
 
 #ifdef CONFIG_SPI_FLASH_MTD
 	ret = spi_flash_mtd_register(flash);
+	if (ret) {
+		printf("SF: failed to register mtd device: %d\n", ret);
+		goto err_mtd;
+	}
 #endif
+	return ret;
 
-err_read_id:
+#ifdef CONFIG_SPI_FLASH_MTD
+err_mtd:
+	spi_free_slave(slave);
+#endif
+err_scan:
 	spi_release_bus(slave);
 	return ret;
 }
author
#15 lore raw

PATCH v5 14/14 dm-sf: Re-factorize spi_flash_std_probe code

Quoted 37 lines · Troy Kisky
Quoted 36 lines · Jagan Teki

spi_flash_probe_tail code looks not in proper shape to add more functionalities. hence refactorized so-that it's more readable and hence we may extend more functionalies to it.

---
 drivers/mtd/spi/sf_probe.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
drivers/mtd/spi/sf_probe.c +2 -5
index 319b7e6..87ac33e 100644
@@ -123,15 +123,12 @@ int spi_flash_std_erase(struct udevice *dev, u32 offset, size_t len)
 
 int spi_flash_std_probe(struct udevice *dev)
 {
-     struct dm_spi_slave_platdata *plat = dev_get_parent_platdata(dev);
+     struct spi_flash *flash = dev_get_uclass_priv(dev);
      struct spi_slave *slave = dev_get_parentdata(dev);
-     struct spi_flash *flash;
      int ret;
 
-     debug("%s: slave=%p, cs=%d\n", __func__, slave, plat->cs);
-
-     flash = dev_get_uclass_priv(dev);
      flash->dev = dev;
+     flash->spi = slave;
 
      /* Claim spi bus */
      ret = spi_claim_bus(slave);
@@ -140,17 +137,26 @@ int spi_flash_std_probe(struct udevice *dev)
              return ret;
      }
 
Quoted 6 lines

drivers/mtd/spi/sf_probe.c int spi_flash_std_probe(struct udevice *dev) · line 140

Quoted 2 lines
drivers/mtd/spi/sf_probe.c +1 -1
-     ret = spi_flash_scan(slave, flash);
+     ret = spi_flash_scan(flash);

Is this bisectable ? It doesn't look like it.

What you mean bisectable here? This commit re-factorize the code in accordance with changes introduced in v5 13/14 on dm-sf front.

Quoted 26 lines
Quoted 26 lines
drivers/mtd/spi/sf_probe.c +11 -2
      if (ret) {
              ret = -EINVAL;
-             goto err_read_id;
+             goto err_scan;
      }
 
 #ifdef CONFIG_SPI_FLASH_MTD
      ret = spi_flash_mtd_register(flash);
+     if (ret) {
+             printf("SF: failed to register mtd device: %d\n", ret);
+             goto err_mtd;
+     }
 #endif
+     return ret;
 
-err_read_id:
+#ifdef CONFIG_SPI_FLASH_MTD
+err_mtd:
+     spi_free_slave(slave);
+#endif
+err_scan:
      spi_release_bus(slave);
      return ret;
 }
Signature · 1 line
Jagan | openedev.
#16 lore raw

PATCH v5 14/14 dm-sf: Re-factorize spi_flash_std_probe code

Hi Jagan,

Quoted 45 lines · Jagan Teki
Quoted 37 lines · Troy Kisky
Quoted 36 lines · Jagan Teki

spi_flash_probe_tail code looks not in proper shape to add more functionalities. hence refactorized so-that it's more readable and hence we may extend more functionalies to it.

---
 drivers/mtd/spi/sf_probe.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
drivers/mtd/spi/sf_probe.c +2 -5
index 319b7e6..87ac33e 100644
@@ -123,15 +123,12 @@ int spi_flash_std_erase(struct udevice *dev, u32 offset, size_t len)
 
 int spi_flash_std_probe(struct udevice *dev)
 {
-     struct dm_spi_slave_platdata *plat = dev_get_parent_platdata(dev);
+     struct spi_flash *flash = dev_get_uclass_priv(dev);
      struct spi_slave *slave = dev_get_parentdata(dev);
-     struct spi_flash *flash;
      int ret;
 
-     debug("%s: slave=%p, cs=%d\n", __func__, slave, plat->cs);
-
-     flash = dev_get_uclass_priv(dev);
      flash->dev = dev;
+     flash->spi = slave;
 
      /* Claim spi bus */
      ret = spi_claim_bus(slave);
@@ -140,17 +137,26 @@ int spi_flash_std_probe(struct udevice *dev)
              return ret;
      }
 
Quoted 6 lines

drivers/mtd/spi/sf_probe.c int spi_flash_std_probe(struct udevice *dev) · line 140

Quoted 2 lines
drivers/mtd/spi/sf_probe.c +1 -1
-     ret = spi_flash_scan(slave, flash);
+     ret = spi_flash_scan(flash);

Is this bisectable ? It doesn't look like it.

Quoted 3 lines

What you mean bisectable here? This commit re-factorize the code in accordance with changes introduced in v5 13/14 on dm-sf front.

We should make sure every commit can build successfully, aka bisectable via 'git bisect'. It looks like you changed the spi_flash_scan() function signature somewhere else, but not in this commit, hence the question bisectable?

Regards,
Bin

author
#17 lore raw

PATCH v5 14/14 dm-sf: Re-factorize spi_flash_std_probe code

Quoted 9 lines · Bin Meng

Hi Jagan,

Quoted 6 lines · Jagan Teki
Quoted 5 lines · Troy Kisky
Quoted 4 lines · Jagan Teki

spi_flash_probe_tail code looks not in proper shape to add more functionalities. hence refactorized so-that it's more readable and hence we may extend more functionalies to it.

Thanks Bin, for the info I will move spi_flash_scan change back to 13/14 patch.

Quoted 54 lines
Quoted 39 lines
Quoted 32 lines
Quoted 32 lines
---
 drivers/mtd/spi/sf_probe.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
drivers/mtd/spi/sf_probe.c +2 -5
index 319b7e6..87ac33e 100644
@@ -123,15 +123,12 @@ int spi_flash_std_erase(struct udevice *dev, u32 offset, size_t len)
 
 int spi_flash_std_probe(struct udevice *dev)
 {
-     struct dm_spi_slave_platdata *plat = dev_get_parent_platdata(dev);
+     struct spi_flash *flash = dev_get_uclass_priv(dev);
      struct spi_slave *slave = dev_get_parentdata(dev);
-     struct spi_flash *flash;
      int ret;
 
-     debug("%s: slave=%p, cs=%d\n", __func__, slave, plat->cs);
-
-     flash = dev_get_uclass_priv(dev);
      flash->dev = dev;
+     flash->spi = slave;
 
      /* Claim spi bus */
      ret = spi_claim_bus(slave);
@@ -140,17 +137,26 @@ int spi_flash_std_probe(struct udevice *dev)
              return ret;
      }
 
Quoted 6 lines

drivers/mtd/spi/sf_probe.c int spi_flash_std_probe(struct udevice *dev) · line 140

Quoted 2 lines
drivers/mtd/spi/sf_probe.c +1 -1
-     ret = spi_flash_scan(slave, flash);
+     ret = spi_flash_scan(flash);

Is this bisectable ? It doesn't look like it.

Quoted 3 lines

What you mean bisectable here? This commit re-factorize the code in accordance with changes introduced in v5 13/14 on dm-sf front.

We should make sure every commit can build successfully, aka bisectable via 'git bisect'. It looks like you changed the spi_flash_scan() function signature somewhere else, but not in this commit, hence the question bisectable?

Regards,
Bin
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Signature · 1 line
Jagan | openedev.