[PATCH 06/19] drivers: mtd: nand: cadence: Add support for readid command

dinesh.maniyam at intel.com dinesh.maniyam at intel.com
Thu Sep 19 05:54:59 CEST 2024


From: Dinesh Maniyam <dinesh.maniyam at intel.com>

This patch will add support for readid command in Cadence NAND driver.
The id is unique and used for flash identification.

Signed-off-by: Dinesh Maniyam <dinesh.maniyam at intel.com>
---
 drivers/mtd/nand/raw/cadence_nand.c | 32 ++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/raw/cadence_nand.c b/drivers/mtd/nand/raw/cadence_nand.c
index 670f5ca184..55fd3dfdb3 100644
--- a/drivers/mtd/nand/raw/cadence_nand.c
+++ b/drivers/mtd/nand/raw/cadence_nand.c
@@ -1919,6 +1919,27 @@ static int cadence_nand_status(struct mtd_info *mtd, unsigned int command)
 	return 0;
 }
 
+static int cadence_nand_readid(struct mtd_info *mtd, int offset_in_page, unsigned int command)
+{
+	struct cadence_nand_info *cadence = mtd_to_cadence(mtd);
+	u8 addrs = (u8)offset_in_page;
+	int ret = 0;
+
+	ret = cadence_nand_cmd_opcode(cadence, command);
+	if (ret)
+		return ret;
+
+	ret = cadence_nand_cmd_address(cadence, ONE_CYCLE, &addrs);
+	if (ret)
+		return ret;
+
+	ret = cadence_nand_cmd_data(cadence, 8, 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)
 {
@@ -1930,6 +1951,11 @@ static void cadence_nand_cmdfunc(struct mtd_info *mtd, unsigned int command,
 	case NAND_CMD_STATUS:
 		ret = cadence_nand_status(mtd, command);
 		break;
+
+	case NAND_CMD_READID:
+		ret = cadence_nand_readid(mtd, offset_in_page, command);
+		break;
+
 	/*
 	 * ecc will override other command for read, write and erase
 	 */
@@ -1959,8 +1985,12 @@ static u8 cadence_nand_read_byte(struct mtd_info *mtd)
 	u32 size = 1;
 	u8 val;
 
-	if (cadence->buf_index == 0)
+	if (cadence->buf_index == 0) {
+		if (cadence->cmd == NAND_CMD_READID)
+			size = 8;
+
 		cadence_nand_read_buf(mtd, &cadence->buf[0], size);
+	}
 
 	val = *(&cadence->buf[0] + cadence->buf_index);
 	cadence->buf_index++;
-- 
2.26.2



More information about the U-Boot mailing list