diff mbox series

[v2] mtd: rawnand: nand_base: Handle algorithm selection

Message ID 20230308212851.370939-1-linus.walleij@linaro.org
State Superseded
Headers show
Series [v2] mtd: rawnand: nand_base: Handle algorithm selection | expand

Commit Message

Linus Walleij March 8, 2023, 9:28 p.m. UTC
For BRCMNAND with 1-bit BCH ECC (BCH-1) such as used on the
D-Link DIR-885L and DIR-890L routers, we need to explicitly
select the ECC like this in the device tree:

  nand-ecc-algo = "bch";
  nand-ecc-strength = <1>;
  nand-ecc-step-size = <512>;

This is handled by the Linux kernel but U-Boot core does
not respect this. Fix it up by parsing the algorithm and
preserve the behaviour using this property to select
software BCH as far as possible.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
ChangeLog v1->v2:
- Drop pointless check for ecc_algo >= 0, it is always
  >= 0.
---
 drivers/mtd/nand/raw/nand_base.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

Comments

Michael Nazzareno Trimarchi March 8, 2023, 11:02 p.m. UTC | #1
Hi

On Wed, Mar 8, 2023 at 10:29 PM Linus Walleij <linus.walleij@linaro.org> wrote:
>
> For BRCMNAND with 1-bit BCH ECC (BCH-1) such as used on the
> D-Link DIR-885L and DIR-890L routers, we need to explicitly
> select the ECC like this in the device tree:
>
>   nand-ecc-algo = "bch";
>   nand-ecc-strength = <1>;
>   nand-ecc-step-size = <512>;
>
> This is handled by the Linux kernel but U-Boot core does
> not respect this. Fix it up by parsing the algorithm and
> preserve the behaviour using this property to select
> software BCH as far as possible.
>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
> ChangeLog v1->v2:
> - Drop pointless check for ecc_algo >= 0, it is always
>   >= 0.
> ---
>  drivers/mtd/nand/raw/nand_base.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
> index 9eba360d55f3..c173fd09237a 100644
> --- a/drivers/mtd/nand/raw/nand_base.c
> +++ b/drivers/mtd/nand/raw/nand_base.c
> @@ -4487,6 +4487,7 @@ EXPORT_SYMBOL(nand_detect);
>  static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, ofnode node)
>  {
>         int ret, ecc_mode = -1, ecc_strength, ecc_step;
> +       int ecc_algo = NAND_ECC_UNKNOWN;
>         const char *str;
>
>         ret = ofnode_read_s32_default(node, "nand-bus-width", -1);
> @@ -4512,10 +4513,13 @@ static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, ofnode nod
>                         ecc_mode = NAND_ECC_SOFT_BCH;
>         }
>
> -       if (ecc_mode == NAND_ECC_SOFT) {
> -               str = ofnode_read_string(node, "nand-ecc-algo");
> -               if (str && !strcmp(str, "bch"))
> +       str = ofnode_read_string(node, "nand-ecc-algo");
> +       if (str && !strcmp(str, "bch")) {
> +               ecc_algo = NAND_ECC_BCH;
> +               if (ecc_mode == NAND_ECC_SOFT)
>                         ecc_mode = NAND_ECC_SOFT_BCH;
> +       } else if (!strcmp(str, "hamming")) {
> +               ecc_algo = NAND_ECC_HAMMING;
>         }
>
>         ecc_strength = ofnode_read_s32_default(node,
> @@ -4529,6 +4533,8 @@ static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, ofnode nod
>                 return -EINVAL;
>         }
>
> +       chip->ecc.algo = ecc_algo;
> +
>         if (ecc_mode >= 0)
>                 chip->ecc.mode = ecc_mode;
>
> --
> 2.39.1
>
Reviewed-by: Michael Trimarchi <michael@amarulasolutions.com>

Michael
William Zhang March 11, 2023, 1:02 a.m. UTC | #2
On 03/08/2023 01:28 PM, Linus Walleij wrote:
> For BRCMNAND with 1-bit BCH ECC (BCH-1) such as used on the
> D-Link DIR-885L and DIR-890L routers, we need to explicitly
> select the ECC like this in the device tree:
> 
>    nand-ecc-algo = "bch";
>    nand-ecc-strength = <1>;
>    nand-ecc-step-size = <512>;
> 
> This is handled by the Linux kernel but U-Boot core does
> not respect this. Fix it up by parsing the algorithm and
> preserve the behaviour using this property to select
> software BCH as far as possible.
> 
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
> ChangeLog v1->v2:
> - Drop pointless check for ecc_algo >= 0, it is always
>    >= 0.
> ---
>   drivers/mtd/nand/raw/nand_base.c | 12 +++++++++---
>   1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
> index 9eba360d55f3..c173fd09237a 100644
> --- a/drivers/mtd/nand/raw/nand_base.c
> +++ b/drivers/mtd/nand/raw/nand_base.c
> @@ -4487,6 +4487,7 @@ EXPORT_SYMBOL(nand_detect);
>   static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, ofnode node)
>   {
>   	int ret, ecc_mode = -1, ecc_strength, ecc_step;
> +	int ecc_algo = NAND_ECC_UNKNOWN;
>   	const char *str;
>   
>   	ret = ofnode_read_s32_default(node, "nand-bus-width", -1);
> @@ -4512,10 +4513,13 @@ static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, ofnode nod
>   			ecc_mode = NAND_ECC_SOFT_BCH;
>   	}
>   
> -	if (ecc_mode == NAND_ECC_SOFT) {
> -		str = ofnode_read_string(node, "nand-ecc-algo");
> -		if (str && !strcmp(str, "bch"))
> +	str = ofnode_read_string(node, "nand-ecc-algo");
> +	if (str && !strcmp(str, "bch")) {
> +		ecc_algo = NAND_ECC_BCH;
> +		if (ecc_mode == NAND_ECC_SOFT)
>   			ecc_mode = NAND_ECC_SOFT_BCH;
> +	} else if (!strcmp(str, "hamming")) {
> +		ecc_algo = NAND_ECC_HAMMING;
>   	}
>   
>   	ecc_strength = ofnode_read_s32_default(node,
> @@ -4529,6 +4533,8 @@ static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, ofnode nod
>   		return -EINVAL;
>   	}
>   
> +	chip->ecc.algo = ecc_algo;
> +
>   	if (ecc_mode >= 0)
>   		chip->ecc.mode = ecc_mode;
>   
> 

Acked-by: William Zhang <william.zhang@broadcom.com>
diff mbox series

Patch

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 9eba360d55f3..c173fd09237a 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -4487,6 +4487,7 @@  EXPORT_SYMBOL(nand_detect);
 static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, ofnode node)
 {
 	int ret, ecc_mode = -1, ecc_strength, ecc_step;
+	int ecc_algo = NAND_ECC_UNKNOWN;
 	const char *str;
 
 	ret = ofnode_read_s32_default(node, "nand-bus-width", -1);
@@ -4512,10 +4513,13 @@  static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, ofnode nod
 			ecc_mode = NAND_ECC_SOFT_BCH;
 	}
 
-	if (ecc_mode == NAND_ECC_SOFT) {
-		str = ofnode_read_string(node, "nand-ecc-algo");
-		if (str && !strcmp(str, "bch"))
+	str = ofnode_read_string(node, "nand-ecc-algo");
+	if (str && !strcmp(str, "bch")) {
+		ecc_algo = NAND_ECC_BCH;
+		if (ecc_mode == NAND_ECC_SOFT)
 			ecc_mode = NAND_ECC_SOFT_BCH;
+	} else if (!strcmp(str, "hamming")) {
+		ecc_algo = NAND_ECC_HAMMING;
 	}
 
 	ecc_strength = ofnode_read_s32_default(node,
@@ -4529,6 +4533,8 @@  static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, ofnode nod
 		return -EINVAL;
 	}
 
+	chip->ecc.algo = ecc_algo;
+
 	if (ecc_mode >= 0)
 		chip->ecc.mode = ecc_mode;