brcm63xx: add preliminary support for 3.13
[openwrt/svn-archive/archive.git] / target / linux / brcm63xx / patches-3.13 / 203-MTD-DEVICES-m25p80-add-support-for-limiting-reads.patch
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
5
6 Signed-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 @@ -101,6 +101,7 @@ struct m25p {
15 u8 program_opcode;
16 u8 *command;
17 bool fast_read;
18 + int max_transfer_len;
19 };
20
21 static inline struct m25p *mtd_to_m25p(struct mtd_info *mtd)
22 @@ -359,10 +360,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 uint8_t opcode;
34 @@ -405,6 +405,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 @@ -1001,6 +1023,9 @@ static int m25p_probe(struct spi_device
64 if (!flash->command)
65 return -ENOMEM;
66
67 + if (data)
68 + flash->max_transfer_len = data->max_transfer_len;
69 +
70 flash->spi = spi;
71 mutex_init(&flash->lock);
72 spi_set_drvdata(spi, 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