1 --- a/drivers/mtd/devices/m25p80.c
2 +++ b/drivers/mtd/devices/m25p80.c
3 @@ -93,6 +93,7 @@ struct m25p {
10 static inline struct m25p *mtd_to_m25p(struct mtd_info *mtd)
11 @@ -344,6 +345,7 @@ static int m25p80_read(struct mtd_info *
12 struct spi_transfer t[2];
17 pr_debug("%s: %s from 0x%08x, len %zd\n", dev_name(&flash->spi->dev),
18 __func__, (u32)from, len);
19 @@ -359,19 +361,10 @@ static int m25p80_read(struct mtd_info *
20 t[0].len = m25p_cmdsz(flash) + (flash->fast_read ? 1 : 0);
21 spi_message_add_tail(&t[0], &m);
25 spi_message_add_tail(&t[1], &m);
27 mutex_lock(&flash->lock);
29 - /* Wait till previous write/erase is done. */
30 - if (wait_till_ready(flash)) {
31 - /* REVISIT status return?? */
32 - mutex_unlock(&flash->lock);
36 /* FIXME switch to OPCODE_FAST_READ. It's required for higher
37 * clocks; and at this writing, every chip this driver handles
38 * supports that opcode.
39 @@ -380,13 +373,43 @@ static int m25p80_read(struct mtd_info *
40 /* Set up the write data buffer. */
41 opcode = flash->fast_read ? OPCODE_FAST_READ : OPCODE_NORM_READ;
42 flash->command[0] = opcode;
43 - m25p_addr2cmd(flash, from, flash->command);
50 + ret = wait_till_ready(flash);
52 + mutex_unlock(&flash->lock);
56 + if (flash->max_read_len > 0 &&
57 + flash->max_read_len < len)
58 + readlen = flash->max_read_len;
62 + t[1].rx_buf = buf + ofs;
65 + m25p_addr2cmd(flash, from + ofs, flash->command);
67 + spi_sync(flash->spi, &m);
69 - spi_sync(flash->spi, &m);
70 + done = m.actual_length - m25p_cmdsz(flash) -
71 + (flash->fast_read ? 1 : 0);
72 + if (done != readlen) {
73 + mutex_unlock(&flash->lock);
77 - *retlen = m.actual_length - m25p_cmdsz(flash) -
78 - (flash->fast_read ? 1 : 0);
84 mutex_unlock(&flash->lock);
87 @@ -1021,6 +1044,12 @@ static int m25p_probe(struct spi_device
88 flash->mtd._unlock = m25p80_unlock;
91 + if (data && data->max_read_len) {
92 + flash->max_read_len = data->max_read_len;
93 + dev_warn(&spi->dev, "max_read_len set to %d bytes\n",
94 + flash->max_read_len);
97 /* sst flash chips use AAI word program */
98 if (info->flags & SST_WRITE)
99 flash->mtd._write = sst_write;
100 --- a/include/linux/spi/flash.h
101 +++ b/include/linux/spi/flash.h
102 @@ -25,6 +25,7 @@ struct flash_platform_data {
106 + size_t max_read_len;
107 /* we'll likely add more ... use JEDEC IDs, etc */