1 --- a/drivers/mtd/spi-nor/spi-nor.c
2 +++ b/drivers/mtd/spi-nor/spi-nor.c
3 @@ -1009,6 +1009,66 @@ 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);
15 + chunk_size = nor->chunk_size;
19 + if (nor->addr_width > 3)
20 + chunk_size -= nor->addr_width - 3;
22 + while (retlen < _len) {
23 + size_t len = min_t(int, chunk_size, _len - retlen);
24 + const u_char *buf = _buf + retlen;
25 + loff_t to = _to + retlen;
27 + if (nor->flags & SNOR_F_SST)
28 + ret = sst_write(mtd, to, len, &retlen, buf);
30 + ret = spi_nor_write(mtd, to, len, &retlen, buf);
39 +static int spi_nor_chunked_read(struct mtd_info *mtd, loff_t _from, size_t _len,
40 + size_t *_retlen, u_char *_buf)
42 + struct spi_nor *nor = mtd_to_spi_nor(mtd);
46 + chunk_size = nor->chunk_size;
51 + while (*_retlen < _len) {
52 + size_t len = min_t(int, chunk_size, _len - *_retlen);
53 + u_char *buf = _buf + *_retlen;
54 + loff_t from = _from + *_retlen;
57 + ret = spi_nor_read(mtd, from, len, &retlen, buf);
67 static int macronix_quad_enable(struct spi_nor *nor)
70 @@ -1187,10 +1247,12 @@ int spi_nor_scan(struct spi_nor *nor, co
73 /* sst nor chips use AAI word program */
74 - if (info->flags & SST_WRITE)
75 + if (info->flags & SST_WRITE) {
76 mtd->_write = sst_write;
78 + nor->flags |= SNOR_F_SST;
80 mtd->_write = spi_nor_write;
83 if (info->flags & USE_FSR)
84 nor->flags |= SNOR_F_USE_FSR;
85 @@ -1218,11 +1280,20 @@ int spi_nor_scan(struct spi_nor *nor, co
86 mtd->writebufsize = nor->page_size;
91 /* If we were instantiated by DT, use it */
92 if (of_property_read_bool(np, "m25p,fast-read"))
93 nor->flash_read = SPI_NOR_FAST;
95 nor->flash_read = SPI_NOR_NORMAL;
97 + if (!of_property_read_u32(np, "m25p,chunked-io", &val)) {
98 + dev_info(dev, "using chunked io (size=%d)\n", val);
99 + mtd->_read = spi_nor_chunked_read;
100 + mtd->_write = spi_nor_chunked_write;
101 + nor->chunk_size = val;
104 /* If we weren't instantiated by DT, default to fast-read */
105 nor->flash_read = SPI_NOR_FAST;
106 --- a/include/linux/mtd/spi-nor.h
107 +++ b/include/linux/mtd/spi-nor.h
108 @@ -116,6 +116,7 @@ enum spi_nor_ops {
110 enum spi_nor_option_flags {
111 SNOR_F_USE_FSR = BIT(0),
112 + SNOR_F_SST = BIT(1),
116 @@ -156,6 +157,7 @@ struct spi_nor {
118 struct device_node *flash_node;