[PATCH 05/19] drivers: mtd: nand: cadence: Add support for read status command
dinesh.maniyam at intel.com
dinesh.maniyam at intel.com
Thu Sep 19 05:54:58 CEST 2024
From: Dinesh Maniyam <dinesh.maniyam at intel.com>
This patch will add support for read status command
in Cadence NAND driver. This status bit is important to check
whether the flash is write-protected.
Signed-off-by: Dinesh Maniyam <dinesh.maniyam at intel.com>
---
drivers/mtd/nand/raw/cadence_nand.c | 46 ++++++++++++++++++++++++++++-
include/cadence-nand.h | 2 ++
2 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/nand/raw/cadence_nand.c b/drivers/mtd/nand/raw/cadence_nand.c
index f9f28c392b..670f5ca184 100644
--- a/drivers/mtd/nand/raw/cadence_nand.c
+++ b/drivers/mtd/nand/raw/cadence_nand.c
@@ -343,6 +343,7 @@ static int cadence_nand_generic_cmd_send(struct cadence_nand_info *cadence,
/* Issue command. */
writel_relaxed(reg, cadence->reg + CMD_REG0);
+ cadence->buf_index = 0;
return 0;
}
@@ -1902,9 +1903,42 @@ static void cadence_nand_select_chip(struct mtd_info *mtd, int chipnr)
}
}
+static int cadence_nand_status(struct mtd_info *mtd, unsigned int command)
+{
+ struct cadence_nand_info *cadence = mtd_to_cadence(mtd);
+ int ret = 0;
+
+ ret = cadence_nand_cmd_opcode(cadence, command);
+ if (ret)
+ return ret;
+
+ ret = cadence_nand_cmd_data(cadence, 1, GCMD_DIR_READ);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
static void cadence_nand_cmdfunc(struct mtd_info *mtd, unsigned int command,
int offset_in_page, int page)
{
+ struct cadence_nand_info *cadence = mtd_to_cadence(mtd);
+ int ret = 0;
+
+ cadence->cmd = command;
+ switch (command) {
+ case NAND_CMD_STATUS:
+ ret = cadence_nand_status(mtd, command);
+ break;
+ /*
+ * ecc will override other command for read, write and erase
+ */
+ default:
+ break;
+ }
+
+ if (ret != 0)
+ printf("ERROR:%s:command:0x%x\n", __func__, cadence->cmd);
}
static int cadence_nand_dev_ready(struct mtd_info *mtd)
@@ -1921,7 +1955,17 @@ static int cadence_nand_dev_ready(struct mtd_info *mtd)
static u8 cadence_nand_read_byte(struct mtd_info *mtd)
{
- return 0;
+ struct cadence_nand_info *cadence = mtd_to_cadence(mtd);
+ u32 size = 1;
+ u8 val;
+
+ if (cadence->buf_index == 0)
+ cadence_nand_read_buf(mtd, &cadence->buf[0], size);
+
+ val = *(&cadence->buf[0] + cadence->buf_index);
+ cadence->buf_index++;
+
+ return val;
}
static void cadence_nand_write_byte(struct mtd_info *mtd, u8 byte)
diff --git a/include/cadence-nand.h b/include/cadence-nand.h
index 101f60ce0e..5b9d6e0382 100644
--- a/include/cadence-nand.h
+++ b/include/cadence-nand.h
@@ -453,6 +453,8 @@ struct cadence_nand_info {
u8 *buf;
u32 buf_size;
u8 *stat;
+ u8 cmd;
+ u32 buf_index;
u8 curr_corr_str_idx;
--
2.26.2
More information about the U-Boot
mailing list