0458148399f50de99037ca795c919ea7c8951b05
[openwrt/staging/linusw.git] /
1 From bc418cd2652f47a327e27f978caa3d85f9558b09 Mon Sep 17 00:00:00 2001
2 From: Brian Norris <computersforpeace@gmail.com>
3 Date: Thu, 5 May 2016 17:31:51 -0700
4 Subject: [PATCH 05/10] mtd: nxp-spifi: return amount of data transferred or
5 error in read/write
6
7 Add checking of SPI transfer errors and return them from read/write
8 functions. Also return the amount of data transferred.
9
10 Signed-off-by: Brian Norris <computersforpeace@gmail.com>
11 ---
12 drivers/mtd/spi-nor/nxp-spifi.c | 13 +++++++++----
13 1 file changed, 9 insertions(+), 4 deletions(-)
14
15 --- a/drivers/mtd/spi-nor/nxp-spifi.c
16 +++ b/drivers/mtd/spi-nor/nxp-spifi.c
17 @@ -185,7 +185,7 @@ static ssize_t nxp_spifi_read(struct spi
18 memcpy_fromio(buf, spifi->flash_base + from, len);
19 *retlen += len;
20
21 - return 0;
22 + return len;
23 }
24
25 static ssize_t nxp_spifi_write(struct spi_nor *nor, loff_t to, size_t len,
26 @@ -194,6 +194,7 @@ static ssize_t nxp_spifi_write(struct sp
27 struct nxp_spifi *spifi = nor->priv;
28 u32 cmd;
29 int ret;
30 + size_t i;
31
32 ret = nxp_spifi_set_memory_mode_off(spifi);
33 if (ret)
34 @@ -209,10 +210,14 @@ static ssize_t nxp_spifi_write(struct sp
35 SPIFI_CMD_FRAMEFORM(spifi->nor.addr_width + 1);
36 writel(cmd, spifi->io_base + SPIFI_CMD);
37
38 - while (len--)
39 - writeb(*buf++, spifi->io_base + SPIFI_DATA);
40 + for (i = 0; i < len; i++)
41 + writeb(buf[i], spifi->io_base + SPIFI_DATA);
42
43 - return nxp_spifi_wait_for_cmd(spifi);
44 + ret = nxp_spifi_wait_for_cmd(spifi);
45 + if (ret)
46 + return ret;
47 +
48 + return len;
49 }
50
51 static int nxp_spifi_erase(struct spi_nor *nor, loff_t offs)