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,61 @@ 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 + if (nor->addr_width > 3)
35 + chunk_size -= nor->addr_width - 3;
37 + while (retlen < _len) {
38 + size_t len = min_t(int, chunk_size, _len - retlen);
39 + const u_char *buf = _buf + retlen;
40 + loff_t from = _from + retlen;
42 + nor->wait_till_ready(nor);
43 + nor->write_reg(nor, SPINOR_OP_WREN, NULL, 0, 0);
45 + m25p80_write(nor, from, len, &retlen, buf);
50 +static int m25p80_chunked_read(struct spi_nor *nor, loff_t _from, size_t _len,
51 + size_t *_retlen, u_char *_buf)
53 + struct m25p *flash = nor->priv;
56 + chunk_size = flash->chunk_size;
62 + while (*_retlen < _len) {
63 + size_t len = min_t(int, chunk_size, _len - *_retlen);
64 + u_char *buf = _buf + *_retlen;
65 + loff_t from = _from + *_retlen;
67 + int ret = m25p80_read(nor, from, len, &retlen, buf);
78 static int m25p80_erase(struct spi_nor *nor, loff_t offset)
80 struct m25p *flash = nor->priv;
81 @@ -197,6 +254,7 @@ static int m25p_probe(struct spi_device
83 enum read_mode mode = SPI_NOR_NORMAL;
84 char *flash_name = NULL;
88 data = dev_get_platdata(&spi->dev);
89 @@ -244,6 +302,14 @@ static int m25p_probe(struct spi_device
93 + if (spi->dev.of_node &&
94 + !of_property_read_u32(spi->dev.of_node, "m25p,chunked-io", &val)) {
95 + dev_warn(&spi->dev, "using chunked io\n");
96 + nor->read = m25p80_chunked_read;
97 + nor->write = m25p80_chunked_write;
98 + flash->chunk_size = val;
101 ppdata.of_node = spi->dev.of_node;
103 return mtd_device_parse_register(&flash->mtd, NULL, &ppdata,