[U-Boot] [PATCH 1/1] mtd/spi: Support of non-jedec MRAM devices

Matt Weber matthew.weber at rockwellcollins.com
Mon Jul 10 16:31:32 UTC 2017


This patch adds support of non-jedec MRAM devices mr25hx from Everspin.
This flash devices do not have jedec device ID and hence support for
name matching is also added as part of this series.

This patch streamlined the update of SPI flash probing function API
changes and included the following updates:

1) Updated "spi_flash_probe" (old method) and
"spi_flash_probe_bus_cs" (new method) APIs
2) Added ifdefs for CONFIG_ENV_SPI_NAME and CONFIG_SF_DEFAULT_NAME so
that addition of flash name in case of non-jedec device becomes
streamlined.
3) Used CONFIG_ENV_SPI_NAME and CONFIG_SF_DEFAULT_NAME at all possible
places except board/ files which has custom or hard coded arguments in
"spi_flash_probe" functions. In such cases, passed NULL as flash name.

Signed-off-by: Ronak Desai <ronak.desai at rockwellcollins.com>
Signed-off-by: Matthew Weber <matthew.weber at rockwellcollins.com>
---
 board/Arcturus/ucp1020/cmd_arc.c         |  4 ++--
 board/Synology/ds414/cmd_syno.c          |  2 +-
 board/aries/ma5d4evk/ma5d4evk.c          |  3 ++-
 board/buffalo/lsxl/lsxl.c                |  2 +-
 board/congatec/cgtqmx6eval/cgtqmx6eval.c |  5 +++--
 board/davinci/da8xxevm/da850evm.c        |  2 +-
 board/renesas/sh7752evb/sh7752evb.c      |  4 ++--
 board/renesas/sh7753evb/sh7753evb.c      |  4 ++--
 board/renesas/sh7757lcr/sh7757lcr.c      |  6 +++---
 board/siemens/taurus/taurus.c            |  3 ++-
 cmd/mvebu/bubt.c                         |  3 ++-
 cmd/sf.c                                 | 12 ++++++++----
 common/env_sf.c                          | 10 ++++++----
 common/spl/spl_spi.c                     |  3 ++-
 common/splash_source.c                   |  3 ++-
 drivers/dfu/dfu_sf.c                     |  3 ++-
 drivers/mtd/spi/Kconfig                  |  5 +++++
 drivers/mtd/spi/fsl_espi_spl.c           |  4 ++--
 drivers/mtd/spi/sf-uclass.c              |  9 +++++----
 drivers/mtd/spi/sf_internal.h            |  4 +++-
 drivers/mtd/spi/sf_probe.c               | 18 +++++++++---------
 drivers/mtd/spi/spi_flash.c              | 27 ++++++++++++++++++++++++---
 drivers/mtd/spi/spi_flash_ids.c          | 11 +++++++++++
 drivers/net/fm/fm.c                      |  4 ++--
 drivers/spi/spi-uclass.c                 | 15 +++++++++------
 include/spi.h                            |  6 +++++-
 include/spi_flash.h                      | 11 +++++++----
 27 files changed, 123 insertions(+), 60 deletions(-)

diff --git a/board/Arcturus/ucp1020/cmd_arc.c b/board/Arcturus/ucp1020/cmd_arc.c
index fa6b485..c4ca1b3 100644
--- a/board/Arcturus/ucp1020/cmd_arc.c
+++ b/board/Arcturus/ucp1020/cmd_arc.c
@@ -74,7 +74,7 @@ static int set_arc_product(int argc, char *const argv[])
 	strcpy(smac[0], argv[4]);
 
 	flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
-				CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
+				CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE, CONFIG_ENV_SPI_NAME);
 
 	/*
 	 * Save factory defaults
@@ -113,7 +113,7 @@ int get_arc_info(void)
 	char *myerr = "ERROR: Failed to read all 4 factory info spi locations";
 
 	flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
-				CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
+				CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE, CONFIG_ENV_SPI_NAME);
 
 	if (spi_flash_read(flash, FIRM_ADDR1, sizeof(smac), smac)) {
 		location++;
diff --git a/board/Synology/ds414/cmd_syno.c b/board/Synology/ds414/cmd_syno.c
index 20544e2..a2c2e9d 100644
--- a/board/Synology/ds414/cmd_syno.c
+++ b/board/Synology/ds414/cmd_syno.c
@@ -38,7 +38,7 @@ static int do_syno_populate(int argc, char * const argv[])
 
 	/* XXX: arg parsing to select flash here? */
 
-	flash = spi_flash_probe(bus, cs, speed, mode);
+	flash = spi_flash_probe(bus, cs, speed, mode, NULL);
 	if (!flash) {
 		printf("Failed to initialize SPI flash at %u:%u\n", bus, cs);
 		return 1;
diff --git a/board/aries/ma5d4evk/ma5d4evk.c b/board/aries/ma5d4evk/ma5d4evk.c
index b9294fc..21d4508 100644
--- a/board/aries/ma5d4evk/ma5d4evk.c
+++ b/board/aries/ma5d4evk/ma5d4evk.c
@@ -283,7 +283,8 @@ static void board_identify(void)
 {
 	struct spi_flash *sf;
 	sf = spi_flash_probe(CONFIG_SF_DEFAULT_BUS, CONFIG_SF_DEFAULT_CS,
-			     CONFIG_SF_DEFAULT_SPEED, CONFIG_SF_DEFAULT_MODE);
+			     CONFIG_SF_DEFAULT_SPEED, CONFIG_SF_DEFAULT_MODE,
+			     CONFIG_SF_DEFAULT_NAME);
 	boot_mode_sf = (sf != NULL);
 }
 
diff --git a/board/buffalo/lsxl/lsxl.c b/board/buffalo/lsxl/lsxl.c
index 0f37345..a970974 100644
--- a/board/buffalo/lsxl/lsxl.c
+++ b/board/buffalo/lsxl/lsxl.c
@@ -214,7 +214,7 @@ static void erase_environment(void)
 	struct spi_flash *flash;
 
 	printf("Erasing environment..\n");
-	flash = spi_flash_probe(0, 0, 1000000, SPI_MODE_3);
+	flash = spi_flash_probe(0, 0, 1000000, SPI_MODE_3, NULL);
 	if (!flash) {
 		printf("Erasing flash failed\n");
 		return;
diff --git a/board/congatec/cgtqmx6eval/cgtqmx6eval.c b/board/congatec/cgtqmx6eval/cgtqmx6eval.c
index 24956a8..6275ca0 100644
--- a/board/congatec/cgtqmx6eval/cgtqmx6eval.c
+++ b/board/congatec/cgtqmx6eval/cgtqmx6eval.c
@@ -397,7 +397,7 @@ int board_phy_config(struct phy_device *phydev)
 
 	return 0;
 }
- 
+
 static void setup_iomux_uart(void)
 {
 	SETUP_IOMUX_PADS(uart2_pads);
@@ -1007,7 +1007,8 @@ static bool is_2gb(void)
 
 	spi = spi_flash_probe(CONFIG_ENV_SPI_BUS,
 			      CONFIG_ENV_SPI_CS,
-			      CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
+			      CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE,
+			      CONFIG_ENV_SPI_NAME);
 	ret = spi_flash_read(spi, CFG_MFG_ADDR_OFFSET, sizeof(struct mfgdata),
 			     buf);
 	if (ret)
diff --git a/board/davinci/da8xxevm/da850evm.c b/board/davinci/da8xxevm/da850evm.c
index 11ea52f..e040426 100644
--- a/board/davinci/da8xxevm/da850evm.c
+++ b/board/davinci/da8xxevm/da850evm.c
@@ -54,7 +54,7 @@ static int get_mac_addr(u8 *addr)
 	int ret;
 
 	flash = spi_flash_probe(CFG_MAC_ADDR_SPI_BUS, CFG_MAC_ADDR_SPI_CS,
-			CFG_MAC_ADDR_SPI_MAX_HZ, CFG_MAC_ADDR_SPI_MODE);
+			CFG_MAC_ADDR_SPI_MAX_HZ, CFG_MAC_ADDR_SPI_MODE, NULL);
 	if (!flash) {
 		printf("Error - unable to probe SPI flash.\n");
 		return -1;
diff --git a/board/renesas/sh7752evb/sh7752evb.c b/board/renesas/sh7752evb/sh7752evb.c
index 525d979..580b916 100644
--- a/board/renesas/sh7752evb/sh7752evb.c
+++ b/board/renesas/sh7752evb/sh7752evb.c
@@ -177,7 +177,7 @@ static int get_sh_eth_mac_raw(unsigned char *buf, int size)
 	struct spi_flash *spi;
 	int ret;
 
-	spi = spi_flash_probe(0, 0, 1000000, SPI_MODE_3);
+	spi = spi_flash_probe(0, 0, 1000000, SPI_MODE_3, NULL);
 	if (spi == NULL) {
 		printf("%s: spi_flash probe failed.\n", __func__);
 		return 1;
@@ -270,7 +270,7 @@ int do_write_mac(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		argv[1], argv[2]);
 
 	/* write MAC data to SPI rom */
-	spi = spi_flash_probe(0, 0, 1000000, SPI_MODE_3);
+	spi = spi_flash_probe(0, 0, 1000000, SPI_MODE_3, NULL);
 	if (!spi) {
 		printf("%s: spi_flash probe failed.\n", __func__);
 		return 1;
diff --git a/board/renesas/sh7753evb/sh7753evb.c b/board/renesas/sh7753evb/sh7753evb.c
index 3d1eeda..9416748 100644
--- a/board/renesas/sh7753evb/sh7753evb.c
+++ b/board/renesas/sh7753evb/sh7753evb.c
@@ -193,7 +193,7 @@ static int get_sh_eth_mac_raw(unsigned char *buf, int size)
 	struct spi_flash *spi;
 	int ret;
 
-	spi = spi_flash_probe(0, 0, 1000000, SPI_MODE_3);
+	spi = spi_flash_probe(0, 0, 1000000, SPI_MODE_3, NULL);
 	if (spi == NULL) {
 		printf("%s: spi_flash probe failed.\n", __func__);
 		return 1;
@@ -286,7 +286,7 @@ int do_write_mac(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		argv[1], argv[2]);
 
 	/* write MAC data to SPI rom */
-	spi = spi_flash_probe(0, 0, 1000000, SPI_MODE_3);
+	spi = spi_flash_probe(0, 0, 1000000, SPI_MODE_3, NULL);
 	if (!spi) {
 		printf("%s: spi_flash probe failed.\n", __func__);
 		return 1;
diff --git a/board/renesas/sh7757lcr/sh7757lcr.c b/board/renesas/sh7757lcr/sh7757lcr.c
index 0a04a9d..e553128 100644
--- a/board/renesas/sh7757lcr/sh7757lcr.c
+++ b/board/renesas/sh7757lcr/sh7757lcr.c
@@ -34,7 +34,7 @@ static int init_pcie_bridge_from_spi(void *buf, size_t size)
 	int ret;
 	unsigned long pcie_addr;
 
-	spi = spi_flash_probe(0, 0, 1000000, SPI_MODE_3);
+	spi = spi_flash_probe(0, 0, 1000000, SPI_MODE_3, NULL);
 	if (!spi) {
 		printf("%s: spi_flash probe error.\n", __func__);
 		return 1;
@@ -234,7 +234,7 @@ static int get_sh_eth_mac_raw(unsigned char *buf, int size)
 	struct spi_flash *spi;
 	int ret;
 
-	spi = spi_flash_probe(0, 0, 1000000, SPI_MODE_3);
+	spi = spi_flash_probe(0, 0, 1000000, SPI_MODE_3, NULL);
 	if (spi == NULL) {
 		printf("%s: spi_flash probe error.\n", __func__);
 		return 1;
@@ -386,7 +386,7 @@ int do_write_mac(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		argv[1], argv[2], argv[3], argv[4]);
 
 	/* write MAC data to SPI rom */
-	spi = spi_flash_probe(0, 0, 1000000, SPI_MODE_3);
+	spi = spi_flash_probe(0, 0, 1000000, SPI_MODE_3, NULL);
 	if (!spi) {
 		printf("%s: spi_flash probe error.\n", __func__);
 		return 1;
diff --git a/board/siemens/taurus/taurus.c b/board/siemens/taurus/taurus.c
index 4aa8d64..ee75178 100644
--- a/board/siemens/taurus/taurus.c
+++ b/board/siemens/taurus/taurus.c
@@ -141,7 +141,8 @@ void spl_board_init(void)
 		flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
 					0,
 					CONFIG_SF_DEFAULT_SPEED,
-					CONFIG_SF_DEFAULT_MODE);
+					CONFIG_SF_DEFAULT_MODE,
+					CONFIG_SF_DEFAULT_NAME);
 		if (!flash) {
 			puts("no flash\n");
 		} else {
diff --git a/cmd/mvebu/bubt.c b/cmd/mvebu/bubt.c
index 1e1f0af..ba3aea9 100644
--- a/cmd/mvebu/bubt.c
+++ b/cmd/mvebu/bubt.c
@@ -252,7 +252,8 @@ static int spi_burn_image(size_t image_size)
 	flash = spi_flash_probe(CONFIG_ENV_SPI_BUS,
 				CONFIG_ENV_SPI_CS,
 				CONFIG_SF_DEFAULT_SPEED,
-				CONFIG_SF_DEFAULT_MODE);
+				CONFIG_SF_DEFAULT_MODE,
+				CONFIG_SF_DEFAULT_NAME);
 	if (!flash) {
 		printf("Failed to probe SPI Flash\n");
 		return -ENOMEDIUM;
diff --git a/cmd/sf.c b/cmd/sf.c
index f971eec..ae6d87c 100644
--- a/cmd/sf.c
+++ b/cmd/sf.c
@@ -84,6 +84,7 @@ static int do_spi_flash_probe(int argc, char * const argv[])
 	unsigned int cs = CONFIG_SF_DEFAULT_CS;
 	unsigned int speed = CONFIG_SF_DEFAULT_SPEED;
 	unsigned int mode = CONFIG_SF_DEFAULT_MODE;
+	const char *name = NULL;
 	char *endp;
 #ifdef CONFIG_DM_SPI_FLASH
 	struct udevice *new, *bus_dev;
@@ -119,6 +120,9 @@ static int do_spi_flash_probe(int argc, char * const argv[])
 		if (*argv[3] == 0 || *endp != 0)
 			return -1;
 	}
+	if (argc >= 5) {
+		name = argv[4];
+	}
 
 #ifdef CONFIG_DM_SPI_FLASH
 	/* Remove the old device, otherwise probe will just be a nop */
@@ -127,7 +131,7 @@ static int do_spi_flash_probe(int argc, char * const argv[])
 		device_remove(new, DM_REMOVE_NORMAL);
 	}
 	flash = NULL;
-	ret = spi_flash_probe_bus_cs(bus, cs, speed, mode, &new);
+	ret = spi_flash_probe_bus_cs(bus, cs, speed, mode, &new, name);
 	if (ret) {
 		printf("Failed to initialize SPI flash at %u:%u (error %d)\n",
 		       bus, cs, ret);
@@ -139,7 +143,7 @@ static int do_spi_flash_probe(int argc, char * const argv[])
 	if (flash)
 		spi_flash_free(flash);
 
-	new = spi_flash_probe(bus, cs, speed, mode);
+	new = spi_flash_probe(bus, cs, speed, mode, name);
 	flash = new;
 
 	if (!new) {
@@ -597,9 +601,9 @@ usage:
 #endif
 
 U_BOOT_CMD(
-	sf,	5,	1,	do_spi_flash,
+	sf,	6,	1,	do_spi_flash,
 	"SPI flash sub-system",
-	"probe [[bus:]cs] [hz] [mode]	- init flash device on given SPI bus\n"
+	"probe [[bus:]cs] [hz] [mode] [name]	- init flash device on given SPI bus\n"
 	"				  and chip select\n"
 	"sf read addr offset|partition len	- read `len' bytes starting at\n"
 	"				          `offset' or from start of mtd\n"
diff --git a/common/env_sf.c b/common/env_sf.c
index 45f441a..a23d174 100644
--- a/common/env_sf.c
+++ b/common/env_sf.c
@@ -31,7 +31,9 @@
 #ifndef CONFIG_ENV_SPI_MODE
 # define CONFIG_ENV_SPI_MODE	CONFIG_SF_DEFAULT_MODE
 #endif
-
+#ifndef CONFIG_ENV_SPI_NAME
+# define CONFIG_ENV_SPI_NAME 	CONFIG_SF_DEFAULT_NAME
+#endif
 #ifdef CONFIG_ENV_OFFSET_REDUND
 static ulong env_offset		= CONFIG_ENV_OFFSET;
 static ulong env_new_offset	= CONFIG_ENV_OFFSET_REDUND;
@@ -54,7 +56,7 @@ static int setup_flash_device(void)
 
 	/* speed and mode will be read from DT */
 	ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
-				     0, 0, &new);
+				     0, 0, &new, CONFIG_ENV_SPI_NAME);
 	if (ret) {
 		set_default_env("!spi_flash_probe_bus_cs() failed");
 		return 1;
@@ -65,8 +67,8 @@ static int setup_flash_device(void)
 
 	if (!env_flash) {
 		env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS,
-			CONFIG_ENV_SPI_CS,
-			CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
+			CONFIG_ENV_SPI_CS, CONFIG_ENV_SPI_MAX_HZ,
+			CONFIG_ENV_SPI_MODE, CONFIG_ENV_SPI_NAME);
 		if (!env_flash) {
 			set_default_env("!spi_flash_probe() failed");
 			return 1;
diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c
index 42880d5..e8d13fc 100644
--- a/common/spl/spl_spi.c
+++ b/common/spl/spl_spi.c
@@ -83,7 +83,8 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
 	flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
 				CONFIG_SF_DEFAULT_CS,
 				CONFIG_SF_DEFAULT_SPEED,
-				CONFIG_SF_DEFAULT_MODE);
+				CONFIG_SF_DEFAULT_MODE,
+				CONFIG_SF_DEFAULT_NAME);
 	if (!flash) {
 		puts("SPI probe failed.\n");
 		return -ENODEV;
diff --git a/common/splash_source.c b/common/splash_source.c
index d1647c8..3a1f72d 100644
--- a/common/splash_source.c
+++ b/common/splash_source.c
@@ -29,7 +29,8 @@ static int splash_sf_read_raw(u32 bmp_load_addr, int offset, size_t read_size)
 		sf = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
 				     CONFIG_SF_DEFAULT_CS,
 				     CONFIG_SF_DEFAULT_SPEED,
-				     CONFIG_SF_DEFAULT_MODE);
+				     CONFIG_SF_DEFAULT_MODE,
+				     CONFIG_SF_DEFAULT_NAME);
 		if (!sf)
 			return -ENODEV;
 	}
diff --git a/drivers/dfu/dfu_sf.c b/drivers/dfu/dfu_sf.c
index b6d5fe2..a80e8de 100644
--- a/drivers/dfu/dfu_sf.c
+++ b/drivers/dfu/dfu_sf.c
@@ -70,6 +70,7 @@ static struct spi_flash *parse_dev(char *devstr)
 	unsigned int cs;
 	unsigned int speed = CONFIG_SF_DEFAULT_SPEED;
 	unsigned int mode = CONFIG_SF_DEFAULT_MODE;
+	const char *name = CONFIG_SF_DEFAULT_NAME;
 	char *s, *endp;
 	struct spi_flash *dev;
 
@@ -103,7 +104,7 @@ static struct spi_flash *parse_dev(char *devstr)
 		}
 	}
 
-	dev = spi_flash_probe(bus, cs, speed, mode);
+	dev = spi_flash_probe(bus, cs, speed, mode, name);
 	if (!dev) {
 		printf("Failed to create SPI flash at %d:%d:%d:%d\n",
 		       bus, cs, speed, mode);
diff --git a/drivers/mtd/spi/Kconfig b/drivers/mtd/spi/Kconfig
index 5700859..eea6d4a 100644
--- a/drivers/mtd/spi/Kconfig
+++ b/drivers/mtd/spi/Kconfig
@@ -91,6 +91,11 @@ config SPI_FLASH_WINBOND
 	help
 	  Add support for various Winbond SPI flash chips (W25xxx)
 
+config SPI_FLASH_EVERSPIN
+	bool "Everspin SPI flash(MRAM) support"
+	help
+	  Add support for various Everspin SPI flash(MRAM) chips (M25Hxxx)
+
 endif
 
 config SPI_FLASH_USE_4K_SECTORS
diff --git a/drivers/mtd/spi/fsl_espi_spl.c b/drivers/mtd/spi/fsl_espi_spl.c
index 1dd44e2..f1127e9 100644
--- a/drivers/mtd/spi/fsl_espi_spl.c
+++ b/drivers/mtd/spi/fsl_espi_spl.c
@@ -17,7 +17,7 @@ void fsl_spi_spl_load_image(uint32_t offs, unsigned int size, void *vdst)
 	struct spi_flash *flash;
 
 	flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
-			CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
+			CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE, CONFIG_ENV_SPI_NAME);
 	if (flash == NULL) {
 		puts("\nspi_flash_probe failed");
 		hang();
@@ -41,7 +41,7 @@ void fsl_spi_boot(void)
 	struct spi_flash *flash;
 
 	flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
-			CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
+			CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE, CONFIG_ENV_SPI_NAME);
 	if (flash == NULL) {
 		puts("\nspi_flash_probe failed");
 		hang();
diff --git a/drivers/mtd/spi/sf-uclass.c b/drivers/mtd/spi/sf-uclass.c
index 8387648..f0b1535 100644
--- a/drivers/mtd/spi/sf-uclass.c
+++ b/drivers/mtd/spi/sf-uclass.c
@@ -34,11 +34,12 @@ int spi_flash_erase_dm(struct udevice *dev, u32 offset, size_t len)
  * it when all SPI flash drivers use dm
  */
 struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
-				  unsigned int max_hz, unsigned int spi_mode)
+				  unsigned int max_hz, unsigned int spi_mode,
+				  const char *flash_name)
 {
 	struct udevice *dev;
 
-	if (spi_flash_probe_bus_cs(bus, cs, max_hz, spi_mode, &dev))
+	if (spi_flash_probe_bus_cs(bus, cs, max_hz, spi_mode, &dev, flash_name))
 		return NULL;
 
 	return dev_get_uclass_priv(dev);
@@ -51,7 +52,7 @@ void spi_flash_free(struct spi_flash *flash)
 
 int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs,
 			   unsigned int max_hz, unsigned int spi_mode,
-			   struct udevice **devp)
+			   struct udevice **devp, const char *flash_name)
 {
 	struct spi_slave *slave;
 	struct udevice *bus;
@@ -67,7 +68,7 @@ int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs,
 	str = strdup(name);
 #endif
 	ret = spi_get_bus_and_cs(busnum, cs, max_hz, spi_mode,
-				  "spi_flash_std", str, &bus, &slave);
+				  "spi_flash_std", str, &bus, &slave, flash_name);
 	if (ret)
 		return ret;
 
diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h
index 839cdbe..df88f56 100644
--- a/drivers/mtd/spi/sf_internal.h
+++ b/drivers/mtd/spi/sf_internal.h
@@ -131,6 +131,7 @@ struct spi_flash_info {
 #define RD_DUAL			BIT(5)	/* use Dual Read */
 #define RD_QUADIO		BIT(6)	/* use Quad IO Read */
 #define RD_DUALIO		BIT(7)	/* use Dual IO Read */
+#define NO_FR			BIT(8)  /* Can't do fast read */
 #define RD_FULL			(RD_QUAD | RD_DUAL | RD_QUADIO | RD_DUALIO)
 };
 
@@ -216,6 +217,7 @@ void spi_flash_mtd_unregister(void);
 /**
  * spi_flash_scan - scan the SPI FLASH
  * @flash:	the spi flash structure
+ * @flash_name: Name of the flash device(to probe non-jedec flash devices)
  *
  * The drivers can use this fuction to scan the SPI FLASH.
  * In the scanning, it will try to get all the necessary information to
@@ -223,6 +225,6 @@ void spi_flash_mtd_unregister(void);
  *
  * Return: 0 for success, others for failure.
  */
-int spi_flash_scan(struct spi_flash *flash);
+int spi_flash_scan(struct spi_flash *flash, const char *flash_name);
 
 #endif /* _SF_INTERNAL_H_ */
diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
index 7b29637..206135a 100644
--- a/drivers/mtd/spi/sf_probe.c
+++ b/drivers/mtd/spi/sf_probe.c
@@ -23,7 +23,7 @@
  * @flashp: Pointer to place to put flash info, which may be NULL if the
  * space should be allocated
  */
-static int spi_flash_probe_slave(struct spi_flash *flash)
+static int spi_flash_probe_slave(struct spi_flash *flash, const char *name)
 {
 	struct spi_slave *spi = flash->spi;
 	int ret;
@@ -41,7 +41,7 @@ static int spi_flash_probe_slave(struct spi_flash *flash)
 		return ret;
 	}
 
-	ret = spi_flash_scan(flash);
+	ret = spi_flash_scan(flash, name);
 	if (ret)
 		goto err_read_id;
 
@@ -55,7 +55,7 @@ err_read_id:
 }
 
 #ifndef CONFIG_DM_SPI_FLASH
-static struct spi_flash *spi_flash_probe_tail(struct spi_slave *bus)
+static struct spi_flash *spi_flash_probe_tail(struct spi_slave *bus, const char *name)
 {
 	struct spi_flash *flash;
 
@@ -67,7 +67,7 @@ static struct spi_flash *spi_flash_probe_tail(struct spi_slave *bus)
 	}
 
 	flash->spi = bus;
-	if (spi_flash_probe_slave(flash)) {
+	if (spi_flash_probe_slave(flash, name)) {
 		spi_free_slave(bus);
 		free(flash);
 		return NULL;
@@ -77,14 +77,14 @@ static struct spi_flash *spi_flash_probe_tail(struct spi_slave *bus)
 }
 
 struct spi_flash *spi_flash_probe(unsigned int busnum, unsigned int cs,
-		unsigned int max_hz, unsigned int spi_mode)
+		unsigned int max_hz, unsigned int spi_mode, const char *name)
 {
 	struct spi_slave *bus;
 
 	bus = spi_setup_slave(busnum, cs, max_hz, spi_mode);
 	if (!bus)
 		return NULL;
-	return spi_flash_probe_tail(bus);
+	return spi_flash_probe_tail(bus, name);
 }
 
 #ifdef CONFIG_OF_SPI_FLASH
@@ -96,7 +96,7 @@ struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node,
 	bus = spi_setup_slave_fdt(blob, slave_node, spi_node);
 	if (!bus)
 		return NULL;
-	return spi_flash_probe_tail(bus);
+	return spi_flash_probe_tail(bus, NULL);
 }
 #endif
 
@@ -152,8 +152,8 @@ static int spi_flash_std_probe(struct udevice *dev)
 	flash = dev_get_uclass_priv(dev);
 	flash->dev = dev;
 	flash->spi = slave;
-	debug("%s: slave=%p, cs=%d\n", __func__, slave, plat->cs);
-	return spi_flash_probe_slave(flash);
+	debug("%s: slave=%p, cs=%d, flash_name=%s\n", __func__, slave, plat->cs, plat->name);
+	return spi_flash_probe_slave(flash, plat->name);
 }
 
 static const struct dm_spi_flash_ops spi_flash_std_ops = {
diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c
index 0034a28..d09be57 100644
--- a/drivers/mtd/spi/spi_flash.c
+++ b/drivers/mtd/spi/spi_flash.c
@@ -863,6 +863,23 @@ static int spansion_quad_enable(struct spi_flash *flash)
 }
 #endif
 
+static const struct spi_flash_info *spi_flash_match_id(struct spi_flash *flash, const char *name)
+{
+	const struct spi_flash_info     *info;
+
+#ifdef CONFIG_SPI_GENERIC
+	if (flash->spi->option & SF_DUAL_PARALLEL_FLASH)
+		flash->spi->flags |= SPI_XFER_LOWER;
+#endif
+
+	info = spi_flash_ids;
+	for (; info->name != NULL; info++) {
+		if (!strcmp(name, info->name))
+			return info;
+	}
+	return NULL;
+}
+
 static const struct spi_flash_info *spi_flash_read_id(struct spi_flash *flash)
 {
 	int				tmp;
@@ -937,13 +954,17 @@ int spi_flash_decode_fdt(struct spi_flash *flash)
 }
 #endif /* CONFIG_IS_ENABLED(OF_CONTROL) */
 
-int spi_flash_scan(struct spi_flash *flash)
+int spi_flash_scan(struct spi_flash *flash, const char *name)
 {
 	struct spi_slave *spi = flash->spi;
 	const struct spi_flash_info *info = NULL;
 	int ret;
 
-	info = spi_flash_read_id(flash);
+	if (name)
+		info = spi_flash_match_id(flash, name);
+	/* Try to auto-detect if chip name wasn't specified or not found */
+	if (!info)
+		info = spi_flash_read_id(flash);
 	if (IS_ERR_OR_NULL(info))
 		return -ENOENT;
 
@@ -1022,7 +1043,7 @@ int spi_flash_scan(struct spi_flash *flash)
 
 	/* Look for read commands */
 	flash->read_cmd = CMD_READ_ARRAY_FAST;
-	if (spi->mode & SPI_RX_SLOW)
+	if (spi->mode & SPI_RX_SLOW || info->flags & NO_FR)
 		flash->read_cmd = CMD_READ_ARRAY_SLOW;
 	else if (spi->mode & SPI_RX_QUAD && info->flags & RD_QUAD)
 		flash->read_cmd = CMD_READ_QUAD_OUTPUT_FAST;
diff --git a/drivers/mtd/spi/spi_flash_ids.c b/drivers/mtd/spi/spi_flash_ids.c
index edca94e..d17b90a 100644
--- a/drivers/mtd/spi/spi_flash_ids.c
+++ b/drivers/mtd/spi/spi_flash_ids.c
@@ -43,6 +43,12 @@
 		.page_size = 256,					\
 		.flags = (_flags),
 
+#define CAT25_INFO(_sector_size, _n_sectors, _flags)			\
+		.sector_size = (_sector_size),				\
+		.n_sectors = (_n_sectors),				\
+		.page_size = 256,					\
+		.flags = (_flags),
+
 const struct spi_flash_info spi_flash_ids[] = {
 #ifdef CONFIG_SPI_FLASH_ATMEL		/* ATMEL */
 	{"at45db011d",	   INFO(0x1f2200, 0x0, 64 * 1024,     4, SECT_4K) },
@@ -167,6 +173,11 @@ const struct spi_flash_info spi_flash_ids[] = {
 	{"w25q64dw",	   INFO(0xef6017, 0x0,	64 * 1024,   128, RD_FULL | WR_QPP | SECT_4K) },
 	{"w25q128fw",	   INFO(0xef6018, 0x0,	64 * 1024,   256, RD_FULL | WR_QPP | SECT_4K) },
 #endif
+#ifdef CONFIG_SPI_FLASH_EVERSPIN       /* Everspin */
+	{ "mr25h256", CAT25_INFO( 32 * 1024, 1, NO_FR) },
+	{ "mr25h10",  CAT25_INFO(128 * 1024, 1, NO_FR) },
+	{ "mr25h40",  CAT25_INFO(512 * 1024, 1, NO_FR) },
+#endif
 	{},	/* Empty entry to terminate the list */
 	/*
 	 * Note:
diff --git a/drivers/net/fm/fm.c b/drivers/net/fm/fm.c
index 89f0d6a..bc41810 100644
--- a/drivers/net/fm/fm.c
+++ b/drivers/net/fm/fm.c
@@ -373,12 +373,12 @@ int fm_init_common(int index, struct ccsr_fman *reg)
 
 	/* speed and mode will be read from DT */
 	ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
-				     0, 0, &new);
+				     0, 0, &new, CONFIG_ENV_SPI_NAME);
 
 	ucode_flash = dev_get_uclass_priv(new);
 #else
 	ucode_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
-			CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
+			CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE, CONFIG_ENV_SPI_NAME);
 #endif
 	if (!ucode_flash)
 		printf("SF: probe for ucode failed\n");
diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
index e06a603..c06292e 100644
--- a/drivers/spi/spi-uclass.c
+++ b/drivers/spi/spi-uclass.c
@@ -268,7 +268,8 @@ int spi_find_bus_and_cs(int busnum, int cs, struct udevice **busp,
 
 int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode,
 		       const char *drv_name, const char *dev_name,
-		       struct udevice **busp, struct spi_slave **devp)
+		       struct udevice **busp, struct spi_slave **devp,
+		       const char *flash_name)
 {
 	struct udevice *bus, *dev;
 	struct dm_spi_slave_platdata *plat;
@@ -300,10 +301,6 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode,
 			      ret);
 			return ret;
 		}
-		plat = dev_get_parent_platdata(dev);
-		plat->cs = cs;
-		plat->max_hz = speed;
-		plat->mode = mode;
 		created = true;
 	} else if (ret) {
 		printf("Invalid chip select %d:%d (err=%d)\n", busnum, cs,
@@ -314,6 +311,12 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode,
 	if (!device_active(dev)) {
 		struct spi_slave *slave;
 
+		plat = dev_get_parent_platdata(dev);
+		plat->cs = cs;
+		plat->max_hz = speed;
+		plat->mode = mode;
+		plat->name = flash_name;
+
 		ret = device_probe(dev);
 		if (ret)
 			goto err;
@@ -372,7 +375,7 @@ struct spi_slave *spi_setup_slave(unsigned int busnum, unsigned int cs,
 	int ret;
 
 	ret = spi_get_bus_and_cs(busnum, cs, speed, mode, NULL, 0, &dev,
-				 &slave);
+				 &slave, NULL);
 	if (ret)
 		return NULL;
 
diff --git a/include/spi.h b/include/spi.h
index 8c4b882..0f4b684 100644
--- a/include/spi.h
+++ b/include/spi.h
@@ -54,11 +54,13 @@ struct dm_spi_bus {
  * @cs:		Chip select number (0..n-1)
  * @max_hz:	Maximum bus speed that this slave can tolerate
  * @mode:	SPI mode to use for this device (see SPI mode flags)
+ * @name:	Name of the flash device(to probe non-jedec flash devices)
  */
 struct dm_spi_slave_platdata {
 	unsigned int cs;
 	uint max_hz;
 	uint mode;
+	char *name;
 };
 
 #endif /* CONFIG_DM_SPI */
@@ -530,11 +532,13 @@ int spi_find_bus_and_cs(int busnum, int cs, struct udevice **busp,
  * @dev_name:	Name of the new device thus created
  * @busp:	Returns bus device
  * @devp:	Return slave device
+ * @name:      Flash name for non-jedec devices
  * @return 0 if found, -ve on error
  */
 int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode,
 			const char *drv_name, const char *dev_name,
-			struct udevice **busp, struct spi_slave **devp);
+			struct udevice **busp, struct spi_slave **devp,
+			const char *flash_name);
 
 /**
  * spi_chip_select() - Get the chip select for a slave
diff --git a/include/spi_flash.h b/include/spi_flash.h
index be2fe3f..5bd0a8d 100644
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -25,7 +25,9 @@
 #ifndef CONFIG_SF_DEFAULT_BUS
 # define CONFIG_SF_DEFAULT_BUS		0
 #endif
-
+#ifndef CONFIG_SF_DEFAULT_NAME
+# define CONFIG_SF_DEFAULT_NAME 	NULL
+#endif
 struct spi_slave;
 
 /**
@@ -156,11 +158,12 @@ 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);
+			   struct udevice **devp, const char *flash_name);
 
 /* 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);
+				  unsigned int max_hz, unsigned int spi_mode,
+				  const char *flash_name);
 
 /* Compatibility function - this is the old U-Boot API */
 void spi_flash_free(struct spi_flash *flash);
@@ -192,7 +195,7 @@ void sandbox_sf_unbind_emul(struct sandbox_state *state, int busnum, int cs);
 
 #else
 struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
-		unsigned int max_hz, unsigned int spi_mode);
+		unsigned int max_hz, unsigned int spi_mode, const char *flash_name);
 
 /**
  * Set up a new SPI flash from an fdt node
-- 
1.9.1



More information about the U-Boot mailing list