Commit 59451e12 authored by Michal Suchanek's avatar Michal Suchanek Committed by Brian Norris

mtd: spi-nor: change return value of read/write

Change the return value of spi-nor device read and write methods to
allow returning amount of data transferred and errors as
read(2)/write(2) does.

Also, start handling positive returns in spi_nor_read(), since we want
to convert drivers to start returning the read-length both via *retlen
and the return code. (We don't need to do the same transition process
for spi_nor_write(), since ->write() didn't used to have a return code
at all.)
Signed-off-by: default avatarMichal Suchanek <hramrach@gmail.com>
Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
Tested-by Cyrille Pitchen <cyrille.pitchen@atmel.com>
Acked-by: default avatarMichal Suchanek <hramrach@gmail.com>
Tested-by: default avatarMichal Suchanek <hramrach@gmail.com>
parent becc7ae5
...@@ -73,7 +73,7 @@ static int m25p80_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len) ...@@ -73,7 +73,7 @@ static int m25p80_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len)
return spi_write(spi, flash->command, len + 1); return spi_write(spi, flash->command, len + 1);
} }
static void m25p80_write(struct spi_nor *nor, loff_t to, size_t len, static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len,
size_t *retlen, const u_char *buf) size_t *retlen, const u_char *buf)
{ {
struct m25p *flash = nor->priv; struct m25p *flash = nor->priv;
...@@ -101,6 +101,7 @@ static void m25p80_write(struct spi_nor *nor, loff_t to, size_t len, ...@@ -101,6 +101,7 @@ static void m25p80_write(struct spi_nor *nor, loff_t to, size_t len,
spi_sync(spi, &m); spi_sync(spi, &m);
*retlen += m.actual_length - cmd_sz; *retlen += m.actual_length - cmd_sz;
return 0;
} }
static inline unsigned int m25p80_rx_nbits(struct spi_nor *nor) static inline unsigned int m25p80_rx_nbits(struct spi_nor *nor)
...@@ -119,7 +120,7 @@ static inline unsigned int m25p80_rx_nbits(struct spi_nor *nor) ...@@ -119,7 +120,7 @@ static inline unsigned int m25p80_rx_nbits(struct spi_nor *nor)
* Read an address range from the nor chip. The address range * Read an address range from the nor chip. The address range
* may be any size provided it is within the physical boundaries. * may be any size provided it is within the physical boundaries.
*/ */
static int m25p80_read(struct spi_nor *nor, loff_t from, size_t len, static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
size_t *retlen, u_char *buf) size_t *retlen, u_char *buf)
{ {
struct m25p *flash = nor->priv; struct m25p *flash = nor->priv;
......
...@@ -868,7 +868,7 @@ static int fsl_qspi_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len) ...@@ -868,7 +868,7 @@ static int fsl_qspi_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len)
return ret; return ret;
} }
static void fsl_qspi_write(struct spi_nor *nor, loff_t to, static ssize_t fsl_qspi_write(struct spi_nor *nor, loff_t to,
size_t len, size_t *retlen, const u_char *buf) size_t len, size_t *retlen, const u_char *buf)
{ {
struct fsl_qspi *q = nor->priv; struct fsl_qspi *q = nor->priv;
...@@ -878,9 +878,10 @@ static void fsl_qspi_write(struct spi_nor *nor, loff_t to, ...@@ -878,9 +878,10 @@ static void fsl_qspi_write(struct spi_nor *nor, loff_t to,
/* invalid the data in the AHB buffer. */ /* invalid the data in the AHB buffer. */
fsl_qspi_invalid(q); fsl_qspi_invalid(q);
return 0;
} }
static int fsl_qspi_read(struct spi_nor *nor, loff_t from, static ssize_t fsl_qspi_read(struct spi_nor *nor, loff_t from,
size_t len, size_t *retlen, u_char *buf) size_t len, size_t *retlen, u_char *buf)
{ {
struct fsl_qspi *q = nor->priv; struct fsl_qspi *q = nor->priv;
......
...@@ -243,8 +243,8 @@ static void mt8173_nor_set_addr(struct mt8173_nor *mt8173_nor, u32 addr) ...@@ -243,8 +243,8 @@ static void mt8173_nor_set_addr(struct mt8173_nor *mt8173_nor, u32 addr)
writeb(addr & 0xff, mt8173_nor->base + MTK_NOR_RADR3_REG); writeb(addr & 0xff, mt8173_nor->base + MTK_NOR_RADR3_REG);
} }
static int mt8173_nor_read(struct spi_nor *nor, loff_t from, size_t length, static ssize_t mt8173_nor_read(struct spi_nor *nor, loff_t from, size_t length,
size_t *retlen, u_char *buffer) size_t *retlen, u_char *buffer)
{ {
int i, ret; int i, ret;
int addr = (int)from; int addr = (int)from;
...@@ -297,36 +297,46 @@ static int mt8173_nor_write_buffer(struct mt8173_nor *mt8173_nor, int addr, ...@@ -297,36 +297,46 @@ static int mt8173_nor_write_buffer(struct mt8173_nor *mt8173_nor, int addr,
return mt8173_nor_execute_cmd(mt8173_nor, MTK_NOR_WR_CMD); return mt8173_nor_execute_cmd(mt8173_nor, MTK_NOR_WR_CMD);
} }
static void mt8173_nor_write(struct spi_nor *nor, loff_t to, size_t len, static ssize_t mt8173_nor_write(struct spi_nor *nor, loff_t to, size_t len,
size_t *retlen, const u_char *buf) size_t *retlen, const u_char *buf)
{ {
int ret; int ret;
struct mt8173_nor *mt8173_nor = nor->priv; struct mt8173_nor *mt8173_nor = nor->priv;
ret = mt8173_nor_write_buffer_enable(mt8173_nor); ret = mt8173_nor_write_buffer_enable(mt8173_nor);
if (ret < 0) if (ret < 0) {
dev_warn(mt8173_nor->dev, "write buffer enable failed!\n"); dev_warn(mt8173_nor->dev, "write buffer enable failed!\n");
return ret;
}
while (len >= SFLASH_WRBUF_SIZE) { while (len >= SFLASH_WRBUF_SIZE) {
ret = mt8173_nor_write_buffer(mt8173_nor, to, buf); ret = mt8173_nor_write_buffer(mt8173_nor, to, buf);
if (ret < 0) if (ret < 0) {
dev_err(mt8173_nor->dev, "write buffer failed!\n"); dev_err(mt8173_nor->dev, "write buffer failed!\n");
return ret;
}
len -= SFLASH_WRBUF_SIZE; len -= SFLASH_WRBUF_SIZE;
to += SFLASH_WRBUF_SIZE; to += SFLASH_WRBUF_SIZE;
buf += SFLASH_WRBUF_SIZE; buf += SFLASH_WRBUF_SIZE;
(*retlen) += SFLASH_WRBUF_SIZE; (*retlen) += SFLASH_WRBUF_SIZE;
} }
ret = mt8173_nor_write_buffer_disable(mt8173_nor); ret = mt8173_nor_write_buffer_disable(mt8173_nor);
if (ret < 0) if (ret < 0) {
dev_warn(mt8173_nor->dev, "write buffer disable failed!\n"); dev_warn(mt8173_nor->dev, "write buffer disable failed!\n");
return ret;
}
if (len) { if (len) {
ret = mt8173_nor_write_single_byte(mt8173_nor, to, (int)len, ret = mt8173_nor_write_single_byte(mt8173_nor, to, (int)len,
(u8 *)buf); (u8 *)buf);
if (ret < 0) if (ret < 0) {
dev_err(mt8173_nor->dev, "write single byte failed!\n"); dev_err(mt8173_nor->dev, "write single byte failed!\n");
return ret;
}
(*retlen) += len; (*retlen) += len;
} }
return 0;
} }
static int mt8173_nor_read_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len) static int mt8173_nor_read_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len)
......
...@@ -172,8 +172,8 @@ static int nxp_spifi_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len) ...@@ -172,8 +172,8 @@ static int nxp_spifi_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len)
return nxp_spifi_wait_for_cmd(spifi); return nxp_spifi_wait_for_cmd(spifi);
} }
static int nxp_spifi_read(struct spi_nor *nor, loff_t from, size_t len, static ssize_t nxp_spifi_read(struct spi_nor *nor, loff_t from, size_t len,
size_t *retlen, u_char *buf) size_t *retlen, u_char *buf)
{ {
struct nxp_spifi *spifi = nor->priv; struct nxp_spifi *spifi = nor->priv;
int ret; int ret;
...@@ -188,8 +188,8 @@ static int nxp_spifi_read(struct spi_nor *nor, loff_t from, size_t len, ...@@ -188,8 +188,8 @@ static int nxp_spifi_read(struct spi_nor *nor, loff_t from, size_t len,
return 0; return 0;
} }
static void nxp_spifi_write(struct spi_nor *nor, loff_t to, size_t len, static ssize_t nxp_spifi_write(struct spi_nor *nor, loff_t to, size_t len,
size_t *retlen, const u_char *buf) size_t *retlen, const u_char *buf)
{ {
struct nxp_spifi *spifi = nor->priv; struct nxp_spifi *spifi = nor->priv;
u32 cmd; u32 cmd;
...@@ -197,7 +197,7 @@ static void nxp_spifi_write(struct spi_nor *nor, loff_t to, size_t len, ...@@ -197,7 +197,7 @@ static void nxp_spifi_write(struct spi_nor *nor, loff_t to, size_t len,
ret = nxp_spifi_set_memory_mode_off(spifi); ret = nxp_spifi_set_memory_mode_off(spifi);
if (ret) if (ret)
return; return ret;
writel(to, spifi->io_base + SPIFI_ADDR); writel(to, spifi->io_base + SPIFI_ADDR);
*retlen += len; *retlen += len;
...@@ -212,7 +212,7 @@ static void nxp_spifi_write(struct spi_nor *nor, loff_t to, size_t len, ...@@ -212,7 +212,7 @@ static void nxp_spifi_write(struct spi_nor *nor, loff_t to, size_t len,
while (len--) while (len--)
writeb(*buf++, spifi->io_base + SPIFI_DATA); writeb(*buf++, spifi->io_base + SPIFI_DATA);
nxp_spifi_wait_for_cmd(spifi); return nxp_spifi_wait_for_cmd(spifi);
} }
static int nxp_spifi_erase(struct spi_nor *nor, loff_t offs) static int nxp_spifi_erase(struct spi_nor *nor, loff_t offs)
......
...@@ -1034,7 +1034,10 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -1034,7 +1034,10 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
ret = nor->read(nor, from, len, retlen, buf); ret = nor->read(nor, from, len, retlen, buf);
spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_READ); spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_READ);
return ret; if (ret < 0)
return ret;
return 0;
} }
static int sst_write(struct mtd_info *mtd, loff_t to, size_t len, static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
......
...@@ -173,9 +173,9 @@ struct spi_nor { ...@@ -173,9 +173,9 @@ struct spi_nor {
int (*read_reg)(struct spi_nor *nor, u8 opcode, u8 *buf, int len); int (*read_reg)(struct spi_nor *nor, u8 opcode, u8 *buf, int len);
int (*write_reg)(struct spi_nor *nor, u8 opcode, u8 *buf, int len); int (*write_reg)(struct spi_nor *nor, u8 opcode, u8 *buf, int len);
int (*read)(struct spi_nor *nor, loff_t from, ssize_t (*read)(struct spi_nor *nor, loff_t from,
size_t len, size_t *retlen, u_char *read_buf); size_t len, size_t *retlen, u_char *read_buf);
void (*write)(struct spi_nor *nor, loff_t to, ssize_t (*write)(struct spi_nor *nor, loff_t to,
size_t len, size_t *retlen, const u_char *write_buf); size_t len, size_t *retlen, const u_char *write_buf);
int (*erase)(struct spi_nor *nor, loff_t offs); int (*erase)(struct spi_nor *nor, loff_t offs);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment