1 --- a/drivers/mtd/spi-nor/spi-nor.c
2 +++ b/drivers/mtd/spi-nor/spi-nor.c
3 @@ -1453,6 +1453,67 @@ write_err:
7 +static int spi_nor_chunked_write(struct mtd_info *mtd, loff_t _to, size_t _len,
8 + size_t *_retlen, const u_char *_buf)
10 + struct spi_nor *nor = mtd_to_spi_nor(mtd);
11 + u32 addr_width = nor->addr_width + !!(nor->flags & SNOR_F_4B_EXT_ADDR);
16 + chunk_size = nor->chunk_size;
21 + chunk_size -= addr_width - 3;
23 + while (retlen < _len) {
24 + size_t len = min_t(int, chunk_size, _len - retlen);
25 + const u_char *buf = _buf + retlen;
26 + loff_t to = _to + retlen;
28 + if (nor->flags & SNOR_F_SST)
29 + ret = sst_write(mtd, to, len, &retlen, buf);
31 + ret = spi_nor_write(mtd, to, len, &retlen, buf);
40 +static int spi_nor_chunked_read(struct mtd_info *mtd, loff_t _from, size_t _len,
41 + size_t *_retlen, u_char *_buf)
43 + struct spi_nor *nor = mtd_to_spi_nor(mtd);
47 + chunk_size = nor->chunk_size;
52 + while (*_retlen < _len) {
53 + size_t len = min_t(int, chunk_size, _len - *_retlen);
54 + u_char *buf = _buf + *_retlen;
55 + loff_t from = _from + *_retlen;
58 + ret = spi_nor_read(mtd, from, len, &retlen, buf);
68 static int macronix_quad_enable(struct spi_nor *nor)
71 @@ -1702,10 +1763,12 @@ int spi_nor_scan(struct spi_nor *nor, co
74 /* sst nor chips use AAI word program */
75 - if (info->flags & SST_WRITE)
76 + if (info->flags & SST_WRITE) {
77 mtd->_write = sst_write;
79 + nor->flags |= SNOR_F_SST;
81 mtd->_write = spi_nor_write;
84 if (info->flags & USE_FSR)
85 nor->flags |= SNOR_F_USE_FSR;
86 @@ -1735,11 +1798,20 @@ int spi_nor_scan(struct spi_nor *nor, co
87 mtd->writebufsize = nor->page_size;
92 /* If we were instantiated by DT, use it */
93 if (of_property_read_bool(np, "m25p,fast-read"))
94 nor->flash_read = SPI_NOR_FAST;
96 nor->flash_read = SPI_NOR_NORMAL;
98 + if (!of_property_read_u32(np, "m25p,chunked-io", &val)) {
99 + dev_info(dev, "using chunked io (size=%d)\n", val);
100 + mtd->_read = spi_nor_chunked_read;
101 + mtd->_write = spi_nor_chunked_write;
102 + nor->chunk_size = val;
105 /* If we weren't instantiated by DT, default to fast-read */
106 nor->flash_read = SPI_NOR_FAST;
107 --- a/include/linux/mtd/spi-nor.h
108 +++ b/include/linux/mtd/spi-nor.h
109 @@ -143,6 +143,7 @@ enum spi_nor_option_flags {
110 SNOR_F_S3AN_ADDR_DEFAULT = BIT(3),
111 SNOR_F_READY_XSR_RDY = BIT(4),
112 SNOR_F_4B_EXT_ADDR = BIT(5),
113 + SNOR_F_SST = BIT(6),
117 @@ -182,6 +183,7 @@ struct spi_nor {