--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
-@@ -1381,6 +1381,66 @@ write_err:
+@@ -1453,6 +1453,67 @@ write_err:
return ret;
}
+ size_t *_retlen, const u_char *_buf)
+{
+ struct spi_nor *nor = mtd_to_spi_nor(mtd);
++ u32 addr_width = nor->addr_width + !!(nor->flags & SNOR_F_4B_EXT_ADDR);
+ int chunk_size;
+ int retlen = 0;
+ int ret;
+ if (!chunk_size)
+ chunk_size = _len;
+
-+ if (nor->addr_width > 3)
-+ chunk_size -= nor->addr_width - 3;
++ if (addr_width > 3)
++ chunk_size -= addr_width - 3;
+
+ while (retlen < _len) {
+ size_t len = min_t(int, chunk_size, _len - retlen);
static int macronix_quad_enable(struct spi_nor *nor)
{
int ret, val;
-@@ -1623,10 +1683,12 @@ int spi_nor_scan(struct spi_nor *nor, co
+@@ -1704,10 +1765,12 @@ int spi_nor_scan(struct spi_nor *nor, co
}
/* sst nor chips use AAI word program */
if (info->flags & USE_FSR)
nor->flags |= SNOR_F_USE_FSR;
-@@ -1656,11 +1718,20 @@ int spi_nor_scan(struct spi_nor *nor, co
+@@ -1739,11 +1802,20 @@ int spi_nor_scan(struct spi_nor *nor, co
mtd->writebufsize = nor->page_size;
if (np) {
nor->flash_read = SPI_NOR_FAST;
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
-@@ -141,6 +141,7 @@ enum spi_nor_option_flags {
- SNOR_F_NO_OP_CHIP_ERASE = BIT(2),
+@@ -143,6 +143,7 @@ enum spi_nor_option_flags {
SNOR_F_S3AN_ADDR_DEFAULT = BIT(3),
SNOR_F_READY_XSR_RDY = BIT(4),
-+ SNOR_F_SST = BIT(5),
+ SNOR_F_4B_EXT_ADDR = BIT(5),
++ SNOR_F_SST = BIT(6),
};
/**
-@@ -180,6 +181,7 @@ struct spi_nor {
+@@ -182,6 +183,7 @@ struct spi_nor {
struct mutex lock;
struct device *dev;
u32 page_size;