1 --- a/drivers/mtd/devices/m25p80.c
2 +++ b/drivers/mtd/devices/m25p80.c
3 @@ -100,6 +100,7 @@ struct m25p {
10 static inline struct m25p *mtd_to_m25p(struct mtd_info *mtd)
11 @@ -352,6 +353,7 @@ static int m25p80_read(struct mtd_info *
12 struct m25p *flash = mtd_to_m25p(mtd);
13 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 @@ -374,8 +376,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 @@ -383,13 +383,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 @@ -397,11 +390,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 @@ -924,6 +950,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 (JEDEC_MFR(info->jedec_id) == CFI_MFR_SST)
102 flash->mtd.write = sst_write;
103 --- a/include/linux/spi/flash.h
104 +++ b/include/linux/spi/flash.h
105 @@ -25,6 +25,7 @@ struct flash_platform_data {
109 + size_t max_read_len;
110 /* we'll likely add more ... use JEDEC IDs, etc */