br2684ctl: add atm-bridge disabled option
[openwrt/svn-archive/archive.git] / target / linux / ramips / patches-3.18 / 0044-mtd-add-chunked-read-io-to-m25p80.patch
1 --- a/drivers/mtd/devices/m25p80.c
2 +++ b/drivers/mtd/devices/m25p80.c
3 @@ -19,6 +19,7 @@
4 #include <linux/errno.h>
5 #include <linux/module.h>
6 #include <linux/device.h>
7 +#include <linux/of.h>
8
9 #include <linux/mtd/mtd.h>
10 #include <linux/mtd/partitions.h>
11 @@ -32,6 +33,7 @@ struct m25p {
12 struct spi_device *spi;
13 struct spi_nor spi_nor;
14 struct mtd_info mtd;
15 + u16 chunk_size;
16 u8 command[MAX_CMD_SIZE];
17 };
18
19 @@ -117,25 +119,14 @@ static inline unsigned int m25p80_rx_nbi
20 }
21 }
22
23 -/*
24 - * Read an address range from the nor chip. The address range
25 - * may be any size provided it is within the physical boundaries.
26 - */
27 -static int m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
28 - size_t *retlen, u_char *buf)
29 +static int __m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
30 + size_t *retlen, u_char *buf)
31 {
32 struct m25p *flash = nor->priv;
33 struct spi_device *spi = flash->spi;
34 struct spi_transfer t[2];
35 struct spi_message m;
36 int dummy = nor->read_dummy;
37 - int ret;
38 -
39 - /* Wait till previous write/erase is done. */
40 - ret = nor->wait_till_ready(nor);
41 - if (ret)
42 - return ret;
43 -
44 spi_message_init(&m);
45 memset(t, 0, (sizeof t));
46
47 @@ -156,6 +147,84 @@ static int m25p80_read(struct spi_nor *n
48 *retlen = m.actual_length - m25p_cmdsz(nor) - dummy;
49 return 0;
50 }
51 +/*
52 + * Read an address range from the nor chip. The address range
53 + * may be any size provided it is within the physical boundaries.
54 + */
55 +static int m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
56 + size_t *retlen, u_char *buf)
57 +{
58 + int ret;
59 +
60 + /* Wait till previous write/erase is done. */
61 + ret = nor->wait_till_ready(nor);
62 + if (ret)
63 + return ret;
64 +
65 + return __m25p80_read(nor, from, len, retlen, buf);
66 +}
67 +
68 +
69 +static void m25p80_chunked_write(struct spi_nor *nor, loff_t _from, size_t _len,
70 + size_t *_retlen, const u_char *_buf)
71 +{
72 + struct m25p *flash = nor->priv;
73 + int chunk_size;
74 + int retlen = 0;
75 +
76 + chunk_size = flash->chunk_size;
77 + if (!chunk_size)
78 + chunk_size = _len;
79 +
80 + if (nor->addr_width > 3)
81 + chunk_size -= nor->addr_width - 3;
82 +
83 + while (retlen < _len) {
84 + size_t len = min_t(int, chunk_size, _len - retlen);
85 + const u_char *buf = _buf + retlen;
86 + loff_t from = _from + retlen;
87 +
88 + nor->wait_till_ready(nor);
89 + nor->write_reg(nor, SPINOR_OP_WREN, NULL, 0, 0);
90 +
91 + m25p80_write(nor, from, len, &retlen, buf);
92 + }
93 + *_retlen += retlen;
94 +}
95 +
96 +static int m25p80_chunked_read(struct spi_nor *nor, loff_t _from, size_t _len,
97 + size_t *_retlen, u_char *_buf)
98 +{
99 + struct m25p *flash = nor->priv;
100 + int chunk_size;
101 + int ret;
102 +
103 + /* Wait till previous write/erase is done. */
104 + ret = nor->wait_till_ready(nor);
105 + if (ret)
106 + return ret;
107 +
108 + chunk_size = flash->chunk_size;
109 + if (!chunk_size)
110 + chunk_size = _len;
111 +
112 + *_retlen = 0;
113 +
114 + while (*_retlen < _len) {
115 + size_t len = min_t(int, chunk_size, _len - *_retlen);
116 + u_char *buf = _buf + *_retlen;
117 + loff_t from = _from + *_retlen;
118 + int retlen = 0;
119 + int ret = __m25p80_read(nor, from, len, &retlen, buf);
120 +
121 + if (ret)
122 + return ret;
123 +
124 + *_retlen += retlen;
125 + }
126 +
127 + return 0;
128 +}
129
130 static int m25p80_erase(struct spi_nor *nor, loff_t offset)
131 {
132 @@ -197,6 +266,7 @@ static int m25p_probe(struct spi_device
133 struct spi_nor *nor;
134 enum read_mode mode = SPI_NOR_NORMAL;
135 char *flash_name = NULL;
136 + u32 val;
137 int ret;
138
139 data = dev_get_platdata(&spi->dev);
140 @@ -244,6 +314,14 @@ static int m25p_probe(struct spi_device
141 if (ret)
142 return ret;
143
144 + if (spi->dev.of_node &&
145 + !of_property_read_u32(spi->dev.of_node, "m25p,chunked-io", &val)) {
146 + dev_warn(&spi->dev, "using chunked io\n");
147 + nor->read = m25p80_chunked_read;
148 + nor->write = m25p80_chunked_write;
149 + flash->chunk_size = val;
150 + }
151 +
152 ppdata.of_node = spi->dev.of_node;
153
154 return mtd_device_parse_register(&flash->mtd, NULL, &ppdata,