[U-Boot] [PATCH v7 74/87] mtd: spi-nor: Add erase ops
Jagan Teki
jteki at openedev.com
Tue Mar 22 08:38:26 CET 2016
Added spi_nor erase ops for m25p80.
Cc: Simon Glass <sjg at chromium.org>
Cc: Bin Meng <bmeng.cn at gmail.com>
Cc: Mugunthan V N <mugunthanvnm at ti.com>
Cc: Michal Simek <michal.simek at xilinx.com>
Cc: Siva Durga Prasad Paladugu <sivadur at xilinx.com>
Signed-off-by: Jagan Teki <jteki at openedev.com>
---
drivers/mtd/spi-nor/m25p80.c | 27 +++++++++++++++++++++++++++
drivers/mtd/spi-nor/spi-nor.c | 2 +-
include/linux/mtd/spi-nor.h | 4 +++-
3 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/spi-nor/m25p80.c b/drivers/mtd/spi-nor/m25p80.c
index bf9fe02..cf27ba0 100644
--- a/drivers/mtd/spi-nor/m25p80.c
+++ b/drivers/mtd/spi-nor/m25p80.c
@@ -166,6 +166,32 @@ static int m25p80_write(struct spi_nor *nor, const u8 *cmd, size_t cmd_len,
return ret;
}
+static int m25p80_erase(struct spi_nor *nor, const u8 *cmd, size_t cmd_len)
+{
+ struct m25p *flash = nor->priv;
+ struct spi_slave *spi = flash->spi;
+ int ret;
+
+ ret = spi_claim_bus(spi);
+ if (ret < 0) {
+ debug("m25p80: unable to claim SPI bus\n");
+ return ret;
+ }
+
+ if (nor->flags & SNOR_F_U_PAGE)
+ spi->flags |= SPI_XFER_U_PAGE;
+
+ ret = spi_write_then_read(spi, cmd, cmd_len, NULL, NULL, 0);
+ if (ret < 0) {
+ debug("m25p80: error %d writing %x\n", ret, *cmd);
+ return ret;
+ }
+
+ spi_release_bus(spi);
+
+ return ret;
+}
+
static int m25p80_spi_nor(struct spi_nor *nor)
{
struct mtd_info *mtd = nor->mtd;
@@ -176,6 +202,7 @@ static int m25p80_spi_nor(struct spi_nor *nor)
/* install hooks */
nor->read_mmap = m25p80_read_mmap;
nor->read = m25p80_read;
+ nor->erase = m25p80_erase;
nor->write = m25p80_write;
nor->read_reg = m25p80_read_reg;
nor->write_reg = m25p80_write_reg;
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 1ee1510..befee67 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -526,7 +526,7 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
write_enable(nor);
- ret = nor->write(nor, cmd, sizeof(cmd), NULL, 0);
+ ret = nor->erase(nor, cmd, sizeof(cmd));
if (ret < 0)
goto erase_err;
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index 8b46b93..4749ff4 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -191,7 +191,8 @@ extern const struct spi_nor_info spi_nor_ids[];
* @read_mmap: [DRIVER-SPECIFIC] read data from the mmapped SPI NOR
* @read: [DRIVER-SPECIFIC] read data from the SPI NOR
* @write: [DRIVER-SPECIFIC] write data to the SPI NOR
- * @flash_lock: [FLASH-SPECIFIC] lock a region of the SPI NOR
+ * @erase: [DRIVER-SPECIFIC] erase a sector of the SPI NOR
+ * @flash_lock: [FLASH-SPECIFIC] unlock a region of the SPI NOR
* @flash_unlock: [FLASH-SPECIFIC] unlock a region of the SPI NOR
* @flash_is_locked: [FLASH-SPECIFIC] check if a region of the SPI NOR is
* @memory_map: address of read-only SPI NOR access
@@ -227,6 +228,7 @@ struct spi_nor {
void *data, size_t data_len);
int (*write)(struct spi_nor *nor, const u8 *cmd, size_t cmd_len,
const void *data, size_t data_len);
+ int (*erase)(struct spi_nor *nor, const u8 *cmd, size_t cmd_len);
int (*flash_lock)(struct spi_nor *nor, loff_t ofs, uint64_t len);
int (*flash_unlock)(struct spi_nor *nor, loff_t ofs, uint64_t len);
--
1.9.1
More information about the U-Boot
mailing list