1 --- a/drivers/mtd/devices/m25p80.c
2 +++ b/drivers/mtd/devices/m25p80.c
3 @@ -94,6 +94,7 @@ struct m25p {
10 static inline struct m25p *mtd_to_m25p(struct mtd_info *mtd)
11 @@ -341,6 +342,7 @@ static int m25p80_read(struct mtd_info *
12 struct m25p *flash = mtd_to_m25p(mtd);
13 struct spi_transfer t[2];
17 DEBUG(MTD_DEBUG_LEVEL2, "%s: %s %s 0x%08x, len %zd\n",
18 dev_name(&flash->spi->dev), __func__, "from",
19 @@ -364,8 +366,6 @@ static int m25p80_read(struct mtd_info *
20 t[0].len = m25p_cmdsz(flash) + FAST_READ_DUMMY_BYTE;
21 spi_message_add_tail(&t[0], &m);
25 spi_message_add_tail(&t[1], &m);
27 /* Byte count starts at zero. */
28 @@ -373,13 +373,6 @@ static int m25p80_read(struct mtd_info *
30 mutex_lock(&flash->lock);
32 - /* Wait till previous write/erase is done. */
33 - if (wait_till_ready(flash)) {
34 - /* REVISIT status return?? */
35 - mutex_unlock(&flash->lock);
39 /* FIXME switch to OPCODE_FAST_READ. It's required for higher
40 * clocks; and at this writing, every chip this driver handles
41 * supports that opcode.
42 @@ -387,11 +380,44 @@ static int m25p80_read(struct mtd_info *
44 /* Set up the write data buffer. */
45 flash->command[0] = OPCODE_READ;
46 - m25p_addr2cmd(flash, from, flash->command);
48 - spi_sync(flash->spi, &m);
55 + ret = wait_till_ready(flash);
57 + mutex_unlock(&flash->lock);
61 + if (flash->max_read_len > 0 &&
62 + flash->max_read_len < len)
63 + readlen = flash->max_read_len;
67 + t[1].rx_buf = buf + ofs;
70 + m25p_addr2cmd(flash, from + ofs, flash->command);
72 + spi_sync(flash->spi, &m);
74 - *retlen = m.actual_length - m25p_cmdsz(flash) - FAST_READ_DUMMY_BYTE;
75 + done = m.actual_length - m25p_cmdsz(flash) -
76 + FAST_READ_DUMMY_BYTE;
77 + if (done != readlen) {
78 + mutex_unlock(&flash->lock);
88 mutex_unlock(&flash->lock);
90 @@ -901,6 +927,12 @@ static int __devinit m25p_probe(struct s
91 flash->mtd.erase = m25p80_erase;
92 flash->mtd.read = m25p80_read;
94 + if (data && data->max_read_len) {
95 + flash->max_read_len = data->max_read_len;
96 + dev_warn(&spi->dev, "max_read_len set to %d bytes\n",
97 + flash->max_read_len);
100 /* sst flash chips use AAI word program */
101 if (info->jedec_id >> 16 == 0xbf)
102 flash->mtd.write = sst_write;
103 --- a/include/linux/spi/flash.h
104 +++ b/include/linux/spi/flash.h
105 @@ -26,6 +26,7 @@ struct flash_platform_data {
107 const char **part_probes;
109 + size_t max_read_len;
110 /* we'll likely add more ... use JEDEC IDs, etc */