bcm53xx: drop linux 4.4 and 4.9 support
[openwrt/staging/wigyori.git] / target / linux / brcm63xx / patches-4.4 / 000-4.8-01-mtd-spi-nor-change-return-value-of-read-write.patch
1 From 59451e1233bd315c5379a631838a03d80e689581 Mon Sep 17 00:00:00 2001
2 From: Michal Suchanek <hramrach@gmail.com>
3 Date: Thu, 5 May 2016 17:31:47 -0700
4 Subject: [PATCH 01/10] mtd: spi-nor: change return value of read/write
5
6 Change the return value of spi-nor device read and write methods to
7 allow returning amount of data transferred and errors as
8 read(2)/write(2) does.
9
10 Also, start handling positive returns in spi_nor_read(), since we want
11 to convert drivers to start returning the read-length both via *retlen
12 and the return code. (We don't need to do the same transition process
13 for spi_nor_write(), since ->write() didn't used to have a return code
14 at all.)
15
16 Signed-off-by: Michal Suchanek <hramrach@gmail.com>
17 Signed-off-by: Brian Norris <computersforpeace@gmail.com>
18 Tested-by Cyrille Pitchen <cyrille.pitchen@atmel.com>
19 Acked-by: Michal Suchanek <hramrach@gmail.com>
20 Tested-by: Michal Suchanek <hramrach@gmail.com>
21 ---
22 drivers/mtd/devices/m25p80.c | 5 +++--
23 drivers/mtd/spi-nor/fsl-quadspi.c | 5 +++--
24 drivers/mtd/spi-nor/nxp-spifi.c | 12 ++++++------
25 drivers/mtd/spi-nor/spi-nor.c | 5 ++++-
26 include/linux/mtd/spi-nor.h | 4 ++--
27 6 files changed, 36 insertions(+), 21 deletions(-)
28
29 --- a/drivers/mtd/devices/m25p80.c
30 +++ b/drivers/mtd/devices/m25p80.c
31 @@ -73,7 +73,7 @@ static int m25p80_write_reg(struct spi_n
32 return spi_write(spi, flash->command, len + 1);
33 }
34
35 -static void m25p80_write(struct spi_nor *nor, loff_t to, size_t len,
36 +static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len,
37 size_t *retlen, const u_char *buf)
38 {
39 struct m25p *flash = nor->priv;
40 @@ -101,6 +101,7 @@ static void m25p80_write(struct spi_nor
41 spi_sync(spi, &m);
42
43 *retlen += m.actual_length - cmd_sz;
44 + return 0;
45 }
46
47 static inline unsigned int m25p80_rx_nbits(struct spi_nor *nor)
48 @@ -119,7 +120,7 @@ static inline unsigned int m25p80_rx_nbi
49 * Read an address range from the nor chip. The address range
50 * may be any size provided it is within the physical boundaries.
51 */
52 -static int m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
53 +static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
54 size_t *retlen, u_char *buf)
55 {
56 struct m25p *flash = nor->priv;
57 --- a/drivers/mtd/spi-nor/fsl-quadspi.c
58 +++ b/drivers/mtd/spi-nor/fsl-quadspi.c
59 @@ -822,7 +822,7 @@ static int fsl_qspi_write_reg(struct spi
60 return ret;
61 }
62
63 -static void fsl_qspi_write(struct spi_nor *nor, loff_t to,
64 +static ssize_t fsl_qspi_write(struct spi_nor *nor, loff_t to,
65 size_t len, size_t *retlen, const u_char *buf)
66 {
67 struct fsl_qspi *q = nor->priv;
68 @@ -832,9 +832,10 @@ static void fsl_qspi_write(struct spi_no
69
70 /* invalid the data in the AHB buffer. */
71 fsl_qspi_invalid(q);
72 + return 0;
73 }
74
75 -static int fsl_qspi_read(struct spi_nor *nor, loff_t from,
76 +static ssize_t fsl_qspi_read(struct spi_nor *nor, loff_t from,
77 size_t len, size_t *retlen, u_char *buf)
78 {
79 struct fsl_qspi *q = nor->priv;
80 --- a/drivers/mtd/spi-nor/nxp-spifi.c
81 +++ b/drivers/mtd/spi-nor/nxp-spifi.c
82 @@ -172,8 +172,8 @@ static int nxp_spifi_write_reg(struct sp
83 return nxp_spifi_wait_for_cmd(spifi);
84 }
85
86 -static int nxp_spifi_read(struct spi_nor *nor, loff_t from, size_t len,
87 - size_t *retlen, u_char *buf)
88 +static ssize_t nxp_spifi_read(struct spi_nor *nor, loff_t from, size_t len,
89 + size_t *retlen, u_char *buf)
90 {
91 struct nxp_spifi *spifi = nor->priv;
92 int ret;
93 @@ -188,8 +188,8 @@ static int nxp_spifi_read(struct spi_nor
94 return 0;
95 }
96
97 -static void nxp_spifi_write(struct spi_nor *nor, loff_t to, size_t len,
98 - size_t *retlen, const u_char *buf)
99 +static ssize_t nxp_spifi_write(struct spi_nor *nor, loff_t to, size_t len,
100 + size_t *retlen, const u_char *buf)
101 {
102 struct nxp_spifi *spifi = nor->priv;
103 u32 cmd;
104 @@ -197,7 +197,7 @@ static void nxp_spifi_write(struct spi_n
105
106 ret = nxp_spifi_set_memory_mode_off(spifi);
107 if (ret)
108 - return;
109 + return ret;
110
111 writel(to, spifi->io_base + SPIFI_ADDR);
112 *retlen += len;
113 @@ -212,7 +212,7 @@ static void nxp_spifi_write(struct spi_n
114 while (len--)
115 writeb(*buf++, spifi->io_base + SPIFI_DATA);
116
117 - nxp_spifi_wait_for_cmd(spifi);
118 + return nxp_spifi_wait_for_cmd(spifi);
119 }
120
121 static int nxp_spifi_erase(struct spi_nor *nor, loff_t offs)
122 --- a/drivers/mtd/spi-nor/spi-nor.c
123 +++ b/drivers/mtd/spi-nor/spi-nor.c
124 @@ -893,7 +893,10 @@ static int spi_nor_read(struct mtd_info
125 ret = nor->read(nor, from, len, retlen, buf);
126
127 spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_READ);
128 - return ret;
129 + if (ret < 0)
130 + return ret;
131 +
132 + return 0;
133 }
134
135 static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
136 --- a/include/linux/mtd/spi-nor.h
137 +++ b/include/linux/mtd/spi-nor.h
138 @@ -169,9 +169,9 @@ struct spi_nor {
139 int (*read_reg)(struct spi_nor *nor, u8 opcode, u8 *buf, int len);
140 int (*write_reg)(struct spi_nor *nor, u8 opcode, u8 *buf, int len);
141
142 - int (*read)(struct spi_nor *nor, loff_t from,
143 + ssize_t (*read)(struct spi_nor *nor, loff_t from,
144 size_t len, size_t *retlen, u_char *read_buf);
145 - void (*write)(struct spi_nor *nor, loff_t to,
146 + ssize_t (*write)(struct spi_nor *nor, loff_t to,
147 size_t len, size_t *retlen, const u_char *write_buf);
148 int (*erase)(struct spi_nor *nor, loff_t offs);
149