sf: Add JEDEC_MFR
PATCH v2 10/22 sf: Add JEDEC_MFR
Instead using idcode[0] for detecting manufacture id add JEDEC_MFR macro for code simplicity and undesirability.
--- drivers/mtd/spi/sf_internal.h | 1 + drivers/mtd/spi/spi_flash.c | 30 +++++++++++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-)
drivers/mtd/spi/sf_internal.h +1 -0
@@ -104,6 +104,7 @@ int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,#define CMD_SPANSION_WRAR 0x71/* Write any device register */ #endif +#define JEDEC_MFR (info) ((info)->id[0])#define JEDEC_ID (info) (((info)->id[1]) << 8 | ((info)->id[2]))#define JEDEC_EXT (info) (((info)->id[3]) << 8 | ((info)->id[4]))
drivers/mtd/spi/spi_flash.c +17 -13
@@ -165,7 +165,8 @@ bar_end:return flash->bank_curr; } -static int spi_flash_read_bar (struct spi_flash *flash,u8 idcode0) +static int spi_flash_read_bar (struct spi_flash *flash, +const struct spi_flash_info *info) {u8 curr_bank =0 ;int ret;
@@ -173,7 +174,7 @@ static int spi_flash_read_bar(struct spi_flash *flash, u8 idcode0)if (flash->size <=SPI_FLASH_16MB_BOUN ) goto bar_end; -switch (idcode0) { +switch (JEDEC_MFR (info)) {case SPI_FLASH_CFI_MFR_SPANSION : flash->bank_read_cmd =CMD_BANKADDR_BRRD ; flash->bank_write_cmd =CMD_BANKADDR_BRWR ;
@@ -949,9 +950,10 @@ static const struct spi_flash_info *spi_flash_read_id(struct spi_flash *flash)return ERR_PTR (-ENODEV ); } -static int set_quad_mode (struct spi_flash *flash,u8 idcode0) +static int set_quad_mode (struct spi_flash *flash, +const struct spi_flash_info *info) { -switch (idcode0) { +switch (JEDEC_MFR (info)) {#ifdef CONFIG_SPI_FLASH_MACRONIX case SPI_FLASH_CFI_MFR_MACRONIX :return macronix_quad_enable (flash);
@@ -966,7 +968,8 @@ static int set_quad_mode(struct spi_flash *flash, u8 idcode0)return micron_quad_enable (flash);#endif default : -printf ("SF: Need set QEB func for %02x flash\n" , idcode0); +printf ("SF: Need set QEB func for %02x flash\n" , +JEDEC_MFR (info));return -1 ; } }
@@ -1085,9 +1088,9 @@ int spi_flash_scan(struct spi_flash *flash) }#endif /* Flash powers up read-only, so clear BP# bits */ -if (idcode[0 ] ==SPI_FLASH_CFI_MFR_ATMEL || - idcode[0 ] ==SPI_FLASH_CFI_MFR_MACRONIX || - idcode[0 ] ==SPI_FLASH_CFI_MFR_SST ) +if (JEDEC_MFR (info) ==SPI_FLASH_CFI_MFR_ATMEL || +JEDEC_MFR (info) ==SPI_FLASH_CFI_MFR_MACRONIX || +JEDEC_MFR (info) ==SPI_FLASH_CFI_MFR_SST )write_sr (flash,0 );/* Assign spi data */
@@ -1115,7 +1118,7 @@ int spi_flash_scan(struct spi_flash *flash)#endif /* lock hooks are flash specific - assign them based on idcode0 */ -switch (idcode[0 ]) { +switch (JEDEC_MFR (info)) {#if defined(CONFIG_SPI_FLASH_STMICRO ) || defined(CONFIG_SPI_FLASH_SST )case SPI_FLASH_CFI_MFR_STMICRO :case SPI_FLASH_CFI_MFR_SST :
@@ -1125,7 +1128,7 @@ int spi_flash_scan(struct spi_flash *flash)#endif break ;default : -debug ("SF: Lock ops not supported for %02x flash\n" , idcode[0 ]); +debug ("SF: Lock ops not supported for %02x flash\n" ,JEDEC_MFR (info)); }/* Compute the flash size */
@@ -1185,9 +1188,10 @@ int spi_flash_scan(struct spi_flash *flash)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 =set_quad_mode (flash, idcode[0 ]); + ret =set_quad_mode (flash, info);if (ret) { -debug ("SF: Fail to set QEB for %02x\n" , idcode[0 ]); +debug ("SF: Fail to set QEB for %02x\n" , +JEDEC_MFR (info));return -EINVAL ; } }
@@ -1218,7 +1222,7 @@ int spi_flash_scan(struct spi_flash *flash)/* Configure the BAR - discover bank cmds and read current bank */ #ifdef CONFIG_SPI_FLASH_BAR - ret =spi_flash_read_bar (flash, idcode[0 ]); + ret =spi_flash_read_bar (flash, info);if (ret <0 )return ret;#endif
Signature · 1 line
2.7.4
PATCH v2 11/22 sf: Simplify lock ops detection code
Simplify the flash_lock ops detection code and added meaningful comment.
--- drivers/mtd/spi/spi_flash.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/mtd/spi/spi_flash.c +4 -8
@@ -1117,19 +1117,15 @@ int spi_flash_scan(struct spi_flash *flash) flash->read = spi_flash_cmd_read_ops;#endif -/* lock hooks are flash specific - assign them based on idcode0 */ -switch (JEDEC_MFR (info)) {#if defined(CONFIG_SPI_FLASH_STMICRO ) || defined(CONFIG_SPI_FLASH_SST ) -case SPI_FLASH_CFI_MFR_STMICRO : -case SPI_FLASH_CFI_MFR_SST : +/* NOR protection support for STmicro/Micron chips and similar */ +if (JEDEC_MFR (info) ==SPI_FLASH_CFI_MFR_STMICRO || +JEDEC_MFR (info) ==SPI_FLASH_CFI_MFR_SST ) { 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" ,JEDEC_MFR (info)); } +#endif /* Compute the flash size */ flash->shift = (flash->dual_flash &SF_DUAL_PARALLEL_FLASH ) ?1 :0 ;
Signature · 1 line
2.7.4
PATCH v2 12/22 sf: sandbox: Fix ID exctract from spi_flash_info
In reply to Jagan TekiThis patch fix the id exctract from spi_flash_info ids.
--- drivers/mtd/spi/sandbox.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mtd/spi/sandbox.c +2 -1
@@ -362,7 +362,8 @@ static int sandbox_sf_xfer(struct udevice *dev, unsigned int bitlen,debug (" id: off:%u tx:" , sbsf->off);if (sbsf->off <IDCODE_LEN ) {/* Extract correct byte from ID 0x00aabbcc */ - id = sbsf->data->jedec >> + id = ((JEDEC_MFR (sbsf->data) <<16 ) | +JEDEC_ID (sbsf->data)) >> (8 * (IDCODE_LEN -1 - sbsf->off)); }else { id =0 ;
Signature · 1 line
2.7.4
PATCH v2 13/22 sf: Cleanup spi_flash_info{}
In reply to Jagan Teki- Proper tabs spaces
- Removed unnecessary
- Added meaningful comments?
--- drivers/mtd/spi/sf_internal.h | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-)
drivers/mtd/spi/sf_internal.h +8 -14
@@ -108,17 +108,8 @@ int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,#define JEDEC_ID (info) (((info)->id[1]) << 8 | ((info)->id[2]))#define JEDEC_EXT (info) (((info)->id[3]) << 8 | ((info)->id[4])) -/** -* struct spi_flash_info - SPI/QSPI flash device params structure -* -* @name: Device name ([MANUFLETTER][DEVTYPE][DENSITY][EXTRAINFO]) -* @sector_size: Isn't necessarily a sector size from vendor, -* the size listed here is what works with CMD_ERASE_64K -* @nr_sectors: No.of sectors on this device -* @flags: Important param, for flash specific behaviour -*/ struct spi_flash_info { -const char *name; +const char *name;/* * This array stores the ID bytes.
@@ -128,12 +119,15 @@ struct spi_flash_info {u8 id[5 ];u8 id_len; -u32 sector_size; -u32 nr_sectors; +/* The size listed here is what works with SPINOR_OP_SE, which isn't +* necessarily called a "sector" by the vendor. +*/ +u32 sector_size; +u32 nr_sectors; -u16 page_size; +u16 page_size; -u16 flags; +u16 flags;#define SECT_4K BIT(0)#define E_FSR BIT(1)#define SST_WR BIT(2)
Signature · 1 line
2.7.4
PATCH v2 14/22 sf: Cleanup sf_params
In reply to Jagan Teki- Move headers froms sf_params to common header file
- Removed unnecessary comment
--- drivers/mtd/spi/sf_internal.h | 5 +++-- drivers/mtd/spi/sf_params.c | 5 ----- 2 files changed, 3 insertions(+), 7 deletions(-)
drivers/mtd/spi/sf_internal.h +3 -2
@@ -10,8 +10,9 @@#ifndef _SF_INTERNAL_H_#define _SF_INTERNAL_H_ -#include <linux/types.h> -#include <linux/compiler.h> +#include <common.h> +#include <spi.h> +#include <spi_flash.h> /* Dual SPI flash memories - see SPI_COMM_DUAL_... */ enum spi_dual_flash {
drivers/mtd/spi/sf_params.c +0 -5
@@ -6,10 +6,6 @@* SPDX-License-Identifier: GPL-2.0+ */ -#include <common.h> -#include <spi.h> -#include <spi_flash.h> -#include "sf_internal.h" /* Used when the "_ext_id" is two bytes at most */
@@ -27,7 +23,6 @@ .page_size = 256, \ .flags = (_flags), -/* SPI/QSPI flash device params structure */ const struct spi_flash_info spi_flash_ids[] = {#ifdef CONFIG_SPI_FLASH_ATMEL /* ATMEL */ {"AT45DB011D", INFO(0x1f2200, 0x0, 64 * 1024, 4, SECT_4K) },
Signature · 1 line
2.7.4
PATCH v2 15/22 sf: nr_sectors -> n_sectors
In reply to Jagan TekiRename nr_sectors as n_sectors to sync with Linux.
--- drivers/mtd/spi/sf_internal.h | 2 +- drivers/mtd/spi/sf_params.c | 2 +- drivers/mtd/spi/spi_flash.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/mtd/spi/sf_internal.h +1 -1
@@ -124,7 +124,7 @@ struct spi_flash_info {* necessarily called a "sector" by the vendor. */ u32 sector_size; -u32 nr_sectors; +u32 n_sectors;u16 page_size;
drivers/mtd/spi/sf_params.c +1 -1
@@ -19,7 +19,7 @@ }, \ .id_len = (!(_jedec_id) ? 0 : (3 + ((_ext_id) ? 2 : 0))), \ .sector_size = (_sector_size), \ - .nr_sectors = (_n_sectors), \ + .n_sectors = (_n_sectors), \ .page_size = 256, \ .flags = (_flags),
drivers/mtd/spi/spi_flash.c +1 -1
@@ -1143,7 +1143,7 @@ int spi_flash_scan(struct spi_flash *flash) } flash->page_size <<= flash->shift; flash->sector_size = info->sector_size << flash->shift; - flash->size = flash->sector_size * info->nr_sectors << flash->shift; + flash->size = flash->sector_size * info->n_sectors << flash->shift;#ifdef CONFIG_SF_DUAL_FLASH if (flash->dual_flash &SF_DUAL_STACKED_FLASH ) flash->size <<=1 ;
Signature · 1 line
2.7.4
PATCH v2 16/22 sf: Add SPI_FLASH_MAX_ID_LEN
In reply to Jagan TekiAdd id length of 5 bytes numerical value to macro.
--- drivers/mtd/spi/sf_internal.h | 3 ++- drivers/mtd/spi/spi_flash.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-)
drivers/mtd/spi/sf_internal.h +2 -1
@@ -108,6 +108,7 @@ int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,#define JEDEC_MFR (info) ((info)->id[0])#define JEDEC_ID (info) (((info)->id[1]) << 8 | ((info)->id[2]))#define JEDEC_EXT (info) (((info)->id[3]) << 8 | ((info)->id[4])) +#define SPI_FLASH_MAX_ID_LEN 5struct spi_flash_info {const char *name;
@@ -117,7 +118,7 @@ struct spi_flash_info {* The first three bytes are the JEDIC ID. * JEDEC ID zero means "no ID" (mostly older chips). */ -u8 id[5 ]; +u8 id[SPI_FLASH_MAX_ID_LEN ];u8 id_len;/* The size listed here is what works with SPINOR_OP_SE, which isn't
drivers/mtd/spi/spi_flash.c +2 -2
@@ -928,10 +928,10 @@ static int micron_quad_enable(struct spi_flash *flash)static const struct spi_flash_info *spi_flash_read_id (struct spi_flash *flash) {int tmp; -u8 id[5 ]; +u8 id[SPI_FLASH_MAX_ID_LEN ];const struct spi_flash_info *info; - tmp =spi_flash_cmd (flash->spi,CMD_READ_ID , id,5 ); + tmp =spi_flash_cmd (flash->spi,CMD_READ_ID , id,SPI_FLASH_MAX_ID_LEN );if (tmp <0 ) {printf ("SF: error %d reading JEDEC ID\n" , tmp);return ERR_PTR (tmp);
Signature · 1 line
2.7.4
PATCH v2 17/22 sf: Increase max id length by 1 byte
In reply to Jagan TekiSo, now SPI_FLASH_ID_MAX_LEN is 6 bytes useful for few spansion flash families S25FS-S
--- drivers/mtd/spi/sf_internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/spi/sf_internal.h +1 -1
@@ -108,7 +108,7 @@ int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,#define JEDEC_MFR (info) ((info)->id[0])#define JEDEC_ID (info) (((info)->id[1]) << 8 | ((info)->id[2]))#define JEDEC_EXT (info) (((info)->id[3]) << 8 | ((info)->id[4])) -#define SPI_FLASH_MAX_ID_LEN 5 +#define SPI_FLASH_MAX_ID_LEN 6struct spi_flash_info {const char *name;
Signature · 1 line
2.7.4
PATCH v2 18/22 sf: Add INFO6 flash_info macro
In reply to Jagan TekiINFO6 is for tabulating 6 byte flash parts, Ex: S25FS256S_64K
--- drivers/mtd/spi/sf_params.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/mtd/spi/sf_params.c +15 -0
@@ -23,6 +23,21 @@ .page_size = 256, \ .flags = (_flags), +#define INFO6 (_jedec_id, _ext_id, _sector_size, _n_sectors, _flags) \ + .id = { \ + ((_jedec_id) >> 16) & 0xff, \ + ((_jedec_id) >> 8) & 0xff, \ + (_jedec_id) & 0xff, \ + ((_ext_id) >> 16) & 0xff, \ + ((_ext_id) >> 8) & 0xff, \ + (_ext_id) & 0xff, \ + }, \ + .id_len = 6, \ + .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) },
Signature · 1 line
2.7.4
PATCH v2 19/22 sf: params: Add S25FS256S_64K spi flash support
In reply to Jagan TekiAdd Spansion S25FS256S_64K spi flash to the list of spi_flash_ids.
In spansion S25FS-S family the physical sectors are grouped as normal and parameter sectors. Parameter sectors are 4kB in size with 8 set located at the bottom or top address of a device. Normal sectors are similar to other flash family with sizes of 64kB or 32 kB.
To erase whole flash using sector erase(D8h or DCh) won't effect the parameter sectors, so in order to erase these we must use 4K sector erase commands (20h or 21h) separately.
So better to erase the whole flash using 4K sector erase instead of detecting these family parts again and do two different erase operations.
--- drivers/mtd/spi/sf_params.c | 1 + 1 file changed, 1 insertion(+)
drivers/mtd/spi/sf_params.c +1 -0
@@ -93,6 +93,7 @@ const struct spi_flash_info spi_flash_ids[] = { {"S25FL128S_64K", INFO(0x012018, 0x4d01, 64 * 1024, 256, RD_FULL | WR_QPP) }, {"S25FL256S_256K", INFO(0x010219, 0x4d00, 256 * 1024, 128, RD_FULL | WR_QPP) }, {"S25FL256S_64K", INFO(0x010219, 0x4d01, 64 * 1024, 512, RD_FULL | WR_QPP) }, + {"S25FS256S_64K", INFO6(0x010219, 0x4d0181, 64 * 1024, 512, RD_FULL | WR_QPP | SECT_4K) }, {"S25FS512S", INFO(0x010220, 0x4D00, 128 * 1024, 512, RD_FULL | WR_QPP) }, {"S25FL512S_256K", INFO(0x010220, 0x4d00, 256 * 1024, 256, RD_FULL | WR_QPP) }, {"S25FL512S_64K", INFO(0x010220, 0x4d01, 64 * 1024, 1024, RD_FULL | WR_QPP) },
Signature · 1 line
2.7.4