brcm63xx: switch to linux 4.4
[openwrt/staging/dedeckeh.git] / target / linux / brcm63xx / patches-4.1 / 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 @@ -31,6 +31,7 @@
15 struct m25p {
16 struct spi_device *spi;
17 struct spi_nor spi_nor;
18 + int max_transfer_len;
19 u8 command[MAX_CMD_SIZE];
20 };
21
22 @@ -119,7 +120,7 @@ static inline unsigned int m25p80_rx_nbi
23 * Read an address range from the nor chip. The address range
24 * may be any size provided it is within the physical boundaries.
25 */
26 -static int m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
27 +static int __m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
28 size_t *retlen, u_char *buf)
29 {
30 struct m25p *flash = nor->priv;
31 @@ -152,6 +153,29 @@ static int m25p80_read(struct spi_nor *n
32 return 0;
33 }
34
35 +static int m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
36 + size_t *retlen, u_char *buf)
37 +{
38 + struct m25p *flash = nor->priv;
39 + size_t off;
40 + size_t read_len = flash->max_transfer_len;
41 + size_t part_len;
42 + int ret = 0;
43 +
44 + if (!read_len)
45 + return __m25p80_read(nor, from, len, retlen, buf);
46 +
47 + *retlen = 0;
48 +
49 + for (off = 0; off < len && !ret; off += read_len) {
50 + ret = __m25p80_read(nor, from + off, min(len - off, read_len),
51 + &part_len, buf + off);
52 + *retlen += part_len;
53 + }
54 +
55 + return ret;
56 +}
57 +
58 static int m25p80_erase(struct spi_nor *nor, loff_t offset)
59 {
60 struct m25p *flash = nor->priv;
61 @@ -223,6 +247,9 @@ static int m25p_probe(struct spi_device
62 else
63 flash_name = spi->modalias;
64
65 + if (data)
66 + flash->max_transfer_len = data->max_transfer_len;
67 +
68 ret = spi_nor_scan(nor, flash_name, mode);
69 if (ret)
70 return ret;
71 --- a/include/linux/spi/flash.h
72 +++ b/include/linux/spi/flash.h
73 @@ -13,6 +13,8 @@ struct mtd_part_parser_data;
74 * @part_probe_types: optional list of MTD parser names to use for
75 * partitioning
76 *
77 + * @max_transfer_len: option maximum read/write length limitation for
78 + * SPI controllers not able to transfer any length commands.
79 * Board init code (in arch/.../mach-xxx/board-yyy.c files) can
80 * provide information about SPI flash parts (such as DataFlash) to
81 * help set up the device and its appropriate default partitioning.
82 @@ -28,6 +30,8 @@ struct flash_platform_data {
83 char *type;
84
85 const char **part_probe_types;
86 +
87 + unsigned int max_transfer_len;
88 /* we'll likely add more ... use JEDEC IDs, etc */
89 };
90