Skip to contentSkip to conversation

mtd: rawnand: gpmi: add support for specific ECC strength

PATCH Applied Stefan Agner 3 participants 8 messages Mar 4, 2018 – Apr 22, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 mtd: rawnand: gpmi: add support for specific ECC strength

Add support for specified ECC strength/size using device tree properties nand-ecc-strength/nand-ecc-step-size.

---
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +20 -10
index 61fdd733492f..d04754289c03 100644
@@ -198,17 +198,16 @@ static inline bool gpmi_check_ecc(struct gpmi_nand_data *this)
  *
  * We may have available oob space in this case.
  */
-static int set_geometry_by_ecc_info(struct gpmi_nand_data *this)
+static int set_geometry_by_ecc_info(struct gpmi_nand_data *this,
+				    unsigned int ecc_strength,
+				    unsigned int ecc_step)
 {
 	struct bch_geometry *geo = &this->bch_geometry;
 	struct nand_chip *chip = &this->nand;
 	struct mtd_info *mtd = nand_to_mtd(chip);
 	unsigned int block_mark_bit_offset;
 
-	if (!(chip->ecc_strength_ds > 0 && chip->ecc_step_ds > 0))
-		return -EINVAL;
-
-	switch (chip->ecc_step_ds) {
+	switch (ecc_step) {
 	case SZ_512:
 		geo->gf_len = 13;
 		break;
@@ -221,8 +220,8 @@ static int set_geometry_by_ecc_info(struct gpmi_nand_data *this)
 			chip->ecc_strength_ds, chip->ecc_step_ds);
 		return -EINVAL;
 	}
-	geo->ecc_chunk_size = chip->ecc_step_ds;
-	geo->ecc_strength = round_up(chip->ecc_strength_ds, 2);
+	geo->ecc_chunk_size = ecc_step;
+	geo->ecc_strength = round_up(ecc_strength, 2);
 	if (!gpmi_check_ecc(this))
 		return -EINVAL;
 
@@ -230,7 +229,7 @@ static int set_geometry_by_ecc_info(struct gpmi_nand_data *this)
 	if (geo->ecc_chunk_size < mtd->oobsize) {
 		dev_err(this->dev,
 			"unsupported nand chip. ecc size: %d, oob size : %d\n",
-			chip->ecc_step_ds, mtd->oobsize);
+			ecc_step, mtd->oobsize);
 		return -EINVAL;
 	}
 
@@ -423,9 +422,20 @@ static int legacy_set_geometry(struct gpmi_nand_data *this)
 
 int common_nfc_set_geometry(struct gpmi_nand_data *this)
 {
+	struct nand_chip *chip = &this->nand;
+
+	if (chip->ecc.strength > 0 && chip->ecc.size > 0)
+		return set_geometry_by_ecc_info(this, chip->ecc.strength,
+						chip->ecc.size);
+
 	if ((of_property_read_bool(this->dev->of_node, "fsl,use-minimum-ecc"))
-				|| legacy_set_geometry(this))
-		return set_geometry_by_ecc_info(this);
+				|| legacy_set_geometry(this)) {
+		if (!(chip->ecc_strength_ds > 0 && chip->ecc_step_ds > 0))
+			return -EINVAL;
+
+		return set_geometry_by_ecc_info(this, chip->ecc_strength_ds,
+						chip->ecc_step_ds);
+	}
 
 	return 0;
 }
Signature · 1 line
2.16.2
#1 lore raw

PATCH v2 2/2 dt-bindings: mtd: rawnand: gpmi: document specific ECC strength

Document newly supported device tree properties nand-ecc-strength/ nand-ecc-step-size to specify ECC strength/size.

---
 Documentation/devicetree/bindings/mtd/gpmi-nand.txt | 5 +++++
 1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/mtd/gpmi-nand.txt +5 -0
index b289ef3c1b7e..393588385c6e 100644
@@ -47,6 +47,11 @@ Optional properties:
                        partitions written from Linux with this feature
                        turned on may not be accessible by the BootROM
                        code.
+  - nand-ecc-strength: integer representing the number of bits to correct
+                       per ECC step. Needs to be a multiple of 2.
+  - nand-ecc-step-size: integer representing the number of data bytes
+                       that are covered by a single ECC step. The driver
+                       supports 512 and 1024.
 
 The device tree may optionally contain sub-nodes describing partitions of the
 address space. See partition.txt for more detail.
Signature · 1 line
2.16.2
Acked-by on v2 2/2
#2 lore raw

Re: [PATCH v2 2/2] dt-bindings: mtd: rawnand: gpmi: document specific ECC strength

Quoted 15 lines · Stefan Agner

Document newly supported device tree properties nand-ecc-strength/ nand-ecc-step-size to specify ECC strength/size.

---
  Documentation/devicetree/bindings/mtd/gpmi-nand.txt | 5 +++++
  1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/mtd/gpmi-nand.txt +0 -0
index b289ef3c1b7e..393588385c6e 100644
@@ -47,6 +47,11 @@ Optional properties:
                         partitions written from Linux with this feature

Documentation/devicetree/bindings/mtd/gpmi-nand.txt Optional properties: · line 57

Quoted 10 lines
Documentation/devicetree/bindings/mtd/gpmi-nand.txt +5 -0
                         turned on may not be accessible by the BootROM
                         code.
+  - nand-ecc-strength: integer representing the number of bits to correct
+                       per ECC step. Needs to be a multiple of 2.
+  - nand-ecc-step-size: integer representing the number of data bytes
+                       that are covered by a single ECC step. The driver
+                       supports 512 and 1024.
 
  The device tree may optionally contain sub-nodes describing partitions of the
  address space. See partition.txt for more detail.
#3 lore raw
In reply to Stefan Agner

Hi,

Quoted 2 lines · On Sun, 4 Mar 2018 21:06:01 +0100 Stefan Agner <[email protected]> wrote:

Add support for specified ECC strength/size using device tree properties nand-ecc-strength/nand-ecc-step-size.

Han, we didn't hear back from you on that. Are you okay with adding these new properties? IIRC, you feared there would be a delta between u-boot and linux support.

Stephan, there's no changelog. Has anything changed in this version or is this just a RESEND?

Regards,

Boris

Quoted 75 lines
---
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +20 -10
index 61fdd733492f..d04754289c03 100644
@@ -198,17 +198,16 @@ static inline bool gpmi_check_ecc(struct gpmi_nand_data *this)
  *
  * We may have available oob space in this case.
  */
-static int set_geometry_by_ecc_info(struct gpmi_nand_data *this)
+static int set_geometry_by_ecc_info(struct gpmi_nand_data *this,
+				    unsigned int ecc_strength,
+				    unsigned int ecc_step)
 {
 	struct bch_geometry *geo = &this->bch_geometry;
 	struct nand_chip *chip = &this->nand;
 	struct mtd_info *mtd = nand_to_mtd(chip);
 	unsigned int block_mark_bit_offset;
 
-	if (!(chip->ecc_strength_ds > 0 && chip->ecc_step_ds > 0))
-		return -EINVAL;
-
-	switch (chip->ecc_step_ds) {
+	switch (ecc_step) {
 	case SZ_512:
 		geo->gf_len = 13;
 		break;
@@ -221,8 +220,8 @@ static int set_geometry_by_ecc_info(struct gpmi_nand_data *this)
 			chip->ecc_strength_ds, chip->ecc_step_ds);
 		return -EINVAL;
 	}
-	geo->ecc_chunk_size = chip->ecc_step_ds;
-	geo->ecc_strength = round_up(chip->ecc_strength_ds, 2);
+	geo->ecc_chunk_size = ecc_step;
+	geo->ecc_strength = round_up(ecc_strength, 2);
 	if (!gpmi_check_ecc(this))
 		return -EINVAL;
 
@@ -230,7 +229,7 @@ static int set_geometry_by_ecc_info(struct gpmi_nand_data *this)
 	if (geo->ecc_chunk_size < mtd->oobsize) {
 		dev_err(this->dev,
 			"unsupported nand chip. ecc size: %d, oob size : %d\n",
-			chip->ecc_step_ds, mtd->oobsize);
+			ecc_step, mtd->oobsize);
 		return -EINVAL;
 	}
 
@@ -423,9 +422,20 @@ static int legacy_set_geometry(struct gpmi_nand_data *this)
 
 int common_nfc_set_geometry(struct gpmi_nand_data *this)
 {
+	struct nand_chip *chip = &this->nand;
+
+	if (chip->ecc.strength > 0 && chip->ecc.size > 0)
+		return set_geometry_by_ecc_info(this, chip->ecc.strength,
+						chip->ecc.size);
+
 	if ((of_property_read_bool(this->dev->of_node, "fsl,use-minimum-ecc"))
-				|| legacy_set_geometry(this))
-		return set_geometry_by_ecc_info(this);
+				|| legacy_set_geometry(this)) {
+		if (!(chip->ecc_strength_ds > 0 && chip->ecc_step_ds > 0))
+			return -EINVAL;
+
+		return set_geometry_by_ecc_info(this, chip->ecc_strength_ds,
+						chip->ecc_step_ds);
+	}
 
 	return 0;
 }
Signature · 3 lines
Boris Brezillon, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com
#4 lore raw
Quoted 8 lines · Boris Brezillon

Hi,

Quoted 2 lines · On Sun, 4 Mar 2018 21:06:01 +0100 Stefan Agner <[email protected]> wrote:

Add support for specified ECC strength/size using device tree properties nand-ecc-strength/nand-ecc-step-size.

Quoted 6 lines

Han, we didn't hear back from you on that. Are you okay with adding these new properties? IIRC, you feared there would be a delta between u-boot and linux support.

Stephan, there's no changelog. Has anything changed in this version or is this just a RESEND?

Sorry forgot that. I just split documentation and driver changes.

--
Stefan

Quoted 87 lines

Regards,

Boris

Quoted 4 lines
---
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 30

++++++++++++++++++++----------

Review

Quoted 3 lines
 1 file changed, 20 insertions(+), 10 deletions(-)
(quoted diff) +0 -0

b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c

drivers/mtd/nand/gpmi-nand/gpmi-nand.c static inline bool gpmi_check_ecc(struct

Quoted 4 lines

index 61fdd733492f..d04754289c03 100644

drivers/mtd/nand/gpmi-nand/gpmi-nand.c +0 -0
@@ -198,17 +198,16 @@ static inline bool gpmi_check_ecc(struct

gpmi_nand_data *this)

drivers/mtd/nand/gpmi-nand/gpmi-nand.c static int set_geometry_by_ecc_info(struct

Quoted 22 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +4 -5
  *
  * We may have available oob space in this case.
  */
-static int set_geometry_by_ecc_info(struct gpmi_nand_data *this)
+static int set_geometry_by_ecc_info(struct gpmi_nand_data *this,
+				    unsigned int ecc_strength,
+				    unsigned int ecc_step)
 {
 	struct bch_geometry *geo = &this->bch_geometry;
 	struct nand_chip *chip = &this->nand;
 	struct mtd_info *mtd = nand_to_mtd(chip);
 	unsigned int block_mark_bit_offset;
 
-	if (!(chip->ecc_strength_ds > 0 && chip->ecc_step_ds > 0))
-		return -EINVAL;
-
-	switch (chip->ecc_step_ds) {
+	switch (ecc_step) {
 	case SZ_512:
 		geo->gf_len = 13;
 		break;
@@ -221,8 +220,8 @@ static int set_geometry_by_ecc_info(struct

gpmi_nand_data *this)

drivers/mtd/nand/gpmi-nand/gpmi-nand.c static int set_geometry_by_ecc_info(struct

Quoted 11 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +2 -2
 			chip->ecc_strength_ds, chip->ecc_step_ds);
 		return -EINVAL;
 	}
-	geo->ecc_chunk_size = chip->ecc_step_ds;
-	geo->ecc_strength = round_up(chip->ecc_strength_ds, 2);
+	geo->ecc_chunk_size = ecc_step;
+	geo->ecc_strength = round_up(ecc_strength, 2);
 	if (!gpmi_check_ecc(this))
 		return -EINVAL;
 
@@ -230,7 +229,7 @@ static int set_geometry_by_ecc_info(struct

gpmi_nand_data *this)

drivers/mtd/nand/gpmi-nand/gpmi-nand.c static int legacy_set_geometry(struct

Quoted 9 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +1 -1
 	if (geo->ecc_chunk_size < mtd->oobsize) {
 		dev_err(this->dev,
 			"unsupported nand chip. ecc size: %d, oob size : %d\n",
-			chip->ecc_step_ds, mtd->oobsize);
+			ecc_step, mtd->oobsize);
 		return -EINVAL;
 	}
 
@@ -423,9 +422,20 @@ static int legacy_set_geometry(struct

gpmi_nand_data *this)

drivers/mtd/nand/gpmi-nand/gpmi-nand.c static int legacy_set_geometry(struct gpmi_nand_data *this)

Quoted 10 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +6 -0
 int common_nfc_set_geometry(struct gpmi_nand_data *this)
 {
+	struct nand_chip *chip = &this->nand;
+
+	if (chip->ecc.strength > 0 && chip->ecc.size > 0)
+		return set_geometry_by_ecc_info(this, chip->ecc.strength,
+						chip->ecc.size);
+
 	if ((of_property_read_bool(this->dev->of_node,

"fsl,use-minimum-ecc"))

Quoted 12 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +7 -2
-				|| legacy_set_geometry(this))
-		return set_geometry_by_ecc_info(this);
+				|| legacy_set_geometry(this)) {
+		if (!(chip->ecc_strength_ds > 0 && chip->ecc_step_ds > 0))
+			return -EINVAL;
+
+		return set_geometry_by_ecc_info(this, chip->ecc_strength_ds,
+						chip->ecc_step_ds);
+	}
 
 	return 0;
 }
Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse my brevity.
#5 lore raw

Han,

Quoted 7 lines · Stefan Agner
Quoted 5 lines · Boris Brezillon

Hi,

On Sun, 4 Mar 2018 21:06:01 +0100
Stefan Agner <[email protected]> wrote:

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

Add support for specified ECC strength/size using device tree properties nand-ecc-strength/nand-ecc-step-size.

Han, we didn't hear back from you on that. Are you okay with adding these new properties? IIRC, you feared there would be a delta between u-boot and linux support.

Any comment on this?

U-Boot support for device tree support and the same properties is underway.

--
Stefan

Quoted 96 lines
Quoted 3 lines

Stephan, there's no changelog. Has anything changed in this version or is this just a RESEND?

Sorry forgot that. I just split documentation and driver changes.

--
Stefan

Quoted 87 lines

Regards,

Boris

Quoted 4 lines
---
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 30

++++++++++++++++++++----------

Review

Quoted 3 lines
 1 file changed, 20 insertions(+), 10 deletions(-)
(quoted diff) +0 -0

b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c

drivers/mtd/nand/gpmi-nand/gpmi-nand.c static inline bool gpmi_check_ecc(struct

Quoted 4 lines

index 61fdd733492f..d04754289c03 100644

drivers/mtd/nand/gpmi-nand/gpmi-nand.c +0 -0
@@ -198,17 +198,16 @@ static inline bool gpmi_check_ecc(struct

gpmi_nand_data *this)

drivers/mtd/nand/gpmi-nand/gpmi-nand.c static int set_geometry_by_ecc_info(struct

Quoted 22 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +4 -5
  *
  * We may have available oob space in this case.
  */
-static int set_geometry_by_ecc_info(struct gpmi_nand_data *this)
+static int set_geometry_by_ecc_info(struct gpmi_nand_data *this,
+				    unsigned int ecc_strength,
+				    unsigned int ecc_step)
 {
 	struct bch_geometry *geo = &this->bch_geometry;
 	struct nand_chip *chip = &this->nand;
 	struct mtd_info *mtd = nand_to_mtd(chip);
 	unsigned int block_mark_bit_offset;
 
-	if (!(chip->ecc_strength_ds > 0 && chip->ecc_step_ds > 0))
-		return -EINVAL;
-
-	switch (chip->ecc_step_ds) {
+	switch (ecc_step) {
 	case SZ_512:
 		geo->gf_len = 13;
 		break;
@@ -221,8 +220,8 @@ static int set_geometry_by_ecc_info(struct

gpmi_nand_data *this)

drivers/mtd/nand/gpmi-nand/gpmi-nand.c static int set_geometry_by_ecc_info(struct

Quoted 11 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +2 -2
 			chip->ecc_strength_ds, chip->ecc_step_ds);
 		return -EINVAL;
 	}
-	geo->ecc_chunk_size = chip->ecc_step_ds;
-	geo->ecc_strength = round_up(chip->ecc_strength_ds, 2);
+	geo->ecc_chunk_size = ecc_step;
+	geo->ecc_strength = round_up(ecc_strength, 2);
 	if (!gpmi_check_ecc(this))
 		return -EINVAL;
 
@@ -230,7 +229,7 @@ static int set_geometry_by_ecc_info(struct

gpmi_nand_data *this)

drivers/mtd/nand/gpmi-nand/gpmi-nand.c static int legacy_set_geometry(struct

Quoted 9 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +1 -1
 	if (geo->ecc_chunk_size < mtd->oobsize) {
 		dev_err(this->dev,
 			"unsupported nand chip. ecc size: %d, oob size : %d\n",
-			chip->ecc_step_ds, mtd->oobsize);
+			ecc_step, mtd->oobsize);
 		return -EINVAL;
 	}
 
@@ -423,9 +422,20 @@ static int legacy_set_geometry(struct

gpmi_nand_data *this)

drivers/mtd/nand/gpmi-nand/gpmi-nand.c static int legacy_set_geometry(struct gpmi_nand_data *this)

Quoted 10 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +6 -0
 int common_nfc_set_geometry(struct gpmi_nand_data *this)
 {
+	struct nand_chip *chip = &this->nand;
+
+	if (chip->ecc.strength > 0 && chip->ecc.size > 0)
+		return set_geometry_by_ecc_info(this, chip->ecc.strength,
+						chip->ecc.size);
+
 	if ((of_property_read_bool(this->dev->of_node,

"fsl,use-minimum-ecc"))

Quoted 12 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +7 -2
-				|| legacy_set_geometry(this))
-		return set_geometry_by_ecc_info(this);
+				|| legacy_set_geometry(this)) {
+		if (!(chip->ecc_strength_ds > 0 && chip->ecc_step_ds > 0))
+			return -EINVAL;
+
+		return set_geometry_by_ecc_info(this, chip->ecc_strength_ds,
+						chip->ecc_step_ds);
+	}
 
 	return 0;
 }
Acked-by on v2 1/2
#6 lore raw
In reply to Stefan Agner
Quoted 68 lines · Stefan Agner

Add support for specified ECC strength/size using device tree properties nand-ecc-strength/nand-ecc-step-size.

---
  drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 30 ++++++++++++++++++++----------
  1 file changed, 20 insertions(+), 10 deletions(-)
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +13 -10
index 61fdd733492f..d04754289c03 100644
@@ -198,17 +198,16 @@ static inline bool gpmi_check_ecc(struct gpmi_nand_data *this)
   *
   * We may have available oob space in this case.
   */
-static int set_geometry_by_ecc_info(struct gpmi_nand_data *this)
+static int set_geometry_by_ecc_info(struct gpmi_nand_data *this,
+				    unsigned int ecc_strength,
+				    unsigned int ecc_step)
  {
  	struct bch_geometry *geo = &this->bch_geometry;
  	struct nand_chip *chip = &this->nand;
  	struct mtd_info *mtd = nand_to_mtd(chip);
  	unsigned int block_mark_bit_offset;
 
-	if (!(chip->ecc_strength_ds > 0 && chip->ecc_step_ds > 0))
-		return -EINVAL;
-
-	switch (chip->ecc_step_ds) {
+	switch (ecc_step) {
  	case SZ_512:
  		geo->gf_len = 13;
  		break;
@@ -221,8 +220,8 @@ static int set_geometry_by_ecc_info(struct gpmi_nand_data *this)
  			chip->ecc_strength_ds, chip->ecc_step_ds);
  		return -EINVAL;
  	}
-	geo->ecc_chunk_size = chip->ecc_step_ds;
-	geo->ecc_strength = round_up(chip->ecc_strength_ds, 2);
+	geo->ecc_chunk_size = ecc_step;
+	geo->ecc_strength = round_up(ecc_strength, 2);
  	if (!gpmi_check_ecc(this))
  		return -EINVAL;
 
@@ -230,7 +229,7 @@ static int set_geometry_by_ecc_info(struct gpmi_nand_data *this)
  	if (geo->ecc_chunk_size < mtd->oobsize) {
  		dev_err(this->dev,
  			"unsupported nand chip. ecc size: %d, oob size : %d\n",
-			chip->ecc_step_ds, mtd->oobsize);
+			ecc_step, mtd->oobsize);
  		return -EINVAL;
  	}
 
@@ -423,9 +422,20 @@ static int legacy_set_geometry(struct gpmi_nand_data *this)
 
  int common_nfc_set_geometry(struct gpmi_nand_data *this)
  {
+	struct nand_chip *chip = &this->nand;
+
+	if (chip->ecc.strength > 0 && chip->ecc.size > 0)
+		return set_geometry_by_ecc_info(this, chip->ecc.strength,
+						chip->ecc.size);
+
  	if ((of_property_read_bool(this->dev->of_node, "fsl,use-minimum-ecc"))
-				|| legacy_set_geometry(this))
-		return set_geometry_by_ecc_info(this);

drivers/mtd/nand/gpmi-nand/gpmi-nand.c static int legacy_set_geometry(struct gpmi_nand_data *this) · line 441

Quoted 10 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +7 -0
+				|| legacy_set_geometry(this)) {
+		if (!(chip->ecc_strength_ds > 0 && chip->ecc_step_ds > 0))
+			return -EINVAL;
+
+		return set_geometry_by_ecc_info(this, chip->ecc_strength_ds,
+						chip->ecc_step_ds);
+	}
 
  	return 0;
  }
#7 lore raw
In reply to Stefan Agner
Quoted 4 lines · On Sun, 4 Mar 2018 21:06:01 +0100 Stefan Agner <[email protected]> wrote:

Add support for specified ECC strength/size using device tree properties nand-ecc-strength/nand-ecc-step-size.

Applied to nand/next.

Thanks,

Boris

Quoted 73 lines
---
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +20 -10
index 61fdd733492f..d04754289c03 100644
@@ -198,17 +198,16 @@ static inline bool gpmi_check_ecc(struct gpmi_nand_data *this)
  *
  * We may have available oob space in this case.
  */
-static int set_geometry_by_ecc_info(struct gpmi_nand_data *this)
+static int set_geometry_by_ecc_info(struct gpmi_nand_data *this,
+				    unsigned int ecc_strength,
+				    unsigned int ecc_step)
 {
 	struct bch_geometry *geo = &this->bch_geometry;
 	struct nand_chip *chip = &this->nand;
 	struct mtd_info *mtd = nand_to_mtd(chip);
 	unsigned int block_mark_bit_offset;
 
-	if (!(chip->ecc_strength_ds > 0 && chip->ecc_step_ds > 0))
-		return -EINVAL;
-
-	switch (chip->ecc_step_ds) {
+	switch (ecc_step) {
 	case SZ_512:
 		geo->gf_len = 13;
 		break;
@@ -221,8 +220,8 @@ static int set_geometry_by_ecc_info(struct gpmi_nand_data *this)
 			chip->ecc_strength_ds, chip->ecc_step_ds);
 		return -EINVAL;
 	}
-	geo->ecc_chunk_size = chip->ecc_step_ds;
-	geo->ecc_strength = round_up(chip->ecc_strength_ds, 2);
+	geo->ecc_chunk_size = ecc_step;
+	geo->ecc_strength = round_up(ecc_strength, 2);
 	if (!gpmi_check_ecc(this))
 		return -EINVAL;
 
@@ -230,7 +229,7 @@ static int set_geometry_by_ecc_info(struct gpmi_nand_data *this)
 	if (geo->ecc_chunk_size < mtd->oobsize) {
 		dev_err(this->dev,
 			"unsupported nand chip. ecc size: %d, oob size : %d\n",
-			chip->ecc_step_ds, mtd->oobsize);
+			ecc_step, mtd->oobsize);
 		return -EINVAL;
 	}
 
@@ -423,9 +422,20 @@ static int legacy_set_geometry(struct gpmi_nand_data *this)
 
 int common_nfc_set_geometry(struct gpmi_nand_data *this)
 {
+	struct nand_chip *chip = &this->nand;
+
+	if (chip->ecc.strength > 0 && chip->ecc.size > 0)
+		return set_geometry_by_ecc_info(this, chip->ecc.strength,
+						chip->ecc.size);
+
 	if ((of_property_read_bool(this->dev->of_node, "fsl,use-minimum-ecc"))
-				|| legacy_set_geometry(this))
-		return set_geometry_by_ecc_info(this);
+				|| legacy_set_geometry(this)) {
+		if (!(chip->ecc_strength_ds > 0 && chip->ecc_step_ds > 0))
+			return -EINVAL;
+
+		return set_geometry_by_ecc_info(this, chip->ecc_strength_ds,
+						chip->ecc_step_ds);
+	}
 
 	return 0;
 }