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 @@ -117,25 +119,14 @@ static inline unsigned int m25p80_rx_nbi
24 - * Read an address range from the nor chip. The address range
25 - * may be any size provided it is within the physical boundaries.
27 -static int m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
28 - size_t *retlen, u_char *buf)
29 +static int __m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
30 + size_t *retlen, u_char *buf)
32 struct m25p *flash = nor->priv;
33 struct spi_device *spi = flash->spi;
34 struct spi_transfer t[2];
36 int dummy = nor->read_dummy;
39 - /* Wait till previous write/erase is done. */
40 - ret = nor->wait_till_ready(nor);
45 memset(t, 0, (sizeof t));
47 @@ -156,6 +147,84 @@ static int m25p80_read(struct spi_nor *n
48 *retlen = m.actual_length - m25p_cmdsz(nor) - dummy;
52 + * Read an address range from the nor chip. The address range
53 + * may be any size provided it is within the physical boundaries.
55 +static int m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
56 + size_t *retlen, u_char *buf)
60 + /* Wait till previous write/erase is done. */
61 + ret = nor->wait_till_ready(nor);
65 + return __m25p80_read(nor, from, len, retlen, buf);
69 +static void m25p80_chunked_write(struct spi_nor *nor, loff_t _from, size_t _len,
70 + size_t *_retlen, const u_char *_buf)
72 + struct m25p *flash = nor->priv;
76 + chunk_size = flash->chunk_size;
80 + if (nor->addr_width > 3)
81 + chunk_size -= nor->addr_width - 3;
83 + while (retlen < _len) {
84 + size_t len = min_t(int, chunk_size, _len - retlen);
85 + const u_char *buf = _buf + retlen;
86 + loff_t from = _from + retlen;
88 + nor->wait_till_ready(nor);
89 + nor->write_reg(nor, SPINOR_OP_WREN, NULL, 0, 0);
91 + m25p80_write(nor, from, len, &retlen, buf);
96 +static int m25p80_chunked_read(struct spi_nor *nor, loff_t _from, size_t _len,
97 + size_t *_retlen, u_char *_buf)
99 + struct m25p *flash = nor->priv;
103 + /* Wait till previous write/erase is done. */
104 + ret = nor->wait_till_ready(nor);
108 + chunk_size = flash->chunk_size;
114 + while (*_retlen < _len) {
115 + size_t len = min_t(int, chunk_size, _len - *_retlen);
116 + u_char *buf = _buf + *_retlen;
117 + loff_t from = _from + *_retlen;
119 + int ret = __m25p80_read(nor, from, len, &retlen, buf);
124 + *_retlen += retlen;
130 static int m25p80_erase(struct spi_nor *nor, loff_t offset)
132 @@ -197,6 +266,7 @@ static int m25p_probe(struct spi_device
134 enum read_mode mode = SPI_NOR_NORMAL;
135 char *flash_name = NULL;
139 data = dev_get_platdata(&spi->dev);
140 @@ -244,6 +314,14 @@ static int m25p_probe(struct spi_device
144 + if (spi->dev.of_node &&
145 + !of_property_read_u32(spi->dev.of_node, "m25p,chunked-io", &val)) {
146 + dev_warn(&spi->dev, "using chunked io\n");
147 + nor->read = m25p80_chunked_read;
148 + nor->write = m25p80_chunked_write;
149 + flash->chunk_size = val;
152 ppdata.of_node = spi->dev.of_node;
154 return mtd_device_parse_register(&flash->mtd, NULL, &ppdata,