Skip to contentSkip to conversation

mtd: nand: Add support to dedicated function to set timings

PATCH Superseded Kory Maincent 2 participants 2 messages Feb 1, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: nand: Add support to dedicated function to set timings

With the current code if the board have a NAND ONFI compliant without support to the get and set features, U-boot return an ENOTSUP error and we can not talk to the memory. Indeed onfi_set_features return ENOTSUP error if set/get features is not supported. In the case of timings we should not return ENOTSUP because we can use the default timings, the modification of the NAND timings is optional.

Fixed it by adding an intermediate nand_onfi_set_timings function which does nothing if set/get feature is not supported.

---
 drivers/mtd/nand/raw/nand_base.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)
drivers/mtd/nand/raw/nand_base.c +19 -11
index f7616985d9..44fb33776f 100644
@@ -974,6 +974,22 @@ static int nand_reset_data_interface(struct nand_chip *chip, int chipnr)
 	return ret;
 }
 
+static int nand_onfi_set_timings(struct mtd_info *mtd, struct nand_chip *chip)
+{
+	if (!chip->onfi_version ||
+	    !(le16_to_cpu(chip->onfi_params.opt_cmd)
+	      & ONFI_OPT_CMD_SET_GET_FEATURES))
+		return 0;
+
+	u8 tmode_param[ONFI_SUBFEATURE_PARAM_LEN] = {
+		chip->onfi_timing_mode_default,
+	};
+
+	return chip->onfi_set_features(mtd, chip,
+				       ONFI_FEATURE_ADDR_TIMING_MODE,
+				       tmode_param);
+}
+
 /**
  * nand_setup_data_interface - Setup the best data interface and timings
  * @chip: The NAND chip
@@ -999,17 +1015,9 @@ static int nand_setup_data_interface(struct nand_chip *chip, int chipnr)
 	 * Ensure the timing mode has been changed on the chip side
 	 * before changing timings on the controller side.
 	 */
-	if (chip->onfi_version) {
-		u8 tmode_param[ONFI_SUBFEATURE_PARAM_LEN] = {
-			chip->onfi_timing_mode_default,
-		};
-
-		ret = chip->onfi_set_features(mtd, chip,
-				ONFI_FEATURE_ADDR_TIMING_MODE,
-				tmode_param);
-		if (ret)
-			goto err;
-	}
+	ret = nand_onfi_set_timings(mtd, chip);
+	if (ret)
+		goto err;
 
 	ret = chip->setup_data_interface(mtd, chipnr, chip->data_interface);
 err:
Signature · 1 line
2.25.1
maintainer
#1 lore raw

Hi Köry,

[email protected] wrote on Tue, 1 Feb 2022 18:45:14 +0100:

Perhaps the title prefix should be "mtd: rawnand:".

I am making a number of reworking proposals below, take what you like.

Quoted 1 line

With the current code if the board have a NAND ONFI compliant without

has an ONFI compliant NAND

Quoted 1 line

support to the get and set features, U-boot return an ENOTSUP error and we

returns an ENOTSUP error
when trying to tune the timings which prevents the probe of the device.

Quoted 1 line

can not talk to the memory. Indeed onfi_set_features return ENOTSUP error

_features() returns ENOTSUP if...

Quoted 3 lines

if set/get features is not supported. In the case of timings we should not return ENOTSUP because we can use the default timings, the modification of the NAND timings is optional.

Actually it does not mean that setting the timings is optional but rather that the NAND is already capable of listening at its highest supported rate, so we assume in this case that it is fine to skip the operation. But as far as I remember the ONFI specification does not clearly state that this is a fully valid behavior.

Quoted 1 line

Fixed it by adding an intermediate nand_onfi_set_timings function which

Fix it ()

Quoted 1 line

does nothing if set/get feature is not supported.

does not error out if...

The code looks good otherwise!

Quoted 43 lines
---
 drivers/mtd/nand/raw/nand_base.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)
drivers/mtd/nand/raw/nand_base.c +16 -7
index f7616985d9..44fb33776f 100644
@@ -974,6 +974,22 @@ static int nand_reset_data_interface(struct nand_chip *chip, int chipnr)
 	return ret;
 }
 
+static int nand_onfi_set_timings(struct mtd_info *mtd, struct nand_chip *chip)
+{
+	if (!chip->onfi_version ||
+	    !(le16_to_cpu(chip->onfi_params.opt_cmd)
+	      & ONFI_OPT_CMD_SET_GET_FEATURES))
+		return 0;
+
+	u8 tmode_param[ONFI_SUBFEATURE_PARAM_LEN] = {
+		chip->onfi_timing_mode_default,
+	};
+
+	return chip->onfi_set_features(mtd, chip,
+				       ONFI_FEATURE_ADDR_TIMING_MODE,
+				       tmode_param);
+}
+
 /**
  * nand_setup_data_interface - Setup the best data interface and timings
  * @chip: The NAND chip
@@ -999,17 +1015,9 @@ static int nand_setup_data_interface(struct nand_chip *chip, int chipnr)
 	 * Ensure the timing mode has been changed on the chip side
 	 * before changing timings on the controller side.
 	 */
-	if (chip->onfi_version) {
-		u8 tmode_param[ONFI_SUBFEATURE_PARAM_LEN] = {
-			chip->onfi_timing_mode_default,
-		};
-
-		ret = chip->onfi_set_features(mtd, chip,
-				ONFI_FEATURE_ADDR_TIMING_MODE,

drivers/mtd/nand/raw/nand_base.c static int nand_setup_data_interface(struct nand_chip *chip, int chipnr) · line 1023

Quoted 10 lines
drivers/mtd/nand/raw/nand_base.c +3 -4
-				tmode_param);
-		if (ret)
-			goto err;
-	}
+	ret = nand_onfi_set_timings(mtd, chip);
+	if (ret)
+		goto err;
 
 	ret = chip->setup_data_interface(mtd, chipnr, chip->data_interface);
 err:

Thanks,
Miquèl