diff options
Diffstat (limited to 'drivers/mtd')
| -rw-r--r-- | drivers/mtd/nand/Makefile | 3 | ||||
| -rw-r--r-- | drivers/mtd/nand/nand_util.c | 2 | ||||
| -rw-r--r-- | drivers/mtd/nand/omap_gpmc.c | 109 | ||||
| -rw-r--r-- | drivers/mtd/onenand/onenand_base.c | 8 | ||||
| -rw-r--r-- | drivers/mtd/spi/Makefile | 4 | ||||
| -rw-r--r-- | drivers/mtd/spi/sf.c | 4 | ||||
| -rw-r--r-- | drivers/mtd/spi/sf_internal.h | 34 | ||||
| -rw-r--r-- | drivers/mtd/spi/sf_ops.c | 163 | ||||
| -rw-r--r-- | drivers/mtd/spi/sf_params.c | 130 | ||||
| -rw-r--r-- | drivers/mtd/spi/sf_probe.c | 273 | ||||
| -rw-r--r-- | drivers/mtd/ubi/Makefile | 3 | 
11 files changed, 499 insertions, 234 deletions
| diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile index e145cd184..02b149cac 100644 --- a/drivers/mtd/nand/Makefile +++ b/drivers/mtd/nand/Makefile @@ -5,8 +5,6 @@  # SPDX-License-Identifier:	GPL-2.0+  # -ifdef CONFIG_CMD_NAND -  ifdef CONFIG_SPL_BUILD  ifdef CONFIG_SPL_NAND_DRIVERS @@ -69,4 +67,3 @@ obj-$(CONFIG_NAND_FSL_IFC) += fsl_ifc_spl.o  obj-$(CONFIG_NAND_MXC) += mxc_nand_spl.o  endif # drivers -endif # nand diff --git a/drivers/mtd/nand/nand_util.c b/drivers/mtd/nand/nand_util.c index eeaa7e8a4..b29282603 100644 --- a/drivers/mtd/nand/nand_util.c +++ b/drivers/mtd/nand/nand_util.c @@ -315,7 +315,7 @@ int nand_unlock(struct mtd_info *mtd, loff_t start, size_t length,  	int page;  	struct nand_chip *chip = mtd->priv; -	debug("nand_unlock%s: start: %08llx, length: %d!\n", +	debug("nand_unlock%s: start: %08llx, length: %zd!\n",  		allexcept ? " (allexcept)" : "", start, length);  	/* select the NAND device */ diff --git a/drivers/mtd/nand/omap_gpmc.c b/drivers/mtd/nand/omap_gpmc.c index 5e7e6b337..389c4de59 100644 --- a/drivers/mtd/nand/omap_gpmc.c +++ b/drivers/mtd/nand/omap_gpmc.c @@ -283,53 +283,55 @@ static void omap_hwecc_init_bch(struct nand_chip *chip, int32_t mode)  	if (bch->ecc_scheme == OMAP_ECC_BCH8_CODE_HW) {  		wr_mode = BCH_WRAPMODE_1; -	switch (bch->nibbles) { -	case ECC_BCH4_NIBBLES: -		unused_length = 3; -		break; -	case ECC_BCH8_NIBBLES: -		unused_length = 2; -		break; -	case ECC_BCH16_NIBBLES: -		unused_length = 0; -		break; -	} - -	/* -	 * This is ecc_size_config for ELM mode. -	 * Here we are using different settings for read and write access and -	 * also depending on BCH strength. -	 */ -	switch (mode) { -	case NAND_ECC_WRITE: -		/* write access only setup eccsize1 config */ -		val = ((unused_length + bch->nibbles) << 22); -		break; +		switch (bch->nibbles) { +		case ECC_BCH4_NIBBLES: +			unused_length = 3; +			break; +		case ECC_BCH8_NIBBLES: +			unused_length = 2; +			break; +		case ECC_BCH16_NIBBLES: +			unused_length = 0; +			break; +		} -	case NAND_ECC_READ: -	default:  		/* -		 * by default eccsize0 selected for ecc1resultsize -		 * eccsize0 config. +		 * This is ecc_size_config for ELM mode.  Here we are using +		 * different settings for read and write access and also +		 * depending on BCH strength.  		 */ -		val  = (bch->nibbles << 12); -		/* eccsize1 config */ -		val |= (unused_length << 22); -		break; -	} +		switch (mode) { +		case NAND_ECC_WRITE: +			/* write access only setup eccsize1 config */ +			val = ((unused_length + bch->nibbles) << 22); +			break; + +		case NAND_ECC_READ: +		default: +			/* +			 * by default eccsize0 selected for ecc1resultsize +			 * eccsize0 config. +			 */ +			val  = (bch->nibbles << 12); +			/* eccsize1 config */ +			val |= (unused_length << 22); +			break; +		}  	} else { -	/* -	 * This ecc_size_config setting is for BCH sw library. -	 * -	 * Note: we only support BCH8 currently with BCH sw library! -	 * Should be really easy to adobt to BCH4, however some omap3 have -	 * flaws with BCH4. -	 * -	 * Here we are using wrapping mode 6 both for reading and writing, with: -	 *  size0 = 0  (no additional protected byte in spare area) -	 *  size1 = 32 (skip 32 nibbles = 16 bytes per sector in spare area) -	 */ -	val = (32 << 22) | (0 << 12); +		/* +		 * This ecc_size_config setting is for BCH sw library. +		 * +		 * Note: we only support BCH8 currently with BCH sw library! +		 * Should be really easy to adobt to BCH4, however some omap3 +		 * have flaws with BCH4. +		 * +		 * Here we are using wrapping mode 6 both for reading and +		 * writing, with: +		 *  size0 = 0  (no additional protected byte in spare area) +		 *  size1 = 32 (skip 32 nibbles = 16 bytes per sector in +		 *		spare area) +		 */ +		val = (32 << 22) | (0 << 12);  	}  	/* ecc size configuration */  	writel(val, &gpmc_cfg->ecc_size_config); @@ -761,7 +763,7 @@ static void __maybe_unused omap_free_bch(struct mtd_info *mtd)  static int omap_select_ecc_scheme(struct nand_chip *nand,  	enum omap_ecc ecc_scheme, unsigned int pagesize, unsigned int oobsize) {  	struct nand_bch_priv	*bch		= nand->priv; -	struct nand_ecclayout	*ecclayout	= nand->ecc.layout; +	struct nand_ecclayout	*ecclayout	= &omap_ecclayout;  	int eccsteps = pagesize / SECTOR_BYTES;  	int i; @@ -774,7 +776,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,  		bch_priv.type		= 0;  		nand->ecc.mode		= NAND_ECC_SOFT;  		nand->ecc.layout	= NULL; -		nand->ecc.size		= pagesize; +		nand->ecc.size		= 0;  		bch->ecc_scheme		= OMAP_ECC_HAM1_CODE_SW;  		break; @@ -789,6 +791,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,  		bch_priv.control	= NULL;  		bch_priv.type		= 0;  		/* populate ecc specific fields */ +		memset(&nand->ecc, 0, sizeof(struct nand_ecc_ctrl));  		nand->ecc.mode		= NAND_ECC_HW;  		nand->ecc.strength	= 1;  		nand->ecc.size		= SECTOR_BYTES; @@ -798,8 +801,12 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,  		nand->ecc.calculate	= omap_calculate_ecc;  		/* define ecc-layout */  		ecclayout->eccbytes	= nand->ecc.bytes * eccsteps; -		for (i = 0; i < ecclayout->eccbytes; i++) -			ecclayout->eccpos[i] = i + BADBLOCK_MARKER_LENGTH; +		for (i = 0; i < ecclayout->eccbytes; i++) { +			if (nand->options & NAND_BUSWIDTH_16) +				ecclayout->eccpos[i] = i + 2; +			else +				ecclayout->eccpos[i] = i + 1; +		}  		ecclayout->oobfree[0].offset = i + BADBLOCK_MARKER_LENGTH;  		ecclayout->oobfree[0].length = oobsize - ecclayout->eccbytes -  						BADBLOCK_MARKER_LENGTH; @@ -823,6 +830,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,  		}  		bch_priv.type = ECC_BCH8;  		/* populate ecc specific fields */ +		memset(&nand->ecc, 0, sizeof(struct nand_ecc_ctrl));  		nand->ecc.mode		= NAND_ECC_HW;  		nand->ecc.strength	= 8;  		nand->ecc.size		= SECTOR_BYTES; @@ -865,6 +873,7 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,  		elm_init();  		bch_priv.type		= ECC_BCH8;  		/* populate ecc specific fields */ +		memset(&nand->ecc, 0, sizeof(struct nand_ecc_ctrl));  		nand->ecc.mode		= NAND_ECC_HW;  		nand->ecc.strength	= 8;  		nand->ecc.size		= SECTOR_BYTES; @@ -891,6 +900,11 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,  		debug("nand: error: ecc scheme not enabled or supported\n");  		return -EINVAL;  	} + +	/* nand_scan_tail() sets ham1 sw ecc; hw ecc layout is set by driver */ +	if (ecc_scheme != OMAP_ECC_HAM1_CODE_SW) +		nand->ecc.layout = ecclayout; +  	return 0;  } @@ -919,6 +933,7 @@ int __maybe_unused omap_nand_switch_ecc(uint32_t hardware, uint32_t eccstrength)  	mtd = &nand_info[nand_curr_device];  	nand = mtd->priv;  	nand->options |= NAND_OWN_BUFFERS; +	nand->options &= ~NAND_SUBPAGE_READ;  	/* Setup the ecc configurations again */  	if (hardware) {  		if (eccstrength == 1) { diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c index 979e4af7c..e33e8d38e 100644 --- a/drivers/mtd/onenand/onenand_base.c +++ b/drivers/mtd/onenand/onenand_base.c @@ -91,7 +91,13 @@ static struct nand_ecclayout onenand_oob_32 = {  	.oobfree	= { {2, 3}, {14, 2}, {18, 3}, {30, 2} }  }; -static const unsigned char ffchars[] = { +/* + * Warning! This array is used with the memcpy_16() function, thus + * it must be aligned to 2 bytes. GCC can make this array unaligned + * as the array is made of unsigned char, which memcpy16() doesn't + * like and will cause unaligned access. + */ +static const unsigned char __aligned(2) ffchars[] = {  	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,  	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 16 */  	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, diff --git a/drivers/mtd/spi/Makefile b/drivers/mtd/spi/Makefile index 26483a23f..9e18fb41d 100644 --- a/drivers/mtd/spi/Makefile +++ b/drivers/mtd/spi/Makefile @@ -10,8 +10,8 @@ obj-$(CONFIG_SPL_SPI_LOAD)	+= spi_spl_load.o  obj-$(CONFIG_SPL_SPI_BOOT)	+= fsl_espi_spl.o  endif -obj-$(CONFIG_CMD_SF)        += sf.o -obj-$(CONFIG_SPI_FLASH) += sf_probe.o sf_ops.o +obj-$(CONFIG_CMD_SF) += sf.o +obj-$(CONFIG_SPI_FLASH) += sf_params.o sf_probe.o sf_ops.o  obj-$(CONFIG_SPI_FRAM_RAMTRON) += ramtron.o  obj-$(CONFIG_SPI_FLASH_SANDBOX) += sandbox.o  obj-$(CONFIG_SPI_M95XXX) += eeprom_m95xxx.o diff --git a/drivers/mtd/spi/sf.c b/drivers/mtd/spi/sf.c index d5e175ca0..664e86082 100644 --- a/drivers/mtd/spi/sf.c +++ b/drivers/mtd/spi/sf.c @@ -18,6 +18,10 @@ static int spi_flash_read_write(struct spi_slave *spi,  	unsigned long flags = SPI_XFER_BEGIN;  	int ret; +#ifdef CONFIG_SF_DUAL_FLASH +	if (spi->flags & SPI_XFER_U_PAGE) +		flags |= SPI_XFER_U_PAGE; +#endif  	if (data_len == 0)  		flags |= SPI_XFER_END; diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h index d291746ed..6bcd52204 100644 --- a/drivers/mtd/spi/sf_internal.h +++ b/drivers/mtd/spi/sf_internal.h @@ -10,12 +10,15 @@  #ifndef _SF_INTERNAL_H_  #define _SF_INTERNAL_H_ +#define SPI_FLASH_3B_ADDR_LEN		3 +#define SPI_FLASH_CMD_LEN		(1 + SPI_FLASH_3B_ADDR_LEN)  #define SPI_FLASH_16MB_BOUN		0x1000000 -/* SECT flags */ -#define SECT_4K				(1 << 1) -#define SECT_32K			(1 << 2) -#define E_FSR				(1 << 3) +/* CFI Manufacture ID's */ +#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_WINBOND	0xef  /* Erase commands */  #define CMD_ERASE_4K			0x20 @@ -28,6 +31,7 @@  #define CMD_PAGE_PROGRAM		0x02  #define CMD_WRITE_DISABLE		0x04  #define CMD_READ_STATUS			0x05 +#define CMD_QUAD_PAGE_PROGRAM		0x32  #define CMD_READ_STATUS1		0x35  #define CMD_WRITE_ENABLE		0x06  #define CMD_READ_CONFIG			0x35 @@ -36,6 +40,10 @@  /* Read commands */  #define CMD_READ_ARRAY_SLOW		0x03  #define CMD_READ_ARRAY_FAST		0x0b +#define CMD_READ_DUAL_OUTPUT_FAST	0x3b +#define CMD_READ_DUAL_IO_FAST		0xbb +#define CMD_READ_QUAD_OUTPUT_FAST	0x6b +#define CMD_READ_QUAD_IO_FAST		0xeb  #define CMD_READ_ID			0x9f  /* Bank addr access commands */ @@ -47,8 +55,10 @@  #endif  /* Common status */ -#define STATUS_WIP			0x01 -#define STATUS_PEC			0x80 +#define STATUS_WIP			(1 << 0) +#define STATUS_QEB_WINSPAN		(1 << 1) +#define STATUS_QEB_MXIC			(1 << 6) +#define STATUS_PEC			(1 << 7)  /* Flash timeout values */  #define SPI_FLASH_PROG_TIMEOUT		(2 * CONFIG_SYS_HZ) @@ -86,11 +96,17 @@ 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 sr); +int spi_flash_cmd_write_status(struct spi_flash *flash, u8 ws); + +/* Read the config register */ +int spi_flash_cmd_read_config(struct spi_flash *flash, u8 *rc); -/* Set quad enbale bit */ -int spi_flash_set_qeb(struct spi_flash *flash); +/* 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) diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c index 108665f44..1f1bb3606 100644 --- a/drivers/mtd/spi/sf_ops.c +++ b/drivers/mtd/spi/sf_ops.c @@ -9,6 +9,7 @@   */  #include <common.h> +#include <malloc.h>  #include <spi.h>  #include <spi_flash.h>  #include <watchdog.h> @@ -23,13 +24,28 @@ static void spi_flash_addr(u32 addr, u8 *cmd)  	cmd[3] = addr >> 0;  } -int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr) +int spi_flash_cmd_read_status(struct spi_flash *flash, u8 *rs) +{ +	int ret; +	u8 cmd; + +	cmd = CMD_READ_STATUS; +	ret = spi_flash_read_common(flash, &cmd, 1, rs, 1); +	if (ret < 0) { +		debug("SF: fail to read status register\n"); +		return ret; +	} + +	return 0; +} + +int spi_flash_cmd_write_status(struct spi_flash *flash, u8 ws)  {  	u8 cmd;  	int ret;  	cmd = CMD_WRITE_STATUS; -	ret = spi_flash_write_common(flash, &cmd, 1, &sr, 1); +	ret = spi_flash_write_common(flash, &cmd, 1, &ws, 1);  	if (ret < 0) {  		debug("SF: fail to write status register\n");  		return ret; @@ -38,6 +54,44 @@ int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr)  	return 0;  } +#if defined(CONFIG_SPI_FLASH_SPANSION) || defined(CONFIG_SPI_FLASH_WINBOND) +int spi_flash_cmd_read_config(struct spi_flash *flash, u8 *rc) +{ +	int ret; +	u8 cmd; + +	cmd = CMD_READ_CONFIG; +	ret = spi_flash_read_common(flash, &cmd, 1, rc, 1); +	if (ret < 0) { +		debug("SF: fail to read config register\n"); +		return ret; +	} + +	return 0; +} + +int spi_flash_cmd_write_config(struct spi_flash *flash, u8 wc) +{ +	u8 data[2]; +	u8 cmd; +	int ret; + +	ret = spi_flash_cmd_read_status(flash, &data[0]); +	if (ret < 0) +		return ret; + +	cmd = CMD_WRITE_STATUS; +	data[1] = wc; +	ret = spi_flash_write_common(flash, &cmd, 1, &data, 2); +	if (ret) { +		debug("SF: fail to write config register\n"); +		return ret; +	} + +	return 0; +} +#endif +  #ifdef CONFIG_SPI_FLASH_BAR  static int spi_flash_cmd_bankaddr_write(struct spi_flash *flash, u8 bank_sel)  { @@ -65,7 +119,7 @@ static int spi_flash_bank(struct spi_flash *flash, u32 offset)  	u8 bank_sel;  	int ret; -	bank_sel = offset / SPI_FLASH_16MB_BOUN; +	bank_sel = offset / (SPI_FLASH_16MB_BOUN << flash->shift);  	ret = spi_flash_cmd_bankaddr_write(flash, bank_sel);  	if (ret) { @@ -73,7 +127,29 @@ static int spi_flash_bank(struct spi_flash *flash, u32 offset)  		return ret;  	} -	return 0; +	return bank_sel; +} +#endif + +#ifdef CONFIG_SF_DUAL_FLASH +static void spi_flash_dual_flash(struct spi_flash *flash, u32 *addr) +{ +	switch (flash->dual_flash) { +	case SF_DUAL_STACKED_FLASH: +		if (*addr >= (flash->size >> 1)) { +			*addr -= flash->size >> 1; +			flash->spi->flags |= SPI_XFER_U_PAGE; +		} else { +			flash->spi->flags &= ~SPI_XFER_U_PAGE; +		} +		break; +	case SF_DUAL_PARALLEL_FLASH: +		*addr >>= flash->shift; +		break; +	default: +		debug("SF: Unsupported dual_flash=%d\n", flash->dual_flash); +		break; +	}  }  #endif @@ -81,6 +157,7 @@ int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)  {  	struct spi_slave *spi = flash->spi;  	unsigned long timebase; +	unsigned long flags = SPI_XFER_BEGIN;  	int ret;  	u8 status;  	u8 check_status = 0x0; @@ -92,7 +169,11 @@ int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)  		check_status = poll_bit;  	} -	ret = spi_xfer(spi, 8, &cmd, NULL, SPI_XFER_BEGIN); +#ifdef CONFIG_SF_DUAL_FLASH +	if (spi->flags & SPI_XFER_U_PAGE) +		flags |= SPI_XFER_U_PAGE; +#endif +	ret = spi_xfer(spi, 8, &cmd, NULL, flags);  	if (ret) {  		debug("SF: fail to read %s status register\n",  		      cmd == CMD_READ_STATUS ? "read" : "flag"); @@ -165,8 +246,8 @@ int spi_flash_write_common(struct spi_flash *flash, const u8 *cmd,  int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len)  { -	u32 erase_size; -	u8 cmd[4]; +	u32 erase_size, erase_addr; +	u8 cmd[SPI_FLASH_CMD_LEN];  	int ret = -1;  	erase_size = flash->erase_size; @@ -177,15 +258,21 @@ int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len)  	cmd[0] = flash->erase_cmd;  	while (len) { +		erase_addr = offset; + +#ifdef CONFIG_SF_DUAL_FLASH +		if (flash->dual_flash > SF_SINGLE_FLASH) +			spi_flash_dual_flash(flash, &erase_addr); +#endif  #ifdef CONFIG_SPI_FLASH_BAR -		ret = spi_flash_bank(flash, offset); +		ret = spi_flash_bank(flash, erase_addr);  		if (ret < 0)  			return ret;  #endif -		spi_flash_addr(offset, cmd); +		spi_flash_addr(erase_addr, cmd);  		debug("SF: erase %2x %2x %2x %2x (%x)\n", cmd[0], cmd[1], -		      cmd[2], cmd[3], offset); +		      cmd[2], cmd[3], erase_addr);  		ret = spi_flash_write_common(flash, cmd, sizeof(cmd), NULL, 0);  		if (ret < 0) { @@ -204,16 +291,23 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,  		size_t len, const void *buf)  {  	unsigned long byte_addr, page_size; +	u32 write_addr;  	size_t chunk_len, actual; -	u8 cmd[4]; +	u8 cmd[SPI_FLASH_CMD_LEN];  	int ret = -1;  	page_size = flash->page_size; -	cmd[0] = CMD_PAGE_PROGRAM; +	cmd[0] = flash->write_cmd;  	for (actual = 0; actual < len; actual += chunk_len) { +		write_addr = offset; + +#ifdef CONFIG_SF_DUAL_FLASH +		if (flash->dual_flash > SF_SINGLE_FLASH) +			spi_flash_dual_flash(flash, &write_addr); +#endif  #ifdef CONFIG_SPI_FLASH_BAR -		ret = spi_flash_bank(flash, offset); +		ret = spi_flash_bank(flash, write_addr);  		if (ret < 0)  			return ret;  #endif @@ -223,9 +317,9 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,  		if (flash->spi->max_write_size)  			chunk_len = min(chunk_len, flash->spi->max_write_size); -		spi_flash_addr(offset, cmd); +		spi_flash_addr(write_addr, cmd); -		debug("PP: 0x%p => cmd = { 0x%02x 0x%02x%02x%02x } chunk_len = %zu\n", +		debug("SF: 0x%p => cmd = { 0x%02x 0x%02x%02x%02x } chunk_len = %zu\n",  		      buf + actual, cmd[0], cmd[1], cmd[2], cmd[3], chunk_len);  		ret = spi_flash_write_common(flash, cmd, sizeof(cmd), @@ -267,41 +361,52 @@ int spi_flash_read_common(struct spi_flash *flash, const u8 *cmd,  int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,  		size_t len, void *data)  { -	u8 cmd[5], bank_sel = 0; -	u32 remain_len, read_len; +	u8 *cmd, cmdsz; +	u32 remain_len, read_len, read_addr; +	int bank_sel = 0;  	int ret = -1;  	/* Handle memory-mapped SPI */  	if (flash->memory_map) { +		ret = spi_claim_bus(flash->spi); +		if (ret) { +			debug("SF: unable to claim SPI bus\n"); +			return ret; +		}  		spi_xfer(flash->spi, 0, NULL, NULL, SPI_XFER_MMAP);  		memcpy(data, flash->memory_map + offset, len);  		spi_xfer(flash->spi, 0, NULL, NULL, SPI_XFER_MMAP_END); +		spi_release_bus(flash->spi);  		return 0;  	} -	cmd[0] = CMD_READ_ARRAY_FAST; -	cmd[4] = 0x00; +	cmdsz = SPI_FLASH_CMD_LEN + flash->dummy_byte; +	cmd = malloc(cmdsz); +	memset(cmd, 0, cmdsz); +	cmd[0] = flash->read_cmd;  	while (len) { -#ifdef CONFIG_SPI_FLASH_BAR -		bank_sel = offset / SPI_FLASH_16MB_BOUN; +		read_addr = offset; -		ret = spi_flash_cmd_bankaddr_write(flash, bank_sel); -		if (ret) { -			debug("SF: fail to set bank%d\n", bank_sel); +#ifdef CONFIG_SF_DUAL_FLASH +		if (flash->dual_flash > SF_SINGLE_FLASH) +			spi_flash_dual_flash(flash, &read_addr); +#endif +#ifdef CONFIG_SPI_FLASH_BAR +		bank_sel = spi_flash_bank(flash, read_addr); +		if (bank_sel < 0)  			return ret; -		}  #endif -		remain_len = (SPI_FLASH_16MB_BOUN * (bank_sel + 1)) - offset; +		remain_len = ((SPI_FLASH_16MB_BOUN << flash->shift) * +				(bank_sel + 1)) - offset;  		if (len < remain_len)  			read_len = len;  		else  			read_len = remain_len; -		spi_flash_addr(offset, cmd); +		spi_flash_addr(read_addr, cmd); -		ret = spi_flash_read_common(flash, cmd, sizeof(cmd), -							data, read_len); +		ret = spi_flash_read_common(flash, cmd, cmdsz, data, read_len);  		if (ret < 0) {  			debug("SF: read failed\n");  			break; diff --git a/drivers/mtd/spi/sf_params.c b/drivers/mtd/spi/sf_params.c new file mode 100644 index 000000000..daf8fe767 --- /dev/null +++ b/drivers/mtd/spi/sf_params.c @@ -0,0 +1,130 @@ +/* + * SPI flash Params table + * + * Copyright (C) 2013 Jagannadha Sutradharudu Teki, Xilinx Inc. + * + * SPDX-License-Identifier:	GPL-2.0+ + */ + +#include <common.h> +#include <spi_flash.h> + +#include "sf_internal.h" + +/* SPI/QSPI flash device params structure */ +const struct spi_flash_params spi_flash_params_table[] = { +#ifdef CONFIG_SPI_FLASH_ATMEL		/* ATMEL */ +	{"AT45DB011D",	   0x1f2200, 0x0,	64 * 1024,     4,	0,		    SECT_4K}, +	{"AT45DB021D",	   0x1f2300, 0x0,	64 * 1024,     8,	0,		    SECT_4K}, +	{"AT45DB041D",	   0x1f2400, 0x0,	64 * 1024,     8,	0,		    SECT_4K}, +	{"AT45DB081D",	   0x1f2500, 0x0,	64 * 1024,    16,	0,		    SECT_4K}, +	{"AT45DB161D",	   0x1f2600, 0x0,	64 * 1024,    32,	0,		    SECT_4K}, +	{"AT45DB321D",	   0x1f2700, 0x0,	64 * 1024,    64,	0,		    SECT_4K}, +	{"AT45DB641D",	   0x1f2800, 0x0,	64 * 1024,   128,	0,		    SECT_4K}, +	{"AT25DF321",      0x1f4701, 0x0,	64 * 1024,    64,	0,		    SECT_4K}, +#endif +#ifdef CONFIG_SPI_FLASH_EON		/* EON */ +	{"EN25Q32B",	   0x1c3016, 0x0,	64 * 1024,    64,	0,			  0}, +	{"EN25Q64",	   0x1c3017, 0x0,	64 * 1024,   128,	0,		    SECT_4K}, +	{"EN25Q128B",	   0x1c3018, 0x0,       64 * 1024,   256,	0,			  0}, +	{"EN25S64",	   0x1c3817, 0x0,	64 * 1024,   128,	0,			  0}, +#endif +#ifdef CONFIG_SPI_FLASH_GIGADEVICE	/* GIGADEVICE */ +	{"GD25Q64B",	   0xc84017, 0x0,	64 * 1024,   128,	0,		    SECT_4K}, +	{"GD25LQ32",	   0xc86016, 0x0,	64 * 1024,    64,	0,		    SECT_4K}, +#endif +#ifdef CONFIG_SPI_FLASH_MACRONIX	/* MACRONIX */ +	{"MX25L2006E",	   0xc22012, 0x0,	64 * 1024,     4,	0,			  0}, +	{"MX25L4005",	   0xc22013, 0x0,	64 * 1024,     8,	0,			  0}, +	{"MX25L8005",	   0xc22014, 0x0,	64 * 1024,    16,	0,			  0}, +	{"MX25L1605D",	   0xc22015, 0x0,	64 * 1024,    32,	0,			  0}, +	{"MX25L3205D",	   0xc22016, 0x0,	64 * 1024,    64,	0,			  0}, +	{"MX25L6405D",	   0xc22017, 0x0,	64 * 1024,   128,	0,			  0}, +	{"MX25L12805",	   0xc22018, 0x0,	64 * 1024,   256, RD_FULL,		     WR_QPP}, +	{"MX25L25635F",	   0xc22019, 0x0,	64 * 1024,   512, RD_FULL,		     WR_QPP}, +	{"MX25L51235F",	   0xc2201a, 0x0,	64 * 1024,  1024, RD_FULL,		     WR_QPP}, +	{"MX25L12855E",	   0xc22618, 0x0,	64 * 1024,   256, RD_FULL,		     WR_QPP}, +#endif +#ifdef CONFIG_SPI_FLASH_SPANSION	/* SPANSION */ +	{"S25FL008A",	   0x010213, 0x0,	64 * 1024,    16,	0,			  0}, +	{"S25FL016A",	   0x010214, 0x0,	64 * 1024,    32,	0,			  0}, +	{"S25FL032A",	   0x010215, 0x0,	64 * 1024,    64,	0,			  0}, +	{"S25FL064A",	   0x010216, 0x0,	64 * 1024,   128,	0,			  0}, +	{"S25FL128P_256K", 0x012018, 0x0300,   256 * 1024,    64, RD_FULL,		     WR_QPP}, +	{"S25FL128P_64K",  0x012018, 0x0301,    64 * 1024,   256, RD_FULL,		     WR_QPP}, +	{"S25FL032P",	   0x010215, 0x4d00,    64 * 1024,    64, RD_FULL,		     WR_QPP}, +	{"S25FL064P",	   0x010216, 0x4d00,    64 * 1024,   128, RD_FULL,		     WR_QPP}, +	{"S25FL128S_64K",  0x012018, 0x4d01,    64 * 1024,   256, RD_FULL,		     WR_QPP}, +	{"S25FL256S_256K", 0x010219, 0x4d00,    64 * 1024,   512, RD_FULL,		     WR_QPP}, +	{"S25FL256S_64K",  0x010219, 0x4d01,	64 * 1024,   512, RD_FULL,		     WR_QPP}, +	{"S25FL512S_256K", 0x010220, 0x4d00,    64 * 1024,  1024, RD_FULL,		     WR_QPP}, +	{"S25FL512S_64K",  0x010220, 0x4d01,    64 * 1024,  1024, RD_FULL,		     WR_QPP}, +#endif +#ifdef CONFIG_SPI_FLASH_STMICRO		/* STMICRO */ +	{"M25P10",	   0x202011, 0x0,	32 * 1024,     4,	0,			  0}, +	{"M25P20",	   0x202012, 0x0,       64 * 1024,     4,	0,			  0}, +	{"M25P40",	   0x202013, 0x0,       64 * 1024,     8,	0,			  0}, +	{"M25P80",	   0x202014, 0x0,       64 * 1024,    16,	0,			  0}, +	{"M25P16",	   0x202015, 0x0,       64 * 1024,    32,	0,			  0}, +	{"M25P32",	   0x202016, 0x0,       64 * 1024,    64,	0,			  0}, +	{"M25P64",	   0x202017, 0x0,       64 * 1024,   128,	0,			  0}, +	{"M25P128",	   0x202018, 0x0,      256 * 1024,    64,	0,			  0}, +	{"N25Q32",	   0x20ba16, 0x0,       64 * 1024,    64, RD_FULL,	   WR_QPP | SECT_4K}, +	{"N25Q32A",	   0x20bb16, 0x0,       64 * 1024,    64, RD_FULL,	   WR_QPP | SECT_4K}, +	{"N25Q64",	   0x20ba17, 0x0,       64 * 1024,   128, RD_FULL,	   WR_QPP | SECT_4K}, +	{"N25Q64A",	   0x20bb17, 0x0,       64 * 1024,   128, RD_FULL,	   WR_QPP | SECT_4K}, +	{"N25Q128",	   0x20ba18, 0x0,       64 * 1024,   256, RD_FULL,		     WR_QPP}, +	{"N25Q128A",	   0x20bb18, 0x0,       64 * 1024,   256, RD_FULL,		     WR_QPP}, +	{"N25Q256",	   0x20ba19, 0x0,       64 * 1024,   512, RD_FULL,	   WR_QPP | SECT_4K}, +	{"N25Q256A",	   0x20bb19, 0x0,       64 * 1024,   512, RD_FULL,	   WR_QPP | SECT_4K}, +	{"N25Q512",	   0x20ba20, 0x0,       64 * 1024,  1024, RD_FULL, WR_QPP | E_FSR | SECT_4K}, +	{"N25Q512A",	   0x20bb20, 0x0,       64 * 1024,  1024, RD_FULL, WR_QPP | E_FSR | SECT_4K}, +	{"N25Q1024",	   0x20ba21, 0x0,       64 * 1024,  2048, RD_FULL, WR_QPP | E_FSR | SECT_4K}, +	{"N25Q1024A",	   0x20bb21, 0x0,       64 * 1024,  2048, RD_FULL, WR_QPP | E_FSR | SECT_4K}, +#endif +#ifdef CONFIG_SPI_FLASH_SST		/* SST */ +	{"SST25VF040B",	   0xbf258d, 0x0,	64 * 1024,     8,	0,          SECT_4K | SST_WP}, +	{"SST25VF080B",	   0xbf258e, 0x0,	64 * 1024,    16,	0,	    SECT_4K | SST_WP}, +	{"SST25VF016B",	   0xbf2541, 0x0,	64 * 1024,    32,	0,	    SECT_4K | SST_WP}, +	{"SST25VF032B",	   0xbf254a, 0x0,	64 * 1024,    64,	0,	    SECT_4K | SST_WP}, +	{"SST25VF064C",	   0xbf254b, 0x0,	64 * 1024,   128,	0,		     SECT_4K}, +	{"SST25WF512",	   0xbf2501, 0x0,	64 * 1024,     1,	0,	    SECT_4K | SST_WP}, +	{"SST25WF010",	   0xbf2502, 0x0,	64 * 1024,     2,       0,          SECT_4K | SST_WP}, +	{"SST25WF020",	   0xbf2503, 0x0,	64 * 1024,     4,       0,	    SECT_4K | SST_WP}, +	{"SST25WF040",	   0xbf2504, 0x0,	64 * 1024,     8,       0,	    SECT_4K | SST_WP}, +	{"SST25WF080",	   0xbf2505, 0x0,	64 * 1024,    16,       0,	    SECT_4K | SST_WP}, +#endif +#ifdef CONFIG_SPI_FLASH_WINBOND		/* WINBOND */ +	{"W25P80",	   0xef2014, 0x0,	64 * 1024,    16,	0,		           0}, +	{"W25P16",	   0xef2015, 0x0,	64 * 1024,    32,	0,		           0}, +	{"W25P32",	   0xef2016, 0x0,	64 * 1024,    64,	0,		           0}, +	{"W25X40",	   0xef3013, 0x0,	64 * 1024,     8,	0,		     SECT_4K}, +	{"W25X16",	   0xef3015, 0x0,	64 * 1024,    32,	0,		     SECT_4K}, +	{"W25X32",	   0xef3016, 0x0,	64 * 1024,    64,	0,		     SECT_4K}, +	{"W25X64",	   0xef3017, 0x0,	64 * 1024,   128,	0,		     SECT_4K}, +	{"W25Q80BL",	   0xef4014, 0x0,	64 * 1024,    16, RD_FULL,	    WR_QPP | SECT_4K}, +	{"W25Q16CL",	   0xef4015, 0x0,	64 * 1024,    32, RD_FULL,	    WR_QPP | SECT_4K}, +	{"W25Q32BV",	   0xef4016, 0x0,	64 * 1024,    64, RD_FULL,	    WR_QPP | SECT_4K}, +	{"W25Q64CV",	   0xef4017, 0x0,	64 * 1024,   128, RD_FULL,	    WR_QPP | SECT_4K}, +	{"W25Q128BV",	   0xef4018, 0x0,	64 * 1024,   256, RD_FULL,	    WR_QPP | SECT_4K}, +	{"W25Q256",	   0xef4019, 0x0,	64 * 1024,   512, RD_FULL,	    WR_QPP | SECT_4K}, +	{"W25Q80BW",	   0xef5014, 0x0,	64 * 1024,    16, RD_FULL,	    WR_QPP | SECT_4K}, +	{"W25Q16DW",	   0xef6015, 0x0,	64 * 1024,    32, RD_FULL,	    WR_QPP | SECT_4K}, +	{"W25Q32DW",	   0xef6016, 0x0,	64 * 1024,    64, RD_FULL,	    WR_QPP | SECT_4K}, +	{"W25Q64DW",	   0xef6017, 0x0,	64 * 1024,   128, RD_FULL,	    WR_QPP | SECT_4K}, +	{"W25Q128FW",	   0xef6018, 0x0,	64 * 1024,   256, RD_FULL,	    WR_QPP | SECT_4K}, +#endif +	/* +	 * Note: +	 * Below paired flash devices has similar spi_flash params. +	 * (S25FL129P_64K, S25FL128S_64K) +	 * (W25Q80BL, W25Q80BV) +	 * (W25Q16CL, W25Q16DV) +	 * (W25Q32BV, W25Q32FV_SPI) +	 * (W25Q64CV, W25Q64FV_SPI) +	 * (W25Q128BV, W25Q128FV_SPI) +	 * (W25Q32DW, W25Q32FV_QPI) +	 * (W25Q64DW, W25Q64FV_QPI) +	 * (W25Q128FW, W25Q128FV_QPI) +	 */ +}; diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c index c1eb75489..bc3cf6cc6 100644 --- a/drivers/mtd/spi/sf_probe.c +++ b/drivers/mtd/spi/sf_probe.c @@ -19,153 +19,93 @@  DECLARE_GLOBAL_DATA_PTR; -/** - * struct spi_flash_params - SPI/QSPI flash device params structure - * - * @name:		Device name ([MANUFLETTER][DEVTYPE][DENSITY][EXTRAINFO]) - * @jedec:		Device jedec ID (0x[1byte_manuf_id][2byte_dev_id]) - * @ext_jedec:		Device ext_jedec ID - * @sector_size:	Sector size of this device - * @nr_sectors:		No.of sectors on this device - * @flags:		Importent param, for flash specific behaviour - */ -struct spi_flash_params { -	const char *name; -	u32 jedec; -	u16 ext_jedec; -	u32 sector_size; -	u32 nr_sectors; -	u16 flags; +/* Read commands array */ +static u8 spi_read_cmds_array[] = { +	CMD_READ_ARRAY_SLOW, +	CMD_READ_DUAL_OUTPUT_FAST, +	CMD_READ_DUAL_IO_FAST, +	CMD_READ_QUAD_OUTPUT_FAST, +	CMD_READ_QUAD_IO_FAST,  }; -static const struct spi_flash_params spi_flash_params_table[] = { -#ifdef CONFIG_SPI_FLASH_ATMEL		/* ATMEL */ -	{"AT45DB011D",	   0x1f2200, 0x0,	64 * 1024,     4,	       SECT_4K}, -	{"AT45DB021D",	   0x1f2300, 0x0,	64 * 1024,     8,	       SECT_4K}, -	{"AT45DB041D",	   0x1f2400, 0x0,	64 * 1024,     8,	       SECT_4K}, -	{"AT45DB081D",	   0x1f2500, 0x0,	64 * 1024,    16,	       SECT_4K}, -	{"AT45DB161D",	   0x1f2600, 0x0,	64 * 1024,    32,	       SECT_4K}, -	{"AT45DB321D",	   0x1f2700, 0x0,	64 * 1024,    64,	       SECT_4K}, -	{"AT45DB641D",	   0x1f2800, 0x0,	64 * 1024,   128,	       SECT_4K}, -	{"AT25DF321",      0x1f4701, 0x0,	64 * 1024,    64,	       SECT_4K}, -#endif -#ifdef CONFIG_SPI_FLASH_EON		/* EON */ -	{"EN25Q32B",	   0x1c3016, 0x0,	64 * 1024,    64,	             0}, -	{"EN25Q64",	   0x1c3017, 0x0,	64 * 1024,   128,	       SECT_4K}, -	{"EN25Q128B",	   0x1c3018, 0x0,       64 * 1024,   256,	             0}, -	{"EN25S64",	   0x1c3817, 0x0,	64 * 1024,   128,		     0}, -#endif -#ifdef CONFIG_SPI_FLASH_GIGADEVICE	/* GIGADEVICE */ -	{"GD25Q64B",	   0xc84017, 0x0,	64 * 1024,   128,	       SECT_4K}, -	{"GD25LQ32",	   0xc86016, 0x0,	64 * 1024,    64,	       SECT_4K}, -#endif -#ifdef CONFIG_SPI_FLASH_MACRONIX	/* MACRONIX */ -	{"MX25L4005",	   0xc22013, 0x0,	64 * 1024,     8,	             0}, -	{"MX25L8005",	   0xc22014, 0x0,	64 * 1024,    16,	             0}, -	{"MX25L1605D",	   0xc22015, 0x0,	64 * 1024,    32,	             0}, -	{"MX25L3205D",	   0xc22016, 0x0,	64 * 1024,    64,	             0}, -	{"MX25L6405D",	   0xc22017, 0x0,	64 * 1024,   128,	             0}, -	{"MX25L12805",	   0xc22018, 0x0,	64 * 1024,   256,	             0}, -	{"MX25L25635F",	   0xc22019, 0x0,	64 * 1024,   512,	             0}, -	{"MX25L51235F",	   0xc2201A, 0x0,	64 * 1024,  1024,	             0}, -	{"MX25L12855E",	   0xc22618, 0x0,	64 * 1024,   256,	             0}, +#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 -#ifdef CONFIG_SPI_FLASH_SPANSION	/* SPANSION */ -	{"S25FL008A",	   0x010213, 0x0,	64 * 1024,    16,	             0}, -	{"S25FL016A",	   0x010214, 0x0,	64 * 1024,    32,	             0}, -	{"S25FL032A",	   0x010215, 0x0,	64 * 1024,    64,	             0}, -	{"S25FL064A",	   0x010216, 0x0,	64 * 1024,   128,	             0}, -	{"S25FL128P_256K", 0x012018, 0x0300,   256 * 1024,    64,	             0}, -	{"S25FL128P_64K",  0x012018, 0x0301,    64 * 1024,   256,	             0}, -	{"S25FL032P",	   0x010215, 0x4d00,    64 * 1024,    64,	             0}, -	{"S25FL064P",	   0x010216, 0x4d00,    64 * 1024,   128,	             0}, -	{"S25FL128S_64K",  0x012018, 0x4d01,    64 * 1024,   256,		     0}, -	{"S25FL256S_256K", 0x010219, 0x4d00,    64 * 1024,   512,	             0}, -	{"S25FL256S_64K",  0x010219, 0x4d01,    64 * 1024,   512,	             0}, -	{"S25FL512S_256K", 0x010220, 0x4d00,    64 * 1024,  1024,	             0}, -	{"S25FL512S_64K",  0x010220, 0x4d01,    64 * 1024,  1024,	             0}, + +#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 -#ifdef CONFIG_SPI_FLASH_STMICRO		/* STMICRO */ -	{"M25P10",	   0x202011, 0x0,       32 * 1024,     4,	             0}, -	{"M25P20",	   0x202012, 0x0,       64 * 1024,     4,	             0}, -	{"M25P40",	   0x202013, 0x0,       64 * 1024,     8,	             0}, -	{"M25P80",	   0x202014, 0x0,       64 * 1024,    16,	             0}, -	{"M25P16",	   0x202015, 0x0,       64 * 1024,    32,	             0}, -	{"M25P32",	   0x202016, 0x0,       64 * 1024,    64,	             0}, -	{"M25P64",	   0x202017, 0x0,       64 * 1024,   128,	             0}, -	{"M25P128",	   0x202018, 0x0,      256 * 1024,    64,	             0}, -	{"N25Q32",	   0x20ba16, 0x0,       64 * 1024,    64,	       SECT_4K}, -	{"N25Q32A",	   0x20bb16, 0x0,       64 * 1024,    64,	       SECT_4K}, -	{"N25Q64",	   0x20ba17, 0x0,       64 * 1024,   128,	       SECT_4K}, -	{"N25Q64A",	   0x20bb17, 0x0,       64 * 1024,   128,	       SECT_4K}, -	{"N25Q128",	   0x20ba18, 0x0,       64 * 1024,   256,	       SECT_4K}, -	{"N25Q128A",	   0x20bb18, 0x0,       64 * 1024,   256,	       SECT_4K}, -	{"N25Q256",	   0x20ba19, 0x0,       64 * 1024,   512,	       SECT_4K}, -	{"N25Q256A",	   0x20bb19, 0x0,       64 * 1024,   512,	       SECT_4K}, -	{"N25Q512",	   0x20ba20, 0x0,       64 * 1024,  1024,      E_FSR | SECT_4K}, -	{"N25Q512A",	   0x20bb20, 0x0,       64 * 1024,  1024,      E_FSR | SECT_4K}, -	{"N25Q1024",	   0x20ba21, 0x0,       64 * 1024,  2048,      E_FSR | SECT_4K}, -	{"N25Q1024A",	   0x20bb21, 0x0,       64 * 1024,  2048,      E_FSR | SECT_4K}, + +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 -#ifdef CONFIG_SPI_FLASH_SST		/* SST */ -	{"SST25VF040B",	   0xbf258d, 0x0,	64 * 1024,     8,     SECT_4K | SST_WP}, -	{"SST25VF080B",	   0xbf258e, 0x0,	64 * 1024,    16,     SECT_4K | SST_WP}, -	{"SST25VF016B",	   0xbf2541, 0x0,	64 * 1024,    32,     SECT_4K | SST_WP}, -	{"SST25VF032B",	   0xbf254a, 0x0,	64 * 1024,    64,     SECT_4K | SST_WP}, -	{"SST25VF064C",	   0xbf254b, 0x0,	64 * 1024,   128,	       SECT_4K}, -	{"SST25WF512",	   0xbf2501, 0x0,	64 * 1024,     1,     SECT_4K | SST_WP}, -	{"SST25WF010",	   0xbf2502, 0x0,	64 * 1024,     2,     SECT_4K | SST_WP}, -	{"SST25WF020",	   0xbf2503, 0x0,	64 * 1024,     4,     SECT_4K | SST_WP}, -	{"SST25WF040",	   0xbf2504, 0x0,	64 * 1024,     8,     SECT_4K | SST_WP}, -	{"SST25WF080",	   0xbf2505, 0x0,	64 * 1024,    16,     SECT_4K | SST_WP}, +#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_WINBOND		/* WINBOND */ -	{"W25P80",	   0xef2014, 0x0,	64 * 1024,    16,		    0}, -	{"W25P16",	   0xef2015, 0x0,	64 * 1024,    32,		    0}, -	{"W25P32",	   0xef2016, 0x0,	64 * 1024,    64,		    0}, -	{"W25X40",	   0xef3013, 0x0,	64 * 1024,     8,	      SECT_4K}, -	{"W25X16",	   0xef3015, 0x0,	64 * 1024,    32,	      SECT_4K}, -	{"W25X32",	   0xef3016, 0x0,	64 * 1024,    64,	      SECT_4K}, -	{"W25X64",	   0xef3017, 0x0,	64 * 1024,   128,	      SECT_4K}, -	{"W25Q80BL",	   0xef4014, 0x0,	64 * 1024,    16,	      SECT_4K}, -	{"W25Q16CL",	   0xef4015, 0x0,	64 * 1024,    32,	      SECT_4K}, -	{"W25Q32BV",	   0xef4016, 0x0,	64 * 1024,    64,	      SECT_4K}, -	{"W25Q64CV",	   0xef4017, 0x0,	64 * 1024,   128,	      SECT_4K}, -	{"W25Q128BV",	   0xef4018, 0x0,	64 * 1024,   256,	      SECT_4K}, -	{"W25Q256",	   0xef4019, 0x0,	64 * 1024,   512,	      SECT_4K}, -	{"W25Q80BW",	   0xef5014, 0x0,	64 * 1024,    16,	      SECT_4K}, -	{"W25Q16DW",	   0xef6015, 0x0,	64 * 1024,    32,	      SECT_4K}, -	{"W25Q32DW",	   0xef6016, 0x0,	64 * 1024,    64,	      SECT_4K}, -	{"W25Q64DW",	   0xef6017, 0x0,	64 * 1024,   128,	      SECT_4K}, -	{"W25Q128FW",	   0xef6018, 0x0,	64 * 1024,   256,	      SECT_4K}, +#ifdef CONFIG_SPI_FLASH_STMICRO +	case SPI_FLASH_CFI_MFR_STMICRO: +		debug("SF: QEB is volatile for %02x flash\n", idcode0); +		return 0;  #endif -	/* -	 * Note: -	 * Below paired flash devices has similar spi_flash params. -	 * (S25FL129P_64K, S25FL128S_64K) -	 * (W25Q80BL, W25Q80BV) -	 * (W25Q16CL, W25Q16DV) -	 * (W25Q32BV, W25Q32FV_SPI) -	 * (W25Q64CV, W25Q64FV_SPI) -	 * (W25Q128BV, W25Q128FV_SPI) -	 * (W25Q32DW, W25Q32FV_QPI) -	 * (W25Q64DW, W25Q64FV_QPI) -	 * (W25Q128FW, W25Q128FV_QPI) -	 */ -}; +	default: +		printf("SF: Need set QEB func for %02x flash\n", idcode0); +		return -1; +	} +}  static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,  		u8 *idcode)  {  	const struct spi_flash_params *params;  	struct spi_flash *flash; -	int i; +	u8 cmd;  	u16 jedec = idcode[1] << 8 | idcode[2];  	u16 ext_jedec = idcode[3] << 8 | idcode[4]; -	/* Get the flash id (jedec = manuf_id + dev_id, ext_jedec) */ -	for (i = 0; i < ARRAY_SIZE(spi_flash_params_table); i++) { -		params = &spi_flash_params_table[i]; +	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) @@ -176,7 +116,7 @@ static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,  		}  	} -	if (i == ARRAY_SIZE(spi_flash_params_table)) { +	if (!params->name) {  		printf("SF: Unsupported flash IDs: ");  		printf("manuf %02x, jedec %04x, ext_jedec %04x\n",  		       idcode[0], jedec, ext_jedec); @@ -194,6 +134,7 @@ static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,  	flash->spi = spi;  	flash->name = params->name;  	flash->memory_map = spi->memory_map; +	flash->dual_flash = flash->spi->option;  	/* Assign spi_flash ops */  	flash->write = spi_flash_cmd_write_ops; @@ -205,23 +146,74 @@ static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,  	flash->read = spi_flash_cmd_read_ops;  	/* Compute the flash size */ -	flash->page_size = (ext_jedec == 0x4d00) ? 512 : 256; -	flash->sector_size = params->sector_size; -	flash->size = flash->sector_size * params->nr_sectors; +	flash->shift = (flash->dual_flash & SF_DUAL_PARALLEL_FLASH) ? 1 : 0; +	flash->page_size = ((ext_jedec == 0x4d00) ? 512 : 256) << 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->erase_size = 4096 << flash->shift;  	} else if (params->flags & SECT_32K) {  		flash->erase_cmd = CMD_ERASE_32K; -		flash->erase_size = 32768; +		flash->erase_size = 32768 << flash->shift;  	} else {  		flash->erase_cmd = CMD_ERASE_64K;  		flash->erase_size = flash->sector_size;  	} -	/* Poll cmd seclection */ +	/* 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)) { +		if (spi_flash_set_qeb(flash, idcode[0])) { +			debug("SF: Fail to set QEB for %02x\n", idcode[0]); +			return NULL; +		} +	} + +	/* 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; +	} + +	/* Poll cmd selection */  	flash->poll_cmd = CMD_READ_STATUS;  #ifdef CONFIG_SPI_FLASH_STMICRO  	if (params->flags & E_FSR) @@ -338,7 +330,10 @@ static struct spi_flash *spi_flash_probe_slave(struct spi_slave *spi)  	puts("\n");  #endif  #ifndef CONFIG_SPI_FLASH_BAR -	if (flash->size > SPI_FLASH_16MB_BOUN) { +	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");  	} diff --git a/drivers/mtd/ubi/Makefile b/drivers/mtd/ubi/Makefile index e1f3a241a..56c282347 100644 --- a/drivers/mtd/ubi/Makefile +++ b/drivers/mtd/ubi/Makefile @@ -5,9 +5,6 @@  # SPDX-License-Identifier:	GPL-2.0+  # -ifdef CONFIG_CMD_UBI  obj-y += build.o vtbl.o vmt.o upd.o kapi.o eba.o io.o wl.o scan.o crc32.o -  obj-y += misc.o  obj-y += debug.o -endif |