Root/target/linux/brcm63xx/patches-3.3/203-MTD-DEVICES-m25p80-add-support-for-limiting-reads.patch

1From 5fb4e8d7287ac8fcb33aae8b1e9e22c5a3c392bd Mon Sep 17 00:00:00 2001
2From: Jonas Gorski <jonas.gorski@gmail.com>
3Date: Thu, 10 Nov 2011 17:33:40 +0100
4Subject: [PATCH 51/79] MTD: DEVICES: m25p80: add support for limiting reads
5
6Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
7---
8 drivers/mtd/devices/m25p80.c | 29 +++++++++++++++++++++++++++--
9 include/linux/spi/flash.h | 4 ++++
10 2 files changed, 31 insertions(+), 2 deletions(-)
11
12--- a/drivers/mtd/devices/m25p80.c
13+++ b/drivers/mtd/devices/m25p80.c
14@@ -100,6 +100,7 @@ struct m25p {
15     u16 addr_width;
16     u8 erase_opcode;
17     u8 *command;
18+ int max_transfer_len;
19 };
20 
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.
25  */
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)
29 {
30- struct m25p *flash = mtd_to_m25p(mtd);
31     struct spi_transfer t[2];
32     struct spi_message m;
33 
34@@ -408,6 +408,28 @@ static int m25p80_read(struct mtd_info *
35     return 0;
36 }
37 
38+static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len,
39+ size_t *retlen, u_char *buf)
40+{
41+ struct m25p *flash = mtd_to_m25p(mtd);
42+ size_t off;
43+ size_t read_len = flash->max_transfer_len;
44+ size_t part_len;
45+ int ret = 0;
46+
47+ if (!read_len)
48+ return __m25p80_read(flash, from, len, retlen, buf);
49+
50+ *retlen = 0;
51+
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;
56+ }
57+
58+ return ret;
59+}
60 /*
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
64         return -ENOMEM;
65     }
66 
67+ if (data)
68+ flash->max_transfer_len = data->max_transfer_len;
69+
70     flash->spi = spi;
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
77  * partitioning
78  *
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 {
85     char *type;
86 
87     const char **part_probe_types;
88+
89+ unsigned int max_transfer_len;
90     /* we'll likely add more ... use JEDEC IDs, etc */
91 };
92 
93

Archive Download this file



interactive