1 --- a/drivers/mtd/devices/m25p80.c
2 +++ b/drivers/mtd/devices/m25p80.c
4 #include <linux/errno.h>
5 #include <linux/module.h>
6 #include <linux/device.h>
9 #include <linux/mtd/mtd.h>
10 #include <linux/mtd/partitions.h>
11 @@ -32,6 +33,7 @@ struct m25p {
12 struct spi_device *spi;
13 struct spi_nor spi_nor;
16 u8 command[MAX_CMD_SIZE];
19 @@ -157,6 +159,58 @@ static int m25p80_read(struct spi_nor *n
23 +static void m25p80_chunked_write(struct spi_nor *nor, loff_t _from, size_t _len,
24 + size_t *_retlen, const u_char *_buf)
26 + struct m25p *flash = nor->priv;
30 + chunk_size = flash->chunk_size;
34 + while (retlen < _len) {
35 + size_t len = min_t(int, chunk_size, _len - retlen);
36 + const u_char *buf = _buf + retlen;
37 + loff_t from = _from + retlen;
39 + nor->wait_till_ready(nor);
40 + nor->write_reg(nor, SPINOR_OP_WREN, NULL, 0, 0);
42 + m25p80_write(nor, from, len, &retlen, buf);
47 +static int m25p80_chunked_read(struct spi_nor *nor, loff_t _from, size_t _len,
48 + size_t *_retlen, u_char *_buf)
50 + struct m25p *flash = nor->priv;
53 + chunk_size = flash->chunk_size;
59 + while (*_retlen < _len) {
60 + size_t len = min_t(int, chunk_size, _len - *_retlen);
61 + u_char *buf = _buf + *_retlen;
62 + loff_t from = _from + *_retlen;
64 + int ret = m25p80_read(nor, from, len, &retlen, buf);
75 static int m25p80_erase(struct spi_nor *nor, loff_t offset)
77 struct m25p *flash = nor->priv;
78 @@ -197,6 +251,7 @@ static int m25p_probe(struct spi_device
80 enum read_mode mode = SPI_NOR_NORMAL;
81 char *flash_name = NULL;
85 data = dev_get_platdata(&spi->dev);
86 @@ -244,6 +299,14 @@ static int m25p_probe(struct spi_device
90 + if (spi->dev.of_node &&
91 + !of_property_read_u32(spi->dev.of_node, "m25p,chunked-io", &val)) {
92 + dev_warn(&spi->dev, "using chunked io\n");
93 + nor->read = m25p80_chunked_read;
94 + nor->write = m25p80_chunked_write;
95 + flash->chunk_size = val;
98 ppdata.of_node = spi->dev.of_node;
100 return mtd_device_parse_register(&flash->mtd, NULL, &ppdata,