Skip to content

Commit c4b3eac

Browse files
asverdlinCyrillePitchen
authored andcommitted
mtd: spi-nor: Recover from Spansion/Cypress errors
S25FL{128|256|512}S datasheets say: "When P_ERR or E_ERR bits are set to one, the WIP bit will remain set to one indicating the device remains busy and unable to receive new operation commands. A Clear Status Register (CLSR) command must be received to return the device to standby mode." Current spi-nor code works until first error occurs, but write/erase errors are not just rare hardware failures, they also occur if user tries to flash write-protected areas. After such attempt no SPI command can be executed any more and even read fails. This patch adds support for P_ERR and E_ERR bits in Status Register 1 (so that operation fails immediately and not after a long timeout) and proper recovery from the error condition. Tested on Spansion S25FS128S, which is supported by S25FL129P entry. Signed-off-by: Alexander Sverdlin <alexander.sverdlin@nokia.com> Signed-off-by: Cyrille Pitchen <cyrille.pitchen@wedev4u.fr>
1 parent fe60283 commit c4b3eac

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

‎drivers/mtd/spi-nor/spi-nor.c‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ struct flash_info {
8888
*/
8989
#define NO_CHIP_ERASE BIT(12) /* Chip does not support chip erase */
9090
#define SPI_NOR_SKIP_SFDP BIT(13) /* Skip parsing of SFDP tables */
91+
#define USE_CLSR BIT(14) /* use CLSR command */
9192
};
9293

9394
#define JEDEC_MFR(info) ((info)->id[0])
@@ -308,8 +309,18 @@ static inline int spi_nor_sr_ready(struct spi_nor *nor)
308309
int sr = read_sr(nor);
309310
if (sr < 0)
310311
return sr;
311-
else
312-
return !(sr & SR_WIP);
312+
313+
if (nor->flags & SNOR_F_USE_CLSR && sr & (SR_E_ERR | SR_P_ERR)) {
314+
if (sr & SR_E_ERR)
315+
dev_err(nor->dev, "Erase Error occurred\n");
316+
else
317+
dev_err(nor->dev, "Programming Error occurred\n");
318+
319+
nor->write_reg(nor, SPINOR_OP_CLSR, NULL, 0);
320+
return -EIO;
321+
}
322+
323+
return !(sr & SR_WIP);
313324
}
314325

315326
static inline int spi_nor_fsr_ready(struct spi_nor *nor)
@@ -1043,15 +1054,15 @@ static const struct flash_info spi_nor_ids[] = {
10431054
*/
10441055
{ "s25sl032p", INFO(0x010215, 0x4d00, 64 * 1024, 64, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
10451056
{ "s25sl064p", INFO(0x010216, 0x4d00, 64 * 1024, 128, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
1046-
{ "s25fl256s0", INFO(0x010219, 0x4d00, 256 * 1024, 128, 0) },
1047-
{ "s25fl256s1", INFO(0x010219, 0x4d01, 64 * 1024, 512, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
1048-
{ "s25fl512s", INFO(0x010220, 0x4d00, 256 * 1024, 256, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
1057+
{ "s25fl256s0", INFO(0x010219, 0x4d00, 256 * 1024, 128, USE_CLSR) },
1058+
{ "s25fl256s1", INFO(0x010219, 0x4d01, 64 * 1024, 512, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | USE_CLSR) },
1059+
{ "s25fl512s", INFO(0x010220, 0x4d00, 256 * 1024, 256, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | USE_CLSR) },
10491060
{ "s70fl01gs", INFO(0x010221, 0x4d00, 256 * 1024, 256, 0) },
10501061
{ "s25sl12800", INFO(0x012018, 0x0300, 256 * 1024, 64, 0) },
10511062
{ "s25sl12801", INFO(0x012018, 0x0301, 64 * 1024, 256, 0) },
1052-
{ "s25fl128s", INFO6(0x012018, 0x4d0180, 64 * 1024, 256, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
1053-
{ "s25fl129p0", INFO(0x012018, 0x4d00, 256 * 1024, 64, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
1054-
{ "s25fl129p1", INFO(0x012018, 0x4d01, 64 * 1024, 256, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
1063+
{ "s25fl128s", INFO6(0x012018, 0x4d0180, 64 * 1024, 256, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | USE_CLSR) },
1064+
{ "s25fl129p0", INFO(0x012018, 0x4d00, 256 * 1024, 64, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | USE_CLSR) },
1065+
{ "s25fl129p1", INFO(0x012018, 0x4d01, 64 * 1024, 256, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | USE_CLSR) },
10551066
{ "s25sl004a", INFO(0x010212, 0, 64 * 1024, 8, 0) },
10561067
{ "s25sl008a", INFO(0x010213, 0, 64 * 1024, 16, 0) },
10571068
{ "s25sl016a", INFO(0x010214, 0, 64 * 1024, 32, 0) },
@@ -2707,6 +2718,8 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
27072718
nor->flags |= SNOR_F_HAS_SR_TB;
27082719
if (info->flags & NO_CHIP_ERASE)
27092720
nor->flags |= SNOR_F_NO_OP_CHIP_ERASE;
2721+
if (info->flags & USE_CLSR)
2722+
nor->flags |= SNOR_F_USE_CLSR;
27102723

27112724
if (info->flags & SPI_NOR_NO_ERASE)
27122725
mtd->flags |= MTD_NO_ERASE;

‎include/linux/mtd/spi-nor.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105

106106
/* Used for Spansion flashes only. */
107107
#define SPINOR_OP_BRWR 0x17 /* Bank register write */
108+
#define SPINOR_OP_CLSR 0x30 /* Clear status register 1 */
108109

109110
/* Used for Micron flashes only. */
110111
#define SPINOR_OP_RD_EVCR 0x65 /* Read EVCR register */
@@ -119,6 +120,9 @@
119120
#define SR_BP2 BIT(4) /* Block protect 2 */
120121
#define SR_TB BIT(5) /* Top/Bottom protect */
121122
#define SR_SRWD BIT(7) /* SR write protect */
123+
/* Spansion/Cypress specific status bits */
124+
#define SR_E_ERR BIT(5)
125+
#define SR_P_ERR BIT(6)
122126

123127
#define SR_QUAD_EN_MX BIT(6) /* Macronix Quad I/O */
124128

@@ -224,6 +228,7 @@ enum spi_nor_option_flags {
224228
SNOR_F_NO_OP_CHIP_ERASE = BIT(2),
225229
SNOR_F_S3AN_ADDR_DEFAULT = BIT(3),
226230
SNOR_F_READY_XSR_RDY = BIT(4),
231+
SNOR_F_USE_CLSR = BIT(5),
227232
};
228233

229234
/**

0 commit comments

Comments
 (0)