[PATCH v3 01/12] mtd: rawnand: turn nand_onfi_detect to use nand_device

Shivamurthy Shastri (sshivamurthy) sshivamurthy at micron.com
Mon Jun 3 05:43:23 PDT 2019


It is necessary to turn nand_onfi_detect to use nand_device structure,
to make ONFI related codes generic for all NAND devices.

Signed-off-by: Shivamurthy Shastri <sshivamurthy at micron.com>
---
 drivers/mtd/nand/raw/internals.h | 2 +-
 drivers/mtd/nand/raw/nand_base.c | 2 +-
 drivers/mtd/nand/raw/nand_onfi.c | 8 +++++---
 include/linux/mtd/rawnand.h      | 5 +++++
 4 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/nand/raw/internals.h b/drivers/mtd/nand/raw/internals.h
index cba6fe7dd8c4..4dc9ae108fa1 100644
--- a/drivers/mtd/nand/raw/internals.h
+++ b/drivers/mtd/nand/raw/internals.h
@@ -141,7 +141,7 @@ int nand_legacy_check_hooks(struct nand_chip *chip);
 
 /* ONFI functions */
 u16 onfi_crc16(u16 crc, u8 const *p, size_t len);
-int nand_onfi_detect(struct nand_chip *chip);
+int nand_onfi_detect(struct nand_device *base);
 
 /* JEDEC functions */
 int nand_jedec_detect(struct nand_chip *chip);
diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 6ecd1c496ce3..96a93481420f 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -4737,7 +4737,7 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
 
 	if (!type->name || !type->pagesize) {
 		/* Check if the chip is ONFI compliant */
-		ret = nand_onfi_detect(chip);
+		ret = nand_onfi_detect(&chip->base);
 		if (ret < 0)
 			return ret;
 		else if (ret)
diff --git a/drivers/mtd/nand/raw/nand_onfi.c b/drivers/mtd/nand/raw/nand_onfi.c
index 0b879bd0a68c..e20b60b8dd93 100644
--- a/drivers/mtd/nand/raw/nand_onfi.c
+++ b/drivers/mtd/nand/raw/nand_onfi.c
@@ -13,6 +13,7 @@
  */
 
 #include <linux/slab.h>
+#include <linux/mtd/nand.h>
 
 #include "internals.h"
 
@@ -137,9 +138,10 @@ static void nand_bit_wise_majority(const void **srcbufs,
 /*
  * Check if the NAND chip is ONFI compliant, returns 1 if it is, 0 otherwise.
  */
-int nand_onfi_detect(struct nand_chip *chip)
+int nand_onfi_detect(struct nand_device *base)
 {
-	struct mtd_info *mtd = nand_to_mtd(chip);
+	struct nand_chip *chip = device_to_nand(base);
+	struct mtd_info *mtd = &base->mtd;
 	struct nand_memory_organization *memorg;
 	struct nand_onfi_params *p;
 	struct onfi_params *onfi;
@@ -147,7 +149,7 @@ int nand_onfi_detect(struct nand_chip *chip)
 	char id[4];
 	int i, ret, val;
 
-	memorg = nanddev_get_memorg(&chip->base);
+	memorg = nanddev_get_memorg(base);
 
 	/* Try ONFI for unknown chip or LP */
 	ret = nand_readid_op(chip, 0x20, id, sizeof(id));
diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h
index f5bb6f11c36b..87282beee008 100644
--- a/include/linux/mtd/rawnand.h
+++ b/include/linux/mtd/rawnand.h
@@ -1154,6 +1154,11 @@ static inline struct mtd_info *nand_to_mtd(struct nand_chip *chip)
 	return &chip->base.mtd;
 }
 
+static inline struct nand_chip *device_to_nand(struct nand_device *base)
+{
+	return container_of(base, struct nand_chip, base);
+}
+
 static inline void *nand_get_controller_data(struct nand_chip *chip)
 {
 	return chip->priv;
-- 
2.17.1




More information about the linux-mtd mailing list