From: Dinesh Maniyam <dinesh.mani...@intel.com>

This patch is to add support for reading param page of NAND device.
These paramaters are unique and used for identification purpose.

Signed-off-by: Dinesh Maniyam <dinesh.mani...@intel.com>
---
 drivers/mtd/nand/raw/cadence_nand.c | 30 +++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/drivers/mtd/nand/raw/cadence_nand.c 
b/drivers/mtd/nand/raw/cadence_nand.c
index 55fd3dfdb3..1b5cda1955 100644
--- a/drivers/mtd/nand/raw/cadence_nand.c
+++ b/drivers/mtd/nand/raw/cadence_nand.c
@@ -1940,6 +1940,31 @@ static int cadence_nand_readid(struct mtd_info *mtd, int 
offset_in_page, unsigne
        return 0;
 }
 
+static int cadence_nand_param(struct mtd_info *mtd, u8 offset_in_page, 
unsigned int command)
+{
+       struct cadence_nand_info *cadence = mtd_to_cadence(mtd);
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       int ret = 0;
+
+       ret = cadence_nand_cmd_opcode(cadence, command);
+       if (ret)
+               return ret;
+
+       ret = cadence_nand_cmd_address(cadence, ONE_CYCLE, &offset_in_page);
+       if (ret)
+               return ret;
+
+       ret = cadence_nand_waitfunc(mtd, chip);
+       if (ret)
+               return ret;
+
+       ret = cadence_nand_cmd_data(cadence, sizeof(struct nand_jedec_params), 
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)
 {
@@ -1956,6 +1981,9 @@ static void cadence_nand_cmdfunc(struct mtd_info *mtd, 
unsigned int command,
                ret = cadence_nand_readid(mtd, offset_in_page, command);
                break;
 
+       case NAND_CMD_PARAM:
+               ret = cadence_nand_param(mtd, offset_in_page, command);
+               break;
        /*
         * ecc will override other command for read, write and erase
         */
@@ -1988,6 +2016,8 @@ static u8 cadence_nand_read_byte(struct mtd_info *mtd)
        if (cadence->buf_index == 0) {
                if (cadence->cmd == NAND_CMD_READID)
                        size = 8;
+               else if (cadence->cmd == NAND_CMD_PARAM)
+                       size = sizeof(struct nand_jedec_params);
 
                cadence_nand_read_buf(mtd, &cadence->buf[0], size);
        }
-- 
2.26.2

Reply via email to