1 From 5fb4e8d7287ac8fcb33aae8b1e9e22c5a3c392bd Mon Sep 17 00:00:00 2001
2 From: Jonas Gorski <jonas.gorski@gmail.com>
3 Date: Thu, 10 Nov 2011 17:33:40 +0100
4 Subject: [PATCH 51/79] MTD: DEVICES: m25p80: add support for limiting reads
6 Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
8 drivers/mtd/devices/m25p80.c | 29 +++++++++++++++++++++++++++--
9 include/linux/spi/flash.h | 4 ++++
10 2 files changed, 31 insertions(+), 2 deletions(-)
12 --- a/drivers/mtd/devices/m25p80.c
13 +++ b/drivers/mtd/devices/m25p80.c
14 @@ -100,6 +100,7 @@ struct m25p {
18 + int max_transfer_len;
21 static inline struct m25p *mtd_to_m25p(struct mtd_info *mtd)
22 @@ -346,10 +347,9 @@ static int m25p80_erase(struct mtd_info
23 * Read an address range from the flash chip. The address range
24 * may be any size provided it is within the physical boundaries.
26 -static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len,
27 +static int __m25p80_read(struct m25p *flash, loff_t from, size_t len,
28 size_t *retlen, u_char *buf)
30 - struct m25p *flash = mtd_to_m25p(mtd);
31 struct spi_transfer t[2];
34 @@ -408,6 +408,28 @@ static int m25p80_read(struct mtd_info *
38 +static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len,
39 + size_t *retlen, u_char *buf)
41 + struct m25p *flash = mtd_to_m25p(mtd);
43 + size_t read_len = flash->max_transfer_len;
48 + return __m25p80_read(flash, from, len, retlen, buf);
52 + for (off = 0; off < len && !ret; off += read_len) {
53 + ret = __m25p80_read(flash, from + off, min(len - off, read_len),
54 + &part_len, buf + off);
55 + *retlen += part_len;
61 * Write an address range to the flash chip. Data must be written in
62 * FLASH_PAGESIZE chunks. The address range may be any size provided
63 @@ -897,6 +919,9 @@ static int __devinit m25p_probe(struct s
68 + flash->max_transfer_len = data->max_transfer_len;
71 mutex_init(&flash->lock);
72 dev_set_drvdata(&spi->dev, flash);
73 --- a/include/linux/spi/flash.h
74 +++ b/include/linux/spi/flash.h
75 @@ -13,6 +13,8 @@ struct mtd_part_parser_data;
76 * @part_probe_types: optional list of MTD parser names to use for
79 + * @max_transfer_len: option maximum read/write length limitation for
80 + * SPI controllers not able to transfer any length commands.
81 * Board init code (in arch/.../mach-xxx/board-yyy.c files) can
82 * provide information about SPI flash parts (such as DataFlash) to
83 * help set up the device and its appropriate default partitioning.
84 @@ -28,6 +30,8 @@ struct flash_platform_data {
87 const char **part_probe_types;
89 + unsigned int max_transfer_len;
90 /* we'll likely add more ... use JEDEC IDs, etc */