[PATCH 1/2] mtd: rawnand: Use the ->init_data_interface() hook

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Rickard x Andersson <rickaran@xxxxxxxx>

Check if the NAND vendor provided hook works and check that
the NAND controller can handle the timings.

Signed-off-by: Rickard x Andersson <rickaran@xxxxxxxx>
---
 drivers/mtd/nand/raw/nand_base.c | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 8744f0033f78..974050a04f23 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -955,6 +955,30 @@ static int nand_setup_data_interface(struct nand_chip *chip, int chipnr)
 	return ret;
 }
 
+static int nand_try_init_data_interface(struct nand_chip *chip)
+{
+	int ret = chip->ops.init_data_interface(chip);
+
+	if (!ret) {
+		/*
+		 * Pass NAND_DATA_IFACE_CHECK_ONLY to only check if the
+		 * controller supports the requested timings.
+		 */
+		ret = chip->controller->ops->setup_data_interface(chip,
+						 NAND_DATA_IFACE_CHECK_ONLY,
+						 &chip->data_interface);
+	}
+
+	if (ret) {
+		/* The provided data interface timings did not work */
+		chip->ops.init_data_interface = NULL;
+		memset(&chip->data_interface, 0,
+		       sizeof(struct nand_data_interface));
+	}
+
+	return ret;
+}
+
 /**
  * nand_choose_data_interface - find the best data interface and timings
  * @chip: The NAND chip
@@ -980,8 +1004,11 @@ static int nand_choose_data_interface(struct nand_chip *chip)
 	 * ->init_data_interface() is expected to update the entire chip's
 	 * nand_data_interface structure.
 	 */
-	if (nand_has_init_data_interface(chip))
-		return chip->ops.init_data_interface(chip);
+	if (nand_has_init_data_interface(chip)) {
+		ret = nand_try_init_data_interface(chip);
+		if (!ret)
+			return 0;
+	}
 
 	/*
 	 * First try to identify the best timings from ONFI parameters and
-- 
2.11.0


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux