All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v6 00/23] sf: MTD support
@ 2015-11-07 13:46 Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 01/23] sf: spi_flash_validate_params => spi_flash_scan Jagan Teki
                   ` (22 more replies)
  0 siblings, 23 replies; 24+ messages in thread
From: Jagan Teki @ 2015-11-07 13:46 UTC (permalink / raw)
  To: u-boot

This series is combination of mtd and sf tunning stuff in previous
version patches.

This is whole patch series for add mtd support to spi-flash
framework and related stuff.

The idea is to introduce the spi-nor flash framework which
similar to Linux with driver-model support.

spi-nor looks:

-----------------------------------------------------------
    cmd_spi                 cmd_sf
------|----------------------------------------------------
      |                    spi_flash
------|----------------------------------------------------
      |                     MTD Core
------|----------------------------------------------------
      |                     sf-uclass
------|----------------------------------------------------
      |                   SPI-NOR Core
------V----------------------------------------------------
   spi-uclass <---->spi-nor-flash         drivers/mtd/spi/*
-----------------------------------------------------------
  drivers/spi/*
-----------------------------------------------------------

drivers/mtd/spi/spi-nor.c: spi-nor core
drivers/mtd/spi/spi-flash-nor.c: spi-nor to spi drivers interface
drivers/mtd/spi/fsl-quadspi.c: spi-nor controller driver

Changes in this series:
- drivers/mtd/spi/sf_probe.c: spi-flash to spi drivers interface(dm and non-dm)
- drivers/mtd/spi/sf_ops.c: Core spi-flash functionalities.
- spi_flash ops and dm_spi_ops are not needed as flash opertaion are
  common for dm and non-dm via MTD

Changes in v5, v6, v3, v2:
	- One patch bisectable separation
	- Rebase to master
	- added newly mtd stuff patches.

Jagan Teki (23):
  sf: spi_flash_validate_params => spi_flash_scan
  sf: Move spi_flash_scan code to sf_ops
  sf: Move read_id code to sf_ops
  sf: probe: Code cleanup
  sf: Use static for file-scope functions
  sf: Fix Makefile
  sf: Use simple name for register access functions
  sf: Use flash function pointers in dm_spi_flash_ops
  sf: Flash power up read-only based on idcode0
  sf: Use static for file-scope functions
  sf: Remove unneeded header includes
  sf: probe: Use spi_flash_scan in dm-spi-flash
  sf: Re-factorize spi_flash_probe_tail code
  dm-sf: Re-factorize spi_flash_std_probe code
  sf: Add MTD support to spi_flash
  sf: Use mtd_info ops instead of spi_flash ops
  cmd_sf: Use mtd->size instead of flash->size
  dm-sf: use mtd_ops, drop dm_spi_flash_ops
  sf: Use MTD lock operations
  sf: Add MTD support for non-dm spi_flash interface
  sf: probe: Minor cleanup
  sf: Drop SPI_FLASH_MTD driver
  configs: Remove CONFIG_SPI_FLASH_MTD

 common/cmd_sf.c                       |  16 +-
 drivers/mtd/spi/Kconfig               |  12 -
 drivers/mtd/spi/Makefile              |   7 +-
 drivers/mtd/spi/sf-uclass.c           |  16 -
 drivers/mtd/spi/sf_internal.h         |  65 +--
 drivers/mtd/spi/sf_mtd.c              | 104 -----
 drivers/mtd/spi/sf_ops.c              | 746 ++++++++++++++++++++++++++--------
 drivers/mtd/spi/sf_probe.c            | 504 ++++-------------------
 include/configs/aristainetos-common.h |   1 -
 include/configs/gw_ventana.h          |   1 -
 include/configs/socfpga_common.h      |   1 -
 include/spi_flash.h                   | 163 ++------
 12 files changed, 703 insertions(+), 933 deletions(-)
 delete mode 100644 drivers/mtd/spi/sf_mtd.c

-- 
1.9.1

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v6 01/23] sf: spi_flash_validate_params => spi_flash_scan
  2015-11-07 13:46 [U-Boot] [PATCH v6 00/23] sf: MTD support Jagan Teki
@ 2015-11-07 13:46 ` Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 02/23] sf: Move spi_flash_scan code to sf_ops Jagan Teki
                   ` (21 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: Jagan Teki @ 2015-11-07 13:46 UTC (permalink / raw)
  To: u-boot

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.

Signed-off-by: Jagan Teki <jteki@openedev.com>
---
 drivers/mtd/spi/sf_probe.c | 145 +++++++++++++++++++++++----------------------
 1 file changed, 75 insertions(+), 70 deletions(-)

diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
index bc05d30..6db9e8c 100644
--- a/drivers/mtd/spi/sf_probe.c
+++ b/drivers/mtd/spi/sf_probe.c
@@ -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;
@@ -251,6 +287,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
@@ -277,48 +324,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
@@ -357,47 +397,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
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v6 02/23] sf: Move spi_flash_scan code to sf_ops
  2015-11-07 13:46 [U-Boot] [PATCH v6 00/23] sf: MTD support Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 01/23] sf: spi_flash_validate_params => spi_flash_scan Jagan Teki
@ 2015-11-07 13:46 ` Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 03/23] sf: Move read_id " Jagan Teki
                   ` (20 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: Jagan Teki @ 2015-11-07 13:46 UTC (permalink / raw)
  To: u-boot

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

Signed-off-by: Jagan Teki <jteki@openedev.com>
---
 drivers/mtd/spi/sf_internal.h |  14 ++
 drivers/mtd/spi/sf_ops.c      | 341 ++++++++++++++++++++++++++++++++++++++++++
 drivers/mtd/spi/sf_probe.c    | 340 -----------------------------------------
 3 files changed, 355 insertions(+), 340 deletions(-)

diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h
index 8793f18..bf6b485 100644
--- a/drivers/mtd/spi/sf_internal.h
+++ b/drivers/mtd/spi/sf_internal.h
@@ -244,4 +244,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_ */
diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c
index d832464..2814bf1 100644
--- a/drivers/mtd/spi/sf_ops.c
+++ b/drivers/mtd/spi/sf_ops.c
@@ -11,6 +11,7 @@
 #include <common.h>
 #include <errno.h>
 #include <malloc.h>
+#include <mapmem.h>
 #include <spi.h>
 #include <spi_flash.h>
 #include <watchdog.h>
@@ -19,6 +20,8 @@
 
 #include "sf_internal.h"
 
+DECLARE_GLOBAL_DATA_PTR;
+
 static void spi_flash_addr(u32 addr, u8 *cmd)
 {
 	/* cmd[0] is actual command */
@@ -745,3 +748,341 @@ int stm_unlock(struct spi_flash *flash, u32 ofs, size_t len)
 	return 0;
 }
 #endif  /* CONFIG_SPI_FLASH_STMICRO */
+
+
+/* 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)
+{
+	u8 qeb_status;
+	int ret;
+
+	ret = spi_flash_cmd_read_status(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);
+		if (ret < 0)
+			return ret;
+	}
+
+	return ret;
+}
+#endif
+
+#if defined(CONFIG_SPI_FLASH_SPANSION) || defined(CONFIG_SPI_FLASH_WINBOND)
+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);
+	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);
+		if (ret < 0)
+			return ret;
+	}
+
+	return ret;
+}
+#endif
+
+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:
+		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;
+	}
+}
+
+#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)
+{
+	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) */
+
+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;
+	for (; params->name != NULL; params++) {
+		if ((params->jedec >> 16) == idcode[0]) {
+			if ((params->jedec & 0xFFFF) == jedec) {
+				if (params->ext_jedec == 0)
+					break;
+				else if (params->ext_jedec == ext_jedec)
+					break;
+			}
+		}
+	}
+
+	if (!params->name) {
+		printf("SF: Unsupported flash IDs: ");
+		printf("manuf %02x, jedec %04x, ext_jedec %04x\n",
+		       idcode[0], jedec, ext_jedec);
+		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;
+	flash->memory_map = spi->memory_map;
+	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)
+		flash->flags |= SNOR_F_SST_WR;
+
+	if (params->flags & SNOR_F_SST_WR) {
+		if (flash->spi->op_mode_tx & SPI_OPM_TX_BP)
+			flash->write = sst_write_bp;
+		else
+			flash->write = sst_write_wp;
+	}
+#endif
+	flash->erase = spi_flash_cmd_erase_ops;
+	flash->read = spi_flash_cmd_read_ops;
+#endif
+
+	/* lock hooks are flash specific - assign them based on idcode0 */
+	switch (idcode[0]) {
+#ifdef CONFIG_SPI_FLASH_STMICRO
+	case SPI_FLASH_CFI_MFR_STMICRO:
+		flash->flash_lock = stm_lock;
+		flash->flash_unlock = stm_unlock;
+		flash->flash_is_locked = stm_is_locked;
+#endif
+		break;
+	default:
+		debug("SF: Lock ops not supported for %02x flash\n", idcode[0]);
+	}
+
+	/* Compute the flash size */
+	flash->shift = (flash->dual_flash & SF_DUAL_PARALLEL_FLASH) ? 1 : 0;
+	/*
+	 * 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))
+			flash->page_size = 256;
+		else
+			flash->page_size = 512;
+	} else {
+		flash->page_size = 256;
+	}
+	flash->page_size <<= 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) {
+		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;
+	}
+
+	/* 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 & flash->spi->op_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;
+	}
+
+	/* Not require to look for fastest only two write cmds yet */
+	if (params->flags & WR_QPP && flash->spi->op_mode_tx & SPI_OPM_TX_QPP)
+		flash->write_cmd = CMD_QUAD_PAGE_PROGRAM;
+	else
+		/* 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
+	 * 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;
+	}
+
+#ifdef CONFIG_SPI_FLASH_STMICRO
+	if (params->flags & E_FSR)
+		flash->flags |= SNOR_F_USE_FSR;
+#endif
+
+	/* Configure the BAR - discover bank cmds and read current bank */
+#ifdef CONFIG_SPI_FLASH_BAR
+	ret = spi_flash_read_bank(flash, idcode[0]);
+	if (ret < 0)
+		return ret;
+#endif
+
+#if CONFIG_IS_ENABLED(OF_CONTROL)
+	ret = spi_flash_decode_fdt(gd->fdt_blob, flash);
+	if (ret) {
+		debug("SF: FDT decode error\n");
+		return -EINVAL;
+	}
+#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
+
+	return ret;
+}
diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
index 6db9e8c..994559d 100644
--- a/drivers/mtd/spi/sf_probe.c
+++ b/drivers/mtd/spi/sf_probe.c
@@ -20,346 +20,6 @@
 
 #include "sf_internal.h"
 
-DECLARE_GLOBAL_DATA_PTR;
-
-/* 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)
-{
-	u8 qeb_status;
-	int ret;
-
-	ret = spi_flash_cmd_read_status(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);
-		if (ret < 0)
-			return ret;
-	}
-
-	return ret;
-}
-#endif
-
-#if defined(CONFIG_SPI_FLASH_SPANSION) || defined(CONFIG_SPI_FLASH_WINBOND)
-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);
-	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);
-		if (ret < 0)
-			return ret;
-	}
-
-	return ret;
-}
-#endif
-
-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:
-		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;
-	}
-}
-
-#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)
-{
-	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;
-	for (; params->name != NULL; params++) {
-		if ((params->jedec >> 16) == idcode[0]) {
-			if ((params->jedec & 0xFFFF) == jedec) {
-				if (params->ext_jedec == 0)
-					break;
-				else if (params->ext_jedec == ext_jedec)
-					break;
-			}
-		}
-	}
-
-	if (!params->name) {
-		printf("SF: Unsupported flash IDs: ");
-		printf("manuf %02x, jedec %04x, ext_jedec %04x\n",
-		       idcode[0], jedec, ext_jedec);
-		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;
-	flash->memory_map = spi->memory_map;
-	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)
-		flash->flags |= SNOR_F_SST_WR;
-
-	if (params->flags & SNOR_F_SST_WR) {
-		if (flash->spi->op_mode_tx & SPI_OPM_TX_BP)
-			flash->write = sst_write_bp;
-		else
-			flash->write = sst_write_wp;
-	}
-#endif
-	flash->erase = spi_flash_cmd_erase_ops;
-	flash->read = spi_flash_cmd_read_ops;
-#endif
-
-	/* lock hooks are flash specific - assign them based on idcode0 */
-	switch (idcode[0]) {
-#ifdef CONFIG_SPI_FLASH_STMICRO
-	case SPI_FLASH_CFI_MFR_STMICRO:
-		flash->flash_lock = stm_lock;
-		flash->flash_unlock = stm_unlock;
-		flash->flash_is_locked = stm_is_locked;
-#endif
-		break;
-	default:
-		debug("SF: Lock ops not supported for %02x flash\n", idcode[0]);
-	}
-
-	/* Compute the flash size */
-	flash->shift = (flash->dual_flash & SF_DUAL_PARALLEL_FLASH) ? 1 : 0;
-	/*
-	 * 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))
-			flash->page_size = 256;
-		else
-			flash->page_size = 512;
-	} else {
-		flash->page_size = 256;
-	}
-	flash->page_size <<= 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) {
-		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;
-	}
-
-	/* 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 & flash->spi->op_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;
-	}
-
-	/* Not require to look for fastest only two write cmds yet */
-	if (params->flags & WR_QPP && flash->spi->op_mode_tx & SPI_OPM_TX_QPP)
-		flash->write_cmd = CMD_QUAD_PAGE_PROGRAM;
-	else
-		/* 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
-	 * 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;
-	}
-
-#ifdef CONFIG_SPI_FLASH_STMICRO
-	if (params->flags & E_FSR)
-		flash->flags |= SNOR_F_USE_FSR;
-#endif
-
-	/* Configure the BAR - discover bank cmds and read current bank */
-#ifdef CONFIG_SPI_FLASH_BAR
-	ret = spi_flash_read_bank(flash, idcode[0]);
-	if (ret < 0)
-		return ret;
-#endif
-
-#if CONFIG_IS_ENABLED(OF_CONTROL)
-	ret = spi_flash_decode_fdt(gd->fdt_blob, flash);
-	if (ret) {
-		debug("SF: FDT decode error\n");
-		return -EINVAL;
-	}
-#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
-
-	return ret;
-}
-
 /**
  * spi_flash_probe_slave() - Probe for a SPI flash device on a bus
  *
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v6 03/23] sf: Move read_id code to sf_ops
  2015-11-07 13:46 [U-Boot] [PATCH v6 00/23] sf: MTD support Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 01/23] sf: spi_flash_validate_params => spi_flash_scan Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 02/23] sf: Move spi_flash_scan code to sf_ops Jagan Teki
@ 2015-11-07 13:46 ` Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 04/23] sf: probe: Code cleanup Jagan Teki
                   ` (19 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: Jagan Teki @ 2015-11-07 13:46 UTC (permalink / raw)
  To: u-boot

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

Signed-off-by: Jagan Teki <jteki@openedev.com>
---
 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(-)

diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h
index bf6b485..d1469f4 100644
--- a/drivers/mtd/spi/sf_internal.h
+++ b/drivers/mtd/spi/sf_internal.h
@@ -247,7 +247,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.
@@ -256,6 +255,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_ */
diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c
index 2814bf1..37dfd79 100644
--- a/drivers/mtd/spi/sf_ops.c
+++ b/drivers/mtd/spi/sf_ops.c
@@ -886,14 +886,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++) {
diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
index 994559d..e35b917 100644
--- a/drivers/mtd/spi/sf_probe.c
+++ b/drivers/mtd/spi/sf_probe.c
@@ -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;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v6 04/23] sf: probe: Code cleanup
  2015-11-07 13:46 [U-Boot] [PATCH v6 00/23] sf: MTD support Jagan Teki
                   ` (2 preceding siblings ...)
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 03/23] sf: Move read_id " Jagan Teki
@ 2015-11-07 13:46 ` Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 05/23] sf: Use static for file-scope functions Jagan Teki
                   ` (18 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: Jagan Teki @ 2015-11-07 13:46 UTC (permalink / raw)
  To: u-boot

- 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

Signed-off-by: Jagan Teki <jteki@openedev.com>
---
 drivers/mtd/spi/sf_ops.c | 80 +++++++++++++++++++++++-------------------------
 1 file changed, 39 insertions(+), 41 deletions(-)

diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c
index 37dfd79..d88fb69 100644
--- a/drivers/mtd/spi/sf_ops.c
+++ b/drivers/mtd/spi/sf_ops.c
@@ -30,6 +30,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;
@@ -133,6 +143,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
@@ -750,16 +789,6 @@ int stm_unlock(struct spi_flash *flash, u32 ofs, size_t len)
 #endif  /* CONFIG_SPI_FLASH_STMICRO */
 
 
-/* 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)
 {
@@ -827,37 +856,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)
 {
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v6 05/23] sf: Use static for file-scope functions
  2015-11-07 13:46 [U-Boot] [PATCH v6 00/23] sf: MTD support Jagan Teki
                   ` (3 preceding siblings ...)
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 04/23] sf: probe: Code cleanup Jagan Teki
@ 2015-11-07 13:46 ` Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 06/23] sf: Fix Makefile Jagan Teki
                   ` (17 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: Jagan Teki @ 2015-11-07 13:46 UTC (permalink / raw)
  To: u-boot

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

Signed-off-by: Jagan Teki <jteki@openedev.com>
---
 drivers/mtd/spi/sf_internal.h | 18 ------------------
 drivers/mtd/spi/sf_ops.c      | 11 ++++++-----
 2 files changed, 6 insertions(+), 23 deletions(-)

diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h
index d1469f4..f927d4d 100644
--- a/drivers/mtd/spi/sf_internal.h
+++ b/drivers/mtd/spi/sf_internal.h
@@ -170,12 +170,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);
-
 /* Lock stmicro spi flash region */
 int stm_lock(struct spi_flash *flash, u32 ofs, size_t len);
 
@@ -185,12 +179,6 @@ int stm_unlock(struct spi_flash *flash, u32 ofs, size_t len);
 /* Check if a stmicro spi flash region is completely locked */
 int stm_is_locked(struct spi_flash *flash, u32 ofs, size_t len);
 
-/* 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)
 {
@@ -204,12 +192,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
diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c
index d88fb69..17e121d 100644
--- a/drivers/mtd/spi/sf_ops.c
+++ b/drivers/mtd/spi/sf_ops.c
@@ -40,7 +40,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;
@@ -69,7 +69,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;
@@ -85,7 +85,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;
@@ -100,7 +100,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;
@@ -238,7 +238,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;
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v6 06/23] sf: Fix Makefile
  2015-11-07 13:46 [U-Boot] [PATCH v6 00/23] sf: MTD support Jagan Teki
                   ` (4 preceding siblings ...)
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 05/23] sf: Use static for file-scope functions Jagan Teki
@ 2015-11-07 13:46 ` Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 07/23] sf: Use simple name for register access functions Jagan Teki
                   ` (16 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: Jagan Teki @ 2015-11-07 13:46 UTC (permalink / raw)
  To: u-boot

This patch removes unneeded ifdef and fixed accordingly.

Signed-off-by: Jagan Teki <jteki@openedev.com>
---
 drivers/mtd/spi/Makefile | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/mtd/spi/Makefile b/drivers/mtd/spi/Makefile
index ff48b25..66c4424 100644
--- a/drivers/mtd/spi/Makefile
+++ b/drivers/mtd/spi/Makefile
@@ -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
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v6 07/23] sf: Use simple name for register access functions
  2015-11-07 13:46 [U-Boot] [PATCH v6 00/23] sf: MTD support Jagan Teki
                   ` (5 preceding siblings ...)
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 06/23] sf: Fix Makefile Jagan Teki
@ 2015-11-07 13:46 ` Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 08/23] sf: Use flash function pointers in dm_spi_flash_ops Jagan Teki
                   ` (15 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: Jagan Teki @ 2015-11-07 13:46 UTC (permalink / raw)
  To: u-boot

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

Signed-off-by: Jagan Teki <jteki@openedev.com>
---
 drivers/mtd/spi/sf_ops.c | 42 +++++++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c
index 17e121d..88a5f18 100644
--- a/drivers/mtd/spi/sf_ops.c
+++ b/drivers/mtd/spi/sf_ops.c
@@ -40,7 +40,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;
@@ -69,7 +69,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;
@@ -85,7 +85,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;
@@ -100,13 +100,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;
 
@@ -123,7 +123,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;
@@ -144,7 +144,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;
@@ -175,7 +175,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:
@@ -201,7 +201,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;
 
@@ -322,10 +322,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
@@ -369,10 +369,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
@@ -464,10 +464,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;
@@ -796,14 +796,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;
 	}
@@ -818,14 +818,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;
 	}
@@ -932,7 +932,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 */
@@ -1065,7 +1065,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
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v6 08/23] sf: Use flash function pointers in dm_spi_flash_ops
  2015-11-07 13:46 [U-Boot] [PATCH v6 00/23] sf: MTD support Jagan Teki
                   ` (6 preceding siblings ...)
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 07/23] sf: Use simple name for register access functions Jagan Teki
@ 2015-11-07 13:46 ` Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 09/23] sf: Flash power up read-only based on idcode0 Jagan Teki
                   ` (14 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: Jagan Teki @ 2015-11-07 13:46 UTC (permalink / raw)
  To: u-boot

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.

Signed-off-by: Jagan Teki <jteki@openedev.com>
---
 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(-)

diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c
index 88a5f18..a22b9f9 100644
--- a/drivers/mtd/spi/sf_ops.c
+++ b/drivers/mtd/spi/sf_ops.c
@@ -942,7 +942,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)
@@ -957,7 +956,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
 
 	/* lock hooks are flash specific - assign them based on idcode0 */
 	switch (idcode[0]) {
diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
index e35b917..678b81c 100644
--- a/drivers/mtd/spi/sf_probe.c
+++ b/drivers/mtd/spi/sf_probe.c
@@ -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)
diff --git a/include/spi_flash.h b/include/spi_flash.h
index 0ae0062..dbd75a8 100644
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -94,23 +94,10 @@ struct spi_flash {
 	int (*flash_lock)(struct spi_flash *flash, u32 ofs, size_t len);
 	int (*flash_unlock)(struct spi_flash *flash, u32 ofs, size_t len);
 	int (*flash_is_locked)(struct spi_flash *flash, u32 ofs, size_t len);
-#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 {
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v6 09/23] sf: Flash power up read-only based on idcode0
  2015-11-07 13:46 [U-Boot] [PATCH v6 00/23] sf: MTD support Jagan Teki
                   ` (7 preceding siblings ...)
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 08/23] sf: Use flash function pointers in dm_spi_flash_ops Jagan Teki
@ 2015-11-07 13:46 ` Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 10/23] sf: Use static for file-scope functions Jagan Teki
                   ` (13 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: Jagan Teki @ 2015-11-07 13:46 UTC (permalink / raw)
  To: u-boot

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.

Signed-off-by: Jagan Teki <jteki@openedev.com>
---
 drivers/mtd/spi/sf_internal.h | 2 ++
 drivers/mtd/spi/sf_ops.c      | 7 +++----
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h
index f927d4d..b8692c6 100644
--- a/drivers/mtd/spi/sf_internal.h
+++ b/drivers/mtd/spi/sf_internal.h
@@ -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
diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c
index a22b9f9..d78c3ec 100644
--- a/drivers/mtd/spi/sf_ops.c
+++ b/drivers/mtd/spi/sf_ops.c
@@ -929,11 +929,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;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v6 10/23] sf: Use static for file-scope functions
  2015-11-07 13:46 [U-Boot] [PATCH v6 00/23] sf: MTD support Jagan Teki
                   ` (8 preceding siblings ...)
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 09/23] sf: Flash power up read-only based on idcode0 Jagan Teki
@ 2015-11-07 13:46 ` Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 11/23] sf: Remove unneeded header includes Jagan Teki
                   ` (12 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: Jagan Teki @ 2015-11-07 13:46 UTC (permalink / raw)
  To: u-boot

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

Signed-off-by: Jagan Teki <jteki@openedev.com>
---
 drivers/mtd/spi/sf_internal.h | 21 ---------------------
 drivers/mtd/spi/sf_ops.c      | 11 ++++++-----
 2 files changed, 6 insertions(+), 26 deletions(-)

diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h
index b8692c6..acf76e1 100644
--- a/drivers/mtd/spi/sf_internal.h
+++ b/drivers/mtd/spi/sf_internal.h
@@ -120,11 +120,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
 
 /**
@@ -168,10 +163,6 @@ int spi_flash_cmd_read(struct spi_slave *spi, const u8 *cmd,
 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);
-
 /* Lock stmicro spi flash region */
 int stm_lock(struct spi_flash *flash, u32 ofs, size_t len);
 
@@ -205,24 +196,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);
diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c
index d78c3ec..7638cb1 100644
--- a/drivers/mtd/spi/sf_ops.c
+++ b/drivers/mtd/spi/sf_ops.c
@@ -299,7 +299,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];
@@ -347,7 +348,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;
@@ -429,7 +430,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;
@@ -521,7 +522,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;
@@ -588,7 +589,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;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v6 11/23] sf: Remove unneeded header includes
  2015-11-07 13:46 [U-Boot] [PATCH v6 00/23] sf: MTD support Jagan Teki
                   ` (9 preceding siblings ...)
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 10/23] sf: Use static for file-scope functions Jagan Teki
@ 2015-11-07 13:46 ` Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 12/23] sf: probe: Use spi_flash_scan in dm-spi-flash Jagan Teki
                   ` (11 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: Jagan Teki @ 2015-11-07 13:46 UTC (permalink / raw)
  To: u-boot

Removed unneeded header includes in sf_ops and sf_probe

Signed-off-by: Jagan Teki <jteki@openedev.com>
---
 drivers/mtd/spi/sf_ops.c   | 2 --
 drivers/mtd/spi/sf_probe.c | 3 ---
 2 files changed, 5 deletions(-)

diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c
index 7638cb1..e4f841b 100644
--- a/drivers/mtd/spi/sf_ops.c
+++ b/drivers/mtd/spi/sf_ops.c
@@ -14,8 +14,6 @@
 #include <mapmem.h>
 #include <spi.h>
 #include <spi_flash.h>
-#include <watchdog.h>
-#include <linux/compiler.h>
 #include <linux/log2.h>
 
 #include "sf_internal.h"
diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
index 678b81c..f2e210d 100644
--- a/drivers/mtd/spi/sf_probe.c
+++ b/drivers/mtd/spi/sf_probe.c
@@ -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"
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v6 12/23] sf: probe: Use spi_flash_scan in dm-spi-flash
  2015-11-07 13:46 [U-Boot] [PATCH v6 00/23] sf: MTD support Jagan Teki
                   ` (10 preceding siblings ...)
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 11/23] sf: Remove unneeded header includes Jagan Teki
@ 2015-11-07 13:46 ` Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 13/23] sf: Re-factorize spi_flash_probe_tail code Jagan Teki
                   ` (10 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: Jagan Teki @ 2015-11-07 13:46 UTC (permalink / raw)
  To: u-boot

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.

Signed-off-by: Jagan Teki <jteki@openedev.com>
---
 drivers/mtd/spi/sf_probe.c | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
index f2e210d..60856f9 100644
--- a/drivers/mtd/spi/sf_probe.c
+++ b/drivers/mtd/spi/sf_probe.c
@@ -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_parent_priv(dev);
 	struct dm_spi_slave_platdata *plat = dev_get_parent_platdata(dev);
+	struct spi_slave *slave = dev_get_parent_priv(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 = {
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v6 13/23] sf: Re-factorize spi_flash_probe_tail code
  2015-11-07 13:46 [U-Boot] [PATCH v6 00/23] sf: MTD support Jagan Teki
                   ` (11 preceding siblings ...)
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 12/23] sf: probe: Use spi_flash_scan in dm-spi-flash Jagan Teki
@ 2015-11-07 13:46 ` Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 14/23] dm-sf: Re-factorize spi_flash_std_probe code Jagan Teki
                   ` (9 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: Jagan Teki @ 2015-11-07 13:46 UTC (permalink / raw)
  To: u-boot

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.

Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Troy Kisky <troy.kisky@boundarydevices.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>
---
 drivers/mtd/spi/sf_internal.h |  3 +-
 drivers/mtd/spi/sf_ops.c      |  7 ++--
 drivers/mtd/spi/sf_probe.c    | 74 ++++++++++++++++++-------------------------
 3 files changed, 34 insertions(+), 50 deletions(-)

diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h
index acf76e1..fda49e9 100644
--- a/drivers/mtd/spi/sf_internal.h
+++ b/drivers/mtd/spi/sf_internal.h
@@ -209,7 +209,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.
@@ -218,6 +217,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_ */
diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c
index e4f841b..37feed1 100644
--- a/drivers/mtd/spi/sf_ops.c
+++ b/drivers/mtd/spi/sf_ops.c
@@ -884,7 +884,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;
@@ -893,7 +893,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;
@@ -934,9 +934,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 */
diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
index 60856f9..ea24fa0 100644
--- a/drivers/mtd/spi/sf_probe.c
+++ b/drivers/mtd/spi/sf_probe.c
@@ -17,49 +17,11 @@
 
 #include "sf_internal.h"
 
-/**
- * spi_flash_probe_slave() - Probe for a SPI flash device on a bus
- *
- * @spi: Bus to probe
- * @flashp: Pointer to place to put flash info, which may be NULL if the
- * space should be allocated
- */
-int spi_flash_probe_slave(struct spi_slave *spi, struct spi_flash *flash)
-{
-	int ret;
-
-	/* Setup spi_slave */
-	if (!spi) {
-		printf("SF: Failed to set up slave\n");
-		return -ENODEV;
-	}
-
-	/* Claim spi bus */
-	ret = spi_claim_bus(spi);
-	if (ret) {
-		debug("SF: Failed to claim SPI bus: %d\n", ret);
-		return ret;
-	}
-
-	ret = spi_flash_scan(spi, 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(spi);
-	return ret;
-}
-
 #ifndef CONFIG_DM_SPI_FLASH
 struct spi_flash *spi_flash_probe_tail(struct spi_slave *bus)
 {
 	struct spi_flash *flash;
+	int ret;
 
 	/* Allocate space if needed (not used by sf-uclass */
 	flash = calloc(1, sizeof(*flash));
@@ -68,13 +30,37 @@ struct spi_flash *spi_flash_probe_tail(struct spi_slave *bus)
 		return NULL;
 	}
 
-	if (spi_flash_probe_slave(bus, flash)) {
-		spi_free_slave(bus);
-		free(flash);
-		return NULL;
+	flash->spi = bus;
+
+	/* Claim spi bus */
+	ret = spi_claim_bus(bus);
+	if (ret) {
+		debug("SF: Failed to claim SPI bus: %d\n", ret);
+		goto err_claim;
 	}
 
+	ret = spi_flash_scan(flash);
+	if (ret)
+		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 flash;
+
+#ifdef CONFIG_SPI_FLASH_MTD
+err_mtd:
+	spi_free_slave(bus);
+#endif
+err_scan:
+	spi_release_bus(bus);
+err_claim:
+	free(flash);
+	return NULL;
 }
 
 struct spi_flash *spi_flash_probe(unsigned int busnum, unsigned int cs,
@@ -154,7 +140,7 @@ 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;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v6 14/23] dm-sf: Re-factorize spi_flash_std_probe code
  2015-11-07 13:46 [U-Boot] [PATCH v6 00/23] sf: MTD support Jagan Teki
                   ` (12 preceding siblings ...)
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 13/23] sf: Re-factorize spi_flash_probe_tail code Jagan Teki
@ 2015-11-07 13:46 ` Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 15/23] sf: Add MTD support to spi_flash Jagan Teki
                   ` (8 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: Jagan Teki @ 2015-11-07 13:46 UTC (permalink / raw)
  To: u-boot

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.

Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Troy Kisky <troy.kisky@boundarydevices.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>
---
 drivers/mtd/spi/sf_probe.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
index ea24fa0..603c6bc 100644
--- a/drivers/mtd/spi/sf_probe.c
+++ b/drivers/mtd/spi/sf_probe.c
@@ -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_parent_priv(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);
@@ -143,14 +140,23 @@ int spi_flash_std_probe(struct udevice *dev)
 	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;
 }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v6 15/23] sf: Add MTD support to spi_flash
  2015-11-07 13:46 [U-Boot] [PATCH v6 00/23] sf: MTD support Jagan Teki
                   ` (13 preceding siblings ...)
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 14/23] dm-sf: Re-factorize spi_flash_std_probe code Jagan Teki
@ 2015-11-07 13:46 ` Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 16/23] sf: Use mtd_info ops instead of spi_flash ops Jagan Teki
                   ` (7 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: Jagan Teki @ 2015-11-07 13:46 UTC (permalink / raw)
  To: u-boot

This patch adds mtd_info support to spi_flash layer, MTD has
proven core for flash operations so adding MTD to spi_flash
will extends more functionality.

Reviewed-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Jagan Teki <jteki@openedev.com>
---
 drivers/mtd/spi/sf_ops.c   | 45 +++++++++++++++++++++++++--------------------
 drivers/mtd/spi/sf_probe.c | 26 ++++++++++++++++++--------
 include/spi_flash.h        |  9 +++++----
 3 files changed, 48 insertions(+), 32 deletions(-)

diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c
index 37feed1..7cbbeaf 100644
--- a/drivers/mtd/spi/sf_ops.c
+++ b/drivers/mtd/spi/sf_ops.c
@@ -147,7 +147,7 @@ static int spi_flash_read_bar(struct spi_flash *flash, u8 idcode0)
 	u8 curr_bank = 0;
 	int ret;
 
-	if (flash->size <= SPI_FLASH_16MB_BOUN)
+	if (flash->mtd->size <= SPI_FLASH_16MB_BOUN)
 		goto bank_end;
 
 	switch (idcode0) {
@@ -177,8 +177,8 @@ static void spi_flash_dual(struct spi_flash *flash, u32 *addr)
 {
 	switch (flash->dual_flash) {
 	case SF_DUAL_STACKED_FLASH:
-		if (*addr >= (flash->size >> 1)) {
-			*addr -= flash->size >> 1;
+		if (*addr >= (flash->mtd->size >> 1)) {
+			*addr -= flash->mtd->size >> 1;
 			flash->spi->flags |= SPI_XFER_U_PAGE;
 		} else {
 			flash->spi->flags &= ~SPI_XFER_U_PAGE;
@@ -304,7 +304,7 @@ static int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset,
 	u8 cmd[SPI_FLASH_CMD_LEN];
 	int ret = -1;
 
-	erase_size = flash->erase_size;
+	erase_size = mtd->erasesize;
 	if (offset % erase_size || len % erase_size) {
 		debug("SF: Erase offset/length not multiple of erase size\n");
 		return -1;
@@ -874,7 +874,7 @@ int spi_flash_decode_fdt(const void *blob, struct spi_flash *flash)
 		return 0;
 	}
 
-	if (flash->size != size) {
+	if (flash->mtd->size != size) {
 		debug("%s: Memory map must cover entire device\n", __func__);
 		return -1;
 	}
@@ -886,6 +886,7 @@ int spi_flash_decode_fdt(const void *blob, struct spi_flash *flash)
 
 int spi_flash_scan(struct spi_flash *flash)
 {
+	struct mtd_info *mtd = flash->mtd;
 	const struct spi_flash_params *params;
 	u16 jedec, ext_jedec;
 	u8 idcode[5];
@@ -935,24 +936,27 @@ int spi_flash_scan(struct spi_flash *flash)
 
 	/* Assign spi data */
 	flash->name = params->name;
+	mtd->type = MTD_NORFLASH;
+	mtd->writesize = 1;
+	mtd->flags = MTD_CAP_NORFLASH;
 	flash->memory_map = flash->spi->memory_map;
 	flash->dual_flash = flash->spi->option;
 
 	/* Assign spi_flash ops */
-	flash->write = spi_flash_cmd_write_ops;
+	mtd->_write = spi_flash_cmd_write_ops;
 #if defined(CONFIG_SPI_FLASH_SST)
 	if (params->flags & SST_WR)
 		flash->flags |= SNOR_F_SST_WR;
 
 	if (params->flags & SNOR_F_SST_WR) {
 		if (flash->spi->op_mode_tx & SPI_OPM_TX_BP)
-			flash->write = sst_write_bp;
+			mtd->_write = sst_write_bp;
 		else
-			flash->write = sst_write_wp;
+			mtd->_write = sst_write_wp;
 	}
 #endif
-	flash->erase = spi_flash_cmd_erase_ops;
-	flash->read = spi_flash_cmd_read_ops;
+	mtd->_erase = spi_flash_cmd_erase_ops;
+	mtd->_read = spi_flash_cmd_read_ops;
 
 	/* lock hooks are flash specific - assign them based on idcode0 */
 	switch (idcode[0]) {
@@ -984,27 +988,28 @@ int spi_flash_scan(struct spi_flash *flash)
 		flash->page_size = 256;
 	}
 	flash->page_size <<= flash->shift;
+	mtd->writebufsize = flash->page_size;
 	flash->sector_size = params->sector_size << flash->shift;
-	flash->size = flash->sector_size * params->nr_sectors << flash->shift;
+	mtd->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;
+		mtd->size <<= 1;
 #endif
 
 	/* Compute erase sector and command */
 	if (params->flags & SECT_4K) {
 		flash->erase_cmd = CMD_ERASE_4K;
-		flash->erase_size = 4096 << flash->shift;
+		mtd->erasesize = 4096 << flash->shift;
 	} else if (params->flags & SECT_32K) {
 		flash->erase_cmd = CMD_ERASE_32K;
-		flash->erase_size = 32768 << flash->shift;
+		mtd->erasesize = 32768 << flash->shift;
 	} else {
 		flash->erase_cmd = CMD_ERASE_64K;
-		flash->erase_size = flash->sector_size;
+		mtd->erasesize = flash->sector_size;
 	}
 
 	/* Now erase size becomes valid sector size */
-	flash->sector_size = flash->erase_size;
+	flash->sector_size = mtd->erasesize;
 
 	/* Look for the fastest read cmd */
 	cmd = fls(params->e_rd_cmd & flash->spi->op_mode_rx);
@@ -1076,8 +1081,8 @@ int spi_flash_scan(struct spi_flash *flash)
 #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, "");
+	print_size(mtd->erasesize, ", total ");
+	print_size(mtd->size, "");
 	if (flash->memory_map)
 		printf(", mapped at %p", flash->memory_map);
 	puts("\n");
@@ -1085,9 +1090,9 @@ int spi_flash_scan(struct spi_flash *flash)
 
 #ifndef CONFIG_SPI_FLASH_BAR
 	if (((flash->dual_flash == SF_SINGLE_FLASH) &&
-	     (flash->size > SPI_FLASH_16MB_BOUN)) ||
+	     (mtd->size > SPI_FLASH_16MB_BOUN)) ||
 	     ((flash->dual_flash > SF_SINGLE_FLASH) &&
-	     (flash->size > SPI_FLASH_16MB_BOUN << 1))) {
+	     (mtd->size > SPI_FLASH_16MB_BOUN << 1))) {
 		puts("SF: Warning - Only lower 16MiB accessible,");
 		puts(" Full access #define CONFIG_SPI_FLASH_BAR\n");
 	}
diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
index 603c6bc..8e6de05 100644
--- a/drivers/mtd/spi/sf_probe.c
+++ b/drivers/mtd/spi/sf_probe.c
@@ -14,9 +14,15 @@
 #include <malloc.h>
 #include <spi.h>
 #include <spi_flash.h>
+#include <linux/mtd/mtd.h>
 
 #include "sf_internal.h"
 
+struct spi_flash_priv {
+	struct spi_flash	flash;
+	struct mtd_info		mtd;
+};
+
 #ifndef CONFIG_DM_SPI_FLASH
 struct spi_flash *spi_flash_probe_tail(struct spi_slave *bus)
 {
@@ -123,12 +129,19 @@ int spi_flash_std_erase(struct udevice *dev, u32 offset, size_t len)
 
 int spi_flash_std_probe(struct udevice *dev)
 {
-	struct spi_flash *flash = dev_get_uclass_priv(dev);
+	struct spi_flash_priv *priv = dev_get_uclass_priv(dev);
 	struct spi_slave *slave = dev_get_parent_priv(dev);
+	struct spi_flash *flash;
 	int ret;
 
-	flash->dev = dev;
+	flash = &priv->flash;
+	flash->mtd = &priv->mtd;
+
 	flash->spi = slave;
+	flash->priv = priv;
+
+	priv->mtd.priv = flash;
+	flash->dev = dev;
 
 	/* Claim spi bus */
 	ret = spi_claim_bus(slave);
@@ -143,19 +156,16 @@ int spi_flash_std_probe(struct udevice *dev)
 		goto err_scan;
 	}
 
-#ifdef CONFIG_SPI_FLASH_MTD
-	ret = spi_flash_mtd_register(flash);
+	ret = add_mtd_device(&priv->mtd);
 	if (ret) {
 		printf("SF: failed to register mtd device: %d\n", ret);
 		goto err_mtd;
 	}
-#endif
+
 	return ret;
 
-#ifdef CONFIG_SPI_FLASH_MTD
 err_mtd:
 	spi_free_slave(slave);
-#endif
 err_scan:
 	spi_release_bus(slave);
 	return ret;
@@ -177,7 +187,7 @@ U_BOOT_DRIVER(spi_flash_std) = {
 	.id		= UCLASS_SPI_FLASH,
 	.of_match	= spi_flash_std_ids,
 	.probe		= spi_flash_std_probe,
-	.priv_auto_alloc_size = sizeof(struct spi_flash),
+	.priv_auto_alloc_size = sizeof(struct spi_flash_priv),
 	.ops		= &spi_flash_std_ops,
 };
 
diff --git a/include/spi_flash.h b/include/spi_flash.h
index dbd75a8..6010b15 100644
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -17,6 +17,7 @@
 
 #include <dm.h>	/* Because we dereference struct udevice here */
 #include <linux/types.h>
+#include <linux/mtd/mtd.h>
 
 #ifndef CONFIG_SF_DEFAULT_SPEED
 # define CONFIG_SF_DEFAULT_SPEED	1000000
@@ -36,16 +37,15 @@ struct spi_slave;
 /**
  * struct spi_flash - SPI flash structure
  *
+ * @mtd:		point to a mtd_info structure
  * @spi:		SPI slave
  * @dev:		SPI flash device
  * @name:		Name of SPI flash
  * @dual_flash:		Indicates dual flash memories - dual stacked, parallel
  * @shift:		Flash shift useful in dual parallel
  * @flags:		Indication of spi flash flags
- * @size:		Total flash size
  * @page_size:		Write (page) size
  * @sector_size:	Sector size
- * @erase_size:		Erase size
  * @bank_read_cmd:	Bank read cmd
  * @bank_write_cmd:	Bank write cmd
  * @bank_curr:		Current flash bank
@@ -54,6 +54,7 @@ struct spi_slave;
  * @write_cmd:		Write cmd - page and quad program.
  * @dummy_byte:		Dummy cycles for read operation.
  * @memory_map:		Address of read-only SPI flash access
+ * @priv:		the private data
  * @flash_lock:		lock a region of the SPI Flash
  * @flash_unlock:	unlock a region of the SPI Flash
  * @flash_is_locked:	check if a region of the SPI Flash is completely locked
@@ -66,6 +67,7 @@ struct spi_slave;
  * return 0 - Success, 1 - Failure
  */
 struct spi_flash {
+	struct mtd_info *mtd;
 	struct spi_slave *spi;
 #ifdef CONFIG_DM_SPI_FLASH
 	struct udevice *dev;
@@ -75,10 +77,8 @@ struct spi_flash {
 	u8 shift;
 	u16 flags;
 
-	u32 size;
 	u32 page_size;
 	u32 sector_size;
-	u32 erase_size;
 #ifdef CONFIG_SPI_FLASH_BAR
 	u8 bank_read_cmd;
 	u8 bank_write_cmd;
@@ -90,6 +90,7 @@ struct spi_flash {
 	u8 dummy_byte;
 
 	void *memory_map;
+	void *priv;
 
 	int (*flash_lock)(struct spi_flash *flash, u32 ofs, size_t len);
 	int (*flash_unlock)(struct spi_flash *flash, u32 ofs, size_t len);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v6 16/23] sf: Use mtd_info ops instead of spi_flash ops
  2015-11-07 13:46 [U-Boot] [PATCH v6 00/23] sf: MTD support Jagan Teki
                   ` (14 preceding siblings ...)
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 15/23] sf: Add MTD support to spi_flash Jagan Teki
@ 2015-11-07 13:46 ` Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 17/23] cmd_sf: Use mtd->size instead of flash->size Jagan Teki
                   ` (6 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: Jagan Teki @ 2015-11-07 13:46 UTC (permalink / raw)
  To: u-boot

Since MTD support is added in spi_flash layer, this patch uses
mtd_info operations instead of legacy spi_flash operations.

Reviewed-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Jagan Teki <jteki@openedev.com>
---
 drivers/mtd/spi/sf_ops.c | 66 ++++++++++++++++++++++++++++--------------------
 include/spi_flash.h      | 23 ++++++++---------
 2 files changed, 49 insertions(+), 40 deletions(-)

diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c
index 7cbbeaf..5fa6113 100644
--- a/drivers/mtd/spi/sf_ops.c
+++ b/drivers/mtd/spi/sf_ops.c
@@ -297,18 +297,16 @@ int spi_flash_write_common(struct spi_flash *flash, const u8 *cmd,
 	return ret;
 }
 
-static int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset,
-					size_t len)
+static int spi_flash_cmd_erase_ops(struct mtd_info *mtd,
+					struct erase_info *instr)
 {
-	u32 erase_size, erase_addr;
+	struct spi_flash *flash = mtd->priv;
+	u32 offset, len, erase_addr;
 	u8 cmd[SPI_FLASH_CMD_LEN];
 	int ret = -1;
 
-	erase_size = mtd->erasesize;
-	if (offset % erase_size || len % erase_size) {
-		debug("SF: Erase offset/length not multiple of erase size\n");
-		return -1;
-	}
+	offset = instr->addr;
+	len = instr->len;
 
 	if (flash->flash_is_locked(flash, offset, len) > 0) {
 		printf("offset 0x%x is protected and cannot be erased\n", offset);
@@ -336,19 +334,24 @@ static int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset,
 		ret = spi_flash_write_common(flash, cmd, sizeof(cmd), NULL, 0);
 		if (ret < 0) {
 			debug("SF: erase failed\n");
-			break;
+			goto erase_err;
 		}
 
-		offset += erase_size;
-		len -= erase_size;
+		offset += mtd->erasesize;
+		len -= mtd->erasesize;
 	}
 
 	return ret;
+
+erase_err:
+	instr->state = MTD_ERASE_FAILED;
+	return ret;
 }
 
-static int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
-		size_t len, const void *buf)
+static int spi_flash_cmd_write_ops(struct mtd_info *mtd, loff_t offset,
+				size_t len, size_t *retlen, const u_char *buf)
 {
+	struct spi_flash *flash = mtd->priv;
 	unsigned long byte_addr, page_size;
 	u32 write_addr;
 	size_t chunk_len, actual;
@@ -395,6 +398,7 @@ static int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
 		}
 
 		offset += chunk_len;
+		*retlen += chunk_len;
 	}
 
 	return ret;
@@ -428,11 +432,12 @@ void __weak spi_flash_copy_mmap(void *data, void *offset, size_t len)
 	memcpy(data, offset, len);
 }
 
-static int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
-		size_t len, void *data)
+static int spi_flash_cmd_read_ops(struct mtd_info *mtd, loff_t offset,
+				size_t len, size_t *retlen, u_char *data)
 {
-	u8 *cmd, cmdsz;
+	struct spi_flash *flash = mtd->priv;
 	u32 remain_len, read_len, read_addr;
+	u8 *cmd, cmdsz;
 	int bank_sel = 0;
 	int ret = -1;
 
@@ -489,6 +494,7 @@ static int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
 		offset += read_len;
 		len -= read_len;
 		data += read_len;
+		*retlen += read_len;
 	}
 
 	free(cmd);
@@ -496,7 +502,8 @@ static int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
 }
 
 #ifdef CONFIG_SPI_FLASH_SST
-static int sst_byte_write(struct spi_flash *flash, u32 offset, const void *buf)
+static int sst_byte_write(struct spi_flash *flash, u32 offset,
+				const void *buf, size_t *retlen)
 {
 	int ret;
 	u8 cmd[4] = {
@@ -517,12 +524,15 @@ static int sst_byte_write(struct spi_flash *flash, u32 offset, const void *buf)
 	if (ret)
 		return ret;
 
+	*retlen += 1;
+
 	return spi_flash_cmd_wait_ready(flash, SPI_FLASH_PROG_TIMEOUT);
 }
 
-static int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,
-		const void *buf)
+static int sst_write_wp(struct mtd_info *mtd, loff_t offset, size_t len,
+				size_t *retlen, const u_char *buf)
 {
+	struct spi_flash *flash = mtd->priv;
 	size_t actual, cmd_len;
 	int ret;
 	u8 cmd[4];
@@ -536,7 +546,7 @@ static int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,
 	/* If the data is not word aligned, write out leading single byte */
 	actual = offset % 2;
 	if (actual) {
-		ret = sst_byte_write(flash, offset, buf);
+		ret = sst_byte_write(flash, offset, buf, retlen);
 		if (ret)
 			goto done;
 	}
@@ -553,7 +563,7 @@ static int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,
 	cmd[3] = offset;
 
 	for (; actual < len - 1; actual += 2) {
-		debug("WP[%02x]: 0x%p => cmd = { 0x%02x 0x%06x }\n",
+		debug("WP[%02x]: 0x%p => cmd = { 0x%02x 0x%06llx }\n",
 		      spi_w8r8(flash->spi, CMD_READ_STATUS), buf + actual,
 		      cmd[0], offset);
 
@@ -570,6 +580,7 @@ static int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,
 
 		cmd_len = 1;
 		offset += 2;
+		*retlen += 2;
 	}
 
 	if (!ret)
@@ -577,19 +588,20 @@ static int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,
 
 	/* If there is a single trailing byte, write it out */
 	if (!ret && actual != len)
-		ret = sst_byte_write(flash, offset, buf + actual);
+		ret = sst_byte_write(flash, offset, buf + actual, retlen);
 
  done:
-	debug("SF: sst: program %s %zu bytes @ 0x%zx\n",
+	debug("SF: sst: program %s %zu bytes @ 0x%llx\n",
 	      ret ? "failure" : "success", len, offset - actual);
 
 	spi_release_bus(flash->spi);
 	return ret;
 }
 
-static int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,
-		const void *buf)
+static int sst_write_bp(struct mtd_info *mtd, loff_t offset, size_t len,
+				size_t *retlen, const u_char *buf)
 {
+	struct spi_flash *flash = mtd->priv;
 	size_t actual;
 	int ret;
 
@@ -600,7 +612,7 @@ static int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,
 	}
 
 	for (actual = 0; actual < len; actual++) {
-		ret = sst_byte_write(flash, offset, buf + actual);
+		ret = sst_byte_write(flash, offset, buf + actual, retlen);
 		if (ret) {
 			debug("SF: sst byte program failed\n");
 			break;
@@ -611,7 +623,7 @@ static int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,
 	if (!ret)
 		ret = spi_flash_cmd_write_disable(flash);
 
-	debug("SF: sst: program %s %zu bytes @ 0x%zx\n",
+	debug("SF: sst: program %s %zu bytes @ 0x%llx\n",
 	      ret ? "failure" : "success", len, offset - actual);
 
 	spi_release_bus(flash->spi);
diff --git a/include/spi_flash.h b/include/spi_flash.h
index 6010b15..4051a35 100644
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -58,12 +58,6 @@ struct spi_slave;
  * @flash_lock:		lock a region of the SPI Flash
  * @flash_unlock:	unlock a region of the SPI Flash
  * @flash_is_locked:	check if a region of the SPI Flash is completely locked
- * @read:		Flash read ops: Read len bytes at offset into buf
- *			Supported cmds: Fast Array Read
- * @write:		Flash write ops: Write len bytes from buf into offset
- *			Supported cmds: Page Program
- * @erase:		Flash erase ops: Erase len bytes from offset
- *			Supported cmds: Sector erase 4K, 32K, 64K
  * return 0 - Success, 1 - Failure
  */
 struct spi_flash {
@@ -95,10 +89,6 @@ struct spi_flash {
 	int (*flash_lock)(struct spi_flash *flash, u32 ofs, size_t len);
 	int (*flash_unlock)(struct spi_flash *flash, u32 ofs, size_t len);
 	int (*flash_is_locked)(struct spi_flash *flash, u32 ofs, size_t len);
-	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);
 };
 
 struct dm_spi_flash_ops {
@@ -163,19 +153,26 @@ int spi_flash_remove(struct udevice *flash);
 static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
 				 size_t len, void *buf)
 {
-	return spi_flash_read_dm(flash->dev, offset, len, buf);
+	return mtd_read(flash->mtd, offset, len, &len, (u_char *)buf);
 }
 
 static inline int spi_flash_write(struct spi_flash *flash, u32 offset,
 				  size_t len, const void *buf)
 {
-	return spi_flash_write_dm(flash->dev, offset, len, buf);
+	return mtd_write(flash->mtd, offset, len, &len, (u_char *)buf);
 }
 
 static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
 				  size_t len)
 {
-	return spi_flash_erase_dm(flash->dev, offset, len);
+	struct erase_info instr;
+
+	instr.mtd = flash->mtd;
+	instr.addr = offset;
+	instr.len = len;
+	instr.callback = 0;
+
+	return mtd_erase(flash->mtd, &instr);
 }
 
 struct sandbox_state;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v6 17/23] cmd_sf: Use mtd->size instead of flash->size
  2015-11-07 13:46 [U-Boot] [PATCH v6 00/23] sf: MTD support Jagan Teki
                   ` (15 preceding siblings ...)
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 16/23] sf: Use mtd_info ops instead of spi_flash ops Jagan Teki
@ 2015-11-07 13:46 ` Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 18/23] dm-sf: use mtd_ops, drop dm_spi_flash_ops Jagan Teki
                   ` (5 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: Jagan Teki @ 2015-11-07 13:46 UTC (permalink / raw)
  To: u-boot

Since mtd got added, replace flash->size with mtd->size.

Reviewed-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Jagan Teki <jteki@openedev.com>
---
 common/cmd_sf.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/common/cmd_sf.c b/common/cmd_sf.c
index 42862d9..d9f1bd1 100644
--- a/common/cmd_sf.c
+++ b/common/cmd_sf.c
@@ -275,13 +275,13 @@ static int do_spi_flash_read_write(int argc, char * const argv[])
 		return -1;
 
 	if (mtd_arg_off_size(argc - 2, &argv[2], &dev, &offset, &len,
-			     &maxsize, MTD_DEV_TYPE_NOR, flash->size))
+			     &maxsize, MTD_DEV_TYPE_NOR, flash->mtd->size))
 		return -1;
 
 	/* Consistency checking */
-	if (offset + len > flash->size) {
-		printf("ERROR: attempting %s past flash size (%#x)\n",
-		       argv[0], flash->size);
+	if (offset + len > flash->mtd->size) {
+		printf("ERROR: attempting %s past flash size (0x%llx)\n",
+		       argv[0], flash->mtd->size);
 		return 1;
 	}
 
@@ -327,7 +327,7 @@ static int do_spi_flash_erase(int argc, char * const argv[])
 		return -1;
 
 	if (mtd_arg_off(argv[1], &dev, &offset, &len, &maxsize,
-			MTD_DEV_TYPE_NOR, flash->size))
+			MTD_DEV_TYPE_NOR, flash->mtd->size))
 		return -1;
 
 	ret = sf_parse_len_arg(argv[2], &size);
@@ -335,9 +335,9 @@ static int do_spi_flash_erase(int argc, char * const argv[])
 		return -1;
 
 	/* Consistency checking */
-	if (offset + size > flash->size) {
-		printf("ERROR: attempting %s past flash size (%#x)\n",
-		       argv[0], flash->size);
+	if (offset + size > flash->mtd->size) {
+		printf("ERROR: attempting %s past flash size (0x%llx)\n",
+		       argv[0], flash->mtd->size);
 		return 1;
 	}
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v6 18/23] dm-sf: use mtd_ops, drop dm_spi_flash_ops
  2015-11-07 13:46 [U-Boot] [PATCH v6 00/23] sf: MTD support Jagan Teki
                   ` (16 preceding siblings ...)
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 17/23] cmd_sf: Use mtd->size instead of flash->size Jagan Teki
@ 2015-11-07 13:46 ` Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 19/23] sf: Use MTD lock operations Jagan Teki
                   ` (4 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: Jagan Teki @ 2015-11-07 13:46 UTC (permalink / raw)
  To: u-boot

Since mtd_info ops got introduced, just drop the unneeded
dm_spi_flash operations.

Reviewed-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Jagan Teki <jteki@openedev.com>
---
 drivers/mtd/spi/sf-uclass.c | 16 --------
 drivers/mtd/spi/sf_probe.c  | 30 ---------------
 include/spi_flash.h         | 90 +++++++--------------------------------------
 3 files changed, 14 insertions(+), 122 deletions(-)

diff --git a/drivers/mtd/spi/sf-uclass.c b/drivers/mtd/spi/sf-uclass.c
index 350e21a..5cdbd1b 100644
--- a/drivers/mtd/spi/sf-uclass.c
+++ b/drivers/mtd/spi/sf-uclass.c
@@ -11,22 +11,6 @@
 #include <dm/device-internal.h>
 #include "sf_internal.h"
 
-int spi_flash_read_dm(struct udevice *dev, u32 offset, size_t len, void *buf)
-{
-	return sf_get_ops(dev)->read(dev, offset, len, buf);
-}
-
-int spi_flash_write_dm(struct udevice *dev, u32 offset, size_t len,
-		       const void *buf)
-{
-	return sf_get_ops(dev)->write(dev, offset, len, buf);
-}
-
-int spi_flash_erase_dm(struct udevice *dev, u32 offset, size_t len)
-{
-	return sf_get_ops(dev)->erase(dev, offset, len);
-}
-
 /*
  * TODO(sjg at chromium.org): This is an old-style function. We should remove
  * it when all SPI flash drivers use dm
diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
index 8e6de05..b9d1346 100644
--- a/drivers/mtd/spi/sf_probe.c
+++ b/drivers/mtd/spi/sf_probe.c
@@ -104,29 +104,6 @@ void spi_flash_free(struct spi_flash *flash)
 
 #else /* defined CONFIG_DM_SPI_FLASH */
 
-static int spi_flash_std_read(struct udevice *dev, u32 offset, size_t len,
-			      void *buf)
-{
-	struct spi_flash *flash = dev_get_uclass_priv(dev);
-
-	return flash->read(flash, offset, len, buf);
-}
-
-int spi_flash_std_write(struct udevice *dev, u32 offset, size_t len,
-			const void *buf)
-{
-	struct spi_flash *flash = dev_get_uclass_priv(dev);
-
-	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 flash->erase(flash, offset, len);
-}
-
 int spi_flash_std_probe(struct udevice *dev)
 {
 	struct spi_flash_priv *priv = dev_get_uclass_priv(dev);
@@ -171,12 +148,6 @@ err_scan:
 	return ret;
 }
 
-static const struct dm_spi_flash_ops spi_flash_std_ops = {
-	.read = spi_flash_std_read,
-	.write = spi_flash_std_write,
-	.erase = spi_flash_std_erase,
-};
-
 static const struct udevice_id spi_flash_std_ids[] = {
 	{ .compatible = "spi-flash" },
 	{ }
@@ -188,7 +159,6 @@ U_BOOT_DRIVER(spi_flash_std) = {
 	.of_match	= spi_flash_std_ids,
 	.probe		= spi_flash_std_probe,
 	.priv_auto_alloc_size = sizeof(struct spi_flash_priv),
-	.ops		= &spi_flash_std_ops,
 };
 
 #endif /* CONFIG_DM_SPI_FLASH */
diff --git a/include/spi_flash.h b/include/spi_flash.h
index 4051a35..5bb56b4 100644
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -91,65 +91,6 @@ struct spi_flash {
 	int (*flash_is_locked)(struct spi_flash *flash, u32 ofs, size_t len);
 };
 
-struct dm_spi_flash_ops {
-	int (*read)(struct udevice *dev, u32 offset, size_t len, void *buf);
-	int (*write)(struct udevice *dev, u32 offset, size_t len,
-		     const void *buf);
-	int (*erase)(struct udevice *dev, u32 offset, size_t len);
-};
-
-/* Access the serial operations for a device */
-#define sf_get_ops(dev) ((struct dm_spi_flash_ops *)(dev)->driver->ops)
-
-#ifdef CONFIG_DM_SPI_FLASH
-/**
- * spi_flash_read_dm() - Read data from SPI flash
- *
- * @dev:	SPI flash device
- * @offset:	Offset into device in bytes to read from
- * @len:	Number of bytes to read
- * @buf:	Buffer to put the data that is read
- * @return 0 if OK, -ve on error
- */
-int spi_flash_read_dm(struct udevice *dev, u32 offset, size_t len, void *buf);
-
-/**
- * spi_flash_write_dm() - Write data to SPI flash
- *
- * @dev:	SPI flash device
- * @offset:	Offset into device in bytes to write to
- * @len:	Number of bytes to write
- * @buf:	Buffer containing bytes to write
- * @return 0 if OK, -ve on error
- */
-int spi_flash_write_dm(struct udevice *dev, u32 offset, size_t len,
-		       const void *buf);
-
-/**
- * spi_flash_erase_dm() - Erase blocks of the SPI flash
- *
- * Note that @len must be a muiltiple of the flash sector size.
- *
- * @dev:	SPI flash device
- * @offset:	Offset into device in bytes to start erasing
- * @len:	Number of bytes to erase
- * @return 0 if OK, -ve on error
- */
-int spi_flash_erase_dm(struct udevice *dev, u32 offset, size_t len);
-
-int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs,
-			   unsigned int max_hz, unsigned int spi_mode,
-			   struct udevice **devp);
-
-/* Compatibility function - this is the old U-Boot API */
-struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
-				  unsigned int max_hz, unsigned int spi_mode);
-
-/* Compatibility function - this is the old U-Boot API */
-void spi_flash_free(struct spi_flash *flash);
-
-int spi_flash_remove(struct udevice *flash);
-
 static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
 				 size_t len, void *buf)
 {
@@ -175,6 +116,20 @@ static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
 	return mtd_erase(flash->mtd, &instr);
 }
 
+#ifdef CONFIG_DM_SPI_FLASH
+int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs,
+			   unsigned int max_hz, unsigned int spi_mode,
+			   struct udevice **devp);
+
+/* Compatibility function - this is the old U-Boot API */
+struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
+				  unsigned int max_hz, unsigned int spi_mode);
+
+/* Compatibility function - this is the old U-Boot API */
+void spi_flash_free(struct spi_flash *flash);
+
+int spi_flash_remove(struct udevice *flash);
+
 struct sandbox_state;
 
 int sandbox_sf_bind_emul(struct sandbox_state *state, int busnum, int cs,
@@ -200,23 +155,6 @@ struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node,
 
 void spi_flash_free(struct spi_flash *flash);
 
-static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
-		size_t len, void *buf)
-{
-	return flash->read(flash, offset, len, buf);
-}
-
-static inline int spi_flash_write(struct spi_flash *flash, u32 offset,
-		size_t len, const void *buf)
-{
-	return flash->write(flash, offset, len, buf);
-}
-
-static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
-		size_t len)
-{
-	return flash->erase(flash, offset, len);
-}
 #endif
 
 static inline int spi_flash_protect(struct spi_flash *flash, u32 ofs, u32 len,
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v6 19/23] sf: Use MTD lock operations
  2015-11-07 13:46 [U-Boot] [PATCH v6 00/23] sf: MTD support Jagan Teki
                   ` (17 preceding siblings ...)
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 18/23] dm-sf: use mtd_ops, drop dm_spi_flash_ops Jagan Teki
@ 2015-11-07 13:46 ` Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 20/23] sf: Add MTD support for non-dm spi_flash interface Jagan Teki
                   ` (3 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: Jagan Teki @ 2015-11-07 13:46 UTC (permalink / raw)
  To: u-boot

Since the spi-flash framework itself is using core MTD
functionalities this patch uses lock operation from mtd.

Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>
---
 drivers/mtd/spi/sf_internal.h |   9 -
 drivers/mtd/spi/sf_ops.c      | 383 ++++++++++++++++++++++--------------------
 include/spi_flash.h           |  34 ++--
 3 files changed, 220 insertions(+), 206 deletions(-)

diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h
index fda49e9..677f582 100644
--- a/drivers/mtd/spi/sf_internal.h
+++ b/drivers/mtd/spi/sf_internal.h
@@ -163,15 +163,6 @@ int spi_flash_cmd_read(struct spi_slave *spi, const u8 *cmd,
 int spi_flash_cmd_write(struct spi_slave *spi, const u8 *cmd, size_t cmd_len,
 		const void *data, size_t data_len);
 
-/* Lock stmicro spi flash region */
-int stm_lock(struct spi_flash *flash, u32 ofs, size_t len);
-
-/* Unlock stmicro spi flash region */
-int stm_unlock(struct spi_flash *flash, u32 ofs, size_t len);
-
-/* Check if a stmicro spi flash region is completely locked */
-int stm_is_locked(struct spi_flash *flash, u32 ofs, size_t len);
-
 /* Enable writing on the SPI flash */
 static inline int spi_flash_cmd_write_enable(struct spi_flash *flash)
 {
diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c
index 5fa6113..a536444 100644
--- a/drivers/mtd/spi/sf_ops.c
+++ b/drivers/mtd/spi/sf_ops.c
@@ -256,6 +256,199 @@ static int spi_flash_cmd_wait_ready(struct spi_flash *flash,
 	return -ETIMEDOUT;
 }
 
+#ifdef CONFIG_SPI_FLASH_STMICRO
+static void stm_get_locked_range(struct spi_flash *flash, u8 sr, loff_t *ofs,
+				uint64_t *len)
+{
+	struct mtd_info *mtd = flash->mtd;
+	u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
+	int shift = ffs(mask) - 1;
+	int pow;
+
+	if (!(sr & mask)) {
+		/* No protection */
+		*ofs = 0;
+		*len = 0;
+	} else {
+		pow = ((sr & mask) ^ mask) >> shift;
+		*len = mtd->size >> pow;
+		*ofs = mtd->size - *len;
+	}
+}
+
+/*
+ * Return 1 if the entire region is locked, 0 otherwise
+ */
+static int stm_is_locked_sr(struct spi_flash *flash, loff_t ofs, uint64_t len,
+			    u8 sr)
+{
+	loff_t lock_offs;
+	uint64_t lock_len;
+
+	stm_get_locked_range(flash, sr, &lock_offs, &lock_len);
+
+	return (ofs + len <= lock_offs + lock_len) && (ofs >= lock_offs);
+}
+
+/*
+ * Check if a region of the flash is (completely) locked. See stm_lock() for
+ * more info.
+ *
+ * Returns 1 if entire region is locked, 0 if any portion is unlocked, and
+ * negative on errors.
+ */
+static int stm_is_locked(struct spi_flash *flash, loff_t ofs, uint64_t len)
+{
+	int status;
+	u8 sr;
+
+	status = read_sr(flash, &sr);
+	if (status < 0)
+		return status;
+
+	return stm_is_locked_sr(flash, ofs, len, sr);
+}
+
+/*
+ * Lock a region of the flash. Compatible with ST Micro and similar flash.
+ * Supports only the block protection bits BP{0,1,2} in the status register
+ * (SR). Does not support these features found in newer SR bitfields:
+ *   - TB: top/bottom protect - only handle TB=0 (top protect)
+ *   - SEC: sector/block protect - only handle SEC=0 (block protect)
+ *   - CMP: complement protect - only support CMP=0 (range is not complemented)
+ *
+ * Sample table portion for 8MB flash (Winbond w25q64fw):
+ *
+ *   SEC  |  TB   |  BP2  |  BP1  |  BP0  |  Prot Length  | Protected Portion
+ *  --------------------------------------------------------------------------
+ *    X   |   X   |   0   |   0   |   0   |  NONE         | NONE
+ *    0   |   0   |   0   |   0   |   1   |  128 KB       | Upper 1/64
+ *    0   |   0   |   0   |   1   |   0   |  256 KB       | Upper 1/32
+ *    0   |   0   |   0   |   1   |   1   |  512 KB       | Upper 1/16
+ *    0   |   0   |   1   |   0   |   0   |  1 MB         | Upper 1/8
+ *    0   |   0   |   1   |   0   |   1   |  2 MB         | Upper 1/4
+ *    0   |   0   |   1   |   1   |   0   |  4 MB         | Upper 1/2
+ *    X   |   X   |   1   |   1   |   1   |  8 MB         | ALL
+ *
+ * Returns negative on errors, 0 on success.
+ */
+static int stm_lock(struct spi_flash *flash, loff_t ofs, uint64_t len)
+{
+	struct mtd_info *mtd = flash->mtd;
+	u8 status_old, status_new;
+	u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
+	u8 shift = ffs(mask) - 1, pow, val;
+
+	read_sr(flash, &status_old);
+
+	/* SPI NOR always locks to the end */
+	if (ofs + len != mtd->size) {
+		/* Does combined region extend to end? */
+		if (!stm_is_locked_sr(flash, ofs + len, mtd->size - ofs - len,
+				      status_old))
+			return -EINVAL;
+		len = mtd->size - ofs;
+	}
+
+	/*
+	 * Need smallest pow such that:
+	 *
+	 *   1 / (2^pow) <= (len / size)
+	 *
+	 * so (assuming power-of-2 size) we do:
+	 *
+	 *   pow = ceil(log2(size / len)) = log2(size) - floor(log2(len))
+	 */
+	pow = ilog2(mtd->size) - ilog2(len);
+	val = mask - (pow << shift);
+	if (val & ~mask)
+		return -EINVAL;
+
+	/* Don't "lock" with no region! */
+	if (!(val & mask))
+		return -EINVAL;
+
+	status_new = (status_old & ~mask) | val;
+
+	/* Only modify protection if it will not unlock other areas */
+	if ((status_new & mask) <= (status_old & mask))
+		return -EINVAL;
+
+	write_sr(flash, status_new);
+
+	return 0;
+}
+
+/*
+ * Unlock a region of the flash. See stm_lock() for more info
+ *
+ * Returns negative on errors, 0 on success.
+ */
+static int stm_unlock(struct spi_flash *flash, loff_t ofs, uint64_t len)
+{
+	struct mtd_info *mtd = flash->mtd;
+	uint8_t status_old, status_new;
+	u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
+	u8 shift = ffs(mask) - 1, pow, val;
+
+	read_sr(flash, &status_old);
+
+	/* Cannot unlock; would unlock larger region than requested */
+	if (stm_is_locked_sr(flash, status_old, ofs - mtd->erasesize,
+			     mtd->erasesize))
+		return -EINVAL;
+	/*
+	 * Need largest pow such that:
+	 *
+	 *   1 / (2^pow) >= (len / size)
+	 *
+	 * so (assuming power-of-2 size) we do:
+	 *
+	 *   pow = floor(log2(size / len)) = log2(size) - ceil(log2(len))
+	 */
+	pow = ilog2(mtd->size) - order_base_2(mtd->size - (ofs + len));
+	if (ofs + len == mtd->size) {
+		val = 0; /* fully unlocked */
+	} else {
+		val = mask - (pow << shift);
+		/* Some power-of-two sizes are not supported */
+		if (val & ~mask)
+			return -EINVAL;
+	}
+
+	status_new = (status_old & ~mask) | val;
+
+	/* Only modify protection if it will not lock other areas */
+	if ((status_new & mask) >= (status_old & mask))
+		return -EINVAL;
+
+	write_sr(flash, status_new);
+
+	return 0;
+}
+#endif  /* CONFIG_SPI_FLASH_STMICRO */
+
+static int spi_flash_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
+{
+	struct spi_flash *flash = mtd->priv;
+
+	return flash->flash_lock(flash, ofs, len);
+}
+
+static int spi_flash_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
+{
+	struct spi_flash *flash = mtd->priv;
+
+	return flash->flash_unlock(flash, ofs, len);
+}
+
+static int spi_flash_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
+{
+	struct spi_flash *flash = mtd->priv;
+
+	return flash->flash_is_locked(flash, ofs, len);
+}
+
 int spi_flash_write_common(struct spi_flash *flash, const u8 *cmd,
 		size_t cmd_len, const void *buf, size_t buf_len)
 {
@@ -308,7 +501,7 @@ static int spi_flash_cmd_erase_ops(struct mtd_info *mtd,
 	offset = instr->addr;
 	len = instr->len;
 
-	if (flash->flash_is_locked(flash, offset, len) > 0) {
+	if (mtd->_is_locked(mtd, offset, len) > 0) {
 		printf("offset 0x%x is protected and cannot be erased\n", offset);
 		return -EINVAL;
 	}
@@ -360,8 +553,8 @@ static int spi_flash_cmd_write_ops(struct mtd_info *mtd, loff_t offset,
 
 	page_size = flash->page_size;
 
-	if (flash->flash_is_locked(flash, offset, len) > 0) {
-		printf("offset 0x%x is protected and cannot be written\n", offset);
+	if (mtd->_is_locked(mtd, offset, len) > 0) {
+		printf("offset 0x%llx is protected and cannot be written\n", offset);
 		return -EINVAL;
 	}
 
@@ -631,176 +824,6 @@ static int sst_write_bp(struct mtd_info *mtd, loff_t offset, size_t len,
 }
 #endif
 
-#ifdef CONFIG_SPI_FLASH_STMICRO
-static void stm_get_locked_range(struct spi_flash *flash, u8 sr, loff_t *ofs,
-				 u32 *len)
-{
-	u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
-	int shift = ffs(mask) - 1;
-	int pow;
-
-	if (!(sr & mask)) {
-		/* No protection */
-		*ofs = 0;
-		*len = 0;
-	} else {
-		pow = ((sr & mask) ^ mask) >> shift;
-		*len = flash->size >> pow;
-		*ofs = flash->size - *len;
-	}
-}
-
-/*
- * Return 1 if the entire region is locked, 0 otherwise
- */
-static int stm_is_locked_sr(struct spi_flash *flash, u32 ofs, u32 len,
-			    u8 sr)
-{
-	loff_t lock_offs;
-	u32 lock_len;
-
-	stm_get_locked_range(flash, sr, &lock_offs, &lock_len);
-
-	return (ofs + len <= lock_offs + lock_len) && (ofs >= lock_offs);
-}
-
-/*
- * Check if a region of the flash is (completely) locked. See stm_lock() for
- * more info.
- *
- * Returns 1 if entire region is locked, 0 if any portion is unlocked, and
- * negative on errors.
- */
-int stm_is_locked(struct spi_flash *flash, u32 ofs, size_t len)
-{
-	int status;
-	u8 sr;
-
-	status = spi_flash_cmd_read_status(flash, &sr);
-	if (status < 0)
-		return status;
-
-	return stm_is_locked_sr(flash, ofs, len, sr);
-}
-
-/*
- * Lock a region of the flash. Compatible with ST Micro and similar flash.
- * Supports only the block protection bits BP{0,1,2} in the status register
- * (SR). Does not support these features found in newer SR bitfields:
- *   - TB: top/bottom protect - only handle TB=0 (top protect)
- *   - SEC: sector/block protect - only handle SEC=0 (block protect)
- *   - CMP: complement protect - only support CMP=0 (range is not complemented)
- *
- * Sample table portion for 8MB flash (Winbond w25q64fw):
- *
- *   SEC  |  TB   |  BP2  |  BP1  |  BP0  |  Prot Length  | Protected Portion
- *  --------------------------------------------------------------------------
- *    X   |   X   |   0   |   0   |   0   |  NONE         | NONE
- *    0   |   0   |   0   |   0   |   1   |  128 KB       | Upper 1/64
- *    0   |   0   |   0   |   1   |   0   |  256 KB       | Upper 1/32
- *    0   |   0   |   0   |   1   |   1   |  512 KB       | Upper 1/16
- *    0   |   0   |   1   |   0   |   0   |  1 MB         | Upper 1/8
- *    0   |   0   |   1   |   0   |   1   |  2 MB         | Upper 1/4
- *    0   |   0   |   1   |   1   |   0   |  4 MB         | Upper 1/2
- *    X   |   X   |   1   |   1   |   1   |  8 MB         | ALL
- *
- * Returns negative on errors, 0 on success.
- */
-int stm_lock(struct spi_flash *flash, u32 ofs, size_t len)
-{
-	u8 status_old, status_new;
-	u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
-	u8 shift = ffs(mask) - 1, pow, val;
-
-	spi_flash_cmd_read_status(flash, &status_old);
-
-	/* SPI NOR always locks to the end */
-	if (ofs + len != flash->size) {
-		/* Does combined region extend to end? */
-		if (!stm_is_locked_sr(flash, ofs + len, flash->size - ofs - len,
-				      status_old))
-			return -EINVAL;
-		len = flash->size - ofs;
-	}
-
-	/*
-	 * Need smallest pow such that:
-	 *
-	 *   1 / (2^pow) <= (len / size)
-	 *
-	 * so (assuming power-of-2 size) we do:
-	 *
-	 *   pow = ceil(log2(size / len)) = log2(size) - floor(log2(len))
-	 */
-	pow = ilog2(flash->size) - ilog2(len);
-	val = mask - (pow << shift);
-	if (val & ~mask)
-		return -EINVAL;
-
-	/* Don't "lock" with no region! */
-	if (!(val & mask))
-		return -EINVAL;
-
-	status_new = (status_old & ~mask) | val;
-
-	/* Only modify protection if it will not unlock other areas */
-	if ((status_new & mask) <= (status_old & mask))
-		return -EINVAL;
-
-	spi_flash_cmd_write_status(flash, status_new);
-
-	return 0;
-}
-
-/*
- * Unlock a region of the flash. See stm_lock() for more info
- *
- * Returns negative on errors, 0 on success.
- */
-int stm_unlock(struct spi_flash *flash, u32 ofs, size_t len)
-{
-	uint8_t status_old, status_new;
-	u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
-	u8 shift = ffs(mask) - 1, pow, val;
-
-	spi_flash_cmd_read_status(flash, &status_old);
-
-	/* Cannot unlock; would unlock larger region than requested */
-	if (stm_is_locked_sr(flash, status_old, ofs - flash->erase_size,
-			     flash->erase_size))
-		return -EINVAL;
-	/*
-	 * Need largest pow such that:
-	 *
-	 *   1 / (2^pow) >= (len / size)
-	 *
-	 * so (assuming power-of-2 size) we do:
-	 *
-	 *   pow = floor(log2(size / len)) = log2(size) - ceil(log2(len))
-	 */
-	pow = ilog2(flash->size) - order_base_2(flash->size - (ofs + len));
-	if (ofs + len == flash->size) {
-		val = 0; /* fully unlocked */
-	} else {
-		val = mask - (pow << shift);
-		/* Some power-of-two sizes are not supported */
-		if (val & ~mask)
-			return -EINVAL;
-	}
-
-	status_new = (status_old & ~mask) | val;
-
-	/* Only modify protection if it will not lock other areas */
-	if ((status_new & mask) >= (status_old & mask))
-		return -EINVAL;
-
-	spi_flash_cmd_write_status(flash, status_new);
-
-	return 0;
-}
-#endif  /* CONFIG_SPI_FLASH_STMICRO */
-
-
 #ifdef CONFIG_SPI_FLASH_MACRONIX
 static int spi_flash_set_qeb_mxic(struct spi_flash *flash)
 {
@@ -970,17 +993,19 @@ int spi_flash_scan(struct spi_flash *flash)
 	mtd->_erase = spi_flash_cmd_erase_ops;
 	mtd->_read = spi_flash_cmd_read_ops;
 
-	/* lock hooks are flash specific - assign them based on idcode0 */
-	switch (idcode[0]) {
+	/* NOR protection support for STmicro/Micron chips and similar */
 #ifdef CONFIG_SPI_FLASH_STMICRO
-	case SPI_FLASH_CFI_MFR_STMICRO:
+	if ((idcode[0]) == SPI_FLASH_CFI_MFR_STMICRO) {
 		flash->flash_lock = stm_lock;
 		flash->flash_unlock = stm_unlock;
 		flash->flash_is_locked = stm_is_locked;
+	}
 #endif
-		break;
-	default:
-		debug("SF: Lock ops not supported for %02x flash\n", idcode[0]);
+
+	if (flash->flash_lock && flash->flash_unlock && flash->flash_is_locked) {
+		mtd->_lock = spi_flash_lock;
+		mtd->_unlock = spi_flash_unlock;
+		mtd->_is_locked = spi_flash_is_locked;
 	}
 
 	/* Compute the flash size */
diff --git a/include/spi_flash.h b/include/spi_flash.h
index 5bb56b4..06951b4 100644
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -55,9 +55,10 @@ struct spi_slave;
  * @dummy_byte:		Dummy cycles for read operation.
  * @memory_map:		Address of read-only SPI flash access
  * @priv:		the private data
- * @flash_lock:		lock a region of the SPI Flash
- * @flash_unlock:	unlock a region of the SPI Flash
- * @flash_is_locked:	check if a region of the SPI Flash is completely locked
+ * @flash_lock:		[FLASH-SPECIFIC] lock a region of the SPI NOR
+ * @flash_unlock:	[FLASH-SPECIFIC] unlock a region of the SPI NOR
+ * @flash_is_locked:	[FLASH-SPECIFIC] check if a region of the SPI NOR is
+ *			completely locked
  * return 0 - Success, 1 - Failure
  */
 struct spi_flash {
@@ -86,9 +87,9 @@ struct spi_flash {
 	void *memory_map;
 	void *priv;
 
-	int (*flash_lock)(struct spi_flash *flash, u32 ofs, size_t len);
-	int (*flash_unlock)(struct spi_flash *flash, u32 ofs, size_t len);
-	int (*flash_is_locked)(struct spi_flash *flash, u32 ofs, size_t len);
+	int (*flash_lock)(struct spi_flash *flash, loff_t ofs, uint64_t len);
+	int (*flash_unlock)(struct spi_flash *flash, loff_t ofs, uint64_t len);
+	int (*flash_is_locked)(struct spi_flash *flash, loff_t ofs, uint64_t len);
 };
 
 static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
@@ -116,6 +117,15 @@ static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
 	return mtd_erase(flash->mtd, &instr);
 }
 
+static inline int spi_flash_protect(struct spi_flash *flash, u32 ofs, u32 len,
+					bool prot)
+{
+	if (prot)
+		return mtd_lock(flash->mtd, ofs, len);
+	else
+		return mtd_unlock(flash->mtd, ofs, len);
+}
+
 #ifdef CONFIG_DM_SPI_FLASH
 int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs,
 			   unsigned int max_hz, unsigned int spi_mode,
@@ -157,18 +167,6 @@ void spi_flash_free(struct spi_flash *flash);
 
 #endif
 
-static inline int spi_flash_protect(struct spi_flash *flash, u32 ofs, u32 len,
-					bool prot)
-{
-	if (!flash->flash_lock)
-		return -EOPNOTSUPP;
-
-	if (prot)
-		return flash->flash_lock(flash, ofs, len);
-	else
-		return flash->flash_unlock(flash, ofs, len);
-}
-
 void spi_boot(void) __noreturn;
 void spi_spl_load_image(uint32_t offs, unsigned int size, void *vdst);
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v6 20/23] sf: Add MTD support for non-dm spi_flash interface
  2015-11-07 13:46 [U-Boot] [PATCH v6 00/23] sf: MTD support Jagan Teki
                   ` (18 preceding siblings ...)
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 19/23] sf: Use MTD lock operations Jagan Teki
@ 2015-11-07 13:46 ` Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 21/23] sf: probe: Minor cleanup Jagan Teki
                   ` (2 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: Jagan Teki @ 2015-11-07 13:46 UTC (permalink / raw)
  To: u-boot

This patch adds MTD support to non-dm spi_flash
interface code.

Reviewed-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Jagan Teki <jteki@openedev.com>
---
 drivers/mtd/spi/sf_probe.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
index b9d1346..71f343b 100644
--- a/drivers/mtd/spi/sf_probe.c
+++ b/drivers/mtd/spi/sf_probe.c
@@ -26,17 +26,24 @@ struct spi_flash_priv {
 #ifndef CONFIG_DM_SPI_FLASH
 struct spi_flash *spi_flash_probe_tail(struct spi_slave *bus)
 {
+	struct spi_flash_priv *priv;
 	struct spi_flash *flash;
 	int ret;
 
-	/* Allocate space if needed (not used by sf-uclass */
-	flash = calloc(1, sizeof(*flash));
-	if (!flash) {
-		debug("SF: Failed to allocate spi_flash\n");
+	/* Allocate space if needed (not used by sf-uclass) */
+	priv = calloc(1, sizeof(*priv));
+	if (!priv) {
+		debug("SF: Failed to allocate spi_flash_priv\n");
 		return NULL;
 	}
 
+	flash = &priv->flash;
+	flash->mtd = &priv->mtd;
+
 	flash->spi = bus;
+	flash->priv = priv;
+
+	priv->mtd.priv = flash;
 
 	/* Claim spi bus */
 	ret = spi_claim_bus(bus);
@@ -49,19 +56,16 @@ struct spi_flash *spi_flash_probe_tail(struct spi_slave *bus)
 	if (ret)
 		goto err_scan;
 
-#ifdef CONFIG_SPI_FLASH_MTD
-	ret = spi_flash_mtd_register(flash);
+	ret = add_mtd_device(&priv->mtd);
 	if (ret) {
 		printf("SF: failed to register mtd device: %d\n", ret);
 		goto err_mtd;
 	}
-#endif
+
 	return flash;
 
-#ifdef CONFIG_SPI_FLASH_MTD
 err_mtd:
 	spi_free_slave(bus);
-#endif
 err_scan:
 	spi_release_bus(bus);
 err_claim:
@@ -95,9 +99,7 @@ struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node,
 
 void spi_flash_free(struct spi_flash *flash)
 {
-#ifdef CONFIG_SPI_FLASH_MTD
-	spi_flash_mtd_unregister();
-#endif
+	del_mtd_device(flash->mtd);
 	spi_free_slave(flash->spi);
 	free(flash);
 }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v6 21/23] sf: probe: Minor cleanup
  2015-11-07 13:46 [U-Boot] [PATCH v6 00/23] sf: MTD support Jagan Teki
                   ` (19 preceding siblings ...)
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 20/23] sf: Add MTD support for non-dm spi_flash interface Jagan Teki
@ 2015-11-07 13:46 ` Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 22/23] sf: Drop SPI_FLASH_MTD driver Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 23/23] configs: Remove CONFIG_SPI_FLASH_MTD Jagan Teki
  22 siblings, 0 replies; 24+ messages in thread
From: Jagan Teki @ 2015-11-07 13:46 UTC (permalink / raw)
  To: u-boot

- Use static for file-scope function
- Remove unneeded header file
- Use spi instead of slave notation for spi_slave {}

Reviewed-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Jagan Teki <jteki@openedev.com>
---
 drivers/mtd/spi/sf_probe.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
index 71f343b..ab0e7c0 100644
--- a/drivers/mtd/spi/sf_probe.c
+++ b/drivers/mtd/spi/sf_probe.c
@@ -24,7 +24,7 @@ struct spi_flash_priv {
 };
 
 #ifndef CONFIG_DM_SPI_FLASH
-struct spi_flash *spi_flash_probe_tail(struct spi_slave *bus)
+static struct spi_flash *spi_flash_probe_tail(struct spi_slave *bus)
 {
 	struct spi_flash_priv *priv;
 	struct spi_flash *flash;
@@ -106,24 +106,24 @@ void spi_flash_free(struct spi_flash *flash)
 
 #else /* defined CONFIG_DM_SPI_FLASH */
 
-int spi_flash_std_probe(struct udevice *dev)
+static int spi_flash_std_probe(struct udevice *dev)
 {
 	struct spi_flash_priv *priv = dev_get_uclass_priv(dev);
-	struct spi_slave *slave = dev_get_parent_priv(dev);
+	struct spi_slave *spi = dev_get_parent_priv(dev);
 	struct spi_flash *flash;
 	int ret;
 
 	flash = &priv->flash;
 	flash->mtd = &priv->mtd;
 
-	flash->spi = slave;
+	flash->spi = spi;
 	flash->priv = priv;
 
 	priv->mtd.priv = flash;
 	flash->dev = dev;
 
 	/* Claim spi bus */
-	ret = spi_claim_bus(slave);
+	ret = spi_claim_bus(spi);
 	if (ret) {
 		debug("SF: Failed to claim SPI bus: %d\n", ret);
 		return ret;
@@ -144,9 +144,9 @@ int spi_flash_std_probe(struct udevice *dev)
 	return ret;
 
 err_mtd:
-	spi_free_slave(slave);
+	spi_free_slave(spi);
 err_scan:
-	spi_release_bus(slave);
+	spi_release_bus(spi);
 	return ret;
 }
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v6 22/23] sf: Drop SPI_FLASH_MTD driver
  2015-11-07 13:46 [U-Boot] [PATCH v6 00/23] sf: MTD support Jagan Teki
                   ` (20 preceding siblings ...)
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 21/23] sf: probe: Minor cleanup Jagan Teki
@ 2015-11-07 13:46 ` Jagan Teki
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 23/23] configs: Remove CONFIG_SPI_FLASH_MTD Jagan Teki
  22 siblings, 0 replies; 24+ messages in thread
From: Jagan Teki @ 2015-11-07 13:46 UTC (permalink / raw)
  To: u-boot

Now MTD core has been added as part of spi-flash layer,
so there is no need for explicit driver for handling
mtd stuff, hence removed all neccessary code regarding
SPI_FLASH_MTD driver.

Signed-off-by: Jagan Teki <jteki@openedev.com>
---
 drivers/mtd/spi/Kconfig       |  12 -----
 drivers/mtd/spi/Makefile      |   1 -
 drivers/mtd/spi/sf_internal.h |   5 --
 drivers/mtd/spi/sf_mtd.c      | 104 ------------------------------------------
 4 files changed, 122 deletions(-)
 delete mode 100644 drivers/mtd/spi/sf_mtd.c

diff --git a/drivers/mtd/spi/Kconfig b/drivers/mtd/spi/Kconfig
index 3f7433c..78932a4 100644
--- a/drivers/mtd/spi/Kconfig
+++ b/drivers/mtd/spi/Kconfig
@@ -116,16 +116,4 @@ config SPI_FLASH_DATAFLASH
 
 	  If unsure, say N
 
-config SPI_FLASH_MTD
-	bool "SPI Flash MTD support"
-	depends on SPI_FLASH
-	help
-          Enable the MTD support for spi flash layer, this adapter is for
-	  translating mtd_read/mtd_write commands into spi_flash_read/write
-	  commands. It is not intended to use it within sf_cmd or the SPI
-	  flash subsystem. Such an adapter is needed for subsystems like
-	  UBI which can only operate on top of the MTD layer.
-
-	  If unsure, say N
-
 endmenu # menu "SPI Flash Support"
diff --git a/drivers/mtd/spi/Makefile b/drivers/mtd/spi/Makefile
index 66c4424..1824261 100644
--- a/drivers/mtd/spi/Makefile
+++ b/drivers/mtd/spi/Makefile
@@ -14,6 +14,5 @@ endif
 
 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
 obj-$(CONFIG_SPI_M95XXX) += eeprom_m95xxx.o
diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h
index 677f582..457c168 100644
--- a/drivers/mtd/spi/sf_internal.h
+++ b/drivers/mtd/spi/sf_internal.h
@@ -193,11 +193,6 @@ int spi_flash_write_common(struct spi_flash *flash, const u8 *cmd,
 int spi_flash_read_common(struct spi_flash *flash, const u8 *cmd,
 		size_t cmd_len, void *data, size_t data_len);
 
-#ifdef CONFIG_SPI_FLASH_MTD
-int spi_flash_mtd_register(struct spi_flash *flash);
-void spi_flash_mtd_unregister(void);
-#endif
-
 /**
  * spi_flash_scan - scan the SPI FLASH
  * @flash:	the spi flash structure
diff --git a/drivers/mtd/spi/sf_mtd.c b/drivers/mtd/spi/sf_mtd.c
deleted file mode 100644
index 0b9cb62..0000000
--- a/drivers/mtd/spi/sf_mtd.c
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright (C) 2012-2014 Daniel Schwierzeck, daniel.schwierzeck at gmail.com
- *
- * SPDX-License-Identifier:	GPL-2.0+
- */
-
-#include <common.h>
-#include <malloc.h>
-#include <asm/errno.h>
-#include <linux/mtd/mtd.h>
-#include <spi_flash.h>
-
-static struct mtd_info sf_mtd_info;
-static char sf_mtd_name[8];
-
-static int spi_flash_mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
-{
-	struct spi_flash *flash = mtd->priv;
-	int err;
-
-	instr->state = MTD_ERASING;
-
-	err = spi_flash_erase(flash, instr->addr, instr->len);
-	if (err) {
-		instr->state = MTD_ERASE_FAILED;
-		instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN;
-		return -EIO;
-	}
-
-	instr->state = MTD_ERASE_DONE;
-	mtd_erase_callback(instr);
-
-	return 0;
-}
-
-static int spi_flash_mtd_read(struct mtd_info *mtd, loff_t from, size_t len,
-	size_t *retlen, u_char *buf)
-{
-	struct spi_flash *flash = mtd->priv;
-	int err;
-
-	err = spi_flash_read(flash, from, len, buf);
-	if (!err)
-		*retlen = len;
-
-	return err;
-}
-
-static int spi_flash_mtd_write(struct mtd_info *mtd, loff_t to, size_t len,
-	size_t *retlen, const u_char *buf)
-{
-	struct spi_flash *flash = mtd->priv;
-	int err;
-
-	err = spi_flash_write(flash, to, len, buf);
-	if (!err)
-		*retlen = len;
-
-	return err;
-}
-
-static void spi_flash_mtd_sync(struct mtd_info *mtd)
-{
-}
-
-static int spi_flash_mtd_number(void)
-{
-#ifdef CONFIG_SYS_MAX_FLASH_BANKS
-	return CONFIG_SYS_MAX_FLASH_BANKS;
-#else
-	return 0;
-#endif
-}
-
-int spi_flash_mtd_register(struct spi_flash *flash)
-{
-	memset(&sf_mtd_info, 0, sizeof(sf_mtd_info));
-	sprintf(sf_mtd_name, "nor%d", spi_flash_mtd_number());
-
-	sf_mtd_info.name = sf_mtd_name;
-	sf_mtd_info.type = MTD_NORFLASH;
-	sf_mtd_info.flags = MTD_CAP_NORFLASH;
-	sf_mtd_info.writesize = 1;
-	sf_mtd_info.writebufsize = flash->page_size;
-
-	sf_mtd_info._erase = spi_flash_mtd_erase;
-	sf_mtd_info._read = spi_flash_mtd_read;
-	sf_mtd_info._write = spi_flash_mtd_write;
-	sf_mtd_info._sync = spi_flash_mtd_sync;
-
-	sf_mtd_info.size = flash->size;
-	sf_mtd_info.priv = flash;
-
-	/* Only uniform flash devices for now */
-	sf_mtd_info.numeraseregions = 0;
-	sf_mtd_info.erasesize = flash->sector_size;
-
-	return add_mtd_device(&sf_mtd_info);
-}
-
-void spi_flash_mtd_unregister(void)
-{
-	del_mtd_device(&sf_mtd_info);
-}
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v6 23/23] configs: Remove CONFIG_SPI_FLASH_MTD
  2015-11-07 13:46 [U-Boot] [PATCH v6 00/23] sf: MTD support Jagan Teki
                   ` (21 preceding siblings ...)
  2015-11-07 13:46 ` [U-Boot] [PATCH v6 22/23] sf: Drop SPI_FLASH_MTD driver Jagan Teki
@ 2015-11-07 13:46 ` Jagan Teki
  22 siblings, 0 replies; 24+ messages in thread
From: Jagan Teki @ 2015-11-07 13:46 UTC (permalink / raw)
  To: u-boot

No explict spi-flash mtd handling driver, it's been
part of spi-flash layer iteself, hence removed it from
board configs.

Signed-off-by: Jagan Teki <jteki@openedev.com>
---
 include/configs/aristainetos-common.h | 1 -
 include/configs/gw_ventana.h          | 1 -
 include/configs/socfpga_common.h      | 1 -
 3 files changed, 3 deletions(-)

diff --git a/include/configs/aristainetos-common.h b/include/configs/aristainetos-common.h
index f03297e..a7d938b 100644
--- a/include/configs/aristainetos-common.h
+++ b/include/configs/aristainetos-common.h
@@ -42,7 +42,6 @@
 #define CONFIG_PHY_MICREL
 
 #define CONFIG_CMD_SF
-#define CONFIG_SPI_FLASH_MTD
 #define CONFIG_SPI_FLASH_STMICRO
 #define CONFIG_MXC_SPI
 #define CONFIG_SF_DEFAULT_SPEED		20000000
diff --git a/include/configs/gw_ventana.h b/include/configs/gw_ventana.h
index 484d763..a63db66 100644
--- a/include/configs/gw_ventana.h
+++ b/include/configs/gw_ventana.h
@@ -69,7 +69,6 @@
 #define CONFIG_CMD_SF
 #ifdef CONFIG_CMD_SF
   #define CONFIG_MXC_SPI
-  #define CONFIG_SPI_FLASH_MTD
   #define CONFIG_SPI_FLASH_BAR
   #define CONFIG_SPI_FLASH_WINBOND
   #define CONFIG_SF_DEFAULT_BUS              0
diff --git a/include/configs/socfpga_common.h b/include/configs/socfpga_common.h
index 3374683..cb32954 100644
--- a/include/configs/socfpga_common.h
+++ b/include/configs/socfpga_common.h
@@ -195,7 +195,6 @@ unsigned int cm_get_l4_sp_clk_hz(void);
 #define CONFIG_SPI_FLASH_STMICRO	/* Micron/Numonyx flash */
 #define CONFIG_SPI_FLASH_SPANSION	/* Spansion flash */
 #ifndef CONFIG_SPL_BUILD
-#define CONFIG_SPI_FLASH_MTD
 #define CONFIG_CMD_MTDPARTS
 #define CONFIG_MTD_DEVICE
 #define CONFIG_MTD_PARTITIONS
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2015-11-07 13:46 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-07 13:46 [U-Boot] [PATCH v6 00/23] sf: MTD support Jagan Teki
2015-11-07 13:46 ` [U-Boot] [PATCH v6 01/23] sf: spi_flash_validate_params => spi_flash_scan Jagan Teki
2015-11-07 13:46 ` [U-Boot] [PATCH v6 02/23] sf: Move spi_flash_scan code to sf_ops Jagan Teki
2015-11-07 13:46 ` [U-Boot] [PATCH v6 03/23] sf: Move read_id " Jagan Teki
2015-11-07 13:46 ` [U-Boot] [PATCH v6 04/23] sf: probe: Code cleanup Jagan Teki
2015-11-07 13:46 ` [U-Boot] [PATCH v6 05/23] sf: Use static for file-scope functions Jagan Teki
2015-11-07 13:46 ` [U-Boot] [PATCH v6 06/23] sf: Fix Makefile Jagan Teki
2015-11-07 13:46 ` [U-Boot] [PATCH v6 07/23] sf: Use simple name for register access functions Jagan Teki
2015-11-07 13:46 ` [U-Boot] [PATCH v6 08/23] sf: Use flash function pointers in dm_spi_flash_ops Jagan Teki
2015-11-07 13:46 ` [U-Boot] [PATCH v6 09/23] sf: Flash power up read-only based on idcode0 Jagan Teki
2015-11-07 13:46 ` [U-Boot] [PATCH v6 10/23] sf: Use static for file-scope functions Jagan Teki
2015-11-07 13:46 ` [U-Boot] [PATCH v6 11/23] sf: Remove unneeded header includes Jagan Teki
2015-11-07 13:46 ` [U-Boot] [PATCH v6 12/23] sf: probe: Use spi_flash_scan in dm-spi-flash Jagan Teki
2015-11-07 13:46 ` [U-Boot] [PATCH v6 13/23] sf: Re-factorize spi_flash_probe_tail code Jagan Teki
2015-11-07 13:46 ` [U-Boot] [PATCH v6 14/23] dm-sf: Re-factorize spi_flash_std_probe code Jagan Teki
2015-11-07 13:46 ` [U-Boot] [PATCH v6 15/23] sf: Add MTD support to spi_flash Jagan Teki
2015-11-07 13:46 ` [U-Boot] [PATCH v6 16/23] sf: Use mtd_info ops instead of spi_flash ops Jagan Teki
2015-11-07 13:46 ` [U-Boot] [PATCH v6 17/23] cmd_sf: Use mtd->size instead of flash->size Jagan Teki
2015-11-07 13:46 ` [U-Boot] [PATCH v6 18/23] dm-sf: use mtd_ops, drop dm_spi_flash_ops Jagan Teki
2015-11-07 13:46 ` [U-Boot] [PATCH v6 19/23] sf: Use MTD lock operations Jagan Teki
2015-11-07 13:46 ` [U-Boot] [PATCH v6 20/23] sf: Add MTD support for non-dm spi_flash interface Jagan Teki
2015-11-07 13:46 ` [U-Boot] [PATCH v6 21/23] sf: probe: Minor cleanup Jagan Teki
2015-11-07 13:46 ` [U-Boot] [PATCH v6 22/23] sf: Drop SPI_FLASH_MTD driver Jagan Teki
2015-11-07 13:46 ` [U-Boot] [PATCH v6 23/23] configs: Remove CONFIG_SPI_FLASH_MTD Jagan Teki

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.