brcm63xx: enhance dt partitions support to match upstream more closely
[openwrt/openwrt.git] / target / linux / brcm63xx / patches-4.4 / 000-4.8-07-mtd-spi-nor-stop-passing-around-retlen.patch
1 From 2dd087b16946cf168f401526adf26afa771bb740 Mon Sep 17 00:00:00 2001
2 From: Michal Suchanek <hramrach@gmail.com>
3 Date: Thu, 5 May 2016 17:31:53 -0700
4 Subject: [PATCH 07/10] mtd: spi-nor: stop passing around retlen
5
6 Do not pass retlen to hardware driver read/write functions. Update it in
7 spi-nor generic driver instead.
8
9 Signed-off-by: Michal Suchanek <hramrach@gmail.com>
10 Signed-off-by: Brian Norris <computersforpeace@gmail.com>
11 Tested-by Cyrille Pitchen <cyrille.pitchen@atmel.com>
12 Acked-by: Michal Suchanek <hramrach@gmail.com>
13 Tested-by: Michal Suchanek <hramrach@gmail.com>
14 ---
15 drivers/mtd/devices/m25p80.c | 7 ++-----
16 drivers/mtd/spi-nor/fsl-quadspi.c | 17 ++++++-----------
17 drivers/mtd/spi-nor/nxp-spifi.c | 6 ++----
18 drivers/mtd/spi-nor/spi-nor.c | 21 +++++++++++++--------
19 include/linux/mtd/spi-nor.h | 4 ++--
20 6 files changed, 28 insertions(+), 35 deletions(-)
21
22 --- a/drivers/mtd/devices/m25p80.c
23 +++ b/drivers/mtd/devices/m25p80.c
24 @@ -74,7 +74,7 @@ static int m25p80_write_reg(struct spi_n
25 }
26
27 static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len,
28 - size_t *retlen, const u_char *buf)
29 + const u_char *buf)
30 {
31 struct m25p *flash = nor->priv;
32 struct spi_device *spi = flash->spi;
33 @@ -106,7 +106,6 @@ static ssize_t m25p80_write(struct spi_n
34 ret = m.actual_length - cmd_sz;
35 if (ret < 0)
36 return -EIO;
37 - *retlen += ret;
38 return ret;
39 }
40
41 @@ -127,7 +126,7 @@ static inline unsigned int m25p80_rx_nbi
42 * may be any size provided it is within the physical boundaries.
43 */
44 static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
45 - size_t *retlen, u_char *buf)
46 + u_char *buf)
47 {
48 struct m25p *flash = nor->priv;
49 struct spi_device *spi = flash->spi;
50 @@ -156,7 +155,6 @@ static ssize_t m25p80_read(struct spi_no
51 msg.data_nbits = m25p80_rx_nbits(nor);
52
53 ret = spi_flash_read(spi, &msg);
54 - *retlen = msg.retlen;
55 if (ret < 0)
56 return ret;
57 return msg.retlen;
58 @@ -184,7 +182,6 @@ static ssize_t m25p80_read(struct spi_no
59 ret = m.actual_length - m25p_cmdsz(nor) - dummy;
60 if (ret < 0)
61 return -EIO;
62 - *retlen += ret;
63 return ret;
64 }
65
66 --- a/drivers/mtd/spi-nor/fsl-quadspi.c
67 +++ b/drivers/mtd/spi-nor/fsl-quadspi.c
68 @@ -577,7 +577,7 @@ static inline void fsl_qspi_invalid(stru
69
70 static ssize_t fsl_qspi_nor_write(struct fsl_qspi *q, struct spi_nor *nor,
71 u8 opcode, unsigned int to, u32 *txbuf,
72 - unsigned count, size_t *retlen)
73 + unsigned count)
74 {
75 int ret, i, j;
76 u32 tmp;
77 @@ -604,11 +604,8 @@ static ssize_t fsl_qspi_nor_write(struct
78 /* Trigger it */
79 ret = fsl_qspi_runcmd(q, opcode, to, count);
80
81 - if (ret == 0) {
82 - if (retlen)
83 - *retlen += count;
84 + if (ret == 0)
85 return count;
86 - }
87
88 return ret;
89 }
90 @@ -816,7 +813,7 @@ static int fsl_qspi_write_reg(struct spi
91
92 } else if (len > 0) {
93 ret = fsl_qspi_nor_write(q, nor, opcode, 0,
94 - (u32 *)buf, len, NULL);
95 + (u32 *)buf, len);
96 if (ret > 0)
97 return 0;
98 } else {
99 @@ -828,12 +825,11 @@ static int fsl_qspi_write_reg(struct spi
100 }
101
102 static ssize_t fsl_qspi_write(struct spi_nor *nor, loff_t to,
103 - size_t len, size_t *retlen, const u_char *buf)
104 + size_t len, const u_char *buf)
105 {
106 struct fsl_qspi *q = nor->priv;
107 -
108 ssize_t ret = fsl_qspi_nor_write(q, nor, nor->program_opcode, to,
109 - (u32 *)buf, len, retlen);
110 + (u32 *)buf, len);
111
112 /* invalid the data in the AHB buffer. */
113 fsl_qspi_invalid(q);
114 @@ -841,7 +837,7 @@ static ssize_t fsl_qspi_write(struct spi
115 }
116
117 static ssize_t fsl_qspi_read(struct spi_nor *nor, loff_t from,
118 - size_t len, size_t *retlen, u_char *buf)
119 + size_t len, u_char *buf)
120 {
121 struct fsl_qspi *q = nor->priv;
122 u8 cmd = nor->read_opcode;
123 @@ -883,7 +879,6 @@ static ssize_t fsl_qspi_read(struct spi_
124 memcpy(buf, q->ahb_addr + q->chip_base_addr + from - q->memmap_offs,
125 len);
126
127 - *retlen += len;
128 return len;
129 }
130
131 --- a/drivers/mtd/spi-nor/nxp-spifi.c
132 +++ b/drivers/mtd/spi-nor/nxp-spifi.c
133 @@ -173,7 +173,7 @@ static int nxp_spifi_write_reg(struct sp
134 }
135
136 static ssize_t nxp_spifi_read(struct spi_nor *nor, loff_t from, size_t len,
137 - size_t *retlen, u_char *buf)
138 + u_char *buf)
139 {
140 struct nxp_spifi *spifi = nor->priv;
141 int ret;
142 @@ -183,13 +183,12 @@ static ssize_t nxp_spifi_read(struct spi
143 return ret;
144
145 memcpy_fromio(buf, spifi->flash_base + from, len);
146 - *retlen += len;
147
148 return len;
149 }
150
151 static ssize_t nxp_spifi_write(struct spi_nor *nor, loff_t to, size_t len,
152 - size_t *retlen, const u_char *buf)
153 + const u_char *buf)
154 {
155 struct nxp_spifi *spifi = nor->priv;
156 u32 cmd;
157 @@ -201,7 +200,6 @@ static ssize_t nxp_spifi_write(struct sp
158 return ret;
159
160 writel(to, spifi->io_base + SPIFI_ADDR);
161 - *retlen += len;
162
163 cmd = SPIFI_CMD_DOUT |
164 SPIFI_CMD_DATALEN(len) |
165 --- a/drivers/mtd/spi-nor/spi-nor.c
166 +++ b/drivers/mtd/spi-nor/spi-nor.c
167 @@ -890,12 +890,13 @@ static int spi_nor_read(struct mtd_info
168 if (ret)
169 return ret;
170
171 - ret = nor->read(nor, from, len, retlen, buf);
172 + ret = nor->read(nor, from, len, buf);
173
174 spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_READ);
175 if (ret < 0)
176 return ret;
177
178 + *retlen += ret;
179 return 0;
180 }
181
182 @@ -922,7 +923,7 @@ static int sst_write(struct mtd_info *mt
183 nor->program_opcode = SPINOR_OP_BP;
184
185 /* write one byte. */
186 - ret = nor->write(nor, to, 1, retlen, buf);
187 + ret = nor->write(nor, to, 1, buf);
188 if (ret < 0)
189 goto sst_write_err;
190 WARN(ret != 1, "While writing 1 byte written %i bytes\n",
191 @@ -938,7 +939,7 @@ static int sst_write(struct mtd_info *mt
192 nor->program_opcode = SPINOR_OP_AAI_WP;
193
194 /* write two bytes. */
195 - ret = nor->write(nor, to, 2, retlen, buf + actual);
196 + ret = nor->write(nor, to, 2, buf + actual);
197 if (ret < 0)
198 goto sst_write_err;
199 WARN(ret != 2, "While writing 2 bytes written %i bytes\n",
200 @@ -961,7 +962,7 @@ static int sst_write(struct mtd_info *mt
201 write_enable(nor);
202
203 nor->program_opcode = SPINOR_OP_BP;
204 - ret = nor->write(nor, to, 1, retlen, buf + actual);
205 + ret = nor->write(nor, to, 1, buf + actual);
206 if (ret < 0)
207 goto sst_write_err;
208 WARN(ret != 1, "While writing 1 byte written %i bytes\n",
209 @@ -970,8 +971,10 @@ static int sst_write(struct mtd_info *mt
210 if (ret)
211 goto sst_write_err;
212 write_disable(nor);
213 + actual += 1;
214 }
215 sst_write_err:
216 + *retlen += actual;
217 spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_WRITE);
218 return ret;
219 }
220 @@ -1000,15 +1003,17 @@ static int spi_nor_write(struct mtd_info
221
222 /* do all the bytes fit onto one page? */
223 if (page_offset + len <= nor->page_size) {
224 - ret = nor->write(nor, to, len, retlen, buf);
225 + ret = nor->write(nor, to, len, buf);
226 if (ret < 0)
227 goto write_err;
228 + *retlen += ret;
229 } else {
230 /* the size of data remaining on the first page */
231 page_size = nor->page_size - page_offset;
232 - ret = nor->write(nor, to, page_size, retlen, buf);
233 + ret = nor->write(nor, to, page_size, buf);
234 if (ret < 0)
235 goto write_err;
236 + *retlen += ret;
237
238 /* write everything in nor->page_size chunks */
239 for (i = ret; i < len; ) {
240 @@ -1022,10 +1027,10 @@ static int spi_nor_write(struct mtd_info
241
242 write_enable(nor);
243
244 - ret = nor->write(nor, to + i, page_size, retlen,
245 - buf + i);
246 + ret = nor->write(nor, to + i, page_size, buf + i);
247 if (ret < 0)
248 goto write_err;
249 + *retlen += ret;
250 i += ret;
251 }
252 }
253 --- a/include/linux/mtd/spi-nor.h
254 +++ b/include/linux/mtd/spi-nor.h
255 @@ -170,9 +170,9 @@ struct spi_nor {
256 int (*write_reg)(struct spi_nor *nor, u8 opcode, u8 *buf, int len);
257
258 ssize_t (*read)(struct spi_nor *nor, loff_t from,
259 - size_t len, size_t *retlen, u_char *read_buf);
260 + size_t len, u_char *read_buf);
261 ssize_t (*write)(struct spi_nor *nor, loff_t to,
262 - size_t len, size_t *retlen, const u_char *write_buf);
263 + size_t len, const u_char *write_buf);
264 int (*erase)(struct spi_nor *nor, loff_t offs);
265
266 int (*flash_lock)(struct spi_nor *nor, loff_t ofs, uint64_t len);