Commit 6bf6ec52 authored by Stefan Agner's avatar Stefan Agner Committed by Boris Brezillon

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.
Signed-off-by: default avatarStefan Agner <stefan@agner.ch>
Acked-by: default avatarHan Xu <han.xu@nxp.com>
Signed-off-by: default avatarBoris Brezillon <boris.brezillon@bootlin.com>
parent 69fb4ca0
...@@ -198,17 +198,16 @@ static inline bool gpmi_check_ecc(struct gpmi_nand_data *this) ...@@ -198,17 +198,16 @@ static inline bool gpmi_check_ecc(struct gpmi_nand_data *this)
* *
* We may have available oob space in this case. * 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 bch_geometry *geo = &this->bch_geometry;
struct nand_chip *chip = &this->nand; struct nand_chip *chip = &this->nand;
struct mtd_info *mtd = nand_to_mtd(chip); struct mtd_info *mtd = nand_to_mtd(chip);
unsigned int block_mark_bit_offset; unsigned int block_mark_bit_offset;
if (!(chip->ecc_strength_ds > 0 && chip->ecc_step_ds > 0)) switch (ecc_step) {
return -EINVAL;
switch (chip->ecc_step_ds) {
case SZ_512: case SZ_512:
geo->gf_len = 13; geo->gf_len = 13;
break; break;
...@@ -221,8 +220,8 @@ static int set_geometry_by_ecc_info(struct gpmi_nand_data *this) ...@@ -221,8 +220,8 @@ static int set_geometry_by_ecc_info(struct gpmi_nand_data *this)
chip->ecc_strength_ds, chip->ecc_step_ds); chip->ecc_strength_ds, chip->ecc_step_ds);
return -EINVAL; return -EINVAL;
} }
geo->ecc_chunk_size = chip->ecc_step_ds; geo->ecc_chunk_size = ecc_step;
geo->ecc_strength = round_up(chip->ecc_strength_ds, 2); geo->ecc_strength = round_up(ecc_strength, 2);
if (!gpmi_check_ecc(this)) if (!gpmi_check_ecc(this))
return -EINVAL; return -EINVAL;
...@@ -230,7 +229,7 @@ static int set_geometry_by_ecc_info(struct gpmi_nand_data *this) ...@@ -230,7 +229,7 @@ static int set_geometry_by_ecc_info(struct gpmi_nand_data *this)
if (geo->ecc_chunk_size < mtd->oobsize) { if (geo->ecc_chunk_size < mtd->oobsize) {
dev_err(this->dev, dev_err(this->dev,
"unsupported nand chip. ecc size: %d, oob size : %d\n", "unsupported nand chip. ecc size: %d, oob size : %d\n",
chip->ecc_step_ds, mtd->oobsize); ecc_step, mtd->oobsize);
return -EINVAL; return -EINVAL;
} }
...@@ -423,9 +422,20 @@ static int legacy_set_geometry(struct gpmi_nand_data *this) ...@@ -423,9 +422,20 @@ static int legacy_set_geometry(struct gpmi_nand_data *this)
int common_nfc_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")) if ((of_property_read_bool(this->dev->of_node, "fsl,use-minimum-ecc"))
|| legacy_set_geometry(this)) || legacy_set_geometry(this)) {
return set_geometry_by_ecc_info(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; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment