Commit 0cf5c7db authored by Abhishek Sahu's avatar Abhishek Sahu Committed by Miquel Raynal

mtd: rawnand: provide only single helper function for ECC conf

Function nand_ecc_choose_conf() will be help for all the cases, so
other helper functions can be made static.

nand_check_ecc_caps(): Invoke nand_ecc_choose_conf() with
                       both chip->ecc.size and chip->ecc.strength
                       value set.

nand_maximize_ecc(): Invoke nand_ecc_choose_conf() with
                     NAND_ECC_MAXIMIZE flag.

nand_match_ecc_req(): Invoke nand_ecc_choose_conf() with either
                      chip->ecc.size or chip->ecc.strength value
                      set and without NAND_ECC_MAXIMIZE flag.

CC: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: default avatarAbhishek Sahu <absahu@codeaurora.org>
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
parent 85632c17
...@@ -6085,24 +6085,17 @@ static int nand_set_ecc_soft_ops(struct mtd_info *mtd) ...@@ -6085,24 +6085,17 @@ static int nand_set_ecc_soft_ops(struct mtd_info *mtd)
* by the controller and the calculated ECC bytes fit within the chip's OOB. * by the controller and the calculated ECC bytes fit within the chip's OOB.
* On success, the calculated ECC bytes is set. * On success, the calculated ECC bytes is set.
*/ */
int nand_check_ecc_caps(struct nand_chip *chip, static int
nand_check_ecc_caps(struct nand_chip *chip,
const struct nand_ecc_caps *caps, int oobavail) const struct nand_ecc_caps *caps, int oobavail)
{ {
struct mtd_info *mtd = nand_to_mtd(chip); struct mtd_info *mtd = nand_to_mtd(chip);
const struct nand_ecc_step_info *stepinfo; const struct nand_ecc_step_info *stepinfo;
int preset_step = chip->ecc.size; int preset_step = chip->ecc.size;
int preset_strength = chip->ecc.strength; int preset_strength = chip->ecc.strength;
int nsteps, ecc_bytes; int ecc_bytes, nsteps = mtd->writesize / preset_step;
int i, j; int i, j;
if (WARN_ON(oobavail < 0))
return -EINVAL;
if (!preset_step || !preset_strength)
return -ENODATA;
nsteps = mtd->writesize / preset_step;
for (i = 0; i < caps->nstepinfos; i++) { for (i = 0; i < caps->nstepinfos; i++) {
stepinfo = &caps->stepinfos[i]; stepinfo = &caps->stepinfos[i];
...@@ -6135,7 +6128,6 @@ int nand_check_ecc_caps(struct nand_chip *chip, ...@@ -6135,7 +6128,6 @@ int nand_check_ecc_caps(struct nand_chip *chip,
return -ENOTSUPP; return -ENOTSUPP;
} }
EXPORT_SYMBOL_GPL(nand_check_ecc_caps);
/** /**
* nand_match_ecc_req - meet the chip's requirement with least ECC bytes * nand_match_ecc_req - meet the chip's requirement with least ECC bytes
...@@ -6147,7 +6139,8 @@ EXPORT_SYMBOL_GPL(nand_check_ecc_caps); ...@@ -6147,7 +6139,8 @@ EXPORT_SYMBOL_GPL(nand_check_ecc_caps);
* number of ECC bytes (i.e. with the largest number of OOB-free bytes). * number of ECC bytes (i.e. with the largest number of OOB-free bytes).
* On success, the chosen ECC settings are set. * On success, the chosen ECC settings are set.
*/ */
int nand_match_ecc_req(struct nand_chip *chip, static int
nand_match_ecc_req(struct nand_chip *chip,
const struct nand_ecc_caps *caps, int oobavail) const struct nand_ecc_caps *caps, int oobavail)
{ {
struct mtd_info *mtd = nand_to_mtd(chip); struct mtd_info *mtd = nand_to_mtd(chip);
...@@ -6159,9 +6152,6 @@ int nand_match_ecc_req(struct nand_chip *chip, ...@@ -6159,9 +6152,6 @@ int nand_match_ecc_req(struct nand_chip *chip,
int best_ecc_bytes_total = INT_MAX; int best_ecc_bytes_total = INT_MAX;
int i, j; int i, j;
if (WARN_ON(oobavail < 0))
return -EINVAL;
/* No information provided by the NAND chip */ /* No information provided by the NAND chip */
if (!req_step || !req_strength) if (!req_step || !req_strength)
return -ENOTSUPP; return -ENOTSUPP;
...@@ -6220,7 +6210,6 @@ int nand_match_ecc_req(struct nand_chip *chip, ...@@ -6220,7 +6210,6 @@ int nand_match_ecc_req(struct nand_chip *chip,
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(nand_match_ecc_req);
/** /**
* nand_maximize_ecc - choose the max ECC strength available * nand_maximize_ecc - choose the max ECC strength available
...@@ -6231,7 +6220,8 @@ EXPORT_SYMBOL_GPL(nand_match_ecc_req); ...@@ -6231,7 +6220,8 @@ EXPORT_SYMBOL_GPL(nand_match_ecc_req);
* Choose the max ECC strength that is supported on the controller, and can fit * Choose the max ECC strength that is supported on the controller, and can fit
* within the chip's OOB. On success, the chosen ECC settings are set. * within the chip's OOB. On success, the chosen ECC settings are set.
*/ */
int nand_maximize_ecc(struct nand_chip *chip, static int
nand_maximize_ecc(struct nand_chip *chip,
const struct nand_ecc_caps *caps, int oobavail) const struct nand_ecc_caps *caps, int oobavail)
{ {
struct mtd_info *mtd = nand_to_mtd(chip); struct mtd_info *mtd = nand_to_mtd(chip);
...@@ -6242,9 +6232,6 @@ int nand_maximize_ecc(struct nand_chip *chip, ...@@ -6242,9 +6232,6 @@ int nand_maximize_ecc(struct nand_chip *chip,
int best_strength, best_ecc_bytes; int best_strength, best_ecc_bytes;
int i, j; int i, j;
if (WARN_ON(oobavail < 0))
return -EINVAL;
for (i = 0; i < caps->nstepinfos; i++) { for (i = 0; i < caps->nstepinfos; i++) {
stepinfo = &caps->stepinfos[i]; stepinfo = &caps->stepinfos[i];
step_size = stepinfo->stepsize; step_size = stepinfo->stepsize;
...@@ -6293,7 +6280,6 @@ int nand_maximize_ecc(struct nand_chip *chip, ...@@ -6293,7 +6280,6 @@ int nand_maximize_ecc(struct nand_chip *chip,
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(nand_maximize_ecc);
/** /**
* nand_ecc_choose_conf - Set the ECC strength and ECC step size * nand_ecc_choose_conf - Set the ECC strength and ECC step size
...@@ -6315,6 +6301,11 @@ EXPORT_SYMBOL_GPL(nand_maximize_ecc); ...@@ -6315,6 +6301,11 @@ EXPORT_SYMBOL_GPL(nand_maximize_ecc);
int nand_ecc_choose_conf(struct nand_chip *chip, int nand_ecc_choose_conf(struct nand_chip *chip,
const struct nand_ecc_caps *caps, int oobavail) const struct nand_ecc_caps *caps, int oobavail)
{ {
struct mtd_info *mtd = nand_to_mtd(chip);
if (WARN_ON(oobavail < 0 || oobavail > mtd->oobsize))
return -EINVAL;
if (chip->ecc.size && chip->ecc.strength) if (chip->ecc.size && chip->ecc.strength)
return nand_check_ecc_caps(chip, caps, oobavail); return nand_check_ecc_caps(chip, caps, oobavail);
......
...@@ -1663,15 +1663,6 @@ int nand_check_erased_ecc_chunk(void *data, int datalen, ...@@ -1663,15 +1663,6 @@ int nand_check_erased_ecc_chunk(void *data, int datalen,
void *extraoob, int extraooblen, void *extraoob, int extraooblen,
int threshold); int threshold);
int nand_check_ecc_caps(struct nand_chip *chip,
const struct nand_ecc_caps *caps, int oobavail);
int nand_match_ecc_req(struct nand_chip *chip,
const struct nand_ecc_caps *caps, int oobavail);
int nand_maximize_ecc(struct nand_chip *chip,
const struct nand_ecc_caps *caps, int oobavail);
int nand_ecc_choose_conf(struct nand_chip *chip, int nand_ecc_choose_conf(struct nand_chip *chip,
const struct nand_ecc_caps *caps, int oobavail); const struct nand_ecc_caps *caps, int oobavail);
......
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