[U-Boot] [PATCH v1 4/9] mtd: nand: mxs_nand: add use_minimum_ecc to struct

Stefan Agner stefan at agner.ch
Fri Apr 20 15:53:09 UTC 2018


From: Stefan Agner <stefan.agner at toradex.com>

Add use_minimum_ecc as struct mxs_nand_info field in preparation
for device tree support.

Signed-off-by: Stefan Agner <stefan.agner at toradex.com>
---

 drivers/mtd/nand/mxs_nand.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/drivers/mtd/nand/mxs_nand.c b/drivers/mtd/nand/mxs_nand.c
index b5fd0fdd62..978f6a6893 100644
--- a/drivers/mtd/nand/mxs_nand.c
+++ b/drivers/mtd/nand/mxs_nand.c
@@ -70,6 +70,8 @@ struct bch_geometry {
 
 struct mxs_nand_info {
 	struct nand_chip chip;
+	unsigned int	max_ecc_strength_supported;
+	bool		use_minimum_ecc;
 	int		cur_chip;
 
 	uint32_t	cmd_queue_len;
@@ -214,19 +216,11 @@ static inline int mxs_nand_calc_mark_offset(struct bch_geometry *geo,
 	return 0;
 }
 
-static inline unsigned int mxs_nand_max_ecc_strength_supported(void)
-{
-	/* Refer to Chapter 17 for i.MX6DQ, Chapter 18 for i.MX6SX */
-	if (is_mx6sx() || is_mx7())
-		return 62;
-	else
-		return 40;
-}
-
 static inline int mxs_nand_calc_ecc_layout_by_info(struct bch_geometry *geo,
 						   struct mtd_info *mtd)
 {
 	struct nand_chip *chip = mtd_to_nand(mtd);
+	struct mxs_nand_info *nand_info = nand_get_controller_data(chip);
 
 	if (!(chip->ecc_strength_ds > 0 && chip->ecc_step_ds > 0))
 		return -ENOTSUPP;
@@ -249,7 +243,7 @@ static inline int mxs_nand_calc_ecc_layout_by_info(struct bch_geometry *geo,
 	if (geo->ecc_chunk_size < mtd->oobsize)
 		return -EINVAL;
 
-	if (geo->ecc_strength > mxs_nand_max_ecc_strength_supported())
+	if (geo->ecc_strength > nand_info->max_ecc_strength_supported)
 		return -EINVAL;
 
 	geo->ecc_chunk_count = mtd->writesize / geo->ecc_chunk_size;
@@ -260,6 +254,9 @@ static inline int mxs_nand_calc_ecc_layout_by_info(struct bch_geometry *geo,
 static inline int mxs_nand_calc_ecc_layout(struct bch_geometry *geo,
 					   struct mtd_info *mtd)
 {
+	struct nand_chip *chip = mtd_to_nand(mtd);
+	struct mxs_nand_info *nand_info = nand_get_controller_data(chip);
+
 	/* The default for the length of Galois Field. */
 	geo->gf_len = 13;
 
@@ -291,7 +288,7 @@ static inline int mxs_nand_calc_ecc_layout(struct bch_geometry *geo,
 			/ (geo->gf_len * geo->ecc_chunk_count);
 
 	geo->ecc_strength = min(round_down(geo->ecc_strength, 2),
-				mxs_nand_max_ecc_strength_supported());
+				nand_info->max_ecc_strength_supported);
 
 	return 0;
 }
@@ -1041,9 +1038,8 @@ static int mxs_nand_setup_ecc(struct mtd_info *mtd)
 	uint32_t tmp;
 	int ret = -ENOTSUPP;
 
-#ifdef CONFIG_NAND_MXS_USE_MINIMUM_ECC
-	ret = mxs_nand_calc_ecc_layout_by_info(geo, mtd);
-#endif
+	if (nand_info->use_minimum_ecc)
+		ret = mxs_nand_calc_ecc_layout_by_info(geo, mtd);
 
 	if (ret == -ENOTSUPP)
 		ret = mxs_nand_calc_ecc_layout(geo, mtd);
@@ -1279,5 +1275,15 @@ void board_nand_init(void)
 	nand_info->gpmi_regs = (struct mxs_gpmi_regs *)MXS_GPMI_BASE;
 	nand_info->bch_regs = (struct mxs_bch_regs *)MXS_BCH_BASE;
 
+	/* Refer to Chapter 17 for i.MX6DQ, Chapter 18 for i.MX6SX */
+	if (is_mx6sx() || is_mx7())
+		nand_info->max_ecc_strength_supported = 62;
+	else
+		nand_info->max_ecc_strength_supported = 40;
+
+#ifdef CONFIG_NAND_MXS_USE_MINIMUM_ECC
+	nand_info->use_minimum_ecc = true;
+#endif
+
 	mxs_nand_init(nand_info);
 }
-- 
2.17.0



More information about the U-Boot mailing list